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

370 lines
13 KiB

3 months ago
using DBUtility;
using System;
using System.Data;
using System.Security.Cryptography;
using System.Text;
namespace AppWebservice
{
public class Function
{
public static readonly string app_id = "9b38d8d9-af87-49d2-a0a1-87516c86f254";
public static readonly string app_secret = "422f5bd0-0393-408b-9024-a98f8c6367a4";
/// <summary>
/// 判断AppID是否合法
/// </summary>
/// <param name="app_id"></param>
/// <returns></returns>
public static bool AppIDIsRight(string app_id)
{
if (app_id.Trim() != Function.app_id.Trim())
{
return false;
}
else
{
return true;
}
}
public static string MD5Encryption(string str)
{
try
{
if (!string.IsNullOrWhiteSpace(str))
{
byte[] result = Encoding.Default.GetBytes(str); //tbPass为输入密码的文本框
MD5 md5 = new MD5CryptoServiceProvider();
byte[] output = md5.ComputeHash(result);
return BitConverter.ToString(output).Replace("-", "");
}
else
{
return string.Empty;
}
}
catch (Exception ex)
{
LogHelper.WriteLogManager(ex);
return string.Empty;
}
}
/// <summary>
/// 传入的参数是否合法
/// </summary>
/// <param name="param"></param>
/// <param name="sign"></param>
/// <returns></returns>
public static bool signIsRight(string[] param, string sign)
{
bool res;
string str = "";
if (param.Length > 0)
{
foreach (string s in param)
{
str += s.Trim();
}
}
string getMd5 = MD5Encryption(str);
if (getMd5 != sign)
{
res = false;
}
else
{
res = true;
}
return res;
}
public static DataTable GetInfoByParticles(string stockNo, out string errorReason)
{
DataTable res = new DataTable();
try
{
string sql = @"
select * from tb_Product where StockNo = '" + stockNo + @"'
";
res = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql, null);
errorReason = "";
return res;
}
catch (Exception ex)
{
LogHelper.WriteLogManager(ex);
errorReason = ex.Message;
return res;
}
}
/// <summary>
/// 绑定塑料粒子与料筒
/// </summary>
/// <param name="particleCode">塑料粒子</param>
/// <param name="drumCode">料筒</param>
/// <param name="errorReason"></param>
/// <returns></returns>
public static int BindparticleCodeAndDrum(string particleCode, string drumCode, out string errorReason)
{
int res = 0;
try
{
string sql = @"
insert into tb_CylinderAndRaw(ID, CylinderID, DrumBarCode, BarCode, Time1)
values((select newid()),(select CylinderID from tb_Cylinder where CylinderNo = '" + drumCode + @"'),'" + drumCode + @"'
'" + particleCode + @"', (select getdate()))
";
res = SqlHelper.ExecuteNonQuery(SqlHelper.SqlConnString, CommandType.Text, sql, null);
errorReason = "";
return res;
}
catch (Exception ex)
{
LogHelper.WriteLogManager(ex);
errorReason = ex.Message;
return res;
}
}
/// <summary>
/// 注塑机号(即工位号)
/// </summary>
/// <param name="machineCode"></param>
/// <param name="errorReason"></param>
/// <returns></returns>
public static DataTable GetPlan(string machineCode, out string errorReason)
{
DataTable res = new DataTable();
try
{
string sql = @"
select ProductName as [Plan] from tb_Product where StockNo = (
select top 1 StockNo from tb_InjectionPlan where StationID = (
select StationID from tb_Station where StationNo = '" + machineCode + @"' )
order by PlanDate desc)
";
res = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql, null);
errorReason = "";
return res;
}
catch(Exception ex)
{
LogHelper.WriteLogManager(ex);
errorReason = ex.Message;
return res;
}
}
public static DataTable GetMaterialInfo(string drumCode, out string errorReason)
{
DataTable res = new DataTable();
try
{
string sql = @"
select CylinderBarCode from tb_CylinderAndRaw where DrumBarCode = '" + drumCode + @"' and Time2 is null
";
res = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql, null);
errorReason = "";
return res;
}
catch (Exception ex)
{
LogHelper.WriteLogManager(ex);
errorReason = ex.Message;
return res;
}
}
/// <summary>
/// 绑定注塑机与料筒
/// </summary>
/// <param name="machineCode">注塑机(实际传的是工位号,一个工位就是一个注塑机)</param>
/// <param name="drumCode">料筒</param>
/// <param name="errorReason"></param>
/// <returns></returns>
public static int BindMachineAndDrum(string machineCode, string drumCode, out string errorReason)
{
int res = 0;
try
{
string sql = @"
insert into tb_StationAndCylinder(ID, StationID, CylinderID, Time1)
values((select newid()), (select StationID from tb_Station where StationNo = '" + machineCode + @"'),
(select CylinderID from tb_Cylinder where CylinderNo = '" + drumCode + @"'),
(select getdate()))
";
res = SqlHelper.ExecuteNonQuery(SqlHelper.SqlConnString, CommandType.Text, sql, null);
errorReason = "";
return res;
}
catch (Exception ex)
{
LogHelper.WriteLogManager(ex);
errorReason = ex.Message;
return res;
}
}
/// <summary>
/// 解绑料筒的绑定关系
/// </summary>
/// <param name="drumCode"></param>
/// <param name="errorReason"></param>
/// <returns></returns>
public static int ClearDrum(string drumCode, out string errorReason)
{
int res = 0;
try
{
string sql = @"
update tb_CylinderAndRaw set Time2 = (select getdate())
where CylinderID = (select CylinderID from tb_Cylinder where CylinderNo = '" + drumCode + @"')
and Time2 is null;
update tb_StationAndCylinder set Time2 = (select getdate())
where CylinderID = (select CylinderID from tb_Cylinder where CylinderNo = '" + drumCode + @"')
and Time2 is null;
";
res = SqlHelper.ExecuteNonQuery(SqlHelper.SqlConnString, CommandType.Text, sql, null);
errorReason = "";
return res;
}
catch (Exception ex)
{
LogHelper.WriteLogManager(ex);
errorReason = ex.Message;
return res;
}
}
#region 工具
/// <summary>
/// 解析条码
/// </summary>
/// <param name="code">条码</param>
/// <param name="stockNo">存货代码</param>
/// <param name="batchNo">批次</param>
public static void GetCode(string code, out string stockNo, out string batchNo)
{
//解析塑料粒子条码,长度为20的为一维码,否则为二维码
//二维码样例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 = ""; //批次
if (code.Length == 20)
{
//一维码
stockNo = code.Substring(0, 10);
batchNo = code.Substring(11, 6);
}
else
{
//二维码
string[] strs = code.Split(';');
if (strs.Length > 0)
{
string str = strs[0];
string[] props = str.Split('.');
if (props.Length > 3)
{
stockNo = props[0];
batchNo = props[1];
}
}
}
}
#endregion
/// <summary>
/// 查询油漆是否存在或在用
/// </summary>
/// <param name="PaintCode"></param>
/// <param name="errorReason"></param>
/// <returns></returns>
public static DataTable GetPaintInfoIsUsing(string PaintCode, out string errorReason)
{
DataTable res = new DataTable();
try
{
string sql = @"
select * from tb_PaintInfo where IsUsing=1 and PaintCode = '" + PaintCode + @"'
";
res = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql, null);
errorReason = "";
return res;
}
catch (Exception ex)
{
LogHelper.WriteLogManager(ex);
errorReason = ex.Message;
return res;
}
}
/// <summary>
/// 查询油漆信息
/// </summary>
/// <param name="PaintCode"></param>
/// <param name="errorReason"></param>
/// <returns></returns>
public static DataTable GetPaintInfo(string PaintCode, out string errorReason)
{
DataTable res = new DataTable();
try
{
string sql = @"
select * from tb_PaintInfo where PaintCode = '" + PaintCode + @"'
";
res = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql, null);
errorReason = "";
return res;
}
catch (Exception ex)
{
LogHelper.WriteLogManager(ex);
errorReason = ex.Message;
return res;
}
}
public static DataTable IsMatch(string PaintCode, string DrumCode, out string errorReason)
{
DataTable res = new DataTable();
try
{
string sql = @"SELECT dbo.tb_BucketInfo.BucketCode, dbo.tb_PaintInfo.PaintCode
FROM dbo.tb_BucketInfo INNER JOIN
dbo.tb_Paint_Bucket ON dbo.tb_BucketInfo.ID = dbo.tb_Paint_Bucket.BucketID INNER JOIN
dbo.tb_PaintInfo ON dbo.tb_Paint_Bucket.PaintID = dbo.tb_PaintInfo.ID where dbo.tb_BucketInfo.BucketCode='" + DrumCode + "' and dbo.tb_PaintInfo.PaintCode = '" + PaintCode + @"'
";
res = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql, null);
errorReason = "";
return res;
}
catch (Exception ex)
{
LogHelper.WriteLogManager(ex);
errorReason = ex.Message;
return res;
}
}
}
}