Beispiel #1
0
        public ProductBillDto GetProductByBarcode(String barcode)
        {
            ProductBillDto dto = null;

            Product product = this.productRepository.GetByBarcode(barcode.Trim());

            if (product == null)
            {
                dto = new ProductBillDto(MessageContent.GET_PRODUCT_ERROR + "\r\n" + MessageContent.REQUIRE_REINPUT_FIELD);
                return(dto);
            }

            ProductDetail productDetail = this.productDetailRepository.GetProductDetailByProductIdAndMinExpidationDate(product.ProductId);

            if (productDetail == null)
            {
                dto = new ProductBillDto(MessageContent.GET_PRODUCT_ERROR + "\r\n" + MessageContent.REQUIRE_REINPUT_FIELD);
                return(dto);
            }

            dto = new ProductBillDto();

            dto.Id          = product.ProductId.ToString();
            dto.ProductName = product.Name;
            dto.Price       = productDetail.Price.ToString();
            dto.SellRate    = "0";
            dto.Unit        = product.Unit;
            dto.Message     = "";
            dto.Barcode     = product.Barcode;
            dto.DetailId    = productDetail.ProductDetailId.ToString();
            dto.ImageUrl    = Convert.ToBase64String(product.ImageUrl);
            return(dto);
        }
        // Thêm sản phẩm vừa chọn
        private void addProduct()
        {
            if ("".Equals(this.txtProductCode.Text.Trim()))
            {
                MessageBox.Show(MessageContent.PRODUCT_CODE_IS_EMPTY, MessageTitle.ADD_PRODUCT_ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if ("".Equals(this.txtQuantity.Text.Trim()))
            {
                MessageBox.Show(MessageContent.PRODUCT_QUANTITY_IS_EMPTY, MessageTitle.ADD_PRODUCT_ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            this.productBillDto.SellRate = this.txtSell.Text;
            this.productBillDto.Quantity = this.txtQuantity.Text;
            this.productBillDto.Index    = (this.productBillDtos.Count() + 1).ToString();
            this.productBillDtos.Add(this.productBillDto);


            this.dgvListProduct.Rows.Add(this.productBillDto.Index, this.productBillDto.Barcode, this.productBillDto.ProductName,
                                         this.productBillDto.Quantity, this.productBillDto.Price, this.productBillDto.SellRate, this.productBillDto.Unit,
                                         this.productBillDto.Total());

            //Console.WriteLine();
            int total = Convert.ToInt32(System.Text.RegularExpressions.Regex.Replace(this.productBillDto.Total(), "[^.0-9]", ""));

            this.lbTotal.Text = (Convert.ToInt32(System.Text.RegularExpressions.Regex.Replace(this.lbTotal.Text, "[^.0-9]", "")) + total)
                                .ToString("#,#", CultureInfo.InvariantCulture);

            this.productBillDto = null;

            this.deleteProduct();
        }
Beispiel #3
0
        public List <ProductBillDto> GetAllBillDetailByBill(int billId)
        {
            List <ProductBillDto> dtos = new List <ProductBillDto>();

            try
            {
                List <BillDetail> billDetails = billDetailRepository.GetByBill(billId).ToList();

                foreach (BillDetail db in billDetails)
                {
                    ProductBillDto dto = new ProductBillDto();
                    dto.Id       = db.BillDetailId.ToString();
                    dto.Quantity = db.Quantity.ToString();
                    dto.SellRate = "0";

                    int productDetailId = db.ProductDetailId;

                    ProductDetail productDetail = this.productDetailRepository.GetById(productDetailId);
                    dto.Barcode = productDetail.GeneratedCode;
                    dto.Price   = productDetail.Price.ToString("#,#", CultureInfo.InvariantCulture);

                    Product product = this.productRepository.GetById(productDetail.ProductId);
                    dto.ProductName = product.Name;
                    dto.Unit        = product.Unit;

                    dtos.Add(dto);
                }
            }
            catch
            {
                return(dtos);
            }

            return(dtos);
        }
        // Lấy thông tin sản phẩm
        private void setProductInfo()
        {
            string productCode = this.txtProductCode.Text.Trim();

            if ("".Equals(productCode))
            {
                return;
            }

            this.productBillDto = this.xuLyHoaDonService.GetProductByGeneratedCode(productCode);

            if (!"".Equals(this.productBillDto.Message.Trim()))
            {
                MessageBox.Show(this.productBillDto.Message, MessageTitle.GET_PRODUCT_ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.productBillDto = null;
                return;
            }

            this.txtProductName.Text = this.productBillDto.ProductName;
            this.txtPrice.Text       = this.productBillDto.Price;

            byte[] bytes = Convert.FromBase64String(this.productBillDto.ImageUrl);

            using (var ms = new MemoryStream(bytes, 0, bytes.Length))
            {
                this.ptbImage.Image    = Image.FromStream(ms, true);
                this.ptbImage.SizeMode = PictureBoxSizeMode.StretchImage;
            }

            this.txtQuantity.Focus();
        }
        public EditBillDetailForm(ProductBillDto productBillDto)
        {
            InitializeComponent();

            this.ProductBillDto = productBillDto;

            this.initForm();
        }
        private void formClosing(object sender, FormClosingEventArgs e)
        {
            ProductBillDto tempProductBillDto = this.editBillDetailForm.ProductBillDto;

            if (this.editBillDetailForm.FlagDelete)
            {
                this.productBillDtos.Remove(tempProductBillDto);
            }
            else
            {
                this.productBillDtos[Convert.ToInt32(tempProductBillDto.Index) - 1] = tempProductBillDto;
            }

            this.reloadDataGridView();

            this.editBillDetailForm = null;
        }
        private void doubleClickRow(object sender, EventArgs e)
        {
            if (this.productBillDtos.Count <= 0)
            {
                return;
            }

            if (this.dgvListProduct.SelectedRows.Count == 0)
            {
                return;
            }

            string index = this.dgvListProduct.SelectedRows[0].Cells[0].Value.ToString();

            ProductBillDto tempProductBillDto = this.productBillDtos[Convert.ToInt32(index) - 1];

            this.editBillDetailForm              = new EditBillDetailForm(tempProductBillDto);
            this.editBillDetailForm.FormClosing += new FormClosingEventHandler(formClosing);
            this.editBillDetailForm.Show();
        }
        // Cập nhật lại Form
        private void resetForm()
        {
            this.txtDate.Text         = DateTime.UtcNow.ToString("dd/MM/yyyy");
            this.txtPhoneNumber.Text  = "";
            this.txtCustomerName.Text = "";
            this.txtProductCode.Text  = "";
            this.txtQuantity.Text     = "1";
            this.txtProductName.Text  = "";
            this.txtSell.Text         = "";
            this.txtPrice.Text        = "";
            this.lbTotal.Text         = "0";

            this.flagEnterPhoneNumberField = false;
            this.flagEnterProductCodeField = false;
            this.FlagDelay = false;

            this.productBillDto     = null;
            this.customerBillDto    = null;
            this.editBillDetailForm = null;
            this.delayBillForm      = null;
            this.productBillDtos    = new List <ProductBillDto>();
            this.saleBillDtos       = new List <SaleBillDto>();

            this.setSellProgramForCombobox();
            this.dgvListProduct.Rows.Clear();

            try
            {
                this.txtBillCode.Text = this.xuLyHoaDonService.GenerateBillCode();
            }
            catch
            {
                MessageBox.Show(MessageContent.SYSTEM_ERROR, MessageTitle.SYSTEM_ERROR,
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }