예제 #1
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public string Add(UFIDA.U8.UAP.CustomApp.ControlForm.Model._共耗费用登记 model)
        {
            StringBuilder strSql  = new StringBuilder();
            StringBuilder strSql1 = new StringBuilder();
            StringBuilder strSql2 = new StringBuilder();

            if (model.费用类型 != null)
            {
                strSql1.Append("费用类型,");
                strSql2.Append("'" + model.费用类型 + "',");
            }
            if (model.会计期间 != null)
            {
                strSql1.Append("会计期间,");
                strSql2.Append("'" + model.会计期间 + "',");
            }
            if (model.金额 != null)
            {
                strSql1.Append("金额,");
                strSql2.Append("" + model.金额 + ",");
            }
            if (model.备注 != null)
            {
                strSql1.Append("备注,");
                strSql2.Append("'" + model.备注 + "',");
            }
            if (model.制单人 != null)
            {
                strSql1.Append("制单人,");
                strSql2.Append("'" + model.制单人 + "',");
            }
            if (model.制单日期 != null)
            {
                strSql1.Append("制单日期,");
                strSql2.Append("'" + model.制单日期 + "',");
            }
            if (model.修改人 != null)
            {
                strSql1.Append("修改人,");
                strSql2.Append("'" + model.修改人 + "',");
            }
            if (model.修改日期 != null)
            {
                strSql1.Append("修改日期,");
                strSql2.Append("'" + model.修改日期 + "',");
            }
            if (model.审核人 != null)
            {
                strSql1.Append("审核人,");
                strSql2.Append("'" + model.审核人 + "',");
            }
            if (model.审核日期 != null)
            {
                strSql1.Append("审核日期,");
                strSql2.Append("'" + model.审核日期 + "',");
            }
            if (model.记账人 != null)
            {
                strSql1.Append("记账人,");
                strSql2.Append("'" + model.记账人 + "',");
            }
            if (model.记账日期 != null)
            {
                strSql1.Append("记账日期,");
                strSql2.Append("'" + model.记账日期 + "',");
            }
            strSql.Append("insert into _共耗费用登记(");
            strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1));
            strSql.Append(")");
            strSql.Append(" values (");
            strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1));
            strSql.Append(")");
            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会计期间 = lookUpEdit会计期间.EditValue.ToString().Trim();
                    if (s会计期间 == "")
                    {
                        lookUpEdit会计期间.Focus();
                        throw new Exception("会计期间不能为空");
                    }


                    string sSQL = "select count(1) from _共耗费用登记 where 会计期间 = '111111' and isnull(审核人,'') <> ''";
                    sSQL = sSQL.Replace("111111", s会计期间);
                    int iCount = BaseFunction.ReturnInt(DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0].Rows[0][0]);
                    if (iCount > 0)
                    {
                        throw new Exception("已经审核不能修改");
                    }

                    for (int i = 0; i < gridView1.RowCount; i++)
                    {
                        decimal d金额 = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridCol金额), 2);
                        if (d金额 < 0)
                        {
                            sErr = sErr + "行" + (i + 1).ToString() + "金额不能小于0\n";
                            continue;
                        }

                        Model._共耗费用登记 model = new UFIDA.U8.UAP.CustomApp.ControlForm.Model._共耗费用登记();
                        model.备注   = gridView1.GetRowCellValue(i, gridCol备注).ToString().Trim();
                        model.费用类型 = gridView1.GetRowCellValue(i, gridCol费用类型).ToString().Trim();
                        model.会计期间 = lookUpEdit会计期间.EditValue.ToString().Trim();
                        model.金额   = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridCol金额), 2);

                        DAL._共耗费用登记 dal = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL._共耗费用登记();

                        sSQL = "select * from _共耗费用登记 where 会计期间 = '111111' and isnull(费用类型,'') = '" + gridView1.GetRowCellValue(i, gridCol费用类型).ToString().Trim() + "'";
                        sSQL = sSQL.Replace("111111", s会计期间);
                        DataTable dt = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                        if (dt == null || dt.Rows.Count == 0)
                        {
                            model.制单人  = sUserName;
                            model.制单日期 = DateTime.Now;
                            sSQL       = dal.Add(model);
                        }
                        else
                        {
                            model.制单人  = gridView1.GetRowCellValue(i, gridCol制单人).ToString().Trim();
                            model.制单日期 = BaseFunction.ReturnDate(gridView1.GetRowCellValue(i, gridCol制单日期));
                            model.修改人  = sUserName;
                            model.修改日期 = DateTime.Now;
                            sSQL       = dal.Update(model);
                        }
                        iCou = iCou + DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                    }

                    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();
            }
        }
예제 #3
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public string Update(UFIDA.U8.UAP.CustomApp.ControlForm.Model._共耗费用登记 model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update _共耗费用登记 set ");
            if (model.金额 != null)
            {
                strSql.Append("金额=" + model.金额 + ",");
            }
            else
            {
                strSql.Append("金额= null ,");
            }
            if (model.备注 != null)
            {
                strSql.Append("备注='" + model.备注 + "',");
            }
            else
            {
                strSql.Append("备注= null ,");
            }
            if (model.制单人 != null)
            {
                strSql.Append("制单人='" + model.制单人 + "',");
            }
            else
            {
                strSql.Append("制单人= null ,");
            }
            if (model.制单日期 != null)
            {
                strSql.Append("制单日期='" + model.制单日期 + "',");
            }
            else
            {
                strSql.Append("制单日期= null ,");
            }
            if (model.修改人 != null)
            {
                strSql.Append("修改人='" + model.修改人 + "',");
            }
            else
            {
                strSql.Append("修改人= null ,");
            }
            if (model.修改日期 != null)
            {
                strSql.Append("修改日期='" + model.修改日期 + "',");
            }
            else
            {
                strSql.Append("修改日期= null ,");
            }
            if (model.审核人 != null)
            {
                strSql.Append("审核人='" + model.审核人 + "',");
            }
            else
            {
                strSql.Append("审核人= null ,");
            }
            if (model.审核日期 != null)
            {
                strSql.Append("审核日期='" + model.审核日期 + "',");
            }
            else
            {
                strSql.Append("审核日期= null ,");
            }
            if (model.记账人 != null)
            {
                strSql.Append("记账人='" + model.记账人 + "',");
            }
            else
            {
                strSql.Append("记账人= null ,");
            }
            if (model.记账日期 != null)
            {
                strSql.Append("记账日期='" + model.记账日期 + "',");
            }
            else
            {
                strSql.Append("记账日期= null ,");
            }
            int n = strSql.ToString().LastIndexOf(",");

            strSql.Remove(n, 1);
            strSql.Append(" where 费用类型='" + model.费用类型 + "' and 会计期间='" + model.会计期间 + "' ");
            return(strSql.ToString());
        }