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

            if (model.ID != null)
            {
                strSql1.Append("ID,");
                strSql2.Append("" + model.ID + ",");
            }
            if (model.bRdFlag != null)
            {
                strSql1.Append("bRdFlag,");
                strSql2.Append("" + model.bRdFlag + ",");
            }
            if (model.cVouchType != null)
            {
                strSql1.Append("cVouchType,");
                strSql2.Append("'" + model.cVouchType + "',");
            }
            if (model.cBusType != null)
            {
                strSql1.Append("cBusType,");
                strSql2.Append("'" + model.cBusType + "',");
            }
            if (model.cSource != null)
            {
                strSql1.Append("cSource,");
                strSql2.Append("'" + model.cSource + "',");
            }
            if (model.cBusCode != null)
            {
                strSql1.Append("cBusCode,");
                strSql2.Append("'" + model.cBusCode + "',");
            }
            if (model.cWhCode != null)
            {
                strSql1.Append("cWhCode,");
                strSql2.Append("'" + model.cWhCode + "',");
            }
            if (model.dDate != null)
            {
                strSql1.Append("dDate,");
                strSql2.Append("'" + model.dDate + "',");
            }
            if (model.cCode != null)
            {
                strSql1.Append("cCode,");
                strSql2.Append("'" + model.cCode + "',");
            }
            if (model.cRdCode != null)
            {
                strSql1.Append("cRdCode,");
                strSql2.Append("'" + model.cRdCode + "',");
            }
            if (model.cDepCode != null)
            {
                strSql1.Append("cDepCode,");
                strSql2.Append("'" + model.cDepCode + "',");
            }
            if (model.cPersonCode != null)
            {
                strSql1.Append("cPersonCode,");
                strSql2.Append("'" + model.cPersonCode + "',");
            }
            if (model.cPTCode != null)
            {
                strSql1.Append("cPTCode,");
                strSql2.Append("'" + model.cPTCode + "',");
            }
            if (model.cSTCode != null)
            {
                strSql1.Append("cSTCode,");
                strSql2.Append("'" + model.cSTCode + "',");
            }
            if (model.cCusCode != null)
            {
                strSql1.Append("cCusCode,");
                strSql2.Append("'" + model.cCusCode + "',");
            }
            if (model.cVenCode != null)
            {
                strSql1.Append("cVenCode,");
                strSql2.Append("'" + model.cVenCode + "',");
            }
            if (model.cOrderCode != null)
            {
                strSql1.Append("cOrderCode,");
                strSql2.Append("'" + model.cOrderCode + "',");
            }
            if (model.cARVCode != null)
            {
                strSql1.Append("cARVCode,");
                strSql2.Append("'" + model.cARVCode + "',");
            }
            if (model.cBillCode != null)
            {
                strSql1.Append("cBillCode,");
                strSql2.Append("" + model.cBillCode + ",");
            }
            if (model.cDLCode != null)
            {
                strSql1.Append("cDLCode,");
                strSql2.Append("" + model.cDLCode + ",");
            }
            if (model.cProBatch != null)
            {
                strSql1.Append("cProBatch,");
                strSql2.Append("'" + model.cProBatch + "',");
            }
            if (model.cHandler != null)
            {
                strSql1.Append("cHandler,");
                strSql2.Append("'" + model.cHandler + "',");
            }
            if (model.cMemo != null)
            {
                strSql1.Append("cMemo,");
                strSql2.Append("'" + model.cMemo + "',");
            }
            if (model.bTransFlag != null)
            {
                strSql1.Append("bTransFlag,");
                strSql2.Append("" + (model.bTransFlag ? 1 : 0) + ",");
            }
            if (model.cAccounter != null)
            {
                strSql1.Append("cAccounter,");
                strSql2.Append("'" + model.cAccounter + "',");
            }
            if (model.cMaker != null)
            {
                strSql1.Append("cMaker,");
                strSql2.Append("'" + model.cMaker + "',");
            }
            if (model.cDefine1 != null)
            {
                strSql1.Append("cDefine1,");
                strSql2.Append("'" + model.cDefine1 + "',");
            }
            if (model.cDefine2 != null)
            {
                strSql1.Append("cDefine2,");
                strSql2.Append("'" + model.cDefine2 + "',");
            }
            if (model.cDefine3 != null)
            {
                strSql1.Append("cDefine3,");
                strSql2.Append("'" + model.cDefine3 + "',");
            }
            if (model.cDefine4 != null)
            {
                strSql1.Append("cDefine4,");
                strSql2.Append("'" + model.cDefine4 + "',");
            }
            if (model.cDefine5 != null)
            {
                strSql1.Append("cDefine5,");
                strSql2.Append("" + model.cDefine5 + ",");
            }
            if (model.cDefine6 != null)
            {
                strSql1.Append("cDefine6,");
                strSql2.Append("'" + model.cDefine6 + "',");
            }
            if (model.cDefine7 != null)
            {
                strSql1.Append("cDefine7,");
                strSql2.Append("" + model.cDefine7 + ",");
            }
            if (model.cDefine8 != null)
            {
                strSql1.Append("cDefine8,");
                strSql2.Append("'" + model.cDefine8 + "',");
            }
            if (model.cDefine9 != null)
            {
                strSql1.Append("cDefine9,");
                strSql2.Append("'" + model.cDefine9 + "',");
            }
            if (model.cDefine10 != null)
            {
                strSql1.Append("cDefine10,");
                strSql2.Append("'" + model.cDefine10 + "',");
            }
            if (model.dKeepDate != null)
            {
                strSql1.Append("dKeepDate,");
                strSql2.Append("'" + model.dKeepDate + "',");
            }
            if (model.dVeriDate != null)
            {
                strSql1.Append("dVeriDate,");
                strSql2.Append("'" + model.dVeriDate + "',");
            }
            if (model.bpufirst != null)
            {
                strSql1.Append("bpufirst,");
                strSql2.Append("" + (model.bpufirst ? 1 : 0) + ",");
            }
            if (model.biafirst != null)
            {
                strSql1.Append("biafirst,");
                strSql2.Append("" + (model.biafirst ? 1 : 0) + ",");
            }
            if (model.iMQuantity != null)
            {
                strSql1.Append("iMQuantity,");
                strSql2.Append("" + model.iMQuantity + ",");
            }
            if (model.dARVDate != null)
            {
                strSql1.Append("dARVDate,");
                strSql2.Append("'" + model.dARVDate + "',");
            }
            if (model.cChkCode != null)
            {
                strSql1.Append("cChkCode,");
                strSql2.Append("'" + model.cChkCode + "',");
            }
            if (model.dChkDate != null)
            {
                strSql1.Append("dChkDate,");
                strSql2.Append("'" + model.dChkDate + "',");
            }
            if (model.cChkPerson != null)
            {
                strSql1.Append("cChkPerson,");
                strSql2.Append("'" + model.cChkPerson + "',");
            }
            if (model.VT_ID != null)
            {
                strSql1.Append("VT_ID,");
                strSql2.Append("" + model.VT_ID + ",");
            }
            if (model.bIsSTQc != null)
            {
                strSql1.Append("bIsSTQc,");
                strSql2.Append("" + (model.bIsSTQc ? 1 : 0) + ",");
            }
            if (model.cDefine11 != null)
            {
                strSql1.Append("cDefine11,");
                strSql2.Append("'" + model.cDefine11 + "',");
            }
            if (model.cDefine12 != null)
            {
                strSql1.Append("cDefine12,");
                strSql2.Append("'" + model.cDefine12 + "',");
            }
            if (model.cDefine13 != null)
            {
                strSql1.Append("cDefine13,");
                strSql2.Append("'" + model.cDefine13 + "',");
            }
            if (model.cDefine14 != null)
            {
                strSql1.Append("cDefine14,");
                strSql2.Append("'" + model.cDefine14 + "',");
            }
            if (model.cDefine15 != null)
            {
                strSql1.Append("cDefine15,");
                strSql2.Append("" + model.cDefine15 + ",");
            }
            if (model.cDefine16 != null)
            {
                strSql1.Append("cDefine16,");
                strSql2.Append("" + model.cDefine16 + ",");
            }
            if (model.gspcheck != null)
            {
                strSql1.Append("gspcheck,");
                strSql2.Append("'" + model.gspcheck + "',");
            }
            if (model.ufts != null)
            {
                strSql1.Append("ufts,");
                strSql2.Append("" + model.ufts + ",");
            }
            if (model.iExchRate != null)
            {
                strSql1.Append("iExchRate,");
                strSql2.Append("" + model.iExchRate + ",");
            }
            if (model.cExch_Name != null)
            {
                strSql1.Append("cExch_Name,");
                strSql2.Append("'" + model.cExch_Name + "',");
            }
            if (model.cShipAddress != null)
            {
                strSql1.Append("cShipAddress,");
                strSql2.Append("'" + model.cShipAddress + "',");
            }
            if (model.caddcode != null)
            {
                strSql1.Append("caddcode,");
                strSql2.Append("'" + model.caddcode + "',");
            }
            if (model.bOMFirst != null)
            {
                strSql1.Append("bOMFirst,");
                strSql2.Append("" + (model.bOMFirst ? 1 : 0) + ",");
            }
            if (model.bFromPreYear != null)
            {
                strSql1.Append("bFromPreYear,");
                strSql2.Append("" + (model.bFromPreYear ? 1 : 0) + ",");
            }
            if (model.bIsLsQuery != null)
            {
                strSql1.Append("bIsLsQuery,");
                strSql2.Append("" + (model.bIsLsQuery ? 1 : 0) + ",");
            }
            if (model.bIsComplement != null)
            {
                strSql1.Append("bIsComplement,");
                strSql2.Append("" + model.bIsComplement + ",");
            }
            if (model.iDiscountTaxType != null)
            {
                strSql1.Append("iDiscountTaxType,");
                strSql2.Append("" + model.iDiscountTaxType + ",");
            }
            if (model.iBG_OverFlag != null)
            {
                strSql1.Append("iBG_OverFlag,");
                strSql2.Append("" + model.iBG_OverFlag + ",");
            }
            if (model.cBG_Auditor != null)
            {
                strSql1.Append("cBG_Auditor,");
                strSql2.Append("'" + model.cBG_Auditor + "',");
            }
            if (model.cBG_AuditTime != null)
            {
                strSql1.Append("cBG_AuditTime,");
                strSql2.Append("'" + model.cBG_AuditTime + "',");
            }
            if (model.ControlResult != null)
            {
                strSql1.Append("ControlResult,");
                strSql2.Append("" + model.ControlResult + ",");
            }
            if (model.ireturncount != null)
            {
                strSql1.Append("ireturncount,");
                strSql2.Append("" + model.ireturncount + ",");
            }
            if (model.iverifystate != null)
            {
                strSql1.Append("iverifystate,");
                strSql2.Append("" + model.iverifystate + ",");
            }
            if (model.iswfcontrolled != null)
            {
                strSql1.Append("iswfcontrolled,");
                strSql2.Append("" + model.iswfcontrolled + ",");
            }
            if (model.cModifyPerson != null)
            {
                strSql1.Append("cModifyPerson,");
                strSql2.Append("'" + model.cModifyPerson + "',");
            }
            if (model.dModifyDate != null)
            {
                strSql1.Append("dModifyDate,");
                strSql2.Append("'" + model.dModifyDate + "',");
            }
            if (model.dnmaketime != null)
            {
                strSql1.Append("dnmaketime,");
                strSql2.Append("'" + model.dnmaketime + "',");
            }
            if (model.dnmodifytime != null)
            {
                strSql1.Append("dnmodifytime,");
                strSql2.Append("'" + model.dnmodifytime + "',");
            }
            if (model.dnverifytime != null)
            {
                strSql1.Append("dnverifytime,");
                strSql2.Append("'" + model.dnverifytime + "',");
            }
            if (model.bredvouch != null)
            {
                strSql1.Append("bredvouch,");
                strSql2.Append("" + model.bredvouch + ",");
            }
            if (model.iFlowId != null)
            {
                strSql1.Append("iFlowId,");
                strSql2.Append("" + model.iFlowId + ",");
            }
            if (model.cPZID != null)
            {
                strSql1.Append("cPZID,");
                strSql2.Append("'" + model.cPZID + "',");
            }
            if (model.cSourceLs != null)
            {
                strSql1.Append("cSourceLs,");
                strSql2.Append("'" + model.cSourceLs + "',");
            }
            if (model.cSourceCodeLs != null)
            {
                strSql1.Append("cSourceCodeLs,");
                strSql2.Append("'" + model.cSourceCodeLs + "',");
            }
            if (model.iPrintCount != null)
            {
                strSql1.Append("iPrintCount,");
                strSql2.Append("" + model.iPrintCount + ",");
            }
            if (model.ctransflag != null)
            {
                strSql1.Append("ctransflag,");
                strSql2.Append("'" + model.ctransflag + "',");
            }
            if (model.csysbarcode != null)
            {
                strSql1.Append("csysbarcode,");
                strSql2.Append("'" + model.csysbarcode + "',");
            }
            if (model.cCurrentAuditor != null)
            {
                strSql1.Append("cCurrentAuditor,");
                strSql2.Append("'" + model.cCurrentAuditor + "',");
            }
            strSql.Append("insert into RdRecord09(");
            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());
        }
