コード例 #1
0
ファイル: TransVouchs.cs プロジェクト: chrgu000/DEMO
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public string Add(UFIDA.U8.UAP.CustomApp.ControlForm.Model.TransVouchs model)
        {
            StringBuilder strSql  = new StringBuilder();
            StringBuilder strSql1 = new StringBuilder();
            StringBuilder strSql2 = new StringBuilder();

            if (model.cTVCode != null)
            {
                strSql1.Append("cTVCode,");
                strSql2.Append("'" + model.cTVCode + "',");
            }
            if (model.cInvCode != null)
            {
                strSql1.Append("cInvCode,");
                strSql2.Append("'" + model.cInvCode + "',");
            }
            if (model.RdsID != null)
            {
                strSql1.Append("RdsID,");
                strSql2.Append("" + model.RdsID + ",");
            }
            if (model.iTVNum != null)
            {
                strSql1.Append("iTVNum,");
                strSql2.Append("" + model.iTVNum + ",");
            }
            if (model.iTVQuantity != null)
            {
                strSql1.Append("iTVQuantity,");
                strSql2.Append("" + model.iTVQuantity + ",");
            }
            if (model.iTVACost != null)
            {
                strSql1.Append("iTVACost,");
                strSql2.Append("" + model.iTVACost + ",");
            }
            if (model.iTVAPrice != null)
            {
                strSql1.Append("iTVAPrice,");
                strSql2.Append("" + model.iTVAPrice + ",");
            }
            if (model.iTVPCost != null)
            {
                strSql1.Append("iTVPCost,");
                strSql2.Append("" + model.iTVPCost + ",");
            }
            if (model.iTVPPrice != null)
            {
                strSql1.Append("iTVPPrice,");
                strSql2.Append("" + model.iTVPPrice + ",");
            }
            if (model.cTVBatch != null)
            {
                strSql1.Append("cTVBatch,");
                strSql2.Append("'" + model.cTVBatch + "',");
            }
            if (model.dDisDate != null)
            {
                strSql1.Append("dDisDate,");
                strSql2.Append("'" + model.dDisDate + "',");
            }
            if (model.cFree1 != null)
            {
                strSql1.Append("cFree1,");
                strSql2.Append("'" + model.cFree1 + "',");
            }
            if (model.cFree2 != null)
            {
                strSql1.Append("cFree2,");
                strSql2.Append("'" + model.cFree2 + "',");
            }
            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.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.cName != null)
            {
                strSql1.Append("cName,");
                strSql2.Append("'" + model.cName + "',");
            }
            if (model.cItemCName != null)
            {
                strSql1.Append("cItemCName,");
                strSql2.Append("'" + model.cItemCName + "',");
            }
            if (model.autoID != null)
            {
                strSql1.Append("autoID,");
                strSql2.Append("" + model.autoID + ",");
            }
            if (model.ID != null)
            {
                strSql1.Append("ID,");
                strSql2.Append("" + model.ID + ",");
            }
            if (model.iMassDate != null)
            {
                strSql1.Append("iMassDate,");
                strSql2.Append("" + model.iMassDate + ",");
            }
            if (model.cBarCode != null)
            {
                strSql1.Append("cBarCode,");
                strSql2.Append("'" + model.cBarCode + "',");
            }
            if (model.cAssUnit != null)
            {
                strSql1.Append("cAssUnit,");
                strSql2.Append("'" + model.cAssUnit + "',");
            }
            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.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.iMPoIds != null)
            {
                strSql1.Append("iMPoIds,");
                strSql2.Append("" + model.iMPoIds + ",");
            }
            if (model.cBVencode != null)
            {
                strSql1.Append("cBVencode,");
                strSql2.Append("'" + model.cBVencode + "',");
            }
            if (model.cInVouchCode != null)
            {
                strSql1.Append("cInVouchCode,");
                strSql2.Append("'" + model.cInVouchCode + "',");
            }
            if (model.dMadeDate != null)
            {
                strSql1.Append("dMadeDate,");
                strSql2.Append("'" + model.dMadeDate + "',");
            }
            if (model.cMassUnit != null)
            {
                strSql1.Append("cMassUnit,");
                strSql2.Append("" + model.cMassUnit + ",");
            }
            if (model.iTRIds != null)
            {
                strSql1.Append("iTRIds,");
                strSql2.Append("" + model.iTRIds + ",");
            }
            if (model.AppTransIDS != null)
            {
                strSql1.Append("AppTransIDS,");
                strSql2.Append("" + model.AppTransIDS + ",");
            }
            if (model.iSSoType != null)
            {
                strSql1.Append("iSSoType,");
                strSql2.Append("" + model.iSSoType + ",");
            }
            if (model.iSSodid != null)
            {
                strSql1.Append("iSSodid,");
                strSql2.Append("'" + model.iSSodid + "',");
            }
            if (model.iDSoType != null)
            {
                strSql1.Append("iDSoType,");
                strSql2.Append("" + model.iDSoType + ",");
            }
            if (model.iDSodid != null)
            {
                strSql1.Append("iDSodid,");
                strSql2.Append("'" + model.iDSodid + "',");
            }
            if (model.bCosting != null)
            {
                strSql1.Append("bCosting,");
                strSql2.Append("" + (model.bCosting ? 1 : 0) + ",");
            }
            if (model.cvmivencode != null)
            {
                strSql1.Append("cvmivencode,");
                strSql2.Append("'" + model.cvmivencode + "',");
            }
            if (model.cinposcode != null)
            {
                strSql1.Append("cinposcode,");
                strSql2.Append("'" + model.cinposcode + "',");
            }
            if (model.coutposcode != null)
            {
                strSql1.Append("coutposcode,");
                strSql2.Append("'" + model.coutposcode + "',");
            }
            if (model.iinvsncount != null)
            {
                strSql1.Append("iinvsncount,");
                strSql2.Append("" + model.iinvsncount + ",");
            }
            if (model.iinvexchrate != null)
            {
                strSql1.Append("iinvexchrate,");
                strSql2.Append("" + model.iinvexchrate + ",");
            }
            if (model.comcode != null)
            {
                strSql1.Append("comcode,");
                strSql2.Append("'" + model.comcode + "',");
            }
            if (model.cmocode != null)
            {
                strSql1.Append("cmocode,");
                strSql2.Append("'" + model.cmocode + "',");
            }
            if (model.invcode != null)
            {
                strSql1.Append("invcode,");
                strSql2.Append("'" + model.invcode + "',");
            }
            if (model.imoseq != null)
            {
                strSql1.Append("imoseq,");
                strSql2.Append("" + model.imoseq + ",");
            }
            if (model.iomids != null)
            {
                strSql1.Append("iomids,");
                strSql2.Append("" + model.iomids + ",");
            }
            if (model.imoids != null)
            {
                strSql1.Append("imoids,");
                strSql2.Append("" + model.imoids + ",");
            }
            if (model.corufts != null)
            {
                strSql1.Append("corufts,");
                strSql2.Append("'" + model.corufts + "',");
            }
            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.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.cciqbookcode != null)
            {
                strSql1.Append("cciqbookcode,");
                strSql2.Append("'" + model.cciqbookcode + "',");
            }
            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.cinvouchtype != null)
            {
                strSql1.Append("cinvouchtype,");
                strSql2.Append("'" + model.cinvouchtype + "',");
            }
            if (model.cbsourcecodels != null)
            {
                strSql1.Append("cbsourcecodels,");
                strSql2.Append("'" + model.cbsourcecodels + "',");
            }
            if (model.cMoLotCode != null)
            {
                strSql1.Append("cMoLotCode,");
                strSql2.Append("'" + model.cMoLotCode + "',");
            }
            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 + "',");
            }
            strSql.Append("insert into TransVouchs(");
            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());
        }
