using System; using System.Collections.Generic; using System.Data; using Dongke.IBOSS.PRD.Basics.DataAccess; using Dongke.IBOSS.PRD.Basics.Library; using Dongke.IBOSS.PRD.Service.DataModels; using Dongke.IBOSS.PRD.Service.WMSDataService.WMS_putBARCODEData; using Dongke.IBOSS.PRD.WCF.DataModels; using Oracle.ManagedDataAccess.Client; namespace Dongke.IBOSS.PRD.Service.WMSDataService { public class WMSDataLogic { /// /// 同步WMS系统条码 /// /// /// public static string PushWMS(DataTable fpData, DateTime now) { INIUtility ini = INIUtility.Instance(INIUtility.IniFile.Config); string endPointConfigurationName = ini.ReadIniData("WMS_INFO", "EndPointConfigurationName"); string userName = ini.ReadIniData("WMS_INFO", "UserName"); string password = ini.ReadIniData("WMS_INFO", "Password"); wmsResultInfo wmsResult = null; try { string outcode; string orderitem; // 主数据 using (ERPWSService2Client wmsClient = new ERPWSService2Client(endPointConfigurationName)) { // 登录 wmsSecurityInfo info = new wmsSecurityInfo(); info.username = userName; info.password = password; wmsBARCODEInfo barcodeInfo = new wmsBARCODEInfo(); List headers = new List(); wmsBarCodeHeader header = null; foreach (DataRow row in fpData.Rows) { outcode = row["outcode"] + ""; orderitem = row["orderitem"] + ""; if (string.IsNullOrEmpty(orderitem) || "0".Equals(orderitem)) { orderitem = "000000"; } header = new wmsBarCodeHeader(); header.SPS = "5020"; header.SKU = row["sapcode"] + ""; header.SerialNO = outcode; header.SerialNO1 = outcode.Substring(outcode.Length - 10, 10); header.SerialNO2 = now.ToString("yyyyMMdd"); header.AddDay = now.ToString("yyyyMMdd"); header.AddTime = now.ToString("HHmmss"); header.CODEI = row["barcode"] + ""; header.UDF1 = row["ordercode"] + ""; header.UDF2 = orderitem; header.AddWho = "HGMESDK"; headers.Add(header); } barcodeInfo.wmsBarCodeHeader = headers.ToArray(); wmsParamInfo wmsParam = new wmsParamInfo(); wmsParam.customerid = "FLUXWMSSOAP"; wmsParam.messageid = "ZTBARCODE"; wmsParam.stdno = "ZTBARCODE"; wmsParam.warehouseid = "WH01"; string ss = JsonHelper.ToJson(barcodeInfo); // 参数 wmsResult = wmsClient.putBARCODEData(info, barcodeInfo, wmsParam); if (wmsResult.returnCode != "0000") { return "同步失败:" + wmsResult.returnDesc; } } // 关系数据 using (ERPWSService2Client wmsClient = new ERPWSService2Client(endPointConfigurationName)) { // 登录 wmsSecurityInfo info = new wmsSecurityInfo(); info.username = userName; info.password = password; wmsBARCODEInfo barcodeInfo = new wmsBARCODEInfo(); List headers = new List(); wmsBarCodeHeader header = null; foreach (DataRow row in fpData.Rows) { outcode = row["outcode"] + ""; orderitem = row["orderitem"] + ""; if (string.IsNullOrEmpty(orderitem) || "0".Equals(orderitem)) { orderitem = "000000"; } header = new wmsBarCodeHeader(); header.SPS = "5020"; header.SKU = row["sapcode"] + ""; header.SerialNO = outcode; header.TraceID = outcode; header.SerialNO1 = outcode.Substring(outcode.Length - 10, 10); header.SerialNO2 = now.ToString("yyyyMMdd"); header.AddDay = now.ToString("yyyyMMdd"); header.AddTime = now.ToString("HHmmss"); header.LPN = row["sapflbatchno"] + ""; header.UDF1 = row["ordercode"] + ""; header.UDF2 = orderitem; header.AddWho = "HGMESDK"; headers.Add(header); } barcodeInfo.wmsBarCodeHeader = headers.ToArray(); wmsParamInfo wmsParam = new wmsParamInfo(); wmsParam.customerid = "FLUXWMSSOAP"; wmsParam.messageid = "ZPPCODE"; wmsParam.stdno = "ZPPCODE"; wmsParam.warehouseid = "WH01"; // 参数 wmsResult = wmsClient.putBARCODEData(info, barcodeInfo, wmsParam); if (wmsResult.returnCode != "0000") { return "同步失败:" + wmsResult.returnDesc; } } } catch (Exception ex) { return "同步失败:" + ex.Message; } return "同步成功"; } /// /// 撤销同步WMS系统的条码 /// /// /// public static string BackPushWMS(DataTable fpData, DateTime now) { INIUtility ini = INIUtility.Instance(INIUtility.IniFile.Config); string endPointConfigurationName = ini.ReadIniData("WMS_INFO", "EndPointConfigurationName"); string userName = ini.ReadIniData("WMS_INFO", "UserName"); string password = ini.ReadIniData("WMS_INFO", "Password"); wmsResultInfo wmsResult = null; try { string outcode; string orderitem; // 关系数据 using (ERPWSService2Client wmsClient = new ERPWSService2Client(endPointConfigurationName)) { // 登录 wmsSecurityInfo info = new wmsSecurityInfo(); info.username = userName; info.password = password; wmsBARCODEInfo barcodeInfo = new wmsBARCODEInfo(); List headers = new List(); wmsBarCodeHeader header = null; foreach (DataRow row in fpData.Rows) { outcode = row["outcode"] + ""; orderitem = row["orderitem"] + ""; if (string.IsNullOrEmpty(orderitem) || "0".Equals(orderitem)) { orderitem = "000000"; } header = new wmsBarCodeHeader(); header.SPS = "5020"; header.SKU = row["sapcode"] + ""; header.SerialNO = outcode; header.TraceID = outcode; header.SerialNO1 = outcode.Substring(outcode.Length - 10, 10); header.SerialNO2 = now.ToString("yyyyMMdd"); header.AddDay = now.ToString("yyyyMMdd"); header.AddTime = now.ToString("HHmmss"); header.LPN = row["sapflbatchno"] + ""; header.UDF1 = row["ordercode"] + ""; header.UDF2 = orderitem; header.UDF5 = "X"; header.AddWho = "HGMESDK"; headers.Add(header); } barcodeInfo.wmsBarCodeHeader = headers.ToArray(); wmsParamInfo wmsParam = new wmsParamInfo(); wmsParam.customerid = "FLUXWMSSOAP"; wmsParam.messageid = "ZPPCODE"; wmsParam.stdno = "ZPPCODE"; wmsParam.warehouseid = "WH01"; // 参数 wmsResult = wmsClient.putBARCODEData(info, barcodeInfo, wmsParam); if (wmsResult.returnCode != "0000") { return "同步失败:" + wmsResult.returnDesc; } } } catch (Exception ex) { return "同步失败:" + ex.Message; } return "同步成功"; } /// /// 手动同步WMS系统条码 /// /// /// public static ServiceResultEntity SyncWMSDataLog(ClientRequestEntity cre, SUserInfo userInfo) { ServiceResultEntity sre = new ServiceResultEntity(); DataTable dtBarcode = cre.Data.Tables[0]; INIUtility ini = INIUtility.Instance(INIUtility.IniFile.Config); string endPointConfigurationName = ini.ReadIniData("WMS_INFO", "EndPointConfigurationName"); string userName = ini.ReadIniData("WMS_INFO", "UserName"); string password = ini.ReadIniData("WMS_INFO", "Password"); wmsResultInfo wmsResult = null; string serialNO; DateTime now; try { if ("1".Equals(cre.Properties["LogType"] + "")) { // 主数据 using (ERPWSService2Client wmsClient = new ERPWSService2Client(endPointConfigurationName)) { // 登录 wmsSecurityInfo info = new wmsSecurityInfo(); info.username = userName; info.password = password; wmsBARCODEInfo barcodeInfo = new wmsBARCODEInfo(); List headers = new List(); wmsBarCodeHeader header = null; foreach (DataRow row in dtBarcode.Rows) { now = Convert.ToDateTime(row["CreateTime"]); serialNO = row["SerialNO"] + ""; header = new wmsBarCodeHeader(); header.SPS = "5020"; header.SKU = row["SKU"] + ""; header.SerialNO = serialNO; header.SerialNO1 = serialNO.Substring(serialNO.Length - 10, 10); header.SerialNO2 = now.ToString("yyyyMMdd"); header.AddDay = now.ToString("yyyyMMdd"); header.AddTime = now.ToString("HHmmss"); header.CODEI = row["CODEI"] + ""; header.UDF1 = row["UDF1"] + ""; header.UDF2 = row["UDF2"] + ""; header.AddWho = "HGMESDK"; headers.Add(header); } barcodeInfo.wmsBarCodeHeader = headers.ToArray(); wmsParamInfo wmsParam = new wmsParamInfo(); wmsParam.customerid = "FLUXWMSSOAP"; wmsParam.messageid = "ZTBARCODE"; wmsParam.stdno = "ZTBARCODE"; wmsParam.warehouseid = "WH01"; // 参数 wmsResult = wmsClient.putBARCODEData(info, barcodeInfo, wmsParam); if (wmsResult.returnCode != "0000") { sre.OtherStatus = -1; sre.Message = "同步失败:" + wmsResult.returnDesc; return sre; } } // 关系数据 using (ERPWSService2Client wmsClient = new ERPWSService2Client(endPointConfigurationName)) { // 登录 wmsSecurityInfo info = new wmsSecurityInfo(); info.username = userName; info.password = password; wmsBARCODEInfo barcodeInfo = new wmsBARCODEInfo(); List headers = new List(); wmsBarCodeHeader header = null; foreach (DataRow row in dtBarcode.Rows) { now = Convert.ToDateTime(row["CreateTime"]); serialNO = row["SerialNO"] + ""; header = new wmsBarCodeHeader(); header.SPS = "5020"; header.SKU = row["SKU"] + ""; header.SerialNO = serialNO; header.TraceID = serialNO; header.SerialNO1 = serialNO.Substring(serialNO.Length - 10, 10); header.SerialNO2 = now.ToString("yyyyMMdd"); header.AddDay = now.ToString("yyyyMMdd"); header.AddTime = now.ToString("HHmmss"); header.LPN = row["LPN"] + ""; header.UDF1 = row["UDF1"] + ""; header.UDF2 = row["UDF2"] + ""; header.AddWho = "HGMESDK"; headers.Add(header); } barcodeInfo.wmsBarCodeHeader = headers.ToArray(); wmsParamInfo wmsParam = new wmsParamInfo(); wmsParam.customerid = "FLUXWMSSOAP"; wmsParam.messageid = "ZPPCODE"; wmsParam.stdno = "ZPPCODE"; wmsParam.warehouseid = "WH01"; // 参数 wmsResult = wmsClient.putBARCODEData(info, barcodeInfo, wmsParam); if (wmsResult.returnCode != "0000") { sre.OtherStatus = -1; sre.Message = "同步失败:" + wmsResult.returnDesc; return sre; } } } else { // 关系数据 using (ERPWSService2Client wmsClient = new ERPWSService2Client(endPointConfigurationName)) { // 登录 wmsSecurityInfo info = new wmsSecurityInfo(); info.username = userName; info.password = password; wmsBARCODEInfo barcodeInfo = new wmsBARCODEInfo(); List headers = new List(); wmsBarCodeHeader header = null; foreach (DataRow row in dtBarcode.Rows) { now = Convert.ToDateTime(row["CreateTime"]); serialNO = row["SerialNO"] + ""; header = new wmsBarCodeHeader(); header.SPS = "5020"; header.SKU = row["SKU"] + ""; header.SerialNO = serialNO; header.TraceID = serialNO; header.SerialNO1 = serialNO.Substring(serialNO.Length - 10, 10); header.SerialNO2 = now.ToString("yyyyMMdd"); header.AddDay = now.ToString("yyyyMMdd"); header.AddTime = now.ToString("HHmmss"); header.LPN = row["LPN"] + ""; header.UDF1 = row["UDF1"] + ""; header.UDF2 = row["UDF2"] + ""; header.UDF5 = "X"; header.AddWho = "HGMESDK"; headers.Add(header); } barcodeInfo.wmsBarCodeHeader = headers.ToArray(); wmsParamInfo wmsParam = new wmsParamInfo(); wmsParam.customerid = "FLUXWMSSOAP"; wmsParam.messageid = "ZPPCODE"; wmsParam.stdno = "ZPPCODE"; wmsParam.warehouseid = "WH01"; // 参数 wmsResult = wmsClient.putBARCODEData(info, barcodeInfo, wmsParam); if (wmsResult.returnCode != "0000") { sre.OtherStatus = -1; sre.Message = "同步失败:" + wmsResult.returnDesc; return sre; } } } } catch (Exception ex) { sre.OtherStatus = -1; sre.Message = "同步失败:" + ex.Message; return sre; } IDBTransaction oracleTrConn = ClsDbFactory.CreateDBTransaction(DataBaseType.ORACLE, DataManager.ConnectionString); string sql = @" UPDATE TP_WMS_LOG SET RETURNDESC = '同步成功', UPDATEUSERID = :USERID WHERE ACCOUNTID = :ACCOUNTID AND LOGTYPE = :LOGTYPE AND CODEI = :CODEI "; OracleParameter[] Paras; foreach (DataRow row in dtBarcode.Rows) { Paras = new OracleParameter[] { new OracleParameter(":USERID",OracleDbType.Int32,userInfo.UserID,ParameterDirection.Input), new OracleParameter(":ACCOUNTID",OracleDbType.Int32,userInfo.AccountID,ParameterDirection.Input), new OracleParameter(":LOGTYPE",OracleDbType.Char, cre.Properties["LogType"] + "",ParameterDirection.Input), new OracleParameter(":CODEI",OracleDbType.Varchar2, row["CODEI"], ParameterDirection.Input), }; oracleTrConn.ExecuteNonQuery(sql, Paras); } oracleTrConn.Commit(); oracleTrConn.Disconnect(); sre.OtherStatus = 1; sre.Message = "同步成功"; return sre; } /// /// 查询同步日志 /// /// /// /// public static ServiceResultEntity GetWMSDataLog(ClientRequestEntity cre, SUserInfo userInfo) { IDBConnection oracleConn = ClsDbFactory.CreateDBConnection(DataBaseType.ORACLE, DataManager.ConnectionString); ServiceResultEntity sre = new ServiceResultEntity(); try { string sqlString = @" SELECT 0 AS SEL, WL.LOGID, WL.LOGTYPE, DECODE(WL.LOGTYPE, '1', '交接', '撤销') AS LOGTYPENAME, WL.SKU, WL.SERIALNO, WL.ADDDAY, WL.ADDTIME, WL.CODEI, NVL(WL.UDF1, 'hegii') AS UDF1, WL.UDF2, WL.LPN, WL.RETURNDESC, WL.CREATETIME FROM TP_WMS_LOG WL WHERE WL.VALUEFLAG = '1' AND WL.ACCOUNTID = :ACCOUNTID AND WL.CREATETIME >= :CREATETIMEBEGIN AND WL.CREATETIME < :CREATETIMEEND "; List paras = new List(); paras.Add(new OracleParameter(":ACCOUNTID", OracleDbType.Int32, userInfo.AccountID, ParameterDirection.Input)); paras.Add(new OracleParameter(":CREATETIMEBEGIN", OracleDbType.Date, cre.Properties["datebegin"], ParameterDirection.Input)); paras.Add(new OracleParameter(":CREATETIMEEND", OracleDbType.Date, cre.Properties["dateend"], ParameterDirection.Input)); if (!string.IsNullOrEmpty(cre.Properties["LogType"] + "")) { sqlString += " AND WL.LOGTYPE = :LOGTYPE\n"; paras.Add(new OracleParameter(":LOGTYPE", OracleDbType.NVarchar2, cre.Properties["LogType"], ParameterDirection.Input)); } if (!string.IsNullOrEmpty(cre.Properties["ReturnDesc"] + "")) { sqlString += " AND WL.RETURNDESC LIKE :RETURNDESC\n"; paras.Add(new OracleParameter(":RETURNDESC", OracleDbType.NVarchar2, "%" + cre.Properties["ReturnDesc"] + "%", ParameterDirection.Input)); } sqlString += " order by WL.CREATETIME"; sre.Data = oracleConn.GetSqlResultToDs(sqlString, paras.ToArray()); return sre; } catch (Exception ex) { throw ex; } } } }