Exemplo n.º 1
0
 /* Reads in user info from a text file detailing username, password,
  * name, id, address, phone, email. */
 private void ReadUserInfo()
 {
     if(myList.Count != 0)
     {
         myList.Clear();
     }
     string line;
     string[] lineArray;
     inFile = new StreamReader("userInfo.txt");
     while (!inFile.EndOfStream)
     {
         line = inFile.ReadLine();
         lineArray = line.Split('|');
         myUser = new Login(lineArray[0], lineArray[1]);
         myList.Add(myUser);
         myCustomer = new Customer(lineArray[0], lineArray[1], int.Parse(lineArray[2]),
                                   lineArray[3], lineArray[4], lineArray[5], lineArray[6]);
         myCustomers.Add(myCustomer);
         userIDInt = int.Parse(lineArray[2]) + 1;
     }
     inFile.Close();
     inFile = new StreamReader("accounts.txt");
     while (!inFile.EndOfStream)
     {
         line = inFile.ReadLine();
         lineArray = line.Split(',');
         myAccount = new Account(int.Parse(lineArray[0]), int.Parse(lineArray[1]),
                                 int.Parse(lineArray[2]), lineArray[3], decimal.Parse(lineArray[4]),
                                 decimal.Parse(lineArray[5]));
         myAccounts.Add(myAccount);
         userAccountInt = int.Parse(lineArray[1]) + 1;
     }
     inFile.Close();
 }
Exemplo n.º 2
0
 private void btnCreateUser_Click(object sender, EventArgs e)
 {
     try
     {
         string[] line;
         string myDate;
         if (txtCreateName.Text.Count() > 0 && txtCreateAddress.Text.Count() > 0 && txtCreatePhone.Text.Count() > 0 &&
             txtCreateEmail.Text.Count() > 0 && txtCreatePassword.Text.Count() > 0)
         {
             myDate = DateTime.Today.ToString();
             line = myDate.Split(' ');
             myCustomer = new Customer(txtCreateUsername.Text,txtCreatePassword.Text, userIDInt,
                 txtCreateName.Text, txtCreateAddress.Text, txtCreatePhone.Text, txtCreateEmail.Text);
             myCustomers.Add(myCustomer);
             myUser = new Login(myCustomer.UserName, myCustomer.UserPassword);
             myList.Add(myUser);
             StreamWriter newUser = File.AppendText("userInfo.txt");
             newUser.WriteLine(myCustomer.ToString());
             myUserInt = 0;
             newUser.Close();
             for(int i = 0;i < 2; i++)
             {
                 if (i == 0)
                 {
                     myAccount = new Account(userIDInt, userAccountInt, i, line[0], 0, 0);
                     myAccounts.Add(myAccount);
                     userAccountInt++;
                 }
                 else
                 {
                     myAccount = new Account(userIDInt, userAccountInt, i, line[0], 0, .0125m);
                     myAccounts.Add(myAccount);
                     userAccountInt++;
                     userIDInt++;
                 }
             }
         }
         WriteUserInfo();
         WriteAccounts();
         SwitchScreen();
     }
     catch
     {
         MessageBox.Show("There was an error with creating this account.  Please try again later.", "ERROR!");
     }
 }