コード例 #2
0
        private void btnImprot_Click(object sender, EventArgs e)
        {
            try
            {
                gridViewPL.FocusedRowHandle -= 1;
                gridViewPL.FocusedRowHandle += 1;
            }
            catch { }

            try
            {
                if (txtEntryNo.Text.Trim() == "")
                {
                    txtEntryNo.Focus();
                    throw new Exception("Please set entry no");
                }

                int iCou = gridViewPL.RowCount;
                if (iCou == 0)
                {
                    throw new Exception("no data");
                }

                string sMCode = "";

                int           iCodeCou = gridViewPL.RowCount;
                string        sErr     = "";
                int           iCount   = 0;
                SqlConnection conn     = new SqlConnection(Conn);
                conn.Open();
                //启用事务
                SqlTransaction tran = conn.BeginTransaction();

                try
                {
                    if (lookUpEditWarehouseIN == null || lookUpEditWarehouseIN.Text.Trim() == "")
                    {
                        lookUpEditWarehouseIN.Focus();
                        throw new Exception("Please choose transfer-in warehouse");
                    }
                    if (lookUpEditWarehouseOUT == null || lookUpEditWarehouseOUT.Text.Trim() == "")
                    {
                        lookUpEditWarehouseOUT.Focus();
                        throw new Exception("Please choose transfer-out warehouse");
                    }

                    string sWhCodeIn  = lookUpEditWarehouseIN.EditValue.ToString().Trim();
                    string sWhCodeOut = lookUpEditWarehouseOUT.EditValue.ToString().Trim();

                    if (sWhCodeIn == sWhCodeOut)
                    {
                        throw new Exception("The warehouse can't be the same");
                    }
                    string sRdCodeIn   = "";
                    string sRdCodeOut  = "";
                    string sDepCodeIn  = "";
                    string sDepCodeOut = "";

                    string    sSQL   = @"
select * from _Code where VouchType = 'TransVouch'
";
                    DataTable dtCode = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                    if (dtCode != null && dtCode.Rows.Count > 0)
                    {
                        sRdCodeIn   = dtCode.Rows[0]["cRdCodeIn"].ToString().Trim();
                        sRdCodeOut  = dtCode.Rows[0]["cRdCodeOut"].ToString().Trim();
                        sDepCodeIn  = dtCode.Rows[0]["cDepCodeIn"].ToString().Trim();
                        sDepCodeOut = dtCode.Rows[0]["cDepCodeOut"].ToString().Trim();
                    }
                    else
                    {
                        throw new Exception("Please set _code [TransVouch]");
                    }

                    if (sWhCodeIn == "" || sWhCodeOut == "" || sRdCodeIn == "" || sRdCodeOut == "")
                    {
                        throw new Exception("Please set _code [TransVouchClaim]");
                    }

                    DateTime dLogDate = BaseFunction.ReturnDate(sLogDate);

                    //string sDate = dateEdit1.DateTime.ToString("yyyy-MM-dd");
                    string sDate = sLogDate;
                    sSQL = @"
select bflag_ST from gl_mend where iyear = aaaaaa and iperiod = bbbbbb
";
                    sSQL = sSQL.Replace("aaaaaa", dLogDate.Year.ToString());
                    sSQL = sSQL.Replace("bbbbbb", dLogDate.Month.ToString());
                    DataTable dtTemp = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                    if (BaseFunction.ReturnBool(dtTemp.Rows[0]["bflag_ST"]))
                    {
                        throw new Exception("The current date has been checked out");
                    }

                    string sDateTime = dateEditQuery.DateTime.ToString("yyyy-MM-dd");

                    bool bNeedTR = false;   //是否需要索赔调拨
                    #region 生成调拨单

                    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'tr',cccccc,@p5 output,@p6 output,default
select @p5, @p6
";
                    sSQL = sSQL.Replace("aaaaaa", lID.ToString());
                    sSQL = sSQL.Replace("bbbbbb", lIDDetails.ToString());
                    sSQL = sSQL.Replace("cccccc", iCou.ToString());
                    sSQL = sSQL.Replace("dddddd", sAccID);
                    DataTable dt = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];

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

                    ////获得单据号
                    sSQL = "select * from VoucherHistory with (ROWLOCK) Where CardNumber='0304' AND cSeed = 'aaaaaa'";
                    sSQL = sSQL.Replace("aaaaaa", dLogDate.ToString("yyyyMMdd"));
                    dt   = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];

                    long iCode = 0;
                    if (dt != null && dt.Rows.Count > 0)
                    {
                        iCode = BaseFunction.ReturnLong(dt.Rows[0]["cNumber"]) + 1;
                        sSQL  = @"
update VoucherHistory set cNumber = aaaaaa where autoid = bbbbbb and CardNumber = '0304'
";
                        sSQL  = sSQL.Replace("aaaaaa", iCode.ToString());
                        sSQL  = sSQL.Replace("bbbbbb", dt.Rows[0]["AutoId"].ToString().Trim());
                        DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                    }
                    else
                    {
                        iCode = 1;
                        sSQL  = @"
insert into VoucherHistory(CardNumber, cContent, cContentRule, cSeed, cNumber, bEmpty)
values('0304','日期','日','aaaaaa',1,0)
";
                        sSQL  = sSQL.Replace("aaaaaa", dLogDate.ToString("yyyyMMdd"));
                        DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                    }
                    iCode += 1;
                    string sCode = iCode.ToString();
                    while (sCode.Length < 4)
                    {
                        sCode = "0" + sCode;
                    }
                    sCode = "TF" + dLogDate.ToString("yyyyMMdd") + sCode;

                    sSQL = @"
select distinct * from Rdrecord01 
where id in (select id from Rdrecords01 where autoid = {0})
";
                    sSQL = string.Format(sSQL, gridViewPL.GetRowCellValue(0, gridColRds01ID));
                    DataTable dtRd = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];

                    Model.TransVouch mod = new UFIDA.U8.UAP.CustomApp.ControlForm.Model.TransVouch();
                    mod.cTVCode = sCode;
                    mod.dTVDate = dLogDate;

                    mod.cOWhCode = sWhCodeOut;
                    mod.cIWhCode = sWhCodeIn;
                    mod.cIRdCode = sRdCodeIn;
                    mod.cORdCode = sRdCodeOut;

                    if (sDepCodeIn != "")
                    {
                        mod.cIDepCode = sDepCodeIn;
                    }
                    if (sDepCodeOut != "")
                    {
                        mod.cODepCode = sDepCodeOut;
                    }
                    mod.cPersonCode = null;
                    mod.cTVMemo     = txtMemo.Text.Trim();

                    if (dtRd.Rows[0]["cDefine1"].ToString().Trim() != "")
                    {
                        mod.cDefine1 = dtRd.Rows[0]["cDefine1"].ToString().Trim();
                    }
                    if (dtRd.Rows[0]["cDefine2"].ToString().Trim() != "")
                    {
                        mod.cDefine2 = dtRd.Rows[0]["cDefine2"].ToString().Trim();
                    }
                    if (dtRd.Rows[0]["cDefine3"].ToString().Trim() != "")
                    {
                        mod.cDefine3 = dtRd.Rows[0]["cDefine3"].ToString().Trim();
                    }
                    if (dtRd.Rows[0]["cDefine4"].ToString().Trim() != "")
                    {
                        mod.cDefine4 = BaseFunction.ReturnDate(dtRd.Rows[0]["cDefine4"]);
                    }
                    if (dtRd.Rows[0]["cDefine5"].ToString().Trim() != "")
                    {
                        mod.cDefine5 = BaseFunction.ReturnLong(dtRd.Rows[0]["cDefine5"]);
                    }
                    if (dtRd.Rows[0]["cDefine6"].ToString().Trim() != "")
                    {
                        mod.cDefine6 = BaseFunction.ReturnDate(dtRd.Rows[0]["cDefine6"]);
                    }
                    if (dtRd.Rows[0]["cDefine7"].ToString().Trim() != "")
                    {
                        mod.cDefine7 = BaseFunction.ReturnDecimal(dtRd.Rows[0]["cDefine7"]);
                    }
                    if (dtRd.Rows[0]["cDefine8"].ToString().Trim() != "")
                    {
                        mod.cDefine8 = dtRd.Rows[0]["cDefine8"].ToString().Trim();
                    }
                    if (dtRd.Rows[0]["cDefine9"].ToString().Trim() != "")
                    {
                        mod.cDefine9 = dtRd.Rows[0]["cDefine9"].ToString().Trim();
                    }
                    if (dtRd.Rows[0]["cDefine10"].ToString().Trim() != "")
                    {
                        mod.cDefine10 = dtRd.Rows[0]["cDefine10"].ToString().Trim();
                    }
                    mod.cAccounter = null;
                    mod.iNetLock   = 1;
                    lID           += 1;
                    mod.ID         = lID;
                    mod.VT_ID      = 89;
                    mod.cMaker     = sUserName;
                    mod.dnmaketime = dLogDate;

                    mod.cVerifyPerson = sUserName;
                    mod.dVerifyDate   = dLogDate;
                    mod.cPSPCode      = null;
                    mod.cMPoCode      = null;
                    mod.iQuantity     = 0;
                    mod.bTransFlag    = null;
                    //if (dtRd.Rows[0]["cDefine11"].ToString().Trim() != "")
                    //{
                    //    mod.cDefine11 = dtRd.Rows[0]["cDefine11"].ToString().Trim();
                    //}
                    mod.cDefine11 = txtEntryNo.Text.Trim();
                    if (dtRd.Rows[0]["cDefine12"].ToString().Trim() != "")
                    {
                        mod.cDefine12 = dtRd.Rows[0]["cDefine12"].ToString().Trim();
                    }
                    if (dtRd.Rows[0]["cDefine13"].ToString().Trim() != "")
                    {
                        mod.cDefine13 = dtRd.Rows[0]["cDefine13"].ToString().Trim();
                    }
                    if (dtRd.Rows[0]["cDefine14"].ToString().Trim() != "")
                    {
                        mod.cDefine14 = dtRd.Rows[0]["cDefine14"].ToString().Trim();
                    }
                    if (dtRd.Rows[0]["cDefine15"].ToString().Trim() != "")
                    {
                        mod.cDefine15 = BaseFunction.ReturnLong(dtRd.Rows[0]["cDefine5"]);
                    }
                    if (dtRd.Rows[0]["cDefine16"].ToString().Trim() != "")
                    {
                        mod.cDefine16 = BaseFunction.ReturnDecimal(dtRd.Rows[0]["cDefine16"]);
                    }

                    mod.iproorderid      = null;
                    mod.cTranRequestCode = null;
                    mod.cVersion         = null;
                    mod.BomId            = null;
                    mod.cFree1           = null;
                    mod.cFree2           = null;
                    mod.cFree3           = null;
                    mod.cFree4           = null;
                    mod.cFree5           = null;
                    mod.cFree6           = null;
                    mod.cFree7           = null;
                    mod.cFree8           = null;
                    mod.cFree9           = null;
                    mod.cFree10          = null;
                    mod.cAppTVCode       = null;
                    mod.csource          = "1";
                    mod.itransflag       = "正向";
                    mod.cModifyPerson    = null;
                    mod.dModifyDate      = null;
                    mod.dnmaketime       = DateTime.Now;
                    mod.dnmodifytime     = null;
                    mod.ireturncount     = null;
                    mod.iverifystate     = null;
                    mod.iswfcontrolled   = 0;
                    mod.csourceguid      = null;
                    mod.csysbarcode      = "||st12||" + mod.cTVCode;

                    mod.cDefine1        = txtEntryNo.Text.Trim();
                    mod.cCurrentAuditor = null;

                    DAL.TransVouch dalTR = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL.TransVouch();
                    sSQL    = dalTR.Add(mod);
                    iCount += DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);

                    sMCode = sMCode + mod.cTVCode + "\n";

                    int iRow = 0;
                    for (int i = 0; i < gridViewPL.RowCount; i++)
                    {
                        if (!BaseFunction.ReturnBool(gridViewPL.GetRowCellValue(i, gridColSelected)))
                        {
                            continue;
                        }

                        long lRds01Autoid = BaseFunction.ReturnLong(gridViewPL.GetRowCellValue(i, gridColRds01ID));
                        if (lRds01Autoid == 0)
                        {
                            sErr = sErr + "Line " + (i + 1).ToString() + " purchase receipt warrant is not imported\n";
                            continue;
                        }

                        sSQL = @"
select autoid from Rdrecords01 where autoid = aaaaaaaa
";
                        sSQL = sSQL.Replace("aaaaaaaa", lRds01Autoid.ToString());
                        DataTable dtRds01 = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];

                        if (dtRds01 == null || dtRds01.Rows.Count == 0)
                        {
                            sErr = sErr + "Line " + (i + 1).ToString() + " purchase receipt warrant is not imported\n";
                            continue;
                        }


                        long lTRsID = BaseFunction.ReturnLong(gridViewPL.GetRowCellValue(i, gridColTrIDs));
                        if (lTRsID > 0)
                        {
                            sSQL = @"
select autoid from TransVouchs where autoid = aaaaaaaa
";
                            sSQL = sSQL.Replace("aaaaaaaa", lTRsID.ToString());
                            DataTable dtTRs01 = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];

                            if (dtTRs01 != null && dtTRs01.Rows.Count > 0)
                            {
                                sErr = sErr + "Line " + (i + 1).ToString() + " is imported\n";
                                continue;
                            }
                        }

                        Model.TransVouchs mods = new UFIDA.U8.UAP.CustomApp.ControlForm.Model.TransVouchs();
                        mods.cTVCode     = mod.cTVCode;
                        mods.cInvCode    = gridViewPL.GetRowCellValue(i, gridColPARTNO).ToString().Trim();
                        mods.iTVNum      = null;
                        mods.iTVQuantity = BaseFunction.ReturnDecimal(gridViewPL.GetRowCellValue(i, gridColQUANTITY));
                        lIDDetails      += 1;
                        mods.autoID      = lIDDetails;
                        mods.ID          = mod.ID;
                        mods.bCosting    = true;

                        iRow            += 1;
                        mods.irowno      = iRow;
                        mods.coutposcode = null;
                        mods.cinposcode  = null;
                        //mods.cTVBatch = gridViewPL.GetRowCellValue(i, gridColcBatch).ToString().Trim();
                        mods.cDefine22 = gridViewPL.GetRowCellValue(i, gridColCONTAINERNO).ToString().Trim();
                        mods.cDefine23 = gridViewPL.GetRowCellValue(i, gridColBOXNO).ToString().Trim();
                        mods.cDefine24 = gridViewPL.GetRowCellValue(i, gridColCASENO).ToString().Trim();
                        mods.cDefine25 = gridViewPL.GetRowCellValue(i, gridColGWKGS).ToString().Trim();
                        mods.cDefine28 = gridViewPL.GetRowCellValue(i, gridColNWKGS).ToString().Trim();

                        mods.cbsysbarcode = "||st12|" + mod.cTVCode + "|" + iRow.ToString();
                        DAL.TransVouchs dalTRs = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL.TransVouchs();
                        sSQL    = dalTRs.Add(mods);
                        iCount += DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);

                        //回写导入中间表 Rdrecords10_Import
                        sSQL = @"
