diff --git a/WebService/Function.cs b/WebService/Function.cs index c58fef3..0f62a25 100644 --- a/WebService/Function.cs +++ b/WebService/Function.cs @@ -611,6 +611,8 @@ namespace Webservice } } + private static readonly object _obj = new object(); + private static string _scanCode2 = string.Empty; public static string WMSSpraying(string barcode, int isPass, string stcokNo, string partNo, string batchNo) { JsonModel model = new JsonModel(); @@ -619,124 +621,132 @@ namespace Webservice model.ResultRowsCount = "0"; model.ErrReason = ""; model.DataList = null; - + string sql33 = ""; try { - #region 目前全部存储一维码,将二维码转换为一维码 - - if (barcode.Contains(".")) + lock (_obj) { - barcode = Function.TransToBarCodeOne(barcode); - } - - #endregion - - #region 查看是否已入库,已入库的不允许再入库 + if (_scanCode2 == barcode) + { + LogHelper.WriteLog("a扫码[" + barcode + "]重复了,连续两次扫码相同,第一次还未执行完成,进行第二次扫码."); + } + _scanCode2 = barcode; - if (IsStockIn(barcode)) - { - model.Result = "0"; - model.ResultType = "Result"; - model.ResultRowsCount = "0"; - model.ErrReason = "已入库,不能再次入库"; + #region 目前全部存储一维码,将二维码转换为一维码 - return JSONTools.ScriptSerialize>(model); - } + if (barcode.Contains(".")) + { + barcode = Function.TransToBarCodeOne(barcode); + } - #endregion + #endregion - #region 查状态,看是否还不合格,不合格的不允许入库 + #region 查看是否已入库,已入库的不允许再入库 - if (isPass == 1) - { - if (!barcodeStatus(barcode)) + if (IsStockIn(barcode)) { model.Result = "0"; model.ResultType = "Result"; model.ResultRowsCount = "0"; - model.ErrReason = "产品检验不合格,不能入库"; + model.ErrReason = "已入库,不能再次入库"; return JSONTools.ScriptSerialize>(model); } - } - - #endregion - - #region 转换零件号 - string lu_code = "",colorCode=""; - - LogHelper.WriteSysLogBase("【转换零件号】:barcode:" + barcode, MethodBase.GetCurrentMethod().Name); + #endregion - if (Function.IsBens(barcode.Substring(0, 10))) - { - #region 奔驰件 + #region 查状态,看是否还不合格,不合格的不允许入库 - if (string.IsNullOrWhiteSpace(partNo)) + if (isPass == 1) { - string sql_p = @" select partNo from tb_Product where StockNo = '" + stcokNo + @"' "; - object pp = SqlHelper.ExecuteScalar(SqlHelper.SqlConnString, CommandType.Text, sql_p, null); - if (pp != null) - { - partNo = pp.ToString(); - } - else + if (!barcodeStatus(barcode)) { model.Result = "0"; model.ResultType = "Result"; model.ResultRowsCount = "0"; - model.ErrReason = barcode + "根据存货代码找不到零件号!"; - model.DataList = null; + model.ErrReason = "产品检验不合格,不能入库"; return JSONTools.ScriptSerialize>(model); } } - if (!string.IsNullOrWhiteSpace(partNo)) + #endregion + + #region 转换零件号 + + string lu_code = "", colorCode = ""; + + LogHelper.WriteSysLogBase("【转换零件号】:barcode:" + barcode, MethodBase.GetCurrentMethod().Name); + + if (Function.IsBens(barcode.Substring(0, 10))) { - if (partNo.Contains("-P")) + #region 奔驰件 + + if (string.IsNullOrWhiteSpace(partNo)) { - lu_code = partNo.Remove(partNo.IndexOf('-')); + string sql_p = @" select partNo from tb_Product where StockNo = '" + stcokNo + @"' "; + object pp = SqlHelper.ExecuteScalar(SqlHelper.SqlConnString, CommandType.Text, sql_p, null); + if (pp != null) + { + partNo = pp.ToString(); + } + else + { + model.Result = "0"; + model.ResultType = "Result"; + model.ResultRowsCount = "0"; + model.ErrReason = barcode + "根据存货代码找不到零件号!"; + model.DataList = null; + + return JSONTools.ScriptSerialize>(model); + } } - else + + if (!string.IsNullOrWhiteSpace(partNo)) { - lu_code = partNo; + if (partNo.Contains("-P")) + { + lu_code = partNo.Remove(partNo.IndexOf('-')); + } + else + { + lu_code = partNo; + } } - } - else - { - model.Result = "0"; - model.ResultType = "Result"; - model.ResultRowsCount = "0"; - model.ErrReason = barcode + "的零件号为空,请维护零件号!"; - model.DataList = null; - - return JSONTools.ScriptSerialize>(model); - } + else + { + model.Result = "0"; + model.ResultType = "Result"; + model.ResultRowsCount = "0"; + model.ErrReason = barcode + "的零件号为空,请维护零件号!"; + model.DataList = null; - string sql_ins = " select top 1 productInfo from tb_InspectResult where barcode = '" + barcode.Trim() + @"' and productInfo <> '' order by createTime desc "; - object proInfo = SqlHelper.ExecuteScalar(SqlHelper.SqlConnString, CommandType.Text, sql_ins, null); - string info = ""; - if (proInfo != null) - { - info = proInfo.ToString(); - } + return JSONTools.ScriptSerialize>(model); + } - if (!string.IsNullOrWhiteSpace(info)) - { - LogHelper.WriteSysLogBase("【获取产品信息】:barcode:" + barcode + ",info:" + info, MethodBase.GetCurrentMethod().Name); + string sql_ins = " select top 1 productInfo from tb_InspectResult where barcode = '" + barcode.Trim() + @"' and productInfo <> '' order by createTime desc "; + object proInfo = SqlHelper.ExecuteScalar(SqlHelper.SqlConnString, CommandType.Text, sql_ins, null); + string info = ""; + if (proInfo != null) + { + info = proInfo.ToString(); + } - string[] str = info.Split(','); - if (str.Length >= 3) + if (!string.IsNullOrWhiteSpace(info)) { - lu_code += "-" + str[2].Trim(); + LogHelper.WriteSysLogBase("【获取产品信息】:barcode:" + barcode + ",info:" + info, MethodBase.GetCurrentMethod().Name); + + string[] str = info.Split(','); + if (str.Length >= 3) + { + lu_code += "-" + str[2].Trim(); + } } - } - else - { - LogHelper.WriteSysLogBase("【查询老外库颜色】:barcode:" + barcode, MethodBase.GetCurrentMethod().Name); + else + { + LogHelper.WriteSysLogBase("【查询老外库颜色】:barcode:" + barcode, MethodBase.GetCurrentMethod().Name); - string sql_color = @" + string sql_color = @" DECLARE @barcode varchar(30); SET @barcode = '" + barcode.Trim() + @"'; SELECT top 1 Setvalue_BC_Color_No @@ -767,67 +777,69 @@ namespace Webservice OR LTrim(RTrim(Side_2_BC12))= @barcode order by TimeStamp desc "; - string sqlConnString = ConfigurationManager.ConnectionStrings["SqlConnStringForeign"].ConnectionString; - DataTable dtColor = SqlHelper.GetDataDateTable(sqlConnString, CommandType.Text, sql_color, null); - if (dtColor != null && dtColor.Rows.Count > 0) - { - string color = dtColor.Rows[0][0].ToString(); - if (!string.IsNullOrWhiteSpace(color)) + string sqlConnString = ConfigurationManager.ConnectionStrings["SqlConnStringForeign"].ConnectionString; + sql33 = sql_color; + DataTable dtColor = SqlHelper.GetDataDateTable(sqlConnString, CommandType.Text, sql_color, null); + if (dtColor != null && dtColor.Rows.Count > 0) { - string sql_colorCode = @" SELECT ColorNo FROM tb_Color WHERE ColorCode = '" + color + @"' "; - DataTable dtColorCode = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql_colorCode, null); - if (dtColorCode != null && dtColorCode.Rows.Count > 0) + string color = dtColor.Rows[0][0].ToString(); + if (!string.IsNullOrWhiteSpace(color)) { - lu_code += "-" + dtColorCode.Rows[0][0].ToString(); + string sql_colorCode = @" SELECT ColorNo FROM tb_Color WHERE ColorCode = '" + color + @"' "; + sql33 = sql_colorCode; + DataTable dtColorCode = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql_colorCode, null); + if (dtColorCode != null && dtColorCode.Rows.Count > 0) + { + lu_code += "-" + dtColorCode.Rows[0][0].ToString(); + } } } } - } - #region 判断是否附加了颜色,没有则报错 + #region 判断是否附加了颜色,没有则报错 - LogHelper.WriteSysLogBase("【判断是否附加了颜色】barcode:" + barcode, MethodBase.GetCurrentMethod().Name); + LogHelper.WriteSysLogBase("【判断是否附加了颜色】barcode:" + barcode, MethodBase.GetCurrentMethod().Name); - if (!lu_code.Contains("-")) - { - model.Result = "0"; - model.ResultType = "Result"; - model.ResultRowsCount = "0"; - model.ErrReason = barcode + "喷涂上线查找不到颜色,无法入库"; - model.DataList = null; - - return JSONTools.ScriptSerialize>(model); - } + if (!lu_code.Contains("-")) + { + model.Result = "0"; + model.ResultType = "Result"; + model.ResultRowsCount = "0"; + model.ErrReason = barcode + "喷涂上线查找不到颜色,无法入库"; + model.DataList = null; - #endregion + return JSONTools.ScriptSerialize>(model); + } - #endregion - } - else - { - #region 非奔驰 + #endregion - string sql_ins = " select top 1 productInfo from tb_InspectResult where barcode = '" + barcode.Trim() + @"' and productInfo <> '' order by createTime desc "; - object proInfo = SqlHelper.ExecuteScalar(SqlHelper.SqlConnString, CommandType.Text, sql_ins, null); - string info = ""; - if (proInfo != null) - { - info = proInfo.ToString(); + #endregion } - - if (!string.IsNullOrWhiteSpace(info)) + else { - string[] str = info.Split(','); - if (str.Length >= 3) + #region 非奔驰 + + string sql_ins = " select top 1 productInfo from tb_InspectResult where barcode = '" + barcode.Trim() + @"' and productInfo <> '' order by createTime desc "; + object proInfo = SqlHelper.ExecuteScalar(SqlHelper.SqlConnString, CommandType.Text, sql_ins, null); + string info = ""; + if (proInfo != null) { - colorCode = str[2].Trim(); + info = proInfo.ToString(); } - } - else - { - LogHelper.WriteSysLogBase("【查询老外库颜色】:barcode:" + barcode, MethodBase.GetCurrentMethod().Name); - string sql_color = @" + if (!string.IsNullOrWhiteSpace(info)) + { + string[] str = info.Split(','); + if (str.Length >= 3) + { + colorCode = str[2].Trim(); + } + } + else + { + LogHelper.WriteSysLogBase("【查询老外库颜色】:barcode:" + barcode, MethodBase.GetCurrentMethod().Name); + + string sql_color = @" DECLARE @barcode varchar(30); SET @barcode = '" + barcode.Trim() + @"'; SELECT Setvalue_BC_Color_No,,[Setvalue_CC_Color_No],[Setvalue_PR_Color_No] @@ -857,100 +869,103 @@ namespace Webservice OR LTrim(RTrim(Side_2_BC11))= @barcode OR LTrim(RTrim(Side_2_BC12))= @barcode "; - string sqlConnString = ConfigurationManager.ConnectionStrings["SqlConnStringForeign"].ConnectionString; - DataTable dtColor = SqlHelper.GetDataDateTable(sqlConnString, CommandType.Text, sql_color, null); - if (dtColor != null && dtColor.Rows.Count > 0) - { - string bc_color = dtColor.Rows[0]["Setvalue_BC_Color_No"].ToString(); - string cc_color = dtColor.Rows[0]["Setvalue_CC_Color_No"].ToString(); - string pr_color = dtColor.Rows[0]["Setvalue_PR_Color_No"].ToString(); - if (!string.IsNullOrWhiteSpace(bc_color)) + string sqlConnString = ConfigurationManager.ConnectionStrings["SqlConnStringForeign"].ConnectionString; + sql33 = sql_color; + DataTable dtColor = SqlHelper.GetDataDateTable(sqlConnString, CommandType.Text, sql_color, null); + if (dtColor != null && dtColor.Rows.Count > 0) { - string sql_colorCode = @" SELECT ColorNo FROM tb_Color WHERE ColorCode = '" + bc_color + @"' and ColorQQCode='" + cc_color + @"' and ColorDQCode='" + pr_color + @"'"; - DataTable dtColorCode = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql_colorCode, null); - if (dtColorCode != null && dtColorCode.Rows.Count > 0) + string bc_color = dtColor.Rows[0]["Setvalue_BC_Color_No"].ToString(); + string cc_color = dtColor.Rows[0]["Setvalue_CC_Color_No"].ToString(); + string pr_color = dtColor.Rows[0]["Setvalue_PR_Color_No"].ToString(); + if (!string.IsNullOrWhiteSpace(bc_color)) { - colorCode = dtColorCode.Rows[0]["ColorNo"].ToString(); + string sql_colorCode = @" SELECT ColorNo FROM tb_Color WHERE ColorCode = '" + bc_color + @"' and ColorQQCode='" + cc_color + @"' and ColorDQCode='" + pr_color + @"'"; + sql33 = sql_colorCode; + DataTable dtColorCode = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql_colorCode, null); + if (dtColorCode != null && dtColorCode.Rows.Count > 0) + { + colorCode = dtColorCode.Rows[0]["ColorNo"].ToString(); + } } } } - } - - string sql = @"select PaintNo from tb_StockToPaintNo where StockNo='" + barcode.Substring(0, 10) + @"' and PaintCode='" + colorCode + @"'"; - DataTable dt = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql, null); - if (dt != null && dt.Rows.Count > 0) - { - lu_code = dt.Rows[0]["PaintNo"].ToString(); - } - - if (string.IsNullOrWhiteSpace(lu_code)) - { - model.Result = "0"; - model.ResultType = "Result"; - model.ResultRowsCount = "0"; - model.ErrReason = barcode + "喷涂上线查找不到颜色,无法入库"; - model.DataList = null; - - return JSONTools.ScriptSerialize>(model); - } - #endregion - } + string sql = @"select PaintNo from tb_StockToPaintNo where StockNo='" + barcode.Substring(0, 10) + @"' and PaintCode='" + colorCode + @"'"; + sql33 = sql; + DataTable dt = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql, null); + if (dt != null && dt.Rows.Count > 0) + { + lu_code = dt.Rows[0]["PaintNo"].ToString(); + } + if (string.IsNullOrWhiteSpace(lu_code)) + { + model.Result = "0"; + model.ResultType = "Result"; + model.ResultRowsCount = "0"; + model.ErrReason = barcode + "喷涂上线查找不到颜色,无法入库"; + model.DataList = null; - #endregion + return JSONTools.ScriptSerialize>(model); + } - #region 组织参数 + #endregion + } - List list = new List(); - WMS03Model wmsM = new WMS03Model(); - wmsM.BarCode = barcode; - wmsM.WmsBarCode = ""; - wmsM.LU_Code = lu_code; - wmsM.Batch = batchNo; - wmsM.Q_level = ""; - wmsM.CreationTime = DateTime.Now; - wmsM.IsOk = isPass; - wmsM.Ok_Status = isPass.ToString(); - wmsM.FactoryId = 0; - wmsM.LineId = 0; - wmsM.WmsRead = 1; - wmsM.ReadTime = null; - wmsM.Remark = ""; - #region 产线及工厂ID - //DataTable dt = new DataTable(); - //dt = Function.GetLineIDByBarcode(barcode); //注塑才能查Barcode表 - //if (dt != null && dt.Rows.Count > 0) - //{ - // int lineID = 0; - // Int32.TryParse(Function.GetNoByID(dt.Rows[0]["LineID"].ToString(), "LineID"), out lineID); - // wmsM.LineId = lineID; - // DataTable dtFac = Function.GetFactoryIDByLineId(dt.Rows[0]["LineID"].ToString()); - // if (dtFac != null && dtFac.Rows.Count > 0) - // { - // int facID = 0; - // Int32.TryParse(Function.GetNoByID(dtFac.Rows[0]["FactoryID"].ToString(), "FactoryID"), out facID); - // wmsM.FactoryId = facID; - // } - //} - - LogHelper.WriteSysLogBase("【添加产线ID】barcode:"+ barcode, MethodBase.GetCurrentMethod().Name); + #endregion - string lineid = ConfigurationManager.AppSettings["LineID"].ToString().Trim(); - int lineId = 0; - Int32.TryParse(lineid, out lineId); - wmsM.LineId = lineId; + #region 组织参数 + + List list = new List(); + WMS03Model wmsM = new WMS03Model(); + wmsM.BarCode = barcode; + wmsM.WmsBarCode = ""; + wmsM.LU_Code = lu_code; + wmsM.Batch = batchNo; + wmsM.Q_level = ""; + wmsM.CreationTime = DateTime.Now; + wmsM.IsOk = isPass; + wmsM.Ok_Status = isPass.ToString(); + wmsM.FactoryId = 0; + wmsM.LineId = 0; + wmsM.WmsRead = 1; + wmsM.ReadTime = null; + wmsM.Remark = ""; + + #region 产线及工厂ID + //DataTable dt = new DataTable(); + //dt = Function.GetLineIDByBarcode(barcode); //注塑才能查Barcode表 + //if (dt != null && dt.Rows.Count > 0) + //{ + // int lineID = 0; + // Int32.TryParse(Function.GetNoByID(dt.Rows[0]["LineID"].ToString(), "LineID"), out lineID); + // wmsM.LineId = lineID; + // DataTable dtFac = Function.GetFactoryIDByLineId(dt.Rows[0]["LineID"].ToString()); + // if (dtFac != null && dtFac.Rows.Count > 0) + // { + // int facID = 0; + // Int32.TryParse(Function.GetNoByID(dtFac.Rows[0]["FactoryID"].ToString(), "FactoryID"), out facID); + // wmsM.FactoryId = facID; + // } + //} + + LogHelper.WriteSysLogBase("【添加产线ID】barcode:" + barcode, MethodBase.GetCurrentMethod().Name); + + string lineid = ConfigurationManager.AppSettings["LineID"].ToString().Trim(); + int lineId = 0; + Int32.TryParse(lineid, out lineId); + wmsM.LineId = lineId; - #endregion + #endregion - list.Add(wmsM); + list.Add(wmsM); - #endregion + #endregion - #region 调用WMS接口前记录数据 + #region 调用WMS接口前记录数据 - string sql_bf = @" INSERT INTO [tb_StockIn_beif] + string sql_bf = @" INSERT INTO [tb_StockIn_beif] ([ID] ,[barcode] ,[pass] @@ -960,40 +975,40 @@ namespace Webservice ,'" + barcode + @"' ,'" + isPass + @"' ,(select getdate())) "; - SqlHelper.ExecuteNonQuery(SqlHelper.SqlConnString, CommandType.Text, sql_bf, null); + SqlHelper.ExecuteNonQuery(SqlHelper.SqlConnString, CommandType.Text, sql_bf, null); - #endregion + #endregion - #region 调用WMS Web Service + #region 调用WMS Web Service - WebService.WebReference.JsonService webService = new WebService.WebReference.JsonService(); - webService.Url = ConfigurationManager.AppSettings["WMSWebServiceURL"].ToString(); - webService.Timeout = 1200000; + WebService.WebReference.JsonService webService = new WebService.WebReference.JsonService(); + webService.Url = ConfigurationManager.AppSettings["WMSWebServiceURL"].ToString(); + webService.Timeout = 1200000; - string jsonParam = " [{\"ServiceType\":\"AddMesData\",\"OperName\":\"ADMIN\"}]"; + string jsonParam = " [{\"ServiceType\":\"AddMesData\",\"OperName\":\"ADMIN\"}]"; -  IsoDateTimeConverter timeConverter = new IsoDateTimeConverter(); -     //这里使用自定义日期格式,如果不使用的话,默认是ISO8601格式  -     timeConverter.DateTimeFormat = "yyyy'-'MM'-'dd' 'HH':'mm':'ss"; -     //timeConverter.DateTimeFormat = "yyyy'-'MM'-'dd"; - string strJson = "[25," + JsonConvert.SerializeObject(list, Formatting.Indented, timeConverter) + "]"; + IsoDateTimeConverter timeConverter = new IsoDateTimeConverter(); + //这里使用自定义日期格式,如果不使用的话,默认是ISO8601格式  + timeConverter.DateTimeFormat = "yyyy'-'MM'-'dd' 'HH':'mm':'ss"; + //timeConverter.DateTimeFormat = "yyyy'-'MM'-'dd"; + string strJson = "[25," + JsonConvert.SerializeObject(list, Formatting.Indented, timeConverter) + "]"; - //string strJson = "[25," + JsonHelper.>(list) + "]"; + //string strJson = "[25," + JsonHelper.>(list) + "]"; - #endregion + #endregion - #region 调用,返回结果 + #region 调用,返回结果 - LogHelper.WriteSysLogBase("条码:" + barcode + "调用WMS入库接口,参数:strJson = " + strJson + "调入时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), MethodBase.GetCurrentMethod().Name); - string res = webService.AddData(jsonParam, strJson); - LogHelper.WriteSysLogBase("条码:" + barcode + "调用WMS入库接口,参数:strJson = " + strJson + "返回结果:" + res + "返回结果时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), MethodBase.GetCurrentMethod().Name); - //LogHelper.WriteSysLogBase("条码:" + barcode + "调用WMS入库接口,参数:strJson = " + strJson + "返回结果:" + res, MethodBase.GetCurrentMethod().Name); + LogHelper.WriteSysLogBase("条码:" + barcode + "调用WMS入库接口,参数:strJson = " + strJson + "调入时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), MethodBase.GetCurrentMethod().Name); + string res = webService.AddData(jsonParam, strJson); + LogHelper.WriteSysLogBase("条码:" + barcode + "调用WMS入库接口,参数:strJson = " + strJson + "返回结果:" + res + "返回结果时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), MethodBase.GetCurrentMethod().Name); + //LogHelper.WriteSysLogBase("条码:" + barcode + "调用WMS入库接口,参数:strJson = " + strJson + "返回结果:" + res, MethodBase.GetCurrentMethod().Name); - #region 调用是否成功,若成功则存入数据库,WMS调用成功则无返回结果 + #region 调用是否成功,若成功则存入数据库,WMS调用成功则无返回结果 - if (res.ToUpper() == "TRUE") - { - string sql = @" INSERT INTO [tb_StockIn] + if (res.ToUpper() == "TRUE") + { + string sql = @" INSERT INTO [tb_StockIn] ([ID] ,[barcode] ,[pass] @@ -1005,35 +1020,49 @@ namespace Webservice ,'" + wmsM.CreationTime + @"' ,'" + wmsM.LU_Code + @"' ) "; - SqlHelper.ExecuteNonQuery(SqlHelper.SqlConnString, CommandType.Text, sql, null); + SqlHelper.ExecuteNonQuery(SqlHelper.SqlConnString, CommandType.Text, sql, null); - model.Result = "1"; - model.ResultType = "Result"; - model.ResultRowsCount = "0"; - model.ErrReason = " 成功"; - } - else - { - model.Result = "0"; - model.ResultType = "Result"; - model.ResultRowsCount = "0"; - model.ErrReason = res; - } - #endregion + model.Result = "1"; + model.ResultType = "Result"; + model.ResultRowsCount = "0"; + model.ErrReason = " 成功"; + } + else + { + model.Result = "0"; + model.ResultType = "Result"; + model.ResultRowsCount = "0"; + model.ErrReason = res; + } + #endregion - return JSONTools.ScriptSerialize>(model); + return JSONTools.ScriptSerialize>(model); + + #endregion + + } - #endregion } catch (Exception ex) { LogHelper.WriteLogManager(ex); + if (ex.Message.Contains("syntax")) + { + LogHelper.WriteLog("查询语句错误,执行语句为:" + sql33); + } + LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name); model.ErrReason = ex.Message; return JSONTools.ScriptSerialize>(model); } + finally + { + _scanCode2 = string.Empty; + } } + private static readonly object _obj2 = new object(); + private static string _scanCode = string.Empty; public static string WMSSprayingReturnNo(string barcode, int isPass, string stcokNo, string partNo, string batchNo,string userName) { JsonModel model = new JsonModel(); @@ -1045,168 +1074,177 @@ namespace Webservice try { - #region 目前全部存储一维码,将二维码转换为一维码 - - LogHelper.WriteSysLogBase("WMS接口:条码:" + barcode + ",转换一维码开始调入时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), MethodBase.GetCurrentMethod().Name); - if (barcode.Contains(".")) + + lock (_obj2) { - barcode = Function.TransToBarCodeOne(barcode); - } - LogHelper.WriteSysLogBase("WMS接口:条码:" + barcode + ",转换一维码结束调用时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), MethodBase.GetCurrentMethod().Name); - - #endregion - - #region 查看是否已入库,已入库的不允许再入库 + if (_scanCode == barcode) + { + LogHelper.WriteLog("扫码[" + barcode + "]重复了,连续两次扫码相同,第一次还未执行完成,进行第二次扫码."); + } + _scanCode = barcode; - LogHelper.WriteSysLogBase("WMS接口:条码:" + barcode + ",查看是否已入库开始调入时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), MethodBase.GetCurrentMethod().Name); - if (IsStockIn(barcode)) - { - model.Result = "0"; - model.ResultType = "Result"; - model.ResultRowsCount = "0"; - model.ErrReason = "已入库,不能再次入库"; + #region 目前全部存储一维码,将二维码转换为一维码 - return JSONTools.ScriptSerialize>(model); - } - LogHelper.WriteSysLogBase("WMS接口:条码:" + barcode + ",查看是否已入库结束调用时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), MethodBase.GetCurrentMethod().Name); + LogHelper.WriteSysLogBase("WMS接口:条码:" + barcode + ",转换一维码开始调入时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), MethodBase.GetCurrentMethod().Name); + if (barcode.Contains(".")) + { + barcode = Function.TransToBarCodeOne(barcode); + } + LogHelper.WriteSysLogBase("WMS接口:条码:" + barcode + ",转换一维码结束调用时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), MethodBase.GetCurrentMethod().Name); - #endregion + #endregion - #region 根据条码查找喷涂线,看线上是否出现过此条码,没有则返回错误--注销 20190728 - //if (!barcode.Contains(".") && barcode.Length > 4) - //{ - // string strCode = barcode.Substring(barcode.Length - 4, 4); - // int num = 0; - // Int32.TryParse(strCode, out num); - // if (num < 7000) - // { - // if (!ExistInLine(barcode)) - // { - // model.Result = "0"; - // model.ResultType = "Result"; - // model.ResultRowsCount = "0"; - // model.ErrReason = "喷涂上线查找不到该条码,无法进行质量判定,请补打条码"; - - // return JSONTools.ScriptSerialize>(model); - // } - // } - //} + #region 查看是否已入库,已入库的不允许再入库 - #endregion + LogHelper.WriteSysLogBase("WMS接口:条码:" + barcode + ",查看是否已入库开始调入时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), MethodBase.GetCurrentMethod().Name); + if (IsStockIn(barcode)) + { + model.Result = "0"; + model.ResultType = "Result"; + model.ResultRowsCount = "0"; + model.ErrReason = "已入库,不能再次入库"; - #region 没有进行质量判定,不允许入库 + return JSONTools.ScriptSerialize>(model); + } + LogHelper.WriteSysLogBase("WMS接口:条码:" + barcode + ",查看是否已入库结束调用时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), MethodBase.GetCurrentMethod().Name); - LogHelper.WriteSysLogBase("WMS接口:条码:" + barcode + ",是否进行过质检判定开始调入时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), MethodBase.GetCurrentMethod().Name); - if (!exsitInspectResult(barcode)) - { - model.Result = "0"; - model.ResultType = "Result"; - model.ResultRowsCount = "0"; - model.ErrReason = "没有进行质量判定,不能入库"; + #endregion - return JSONTools.ScriptSerialize>(model); - } - LogHelper.WriteSysLogBase("WMS接口:条码:" + barcode + ",是否进行过质检判定调用结束时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), MethodBase.GetCurrentMethod().Name); + #region 根据条码查找喷涂线,看线上是否出现过此条码,没有则返回错误--注销 20190728 + //if (!barcode.Contains(".") && barcode.Length > 4) + //{ + // string strCode = barcode.Substring(barcode.Length - 4, 4); + // int num = 0; + // Int32.TryParse(strCode, out num); + // if (num < 7000) + // { + // if (!ExistInLine(barcode)) + // { + // model.Result = "0"; + // model.ResultType = "Result"; + // model.ResultRowsCount = "0"; + // model.ErrReason = "喷涂上线查找不到该条码,无法进行质量判定,请补打条码"; + + // return JSONTools.ScriptSerialize>(model); + // } + // } + //} - #endregion + #endregion - #region 查状态,看是否还不合格,不合格的不允许入库 + #region 没有进行质量判定,不允许入库 - LogHelper.WriteSysLogBase("WMS接口:条码:" + barcode + ",查看合格状态开始调入时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), MethodBase.GetCurrentMethod().Name); - if (isPass == 1) - { - if (!barcodeStatus(barcode)) + LogHelper.WriteSysLogBase("WMS接口:条码:" + barcode + ",是否进行过质检判定开始调入时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), MethodBase.GetCurrentMethod().Name); + if (!exsitInspectResult(barcode)) { model.Result = "0"; model.ResultType = "Result"; model.ResultRowsCount = "0"; - model.ErrReason = "产品检验不合格,不能入库"; + model.ErrReason = "没有进行质量判定,不能入库"; return JSONTools.ScriptSerialize>(model); } - } - LogHelper.WriteSysLogBase("WMS接口:条码:" + barcode + ",查看合格状态结束调用时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), MethodBase.GetCurrentMethod().Name); - - #endregion - - #region 转换零件号 - - string lu_code = "", colorCode = ""; + LogHelper.WriteSysLogBase("WMS接口:条码:" + barcode + ",是否进行过质检判定调用结束时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), MethodBase.GetCurrentMethod().Name); - LogHelper.WriteSysLogBase("WMS接口:条码:" + barcode + ",转换零件号开始调入时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), MethodBase.GetCurrentMethod().Name); + #endregion - if (Function.IsBens(barcode.Substring(0, 10))) - { - #region 奔驰产品 + #region 查状态,看是否还不合格,不合格的不允许入库 - if (string.IsNullOrWhiteSpace(partNo)) + LogHelper.WriteSysLogBase("WMS接口:条码:" + barcode + ",查看合格状态开始调入时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), MethodBase.GetCurrentMethod().Name); + if (isPass == 1) { - string sql_p = @" select partNo from tb_Product where StockNo = '" + stcokNo + @"' "; - object pp = SqlHelper.ExecuteScalar(SqlHelper.SqlConnString, CommandType.Text, sql_p, null); - if (pp != null) - { - partNo = pp.ToString(); - } - else + if (!barcodeStatus(barcode)) { model.Result = "0"; model.ResultType = "Result"; model.ResultRowsCount = "0"; - model.ErrReason = barcode + "根据存货代码找不到零件号!"; - model.DataList = null; + model.ErrReason = "产品检验不合格,不能入库"; return JSONTools.ScriptSerialize>(model); } } + LogHelper.WriteSysLogBase("WMS接口:条码:" + barcode + ",查看合格状态结束调用时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), MethodBase.GetCurrentMethod().Name); + + #endregion + + #region 转换零件号 + + string lu_code = "", colorCode = ""; + + LogHelper.WriteSysLogBase("WMS接口:条码:" + barcode + ",转换零件号开始调入时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), MethodBase.GetCurrentMethod().Name); - if (!string.IsNullOrWhiteSpace(partNo)) + if (Function.IsBens(barcode.Substring(0, 10))) { - if (partNo.Contains("-")) + #region 奔驰产品 + + if (string.IsNullOrWhiteSpace(partNo)) { - lu_code = partNo.Remove(partNo.IndexOf('-')); + string sql_p = @" select partNo from tb_Product where StockNo = '" + stcokNo + @"' "; + object pp = SqlHelper.ExecuteScalar(SqlHelper.SqlConnString, CommandType.Text, sql_p, null); + if (pp != null) + { + partNo = pp.ToString(); + } + else + { + model.Result = "0"; + model.ResultType = "Result"; + model.ResultRowsCount = "0"; + model.ErrReason = barcode + "根据存货代码找不到零件号!"; + model.DataList = null; + + return JSONTools.ScriptSerialize>(model); + } } - else + + if (!string.IsNullOrWhiteSpace(partNo)) { - lu_code = partNo; + if (partNo.Contains("-")) + { + lu_code = partNo.Remove(partNo.IndexOf('-')); + } + else + { + lu_code = partNo; + } } - } - else - { - model.Result = "0"; - model.ResultType = "Result"; - model.ResultRowsCount = "0"; - model.ErrReason = barcode + "的零件号为空,请维护零件号!"; - model.DataList = null; - - return JSONTools.ScriptSerialize>(model); - } + else + { + model.Result = "0"; + model.ResultType = "Result"; + model.ResultRowsCount = "0"; + model.ErrReason = barcode + "的零件号为空,请维护零件号!"; + model.DataList = null; - LogHelper.WriteSysLogBase("WMS接口:条码:" + barcode + ",转换零件号获取productinfo开始调入时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), MethodBase.GetCurrentMethod().Name); + return JSONTools.ScriptSerialize>(model); + } - string sql_ins = " select top 1 productInfo from tb_InspectResult where barcode = '" + barcode.Trim() + @"' and productInfo <> '' order by createTime desc "; - object proInfo = SqlHelper.ExecuteScalar(SqlHelper.SqlConnString, CommandType.Text, sql_ins, null); - string info = ""; - if (proInfo != null) - { - info = proInfo.ToString(); - } - LogHelper.WriteSysLogBase("WMS接口:条码:" + barcode + ",转换零件号获取productinfo结束调用时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), MethodBase.GetCurrentMethod().Name); + LogHelper.WriteSysLogBase("WMS接口:条码:" + barcode + ",转换零件号获取productinfo开始调入时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), MethodBase.GetCurrentMethod().Name); - if (!string.IsNullOrWhiteSpace(info)) - { - LogHelper.WriteSysLogBase("【获取产品信息】:barcode:" + barcode + ",info:" + info, MethodBase.GetCurrentMethod().Name); + string sql_ins = " select top 1 productInfo from tb_InspectResult where barcode = '" + barcode.Trim() + @"' and productInfo <> '' order by createTime desc "; + object proInfo = SqlHelper.ExecuteScalar(SqlHelper.SqlConnString, CommandType.Text, sql_ins, null); + string info = ""; + if (proInfo != null) + { + info = proInfo.ToString(); + } + LogHelper.WriteSysLogBase("WMS接口:条码:" + barcode + ",转换零件号获取productinfo结束调用时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), MethodBase.GetCurrentMethod().Name); - string[] str = info.Split(','); - if (str.Length >= 3) + if (!string.IsNullOrWhiteSpace(info)) { - lu_code += "-" + str[2].Trim(); + LogHelper.WriteSysLogBase("【获取产品信息】:barcode:" + barcode + ",info:" + info, MethodBase.GetCurrentMethod().Name); + + string[] str = info.Split(','); + if (str.Length >= 3) + { + lu_code += "-" + str[2].Trim(); + } } - } - else - { - LogHelper.WriteSysLogBase("WMS接口:条码:" + barcode + ",转换零件号查询老外库颜色开始调入时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), MethodBase.GetCurrentMethod().Name); + else + { + LogHelper.WriteSysLogBase("WMS接口:条码:" + barcode + ",转换零件号查询老外库颜色开始调入时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), MethodBase.GetCurrentMethod().Name); - string sql_color = @" + string sql_color = @" DECLARE @barcode varchar(30); SET @barcode = '" + barcode.Trim() + @"'; SELECT top 1 Setvalue_BC_Color_No @@ -1237,71 +1275,71 @@ namespace Webservice OR LTrim(RTrim(Side_2_BC12))= @barcode order by TimeStamp desc "; - string sqlConnString = ConfigurationManager.ConnectionStrings["SqlConnStringForeign"].ConnectionString; - DataTable dtColor = SqlHelper.GetDataDateTable(sqlConnString, CommandType.Text, sql_color, null); - LogHelper.WriteSysLogBase("WMS接口:条码:" + barcode + ",转换零件号查询老外库颜色结束调用时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), MethodBase.GetCurrentMethod().Name); - if (dtColor != null && dtColor.Rows.Count > 0) - { - string color = dtColor.Rows[0][0].ToString(); - if (!string.IsNullOrWhiteSpace(color)) + string sqlConnString = ConfigurationManager.ConnectionStrings["SqlConnStringForeign"].ConnectionString; + DataTable dtColor = SqlHelper.GetDataDateTable(sqlConnString, CommandType.Text, sql_color, null); + LogHelper.WriteSysLogBase("WMS接口:条码:" + barcode + ",转换零件号查询老外库颜色结束调用时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), MethodBase.GetCurrentMethod().Name); + if (dtColor != null && dtColor.Rows.Count > 0) { - string sql_colorCode = @" SELECT ColorNo FROM tb_Color WHERE ColorCode = '" + color + @"' "; - DataTable dtColorCode = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql_colorCode, null); - if (dtColorCode != null && dtColorCode.Rows.Count > 0) + string color = dtColor.Rows[0][0].ToString(); + if (!string.IsNullOrWhiteSpace(color)) { - lu_code += "-" + dtColorCode.Rows[0][0].ToString(); + string sql_colorCode = @" SELECT ColorNo FROM tb_Color WHERE ColorCode = '" + color + @"' "; + DataTable dtColorCode = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql_colorCode, null); + if (dtColorCode != null && dtColorCode.Rows.Count > 0) + { + lu_code += "-" + dtColorCode.Rows[0][0].ToString(); + } } } } - } - LogHelper.WriteSysLogBase("WMS接口:条码:" + barcode + ",转换零件号结束调用时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), MethodBase.GetCurrentMethod().Name); + LogHelper.WriteSysLogBase("WMS接口:条码:" + barcode + ",转换零件号结束调用时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), MethodBase.GetCurrentMethod().Name); - #region 判断是否附加了颜色,没有则报错 + #region 判断是否附加了颜色,没有则报错 - LogHelper.WriteSysLogBase("【判断是否附加了颜色】barcode:" + barcode, MethodBase.GetCurrentMethod().Name); - - if (!lu_code.Contains("-")) - { - model.Result = "0"; - model.ResultType = "Result"; - model.ResultRowsCount = "0"; - model.ErrReason = barcode + "喷涂上线查找不到颜色,无法入库"; - model.DataList = null; + LogHelper.WriteSysLogBase("【判断是否附加了颜色】barcode:" + barcode, MethodBase.GetCurrentMethod().Name); - return JSONTools.ScriptSerialize>(model); - } + if (!lu_code.Contains("-")) + { + model.Result = "0"; + model.ResultType = "Result"; + model.ResultRowsCount = "0"; + model.ErrReason = barcode + "喷涂上线查找不到颜色,无法入库"; + model.DataList = null; - #endregion + return JSONTools.ScriptSerialize>(model); + } - #endregion + #endregion - } - else - { - #region 非奔驰 + #endregion - string sql_ins = " select top 1 productInfo from tb_InspectResult where barcode = '" + barcode.Trim() + @"' and productInfo <> '' order by createTime desc "; - object proInfo = SqlHelper.ExecuteScalar(SqlHelper.SqlConnString, CommandType.Text, sql_ins, null); - string info = ""; - if (proInfo != null) - { - info = proInfo.ToString(); } - - if (!string.IsNullOrWhiteSpace(info)) + else { - string[] str = info.Split(','); - if (str.Length >= 3) + #region 非奔驰 + + string sql_ins = " select top 1 productInfo from tb_InspectResult where barcode = '" + barcode.Trim() + @"' and productInfo <> '' order by createTime desc "; + object proInfo = SqlHelper.ExecuteScalar(SqlHelper.SqlConnString, CommandType.Text, sql_ins, null); + string info = ""; + if (proInfo != null) { - colorCode = str[2].Trim(); + info = proInfo.ToString(); } - } - else - { - LogHelper.WriteSysLogBase("【查询老外库颜色】:barcode:" + barcode, MethodBase.GetCurrentMethod().Name); - string sql_color = @" + if (!string.IsNullOrWhiteSpace(info)) + { + string[] str = info.Split(','); + if (str.Length >= 3) + { + colorCode = str[2].Trim(); + } + } + else + { + LogHelper.WriteSysLogBase("【查询老外库颜色】:barcode:" + barcode, MethodBase.GetCurrentMethod().Name); + + string sql_color = @" DECLARE @barcode varchar(30); SET @barcode = '" + barcode.Trim() + @"'; SELECT top 1 Setvalue_BC_Color_No,,[Setvalue_CC_Color_No],[Setvalue_PR_Color_No] @@ -1332,86 +1370,86 @@ namespace Webservice OR LTrim(RTrim(Side_2_BC12))= @barcode order by TimeStamp desc "; - string sqlConnString = ConfigurationManager.ConnectionStrings["SqlConnStringForeign"].ConnectionString; - DataTable dtColor = SqlHelper.GetDataDateTable(sqlConnString, CommandType.Text, sql_color, null); - if (dtColor != null && dtColor.Rows.Count > 0) - { - string bc_color = dtColor.Rows[0]["Setvalue_BC_Color_No"].ToString(); - string cc_color = dtColor.Rows[0]["Setvalue_CC_Color_No"].ToString(); - string pr_color = dtColor.Rows[0]["Setvalue_PR_Color_No"].ToString(); - if (!string.IsNullOrWhiteSpace(bc_color)) + string sqlConnString = ConfigurationManager.ConnectionStrings["SqlConnStringForeign"].ConnectionString; + DataTable dtColor = SqlHelper.GetDataDateTable(sqlConnString, CommandType.Text, sql_color, null); + if (dtColor != null && dtColor.Rows.Count > 0) { - string sql_colorCode = @" SELECT ColorNo FROM tb_Color WHERE ColorCode = '" + bc_color + @"' and ColorQQCode='" + cc_color + @"' and ColorDQCode='" + pr_color + @"'"; - DataTable dtColorCode = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql_colorCode, null); - if (dtColorCode != null && dtColorCode.Rows.Count > 0) + string bc_color = dtColor.Rows[0]["Setvalue_BC_Color_No"].ToString(); + string cc_color = dtColor.Rows[0]["Setvalue_CC_Color_No"].ToString(); + string pr_color = dtColor.Rows[0]["Setvalue_PR_Color_No"].ToString(); + if (!string.IsNullOrWhiteSpace(bc_color)) { - colorCode = dtColorCode.Rows[0]["ColorNo"].ToString(); + string sql_colorCode = @" SELECT ColorNo FROM tb_Color WHERE ColorCode = '" + bc_color + @"' and ColorQQCode='" + cc_color + @"' and ColorDQCode='" + pr_color + @"'"; + DataTable dtColorCode = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql_colorCode, null); + if (dtColorCode != null && dtColorCode.Rows.Count > 0) + { + colorCode = dtColorCode.Rows[0]["ColorNo"].ToString(); + } } } } - } - - string sql = @"select PaintNo from tb_StockToPaintNo where StockNo='" + barcode.Substring(0, 10) + @"' and PaintCode='" + colorCode + @"'"; - DataTable dt = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql, null); - if (dt != null && dt.Rows.Count > 0) - { - lu_code = dt.Rows[0]["PaintNo"].ToString(); - } - - if (string.IsNullOrWhiteSpace(lu_code)) - { - model.Result = "0"; - model.ResultType = "Result"; - model.ResultRowsCount = "0"; - model.ErrReason = barcode + "喷涂上线查找不到颜色,无法入库"; - model.DataList = null; - - return JSONTools.ScriptSerialize>(model); - } - - #endregion - } + string sql = @"select PaintNo from tb_StockToPaintNo where StockNo='" + barcode.Substring(0, 10) + @"' and PaintCode='" + colorCode + @"'"; + DataTable dt = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql, null); + if (dt != null && dt.Rows.Count > 0) + { + lu_code = dt.Rows[0]["PaintNo"].ToString(); + } - #endregion + if (string.IsNullOrWhiteSpace(lu_code)) + { + model.Result = "0"; + model.ResultType = "Result"; + model.ResultRowsCount = "0"; + model.ErrReason = barcode + "喷涂上线查找不到颜色,无法入库"; + model.DataList = null; - #region 组织参数 + return JSONTools.ScriptSerialize>(model); + } - List list = new List(); - WMS03Model wmsM = new WMS03Model(); - wmsM.BarCode = barcode; - wmsM.WmsBarCode = ""; - wmsM.LU_Code = lu_code; - wmsM.Batch = batchNo; - wmsM.Q_level = ""; - wmsM.CreationTime = DateTime.Now; - wmsM.IsOk = isPass; - wmsM.Ok_Status = isPass.ToString(); - wmsM.FactoryId = 0; - wmsM.LineId = 0; - wmsM.WmsRead = 1; - wmsM.ReadTime = null; - wmsM.Remark = ""; + #endregion + } - #region 产线及工厂ID - LogHelper.WriteSysLogBase("【添加产线ID】barcode:" + barcode, MethodBase.GetCurrentMethod().Name); + #endregion - string lineid = ConfigurationManager.AppSettings["LineID"].ToString().Trim(); - int lineId = 0; - Int32.TryParse(lineid, out lineId); - wmsM.LineId = lineId; + #region 组织参数 + + List list = new List(); + WMS03Model wmsM = new WMS03Model(); + wmsM.BarCode = barcode; + wmsM.WmsBarCode = ""; + wmsM.LU_Code = lu_code; + wmsM.Batch = batchNo; + wmsM.Q_level = ""; + wmsM.CreationTime = DateTime.Now; + wmsM.IsOk = isPass; + wmsM.Ok_Status = isPass.ToString(); + wmsM.FactoryId = 0; + wmsM.LineId = 0; + wmsM.WmsRead = 1; + wmsM.ReadTime = null; + wmsM.Remark = ""; + + #region 产线及工厂ID + + LogHelper.WriteSysLogBase("【添加产线ID】barcode:" + barcode, MethodBase.GetCurrentMethod().Name); + + string lineid = ConfigurationManager.AppSettings["LineID"].ToString().Trim(); + int lineId = 0; + Int32.TryParse(lineid, out lineId); + wmsM.LineId = lineId; - #endregion + #endregion - list.Add(wmsM); + list.Add(wmsM); - #endregion + #endregion - #region 调用WMS接口前记录数据 + #region 调用WMS接口前记录数据 - LogHelper.WriteSysLogBase("WMS接口:条码:" + barcode + ",调用WMS接口前记录数据开始调入时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), MethodBase.GetCurrentMethod().Name); - string sql_bf = @" INSERT INTO [tb_StockIn_beif] + LogHelper.WriteSysLogBase("WMS接口:条码:" + barcode + ",调用WMS接口前记录数据开始调入时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), MethodBase.GetCurrentMethod().Name); + string sql_bf = @" INSERT INTO [tb_StockIn_beif] ([ID] ,[barcode] ,[pass] @@ -1421,39 +1459,39 @@ namespace Webservice ,'" + barcode + @"' ,'" + isPass.ToString() + @"' ,(select getdate())) "; - SqlHelper.ExecuteNonQuery(SqlHelper.SqlConnString, CommandType.Text, sql_bf, null); - LogHelper.WriteSysLogBase("WMS接口:条码:" + barcode + ",调用WMS接口前记录数据结束调用时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), MethodBase.GetCurrentMethod().Name); - #endregion + SqlHelper.ExecuteNonQuery(SqlHelper.SqlConnString, CommandType.Text, sql_bf, null); + LogHelper.WriteSysLogBase("WMS接口:条码:" + barcode + ",调用WMS接口前记录数据结束调用时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), MethodBase.GetCurrentMethod().Name); + #endregion - #region 调用WMS Web Service + #region 调用WMS Web Service - WebService.WebReference.JsonService webService = new WebService.WebReference.JsonService(); - webService.Url = ConfigurationManager.AppSettings["WMSWebServiceURL"].ToString(); - webService.Timeout = 1200000; + WebService.WebReference.JsonService webService = new WebService.WebReference.JsonService(); + webService.Url = ConfigurationManager.AppSettings["WMSWebServiceURL"].ToString(); + webService.Timeout = 1200000; - string jsonParam = " [{\"ServiceType\":\"AddMesData\",\"OperName\":\"ADMIN\"}]"; - //string strJson = "[25," + JSONTools.ScriptSerialize>(list) + "]"; + string jsonParam = " [{\"ServiceType\":\"AddMesData\",\"OperName\":\"ADMIN\"}]"; + //string strJson = "[25," + JSONTools.ScriptSerialize>(list) + "]"; - IsoDateTimeConverter timeConverter = new IsoDateTimeConverter(); - //这里使用自定义日期格式,如果不使用的话,默认是ISO8601格式  - timeConverter.DateTimeFormat = "yyyy'-'MM'-'dd' 'HH':'mm':'ss"; - //timeConverter.DateTimeFormat = "yyyy'-'MM'-'dd"; - string strJson = "[25," + JsonConvert.SerializeObject(list, Formatting.Indented, timeConverter) + "]"; + IsoDateTimeConverter timeConverter = new IsoDateTimeConverter(); + //这里使用自定义日期格式,如果不使用的话,默认是ISO8601格式  + timeConverter.DateTimeFormat = "yyyy'-'MM'-'dd' 'HH':'mm':'ss"; + //timeConverter.DateTimeFormat = "yyyy'-'MM'-'dd"; + string strJson = "[25," + JsonConvert.SerializeObject(list, Formatting.Indented, timeConverter) + "]"; - #endregion + #endregion - #region 调用,返回结果 + #region 调用,返回结果 - LogHelper.WriteSysLogBase("WMS接口:条码:" + barcode + "调用WMS入库接口,参数:strJson = " + strJson + "调入时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), MethodBase.GetCurrentMethod().Name); - string res = webService.AddData(jsonParam, strJson); - LogHelper.WriteSysLogBase("WMS接口:条码:" + barcode + "调用WMS入库接口,参数:strJson = " + strJson + "返回结果:" + res + "返回结果时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), MethodBase.GetCurrentMethod().Name); + LogHelper.WriteSysLogBase("WMS接口:条码:" + barcode + "调用WMS入库接口,参数:strJson = " + strJson + "调入时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), MethodBase.GetCurrentMethod().Name); + string res = webService.AddData(jsonParam, strJson); + LogHelper.WriteSysLogBase("WMS接口:条码:" + barcode + "调用WMS入库接口,参数:strJson = " + strJson + "返回结果:" + res + "返回结果时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), MethodBase.GetCurrentMethod().Name); - #region 调用是否成功,若成功则存入数据库,WMS调用成功则无返回结果 + #region 调用是否成功,若成功则存入数据库,WMS调用成功则无返回结果 - LogHelper.WriteSysLogBase("WMS接口:条码:" + barcode + ",记录StockIn表开始调入时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), MethodBase.GetCurrentMethod().Name); - if (res.ToUpper() == "TRUE") - { - string sql = @" INSERT INTO [tb_StockIn] + LogHelper.WriteSysLogBase("WMS接口:条码:" + barcode + ",记录StockIn表开始调入时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), MethodBase.GetCurrentMethod().Name); + if (res.ToUpper() == "TRUE") + { + string sql = @" INSERT INTO [tb_StockIn] ([ID] ,[barcode] ,[pass] @@ -1466,43 +1504,49 @@ namespace Webservice ,'" + wmsM.LU_Code + @"' ,'" + userName + @"' ) "; - SqlHelper.ExecuteNonQuery(SqlHelper.SqlConnString, CommandType.Text, sql, null); + SqlHelper.ExecuteNonQuery(SqlHelper.SqlConnString, CommandType.Text, sql, null); + + LogHelper.WriteSysLogBase("WMS接口:条码:" + barcode + ",记录StockIn表结束调用时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), MethodBase.GetCurrentMethod().Name); - LogHelper.WriteSysLogBase("WMS接口:条码:" + barcode + ",记录StockIn表结束调用时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), MethodBase.GetCurrentMethod().Name); + List modelL = new List(); + PartInfoModel modelp = new PartInfoModel(); + modelp.PartNo = lu_code; + + LogHelper.WriteSysLogBase("WMS接口:条码:" + barcode + ",查询ProductName开始调入时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), MethodBase.GetCurrentMethod().Name); + string sql_q = @" select ProductName from tb_Product where PartNo = '" + lu_code + @"' "; + object aa = SqlHelper.ExecuteScalar(SqlHelper.SqlConnString, CommandType.Text, sql_q, null); + if (aa != null) + { + modelp.ProductName = aa.ToString(); + } + modelL.Add(modelp); - List modelL = new List(); - PartInfoModel modelp = new PartInfoModel(); - modelp.PartNo = lu_code; + LogHelper.WriteSysLogBase("WMS接口:条码:" + barcode + ",查询ProductName结束调用时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), MethodBase.GetCurrentMethod().Name); - LogHelper.WriteSysLogBase("WMS接口:条码:" + barcode + ",查询ProductName开始调入时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), MethodBase.GetCurrentMethod().Name); - string sql_q = @" select ProductName from tb_Product where PartNo = '" + lu_code + @"' "; - object aa = SqlHelper.ExecuteScalar(SqlHelper.SqlConnString, CommandType.Text, sql_q, null); - if (aa != null) + model.DataList = modelL; + model.Result = "1"; + model.ResultType = "Result"; + model.ResultRowsCount = "1"; + model.ErrReason = " 成功"; + } + else { - modelp.ProductName = aa.ToString(); + model.Result = "0"; + model.ResultType = "Result"; + model.ResultRowsCount = "0"; + model.ErrReason = res; } - modelL.Add(modelp); + #endregion + + return JSONTools.ScriptSerialize>(model); + + #endregion - LogHelper.WriteSysLogBase("WMS接口:条码:" + barcode + ",查询ProductName结束调用时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), MethodBase.GetCurrentMethod().Name); - model.DataList = modelL; - model.Result = "1"; - model.ResultType = "Result"; - model.ResultRowsCount = "1"; - model.ErrReason = " 成功"; - } - else - { - model.Result = "0"; - model.ResultType = "Result"; - model.ResultRowsCount = "0"; - model.ErrReason = res; } - #endregion - return JSONTools.ScriptSerialize>(model); - #endregion + } catch (Exception ex) { @@ -1511,6 +1555,10 @@ namespace Webservice model.ErrReason = ex.Message; return JSONTools.ScriptSerialize>(model); } + finally + { + _scanCode = string.Empty; + } } /// diff --git a/WebService/WMSWebService.asmx.cs b/WebService/WMSWebService.asmx.cs index f028f0d..7bd7620 100644 --- a/WebService/WMSWebService.asmx.cs +++ b/WebService/WMSWebService.asmx.cs @@ -35,7 +35,7 @@ namespace Webservice /// lx 20190610 /// /// 条码号:A2048856739-P.190605.0008(二维码) - [WebMethod] + [WebMethod] [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)] public void WMSSprayingForApp(string barcode) { @@ -47,7 +47,7 @@ namespace Webservice //model.DataList = null; //Context.Response.Write(JSONTools.ScriptSerialize>(model)); - + Context.Response.ContentType = "application/json; charset=utf-8"; string errorReason = ""; JsonModel model = new JsonModel(); @@ -85,16 +85,7 @@ namespace Webservice Context.Response.Write(res); } - [WebMethod] - [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)] - public string WMSSprayingForAppForTest(string barcode) - { - string errorReason = string.Empty; - WMSSprayingForApp(barcode); - if (string.IsNullOrEmpty(errorReason)) - return "true"; - return errorReason; - } + [WebMethod] [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)] public string WMSSprayingForCSForTest(string barcode, int isOK) @@ -412,6 +403,8 @@ namespace Webservice //{ // WMSSprayingForAppReturnNo(barcode,"system"); //} + + [WebMethod] [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)] public void WMSSprayingForAppReturnNo(string barcode,string userName)