Esempio n. 1
0
        void lstMenu_Click(object sender, EventArgs e)
        {
            Sell_icreamEntities db = new Sell_icreamEntities();
            int  id   = (int)lstMenu.SelectedRows[0].Cells[0].Value;
            menu Menu = db.menus.Single(st => st.id == id);

            txtMa.Text  = Menu.id.ToString();
            txtTen.Text = Menu.Name.Trim();
            txtGia.Text = Menu.Price.ToString();
        }
Esempio n. 2
0
 private void btnLuu_Click(object sender, EventArgs e)
 {
     if (flag == 1)
     {
         try
         {
             Sell_icreamEntities db = new Sell_icreamEntities();
             menu Menu = new menu();
             Menu.id    = int.Parse(this.txtMa.Text);
             Menu.Name  = this.txtTen.Text;
             Menu.Price = int.Parse(this.txtGia.Text);
             db.menus.Add(Menu);
             db.SaveChanges();
             MessageBox.Show("Thêm món mới thành công!");
             this.frmManager_Load(null, null);
         }
         catch (Exception)
         { MessageBox.Show("Thêm món mới không thành công!"); }
     }
     if (flag == 2)
     {
         try
         {
             Sell_icreamEntities db = new Sell_icreamEntities();
             int  id   = (int)lstMenu.SelectedRows[0].Cells[0].Value;
             menu Menu = db.menus.Single(st => st.id == id);
             Menu.Name            = this.txtTen.Text;
             Menu.Price           = int.Parse(this.txtGia.Text);
             db.Entry(Menu).State = EntityState.Modified;
             db.SaveChanges();
             MessageBox.Show("Cập nhật thông tin món ăn thành công!");
             this.frmManager_Load(null, null);
             groupBox1.Enabled = true;
             lstMenu.Enabled   = true;
         }
         catch (Exception)
         {
             MessageBox.Show("Cập nhật thông tin món ăn không thành công!");
         }
     }
     lstMenu.Enabled   = true;
     groupBox2.Enabled = true;
     groupBox1.Enabled = false;
 }
Esempio n. 3
0
 private void btnOk_Click(object sender, EventArgs e)
 {
     //Add new item
     if (flag == 1)
     {
         Sell_icreamEntities db = new Sell_icreamEntities();
         menu   Menu            = (menu)cboName.SelectedItem;
         string stmp            = cboName.Text;
         try
         {
             Bill_Item tmp = db.Bill_Item.Single(st => st.C_Bill_id == ID && st.Item_id == Menu.id);
             int       dem = int.Parse(tmp.Quality) + (int)SL.Value;
             tmp.Quality         = dem.ToString();
             db.Entry(tmp).State = EntityState.Modified;
             db.SaveChanges();
             db.SaveChanges();
             LoadItem(ID);
         }
         catch (Exception)
         {
             Bill_Item item = new Bill_Item();
             item.C_Bill_id = ID;
             item.Item_id   = Menu.id;
             item.Quality   = SL.Value.ToString();
             item.Price     = Menu.Price;
             db.Bill_Item.Add(item);
             db.SaveChanges();
         }
         LoadItem(ID);
         flag = 0;
         btnThemSP.Enabled = true;
         btnXoa.Enabled    = true;
         btnSua.Enabled    = true;
     }
     //Edit 1 Item in Bill
     if (flag == 2)
     {
         Sell_icreamEntities db = new Sell_icreamEntities();
         try
         {
             Bill_Item bit = db.Bill_Item.Single(st => st.id == ID2);
             bit.Quality = SL.Value.ToString();
             DialogResult dr = MessageBox.Show("Bạn có chắc  chắn chỉnh sửa?", "Xác nhận", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
             if (dr == DialogResult.Yes)
             {
                 try
                 {
                     db.Entry(bit).State = EntityState.Modified;
                     db.SaveChanges();
                     MessageBox.Show("Cập nhật thành công!");
                     this.LoadItem(ID);
                 }
                 catch (Exception)
                 { MessageBox.Show("Chỉnh sửa không thành công! "); }
                 flag = 0;
                 btnThemSP.Enabled = true;
                 btnXoa.Enabled    = true;
                 btnSua.Enabled    = true;
                 btnHuy.Hide();
             }
             else
             {
                 return;
             }
         }
         catch (Exception)
         { MessageBox.Show("Vui lòng chọn lại món cần chỉnh sửa "); }
     }
 }