一厂MES,含注塑,喷涂,冲孔
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

1675 lines
76 KiB

using DBUtility;
using PaintingPC.Model;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
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
{
/// <summary>
/// 解析条码(一维码返回存货代码,二维码返回零件号)
/// </summary>
/// <param name="code">条码</param>
/// <param name="stockNo">存货代码</param>
/// <param name="batchNo">批次</param>
/// /// <param name="partNo">零件号</param>
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);
}
}
/// <summary>
/// 根据存货代码获得零件名称、颜色名称
/// </summary>
/// <param name="stockNo"></param>
/// <param name="partName"></param>
/// <param name="colorName"></param>
public static void GetInfoByStockNo(string stockNo, string partNo, out string partName)
{
partName = "";
string sql = "";
try
{
DataTable dt = new DataTable();
if (!string.IsNullOrWhiteSpace(stockNo) || !string.IsNullOrWhiteSpace(partNo))
{
sql = " select ProductName from tb_Product where StockNo = '" + stockNo + @"' or 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);
}
}
/// <summary>
/// 根据条码获取图片地址
/// </summary>
/// <param name="barcode"></param>
/// <returns></returns>
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;
}
}
/// <summary>
/// 从远程服务器下载文件到本地
/// </summary>
/// <param name="src">远程服务器文件夹路径</param>
/// <param name="dst">要保存到本地的文件夹路径</param>
/// <param name="fileName">远程服务器src路径下的文件名</param>
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);
}
}
/// <summary>
/// 保存检验结果
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
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]
)
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 +@"'
) ";
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)
{
return InitPanelLabel(BackgroundPanel, LabelSizeW, LabelSizeH, dataSouce, LabelTextCol, LabelTagCol, LabelClick);
}
private static Panel InitPanelLabel(Panel BackgroundPanel, int LabelSizeW, int LabelSizeH, DataTable dataSouce, string LabelTextCol, string LabelTagCol, EventHandler LabelClick)
{
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<Point> points = new List<Point>();
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("微软雅黑", 24, FontStyle.Bold);
dLb[i].Size = new Size(LabelSizeW, LabelSizeH);
dLb[i].Location = points[i];
dLb[i].BorderStyle = BorderStyle.FixedSingle;
dLb[i].BackColor = Color.Blue;
dLb[i].TextAlign = ContentAlignment.MiddleCenter;
BackgroundPanel.Controls.Add(dLb[i]);
dLb[i].Click += LabelClick;
}
}
return BackgroundPanel;
}
/// <summary>
/// 根据条码获取检验信息
/// </summary>
/// <param name="barcode"></param>
/// <returns></returns>
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;
}
}
/// <summary>
/// 获取国外数据库数据--暂时不用此方法
/// </summary>
/// <param name="skidNo"></param>
/// <returns></returns>
public static DataTable GetForeignData(string skidNo)
{
DataTable res = new DataTable();
try
{
string sqlConnString = ConfigurationManager.ConnectionStrings["SqlConnStringForeign"].ToString();
#region 查国外下线数据库
string sql = @" select top 1 *
from Paintline_Proddata where LTrim(RTrim(Skid_No)) = '" + skidNo + @"' order by TimeStamp desc ";
res = SqlHelper.GetDataDateTable(sqlConnString, CommandType.Text, sql, null);
LogHelper.WriteSysLogBase("[sql:]" + sql, MethodBase.GetCurrentMethod().Name);
#endregion
#region 线下没查到条码,查国外上线数据库
string indexName1 = ConfigurationManager.AppSettings["FrmFirstCheckLeftSide"];
string indexName2 = ConfigurationManager.AppSettings["FrmFirstCheckRightSide"];
if (res == null || res.Rows.Count < 1 || string.IsNullOrWhiteSpace(res.Rows[0][indexName1].ToString()) || string.IsNullOrWhiteSpace(res.Rows[0][indexName2].ToString()))
{
string sql_2 = " select top 1 * from Paintline_Loadingdata where LTrim(RTrim(Skid_No)) = '" + skidNo + @"' order by TimeStamp desc ";
res = SqlHelper.GetDataDateTable(sqlConnString, CommandType.Text, sql_2, null);
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;
}
}
/// <summary>
/// 查询外国数据库获取颜色码
/// </summary>
/// <param name="key"></param>
/// <param name="skidNo"></param>
/// <returns></returns>
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;
}
}
/// <summary>
/// 获取班次,规定早8至晚8为A班
/// </summary>
/// <returns></returns>
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");
if (classA)
{
return "A班";
}
else
{
return "B班";
}
}
/// <summary>
/// 判断传入时间是否在工作时间段内
/// </summary>
/// <param name="timeStr"></param>
/// <param name="startTime"></param>
/// <param name="endTime"></param>
/// <returns></returns>
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;
}
}
/// <summary>
/// 根据滑撬号查询第side个条码号
/// </summary>
/// <param name="skidNo"></param>
/// <param name="side"></param>
/// <returns></returns>
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;
}
}
/// <summary>
/// 根据条码获取要取的层数及BC0几
/// </summary>
/// <param name="no"></param>
/// <param name="title"></param>
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;
}
}
/// <summary>
/// 根据条码获取层数
/// </summary>
/// <param name="stockNo"></param>
/// <param name="partNo"></param>
/// <returns></returns>
public static string GetProductLayer(string stockNo, string partNo)
{
string res = "";
try
{
if (!string.IsNullOrWhiteSpace(stockNo))
{
string sql = @" select Layers 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 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;
}
}
/// <summary>
/// 手动换班
/// </summary>
/// <param name="label"></param>
public static void ChangeWorkClass(Label label)
{
if (label.Text.Trim() == "A班")
{
label.Text = "B班";
}
else
{
label.Text = "A班";
}
}
/// <summary>
/// 根据条码在老外库里查询颜色信息
/// </summary>
/// <param name="barcode"></param>
/// <returns></returns>
public static string GetProductInfo(string barcode)
{
string res = "";
try
{
#region 暂时不要
// string sql = @"
// DECLARE @barcode varchar(30);
// SET @barcode = '" + barcode + @"';
// 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"].ToString();
// //object aa = SqlHelper.ExecuteScalar(sqlConnString, CommandType.Text, sql, null);
// DataTable dtColor = SqlHelper.GetDataDateTable(sqlConnString, CommandType.Text, sql, null);
// string colorNo = "";
// string colorQQNo = "";
// string colorPRNo = "";
// //if (aa != null)
// //{
// // colorNo = aa.ToString();
// //}
// if (dtColor != null && dtColor.Rows.Count > 0)
// {
// colorNo = dtColor.Rows[0]["Setvalue_BC_Color_No"].ToString();
// colorQQNo = dtColor.Rows[0]["Setvalue_CC_Color_No"].ToString();
// colorPRNo = dtColor.Rows[0]["Setvalue_PR_Color_No"].ToString();
// }
// //根据颜色代码查颜色
// string colorInfo = "";
// if (!string.IsNullOrWhiteSpace(colorNo))
// {
// DataTable dt = new DataTable();
// //string sql_c = @" select * from tb_Color where ColorCode = '" + colorNo + "' ";
// 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 + "'";
// }
// 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
string colorInfo = "";
string sql = @" select top 1 ColorName from tb_PaintLoad where barcode = '" + barcode + @"' order by CreateTime desc ";
object aa = SqlHelper.ExecuteScalar(SqlHelper.SqlConnString, CommandType.Text, sql, null);
if (aa != null)
{
colorInfo = aa.ToString();
}
//根据条码查询产品信息
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;
}
}
/// <summary>
/// 查询补打条码信息
/// </summary>
/// <param name="barcode"></param>
/// <returns></returns>
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;
}
}
/// <summary>
/// 根据滑撬号获取圈数
/// </summary>
/// <param name="skidNo"></param>
/// <returns></returns>
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;
}
}
/// <summary>
/// 根据颜色号获取圈数
/// </summary>
/// <param name="colorCode"></param>
/// <returns></returns>
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;
}
}
/// <summary>
/// 根据条码号获取AB侧
/// </summary>
/// <param name="?"></param>
/// <returns></returns>
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;
}
}
/// <summary>
/// 根据一检结果显示一检时的位置
/// </summary>
/// <param name="dt"></param>
/// <returns></returns>
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;
}
}
/// <summary>
/// 判断条码有效性
/// </summary>
/// <param name="barcode"></param>
/// <returns></returns>
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;
}
/// <summary>
/// 将二维码转换成相应一维码
/// </summary>
/// <param name="barcode"></param>
/// <returns></returns>
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;
}
}
/// <summary>
/// 将传入条码统一变成一维码
/// </summary>
/// <param name="barcode"></param>
/// <returns></returns>
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;
}
#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)
{
int res = 0;
try
{
string sql = @"
INSERT INTO tb_ChainUp
([ID]
,[barcode]
,[carTypeID]
,[carType]
,[colorID]
,[color]
,[flag])
VALUES
((select newid())
,'" + barcode + @"'
,'" + carTypeID + @"'
,'" + carType + @"'
,'" + colorID + @"'
,'" + color + @"'
," + flag + @")
";
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 (aa == "[合格]")
{
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 08:00:00", "2019-06-12 20:00:00");
//if (classA)
//{
// return ("createTime between '" + DateTime.Now.ToString("yyyy-MM-dd") + " 08:00:00' and '" + DateTime.Now.ToString("yyyy-MM-dd") + " 20:00:00'");
//}
//else
//{
// bool isYesterday = IsBetweenTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "2019-06-12 00:00:00", "2019-06-12 07:59:59");
// if (isYesterday)
// {
// return ("createTime between '" + DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd") + " 20:00:00' and '" + DateTime.Now.ToString("yyyy-MM-dd") + " 07:59:59' ");
// }
// bool isToday = IsBetweenTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "2019-06-12 20:00:00", "2019-06-12 23:59:59");
// if (isToday)
// {
// return ("createTime between '" + DateTime.Now.ToString("yyyy-MM-dd") + " 20:00:00' and '" + DateTime.Now.AddDays(1).ToString("yyyy-MM-dd") + " 07:59: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
";
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(sql, 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;
}
}
}