Ejemplo n.º 1
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public string Add(DllForService.Model.DispatchLists model)
        {
            StringBuilder strSql  = new StringBuilder();
            StringBuilder strSql1 = new StringBuilder();
            StringBuilder strSql2 = new StringBuilder();

            if (model.DLID != null)
            {
                strSql1.Append("DLID,");
                strSql2.Append("" + model.DLID + ",");
            }
            if (model.iCorID != null)
            {
                strSql1.Append("iCorID,");
                strSql2.Append("" + model.iCorID + ",");
            }
            if (model.cWhCode != null)
            {
                strSql1.Append("cWhCode,");
                strSql2.Append("'" + model.cWhCode + "',");
            }
            if (model.cInvCode != null)
            {
                strSql1.Append("cInvCode,");
                strSql2.Append("'" + model.cInvCode + "',");
            }
            if (model.iQuantity != null)
            {
                strSql1.Append("iQuantity,");
                strSql2.Append("" + model.iQuantity + ",");
            }
            if (model.iNum != null)
            {
                strSql1.Append("iNum,");
                strSql2.Append("" + model.iNum + ",");
            }
            if (model.iQuotedPrice != null)
            {
                strSql1.Append("iQuotedPrice,");
                strSql2.Append("" + model.iQuotedPrice + ",");
            }
            if (model.iUnitPrice != null)
            {
                strSql1.Append("iUnitPrice,");
                strSql2.Append("" + model.iUnitPrice + ",");
            }
            if (model.iTaxUnitPrice != null)
            {
                strSql1.Append("iTaxUnitPrice,");
                strSql2.Append("" + model.iTaxUnitPrice + ",");
            }
            if (model.iMoney != null)
            {
                strSql1.Append("iMoney,");
                strSql2.Append("" + model.iMoney + ",");
            }
            if (model.iTax != null)
            {
                strSql1.Append("iTax,");
                strSql2.Append("" + model.iTax + ",");
            }
            if (model.iSum != null)
            {
                strSql1.Append("iSum,");
                strSql2.Append("" + model.iSum + ",");
            }
            if (model.iDisCount != null)
            {
                strSql1.Append("iDisCount,");
                strSql2.Append("" + model.iDisCount + ",");
            }
            if (model.iNatUnitPrice != null)
            {
                strSql1.Append("iNatUnitPrice,");
                strSql2.Append("" + model.iNatUnitPrice + ",");
            }
            if (model.iNatMoney != null)
            {
                strSql1.Append("iNatMoney,");
                strSql2.Append("" + model.iNatMoney + ",");
            }
            if (model.iNatTax != null)
            {
                strSql1.Append("iNatTax,");
                strSql2.Append("" + model.iNatTax + ",");
            }
            if (model.iNatSum != null)
            {
                strSql1.Append("iNatSum,");
                strSql2.Append("" + model.iNatSum + ",");
            }
            if (model.iNatDisCount != null)
            {
                strSql1.Append("iNatDisCount,");
                strSql2.Append("" + model.iNatDisCount + ",");
            }
            if (model.iSettleNum != null)
            {
                strSql1.Append("iSettleNum,");
                strSql2.Append("" + model.iSettleNum + ",");
            }
            if (model.iSettleQuantity != null)
            {
                strSql1.Append("iSettleQuantity,");
                strSql2.Append("" + model.iSettleQuantity + ",");
            }
            if (model.iBatch != null)
            {
                strSql1.Append("iBatch,");
                strSql2.Append("" + model.iBatch + ",");
            }
            if (model.cBatch != null)
            {
                strSql1.Append("cBatch,");
                strSql2.Append("'" + model.cBatch + "',");
            }
            if (model.bSettleAll != null)
            {
                strSql1.Append("bSettleAll,");
                strSql2.Append("" + (model.bSettleAll ? 1 : 0) + ",");
            }
            if (model.cMemo != null)
            {
                strSql1.Append("cMemo,");
                strSql2.Append("'" + model.cMemo + "',");
            }
            if (model.cFree1 != null)
            {
                strSql1.Append("cFree1,");
                strSql2.Append("'" + model.cFree1 + "',");
            }
            if (model.cFree2 != null)
            {
                strSql1.Append("cFree2,");
                strSql2.Append("'" + model.cFree2 + "',");
            }
            if (model.iTB != null)
            {
                strSql1.Append("iTB,");
                strSql2.Append("" + model.iTB + ",");
            }
            if (model.dvDate != null)
            {
                strSql1.Append("dvDate,");
                strSql2.Append("'" + model.dvDate + "',");
            }
            if (model.TBQuantity != null)
            {
                strSql1.Append("TBQuantity,");
                strSql2.Append("" + model.TBQuantity + ",");
            }
            if (model.TBNum != null)
            {
                strSql1.Append("TBNum,");
                strSql2.Append("" + model.TBNum + ",");
            }
            if (model.iSOsID != null)
            {
                strSql1.Append("iSOsID,");
                strSql2.Append("" + model.iSOsID + ",");
            }
            if (model.iDLsID != null)
            {
                strSql1.Append("iDLsID,");
                strSql2.Append("" + model.iDLsID + ",");
            }
            if (model.KL != null)
            {
                strSql1.Append("KL,");
                strSql2.Append("" + model.KL + ",");
            }
            if (model.KL2 != null)
            {
                strSql1.Append("KL2,");
                strSql2.Append("" + model.KL2 + ",");
            }
            if (model.cInvName != null)
            {
                strSql1.Append("cInvName,");
                strSql2.Append("'" + model.cInvName + "',");
            }
            if (model.iTaxRate != null)
            {
                strSql1.Append("iTaxRate,");
                strSql2.Append("" + model.iTaxRate + ",");
            }
            if (model.cDefine22 != null)
            {
                strSql1.Append("cDefine22,");
                strSql2.Append("'" + model.cDefine22 + "',");
            }
            if (model.cDefine23 != null)
            {
                strSql1.Append("cDefine23,");
                strSql2.Append("'" + model.cDefine23 + "',");
            }
            if (model.cDefine24 != null)
            {
                strSql1.Append("cDefine24,");
                strSql2.Append("'" + model.cDefine24 + "',");
            }
            if (model.cDefine25 != null)
            {
                strSql1.Append("cDefine25,");
                strSql2.Append("'" + model.cDefine25 + "',");
            }
            if (model.cDefine26 != null)
            {
                strSql1.Append("cDefine26,");
                strSql2.Append("" + model.cDefine26 + ",");
            }
            if (model.cDefine27 != null)
            {
                strSql1.Append("cDefine27,");
                strSql2.Append("" + model.cDefine27 + ",");
            }
            if (model.fOutQuantity != null)
            {
                strSql1.Append("fOutQuantity,");
                strSql2.Append("" + model.fOutQuantity + ",");
            }
            if (model.fOutNum != null)
            {
                strSql1.Append("fOutNum,");
                strSql2.Append("" + model.fOutNum + ",");
            }
            if (model.cItemCode != null)
            {
                strSql1.Append("cItemCode,");
                strSql2.Append("'" + model.cItemCode + "',");
            }
            if (model.cItem_class != null)
            {
                strSql1.Append("cItem_class,");
                strSql2.Append("'" + model.cItem_class + "',");
            }
            if (model.fSaleCost != null)
            {
                strSql1.Append("fSaleCost,");
                strSql2.Append("" + model.fSaleCost + ",");
            }
            if (model.fSalePrice != null)
            {
                strSql1.Append("fSalePrice,");
                strSql2.Append("" + model.fSalePrice + ",");
            }
            if (model.cVenAbbName != null)
            {
                strSql1.Append("cVenAbbName,");
                strSql2.Append("'" + model.cVenAbbName + "',");
            }
            if (model.cItemName != null)
            {
                strSql1.Append("cItemName,");
                strSql2.Append("'" + model.cItemName + "',");
            }
            if (model.cItem_CName != null)
            {
                strSql1.Append("cItem_CName,");
                strSql2.Append("'" + model.cItem_CName + "',");
            }
            if (model.cFree3 != null)
            {
                strSql1.Append("cFree3,");
                strSql2.Append("'" + model.cFree3 + "',");
            }
            if (model.cFree4 != null)
            {
                strSql1.Append("cFree4,");
                strSql2.Append("'" + model.cFree4 + "',");
            }
            if (model.cFree5 != null)
            {
                strSql1.Append("cFree5,");
                strSql2.Append("'" + model.cFree5 + "',");
            }
            if (model.cFree6 != null)
            {
                strSql1.Append("cFree6,");
                strSql2.Append("'" + model.cFree6 + "',");
            }
            if (model.cFree7 != null)
            {
                strSql1.Append("cFree7,");
                strSql2.Append("'" + model.cFree7 + "',");
            }
            if (model.cFree8 != null)
            {
                strSql1.Append("cFree8,");
                strSql2.Append("'" + model.cFree8 + "',");
            }
            if (model.cFree9 != null)
            {
                strSql1.Append("cFree9,");
                strSql2.Append("'" + model.cFree9 + "',");
            }
            if (model.cFree10 != null)
            {
                strSql1.Append("cFree10,");
                strSql2.Append("'" + model.cFree10 + "',");
            }
            if (model.bIsSTQc != null)
            {
                strSql1.Append("bIsSTQc,");
                strSql2.Append("" + (model.bIsSTQc ? 1 : 0) + ",");
            }
            if (model.iInvExchRate != null)
            {
                strSql1.Append("iInvExchRate,");
                strSql2.Append("" + model.iInvExchRate + ",");
            }
            if (model.cUnitID != null)
            {
                strSql1.Append("cUnitID,");
                strSql2.Append("'" + model.cUnitID + "',");
            }
            if (model.cCode != null)
            {
                strSql1.Append("cCode,");
                strSql2.Append("'" + model.cCode + "',");
            }
            if (model.iRetQuantity != null)
            {
                strSql1.Append("iRetQuantity,");
                strSql2.Append("" + model.iRetQuantity + ",");
            }
            if (model.fEnSettleQuan != null)
            {
                strSql1.Append("fEnSettleQuan,");
                strSql2.Append("" + model.fEnSettleQuan + ",");
            }
            if (model.fEnSettleSum != null)
            {
                strSql1.Append("fEnSettleSum,");
                strSql2.Append("" + model.fEnSettleSum + ",");
            }
            if (model.iSettlePrice != null)
            {
                strSql1.Append("iSettlePrice,");
                strSql2.Append("" + model.iSettlePrice + ",");
            }
            if (model.cDefine28 != null)
            {
                strSql1.Append("cDefine28,");
                strSql2.Append("'" + model.cDefine28 + "',");
            }
            if (model.cDefine29 != null)
            {
                strSql1.Append("cDefine29,");
                strSql2.Append("'" + model.cDefine29 + "',");
            }
            if (model.cDefine30 != null)
            {
                strSql1.Append("cDefine30,");
                strSql2.Append("'" + model.cDefine30 + "',");
            }
            if (model.cDefine31 != null)
            {
                strSql1.Append("cDefine31,");
                strSql2.Append("'" + model.cDefine31 + "',");
            }
            if (model.cDefine32 != null)
            {
                strSql1.Append("cDefine32,");
                strSql2.Append("'" + model.cDefine32 + "',");
            }
            if (model.cDefine33 != null)
            {
                strSql1.Append("cDefine33,");
                strSql2.Append("'" + model.cDefine33 + "',");
            }
            if (model.cDefine34 != null)
            {
                strSql1.Append("cDefine34,");
                strSql2.Append("" + model.cDefine34 + ",");
            }
            if (model.cDefine35 != null)
            {
                strSql1.Append("cDefine35,");
                strSql2.Append("" + model.cDefine35 + ",");
            }
            if (model.cDefine36 != null)
            {
                strSql1.Append("cDefine36,");
                strSql2.Append("'" + model.cDefine36 + "',");
            }
            if (model.cDefine37 != null)
            {
                strSql1.Append("cDefine37,");
                strSql2.Append("'" + model.cDefine37 + "',");
            }
            if (model.dMDate != null)
            {
                strSql1.Append("dMDate,");
                strSql2.Append("'" + model.dMDate + "',");
            }
            if (model.bGsp != null)
            {
                strSql1.Append("bGsp,");
                strSql2.Append("" + (model.bGsp ? 1 : 0) + ",");
            }
            if (model.cGspState != null)
            {
                strSql1.Append("cGspState,");
                strSql2.Append("'" + model.cGspState + "',");
            }
            if (model.cSoCode != null)
            {
                strSql1.Append("cSoCode,");
                strSql2.Append("'" + model.cSoCode + "',");
            }
            if (model.cCorCode != null)
            {
                strSql1.Append("cCorCode,");
                strSql2.Append("'" + model.cCorCode + "',");
            }
            if (model.iPPartSeqID != null)
            {
                strSql1.Append("iPPartSeqID,");
                strSql2.Append("" + model.iPPartSeqID + ",");
            }
            if (model.iPPartID != null)
            {
                strSql1.Append("iPPartID,");
                strSql2.Append("" + model.iPPartID + ",");
            }
            if (model.iPPartQty != null)
            {
                strSql1.Append("iPPartQty,");
                strSql2.Append("" + model.iPPartQty + ",");
            }
            if (model.cContractID != null)
            {
                strSql1.Append("cContractID,");
                strSql2.Append("'" + model.cContractID + "',");
            }
            if (model.cContractTagCode != null)
            {
                strSql1.Append("cContractTagCode,");
                strSql2.Append("'" + model.cContractTagCode + "',");
            }
            if (model.cContractRowGuid != null)
            {
                strSql1.Append("cContractRowGuid,");
                strSql2.Append("'" + Guid.NewGuid().ToString() + "',");
            }
            if (model.iMassDate != null)
            {
                strSql1.Append("iMassDate,");
                strSql2.Append("" + model.iMassDate + ",");
            }
            if (model.cMassUnit != null)
            {
                strSql1.Append("cMassUnit,");
                strSql2.Append("" + model.cMassUnit + ",");
            }
            if (model.bQANeedCheck != null)
            {
                strSql1.Append("bQANeedCheck,");
                strSql2.Append("" + (model.bQANeedCheck ? 1 : 0) + ",");
            }
            if (model.bQAUrgency != null)
            {
                strSql1.Append("bQAUrgency,");
                strSql2.Append("" + (model.bQAUrgency ? 1 : 0) + ",");
            }
            if (model.bQAChecking != null)
            {
                strSql1.Append("bQAChecking,");
                strSql2.Append("" + (model.bQAChecking ? 1 : 0) + ",");
            }
            if (model.bQAChecked != null)
            {
                strSql1.Append("bQAChecked,");
                strSql2.Append("" + (model.bQAChecked ? 1 : 0) + ",");
            }
            if (model.iQAQuantity != null)
            {
                strSql1.Append("iQAQuantity,");
                strSql2.Append("" + model.iQAQuantity + ",");
            }
            if (model.iQANum != null)
            {
                strSql1.Append("iQANum,");
                strSql2.Append("" + model.iQANum + ",");
            }
            if (model.cCusInvCode != null)
            {
                strSql1.Append("cCusInvCode,");
                strSql2.Append("'" + model.cCusInvCode + "',");
            }
            if (model.cCusInvName != null)
            {
                strSql1.Append("cCusInvName,");
                strSql2.Append("'" + model.cCusInvName + "',");
            }
            if (model.fsumsignquantity != null)
            {
                strSql1.Append("fsumsignquantity,");
                strSql2.Append("" + model.fsumsignquantity + ",");
            }
            if (model.fsumsignnum != null)
            {
                strSql1.Append("fsumsignnum,");
                strSql2.Append("" + model.fsumsignnum + ",");
            }
            if (model.cbaccounter != null)
            {
                strSql1.Append("cbaccounter,");
                strSql2.Append("'" + model.cbaccounter + "',");
            }
            if (model.bcosting != null)
            {
                strSql1.Append("bcosting,");
                strSql2.Append("" + (model.bcosting ? 1 : 0) + ",");
            }
            if (model.cordercode != null)
            {
                strSql1.Append("cordercode,");
                strSql2.Append("'" + model.cordercode + "',");
            }
            if (model.iorderrowno != null)
            {
                strSql1.Append("iorderrowno,");
                strSql2.Append("" + model.iorderrowno + ",");
            }
            if (model.fcusminprice != null)
            {
                strSql1.Append("fcusminprice,");
                strSql2.Append("" + model.fcusminprice + ",");
            }
            if (model.icostquantity != null)
            {
                strSql1.Append("icostquantity,");
                strSql2.Append("" + model.icostquantity + ",");
            }
            if (model.icostsum != null)
            {
                strSql1.Append("icostsum,");
                strSql2.Append("" + model.icostsum + ",");
            }
            if (model.ispecialtype != null)
            {
                strSql1.Append("ispecialtype,");
                strSql2.Append("" + model.ispecialtype + ",");
            }
            if (model.cvmivencode != null)
            {
                strSql1.Append("cvmivencode,");
                strSql2.Append("'" + model.cvmivencode + "',");
            }
            if (model.iexchsum != null)
            {
                strSql1.Append("iexchsum,");
                strSql2.Append("" + model.iexchsum + ",");
            }
            if (model.imoneysum != null)
            {
                strSql1.Append("imoneysum,");
                strSql2.Append("" + model.imoneysum + ",");
            }
            if (model.irowno != null)
            {
                strSql1.Append("irowno,");
                strSql2.Append("" + model.irowno + ",");
            }
            if (model.frettbquantity != null)
            {
                strSql1.Append("frettbquantity,");
                strSql2.Append("" + model.frettbquantity + ",");
            }
            if (model.fretsum != null)
            {
                strSql1.Append("fretsum,");
                strSql2.Append("" + model.fretsum + ",");
            }
            if (model.iExpiratDateCalcu != null)
            {
                strSql1.Append("iExpiratDateCalcu,");
                strSql2.Append("" + model.iExpiratDateCalcu + ",");
            }
            if (model.dExpirationdate != null)
            {
                strSql1.Append("dExpirationdate,");
                strSql2.Append("'" + model.dExpirationdate + "',");
            }
            if (model.cExpirationdate != null)
            {
                strSql1.Append("cExpirationdate,");
                strSql2.Append("'" + model.cExpirationdate + "',");
            }
            if (model.cbatchproperty1 != null)
            {
                strSql1.Append("cbatchproperty1,");
                strSql2.Append("" + model.cbatchproperty1 + ",");
            }
            if (model.cbatchproperty2 != null)
            {
                strSql1.Append("cbatchproperty2,");
                strSql2.Append("" + model.cbatchproperty2 + ",");
            }
            if (model.cbatchproperty3 != null)
            {
                strSql1.Append("cbatchproperty3,");
                strSql2.Append("" + model.cbatchproperty3 + ",");
            }
            if (model.cbatchproperty4 != null)
            {
                strSql1.Append("cbatchproperty4,");
                strSql2.Append("" + model.cbatchproperty4 + ",");
            }
            if (model.cbatchproperty5 != null)
            {
                strSql1.Append("cbatchproperty5,");
                strSql2.Append("" + model.cbatchproperty5 + ",");
            }
            if (model.cbatchproperty6 != null)
            {
                strSql1.Append("cbatchproperty6,");
                strSql2.Append("'" + model.cbatchproperty6 + "',");
            }
            if (model.cbatchproperty7 != null)
            {
                strSql1.Append("cbatchproperty7,");
                strSql2.Append("'" + model.cbatchproperty7 + "',");
            }
            if (model.cbatchproperty8 != null)
            {
                strSql1.Append("cbatchproperty8,");
                strSql2.Append("'" + model.cbatchproperty8 + "',");
            }
            if (model.cbatchproperty9 != null)
            {
                strSql1.Append("cbatchproperty9,");
                strSql2.Append("'" + model.cbatchproperty9 + "',");
            }
            if (model.cbatchproperty10 != null)
            {
                strSql1.Append("cbatchproperty10,");
                strSql2.Append("'" + model.cbatchproperty10 + "',");
            }
            if (model.dblPreExchMomey != null)
            {
                strSql1.Append("dblPreExchMomey,");
                strSql2.Append("" + model.dblPreExchMomey + ",");
            }
            if (model.dblPreMomey != null)
            {
                strSql1.Append("dblPreMomey,");
                strSql2.Append("" + model.dblPreMomey + ",");
            }
            if (model.idemandtype != null)
            {
                strSql1.Append("idemandtype,");
                strSql2.Append("" + model.idemandtype + ",");
            }
            if (model.cdemandcode != null)
            {
                strSql1.Append("cdemandcode,");
                strSql2.Append("'" + model.cdemandcode + "',");
            }
            if (model.cdemandmemo != null)
            {
                strSql1.Append("cdemandmemo,");
                strSql2.Append("'" + model.cdemandmemo + "',");
            }
            if (model.cdemandid != null)
            {
                strSql1.Append("cdemandid,");
                strSql2.Append("'" + model.cdemandid + "',");
            }
            if (model.idemandseq != null)
            {
                strSql1.Append("idemandseq,");
                strSql2.Append("" + model.idemandseq + ",");
            }
            if (model.cvencode != null)
            {
                strSql1.Append("cvencode,");
                strSql2.Append("'" + model.cvencode + "',");
            }
            if (model.cReasonCode != null)
            {
                strSql1.Append("cReasonCode,");
                strSql2.Append("'" + model.cReasonCode + "',");
            }
            if (model.cInvSN != null)
            {
                strSql1.Append("cInvSN,");
                strSql2.Append("'" + model.cInvSN + "',");
            }
            if (model.iInvSNCount != null)
            {
                strSql1.Append("iInvSNCount,");
                strSql2.Append("" + model.iInvSNCount + ",");
            }
            if (model.bneedsign != null)
            {
                strSql1.Append("bneedsign,");
                strSql2.Append("" + (model.bneedsign ? 1 : 0) + ",");
            }
            if (model.bsignover != null)
            {
                strSql1.Append("bsignover,");
                strSql2.Append("" + (model.bsignover ? 1 : 0) + ",");
            }
            if (model.bneedloss != null)
            {
                strSql1.Append("bneedloss,");
                strSql2.Append("" + (model.bneedloss ? 1 : 0) + ",");
            }
            if (model.flossrate != null)
            {
                strSql1.Append("flossrate,");
                strSql2.Append("" + model.flossrate + ",");
            }
            if (model.frlossqty != null)
            {
                strSql1.Append("frlossqty,");
                strSql2.Append("" + model.frlossqty + ",");
            }
            if (model.fulossqty != null)
            {
                strSql1.Append("fulossqty,");
                strSql2.Append("" + model.fulossqty + ",");
            }
            if (model.isettletype != null)
            {
                strSql1.Append("isettletype,");
                strSql2.Append("" + model.isettletype + ",");
            }
            if (model.crelacuscode != null)
            {
                strSql1.Append("crelacuscode,");
                strSql2.Append("'" + model.crelacuscode + "',");
            }
            if (model.cLossMaker != null)
            {
                strSql1.Append("cLossMaker,");
                strSql2.Append("'" + model.cLossMaker + "',");
            }
            if (model.dLossDate != null)
            {
                strSql1.Append("dLossDate,");
                strSql2.Append("'" + model.dLossDate + "',");
            }
            if (model.dLossTime != null)
            {
                strSql1.Append("dLossTime,");
                strSql2.Append("'" + model.dLossTime + "',");
            }
            if (model.icoridlsid != null)
            {
                strSql1.Append("icoridlsid,");
                strSql2.Append("" + model.icoridlsid + ",");
            }
            if (model.fretoutqty != null)
            {
                strSql1.Append("fretoutqty,");
                strSql2.Append("" + model.fretoutqty + ",");
            }
            if (model.body_outid != null)
            {
                strSql1.Append("body_outid,");
                strSql2.Append("'" + Guid.NewGuid().ToString() + "',");
            }
            if (model.fVeriBillQty != null)
            {
                strSql1.Append("fVeriBillQty,");
                strSql2.Append("" + model.fVeriBillQty + ",");
            }
            if (model.fVeriBillSum != null)
            {
                strSql1.Append("fVeriBillSum,");
                strSql2.Append("" + model.fVeriBillSum + ",");
            }
            if (model.fVeriRetQty != null)
            {
                strSql1.Append("fVeriRetQty,");
                strSql2.Append("" + model.fVeriRetQty + ",");
            }
            if (model.fVeriRetSum != null)
            {
                strSql1.Append("fVeriRetSum,");
                strSql2.Append("" + model.fVeriRetSum + ",");
            }
            if (model.fLastSettleQty != null)
            {
                strSql1.Append("fLastSettleQty,");
                strSql2.Append("" + model.fLastSettleQty + ",");
            }
            if (model.fLastSettleSum != null)
            {
                strSql1.Append("fLastSettleSum,");
                strSql2.Append("" + model.fLastSettleSum + ",");
            }
            if (model.cBookWhcode != null)
            {
                strSql1.Append("cBookWhcode,");
                strSql2.Append("'" + model.cBookWhcode + "',");
            }
            if (model.cInVouchType != null)
            {
                strSql1.Append("cInVouchType,");
                strSql2.Append("'" + model.cInVouchType + "',");
            }
            if (model.cPosition != null)
            {
                strSql1.Append("cPosition,");
                strSql2.Append("'" + model.cPosition + "',");
            }
            if (model.fretqtywkp != null)
            {
                strSql1.Append("fretqtywkp,");
                strSql2.Append("" + model.fretqtywkp + ",");
            }
            if (model.fretqtyykp != null)
            {
                strSql1.Append("fretqtyykp,");
                strSql2.Append("" + model.fretqtyykp + ",");
            }
            if (model.frettbqtyykp != null)
            {
                strSql1.Append("frettbqtyykp,");
                strSql2.Append("" + model.frettbqtyykp + ",");
            }
            if (model.fretsumykp != null)
            {
                strSql1.Append("fretsumykp,");
                strSql2.Append("" + model.fretsumykp + ",");
            }
            if (model.dkeepdate != null)
            {
                strSql1.Append("dkeepdate,");
                strSql2.Append("'" + model.dkeepdate + "',");
            }
            if (model.cSCloser != null)
            {
                strSql1.Append("cSCloser,");
                strSql2.Append("'" + model.cSCloser + "',");
            }
            if (model.isaleoutid != null)
            {
                strSql1.Append("isaleoutid,");
                strSql2.Append("" + model.isaleoutid + ",");
            }
            if (model.bsaleprice != null)
            {
                strSql1.Append("bsaleprice,");
                strSql2.Append("" + (model.bsaleprice ? 1 : 0) + ",");
            }
            if (model.bgift != null)
            {
                strSql1.Append("bgift,");
                strSql2.Append("" + (model.bgift ? 1 : 0) + ",");
            }
            if (model.bmpforderclosed != null)
            {
                strSql1.Append("bmpforderclosed,");
                strSql2.Append("" + (model.bmpforderclosed ? 1 : 0) + ",");
            }
            if (model.cbSysBarCode != null)
            {
                strSql1.Append("cbSysBarCode,");
                strSql2.Append("'" + model.cbSysBarCode + "',");
            }
            if (model.fxjquantity != null)
            {
                strSql1.Append("fxjquantity,");
                strSql2.Append("" + model.fxjquantity + ",");
            }
            if (model.fxjnum != null)
            {
                strSql1.Append("fxjnum,");
                strSql2.Append("" + model.fxjnum + ",");
            }
            if (model.bIAcreatebill != null)
            {
                strSql1.Append("bIAcreatebill,");
                strSql2.Append("" + (model.bIAcreatebill ? 1 : 0) + ",");
            }
            if (model.cParentCode != null)
            {
                strSql1.Append("cParentCode,");
                strSql2.Append("'" + model.cParentCode + "',");
            }
            if (model.cChildCode != null)
            {
                strSql1.Append("cChildCode,");
                strSql2.Append("'" + model.cChildCode + "',");
            }
            if (model.fchildqty != null)
            {
                strSql1.Append("fchildqty,");
                strSql2.Append("" + model.fchildqty + ",");
            }
            if (model.fchildrate != null)
            {
                strSql1.Append("fchildrate,");
                strSql2.Append("" + model.fchildrate + ",");
            }
            if (model.iCalcType != null)
            {
                strSql1.Append("iCalcType,");
                strSql2.Append("" + model.iCalcType + ",");
            }
            if (model.fappretwkpqty != null)
            {
                strSql1.Append("fappretwkpqty,");
                strSql2.Append("" + model.fappretwkpqty + ",");
            }
            if (model.fappretwkpsum != null)
            {
                strSql1.Append("fappretwkpsum,");
                strSql2.Append("" + model.fappretwkpsum + ",");
            }
            if (model.fappretykpqty != null)
            {
                strSql1.Append("fappretykpqty,");
                strSql2.Append("" + model.fappretykpqty + ",");
            }
            if (model.fappretykpsum != null)
            {
                strSql1.Append("fappretykpsum,");
                strSql2.Append("" + model.fappretykpsum + ",");
            }
            if (model.fappretwkptbqty != null)
            {
                strSql1.Append("fappretwkptbqty,");
                strSql2.Append("" + model.fappretwkptbqty + ",");
            }
            if (model.fappretykptbqty != null)
            {
                strSql1.Append("fappretykptbqty,");
                strSql2.Append("" + model.fappretykptbqty + ",");
            }
            if (model.irtnappid != null)
            {
                strSql1.Append("irtnappid,");
                strSql2.Append("" + model.irtnappid + ",");
            }
            if (model.crtnappcode != null)
            {
                strSql1.Append("crtnappcode,");
                strSql2.Append("'" + model.crtnappcode + "',");
            }
            if (model.fretailrealamount != null)
            {
                strSql1.Append("fretailrealamount,");
                strSql2.Append("" + model.fretailrealamount + ",");
            }
            if (model.fretailsettleamount != null)
            {
                strSql1.Append("fretailsettleamount,");
                strSql2.Append("" + model.fretailsettleamount + ",");
            }
            strSql.Append("insert into DispatchLists(");
            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());
        }
