Exemple #1
0
        private void buttonUpdateProduct_Click(object sender, EventArgs e)
        {
            ReceiveVoucherInfo voucherInfo = new ReceiveVoucherInfo();
            string             idVoucher = reVoucherSelected.ID;
            string             idProduct, nameProduct, note;
            int quantityInput, inputPrice, outputPrice, quantityOutput;


            if (rowSeletedObj != null)
            {
                FormUpdateReceiveVoucherInfo f = new FormUpdateReceiveVoucherInfo();
                //send data to form f
                f.reVoucherInfoSelected = rowSeletedObj;
                f.productHaveNotChosenAndThisSelectedProduct = listProductOutOfReceiveVoucher;
                f.ShowDialog();

                //get data update from form f
                var infoAfterUpdate = f.infoUpdate;
                if (infoAfterUpdate != null)
                {
                    reVoucherInfos.Remove(rowSeletedObj);
                    reVoucherInfos.Add(infoAfterUpdate);
                    rowSeletedObj = null;

                    LoadDtgvVoucherInfo();
                }
            }
            else
            {
                MessageBox.Show("Hãy chọn thông tin bạn muốn sửa trong bảng");
            }
        }
Exemple #2
0
        private void buttonDeleteProduct_Click(object sender, EventArgs e)
        {
            //if still have data row on dtgv
            if (rowSeletedObj != null)
            {
                //you can't delete product  if it's quantityOutput > 0 (has been sold)
                if (rowSeletedObj.QuantityOutput == 0)
                {
                    string  idProduct      = rowSeletedObj.IDProduct;
                    Product productRemoved = ProductDAO.Instance.GetByID(idProduct);

                    //before delete product in datagridview, we must add that product to comboboxProduct
                    List <Product> productsCombobox = comboBoxProductID.Items.Cast <Product>().ToList();
                    productsCombobox.Add(productRemoved);

                    LoadProductCombobox(productsCombobox);

                    reVoucherInfos.Remove(rowSeletedObj);
                    LoadDtgvVoucherInfo();

                    rowSeletedObj = null;
                }
                else
                {
                    MessageBox.Show("Bạn không thể xóa sản phẩm đã được bán");
                }
            }
        }
Exemple #3
0
 private void dataGridViewProduct_CellClick(object sender, DataGridViewCellEventArgs e)
 {
     if (e.RowIndex >= 0 && e.RowIndex < dtgvProduct.RowCount)
     {
         rowSeletedObj = dtgvProduct.Rows[e.RowIndex].DataBoundItem as ReceiveVoucherInfoDTO;
     }
     else
     {
         rowSeletedObj = null;
     }
 }
Exemple #4
0
        public int Inser(ReceiveVoucherInfoDTO infoes)
        {
            int rowAffected = 0;

            if (infoes != null)
            {
                db.ReceiveVoucherInfoes.Add(dtoToEntity(infoes));

                rowAffected = db.SaveChanges();
            }
            return(rowAffected);
        }
Exemple #5
0
        public ReceiveVoucherInfo dtoToEntity(ReceiveVoucherInfoDTO dto)
        {
            ReceiveVoucherInfo info = new ReceiveVoucherInfo();

            info.IDReceiveVoucher = dto.IDReceiveVoucher;
            info.IDProduct        = dto.IDProduct;
            info.QuantityInput    = dto.QuantityInput;
            info.PriceInput       = dto.PriceInput;
            info.QuantityOutput   = dto.QuantityOutput;
            info.Note             = dto.Note;

            return(info);
        }
