Exemple #1
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public string Add(TH.clsU8.Model.rdrecords09 model)
        {
            StringBuilder strSql  = new StringBuilder();
            StringBuilder strSql1 = new StringBuilder();
            StringBuilder strSql2 = new StringBuilder();

            if (model.AutoID != null)
            {
                strSql1.Append("AutoID,");
                strSql2.Append("" + model.AutoID + ",");
            }
            if (model.ID != null)
            {
                strSql1.Append("ID,");
                strSql2.Append("" + model.ID + ",");
            }
            if (model.cInvCode != null)
            {
                strSql1.Append("cInvCode,");
                strSql2.Append("'" + model.cInvCode + "',");
            }
            if (model.iNum != null)
            {
                strSql1.Append("iNum,");
                strSql2.Append("" + model.iNum + ",");
            }
            if (model.iQuantity != null)
            {
                strSql1.Append("iQuantity,");
                strSql2.Append("" + model.iQuantity + ",");
            }
            if (model.iUnitCost != null)
            {
                strSql1.Append("iUnitCost,");
                strSql2.Append("" + model.iUnitCost + ",");
            }
            if (model.iPrice != null)
            {
                strSql1.Append("iPrice,");
                strSql2.Append("" + model.iPrice + ",");
            }
            if (model.iAPrice != null)
            {
                strSql1.Append("iAPrice,");
                strSql2.Append("" + model.iAPrice + ",");
            }
            if (model.iPUnitCost != null)
            {
                strSql1.Append("iPUnitCost,");
                strSql2.Append("" + model.iPUnitCost + ",");
            }
            if (model.iPPrice != null)
            {
                strSql1.Append("iPPrice,");
                strSql2.Append("" + model.iPPrice + ",");
            }
            if (model.cBatch != null)
            {
                strSql1.Append("cBatch,");
                strSql2.Append("'" + model.cBatch + "',");
            }
            if (model.cVouchCode != null)
            {
                strSql1.Append("cVouchCode,");
                strSql2.Append("" + model.cVouchCode + ",");
            }
            if (model.cInVouchCode != null)
            {
                strSql1.Append("cInVouchCode,");
                strSql2.Append("'" + model.cInVouchCode + "',");
            }
            if (model.cinvouchtype != null)
            {
                strSql1.Append("cinvouchtype,");
                strSql2.Append("'" + model.cinvouchtype + "',");
            }
            if (model.iSOutQuantity != null)
            {
                strSql1.Append("iSOutQuantity,");
                strSql2.Append("" + model.iSOutQuantity + ",");
            }
            if (model.iSOutNum != null)
            {
                strSql1.Append("iSOutNum,");
                strSql2.Append("" + model.iSOutNum + ",");
            }
            if (model.coutvouchid != null)
            {
                strSql1.Append("coutvouchid,");
                strSql2.Append("" + model.coutvouchid + ",");
            }
            if (model.coutvouchtype != null)
            {
                strSql1.Append("coutvouchtype,");
                strSql2.Append("'" + model.coutvouchtype + "',");
            }
            if (model.iSRedOutQuantity != null)
            {
                strSql1.Append("iSRedOutQuantity,");
                strSql2.Append("" + model.iSRedOutQuantity + ",");
            }
            if (model.iSRedOutNum != null)
            {
                strSql1.Append("iSRedOutNum,");
                strSql2.Append("" + model.iSRedOutNum + ",");
            }
            if (model.cFree1 != null)
            {
                strSql1.Append("cFree1,");
                strSql2.Append("'" + model.cFree1 + "',");
            }
            if (model.cFree2 != null)
            {
                strSql1.Append("cFree2,");
                strSql2.Append("'" + model.cFree2 + "',");
            }
            if (model.iFlag != null)
            {
                strSql1.Append("iFlag,");
                strSql2.Append("" + model.iFlag + ",");
            }
            if (model.iFNum != null)
            {
                strSql1.Append("iFNum,");
                strSql2.Append("" + model.iFNum + ",");
            }
            if (model.iFQuantity != null)
            {
                strSql1.Append("iFQuantity,");
                strSql2.Append("" + model.iFQuantity + ",");
            }
            if (model.dVDate != null)
            {
                strSql1.Append("dVDate,");
                strSql2.Append("'" + model.dVDate + "',");
            }
            if (model.iTrIds != null)
            {
                strSql1.Append("iTrIds,");
                strSql2.Append("" + model.iTrIds + ",");
            }
            if (model.cPosition != null)
            {
                strSql1.Append("cPosition,");
                strSql2.Append("'" + model.cPosition + "',");
            }
            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.cItem_class != null)
            {
                strSql1.Append("cItem_class,");
                strSql2.Append("'" + model.cItem_class + "',");
            }
            if (model.cItemCode != null)
            {
                strSql1.Append("cItemCode,");
                strSql2.Append("'" + model.cItemCode + "',");
            }
            if (model.iDLsID != null)
            {
                strSql1.Append("iDLsID,");
                strSql2.Append("" + model.iDLsID + ",");
            }
            if (model.cName != null)
            {
                strSql1.Append("cName,");
                strSql2.Append("'" + model.cName + "',");
            }
            if (model.cItemCName != null)
            {
                strSql1.Append("cItemCName,");
                strSql2.Append("'" + model.cItemCName + "',");
            }
            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.cBarCode != null)
            {
                strSql1.Append("cBarCode,");
                strSql2.Append("'" + model.cBarCode + "',");
            }
            if (model.iNQuantity != null)
            {
                strSql1.Append("iNQuantity,");
                strSql2.Append("" + model.iNQuantity + ",");
            }
            if (model.iNNum != null)
            {
                strSql1.Append("iNNum,");
                strSql2.Append("" + model.iNNum + ",");
            }
            if (model.cAssUnit != null)
            {
                strSql1.Append("cAssUnit,");
                strSql2.Append("'" + model.cAssUnit + "',");
            }
            if (model.dMadeDate != null)
            {
                strSql1.Append("dMadeDate,");
                strSql2.Append("'" + model.dMadeDate + "',");
            }
            if (model.iMassDate != null)
            {
                strSql1.Append("iMassDate,");
                strSql2.Append("" + model.iMassDate + ",");
            }
            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.iCheckIds != null)
            {
                strSql1.Append("iCheckIds,");
                strSql2.Append("" + model.iCheckIds + ",");
            }
            if (model.cBVencode != null)
            {
                strSql1.Append("cBVencode,");
                strSql2.Append("'" + model.cBVencode + "',");
            }
            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.cCheckCode != null)
            {
                strSql1.Append("cCheckCode,");
                strSql2.Append("'" + model.cCheckCode + "',");
            }
            if (model.iCheckIdBaks != null)
            {
                strSql1.Append("iCheckIdBaks,");
                strSql2.Append("" + model.iCheckIdBaks + ",");
            }
            if (model.cRejectCode != null)
            {
                strSql1.Append("cRejectCode,");
                strSql2.Append("'" + model.cRejectCode + "',");
            }
            if (model.iRejectIds != null)
            {
                strSql1.Append("iRejectIds,");
                strSql2.Append("" + model.iRejectIds + ",");
            }
            if (model.cCheckPersonCode != null)
            {
                strSql1.Append("cCheckPersonCode,");
                strSql2.Append("'" + model.cCheckPersonCode + "',");
            }
            if (model.dCheckDate != null)
            {
                strSql1.Append("dCheckDate,");
                strSql2.Append("'" + model.dCheckDate + "',");
            }
            if (model.cMassUnit != null)
            {
                strSql1.Append("cMassUnit,");
                strSql2.Append("" + model.cMassUnit + ",");
            }
            if (model.bChecked != null)
            {
                strSql1.Append("bChecked,");
                strSql2.Append("" + (model.bChecked ? 1 : 0) + ",");
            }
            if (model.iEqDID != null)
            {
                strSql1.Append("iEqDID,");
                strSql2.Append("" + model.iEqDID + ",");
            }
            if (model.bLPUseFree != null)
            {
                strSql1.Append("bLPUseFree,");
                strSql2.Append("" + (model.bLPUseFree ? 1 : 0) + ",");
            }
            if (model.iRSRowNO != null)
            {
                strSql1.Append("iRSRowNO,");
                strSql2.Append("" + model.iRSRowNO + ",");
            }
            if (model.iOriTrackID != null)
            {
                strSql1.Append("iOriTrackID,");
                strSql2.Append("" + model.iOriTrackID + ",");
            }
            if (model.coritracktype != null)
            {
                strSql1.Append("coritracktype,");
                strSql2.Append("'" + model.coritracktype + "',");
            }
            if (model.cbaccounter != null)
            {
                strSql1.Append("cbaccounter,");
                strSql2.Append("'" + model.cbaccounter + "',");
            }
            if (model.dbKeepDate != null)
            {
                strSql1.Append("dbKeepDate,");
                strSql2.Append("'" + model.dbKeepDate + "',");
            }
            if (model.bCosting != null)
            {
                strSql1.Append("bCosting,");
                strSql2.Append("" + (model.bCosting ? 1 : 0) + ",");
            }
            if (model.bVMIUsed != null)
            {
                strSql1.Append("bVMIUsed,");
                strSql2.Append("" + (model.bVMIUsed ? 1 : 0) + ",");
            }
            if (model.iVMISettleQuantity != null)
            {
                strSql1.Append("iVMISettleQuantity,");
                strSql2.Append("" + model.iVMISettleQuantity + ",");
            }
            if (model.iVMISettleNum != null)
            {
                strSql1.Append("iVMISettleNum,");
                strSql2.Append("" + model.iVMISettleNum + ",");
            }
            if (model.cvmivencode != null)
            {
                strSql1.Append("cvmivencode,");
                strSql2.Append("'" + model.cvmivencode + "',");
            }
            if (model.iInvSNCount != null)
            {
                strSql1.Append("iInvSNCount,");
                strSql2.Append("" + model.iInvSNCount + ",");
            }
            if (model.cwhpersoncode != null)
            {
                strSql1.Append("cwhpersoncode,");
                strSql2.Append("'" + model.cwhpersoncode + "',");
            }
            if (model.cwhpersonname != null)
            {
                strSql1.Append("cwhpersonname,");
                strSql2.Append("'" + model.cwhpersonname + "',");
            }
            if (model.cserviceoid != null)
            {
                strSql1.Append("cserviceoid,");
                strSql2.Append("'" + model.cserviceoid + "',");
            }
            if (model.cbserviceoid != null)
            {
                strSql1.Append("cbserviceoid,");
                strSql2.Append("'" + model.cbserviceoid + "',");
            }
            if (model.iinvexchrate != null)
            {
                strSql1.Append("iinvexchrate,");
                strSql2.Append("" + model.iinvexchrate + ",");
            }
            if (model.cbdlcode != null)
            {
                strSql1.Append("cbdlcode,");
                strSql2.Append("'" + model.cbdlcode + "',");
            }
            if (model.corufts != null)
            {
                strSql1.Append("corufts,");
                strSql2.Append("'" + model.corufts + "',");
            }
            if (model.strContractGUID != null)
            {
                strSql1.Append("strContractGUID,");
                strSql2.Append("'" + Guid.NewGuid().ToString() + "',");
            }
            if (model.iExpiratDateCalcu != null)
            {
                strSql1.Append("iExpiratDateCalcu,");
                strSql2.Append("" + model.iExpiratDateCalcu + ",");
            }
            if (model.cExpirationdate != null)
            {
                strSql1.Append("cExpirationdate,");
                strSql2.Append("'" + model.cExpirationdate + "',");
            }
            if (model.dExpirationdate != null)
            {
                strSql1.Append("dExpirationdate,");
                strSql2.Append("'" + model.dExpirationdate + "',");
            }
            if (model.cciqbookcode != null)
            {
                strSql1.Append("cciqbookcode,");
                strSql2.Append("'" + model.cciqbookcode + "',");
            }
            if (model.iBondedSumQty != null)
            {
                strSql1.Append("iBondedSumQty,");
                strSql2.Append("" + model.iBondedSumQty + ",");
            }
            if (model.ccusinvcode != null)
            {
                strSql1.Append("ccusinvcode,");
                strSql2.Append("'" + model.ccusinvcode + "',");
            }
            if (model.ccusinvname != null)
            {
                strSql1.Append("ccusinvname,");
                strSql2.Append("'" + model.ccusinvname + "',");
            }
            if (model.iorderdid != null)
            {
                strSql1.Append("iorderdid,");
                strSql2.Append("" + model.iorderdid + ",");
            }
            if (model.iordertype != null)
            {
                strSql1.Append("iordertype,");
                strSql2.Append("" + model.iordertype + ",");
            }
            if (model.iordercode != null)
            {
                strSql1.Append("iordercode,");
                strSql2.Append("'" + model.iordercode + "',");
            }
            if (model.iorderseq != null)
            {
                strSql1.Append("iorderseq,");
                strSql2.Append("" + model.iorderseq + ",");
            }
            if (model.isodid != null)
            {
                strSql1.Append("isodid,");
                strSql2.Append("'" + model.isodid + "',");
            }
            if (model.isotype != null)
            {
                strSql1.Append("isotype,");
                strSql2.Append("" + model.isotype + ",");
            }
            if (model.csocode != null)
            {
                strSql1.Append("csocode,");
                strSql2.Append("'" + model.csocode + "',");
            }
            if (model.isoseq != null)
            {
                strSql1.Append("isoseq,");
                strSql2.Append("" + model.isoseq + ",");
            }
            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.cbMemo != null)
            {
                strSql1.Append("cbMemo,");
                strSql2.Append("'" + model.cbMemo + "',");
            }
            if (model.irowno != null)
            {
                strSql1.Append("irowno,");
                strSql2.Append("" + model.irowno + ",");
            }
            if (model.strowguid != null)
            {
                strSql1.Append("strowguid,");
                strSql2.Append("'" + Guid.NewGuid().ToString() + "',");
            }
            if (model.rowufts != null)
            {
                strSql1.Append("rowufts,");
                strSql2.Append("" + model.rowufts + ",");
            }
            if (model.ipreuseqty != null)
            {
                strSql1.Append("ipreuseqty,");
                strSql2.Append("" + model.ipreuseqty + ",");
            }
            if (model.ipreuseinum != null)
            {
                strSql1.Append("ipreuseinum,");
                strSql2.Append("" + model.ipreuseinum + ",");
            }
            if (model.cbsourcecodels != null)
            {
                strSql1.Append("cbsourcecodels,");
                strSql2.Append("'" + model.cbsourcecodels + "',");
            }
            if (model.iGroupNO != null)
            {
                strSql1.Append("iGroupNO,");
                strSql2.Append("" + model.iGroupNO + ",");
            }
            if (model.iDebitIDs != null)
            {
                strSql1.Append("iDebitIDs,");
                strSql2.Append("" + model.iDebitIDs + ",");
            }
            if (model.idebitchildids != null)
            {
                strSql1.Append("idebitchildids,");
                strSql2.Append("" + model.idebitchildids + ",");
            }
            if (model.iimosid != null)
            {
                strSql1.Append("iimosid,");
                strSql2.Append("" + model.iimosid + ",");
            }
            if (model.cPOID != null)
            {
                strSql1.Append("cPOID,");
                strSql2.Append("'" + model.cPOID + "',");
            }
            if (model.strContractId != null)
            {
                strSql1.Append("strContractId,");
                strSql2.Append("'" + model.strContractId + "',");
            }
            if (model.strCode != null)
            {
                strSql1.Append("strCode,");
                strSql2.Append("'" + model.strCode + "',");
            }
            if (model.cInVoucherLineID != null)
            {
                strSql1.Append("cInVoucherLineID,");
                strSql2.Append("" + model.cInVoucherLineID + ",");
            }
            if (model.cInVoucherCode != null)
            {
                strSql1.Append("cInVoucherCode,");
                strSql2.Append("'" + model.cInVoucherCode + "',");
            }
            if (model.cInVoucherType != null)
            {
                strSql1.Append("cInVoucherType,");
                strSql2.Append("'" + model.cInVoucherType + "',");
            }
            if (model.cbsysbarcode != null)
            {
                strSql1.Append("cbsysbarcode,");
                strSql2.Append("'" + model.cbsysbarcode + "',");
            }
            if (model.ipickedquantity != null)
            {
                strSql1.Append("ipickedquantity,");
                strSql2.Append("" + model.ipickedquantity + ",");
            }
            if (model.ipickednum != null)
            {
                strSql1.Append("ipickednum,");
                strSql2.Append("" + model.ipickednum + ",");
            }
            strSql.Append("insert into rdrecords09(");
            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
            {
                string        sErr   = "";
                int           iCount = 0;
                SqlConnection conn   = new SqlConnection(sConnString);
                conn.Open();
                //启用事务
                SqlTransaction tran = conn.BeginTransaction();
                string         sSQL = "";
                try
                {
                    string s采购订单号 = gridView1.GetRowCellValue(0, gridColcPOID).ToString().Trim();
                    sSQL = @"
select a.cPOID 
from PO_PoMain a inner join PO_Podetails b on a.POID = b.POID
	inner join  RdRecord09 c on b.cDefine33 = c.cCode
	and a.cPOID = '111111'
";
                    sSQL = sSQL.Replace("111111", s采购订单号);
                    DataTable dt = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                    if (dt != null && dt.Rows.Count > 0)
                    {
                        throw new Exception("Packing bag has been out of the warehouse");
                    }

                    sSQL = "select isnull(bflag_ST,0) as bflag_ST from GL_mend where iYPeriod = '" + dateEdit1.DateTime.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_ST"]);
                    if (i结账 > 0)
                    {
                        throw new Exception(dateEdit1.DateTime.ToString("yyyy-MM") + " have checked out");
                    }

                    int iCouRow = gridView1.RowCount;

                    DateTime dLog     = dateEdit1.DateTime;
                    DateTime sLogDate = dateEdit1.DateTime;

                    //获得单据号
                    sSQL = "select cNumber from VoucherHistory Where CardNumber='0302'";        // and cSeed = '" + dLog.ToString("yyyyMM") + "'
                    dt   = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];

                    long lCode = 0;
                    if (dt != null && dt.Rows.Count > 0)
                    {
                        lCode  = BaseFunction.ReturnLong(dt.Rows[0]["cNumber"]);
                        lCode += 1;
                        sSQL   = "update  VoucherHistory set cNumber = '" + lCode.ToString() + "' Where CardNumber='0302'";
                        DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                    }
                    else
                    {
                        lCode = 1;
                        sSQL  = "insert into VoucherHistory(CardNumber,cContent,cContentRule,cSeed,cNumber,bEmpty)" +
                                "values('0302',null,null,null,'1',0)";
                        DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                    }


                    string sCode = lCode.ToString();
                    while (sCode.Length < 10)
                    {
                        sCode = "0" + sCode;
                    }


                    long lID        = -1;
                    long lIDDetails = -1;
                    sSQL = @"
declare @p5 int
set @p5=111111
declare @p6 int
set @p6=222222
exec sp_GetId N'',N'003',N'rd',333333,@p5 output,@p6 output,default
select @p5, @p6
";
                    sSQL = sSQL.Replace("111111", lID.ToString());
                    sSQL = sSQL.Replace("222222", lIDDetails.ToString());
                    sSQL = sSQL.Replace("333333", iCouRow.ToString());
                    dt   = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];

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

                    TH.clsU8.Model.RdRecord09 model = new TH.clsU8.Model.RdRecord09();
                    lID             += 1;
                    model.ID         = lID;
                    model.bRdFlag    = 0;
                    model.cVouchType = "09";
                    model.cBusType   = "其他出库";
                    model.cSource    = "库存";
                    //model.cBusCode
                    model.cWhCode = lookUpEditWarehouse.EditValue.ToString().Trim();
                    model.dDate   = BaseFunction.ReturnDate(dateEdit1.DateTime.ToString("yyyy-MM-dd"));
                    model.cCode   = sCode;
                    model.cRdCode = lookUpEditOutType.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.bTransFlag       = false;
                    model.bpufirst         = false;
                    model.biafirst         = false;
                    model.VT_ID            = 85;
                    model.bIsSTQc          = false;
                    model.bFromPreYear     = false;
                    model.bIsComplement    = 0;
                    model.iDiscountTaxType = 0;
                    model.iBG_OverFlag     = 0;
                    model.dnmaketime       = DateTime.Now;
                    model.bredvouch        = 0;
                    model.iPrintCount      = 0;
                    model.csysbarcode      = "||st09|" + sCode;
                    model.cMaker           = sUserName;
                    model.cDefine1         = s采购订单号;
                    model.cHandler         = sUserName;
                    model.dVeriDate        = BaseFunction.ReturnDate(DateTime.Now.ToString("yyyy-MM-dd"));
                    model.dnverifytime     = DateTime.Now;

                    TH.clsU8.DAL.RdRecord09 dal = new TH.clsU8.DAL.RdRecord09();
                    sSQL = dal.Add(model);
                    DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);

                    int iRow = 0;
                    for (int i = 0; i < gridView1.RowCount; i++)
                    {
                        string scInvCode  = gridView1.GetRowCellValue(i, gridColcInvCode).ToString().Trim();
                        string scInvCode2 = gridView1.GetRowCellValue(i, gridColcInvCode2).ToString().Trim();

                        if (scInvCode2 == "")
                        {
                            sErr = sErr + "Item Code " + scInvCode + " no set\n";
                            continue;
                        }

                        decimal dQty = clsU8.BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridColQty), 2);

                        string sInvCode = gridView1.GetRowCellValue(i, gridColcInvCode2).ToString().Trim();
                        sSQL = "select cInvCode,cWhCode,iQuantity as iQty,cWhCode,isnull(cBatch,'') as cBatch from currentstock   where cInvCode = '" + sInvCode + "' and cWhCode = '" + model.cWhCode + "' order by cBatch";
                        dt   = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];

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

                            string  sBatch      = dt.Rows[j]["cBatch"].ToString().Trim();
                            decimal dCurrQtyRow = BaseFunction.ReturnDecimal(dt.Rows[j]["iQty"], 2);

                            if (dCurrQtyRow <= 0)
                            {
                                continue;
                            }

                            decimal dOutRow = 0;
                            if (dCurrQtyRow >= dQty)
                            {
                                dOutRow = dQty;
                                dQty    = 0;
                            }
                            else
                            {
                                dOutRow = dCurrQtyRow;
                                dQty    = dQty - dCurrQtyRow;
                            }

                            TH.clsU8.Model.rdrecords09 models = new TH.clsU8.Model.rdrecords09();

                            lIDDetails              += 1;
                            models.AutoID            = lIDDetails;
                            models.ID                = lID;
                            models.cInvCode          = sInvCode;
                            models.iQuantity         = dOutRow;
                            models.cBatch            = sBatch;
                            models.iFlag             = 0;
                            models.bLPUseFree        = false;
                            models.iRSRowNO          = 0;
                            models.iOriTrackID       = 0;
                            models.bCosting          = true;
                            models.bVMIUsed          = false;
                            models.iExpiratDateCalcu = 0;
                            models.iordertype        = 0;
                            models.isotype           = 0;
                            models.irowno            = iRow;

                            iRow += 1;
                            models.cbsysbarcode = "||st09|" + sCode + "|" + (iRow + 1).ToString();



                            TH.clsU8.DAL.rdrecords09 dals = new TH.clsU8.DAL.rdrecords09();
                            sSQL   = dals.Add(models);
                            iCount = iCount + DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);

                            sSQL = "update PO_Podetails set cDefine34 = " + models.iQuantity.ToString() + ",cDefine33 = '" + model.cCode + "' where ID = " + gridView1.GetRowCellValue(i, gridColID).ToString();
                            DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);

                            if (sBatch == "")
                            {
                                sSQL = "update currentstock set iQuantity = iQuantity - " + models.iQuantity.ToString().Trim() + " where cInvCode = '" + models.cInvCode + "' and cWhCode = '" + model.cWhCode + "' and isnull(cBatch,'') =''";
                            }
                            else
                            {
                                sSQL = "update currentstock set iQuantity = iQuantity - " + models.iQuantity.ToString().Trim() + " where cInvCode = '" + models.cInvCode + "' and cWhCode = '" + model.cWhCode + "' and isnull(cBatch,'') = '" + sBatch + "'";
                            }
                            DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                        }
                    }

                    if (sErr != "")
                    {
                        throw new Exception(sErr);
                    }
                    if (iCount > 0)
                    {
                        tran.Commit();

                        MessageBox.Show("OK\n" + sCode);
                    }
                    else
                    {
                        throw new Exception("Save failed");
                    }
                }
                catch (Exception error)
                {
                    tran.Rollback();
                    throw new Exception(error.Message);
                }
            }
            catch (Exception ee)
            {
                MessageBox.Show(ee.Message);
            }
        }