Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
Sab669
Sep 24, 2009

I'm having a small logic problem, maybe you guys can help?

quote:

string scores = "";
score.Sort();
int x = score.Count();
for (int y = 0; y < x; y++)
scores = score[y] + "\r";

MessageBox.Show(scores, "Scores");

But when I display the string, it only shows the last index of the list.

e; disregard this, I figured it out.
scores += score[y] + "\r"; duh.. so stupid of me.

Sab669 fucked around with this message at 01:28 on Dec 10, 2009

Adbot
ADBOT LOVES YOU

Sab669
Sep 24, 2009

I'm having a bit of a problem with a combo box for this project I'm working on. Basically, the program is just a simple application that let's the owner of a restaurant manage employee data, items on their menu, and reservations.

I'm handling the menu portion, and my two group mates are doing the other two functions. Each one of these three functions will obviously have the basic Create / Read / Update / Delete abilities, and I have 3 out of 4 of these functions working. I'm stuck on the Update portion.

So, say you launch the program, this is what it'd look like:


Then when you select Menu, you're presented with the various CRUD options:


As said, I'm stuck on Edit. I have the user prompted with a combo box that lets them select the piece of food they want to edit, then click the button:


That will open up a new form, which is populated with info from the database HOWEVER the combo box is what I'm stuck on. I've tried changing all sorts of properties, but I have no idea which one I want to change, and it keeps throwing errors that I don't quite understand, or it doesn't throw an error and then defaults to the first thing, which is Appetizer:



What it should be:


So yea, I've tried tooling around with drat near every property of the combo box, and I can't seem to figure out what I'm doing wrong.

Here's the code for the entire page. Initially, instead of a for loop, I just had while(drSelect.Read()) but that was returning -1 for menuType, I think? So I tried a for instead, but that didn't solve the problem.
http://pastebin.com/CZVWBYn8

The database I'm using has 2 tables.
Menus, which stores the menuID, menuPrice, menuName, menuDesc, and menuType (foriegn key to the following table)

Types, which stores typeID, typeName

So this would be the Appetizer, Entree, Dessert, Beverage table. But again, I can't seem to get the Edit Menu form to properly display which course the designated food falls under. Any ideas what I'm doing wrong, goons?

Sab669 fucked around with this message at 00:13 on May 5, 2010

Sab669
Sep 24, 2009

Sweeper posted:

I'm couldn't really follow your post, but you want it to have Entree selected?

So.. comboBox1.SelectedIndex = 1;
Index starts at 0, so entree is 1? I would also recommend you put your items in alphabetical order, it makes more sense.

And if you have your combo box indices linked to your database ids you can just select the correct id based on the one you get from the database.


Well, for the condition shown in the screen shot, yes, Entree is supposed to be selected. But if they chose Bud Lite in the previous prompt, then it should display Beverage.

I've tried cmbCourse.SelectedIndex = Convert.ToInt16(drSelect["menuType"]); and it didn't work. As I've said, I've tried drat near every property for the combo box. From SelectedMember, Index, Value, to DisplayMember or Value, I've fidgetted with almost everything.

Sab669
Sep 24, 2009

Sprawl posted:

Well you are setting the index an int value with a 0 index to well i'm not sure how that even works.

code:
int index = cmbCourse.FindString(drSelect["menuType"]);
cmbCourse.SelectedIndex = index;
This is assuming your "menutype" is the string your looking for if its say the ID in your table then you'll have to pull out the string.

Also this is an app for school right? just proof of concept?

efb;

I've made the mistake of going to a Tech school, rather than a traditional college, so this is actually my "senior" project. Will have my associates degree in a few weeks.

e; so yes, I know it's terrible and I'm not a good programmer.

Sab669
Sep 24, 2009

I've tried printing out menuType to a text field, like just concatenating it onto txtDesc.Text and it does return the value expected (in this case, a 2).

Sab669
Sep 24, 2009

Sprawl posted:

Okay well iirc a combo box index is a 0 index so you would need to -1 to that value anyways.

I think i finally understand what you need to do

code:
cmbCourse.SelectedIndex = drSelect["menuType"];
should be

code:
cmbCourse.SelectedIndex = ID - 1;

