Пример #1
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public string Add(UFIDA.U8.UAP.CustomApp.ControlForm.Model._AlocationProportion model)
        {
            StringBuilder strSql  = new StringBuilder();
            StringBuilder strSql1 = new StringBuilder();
            StringBuilder strSql2 = new StringBuilder();

            if (model.CostType != null)
            {
                strSql1.Append("CostType,");
                strSql2.Append("'" + model.CostType + "',");
            }
            if (model.cDepCode != null)
            {
                strSql1.Append("cDepCode,");
                strSql2.Append("'" + model.cDepCode + "',");
            }
            if (model.dPercentage != null)
            {
                strSql1.Append("dPercentage,");
                strSql2.Append("" + model.dPercentage + ",");
            }
            if (model.Remark != null)
            {
                strSql1.Append("Remark,");
                strSql2.Append("'" + model.Remark + "',");
            }
            strSql.Append("insert into _AlocationProportion(");
            strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1));
            strSql.Append(")");
            strSql.Append(" values (");
            strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1));
            strSql.Append(")");
            strSql.Append(";select @@IDENTITY");
            return(strSql.ToString());
        }
Пример #2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                try
                {
                    gridView1.FocusedRowHandle -= 1;
                    gridView1.FocusedRowHandle += 1;
                }
                catch { }

                string        sErr = "";
                int           iCou = 0;
                SqlConnection conn = new SqlConnection(DbHelperSQL.connectionString);
                conn.Open();
                //启用事务
                SqlTransaction tran = conn.BeginTransaction();
                try
                {
                    string s费用类型 = lookUpEditCostType.EditValue.ToString().Trim();
                    if (s费用类型 == "")
                    {
                        lookUpEditCostType.Focus();
                        throw new Exception("费用不能为空");
                    }

                    string sSQL = "delete _AlocationProportion where [CostType] = '" + lookUpEditCostType.EditValue.ToString().Trim() + "'";
                    DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);

                    decimal d总比例 = 0;
                    for (int i = 0; i < gridView1.RowCount; i++)
                    {
                        decimal d = TH.BaseClass.BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridColdPercentage), 2);
                        d总比例 = d总比例 + d;

                        Model._AlocationProportion model = new UFIDA.U8.UAP.CustomApp.ControlForm.Model._AlocationProportion();
                        model.cDepCode    = gridView1.GetRowCellValue(i, gridColcDepCode).ToString().Trim();
                        model.CostType    = lookUpEditCostType.EditValue.ToString().Trim();
                        model.dPercentage = d;
                        model.Remark      = gridView1.GetRowCellValue(i, gridColRemark).ToString().Trim();

                        DAL._AlocationProportion dal = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL._AlocationProportion();
                        sSQL = dal.Add(model);
                        iCou = iCou + DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                    }

                    if (d总比例 != 100)
                    {
                        throw new Exception("分配比例汇总后必须是100");
                    }


                    tran.Commit();

                    GetGrid();

                    if (iCou > 0)
                    {
                        MessageBox.Show("保存成功");
                    }
                }
                catch (Exception error)
                {
                    tran.Rollback();
                    throw new Exception(error.Message);
                }
            }
            catch (Exception ee)
            {
                FrmMsgBox f = new FrmMsgBox();
                f.Text = "保存失败";
                f.richTextBox1.Text = ee.Message;
                f.ShowDialog();
            }
        }