update RdRecords01_Import set TrIDs = AAAAAA,EntryNO = 'CCCCCC'
WHERE AUTOID = BBBBBB
";
                        sSQL = sSQL.Replace("AAAAAA", mods.autoID.ToString());
                        sSQL = sSQL.Replace("BBBBBB", gridViewPL.GetRowCellValue(i, gridColAutoID).ToString());
                        sSQL = sSQL.Replace("CCCCCC", txtEntryNo.Text.Trim());
                        int iRet = DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                        if (iRet != 1)
                        {
                            sErr = sErr + "Line " + (i + 1) + " update dl err\n";
                        }

                        decimal dClaimQty = BaseFunction.ReturnDecimal(gridViewPL.GetRowCellValue(i, gridColClaimQty));

                        if (dClaimQty > 0)
                        {
                            bNeedTR = true;
                        }
                    }

                    if (iRow > 0)
                    {
                        clsU8 cls = new clsU8();
                        cls.TransVouch_Audit_U8V111(tran, mod.cTVCode, sAccID, sUserName);
                    }

                    #endregion


                    #region 生成索赔调拨单
                    if (bNeedTR)
                    {
                        sRdCodeIn   = "";
                        sRdCodeOut  = "";
                        sDepCodeIn  = "";
                        sDepCodeOut = "";

                        sSQL   = @"
select * from _Code where VouchType = 'TransVouchClaim'
";
                        dtCode = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                        if (dtCode != null && dtCode.Rows.Count > 0)
                        {
                            sRdCodeIn   = dtCode.Rows[0]["cRdCodeIn"].ToString().Trim();
                            sRdCodeOut  = dtCode.Rows[0]["cRdCodeOut"].ToString().Trim();
                            sDepCodeIn  = dtCode.Rows[0]["cDepCodeIn"].ToString().Trim();
                            sDepCodeOut = dtCode.Rows[0]["cDepCodeOut"].ToString().Trim();
                        }
                        else
                        {
                            throw new Exception("Please set _code [TransVouchClaim]");
                        }

                        if (sRdCodeIn == "" || sRdCodeOut == "")
                        {
                            throw new Exception("Please set _code [TransVouchClaim]");
                        }

                        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'tr',cccccc,@p5 output,@p6 output,default
select @p5, @p6
";
                        sSQL       = sSQL.Replace("aaaaaa", lID.ToString());
                        sSQL       = sSQL.Replace("bbbbbb", lIDDetails.ToString());
                        sSQL       = sSQL.Replace("cccccc", iCou.ToString());
                        sSQL       = sSQL.Replace("dddddd", sAccID);
                        dt         = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];

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

                        ////获得单据号
                        sSQL = "select * from VoucherHistory with (ROWLOCK) Where CardNumber='0304' AND cSeed = 'aaaaaa'";
                        sSQL = sSQL.Replace("aaaaaa", dLogDate.ToString("yyyyMMdd"));
                        dt   = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];

                        iCode = 0;
                        if (dt != null && dt.Rows.Count > 0)
                        {
                            iCode = BaseFunction.ReturnLong(dt.Rows[0]["cNumber"]) + 1;
                            sSQL  = @"
update VoucherHistory set cNumber = aaaaaa where autoid = bbbbbb and CardNumber = '0304'
";
                            sSQL  = sSQL.Replace("aaaaaa", iCode.ToString());
                            sSQL  = sSQL.Replace("bbbbbb", dt.Rows[0]["AutoId"].ToString().Trim());
                            DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                        }
                        else
                        {
                            iCode = 1;
                            sSQL  = @"
insert into VoucherHistory(CardNumber, cContent, cContentRule, cSeed, cNumber, bEmpty)
values('0304','日期','日','aaaaaa',1,0)
";
                            sSQL  = sSQL.Replace("aaaaaa", dLogDate.ToString("yyyyMMdd"));
                            DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                        }
                        iCode += 1;
                        sCode  = iCode.ToString();
                        while (sCode.Length < 4)
                        {
                            sCode = "0" + sCode;
                        }
                        sCode = "TF" + dLogDate.ToString("yyyyMMdd") + sCode;

                        mod         = new UFIDA.U8.UAP.CustomApp.ControlForm.Model.TransVouch();
                        mod.cTVCode = sCode;
                        mod.dTVDate = dLogDate;

                        mod.cOWhCode = lookUpEditWarehouseIN.EditValue.ToString().Trim();
                        if (mod.cOWhCode.ToUpper().StartsWith("A"))
                        {
                            mod.cIWhCode = "A61";
                        }
                        if (mod.cOWhCode.ToUpper().StartsWith("B"))
                        {
                            mod.cIWhCode = "B61";
                        }

                        if (mod.cIWhCode == null || mod.cIWhCode.Trim() == "")
                        {
                            throw new Exception("Please set claim warehouse");
                        }

                        mod.cIRdCode = sRdCodeOut;
                        mod.cORdCode = sRdCodeIn;

                        mod.cIDepCode = sDepCodeIn;
                        mod.cODepCode = sDepCodeOut;

                        mod.cPersonCode = null;
                        mod.cTVMemo     = txtMemo.Text.Trim();

                        if (dtRd.Rows[0]["cDefine1"].ToString().Trim() != "")
                        {
                            mod.cDefine1 = dtRd.Rows[0]["cDefine1"].ToString().Trim();
                        }
                        if (dtRd.Rows[0]["cDefine2"].ToString().Trim() != "")
                        {
                            mod.cDefine2 = dtRd.Rows[0]["cDefine2"].ToString().Trim();
                        }
                        if (dtRd.Rows[0]["cDefine3"].ToString().Trim() != "")
                        {
                            mod.cDefine3 = dtRd.Rows[0]["cDefine3"].ToString().Trim();
                        }
                        if (dtRd.Rows[0]["cDefine4"].ToString().Trim() != "")
                        {
                            mod.cDefine4 = BaseFunction.ReturnDate(dtRd.Rows[0]["cDefine4"]);
                        }
                        if (dtRd.Rows[0]["cDefine5"].ToString().Trim() != "")
                        {
                            mod.cDefine5 = BaseFunction.ReturnLong(dtRd.Rows[0]["cDefine5"]);
                        }
                        if (dtRd.Rows[0]["cDefine6"].ToString().Trim() != "")
                        {
                            mod.cDefine6 = BaseFunction.ReturnDate(dtRd.Rows[0]["cDefine6"]);
                        }
                        if (dtRd.Rows[0]["cDefine7"].ToString().Trim() != "")
                        {
                            mod.cDefine7 = BaseFunction.ReturnDecimal(dtRd.Rows[0]["cDefine7"]);
                        }
                        if (dtRd.Rows[0]["cDefine8"].ToString().Trim() != "")
                        {
                            mod.cDefine8 = dtRd.Rows[0]["cDefine8"].ToString().Trim();
                        }
                        if (dtRd.Rows[0]["cDefine9"].ToString().Trim() != "")
                        {
                            mod.cDefine9 = dtRd.Rows[0]["cDefine9"].ToString().Trim();
                        }
                        if (dtRd.Rows[0]["cDefine10"].ToString().Trim() != "")
                        {
                            mod.cDefine10 = dtRd.Rows[0]["cDefine10"].ToString().Trim();
                        }
                        mod.cAccounter = null;
                        mod.iNetLock   = 1;
                        lID           += 1;
                        mod.ID         = lID;
                        mod.VT_ID      = 89;
                        mod.cMaker     = sUserName;
                        mod.dnmaketime = dLogDate;

                        mod.cVerifyPerson = sUserName;
                        mod.dVerifyDate   = dLogDate;
                        mod.cPSPCode      = null;
                        mod.cMPoCode      = null;
                        mod.iQuantity     = 0;
                        mod.bTransFlag    = null;
                        if (dtRd.Rows[0]["cDefine11"].ToString().Trim() != "")
                        {
                            mod.cDefine11 = dtRd.Rows[0]["cDefine11"].ToString().Trim();
                        }
                        if (dtRd.Rows[0]["cDefine12"].ToString().Trim() != "")
                        {
                            mod.cDefine12 = dtRd.Rows[0]["cDefine12"].ToString().Trim();
                        }
                        if (dtRd.Rows[0]["cDefine13"].ToString().Trim() != "")
                        {
                            mod.cDefine13 = dtRd.Rows[0]["cDefine13"].ToString().Trim();
                        }
                        if (dtRd.Rows[0]["cDefine14"].ToString().Trim() != "")
                        {
                            mod.cDefine14 = dtRd.Rows[0]["cDefine14"].ToString().Trim();
                        }
                        if (dtRd.Rows[0]["cDefine15"].ToString().Trim() != "")
                        {
                            mod.cDefine15 = BaseFunction.ReturnLong(dtRd.Rows[0]["cDefine5"]);
                        }
                        if (dtRd.Rows[0]["cDefine16"].ToString().Trim() != "")
                        {
                            mod.cDefine16 = BaseFunction.ReturnDecimal(dtRd.Rows[0]["cDefine16"]);
                        }
                        mod.iproorderid      = null;
                        mod.cTranRequestCode = null;
                        mod.cVersion         = null;
                        mod.BomId            = null;
                        mod.cFree1           = null;
                        mod.cFree2           = null;
                        mod.cFree3           = null;
                        mod.cFree4           = null;
                        mod.cFree5           = null;
                        mod.cFree6           = null;
                        mod.cFree7           = null;
                        mod.cFree8           = null;
                        mod.cFree9           = null;
                        mod.cFree10          = null;
                        mod.cAppTVCode       = null;
                        mod.csource          = "1";
                        mod.itransflag       = "正向";
                        mod.cModifyPerson    = null;
                        mod.dModifyDate      = null;
                        mod.dnmaketime       = DateTime.Now;
                        mod.dnmodifytime     = null;
                        mod.ireturncount     = null;
                        mod.iverifystate     = null;
                        mod.iswfcontrolled   = 0;
                        mod.csourceguid      = null;
                        mod.csysbarcode      = "||st12||" + mod.cTVCode;

                        mod.cDefine1        = txtEntryNo.Text.Trim();
                        mod.cCurrentAuditor = null;

                        dalTR   = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL.TransVouch();
                        sSQL    = dalTR.Add(mod);
                        iCount += DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);

                        sMCode = sMCode + mod.cTVCode + "\n";

                        iRow = 0;
                        for (int i = 0; i < gridViewPL.RowCount; i++)
                        {
                            if (!BaseFunction.ReturnBool(gridViewPL.GetRowCellValue(i, gridColSelected)))
                            {
                                continue;
                            }



                            decimal dQty      = BaseFunction.ReturnDecimal(gridViewPL.GetRowCellValue(i, gridColQUANTITY));
                            decimal dClaimQty = BaseFunction.ReturnDecimal(gridViewPL.GetRowCellValue(i, gridColClaimQty));
                            if (dClaimQty < 0 || dClaimQty > dQty)
                            {
                                sErr = sErr + "Line " + (i + 1).ToString() + " the claim quantity is wrong\n";
                                continue;
                            }
                            if (dClaimQty == 0)
                            {
                                continue;
                            }

                            long lRds01Autoid = BaseFunction.ReturnLong(gridViewPL.GetRowCellValue(i, gridColRds01ID));
                            if (lRds01Autoid == 0)
                            {
                                sErr = sErr + "Line " + (i + 1).ToString() + " purchase receipt warrant is not imported\n";
                                continue;
                            }

                            sSQL = @"
select autoid from Rdrecords01 where autoid = aaaaaaaa
";
                            sSQL = sSQL.Replace("aaaaaaaa", lRds01Autoid.ToString());
                            DataTable dtRds01 = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];

                            if (dtRds01 == null || dtRds01.Rows.Count == 0)
                            {
                                sErr = sErr + "Line " + (i + 1).ToString() + " purchase receipt warrant is not imported\n";
                                continue;
                            }


                            long lTRsID = BaseFunction.ReturnLong(gridViewPL.GetRowCellValue(i, gridColTrIDs));
                            if (lTRsID > 0)
                            {
                                sSQL = @"
select autoid from TransVouchs where autoid = aaaaaaaa
";
                                sSQL = sSQL.Replace("aaaaaaaa", lTRsID.ToString());
                                DataTable dtTRs01 = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];

                                if (dtTRs01 != null && dtTRs01.Rows.Count > 0)
                                {
                                    sErr = sErr + "Line " + (i + 1).ToString() + " is imported\n";
                                    continue;
                                }
                            }

                            Model.TransVouchs mods = new UFIDA.U8.UAP.CustomApp.ControlForm.Model.TransVouchs();
                            mods.cTVCode  = mod.cTVCode;
                            mods.cInvCode = gridViewPL.GetRowCellValue(i, gridColPARTNO).ToString().Trim();
                            mods.iTVNum   = null;

                            mods.iTVQuantity = dClaimQty;
                            lIDDetails      += 1;
                            mods.autoID      = lIDDetails;
                            mods.ID          = mod.ID;
                            mods.bCosting    = true;

                            iRow            += 1;
                            mods.irowno      = iRow;
                            mods.coutposcode = null;
                            mods.cinposcode  = null;
                            //mods.cTVBatch = gridViewPL.GetRowCellValue(i, gridColcBatch).ToString().Trim();
                            mods.cDefine22 = gridViewPL.GetRowCellValue(i, gridColCONTAINERNO).ToString().Trim();
                            mods.cDefine23 = gridViewPL.GetRowCellValue(i, gridColBOXNO).ToString().Trim();
                            mods.cDefine24 = gridViewPL.GetRowCellValue(i, gridColCASENO).ToString().Trim();
                            mods.cDefine25 = gridViewPL.GetRowCellValue(i, gridColGWKGS).ToString().Trim();
                            mods.cDefine28 = gridViewPL.GetRowCellValue(i, gridColNWKGS).ToString().Trim();

                            mods.cbsysbarcode = "||st12|" + mod.cTVCode + "|" + iRow.ToString();
                            DAL.TransVouchs dalTRs = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL.TransVouchs();
                            sSQL    = dalTRs.Add(mods);
                            iCount += DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);

                            //回写导入中间表 Rdrecords10_Import
                            sSQL = @"
