Пример #1
0
        private void btnAddSaveProgram_Click(object sender, RoutedEventArgs e)
        //if the information that have been input by the user is valid and if it is allowed to that client to open a new saving program
        //then a new saving program is created.
        {
            if (checkIdAmount() == false)//validates that the entered Id does exist in the data base.
            {
                return;
            }

            if (DpClosingDate.SelectedDate == null)
            {
                MessageBox.Show("invalid closing date");
                return;
            }

            closingDate = DpClosingDate.SelectedDate.Value;
            NewSavingAcount saveAcount = new NewSavingAcount(double.Parse(txtSaveAmount.Text), closingDate);
            int             index      = manager.CheckId(int.Parse(txtId.Text));

            if (index == -1)
            {
                MessageBox.Show("Id is invalide");
                return;
            }

            if (int.Parse(txtSaveAmount.Text) > manager[index].Balance)
            {
                MessageBox.Show("There is not enough money");
                return;
            }

            manager[index].AddSaveProgram(saveAcount);
            manager[index].Balance -= double.Parse(txtSaveAmount.Text);
            txtSaveAmount.Clear();
        }
Пример #2
0
 public virtual void AddSaveProgramLoad(NewSavingAcount newsaving)
 //adding a saving program without the message that was shown in the previous function.
 {
     if (savingPrograms.Count < 1)
     {
         savingPrograms.Add(newsaving);
         totalAmount += newsaving.Amount;
     }
 }
Пример #3
0
 public virtual void AddSaveProgram(NewSavingAcount newsaving)
 //in this class only 1 saving program is allowed
 //and therefor only one can be added.
 //adding a saving program and displays the apropriate message.
 {
     if (savingPrograms.Count < 1)
     {
         savingPrograms.Add(newsaving);
         MessageBox.Show("Save acount has been added");
         totalAmount += newsaving.Amount;
     }
     else
     {
         MessageBox.Show("Error!! Only one saving program is allowed");
     }
 }
Пример #4
0
 public override void AddSaveProgramLoad(NewSavingAcount newsaving)
 //adding a saving program without the message that was shown in the previous function.
 {
     savingPrograms.Add(newsaving);
 }
Пример #5
0
 public override void AddSaveProgram(NewSavingAcount newsaving)
 //adding a saving program and displays the apropriate message.
 {
     savingPrograms.Add(newsaving);
     MessageBox.Show("Save acount has been added");
 }
Пример #6
0
        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();
            }
        }