Well, the thing with ID - 1 is that ID is actually the ID of the meal they edited, so that can range from 1 through 40 based off whatever meal they selected from that first drop down box. But I get what you're saying.

I could just parse out menuType to any variable, subtract one, and then do SelectedIndex = that.

Thing is though, I know I tried setting SelectedIndex = menuType, and it threw some error. I don't recall what, exactly though. And I'm honestly not sure if I can work on it now (I'm out of class finally) and my laptop was having some problems connecting to the DB last I knew.

Sab669
Sep 24, 2009

Sweeper posted:

You should have a meal type id and a meal id, otherwise you can't tell what kind of meal it is without hardcoding it in. The meal type id will tell you if it is an entree or whatever and the meal id is the unique id you identify the meal as.

In the menu table, menuType is just an int from 1-4, which is a foriegn key for the actual Types table, which is typesID (this being the other key), and then actual typesName field.

Thanks for the help guys. I'll try it out when I get a chance. I guess one last big question; how bad IS my code?

Sab669
Sep 24, 2009

I have now found I have an excessive amount of spare time on my hands- forced into switching to part time for school, hours getting cut at work, distance relationship with the girlfriend. So I have copious amounts of time, and I want to try and do something constructive.

I have my associate's in IT / Software, but I really don't know gently caress all. I was hardly even taught how to work with classes. Either way, I want to brush up on my C# so I can actually do stuff, but I have no idea where to start. I can't come up with a program I'd like to make, anyone have any tips on how to motivate myself? Any websites out there that have 'homework assignments' so I can try and do something?

Learning how to do stuff with graphics would be awesome, but I guess one step at a time.

Sab669
Sep 24, 2009

I'd like to think I'm a competent IT major. I graduate soon and I've started to look for work. My roommate works for a company and I just found out they have a few openings for a Embedded Firmware Engineering position.

My only problem is it's straight up C. I've done SOME C++, but all of my formal education is in C#. How difficult would it be to learn C?

Sab669
Sep 24, 2009

Interesting insight, it is for an entry level thing (it says 0-2 years exp. in a professional environment). I think I'm still going to apply for it? Either I get interview experience, or I get a job and who knows from there.

It is definitely something I'm interested in, I think it'd be really cool to work that low-level and have that level of control.

e; vvv What?

Sab669 fucked around with this message at 18:08 on Jan 17, 2012

Sab669
Sep 24, 2009

Good god, why is VB so ugly? I found what could be an awesome job, except its "70% VB, 30% C#" so I've been looking at VB today.. god drat :stare:

Sab669
Sep 24, 2009

Shy posted:

Why? I never used it but I thought it pretty much does the same job as C# almost as easily.
Not trying to call anyone out, but it would be really interesting to hear what makes it awful (other than not being C-like which is certainly a deal breaker for some people).

Well, I mean it's similar enough, it just overall seems like a lot of extra typing compared to what I'm used to

http://www.harding.edu/fmccown/vbnet_csharp_comparison.html

That's what I was briefly skimming for a comparison

Sab669
Sep 24, 2009

So, I'm pretty new to the whole "security", thing. I don't take my first official software security class until next quarter, but I'm always down for learning sooner.

I'm working on an online shopping cart sort of application in a .net class I'm taking this quarter, and I have it so people need to sign up before they can purchase stuff. But I'm curious, what's considered the 'proper' way of encrypting passwords in .Net?

I recently "learned how" in PHP (or rather, someone briefly showed me the phpass class), but I wouldn't know how to properly encrypt it when I first add a user to a database, and then when they actually log in compare that to what's in the DB.

Any pointers, goons?

Sab669
Sep 24, 2009

In regards to my post the on the previous page, I guess I didn't realize there was a difference between "encrypting" and "hashing"- thought they basically meant the same thing.

But yea, I know I never want to store the users' passwords. Have them create an account, hash and salt the password (account creation date/ time is a common salt from what I hear),and then re-do the process when they log in... but I don't know how to actually do that in the language is what my issue was. I wasn't sure which has is more secure than another or how to actually handle any of it.

Thanks for the crash course, though.

e;
Found this on StackOverflow
code:
using System.Security.Cryptography;

public static string EncodePasswordToBase64(string password)
{  byte[] bytes   = Encoding.Unicode.GetBytes(password);
   byte[] inArray = HashAlgorithm.Create("SHA1").ComputeHash(bytes);
   return Convert.ToBase64String(inArray);
}
I guess I'm just so unsure of all this stuff because, again, when I was trying to do this in PHP I had the issue of not properly re-creating the salt when the user logged in. So if "cat" was their password and the salt was 123 when they created the account, maybe it was cat234 the value being generated when they tried to logged in.

Sab669 fucked around with this message at 16:43 on Feb 2, 2012

Sab669
Sep 24, 2009

I guess I must be doing this completely the wrong way. I'm trying to make a shopping cart for class and I've got most of the framework set up [I think] and now I'm trying to do the front end. This is probably going make a lot of people cry, but I guess I don't know how else to do it.

http://pastebin.com/XTVtN4MM

Basically, I'm just looping through my SqlDataReader object to print out a table that has a thumbnail of each item. I have a label that doesn't show up on that stores the product ID. But the button doesn't show up, either.

I am aware the button doesn't have any method tied to it yet, I was going to do that after I got it to all appear properly.

But yea, uh, after you guys recover from your head exploding could someone tell how I should be making the button to add stuff to the cart display?

e; Oh, and then tableCode is just being thrown into a label on the page. Everything shows up fine except the button / the label that stores the productID (I don't want that label to show up, though)

Sab669 fucked around with this message at 22:42 on Feb 13, 2012

Sab669
Sep 24, 2009

Oh, that's pretty cool Ithaqua. I wasn't aware that that was even a thing. I was kind of thinking about how I'd do this in PHP an adapting it to this project. Though I suppose even in PHP that's not exactly the best way to do it.

Sab669
Sep 24, 2009

edit; one big giant derp :downs:

Sab669 fucked around with this message at 22:41 on Feb 16, 2012

Sab669
Sep 24, 2009

What would be the difference between a DataList control and the Repeater control? Unfortunately, the Murach ASP book simply states, "Instead of a DataList control, you can also use the Repeater control, which has one draw back. It cannot be designed through the interface, and as such it won't be discussed in this book".

A few weeks ago I mentioned I'm working on a shopping cart for a website and was approaching displaying the results of a SQL statement completely wrong and I was told to look into Repeaters. Having a bit of trouble understanding a lot of the tutorials I'm finding online, though.

Sab669
Sep 24, 2009

A few more newbie questions :downs:

I'm trying to loop through a folder and display all of the images in it. Then, I'd like each image to be clickable so that when it is clicked it'll automatically download the file.

code:
string[] fileEntries = Directory.GetFiles(Server.MapPath("~/Images"));
            ImageButton[] buttons = new ImageButton[fileEntries.Length];
            int i = 0;

            foreach (string file in fileEntries)
            {
                buttons[i] = new ImageButton();
                buttons[i].ImageUrl = file;
                //buttons[i].Click += new ImageClickEventHandler(imageDownLoad);
                i++;
                
            }
That's what I have, but the ImageButtons don't actually show up on the page.
Also I'm having issues with that line I commented out as well. It gives the error, "No overload for imageDownload matches delegate System.Web.UI.ImageClickEventHandler" but the first issue of them not showing up is a bit more critical at the moment.

Sab669
Sep 24, 2009

Looking through a breakpoint, it says buttons[0]'s ImageUrl = "E:\\MyProject\\Images\\Image1.jpg", so that would be correct, right?

e; or should it simply just be Images\\Image1.jpg?

Sab669
Sep 24, 2009

Yea, that was dumb of me Ithaqua. I'm not sure why I thought it'd work :v:

I was able to just Subtract 0 - n so that it was only putting in Images\\Image1.jpg into the ImageUrl, then added that to a control on the page and it worked now.

Now to iron out this issue of not being able to set the OnClick in the code...

Sab669
Sep 24, 2009

This is a really dumb question but I've never had this happen before. I just got to class to finish up a project. Set some breakpoints before/where it crashes and hit F5, but no window pops up showing me whats in all my variables and stuff.

I've no idea what this window is even called to look for it, and my teacher isn't sure either. He thought it was the Immediate window but that's not it. Anyone know?

Sab669
Sep 24, 2009

I'll try that. I was also able to just google "Visual Studios Debug window" and found a screenshot of what I was looking for, the "Local" window. So I just typed in Local into the Command window and that pulled it up for me.

Sab669
Sep 24, 2009

Are any of you goons familiar with the StrataFrame framework? I'm contemplating applying for an internship with a company that uses it. The website for it looks very... "tries to be cool" and turns me off, I feel. I've never heard of it before, but hey I'm also a student so what do I know.

Sab669
Sep 24, 2009

edit; fixed.

Sab669 fucked around with this message at 20:12 on Apr 26, 2012

Sab669
Sep 24, 2009

This is a random, dumb question, but is there a way to set the width of a combo box's menu? The actual part that displays the currently selected index is small to fit 'in line' with the rest of the controls on this form, but then when you expand it to select the item you want you can't read all of the text.

e; of course as I post I re-read the property list for a third time and find the DropDownWidth :downs:

Sab669
Sep 24, 2009

Any of you guys have experience using the Property Grid control?

For example, lets saying I'm making a tool to generate a weapon.
I've got a List View on the side of my form that lists all the possible components; barrel, stock, scope etc.

I would like it that when I click on one of the barrel, the property grid would show options A, B, and C to set. stock will show X, Y and Z, and scope will show another set.

Problem is, I have no idea how to use the PropertyGrid. Does anyone have any decent recommended readings or sample projects? I see it has a Selected Object property, which I can set to a row in my list view, but that lets me edit the row itself- not the item in the row.

Sab669 fucked around with this message at 21:08 on May 9, 2012

Sab669
Sep 24, 2009

Alright, playing around with that property grid from last week a little bit more and I'm having an error with that / list view control...

code:
private void lvJobComponents_SelectedIndexChanged(object sender, EventArgs e)
{
   jobPropertiesBO1.FillByParentPrimaryKey(lvJobComponents.SelectedItems[0].Tag);
   pgComponentProperties.SelectedObject = jobPropertiesBO1;
}
So any time my List View of JobComponents selected item changes, this event should fire. Then I populate my object based off its' parents primary key, which is the tag for the single selected item (multi-select is turned off). Then I just try to set my property grid to that object that gets populated based on the list view's currently selected item.

Now, the funny thing is when I launch the application and select an item the first time it works as I expect it to. But then when I select a different item, it crashes and gives me this error:

System.ArgumentOutOfRangeException was unhandled
Message=InvalidArgument=Value of '0' is not valid for 'index'.
Parameter name: index


Whether I run it and select the second item in the list, then the first or run it and select the first then the second it gives me this error on the first line of that event.



Edit; Well, no idea what the hell my problem was but it's fixed :downs:

Sab669 fucked around with this message at 20:50 on May 14, 2012

Sab669
Sep 24, 2009

So I've been posting my frustrations about the Property Grid control lately, and I've overcome most of the issues I've had except I'm having quite a bit of trouble understanding this.

The user launches the application, selects a job order and then a list view is populated with a "component" object. The user selects one of these components, and then another class is populated based on the various properties/configurations this component could have. I've been using this to loop through a result set and add the appropriate component properties to the object.

However, with the method I'm using, every property of that PropertyBag class is just a string, but I'd like to be able to handle images or combo boxes in the property grid as well. I can't seem to figure out how to determine that though, I was thinking of perhaps adding a column to the database for each property that would just list how it should be handled in the property grid, then when that property bag is being built it would take that into consideration.

Any advice on a possibly simpler way to handle something like this?

e; Also, random question. What's the difference from simply trying to cast something from one data type to another, and using the Convert class' various ToWHatever methods?

Sab669 fucked around with this message at 19:18 on May 21, 2012

Sab669
Sep 24, 2009

This is kind of a random question, but is there a way to move where a form is displayed in Visual Studios in the designer?

Like this;

Sab669
Sep 24, 2009


Well, I got a new job recently and my monitor space is... significantly larger than what I'm used to. I can't seem to get a comfortable setting to work in when I'm looking at the designer.

I know it sounds kind of retarded and babyish, I wasn't sure if it was some easy thing to do that I just never learned / couldn't find on Google.

Sab669
Sep 24, 2009

In C#, I have a form1 that can display form2. When form2 closes, how would I refresh a control on form1?

Sab669
Sep 24, 2009

Mr.Hotkeys posted:

Add something like the second line before you show the form:

C# code:
Form2 form2 = new Form2();
form2.FormClosed += ((s, e) => this.Refresh());
form2.Show();
Or if you want to refresh just one specific control then call its refresh method instead of the form's refresh (throw its name in place of the this).

Thanks for the tip; what exactly is happening here with the ((s, e) so I can go read up on it?

e; vvv Very interesting.

Sab669 fucked around with this message at 15:05 on May 30, 2012

Sab669
Sep 24, 2009

So I'm trying to create a little logging system that keeps track of changes to a business object.

code:
if (!Object.Equals(jhTemp, jobHeaderBO1))
{
    jobHeaderBO1.modifiedBy = SecurityBasics.CurrentUser.UserPK;
    jobHeaderBO1.modifiedDate = DateTime.Now;
}
When the business object (jobHeaderBO1) loads, I set jhTemp equal to it. Then when the user clicks the save button, I compare the temp that has the "original" values, and then the actual object that user was toying with. If they're not the same, then we set the modded date and user and carry on saving them. If not, those two fields remain unchanged and retain the original modified date & by values.

Am I wrong in my logic here? Does Object.Equals work differently? When I make a change to a field for the object, the if statement is being skipped over.

Sab669
Sep 24, 2009

How would one go about populating an array with the values from a combo box?

code:
string[] cbItems = new string[cbSetupUnitID.Items.Count];
for (int i = 0; i < cbSetupUnitID.Items.Count; i++)
{
   cbItems[i] = cbSetupUnitID.Items[i].ToString();
}
This doesn't give me the text value of each possible item in the combo box, though :(

Sab669 fucked around with this message at 19:47 on Jun 4, 2012

Sab669
Sep 24, 2009

Unfortunately, if I try that, each item in the array just says System.Data.DataRowView. Might just try to go about this in a different way entirely.

Sab669
Sep 24, 2009

Ithaqua posted:

That's because you're putting a DataRowView in your combo box. You should be able to access it by the property name:

cbItems[i] = cbSetupUnitID.Items[i]["WhateverFuckingPropertyName"].ToString();

Ah, the thing with that is when it comes to production time, the end user will actually be able to add values to what could appear in this drop down if they so chose, so I was hoping to just automatically go and get everything in it and throw that into the array for use elsewhere.

But I approached the problem differently and it does what I need it to do now, though. Thanks for the help as always goons.

Sab669
Sep 24, 2009

Well, for what it's worth

MSDN posted:

@Disconnect
To ensure that all data is sent and received before the socket is closed, you should call Shutdown before calling the Disconnect method.

@Close
For connection-oriented protocols, it is recommended that you call Shutdown before calling the Close method. This ensures that all data is sent and received on the connected socket before it is closed.

If you need to call Close without first calling Shutdown, you can ensure that data queued for outgoing transmission will be sent by setting the DontLinger Socket option to false and specifying a non-zero time-out interval. Close will then block until this data is sent or until the specified time-out expires. If you set DontLinger to false and specify a zero time-out interval, Close releases the connection and automatically discards outgoing queued data.

So it sounds all rather redundant (if you don't need any of the 'extra features'), but what the hell do I know. Personally I'd say, what's 2 extra method calls and just do it.

Sab669
Sep 24, 2009

More property grid questions! Just when I thought I was out, THEY PULL ME BACK IN. :argh:

Is there a way to disable this stupid thing from showing up at run-time?

It really doesn't bother me, but my boss wants it gone and I don't see anything relevant to "Property Pages" in the PropertyGrid's property sheet in visual studios, and can't find much on Google.

Also, I see the PropertyGrid has a "PropertySort", which can be set to NoSort in which case it displays records in the order in which they are received. I was hoping to maintain a categorized grouping of properties, but have the category and the property itself have an ID that would determine their appearance. Is that not possible? As soon as I click the "Categorized" view mode during run time, it goes to Alphabetized Categories.

Sab669 fucked around with this message at 22:10 on Jun 6, 2012

Adbot
ADBOT LOVES YOU

Sab669
Sep 24, 2009

Does the SelectedIndexChanged event on a ListView not get fired if you programmatically set the SelectedItem to a value that is the same as what is currently selected?

  • Locked thread