using Cksoft.Data;
using Cksoft.Unity;
using DllEapEntity;
using System;
using System.Collections.Generic;
using System.Linq;
using DllEapEntity.Dtos;
using DllHsmsWeb;
using DllHsms;
namespace DllEapDal
{
public class MacCountDal
{
private IDatabase CurrDb = null;
public MacCountDal(IDatabase db)
{
CurrDb = db;
}
///
/// 根据机台ID,读取机台数据,并保存
///
/// 机台编号
/// trackinout id
/// 用户编号
///
///
public int IMacCount(Machine mac, string usercode, ref string errorinfo)
{
try
{
HsmsWeb hsms = new HsmsWeb();
string condition = $" and b.FCode='{mac.FCode}'";
List mst = CurrDb.FindListForCondition(condition, ref errorinfo).ToList();
if (mst.Count <= 0)
{
errorinfo = $"机台【{mac.FCode}】没有对应的指令【S1F3】。";
return -1;
}
int ordermstid = mst[0].PreID;//机台对应的指令主档ID
condition = $@" and {EntityAttribute.GetPropertyCondition(nameof(OrderDetail.PreID))}={ordermstid}
and {EntityAttribute.GetPropertyCondition(nameof(OrderDetail.SVal))}=1
and {EntityAttribute.GetPropertyCondition(nameof(OrderDetail.FVal))}=3";
List orders = CurrDb.FindListForCondition(condition, ref errorinfo).ToList();
if (orders.Count <= 0)
{
errorinfo = $"机台【{mac.FCode}】没有对应的指令【S1F3】。";
return -1;
}
//读取指令参数列表
condition = $" and b.FCode='{StandardCode.SVID_FinishUnit}' and a.preid={mac.MModeID}";
List detailsec = CurrDb.FindListForCondition(condition, ref errorinfo).ToList();
List datas = HsmsUnity.GetOrderS1F3Data(detailsec, ref errorinfo);
OrderBlock result = hsms.SendOrderFor(mac.FCode, orders[0], datas, ref errorinfo);
if (result == null)
return -1;
//List tempdatas = result.Datalists.Where(t => t.ParentID == 0).ToList();
//if (tempdatas.Count <= 0)
//{
// errorinfo = $"指令返回的数据中,没找到L数据。";
// return -1;
//}
//string fcount = tempdatas[0].FContent;
string fcount = result.Datalists[1].FContent;
MacCount maccount = new MacCount();
maccount.FCount = int.Parse(fcount);
maccount.MacID = mac.ID;
maccount.ParamCode = StandardCode.SVID_FinishUnit;
maccount.FDate = DateTime.Now;
CurrDb.InsertFor(maccount, usercode);
return 1;
}
catch (Exception ex)
{
errorinfo = ex.Message.ToString();
return -1;
}
}
public IEnumerable Get(string filter, ref string errorinfo)
{
return CurrDb.FindListForCondition(filter, ref errorinfo);
}
}
}