// get sell quantity of each product
        public int getSellQuantityOfEachProduct(tblHangHoa product, DateTime dateStart, DateTime dateEnd)
        {
            int sellQuantity = Convert.ToInt32(BLL_REPORT.Instance.getListInvoiceDetail(dateStart, dateEnd).Where(
                                                   p => p.MaHangHoa == product.MaHangHoa).Sum(p => p.SoLuong));

            return(sellQuantity);
        }
        // get sell money of each product
        public double getSellMoneyOfEachProduct(tblHangHoa product, DateTime dateStart, DateTime dateEnd)
        {
            double sellMoney = Convert.ToDouble(BLL_REPORT.Instance.getListInvoiceDetail(dateStart, dateEnd).Where(
                                                    p => p.MaHangHoa == product.MaHangHoa).Sum(p => p.TongTien));

            return(sellMoney);
        }
        // delete product
        public void FuncDeleteProduct(List <string> listIdProduct)
        {
            var product = new tblHangHoa();

            foreach (string idProduct in listIdProduct)
            {
                product = db.tblHangHoas.Find(idProduct);
                db.tblHangHoas.Remove(product);
                db.SaveChanges();
            }
        }
        // edit product
        public void FuncEditProduct(tblHangHoa _product)
        {
            var product = db.tblHangHoas.Find(_product.MaHangHoa);

            product.TenHangHoa    = _product.TenHangHoa;
            product.SoLuong       = _product.SoLuong;
            product.GiaBan        = _product.GiaBan;
            product.GiaNhap       = _product.GiaNhap;
            product.MaLoaiHangHoa = _product.MaLoaiHangHoa;
            product.MaNhaSanXuat  = _product.MaNhaSanXuat;
            product.MoTa          = _product.MoTa;
            product.HinhAnh       = _product.HinhAnh;
            db.SaveChanges();
        }
Example #5
0
        // save
        private void btnSAVE_Click(object sender, EventArgs e)
        {
            tblHangHoa product = new tblHangHoa();

            product.MaHangHoa     = txtID_PRODUCT.Text.Trim();
            product.TenHangHoa    = txtNAME_PRODUCT.Text.Trim();
            product.SoLuong       = Convert.ToInt32(txtQUANTITY.Text.Trim());
            product.GiaBan        = Convert.ToDouble(txtSALE.Text.Trim());
            product.GiaNhap       = Convert.ToDouble(txtBUY.Text.Trim());
            product.MoTa          = txtDESCRIBE.Text;
            product.MaLoaiHangHoa = ((CBBItem)cbbTYPE_OF_PRODUCT.SelectedItem).VALUE;
            product.MaNhaSanXuat  = ((CBBItem)cbbPRODUCERs.SelectedItem).VALUE;
            product.HinhAnh       = images;
            if (String.IsNullOrEmpty(product.TenHangHoa))
            {
                MessageBox.Show("Tên hàng hóa trống!", "Lỗi nhập thiếu thông tin", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Disable(true);
            }
            else
            {
                if (isAdd)
                {
                    BLL_PRODUCT.Instance.FuncAddNewProduct(product); // add new product
                    MessageBox.Show("Thêm hàng hóa thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    Disable(false);
                    LoadData();
                }
                else
                {
                    BLL_PRODUCT.Instance.FuncEditProduct(product); // edit product
                    MessageBox.Show("Sửa hàng hóa thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    Disable(false);
                    LoadData();
                }
            }
        }
 // add new product
 public void FuncAddNewProduct(tblHangHoa product)
 {
     db.tblHangHoas.Add(product);
     db.SaveChanges();
 }
Example #7
0
        private void btnSAVE_Click(object sender, EventArgs e)
        {
            byte[]       images  = null;
            FileStream   fStream = new FileStream(imageLocation, FileMode.Open, FileAccess.Read);
            BinaryReader bReader = new BinaryReader(fStream);

            images = bReader.ReadBytes((int)fStream.Length);
            SALEMANAGEMENT_DB DB      = new SALEMANAGEMENT_DB();
            tblHangHoa        HANGHOA = new tblHangHoa();

            HANGHOA.MaHangHoa     = txtID_PRODUCT.Text;
            HANGHOA.TenHangHoa    = txtNAME_PRODUCT.Text;
            HANGHOA.SoLuong       = Convert.ToInt32(txtQUANTITY.Text);
            HANGHOA.GiaBan        = Convert.ToDouble(txtSALE.Text);
            HANGHOA.GiaNhap       = Convert.ToDouble(txtBUY.Text);
            HANGHOA.MoTa          = txtDESCRIBE.Text;
            HANGHOA.MaLoaiHangHoa = ((CBBItem)cbbTYPE_OF_PRODUCT.SelectedItem).VALUE;
            HANGHOA.MaNhaCungCap  = ((CBBItem)cbbSUPPLIERs.SelectedItem).VALUE;
            HANGHOA.MaNhaSanXuat  = ((CBBItem)cbbPRODUCERs.SelectedItem).VALUE;
            HANGHOA.HinhAnh       = images;
            if (string.IsNullOrEmpty(txtID_PRODUCT.Text) || string.IsNullOrEmpty(txtNAME_PRODUCT.Text) || string.IsNullOrEmpty(txtQUANTITY.Text) ||
                string.IsNullOrEmpty(txtBUY.Text) || string.IsNullOrEmpty(txtSALE.Text))
            {
                MessageBox.Show("Vui lòng nhập đầy đủ thông tin hàng hóa", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                disable(true);
            }
            else
            {
                if (isAdd)
                {
                    try
                    {
                        DB.tblHangHoas.Add(HANGHOA);
                        DB.SaveChanges();
                        MessageBox.Show("Thêm hàng hóa thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        disable(false);
                        ShowProduct();
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Mã số hàng hóa bị trùng. Vui lòng nhập mã khác", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        disable(true);
                    }
                }
                else
                {
                    var GETITEM = DB.tblHangHoas.Find(HANGHOA.MaHangHoa);
                    GETITEM.TenHangHoa    = HANGHOA.TenHangHoa;
                    GETITEM.SoLuong       = HANGHOA.SoLuong;
                    GETITEM.GiaBan        = HANGHOA.GiaBan;
                    GETITEM.GiaNhap       = HANGHOA.GiaNhap;
                    GETITEM.MaLoaiHangHoa = HANGHOA.MaLoaiHangHoa;
                    GETITEM.MaNhaCungCap  = HANGHOA.MaNhaCungCap;
                    GETITEM.MaNhaSanXuat  = HANGHOA.MaNhaSanXuat;
                    GETITEM.HinhAnh       = HANGHOA.HinhAnh;
                    DB.SaveChanges();
                    MessageBox.Show("Sửa hàng hóa thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    disable(false);
                    ShowProduct();
                }
            }
        }