private void btnLoad_Click(object sender, RoutedEventArgs e) //loads the acount list data from a text file { OpenFileDialog dialog = new OpenFileDialog(); dialog.Filter = "txt files (*.txt)|*.txt"; bool?res = dialog.ShowDialog(); if (res != null && res.Value == true) { StreamReader loadMe = new StreamReader(dialog.FileName); string line; while ((line = loadMe.ReadLine()) != null) { if (string.IsNullOrWhiteSpace(line))//empty line for separete clients { continue; } string[] subValues = line.Split('|');//last element is All saving programs string[] subSaving = null; if (!string.IsNullOrWhiteSpace(subValues[subValues.Length - 1])) { subSaving = subValues[subValues.Length - 1].Split(new char[] { '!' }, StringSplitOptions.RemoveEmptyEntries); } AcountProgram ap; if (subValues[0] == "Normal") { ap = new AcountProgram(subValues[1], subValues[2], int.Parse(subValues[3]), DateTime.Parse(subValues[4]), double.Parse(subValues[5]), subValues[6]); } else if (subValues[0] == "vip") { ap = new Vip(subValues[1], subValues[2], int.Parse(subValues[3]), DateTime.Parse(subValues[4]), double.Parse(subValues[5]), subValues[6]); } else //if(subValues[0] == "business") { ap = new Business(subValues[1], subValues[2], int.Parse(subValues[3]), DateTime.Parse(subValues[4]), subValues[7], double.Parse(subValues[5]), subValues[6]); } if (subSaving != null) //then the client has saving programs { string[] subSavingDetail = null; for (int i = 0; i < subSaving.Length; i++) { subSavingDetail = subSaving[i].Split('~'); NewSavingAcount newsave = new NewSavingAcount(double.Parse(subSavingDetail[2]), DateTime.Parse(subSavingDetail[1]), DateTime.Parse(subSavingDetail[0])); ap.AddSaveProgramLoad(newsave); } } manager.Add(ap); } MessageBox.Show("File has been successfuly loded"); loadMe.Close(); } }
private void btnRegister_Click(object sender, RoutedEventArgs e) { string error = " "; //validation of all the data fields have been entered corectly. if (!CheckText(txtFirstName.Text)) { txtFirstName.Text = ""; error = ", First name is invalid"; } if (!CheckText(txtLastName.Text)) { txtLastName.Text = ""; error = error + ", Last name is invalid"; } if (txtID.Text.Length != 9 || !CheckNum(txtID.Text)) { txtID.Text = ""; error = error + ", ID is invalid"; } if (txtBalance.Text.Length == 0 || !CheckNum(txtBalance.Text)) { txtBalance.Text = ""; error = error + ", Balance is invalid"; } if (cbBusiness.IsChecked == true) { if (txtBusinessName.Text.Length == 0) { error = error + ", Business name is invalid"; } } if (!string.IsNullOrWhiteSpace(error)) //checks if there is an error on one or more of the fields that have been entered and if true //displays the error. { error = error.Remove(0, 2); System.Windows.Forms.MessageBox.Show(error); return; } if (manager.CheckId(int.Parse(txtID.Text)) != -1) //checks if the ID that have been entered by the user does not allready exists in the system. { txtID.Clear(); System.Windows.Forms.MessageBox.Show("ID exists in the system"); return; } //checks wich acount type have been chosen and saves acourdingly. if (cbBusiness.IsChecked == true) { manager.Add(new Business(txtFirstName.Text, txtLastName.Text, int.Parse(txtID.Text), DateTime.Now, txtBusinessName.Text, double.Parse(txtBalance.Text), imageUri)); } else if (double.Parse(txtBalance.Text) > 100000) { manager.Add(new Vip(txtFirstName.Text, txtLastName.Text, int.Parse(txtID.Text), DateTime.Now, double.Parse(txtBalance.Text), imageUri)); } else { manager.Add(new AcountProgram(txtFirstName.Text, txtLastName.Text, int.Parse(txtID.Text), DateTime.Now, double.Parse(txtBalance.Text), imageUri)); } System.Windows.Forms.MessageBox.Show("Congratulations! Account has been registered"); Clear(); }