using iWare_SCADA_Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Text;
using System.Threading.Tasks;
using System.Web.UI.WebControls;
namespace iWare_SCADA_BusinessLogical.Utils
{
///
/// 业务系统帮助类
///
public class SystemBussinessHelper
{
///
/// 获取夹具工位
///
///
///
///
public static string GetJiaJuGongWei(string str, string workingProcedure)
{
try
{
if (string.IsNullOrEmpty(str))
{
return "";
}
if (workingProcedure == "OP20")
{
if (str.Length == "OP2002C2".Length)
{
int length = str.Length;
string lastTwoCharacters = str.Substring(length - 2, 2);
return lastTwoCharacters;
}
}
else if (workingProcedure == "OP50")
{
if (str.Length == "OP5001A3".Length)
{
int length = str.Length;
string lastTwoCharacters = str.Substring(length - 2, 2);
return lastTwoCharacters;
}
}
}
catch (Exception)
{
return "";
}
return "";
}
///
/// 模拟时间(返回秒)
///
///
///
public static int MoNiTimeForWorkingProcedure(string workingProcedure)
{
switch (workingProcedure)
{
case "OP10":
case "OP40":
return 4;
case "OP20":
return 2 * 60;
case "OP30":
return 2 * 60;
case "OP35":
return 1 * 60;
case "OP50":
return 3 * 60;
case "OP60":
return 4 * 60;
case "OP70":
return 9 * 60;//9分钟
default:
return 1 * 60;
}
}
///
/// 校验读取的二维码是否正确
///
///
///
public static bool ValidateIsRightWorkPieceID(string workPieceID)
{
if (string.IsNullOrEmpty(workPieceID))
{
return false;
}
if (workPieceID.Length == 22)
{
var n_workPieceID = workPieceID.Trim();
if (n_workPieceID.Length == 22)
{
if (n_workPieceID.ToUpper().IndexOf("ERROR") > -1)
{
return false;
}
if (n_workPieceID.ToUpper().IndexOf("ERR") > -1)
{
return false;
}
if (n_workPieceID.ToUpper().IndexOf('\0') > -1)
{
return false;
}
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
///
/// 设置 WorkPieceInfo 的DataCapturePointCname
///
///
///
///
public static void SetWorkPieceInfoMiddleForCreatedUserName(ref WorkPieceInfo workPiece, string _DataCapturePointName)
{
workPiece.DataCapturePointCname = _DataCapturePointName;
}
///
/// 设置 WorkPieceInfo 的UpdateDataCapturePointCname
///
///
///
///
public static void SetWorkPieceInfoMiddleForUpdateDataCapturePointCname(ref WorkPieceInfo workPiece, string _DataCapturePointName)
{
workPiece.UpdateDataCapturePointCname = _DataCapturePointName;
}
///
/// 设置WorkPieceLog 的创建人
///
///
///
///
public static void SetWorkPieceLogMiddleForCreatedUserName(ref WorkPieceLogMiddle workPieceLog, string _DataCapturePointCode, string _DataCapturePointName)
{
workPieceLog.CreatedUserName = _DataCapturePointCode;
workPieceLog.DataCapturePointCname = _DataCapturePointName;
}
///
/// 设置WorkPieceLog 的创建人
///
///
///
///
public static void SetWorkPieceLogMiddleForCreatedUserName(ref WorkPieceLog workPieceLog, string _DataCapturePointCode, string _DataCapturePointName)
{
workPieceLog.CreatedUserName = _DataCapturePointCode;
workPieceLog.DataCapturePointCname = _DataCapturePointName;
}
///
/// 设置WorkPieceLog 的更新人
///
///
///
///
public static void SetWorkPieceLogMiddleForUpdatedUserName(ref WorkPieceLogMiddle workPieceLog, string _DataCapturePointCode, string _DataCapturePointName)
{
workPieceLog.UpdatedUserName = _DataCapturePointCode;
workPieceLog.UpdateDataCapturePointCname = _DataCapturePointName;
}
///
/// 是否允许修改WorkPieceState 为WIP
///
///
///
///
///
public static bool IsAllowUpdateWorkPieceStateToWip(WorkPieceInfo info, DbModel db, WorkPieceLogMiddle logMiddle)
{
//这里修复OP10、OP40 因为PLC先推 SPC推出、再推 产品下线问题,导致 产品下线更新数据时,把SPC数据覆盖的问题 【Editby shaocx,2024-08-27】
if (logMiddle.WorkingProcedure == "OP10" || logMiddle.WorkingProcedure == "OP40")
{
var curPross = db.WorkPieceProcess.Where(x => x.WorkPieceID == info.WorkPieceID).OrderByDescending(x => x.Id).FirstOrDefault();
if (curPross != null && curPross.OperationType == OperationType.SPC.ToString())
{
return false;
}
return true;
}
return true;
}
}
}