private void btnDeposit_Click(object sender, RoutedEventArgs e) //making sure a valid ID have been entered. { if (checkIdAmount() == false) { return; } int index = manager.CheckId(int.Parse(txtId.Text));//gets the acount Index by its ID. if (index != -1) { manager[index].Balance += double.Parse(txtSaveAmount.Text); manager[index].TotalAmount += double.Parse(txtSaveAmount.Text); MessageBox.Show("Deposit was made on the total: " + txtSaveAmount.Text + "$ to account: " + txtId.Text); } else { System.Windows.Forms.MessageBox.Show("invalid Id has been entered"); } bool?isVip = manager[index].CheckVip(manager[index]); //checking if after the deposit the acount's total money amount is over 100,000. if (isVip == true) //if isnt Business acount and total money amount is over 100,000. { AcountProgram temp = manager[index]; for (int j = 0; j < manager[index].NumOfSavings.Count; j++) { temp.NumOfSavings[j] = new NewSavingAcount(manager[index].NumOfSavings[j].Amount, manager[index].NumOfSavings[j].ClosingDate); } manager[index] = new Vip(temp.FirstName, temp.LastName, temp.IdNum, temp.OpeningDate, temp.Balance, temp.GetImage()); for (int j = 0; j < temp.NumOfSavings.Count; j++) { manager[index].AddSaveProgramLoad(temp.NumOfSavings[j]); } } else if (isVip == false)//if isnt Business acount and total money amount is under 100,000. { AcountProgram temp = manager[index]; for (int j = 0; j < manager[index].NumOfSavings.Count; j++) { temp.NumOfSavings[j] = new NewSavingAcount(manager[index].NumOfSavings[j].Amount, manager[index].NumOfSavings[j].ClosingDate); } manager[index] = new AcountProgram(temp.FirstName, temp.LastName, temp.IdNum, temp.OpeningDate, temp.Balance, temp.GetImage()); for (int j = 0; j < temp.NumOfSavings.Count; j++) { manager[index].AddSaveProgramLoad(temp.NumOfSavings[j]); } } txtSaveAmount.Clear(); }
public virtual bool?CheckVip(AcountProgram acount) //checks if total money amount is over ,so the program will know if a transferation //between normal acount to vip is needed. { if (acount.totalAmount > 100000) { return(true); } else { return(false); } }
public void SortByOld() //sorts the list by oldest opening date. { for (int i = bankAcounts.Count - 1; i > 0; i--) { for (int j = 0; j < i; j++) { if (bankAcounts[j].OpeningDate < bankAcounts[j + 1].OpeningDate) { AcountProgram temp = bankAcounts[j]; bankAcounts[j] = bankAcounts[j + 1]; bankAcounts[j + 1] = temp; } } } }
public void SortByFirstName() //sorts the list in an alphabetic order acourding to the first name. { for (int i = bankAcounts.Count - 1; i > 0; i--) { for (int j = 0; j < i; j++) { if (string.Compare(bankAcounts[j].FirstName, bankAcounts[j + 1].FirstName, true) > 0) { AcountProgram temp = bankAcounts[j]; bankAcounts[j] = bankAcounts[j + 1]; bankAcounts[j + 1] = temp; } } } }
public void SortByLowTotal() //sorts by the lowest total money amount. { for (int i = bankAcounts.Count - 1; i > 0; i--) { for (int j = 0; j < i; j++) { if (bankAcounts[j].TotalAmount > bankAcounts[j + 1].TotalAmount) { AcountProgram temp = bankAcounts[j]; bankAcounts[j] = bankAcounts[j + 1]; bankAcounts[j + 1] = temp; } } } }
public void SortByLowBalance() //sorts the list by the lowest balance. { for (int i = bankAcounts.Count - 1; i > 0; i--) { for (int j = 0; j < i; j++) { if (bankAcounts[j].Balance > bankAcounts[j + 1].Balance) { AcountProgram temp = bankAcounts[j]; bankAcounts[j] = bankAcounts[j + 1]; bankAcounts[j + 1] = temp; } } } }
private void mbCalculate_Click(object sender, RoutedEventArgs e) //calculates and change all of the acount details as instructed at the program's specification file. { for (int i = 0; i < manager.AcountsCount; i++) { manager[i].Calculate(i, manager); bool?isVip = manager[i].CheckVip(manager[i]); if (isVip == true)//if acount total money amount is over 100000 then the acount becomes a vip acount. { AcountProgram temp = manager[i]; for (int j = 0; j < manager[i].NumOfSavings.Count; j++) { temp.NumOfSavings[j] = new NewSavingAcount(manager[i].NumOfSavings[j].Amount, manager[i].NumOfSavings[j].ClosingDate); } manager[i] = new Vip(temp.FirstName, temp.LastName, temp.IdNum, temp.OpeningDate, temp.Balance, temp.GetImage()); for (int j = 0; j < temp.NumOfSavings.Count; j++) { manager[i].AddSaveProgramLoad(temp.NumOfSavings[j]); } } else if (isVip == false) { AcountProgram temp = manager[i]; for (int j = 0; j < manager[i].NumOfSavings.Count; j++) { temp.NumOfSavings[j] = new NewSavingAcount(manager[i].NumOfSavings[j].Amount, manager[i].NumOfSavings[j].ClosingDate); } manager[i] = new AcountProgram(temp.FirstName, temp.LastName, temp.IdNum, temp.OpeningDate, temp.Balance, temp.GetImage()); for (int j = 0; j < temp.NumOfSavings.Count; j++) { manager[i].AddSaveProgramLoad(temp.NumOfSavings[j]); } } } lbId.Visibility = Visibility.Visible; lblBalance.Visibility = Visibility.Hidden; lbFname.Visibility = Visibility.Hidden; lbLname.Visibility = Visibility.Hidden; lbTotal.Visibility = Visibility.Visible; listShowDetails.Items.Clear(); txtBdetails.Items.Clear(); showDetails(); }
public string GetSavingPrograms(AcountProgram acount, int index) //returns a string with the saving program details. { return(string.Format("Opening date: {0} \nClosing date: {1} \nAmount: {2:f3}$", acount.NumOfSavings[index].OpeningDate, acount.NumOfSavings[index].ClosingDate, acount.NumOfSavings[index].Amount)); }
public int GetNumOfSavingPrograms(AcountProgram acount) //this function gets an acount program and returns its number of the saving programs. { return(acount.NumOfSavings.Count); }
public void Add(AcountProgram newAccount)//adding a new acount to the list. { this.bankAcounts.Add(newAccount); }
private void btnPull_Click(object sender, RoutedEventArgs e) //if all the entered data is correct and the action is allowed as instructed by the specification file //a pull from the balance will be made. { if (checkIdAmount() == false) { return; } int index = manager.CheckId(int.Parse(txtId.Text)); if (index != -1) { int checker = 0; //diferent negativ total money amount as instructed at the specification file. if (manager[index].CheckClass() == "normal") { checker = -10000; } else if (manager[index].CheckClass() == "vip") { checker = -25000; } else { checker = -75000; } if ((manager[index].TotalAmount - double.Parse(txtSaveAmount.Text) + 1) > checker) { manager[index].Balance -= double.Parse(txtSaveAmount.Text); manager[index].TotalAmount -= double.Parse(txtSaveAmount.Text); MessageBox.Show("Pull was made on the total: " + txtSaveAmount.Text + "$ from account: " + txtId.Text); } else { MessageBox.Show("your acount's total amount will be lower then your allowed negative money"); } } else { System.Windows.Forms.MessageBox.Show("invalid Id has been entered"); } bool?isVip = manager[index].CheckVip(manager[index]); //checking if after the deposit the acount's total money amount is over 100,000. if (isVip == true) //if isnt Business acount and total money amount is over 100,000. { AcountProgram temp = manager[index]; for (int j = 0; j < manager[index].NumOfSavings.Count; j++) { temp.NumOfSavings[j] = new NewSavingAcount(manager[index].NumOfSavings[j].Amount, manager[index].NumOfSavings[j].ClosingDate); } manager[index] = new Vip(temp.FirstName, temp.LastName, temp.IdNum, temp.OpeningDate, temp.Balance, temp.GetImage()); for (int j = 0; j < temp.NumOfSavings.Count; j++) { manager[index].AddSaveProgramLoad(temp.NumOfSavings[j]); } } else if (isVip == false)//if isnt Business acount and total money amount is under 100,000. { AcountProgram temp = manager[index]; for (int j = 0; j < manager[index].NumOfSavings.Count; j++) { temp.NumOfSavings[j] = new NewSavingAcount(manager[index].NumOfSavings[j].Amount, manager[index].NumOfSavings[j].ClosingDate); } manager[index] = new AcountProgram(temp.FirstName, temp.LastName, temp.IdNum, temp.OpeningDate, temp.Balance, temp.GetImage()); for (int j = 0; j < temp.NumOfSavings.Count; j++) { manager[index].AddSaveProgramLoad(temp.NumOfSavings[j]); } } txtSaveAmount.Clear(); }
public override bool?CheckVip(AcountProgram acount) //checks if total money amount is over ,so the program will know if a transferation //between normal acount to vip is needed. { return(base.CheckVip(acount)); }
public override bool?CheckVip(AcountProgram acount) //returns null becouse it isnt normal nor a VIP acount. { return(null); }
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(); } }