Ejemplo n.º 2
0
        public void CreateFHD()
        {
            try
            {
                StreamWriter(DateTime.Now.ToString("yyyyMMddHHmmss") + @"【Start】-----------------------------------------------------------");

                string sUFDatabase = GetConfigValue("UFDatabase");
                string sServer     = GetConfigValue("ServerInfo");
                string sSQLUid     = GetConfigValue("SQLUID");
                string sSQLPwd     = GetConfigValue("SQLPWD");

                string sConn = "server=" + sServer + ";uid=" + sSQLUid + " ;pwd=" + sSQLPwd + ";database=" + sUFDatabase + ";";

                string sAccID = sUFDatabase.Substring(7, 3);

                string sErr = "";

                int iCount = 0;

                //获得已审核,未关闭(含行关闭),累计发货数量为0 的订单
                //红字单据不考虑

                DbHelperSQL.connectionString = sConn;

                string    sSQL            = @"
SELECT     TOP (200) sType, StartTime, EndTime, Next_StartTime,GETDATE() AS dNowTime
FROM         _AutoService
where sType = 'DP'
";
                DataTable dt              = DbHelperSQL.Query(sSQL);
                DateTime  dStartTime      = Convert.ToDateTime(dt.Rows[0]["StartTime"]);
                DateTime  dEndTime        = Convert.ToDateTime(dt.Rows[0]["EndTime"]);
                DateTime  dNext_StartTime = Convert.ToDateTime(dt.Rows[0]["Next_StartTime"]);
                DateTime  dNowTime        = Convert.ToDateTime(dt.Rows[0]["dNowTime"]);

                if (dNext_StartTime > dNowTime)
                {
                    StreamWriter(DateTime.Now.ToString("yyyyMMddHHmmss") + "  运行时间未到");
                    return;
                }

                StreamWriter(DateTime.Now.ToString("yyyyMMddHHmmss") + "  开始运行");

                sSQL = "update _AutoService set StartTime = getdate() where sType = 'DP'";
                DbHelperSQL.ExecuteSql(sSQL);

                sSQL = @"
select distinct a.*
from SO_SOMain a inner join SO_SODetails b on a.id = b.id 
	inner join [dbo].[_DSSaleBaseInfo] c on c.cSTCode = a.cSTCode
where isnull(c.[bDS],0) = 1  and isnull(a.cCloser,'') = '' and isnull(a.cVerifier ,'') <> '' 
    and a.ID not in 
    (
        select id 
        from  SO_SODetails
        where  isnull(iFHQuantity ,0) <> 0 or isnull(cSCloser ,'') <> ''
	)
";
                //测试用语句
//                sSQL = @"
//select distinct a.*
//from SO_SOMain a inner join SO_SODetails b on a.id = b.id
//	inner join [dbo].[_DSSaleBaseInfo] c on c.cSTCode = a.cSTCode
//where isnull(c.[bDS],0) = 1  and isnull(a.cCloser,'') = '' and isnull(a.cVerifier ,'') <> ''
//    and a.cSOCode = '20171016000822'
//";
                DataTable dtSO = DbHelperSQL.Query(sSQL);
                StreamWriter(DateTime.Now.ToString("yyyyMMddHHmmss") + "  加载需要发货的销售订单");

                if (dtSO == null || dtSO.Rows.Count == 0)
                {
                    try
                    {
                        string sSQL2 = @"
update _AutoService set  EndTime = getdate(), Next_StartTime = DATEADD(MINUTE,5,GetDate()) 
where sType = 'DP'
";
                        DbHelperSQL.ExecuteSql(sSQL2);
                    }
                    catch { }
                    return;
                }
                StreamWriter(DateTime.Now.ToString("yyyyMMddHHmmss") + "  加载需要发货的销售订单,累计获得订单数量" + dtSO.Rows.Count);
                for (int i = 0; i < dtSO.Rows.Count; i++)
                {
                    sErr = "";

                    #region 发货单
                    SqlConnection conn = new SqlConnection(sConn);
                    conn.Open();
                    //启用事务
                    SqlTransaction tran = conn.BeginTransaction();


                    string sSOCode = dtSO.Rows[i]["cSOCode"].ToString().Trim();

                    try
                    {
                        sSQL = @"
select distinct a.*, a.cDefine12 as cWhCode,b.*,inv.cInvName,inv.cInvStd,isnull(inv.bInvBatch ,0) as bInvBatch,d.cRdCode
from SO_SOMain a inner join SO_SODetails b on a.id = b.id 
	inner join [dbo].[_DSSaleBaseInfo] c on c.cSTCode = a.cSTCode
    inner join Inventory inv on b.cInvCode = inv.cInvCode
    inner join SaleType d on d.cSTCode = a.cSTCode
where a.cSOCode = 'aaaaaaaa'
";
                        sSQL = sSQL.Replace("aaaaaaaa", sSOCode);
                        DataTable dtSOs = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];

                        string   sCusCode = dtSOs.Rows[0]["cCusCode"].ToString().Trim();
                        DateTime dtmSO    = BaseFunction.ReturnDate(dtSOs.Rows[0]["dDate"]);

                        sSQL = "select isnull(bflag_SA,0) as bflag from GL_mend where iYPeriod = '" + dtmSO.ToString("yyyyMM") + "'";
                        dt   = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                        if (dt == null || dt.Rows.Count == 0)
                        {
                            StreamWriter(DateTime.Now.ToString("yyyyMMddHHmmss") + "  单据日期已经结账1");
                            throw new Exception(sSOCode + "当前单据日期已经结帐");
                        }
                        int i结账 = BaseFunction.ReturnInt(dt.Rows[0]["bflag"]);
                        if (i结账 > 0)
                        {
                            StreamWriter(DateTime.Now.ToString("yyyyMMddHHmmss") + "  单据日期已经结账2");
                            throw new Exception(sSOCode + "当前单据日期已经结帐");
                        }

                        string sCode = "DP-" + sSOCode;

                        long lID        = -1;
                        long lIDDetails = -1;
                        sSQL = @"
                                            declare @p5 int
                                            set @p5=aaaaaa
                                            declare @p6 int
                                            set @p6=bbbbbb
                                            exec sp_GetId N'00',N'dddddd',N'DISPATCH',eeeeee,@p5 output,@p6 output,default
                                            select @p5, @p6
                                            ";
                        sSQL = sSQL.Replace("aaaaaa", lID.ToString());
                        sSQL = sSQL.Replace("bbbbbb", lIDDetails.ToString());
                        sSQL = sSQL.Replace("dddddd", sAccID);
                        sSQL = sSQL.Replace("eeeeee", dtSOs.Rows.Count.ToString());
                        dt   = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];

                        lID        = BaseFunction.ReturnLong(dt.Rows[0][0]);
                        lIDDetails = BaseFunction.ReturnLong(dt.Rows[0][1]) - dtSOs.Rows.Count;


                        Model.DispatchList mod = new DllForService.Model.DispatchList();
                        mod.DLID = lID;


                        mod.cDLCode    = sCode;
                        mod.cVouchType = "05";
                        mod.cRdCode    = dtSOs.Rows[0]["cRdCode"].ToString().Trim();
                        mod.cSTCode    = dtSOs.Rows[0]["cSTCode"].ToString().Trim();
                        mod.dDate      = dtmSO;
                        mod.bneedbill  = true;
                        mod.cDepCode   = dtSO.Rows[0]["cDepCode"].ToString().Trim();
                        //mod.cPersonCode = lookUpEditcPersonCode.EditValue.ToString();
                        mod.SBVID       = 0;
                        mod.cCusCode    = sCusCode;
                        mod.cexch_name  = dtSOs.Rows[0]["cexch_name"].ToString().Trim();
                        mod.iExchRate   = BaseFunction.ReturnDecimal(dtSOs.Rows[0]["iExchRate"]);
                        mod.iTaxRate    = BaseFunction.ReturnDecimal(dtSOs.Rows[0]["iTaxRate"]);
                        mod.bFirst      = false;
                        mod.bReturnFlag = false;
                        mod.bSettleAll  = false;
                        mod.cMemo       = dtSOs.Rows[0]["cMemo"].ToString().Trim();
                        mod.cBusType    = dtSOs.Rows[0]["cBusType"].ToString().Trim();
                        mod.cCusName    = dtSOs.Rows[0]["cCusName"].ToString().Trim();

                        mod.cDefine1 = dtSOs.Rows[0]["cDefine1"].ToString().Trim();
                        mod.cDefine2 = dtSOs.Rows[0]["cDefine1"].ToString().Trim();
                        mod.cDefine3 = dtSOs.Rows[0]["cDefine3"].ToString().Trim();

                        if (dtSOs.Rows[0]["cDefine4"].ToString().Trim() != "" && BaseFunction.ReturnDate(dtSOs.Rows[0]["cDefine4"]) > BaseFunction.ReturnDate("1901-01-01"))
                        {
                            mod.cDefine4 = BaseFunction.ReturnDate(dtSOs.Rows[0]["cDefine4"]);
                        }
                        if (dtSOs.Rows[0]["cDefine5"].ToString().Trim() != "")
                        {
                            mod.cDefine5 = BaseFunction.ReturnLong(dtSOs.Rows[0]["cDefine5"]);
                        }
                        if (dtSOs.Rows[0]["cDefine6"].ToString().Trim() != "" && BaseFunction.ReturnDate(dtSOs.Rows[0]["cDefine6"]) > BaseFunction.ReturnDate("1901-01-01"))
                        {
                            mod.cDefine6 = BaseFunction.ReturnDate(dtSOs.Rows[0]["cDefine6"]);
                        }
                        if (dtSOs.Rows[0]["cDefine7"].ToString().Trim() != "")
                        {
                            mod.cDefine7 = BaseFunction.ReturnDecimal(dtSOs.Rows[0]["cDefine7"]);
                        }
                        mod.cDefine8  = dtSOs.Rows[0]["cDefine8"].ToString().Trim();
                        mod.cDefine9  = dtSOs.Rows[0]["cDefine9"].ToString().Trim();
                        mod.cDefine10 = dtSOs.Rows[0]["cDefine10"].ToString().Trim();
                        mod.cDefine11 = dtSOs.Rows[0]["cDefine11"].ToString().Trim();
                        mod.cDefine12 = dtSOs.Rows[0]["cDefine12"].ToString().Trim();
                        mod.cDefine13 = dtSOs.Rows[0]["cDefine13"].ToString().Trim();
                        mod.cDefine14 = dtSOs.Rows[0]["cDefine14"].ToString().Trim();
                        if (dtSOs.Rows[0]["cDefine15"].ToString().Trim() != "")
                        {
                            mod.cDefine15 = BaseFunction.ReturnLong(dtSOs.Rows[0]["cDefine15"]);
                        }
                        if (dtSOs.Rows[0]["cDefine16"].ToString().Trim() != "")
                        {
                            mod.cDefine16 = BaseFunction.ReturnDecimal(dtSOs.Rows[0]["cDefine16"]);
                        }

                        mod.iVTid          = 71;
                        mod.cMaker         = "demo";
                        mod.cMemo          = dtSOs.Rows[0]["cMemo"].ToString().Trim();
                        mod.cVerifier      = "demo";
                        mod.dverifydate    = BaseFunction.ReturnDate(mod.dDate.ToString("yyyy-MM-dd"));
                        mod.dverifydate    = mod.dDate;
                        mod.dverifysystime = mod.dDate;
                        mod.cSaleOut       = sSOCode;
                        mod.cSysBarCode    = "||SA01|" + mod.cDLCode;

                        DAL.DispatchList dal = new DllForService.DAL.DispatchList();

                        sSQL = dal.Add(mod);
                        DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);

                        StreamWriter(DateTime.Now.ToString("yyyyMMddHHmmss") + "  单据表头生成成功:单据第" + (i + 1).ToString() + "");
                        int iRow = 0;

                        for (int j = 0; j < dtSOs.Rows.Count; j++)
                        {
                            decimal dQty = BaseFunction.ReturnDecimal(dtSOs.Rows[j]["iQuantity"]);
                            if (dQty <= 0)
                            {
                                continue;
                            }

                            string sInvCode = dtSOs.Rows[j]["cInvCode"].ToString().Trim();
                            string sWhCode  = dtSOs.Rows[j]["cWhCode"].ToString().Trim();

                            sSQL = "select sum(iQuantity) as iQty from CurrentStock where cInvCode = 'aaaaaaaa' and cWhCode = 'bbbbbbbb' ";
                            sSQL = sSQL.Replace("aaaaaaaa", sInvCode);
                            sSQL = sSQL.Replace("bbbbbbbb", sWhCode);
                            DataTable dtCurr = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                            if (dtCurr == null || dtCurr.Rows.Count == 0)
                            {
                                sErr = sErr + sCode + " There are not enough " + sInvCode + " in the warehouse " + sWhCode + "\n";
                                continue;
                            }

                            decimal dCurrSum = BaseFunction.ReturnDecimal(dtCurr.Rows[0]["iQty"]);
                            if (dCurrSum < dQty)
                            {
                                sErr = sErr + sCode + " There are not enough " + sInvCode + " in the warehouse " + sWhCode + "\n";
                                continue;
                            }

                            sSQL   = "select * from CurrentStock where isnull(iQuantity,0) > 0 and  cInvCode = 'aaaaaaaa' and cWhCode = 'bbbbbbbb' order by dVDate ";
                            sSQL   = sSQL.Replace("aaaaaaaa", sInvCode);
                            sSQL   = sSQL.Replace("bbbbbbbb", sWhCode);
                            dtCurr = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];

                            for (int k = 0; k < dtCurr.Rows.Count; k++)
                            {
                                if (dQty <= 0)
                                {
                                    break;
                                }

                                decimal dCurr = BaseFunction.ReturnDecimal(dtCurr.Rows[k]["iQuantity"]);

                                if (dCurr <= 0)
                                {
                                    break;
                                }

                                decimal dQtyNow = 0;
                                if (dCurr <= dQty)
                                {
                                    dQtyNow = dCurr;
                                    dQty    = dQty - dCurr;
                                }
                                else
                                {
                                    dQtyNow = dQty;
                                    dQty    = 0;
                                }

                                if (dQtyNow <= 0)
                                {
                                    break;
                                }

                                Model.DispatchLists mods = new DllForService.Model.DispatchLists();
                                lIDDetails        += 1;
                                mods.AutoID        = lIDDetails;
                                mods.DLID          = mod.DLID;
                                mods.cWhCode       = dtSOs.Rows[j]["cWhCode"].ToString().Trim();
                                mods.cInvCode      = sInvCode;
                                mods.cInvName      = dtSOs.Rows[j]["cInvName"].ToString().Trim();
                                mods.iQuantity     = dQtyNow;
                                mods.iQuotedPrice  = 0;
                                mods.iUnitPrice    = BaseFunction.ReturnDecimal(dtSOs.Rows[j]["iUnitPrice"]);
                                mods.iTaxUnitPrice = BaseFunction.ReturnDecimal(dtSOs.Rows[j]["iTaxUnitPrice"]);
                                mods.iMoney        = BaseFunction.ReturnDecimal(mods.iUnitPrice * mods.iQuantity, 2);
                                mods.iSum          = BaseFunction.ReturnDecimal(mods.iTaxUnitPrice * mods.iQuantity, 2);
                                mods.iTax          = mods.iSum - mods.iMoney;
                                mods.iDisCount     = 0;
                                mods.iNatUnitPrice = BaseFunction.ReturnDecimal(mods.iUnitPrice * mod.iExchRate);
                                mods.iNatMoney     = BaseFunction.ReturnDecimal(mods.iNatUnitPrice * mods.iQuantity, 2);
                                mods.iNatSum       = BaseFunction.ReturnDecimal(mods.iNatMoney * (1 + mod.iTaxRate / 100), 2);
                                mods.iNatTax       = mods.iNatSum - mods.iNatMoney;
                                mods.bSettleAll    = false;
                                mods.iDLsID        = lIDDetails;
                                mods.bcosting      = true;
                                mods.iSOsID        = BaseFunction.ReturnLong(dtSOs.Rows[j]["iSOsID"]);
                                mods.iTaxRate      = BaseFunction.ReturnDecimal(dtSOs.Rows[j]["iTaxRate"]);
                                iRow       += 1;
                                mods.irowno = iRow;
                                if (BaseFunction.ReturnBool(dtSOs.Rows[j]["bInvBatch"]))
                                {
                                    mods.cBatch = dtCurr.Rows[k]["cBatch"].ToString().Trim();
                                }


                                mods.cDefine22 = dtSOs.Rows[j]["cDefine22"].ToString().Trim();
                                mods.cDefine23 = dtSOs.Rows[j]["cDefine23"].ToString().Trim();
                                mods.cDefine24 = dtSOs.Rows[j]["cDefine24"].ToString().Trim();
                                mods.cDefine25 = dtSOs.Rows[j]["cDefine25"].ToString().Trim();

                                if (dtSOs.Rows[j]["cDefine26"].ToString().Trim() != "")
                                {
                                    mods.cDefine26 = BaseFunction.ReturnDecimal(dtSOs.Rows[j]["cDefine26"]);
                                }
                                if (dtSOs.Rows[j]["cDefine27"].ToString().Trim() != "")
                                {
                                    mods.cDefine27 = BaseFunction.ReturnDecimal(dtSOs.Rows[j]["cDefine27"]);
                                }
                                mods.cDefine28 = dtSOs.Rows[j]["cDefine28"].ToString().Trim();
                                mods.cDefine29 = dtSOs.Rows[j]["cDefine29"].ToString().Trim();
                                mods.cDefine30 = dtSOs.Rows[j]["cDefine30"].ToString().Trim();
                                mods.cDefine31 = dtSOs.Rows[j]["cDefine31"].ToString().Trim();
                                mods.cDefine32 = dtSOs.Rows[j]["cDefine32"].ToString().Trim();
                                mods.cDefine33 = dtSOs.Rows[j]["cDefine33"].ToString().Trim();
                                if (dtSOs.Rows[j]["cDefine34"].ToString().Trim() != "")
                                {
                                    mods.cDefine34 = BaseFunction.ReturnLong(dtSOs.Rows[j]["cDefine34"]);
                                }
                                if (dtSOs.Rows[j]["cDefine35"].ToString().Trim() != "")
                                {
                                    mods.cDefine35 = BaseFunction.ReturnLong(dtSOs.Rows[j]["cDefine35"]);
                                }
                                if (dtSOs.Rows[j]["cDefine36"].ToString().Trim() != "" && BaseFunction.ReturnDate(dtSOs.Rows[j]["cDefine36"]) > BaseFunction.ReturnDate("1901-01-01"))
                                {
                                    mods.cDefine36 = BaseFunction.ReturnDate(dtSOs.Rows[j]["cDefine36"]);
                                }
                                if (dtSOs.Rows[j]["cDefine37"].ToString().Trim() != "" && BaseFunction.ReturnDate(dtSOs.Rows[j]["cDefine37"]) > BaseFunction.ReturnDate("1901-01-01"))
                                {
                                    mods.cDefine37 = BaseFunction.ReturnDate(dtSOs.Rows[j]["cDefine37"]);
                                }
                                mods.bsaleprice = BaseFunction.ReturnBool(dtSOs.Rows[j]["bsaleprice"]);;

                                DAL.DispatchLists dals = new DllForService.DAL.DispatchLists();
                                sSQL    = dals.Add(mods);
                                iCount += DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);

                                sSQL = @"
if exists(select * from  CurrentStock where cInvCode = '@cInvCode' and cWhCode = '@cWhCode') 
	update  CurrentStock set fOutQuantity = isnull(fOutQuantity,0) + @dQty  where cInvCode = '@cInvCode' and cWhCode = '@cWhCode'  and isnull(cBatch,'') = @cBatch 
else 
	begin 
		declare @itemid varchar(20); 
		declare @iCount int;  
		select @iCount=count(itemid) from CurrentStock where cInvCode = '@cInvCode' and cWhCode = '@cWhCode' and isnull(cBatch,'') = @cBatch 
		if( @iCount > 0 ) 
			select @itemid=itemid from CurrentStock where cInvCode = '@cInvCode' and cWhCode = '@cWhCode' and isnull(cBatch,'') = @cBatch 
		else  
			select @itemid=max(itemid+1) from CurrentStock  
		
		insert into CurrentStock(cWhCode,cInvCode,fOutQuantity,itemid,cBatch)values('@cWhCode','@cInvCode', @dQty ,@itemid,@cBatch) 
	end
                        ";
                                sSQL = sSQL.Replace("@cInvCode", mods.cInvCode);
                                sSQL = sSQL.Replace("@cWhCode", mods.cWhCode);
                                sSQL = sSQL.Replace("@dQty", mods.iQuantity.ToString());
                                if (BaseFunction.ReturnBool(dtSOs.Rows[j]["bInvBatch"]))
                                {
                                    sSQL = sSQL.Replace("@cBatch", "'" + mods.cBatch + "'");
                                }
                                else
                                {
                                    sSQL = sSQL.Replace("@cBatch", "''");
                                }
                                DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);

                                sSQL = "update SO_SODetails set iFHQuantity = isnull(iFHQuantity,0) + " + mods.iQuantity + ",iFHMoney = isnull(iFHMoney,0) + " + mods.iSum + " where iSOsID = " + mods.iSOsID;
                                DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);


                                StreamWriter(DateTime.Now.ToString("yyyyMMddHHmmss") + "  单据表头生成成功:单据第" + (i + 1).ToString() + ",行" + (j + 1).ToString());
                            }
                        }


                        int iTest = iRow - dtSOs.Rows.Count;
                        sSQL = @"
