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

1020 lines
42 KiB

using DBUtility;
using PaintingPC.Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
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);
if (res.Rows.Count > 0)
{
UpdatePlanState2(res.Rows[0]["ID"].ToString(), stationNo);
}
#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);
if (res.Rows.Count > 0)
{
UpdatePlanState2(res.Rows[0]["ID"].ToString(), stationNo);
}
#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);
if (res.Rows.Count > 0)
{
UpdatePlanState2(res.Rows[0]["ID"].ToString(), stationNo);
}
}
return res;
}
catch (Exception ex)
{
LogHelper.WriteLog(ex.ToString());
return res;
}
}
static int UpdatePlanState2(string planID,string stationNo)
{
int res = 0;
try
{
string sql1 = @" update tb_ZP_MK_Plan set State = '2' where State = 1 and Station='" + stationNo + "' ";
string sql2 = @" update tb_ZP_MK_Plan set State = '1' where ID='" + planID + "' ";
res = SqlHelper.ExecuteNonQuery(SqlHelper.SqlConnString, CommandType.Text, sql1, null);
res = SqlHelper.ExecuteNonQuery(SqlHelper.SqlConnString, CommandType.Text, sql2, null);
return res;
}
catch (Exception ex)
{
LogHelper.WriteLog("切换计划时,更新计划状态失败[UpdatePlanState2],失败原因:"+ex.Message);
//LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name);
return res;
}
}
public static int DeleteLineData(string id )
{
int res = 0;
try
{
string sql1 = @" delete from tb_Punch_Line where ID='" + id + "' ";
res = SqlHelper.ExecuteNonQuery(SqlHelper.SqlConnString, CommandType.Text, sql1, null);
return res;
}
catch (Exception ex)
{
LogHelper.WriteLog("扫码生产完成,删除操作临时数据失败,[DeleteLineData],失败原因:" + ex.Message);
//LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name);
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}' ";
res = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql, null);
return res;
}
catch (Exception ex)
{
LogHelper.WriteLog("小件装配,tb_Product,异常原因:" + ex.ToString());
return res;
}
}
public static string GetProductName(string partNo)
{
DataTable res = new DataTable();
try
{
string sql = $" select Top 1 * from tb_Product where PartNo='{partNo}' ";
res = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql, null);
if (res.Rows.Count > 0)
{
return res.Rows[0]["ProductName"].ToString();
}
return "";
}
catch (Exception ex)
{
LogHelper.WriteLog("通过零件号查询零件名称,tb_Product表发生异常,异常原因:" + ex.ToString());
return "";
}
}
/// <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}' ";
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 * from tb_Bom_MK where PartNo1='{assemblePartCode}' and StationNo='{stationNo}' ";
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 partNo1, string partNo2, 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]
([barcode]
,[BcpID]
,ZcPartNo
,[ZcBarCode]
,[OrderNo]
,[WorkClass]
,[CreateTime], PlanID,SerialNo
,barCode1,barCode2,barCode3
,barCode4,barCode5,barCode6,StationNo,StationDescription)
VALUES
('" + barcode + @"'
,'" + partNo2 + @"'
,'" + partNo1 + @"'
,'" + 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_ZP_MK_Plan set OKCount = OKCount + 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;
}
}
static string GetPartNoFromBarCode(string pBarCode)
{
if (pBarCode.Length == 33 || pBarCode.Length == 31)
{
string color = pBarCode.Substring(19, 3);
if (Regex.IsMatch(color, "^[0-9]+$") == true) //三位全是数字,认为不含颜色
{
pBarCode = pBarCode.Substring(6, 13);
}
else
{
pBarCode = pBarCode.Substring(6, 16);
}
}
else if (pBarCode.Length == 28)
{
pBarCode = pBarCode.Substring(6, 13);
}
else if (pBarCode.Length == 24)
{
pBarCode = pBarCode.Substring(0, 13);
}
else
{
if (pBarCode.Length > 10)
{
if (pBarCode.Contains("."))
{
pBarCode = pBarCode.Substring(0, pBarCode.IndexOf("."));
}
else if (pBarCode.Contains("/"))
{
pBarCode = pBarCode.Substring(0, pBarCode.IndexOf("/"));
}
else if (pBarCode.Length == 11)
{
pBarCode = pBarCode;
}
else
{
pBarCode = pBarCode.Substring(0, 10);
}
}
}
return pBarCode;
}
public static string GetProductNo(string barcode)
{
string res = "";
try
{
if (barcode.Length != 20)
{
return GetPartNoFromBarCode(barcode);
}
//LogHelper.WriteSysLogBase("[一码到底]扫入条码:" + barcode, MethodBase.GetCurrentMethod().Name);
//if (barcode.Length != 20)
//{
// barcode = UniteBarCodeToOne(barcode);
//}
string sql = @" 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();
if (string.IsNullOrEmpty(res))
{
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)
{
res = cc.ToString();
//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;
}
if (!string.IsNullOrEmpty(stockNo))
{
string sql3 = @"select partNo
from tb_Product
where StockNo = '" + stockNo + @"'";
object dd = SqlHelper.ExecuteScalar(SqlHelper.SqlConnString, CommandType.Text, sql3, null);
if (dd != null)
{
res = dd.ToString();
}
}
//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 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 string SaveLineInfo(string sjBarCode, string planID,string stationNo,string partNo1,string partNo2, int LeftRivet1All, int RightRivet1All, int LeftScrew1All, int RightScrew1All, int IrIsAll )
{
string res = string.Empty;
try
{
string sql = $"insert into tb_Punch_Line (SjBarCode,PlanID,StationNo,PartNo1,PartNo2,barCode1,barCode2,barCode3,barCode4,barCode5,barCode6, LeftRivet1All,RightRivet1All,LeftScrew1All,RightScrew1All,IrIsAll ) " +
$"values('{sjBarCode}','{planID}','{stationNo}','{partNo1}','{partNo2}','{ScanAll.barCode1}','{ScanAll.barCode2}','{ScanAll.barCode3}','{ScanAll.barCode4}','{ScanAll.barCode5}','{ScanAll.barCode6}','{LeftRivet1All}','{RightRivet1All}','{LeftScrew1All}','{RightScrew1All}','{IrIsAll}' );select @@Identity";
object dd = SqlHelper.ExecuteScalar(SqlHelper.SqlConnString, CommandType.Text, sql, null);
if (dd != null)
{
res = dd.ToString();
}
}
catch (Exception ex)
{
//LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name);
LogHelper.WriteLog("保存tb_Punch_Line表数据时发生异常,异常原因:" + ex.ToString());
}
return res;
}
public static int UpdateLineCount(string field, string id)
{
int res = -1;
try
{
string sql = $"update tb_Punch_Line set {field} where id={id} ";
res = SqlHelper.ExecuteNonQuery(SqlHelper.SqlConnString, CommandType.Text, sql, null);
}
catch (Exception ex)
{
//LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name);
LogHelper.WriteLog(ex.ToString());
}
return res;
}
public static DataTable GetPunchLineInfo( string id)
{
DataTable res = null;
try
{
string sql = @"select * from tb_Punch_Line where ID ='" + id + @"'";
res = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql, null);
}
catch (Exception ex)
{
//LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name);
LogHelper.WriteLog($"查询tb_Punch_Line表错误,ID={id},异常信息:"+ex.Message);
}
return res;
}
public static DataTable GetPunchLineInfo(string planID,string stationNo)
{
DataTable res = null;
try
{
string sql = @"select * from tb_Punch_Line where PlanID ='" + planID + @"' and StationNo='"+ stationNo + "'";
res = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql, null);
}
catch (Exception ex)
{
//LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name);
LogHelper.WriteLog($"根据计划ID,工位号查询tb_Punch_Line表错误,planID={planID},stationNo={stationNo},异常信息:" + ex.Message);
}
return res;
}
public static int UpdatePlanState(string state, string id)
{
int res = -1;
try
{
string sql = $"update tb_ZP_MK_Plan set State='{state}' where id={id} ";
res = SqlHelper.ExecuteNonQuery(SqlHelper.SqlConnString, CommandType.Text, sql, null);
}
catch (Exception ex)
{
//LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name);
LogHelper.WriteLog(ex.ToString());
}
return res;
}
public static DataTable GetPunchRecord(string planID,string barcode,string date1,string date2)
{
DataTable res = null;
try
{
string where = "(1 = 1)";
if (!string.IsNullOrEmpty(barcode))
{
where = $" barcode='{barcode}' ";
}
string sql = $"select * from tb_Punch_Code_Record where PlanID ='{planID}' and {where} and CreateTime>'{date1}' and CreateTime<'{date2}'";
res = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql, null);
}
catch (Exception ex)
{
//LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name);
LogHelper.WriteLog($"查询tb_Punch_Code_Record表错误,planID={planID},异常信息:" + ex.Message);
}
return res;
}
/// <summary>
/// 是否需要前置工序验证
/// </summary>
/// <returns></returns>
public static bool GetVerifyPreProcess()
{
DataTable res = null;
try
{
string sql = $"select * from tb_Config where name ='PunchAssembleVerifyQA' ";
res = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql, null);
if (res.Rows.Count == 0)
{
return true;
}
else
{
if (res.Rows[0]["value"].ToString()?.ToLower() == "false")
return false;
}
}
catch (Exception ex)
{
//LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name);
LogHelper.WriteLog($"查询tb_Config表错误 ,异常信息:" + ex.Message);
}
return true;
}
/// <summary>
/// 查询前置工序,上线前质检是否存在
/// </summary>
/// <returns></returns>
public static bool GetInspectResultCheck(string sjBarCode)
{
DataTable res = null;
try
{
string sql = $"select * from tb_InspectResult_Check where barcode ='{sjBarCode}' and inspectResult='合格' ";
res = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql, null);
if (res.Rows.Count > 0)
{
return true;
}
}
catch (Exception ex)
{
//LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name);
LogHelper.WriteLog($"查询tb_InspectResult_Check表错误,barcode ='{sjBarCode}' ,异常信息:" + ex.Message);
}
return false;
}
public static string InsertInspect3(InspectModel model1)
{
return "";
}
public static DataTable SearchDefectInfo(string stationNo)
{
return null;
}
public static DataTable SearchInfoByBarCode(string barcode)
{
return null;
}
public static string GetImgPath()
{
return "";
}
public static DataTable GetLastResult(string barcode)
{
return null;
}
public static bool GetPointRepairFrWms(string barcode ,ref string errorMsg)
{
return true;
}
}
}