Esempio n. 1
0
 protected BaoGiaItemFacade(BaoGiaItemModel model) : base(model)
 {
 }
Esempio n. 2
0
        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++)
                {
                    string code = TextUtils.ToString(grvData.GetRowCellValue(i, colModuleCode)).ToUpper();
                    if (code == "")
                    {
                        continue;
                    }
                    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   = code;
                        curentItem.ModuleName   = TextUtils.ToString(grvData.GetRowCellValue(i, colModuleName)).ToUpper();
                        curentItem.ModuleCodeHD = TextUtils.ToString(grvData.GetRowCellValue(i, colModuleCodeHD));
                        curentItem.ModuleNameHD = TextUtils.ToString(grvData.GetRowCellValue(i, colModuleNameHD));

                        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.PriceDT = TextUtils.ToDecimal(grvData.GetRowCellValue(i, colPriceDT));

                        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();
            }
        }