예제 #1
0
        private void btn_takecredit_Click(object sender, EventArgs e)
        {
            using (BankAppDbContext bc = new BankAppDbContext())
            {
                try
                {
                    Customer customer = new Customer()
                    {
                        Name           = txbx_name.Text,
                        Surname        = txbx_surname.Text,
                        PassportNumber = Convert.ToInt32(txbx_passportnumber.Text)
                    };

                    bc.Customers.Add(customer);
                    bc.SaveChanges();

                    TakeCreditForm takeCreditForm = new TakeCreditForm();
                    takeCreditForm.ShowDialog();
                }
                catch (DbEntityValidationException exp)
                {
                    foreach (var item in exp.EntityValidationErrors)
                    {
                        label4.Text = "";
                        foreach (var i in item.ValidationErrors)
                        {
                            label4.Text += i.ErrorMessage + "\n";
                        }
                    }
                }
            }
        }
 private void btb_addcredit_Click(object sender, EventArgs e)
 {
     using (BankAppDbContext bn = new BankAppDbContext())
     {
         try
         {
             if (txbx_amount.Text != null)
             {
                 Credit credit = new Credit()
                 {
                     Amount     = Convert.ToDecimal(txbx_amount.Text),
                     GivenDate  = dateTimePicker1.Value,
                     CustomerId = bn.Customers.ToList().Last().Id
                 };
                 bn.Credits.Add(credit);
                 bn.SaveChanges();
                 ShowAllForm showAllForm = new ShowAllForm();
                 showAllForm.ShowDialog();
             }
         }
         catch (DbEntityValidationException exp)
         {
             foreach (var item in exp.EntityValidationErrors)
             {
                 foreach (var i in item.ValidationErrors)
                 {
                     label2.Text += i.ErrorMessage + "\n";
                 }
             }
         }
     }
 }