Exemple #1
0
 private void OrdersGV_CellContentClick(object sender, DataGridViewCellEventArgs e)
 {
     if (e.ColumnIndex == 4)
     {
         this.OrdersGV.CommitEdit(DataGridViewDataErrorContexts.Commit);
         string s       = OrdersGV[0, e.RowIndex].Value.ToString(),
                t       = OrdersGV[1, e.RowIndex].Value.ToString(),
                u       = OrdersGV[2, e.RowIndex].Value.ToString();
         Entities   ent = new Entities();
         ORDER_FOOD fo  = (from x in ent.ORDER_FOOD
                           where x.FOOD_NAME == s &&
                           x.RESTAURANT_NAME == t &&
                           x.RESTAURANT_LOCATION == u &&
                           x.ORDER_ID == ordID
                           select x).FirstOrDefault();
         if (OrdersGV[4, e.RowIndex].Value.ToString() == "true")
         {
             fo.BOUGHT = "y";
         }
         else
         {
             fo.BOUGHT = "n";
         }
         ent.SaveChanges();
         enableConfirmBtn();
     }
 }
        private void button2_Click(object sender, EventArgs e)
        {
            Entities   ent  = new Entities();
            ORDER_FOOD ordf = new ORDER_FOOD();

            ordf.BOUGHT               = "n";
            ordf.FOOD_NAME            = name.Text;
            ordf.NO_OF_ITEMS_PER_FOOD = Convert.ToInt32(numericUpDown1.Value);
            ordf.ORDER_ID             = Helper.currentOrderId;
            ordf.RESTAURANT_LOCATION  = resl.Text;
            ordf.RESTAURANT_NAME      = resn.Text;
            if (ent.ORDER_FOOD.Where(x => x.ORDER_ID == Helper.currentOrderId && x.RESTAURANT_NAME == resn.Text &&
                                     x.RESTAURANT_LOCATION == resl.Text && x.FOOD_NAME == this.name.Text).Count() > 0)
            {
                ordf.NO_OF_ITEMS_PER_FOOD += ent.ORDER_FOOD.Where(x => x.ORDER_ID == Helper.currentOrderId && x.RESTAURANT_NAME == resn.Text &&
                                                                  x.RESTAURANT_LOCATION == resl.Text && x.FOOD_NAME == this.name.Text).First().NO_OF_ITEMS_PER_FOOD;
            }
            ent.ORDER_FOOD.AddOrUpdate(ordf);
            ent.SaveChanges();
        }