123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384 |
- using Cksoft.Data;
- using Cksoft.Unity;
- using DllEapEntity;
- using DllHsms;
- using DllHsmsWeb;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading;
- namespace DllEapDal
- {
- public class MacOrderSendDal
- {
- private IDatabase CurrDb = null;
- public MacOrderSendDal(IDatabase db)
- {
- CurrDb = db;
- }
- public Machine ReadMachine(string maccode, ref string errorinfo)
- {
- //读取机台信息
- string condition = $" and a.fcode='{maccode}'";
- List<Machine> macs = CurrDb.FindListForCondition<Machine>(condition, ref errorinfo).ToList();
- if (macs == null)
- return null;
- if (macs.Count <= 0)
- {
- errorinfo = $"未找到机台编号【{maccode}】的机台信息。";
- return null;
- }
- return macs[0];
- }
- public OrderDetail ReadMachineOrderDetail(int macid, int sval, int fval, ref string errorinfo)
- {
- //读取机台信息
- string condition = $" and a.macid={macid}";
- List<MacOrder> macs = CurrDb.FindListForCondition<MacOrder>(condition, ref errorinfo).ToList();
- if (macs == null)
- return null;
- if (macs.Count <= 0)
- {
- errorinfo = $"未找到机台ID【{macid}】的机台指令信息。";
- return null;
- }
- condition = $" and a.preid={macs[0].PreID} and a.sval={sval} and a.fval={fval}";
- List<OrderDetail> details = CurrDb.FindListForCondition<OrderDetail>(condition, ref errorinfo).ToList();
- if (details == null)
- return null;
- if (details.Count <= 0)
- {
- errorinfo = "未找到您要的指令。";
- return null;
- }
- return details[0];
- }
- public OrderDetail ReadMachineOrderDetail(int macid, int sval, int fval, string fname, ref string errorinfo)
- {
- //读取机台信息
- string condition = $" and a.macid={macid}";
- List<MacOrder> macs = CurrDb.FindListForCondition<MacOrder>(condition, ref errorinfo).ToList();
- if (macs == null)
- return null;
- if (macs.Count <= 0)
- {
- errorinfo = $"未找到机台ID【{macid}】的机台指令信息。";
- return null;
- }
- condition = $" and a.preid={macs[0].PreID} and a.sval={sval} and a.fval={fval} and lower(a.FName)='{fname.ToLower()}'";
- List<OrderDetail> details = CurrDb.FindListForCondition<OrderDetail>(condition, ref errorinfo).ToList();
- if (details == null)
- return null;
- if (details.Count <= 0)
- {
- errorinfo = "未找到您要的指令。";
- return null;
- }
- return details[0];
- }
- public int SendStopMac(string maccode, ref string errorinfo)
- {
- try
- {
- Machine mac = ReadMachine(maccode, ref errorinfo);
- if (mac == null)
- return -1;
- OrderDetail order = ReadMachineOrderDetail(mac.ID, 2, 41, "s2f41stop", ref errorinfo);
- if (order == null)
- return -1;
- //从机型参数中读取程序参数信息
- string condition = $" and a.preid={order.ID}";
- List<OrderData> datas = CurrDb.FindListForCondition<OrderData>(condition, ref errorinfo).ToList();
- if (datas == null)
- return -1;
- HsmsWeb accessmac = new HsmsWeb();
- OrderBlock rec = accessmac.SendOrderFor(mac.FCode, order, datas, ref errorinfo);
- if (rec == null)
- return -1;
- return 1;
- }
- catch (Exception ex)
- {
- errorinfo = ex.Message.ToString();
- return -1;
- }
- }
- public int SendResumeMac(string maccode, ref string errorinfo)
- {
- try
- {
- Machine mac = ReadMachine(maccode, ref errorinfo);
- if (mac == null)
- return -1;
- OrderDetail order = ReadMachineOrderDetail(mac.ID, 2, 41, "s2f41resume", ref errorinfo);
- if (order == null)
- return -1;
- //从机型参数中读取程序参数信息
- string condition = $" and a.preid={order.ID}";
- List<OrderData> datas = CurrDb.FindListForCondition<OrderData>(condition, ref errorinfo).ToList();
- if (datas == null)
- return -1;
- HsmsWeb accessmac = new HsmsWeb();
- OrderBlock rec = accessmac.SendOrderFor(mac.FCode, order, datas, ref errorinfo);
- if (rec == null)
- return -1;
- return 1;
- }
- catch (Exception ex)
- {
- errorinfo = ex.Message.ToString();
- return -1;
- }
- }
- public int SendS10F3(string maccode,string info, ref string errorinfo)
- {
- try
- {
- Machine mac = ReadMachine(maccode, ref errorinfo);
- if (mac == null)
- return -1;
- OrderDetail order = ReadMachineOrderDetail(mac.ID, 10, 3, "s10f3", ref errorinfo);
- if (order == null)
- return -1;
- //从机型参数中读取程序参数信息
- string condition = $" and a.preid={order.ID}";
- List<OrderData> datas = CurrDb.FindListForCondition<OrderData>(condition, ref errorinfo).OrderBy(t => t.FNum).ToList();
- if (datas == null)
- return -1;
- List<OrderData> tempdatas = datas.Where(t => t.ParentID == 0).ToList();
- tempdatas = datas.Where(t => t.ParentID == tempdatas[0].ID).OrderBy(t => t.FNum).ToList();
- tempdatas[1].FContent = info;
- tempdatas[1].FLen = info.Length;
- HsmsWeb accessmac = new HsmsWeb();
- OrderBlock rec = accessmac.SendOrderFor(mac.FCode, order, datas, ref errorinfo);
- if (rec == null)
- return -1;
- if(rec.Datalists[0].FContent!="00")
- {
- errorinfo = rec.Datalists[0].FContent;
- return -1;
- }
- return 1;
- }
- catch (Exception ex)
- {
- errorinfo = ex.Message.ToString();
- return -1;
- }
- }
- public List<OrderData> SendOrder(Machine mac, int sval,int fval,string fname, ref string errorinfo)
- {
- try
- {
- OrderDetail order = ReadMachineOrderDetail(mac.ID, sval, fval, fname, ref errorinfo);
- if (order == null)
- return null;
- //从机型参数中读取程序参数信息
- string condition = $" and a.preid={order.ID}";
- List<OrderData> datas = CurrDb.FindListForCondition<OrderData>(condition, ref errorinfo).OrderBy(t => t.FNum).ToList();
- if (datas == null)
- return null;
- HsmsWeb accessmac = new HsmsWeb();
- OrderBlock rec = accessmac.SendOrderFor(mac.FCode, order, datas, ref errorinfo);
- if (rec == null)
- return null;
- return rec.Datalists;
- }
- catch (Exception ex)
- {
- errorinfo = ex.Message.ToString();
- return null;
- }
- }
- public int SendS7F5(string maccode, string programname, ref string errorinfo)
- {
- try
- {
- Machine mac = ReadMachine(maccode, ref errorinfo);
- if (mac == null)
- return -1;
- OrderDetail order = ReadMachineOrderDetail(mac.ID, 7, 5, "s7f5", ref errorinfo);
- if (order == null)
- return -1;
- //从机型参数中读取程序参数信息
- string condition = $" and a.preid={order.ID}";
- List<OrderData> datas = CurrDb.FindListForCondition<OrderData>(condition, ref errorinfo).OrderBy(t => t.FNum).ToList();
- if (datas == null)
- return -1;
- datas[0].FContent = programname;
- datas[0].FLen = programname.Length;
- //List<OrderData> tempdatas = datas.Where(t => t.ParentID == 0).ToList();
- //tempdatas = datas.Where(t => t.ParentID == tempdatas[0].ID).OrderBy(t => t.FNum).ToList();
- //tempdatas[0].FContent = programname;
- //tempdatas[0].FLen = programname.Length;
- HsmsWeb accessmac = new HsmsWeb();
- int result = accessmac.SendOrderNoAnswer(mac.FCode, order, datas, ref errorinfo);
- if (result <=0)
- return -1;
- return 1;
- }
- catch (Exception ex)
- {
- errorinfo = ex.Message.ToString();
- return -1;
- }
- }
- public List<MacParam> GetParamValue(string macCode, List<MacParam> paramlists,ref string errorinfo)
- {
- try
- {
- string condition = $" and a.fcode='{macCode}'";
- List<Machine> macs = CurrDb.FindListForCondition<Machine>(condition, ref errorinfo).ToList();
- if (macs == null || macs.Count <= 0)
- {
- errorinfo = $"在EAP系统中,未找到机台编号为【{macCode}】的机台信息。";
- return null;
- }
- string fcode = "";
- foreach (var item in paramlists)
- {
- if (fcode == "")
- fcode = $"'{item.FCode}'";
- else
- fcode = $"{fcode},'{item.FCode}'";
- }
- condition = $" and b.FCode in({fcode}) and a.PreID={macs[0].MModeID}";
- List<MMSecDetail> secdetails = CurrDb.FindListForCondition<MMSecDetail>(condition, ref errorinfo).ToList();
- if (secdetails == null || secdetails.Count <= 0)
- {
- errorinfo = $"在EAP系统中,未找您给的参数代码【{fcode}】。";
- return null;
- }
- List<MMSecDetail> svids = secdetails.Where(t => t.SecFType == SecType.SVID).ToList();
- if (svids.Count > 0)
- {
- //从机台中取值
- svids = ReadDataFor(macs[0], svids, SecType.SVID, ref errorinfo);
- if (svids == null)
- return null;
- }
- List<MMSecDetail> ecids = secdetails.Where(t => t.SecFType == SecType.ECID).ToList();
- if (ecids.Count > 0)
- {
- //从机台中取值
- ecids = ReadDataFor(macs[0], ecids, SecType.ECID, ref errorinfo);
- if (ecids == null)
- return null;
- }
- foreach(var item in paramlists)
- {
- var templist = secdetails.Where(t => t.SecFCode == item.FCode).ToList();
- if (templist.Count > 0)
- item.FValue = templist[0].Remark;
- }
- return paramlists;
- }
- catch (Exception ex)
- {
- errorinfo = ex.Message.ToString();
- return null;
- }
- }
- private List<OrderData> GetData(List<MMSecDetail> mmsecs, int preid, ref string errorinfo)
- {
- List<OrderData> ldata = new List<OrderData>();
- OrderData lentity = new OrderData();
- lentity.ID = 1;
- lentity.ParentID = 0;
- lentity.PreID = preid;
- lentity.FCode = "L";
- lentity.FLen = 1;
- ldata.Add(lentity);
- int id = 2;
- int fnum = 0;
- foreach (var item in mmsecs)
- {
- id++;
- fnum += 10;
- OrderData entity = new OrderData();
- entity.ID = id;
- entity.ParentID = 1;
- entity.FNum = fnum;
- entity.PreID = preid;
- entity.FCode = item.DCode;
- entity.FContent = item.FVal;
- entity.FLen = 1;
- ldata.Add(entity);
- }
- return ldata;
- }
- //db机台主动取数据
- private List<MMSecDetail> ReadDataFor(Machine mac, List<MMSecDetail> mmsecs, int ftype, ref string errorinfo)
- {
- try
- {
- int sval = 1;
- int fval = 3;
- if (ftype == SecType.ECID)
- {
- sval = 2;
- fval = 13;
- }
- string condition = $" and a.preid=(SELECT preid FROM macorder where macid={mac.ID}) and a.sval={sval} and a.fval={fval}";
- List<OrderDetail> orders = CurrDb.FindListForCondition<OrderDetail>(condition, ref errorinfo).ToList();
- if (orders.Count <= 0)
- {
- errorinfo = $"未找到机台{mac.FCode}对应的S{sval}F{fval}指令。";
- return null;
- }
- List<OrderData> datas = GetData(mmsecs, orders[0].ID, ref errorinfo);
- if (datas == null)
- return null;
- HsmsWeb accessmac = new HsmsWeb();
- OrderBlock rec = accessmac.SendOrderFor(mac.FCode, orders[0], datas, ref errorinfo);
- if (rec == null)
- return null;
- for (int i = 1; i < rec.Datalists.Count; i++)
- {
- mmsecs[i - 1].Remark = rec.Datalists[i].FContent;
- }
- return mmsecs;
- }
- catch (Exception ex)
- {
- errorinfo = ex.Message.ToString();
- return null;
- }
- }
- public int SendS10F3NoAnswer(string maccode, string info, ref string errorinfo)
- {
- try
- {
- Machine mac = ReadMachine(maccode, ref errorinfo);
- if (mac == null)
- return -1;
- OrderDetail order = ReadMachineOrderDetail(mac.ID, 10, 3, "s10f3", ref errorinfo);
- if (order == null)
- return -1;
- //从机型参数中读取程序参数信息
- string condition = $" and a.preid={order.ID}";
- List<OrderData> datas = CurrDb.FindListForCondition<OrderData>(condition, ref errorinfo).OrderBy(t => t.FNum).ToList();
- if (datas == null)
- return -1;
- List<OrderData> tempdatas = datas.Where(t => t.ParentID == 0).ToList();
- tempdatas = datas.Where(t => t.ParentID == tempdatas[0].ID).OrderBy(t => t.FNum).ToList();
- tempdatas[1].FContent = info;
- tempdatas[1].FLen = info.Length;
- HsmsWeb accessmac = new HsmsWeb();
- return accessmac.SendOrderNoAnswer(mac.FCode, order, datas, ref errorinfo);
- }
- catch (Exception ex)
- {
- errorinfo = ex.Message.ToString();
- return -1;
- }
- }
- }
- }
|