Exemplo n.º 2
0
        /// <summary>
        /// 保存调拨单扫描数量
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public int iSaveGetTransVouchChkQty(string sCode, DataTable dtBarCode, string sUid)
        {
            int iCou = 0;

            try
            {
                string sTrCode = sCode;

                SqlConnection conn = new SqlConnection(DbHelperSQL.connectionString);
                conn.Open();
                //启用事务
                SqlTransaction tran = conn.BeginTransaction();
                try
                {
                    decimal dQtyScanSum = 0;        //  累计扫描数量
                    for (int i = 0; i < dtBarCode.Rows.Count; i++)
                    {
                        dQtyScanSum = dQtyScanSum + ClsBaseDataInfo.ReturnObjectToDecimal(dtBarCode.Rows[i]["数量"]);
                    }

                    string    sSQL         = "select a.cTVCode as cCode,b.irowno,b.cInvCode ,b.iTVQuantity as iQuantity,b.cDefine29 as 已扫描数量,cast(null as decimal(16,6)) as 本次扫描数量,b.autoid from TransVouch a inner join TransVouchs b on a.cTVCode = b.cTVCode  where a.cTVCode = '" + sCode + "' order by b.cInvCode";
                    DataTable dtRdRecord11 = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];

                    sSQL = "select getdate()";
                    DataTable dtTime          = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                    DateTime  dtmNow          = BaseFunction.ReturnDate(dtTime.Rows[0][0]);
                    string    s_BarCodeRDCode = BaseFunction.ReturnDate(dtTime.Rows[0][0]).ToString("yyMMddHHmmss");
                    dtTime = null;

                    _BarCodeRD   DAL_BarCodeRD   = new _BarCodeRD();
                    _BarCodeList DAL_BarCodeList = new _BarCodeList();

                    for (int i = 0; i < dtBarCode.Rows.Count; i++)
                    {
                        string  sInvCode    = dtBarCode.Rows[i]["存货编码"].ToString().Trim();
                        decimal dQtyBarCode = BaseFunction.ReturnDecimal(dtBarCode.Rows[i]["数量"]);


                        //条形码中仅存货编码与入库单对应
                        DataRow[] drCode = dtRdRecord11.Select("cInvCode = '" + sInvCode + "'");

                        for (int j = 0; j < drCode.Length; j++)
                        {
                            if (dQtyBarCode <= 0)
                            {
                                break;
                            }

                            decimal diQuantity = BaseFunction.ReturnDecimal(drCode[j]["iQuantity"]);
                            decimal dQtyScaned = BaseFunction.ReturnDecimal(drCode[j]["已扫描数量"]);
                            decimal dQtyNow    = BaseFunction.ReturnDecimal(drCode[j]["本次扫描数量"]);
                            decimal d          = diQuantity - dQtyScaned - dQtyNow;


                            Model._BarCodeRD model_BarCodeRD = new TH.WebService.Model._BarCodeRD();
                            model_BarCodeRD.sCode      = s_BarCodeRDCode;
                            model_BarCodeRD.BarCode    = dtBarCode.Rows[i]["条形码"].ToString().Trim();
                            model_BarCodeRD.sType      = "调拨单";
                            model_BarCodeRD.ExsID      = BaseFunction.ReturnLong(drCode[j]["autoid"]);
                            model_BarCodeRD.ExCode     = drCode[j]["cCode"].ToString().Trim();
                            model_BarCodeRD.ExRowNo    = ClsBaseDataInfo.ReturnObjectToLong(drCode[j]["iRowNo"]);
                            model_BarCodeRD.cInvCode   = drCode[j]["cInvCode"].ToString().Trim();
                            model_BarCodeRD.CreateUid  = dtBarCode.Rows[i]["制单人"].ToString().Trim();
                            model_BarCodeRD.CreateDate = dtmNow;
                            model_BarCodeRD.XBarCode   = dtBarCode.Rows[i]["箱码"].ToString().Trim();
                            model_BarCodeRD.RDType     = 0;

                            //条形码数量超出单据数量
                            if (dQtyBarCode >= d)
                            {
                                model_BarCodeRD.Qty = d;
                                dQtyScanSum         = dQtyScanSum - d;

                                drCode[j]["本次扫描数量"] = BaseFunction.ReturnDecimal(drCode[j]["本次扫描数量"]) + d;
                                dQtyBarCode         = dQtyBarCode - d;
                            }
                            else
                            {
                                model_BarCodeRD.Qty = dQtyBarCode;
                                dQtyScanSum         = dQtyScanSum - dQtyBarCode;

                                drCode[j]["本次扫描数量"] = BaseFunction.ReturnDecimal(drCode[j]["本次扫描数量"]) + dQtyBarCode;
                                dQtyBarCode         = 0;
                            }

                            sSQL = DAL_BarCodeRD.Add(model_BarCodeRD);
                            iCou = iCou + DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);

                            sSQL = "update TransVouchs set cDefine29 = cast(isnull(cDefine29,0) as decimal(16,6)) + " + model_BarCodeRD.Qty.ToString() + " where autoid = " + model_BarCodeRD.ExsID.ToString();
                            DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                        }
                    }

                    if (dQtyScanSum != 0)
                    {
                        throw new Exception("扫描数量未完全分配");
                    }
                    if (iCou == 0)
                    {
                        throw new Exception("没有语句执行");
                    }


                    #region 判断所有数量扫描后审核单据

                    sSQL = "select getdate()";
                    DataTable dTime    = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                    DateTime  dTimeNow = ClsBaseDataInfo.ReturnObjectToDatetime(dTime.Rows[0][0]);
                    sSQL = @"
select case when sum(cast(isnull(b.cDefine29,0) as decimal(16,6))) <> sum(b.iTVQuantity) then 1 else 0 end as iCou
from TransVouch a inner join TransVouchs b on a.cTVCode = b.cTVCode
where a.cTVCode = '111111' 
group by a.cTVCode 

";
                    sSQL = sSQL.Replace("111111", sCode);
                    DataTable dtTemp2 = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                    if (dtTemp2 != null && dtTemp2.Rows.Count == 1)
                    {
                        int iC = BaseFunction.ReturnInt(dtTemp2.Rows[0][0]);
                        if (iC == 0)
                        {
                            sSQL = "update TransVouch set cVerifyPerson = '222222',dVerifyDate  = '333333',dnverifytime = getdate() where cTVCode = '111111'";
                            sSQL = sSQL.Replace("111111", sCode);
                            sSQL = sSQL.Replace("222222", sUid);
                            sSQL = sSQL.Replace("333333", dTimeNow.ToString("yyyy-MM-dd"));
                            DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);


                            sSQL = @"
select *
from TransVouch a inner join TransVouchs b on a.cTVCode = b.cTVCode
where a.cTVCode = '111111' 
order by autoid
";
                            sSQL = sSQL.Replace("111111", sCode);
                            DataTable dtTran  = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                            int       iCouRow = dtTran.Rows.Count;

                            #region 生成其他入库单据
                            //获得单据号
                            sSQL = "select cNumber from VoucherHistory Where CardNumber='0301' and cSeed = '" + dTimeNow.ToString("yyyyMM") + "'";
                            DataTable 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='0301'  and cSeed = '" + dTimeNow.ToString("yyyyMM") + "'";
                                DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                            }
                            else
                            {
                                lCode = 1;
                                sSQL  = "insert into VoucherHistory(CardNumber,cContent,cContentRule,cSeed,cNumber,bEmpty)" +
                                        "values('0301','日期','月','" + dTimeNow.ToString("yyyyMM") + "','1',0)";
                                DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                            }
                            sCode = lCode.ToString();
                            while (sCode.Length < 5)
                            {
                                sCode = "0" + sCode;
                            }

                            sCode = "QR" + dTimeNow.ToString("yyMM") + sCode;

                            long lID        = 0;
                            long lIDDetails = 0;


                            sSQL = @"
declare @p5 int
set @p5=111111
declare @p6 int
set @p6=222222
exec sp_GetId N'',N'444444',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());
                            sSQL = sSQL.Replace("444444", sAccID);
                            dt   = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];

                            lID        = ClsBaseDataInfo.ReturnObjectToLong(dt.Rows[0][0]) - 1;
                            lIDDetails = ClsBaseDataInfo.ReturnObjectToLong(dt.Rows[0][1]) - iCouRow;

                            lID += 1;
                            Model.RdRecord08 modelr8 = new TH.WebService.Model.RdRecord08();
                            modelr8.ID               = lID;
                            modelr8.bRdFlag          = 1;
                            modelr8.cVouchType       = "08";
                            modelr8.cBusType         = "调拨入库";
                            modelr8.cSource          = "调拨";
                            modelr8.cBusCode         = sTrCode;
                            modelr8.cWhCode          = dtTran.Rows[0]["cIWhCode"].ToString().Trim();
                            modelr8.dDate            = BaseFunction.ReturnDate(dTimeNow.ToString("yyyy-MM-dd"));
                            modelr8.cCode            = sCode;
                            modelr8.cRdCode          = dtTran.Rows[0]["cIRdCode"].ToString().Trim();
                            modelr8.cDepCode         = dtTran.Rows[0]["cIDepCode"].ToString().Trim();
                            modelr8.bTransFlag       = false;
                            modelr8.cMaker           = sUid;
                            modelr8.bpufirst         = false;
                            modelr8.biafirst         = false;
                            modelr8.VT_ID            = 67;
                            modelr8.bIsSTQc          = false;
                            modelr8.bOMFirst         = false;
                            modelr8.bFromPreYear     = false;
                            modelr8.bIsComplement    = 0;
                            modelr8.iDiscountTaxType = 0;
                            modelr8.ireturncount     = 0;
                            modelr8.iverifystate     = 0;
                            modelr8.iswfcontrolled   = 0;
                            modelr8.dnmaketime       = dTimeNow;
                            modelr8.bredvouch        = 0;
                            modelr8.iPrintCount      = 0;

                            DAL.RdRecord08 DALr8 = new RdRecord08();
                            sSQL = DALr8.Add(modelr8);
                            DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);

                            for (int i = 0; i < dtTran.Rows.Count; i++)
                            {
                                Model.rdrecords08 modelr8s = new TH.WebService.Model.rdrecords08();

                                lIDDetails         += 1;
                                modelr8s.AutoID     = lIDDetails;
                                modelr8s.ID         = lID;
                                modelr8s.cInvCode   = dtTran.Rows[i]["cInvCode"].ToString().Trim();
                                modelr8s.iQuantity  = BaseFunction.ReturnDecimal(dtTran.Rows[i]["iTVQuantity"]);
                                modelr8s.iNum       = BaseFunction.ReturnDecimal(dtTran.Rows[i]["iTVNum"]);
                                modelr8s.iTrIds     = BaseFunction.ReturnLong(dtTran.Rows[i]["autoID"]);
                                modelr8s.iNQuantity = BaseFunction.ReturnDecimal(dtTran.Rows[i]["iTVQuantity"]);
                                modelr8s.irowno     = BaseFunction.ReturnInt(dtTran.Rows[i]["irowno"]);

                                DAL.rdrecords08 DALr8s = new rdrecords08();
                                sSQL = DALr8s.Add(modelr8s);
                                DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);

                                sSQL = "insert into IA_ST_UnAccountVouch08(idun,idsun,cvoutypeun,cbustypeun)values " +
                                       "('" + lID + "','" + lIDDetails + "','08','调拨入库')";
                                DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                            }
                            #endregion

                            #region 生成其他出库单据
                            //获得单据号
                            sSQL = "select cNumber from VoucherHistory Where CardNumber='0302' and cSeed = '" + dTimeNow.ToString("yyyyMM") + "'";
                            dt   = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];

                            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'  and cSeed = '" + dTimeNow.ToString("yyyyMM") + "'";
                                DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                            }
                            else
                            {
                                lCode = 1;
                                sSQL  = "insert into VoucherHistory(CardNumber,cContent,cContentRule,cSeed,cNumber,bEmpty)" +
                                        "values('0302','日期','月','" + dTimeNow.ToString("yyyyMM") + "','1',0)";
                                DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                            }
                            sCode = lCode.ToString();
                            while (sCode.Length < 5)
                            {
                                sCode = "0" + sCode;
                            }

                            sCode = "QC" + dTimeNow.ToString("yyMM") + sCode;

                            lID        = 0;
                            lIDDetails = 0;


                            sSQL = @"