update  UFSystem..UA_Identity set iChildId = iChildId + {0} WHERE   (cAcc_Id = '001') AND (cVouchType = 'DISPATCH')
";
                        sSQL = string.Format(sSQL, iTest);
                        DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);



                        if (sErr != "")
                        {
                            throw new Exception(sErr);
                        }

                        #region 销售出库单


                        StreamWriter(DateTime.Now.ToString("yyyyMMddHHmmss") + "  生成销售出库单,开始");

                        //获得发货单有多少仓库,每个仓库有几行记录出库
                        sSQL = @"
select  b.cWhCode,count(1) as iCou
from DispatchList a  inner join DispatchLists b on a.DLID = b.DLID
	inner join [dbo].[_DSSaleBaseInfo] c on c.cSTCode = a.cSTCode
    inner join Inventory inv on b.cInvCode = inv.cInvCode
    inner join SaleType d on d.cSTCode = a.cSTCode
where a.cDLCode = 'aaaaaa'
group by b.cWhCode 
";
                        sSQL = sSQL.Replace("aaaaaa", mod.cDLCode);
                        DataTable dtWh = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];

                        for (int iii = 0; iii < dtWh.Rows.Count; iii++)
                        {
                            string sRDCode = "";

                            sSQL = @"
select * 
from DispatchList a inner join DispatchLists b on a.DLID = b.DLID
	inner join SaleType c on c.cSTCode = a.cSTCode
    inner join Inventory inv on inv.cInvCode = b.cInvCode
where a.cDLCode = 'aaaaaa' and b.cWhCode = 'bbbbbb'
order by AutoID
";
                            sSQL = sSQL.Replace("aaaaaa", mod.cDLCode);
                            sSQL = sSQL.Replace("bbbbbb", dtWh.Rows[iii]["cWhCode"].ToString().Trim());
                            DataTable dtDispatchList = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                            if (dtDispatchList == null || dtDispatchList.Rows.Count == 0)
                            {
                                throw new Exception(sCode + " is not exists");
                            }

                            sSQL = "select isnull(bflag_ST,0) as bflag from GL_mend where iYPeriod = '" + mod.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");
                            }
                            i结账 = BaseFunction.ReturnInt(dt.Rows[0]["bflag"]);
                            if (i结账 > 0)
                            {
                                throw new Exception(mod.dDate.ToString("yyyy-MM") + " have checked out");
                            }

                            lID        = -1;
                            lIDDetails = -1;
                            sSQL       = @"