update RdRecords01_Import set TrIDsClaim = AAAAAA,ClaimQty = DDDDDD
WHERE AUTOID = BBBBBB
";
                            sSQL = sSQL.Replace("AAAAAA", mods.autoID.ToString());
                            sSQL = sSQL.Replace("BBBBBB", gridViewPL.GetRowCellValue(i, gridColAutoID).ToString());
                            sSQL = sSQL.Replace("DDDDDD", BaseFunction.ReturnDecimal(gridViewPL.GetRowCellValue(i, gridColClaimQty)).ToString().Trim());
                            int iRet = DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                        }

                        if (iRow > 0)
                        {
                            clsU8 cls = new clsU8();
                            cls.TransVouch_Audit_U8V111(tran, mod.cTVCode, sAccID, sUserName);
                        }
                    }

                    #endregion

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

                    if (iCount > 0)
                    {
                        tran.Commit();
                        MessageBox.Show("Success:\n" + sMCode);

                        SetTxtNull();
                    }
                    else
                    {
                        throw new Exception("Save failed");
                    }
                }
                catch (Exception error)
                {
                    tran.Rollback();
                    throw new Exception(error.Message);
                }
            }
            catch (Exception ee)
            {
                FrmMsgBox frm = new FrmMsgBox();
                frm.richTextBox1.Text = ee.Message;
                frm.ShowDialog();
            }
        }
