using ChangKeTec.Utils; using DBUtility; using Newtonsoft.Json; using Newtonsoft.Json.Converters; using System; using System.Collections.Generic; using System.Configuration; using System.Data; using System.Reflection; using System.Security.Cryptography; using System.Text; using Tools; using WebService.Model; namespace Webservice { public class Function { public static readonly string app_id = "9b38d8d9-af87-49d2-a0a1-87516c86f254"; public static readonly string app_secret = "422f5bd0-0393-408b-9024-a98f8c6367a4"; /// /// 判断AppID是否合法 /// /// /// public static bool AppIDIsRight(string app_id) { if (app_id.Trim() != Function.app_id.Trim()) { return false; } else { return true; } } public static string MD5Encryption(string str) { try { if (!string.IsNullOrWhiteSpace(str)) { byte[] result = Encoding.Default.GetBytes(str); //tbPass为输入密码的文本框 MD5 md5 = new MD5CryptoServiceProvider(); byte[] output = md5.ComputeHash(result); return BitConverter.ToString(output).Replace("-", ""); } else { return string.Empty; } } catch (Exception ex) { LogHelper.WriteLogManager(ex); return string.Empty; } } /// /// 传入的参数是否合法 /// /// /// /// public static bool signIsRight(string[] param, string sign) { bool res; string str = ""; if (param.Length > 0) { foreach (string s in param) { str += s.Trim(); } } string getMd5 = MD5Encryption(str); if (getMd5 != sign) { res = false; } else { res = true; } return res; } public static DataTable GetInfoByParticles(string stockNo, string partNo, out string errorReason) { DataTable res = new DataTable(); try { if (!string.IsNullOrWhiteSpace(stockNo)) { string sql = @" select * from tb_Product where StockNo = '" + stockNo + @"' "; res = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql, null); } else if (!string.IsNullOrWhiteSpace(partNo)) { string sql = @" select * from tb_Product where PartNo = '" + partNo + @"' "; res = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql, null); } errorReason = ""; return res; } catch (Exception ex) { LogHelper.WriteLogManager(ex); LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name); errorReason = ex.Message; return res; } } public static bool QueryIsBind(string particleCode, string drumCode, out string errorReason,out int flag) { try { string[] part = particleCode.Split('.'); string newpartNo = part[0]; #region 2021-04-12 wff新增 同一种料可以加,不同种料提示先解绑 string sql3 = " select top 1 * from tb_CylinderAndRaw where DrumBarCode='" + drumCode + "' and Time2 is null order by Time1 desc"; DataTable dt1 = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql3, null); if (dt1 != null && dt1.Rows.Count > 0) { string[] aa = dt1.Rows[0]["BarCode"].ToString().Split('.'); string oldpartNo = aa[0]; if (newpartNo == oldpartNo) { #region 2021-04-19续料的时候将之前的解绑并增加新记录续料状态(Flang=1) string sql_2 = " update tb_CylinderAndRaw set Time2 = getdate() where DrumBarCode = '" + drumCode.Trim() + "' and Time2 is null "; SqlHelper.ExecuteNonQuery(SqlHelper.SqlConnString, CommandType.Text, sql_2, null); #endregion errorReason = ""; flag = 1; return false; } errorReason = " 料筒" + drumCode + "中已绑定" + oldpartNo + "的塑料粒子,请先做解绑操作!"; flag = 0; return true; } errorReason = ""; flag = 0; return false; #endregion #region 2021-04-12wff注销 //string sql = " SELECT * FROM tb_StationAndCylinder WHERE CylinderID = ( SELECT CylinderID from tb_Cylinder WHERE CylinderNo = ('" + drumCode + "') ) and Time2 is null "; //DataTable dt = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql, null); //if (dt != null && dt.Rows.Count > 0) //{ // errorReason = " 料筒" + drumCode + "已绑定了塑料粒子与注塑机,请先做解绑操作!"; // return true; //} //else //{ //} //string sql_2 = " update tb_CylinderAndRaw set Time2 = getdate() where DrumBarCode = '" + drumCode.Trim() + "' and Time2 is null "; //SqlHelper.ExecuteNonQuery(SqlHelper.SqlConnString, CommandType.Text, sql_2, null); //errorReason = ""; //return false; #endregion } catch (Exception ex) { LogHelper.WriteLogManager(ex); LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name); errorReason = ex.ToString(); flag= 0; return true; } } /// /// 绑定塑料粒子与料筒 /// /// 塑料粒子 /// 料筒 /// /// public static int BindparticleCodeAndDrum(string particleCode, string drumCode,int flag, out string errorReason) { int res = 0; try { string sql = @" insert into tb_CylinderAndRaw(ID, CylinderID, DrumBarCode, BarCode, Time1,Flag) values((select newid()),(select CylinderID from tb_Cylinder where CylinderNo = '" + drumCode + @"'),'" + drumCode + @"', '" + particleCode + @"', (select getdate()),"+ flag+ @") "; res = SqlHelper.ExecuteNonQuery(SqlHelper.SqlConnString, CommandType.Text, sql, null); errorReason = ""; return res; } catch (Exception ex) { LogHelper.WriteLogManager(ex); LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name); errorReason = ex.Message; return res; } } /// /// 注塑机号(即工位号) /// /// /// /// public static DataTable GetPlan(string machineCode, out string errorReason) { DataTable res = new DataTable(); try { string sql = @" select top 1 ProductName as [Plan] from tb_Product where StockNo in ( select top 1 StockNo from tb_InjectionPlan where StationID = ( select StationID from tb_Station where StationNo = '" + machineCode + @"' ) AND (IsFinish IS NULL OR IsFinish = 0) ORDER BY BeginTime ASC ) "; res = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql, null); if (res == null || res.Rows.Count < 1) { string sql2 = @" select top 1 ProductName as [Plan] from tb_Product where PartNo in ( select top 1 PartNo from tb_InjectionPlan where StationID = ( select StationID from tb_Station where StationNo = '" + machineCode + @"' ) AND (IsFinish IS NULL OR IsFinish = 0) ORDER BY BeginTime ASC ) "; res = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql2, null); } if (res != null && res.Rows.Count > 0) { errorReason = ""; } else { errorReason = "根据注塑机号查询不到信息,请查看是否维护生产计划"; } return res; } catch(Exception ex) { LogHelper.WriteLogManager(ex); LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name); errorReason = ex.Message; return res; } } public static DataTable GetMaterialInfo(string drumCode, out string errorReason) { DataTable res = new DataTable(); try { string sql = @" select top 1 BarCode from tb_CylinderAndRaw where DrumBarCode = '" + drumCode + @"' and Time2 is null order by Time1 desc "; res = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql, null); errorReason = ""; return res; } catch (Exception ex) { LogHelper.WriteLogManager(ex); LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name); errorReason = ex.Message; return res; } } /// /// 绑定注塑机与料筒 /// /// 注塑机(实际传的是工位号,一个工位就是一个注塑机) /// 料筒 /// /// public static int BindMachineAndDrum(string machineCode, string drumCode, out string errorReason) { int res = 0; try { #region 查询当前注塑机计划生产的产品与料筒中的原料是否有对应关系,如果不匹配则不能绑定 string particlePartNo = ""; string productPartNo = ""; string sqlGetproductPartNo = @" SELECT partNo FROM tb_Product WHERE StockNo = ( SELECT TOP 1 StockNo FROM tb_InjectionPlan WHERE StationID = ( SELECT StationID FROM tb_Station WHERE StationNo = '" + machineCode + @"' ) AND (IsFinish IS NULL OR IsFinish = 0) ORDER BY BeginTime ) "; object aa = SqlHelper.ExecuteScalar(SqlHelper.SqlConnString, CommandType.Text, sqlGetproductPartNo, null); if (aa != null) { productPartNo = aa.ToString(); } string sqlGetparticlePartNo = @" SELECT TOP 1 BarCode,Time1 FROM tb_CylinderAndRaw WHERE DrumBarCode = '" + drumCode + @"' AND Time2 IS NULL ORDER BY Time1 DESC "; DataTable bb = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sqlGetparticlePartNo, null); if (bb!=null &&bb.Rows.Count>0) { string stockNo = ""; string partNo = ""; string batchNo = ""; GetCode(bb.Rows[0]["BarCode"].ToString(), out stockNo, out batchNo, out partNo); particlePartNo = partNo; #region 2022-04-11 wff增加烘干时间不足两小时不允许料筒和机台绑定 if (TimeDiff(Convert.ToDateTime(bb.Rows[0]["Time1"].ToString()),DateTime.Now) < 7200) { res = 0; errorReason = "原料烘干未达到两个小时,无法绑定注塑机"; return res; } #endregion } string sqlGetProductAndMetiral = @" SELECT * FROM tb_Bom WHERE PartNo1 = '" + productPartNo + @"' AND PartNo2 = '" + particlePartNo + @"' "; DataTable dt = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sqlGetProductAndMetiral, null); LogHelper.WriteSysLogBase("APP【绑定注塑机与料筒】machineCode:" + machineCode + ",drumCode:" + drumCode + ",产品:" + productPartNo + ",原料:" + particlePartNo, MethodBase.GetCurrentMethod().Name); if (dt != null && dt.Rows.Count > 0) { #region 先解绑之前的注塑机与料筒 string sql_unBind = " update tb_StationAndCylinder set Time2 = getdate() where StationID = (select StationID from tb_Station where StationNo = '" + machineCode + @"') "; SqlHelper.ExecuteNonQuery(SqlHelper.SqlConnString, CommandType.Text, sql_unBind, null); #endregion #region 绑定注塑机与料筒 string sql = @" insert into tb_StationAndCylinder(ID, StationID, CylinderID, Time1) values((select newid()), (select StationID from tb_Station where StationNo = '" + machineCode + @"'), (select CylinderID from tb_Cylinder where CylinderNo = '" + drumCode + @"'), (select getdate())) "; res = SqlHelper.ExecuteNonQuery(SqlHelper.SqlConnString, CommandType.Text, sql, null); errorReason = ""; #endregion } else { res = 0; errorReason = "当前注塑机生产产品与料筒的原料不匹配"; } #endregion return res; } catch (Exception ex) { LogHelper.WriteLogManager(ex); LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name); errorReason = ex.Message; return res; } } /// /// 解绑料筒的绑定关系 /// /// /// /// public static int ClearDrum(string drumCode, out string errorReason) { int res = 0; try { string sql = @" update tb_CylinderAndRaw set Time2 = (select getdate()) where CylinderID = (select CylinderID from tb_Cylinder where CylinderNo = '" + drumCode + @"') and Time2 is null; update tb_StationAndCylinder set Time2 = (select getdate()) where CylinderID = (select CylinderID from tb_Cylinder where CylinderNo = '" + drumCode + @"') and Time2 is null; "; res = SqlHelper.ExecuteNonQuery(SqlHelper.SqlConnString, CommandType.Text, sql, null); errorReason = ""; return res; } catch (Exception ex) { LogHelper.WriteLogManager(ex); LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name); errorReason = ex.Message; return res; } } #region 工具 /// /// 解析条码(一维码返回存货代码,二维码返回零件号) /// /// 条码 /// 存货代码 /// 批次 /// /// 零件号 public static void GetCode(string code, out string stockNo, out string batchNo, out string partNo) { //解析塑料粒子条码,长度为20的为一维码22000000821906090201,否则为二维码 //二维码样例Z-340.180411.000001;5000;S35001;20180411;P1710401.[#Line#];180411; //第一个分号之前的数据,即Z-340.180411.000001; Z-340为零件号,180411为批次号,000001为流水号 //一维码前十位为零件号,tb_Product PartNo,11~16位为批次 stockNo = ""; //存货代码 batchNo = ""; //批次 partNo = ""; //零件号 try { if (code.Contains(".") == false) { //一维码 if (code.Length > 9) { stockNo = code.Substring(0, 10); batchNo = code.Substring(10, 6); } } else { //二维码 string[] strs = code.Split(';'); if (strs.Length > 0) { string str = strs[0]; string[] props = str.Split('.'); if (props.Length >= 3) { partNo = props[0]; batchNo = props[1]; } } } } catch (Exception ex) { stockNo = ""; //存货代码 batchNo = ""; //批次 partNo = ""; //零件号 LogHelper.WriteLogManager(ex); LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name); } } /// /// 转换字符串编码 /// /// /// public static string EncodingStr(String str) { Encoding utf8 = Encoding.UTF8; Encoding defaultCode = Encoding.Default; byte[] utf8Bytes = defaultCode.GetBytes(str); byte[] defaultBytes = Encoding.Convert(utf8, defaultCode, utf8Bytes); char[] defaultChars = new char[defaultCode.GetCharCount(defaultBytes, 0, defaultBytes.Length)]; defaultCode.GetChars(defaultBytes, 0, defaultBytes.Length, defaultChars, 0); return new string(defaultChars); } #endregion #region WMS接口 /// /// 根据条码查询产线ID /// lx 20190610 /// /// /// public static DataTable GetLineIDByBarcode(string barcode) { DataTable res = new DataTable(); try { string sql = @" SELECT [StationID] ,[LineID] FROM tb_Station WHERE StationID = ( SELECT TOP 1 StationID FROM tb_BarCode WHERE BarCode = '" + barcode + @"' ) "; res = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql, null); return res; } catch (Exception ex) { LogHelper.WriteLogManager(ex); LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name); return res; } } /// /// 根据产线ID查询工厂ID /// lx 20190610 /// /// /// public static DataTable GetFactoryIDByLineId(string lineID) { DataTable res = new DataTable(); try { string sql = @" SELECT FactoryID FROM tb_Place WHERE PlaceID = ( SELECT PlaceID FROM tb_Line WHERE LineID = '" + lineID + @"' ) "; res = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql, null); return res; } catch (Exception ex) { LogHelper.WriteLogManager(ex); LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name); return res; } } /// /// 根据id查询指定值 /// /// /// /// public static string GetNoByID(string id, string name) { string res = ""; try { string queryName = ""; string tableName = ""; switch (name.ToLower().Trim()) { case "lineid": queryName = " LineName "; tableName = " tb_Line "; break; case "factoryid": queryName = " FactoryName "; tableName = " tb_Factory "; break; } string sql = @" select " + queryName + " from " + tableName + " where " + name + " = '" + id + "' "; res = SqlHelper.ExecuteScalar(SqlHelper.SqlConnString, CommandType.Text, sql, null).ToString(); return res; } catch (Exception ex) { LogHelper.WriteLogManager(ex); LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name); return res; } } public static string WMSSpraying(string barcode, int isPass, string stcokNo, string partNo, string batchNo) { JsonModel model = new JsonModel(); model.Result = "0"; model.ResultType = "Result"; model.ResultRowsCount = "0"; model.ErrReason = ""; model.DataList = null; try { #region 目前全部存储一维码,将二维码转换为一维码 if (barcode.Contains(".")) { barcode = Function.TransToBarCodeOne(barcode); } #endregion #region 查看是否已入库,已入库的不允许再入库 if (IsStockIn(barcode)) { model.Result = "0"; model.ResultType = "Result"; model.ResultRowsCount = "0"; model.ErrReason = "已入库,不能再次入库"; return JSONTools.ScriptSerialize>(model); } #endregion #region 查状态,看是否还不合格,不合格的不允许入库 if (isPass == 1) { if (!barcodeStatus(barcode)) { model.Result = "0"; model.ResultType = "Result"; model.ResultRowsCount = "0"; model.ErrReason = "产品检验不合格,不能入库"; return JSONTools.ScriptSerialize>(model); } } #endregion #region 转换零件号 string lu_code = "",colorCode=""; LogHelper.WriteSysLogBase("【转换零件号】:barcode:" + barcode, MethodBase.GetCurrentMethod().Name); if (Function.IsBens(barcode.Substring(0, 10))) { #region 奔驰件 if (string.IsNullOrWhiteSpace(partNo)) { 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); } } if (!string.IsNullOrWhiteSpace(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); } 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)) { 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); string sql_color = @" DECLARE @barcode varchar(30); SET @barcode = '" + barcode.Trim() + @"'; SELECT top 1 Setvalue_BC_Color_No FROM [PRODUCTION_DATA].[dbo].[Paintline_Proddata] WHERE LTrim(RTrim(Side_1_BC01)) = @barcode OR LTrim(RTrim(Side_1_BC02))= @barcode OR LTrim(RTrim(Side_1_BC03))= @barcode OR LTrim(RTrim(Side_1_BC04))= @barcode OR LTrim(RTrim(Side_1_BC05))= @barcode OR LTrim(RTrim(Side_1_BC06))= @barcode OR LTrim(RTrim(Side_1_BC07))= @barcode OR LTrim(RTrim(Side_1_BC08))= @barcode OR LTrim(RTrim(Side_1_BC09))= @barcode OR LTrim(RTrim(Side_1_BC10))= @barcode OR LTrim(RTrim(Side_1_BC11))= @barcode OR LTrim(RTrim(Side_1_BC12))= @barcode OR LTrim(RTrim(Side_2_BC01)) = @barcode OR LTrim(RTrim(Side_2_BC02))= @barcode OR LTrim(RTrim(Side_2_BC03))= @barcode OR LTrim(RTrim(Side_2_BC04))= @barcode OR LTrim(RTrim(Side_2_BC05))= @barcode OR LTrim(RTrim(Side_2_BC06))= @barcode OR LTrim(RTrim(Side_2_BC07))= @barcode OR LTrim(RTrim(Side_2_BC08))= @barcode OR LTrim(RTrim(Side_2_BC09))= @barcode OR LTrim(RTrim(Side_2_BC10))= @barcode OR LTrim(RTrim(Side_2_BC11))= @barcode 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 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(); } } } } #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; return JSONTools.ScriptSerialize>(model); } #endregion #endregion } else { #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) { info = proInfo.ToString(); } 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] FROM [PRODUCTION_DATA].[dbo].[Paintline_Proddata] WHERE LTrim(RTrim(Side_1_BC01)) = @barcode OR LTrim(RTrim(Side_1_BC02))= @barcode OR LTrim(RTrim(Side_1_BC03))= @barcode OR LTrim(RTrim(Side_1_BC04))= @barcode OR LTrim(RTrim(Side_1_BC05))= @barcode OR LTrim(RTrim(Side_1_BC06))= @barcode OR LTrim(RTrim(Side_1_BC07))= @barcode OR LTrim(RTrim(Side_1_BC08))= @barcode OR LTrim(RTrim(Side_1_BC09))= @barcode OR LTrim(RTrim(Side_1_BC10))= @barcode OR LTrim(RTrim(Side_1_BC11))= @barcode OR LTrim(RTrim(Side_1_BC12))= @barcode OR LTrim(RTrim(Side_2_BC01)) = @barcode OR LTrim(RTrim(Side_2_BC02))= @barcode OR LTrim(RTrim(Side_2_BC03))= @barcode OR LTrim(RTrim(Side_2_BC04))= @barcode OR LTrim(RTrim(Side_2_BC05))= @barcode OR LTrim(RTrim(Side_2_BC06))= @barcode OR LTrim(RTrim(Side_2_BC07))= @barcode OR LTrim(RTrim(Side_2_BC08))= @barcode OR LTrim(RTrim(Side_2_BC09))= @barcode OR LTrim(RTrim(Side_2_BC10))= @barcode 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 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 } #endregion #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 list.Add(wmsM); #endregion #region 调用WMS接口前记录数据 string sql_bf = @" INSERT INTO [tb_StockIn_beif] ([ID] ,[barcode] ,[pass] ,[createTime]) VALUES ((select newid()) ,'" + barcode + @"' ,'" + isPass + @"' ,(select getdate())) "; SqlHelper.ExecuteNonQuery(SqlHelper.SqlConnString, CommandType.Text, sql_bf, null); #endregion #region 调用WMS Web Service WebService.WebReference.JsonService webService = new WebService.WebReference.JsonService(); webService.Url = ConfigurationManager.AppSettings["WMSWebServiceURL"].ToString(); webService.Timeout = 1200000; 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) + "]"; //string strJson = "[25," + JsonHelper.>(list) + "]"; #endregion #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); #region 调用是否成功,若成功则存入数据库,WMS调用成功则无返回结果 if (res.ToUpper() == "TRUE") { string sql = @" INSERT INTO [tb_StockIn] ([ID] ,[barcode] ,[pass] ,[createTime],paintCode) VALUES ((select newid()) ,'" + barcode + @"' ,'" + isPass.ToString() + @"' ,'" + wmsM.CreationTime + @"' ,'" + wmsM.LU_Code + @"' ) "; 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 return JSONTools.ScriptSerialize>(model); #endregion } catch (Exception ex) { LogHelper.WriteLogManager(ex); LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name); model.ErrReason = ex.Message; return JSONTools.ScriptSerialize>(model); } } public static string WMSSprayingReturnNo(string barcode, int isPass, string stcokNo, string partNo, string batchNo) { JsonModel model = new JsonModel(); model.Result = "0"; model.ResultType = "Result"; model.ResultRowsCount = "0"; model.ErrReason = ""; model.DataList = null; try { #region 目前全部存储一维码,将二维码转换为一维码 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 #region 查看是否已入库,已入库的不允许再入库 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 = "已入库,不能再次入库"; return JSONTools.ScriptSerialize>(model); } LogHelper.WriteSysLogBase("WMS接口:条码:" + barcode + ",查看是否已入库结束调用时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), MethodBase.GetCurrentMethod().Name); #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); // } // } //} #endregion #region 没有进行质量判定,不允许入库 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 = "没有进行质量判定,不能入库"; return JSONTools.ScriptSerialize>(model); } LogHelper.WriteSysLogBase("WMS接口:条码:" + barcode + ",是否进行过质检判定调用结束时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), MethodBase.GetCurrentMethod().Name); #endregion #region 查状态,看是否还不合格,不合格的不允许入库 LogHelper.WriteSysLogBase("WMS接口:条码:" + barcode + ",查看合格状态开始调入时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), MethodBase.GetCurrentMethod().Name); if (isPass == 1) { if (!barcodeStatus(barcode)) { model.Result = "0"; model.ResultType = "Result"; model.ResultRowsCount = "0"; 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 (Function.IsBens(barcode.Substring(0, 10))) { #region 奔驰产品 if (string.IsNullOrWhiteSpace(partNo)) { 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); } } if (!string.IsNullOrWhiteSpace(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); } LogHelper.WriteSysLogBase("WMS接口:条码:" + barcode + ",转换零件号获取productinfo开始调入时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), 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); if (!string.IsNullOrWhiteSpace(info)) { 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); string sql_color = @" DECLARE @barcode varchar(30); SET @barcode = '" + barcode.Trim() + @"'; SELECT top 1 Setvalue_BC_Color_No FROM [PRODUCTION_DATA].[dbo].[Paintline_Proddata] WHERE LTrim(RTrim(Side_1_BC01)) = @barcode OR LTrim(RTrim(Side_1_BC02))= @barcode OR LTrim(RTrim(Side_1_BC03))= @barcode OR LTrim(RTrim(Side_1_BC04))= @barcode OR LTrim(RTrim(Side_1_BC05))= @barcode OR LTrim(RTrim(Side_1_BC06))= @barcode OR LTrim(RTrim(Side_1_BC07))= @barcode OR LTrim(RTrim(Side_1_BC08))= @barcode OR LTrim(RTrim(Side_1_BC09))= @barcode OR LTrim(RTrim(Side_1_BC10))= @barcode OR LTrim(RTrim(Side_1_BC11))= @barcode OR LTrim(RTrim(Side_1_BC12))= @barcode OR LTrim(RTrim(Side_2_BC01)) = @barcode OR LTrim(RTrim(Side_2_BC02))= @barcode OR LTrim(RTrim(Side_2_BC03))= @barcode OR LTrim(RTrim(Side_2_BC04))= @barcode OR LTrim(RTrim(Side_2_BC05))= @barcode OR LTrim(RTrim(Side_2_BC06))= @barcode OR LTrim(RTrim(Side_2_BC07))= @barcode OR LTrim(RTrim(Side_2_BC08))= @barcode OR LTrim(RTrim(Side_2_BC09))= @barcode OR LTrim(RTrim(Side_2_BC10))= @barcode OR LTrim(RTrim(Side_2_BC11))= @barcode 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 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); #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; return JSONTools.ScriptSerialize>(model); } #endregion #endregion } else { #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) { info = proInfo.ToString(); } 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] FROM [PRODUCTION_DATA].[dbo].[Paintline_Proddata] WHERE LTrim(RTrim(Side_1_BC01)) = @barcode OR LTrim(RTrim(Side_1_BC02))= @barcode OR LTrim(RTrim(Side_1_BC03))= @barcode OR LTrim(RTrim(Side_1_BC04))= @barcode OR LTrim(RTrim(Side_1_BC05))= @barcode OR LTrim(RTrim(Side_1_BC06))= @barcode OR LTrim(RTrim(Side_1_BC07))= @barcode OR LTrim(RTrim(Side_1_BC08))= @barcode OR LTrim(RTrim(Side_1_BC09))= @barcode OR LTrim(RTrim(Side_1_BC10))= @barcode OR LTrim(RTrim(Side_1_BC11))= @barcode OR LTrim(RTrim(Side_1_BC12))= @barcode OR LTrim(RTrim(Side_2_BC01)) = @barcode OR LTrim(RTrim(Side_2_BC02))= @barcode OR LTrim(RTrim(Side_2_BC03))= @barcode OR LTrim(RTrim(Side_2_BC04))= @barcode OR LTrim(RTrim(Side_2_BC05))= @barcode OR LTrim(RTrim(Side_2_BC06))= @barcode OR LTrim(RTrim(Side_2_BC07))= @barcode OR LTrim(RTrim(Side_2_BC08))= @barcode OR LTrim(RTrim(Side_2_BC09))= @barcode OR LTrim(RTrim(Side_2_BC10))= @barcode OR LTrim(RTrim(Side_2_BC11))= @barcode 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 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 } #endregion #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 list.Add(wmsM); #endregion #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] ([ID] ,[barcode] ,[pass] ,[createTime]) VALUES ((select newid()) ,'" + 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 #region 调用WMS Web Service 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) + "]"; 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 #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); #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] ([ID] ,[barcode] ,[pass] ,[createTime],paintCode) VALUES ((select newid()) ,'" + barcode + @"' ,'" + isPass.ToString() + @"' ,'" + wmsM.CreationTime + @"' ,'" + wmsM.LU_Code + @"' ) "; 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); 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); 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) { LogHelper.WriteLogManager(ex); LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name); model.ErrReason = ex.Message; return JSONTools.ScriptSerialize>(model); } } /// /// 将二维码转换成相应一维码 /// /// /// // public static string TransToBarCodeOne(string barcode) // { // string res = ""; // try // { // string sql = @" // SELECT TOP 1 OneBarCode FROM tb_BarCode WHERE BarCode = '"+ barcode +@"' // "; // object aa = SqlHelper.ExecuteScalar(SqlHelper.SqlConnString, CommandType.Text, sql, null); // if (aa != null) // { // res = aa.ToString(); // } // return res; // } // catch (Exception ex) // { // LogHelper.WriteLogManager(ex); // LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name); // return res; // } // } public static string TransToBarCodeOne(string barcode) { string res = ""; try { string sql = @" SELECT TOP 1 OneBarCode FROM tb_BarCode WHERE BarCode = '" + barcode + @"' "; object aa = SqlHelper.ExecuteScalar(SqlHelper.SqlConnString, CommandType.Text, sql, null); if (aa != null) { res = aa.ToString(); } else { string sqll = @" select OneBarCode from [10.60.101.60].[BBMPT1].[dbo].[v_Code] where barcode = '" + barcode + @"' "; object bb = SqlHelper.ExecuteScalar(SqlHelper.SqlConnString, CommandType.Text, sqll, null); if (bb != null) { res = bb.ToString(); } } return res; } catch (Exception ex) { LogHelper.WriteLogManager(ex); LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name); return res; } } /// /// 查看是否已入库 /// /// /// public static bool IsStockIn(string barcode) { try { string sql = @" select * from tb_StockIn where barcode = '" + barcode + "' and pass = '1' "; DataTable dt = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql, null); if (dt != null && dt.Rows.Count > 0) { return true; } else { return false; } } catch (Exception ex) { LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name); return false; } } /// /// 查询检验结果,最终是否合格 /// /// /// public static bool barcodeStatus(string barcode) { try { DataTable dt = new DataTable(); string sql = ""; if (barcode.Contains(".")) { string barcodeOne = TransToBarCodeOne(barcode); sql = @" select * from (SELECT * from (select TOP 1 * from tb_InspectResult where barcode = '" + barcode + @"' or barcode = '" + barcodeOne + @"' AND InspectTimes = '1' ORDER BY createTime DESC) aa UNION SELECT * from (select TOP 1 * from tb_InspectResult where barcode = '" + barcode + @"' or barcode = '" + barcodeOne + @"' AND InspectTimes = '2' ORDER BY createTime DESC) bb UNION SELECT * from (select TOP 1 * from tb_InspectResult where barcode = '" + barcode + @"' or barcode = '" + barcodeOne + @"' AND InspectTimes = '3' ORDER BY createTime DESC) cc) dd order by createTime DESC "; } else { sql = @" select * from (SELECT * from (select TOP 1 * from tb_InspectResult where barcode = '" + barcode + @"' AND InspectTimes = '1' ORDER BY createTime DESC) aa UNION SELECT * from (select TOP 1 * from tb_InspectResult where barcode = '" + barcode + @"' AND InspectTimes = '2' ORDER BY createTime DESC) bb UNION SELECT * from (select TOP 1 * from tb_InspectResult where barcode = '" + barcode + @"' AND InspectTimes = '3' ORDER BY createTime DESC) cc) dd order by createTime DESC "; } dt = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql, null); LogHelper.WriteSysLogBase("质量判定结果--"+sql + " : " + dt.ToString(), MethodBase.GetCurrentMethod().Name); //查询质量判定结果 if (dt != null && dt.Rows.Count > 0) { string inspectResult = dt.Rows[0]["inspectResult"].ToString().Trim(); if ("[合格]" == inspectResult) { return true; } else { return false; } } return false; } catch (Exception ex) { LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name); return false; } } /// /// 查询是否进行了质量判定 /// /// /// public static bool exsitInspectResult(string barcode) { bool res = false; try { string sql = ""; if (barcode.Contains(".")) { string barcodeOne = TransToBarCodeOne(barcode); sql = @" select ID from tb_InspectResult WITH (NOLOCK) where barcode = '" + barcode.Trim() + "' or barcode = '" + barcodeOne + @"' "; } else { sql = @" select ID from tb_InspectResult WITH (NOLOCK) where barcode = '" + barcode.Trim() + "'"; } DataTable dt = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql, null); LogHelper.WriteSysLogBase("是否进行过质量判定--" + sql + " : " + dt.Rows.Count, MethodBase.GetCurrentMethod().Name); //查询是否进行过质量判定 if (dt.Rows.Count > 0) { res = true; } return res; } catch (Exception ex) { LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name); return false; } } /// /// 查询条码是否曾经上喷涂线 /// /// /// public static bool ExistInLine(string barcode) { bool res = false; try { string sql = @" DECLARE @barcode varchar(30); SET @barcode = '" + barcode + @"'; SELECT Setvalue_BC_Color_No, * FROM [PRODUCTION_DATA].[dbo].[Paintline_Proddata] WHERE LTrim(RTrim(Side_1_BC01)) = @barcode OR LTrim(RTrim(Side_1_BC02))= @barcode OR LTrim(RTrim(Side_1_BC03))= @barcode OR LTrim(RTrim(Side_1_BC04))= @barcode OR LTrim(RTrim(Side_1_BC05))= @barcode OR LTrim(RTrim(Side_1_BC06))= @barcode OR LTrim(RTrim(Side_1_BC07))= @barcode OR LTrim(RTrim(Side_1_BC08))= @barcode OR LTrim(RTrim(Side_1_BC09))= @barcode OR LTrim(RTrim(Side_1_BC10))= @barcode OR LTrim(RTrim(Side_1_BC11))= @barcode OR LTrim(RTrim(Side_1_BC12))= @barcode OR LTrim(RTrim(Side_2_BC01)) = @barcode OR LTrim(RTrim(Side_2_BC02))= @barcode OR LTrim(RTrim(Side_2_BC03))= @barcode OR LTrim(RTrim(Side_2_BC04))= @barcode OR LTrim(RTrim(Side_2_BC05))= @barcode OR LTrim(RTrim(Side_2_BC06))= @barcode OR LTrim(RTrim(Side_2_BC07))= @barcode OR LTrim(RTrim(Side_2_BC08))= @barcode OR LTrim(RTrim(Side_2_BC09))= @barcode OR LTrim(RTrim(Side_2_BC10))= @barcode OR LTrim(RTrim(Side_2_BC11))= @barcode OR LTrim(RTrim(Side_2_BC12))= @barcode "; string sqlConnString = ConfigurationManager.ConnectionStrings["SqlConnStringForeign"].ConnectionString; DataTable dt = SqlHelper.GetDataDateTable(sqlConnString, CommandType.Text, sql, null); if (dt != null && dt.Rows.Count > 0) { res = true; } else { // string sql2 = @" // DECLARE @barcode varchar(30); // SET @barcode = '" + barcode + @"'; // SELECT Setvalue_BC_Color_No, * // FROM [PRODUCTION_DATA].[dbo].[Paintline_Loadingdata] // WHERE LTrim(RTrim(Side_1_BC01)) = @barcode // OR LTrim(RTrim(Side_1_BC02))= @barcode // OR LTrim(RTrim(Side_1_BC03))= @barcode // OR LTrim(RTrim(Side_1_BC04))= @barcode // OR LTrim(RTrim(Side_1_BC05))= @barcode // OR LTrim(RTrim(Side_1_BC06))= @barcode // OR LTrim(RTrim(Side_1_BC07))= @barcode // OR LTrim(RTrim(Side_1_BC08))= @barcode // OR LTrim(RTrim(Side_1_BC09))= @barcode // OR LTrim(RTrim(Side_1_BC10))= @barcode // OR LTrim(RTrim(Side_1_BC11))= @barcode // OR LTrim(RTrim(Side_1_BC12))= @barcode // OR LTrim(RTrim(Side_2_BC01)) = @barcode // OR LTrim(RTrim(Side_2_BC02))= @barcode // OR LTrim(RTrim(Side_2_BC03))= @barcode // OR LTrim(RTrim(Side_2_BC04))= @barcode // OR LTrim(RTrim(Side_2_BC05))= @barcode // OR LTrim(RTrim(Side_2_BC06))= @barcode // OR LTrim(RTrim(Side_2_BC07))= @barcode // OR LTrim(RTrim(Side_2_BC08))= @barcode // OR LTrim(RTrim(Side_2_BC09))= @barcode // OR LTrim(RTrim(Side_2_BC10))= @barcode // OR LTrim(RTrim(Side_2_BC11))= @barcode // OR LTrim(RTrim(Side_2_BC12))= @barcode // "; // DataTable dt2 = SqlHelper.GetDataDateTable(sqlConnString, CommandType.Text, sql2, null); // if (dt2 != null && dt2.Rows.Count > 0) // { // res = true; // } // else // { // res = false; // } res = false; } return res; } catch (Exception ex) { LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name); return false; } } public static bool AddStockInBarcode(string barcode, out string errorReason) { bool res = false; try { string sql = @" INSERT INTO tb_StockIn ([ID] ,[barcode] ,[pass] ,[createTime],paintCode) VALUES ((select newid()) ,'" + barcode + @"' ,'1' ,(select getdate()),(select top 1 paintCode from tb_StockIn where barcode = '" + barcode + @"' and paintCode is not null order by createtime desc)) "; int result = SqlHelper.ExecuteNonQuery(SqlHelper.SqlConnString, CommandType.Text, sql, null); if (result > 0) { res = true; } else { res = false; } errorReason = ""; return res; } catch (Exception ex) { LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name); errorReason = ex.ToString(); return res; } } #endregion #region 加漆防错接口 /// /// 查询油漆是否存在或在用 /// /// /// /// public static DataTable GetPaintInfoIsUsing(string PaintCode, out string errorReason) { DataTable res = new DataTable(); try { string sql = @" select * from tb_PaintInfo where IsUsing=1 and PaintCode = '" + PaintCode + @"' "; res = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql, null); errorReason = ""; return res; } catch (Exception ex) { LogHelper.WriteLogManager(ex); errorReason = ex.Message; return res; } } /// /// 查询油漆信息 /// /// /// /// public static DataTable GetPaintInfo(string PaintCode, out string errorReason) { DataTable res = new DataTable(); try { string sql = @" select * from tb_PaintInfo where PaintCode = '" + PaintCode + @"' "; res = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql, null); errorReason = ""; return res; } catch (Exception ex) { LogHelper.WriteLogManager(ex); errorReason = ex.Message; return res; } } public static DataTable IsMatch(string PaintCode, string DrumCode, out string errorReason) { DataTable res = new DataTable(); try { string sql = @"SELECT dbo.tb_BucketInfo.BucketCode, dbo.tb_PaintInfo.PaintCode FROM dbo.tb_BucketInfo INNER JOIN dbo.tb_Paint_Bucket ON dbo.tb_BucketInfo.ID = dbo.tb_Paint_Bucket.BucketID INNER JOIN dbo.tb_PaintInfo ON dbo.tb_Paint_Bucket.PaintID = dbo.tb_PaintInfo.ID where dbo.tb_BucketInfo.BucketCode='" + DrumCode + "' and dbo.tb_PaintInfo.PaintCode = '" + PaintCode + @"' "; res = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql, null); errorReason = ""; return res; } catch (Exception ex) { LogHelper.WriteLogManager(ex); errorReason = ex.Message; return res; } } public static bool IsOut(string barcode) { bool flag = false; try { List list=new List(); wmsOutModel md=new wmsOutModel(); md.ServiceType = "GerPickFactForMesValdate"; md.BarCode = barcode; list.Add(md); #region 调用wms webservice WebService.WebReference.JsonService webService = new WebService.WebReference.JsonService(); webService.Url = ConfigurationManager.AppSettings["WMSWebServiceURL"].ToString(); webService.Timeout = 1200000; string strJson = JsonConvert.SerializeObject(list); LogHelper.WriteSysLogBase("WMS油漆是否出库接口:条码:" + barcode + "油漆是否出库接口,参数:strJson = " + strJson + "调入时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), MethodBase.GetCurrentMethod().Name); string res = webService.GetData(strJson); LogHelper.WriteSysLogBase("WMS油漆是否出库接口:条码:" + barcode + "调用WMS油漆是否出库接口,参数:strJson = " + strJson + "返回结果:" + res + "返回结果时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), MethodBase.GetCurrentMethod().Name); #endregion if (res.ToLower().Contains("true")) { flag = true; } return flag; } catch (Exception ex) { LogHelper.WriteLogManager(ex); LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name); return flag; } } #endregion #region 质检判定 /// /// 获取班次,规定早8至晚8为A班 /// /// public static string GetWorkClass() { bool classA = IsBetweenTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "2019-06-12 08:00:00", "2019-06-12 20:00:00"); if (classA) { return "A班"; } else { return "B班"; } } /// /// 判断传入时间是否在工作时间段内 /// /// /// /// /// public static bool IsBetweenTime(string timeStr, string startTime, string endTime) { //判断传入时间是否在工作时间段内 try { TimeSpan startSpan = DateTime.Parse(startTime).TimeOfDay; TimeSpan endSpan = DateTime.Parse(endTime).TimeOfDay; DateTime t1 = Convert.ToDateTime(timeStr); TimeSpan dspNow = t1.TimeOfDay; if (dspNow > startSpan && dspNow < endSpan) { return true; } return false; } catch (Exception ex) { LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name); return false; } } /// /// 根据条码号获取AB侧 /// /// /// public static string GetSide(string barcode) { string res = ""; try { //有一检结果的 string sql = @" select top 1 side from tb_InspectResult where barcode = '" + barcode + "' and InspectTimes = '1' order by createTime desc "; object aa = SqlHelper.ExecuteScalar(SqlHelper.SqlConnString, CommandType.Text, sql, null); if (aa != null) { res = aa.ToString(); } else { if (string.IsNullOrWhiteSpace(res)) { //没有一检结果,查询老外数据库 string sql_foreign = @" DECLARE @barcode varchar(30); SET @barcode = '" + barcode + @"'; SELECT Setvalue_BC_Color_No FROM [PRODUCTION_DATA].[dbo].[Paintline_Loadingdata] WHERE LTrim(RTrim(Side_1_BC01)) = @barcode OR LTrim(RTrim(Side_1_BC02))= @barcode OR LTrim(RTrim(Side_1_BC03))= @barcode OR LTrim(RTrim(Side_1_BC04))= @barcode OR LTrim(RTrim(Side_1_BC05))= @barcode OR LTrim(RTrim(Side_1_BC06))= @barcode OR LTrim(RTrim(Side_1_BC07))= @barcode OR LTrim(RTrim(Side_1_BC08))= @barcode OR LTrim(RTrim(Side_1_BC09))= @barcode OR LTrim(RTrim(Side_1_BC10))= @barcode OR LTrim(RTrim(Side_1_BC11))= @barcode OR LTrim(RTrim(Side_1_BC12))= @barcode "; string sqlConnString = ConfigurationManager.ConnectionStrings["SqlConnStringForeign"].ToString(); object bb = SqlHelper.ExecuteScalar(sqlConnString, CommandType.Text, sql_foreign, null); string colorNo = ""; if (bb != null) { colorNo = bb.ToString(); if (!string.IsNullOrWhiteSpace(colorNo)) { res = "A侧"; } } else { string sql_foreign2 = @" DECLARE @barcode varchar(30); SET @barcode = '" + barcode + @"'; SELECT Setvalue_BC_Color_No FROM [PRODUCTION_DATA].[dbo].[Paintline_Loadingdata] WHERE LTrim(RTrim(Side_2_BC01)) = @barcode OR LTrim(RTrim(Side_2_BC02))= @barcode OR LTrim(RTrim(Side_2_BC03))= @barcode OR LTrim(RTrim(Side_2_BC04))= @barcode OR LTrim(RTrim(Side_2_BC05))= @barcode OR LTrim(RTrim(Side_2_BC06))= @barcode OR LTrim(RTrim(Side_2_BC07))= @barcode OR LTrim(RTrim(Side_2_BC08))= @barcode OR LTrim(RTrim(Side_2_BC09))= @barcode OR LTrim(RTrim(Side_2_BC10))= @barcode OR LTrim(RTrim(Side_2_BC11))= @barcode OR LTrim(RTrim(Side_2_BC12))= @barcode "; object cc = SqlHelper.ExecuteScalar(sqlConnString, CommandType.Text, sql_foreign2, null); string colorNo2 = ""; if (cc != null) { colorNo2 = cc.ToString(); if (!string.IsNullOrWhiteSpace(colorNo2)) { res = "B侧"; } } else { string sql_foreign3 = @" DECLARE @barcode varchar(30); SET @barcode = '" + barcode + @"'; SELECT Setvalue_BC_Color_No FROM [PRODUCTION_DATA].[dbo].[Paintline_Proddata] WHERE LTrim(RTrim(Side_2_BC01)) = @barcode OR LTrim(RTrim(Side_2_BC02))= @barcode OR LTrim(RTrim(Side_2_BC03))= @barcode OR LTrim(RTrim(Side_2_BC04))= @barcode OR LTrim(RTrim(Side_2_BC05))= @barcode OR LTrim(RTrim(Side_2_BC06))= @barcode OR LTrim(RTrim(Side_2_BC07))= @barcode OR LTrim(RTrim(Side_2_BC08))= @barcode OR LTrim(RTrim(Side_2_BC09))= @barcode OR LTrim(RTrim(Side_2_BC10))= @barcode OR LTrim(RTrim(Side_2_BC11))= @barcode OR LTrim(RTrim(Side_2_BC12))= @barcode "; object dd = SqlHelper.ExecuteScalar(sqlConnString, CommandType.Text, sql_foreign3, null); string colorNo3 = ""; if (dd != null) { colorNo3 = dd.ToString(); if (!string.IsNullOrWhiteSpace(colorNo3)) { res = "B侧"; } } else { string sql_foreign4 = @" DECLARE @barcode varchar(30); SET @barcode = '" + barcode + @"'; SELECT Setvalue_BC_Color_No FROM [PRODUCTION_DATA].[dbo].[Paintline_Proddata] WHERE LTrim(RTrim(Side_1_BC01)) = @barcode OR LTrim(RTrim(Side_1_BC02))= @barcode OR LTrim(RTrim(Side_1_BC03))= @barcode OR LTrim(RTrim(Side_1_BC04))= @barcode OR LTrim(RTrim(Side_1_BC05))= @barcode OR LTrim(RTrim(Side_1_BC06))= @barcode OR LTrim(RTrim(Side_1_BC07))= @barcode OR LTrim(RTrim(Side_1_BC08))= @barcode OR LTrim(RTrim(Side_1_BC09))= @barcode OR LTrim(RTrim(Side_1_BC10))= @barcode OR LTrim(RTrim(Side_1_BC11))= @barcode OR LTrim(RTrim(Side_1_BC12))= @barcode "; object ee = SqlHelper.ExecuteScalar(sqlConnString, CommandType.Text, sql_foreign4, null); string colorNo4 = ""; if (ee != null) { colorNo4 = ee.ToString(); if (!string.IsNullOrWhiteSpace(colorNo4)) { res = "A侧"; } } } } } } } return res; } catch (Exception ex) { LogHelper.WriteLogManager(ex); LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name); return res; } } /// /// 根据条码在老外库里查询颜色信息 /// /// /// public static string GetProductInfo(string barcode) { string res = ""; try { string sql = @" DECLARE @barcode varchar(30); SET @barcode = '" + barcode + @"'; SELECT Setvalue_BC_Color_No FROM [PRODUCTION_DATA].[dbo].[Paintline_Proddata] WHERE LTrim(RTrim(Side_1_BC01)) = @barcode OR LTrim(RTrim(Side_1_BC02))= @barcode OR LTrim(RTrim(Side_1_BC03))= @barcode OR LTrim(RTrim(Side_1_BC04))= @barcode OR LTrim(RTrim(Side_1_BC05))= @barcode OR LTrim(RTrim(Side_1_BC06))= @barcode OR LTrim(RTrim(Side_1_BC07))= @barcode OR LTrim(RTrim(Side_1_BC08))= @barcode OR LTrim(RTrim(Side_1_BC09))= @barcode OR LTrim(RTrim(Side_1_BC10))= @barcode OR LTrim(RTrim(Side_1_BC11))= @barcode OR LTrim(RTrim(Side_1_BC12))= @barcode OR LTrim(RTrim(Side_2_BC01)) = @barcode OR LTrim(RTrim(Side_2_BC02))= @barcode OR LTrim(RTrim(Side_2_BC03))= @barcode OR LTrim(RTrim(Side_2_BC04))= @barcode OR LTrim(RTrim(Side_2_BC05))= @barcode OR LTrim(RTrim(Side_2_BC06))= @barcode OR LTrim(RTrim(Side_2_BC07))= @barcode OR LTrim(RTrim(Side_2_BC08))= @barcode OR LTrim(RTrim(Side_2_BC09))= @barcode OR LTrim(RTrim(Side_2_BC10))= @barcode OR LTrim(RTrim(Side_2_BC11))= @barcode OR LTrim(RTrim(Side_2_BC12))= @barcode "; string sqlConnString = ConfigurationManager.ConnectionStrings["SqlConnStringForeign"].ToString(); object aa = SqlHelper.ExecuteScalar(sqlConnString, CommandType.Text, sql, null); string colorNo = ""; if (aa != null) { colorNo = aa.ToString(); } //根据颜色代码查颜色 string colorInfo = ""; if (!string.IsNullOrWhiteSpace(colorNo)) { DataTable dt = new DataTable(); string sql_c = @" select * from tb_Color where ColorCode = '" + colorNo + "' "; dt = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql_c, null); if (dt != null && dt.Rows.Count > 0) { res = dt.Rows[0]["Des"].ToString(); colorInfo = dt.Rows[0]["Des"].ToString().Trim() + "," + dt.Rows[0]["ColorCode"].ToString().Trim() + "," + dt.Rows[0]["ColorNo"].ToString().Trim(); } } //根据条码查询产品信息 string stockNo = ""; string batchNo = ""; string partNo = ""; Function.GetCode(barcode, out stockNo, out batchNo, out partNo); string productName = ""; Function.GetInfoByStockNo(stockNo, partNo, out productName); colorInfo = colorInfo + "," + productName; res = colorInfo; return res; } catch (Exception ex) { LogHelper.WriteLogManager(ex); LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name); return res; } } /// /// 根据存货代码获得零件名称、颜色名称 /// /// /// /// public static void GetInfoByStockNo(string stockNo, string partNo, out string partName) { partName = ""; string sql = ""; try { DataTable dt = new DataTable(); if (!string.IsNullOrWhiteSpace(stockNo)) { sql = " select ProductName from tb_Product where StockNo = '" + stockNo + @"' "; dt = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql, null); } else if (!string.IsNullOrWhiteSpace(partNo)) { sql = @" select ProductName from tb_Product where PartNo = '" + partNo + @"' "; dt = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql, null); } if (dt != null && dt.Rows.Count > 0) { partName = dt.Rows[0]["ProductName"].ToString(); } else { partName = ""; } LogHelper.WriteSysLogBase("[入参]:stockNo=" + stockNo + ",partNo=" + partNo + "; [出参:]partName=" + partName + ";[sql:] + sql", MethodBase.GetCurrentMethod().Name); } catch (Exception ex) { LogHelper.WriteLogManager(ex); LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name); } } /// /// 保存检验结果 /// /// /// public static int InsertInspect(InspectModel model) { int res = 0; try { string sql = @" INSERT INTO [dbo].[tb_InspectResult] ([ID] ,[barcode] ,[side] ,[position] ,[stationNo] ,[workClass] ,[inspectResult] ,[damnPosition] ,[defectID] ,[reason] ,[productInfo] ,[productOption] ,[createTime] ,[InspectTimes] ,[remark1] ,[remark2] ,[remark3] ) VALUES ('" + model.ID + @"' ,'" + model.barcode + @"' ,'" + model.side + @"' ,'" + model.position + @"' ,'" + model.stationNo + @"' ,'" + model.workClass + @"' ,'" + model.inspectResult + @"' ,'" + model.damnPosition + @"' ,'" + model.defectID + @"' ,'" + model.reason + @"' ,'" + model.productInfo + @"' ,'" + model.productOption + @"' ,(select getdate()) , '" + model.InspectTimes + @"' , '" + model.remark1 + @"' , '" + model.remark2 + @"' , '" + model.remark3 + @"' ) "; res = SqlHelper.ExecuteNonQuery(SqlHelper.SqlConnString, CommandType.Text, sql, null); LogHelper.WriteSysLogBase("[sql:]" + sql, MethodBase.GetCurrentMethod().Name); return res; } catch (Exception ex) { LogHelper.WriteLogManager(ex); LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name); return res; } } #endregion #region 247防错 public static DataTable IsMatchDeviceAndPart(string DeviceNo, string PartNo, out string errorReason) { DataTable res = new DataTable(); try { string sql = @"SELECT * from tb_Mistake_247 where [DeviceNo]='" + DeviceNo + "' and PartNo = '" + PartNo + @"' "; res = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql, null); errorReason = ""; return res; } catch (Exception ex) { LogHelper.WriteLogManager(ex); errorReason = ex.Message; return res; } } //public static int InsertInspect(InspectModel model) #endregion #region 一码到底 public static bool WMSInterfaceStockIn(string barcode, string partNo, string batchNo, int isPass) { bool res = false; try { List list = new List(); WMS03Model wmsM = new WMS03Model(); wmsM.BarCode = barcode; wmsM.WmsBarCode = ""; wmsM.LU_Code = partNo; 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 = ""; string lineid = ConfigurationManager.AppSettings["LineID"].ToString().Trim(); int lineId = 0; Int32.TryParse(lineid, out lineId); wmsM.LineId = lineId; list.Add(wmsM); #region 调用WMS接口前记录数据 string sql_bf = @" INSERT INTO [tb_StockIn_beif] ([ID] ,[barcode] ,[pass] ,[createTime]) VALUES ((select newid()) ,'" + barcode + @"' ,'" + isPass.ToString() + @"' ,(select getdate())) "; SqlHelper.ExecuteNonQuery(SqlHelper.SqlConnString, CommandType.Text, sql_bf, null); #endregion #region 调用WMS Web Service 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 = "[55," + JSONTools.ScriptSerialize>(list) + "]"; IsoDateTimeConverter timeConverter = new IsoDateTimeConverter(); //这里使用自定义日期格式,如果不使用的话,默认是ISO8601格式  timeConverter.DateTimeFormat = "yyyy'-'MM'-'dd' 'HH':'mm':'ss"; //timeConverter.DateTimeFormat = "yyyy'-'MM'-'dd"; string strJson = "[55," + JsonConvert.SerializeObject(list, Formatting.Indented, timeConverter) + "]"; #endregion #region 调用,返回结果 LogHelper.WriteSysLogBase("条码:" + barcode + "调用WMS入库接口,参数:strJson = " + strJson + "调入时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), MethodBase.GetCurrentMethod().Name); string resStr = webService.AddData(jsonParam, strJson); LogHelper.WriteSysLogBase("条码:" + barcode + "调用WMS入库接口,参数:strJson = " + strJson + "返回结果:" + resStr + "返回结果时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), MethodBase.GetCurrentMethod().Name); //LogHelper.WriteSysLogBase("条码:" + barcode + "调用WMS入库接口,参数:strJson = " + strJson + "返回结果:" + resStr, MethodBase.GetCurrentMethod().Name); if (resStr.ToLower() == "true") { res = true; } return res; #endregion } catch (Exception ex) { LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name); return res; } } #endregion /// /// 计算时间差 /// /// 时间1 /// 时间2 /// 返回值:时间差(毫秒为单位) private static long TimeDiff(DateTime t, DateTime t2) { long lReturn = -1; TimeSpan NowValue = new TimeSpan(t.Ticks); TimeSpan TimeValue = new TimeSpan(t2.Ticks); TimeSpan DateDiff = TimeSpan.Zero; try { //计算时间差 //DateDiff = TimeValue.Subtract(NowValue).Duration(); DateDiff = TimeValue.Subtract(NowValue); int hours = DateDiff.Hours; int minutes = DateDiff.Minutes; int seconds = DateDiff.Seconds; int milliseconds = DateDiff.Milliseconds; string TimeDiff = hours.ToString() + ":" + minutes.ToString() + ":" + seconds.ToString() + "." + milliseconds.ToString(); //是否比现在的时间小,如果小就设置成第二天再启动,否则当天启动 if (hours <= 0 && minutes <= 0 && seconds <= 0 && milliseconds <= 0) hours += 24; lReturn = hours * 3600 + minutes * 60 + seconds; } catch (Exception ex) { LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name); } return lReturn; } /// /// 判断是否未奔驰件 /// /// /// true是奔驰件,false非奔驰件 private static bool IsBens(string stockNo) { bool res=false; try { string sql = @"select ID from tb_StockToPaintNo where stockNo='"+ stockNo +@"'"; DataTable dt = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql, null); if (dt != null && dt.Rows.Count > 0) { res = false; } else { res = true; } } catch (Exception ex) { LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name); return res; } return res; } public static DataTable GetInspectResult(string sjBarCode) { string sql_ins = " select top 1 * from tb_InspectResult where barcode = '" + sjBarCode.Trim() + @"' and productInfo <> '' order by createTime desc "; DataTable proInfo = SqlHelper.GetDataSet(SqlHelper.SqlConnString, CommandType.Text, sql_ins, null).Tables[0]; return proInfo; } } }