Exemple #6
0
        private void buttonOK_Click(object sender, EventArgs e)
        {
            var result = MessageBox.Show("Xác nhận thay đổi?", "Xác nhận", MessageBoxButtons.OKCancel);

            if (result == DialogResult.OK)
            {
                int rowAffected = 0;
                //step1: update receive voucher
                ReceiveVoucher voucherUpdate = new ReceiveVoucher();
                voucherUpdate.ID         = reVoucherSelected.ID;
                voucherUpdate.IDSupplier = (comboBoxIDSupplier.SelectedItem as Supplier).ID;
                voucherUpdate.Date       = dateTimePickerInputDate.Value;

                //ReceiveVoucherDAO.Instance.UpdateReceiveVoucher(voucherUpdate);

                //step2: update receive voucher infomation
                //step2.1: remove all product have quantityOutput = 0( not been sold)
                //step2.2: if product in dtgview has been sold, the only thing we can do is update it
                //step2.3: add product in dtgrview never be sold, add it to receive voucher

                //add new product info have quantity output = 0
                //or update if it's quantity output > 0

                for (int i = 0; i < dtgvProduct.RowCount; i++)
                {
                    ReceiveVoucherInfoDTO infoDTO = dtgvProduct.Rows[i].DataBoundItem as ReceiveVoucherInfoDTO;

                    ReceiveVoucherInfo voucherInfo = new ReceiveVoucherInfo();
                    voucherInfo.IDProduct        = infoDTO.IDProduct;
                    voucherInfo.IDReceiveVoucher = infoDTO.IDReceiveVoucher;
                    voucherInfo.QuantityInput    = infoDTO.QuantityInput;
                    voucherInfo.PriceInput       = infoDTO.PriceInput;
                    voucherInfo.QuantityOutput   = infoDTO.QuantityOutput;
                    voucherInfo.Note             = infoDTO.Note;

                    voucherUpdate.ReceiveVoucherInfoes.Add(voucherInfo);
                }

                rowAffected = ReceiveVoucherDAO.Instance.UpdateReceiveVoucher(voucherUpdate);
                if (rowAffected > 0)
                {
                    MessageBox.Show("Cập nhật thành công");
                }
                else
                {
                    MessageBox.Show("Không thành công");
                }
                this.Close();
            }
        }
Exemple #7
0
        private void buttonAddProduct_Click(object sender, EventArgs e)
        {
            //if there are at least one product on combobox
            if ((comboBoxProductID.SelectedItem as Product) != null)
            {
                string pID, pName, note, voucherID;
                int    inputQuantity, inputPrice;

                voucherID     = reVoucherSelected.ID;
                pID           = comboBoxProductID.Text;
                pName         = comboBoxProductName.Text;
                inputQuantity = (int)numericUpDownInputQuantity.Value;
                inputPrice    = (int)numericUpDownInputPrice.Value;
                note          = textBoxNote.Text;
                const int outputQuantity = 0;

                if (inputQuantity > 0)
                {
                    ReceiveVoucherInfoDTO info = new ReceiveVoucherInfoDTO();
                    info.IDProduct        = pID;
                    info.ProductName      = pName;
                    info.QuantityInput    = inputQuantity;
                    info.PriceInput       = inputPrice;
                    info.QuantityOutput   = outputQuantity;
                    info.Note             = note;
                    info.IDReceiveVoucher = voucherID;

                    reVoucherInfos.Add(info);

                    LoadDtgvVoucherInfo();
                }
                else
                {
                    MessageBox.Show("Bạn chưa nhập số lượng");
                }

                //after add good: remove id of that good from combobox (id good can't dupplication)
                //and clear textboxNote
                var products = comboBoxProductID.Items.Cast <Product>().ToList();
                products.RemoveAt(comboBoxProductID.SelectedIndex);
                textBoxNote.Clear();

                LoadProductCombobox(products);
            }
        }
Exemple #8
0
        public int UpdateReceiveVoucherInfo(ReceiveVoucherInfoDTO voucherInfo)
        {
            int    rowAffected = 0;
            string idProduct, idVoucher;

            idProduct = voucherInfo.IDProduct;
            idVoucher = voucherInfo.IDReceiveVoucher;

            ReceiveVoucherInfo voucherInfoUpdate = db.ReceiveVoucherInfoes.Find(idProduct, idVoucher);

            voucherInfoUpdate.PriceInput     = voucherInfo.PriceInput;
            voucherInfoUpdate.QuantityInput  = voucherInfo.QuantityInput;
            voucherInfoUpdate.QuantityOutput = voucherInfo.QuantityOutput;
            voucherInfoUpdate.Note           = voucherInfo.Note;

            rowAffected = db.SaveChanges();
            return(rowAffected);
        }
        private void buttonOK_Click(object sender, EventArgs e)
        {
            if (CheckQuantityInput())
            {
                string idProduct, note, productName, voucherID;
                int    quantityInput, priceInput, outputPrice, quantityOutput;

                voucherID      = reVoucherInfoSelected.IDReceiveVoucher;
                idProduct      = (comboBoxProductID.SelectedItem as Product).ID;
                productName    = (comboBoxProductName.SelectedItem as Product).Name;
                quantityInput  = (int)numericUpDownInputQuantity.Value;
                priceInput     = (int)numericUpDownInputPrice.Value;
                quantityOutput = int.Parse(labelQuantityOutput.Text);
                note           = textBoxNote.Text;

                infoUpdate = new ReceiveVoucherInfoDTO(idProduct, productName, voucherID, quantityInput, priceInput, quantityOutput, note);

                this.Close();
            }
            else
            {
                MessageBox.Show("Số lượng nhập phải lớn hơn hoặc bằng số lượng xuất");
            }
        }