void save(bool close) { ProcessTransaction pt = new ProcessTransaction(); pt.OpenConnection(); pt.BeginTransaction(); try { if (!ValidateForm()) { return; } //grvDiff.FocusedRowHandle = grvData.FocusedRowHandle = -1; BaoGia.Code = txtBaoGiaCode.Text.Trim(); BaoGia.ProjectCode = txtProjectCode.Text.Trim().ToUpper(); BaoGia.ProjectName = txtProjectName.Text.Trim().ToUpper(); BaoGia.DepartmentName = txtDepartmentName.Text.Trim().ToUpper(); BaoGia.CustomerCode = txtCustomerCode.Text.Trim().ToUpper(); BaoGia.CustomerName = txtCustomerName.Text.Trim().ToUpper(); BaoGia.CustomerCodeF = txtFinishCustomerCode.Text.Trim().ToUpper(); BaoGia.CustomerNameF = txtFinishCustomerName.Text.Trim().ToUpper(); BaoGia.CustomerPercentType = cboPriceType.SelectedIndex; BaoGia.CustomerPercent = TextUtils.ToDecimal(txtCustomerPercent.Text); BaoGia.CustomerCash = TextUtils.ToDecimal(txtCustomerCash.Text); BaoGia.CustomerTotal = TextUtils.ToDecimal(txtCustomerTotal.Text); //BaoGia.TotalTPA = TextUtils.ToDecimal(colTotalTPA.SummaryItem.SummaryValue); //BaoGia.TotalReal = TextUtils.ToDecimal(colTotalReal.SummaryItem.SummaryValue); //BaoGia.TotalHD = TextUtils.ToDecimal(colTotalHD.SummaryItem.SummaryValue); //BaoGia.TotalVT = TextUtils.ToDecimal(colTotalVT.SummaryItem.SummaryValue); BaoGia.TotalPhatSinh = TextUtils.ToDecimal(colDiffPrice.SummaryItem.SummaryValue); if (BaoGia.ID <= 0) { BaoGia.ID = (int)pt.Insert(BaoGia); } else { pt.Update(BaoGia); } #region BaoGiaItem //for (int i = 0; i < grvData.RowCount; i++) //{ // try // { // BaoGiaItemModel curentItem = new BaoGiaItemModel(); // int baoGiaID = TextUtils.ToInt(grvData.GetRowCellValue(i, colBaoGiaID)); // if (baoGiaID > 0) // { // curentItem = (BaoGiaItemModel)BaoGiaItemBO.Instance.FindByPK(baoGiaID); // } // curentItem.BaoGiaID = BaoGia.ID; // curentItem.CostGroupID = TextUtils.ToInt(grvData.GetRowCellValue(i, colCostGroupID)); // curentItem.ModuleCode = grvData.GetRowCellValue(i, colModuleCode).ToString().ToUpper(); // curentItem.ModuleName = grvData.GetRowCellValue(i, colModuleName).ToString().ToUpper(); // curentItem.PriceHD = TextUtils.ToDecimal(grvData.GetRowCellValue(i, colPriceHD)); // curentItem.PriceHDnoVAT = TextUtils.ToDecimal(grvData.GetRowCellValue(i, colPriceHDnoVAT)); // curentItem.PriceReal = TextUtils.ToDecimal(grvData.GetRowCellValue(i, colPriceReal)); // curentItem.PriceTPA = TextUtils.ToDecimal(grvData.GetRowCellValue(i, colPriceTPA)); // curentItem.PriceType = grvData.GetRowCellValue(i, colPriceType).ToString(); // curentItem.PriceVT = TextUtils.ToDecimal(grvData.GetRowCellValue(i, colPriceVT)); // curentItem.ProductCode = grvData.GetRowCellValue(i, colProductCode).ToString().ToUpper(); // curentItem.ProductName = grvData.GetRowCellValue(i, colProductName).ToString().ToUpper(); // curentItem.Qty = TextUtils.ToDecimal(grvData.GetRowCellValue(i, colQty)); // curentItem.TotalHD = TextUtils.ToDecimal(grvData.GetRowCellValue(i, colTotalHD)); // curentItem.TotalReal = TextUtils.ToDecimal(grvData.GetRowCellValue(i, colTotalReal)); // curentItem.TotalHDnoVAT = TextUtils.ToDecimal(grvData.GetRowCellValue(i, colTotalHDnoVat)); // curentItem.TotalTPA = TextUtils.ToDecimal(grvData.GetRowCellValue(i, colTotalTPA)); // curentItem.TotalVT = TextUtils.ToDecimal(grvData.GetRowCellValue(i, colTotalVT)); // curentItem.VAT = TextUtils.ToDecimal(grvData.GetRowCellValue(i, colVAT)); // if (baoGiaID > 0) // { // pt.Update(curentItem); // } // else // { // pt.Insert(curentItem); // } // } // catch (Exception) // { // } //} #endregion #region Chi phí phát sinh 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 = TextUtils.ToDecimal(grvDiff.GetRowCellValue(i, colDiffPrice)); if (diffID > 0) { pt.Update(diffModel); } else { pt.Insert(diffModel); } } #endregion pt.CommitTransaction(); _isSaved = true; loadBaogiaItem(); loadModule(); loadDiffCost(); if (close) { this.DialogResult = DialogResult.OK; } else { MessageBox.Show("Lưu trữ thành công!", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { MessageBox.Show("Lưu trữ không thành công!" + Environment.NewLine + ex.Message, TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { pt.CloseConnection(); } }
protected BaoGiaDiffFacade(BaoGiaDiffModel 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); } }