1

I am new to c#

This is my form design: https://i.stack.imgur.com/l3IO8.png

The main idea is that a customers info can be inuptted into the "Title", "Name" etc text boxes and then be saved to the listbox under the clients name. Then when the client is selected from the list the information will be displayed back in the text boxes.

This information (database) will be saved to a file on the desktop and will be loaded back into the form.

As I mentioned, I am new to C# and I don't know exactly where to start. I have heard a few names tossed around, Serialization? LINQ to XML? What is the best way to approach this project and are there any similar projects that I can easily learn off.

urbexppxuc
  • 21
  • 1
  • 3
  • 1
    I think XML is the best choice in this case. Look, for example here: http://stackoverflow.com/questions/670563/linq-to-read-xml http://broadcast.oreilly.com/2010/10/understanding-c-simple-linq-to.html – user1429899 Aug 19 '14 at 06:29

1 Answers1

1

A CSV (Comma Separated Values) file might be a good idea.

You could combine each customers details then save each one as a new line in a CSV file.

For Example.

string custDetails = title + ',' + fullName + ',' (and so on.....)

or (if you are comfortable using loops)

for (int i = 0; i < 5; i++)                      // 5 text boxes
{
    custDetails += textBox[i].Text + ',';        // Add each value + a comma (to separate the values later)
}

Then write the line to a file and save it to the desktop.

Then when the form is loaded, read the file LINE BY LINE into a List, split the string on commas (Look up c# string split)

And finally when the selected index of the list box is changed, update the values for each text box.

Hopefully that was clear enough for you and helps you out :)

EDIT: Added an example of reading a file line by line

 static void Main(string[] args)
    {
        List<String> list = new List<String>();
        using (StreamReader sr = new StreamReader(@"C:\Users\Tim\Desktop\example.csv"))
        {
            string line;
            while ((line = sr.ReadLine()) != null)
            {
                list.Add(line);
                Console.WriteLine(line);
            }
        }
    }

This goes through the file at "C:\Users\Tim\Desktop\example.csv" and puts every line of that file into a list.

This is useful because later, you can find the data in the list for the customer you want to see in your address book. You then just need to grab that string, split it at every comma, and put that data into the text boxes in your form. :)

Hopefully that clarifies things for you. (Drop me a message in the comments if this isn't clear enough or if you don't understand something :))

Tim
  • 370
  • 5
  • 9
  • Thanks I'll look into this. In the mean time are there any examples of solutions I can look at? – urbexppxuc Aug 19 '14 at 09:15
  • Ok so I understand everything up until when yo usaid read the file "LINE by LINE into a List". – urbexppxuc Aug 19 '14 at 09:28
  • When you're using streamreader to read the file, you can read it line by line into a list or an array. For example, line one might be "sometitle,somename,someaddress,somephone,someID" Then line 2 could be "aTitle,aName,anAddress,aPhone,aCustID" then you could split that string every time it sees a comma and put those values into the texboxes. I'll see if I can find an example for you. – Tim Aug 19 '14 at 10:25
  • any luck finding an example? – urbexppxuc Aug 20 '14 at 06:32