/// <summary> /// 增加一条数据 /// </summary> public string Add(UFIDA.U8.UAP.CustomApp.ControlForm.Model._高开返利单_SZ model) { StringBuilder strSql = new StringBuilder(); StringBuilder strSql1 = new StringBuilder(); StringBuilder strSql2 = new StringBuilder(); if (model.cCode != null) { strSql1.Append("cCode,"); strSql2.Append("'" + model.cCode + "',"); } if (model.dtmDate != null) { strSql1.Append("dtmDate,"); strSql2.Append("'" + model.dtmDate + "',"); } if (model.FPIDs != null) { strSql1.Append("FPIDs,"); strSql2.Append("" + model.FPIDs + ","); } if (model.cSBVCode != null) { strSql1.Append("cSBVCode,"); strSql2.Append("'" + model.cSBVCode + "',"); } if (model.dDate != null) { strSql1.Append("dDate,"); strSql2.Append("'" + model.dDate + "',"); } if (model.cPersonCode != null) { strSql1.Append("cPersonCode,"); strSql2.Append("'" + model.cPersonCode + "',"); } if (model.cPersonName != null) { strSql1.Append("cPersonName,"); strSql2.Append("'" + model.cPersonName + "',"); } if (model.cDepCode != null) { strSql1.Append("cDepCode,"); strSql2.Append("'" + model.cDepCode + "',"); } if (model.cDepName != null) { strSql1.Append("cDepName,"); strSql2.Append("'" + model.cDepName + "',"); } if (model.cCusCode != null) { strSql1.Append("cCusCode,"); strSql2.Append("'" + model.cCusCode + "',"); } if (model.cCusName != null) { strSql1.Append("cCusName,"); strSql2.Append("'" + model.cCusName + "',"); } if (model.cCusAbbName != null) { strSql1.Append("cCusAbbName,"); strSql2.Append("'" + model.cCusAbbName + "',"); } if (model.cInvCode != null) { strSql1.Append("cInvCode,"); strSql2.Append("'" + model.cInvCode + "',"); } if (model.cInvAddCode != null) { strSql1.Append("cInvAddCode,"); strSql2.Append("'" + model.cInvAddCode + "',"); } if (model.cInvName != null) { strSql1.Append("cInvName,"); strSql2.Append("'" + model.cInvName + "',"); } if (model.cInvStd != null) { strSql1.Append("cInvStd,"); strSql2.Append("'" + model.cInvStd + "',"); } if (model.iTaxUnitPrice != null) { strSql1.Append("iTaxUnitPrice,"); strSql2.Append("" + model.iTaxUnitPrice + ","); } if (model.iQuantity != null) { strSql1.Append("iQuantity,"); strSql2.Append("" + model.iQuantity + ","); } if (model.iSum != null) { strSql1.Append("iSum,"); strSql2.Append("" + model.iSum + ","); } if (model.cDLCode != null) { strSql1.Append("cDLCode,"); strSql2.Append("'" + model.cDLCode + "',"); } if (model.iTaxUnitPriceFH != null) { strSql1.Append("iTaxUnitPriceFH,"); strSql2.Append("" + model.iTaxUnitPriceFH + ","); } if (model.iTaxRateCJ != null) { strSql1.Append("iTaxRateCJ,"); strSql2.Append("" + model.iTaxRateCJ + ","); } if (model.iTaxCJ != null) { strSql1.Append("iTaxCJ,"); strSql2.Append("" + model.iTaxCJ + ","); } if (model.iMoneyFL != null) { strSql1.Append("iMoneyFL,"); strSql2.Append("" + model.iMoneyFL + ","); } if (model.createUid != null) { strSql1.Append("createUid,"); strSql2.Append("'" + model.createUid + "',"); } if (model.dtmCreate != null) { strSql1.Append("dtmCreate,"); strSql2.Append("'" + model.dtmCreate + "',"); } if (model.auditUid != null) { strSql1.Append("auditUid,"); strSql2.Append("'" + model.auditUid + "',"); } if (model.dtmAudit != null) { strSql1.Append("dtmAudit,"); strSql2.Append("'" + model.dtmAudit + "',"); } if (model.Remark != null) { strSql1.Append("Remark,"); strSql2.Append("'" + model.Remark + "',"); } if (model.DLS != null) { strSql1.Append("DLS,"); strSql2.Append("'" + model.DLS + "',"); } if (model.DLSName != null) { strSql1.Append("DLSName,"); strSql2.Append("'" + model.DLSName + "',"); } if (model.sGUID != null) { strSql1.Append("GUID,"); strSql2.Append("'" + model.sGUID + "',"); } if (model.bRed != null) { strSql1.Append("bRed,"); if (Convert.ToBoolean(model.bRed)) { strSql2.Append("1,"); } else { strSql2.Append("0,"); } } strSql.Append("insert into _高开返利单_SZ("); 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()); }
private void btnSave_Click(object sender, EventArgs e) { try { try { gridView1.FocusedRowHandle -= 1; gridView1.FocusedRowHandle += 1; } catch { } int iCou = 0; string sErr = ""; string s_Guid = Guid.NewGuid().ToString(); SqlConnection conn = new SqlConnection(DbHelperSQL.connectionString); conn.Open(); //启用事务 SqlTransaction tran = conn.BeginTransaction(); try { int iCode = 0; string sSQL = ""; if (txt单据号.Text.Trim() != "") { sSQL = @" select * from [dbo].[_高开返利单_SZ] where cCode = '{0}' "; sSQL = string.Format(sSQL, txt单据号.Text.Trim()); DataTable dt = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0]; if (dt == null || dt.Rows.Count == 0) { iCode = 0; } else { if (dt.Rows[0]["auditUid"].ToString().Trim() != "") { throw new Exception("单据已经审核"); } sSQL = @" delete [_高开返利单_SZ] where cCode = '{0}' "; sSQL = string.Format(sSQL, txt单据号.Text.Trim()); DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); } } sSQL = @" select max(cCode) as cCodeMax from [dbo].[_高开返利单_SZ] where cCode like '{0}%' "; sSQL = string.Format(sSQL, dtm.DateTime.ToString("yyyyMM")); DataTable dtCode = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0]; if (dtCode == null || dtCode.Rows.Count == 0 || dtCode.Rows[0]["cCodeMax"].ToString().Trim() == "") { iCode = 1; } else { string sCodeTemp = dtCode.Rows[0]["cCodeMax"].ToString().Trim(); string stemp = sCodeTemp.Substring(6); iCode = BaseFunction.ReturnInt(stemp) + 1; } string sCode = iCode.ToString().Trim(); sCode = dtm.DateTime.ToString("yyyyMM") + sCode.PadLeft(4, '0'); decimal?d金额 = 0; for (int i = 0; i < gridView1.RowCount; i++) { if (!BaseFunction.ReturnBool(gridView1.GetRowCellValue(i, gridCol选择))) { continue; } bool bRed = BaseFunction.ReturnBool(gridView1.GetRowCellValue(i, gridColbRed)); decimal d发货单价 = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridCol发货单价)); if (d发货单价 <= 0 && !bRed) { sErr = sErr + "行" + (i + 1).ToString() + "发货单价不正确\n"; continue; } Model._高开返利单_SZ mod = new UFIDA.U8.UAP.CustomApp.ControlForm.Model._高开返利单_SZ(); mod.cCode = sCode; mod.dtmDate = dtm.DateTime; mod.FPIDs = BaseFunction.ReturnInt(gridView1.GetRowCellValue(i, gridCol发票表体ID)); mod.cSBVCode = gridView1.GetRowCellValue(i, gridCol发票号).ToString().Trim(); mod.dDate = BaseFunction.ReturnDate(gridView1.GetRowCellValue(i, gridCol发票日期)); mod.cPersonCode = gridView1.GetRowCellValue(i, gridColcPersonCode).ToString().Trim(); mod.cPersonName = gridView1.GetRowCellValue(i, gridColcPersonName).ToString().Trim(); //mod.cPersonCode = lookUpEditcPersonCode.EditValue.ToString().Trim(); //mod.cPersonName = lookUpEditcPersonName.Text.Trim(); //mod.cDepCode = gridView1.GetRowCellValue(i, gridCol部门编号).ToString().Trim(); //mod.cDepName = gridView1.GetRowCellValue(i, gridCol部门名称).ToString().Trim(); mod.cCusCode = gridView1.GetRowCellValue(i, gridCol客户编码).ToString().Trim(); mod.cCusName = gridView1.GetRowCellValue(i, gridCol客户名称).ToString().Trim(); //mod.cCusAbbName = gridView1.GetRowCellValue(i, gridCol客户简称).ToString().Trim(); mod.cInvCode = gridView1.GetRowCellValue(i, gridCol存货编码).ToString().Trim(); mod.cInvAddCode = gridView1.GetRowCellValue(i, gridCol存货旧编码).ToString().Trim(); mod.cInvName = gridView1.GetRowCellValue(i, gridCol存货名称).ToString().Trim(); mod.cInvStd = gridView1.GetRowCellValue(i, gridCol规格型号).ToString().Trim(); mod.iTaxUnitPrice = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridCol单价)); mod.iQuantity = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridCol数量)); mod.iSum = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridCol金额)); mod.cDLCode = gridView1.GetRowCellValue(i, gridCol发货单号).ToString().Trim(); mod.iTaxUnitPriceFH = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridCol发货单价)); mod.iTaxRateCJ = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridCol差价税率)); mod.iTaxCJ = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridCol差价税额)); mod.iMoneyFL = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridCol返利金额)); mod.createUid = sUserID; mod.dtmCreate = BaseFunction.ReturnDate(sLogDate); mod.Remark = txt备注.Text.Trim(); mod.DLS = gridView1.GetRowCellValue(i, gridCol代理商编码).ToString().Trim(); mod.DLSName = gridView1.GetRowCellValue(i, gridCol代理商).ToString().Trim(); mod.sGUID = s_Guid; mod.bRed = BaseFunction.ReturnBool(gridView1.GetRowCellValue(i, gridColbRed)); DAL._高开返利单_SZ dal = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL._高开返利单_SZ(); sSQL = dal.Add(mod); iCou += DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); txt单据号.Text = mod.cCode; lookUpEdit_cPersonCode.EditValue = mod.cPersonCode; d金额 += mod.iMoneyFL; } if (sErr.Length > 0) { throw new Exception(sErr.Trim()); } if (iCou > 0) { tran.Commit(); MessageBox.Show("保存成功\n单据号:" + sCode); SetEnable(false); } else { throw new Exception("请选择需要保存的数据"); } } 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(); } }