Exemplo n.º 1
0
        private void DriverForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (deliveredFridgesTodayIdList.Count > 0)
            {
                string line = "";
                using (var connection = new FridgeBussinessEntities2())
                {
                    foreach (int id in deliveredFridgesTodayIdList)
                    {
                        Fridge temp = new Fridge();
                        temp  = connection.Fridge.Single(f => f.FridgeID == id);
                        line += "Klientas: " + temp.Customer + " | Saldytuvo nr: " + temp.FridgeID + "\n";
                    }
                }

                DialogResult result = MessageBox.Show("Pakeitimai:\n" + line + "Issaugoti?", "Warning",
                                                      MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning);
                if (result == DialogResult.Yes)
                {
                    using (var connection = new FridgeBussinessEntities2())
                    {
                        foreach (var fr in deliveredFridgesTodayIdList)
                        {
                            connection.Fridge.Single(f => f.FridgeID == fr).DeliveredAt = DateTime.Today;
                        }
                        connection.SaveChanges();
                    }
                }
                else if (result == DialogResult.Cancel)
                {
                    e.Cancel = true;
                }
            }
        }
Exemplo n.º 2
0
 private void SaveFridge(Fridge newFridge)
 {
     using (var conn = new FridgeBussinessEntities2())
     {
         if (fridgeID == -1)
         {
             conn.Fridge.Add(newFridge);
             conn.SaveChanges();
         }
         else
         {
             Fridge temp = conn.Fridge.FirstOrDefault(f => f.FridgeID == newFridge.FridgeID);
             conn.Fridge.Remove(temp);
             conn.Fridge.Add(newFridge);
             conn.SaveChanges();
         }
     }
 }
Exemplo n.º 3
0
        private void DeleteFridgeButton_Click(object sender, EventArgs e)
        {
            int fridgeid = (int)FridgeGridView.CurrentRow.Cells[0].Value;

            using (var con = new FridgeBussinessEntities2())
            {
                con.Fridge.Remove(con.Fridge.FirstOrDefault(f => f.FridgeID == fridgeid));
                con.SaveChanges();
            }
            Form1_Load(this, e);
        }
Exemplo n.º 4
0
 private void PlaceOrderButton_Click(object sender, EventArgs e)
 {
     if (CartGridView.Rows.Count > 0)
     {
         using (var connection = new FridgeBussinessEntities2())
         {
             foreach (DataRow row in shoppingCartTable.Rows)
             {
                 if (!string.IsNullOrEmpty(row["FridgeId"].ToString()))
                 {
                     int    frid      = (int)row["FridgeId"];
                     Fridge toReplace = connection.Fridge.First(f => f.FridgeID == frid);
                     connection.Fridge.Remove(toReplace);
                     connection.SaveChanges();
                     toReplace.Customer     = currentClient;
                     toReplace.DeliverUntil = DateTime.Today.AddDays(OrderToDeliverDayCount);
                     connection.Fridge.Add(toReplace);
                 }
                 else
                 {
                     connection.Fridge.Add(new Fridge
                     {
                         Volume   = (decimal)row["Volume"],
                         Customer = currentClient
                     });
                 }
                 connection.SaveChanges();
             }
         }
         MessageBox.Show("Order successful");
         Close();
     }
     else
     {
         MessageBox.Show("The cart is empty");
     }
 }