一厂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.
 
 
 
 
 

632 lines
26 KiB

using DBUtility;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PunchingMistake
{
public class Function2
{
public static DataTable GetProScreen(string stationNo)
{
DataTable res = new DataTable();
try
{
string sql = @"
select top 1 a.ID, d.[Des], a.OrderNo, a.PartNo,b.ProductName,a.OrderCount,a.OKCount,a.BadCount,a.RepairCount, c.PartNo1, c.PartNo2, b.IsHigh,d.StationNo
from tb_ZP_MK_Plan a
left join tb_Product b
on a.PartNo = b.PartNo
left join tb_Bom_MK c
on b.PartNo = c.PartNo1
left join tb_Station d
on c.StationNo = d.StationNo
where d.StationNo = '" + stationNo + @"'
and a.State = 1
order by CreateTime desc
";
res = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql, null);
if (res == null || res.Rows.Count < 1)
{
sql = @"
select top 1 a.ID, d.[Des], a.OrderNo, a.PartNo,b.ProductName,a.OrderCount,a.OKCount,a.BadCount,a.RepairCount, c.PartNo1, c.PartNo2, b.IsHigh,d.StationNo
from tb_ZP_MK_Plan a
left join tb_Product b
on a.PartNo = b.PartNo
left join tb_Bom_MK c
on b.PartNo = c.PartNo1
left join tb_Station d
on c.StationNo = d.StationNo
where d.StationNo = '" + stationNo + @"'
and a.State = 0
order by CreateTime desc
";
res = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql, null);
}
if (res == null || res.Rows.Count < 1)
{
sql = @"
select top 1 a.ID, d.[Des], a.OrderNo, a.PartNo,b.ProductName,a.OrderCount,a.OKCount,a.BadCount,a.RepairCount, c.PartNo1, c.PartNo2, b.IsHigh,d.StationNo
from tb_ZP_MK_Plan a
left join tb_Product b
on a.PartNo = b.PartNo
left join tb_Bom_MK c
on b.PartNo = c.PartNo1
left join tb_Station d
on c.StationNo = d.StationNo
where d.StationNo = '" + stationNo + @"'
and a.State = 2
order by CreateTime desc
";
res = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql, null);
}
return res;
}
catch (Exception ex)
{
LogHelper.WriteLog(ex.ToString() );
return res;
}
}
public static DataTable GetProScreenPlan(string id, string stationNo, string plan)
{
DataTable res = new DataTable();
try
{
if (plan == "下一计划")
{
#region 查询当前计划时间
string time = "";
string sql;
string sqll = @" select CreateTime from tb_ZP_MK_Plan where ID = '" + id + @"' ";
DataTable dt = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sqll, null);
if (dt != null && dt.Rows.Count > 0)
{
time = dt.Rows[0][0].ToString();
time = Tools.NumericParse.StringToDateTime(time).Value.AddSeconds(1).ToString("yyyy-MM-dd HH:mm:ss");
}
#endregion
#region 查询下一计划
DateTime dtime = DateTime.Now;
DateTime.TryParse(time, out dtime);
sql = @" select top 1 a.ID, d.[Des], a.OrderNo, a.PartNo,b.ProductName,a.OrderCount,a.OKCount,a.BadCount,a.RepairCount, c.PartNo1, c.PartNo2, b.IsHigh,d.StationNo
from tb_ZP_MK_Plan a
left join tb_Product b
on a.PartNo = b.PartNo
left join tb_Bom_MK c
on b.PartNo = c.PartNo1
left join tb_Station d
on c.StationNo = d.StationNo
where d.StationNo = '" + stationNo + @"'
and State <> 3
and a.CreateTime > '" + dtime.ToString("yyyy-MM-dd HH:mm:ss") + @"'
order by CreateTime asc
";
res = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql, null);
#endregion
}
else if (plan == "上一计划")
{
#region 查询当前计划时间
string time = "";
string sql;
string sqll = @" select CreateTime from tb_ZP_MK_Plan where ID = '" + id + @"' ";
DataTable dt = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sqll, null);
if (dt != null && dt.Rows.Count > 0)
{
time = dt.Rows[0][0].ToString();
//time = Tools.NumericParse.StringToDateTime(time).Value.AddSeconds(-1).ToString("yyyy-MM-dd HH:mm:ss");
}
#endregion
#region 查询上一计划
DateTime dtime = DateTime.Now;
DateTime.TryParse(time, out dtime);
sql = @"
select top 1 a.ID, d.[Des], a.OrderNo, a.PartNo,b.ProductName,a.OrderCount,a.OKCount,a.BadCount,a.RepairCount, c.PartNo1, c.PartNo2, b.IsHigh,d.StationNo
from tb_ZP_MK_Plan a
left join tb_Product b
on a.PartNo = b.PartNo
left join tb_Bom_MK c
on b.PartNo = c.PartNo1
left join tb_Station d
on c.StationNo = d.StationNo
where d.StationNo = '" + stationNo + @"'
and State <> 3
and a.CreateTime < '" + dtime.ToString("yyyy-MM-dd HH:mm:ss") + @"'
order by CreateTime asc
";
res = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql, null);
#endregion
}
else if (plan == "当前计划")
{
string sql = @"
select a.ID, d.[Des], a.OrderNo, a.PartNo,b.ProductName,a.OrderCount,a.OKCount,a.BadCount,a.RepairCount, c.PartNo1, c.PartNo2, b.IsHigh,d.StationNo
from tb_ZP_MK_Plan a
left join tb_Product b
on a.PartNo = b.PartNo
left join tb_Bom_MK c
on b.PartNo = c.PartNo1
left join tb_Station d
on c.StationNo = d.StationNo
where a.ID='" + id + @"'
";
res = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql, null);
}
return res;
}
catch (Exception ex)
{
LogHelper.WriteLog(ex.ToString());
return res;
}
}
/// <summary>
/// 塑件码是否通过了Wms报工
/// </summary>
/// <param name="sjBarCode"></param>
/// <returns></returns>
public static DataTable SearchStockIn(string sjBarCode)
{
DataTable res = new DataTable();
try
{
string sql = $" select * from tb_StockIn where barcode='{sjBarCode}' and Pass=1";
res = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql, null);
return res;
}
catch(Exception ex)
{
LogHelper.WriteLog("小件装配,查询StockIn发生异常,异常原因:" + ex.ToString());
return res;
}
}
public static DataTable SearchPunchCodeRecord(string sjBarCode)
{
DataTable res = new DataTable();
try
{
string sql = $" select Top 1 * from tb_Punch_Code_Record where barcode='{sjBarCode}' order by id desc ";
res = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql, null);
return res;
}
catch (Exception ex)
{
LogHelper.WriteLog("小件装配,查询Punch_Code_Record发生异常,异常原因:" + ex.ToString());
return res;
}
}
public static DataTable GetProductInfo(string stockNo)
{
DataTable res = new DataTable();
try
{
string sql = $" select Top 1 * from tb_Product where StockNo='{stockNo}' order by id desc ";
res = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql, null);
return res;
}
catch (Exception ex)
{
LogHelper.WriteLog("小件装配,tb_Product,异常原因:" + ex.ToString());
return res;
}
}
/// <summary>
/// 半成品条码,找总成条码
/// </summary>
/// <param name="partCode"></param>
/// <param name="stationNo"></param>
/// <returns></returns>
public static string GetAssemblePartCode(string partCode,string stationNo)
{
DataTable res = new DataTable();
try
{
string sql = $" select Top 1 * from tb_Bom_MK where PartNo2='{partCode}' and IsPartAssemble=1 and StationNo='{stationNo}' order by id desc ";
res = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql, null);
if(res .Rows.Count > 1)
{
throw new Exception($"半成品条码[{partCode}]在工位[{stationNo}]上配置存在多个,请检查BOM配置.");
}
else if (res.Rows.Count == 0)
{
throw new Exception($"半成品条码[{partCode}]在工位[{stationNo}]上未进行配置,请检查BOM配置.");
}
else
{
return res.Rows[0]["PartNo1"].ToString();
}
}
catch (Exception ex)
{
LogHelper.WriteLog("小件装配,在表tb_Bom_MK中根据半成品条码查询总成零件号错误,异常原因:" + ex.ToString());
throw ex;
}
}
public static DataTable GetBomTable(string assemblePartCode,string stationNo)
{
DataTable res = new DataTable();
try
{
string sql = $" select Top 1 * from tb_Bom_MK where PartNo1='{assemblePartCode}' and StationNo='{stationNo}' order by id desc ";
res = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql, null);
return res;
}
catch (Exception ex)
{
LogHelper.WriteLog($"小件装配,总成零件号[{assemblePartCode}],工位[{stationNo}]在表tb_Bom_MK中查询发生异常,异常原因:" + ex.ToString());
throw ex;
}
}
public static string GetStation(string stationNo)
{
string res = "";
try
{
string sql = @" select [des] from tb_Station where StationNo = '" + stationNo + @"' ";
object aa = SqlHelper.ExecuteScalar(SqlHelper.SqlConnString, CommandType.Text, sql, null);
if (aa != null)
{
res = aa.ToString();
}
return res;
}
catch (Exception ex)
{
//LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name);
return res;
}
}
public static int SavePartAndProduct_New(string barcode, string BcpID, string ZcID, string OrderNo, string WorkClass, string planID, string SerialNo, string barCode1, string barCode2, string barCode3, string barCode4, string barCode5, string barCode6, string stationId, string description)
{
int res = 0;
try
{
string sql = @"
INSERT INTO [dbo].[tb_Punch_Code_Record]
([ID]
,[barcode]
,[BcpID]
,[ZcID]
,[OrderNo]
,[WorkClass]
,[CreateTime], PlanID,SerialNo
,barCode1,barCode2,barCode3
,barCode4,barCode5,barCode6,StationId,StationDescription)
VALUES
((select newid())
,'" + barcode + @"'
,'" + BcpID + @"'
,'" + ZcID + @"'
,'" + OrderNo + @"'
,'" + WorkClass + @"'
,(select getdate()), '" + planID + @"','" + SerialNo + @"'
,'" + barCode1 + @"','" + barCode2 + @"','" + barCode3 + @"'
,'" + barCode4 + @"','" + barCode5 + @"','" + barCode6 + @"','" + stationId + @"','" + description + "@')";
res = SqlHelper.ExecuteNonQuery(SqlHelper.SqlConnString, CommandType.Text, sql, null);
return res;
}
catch (Exception ex)
{
//LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name);
return res;
}
}
public static string SerialNo(string partNo, string batch)
{
string res = "";
try
{
string temp_no = partNo + "." + batch;
string sql = @"select top 1 SerialNo from tb_Punch_Code_Record where SerialNo like '" + temp_no +
@"%' order by CreateTime desc";
object dt = SqlHelper.ExecuteScalar(SqlHelper.SqlConnString, CommandType.Text, sql, null);
if (dt != null)
{
res = dt.ToString();
}
}
catch (Exception ex)
{
//LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name);
throw ex;
}
return res;
}
public static int SaveZcCode(string barcode, string partNo)
{
int res = 0;
try
{
string sql = @" update tb_StockIn set ZcCode = '" + partNo + "' where barcode = '" + barcode + "' ";
res = SqlHelper.ExecuteNonQuery(SqlHelper.SqlConnString, CommandType.Text, sql, null);
return res;
}
catch (Exception ex)
{
//LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name);
return res;
}
}
public static int AddCompleteCount(string ID)
{
int res = 0;
try
{
string sql = " update tb_Plan_Punch set CompleteCount = CompleteCount + 1 where ID = '" + ID + "' ";
res = SqlHelper.ExecuteNonQuery(SqlHelper.SqlConnString, CommandType.Text, sql, null);
return res;
}
catch (Exception ex)
{
//LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name);
return res;
}
}
public static bool CheckPlanCompleted(string ID)
{
bool res = false;
try
{
string sql = @"
select IsFinish from tb_Plan_Punch where ID = '" + ID + @"'
";
object aa = SqlHelper.ExecuteScalar(SqlHelper.SqlConnString, CommandType.Text, sql, null);
if (aa != null)
{
string bb = aa.ToString();
if (bb == "3")
{
res = true;
}
else
{
res = false;
}
}
return res;
}
catch (Exception ex)
{
//LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name);
return res;
}
}
public static string GetProductID(string barcode)
{
string res = "";
try
{
//LogHelper.WriteSysLogBase("[一码到底]扫入条码:" + barcode, MethodBase.GetCurrentMethod().Name);
if (barcode.Length != 20)
{
barcode = UniteBarCodeToOne(barcode);
}
string sql = @" select ProductID
from tb_Product
where partNo = ( select top 1 paintCode from tb_StockIn where barcode = '" + barcode + @"' ) ";
object aa = SqlHelper.ExecuteScalar(SqlHelper.SqlConnString, CommandType.Text, sql, null);
if (aa != null)
res = aa.ToString();
else
{
string sql1 = @" select top 1 productInfo
from tb_InspectResult
where barcode = '" + barcode + @"'
order by createtime desc ";
object bb = SqlHelper.ExecuteScalar(SqlHelper.SqlConnString, CommandType.Text, sql1, null);
if (bb != null)
{
string color = "";
string colorInfo = bb.ToString();
string[] colors = colorInfo.Split(',');
if (colors.Length >= 2)
{
color = colors[2];
string sql2 = @" select partNo from tb_Product where stockNo = '" + barcode.Substring(0, 10) + @"' ";
object cc = SqlHelper.ExecuteScalar(SqlHelper.SqlConnString, CommandType.Text, sql2, null);
if (cc != null)
{
string partNo = cc.ToString();
string paintCode = partNo.Replace("-P", "") + "-" + color;
string sql3 = @" select ProductID
from tb_Product
where partNo = '" + paintCode + @"' ";
object dd = SqlHelper.ExecuteScalar(SqlHelper.SqlConnString, CommandType.Text, sql3, null);
if (dd != null)
{
res = dd.ToString();
}
}
}
}
else
{
string partNo = "", stockNo = "";
if (barcode.Contains('/'))
{
string[] aastr = barcode.Split('/');
partNo = aastr[0];
}
else if (barcode.Contains('.'))
{
string[] aastr = barcode.Split('.');
partNo = aastr[0];
}
else if (barcode.Length == 20)
{
stockNo = barcode.Substring(0, 10);
}
else
{
partNo = barcode;
}
string sql3 = "";
if (partNo != "")
{
sql3 = @"select ProductID
from tb_Product
where partNo = '" + partNo + @"'";
}
else
{
sql3 = @"select ProductID
from tb_Product
where StockNo = '" + stockNo + @"'";
}
object dd = SqlHelper.ExecuteScalar(SqlHelper.SqlConnString, CommandType.Text, sql3, null);
if (dd != null)
{
res = dd.ToString();
}
}
}
//LogHelper.WriteSysLogBase("[一码到底]传出ProductID2:" + res, MethodBase.GetCurrentMethod().Name);
return res;
}
catch (Exception 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 string TransToBarCodeOne(string barcode)
{
string res = barcode;
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].[tb_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.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name);
return res;
}
}
public static string GetPartNoByID(string id)
{
string res = "";
try
{
string sql = @"select PartNo from tb_Product where ProductID ='" + id + @"'";
object dt = SqlHelper.ExecuteScalar(SqlHelper.SqlConnString, CommandType.Text, sql, null);
if (dt != null)
{
res = dt.ToString();
}
}
catch (Exception ex)
{
//LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name);
}
return res;
}
}
public static class ScanAll
{
public static bool ScanResult;
public static string barCode1;
public static string barCode2;
public static string barCode3;
public static string barCode4;
public static string barCode5;
public static string barCode6;
public static string partNo1;
public static string partNo2;
public static string partNo3;
public static string partNo4;
public static string partNo5;
public static string partNo6;
}
public class OtherPart
{
public string productID3 { get; set; }
public string qty3 { get; set; }
public string productID4 { get; set; }
public string qty4 { get; set; }
public string productID5 { get; set; }
public string qty5 { get; set; }
public string productID6 { get; set; }
public string qty6 { get; set; }
public string productID7 { get; set; }
public string qty7 { get; set; }
public string productID8 { get; set; }
public string qty8 { get; set; }
}
}