Esempio n. 1
0
        void save(bool close)
        {
            ProcessTransaction pt = new ProcessTransaction();

            pt.OpenConnection();
            pt.BeginTransaction();

            try
            {
                if (!ValidateForm())
                {
                    return;
                }

                CostGroup.Code         = txtCode.Text.Trim();
                CostGroup.Name         = txtName.Text.Trim();
                CostGroup.Description  = txtDescription.Text.Trim();
                CostGroup.PercentTrade = TextUtils.ToDecimal(txtPercentTrade.Text.Trim());
                CostGroup.PercentUser  = TextUtils.ToDecimal(txtPercentUser.Text.Trim());
                CostGroup.VAT          = TextUtils.ToDecimal(txtPercentVat.Text.Trim());
                CostGroup.DividedRate  = TextUtils.ToDecimal(txtDividedRate.Text.Trim());
                CostGroup.ProfitSX     = TextUtils.ToDecimal(txtProfitSX.Text.Trim());
                CostGroup.ProfitTM     = TextUtils.ToDecimal(txtProfitTM.Text.Trim());

                if (CostGroup.ID == 0)
                {
                    CostGroup.ID = (int)pt.Insert(CostGroup);
                }
                else
                {
                    pt.Update(CostGroup);
                }

                if (grvData.RowCount > 0)
                {
                    for (int i = 0; i < grvData.RowCount; i++)
                    {
                        int           id = TextUtils.ToInt(grvData.GetRowCellValue(i, colID));
                        CostLinkModel costLink;
                        if (id == 0)
                        {
                            costLink = new CostLinkModel();
                        }
                        else
                        {
                            costLink = (CostLinkModel)CostLinkBO.Instance.FindByPK(id);
                        }

                        costLink.CostGroupID  = CostGroup.ID;
                        costLink.CostDetailID = TextUtils.ToInt(grvData.GetRowCellValue(i, colCostDetailID));
                        costLink.CostPercent  = TextUtils.ToDecimal(grvData.GetRowCellValue(i, colPercent));

                        if (id == 0)
                        {
                            pt.Insert(costLink);
                        }
                        else
                        {
                            pt.Update(costLink);
                        }
                    }
                }

                pt.CommitTransaction();
                _isSaved = true;

                if (close)
                {
                    this.DialogResult = DialogResult.OK;
                }
                else
                {
                    loadGrid();
                    MessageBox.Show("Lưu trữ thành công!", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                pt.CloseConnection();
            }
        }
Esempio n. 2
0
 protected CostLinkFacade(CostLinkModel model) : base(model)
 {
 }