コード例 #3
0
ファイル: BarTransfer.cs プロジェクト: chrgu000/DEMO
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                gridView1.FocusedRowHandle -= 1;
                gridView1.FocusedRowHandle += 1;
            }
            catch { }

            txtBarCode.Focus();
            string sErr = "";

            int iCount = 0;

            try
            {
                string sProcess     = gridView1.GetRowCellValue(0, gridColProcess).ToString().Trim();
                string sProcessNext = gridView1.GetRowCellValue(0, gridColProcessNext).ToString().Trim();
                if (sProcess == sProcessNext)
                {
                    throw new Exception("Process is err");
                }

                SqlConnection conn = new SqlConnection(Conn);
                conn.Open();
                SqlTransaction tran = conn.BeginTransaction();
                try
                {
                    string   sSQL     = "select getdate()";
                    DateTime dNow     = BaseFunction.ReturnDate(DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0].Rows[0][0]);
                    DateTime dNowDate = BaseFunction.ReturnDate(dNow.ToString("yyyy-MM-dd"));

                    int    iYear   = dNow.Year;
                    int    iPeriod = dNow.Month;
                    string s期间     = BaseFunction.ReturnDate(iYear.ToString() + "-" + iPeriod.ToString() + "-01").ToString("yyyyMM");
                    sSQL = "select isnull(bflag_ST,0) as bflag from GL_mend where iYPeriod = '" + s期间 + "'";
                    DataTable dt = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                    if (dt == null || dt.Rows.Count == 0)
                    {
                        throw new Exception("Access module state failure");
                    }
                    int i结账 = BaseFunction.ReturnInt(dt.Rows[0]["bflag"]);
                    if (i结账 > 0)
                    {
                        throw new Exception(dNow.ToString("yyyy-MM") + " have checked out");
                    }

                    //判断是否转入质检工序
                    bool bIQCIn = false;  //材料入库检验
                    bool bOQCIn = false;  //产品销售出库检验
                    sSQL = @"
select cWhMemo
from Warehouse 
where cWhCode = '{0}'
";
                    sSQL = string.Format(sSQL, lookUpEditProcessNext.EditValue.ToString().Trim());
                    dt   = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                    if (dt.Rows[0]["cWhMemo"].ToString().Trim().ToLower().Contains("iqc"))
                    {
                        bIQCIn = true;
                    }
                    if (dt.Rows[0]["cWhMemo"].ToString().Trim().ToLower().Contains("oqc"))
                    {
                        bOQCIn = true;
                    }


                    //判断是否从质检工序转出
                    bool bIQCOut = false;  //材料入库检验工序转出
                    bool bOQCOut = false;  //产品销售出库检验工序转出
                    sSQL = @"
select cWhMemo
from Warehouse 
where cWhCode = '{0}'
";
                    sSQL = string.Format(sSQL, lookUpEditProcess.EditValue.ToString().Trim());
                    dt   = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                    if (dt.Rows[0]["cWhMemo"].ToString().Trim().ToLower().Contains("iqc"))
                    {
                        bIQCOut = true;
                    }
                    if (dt.Rows[0]["cWhMemo"].ToString().Trim().ToLower().Contains("oqc"))
                    {
                        bOQCOut = true;
                    }

                    #region 流转

                    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'tr',1,@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);
                    dt   = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];

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

                    ////获得单据号
                    sSQL = "select * from VoucherHistory with (ROWLOCK) Where CardNumber='0304' AND cContentRule = 'YYYY' AND cSeed = 'aaaaaa'";
                    sSQL = sSQL.Replace("aaaaaa", dNow.ToString("yyyy"));
                    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"]);
                    }
                    else
                    {
                        lCode = 0;
                    }
                    lCode += 1;
                    string sCode = lCode.ToString();
                    while (sCode.Length < 6)
                    {
                        sCode = "0" + sCode;
                    }
                    sCode = "TR" + dNow.ToString("yyyy") + sCode;

                    Model.TransVouch mod = new UFIDA.U8.UAP.CustomApp.ControlForm.Model.TransVouch();
                    mod.cTVCode     = sCode;
                    mod.dTVDate     = dNowDate;
                    mod.cOWhCode    = lookUpEditProcess.EditValue.ToString().Trim();
                    mod.cIWhCode    = lookUpEditProcessNext.EditValue.ToString().Trim();
                    mod.cODepCode   = null;
                    mod.cIDepCode   = null;
                    mod.cPersonCode = null;
                    mod.cIRdCode    = "TI";
                    mod.cORdCode    = "TO";
                    mod.cTVMemo     = null;
                    mod.cDefine1    = null;
                    mod.cDefine2    = null;
                    mod.cDefine3    = null;
                    mod.cDefine4    = null;
                    mod.cDefine5    = null;
                    mod.cDefine6    = null;
                    mod.cDefine7    = null;
                    mod.cDefine8    = null;
                    mod.cDefine9    = null;
                    mod.cDefine10   = null;
                    mod.cAccounter  = null;
                    mod.iNetLock    = 1;
                    lID            += 1;
                    mod.ID          = lID;
                    mod.VT_ID       = 89;
                    mod.cMaker      = sUserName;
                    mod.dnmaketime  = dNow;

                    mod.cVerifyPerson    = sUserName;
                    mod.dVerifyDate      = dNowDate;
                    mod.cPSPCode         = null;
                    mod.cMPoCode         = null;
                    mod.iQuantity        = 0;
                    mod.bTransFlag       = null;
                    mod.cDefine11        = null;
                    mod.cDefine12        = null;
                    mod.cDefine13        = null;
                    mod.cDefine14        = null;
                    mod.cDefine15        = null;
                    mod.cDefine16        = null;
                    mod.iproorderid      = null;
                    mod.cTranRequestCode = null;
                    mod.cVersion         = null;
                    mod.BomId            = null;
                    mod.cFree1           = null;
                    mod.cFree2           = null;
                    mod.cFree3           = null;
                    mod.cFree4           = null;
                    mod.cFree5           = null;
                    mod.cFree6           = null;
                    mod.cFree7           = null;
                    mod.cFree8           = null;
                    mod.cFree9           = null;
                    mod.cFree10          = null;
                    mod.cAppTVCode       = null;
                    mod.csource          = "1";
                    mod.itransflag       = "正向";
                    mod.cModifyPerson    = null;
                    mod.dModifyDate      = null;
                    mod.dnmaketime       = dNow;
                    mod.dnmodifytime     = null;
                    mod.ireturncount     = null;
                    mod.iverifystate     = null;
                    mod.iswfcontrolled   = 0;
                    mod.csourceguid      = null;
                    mod.csysbarcode      = "||st12||" + mod.cTVCode;
                    DAL.TransVouch dalTR = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL.TransVouch();
                    sSQL    = dalTR.Add(mod);
                    iCount += DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                    mod.cCurrentAuditor = null;

                    int iRow = 0;
                    for (int i = 0; i < gridView1.RowCount; i++)
                    {
                        if (!BaseFunction.ReturnBool(gridView1.GetRowCellValue(i, gridColchoose)))
                        {
                            continue;
                        }

                        string sBarCode = gridView1.GetRowCellValue(i, gridColLotNO).ToString().Trim();
                        sSQL = @"
select * from _BarCodeLabel  where [BarCode] = '{0}' and iSOsID = {1}";
                        sSQL = string.Format(sSQL, sBarCode, gridView1.GetRowCellValue(i, gridColiSOsID).ToString());
                        dt   = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                        if (dt == null || dt.Rows.Count == 0)
                        {
                            sErr = sErr + "row " + (i + 1).ToString() + "is not exists \n";
                            continue;
                        }
                        if (dt.Rows[0]["CloseUid"].ToString().Trim() != "")
                        {
                            sErr = sErr + "row " + (i + 1).ToString() + " is closed \n";
                            continue;
                        }
                        if (dt.Rows[0]["Process"].ToString().Trim().ToLower() != lookUpEditProcess.EditValue.ToString().Trim().ToLower())
                        {
                            sErr = sErr + "row " + (i + 1).ToString() + "  process is changed \n";
                            continue;
                        }
                        if (BaseFunction.ReturnDecimal(dt.Rows[0]["LotQTY"]) != BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridColLOTQTY)))
                        {
                            sErr = sErr + "row " + (i + 1).ToString() + " number is changed \n";
                            continue;
                        }
                        if (dt.Rows[0]["IQCStatus"].ToString() != gridView1.GetRowCellValue(i, gridColIQCStatus).ToString().Trim())
                        {
                            sErr = sErr + "row " + (i + 1).ToString() + " iqcstatus is changed \n";
                            continue;
                        }
                        if (dt.Rows[0]["OQCStatus"].ToString() != gridView1.GetRowCellValue(i, gridColOQCStatus).ToString().Trim())
                        {
                            sErr = sErr + "row " + (i + 1).ToString() + " iqcstatus is changed \n";
                            continue;
                        }

                        iRow += 1;
                        Model.BarStatus model = new UFIDA.U8.UAP.CustomApp.ControlForm.Model.BarStatus();
                        model.BarCode = sBarCode;
                        model.iSOsID  = BaseFunction.ReturnLong(gridView1.GetRowCellValue(i, gridColiSOsID));
                        model.Type    = "工序流转";
                        if (bIQCIn)
                        {
                            model.Type = "IQC";

                            sSQL = @"
update  _IQC_RMDF set ClosedUid = '{0}',dtmClose = getdate()
where LotNo = '{1}' and iSOsID = '{2}' and isnull(ClosedUid,'') <> ''
";
                            sSQL = string.Format(sSQL, sUserID, model.BarCode, model.iSOsID);
                            DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                        }
                        if (bOQCIn)
                        {
                            model.Type = "OQC";
                        }

                        model.RoutingFrom = lookUpEditProcess.EditValue.ToString().Trim();
                        model.RoutingTo   = lookUpEditProcessNext.EditValue.ToString().Trim();
                        model.UpdateTime  = dNow;
                        model.QTY         = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridColLOTQTY));
                        model.CreateUid   = sUserID;
                        model.CreateDate  = dNow;
                        DAL.BarStatus dal = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL.BarStatus();
                        sSQL    = dal.Add(model);
                        iCount += DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);

                        //回写上一道工序的结束时间
                        sSQL = @"