declare @p5 int
set @p5=aaaaaa
declare @p6 int
set @p6=bbbbbb
exec sp_GetId N'00',N'dddddd',N'rd',eeeeee,@p5 output,@p6 output,default
select @p5, @p6
                    ";
                            sSQL       = sSQL.Replace("aaaaaa", lID.ToString());
                            sSQL       = sSQL.Replace("bbbbbb", lIDDetails.ToString());
                            sSQL       = sSQL.Replace("dddddd", sAccID);
                            sSQL       = sSQL.Replace("eeeeee", dtWh.Rows[iii]["iCou"].ToString().Trim());
                            dt         = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];

                            lID        = BaseFunction.ReturnLong(dt.Rows[0][0]);
                            lIDDetails = BaseFunction.ReturnLong(dt.Rows[0][1]) - BaseFunction.ReturnInt(dtWh.Rows[iii]["iCou"]);

                            if (dt == null || dt.Rows.Count == 0)
                            {
                                throw new Exception(sCode + " is not exists");
                            }

                            Model.rdrecord32 modRD = new DllForService.Model.rdrecord32();
                            modRD.ID         = lID;
                            modRD.bRdFlag    = 0;
                            modRD.cVouchType = "32";
                            modRD.cBusType   = mod.cBusType;
                            modRD.cSource    = "发货单";
                            modRD.cBusCode   = mod.cDLCode;
                            modRD.cWhCode    = dtWh.Rows[iii]["cWhCode"].ToString().Trim();
                            modRD.dDate      = mod.dDate;
                            modRD.cCode      = "RD-" + modRD.cWhCode + "-" + sSOCode;


                            if (sRDCode == "")
                            {
                                sRDCode = modRD.cCode;
                            }
                            else
                            {
                                sRDCode = sRDCode + "," + modRD.cCode;
                            }

                            modRD.cDepCode         = mod.cDepCode;
                            modRD.cPersonCode      = mod.cPersonCode;
                            modRD.cSTCode          = mod.cSTCode;
                            modRD.cRdCode          = dtDispatchList.Rows[0]["cRdCode"].ToString().Trim();
                            modRD.cCusCode         = mod.cCusCode;
                            modRD.cDLCode          = mod.DLID;
                            modRD.bTransFlag       = false;
                            modRD.cMaker           = "demo";
                            modRD.cDefine1         = mod.cDefine1;
                            modRD.cDefine2         = mod.cDefine2;
                            modRD.cDefine3         = mod.cDefine3;
                            modRD.cDefine4         = mod.cDefine4;
                            modRD.cDefine5         = mod.cDefine5;
                            modRD.cDefine6         = mod.cDefine6;
                            modRD.cDefine7         = mod.cDefine7;
                            modRD.cDefine8         = mod.cDefine8;
                            modRD.cDefine9         = mod.cDefine9;
                            modRD.cDefine10        = mod.cDefine10;
                            modRD.cDefine11        = mod.cDefine11;
                            modRD.cDefine12        = mod.cDefine12;
                            modRD.cDefine13        = mod.cDefine13;
                            modRD.cDefine14        = mod.cDefine14;
                            modRD.cDefine15        = mod.cDefine15;
                            modRD.cDefine16        = mod.cDefine16;
                            modRD.bpufirst         = false;
                            modRD.biafirst         = false;
                            modRD.VT_ID            = 87;
                            modRD.bIsSTQc          = false;
                            modRD.bFromPreYear     = false;
                            modRD.bIsComplement    = 0;
                            modRD.iDiscountTaxType = 0;
                            modRD.ireturncount     = 0;
                            modRD.iverifystate     = 0;
                            modRD.iswfcontrolled   = 0;
                            modRD.dnmaketime       = mod.dverifysystime;
                            modRD.bredvouch        = 0;
                            modRD.iPrintCount      = 0;
                            modRD.cinvoicecompany  = modRD.cCusCode;
                            modRD.dnmaketime       = mod.dDate;
                            modRD.csysbarcode      = "||st32|" + modRD.cCode;
                            modRD.cHandler         = "demo";
                            modRD.dnverifytime     = mod.dverifysystime;
                            modRD.dVeriDate        = mod.dverifydate;

                            DAL.rdrecord32 dalRD = new DllForService.DAL.rdrecord32();
                            sSQL = dalRD.Add(modRD);
                            DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);

                            int iRDRow = 0;
                            for (int jj = 0; jj < dtDispatchList.Rows.Count; jj++)
                            {
                                if (dtDispatchList.Rows[jj]["cWhCode"].ToString().Trim() != modRD.cWhCode)
                                {
                                    continue;
                                }

                                decimal dOutSum = BaseFunction.ReturnDecimal(dtDispatchList.Rows[jj]["fOutQuantity"]);
                                if (dOutSum > 0)
                                {
                                    sErr = sErr + "Item No " + dtDispatchList.Rows[jj]["cInvCode"].ToString() + " No.Site list " + dtDispatchList.Rows[jj]["cDefine10"].ToString() + " is used\n";
                                    continue;
                                }

                                iRDRow += 1;
                                Model.rdrecords32 modRDs = new DllForService.Model.rdrecords32();
                                lIDDetails      += 1;
                                modRDs.AutoID    = lIDDetails;
                                modRDs.ID        = modRD.ID;
                                modRDs.cInvCode  = dtDispatchList.Rows[jj]["cInvCode"].ToString().Trim();
                                modRDs.iQuantity = BaseFunction.ReturnDecimal(dtDispatchList.Rows[jj]["iQuantity"]);
                                modRDs.iNum      = BaseFunction.ReturnDecimal(dtDispatchList.Rows[jj]["iNum"]);

                                sSQL = "select sum(iQuantity) as iQty from CurrentStock where cWhCode = 'aaaaaa' and cInvCode = 'bbbbbb'";
                                sSQL = sSQL.Replace("aaaaaa", modRD.cWhCode);
                                sSQL = sSQL.Replace("bbbbbb", modRDs.cInvCode);
                                DataTable dtCurr = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                                if (dtCurr == null || dtCurr.Rows.Count == 0)
                                {
                                    sErr = sErr + "Item No " + dtDispatchList.Rows[jj]["cInvCode"].ToString() + " not enough\n";
                                    continue;
                                }
                                decimal dCurr = BaseFunction.ReturnDecimal(dtCurr.Rows[0]["iQty"]);
                                if (dCurr < modRDs.iQuantity)
                                {
                                    sErr = sErr + "Item No  " + dtDispatchList.Rows[jj]["cInvCode"].ToString() + " not enough\n";
                                    continue;
                                }
                                //modRDs.iUnitCost = BaseFunction.ReturnDecimal(dtDispatchList.Rows[jj]["iUnitPrice"]);
                                //modRDs.iPrice = BaseFunction.ReturnDecimal(dtDispatchList.Rows[jj]["iMoney"]);
                                modRDs.iFlag              = 0;
                                modRDs.iDLsID             = BaseFunction.ReturnLong(dtDispatchList.Rows[jj]["iDLsID"]);
                                modRDs.iNQuantity         = modRDs.iQuantity;
                                modRDs.iNNum              = modRDs.iNum;
                                modRDs.bLPUseFree         = false;
                                modRDs.iRSRowNO           = 0;
                                modRDs.iOriTrackID        = 0;
                                modRDs.bCosting           = true;
                                modRDs.bVMIUsed           = false;
                                modRDs.cbdlcode           = sCode;
                                modRDs.iExpiratDateCalcu  = 0;
                                modRDs.ccusinvcode        = dtDispatchList.Rows[jj]["ccusinvcode"].ToString().Trim();
                                modRDs.iordertype         = 0;
                                modRDs.ipesotype          = 0;
                                modRDs.isotype            = 0;
                                modRDs.irowno             = iRDRow;
                                modRDs.bIAcreatebill      = false;
                                modRDs.bsaleoutcreatebill = false;
                                modRDs.bneedbill          = true;
                                modRDs.cBatch             = dtDispatchList.Rows[jj]["cBatch"].ToString().Trim();


                                modRDs.cDefine22 = dtDispatchList.Rows[jj]["cDefine22"].ToString().Trim();
                                modRDs.cDefine23 = dtDispatchList.Rows[jj]["cDefine23"].ToString().Trim();
                                modRDs.cDefine24 = dtDispatchList.Rows[jj]["cDefine24"].ToString().Trim();
                                modRDs.cDefine25 = dtDispatchList.Rows[jj]["cDefine25"].ToString().Trim();
                                if (dtDispatchList.Rows[jj]["cDefine26"].ToString().Trim() != "")
                                {
                                    modRDs.cDefine26 = BaseFunction.ReturnDecimal(dtDispatchList.Rows[jj]["cDefine26"]);
                                }
                                if (dtDispatchList.Rows[jj]["cDefine27"].ToString().Trim() != "")
                                {
                                    modRDs.cDefine27 = BaseFunction.ReturnDecimal(dtDispatchList.Rows[jj]["cDefine27"]);
                                }
                                modRDs.cDefine28 = dtDispatchList.Rows[jj]["cDefine28"].ToString().Trim();
                                modRDs.cDefine29 = dtDispatchList.Rows[jj]["cDefine29"].ToString().Trim();
                                modRDs.cDefine30 = dtDispatchList.Rows[jj]["cDefine30"].ToString().Trim();
                                modRDs.cDefine31 = dtDispatchList.Rows[jj]["cDefine31"].ToString().Trim();
                                modRDs.cDefine32 = dtDispatchList.Rows[jj]["cDefine32"].ToString().Trim();
                                modRDs.cDefine33 = dtDispatchList.Rows[jj]["cDefine33"].ToString().Trim();
                                if (dtDispatchList.Rows[jj]["cDefine34"].ToString().Trim() != "")
                                {
                                    modRDs.cDefine34 = BaseFunction.ReturnInt(dtDispatchList.Rows[jj]["cDefine34"]);
                                }
                                if (dtDispatchList.Rows[jj]["cDefine35"].ToString().Trim() != "")
                                {
                                    modRDs.cDefine35 = BaseFunction.ReturnInt(dtDispatchList.Rows[jj]["cDefine35"]);
                                }
                                if (dtDispatchList.Rows[jj]["cDefine36"].ToString().Trim() != "" && BaseFunction.ReturnDate(dtDispatchList.Rows[jj]["cDefine36"]) > BaseFunction.ReturnDate("1901-01-01"))
                                {
                                    modRDs.cDefine36 = BaseFunction.ReturnDate(dtDispatchList.Rows[jj]["cDefine36"]);
                                }
                                if (dtDispatchList.Rows[jj]["cDefine37"].ToString().Trim() != "" && BaseFunction.ReturnDate(dtDispatchList.Rows[jj]["cDefine37"]) > BaseFunction.ReturnDate("1901-01-01"))
                                {
                                    modRDs.cDefine37 = BaseFunction.ReturnDate(dtDispatchList.Rows[jj]["cDefine37"]);
                                }


                                DAL.rdrecords32 dals = new DllForService.DAL.rdrecords32();
                                sSQL = dals.Add(modRDs);
                                DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);

                                sSQL = @"