declare @p5 int
set @p5=111111
declare @p6 int
set @p6=222222
exec sp_GetId N'',N'444444',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());
                            sSQL = sSQL.Replace("444444", sAccID);
                            dt   = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];

                            lID        = ClsBaseDataInfo.ReturnObjectToLong(dt.Rows[0][0]) - 1;
                            lIDDetails = ClsBaseDataInfo.ReturnObjectToLong(dt.Rows[0][1]) - iCouRow;

                            lID += 1;
                            Model.RdRecord09 modelr9 = new TH.WebService.Model.RdRecord09();
                            modelr9.ID               = lID;
                            modelr9.bRdFlag          = 0;
                            modelr9.cVouchType       = "09";
                            modelr9.cBusType         = "调拨出库";
                            modelr9.cSource          = "调拨";
                            modelr9.cBusCode         = sTrCode;
                            modelr9.cWhCode          = dtTran.Rows[0]["cOWhCode"].ToString().Trim();
                            modelr9.dDate            = BaseFunction.ReturnDate(dTimeNow.ToString("yyyy-MM-dd"));
                            modelr9.cCode            = sCode;
                            modelr9.cRdCode          = dtTran.Rows[0]["cORdCode"].ToString().Trim();
                            modelr9.cDepCode         = dtTran.Rows[0]["cODepCode"].ToString().Trim();
                            modelr9.bTransFlag       = false;
                            modelr9.cMaker           = sUid;
                            modelr9.bpufirst         = false;
                            modelr9.biafirst         = false;
                            modelr9.VT_ID            = 67;
                            modelr9.bIsSTQc          = false;
                            modelr9.bOMFirst         = false;
                            modelr9.bFromPreYear     = false;
                            modelr9.bIsComplement    = 0;
                            modelr9.iDiscountTaxType = 0;
                            modelr9.ireturncount     = 0;
                            modelr9.iverifystate     = 0;
                            modelr9.iswfcontrolled   = 0;
                            modelr9.dnmaketime       = dTimeNow;
                            modelr9.bredvouch        = 0;
                            modelr9.iPrintCount      = 0;

                            DAL.RdRecord09 DALr9 = new RdRecord09();
                            sSQL = DALr9.Add(modelr9);
                            DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);

                            for (int i = 0; i < dtTran.Rows.Count; i++)
                            {
                                Model.rdrecords09 modelr9s = new TH.WebService.Model.rdrecords09();

                                lIDDetails         += 1;
                                modelr9s.AutoID     = lIDDetails;
                                modelr9s.ID         = lID;
                                modelr9s.cInvCode   = dtTran.Rows[i]["cInvCode"].ToString().Trim();
                                modelr9s.iQuantity  = BaseFunction.ReturnDecimal(dtTran.Rows[i]["iTVQuantity"]);
                                modelr9s.iNum       = BaseFunction.ReturnDecimal(dtTran.Rows[i]["iTVNum"]);
                                modelr9s.iTrIds     = BaseFunction.ReturnLong(dtTran.Rows[i]["autoID"]);
                                modelr9s.iNQuantity = BaseFunction.ReturnDecimal(dtTran.Rows[i]["iTVQuantity"]);
                                modelr9s.irowno     = BaseFunction.ReturnInt(dtTran.Rows[i]["irowno"]);

                                DAL.RdRecords09 DALr9s = new RdRecords09();
                                sSQL = DALr9s.Add(modelr9s);
                                DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);

                                sSQL = "insert into IA_ST_UnAccountVouch09(idun,idsun,cvoutypeun,cbustypeun)values " +
                                       "('" + lID + "','" + lIDDetails + "','09','调拨出库')";
                                DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                            }
                            #endregion
                        }


                        //sSQL = "exec SP_ClearCurrentStock_ST";
                        //DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                    }


                    #endregion



                    tran.Commit();
                }
                catch (Exception error)
                {
                    tran.Rollback();
                    throw new Exception(error.Message);
                }
            }
            catch (Exception ee)
            {
                throw new Exception(ee.Message);
            }
            return(iCou);
        }