protected CostSummaryFacade(CostSummaryModel model) : base(model) { }
private void btnSave_Click(object sender, EventArgs e) { if (!ValidateForm()) { return; } grvCost.FocusedRowHandle = grvCostTM.FocusedRowHandle = grvDiff.FocusedRowHandle = -1; try { #region Chi phí phát sinh if (grvDiff.RowCount > 0) { for (int i = 0; i < grvDiff.RowCount; i++) { BaoGiaDiffModel diffModel = new BaoGiaDiffModel(); int diffID = TextUtils.ToInt(grvDiff.GetRowCellValue(i, colDiffID)); if (diffID > 0) { diffModel = (BaoGiaDiffModel)BaoGiaDiffBO.Instance.FindByPK(diffID); } diffModel.STT = TextUtils.ToInt(grvDiff.GetRowCellValue(i, colDiffSTT)); diffModel.BaoGiaID = BaoGia.ID; diffModel.Description = grvDiff.GetRowCellValue(i, colDiffDescription) != null?grvDiff.GetRowCellValue(i, colDiffDescription).ToString() : ""; diffModel.Name = grvDiff.GetRowCellValue(i, colDiffName) != null?grvDiff.GetRowCellValue(i, colDiffName).ToString() : ""; diffModel.Price = grvDiff.GetRowCellValue(i, colDiffPrice) != null?TextUtils.ToDecimal(grvDiff.GetRowCellValue(i, colDiffPrice)) : 0; if (diffID > 0) { BaoGiaDiffBO.Instance.Update(diffModel); } else { BaoGiaDiffBO.Instance.Insert(diffModel); } } } #endregion #region Chi phí sản xuất if (grvCost.RowCount > 0) { for (int i = 0; i < grvCost.RowCount; i++) { CostSummaryModel sxModel = new CostSummaryModel(); int sxID = TextUtils.ToInt(grvCost.GetRowCellValue(i, colID)); if (sxID > 0) { sxModel = (CostSummaryModel)CostSummaryBO.Instance.FindByPK(sxID); } sxModel.CostDetailID = TextUtils.ToInt(grvCost.GetRowCellValue(i, colCostDetailID)); sxModel.BaoGiaID = BaoGia.ID; sxModel.DepartmentID = TextUtils.ToInt(grvCost.GetRowCellValue(i, colDepartmentID)); sxModel.TotalDK = TextUtils.ToDecimal(grvCost.GetRowCellValue(i, colTotal)); sxModel.TotalTT = TextUtils.ToDecimal(grvCost.GetRowCellValue(i, colTotalReal)); if (sxID > 0) { CostSummaryBO.Instance.Update(sxModel); } else { CostSummaryBO.Instance.Insert(sxModel); } } } #endregion #region Chi phí thương mại if (grvCostTM.RowCount > 0) { for (int i = 0; i < grvCostTM.RowCount; i++) { CostSummaryModel tmModel = new CostSummaryModel(); int tmID = TextUtils.ToInt(grvCostTM.GetRowCellValue(i, colIDTM)); if (tmID > 0) { tmModel = (CostSummaryModel)CostSummaryBO.Instance.FindByPK(tmID); } tmModel.CostDetailID = TextUtils.ToInt(grvCostTM.GetRowCellValue(i, colCostDetailIDTM)); tmModel.BaoGiaID = BaoGia.ID; tmModel.DepartmentID = TextUtils.ToInt(grvCostTM.GetRowCellValue(i, colDepartmentIDTM)); tmModel.TotalDK = TextUtils.ToDecimal(grvCostTM.GetRowCellValue(i, colTotalTM)); tmModel.TotalTT = TextUtils.ToDecimal(grvCostTM.GetRowCellValue(i, colTotalRealTM)); if (tmID > 0) { CostSummaryBO.Instance.Update(tmModel); } else { CostSummaryBO.Instance.Insert(tmModel); } } } #endregion #region Update Báo giá BaoGia.TotalPhatSinh = TextUtils.ToDecimal(colDiffPrice.SummaryItem.SummaryValue); BaoGia.TotalSX = TextUtils.ToDecimal(colTotal.SummaryItem.SummaryValue); BaoGia.TotalDkSX = TextUtils.ToDecimal(colTotalReal.SummaryItem.SummaryValue); BaoGia.TotalTM = TextUtils.ToDecimal(colTotalTM.SummaryItem.SummaryValue); BaoGia.TotalDkTM = TextUtils.ToDecimal(colTotalRealTM.SummaryItem.SummaryValue); BaoGiaBO.Instance.Update(BaoGia); #endregion _isSaved = true; LoadGrid(0); LoadGrid(1); loadDiffGrid(); MessageBox.Show("Ghi dữ liệu thành công!", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show("Lỗi: " + ex.Message, TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Error); } }