if exists(select * from  CurrentStock where cInvCode = '@cInvCode' and cWhCode = '@cWhCode') 
	update  CurrentStock set fOutQuantity = isnull(fOutQuantity,0) - @dQty ,iQuantity = isnull(iQuantity,0) - @dQty  where cInvCode = '@cInvCode' and cWhCode = '@cWhCode'  and isnull(cBatch,'') = @cBatch 
else 
	begin 
		declare @itemid varchar(20); 
		declare @iCount int;  
		select @iCount=count(itemid) from CurrentStock where cInvCode = '@cInvCode' and cWhCode = '@cWhCode' and isnull(cBatch,'') = @cBatch 
		if( @iCount > 0 ) 
			select @itemid=itemid from CurrentStock where cInvCode = '@cInvCode' and cWhCode = '@cWhCode' and isnull(cBatch,'') = @cBatch 
		else  
			select @itemid=max(itemid+1) from CurrentStock  
		
		insert into CurrentStock(cWhCode,cInvCode,fOutQuantity,iQuantity,itemid,cBatch)values('@cWhCode','@cInvCode', -1 * @dQty, -1 * @dQty ,@itemid,@cBatch) 
	end
";
                                sSQL = sSQL.Replace("@cInvCode", modRDs.cInvCode);
                                sSQL = sSQL.Replace("@cWhCode", modRD.cWhCode);
                                sSQL = sSQL.Replace("@dQty", modRDs.iQuantity.ToString());
                                if (BaseFunction.ReturnBool(dtDispatchList.Rows[jj]["bInvBatch"]))
                                {
                                    sSQL = sSQL.Replace("@cBatch", "'" + modRDs.cBatch + "'");
                                }
                                else
                                {
                                    sSQL = sSQL.Replace("@cBatch", "''");
                                }
                                DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);

                                sSQL = "update DispatchLists set fOutQuantity = iQuantity where Autoid = " + dtDispatchList.Rows[jj]["Autoid"].ToString().Trim();
                                DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);

                                sSQL = @"
