Пример #1
0
 private void button2_Click(object sender, EventArgs e)
 {
     if (newSO != null)
     {
         int prid = Convert.ToInt32(comboBox2.SelectedValue);
         var q    = db.Products.Where(p => p.Product_ID == prid).FirstOrDefault();
         var q1   = db.Supplier_Order_Line.Where(sol => sol.Product_ID == prid && sol.Supplier_Order_Id == newSO.Supplier_Order_Id).FirstOrDefault();
         if (newSOL == null)
         {
             newSOL = new Supplier_Order_Line()
             {
                 Supplier_Order_Id = newSO.Supplier_Order_Id,
                 Product_ID        = Convert.ToInt32(comboBox2.SelectedValue),
                 Quantity          = Convert.ToInt32(numericUpDown1.Value)
             };
             db.Supplier_Order_Line.Add(newSOL);
             db.SaveChanges();
             var q2 = db.Supplier_Order.Where(x => x.Supplier_Order_Id == newSO.Supplier_Order_Id).First();
             dataGridView1.DataSource = db.GetSOL(newSO.Supplier_Order_Id).Where(x => x.SO_Number == q2.SO_Number).ToList();
         }
         else
         {
             var q3 = db.Supplier_Order.Where(x => x.Supplier_Order_Id == newSO.Supplier_Order_Id).First();
             if (q1 == null)
             {
                 newSOL = new Supplier_Order_Line()
                 {
                     Supplier_Order_Id = newSO.Supplier_Order_Id,
                     Product_ID        = Convert.ToInt32(comboBox2.SelectedValue),
                     Quantity          = Convert.ToInt32(numericUpDown1.Value)
                 };
                 db.Supplier_Order_Line.Add(newSOL);
                 //q.Available_Quantity -= Convert.ToInt32(numericUpDown1.Value);
                 db.SaveChanges();
                 dataGridView1.DataSource = db.GetSOL(newSO.Supplier_Order_Id).Where(x => x.SO_Number == q3.SO_Number).ToList();
             }
             else
             {
                 var q4 = db.Supplier_Order_Line.Where(sol => sol.Supplier_Order_Id == newSO.Supplier_Order_Id && sol.Supplier_Order_Line_ID == q1.Supplier_Order_Line_ID).
                          FirstOrDefault();
                 q4.Quantity += Convert.ToInt32(numericUpDown1.Value);
                 //q.Available_Quantity -= Convert.ToInt32(numericUpDown1.Value);
                 db.SaveChanges();
                 dataGridView1.DataSource = db.GetSOL(newSO.Supplier_Order_Id).Where(x => x.SO_Number == q3.SO_Number).ToList();
             }
         }
     }
 }
Пример #2
0
        private void button4_Click(object sender, EventArgs e)
        {
            try
            {
                var q1 = db.Client_Purchase_Order.Where(c => c.Supplier_Order_Id == null)
                         .Select(c => c.Client_Purchase_Id).ToList();

                var q = db.Client_Purchase_Order_Line.OrderBy(c => c.Product_ID).GroupBy(c => c.Product_ID).
                        Select(s => new { Client_Purchase_Order_Line = s.Key, totalquantity = s.Sum(r => r.Quantity), }).ToList();
                var q2 = db.GetTotalQty().ToList();

                if (MessageBox.Show("Are you sure you want to place order?", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    if (q2.FirstOrDefault() != null)
                    {
                        addNewSO();

                        foreach (var item in q2)
                        {
                            newSOL = new Supplier_Order_Line()
                            {
                                Supplier_Order_Id = newSO.Supplier_Order_Id,
                                Product_ID        = item.Product_ID,
                                Quantity          = Convert.ToInt32(item.Total_Quantity)
                            };
                            db.Supplier_Order_Line.Add(newSOL);
                        }
                        foreach (var item in q1)
                        {
                            Client_Purchase_Order xpo = db.Client_Purchase_Order.Single(po => po.Client_Purchase_Id == item);
                            xpo.Supplier_Order_Id = newSO.Supplier_Order_Id;
                        }
                        db.SaveChanges();
                        dataGridView1.DataSource = db.GetSOL(newSO.Supplier_Order_Id).ToList();
                    }
                    else
                    {
                        MessageBox.Show("There are no client orders to be added");
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }