private void btnSAVE_Click(object sender, EventArgs e) { tblLoaiHangHoa typeOfProduct = new tblLoaiHangHoa(); typeOfProduct.MaLoaiHangHoa = txtIdTypeOfProduct.Text.Trim(); typeOfProduct.TenLoaiHangHoa = txtNameTypeOfProduct.Text.Trim(); if (String.IsNullOrEmpty(typeOfProduct.MaLoaiHangHoa) && !String.IsNullOrEmpty(typeOfProduct.TenLoaiHangHoa)) { MessageBox.Show("Mã loại hàng hóa trống!", "Lỗi nhập thiếu thông tin", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (!String.IsNullOrEmpty(typeOfProduct.MaLoaiHangHoa) && String.IsNullOrEmpty(typeOfProduct.TenLoaiHangHoa)) { MessageBox.Show("Tên loại hàng hóa trống!", "Lỗi nhập thiếu thông tin", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (String.IsNullOrEmpty(typeOfProduct.MaLoaiHangHoa) && String.IsNullOrEmpty(typeOfProduct.TenLoaiHangHoa)) { MessageBox.Show("Mã và tên loại hàng hóa trống!", "Lỗi nhập thiếu thông tin", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { try { BLL_TYPEOFPRODUCT.Instance.FuncAddNewProduct(typeOfProduct); MessageBox.Show("Thêm loại hàng hóa thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); d(typeOfProduct.MaLoaiHangHoa, typeOfProduct.TenLoaiHangHoa); this.Close(); } catch (Exception) { MessageBox.Show("Mã loại hàng hóa đã tồn tại", "Lỗi trùng mã", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
// edit type of product public void FuncEditProduct(tblLoaiHangHoa _typeOfProduct) { var typeOfProduct = db.tblLoaiHangHoas.Find(_typeOfProduct.MaLoaiHangHoa); typeOfProduct.TenLoaiHangHoa = _typeOfProduct.TenLoaiHangHoa; db.SaveChanges(); }
private void btnSAVE_Click(object sender, EventArgs e) { SALEMANAGEMENT_DB DB = new SALEMANAGEMENT_DB(); tblLoaiHangHoa TYPEOFITEM = new tblLoaiHangHoa(); if (string.IsNullOrEmpty(txtID_TYPEOFITEM.Text) || string.IsNullOrEmpty(txtNAME_TYPEOFITEM.Text)) { MessageBox.Show("Vui lòng nhập đầy đủ thông tin", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { TYPEOFITEM.MaLoaiHangHoa = txtID_TYPEOFITEM.Text; TYPEOFITEM.TenLoaiHangHoa = txtNAME_TYPEOFITEM.Text; try { DB.tblLoaiHangHoas.Add(TYPEOFITEM); DB.SaveChanges(); d(TYPEOFITEM.MaLoaiHangHoa, TYPEOFITEM.TenLoaiHangHoa); this.Close(); } catch (Exception) { MessageBox.Show("Mã số bị trùng. Vui lòng nhập mã khác", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
// get sale money of each type of product public double getSellMoneyOfEachTypeOfProduct(tblLoaiHangHoa typeOfProduct, DateTime dateStart, DateTime dateEnd) { double sellMoney = Convert.ToDouble(BLL_REPORT.Instance.getListInvoiceDetail(dateStart, dateEnd).Where( p => p.tblHangHoa.MaLoaiHangHoa == typeOfProduct.MaLoaiHangHoa).Sum(p => p.TongTien)); return(sellMoney); }
// get sale quantity of each type of product public int getSellQuantityOfEachTypeOfProduct(tblLoaiHangHoa typeOfProduct, DateTime dateStart, DateTime dateEnd) { int sellQuantity = Convert.ToInt32(BLL_REPORT.Instance.getListInvoiceDetail(dateStart, dateEnd).Where( p => p.tblHangHoa.MaLoaiHangHoa == typeOfProduct.MaLoaiHangHoa).Sum(p => p.SoLuong)); return(sellQuantity); }
// get quantity of each type of product public int getQuantityOfEachTypeOfProduct(tblLoaiHangHoa typeOfProduct) { int quantity = Convert.ToInt32(db.tblHangHoas.Where( p => p.MaLoaiHangHoa == typeOfProduct.MaLoaiHangHoa).Sum(p => p.SoLuong)); return(quantity); }
// delete type of product public void FuncDeleteTypeProduct(List <string> listId) { var typeOfProduct = new tblLoaiHangHoa(); foreach (string idProduct in listId) { typeOfProduct = db.tblLoaiHangHoas.Find(idProduct); db.tblLoaiHangHoas.Remove(typeOfProduct); db.SaveChanges(); } }
// add new type of product public void FuncAddNewProduct(tblLoaiHangHoa typeOfProduct) { db.tblLoaiHangHoas.Add(typeOfProduct); db.SaveChanges(); }