using DBUtility; using PaintingPC.Model; using System; using System.Collections.Generic; using System.Configuration; using System.Data; using System.Data.SqlClient; using System.Diagnostics; using System.Drawing; using System.IO; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace PaintingPC { public class Function : Interface1 { /// /// 解析条码(一维码返回存货代码,二维码返回零件号) /// /// 条码 /// 存货代码 /// 批次 /// /// 零件号 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 >= 2) { partNo = props[0]; batchNo = props[1]; } } } LogHelper.WriteSysLogBase("[入参]:code=" + code + "; [出参:]stockNo=" + stockNo + ",batchNo=" + batchNo + ",partNo=" + partNo, MethodBase.GetCurrentMethod().Name); } catch (Exception ex) { LogHelper.WriteLogManager(ex); LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name); } } /// /// 根据存货代码获得零件名称、颜色名称 /// /// /// /// public static void GetInfoByStockNo(string stockNo, out string partNo, out string partName) { partNo = ""; 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); } if (dt != null && dt.Rows.Count > 0) { partName = dt.Rows[0]["ProductName"].ToString(); partNo = dt.Rows[0]["PartNo"].ToString(); } else { partName = ""; partNo = ""; } LogHelper.WriteSysLogBase("[入参]:stockNo=" + stockNo + "; [出参:]partName=" + partName + "partName="+partNo+";[sql:] + sql", MethodBase.GetCurrentMethod().Name); } catch (Exception ex) { LogHelper.WriteLogManager(ex); LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name); } } /// /// 根据条码获取图片地址 /// /// /// public static DataTable SearchInfoByBarCode(string barcode) { DataTable res = new DataTable(); try { string stockNo = ""; string batchNo = ""; string partNo = ""; GetCode(barcode, out stockNo, out batchNo, out partNo); string sql = ""; if (!string.IsNullOrWhiteSpace(stockNo)) { sql = " select * from tb_Product where StockNo = '" + stockNo.Trim() + @"'"; res = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql, null); } else if (!string.IsNullOrWhiteSpace(partNo)) { sql = " select * from tb_Product where PartNo = '" + partNo.Trim() + @"'"; res = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql, null); } LogHelper.WriteSysLogBase("[入参:]barcode=" + barcode+"[sql:]"+ sql, MethodBase.GetCurrentMethod().Name); return res; } catch (Exception ex) { LogHelper.WriteLogManager(ex); LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name); return res; } } public static DataTable SearchDefectInfo(string stationNo) { DataTable res = new DataTable(); try { string sql = @" select * from tb_Defect where LineID = (select LineID from tb_Station where StationNo = '"+ stationNo +@"') "; res = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql, null); LogHelper.WriteSysLogBase("[入参:]stationNo=" + stationNo + "[sql:]" + sql, MethodBase.GetCurrentMethod().Name); return res; } catch (Exception ex) { LogHelper.WriteLogManager(ex); LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name); return res; } } /// /// 从远程服务器下载文件到本地 /// /// 远程服务器文件夹路径 /// 要保存到本地的文件夹路径 /// 远程服务器src路径下的文件名 public static void TransportRemoteToLocal(string src, string dst, string fileName) //src:远程服务器文件夹路径 dst:要保存到本地的文件路径 fileName:远程服务器src路径下的文件名 { try { FileStream inFileStream = new FileStream(src, FileMode.Open); //远程服务器文件 此处假定远程服务器共享文件夹下确实包含本文件,否则程序报错 if (!Directory.Exists(dst)) { Directory.CreateDirectory(dst); } dst = dst + fileName; FileStream outFileStream = new FileStream(dst, FileMode.OpenOrCreate); //从远程服务器下载到本地的文件 byte[] buf = new byte[inFileStream.Length]; int byteCount; while ((byteCount = inFileStream.Read(buf, 0, buf.Length)) > 0) { outFileStream.Write(buf, 0, byteCount); } inFileStream.Flush(); inFileStream.Close(); outFileStream.Flush(); outFileStream.Close(); } 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] ( [barcode] ,[side] ,[position] ,[stationNo] ,[workClass] ,[inspectResult] ,[damnPosition] ,[defectID] ,[reason] ,[productInfo] ,[productOption] ,[createTime] ,[InspectTimes] ) VALUES ('" + 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 +@"' ) "; 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; } } public Panel IInitPanel(Panel BackgroundPanel, int LabelSizeW, int LabelSizeH, DataTable dataSouce, string LabelTextCol, string LabelTagCol, EventHandler LabelClick, string productName, string color) { return InitPanelLabel(BackgroundPanel, LabelSizeW, LabelSizeH, dataSouce, LabelTextCol, LabelTagCol, LabelClick, productName,color); } private static Panel InitPanelLabel(Panel BackgroundPanel, int LabelSizeW, int LabelSizeH, DataTable dataSouce, string LabelTextCol, string LabelTagCol, EventHandler LabelClick,string productName,string color) { BackgroundPanel.Controls.Clear(); if (dataSouce != null && dataSouce.Rows.Count > 0) { Label[] dLb = new Label[dataSouce.Rows.Count]; int row = 0, col = 1; row = BackgroundPanel.Size.Height / LabelSizeH; col = BackgroundPanel.Size.Width / LabelSizeW; List points = new List(); for (int i = 0; i < row; i++) { for (int j = 0; j < col; j++) { Point p = new Point(); p.X = 9 + j * LabelSizeW; p.Y = 9 + i * LabelSizeH; points.Add(p); } } for (int i = 0; i < dataSouce.Rows.Count; i++) { dLb[i] = new Label(); dLb[i].Text = dataSouce.Rows[i][LabelTextCol].ToString(); dLb[i].Tag = dataSouce.Rows[i][LabelTagCol].ToString(); dLb[i].Font = new Font("微软雅黑", 16); dLb[i].Size = new Size(LabelSizeW, LabelSizeH); dLb[i].Location = points[i]; dLb[i].BorderStyle = BorderStyle.FixedSingle; if (productName == "") { dLb[i].BackColor = Color.Blue; } else { if (dLb[i].Text.Contains(productName) && dLb[i].Text.Contains(color)) { dLb[i].BackColor = Color.Red; } else { dLb[i].BackColor = Color.Blue; } } dLb[i].TextAlign = ContentAlignment.MiddleCenter; BackgroundPanel.Controls.Add(dLb[i]); dLb[i].Click += LabelClick; } } return BackgroundPanel; } /// /// 根据条码获取检验信息 /// /// /// public static DataTable GetInspectInfoByBarCode(string barcode) { DataTable res = new DataTable(); try { string 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 "; res = SqlHelper.GetDataDateTable(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; } } /// /// 查询外国数据库获取颜色码 /// /// /// /// public static string GetForeignDataColor(string skidNo, out string colorInfo) { string res = ""; colorInfo = ""; try { string colorNo = ""; string colorQQNo = ""; string colorPRNo = ""; string sqlConnString = ConfigurationManager.ConnectionStrings["SqlConnStringForeign"].ToString(); string sql = " select top 1 Setvalue_BC_Color_No, Setvalue_CC_Color_No, Setvalue_PR_Color_No from Paintline_Proddata where LTrim(RTrim(Skid_No)) = '" + skidNo + @"' order by TimeStamp desc "; DataTable dtC = SqlHelper.GetDataDateTable(sqlConnString, CommandType.Text, sql, null); if (dtC != null && dtC.Rows.Count > 0) { colorNo = dtC.Rows[0]["Setvalue_BC_Color_No"].ToString(); colorQQNo = dtC.Rows[0]["Setvalue_CC_Color_No"].ToString(); colorPRNo = dtC.Rows[0]["Setvalue_PR_Color_No"].ToString(); } #region 注销-不要 //if (string.IsNullOrWhiteSpace(colorNo)) //{ // string sql_2 = " select top 1 Setvalue_BC_Color_No from Paintline_Loadingdata where LTrim(RTrim(Skid_No)) = '" + skidNo + @"' order by TimeStamp desc "; // object aa = SqlHelper.ExecuteScalar(sqlConnString, CommandType.Text, sql_2, null); // if (aa != null) // { // colorNo = aa.ToString(); // } //} #endregion if (!string.IsNullOrWhiteSpace(colorNo)) { DataTable dt = new DataTable(); if (colorNo.Trim() == "BC37" && colorQQNo.Trim() == "CC04") { #region 单独修改亚光山脉灰 string sql_c = @" select * from tb_Color where ColorCode = '" + colorNo + "' and ColorQQCode = '" + colorQQNo + "' "; 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(); } #endregion } else { string sql_c = ""; if (!string.IsNullOrWhiteSpace(colorQQNo) && !string.IsNullOrWhiteSpace(colorPRNo)) { sql_c = @" select * from tb_Color where ColorCode = '" + colorNo + "' and ColorQQCode = '" + colorQQNo + "' and ColorDQCode = '" + colorPRNo + "' "; } else { sql_c = @" select * from tb_Color where ColorCode = '" + colorNo + "'"; } //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(); } } } LogHelper.WriteSysLogBase("[入参:]skidNo=" + skidNo + ";[出参:]colorInfo=" + colorInfo, MethodBase.GetCurrentMethod().Name); return res; } catch (Exception ex) { LogHelper.WriteLogManager(ex); LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name); return res; } } /// /// 获取班次,规定早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"); //bool classA = IsBetweenTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), DateTime.Now.ToString("yyyy-MM-dd") + " 08:00:00", DateTime.Now.ToString("yyyy-MM-dd") + " 20:00:00"); bool classA = IsBetweenTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), DateTime.Now.ToString("yyyy-MM-dd") + " 07:45:00", DateTime.Now.ToString("yyyy-MM-dd") + " 19:45: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; } } public static DataTable GetAllColor() { DataTable res = new DataTable(); try { // string sql = @" SELECT [ID] // ,[ColorCode] // ,[ColorNo] // ,[Des] // FROM [tb_Color] // ORDER BY ColorCode "; string sql = @" select distinct Convert(varchar(50),[Des]) as [Des],ColorCode from tb_Color ORDER BY ColorCode "; 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; } } /// /// 根据滑撬号查询第side个条码号 /// /// /// /// public static string GetForeignBarCode(string skidNo, string side, int circle) { string res = ""; try { string sqlConnString = ConfigurationManager.ConnectionStrings["SqlConnStringForeign"].ToString(); if (!string.IsNullOrWhiteSpace(side)) { if (circle > 1) { #region 查国外下线数据库 #region 2019-10-30注销 // string sql = @" select top 1 " + side + @" // from Paintline_Proddata where LTrim(RTrim(Skid_No)) = '" + skidNo + @"' and " + side + " like '%00000%' order by TimeStamp desc "; // object bb = SqlHelper.ExecuteScalar(sqlConnString, CommandType.Text, sql, null); // if (bb != null) // { // res = bb.ToString(); // return res; // } // LogHelper.WriteSysLogBase("[sql:]" + sql, MethodBase.GetCurrentMethod().Name); #endregion string color = ""; string sql_color_xia = @" select top 1 Setvalue_BC_Color_No from Paintline_Proddata where LTrim(RTrim(Skid_No)) = '" + skidNo + @"' order by TimeStamp desc "; object aa = SqlHelper.ExecuteScalar(sqlConnString, CommandType.Text, sql_color_xia, null); if (aa != null) { color = aa.ToString(); } // string sql = @" select top 1 * from (select top 2 " + side + @" // from Paintline_Proddata where LTrim(RTrim(Skid_No)) = '" + skidNo + @"' and Setvalue_BC_Color_No = '" + color + @"' order by TimeStamp desc) aa order by TimeStamp asc "; string sql = @" select top 1 " + side + @" from (select top 2 " + side + @",TimeStamp from Paintline_Proddata where LTrim(RTrim(Skid_No)) = '" + skidNo + @"' order by TimeStamp desc) aa order by TimeStamp asc "; object bb = SqlHelper.ExecuteScalar(sqlConnString, CommandType.Text, sql, null); if (bb != null) { res = bb.ToString(); return res; } LogHelper.WriteSysLogBase("[sql:]" + sql, MethodBase.GetCurrentMethod().Name); #endregion #region 下线没查到条码,查国外上线数据库 //if (string.IsNullOrWhiteSpace(res)) //{ // string sql_2 = " select top 1 " + side + @" from Paintline_Loadingdata where LTrim(RTrim(Skid_No)) = '" + skidNo + @"' and " + side + " like '%00000%' order by TimeStamp desc "; // object aa = SqlHelper.ExecuteScalar(sqlConnString, CommandType.Text, sql_2, null); // if (aa != null) // { // res = aa.ToString(); // return res; // } // LogHelper.WriteSysLogBase("[sql:]" + sql_2, MethodBase.GetCurrentMethod().Name); //} #endregion } else { #region 查国外下线数据库 string sql = @" select top 1 " + side + @" from Paintline_Proddata where LTrim(RTrim(Skid_No)) = '" + skidNo + @"' order by TimeStamp desc "; object bb = SqlHelper.ExecuteScalar(sqlConnString, CommandType.Text, sql, null); if (bb != null) { res = bb.ToString(); return res; } LogHelper.WriteSysLogBase("[sql:]" + sql, MethodBase.GetCurrentMethod().Name); #endregion #region 上线没查到条码,查国外下线数据库 //if (string.IsNullOrWhiteSpace(res)) //{ // string sql_2 = " select top 1 " + side + @" from Paintline_Loadingdata where LTrim(RTrim(Skid_No)) = '" + skidNo + @"' order by TimeStamp desc "; // object aa = SqlHelper.ExecuteScalar(sqlConnString, CommandType.Text, sql_2, null); // if (aa != null) // { // res = aa.ToString(); // return res; // } // LogHelper.WriteSysLogBase("[sql:]" + sql_2, MethodBase.GetCurrentMethod().Name); //} #endregion } } return res; } catch (Exception ex) { LogHelper.WriteLogManager(ex); LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name); return res; } } /// /// 根据条码获取要取的层数及BC0几 /// /// /// public static string GetForeignBCString(string no, string title) { string res = ""; try { string stockNo = ""; string batchNo = ""; string partNo = ""; GetCode(no, out stockNo, out batchNo, out partNo); string layer = Function.GetProductLayer(stockNo, partNo); string floor = ""; string side = ""; if (!string.IsNullOrWhiteSpace(title)) { string[] strs = title.Split(' '); if (strs.Length >0) { for (int i = 0; i < strs.Length; i++) { if (strs[i].Contains("侧")) { side = strs[i].Replace("侧","").Trim(); } if (strs[i].Contains("支架")) { floor = strs[i].Replace("支架", "").Trim(); } } } string sql = @" select des from tb_LayerAndBC where layer = " + layer + " and floor = '" + floor + "' and side = '" + side + "' "; 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 GetProductLayer(string stockNo, string partNo) { string res = ""; try { if (!string.IsNullOrWhiteSpace(stockNo)) { string sql = @" select Layers,Side from tb_Product where StockNo = '" + stockNo.Trim() + "' "; object aa = SqlHelper.ExecuteScalar(SqlHelper.SqlConnString, CommandType.Text, sql, null); if (aa != null) { res = aa.ToString(); return res; } } if (!string.IsNullOrWhiteSpace(partNo)) { string sql = @" select Layers,Side from tb_Product where PartNo = '" + partNo.Trim() + "' "; object aa = SqlHelper.ExecuteScalar(SqlHelper.SqlConnString, CommandType.Text, sql, null); if (aa != null) { res = aa.ToString(); return res; } } return res; } catch (Exception ex) { LogHelper.WriteLogManager(ex); LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name); return res; } } /// /// 手动换班 /// /// public static void ChangeWorkClass(Label label) { if (label.Text.Trim() == "A班") { label.Text = "B班"; } else { label.Text = "A班"; } } /// /// 根据条码在老外库里查询颜色信息 /// /// /// public static string GetProductInfo(string barcode) { string res = ""; //string colorNo = ""; //string colorQQNo = ""; //string colorPRNo = ""; string colorInfo = "", paintCode = "", paintID = ""; string barCode1_1 = "", barCode1_2 = "", barCode1_3 = "", barCode1_4 = "", barCode1_5 = "", barCode1_6 = "", barCode2_1 = "", barCode2_2 = "", barCode2_3 = "", barCode2_4 = "", barCode2_5 = "", barCode2_6 = ""; string columnName = "",side=""; try { DataTable dt1 = GetLastResult(barcode); if (dt1 != null && dt1.Rows.Count > 0) { colorInfo = dt1.Rows[0]["productInfo"].ToString()+ "," + dt1.Rows[0]["remark3"].ToString(); } else { #region 从老外系统获得颜色信息 string sql = @" DECLARE @barcode varchar(30); SET @barcode = '"+barcode+ @"'; SELECT paintcode, LTrim(RTrim(Side1_Data1)) as Side1_Data1, LTrim(RTrim(Side1_Data2)) as Side1_Data2, LTrim(RTrim(Side1_Data3)) as Side1_Data3, LTrim(RTrim(Side1_Data4)) as Side1_Data4, LTrim(RTrim(Side1_Data5)) as Side1_Data5, LTrim(RTrim(Side1_Data6)) as Side1_Data6, LTrim(RTrim(Side2_Data1)) as Side2_Data1, LTrim(RTrim(Side2_Data2)) as Side2_Data2, LTrim(RTrim(Side2_Data3)) as Side2_Data3, LTrim(RTrim(Side2_Data4)) as Side2_Data4, LTrim(RTrim(Side2_Data5)) as Side2_Data5, LTrim(RTrim(Side2_Data6)) as Side2_Data6 FROM [dbo].[Skiddata_Unloading] WHERE LTrim(RTrim(Side1_Data1)) = @barcode OR LTrim(RTrim(Side1_Data2))= @barcode OR LTrim(RTrim(Side1_Data3))= @barcode OR LTrim(RTrim(Side1_Data4))= @barcode OR LTrim(RTrim(Side1_Data5))= @barcode OR LTrim(RTrim(Side1_Data6))= @barcode OR LTrim(RTrim(Side2_Data1)) = @barcode OR LTrim(RTrim(Side2_Data2))= @barcode OR LTrim(RTrim(Side2_Data3))= @barcode OR LTrim(RTrim(Side2_Data4))= @barcode OR LTrim(RTrim(Side2_Data5))= @barcode OR LTrim(RTrim(Side2_Data6))= @barcode "; string sqlConnString = ConfigurationManager.ConnectionStrings["SqlConnStringForeign"].ToString(); //object aa = SqlHelper.ExecuteScalar(sqlConnString, CommandType.Text, sql, null); DataTable dtColor = SqlHelper.GetDataDateTable(sqlConnString, CommandType.Text, sql, null); if (dtColor != null && dtColor.Rows.Count > 0) { paintCode = dtColor.Rows[0]["paintcode"].ToString(); } //根据颜色代码查颜色 if (!string.IsNullOrWhiteSpace(paintCode) && paintCode.ToLower() != "na") { DataTable dt = new DataTable(); string sql_c = ""; sql_c = @"select * from tb_PaintInfo where PaintCode='" + paintCode + @"'"; dt = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql_c, null); if (dt != null && dt.Rows.Count > 0) { //res = dt.Rows[0]["ColorName"].ToString(); //colorInfo = dt.Rows[0]["Des"].ToString().Trim() + "," + // dt.Rows[0]["ColorCode"].ToString().Trim() + "," + // dt.Rows[0]["ColorNo"].ToString().Trim(); //colorInfo = dt.Rows[0]["ColorName"].ToString(); paintID = dt.Rows[0]["ID"].ToString(); } string sql_1 = @"select Color from tb_PaintColorInfo where StockNo='" + barcode.Substring(0, 10) + @"' and PaintID='" + paintID + @"'"; DataTable dt_1 = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql_1, null); if (dt_1 != null && dt_1.Rows.Count > 0) { colorInfo = dt_1.Rows[0]["Color"].ToString(); } } #endregion barcode = UniteBarCodeToOne(barcode); #region 根据条码查询产品信息 string stockNo = ""; string batchNo = ""; string partNo = ""; Function.GetCode(barcode, out stockNo, out batchNo, out partNo); string productName = ""; GetInfoByStockNo(stockNo, out partNo, out productName); #endregion colorInfo = colorInfo + "," + productName + "," + paintID; } res = colorInfo; return res; } catch (Exception ex) { LogHelper.WriteLogManager(ex); LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name); return res; } } /// /// 查询补打条码信息 /// /// /// public static string GetReprintInfo(string barcode) { string res = ""; try { if (!string.IsNullOrWhiteSpace(barcode)) { string sql = @" SELECT ProductID, StockNo, ColorDes,(SELECT ProductName FROM tb_Product WHERE ProductID =(SELECT top 1 ProductID FROM tb_PaintBarCode WHERE OneBarCode = '" + barcode + "')) ProductName FROM tb_PaintBarCode WHERE OneBarCode = '" + barcode + "' "; DataTable aa = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql, null); if (aa != null && aa.Rows.Count > 0) { res = aa.Rows[0]["ColorDes"].ToString() + "," + aa.Rows[0]["ProductName"].ToString(); } } return res; } catch (Exception ex) { LogHelper.WriteLogManager(ex); LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name); return res; } } /// /// 根据滑撬号获取圈数 /// /// /// public static int GetCircle(string skidNo) { int res = 0; try { string sqlConnString = ConfigurationManager.ConnectionStrings["SqlConnStringForeign"].ToString(); string sql_color_xia = @" select top 1 Setvalue_BC_Color_No from Paintline_Proddata where LTrim(RTrim(Skid_No)) = '" + skidNo + @"' order by TimeStamp desc "; object bb = SqlHelper.ExecuteScalar(sqlConnString, CommandType.Text, sql_color_xia, null); if (bb != null) { string color = bb.ToString(); res = GetCircleByColor(color); } else { //string sql_color = @" select top 1 Setvalue_BC_Color_No from Paintline_Loadingdata where LTrim(RTrim(Skid_No)) = '" + skidNo + @"' order by TimeStamp desc "; //object aa = SqlHelper.ExecuteScalar(sqlConnString, CommandType.Text, sql_color, null); //if (aa != null) //{ // string color = aa.ToString(); // res = GetCircleByColor(color); //} } return res; } catch (Exception ex) { LogHelper.WriteLogManager(ex); LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name); return res; } } /// /// 根据颜色号获取圈数 /// /// /// public static int GetCircleByColor(string colorCode) { int res = 0; try { string sql = @" select isnull(Circle,0) from tb_Color where ColorCode = '" + colorCode + "' "; object aa = SqlHelper.ExecuteScalar(SqlHelper.SqlConnString, CommandType.Text, sql, null); if (aa != null) { Int32.TryParse(aa.ToString(), out res); } return res; } catch (Exception ex) { LogHelper.WriteLogManager(ex); LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name); return res; } } /// /// 根据条码号获取AB侧+支架位置 /// /// /// public static string GetSide(string barCode,string paintId) { string res = "",stockNo="",productId=""; int layers = 0; string columnName = "",side="",floor=""; try { //有一检结果的 string sql = @" select top 1 side from tb_InspectResult where barcode = '" + barCode + "' 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)) { //没有一检结果,查询产品是几层、几侧的产品 #region 判断是一维码还是二维码 if (barCode.Contains(".") == false) { //一维码 if (barCode.Length > 10) { stockNo = barCode.Substring(0, 10); } } else { //二维码 //string[] strs = barCode.Split('.'); //if (strs.Length > 0) //{ // partNo = strs[0]; //} } #endregion string sql1 = ""; if (!string.IsNullOrWhiteSpace(stockNo)) { //sql1 = @"select Layers,ProductID from tb_Product where StockNo='" + stockNo + @"'"; sql1 = @"SELECT ProductID FROM dbo.tb_Product WITH (NOLOCK) WHERE PartNo IN(select Paint_No from tb_PaintColorInfo WITH (NOLOCK) where StockNo='" + stockNo + @"' and PaintID='"+ paintId +@"')"; DataTable dt = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql1, null); if (dt != null && dt.Rows.Count>0) { productId = dt.Rows[0]["ProductID"].ToString(); } } #region 取消从存储过程中获取列 //string sqlConnString = ConfigurationManager.ConnectionStrings["SqlConnStringForeign"].ToString(); ////DataTable dtColor = SqlHelper.GetDataDateTable(sqlConnString, CommandType.StoredProcedure, "P_SYSTEM_FindData", param); //SqlParameter[] param = new SqlParameter[1]; //param[0] = new SqlParameter("@value", SqlDbType.VarChar); //param[0].Value = barcode; //DataTable dtC = SqlHelper.GetDataDateTable(sqlConnString, CommandType.StoredProcedure, "P_SYSTEM_FindData", param); //if (dtC != null && dtC.Rows.Count > 0) //{ // columnName = dtC.Rows[0]["columnname"].ToString(); //} #endregion #region 从老外系统获得列名 string sqlConnString = ConfigurationManager.ConnectionStrings["SqlConnStringForeign"].ToString(); string strSql1 = @"select top 1 TimeStamp FROM [BMPT_BJ1_Paintlinedata].[dbo].[Skiddata_Unloading] WHERE LTrim(RTrim(Side1_Data1)) = '" + barCode + @"' order by TimeStamp desc"; DataTable dt1 = SqlHelper.GetDataDateTable(sqlConnString, CommandType.Text, strSql1, null); if (dt1 != null && dt1.Rows.Count > 0) { columnName = "Side1_Data1"; } else { string strSql2 = @"select top 1 TimeStamp FROM [BMPT_BJ1_Paintlinedata].[dbo].[Skiddata_Unloading] WHERE LTrim(RTrim(Side1_Data2)) = '" + barCode + @"' order by TimeStamp desc"; DataTable dt2 = SqlHelper.GetDataDateTable(sqlConnString, CommandType.Text, strSql2, null); if (dt2 != null && dt2.Rows.Count > 0) { columnName = "Side1_Data2"; } else { string strSql3 = @"select top 1 TimeStamp FROM [BMPT_BJ1_Paintlinedata].[dbo].[Skiddata_Unloading] WHERE LTrim(RTrim(Side1_Data3)) = '" + barCode + @"' order by TimeStamp desc"; DataTable dt3 = SqlHelper.GetDataDateTable(sqlConnString, CommandType.Text, strSql3, null); if (dt3 != null && dt3.Rows.Count > 0) { columnName = "Side1_Data3"; } else { string strSql4 = @"select top 1 TimeStamp FROM [BMPT_BJ1_Paintlinedata].[dbo].[Skiddata_Unloading] WHERE LTrim(RTrim(Side1_Data4)) = '" + barCode + @"' order by TimeStamp desc"; DataTable dt4 = SqlHelper.GetDataDateTable(sqlConnString, CommandType.Text, strSql4, null); if (dt4 != null && dt4.Rows.Count > 0) { columnName = "Side1_Data4"; } else { string strSql5 = @"select top 1 TimeStamp FROM [BMPT_BJ1_Paintlinedata].[dbo].[Skiddata_Unloading] WHERE LTrim(RTrim(Side1_Data5)) = '" + barCode + @"' order by TimeStamp desc"; DataTable dt5 = SqlHelper.GetDataDateTable(sqlConnString, CommandType.Text, strSql5, null); if (dt5 != null && dt5.Rows.Count > 0) { columnName = "Side1_Data5"; } else { string strSql6 = @"select top 1 TimeStamp FROM [BMPT_BJ1_Paintlinedata].[dbo].[Skiddata_Unloading] WHERE LTrim(RTrim(Side1_Data6)) = '" + barCode + @"' order by TimeStamp desc"; DataTable dt6 = SqlHelper.GetDataDateTable(sqlConnString, CommandType.Text, strSql6, null); if (dt6 != null && dt6.Rows.Count > 0) { columnName = "Side1_Data6"; } else { string strSql7 = @"select top 1 TimeStamp FROM [BMPT_BJ1_Paintlinedata].[dbo].[Skiddata_Unloading] WHERE LTrim(RTrim(Side2_Data1)) = '" + barCode + @"' order by TimeStamp desc"; DataTable dt7 = SqlHelper.GetDataDateTable(sqlConnString, CommandType.Text, strSql7, null); if (dt7 != null && dt7.Rows.Count > 0) { columnName = "Side2_Data1"; } else { string strSql8 = @"select top 1 TimeStamp FROM [BMPT_BJ1_Paintlinedata].[dbo].[Skiddata_Unloading] WHERE LTrim(RTrim(Side2_Data2)) = '" + barCode + @"' order by TimeStamp desc"; DataTable dt8 = SqlHelper.GetDataDateTable(sqlConnString, CommandType.Text, strSql8, null); if (dt8 != null && dt8.Rows.Count > 0) { columnName = "Side2_Data2"; } else { string strSql9 = @"select top 1 TimeStamp FROM [BMPT_BJ1_Paintlinedata].[dbo].[Skiddata_Unloading] WHERE LTrim(RTrim(Side2_Data3)) = '" + barCode + @"' order by TimeStamp desc"; DataTable dt9 = SqlHelper.GetDataDateTable(sqlConnString, CommandType.Text, strSql9, null); if (dt9 != null && dt9.Rows.Count > 0) { columnName = "Side2_Data3"; } else { string strSql10 = @"select top 1 TimeStamp FROM [BMPT_BJ1_Paintlinedata].[dbo].[Skiddata_Unloading] WHERE LTrim(RTrim(Side2_Data4)) = '" + barCode + @"' order by TimeStamp desc"; DataTable dt10 = SqlHelper.GetDataDateTable(sqlConnString, CommandType.Text, strSql10, null); if (dt10 != null && dt10.Rows.Count > 0) { columnName = "Side2_Data4"; } else { string strSql11 = @"select top 1 TimeStamp FROM [BMPT_BJ1_Paintlinedata].[dbo].[Skiddata_Unloading] WHERE LTrim(RTrim(Side2_Data5)) = '" + barCode + @"' order by TimeStamp desc"; DataTable dt11 = SqlHelper.GetDataDateTable(sqlConnString, CommandType.Text, strSql11, null); if (dt11 != null && dt11.Rows.Count > 0) { columnName = "Side2_Data5"; } else { string strSql12 = @"select top 1 TimeStamp FROM [BMPT_BJ1_Paintlinedata].[dbo].[Skiddata_Unloading] WHERE LTrim(RTrim(Side2_Data6)) = '" + barCode + @"' order by TimeStamp desc"; DataTable dt12 = SqlHelper.GetDataDateTable(sqlConnString, CommandType.Text, strSql12, null); if (dt12 != null && dt12.Rows.Count > 0) { columnName = "Side2_Data6"; } } } } } } } } } } } } #endregion #region 根据列名和层获取支架位置 string sql2 = @"select floor,side from tb_LayerAndBC where des like '%" + columnName + @"%' and ProductId='"+ productId +@"'"; DataTable dtZ = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql2, null); if (dtZ != null && dtZ.Rows.Count > 0) { floor = dtZ.Rows[0]["floor"]+"支架"; side = dtZ.Rows[0]["side"] + "侧"; } #endregion res = side + ";" + floor; } } return res; } catch (Exception ex) { LogHelper.WriteLogManager(ex); LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name); return res; } } /// /// 根据一检结果显示一检时的位置 /// /// /// public static string GetFirstInsPosition(DataTable dt) { string res = ""; try { if (dt != null && dt.Rows.Count > 0) { DataRow[] dr = dt.Select(" InspectTimes = '1' "); if (dr != null && dr.Length > 0) { string position = dr[0]["position"].ToString(); string sql = @" select value from tb_Config where name = 'RemoveStr' "; object objStr = SqlHelper.ExecuteScalar(SqlHelper.SqlConnString, CommandType.Text, sql, null); if (objStr != null) { res = position.Replace(objStr.ToString(), "").Trim(); } } } return res; } catch (Exception ex) { LogHelper.WriteLogManager(ex); LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name); return res; } } /// /// 判断条码有效性 /// /// /// public static bool BarCodeValid(string barcode) { bool res = false; if (!string.IsNullOrWhiteSpace(barcode)) { if (barcode.Contains(".")) { res = true; } else { if (barcode.Length == 20) { res = true; } } } return res; } /// /// 将二维码转换成相应一维码 /// /// /// public static string TransToBarCodeOne(string barcode) { string res = ""; try { string sql = @" SELECT TOP 1 OneBarCode FROM v_Code WHERE BarCode = '" + barcode + @"' "; object aa = SqlHelper.ExecuteScalar(SqlHelper.SqlConnString, CommandType.Text, sql, null); if (aa != null) { res = aa.ToString(); } else { string sql2 = @" select TOP 1 OneBarCode from [10.60.101.9].[BBMPT].[dbo].[View_BarCode] where BarCode = '" + barcode + @"' "; object bb = SqlHelper.ExecuteScalar(SqlHelper.SqlConnString, CommandType.Text, sql2, 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 string UniteBarCodeToOne(string barcode) { string res = barcode; if (!string.IsNullOrWhiteSpace(barcode)) { if (barcode.Contains(".")) { res = TransToBarCodeOne(barcode); } } return res; } public static DataTable GetMesBarCode(string title, string sideNo, out string bcStrs) { DataTable res = new DataTable(); bcStrs = ""; try { string sql = @" select top 1 Layer from tb_SkidInfo where SkidNo = '" + sideNo + "' order by CreateTime desc "; object aa = SqlHelper.ExecuteScalar(SqlHelper.SqlConnString, CommandType.Text, sql, null); if (aa != null) { string layer = aa.ToString(); //层数 string szx = ""; //上中下 if (title.Contains("上")) { szx = "上"; } else if (title.Contains("中")) { szx = "中"; } else if (title.Contains("下")) { szx = "下"; } string side = ""; if (title.Contains("A")) { side = "A"; } else if (title.Contains("B")) { side = "B"; } string sqlQuery = @" SELECT des FROM tb_LayerAndBC WHERE layer = '" + layer + "' AND [floor] = '" + szx + "' AND side = '" + side + "' "; object bb = SqlHelper.ExecuteScalar(SqlHelper.SqlConnString, CommandType.Text, sqlQuery, null); if(bb != null) { bcStrs = bb.ToString(); #region 拼接查询时的列条件 string[] bcStr = bcStrs.Split(';'); string sqlBcStr = ""; for (int i = 0; i < bcStr.Length; i++) { sqlBcStr += bcStr[i] + ","; } sqlBcStr = sqlBcStr.Remove(sqlBcStr.Length - 1); #endregion string sqlGetBarCode = @" select top 1 ColorInfo, " + sqlBcStr + " from tb_SkidInfo order by CreateTime desc "; res = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sqlGetBarCode, null); } } return res; } catch (Exception ex) { LogHelper.WriteLogManager(ex); LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name); return res; } } /// /// 该条码已打磨次数 /// /// /// public static int YiDaMoCiShu(string barcode) { int res = 0; try { string sql = @" select count(0) from tb_InspectResult where barcode = '" + barcode + @"' and inspectResult = '[打磨]' "; object aa = SqlHelper.ExecuteScalar(SqlHelper.SqlConnString, CommandType.Text, sql, null); if (aa != null) { res = Convert.ToInt32(aa.ToString()); } } catch (Exception ex) { LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name); } return res; } /// /// 可回喷次数 /// /// /// public static int keHuiPen(string barcode) { int res = 0; try { string stockNo = ""; string batchNo = ""; string partNo = ""; GetCode(barcode, out stockNo, out batchNo, out partNo); string sql = @" select BackPlatingNum from tb_Product where StockNo = '" + stockNo + @"' "; object aa = SqlHelper.ExecuteScalar(SqlHelper.SqlConnString, CommandType.Text, sql, null); if (aa != null) { res = Convert.ToInt32(aa.ToString()); } } catch (Exception ex) { LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name); } return res; } public static string carTypeName(string stockNo,string paintId) { string res = ""; try { string sql= @"SELECT c.CarTypeName FROM dbo.tb_Product p LEFT OUTER JOIN dbo.tb_CarType c ON p.CarTypeID=c.ID where p.PartNo in (select Paint_No from tb_PaintColorInfo where StockNo='"+ stockNo + @"'and PaintID='"+ paintId + @"')"; DataTable dt= SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql, null); if (dt!=null && dt.Rows.Count>0) { res = dt.Rows[0]["CarTypeName"].ToString(); } } catch (Exception ex) { LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name); } return res; } #region Temp //public static DataTable GetCarTypeAll() //{ // DataTable res = new DataTable(); // try // { // string sql = @" select * from tb_CarType order by CarTypeName "; // res = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql, null); // } // catch (Exception ex) // { // LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name); // } // return res; //} public static DataTable GetCarTypeAll() { DataTable res = new DataTable(); try { string sql = @" select distinct [Type] from tb_PaintColorInfo order by [Type] "; res = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql, null); } catch (Exception ex) { LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name); } return res; } // public static DataTable GetColorByCarType(string carTypeID) // { // DataTable res = new DataTable(); // try // { // string sql = @" select * // from tb_Color // where ID in ( // select ColorID from tb_CarTypeColor where CarTypeID = '" + carTypeID + @"' // ) "; // res = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql, null); // } // catch (Exception ex) // { // LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name); // } // return res; // } public static DataTable GetColorByType(string type) { DataTable res = new DataTable(); try { string sql = @" select Color from tb_PaintColorInfo where [Type] = '" + type + @"' order by [Color] "; res = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql, null); } catch (Exception ex) { LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name); } return res; } public static int SavePaintLoad(string barcode, string colorName) { int res = 0; try { string sql = @" insert into tb_PaintLoad(ID, barcode, ColorName) values((select newID()), '" + barcode + @"', '" + colorName + @"') "; res = SqlHelper.ExecuteNonQuery(SqlHelper.SqlConnString, CommandType.Text, sql, null); } catch (Exception ex) { LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name); } return res; } #endregion public static int SaveChainUp(string barcode, string carTypeID, string carType, string colorID, string color, string flag,string productName) { int res = 0; try { string sql = @" INSERT INTO tb_ChainUp ([barcode] ,[carTypeID] ,[carType] ,[colorID] ,[color] ,[flag] ,productName) VALUES ('" + barcode + @"' ,'" + carTypeID + @"' ,'" + carType + @"' ,'" + colorID + @"' ,'" + color + @"' ," + flag + @" ,'"+ productName + @"') "; res = SqlHelper.ExecuteNonQuery(SqlHelper.SqlConnString, CommandType.Text, sql, null); } catch (Exception ex) { LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name); } return res; } public static bool InspectPass(string barcode) { bool res = false; try { string sql = @" select top 1 inspectResult from tb_InspectResult where barcode = '"+ barcode +@"' order by createTime desc "; object aa = SqlHelper.ExecuteScalar(SqlHelper.SqlConnString, CommandType.Text, sql, null); if (aa != null) { string result = aa.ToString(); if (result == "[合格]") { res = true; } } } catch (Exception ex) { LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name); } return res; } public static string GetWorkClassTime() { string res = ""; try { //bool classA = IsBetweenTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "2019-06-12 07:45:00", "2019-06-12 19:45:00"); //if (classA) //{ // return ("createTime between '" + DateTime.Now.ToString("yyyy-MM-dd") + " 07:45:00' and '" + DateTime.Now.ToString("yyyy-MM-dd") + " 19:45:00'"); //} //else //{ // bool isYesterday = IsBetweenTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "2019-06-12 00:00:00", "2019-06-12 07:44:59"); // if (isYesterday) // { // return ("createTime between '" + DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd") + " 19:45:01' and '" + DateTime.Now.ToString("yyyy-MM-dd") + " 07:44:59' "); // } // bool isToday = IsBetweenTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "2019-06-12 19:45:01", "2019-06-12 23:59:59"); // if (isToday) // { // return ("createTime between '" + DateTime.Now.ToString("yyyy-MM-dd") + " 19:45:01' and '" + DateTime.Now.AddDays(1).ToString("yyyy-MM-dd") + " 07:44:59' "); // } //} bool classA = IsBetweenTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "2019-06-12 06:00:00", "2019-06-12 18:00:00"); if (classA) { return ("createTime between '" + DateTime.Now.ToString("yyyy-MM-dd") + " 06:00:00' and '" + DateTime.Now.ToString("yyyy-MM-dd") + " 18:00:00'"); } else { bool isYesterday = IsBetweenTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "2019-06-12 00:00:00", "2019-06-12 05:59:59"); if (isYesterday) { return ("createTime between '" + DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd") + " 18:00:00' and '" + DateTime.Now.ToString("yyyy-MM-dd") + " 05:59:59' "); } bool isToday = IsBetweenTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "2019-06-12 18:00:00", "2019-06-12 23:59:59"); if (isToday) { return ("createTime between '" + DateTime.Now.ToString("yyyy-MM-dd") + " 18:00:00' and '" + DateTime.Now.AddDays(1).ToString("yyyy-MM-dd") + " 05:59:59' "); } } } catch (Exception ex) { LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name); } return res; } public static string GetChainCountAll() { string res = "0"; try { string sql = @" select count(0) from tb_ChainUp where "; string condition = GetWorkClassTime(); object aa = SqlHelper.ExecuteScalar(SqlHelper.SqlConnString, CommandType.Text, sql + condition, null); if (aa != null) { res = aa.ToString(); } } catch (Exception ex) { LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name); } return res; } public static string GetChainCountDown() { string res = "0"; try { string sql = @" select top 1 createTime from [tb_ChainUp] where IsLast = 1 order by createTime desc "; object aa = SqlHelper.ExecuteScalar(SqlHelper.SqlConnString, CommandType.Text, sql, null); if (aa != null) { string stime = aa.ToString(); string sql_num = @" select count(0) from tb_ChainUp where createTime >= '" + stime + @"' and createTime <= getdate() and flag = 1 "; object bb = SqlHelper.ExecuteScalar(SqlHelper.SqlConnString, CommandType.Text, sql_num, null); if (bb != null) { res = bb.ToString(); } } else { //string stime = DateTime.Now.ToString("yyyy-MM-dd"); //string starttime_sql = " select top 1 value from tb_Config where name = 'PaintChainStartTime' "; //object cc = SqlHelper.ExecuteScalar(SqlHelper.SqlConnString, CommandType.Text, starttime_sql, null); //if (cc != null) //{ // stime += " " + cc.ToString(); //} //string sql_num = @" select count(0) from tb_ChainUp where createTime >= '" + stime + @"' and createTime <= getdate() and flag = 1 "; //object bb = SqlHelper.ExecuteScalar(SqlHelper.SqlConnString, CommandType.Text, sql_num, null); //if (bb != null) //{ // res = bb.ToString(); //} string sql1 = @" select count(0) from tb_ChainUp where "; string condition = GetWorkClassTime(); object cc = SqlHelper.ExecuteScalar(SqlHelper.SqlConnString, CommandType.Text, sql1 + condition + " and flag = 1 ", null); if (cc != null) { res = cc.ToString(); } } } catch (Exception ex) { LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name); } return res; } public static DataTable GetChainCountLabel() { DataTable res = new DataTable(); try { string timeWhere = GetWorkClassTime(); // string sql = @" // select count(0) num,carType,color,carType+char(13)+char(10)+color+char(13)+char(10)+Convert(varchar(10),count(0)) colDes // from tb_ChainUp // where " + timeWhere + @" //group by carType,color // "; string sql = @" select count(0) num,productName,color,productName+char(13)+char(10)+color+char(13)+char(10)+Convert(varchar(10),count(0)) colDes from tb_ChainUp where " + timeWhere + @" group by productName,color "; res = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql, null); } catch (Exception ex) { LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name); } return res; } /// /// 判断是否为北京现代的产品 /// /// /// public static bool IsHyundai(string barcode) { bool res = false; try { string stockNo = "", batchNo = "", partNo = ""; GetCode(barcode, out stockNo, out batchNo, out partNo); string sql = @" select ManufacturerName from tb_Manufacturer where [ID] = ( select ManufacturerID from tb_CarType where [ID] = ( select CarTypeID from tb_Product where StockNo = '" + stockNo + @"' ) ) "; object aa = SqlHelper.ExecuteScalar(SqlHelper.SqlConnString, CommandType.Text, sql, null); if (aa != null) { string cj = aa.ToString(); if (cj.Trim() == "现代") { res = true; } } } catch (Exception ex) { LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name); } return res; } public static void GetCareTypeColor(string barcode, out string CartypeID, out string CartypeName, out string ColorID, out string ColorName) { CartypeID = ""; CartypeName = ""; ColorID = ""; ColorName = ""; try { barcode = Function.UniteBarCodeToOne(barcode); string sql = " select top 1 productInfo from tb_InspectResult where barcode = '" + barcode + "' and productInfo is not null and productInfo <> ' ' order by createTime desc "; object aa = SqlHelper.ExecuteScalar(SqlHelper.SqlConnString, CommandType.Text, sql, null); if (aa != null) { string productinfo = aa.ToString(); string[] bb = productinfo.Split(','); if (bb.Length > 1) { ColorName = bb[0]; CartypeName = bb[1]; string sql_1 = " select top 1 ID from tb_Color where Des like '%colorName%' "; object cc = SqlHelper.ExecuteScalar(SqlHelper.SqlConnString, CommandType.Text, sql_1, null); if (cc != null) { ColorID = cc.ToString(); } string sql_2 = " select top 1 ID from tb_CarType where CarTypeName = '" + CartypeName + "' "; object dd = SqlHelper.ExecuteScalar(SqlHelper.SqlConnString, CommandType.Text, sql_2, null); if (dd != null) { CartypeID = dd.ToString(); } } } } catch (Exception ex) { LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name); } } public static void GetHyundyPrintInfo(string stockNo,string paintId,out string productName, out string customerNo, out string carModelCode, out string colorCodeB, out string templateName,out string fr,out string partNo) { productName = ""; customerNo = ""; carModelCode = ""; colorCodeB = ""; templateName = ""; fr = ""; partNo = ""; try { string sql = @"select StockNo,PartNo,ProductName,CustomerNo,CarModelCode,ColorCodeB ,TemplateName FROM tb_Product WITH (NOLOCK) WHERE PartNo=(select Paint_No FROM tb_PaintColorInfo WITH (NOLOCK) where StockNo='" + stockNo + @"' and PaintID='" + paintId + @"')"; DataTable dt = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql, null); if (dt != null && dt.Rows.Count > 0) { productName = dt.Rows[0]["ProductName"].ToString(); customerNo = dt.Rows[0]["CustomerNo"].ToString(); carModelCode = dt.Rows[0]["CarModelCode"].ToString(); colorCodeB = dt.Rows[0]["ColorCodeB"].ToString(); templateName = dt.Rows[0]["TemplateName"].ToString(); partNo = dt.Rows[0]["PartNo"].ToString(); if (dt.Rows[0]["ProductName"].ToString().Contains("前")) { fr = "F"; } else if (dt.Rows[0]["ProductName"].ToString().Contains("后")) { fr = "R"; } } } catch (Exception ex) { LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name); } } public static string GetImgPath() { string res = ""; try { string sql_imgPath = " select top 1 value from tb_Config where name = 'ImgPath' "; object aa = SqlHelper.ExecuteScalar(SqlHelper.SqlConnString, CommandType.Text, sql_imgPath, null); if (aa != null) { res = aa.ToString(); } } catch (Exception ex) { LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name); } return res; } public static string GetSequence() { string res = "1"; try { string sql = @" select count(0)+1 from tb_ChainUpBarcode where Convert(varchar(10),Createtime,120) = Convert(varchar(10),getdate(),120) "; object aa = SqlHelper.ExecuteScalar(SqlHelper.SqlConnString, CommandType.Text, sql, null); if (aa != null) { res = aa.ToString(); } } catch (Exception ex) { LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name); } return res; } public static void SaveSeq(string barcode,string barcode1, string barcode2, string seq) { try { string sql = @" insert into tb_ChainUpBarcode(Barcode, Barcode1, Barcode2,Seq) values('" + barcode + "','" + barcode1 + "', '" + barcode2 + "','" + seq + "') "; SqlHelper.ExecuteNonQuery(SqlHelper.SqlConnString, CommandType.Text, sql, null); } catch (Exception ex) { LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name); } } public static DataTable GetColorByStockNo(string stockNo) { DataTable res = new DataTable(); try { string pId = ""; // string sql = @" // select distinct Color // from tb_PaintColorInfo // where stockNo = '" + stockNo + @"' // "; string sql = @" select Color from tb_PaintColorInfo where stockNo = '" + stockNo + @"' "; return SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql, null); //if (dt != null && dt.Rows.Count > 0) //{ // for (int i = 0; i < dt.Rows.Count; i++) // { // pId = dt.Rows[i]["PaintID"].ToString(); // } //} //if (!string.IsNullOrWhiteSpace(pId)&&pId.Contains(',')) //{ // if (pId.Contains(',')) // { // string[] s_pid = pId.Split(','); // pId = s_pid[0]; // } //} //string cSql = @"select ColorName from tb_PaintInfo where ID='" + pId + @"'"; //res = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, cSql, null); } catch (Exception ex) { LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name); } return res; } public static bool ChainHaveScan(string barcode) { bool res = false; try { string sql = @" select * from tb_ChainUp where barcode = '"+ barcode +@"' and flag <> 2 "; DataTable dt = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql, null); if (dt != null && dt.Rows.Count > 0) { res = true; } } catch (Exception ex) { LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name); } return res; } public static int GetInspectTimes(string barcode) { try { int res = 0; string sql = @"select top 1 InspectTimes from tb_InspectResult where barcode='"+ barcode+ @"' order by ID desc "; DataTable dt = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql, null); if (dt != null && dt.Rows.Count>0) { res = Convert.ToInt32(dt.Rows[0]["InspectTimes"]); } return res; } catch (Exception ex) { LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name); return 0; } } public static DataTable GetLastResult(string barcode) { DataTable res = new DataTable(); try { string sql = @"select top 1 * from tb_InspectResult where barcode='" + barcode + @"' order by ID desc "; res= SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql, null); } catch (Exception ex) { LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name); } return res; } } }