insert into [IA_ST_UnAccountVouch32]( IDUN, IDSUN, cVouTypeUN, cBustypeUN)
values({0},{1},'32','普通销售')
";
                                sSQL = string.Format(sSQL, modRD.ID, modRDs.AutoID);
                                DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                            }

                            CreateLog(sConn, sSOCode, mod.cDLCode, sRDCode, "Success", "");
                        }

                        StreamWriter(DateTime.Now.ToString("yyyyMMddHHmmss") + "  生成销售出库单,完成");

                        if (sErr != "")
                        {
                            throw new Exception(sErr);
                        }

                        #endregion

                        tran.Commit();
                    }
                    catch (Exception ee)
                    {
                        StreamWriter(DateTime.Now.ToString("yyyyMMddHHmmss") + "  " + ee.Message.ToString());
                        CreateLog(sConn, sSOCode, "", "", "Error", ee.Message);
                        tran.Rollback();
                    }

                    #endregion
                }
            }
            catch (Exception ee)
            {
                StreamWriter(DateTime.Now.ToString("yyyyMMddHHmmss") + "  " + ee.Message.ToString());

                throw new Exception(ee.Message);
            }
            finally
            {
                StreamWriter(DateTime.Now.ToString("yyyyMMddHHmmss") + @"【End】-----------------------------------------------------------");
                StreamWriter("");
                StreamWriter("");
            }
        }