You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

197 lines
8.5 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Mesnac.Codd.Session;
using System.Data;
using Mesnac.Action.Feeding.Qingquan.BasicInfo;
using Mesnac.Action.Feeding.Qingquan.FeedingPlc;
namespace Mesnac.Action.Feeding.Qingquan.LockScales
{
/// <summary>
/// 条码检测辅助类
/// </summary>
public class CheckBarcodeHelper
{
#region 静态字段定义
private static bool _isBarcodeContrl = false; //是否进行条码控制
private static int cntGetBarcd = 0; //获取扫描物料列表计时器
private static int cntControl = 0; //获取条码控制计时变量
private static bool existsMater = false; //是否存在物料
private static bool havaUseOut = true; //是否存在使用完毕的物料有则为false
#endregion
#region 静态属性定义
/// <summary>
/// 是否进行条码控制
/// </summary>
public static bool IsBarcodeContrl
{
get { return CheckBarcodeHelper._isBarcodeContrl; }
}
#endregion
/// <summary>
/// 检查条码控制
/// </summary>
public static void CheckBarcode()
{
List<string> msgList = new List<string>(); //消息提示
int RubSL = 0;
bool result = false;
PlanCommon.GetScanBarcode(); //相当于每2秒从扫描的条码表中获取未使用的物料
cntControl++; //累加条码控制计时变量
if (cntControl >= 6)
{
_isBarcodeContrl = GetBarContrl() >= 1; //相当于每12秒从表Ppt_equipstate读取该机台“是否控制条码必须扫描”
cntControl = 0;
}
if (!_isBarcodeContrl)
{
RubSL = RunShuSongHandler.UpLoadRubSL();
if (RubSL == 1)
{
result = RunShuSongHandler.DownloadRubSL(); //将送料信号准备好标志置0 双方约定
result = RunShuSongHandler.DownloadRubShuSong(1, "取消锁A"); //取消胶料秤控制,即放行
}
//隐藏画面2的条码扫描报警信息
PlcData.Instance.PlcVarWriteByDataKey(PlcData.Instance.ScanBarcodeAlarmInfo, String.Empty); //把扫描报警信息写入PLC变量并不真正下传至PLC
return;
}
#region 和配方中的物料相比较判断是否部分物料是否使用完毕某些物料使用完毕haveUseOut置为False
FeedingAction action = new FeedingAction();
havaUseOut = true;
if (action.NetType == Base.BaseAction.NetTypes.Net)
{
List<RecipeData.RecipeWeightInfo> lst = RecipeCache.Instance.AllWeightInfo;
foreach (RecipeData.RecipeWeightInfo item in lst)
{
if (item.WeightType == (int)RecipeData.WeightType. || item.WeightType == (int)RecipeData.WeightType.)
{
if (!Global.PublicVar.Instance.G_lstRubCtrl.Contains(item.MaterialCode.Trim()))
{
//msgList.Add(item.MaterialCode.Trim()); //把没有扫描的物料编码放入消息列表中
msgList.Add(item.MaterialName.Trim()); //把没有扫描的物料名称放入消息列表中
havaUseOut = false;
}
}
}
}
#endregion
RubSL = RunShuSongHandler.UpLoadRubSL();
if (RubSL == 1 && Global.PublicVar.Instance.G_DownloadSL == 0 && havaUseOut)
{
Global.PublicVar.Instance.G_DownloadSL = 1;
CreatePreTrace(); //送料信号准备好形成预追溯
result = RunShuSongHandler.DownloadRubSL(); //将送料信号准备好标志置0 双方约定
result = RunShuSongHandler.DownloadRubShuSong(1, "解锁B"); //取消胶料秤控制,即放行
//隐藏画面2的条码扫描报警信息
PlcData.Instance.PlcVarWriteByDataKey(PlcData.Instance.ScanBarcodeAlarmInfo, String.Empty); //把扫描报警信息写入PLC变量并不真正下传至PLC
}
int shuSong = RunShuSongHandler.UpLoadRubSLAllow();
if (shuSong != 1)
{
Global.PublicVar.Instance.G_DownloadSL = 0;
}
if (!havaUseOut && Global.PublicVar.Instance.G_DownloadSL == 0)
{
string strMsg = PlanCommon.CombineMsgList(msgList, "\r\n");
strMsg += "\r\n" + "条码没有扫描,胶料秤锁定";
PlcData.Instance.PlcVarWriteByDataKey(PlcData.Instance.ScanBarcodeAlarmInfo, strMsg); //把扫描报警信息写入PLC变量并不真正下传至PLC
}
else if (havaUseOut)
{
PlcData.Instance.PlcVarWriteByDataKey(PlcData.Instance.ScanBarcodeAlarmInfo, String.Empty); //把扫描报警信息写入PLC变量并不真正下传至PLC
}
}
#region 从网络库查询配置是否控制条码必须扫描(获取锁秤标志)
/// <summary>
/// 从网络库查询配置是否控制条码必须扫描(获取锁秤标志)
/// </summary>
/// <returns>执行错误返回-10:不锁秤,>1锁秤</returns>
public static int GetBarContrl()
{
try
{
FeedingAction action = new FeedingAction();
if (action.NetType == Base.BaseAction.NetTypes.Local)
{
ICSharpCode.Core.LoggingService.Warn("单机版无法从网络库获取锁秤标志。");
return -1;
}
DbHelper serverHelper = action.NewDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Server);
if (serverHelper == null)
{
ICSharpCode.Core.LoggingService.Error("获取锁秤标志失败:获取网络数据库连接失败。");
return -1;
}
serverHelper.ClearParameter();
serverHelper.CommandType = System.Data.CommandType.Text;
string strSql = "select BarCtl from ppt_equipstate where equip_Code= @EquipCode";
serverHelper.CommandText = strSql;
serverHelper.AddParameter("@EquipCode", action.CurrEquipCode);
object oResult = serverHelper.ToScalar();
if (oResult == null || oResult == System.DBNull.Value)
{
ICSharpCode.Core.LoggingService.Warn("获取锁秤标志失败:网络库中不存在此机台的对应的锁秤标记记录。");
return -1;
}
int intResult = 0;
int.TryParse(oResult.ToString(), out intResult);
return intResult;
}
catch (Exception ex)
{
ICSharpCode.Core.LoggingService.Error(String.Format("获取锁秤标志失败:{0}", ex.Message));
return -1;
}
}
#endregion
#region 形成预追溯
/// <summary>
/// 形成预追溯
/// </summary>
public static void CreatePreTrace()
{
FeedingAction action = new FeedingAction();
try
{
if (action.NetType == Base.BaseAction.NetTypes.Local)
{
ICSharpCode.Core.LoggingService.Warn("单机版无法形成预追溯。");
return;
}
string procedureName = "Proc_PreBarTrace_1"; //预追溯存储过程名
Dictionary<string, object> paras = new Dictionary<string, object>();
paras.Add("@Equip_code", action.CurrEquipCode); //机台号
int currNum = PlcData.Instance.PloyFinishedCount.LastValue.ToInt() + 1;
paras.Add("@CurNum", currNum); //当前车数
action.ExecuteProcedure(Basic.DataSourceFactory.MCDbType.Server, procedureName, paras);
}
catch (Exception ex)
{
ICSharpCode.Core.LoggingService.Error("形成预追溯失败:" + ex.Message);
action.DBLog("错误日志", "预追溯", ex.Message);
}
}
#endregion
}
}