using Mesnac.Compressor.Data;
using Mesnac.Compressor.Entity;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
namespace Mesnac.Compressor.Station
{
public class NoRFIDStation : Common, IStation
{
///
/// 无RFID托盘的工位直接将产品条码号放到数据表中,没有系统条码之分,这样统计数据只能按最后一次来统计
/// 对于重投次数也不太好统计
///
///
///
public bool PrepareWork(StationInfo station)
{
//先判断后台开关是否打开在进行逻辑验证
bool iflag = IsOpen(station.stationID);
if (iflag)
{
//主线产品码未扫描到条码下发PLC报警
//大转盘壳体条码
if (station.stationID == "1")
{
if (string.IsNullOrEmpty(station.Data.subLineList[1].barcode) || station.Data.subLineList[1].barcode.Equals("ERROR"))
{
ICSharpCode.Core.LoggingService.Error(station.StationCode + "未收到PLC传递的条码");
this.DaoWeiQingQiuHandle(station, (int)DaoWeiResult.NoBarCode);
return false;
}
}
//前盖条码
else if (station.stationID == "5" || station.stationID == "6" || station.stationID == "8" || station.stationID == "9")
{
if (string.IsNullOrEmpty(station.Data.subLineList[2].barcode) || station.Data.subLineList[2].barcode.Equals("ERROR"))
{
ICSharpCode.Core.LoggingService.Error(station.StationCode + "未收到PLC传递的条码");
this.DaoWeiQingQiuHandle(station, (int)DaoWeiResult.NoBarCode);
return false;
}
}
//静盘条码
else if (station.stationID == "11" || station.stationID == "35" || station.stationID == "12")
{
if (string.IsNullOrEmpty(station.Data.subLineList[4].barcode) || station.Data.subLineList[4].barcode.Equals("ERROR"))
{
ICSharpCode.Core.LoggingService.Error(station.StationCode + "未收到PLC传递的条码");
this.DaoWeiQingQiuHandle(station, (int)DaoWeiResult.NoBarCode);
return false;
}
}
//动盘条码
else if (station.stationID == "12")
{
if (!station.Data.DP_OpenFlag)
{
if (string.IsNullOrEmpty(station.Data.subLineList[3].barcode) || station.Data.subLineList[3].barcode.Equals("ERROR"))
{
ICSharpCode.Core.LoggingService.Error(station.StationCode + "未收到PLC传递的条码");
this.DaoWeiQingQiuHandle(station, (int)DaoWeiResult.NoBarCode);
return false;
}
}
}
//后盖条码
else if (station.stationID == "15")
{
if (string.IsNullOrEmpty(station.Data.subLineList[5].barcode) || station.Data.subLineList[5].barcode.Equals("ERROR"))
{
ICSharpCode.Core.LoggingService.Error(station.StationCode + "未收到PLC传递的条码");
this.DaoWeiQingQiuHandle(station, (int)DaoWeiResult.NoBarCode);
return false;
}
}
//判断上一工位开关是否打开
string preStationID = GetFirstStationIDByStationID(station.stationID);
if (!string.IsNullOrEmpty(preStationID))
{
bool iPreflag = IsOpen(preStationID);
if (iPreflag)
{
string LastWorkInfo = "";
if (station.barcodeHead == "A2")
{
//判断是否判断是否有上一工位信息,判断是否合格====通过条码号从上个表里获取数据
LastWorkInfo = LastWorkProductionInfo(station.Data.subLineList[2].barcode, station.PreTableName);
}
else if (station.barcodeHead == "A1")
{
LastWorkInfo = LastWorkProductionInfo(station.Data.ProductBarcode, station.PreTableName);
}
else if (station.barcodeHead == "A3")
{
LastWorkInfo = LastWorkProductionInfo(station.Data.subLineList[4].barcode, station.PreTableName);
}
//没有上工位信息
if (string.IsNullOrEmpty(LastWorkInfo))
{
ICSharpCode.Core.LoggingService.Debug(station.StationCode + "检测无上工位信息");
this.DaoWeiQingQiuHandle(station, (int)DaoWeiResult.PreNoWork);
return false;
}
else
{
//NG物料拿取
if (LastWorkInfo != "1")
{
this.DaoWeiQingQiuHandle(station, (int)DaoWeiResult.TakeNG);
return false;
}
}
}
}
//这里加一个物料是否匹配=======//还要加判断,当前工位是否需要判断
//ICSharpCode.Core.LoggingService.Debug("》》》》》》开始写入PLC反馈信号!");
}
this.DaoWeiQingQiuHandle(station, (int)DaoWeiResult.OK);
//ICSharpCode.Core.LoggingService.Debug("》》》》》》写入PLC反馈信号完成!");
return true;
}
public bool HandleData(StationInfo station)
{
try
{
SqlHelper sh = new SqlHelper();
DbHandler db = new DbHandler();
string LineID = "";
//判断动静盘工位
if (station.stationID == "12")
{
if (!station.Data.DP_OpenFlag)
{
//保存绑定动静盘
//判断是否含有动静盘条码
string DPBarCode = station.Data.subLineList[3].barcode;
string JPBarCode = station.Data.subLineList[4].barcode;
string ProductBarCode = station.Data.ProductBarcode;
db.InsertDJRelationShip(DPBarCode, JPBarCode);
}
}
foreach (subLine s in station.Data.subLineList)
{
if (!string.IsNullOrEmpty(s.barcode) && s.barcode != "")
{
LineID = s.lineID;
//没有托盘的条码只能通过支线条码作为产品主条码
station.Data.ProductBarcode = s.barcode;
//保存物料条码
ICSharpCode.Core.LoggingService.Debug("支线工位:" + station.StationCode + " 物料条码:" +s.barcode);
}
}
//插入新数据
string InsertSql = sh.DataInsertSql2(station);
db.ExecSql(InsertSql);
ICSharpCode.Core.LoggingService.Debug("工位:" + station.StationCode + " 保存数据成功。托盘号:" + station.Data.RFIDNo);
}
catch (Exception e)
{
ICSharpCode.Core.LoggingService.Info(e.ToString());
return false;
}
finally
{
//这里要加一个OK放行
FinishSavePLCWork(station);
}
return true;
}
}
}