using System; using System.Collections.Generic; using System.Text; using System.Data; using Stone.Entity; using Stone.DataService.Biz.BizPublic; using Gm_WMS.DataAccess.DataService; using Stone.DataService.Biz.Info; namespace Stone.DataService.Biz.Bill { public class F_BillVDA { public F_BillVDA() { } public DataSet BillNew(Command cmd) { string BillNo = cmd.Pars[0]; string UserName = cmd.Pars[1]; if (BillNo.Trim() == "") throw new Exception("ASN单号不能为空!"); Entity_v_JIS_VDA v_JIS_VDA = new Entity_v_JIS_VDA(); DataSet dsData = v_JIS_VDA.GetData("[PartNumber], [Qty], isnull([BarCode], '') as [BarCode], [PackageNo], [EnglishName], [AsnNumber], [fileType], [IsCheck]", "[AsnNumber]='" + BillNo + "'", "[PackageNo] asc"); if (dsData.Tables[0].Rows.Count == 0) { throw new Exception("ASN单号未找到!"); } for (int i = 0; i < dsData.Tables[0].Rows.Count; i++) { if (Convert.ToInt32(dsData.Tables[0].Rows[i]["IsCheck"]) == 0) { dsData.Tables[0].Rows[i]["BarCode"] = ""; } } return dsData; } public DataSet PackageScan(Command cmd) { string JQH = cmd.Pars[0]; //机器号,默认1 string BILLNO = cmd.Pars[1]; //AsnNumber string DZXH = cmd.Pars[2]; //地址序号(SY88, SY78) string id = cmd.Pars[3]; //条码流水号 string LPackageNo = cmd.Pars[4]; //左箱号 string RPackageNo = cmd.Pars[5]; //右箱号 string CZYXM = cmd.Pars[6]; //操作员姓名 string PartNumber = cmd.Pars[7]; //零件号 int Qty = Convert.ToInt32(cmd.Pars[8]); //数量 string sql = ""; #region step1 提交信息 sql = @" DECLARE @RC int DECLARE @JQH nvarchar(50) DECLARE @BILLNO nvarchar(50) DECLARE @DZXH nvarchar(50) DECLARE @id nvarchar(50) DECLARE @LPackageNo nvarchar(50) DECLARE @RPackageNo nvarchar(50) DECLARE @CZYXM nvarchar(50) DECLARE @PartNumber nvarchar(50) set @JQH = '{JQH}' set @BILLNO = '{BILLNO}' set @DZXH = '{DZXH}' set @id = '{id}' set @LPackageNo = '{LPackageNo}' set @RPackageNo = '{RPackageNo}' set @CZYXM = '{CZYXM}' set @PartNumber = '{PartNumber}' EXECUTE @RC = [P_CK_ADD] @JQH ,@BILLNO ,@DZXH ,@id ,@LPackageNo ,@RPackageNo ,@CZYXM ,@PartNumber "; sql = sql.Replace("{JQH}", JQH); sql = sql.Replace("{BILLNO}", BILLNO); sql = sql.Replace("{DZXH}", DZXH); sql = sql.Replace("{id}", id); sql = sql.Replace("{LPackageNo}", LPackageNo); sql = sql.Replace("{RPackageNo}", RPackageNo); sql = sql.Replace("{CZYXM}", CZYXM); sql = sql.Replace("{PartNumber}", PartNumber); F_BarCode.Exec_NonQuery(sql); #endregion #region step2 判断是否错误信息 sql = "select * from [MSG] where [机器号]='{JQH}'"; sql = sql.Replace("{JQH}", JQH); DataTable dtMsg = F_BarCode.Exec_DataSet(sql).Tables[0]; if (dtMsg.Rows.Count > 0) { throw new Exception(dtMsg.Rows[0]["错误提示"].ToString()); } #endregion #region step3 取条码信息 sql = "select * from CKLS where [流水号]=" + id; DataSet dsData = F_BarCode.Exec_DataSet(sql); if (dsData.Tables[0].Rows.Count == 0) throw new Exception("流水号[" + id + "]在系统中不存在"); if (dsData.Tables[0].Rows[0]["零件号"].ToString().Trim() != PartNumber.Trim()) { //throw new Exception("零件号不正确"); throw new Exception("零件号不正确\r\n本地零件号:" + PartNumber + "\r\n条码零件号:" + dsData.Tables[0].Rows[0]["零件号"].ToString()); } if (Convert.ToInt32(dsData.Tables[0].Rows[0]["装箱数量"]) != Qty) { //throw new Exception("数量不正确"); throw new Exception("数量不正确\r\n本地装箱数量:" + Qty + "\r\n条码装箱数量:" + dsData.Tables[0].Rows[0]["装箱数量"].ToString()); } #endregion #region step4 回写数量 sql = @" DECLARE @RC int DECLARE @JQH nvarchar(50) DECLARE @SL int set @SL = {SL} EXECUTE @RC = [P_CK_SL] @JQH ,@SL "; sql = sql.Replace("{SL}", Qty.ToString()); F_BarCode.Exec_NonQuery(sql); #endregion #region step5 判断是否成功 sql = "select * from JK_CK where [SN]=" + id + " and [BillNo]='" + BILLNO + "'"; if (F_BarCode.Exec_DataSet(sql).Tables[0].Rows.Count == 0) throw new Exception("写入中间表失败,请重新扫描"); #endregion return dsData; } public void PackageDel(Command cmd) { string JQH = cmd.Pars[0]; string id = cmd.Pars[1]; string BillNo = cmd.Pars[2]; string sql = @" DECLARE @RC int DECLARE @JQH nvarchar(50) DECLARE @id nvarchar(50) DECLARE @BillNo nvarchar(50) set @JQH = '{JQH}' set @id = '{id}' set @BillNo = '{BillNo}' EXECUTE @RC = [EDI].[dbo].[P_CK_DEL] @JQH ,@id ,@BillNo "; sql = sql.Replace("{JQH}", JQH); sql = sql.Replace("{id}", id); sql = sql.Replace("{BillNo}", BillNo); F_BarCode.Exec_NonQuery(sql); } public void PackageOK(string BillNo) { string sql = @" DECLARE @RC int DECLARE @BillNo nvarchar(50) set @BillNo = '{BillNo}' EXECUTE @RC = [EDI].[dbo].[P_CK_OK] @BillNo "; sql = sql.Replace("{BillNo}", BillNo); F_BarCode.Exec_NonQuery(sql); } public void BillSubmit(Command cmd, DataSet dsData) { string UserName = cmd.Pars[0]; if (dsData.Tables[0].Rows.Count == 0) throw new Exception("提交的数据不能为空!"); string BillNo = dsData.Tables[0].Rows[0]["AsnNumber"].ToString(); if (new Entity_t_JIS_VDA().GetData("[AsnNumber]='" + BillNo + "' and [IsCheck]=1").Tables[0].Rows.Count > 0) throw new Exception(BillNo + " 已经提交过了"); LocalDBService db = null; try { db = new LocalDBService(); db.BeginTrans(); Entity_t_JIS_VDA t_JIS_VDA = new Entity_t_JIS_VDA(db); PackageOK(BillNo); foreach (DataRow drData in dsData.Tables[0].Rows) { t_JIS_VDA.Edit("[IsCheck]=1, [CheckUser]='" + UserName + "', [CheckTime]=getdate(), [BarCode]='" + drData["BarCode"].ToString() + "'", "[AsnNumber]='" + BillNo + "' and [PackageNo]='" + drData["PackageNo"].ToString() + "'"); } db.Commit(); } catch (Exception ex) { if (db != null) db.Rollback(); throw ex; } finally { if (db != null) db.EndTrans(); } } } }