Ejemplo n.º 1
0
 private void buttonAddClient_Click(object sender, EventArgs e)
 {
     if (textBoxName.Text.Length == 0 || textBoxDirector.Text.Length == 0)
     {
         MessageBox.Show("Вы ввели не все данные!");
         return;
     }
     if (!MailIsValid(textBoxEmail.Text) && textBoxEmail.Text.Length != 0)
     {
         MessageBox.Show("Электронная почта введена некорректно!");
         return;
     }
     if (client == null)
     {
         Client client = new Client(textBoxDirector.Text, textBoxINN.Text, textBoxName.Text, new BankMapper().Get(comboBoxBank.Text),
                                    textBoxNumbOfTel.Text, textBoxEmail.Text, textBoxBill.Text, textBoxKPP.Text, textBoxOKTMO.Text, textBoxOKATO.Text,
                                    textBoxOGRN.Text, textBoxAddress.Text, textBoxFactAddress.Text);
         try
         {
             client = new ClientMapper().Insert(client);
         }
         catch (Exception ex)
         {
             MessageBox.Show("При добавлении данных произошла ошибка - " +
                             $"{ex.Message}");
             client = null;
             return;
         }
         if (formAddWayBill != null && formAddWayBill.Visible)
         {
             if (formAddWayBill.insWayBill != null)
             {
                 formAddWayBill.insWayBill.Client = client;
             }
             else
             {
                 formAddWayBill.wayBill.Client = client;
             }
             formAddWayBill.textBoxClient.Text = client.Name;
             this.Close();
             return;
         }
         mainForm.dataGridView.ClearSelection();
     }
     else
     {
         ClientMapper cm = new ClientMapper();
         client.Director = textBoxDirector.Text;
         client.INN      = textBoxINN.Text;
         client.Name     = textBoxName.Text;
         try
         {
             client.Bank = new BankMapper().Get(comboBoxBank.SelectedValue.ToString());
         }
         catch (NullReferenceException ex) { }
         client.PhoneNumber = textBoxNumbOfTel.Text;
         client.Email       = textBoxEmail.Text;
         client.Bill        = textBoxBill.Text;
         client.KPP         = textBoxKPP.Text;
         client.OKTMO       = textBoxOKTMO.Text;
         client.OKATO       = textBoxOKATO.Text;
         client.OGRN        = textBoxOGRN.Text;
         client.Address     = textBoxAddress.Text;
         client.FactAddress = textBoxFactAddress.Text;
         try
         {
             cm.Update(client);
         }
         catch (Exception ex)
         {
             MessageBox.Show("При добавлении данных произошла ошибка - " +
                             $"{ex.Message}");
             return;
         }
     }
     Form1.AddListClientInGrid(mainForm.dataGridView);
     this.Close();
     mainForm.dataGridView.ClearSelection();
     mainForm.dataGridView.Rows[Form1.SelectIndex].Selected = true;
 }