Exemplo n.º 1
0
 private void btxoa_Click(object sender, EventArgs e)
 {
     if (madouong == 0)
     {
         MessageBox.Show("Yêu cầu chọn đồ uống cần xóa !");
         return;
     }
     if (MessageBox.Show(this, "Bạn có muốn xóa đồ uống này không ?", "Xóa", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
     {
         using (DatabaseQLTSEntities quanli = new DatabaseQLTSEntities())
         {
             CTHoaDon ct_hd = quanli.CTHoaDons.FirstOrDefault(p => p.IdDoUong == madouong);
             if (ct_hd != null)
             {
                 MessageBox.Show(this, "Dữ liệu đang sử dụng không thể xóa !", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 return;
             }
             List <CTDoUong> ds_chitiet = quanli.CTDoUongs.Where(p => p.IdDoUong == madouong).ToList();
             foreach (var item in ds_chitiet)
             {
                 quanli.CTDoUongs.Remove(item);
                 quanli.SaveChanges();
             }
             DoUong du = quanli.DoUongs.FirstOrDefault(p => p.Id == madouong);
             quanli.DoUongs.Remove(du);
             quanli.SaveChanges();
             reset();
             Napdatalist();
         }
     }
 }
Exemplo n.º 2
0
 private void dgvloai_CellClick(object sender, DataGridViewCellEventArgs e)
 {
     btluu.Enabled     = true;
     txtloai.Text      = dgvloai.Rows[e.RowIndex].Cells["tenloai"].Value.ToString();
     txtloai.ForeColor = Color.Black;
     mloai             = int.Parse(dgvloai.Rows[e.RowIndex].Cells["maloai"].Value.ToString());
     if (e.ColumnIndex == 0)
     {
         if (MessageBox.Show(this, "Bạn có muốn xóa loại đồ uống này không ?", "Xóa", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
         {
             using (DatabaseQLTSEntities quanli = new DatabaseQLTSEntities())
             {
                 DoUong du = quanli.DoUongs.FirstOrDefault(p => p.IdLoai == mloai);
                 if (du != null)
                 {
                     MessageBox.Show(this, "Dữ liệu đang sử dụng không thể xóa !", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                     return;
                 }
                 LoaiDoUong loai = quanli.LoaiDoUongs.FirstOrDefault(p => p.IdLoai == mloai);
                 quanli.LoaiDoUongs.Remove(loai);
                 quanli.SaveChanges();
                 loadLoaiDU();
             }
         }
     }
 }
Exemplo n.º 3
0
 private void btsua_Click(object sender, EventArgs e)
 {
     if (hinhanh.Image == null)
     {
         errorMessage.Clear();
         errorMessage.SetError(hinhanh, "Bạn cần click vào chọn ảnh");
         return;
     }
     if (btthem.Text == "Thêm")
     {
         errorMessage.Clear();
         string ten = txtten.Text.Trim();
         if (string.IsNullOrEmpty(ten))
         {
             errorMessage.SetError(txtten, "Bạn cần nhập tên đồ uống !");
             txtten.Focus();
             return;
         }
         if (cbloai.SelectedItem == null)
         {
             errorMessage.Clear();
             errorMessage.SetError(cbloai, "Bạn cần chọn loại đồ uống!");
         }
         ThemDoUong();
     }
     else
     {
         using (DatabaseQLTSEntities quanli = new DatabaseQLTSEntities())
         {
             int    maloai = quanli.LoaiDoUongs.FirstOrDefault(p => p.TenLoai == cbloai.Text).IdLoai;
             DoUong du     = quanli.DoUongs.FirstOrDefault(p => p.Id == madouong);
             du.IdLoai    = maloai;
             du.TenDoUong = txtten.Text;
             MemoryStream me     = new MemoryStream();
             byte[]       images = null;
             if (img != "")
             {
                 FileStream   stream = new FileStream(img, FileMode.Open, FileAccess.Read);
                 BinaryReader brs    = new BinaryReader(stream);
                 images     = brs.ReadBytes((int)stream.Length);
                 du.HinhAnh = images;
             }
             if (cbsize.Text != "")
             {
                 quanli.updateCTdu(du.Id, cbsize.SelectedItem.ToString(), int.Parse(txtgia.Text));
             }
             quanli.SaveChanges();
             Napdatalist();
             MessageBox.Show(this, "Đã Lưu !", "Lưu", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
     }
 }
Exemplo n.º 4
0
 public void ThemDoUong()
 {
     try
     {
         if (img.Equals(""))
         {
             MessageBox.Show("Yêu cầu click vô image chọn ảnh!!! ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
             return;
         }
         MemoryStream me     = new MemoryStream();
         byte[]       images = null;
         FileStream   stream = new FileStream(img, FileMode.Open, FileAccess.Read);
         BinaryReader brs    = new BinaryReader(stream);
         images = brs.ReadBytes((int)stream.Length);
         using (DatabaseQLTSEntities quanli = new DatabaseQLTSEntities())
         {
             int    maloai = quanli.LoaiDoUongs.FirstOrDefault(p => p.TenLoai == cbloai.Text).IdLoai;
             DoUong du     = new DoUong();
             du.IdLoai    = maloai;
             du.TenDoUong = txtten.Text;
             du.HinhAnh   = images;
             quanli.DoUongs.Add(du);
             quanli.SaveChanges();
         }
         MessageBox.Show(this, "Đã Lưu !", "Lưu", MessageBoxButtons.OK, MessageBoxIcon.Information);
         Napdatalist();
         ds_douong.Clear();
         using (DatabaseQLTSEntities quanli = new DatabaseQLTSEntities())
         {
             ds_douong = quanli.DoUongs.ToList();
         }
         reset();
     }
     catch (Exception)
     {
         MessageBox.Show("Không thể thêm , vui lòng kiểm tra lại!! ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
         return;
     }
 }