/// <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.审核人 + "',"); } 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()); }
private void btnSave_Click(object sender, EventArgs e) { try { try { gridView1.FocusedRowHandle -= 1; gridView1.FocusedRowHandle += 1; } catch { } if (gridView1.RowCount <= 0) { throw new Exception("请设置数据后处理"); } if (BaseFunction.ReturnDecimal(txt仪表.Text.Trim()) != BaseFunction.ReturnDecimal(gridView1.Columns["仪表金额"].SummaryItem.SummaryValue) || BaseFunction.ReturnDecimal(txt环保.Text.Trim()) != BaseFunction.ReturnDecimal(gridView1.Columns["环保金额"].SummaryItem.SummaryValue) || BaseFunction.ReturnDecimal(txt机修.Text.Trim()) != BaseFunction.ReturnDecimal(gridView1.Columns["机修金额"].SummaryItem.SummaryValue) ) { throw new Exception("请重新计算后保存"); } 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("已经审核不能修改"); } sSQL = "delete _辅助费用分配 where 会计期间 = '111111'"; sSQL = sSQL.Replace("111111", s会计期间); DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); for (int i = 0; i < gridView1.RowCount; i++) { Model._辅助费用分配 model = new UFIDA.U8.UAP.CustomApp.ControlForm.Model._辅助费用分配(); model.部门编码 = gridView1.GetRowCellValue(i, gridCol部门编码).ToString().Trim(); model.仪表工时 = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridCol仪表工时), 2); model.仪表金额 = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridCol仪表金额), 2); model.机修工时 = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridCol机修工时), 2); model.机修金额 = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridCol机修金额), 2); model.环保工时 = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridCol环保工时), 2); model.环保金额 = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridCol环保金额), 2); model.合计 = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridCol合计), 2); model.会计期间 = s会计期间; model.制单人 = sUserName; model.制单日期 = DateTime.Now; DAL._辅助费用分配 dal = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL._辅助费用分配(); sSQL = dal.Add(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(); } }