declare @iID int 
select @iID = max(iID)
from _BarStatus
where [BarCode] = '{0}' and iSOsID = '{1}'
    and iID < (
        select max(iID) as maxID
        from _BarStatus
        where [BarCode] = '{0}' and iSOsID = '{1}'
    )

update _BarStatus set EndTime = '{2}' where iID = @iID and [BarCode] = '{0}' and iSOsID = '{1}'
";
                        sSQL = string.Format(sSQL, sBarCode, model.iSOsID, dNow);
                        DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);

                        if (bIQCOut)
                        {
                            sSQL = @"
select *
from _BarCodeLabel
where [BarCode] = '{0}' and iSOsID = '{1}'
";
                            sSQL = string.Format(sSQL, sBarCode, model.iSOsID);
                            DataTable dtQC       = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                            string    sIQCStatus = dtQC.Rows[0]["IQCStatus"].ToString().Trim().ToLower();
                            sIQCStatus = sIQCStatus.Replace(" ", "");
                            if (!sIQCStatus.ToLower().StartsWith("iqc"))
                            {
                                sErr = sErr + "row " + (i + 1).ToString() + " IQC not passed \n";
                                continue;
                            }
                        }
                        if (bOQCOut)
                        {
                            sSQL = @"
select *
from _BarCodeLabel
where [BarCode] = '{0}' and iSOsID = '{1}'
";
                            sSQL = string.Format(sSQL, sBarCode, model.iSOsID);
                            DataTable dtQC       = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                            string    sOQCStatus = dtQC.Rows[0]["OQCStatus"].ToString().Trim().ToLower();
                            sOQCStatus = sOQCStatus.Replace(sOQCStatus, " ");
                            if (sOQCStatus == "oqc-ONHOLD".ToLower())
                            {
                                sErr = sErr + "row " + (i + 1).ToString() + " OQC onhold \n";
                                continue;
                            }
                        }

                        //回写 BarCodeLabel
                        sSQL = "update [_BarCodeLabel] set process = '" + model.RoutingTo + "',Status = '流转' where [BarCode] = '" + sBarCode + "' and iSOsID = '" + model.iSOsID + "'";
                        DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);

                        if (bIQCIn)
                        {
                            sSQL = "update [_BarCodeLabel] set IQCStatus = 'Pending IQC',Status = 'IQC' where [BarCode] = '" + sBarCode + "' and iSOsID = '" + model.iSOsID + "'";
                            int iRunCou = DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                        }
                        if (bOQCIn)
                        {
                            sSQL = "update [_BarCodeLabel] set OQCStatus = 'Pending OQC',Status = 'OQC' where [BarCode] = '" + sBarCode + "' and iSOsID = '" + model.iSOsID + "'";
                            DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                        }

                        Model.TransVouchs mods = new UFIDA.U8.UAP.CustomApp.ControlForm.Model.TransVouchs();
                        mods.cTVCode     = mod.cTVCode;
                        mods.cInvCode    = gridView1.GetRowCellValue(i, gridColItemNO).ToString().Trim();
                        mods.iTVNum      = null;
                        mods.iTVQuantity = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridColLOTQTY));
                        lIDDetails      += 1;
                        mods.autoID      = lIDDetails;
                        mods.ID          = mod.ID;
                        mods.bCosting    = true;
                        mods.irowno      = iRow;
                        mods.coutposcode = null;
                        mods.cinposcode  = null;
                        mods.cTVBatch    = gridView1.GetRowCellValue(i, gridColcBatch).ToString().Trim();


                        mods.cbsysbarcode = "||st12|" + mod.cTVCode + "|" + iRow.ToString();
                        DAL.TransVouchs dalTRs = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL.TransVouchs();
                        sSQL    = dalTRs.Add(mods);
                        iCount += DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                    }

                    if (sErr.Length > 0)
                    {
                        throw new Exception(sErr);
                    }

                    if (lID > 1000000000)
                    {
                        lID = lID - 1000000000;
                    }
                    if (lIDDetails > 1000000000)
                    {
                        lIDDetails = lIDDetails - 1000000000;
                    }
                    sSQL = "update UFSystem..UA_Identity set iFatherId = " + lID.ToString() + ",iChildId = " + lIDDetails + " where cAcc_Id = '" + sAccID + "' and cVouchType = 'tr'";
                    DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);


                    sSQL = @"
                    if exists(select * from VoucherHistory where CardNumber='0304' AND cContentRule = 'YYYY' AND cSeed = 'bbbbbb')
                        update VoucherHistory set cNumber = aaaaaa  where CardNumber = '0304' AND cContentRule = 'YYYY' AND cSeed = 'bbbbbb'
                    else
                        insert into VoucherHistory(CardNumber,cContent,cContentRule,cSeed,cNumber,bEmpty)
                        values('0304','日期','YYYY','bbbbbb','aaaaaa',0)
                    ";
                    sSQL = sSQL.Replace("aaaaaa", lCode.ToString());
                    sSQL = sSQL.Replace("bbbbbb", dNow.ToString("yyyy"));
                    DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);

                    clsU8 cls = new clsU8();
                    cls.TransVouch_Audit_U8V111(tran, mod.cTVCode, sAccID, sUserName);


                    #endregion

                    if (iCount > 0)
                    {
                        tran.Commit();

                        MessageBox.Show("OK\n");

                        SetTxtNull();

                        gridControl1.DataSource = DbHelperSQL.Query(sSQLBar);
                        txtBarCode.Focus();
                    }
                }
                catch (Exception ee)
                {
                    tran.Rollback();
                    throw new Exception(ee.Message);
                }
            }
            catch (Exception ee)
            {
                FrmMsgBox frm = new FrmMsgBox();
                frm.richTextBox1.Text = ee.Message;
                frm.ShowDialog();
            }
            gridColScanTime.SortOrder = DevExpress.Data.ColumnSortOrder.Descending;
        }