Exemple #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();
        }
        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();
        }