Exemple #1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtPlan.Text))
            {
                Ultils.TextControlNotNull(txtPlan, "Kế hoạch");
            }
            else
            {
                var receipt = new Receipt()
                {
                    ReceiptID = lblReceiptID.Text,
                    ReceiptDate = DateTime.Now,
                    TotalMoney = Convert.ToInt32(_total),
                    //Price = Convert.ToInt32(_price),
                    Active = true,
                    CreateBy = Program.CurrentUser.Username

                };

                try
                {
                    _receiptService.Add(receipt);
                    _logService.InsertLog(Program.CurrentUser.Username, "Nhập kho", this.Text);
                    foreach (Cart cart in _order.Carts)
                    {
                        InsertReceiptDetails(lblReceiptID.Text, cart.ProductId, cart.Quantity, cart.Price, cart.Total);
                        _inventoryService.InsertOrUpdateReceipt(cart.ProductId, cart.Quantity, lblReceiptID.Text, int.Parse(txtPlan.Text));
                    }
                    if (_order.Carts.Count > 0)
                    {
                        _order.Carts.Clear();
                    }

                    MessageBoxHelper.ShowMessageBoxInfo("Nhập hàng thành công!");
                    gridControlStockImport.DataSource = null;
                    ResetProductControls();
                    EnabledButtonSaveAndPrint(false);
                    // Tạo tiếp ID
                    lblReceiptID.Text = _receiptService.NextId();

                }
                catch (SqlException ex)
                {
                    MessageBoxHelper.ShowMessageBoxError(ex.Message);
                }
                catch (Exception ex)
                {
                    MessageBoxHelper.ShowMessageBoxError(ex.Message);
                }
            }
            
        }
Exemple #2
0
 /// <summary>
 /// Cập nhật thông tin
 /// </summary>
 /// <param name="receipt"></param>
 public void Update(Receipt receipt)
 {
     _context.Receipts.Attach(receipt);
     _context.Entry(receipt).State = EntityState.Modified;
     SaveChanges();
 }
Exemple #3
0
        protected void btnSave_OnClick(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(txtBarcode.Text))
            {
                Product product = _productService.GetProductByBarcode(txtBarcode.Text);
                if (product != null)
                {
                    if (string.IsNullOrEmpty(txtQuantity.Text))
                    {
                        messagebox.InnerHtml = "<div class='alert alert-warning'>" +
                                           "<strong>Lỗi!</strong> " +
                                           "Vui lòng nhập vào số lượng!</div>";
                    }
                    else
                    {
                        var list = new ArrayList();

                        if (Convert.ToInt32(txtQuantity.Text) < 1)
                        {
                            messagebox.InnerHtml = "<div class='alert alert-warning'>" +
                                           "<strong>Lỗi!</strong> " +
                                           "Số lượng phải lớn hơn một!</div>";
                        }
                        else
                        {
                            CreateOrder(product.ProductID, product.ProductName, txtQuantity.Text, product.Price, product.UnitID, product.StockID);
                            foreach (var cart in _order.Carts)
                            {
                                list.Add(cart);
                            }
                            string receiptId = _receiptService.NextId();
                            var receipt = new Receipt()
                            {
                                ReceiptID = receiptId,
                                ReceiptDate = DateTime.Now,
                                TotalMoney = _order.TotalOrder,
                                //Price = Convert.ToInt32(_price),
                                Active = true,
                                CreateBy = "barcode"

                            };

                            try
                            {
                                _receiptService.Add(receipt);
                                _logService.InsertLog("barcode", "Nhập kho", this.Title);
                                foreach (Cart cart in _order.Carts)
                                {
                                    InsertReceiptDetails(receiptId, cart.ProductId, cart.Quantity, cart.Price, cart.Total);
                                    _inventoryService.InsertOrUpdateReceipt(cart.ProductId, cart.Quantity, receiptId, int.Parse(txtPlan.Text));
                                }
                                if (_order.Carts.Count > 0)
                                {
                                    _order.Carts.Clear();
                                }

                                messagebox.InnerHtml = "<div class='alert alert-success'>" +
                                                       "<strong>Nhập hàng thành công!</strong></div>";

                            }
                            catch (SqlException ex)
                            {
                                messagebox.InnerHtml = string.Format("<div class='alert alert-danger'>" +
                                           "<strong>Lỗi!</strong> {0} .</div>", ex.Message);
                            }
                            catch (Exception ex)
                            {
                                messagebox.InnerHtml = string.Format("<div class='alert alert-danger'>" +
                                           "<strong>Lỗi!</strong> {0} .</div>", ex.Message);
                            }

                            txtBarcode.Text = string.Empty;
                            txtBarcode.Focus();
                        }
                    }
                }
                else
                {
                    messagebox.InnerHtml = "<div class='alert alert-danger'>" +
                                           "<strong>Lỗi!</strong> " +
                                           "Barcode không tồn tại!</div>";
                }
            }
            else
            {
                messagebox.InnerHtml = "<div class='alert alert-danger'>" +
                                           "<strong>Lỗi!</strong> " +
                                           "Barcode không được bỏ trống!</div>";
            }
        }
Exemple #4
0
 /// <summary>
 /// Thêm mới
 /// </summary>
 /// <param name="receipt"></param>
 /// <returns></returns>
 public void Add(Receipt receipt)
 {
     _context.Receipts.Add(receipt);
     SaveChanges();
 }