/// <summary> /// 增加一条数据 /// </summary> public string Add(TH.clsU8.Model.RdRecord08 model) { StringBuilder strSql = new StringBuilder(); StringBuilder strSql1 = new StringBuilder(); StringBuilder strSql2 = new StringBuilder(); if (model.ID != null) { strSql1.Append("ID,"); strSql2.Append("" + model.ID + ","); } if (model.bRdFlag != null) { strSql1.Append("bRdFlag,"); strSql2.Append("" + model.bRdFlag + ","); } if (model.cVouchType != null) { strSql1.Append("cVouchType,"); strSql2.Append("'" + model.cVouchType + "',"); } if (model.cBusType != null) { strSql1.Append("cBusType,"); strSql2.Append("'" + model.cBusType + "',"); } if (model.cSource != null) { strSql1.Append("cSource,"); strSql2.Append("'" + model.cSource + "',"); } if (model.cBusCode != null) { strSql1.Append("cBusCode,"); strSql2.Append("'" + model.cBusCode + "',"); } if (model.cWhCode != null) { strSql1.Append("cWhCode,"); strSql2.Append("'" + model.cWhCode + "',"); } if (model.dDate != null) { strSql1.Append("dDate,"); strSql2.Append("'" + model.dDate + "',"); } if (model.cCode != null) { strSql1.Append("cCode,"); strSql2.Append("'" + model.cCode + "',"); } if (model.cRdCode != null) { strSql1.Append("cRdCode,"); strSql2.Append("'" + model.cRdCode + "',"); } if (model.cDepCode != null) { strSql1.Append("cDepCode,"); strSql2.Append("'" + model.cDepCode + "',"); } if (model.cPersonCode != null) { strSql1.Append("cPersonCode,"); strSql2.Append("'" + model.cPersonCode + "',"); } if (model.cPTCode != null) { strSql1.Append("cPTCode,"); strSql2.Append("'" + model.cPTCode + "',"); } if (model.cSTCode != null) { strSql1.Append("cSTCode,"); strSql2.Append("'" + model.cSTCode + "',"); } if (model.cCusCode != null) { strSql1.Append("cCusCode,"); strSql2.Append("'" + model.cCusCode + "',"); } if (model.cVenCode != null) { strSql1.Append("cVenCode,"); strSql2.Append("'" + model.cVenCode + "',"); } if (model.cOrderCode != null) { strSql1.Append("cOrderCode,"); strSql2.Append("'" + model.cOrderCode + "',"); } if (model.cARVCode != null) { strSql1.Append("cARVCode,"); strSql2.Append("'" + model.cARVCode + "',"); } if (model.cBillCode != null) { strSql1.Append("cBillCode,"); strSql2.Append("" + model.cBillCode + ","); } if (model.cDLCode != null) { strSql1.Append("cDLCode,"); strSql2.Append("" + model.cDLCode + ","); } if (model.cProBatch != null) { strSql1.Append("cProBatch,"); strSql2.Append("'" + model.cProBatch + "',"); } if (model.cHandler != null) { strSql1.Append("cHandler,"); strSql2.Append("'" + model.cHandler + "',"); } if (model.cMemo != null) { strSql1.Append("cMemo,"); strSql2.Append("'" + model.cMemo + "',"); } if (model.bTransFlag != null) { strSql1.Append("bTransFlag,"); strSql2.Append("" + (model.bTransFlag ? 1 : 0) + ","); } if (model.cAccounter != null) { strSql1.Append("cAccounter,"); strSql2.Append("'" + model.cAccounter + "',"); } if (model.cMaker != null) { strSql1.Append("cMaker,"); strSql2.Append("'" + model.cMaker + "',"); } if (model.cDefine1 != null) { strSql1.Append("cDefine1,"); strSql2.Append("'" + model.cDefine1 + "',"); } if (model.cDefine2 != null) { strSql1.Append("cDefine2,"); strSql2.Append("'" + model.cDefine2 + "',"); } if (model.cDefine3 != null) { strSql1.Append("cDefine3,"); strSql2.Append("'" + model.cDefine3 + "',"); } if (model.cDefine4 != null) { strSql1.Append("cDefine4,"); strSql2.Append("'" + model.cDefine4 + "',"); } if (model.cDefine5 != null) { strSql1.Append("cDefine5,"); strSql2.Append("" + model.cDefine5 + ","); } if (model.cDefine6 != null) { strSql1.Append("cDefine6,"); strSql2.Append("'" + model.cDefine6 + "',"); } if (model.cDefine7 != null) { strSql1.Append("cDefine7,"); strSql2.Append("" + model.cDefine7 + ","); } if (model.cDefine8 != null) { strSql1.Append("cDefine8,"); strSql2.Append("'" + model.cDefine8 + "',"); } if (model.cDefine9 != null) { strSql1.Append("cDefine9,"); strSql2.Append("'" + model.cDefine9 + "',"); } if (model.cDefine10 != null) { strSql1.Append("cDefine10,"); strSql2.Append("'" + model.cDefine10 + "',"); } if (model.dKeepDate != null) { strSql1.Append("dKeepDate,"); strSql2.Append("'" + model.dKeepDate + "',"); } if (model.dVeriDate != null) { strSql1.Append("dVeriDate,"); strSql2.Append("'" + model.dVeriDate + "',"); } if (model.bpufirst != null) { strSql1.Append("bpufirst,"); strSql2.Append("" + (model.bpufirst ? 1 : 0) + ","); } if (model.biafirst != null) { strSql1.Append("biafirst,"); strSql2.Append("" + (model.biafirst ? 1 : 0) + ","); } if (model.iMQuantity != null) { strSql1.Append("iMQuantity,"); strSql2.Append("" + model.iMQuantity + ","); } if (model.dARVDate != null) { strSql1.Append("dARVDate,"); strSql2.Append("'" + model.dARVDate + "',"); } if (model.cChkCode != null) { strSql1.Append("cChkCode,"); strSql2.Append("'" + model.cChkCode + "',"); } if (model.dChkDate != null) { strSql1.Append("dChkDate,"); strSql2.Append("'" + model.dChkDate + "',"); } if (model.cChkPerson != null) { strSql1.Append("cChkPerson,"); strSql2.Append("'" + model.cChkPerson + "',"); } if (model.VT_ID != null) { strSql1.Append("VT_ID,"); strSql2.Append("" + model.VT_ID + ","); } if (model.bIsSTQc != null) { strSql1.Append("bIsSTQc,"); strSql2.Append("" + (model.bIsSTQc ? 1 : 0) + ","); } if (model.cDefine11 != null) { strSql1.Append("cDefine11,"); strSql2.Append("'" + model.cDefine11 + "',"); } if (model.cDefine12 != null) { strSql1.Append("cDefine12,"); strSql2.Append("'" + model.cDefine12 + "',"); } if (model.cDefine13 != null) { strSql1.Append("cDefine13,"); strSql2.Append("'" + model.cDefine13 + "',"); } if (model.cDefine14 != null) { strSql1.Append("cDefine14,"); strSql2.Append("'" + model.cDefine14 + "',"); } if (model.cDefine15 != null) { strSql1.Append("cDefine15,"); strSql2.Append("" + model.cDefine15 + ","); } if (model.cDefine16 != null) { strSql1.Append("cDefine16,"); strSql2.Append("" + model.cDefine16 + ","); } if (model.gspcheck != null) { strSql1.Append("gspcheck,"); strSql2.Append("'" + model.gspcheck + "',"); } //if (model.ufts != null) //{ // strSql1.Append("ufts,"); // strSql2.Append("" + model.ufts + ","); //} if (model.iExchRate != null) { strSql1.Append("iExchRate,"); strSql2.Append("" + model.iExchRate + ","); } if (model.cExch_Name != null) { strSql1.Append("cExch_Name,"); strSql2.Append("'" + model.cExch_Name + "',"); } if (model.bOMFirst != null) { strSql1.Append("bOMFirst,"); strSql2.Append("" + (model.bOMFirst ? 1 : 0) + ","); } if (model.bFromPreYear != null) { strSql1.Append("bFromPreYear,"); strSql2.Append("" + (model.bFromPreYear ? 1 : 0) + ","); } if (model.bIsLsQuery != null) { strSql1.Append("bIsLsQuery,"); strSql2.Append("" + (model.bIsLsQuery ? 1 : 0) + ","); } if (model.bIsComplement != null) { strSql1.Append("bIsComplement,"); strSql2.Append("" + model.bIsComplement + ","); } if (model.iDiscountTaxType != null) { strSql1.Append("iDiscountTaxType,"); strSql2.Append("" + model.iDiscountTaxType + ","); } if (model.ireturncount != null) { strSql1.Append("ireturncount,"); strSql2.Append("" + model.ireturncount + ","); } if (model.iverifystate != null) { strSql1.Append("iverifystate,"); strSql2.Append("" + model.iverifystate + ","); } if (model.iswfcontrolled != null) { strSql1.Append("iswfcontrolled,"); strSql2.Append("" + model.iswfcontrolled + ","); } if (model.cModifyPerson != null) { strSql1.Append("cModifyPerson,"); strSql2.Append("'" + model.cModifyPerson + "',"); } if (model.dModifyDate != null) { strSql1.Append("dModifyDate,"); strSql2.Append("'" + model.dModifyDate + "',"); } //if (model.dnmaketime != null) //{ strSql1.Append("dnmaketime,"); strSql2.Append("getdate(),"); //} if (model.dnmodifytime != null) { strSql1.Append("dnmodifytime,"); strSql2.Append("'" + model.dnmodifytime + "',"); } //if (model.dnverifytime != null) //{ strSql1.Append("dnverifytime,"); strSql2.Append("'" + model.dnverifytime + "',"); //} if (model.bredvouch != null) { strSql1.Append("bredvouch,"); strSql2.Append("'" + model.bredvouch + "',"); } if (model.iFlowId != null) { strSql1.Append("iFlowId,"); strSql2.Append("" + model.iFlowId + ","); } if (model.cPZID != null) { strSql1.Append("cPZID,"); strSql2.Append("'" + model.cPZID + "',"); } if (model.cSourceLs != null) { strSql1.Append("cSourceLs,"); strSql2.Append("'" + model.cSourceLs + "',"); } if (model.cSourceCodeLs != null) { strSql1.Append("cSourceCodeLs,"); strSql2.Append("'" + model.cSourceCodeLs + "',"); } if (model.iPrintCount != null) { strSql1.Append("iPrintCount,"); strSql2.Append("" + model.iPrintCount + ","); } if (model.ctransflag != null) { strSql1.Append("ctransflag,"); strSql2.Append("'" + model.ctransflag + "',"); } if (model.csysbarcode != null) { strSql1.Append("csysbarcode,"); strSql2.Append("'" + model.csysbarcode + "',"); } if (model.cCurrentAuditor != null) { strSql1.Append("cCurrentAuditor,"); strSql2.Append("'" + model.cCurrentAuditor + "',"); } strSql.Append("insert into RdRecord08("); 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 { gridView1.PostEditor(); try { gridView1.FocusedRowHandle -= 1; gridView1.FocusedRowHandle += 1; } catch { } if (lookUpEditRd_Style.EditValue == null || lookUpEditRd_Style.EditValue.ToString().Trim() == "") { throw new Exception("Please choose inventory-in type"); } if (lookUpEditcWhCode.EditValue == null || lookUpEditcWhCode.EditValue.ToString().Trim() == "") { throw new Exception("Please choose warehouse"); } string sErr = ""; int iCount = 0; SqlConnection conn = new SqlConnection(sConnString); conn.Open(); //启用事务 SqlTransaction tran = conn.BeginTransaction(); try { string sSQL = "select getdate()"; DateTime dNow = BaseFunction.ReturnDate(DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0].Rows[0][0]); DateTime dNowDate = BaseFunction.ReturnDate(dNow.ToString("yyyy-MM-dd")); if (dtSOMain == null || dtSOMain.Rows.Count == 0) { throw new Exception("Sale Order not exists err"); } string sCTCode = dtSOMain.Rows[0]["cSTCode"].ToString().Trim(); sSQL = @" select a.cCode,b.cSoCode from rdrecord08 a inner join rdrecords08 b on a.id = b.id where b.cSoCode = 'aaaaaa' "; sSQL = sSQL.Replace("aaaaaa", s单据号); DataTable dt = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0]; if (dt != null && dt.Rows.Count > 0) { throw new Exception("exist \n" + dt.Rows[0]["cCode"].ToString().Trim()); } DateTime dDate = BaseFunction.ReturnDate(dtSOMain.Rows[0]["dDate"]); sSQL = "select isnull(bflag_ST,0) as bflag from GL_mend where iYPeriod = '" + dDate.ToString("yyyyMM") + "'"; dt = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0]; if (dt == null || dt.Rows.Count == 0) { throw new Exception("Access module state failure"); } int i结账 = BaseFunction.ReturnInt(dt.Rows[0]["bflag"]); if (i结账 > 0) { throw new Exception(dDate.ToString("yyyy-MM") + " have checked out"); } //获得单据号 sSQL = "select cNumber from VoucherHistory with (ROWLOCK) WHERE (CardNumber = '0301') AND (cContent = '日期') AND (cContentRule = 'YYYY') AND (cSeed = 'aaaaaa')"; sSQL = sSQL.Replace("aaaaaa", dDate.ToString("yyyy")); dt = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0]; long lCodeRD = 0; if (dt != null && dt.Rows.Count > 0) { lCodeRD = BaseFunction.ReturnLong(dt.Rows[0]["cNumber"]); } else { lCodeRD = 0; } long lID = -1; long lIDRDDetails = -1; sSQL = @" declare @p5 int set @p5=aaaaaa declare @p6 int set @p6=bbbbbb exec sp_GetId N'00',N'dddddd',N'rd',cccccc,@p5 output,@p6 output,default select @p5, @p6 "; sSQL = sSQL.Replace("aaaaaa", lID.ToString()); sSQL = sSQL.Replace("bbbbbb", lIDRDDetails.ToString()); sSQL = sSQL.Replace("cccccc", 1.ToString()); sSQL = sSQL.Replace("dddddd", s数据库.Substring(7, 3)); dt = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0]; lID = BaseFunction.ReturnLong(dt.Rows[0][0]) - 1; lIDRDDetails = BaseFunction.ReturnLong(dt.Rows[0][1]) - 1; //ArrayList aList = new ArrayList(); TH.clsU8.Model.RdRecord08 model = new TH.clsU8.Model.RdRecord08(); lID += 1; model.ID = lID; model.bRdFlag = 1; model.cVouchType = "08"; model.cBusType = "其他入库"; model.cSource = "库存"; //model.cBusCode = model.cWhCode = lookUpEditcWhCode.EditValue.ToString().Trim(); //需要仓库默认值 model.dDate = dDate; //需要默认值 lCodeRD += 1; string sCodeRD = lCodeRD.ToString(); while (sCodeRD.Length < 6) { sCodeRD = "0" + sCodeRD; } model.cCode = "MI" + model.dDate.Year.ToString() + sCodeRD; model.cRdCode = lookUpEditRd_Style.EditValue.ToString().Trim(); //需要默认值 //model.cDepCode = "" //model.cPersonCode; //model.cPTCode; //model.cSTCode; //model.cCusCode; //model.cVenCode; //model.cOrderCode; //model.cARVCode; //model.cBillCode; //model.cDLCode; //model.cProBatch; model.cHandler = sUserName; //model.cMemo; model.bTransFlag = false; //model.cAccounter; model.cMaker = sUserName; model.cDefine1 = dtSOMain.Rows[0]["cDefine1"].ToString(); model.cDefine2 = dtSOMain.Rows[0]["cDefine2"].ToString(); model.cDefine3 = dtSOMain.Rows[0]["cDefine3"].ToString(); if (dtSOMain.Rows[0]["cDefine4"].ToString().Trim() != "") { model.cDefine4 = BaseFunction.ReturnDate(dtSOMain.Rows[0]["cDefine4"]); } if (dtSOMain.Rows[0]["cDefine5"].ToString().Trim() != "") { model.cDefine5 = BaseFunction.ReturnLong(dtSOMain.Rows[0]["cDefine5"]); } if (dtSOMain.Rows[0]["cDefine6"].ToString().Trim() != "") { model.cDefine6 = BaseFunction.ReturnDate(dtSOMain.Rows[0]["cDefine6"]); } if (dtSOMain.Rows[0]["cDefine7"].ToString().Trim() != "") { model.cDefine7 = BaseFunction.ReturnDecimal(dtSOMain.Rows[0]["cDefine7"]); } model.cDefine8 = dtSOMain.Rows[0]["cDefine8"].ToString(); model.cDefine9 = dtSOMain.Rows[0]["cDefine9"].ToString(); model.cDefine10 = dtSOMain.Rows[0]["cDefine10"].ToString(); //model.dKeepDate; model.dVeriDate = dDate; model.bpufirst = false; model.biafirst = false; //model.iMQuantity; //model.dARVDate; //model.cChkCode; //model.dChkDate; //model.cChkPerson; model.VT_ID = 67; model.bIsSTQc = false; model.cDefine11 = dtSOMain.Rows[0]["cDefine11"].ToString(); model.cDefine12 = dtSOMain.Rows[0]["cDefine12"].ToString(); model.cDefine13 = dtSOMain.Rows[0]["cDefine13"].ToString(); //model.cDefine14 = dtSOMain.Rows[0]["cDefine14"].ToString(); model.cDefine14 = dtSOMain.Rows[0]["cSOCode"].ToString(); if (dtSOMain.Rows[0]["cDefine15"].ToString() != "") { model.cDefine15 = BaseFunction.ReturnLong(dtSOMain.Rows[0]["cDefine15"]); } if (dtSOMain.Rows[0]["cDefine16"].ToString() != "") { model.cDefine16 = BaseFunction.ReturnDecimal(dtSOMain.Rows[0]["cDefine16"]); } //model.gspcheck; //model.ufts; //model.iExchRate; //model.cExch_Name; model.bOMFirst = false; model.bFromPreYear = false; model.bIsLsQuery = false; model.bIsComplement = 0; model.iDiscountTaxType = 0; model.ireturncount = 0; model.iverifystate = 0; model.iswfcontrolled = 0; //model.cModifyPerson; //model.dModifyDate; //model.dnmaketime; //model.dnmodifytime; //model.dnverifytime; model.bredvouch = 0; //model.iFlowId; //model.cPZID; //model.cSourceLs; //model.cSourceCodeLs; model.iPrintCount = 0; //model.ctransflag; //model.csysbarcode; //model.cCurrentAuditor; TH.clsU8.DAL.RdRecord08 dal = new TH.clsU8.DAL.RdRecord08(); sSQL = dal.Add(model); DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); for (int i = 0; i < dtSOMain.Rows.Count; i++) { lIDRDDetails += 1; TH.clsU8.Model.rdrecords08 modelsRD = new TH.clsU8.Model.rdrecords08(); modelsRD.AutoID = lIDRDDetails; modelsRD.ID = model.ID; modelsRD.cInvCode = dtSOMain.Rows[i]["cInvCode"].ToString().Trim(); if (dtSOMain.Rows[i]["iNum"].ToString().Trim() != "") { modelsRD.iNum = BaseFunction.ReturnDecimal(dtSOMain.Rows[i]["iNum"]); } modelsRD.iQuantity = BaseFunction.ReturnDecimal(dtSOMain.Rows[i]["iQuantity"]); //modelsRD.iUnitCost; //modelsRD.iPrice; //modelsRD.iAPrice; //modelsRD.iPUnitCost; //modelsRD.iPPrice; bool bBatch = BaseFunction.ReturnBool(dtSOMain.Rows[i]["bInvBatch"]); if (bBatch) { modelsRD.cBatch = dtSOMain.Rows[i]["cDefine25"].ToString().Trim(); if (modelsRD.cBatch == "") { modelsRD.cBatch = dNow.ToString("yyyyMMdd"); } } //modelsRD.cVouchCode; //modelsRD.cInVouchCode; //modelsRD.cinvouchtype; //modelsRD.iSOutQuantity; //modelsRD.iSOutNum; //modelsRD.cFree1; //modelsRD.cFree2; modelsRD.iFlag = 0; //modelsRD.iFNum; //modelsRD.iFQuantity; //modelsRD.dVDate; //modelsRD.iTrIds; //modelsRD.cPosition; //modelsRD.cDefine22; //modelsRD.cDefine23; //modelsRD.cDefine24; //modelsRD.cDefine25; //modelsRD.cDefine26; //modelsRD.cDefine27; //modelsRD.cItem_class; //modelsRD.cItemCode; //modelsRD.cName; //modelsRD.cItemCName; //modelsRD.cFree3; //modelsRD.cFree4; //modelsRD.cFree5; //modelsRD.cFree6; //modelsRD.cFree7; //modelsRD.cFree8; //modelsRD.cFree9; //modelsRD.cFree10; //modelsRD.cBarCode; //modelsRD.iNQuantity; //modelsRD.iNNum; //modelsRD.cAssUnit; //modelsRD.dMadeDate; //modelsRD.iMassDate; //modelsRD.cDefine28; //modelsRD.cDefine29; //modelsRD.cDefine30; //modelsRD.cDefine31; //modelsRD.cDefine32; //modelsRD.cDefine33; //modelsRD.cDefine34; //modelsRD.cDefine35; //modelsRD.cDefine36; //modelsRD.cDefine37; //modelsRD.iCheckIds; //modelsRD.cBVencode; //modelsRD.chVencode; //modelsRD.bGsp; //modelsRD.cGspState; //modelsRD.cCheckCode; //modelsRD.iCheckIdBaks; //modelsRD.cRejectCode; //modelsRD.iRejectIds; //modelsRD.cCheckPersonCode; //modelsRD.dCheckDate; //modelsRD.cMassUnit; //modelsRD.bChecked; modelsRD.bLPUseFree = false; //modelsRD.iRSRowNO; //modelsRD.iOriTrackID; //modelsRD.coritracktype; //modelsRD.cbaccounter; //modelsRD.dbKeepDate; modelsRD.bCosting = true; modelsRD.bVMIUsed = false; //modelsRD.iVMISettleQuantity; //modelsRD.iVMISettleNum; //modelsRD.cvmivencode; //modelsRD.iInvSNCount; //modelsRD.cwhpersoncode; //modelsRD.cwhpersonname; //modelsRD.cserviceoid; //modelsRD.cbserviceoid; //modelsRD.iinvexchrate; //modelsRD.corufts; //modelsRD.strContractGUID; modelsRD.iExpiratDateCalcu = 0; //modelsRD.cExpirationdate; //modelsRD.dExpirationdate; //modelsRD.cciqbookcode; //modelsRD.iBondedSumQty; //modelsRD.iorderdid; modelsRD.iordertype = 0; //modelsRD.iordercode; //modelsRD.iorderseq; modelsRD.isodid = dtSOMain.Rows[i]["isosid"].ToString().Trim(); modelsRD.isotype = 0; modelsRD.csocode = s单据号; modelsRD.isoseq = BaseFunction.ReturnInt(dtSOMain.Rows[i]["iRowNo"]); //modelsRD.cBatchProperty1; //modelsRD.cBatchProperty2; //modelsRD.cBatchProperty3; //modelsRD.cBatchProperty4; //modelsRD.cBatchProperty5; //modelsRD.cBatchProperty6; //modelsRD.cBatchProperty7; //modelsRD.cBatchProperty8; //modelsRD.cBatchProperty9; //modelsRD.cBatchProperty10; //modelsRD.cbMemo; modelsRD.irowno = i + 1; //modelsRD.strowguid; //modelsRD.rowufts; //modelsRD.ipreuseqty; //modelsRD.ipreuseinum; //modelsRD.cbsourcecodels; //modelsRD.iGroupNO; //modelsRD.iDebitIDs; //modelsRD.idebitchildids; //modelsRD.OutCopiedQuantity; //modelsRD.cbsysbarcode TH.clsU8.DAL.rdrecords08 dalsRD = new TH.clsU8.DAL.rdrecords08(); sSQL = dalsRD.Add(modelsRD); iCount = iCount + DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); sSQL = @" if exists (select * from CurrentStock where cInvCode = '@cInvCode' and cWhCode = '@cWhCode' and isnull(cFree1,'') = @cFree1 and isnull(cFree2,'') = @cFree2 and isnull(cFree3,'') = @cFree3 and isnull(cFree4,'') = @cFree4 and isnull(cFree5,'') = @cFree5 and isnull(cFree6,'') = @cFree6 and isnull(cFree7,'') = @cFree7 and isnull(cFree8,'') = @cFree8 and isnull(cFree9,'') = @cFree9 and isnull(cFree10,'') = @cFree10 and isnull(cBatch,'') = @cBatch ) update CurrentStock set iQuantity = isnull(iQuantity,0) + @iQuantity where cInvCode = '@cInvCode' and cWhCode = '@cWhCode' and isnull(cFree1,'') = @cFree1 and isnull(cFree2,'') = @cFree2 and isnull(cFree3,'') = @cFree3 and isnull(cFree4,'') = @cFree4 and isnull(cFree5,'') = @cFree5 and isnull(cFree6,'') = @cFree6 and isnull(cFree7,'') = @cFree7 and isnull(cFree8,'') = @cFree8 and isnull(cFree9,'') = @cFree9 and isnull(cFree10,'') = @cFree10 and isnull(cBatch,'') = @cBatch else begin declare @itemid varchar(20); declare @iCount int; select @iCount=count(itemid) from CurrentStock where cInvCode = '@cInvCode'; if( @iCount > 0 ) select @itemid=itemid from CurrentStock where cInvCode = '@cInvCode'; else select @itemid=max(itemid+1) from CurrentStock insert into CurrentStock(cWhCode,cInvCode,iQuantity,itemid, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10,cBatch,iSoDid) values('@cWhCode','@cInvCode', @iQuantity,isnull(@itemid,1), @cFree1, @cFree2, @cFree3, @cFree4, @cFree5, @cFree6, @cFree7, @cFree8, @cFree9, @cFree10,@cBatch,'') end "; sSQL = sSQL.Replace("@cInvCode", modelsRD.cInvCode); sSQL = sSQL.Replace("@cWhCode", model.cWhCode); sSQL = sSQL.Replace("@iQuantity", modelsRD.iQuantity.ToString()); sSQL = sSQL.Replace("@iNum", modelsRD.iNum.ToString()); sSQL = sSQL.Replace("@cFree10", modelsRD.cFree10 == null ? "''" : "'" + modelsRD.cFree10 + "'"); sSQL = sSQL.Replace("@cFree1", modelsRD.cFree1 == null ? "''" : "'" + modelsRD.cFree1 + "'"); sSQL = sSQL.Replace("@cFree2", modelsRD.cFree2 == null ? "''" : "'" + modelsRD.cFree2 + "'"); sSQL = sSQL.Replace("@cFree3", modelsRD.cFree3 == null ? "''" : "'" + modelsRD.cFree3 + "'"); sSQL = sSQL.Replace("@cFree4", modelsRD.cFree4 == null ? "''" : "'" + modelsRD.cFree4 + "'"); sSQL = sSQL.Replace("@cFree5", modelsRD.cFree5 == null ? "''" : "'" + modelsRD.cFree5 + "'"); sSQL = sSQL.Replace("@cFree6", modelsRD.cFree6 == null ? "''" : "'" + modelsRD.cFree6 + "'"); sSQL = sSQL.Replace("@cFree7", modelsRD.cFree7 == null ? "''" : "'" + modelsRD.cFree7 + "'"); sSQL = sSQL.Replace("@cFree8", modelsRD.cFree8 == null ? "''" : "'" + modelsRD.cFree8 + "'"); sSQL = sSQL.Replace("@cFree9", modelsRD.cFree9 == null ? "''" : "'" + modelsRD.cFree9 + "'"); sSQL = sSQL.Replace("@cBatch", modelsRD.cBatch == null ? "''" : "'" + modelsRD.cBatch + "'"); DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); } if (sErr != "") { throw new Exception(sErr); } sSQL = @" exec ST_SaveForStock N'08',N'aaaaaa',1,0 ,1 "; sSQL = sSQL.Replace("aaaaaa", lID.ToString()); DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); sSQL = @" exec ST_SaveForTrackStock N'08',N'aaaaaa', 0 ,1 "; sSQL = sSQL.Replace("aaaaaa", lID.ToString()); DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); sSQL = @" exec IA_SP_WriteUnAccountVouchForST 'aaaaaa',N'08' "; sSQL = sSQL.Replace("aaaaaa", lID.ToString()); DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); if (lID > 1000000000) { lID = lID - 1000000000; } if (lIDRDDetails > 1000000000) { lIDRDDetails = lIDRDDetails - 1000000000; } sSQL = "update UFSystem..UA_Identity set iFatherId = " + lID.ToString() + ",iChildId = " + lIDRDDetails + " where cAcc_Id = '" + s数据库.Substring(7, 3) + "' and cVouchType = 'rd'"; DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); sSQL = @" if exists(select * from VoucherHistory where (CardNumber = '0301') AND (cContent = '日期') AND (cContentRule = 'YYYY') AND (cSeed = 'bbbbbb')) update VoucherHistory set cNumber = aaaaaa where (CardNumber = '0301') AND (cContent = '日期') AND (cContentRule = 'YYYY') AND (cSeed = 'bbbbbb') else insert into VoucherHistory(CardNumber,cContent,cContentRule,cSeed,cNumber,bEmpty) values('0301','日期','YYYY','bbbbbb','1',0) "; sSQL = sSQL.Replace("aaaaaa", lCodeRD.ToString()); sSQL = sSQL.Replace("bbbbbb", model.dDate.ToString("yyyy")); DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); if (iCount > 0) { tran.Commit(); MessageBox.Show("OK\n" + model.cCode); this.Close(); } else { throw new Exception("Save failed"); } } catch (Exception error) { tran.Rollback(); throw new Exception(error.Message); } } catch (Exception ee) { MessageBox.Show(ee.Message); } }