示例#1
0
        private void dgvProductList_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (sender is DataGridView)
            {
                DataGridViewCell cell = ((DataGridView)sender).CurrentCell;
                if (cell.ColumnIndex == ((DataGridView)sender).ColumnCount - 1)
                {
                    DialogResult result = MessageBox.Show("Bạn có muốn xóa sản phẩm này?",
                                                          "Xoá sản phẩm này",
                                                          MessageBoxButtons.YesNo,
                                                          MessageBoxIcon.Question);
                    if (result == DialogResult.Yes)
                    {
                        DataGridViewRow currentRow = dgvProductList.Rows[e.RowIndex];

                        ProductService    productService    = new ProductService();
                        int               id                = ObjectHelper.GetValueFromAnonymousType <int>(currentRow.DataBoundItem, "Id");
                        ProductLogService productLogService = new ProductLogService();
                        ProductLog        log               = productLogService.GetProductLogs().Where(p => p.ProductId == id && p.Status == BHConstant.ACTIVE_STATUS).FirstOrDefault();
                        if (log == null)
                        {
                            if (!productService.DeleteProduct(id))
                            {
                                MessageBox.Show("Hiện tại hệ thống đang có lỗi. Vui lòng thử lại sau!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }
                        else
                        {
                            MessageBox.Show("Sản phẩm này còn trong kho nên không thể xóa được!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                        loadProductList();
                    }
                }
            }
        }
 private void EntranceStock_Load(object sender, EventArgs e)
 {
     productLogService = new ProductLogService();
     unitService = new MeasurementUnitService();
     loadSomeData();
     SetupColumns();
     updateProductionRequestDetailCells();
 }
示例#3
0
 private void EntranceStock_Load(object sender, EventArgs e)
 {
     productLogService = new ProductLogService();
     unitService       = new MeasurementUnitService();
     loadSomeData();
     SetupColumns();
     updateProductionRequestDetailCells();
 }
 public ProductAndMaterialReport()
 {
     InitializeComponent();
     productLogService = new ProductLogService();
     LoadDataCombobox();
     dtpFrom.Value = DateTime.Today.AddDays(-DateTime.Now.Day + 1);
     dtpFrom.CustomFormat = BHConstant.DATE_FORMAT;
     dtpTo.CustomFormat = BHConstant.DATE_FORMAT;
 }
 public ProductAndMaterialReport()
 {
     InitializeComponent();
     productLogService = new ProductLogService();
     LoadDataCombobox();
     dtpFrom.Value        = DateTime.Today.AddDays(-DateTime.Now.Day + 1);
     dtpFrom.CustomFormat = BHConstant.DATE_FORMAT;
     dtpTo.CustomFormat   = BHConstant.DATE_FORMAT;
 }
        private void AddProduct_Load(object sender, EventArgs e)
        {
            ProductService productService = new ProductService();

            products = productService.GetProducts();

            productLogService = new ProductLogService();
            loadSomeData();
            SetupColumns();

            oldAttr = new List <int>();
            if (mode == 1) // Load data grid
            {
                List <ProductAttribute> pas = product.ProductAttributes.ToList <ProductAttribute>();
                oldAttr = pas.Select(x => x.AttributeId).ToList();
                foreach (DataGridViewRow dgv in dgvBaseAttributes.Rows)
                {
                    DataGridViewCheckBoxCell checkbox = (DataGridViewCheckBoxCell)dgvBaseAttributes.Rows[dgv.Index].Cells[0];
                    checkbox.Value = "0";
                    foreach (ProductAttribute pa in pas)
                    {
                        if ((BaseAttribute)dgv.DataBoundItem == pa.BaseAttribute)
                        {
                            checkbox.Value = "1";
                            if (productLogService.GetNewestProductLog(product.Id, pa.AttributeId) != null)
                            {
                                checkbox.FlatStyle       = FlatStyle.Flat;
                                checkbox.Style.ForeColor = Color.DarkGray;
                                checkbox.ReadOnly        = true;
                                checkbox.ToolTipText     = "Thuộc tính của sản phẩm đang được sử dụng";
                            }
                            break;
                        }
                    }
                }
            }

            var product_codes = new AutoCompleteStringCollection();

            product_codes.AddRange(products.Select(x => x.ProductCode).ToArray());
            txtCode.AutoCompleteCustomSource = product_codes;
            txtCode.AutoCompleteMode         = AutoCompleteMode.SuggestAppend;
            txtCode.AutoCompleteSource       = AutoCompleteSource.CustomSource;
        }
        private void dgwStockEntranceList_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (sender is DataGridView)
            {
                DataGridViewCell cell = ((DataGridView)sender).CurrentCell;
                if (cell.ColumnIndex == ((DataGridView)sender).ColumnCount - 1)
                {
                    DialogResult result = MessageBox.Show("Bạn có muốn xóa phiếu nhập kho này?",
                    "Xoá phiếu nhập kho",
                     MessageBoxButtons.YesNo,
                    MessageBoxIcon.Question);
                    if (result == DialogResult.Yes)
                    {
                        DateTime systime = BaoHienRepository.GetBaoHienDBDataContext().GetSystemDate();
                        DataGridViewRow currentRow = dgwStockEntranceList.Rows[e.RowIndex];

                        EntranceStockService entranceStockService = new EntranceStockService();
                        int id = ObjectHelper.GetValueFromAnonymousType<int>(currentRow.DataBoundItem, "Id");
                        EntranceStock es = entranceStockService.GetEntranceStock(id);

                        ProductLogService productLogService = new ProductLogService();
                        EntranceStockDetailService entranceStockDetailService = new EntranceStockDetailService();
                        List<EntranceStockDetail> details = entranceStockDetailService.SelectEntranceStockDetailByWhere(x => x.EntranceStockId == es.Id).ToList();
                        string msg = "";
                        int error = 0;
                        ProductLog pl, newpl;
                        foreach (EntranceStockDetail item in details)
                        {
                            pl = productLogService.GetProductLog(item.ProductId, item.AttributeId, item.UnitId);
                            if (pl.AfterNumber - item.NumberUnit < 0)
                            {
                                if (error == 0)
                                {
                                    msg += "Những sản phẩm sau đã bị XÓA nhưng không đảm bảo dữ liệu trong kho:\n";
                                    error = 1;
                                }
                                msg += "- " + productLogService.GetNameOfProductLog(pl) + " : " + item.NumberUnit + "\n";
                            }
                        }
                        if (error > 0)
                        {
                            MessageBox.Show(msg, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                        try
                        {
                            foreach (EntranceStockDetail item in details)
                            {
                                pl = productLogService.GetProductLog(item.ProductId, item.AttributeId, item.UnitId);
                                newpl = new ProductLog()
                                {
                                    ProductId = item.ProductId,
                                    AttributeId = item.AttributeId,
                                    UnitId = item.UnitId,
                                    BeforeNumber = pl.AfterNumber,
                                    Amount = item.NumberUnit,
                                    AfterNumber = pl.AfterNumber - item.NumberUnit,
                                    RecordCode = es.EntranceCode,
                                    Status = BHConstant.DEACTIVE_STATUS,
                                    Direction = BHConstant.DIRECTION_OUT,
                                    UpdatedDate = systime
                                };
                                productLogService.AddProductLog(newpl);
                            }
                            productLogService.DeactiveProductLog(es.EntranceCode);
                            if (!entranceStockService.DeleteEntranceStock(id))
                            {
                                MessageBox.Show("Hiện tại hệ thống đang có lỗi. Vui lòng thử lại sau!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }
                        catch { }
                        loadEntranceStockList();
                    }

                }

            }
        }
        private void dgvProductList_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (sender is DataGridView)
            {
                DataGridViewCell cell = ((DataGridView)sender).CurrentCell;
                if (cell.ColumnIndex == ((DataGridView)sender).ColumnCount - 1)
                {
                    DialogResult result = MessageBox.Show("Bạn có muốn xóa sản phẩm này?",
                    "Xoá sản phẩm này",
                     MessageBoxButtons.YesNo,
                    MessageBoxIcon.Question);
                    if (result == DialogResult.Yes)
                    {
                        DataGridViewRow currentRow = dgvProductList.Rows[e.RowIndex];

                        ProductService productService = new ProductService();
                        int id = ObjectHelper.GetValueFromAnonymousType<int>(currentRow.DataBoundItem, "Id");
                        ProductLogService productLogService = new ProductLogService();
                        ProductLog log = productLogService.GetProductLogs().Where(p => p.ProductId == id && p.Status == BHConstant.ACTIVE_STATUS).FirstOrDefault();
                        if (log == null)
                        {
                            if (!productService.DeleteProduct(id))
                            {
                                MessageBox.Show("Hiện tại hệ thống đang có lỗi. Vui lòng thử lại sau!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }
                        else
                        {
                            MessageBox.Show("Sản phẩm này còn trong kho nên không thể xóa được!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                        loadProductList();
                    }

                }

            }
        }
 private void AddOrder_Load(object sender, EventArgs e)
 {
     unitService = new MeasurementUnitService();
     productLogService = new ProductLogService();
     loadSomeData();
     SetupColumns();
     updateProductionRequestDetailCells();
     calculateTotal();
     loadOther();
 }
 private void AddProductionRequest_Load(object sender, EventArgs e)
 {
     unitService = new MeasurementUnitService();
     productLogService = new ProductLogService();
     loadSomeData();
     SetupColumnsForMaterial();
     SetupColumnsForProductRequest();
     updateProductionRequestDetailCells();
 }
        private void AddProduct_Load(object sender, EventArgs e)
        {
            ProductService productService = new ProductService();
            products = productService.GetProducts();

            productLogService = new ProductLogService();
            loadSomeData();
            SetupColumns();

            oldAttr = new List<int>();
            if (mode == 1) // Load data grid
            {
                List<ProductAttribute> pas = product.ProductAttributes.ToList<ProductAttribute>();
                oldAttr = pas.Select(x => x.AttributeId).ToList();
                foreach (DataGridViewRow dgv in dgvBaseAttributes.Rows)
                {
                    DataGridViewCheckBoxCell checkbox = (DataGridViewCheckBoxCell)dgvBaseAttributes.Rows[dgv.Index].Cells[0];
                    checkbox.Value = "0";
                    foreach (ProductAttribute pa in pas)
                    {
                        if ((BaseAttribute)dgv.DataBoundItem == pa.BaseAttribute)
                        {
                            checkbox.Value = "1";
                            if (productLogService.GetNewestProductLog(product.Id, pa.AttributeId) != null)
                            {
                                checkbox.FlatStyle = FlatStyle.Flat;
                                checkbox.Style.ForeColor = Color.DarkGray;
                                checkbox.ReadOnly = true;
                                checkbox.ToolTipText = "Thuộc tính của sản phẩm đang được sử dụng";
                            }
                            break;
                        }
                    }
                }
            }

            var product_codes = new AutoCompleteStringCollection();
            product_codes.AddRange(products.Select(x => x.ProductCode).ToArray());
            txtCode.AutoCompleteCustomSource = product_codes;
            txtCode.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
            txtCode.AutoCompleteSource = AutoCompleteSource.CustomSource;
        }
        private void DeleteOrder(DataGridViewCellEventArgs e)
        {
            DialogResult result = MessageBox.Show("Bạn muốn xóa đơn hàng này?", "Xoá đơn hàng", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (result == DialogResult.Yes)
            {
                DataGridViewRow currentRow = dgwOrderList.Rows[e.RowIndex];

                OrderService orderService = new OrderService();
                int          id           = ObjectHelper.GetValueFromAnonymousType <int>(currentRow.DataBoundItem, "Id");
                Order        order        = orderService.GetOrder(id);
                DateTime     systime      = BaoHienRepository.GetBaoHienDBDataContext().GetSystemDate();

                #region CustomerLog

                CustomerLogService cls = new CustomerLogService();
                CustomerLog        cl  = cls.GetCustomerLog(order.OrderCode);
                bool kq = true;
                if (cl != null)
                {
                    kq = cls.DeleteCustomerLog(cl.Id);
                }

                #endregion

                #region ProductLog

                ProductLogService  productLogService = new ProductLogService();
                OrderDetailService orderDetailService = new OrderDetailService();
                List <OrderDetail> details = orderDetailService.SelectOrderDetailByWhere(x => x.OrderId == order.Id).ToList();
                ProductLog         pl, newpl;
                foreach (OrderDetail item in details)
                {
                    pl    = productLogService.GetProductLog(item.ProductId, item.AttributeId, item.UnitId);
                    newpl = new ProductLog()
                    {
                        ProductId    = item.ProductId,
                        AttributeId  = item.AttributeId,
                        UnitId       = item.UnitId,
                        BeforeNumber = pl.AfterNumber,
                        Amount       = item.NumberUnit,
                        AfterNumber  = pl.AfterNumber + item.NumberUnit,
                        RecordCode   = order.OrderCode,
                        Status       = BHConstant.DEACTIVE_STATUS,
                        Direction    = BHConstant.DIRECTION_IN,
                        UpdatedDate  = systime
                    };
                    productLogService.AddProductLog(newpl);
                }
                productLogService.DeactiveProductLog(order.OrderCode);

                #endregion

                #region EmployeeLog

                int salerId = (int)order.Customer.SalerId;
                if (salerId > 0)
                {
                    EmployeeLogService els      = new EmployeeLogService();
                    EmployeeLog        order_el = els.SelectEmployeeLogByWhere(x => x.RecordCode == order.OrderCode).FirstOrDefault();
                    if (order_el != null)
                    {
                        els.DeleteEmployeeLog(order_el.Id);
                    }
                }

                #endregion

                if (!orderService.DeleteOrder(id) && kq)
                {
                    MessageBox.Show("Hiện tại hệ thống đang có lỗi. Vui lòng thử lại sau!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                loadOrderList();
            }
        }
        private void DeleteOrder(DataGridViewCellEventArgs e)
        {
            DialogResult result = MessageBox.Show("Bạn muốn xóa đơn hàng này?", "Xoá đơn hàng", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (result == DialogResult.Yes)
            {
                DataGridViewRow currentRow = dgwOrderList.Rows[e.RowIndex];

                OrderService orderService = new OrderService();
                int id = ObjectHelper.GetValueFromAnonymousType<int>(currentRow.DataBoundItem, "Id");
                Order order = orderService.GetOrder(id);
                DateTime systime = BaoHienRepository.GetBaoHienDBDataContext().GetSystemDate();

                #region CustomerLog

                CustomerLogService cls = new CustomerLogService();
                CustomerLog cl = cls.GetCustomerLog(order.OrderCode);
                bool kq = true;
                if (cl != null)
                    kq = cls.DeleteCustomerLog(cl.Id);

                #endregion

                #region ProductLog

                ProductLogService productLogService = new ProductLogService();
                OrderDetailService orderDetailService = new OrderDetailService();
                List<OrderDetail> details = orderDetailService.SelectOrderDetailByWhere(x => x.OrderId == order.Id).ToList();
                ProductLog pl, newpl;
                foreach (OrderDetail item in details)
                {
                    pl = productLogService.GetProductLog(item.ProductId, item.AttributeId, item.UnitId);
                    newpl = new ProductLog()
                    {
                        ProductId = item.ProductId,
                        AttributeId = item.AttributeId,
                        UnitId = item.UnitId,
                        BeforeNumber = pl.AfterNumber,
                        Amount = item.NumberUnit,
                        AfterNumber = pl.AfterNumber + item.NumberUnit,
                        RecordCode = order.OrderCode,
                        Status = BHConstant.DEACTIVE_STATUS,
                        Direction = BHConstant.DIRECTION_IN,
                        UpdatedDate = systime
                    };
                    productLogService.AddProductLog(newpl);
                }
                productLogService.DeactiveProductLog(order.OrderCode);

                #endregion

                #region EmployeeLog

                int salerId = (int)order.Customer.SalerId;
                if (salerId > 0)
                {
                    EmployeeLogService els = new EmployeeLogService(); 
                    EmployeeLog order_el = els.SelectEmployeeLogByWhere(x => x.RecordCode == order.OrderCode).FirstOrDefault();
                    if(order_el != null)
                        els.DeleteEmployeeLog(order_el.Id);
                }

                #endregion

                if (!orderService.DeleteOrder(id) && kq)
                {
                    MessageBox.Show("Hiện tại hệ thống đang có lỗi. Vui lòng thử lại sau!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                loadOrderList();
            }
        }
示例#14
0
        private void dgwRequestList_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (sender is DataGridView)
            {
                DataGridViewCell cell = ((DataGridView)sender).CurrentCell;
                if (cell.ColumnIndex == ((DataGridView)sender).ColumnCount - 1)
                {
                    DialogResult result = MessageBox.Show("Bạn có muốn xóa phiếu sản xuât này?",
                                                          "Xoá phiếu sản xuât",
                                                          MessageBoxButtons.YesNo,
                                                          MessageBoxIcon.Question);
                    if (result == DialogResult.Yes)
                    {
                        DataGridViewRow currentRow = dgwRequestList.Rows[e.RowIndex];

                        ProductionRequestService       productionRequestService       = new ProductionRequestService();
                        ProductionRequestDetailService productionRequestDetailService = new ProductionRequestDetailService();
                        int id = ObjectHelper.GetValueFromAnonymousType <int>(currentRow.DataBoundItem, "Id");
                        ProductionRequest pr = productionRequestService.GetProductionRequest(id);
                        List <ProductionRequestDetail> productionRequestDetails = productionRequestDetailService.GetProductionRequestDetails().Where(p => p.ProductionRequestId == id).ToList();
                        bool     ret     = false;
                        DateTime systime = BaoHienRepository.GetBaoHienDBDataContext().GetSystemDate();

                        ProductLogService productLogService = new ProductLogService();
                        string            msg = "";
                        int        error = 0, amount = 0;
                        ProductLog pl, newpl;
                        foreach (ProductionRequestDetail item in productionRequestDetails)
                        {
                            pl     = productLogService.GetProductLog(item.ProductId, item.AttributeId, item.UnitId);
                            amount = (item.Direction == BHConstant.DIRECTION_OUT) ? -item.NumberUnit : item.NumberUnit;
                            if (pl.AfterNumber - amount < 0)
                            {
                                if (error == 0)
                                {
                                    msg  += "Những sản phẩm sau đã bị XÓA nhưng không đảm bảo dữ liệu trong kho:\n";
                                    error = 1;
                                }
                                msg += "- " + productLogService.GetNameOfProductLog(pl) + " : " + item.NumberUnit + "\n";
                            }
                        }
                        if (error > 0)
                        {
                            MessageBox.Show(msg, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                        foreach (ProductionRequestDetail item in productionRequestDetails)
                        {
                            pl     = productLogService.GetProductLog(item.ProductId, item.AttributeId, item.UnitId);
                            amount = (item.Direction == BHConstant.DIRECTION_OUT) ? -item.NumberUnit : item.NumberUnit;
                            newpl  = new ProductLog()
                            {
                                ProductId    = item.ProductId,
                                AttributeId  = item.AttributeId,
                                UnitId       = item.UnitId,
                                BeforeNumber = pl.AfterNumber,
                                Amount       = item.NumberUnit,
                                AfterNumber  = pl.AfterNumber - amount,
                                RecordCode   = pr.ReqCode,
                                Status       = BHConstant.DEACTIVE_STATUS,
                                Direction    = !item.Direction,
                                UpdatedDate  = systime
                            };
                            productLogService.AddProductLog(newpl);
                        }
                        productLogService.DeactiveProductLog(pr.ReqCode);
                        if (!productionRequestService.DeleteProductionRequest(id))
                        {
                            MessageBox.Show("Hiện tại hệ thống đang có lỗi. Vui lòng thử lại sau!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                        loadProductionRequestList();
                    }
                }
            }
        }
        private void dgwRequestList_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (sender is DataGridView)
            {
                DataGridViewCell cell = ((DataGridView)sender).CurrentCell;
                if (cell.ColumnIndex == ((DataGridView)sender).ColumnCount - 1)
                {
                    DialogResult result = MessageBox.Show("Bạn có muốn xóa phiếu sản xuât này?",
                    "Xoá phiếu sản xuât",
                     MessageBoxButtons.YesNo,
                    MessageBoxIcon.Question);
                    if (result == DialogResult.Yes)
                    {
                        DataGridViewRow currentRow = dgwRequestList.Rows[e.RowIndex];

                        ProductionRequestService productionRequestService = new ProductionRequestService();
                        ProductionRequestDetailService productionRequestDetailService = new ProductionRequestDetailService();
                        int id = ObjectHelper.GetValueFromAnonymousType<int>(currentRow.DataBoundItem, "Id");
                        ProductionRequest pr = productionRequestService.GetProductionRequest(id);
                        List<ProductionRequestDetail> productionRequestDetails = productionRequestDetailService.GetProductionRequestDetails().Where(p => p.ProductionRequestId == id).ToList();
                        bool ret = false;
                        DateTime systime = BaoHienRepository.GetBaoHienDBDataContext().GetSystemDate();

                        ProductLogService productLogService = new ProductLogService();
                        string msg = "";
                        int error = 0, amount = 0;
                        ProductLog pl, newpl;
                        foreach (ProductionRequestDetail item in productionRequestDetails)
                        {
                            pl = productLogService.GetProductLog(item.ProductId, item.AttributeId, item.UnitId);
                            amount = (item.Direction == BHConstant.DIRECTION_OUT) ? -item.NumberUnit : item.NumberUnit;
                            if (pl.AfterNumber - amount < 0)
                            {
                                if (error == 0)
                                {
                                    msg += "Những sản phẩm sau đã bị XÓA nhưng không đảm bảo dữ liệu trong kho:\n";
                                    error = 1;
                                }
                                msg += "- " + productLogService.GetNameOfProductLog(pl) + " : " + item.NumberUnit + "\n";
                            }
                        }
                        if (error > 0)
                        {
                            MessageBox.Show(msg, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                        foreach (ProductionRequestDetail item in productionRequestDetails)
                        {
                            pl = productLogService.GetProductLog(item.ProductId, item.AttributeId, item.UnitId);
                            amount = (item.Direction == BHConstant.DIRECTION_OUT) ? -item.NumberUnit : item.NumberUnit;
                            newpl = new ProductLog()
                            {
                                ProductId = item.ProductId,
                                AttributeId = item.AttributeId,
                                UnitId = item.UnitId,
                                BeforeNumber = pl.AfterNumber,
                                Amount = item.NumberUnit,
                                AfterNumber = pl.AfterNumber - amount,
                                RecordCode = pr.ReqCode,
                                Status = BHConstant.DEACTIVE_STATUS,
                                Direction = !item.Direction,
                                UpdatedDate = systime
                            };
                            productLogService.AddProductLog(newpl);
                        }
                        productLogService.DeactiveProductLog(pr.ReqCode);
                        if (!productionRequestService.DeleteProductionRequest(id))
                        {
                            MessageBox.Show("Hiện tại hệ thống đang có lỗi. Vui lòng thử lại sau!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                        loadProductionRequestList();
                    }

                }

            }
        }
        private void dgwStockEntranceList_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (sender is DataGridView)
            {
                DataGridViewCell cell = ((DataGridView)sender).CurrentCell;
                if (cell.ColumnIndex == ((DataGridView)sender).ColumnCount - 1)
                {
                    DialogResult result = MessageBox.Show("Bạn có muốn xóa phiếu nhập kho này?",
                                                          "Xoá phiếu nhập kho",
                                                          MessageBoxButtons.YesNo,
                                                          MessageBoxIcon.Question);
                    if (result == DialogResult.Yes)
                    {
                        DateTime        systime    = BaoHienRepository.GetBaoHienDBDataContext().GetSystemDate();
                        DataGridViewRow currentRow = dgwStockEntranceList.Rows[e.RowIndex];

                        EntranceStockService entranceStockService = new EntranceStockService();
                        int           id = ObjectHelper.GetValueFromAnonymousType <int>(currentRow.DataBoundItem, "Id");
                        EntranceStock es = entranceStockService.GetEntranceStock(id);

                        ProductLogService          productLogService          = new ProductLogService();
                        EntranceStockDetailService entranceStockDetailService = new EntranceStockDetailService();
                        List <EntranceStockDetail> details = entranceStockDetailService.SelectEntranceStockDetailByWhere(x => x.EntranceStockId == es.Id).ToList();
                        string     msg = "";
                        int        error = 0;
                        ProductLog pl, newpl;
                        foreach (EntranceStockDetail item in details)
                        {
                            pl = productLogService.GetProductLog(item.ProductId, item.AttributeId, item.UnitId);
                            if (pl.AfterNumber - item.NumberUnit < 0)
                            {
                                if (error == 0)
                                {
                                    msg  += "Những sản phẩm sau đã bị XÓA nhưng không đảm bảo dữ liệu trong kho:\n";
                                    error = 1;
                                }
                                msg += "- " + productLogService.GetNameOfProductLog(pl) + " : " + item.NumberUnit + "\n";
                            }
                        }
                        if (error > 0)
                        {
                            MessageBox.Show(msg, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                        try
                        {
                            foreach (EntranceStockDetail item in details)
                            {
                                pl    = productLogService.GetProductLog(item.ProductId, item.AttributeId, item.UnitId);
                                newpl = new ProductLog()
                                {
                                    ProductId    = item.ProductId,
                                    AttributeId  = item.AttributeId,
                                    UnitId       = item.UnitId,
                                    BeforeNumber = pl.AfterNumber,
                                    Amount       = item.NumberUnit,
                                    AfterNumber  = pl.AfterNumber - item.NumberUnit,
                                    RecordCode   = es.EntranceCode,
                                    Status       = BHConstant.DEACTIVE_STATUS,
                                    Direction    = BHConstant.DIRECTION_OUT,
                                    UpdatedDate  = systime
                                };
                                productLogService.AddProductLog(newpl);
                            }
                            productLogService.DeactiveProductLog(es.EntranceCode);
                            if (!entranceStockService.DeleteEntranceStock(id))
                            {
                                MessageBox.Show("Hiện tại hệ thống đang có lỗi. Vui lòng thử lại sau!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }
                        catch { }
                        loadEntranceStockList();
                    }
                }
            }
        }