예제 #1
0
        private void btn_save_Click(object sender, EventArgs e)
        {
            using (idkModel idk = new idkModel())
            {
                using (DbContextTransaction transaction = idk.Database.BeginTransaction())
                {
                    try
                    {
                        Order o;

                        if (Id.HasValue)
                        {
                            o = (from odi in idk.Orders
                                 join pd in idk.OrderItems on odi.Id equals pd.OrderId
                                 where pd.Id == Id
                                 select odi).FirstOrDefault();
                        }
                        else
                        {
                            o = new Order();

                            o.OrderDate   = DateTime.Now;
                            o.OrderNumber = numericUpDown2.Text;
                        }
                        o.CustomerId = (from ct in idk.Customers
                                        where ct.FirstName == comboBox1_customer.Text
                                        select ct.Id).FirstOrDefault();
                        o.OrderDate   = dateTimePicker1.Value;
                        o.OrderNumber = numericUpDown2.Text;

                        o.TotalAmount = numericUpDown1.Value;
                        if (!Id.HasValue)
                        {
                            idk.Orders.Add(o);
                        }

                        idk.Orders.Add(o);
                        idk.SaveChanges();
                        transaction.Commit();
                        MessageBox.Show("ოპერაცია წარმატებით დასრულდა", "წარმატება", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    catch (Exception ee)
                    {
                        //transaction.Rollback();
                        MessageBox.Show(ee.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    finally
                    {
                        this.Close();
                    }
                }
            }
        }
        private void button_add_Click(object sender, EventArgs e)
        {
            using (idkModel idk = new idkModel())
            {
                try
                {
                    Supplier sp;
                    if (yn.HasValue)
                    {
                        sp = (from ep in idk.Suppliers
                              where ep.Id == yn
                              select ep).FirstOrDefault();
                    }
                    else
                    {
                        sp = new Supplier();
                    }
                    sp.CompanyName  = textBox_name.Text;
                    sp.ContactName  = textBox_contName.Text;
                    sp.ContactTitle = textBox_title.Text;
                    sp.Country      = textBox1_country.Text;
                    sp.City         = textBox2_city.Text;
                    sp.Phone        = textBox_phone.Text;
                    sp.Fax          = textBox_fax.Text;
                    if (!yn.HasValue)
                    {
                        idk.Suppliers.Add(sp);
                    }

                    idk.Suppliers.Add(sp);
                    idk.SaveChanges();
                    MessageBox.Show("ოპერაცია წარმატებით დასრულდა", "წარმატება", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch (Exception ee)
                {
                    MessageBox.Show(ee.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                finally
                {
                    this.Close();
                }
            }
        }
예제 #3
0
 private void button_add_Click(object sender, EventArgs e)
 {
     using (idkModel idk = new idkModel())
     {
         try
         {
             Product pd;
             if (Id.HasValue)
             {
                 pd = (from p in idk.Products
                       join s in idk.Suppliers on p.SupplierId equals s.Id
                       where p.Id == Id
                       select p).FirstOrDefault();
             }
             else
             {
                 pd = new Product();
             }
             pd.ProductName = textBox_name.Text;
             pd.SupplierId  = (from ct in idk.Suppliers
                               where ct.CompanyName == comboBox_supplier.Text
                               select ct.Id).FirstOrDefault();
             pd.UnitPrice      = numericUpDown_price.Value;
             pd.Package        = textBox_package.Text;
             pd.IsDiscontinued = checkBox_discontinued.Checked;
             if (!Id.HasValue)
             {
                 idk.Products.Add(pd);
             }
             idk.Products.Add(pd);
             idk.SaveChanges();
             MessageBox.Show("ოპერაცია წარმატებით დასრულდა", "წარმატება", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
         catch (Exception ee)
         {
             MessageBox.Show(ee.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
         finally
         {
             this.Close();
         }
     }
 }
예제 #4
0
 private void button1_Click(object sender, EventArgs e)
 {
     try
     {
         using (idkModel idk = new idkModel())
         {
             Customer c;
             if (Id.HasValue)
             {
                 c = (from cc in idk.Customers
                      where cc.Id == Id
                      select cc).FirstOrDefault();
             }
             else
             {
                 c = new Customer();
             }
             c.FirstName = txtBox_fn.Text;
             c.LastName  = txtBox_ln.Text;
             c.City      = txtBox_ct.Text;
             c.Country   = txtBox_cntry.Text;
             c.Phone     = txtBox_ph.Text;
             if (!Id.HasValue)
             {
                 idk.Customers.Add(c);
             }
             idk.Customers.Add(c);
             idk.SaveChanges();
         }
         MessageBox.Show("ოპერაცია წარმატებით დასრულდა", "წარმატება", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "მოხდა შეცდომა", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     finally
     {
         this.Close();
     }
 }