Example #1
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();
                    }
                }
            }
        }
 public void loadDataForEditProductRequest(int productionRequestId)
 {
     this.Text = "Chỉnh sửa phiếu sản xuất";
     isUpdating = true;
     ProductionRequestService prs = new ProductionRequestService();
     productionRequest = prs.GetProductionRequest(productionRequestId);
     old_marterial_details = new List<ProductionRequestDetail>();
     old_production_details = new List<ProductionRequestDetail>();
     if (productionRequest != null)
     {
         ProductionRequestDetailService prds = new ProductionRequestDetailService();
         productionRequestDetailInProductions = new BindingList<ProductionRequestDetail>(prds.GetProductionRequestDetails()
             .Where(p => p.ProductionRequestId == productionRequestId && p.Direction == BHConstant.PRODUCTION_REQUEST_DETAIL_OUT).ToList());
         foreach (ProductionRequestDetail od in productionRequestDetailInProductions)
         {
             old_production_details.Add(new ProductionRequestDetail
             {
                 AttributeId = od.AttributeId,
                 ProductId = od.ProductId,
                 UnitId = od.UnitId,
                 ProductionRequestId = od.ProductionRequestId,
                 NumberUnit = od.NumberUnit
             });
         }
         productionRequestDetailInMaterials = new BindingList<ProductionRequestDetail>(prds.GetProductionRequestDetails()
             .Where(p => p.ProductionRequestId == productionRequestId && p.Direction == BHConstant.PRODUCTION_REQUEST_DETAIL_IN).ToList());
         foreach (ProductionRequestDetail od in productionRequestDetailInMaterials)
         {
             old_marterial_details.Add(new ProductionRequestDetail
             {
                 AttributeId = od.AttributeId,
                 ProductId = od.ProductId,
                 UnitId = od.UnitId,
                 ProductionRequestId = od.ProductionRequestId,
                 NumberUnit = od.NumberUnit
             });
         }
     }            
 }
        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();
                    }

                }

            }
        }