1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303 |
- using Cksoft.Data;
- using Cksoft.Unity;
- using DllEapEntity;
- using DllEapEntity.Rms;
- using DllHsms;
- using DllHsmsWeb;
- using Microsoft.Extensions.Logging;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using ZipFileHelper;
- namespace DllEapDal
- {
- public class ProgramDal
- {
- private IDatabase CurrDb = null;
- public ProgramDal(IDatabase db)
- {
-
- CurrDb = db;
- loger = AppConfigurtaionServices.MyLog;// (ILogger)AppConfigurtaionServices.Instance.GetService(typeof(ILogger<ProgramDal>));// (ILogger)log4net.LogManager.GetLogger(typeof(ProgramDal));
- //loger.LogError("自己创建loger实例......");
- //loger.LogError("自己创建loger实例......2222");
- }
- private ILogger loger = null;
- public ProgramDal(IDatabase db,ILogger loger)
- {
- CurrDb = db;
- this.loger = loger;
- }
- 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];
- }
- /// <summary>
- /// 获取请求机台程序的指令数据
- /// </summary>
- /// <param name="programname"></param>
- /// <param name="preid"></param>
- /// <param name="errorinfo"></param>
- /// <returns></returns>
- private List<OrderData> GetS2F41Data(string programname, int preid, ref string errorinfo)
- {
- string rcmd = "PP_PREP";
- List<OrderData> ldata = new List<OrderData>();
- OrderData lentity = new OrderData();
- lentity.ID = 1;
- lentity.ParentID = 0;
- lentity.PreID = preid;
- lentity.FCode = "L";
- lentity.FLen = 2;
- ldata.Add(lentity);
- OrderData entity = new OrderData();
- entity.ID = 2;
- entity.ParentID = 1;
- entity.FNum = 10;
- entity.PreID = preid;
- entity.FCode = "A";
- entity.FContent = rcmd;
- entity.FLen = rcmd.Length;
- ldata.Add(entity);
- entity = new OrderData();//添加L节点
- entity.ID = 3;
- entity.ParentID = 1;
- entity.FNum = 20;
- entity.PreID = preid;
- entity.FCode = "L";
- entity.FLen = 1;
- ldata.Add(entity);
- entity = new OrderData();//添加L节点
- entity.ID = 4;
- entity.ParentID = 3;
- entity.FNum = 10;
- entity.PreID = preid;
- entity.FCode = "L";
- entity.FLen = 2;
- ldata.Add(entity);
- string cpname = "PPID";
- entity = new OrderData();
- entity.ID = 5;
- entity.ParentID = 4;
- entity.FNum = 10;
- entity.PreID = preid;
- entity.FCode = "A";
- entity.FContent = cpname;
- entity.FLen = cpname.Length;
- ldata.Add(entity);
- entity = new OrderData();
- entity.ID = 6;
- entity.ParentID = 4;
- entity.FNum = 20;
- entity.PreID = preid;
- entity.FCode = "A";
- entity.FContent = programname;
- entity.FLen = programname.Length;
- ldata.Add(entity);
- return ldata;
- }
- /// <summary>
- /// DP机台装载程序指令数据
- /// </summary>
- /// <param name="programname">要装载的程序名称</param>
- /// <param name="preid"></param>
- /// <param name="errorinfo"></param>
- /// <returns></returns>
- private List<OrderData> GetS2F41DataForPPSelect(string programname, int preid, ref string errorinfo)
- {
- string rcmd = "PP_SELECT";
- List<OrderData> ldata = new List<OrderData>();
- OrderData lentity = new OrderData();
- lentity.ID = 1;
- lentity.ParentID = 0;
- lentity.PreID = preid;
- lentity.FCode = "L";
- lentity.FLen = 2;
- ldata.Add(lentity);
- OrderData entity = new OrderData();
- entity.ID = 2;
- entity.ParentID = 1;
- entity.FNum = 10;
- entity.PreID = preid;
- entity.FCode = "A";
- entity.FContent = rcmd;
- entity.FLen = rcmd.Length;
- ldata.Add(entity);
- entity = new OrderData();//添加L节点
- entity.ID = 3;
- entity.ParentID = 1;
- entity.FNum = 20;
- entity.PreID = preid;
- entity.FCode = "L";
- entity.FLen = 1;
- ldata.Add(entity);
- entity = new OrderData();//添加L节点
- entity.ID = 4;
- entity.ParentID = 3;
- entity.FNum = 10;
- entity.PreID = preid;
- entity.FCode = "L";
- entity.FLen = 2;
- ldata.Add(entity);
- string cpname = "PPID";
- entity = new OrderData();
- entity.ID = 5;
- entity.ParentID = 4;
- entity.FNum = 10;
- entity.PreID = preid;
- entity.FCode = "A";
- entity.FContent = cpname;
- entity.FLen = cpname.Length;
- ldata.Add(entity);
- entity = new OrderData();
- entity.ID = 6;
- entity.ParentID = 4;
- entity.FNum = 20;
- entity.PreID = preid;
- entity.FCode = "A";
- entity.FContent = programname;
- entity.FLen = programname.Length;
- ldata.Add(entity);
- return ldata;
- }
- private List<OrderData> GetS2F41DataForHit(int preid,string rcmd, ref string errorinfo)
- {
- //string rcmd = "ENTER_HIT";
- List<OrderData> ldata = new List<OrderData>();
- OrderData lentity = new OrderData();
- lentity.ID = 1;
- lentity.ParentID = 0;
- lentity.PreID = preid;
- lentity.FCode = "L";
- lentity.FLen = 2;
- ldata.Add(lentity);
- OrderData entity = new OrderData();
- entity.ID = 2;
- entity.ParentID = 1;
- entity.FNum = 10;
- entity.PreID = preid;
- entity.FCode = "A";
- entity.FContent = rcmd;
- entity.FLen = rcmd.Length;
- ldata.Add(entity);
- entity = new OrderData();//添加L节点
- entity.ID = 3;
- entity.ParentID = 1;
- entity.FNum = 20;
- entity.PreID = preid;
- entity.FCode = "L";
- entity.FLen = 0;
- ldata.Add(entity);
- return ldata;
- }
- private List<OrderData> GetS7F5Data(string programname, 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 = "A";
- lentity.FContent = programname;
- lentity.FLen = programname.Length;
- ldata.Add(lentity);
- return ldata;
- }
- /// <summary>
- /// 将机台设置为1086参数
- /// </summary>
- /// <param name="mac"></param>
- /// <param name="errorinfo"></param>
- /// <returns></returns>
- private int SetEc1086(Machine mac, ref string errorinfo)
- {
- try
- {
- HsmsWeb accessmac = new HsmsWeb();
- //发送指令,将程序模式设置为hit模式
- OrderDetail order = ReadMachineOrderDetail(mac.ID, 2, 41, ref errorinfo);
- List<OrderData> datas = GetS2F41DataForHit(order.PreID, "ENTER_HIT", ref errorinfo);
- OrderBlock rec = accessmac.SendOrderFor(mac.FCode, order, datas, ref errorinfo);
- if (rec == null)
- return -1;
- int result = int.Parse(rec.Datalists[1].FContent);
- if (result > 0)
- {
- errorinfo = $"将机台设置为HIT模式出错,错误代码为:{result}";
- return -1;
- }
- return 1;
- }
- catch (Exception ex)
- {
- errorinfo = ex.Message.ToString();
- return -1;
- }
- }
- /// <summary>
- /// 发送指令
- /// </summary>
- /// <param name="mac"></param>
- /// <param name="errorinfo"></param>
- /// <returns></returns>
- public int SendOrder(Machine mac,int sval,int fval, ref string errorinfo)
- {
- try
- {
- string condition = $"";
- List<MacOrder> macorder = CurrDb.FindListForCondition<MacOrder>(condition, ref errorinfo).ToList();
- if(macorder.Count<=0)
- {
- errorinfo = $"未找到机台【{mac.FCode}】对应的指令。";
- return -1;
- }
- condition = $" and a.preid={macorder[0].PreID} and a.sval={sval} and a.fval={fval}";
- List<OrderDetail> order = CurrDb.FindListForCondition<OrderDetail>(condition, ref errorinfo).ToList();
- if(order.Count<=0)
- {
- errorinfo = $"未找到机台【{mac.FCode}】对应的S2F15指令。";
- return -1;
- }
- condition = $" and a.preid={order[0].ID}";
- List<OrderData> datas = CurrDb.FindListForCondition<OrderData>(condition, ref errorinfo).ToList();
- HsmsWeb accessmac = new HsmsWeb();
- OrderBlock rec = accessmac.SendOrderFor(mac.FCode, order[0], datas, ref errorinfo);
- if (rec == null)
- return -1;
- int result = int.Parse(rec.Datalists[0].FContent);
- if (result > 0)
- {
- errorinfo = $"设置机台ECID参数出错,错误代码为:{result}";
- return -1;
- }
- return 1;
- }
- catch (Exception ex)
- {
- errorinfo = ex.Message.ToString();
- return -1;
- }
- }
- /// <summary>
- /// 将机台设置为HIT模式
- /// </summary>
- /// <param name="mac"></param>
- /// <param name="errorinfo"></param>
- /// <returns></returns>
- private int SetHit(Machine mac,string rcmd,ref string errorinfo)
- {
- try
- {
- HsmsWeb accessmac = new HsmsWeb();
- //发送指令,将程序模式设置为hit模式
- OrderDetail order = ReadMachineOrderDetail(mac.ID, 2, 41, ref errorinfo);
- List<OrderData> datas = GetS2F41DataForHit(order.PreID, rcmd, ref errorinfo);
- OrderBlock rec = accessmac.SendOrderFor(mac.FCode, order, datas, ref errorinfo);
- if (rec == null)
- return -1;
- int result = int.Parse(rec.Datalists[1].FContent);
- if (result == 5)
- return 1;
- if (result == 0)
- return 1;
- return -1;
- }
- catch(Exception ex)
- {
- errorinfo = ex.Message.ToString();
- return -1;
- }
- }
- /// <summary>
- /// 获取机台当前使用的程序文件,并将文件放到指定的目录
- /// </summary>
- /// <param name="mac"></param>
- /// <param name="errorinfo"></param>
- /// <returns></returns>
- public string ReadProgramFromMac(Machine mac,ProgramMst program,string desdir,ref string errorinfo)
- {
- try
- {
- HsmsWeb accessmac = new HsmsWeb();
- //发送指令,将程序模式设置为hit模式
- //OrderDetail order = ReadMachineOrderDetail(mac.ID, 2, 41, ref errorinfo);
- //List<OrderData> datas = GetS2F41DataForHit(program.FName, order.PreID, ref errorinfo);
- //OrderBlock rec = accessmac.SendOrderFor(mac.FCode, order, datas, ref errorinfo);
- //if (rec == null)
- // return null;
- //int result = int.Parse(rec.Datalists[1].FContent);
- //if(result>0)
- //{
- // errorinfo = $"将机台设置为HIT模式出错,错误代码为:{result}";
- // return null;
- //}
- int result = SetHit(mac, "ENTER_HIT", ref errorinfo);
- if(result<=0)
- {
- return null;
- }
- //发送取程序的指令
- OrderDetail order = ReadMachineOrderDetail(mac.ID, 2, 41, ref errorinfo);
- List<OrderData> datas = GetS2F41Data(program.FName, order.PreID, ref errorinfo);
- OrderBlock rec = accessmac.SendOrderFor(mac.FCode, order, datas, ref errorinfo);
- if (rec == null)
- return null;
- result = int.Parse(rec.Datalists[1].FContent);
- if (result != 0&& result != 4)
- {
- errorinfo = $"下载程序不成功,错误代码为:{rec.Datalists[1].FContent}。";
- return null;
- }
- if(result==4)
- {
- //说明机台已经开始处理程序,休眠5秒钟,等待机台处理
- //或等待处理完成事件上来
- Thread.Sleep(1000 * 5);
- }
- order = ReadMachineOrderDetail(mac.ID, 7, 5, ref errorinfo);
- datas = GetS7F5Data(program.FName, order.PreID, ref errorinfo);
- rec = accessmac.SendOrderFor(mac.FCode, order, datas, ref errorinfo);
- if (rec == null)
- return null;
- datas = rec.Datalists;
- if(datas[0].FLen==0)
- {
- errorinfo = "未能正确的获取程序文件。";
- return "";
- }
- result = UnityHelper.WriteFile(desdir, program.FName, datas[2].OrgDatas, ref errorinfo);
- if (result <= 0)
- return null;
- return program.FName;
- }
- catch(Exception ex)
- {
- errorinfo = ex.Message.ToString();
- return "";
- }
- }
- /// <summary>
- /// 获取程序参数
- /// </summary>
- /// <param name="mac"></param>
- /// <param name="program"></param>
- /// <param name="desdir"></param>
- /// <param name="errorinfo"></param>
- /// <returns></returns>
- public List<FileParams> GetProgramParams(string rarpath,Machine mac, ProgramMst program, string desdir, ref string errorinfo)
- {
- try
- {
- string programname = ReadProgramFromMac(mac, program, desdir, ref errorinfo);
- if (string.IsNullOrEmpty(programname))
- return null;
- string filepath = desdir + "\\" + programname;
- string tempdesdir = desdir + "\\temp";
- List<FileParams> filesdata = UnCompressForKs.GetParamsFor(rarpath, filepath, programname
- , tempdesdir, mac.MModeID, ref errorinfo);
- return filesdata;
- }
- catch (Exception ex)
- {
- errorinfo = ex.Message.ToString();
- return null;
- }
- }
- /// <summary>
- /// 根据机台编号、产品编号、制程代码等信息查找程序,返回程序ID
- /// </summary>
- /// <param name="maccode"></param>
- /// <param name="partcode"></param>
- /// <param name="pcode"></param>
- /// <param name="errorinfo"></param>
- /// <returns></returns>
- public ProgramMst FindProgram(Machine mac, string partcode, string pcode, ref string errorinfo)
- {
- try
- {
- string condition = $" and b.ModelID={mac.MModeID} and b.ProcessCode='{pcode}'";
- List<ProgramRule> rules = CurrDb.FindListForCondition<ProgramRule>(condition, ref errorinfo).ToList();
- if (rules == null)
- return null;
- if (rules.Count <= 0)
- {
- errorinfo = "未找到对应的程序规则。";
- return null;
- }
- //先精确匹配产品编号
- List<ProgramRule> templist = rules.Where(t => t.PartCode == partcode).ToList();
- if (templist.Count > 0)
- return CurrDb.FindEntityFor<ProgramMst>(templist[0].ProgramMstID);
- //取模糊匹配的规则
- rules = rules.Where(t => t.PartCode.Contains("%")).ToList();
- if (rules.Count <= 0)
- {
- errorinfo = "未找到对应的程序规则。";
- return null;
- }
- //去掉规则里产品编号的“%”符号
- foreach (var item in rules)
- {
- item.PartCode = item.PartCode.Replace("%", "");
- }
- //排序规则列表,按产品编号长度从大到小排列
- rules = rules.OrderByDescending(t => t.PartCode.Length).ToList();
- foreach (var item in rules)
- {
- if (partcode.Contains(item.PartCode))
- {
- return CurrDb.FindEntityFor<ProgramMst>(item.ProgramMstID);
- }
- }
- errorinfo = "未找到对应的程序规则。";
- return null;
- }
- catch (Exception ex)
- {
- errorinfo = ex.Message.ToString();
- return null;
- }
- }
- /// <summary>
- /// 根据机台编号读取机台
- /// </summary>
- /// <param name="maccode"></param>
- /// <param name="errorinfo"></param>
- /// <returns></returns>
- public Machine ReadMachine(string maccode, ref string errorinfo)
- {
- try
- {
- string condition = $" and a.fcode='{maccode}'";
- List<Machine> macs = CurrDb.FindListForCondition<Machine>(condition, ref errorinfo).ToList();
- if (macs == null)
- {
- errorinfo = $"未找到机台编号【{maccode}】的机台信息。";
- return null;
- }
- if (macs.Count <= 0)
- {
- errorinfo = $"未找到机台编号【{maccode}】的机台信息。";
- return null;
- }
- return macs[0];
- }
- catch (Exception ex)
- {
- errorinfo = ex.Message.ToString();
- return null;
- }
- }
- private void SendInfo(string maccode,string info)
- {
- try
- {
- MacOrderSendDal senddal = new MacOrderSendDal(CurrDb);
- string temperrorinfo = "";
- senddal.SendS10F3(maccode, info, ref temperrorinfo);
- }
- catch
- {
- return;
- }
- }
- public string GetMacStatus(Machine mac, ref string errorinfo)
- {
- try
- {
- OrderDetail order = ReadMachineOrderDetail(mac.ID, 1, 3, ref errorinfo);
- if (order == null)
- return "";
- string condition = $" and a.PreID={mac.MModeID} and b.FCode='{StandardCode.SVID_CurrentStatus}'";
- List<MMSecDetail> mmsecs = CurrDb.FindListForCondition<MMSecDetail>(condition, ref errorinfo).ToList();
- if (mmsecs.Count <= 0)
- {
- errorinfo = $"未找到机台【{mac.FCode}】对应的状态参数定义。";
- return "";
- }
- List<OrderData> datas = new List<OrderData>();
- OrderData lentity = new OrderData();
- lentity.ID = 1;
- lentity.ParentID = 0;
- lentity.PreID = order.ID;
- lentity.FCode = "L";
- lentity.FContent = "";
- lentity.FLen = 1;
- lentity.FNum = 10;
- datas.Add(lentity);
- lentity = new OrderData();
- lentity.ID = 2;
- lentity.ParentID = 1;
- lentity.PreID = order.ID;
- lentity.FCode = mmsecs[0].DCode;
- lentity.FContent = mmsecs[0].FVal;
- lentity.FLen = 1;
- lentity.FNum = 10;
- datas.Add(lentity);
- HsmsWeb accessmac = new HsmsWeb();
- OrderBlock rec = accessmac.SendOrderFor(mac.FCode, order, datas, ref errorinfo);
- if (rec == null)
- return "";
- return rec.Datalists[1].FContent;
- }
- catch (Exception ex)
- {
- errorinfo = ex.Message.ToString();
- return "";
- }
- }
- private int AsmDownloadProgram(Machine mac,string programname, MacOrderSendDal senddal, ref string errorinfo)
- {
- string temperrorinfo = "";
- AsmProgramDal asmdal = new AsmProgramDal(CurrDb);
- int result = asmdal.DownloadProgram(mac, programname, ref errorinfo);
- if (result == -100)
- {
- loger.LogError($"S7F2回复代码为{errorinfo}");
- temperrorinfo = "";
- senddal.SendS10F3(mac.FCode, $"Recipe download fail [{programname}] S7F1({errorinfo})", ref temperrorinfo);
- return result;
- }
- if (result == -200)
- {
- loger.LogError($"S7F4回复代码为{errorinfo}");
- temperrorinfo = "";
- senddal.SendS10F3(mac.FCode, $"Recipe download fail [{programname}] S7F3({errorinfo})", ref temperrorinfo);
- return result;
- }
- if (result <= 0)
- {
- loger.LogError($"下载程序错误{errorinfo}");
- temperrorinfo = "";
- senddal.SendS10F3(mac.FCode, $"Recipe download fail [{programname}] unknow error", ref temperrorinfo);
- return result;
- }
- temperrorinfo = "";
- loger.LogError($"发送下载程序成功信息到机台上");
- senddal.SendS10F3(mac.FCode, $"Recipe download success [{programname}]", ref temperrorinfo);
- loger.LogError($"信息发送完成:{temperrorinfo}开始装载程序......");
- //programname += ".WB";
- result = asmdal.SelProgram(mac, programname, ref errorinfo);
- if (result == -300)
- {
- temperrorinfo = "";
- senddal.SendS10F3(mac.FCode, $"Selcet Recipe fail [{programname}] S2F41({errorinfo})", ref temperrorinfo);
- return result;
- }
- if (result <= 0)
- {
- temperrorinfo = "";
- senddal.SendS10F3(mac.FCode, $"Selcet Recipe fail [{programname}] unknow error", ref temperrorinfo);
- errorinfo = $"选择程序发生错误:{errorinfo}";
- return result;
- }
- temperrorinfo = "";
- senddal.SendS10F3(mac.FCode, $"Selcet Recipe success [{programname}]", ref temperrorinfo);
- return 1;
- }
- private int KnsDownloadProgram(Machine mac, string programname, MacOrderSendDal senddal, ref string errorinfo)
- {
- string temperrorinfo = "";
- KnsProgramDal asmdal = new KnsProgramDal(CurrDb);
- int result = asmdal.DownloadProgram(mac, programname, ref errorinfo);
- if (result == -100)
- {
- loger.LogError($"S7F2回复代码为{errorinfo}");
- temperrorinfo = "";
- senddal.SendS10F3(mac.FCode, $"Recipe download fail [{programname}] S7F1({errorinfo})", ref temperrorinfo);
- return result;
- }
- if (result == -200)
- {
- loger.LogError($"S7F4回复代码为{errorinfo}");
- temperrorinfo = "";
- senddal.SendS10F3(mac.FCode, $"Recipe download fail [{programname}] S7F3({errorinfo})", ref temperrorinfo);
- return result;
- }
- if (result <= 0)
- {
- loger.LogError($"下载程序错误{errorinfo}");
- temperrorinfo = "";
- senddal.SendS10F3(mac.FCode, $"Recipe download fail [{programname}] unknow error", ref temperrorinfo);
- return result;
- }
- temperrorinfo = "";
- loger.LogError($"发送下载程序成功信息到机台上");
- senddal.SendS10F3(mac.FCode, $"Recipe download success [{programname}]", ref temperrorinfo);
- loger.LogError($"信息发送完成:{temperrorinfo}开始装载程序......");
- if(!Convert.ToBoolean(AppConfigurtaionServices.Configuration["SelectProgram"]))
- {
- //不用选择程序
- return 1;
- }
- int KnsSelectProgram = Convert.ToInt32( AppConfigurtaionServices.Configuration["KnsSelectProgram"]);
- Thread.Sleep(KnsSelectProgram);
- result = asmdal.SelectProgram(mac, programname, ref errorinfo);
- if (result == -300)
- {
- temperrorinfo = "";
- senddal.SendS10F3(mac.FCode, $"Selcet Recipe fail [{programname}] S2F41({errorinfo})", ref temperrorinfo);
- return result;
- }
- if (result <= 0)
- {
- temperrorinfo = "";
- senddal.SendS10F3(mac.FCode, $"Selcet Recipe fail [{programname}] unknow error", ref temperrorinfo);
- errorinfo = $"选择程序发生错误:{errorinfo}";
- return result;
- }
- temperrorinfo = "";
- senddal.SendS10F3(mac.FCode, $"Selcet Recipe success [{programname}]", ref temperrorinfo);
- return 1;
- }
- private int KnsDownloadProgramS7F6(Machine mac, string programname, MacOrderSendDal senddal, ref string errorinfo)
- {
- string temperrorinfo = "";
- KnsProgramDal asmdal = new KnsProgramDal(CurrDb);
- int result = asmdal.DownloadProgramS7F6(mac, programname, ref errorinfo);
- if (result == -100)
- {
- loger.LogError($"S7F6回复代码为{errorinfo}");
- temperrorinfo = "";
- senddal.SendS10F3(mac.FCode, $"Recipe download fail [{programname}] S7F1({errorinfo})", ref temperrorinfo);
- return result;
- }
- senddal.SendS10F3(mac.FCode, $"Selcet Recipe success [{programname}]", ref temperrorinfo);
- return 1;
- }
- private int Dad3350DownloadProgram(Machine mac, string orgprogramname, MacOrderSendDal senddal, ref string errorinfo)
- {
- string programname = "";
- string temperrorinfo = "";
- Dad3350ProgramDal dal = new Dad3350ProgramDal(CurrDb, loger);
- int result = dal.DownloadProgram(mac, orgprogramname, ref programname, ref errorinfo);
- if (result == -100)
- {
- loger.LogError($"S7F2回复代码为{errorinfo}");
- temperrorinfo = "";
- senddal.SendS10F3(mac.FCode, $"Recipe download fail [{orgprogramname}] S7F1({errorinfo})", ref temperrorinfo);
- return result;
- }
- if (result == -200)
- {
- loger.LogError($"S7F4回复代码为{errorinfo}");
- temperrorinfo = "";
- senddal.SendS10F3(mac.FCode, $"Recipe download fail [{orgprogramname}] S7F3({errorinfo})", ref temperrorinfo);
- return result;
- }
- if (result <= 0)
- {
- temperrorinfo = "";
- senddal.SendS10F3(mac.FCode, $"Recipe download fail [{orgprogramname}]", ref temperrorinfo);
- return result;
- }
- temperrorinfo = "";
- loger.LogError($"发送下载程序成功信息到机台上");
- senddal.SendS10F3(mac.FCode, $"Recipe download success [{orgprogramname}]", ref temperrorinfo);
- loger.LogError($"信息发送完成:{temperrorinfo}开始装载程序......");
- result = dal.SelectProgram(mac, programname, ref errorinfo);
- if (result <= 0)
- {
- temperrorinfo = "";
- senddal.SendS10F3(mac.FCode, $"Selcet Recipe fail [{orgprogramname}]", ref temperrorinfo);
- errorinfo = $"选择程序发生错误:{errorinfo}";
- return result;
- }
- temperrorinfo = "";
- senddal.SendS10F3(mac.FCode, $"Selcet Recipe success [{orgprogramname}]", ref temperrorinfo);
- return 1;
- }
- private int BgDownloadProgram(Machine mac, string orgprogramname, MacOrderSendDal senddal, ref string errorinfo)
- {
- string temperrorinfo = "";
- BgProgramDal bgdal = new BgProgramDal(CurrDb);
- int result = bgdal.DownloadProgram(mac, orgprogramname, ref errorinfo);
- if (result == -100)
- {
- loger.LogError($"S7F2回复代码为{errorinfo}");
- temperrorinfo = "";
- senddal.SendS10F3(mac.FCode, $"Recipe download fail [{orgprogramname}] S7F1({errorinfo})", ref temperrorinfo);
- return result;
- }
- if (result == -200)
- {
- loger.LogError($"S7F4回复代码为{errorinfo}");
- temperrorinfo = "";
- senddal.SendS10F3(mac.FCode, $"Recipe download fail [{orgprogramname}] S7F3({errorinfo})", ref temperrorinfo);
- return result;
- }
- if (result <= 0)
- {
- loger.LogError($"下载程序错误{errorinfo}");
- temperrorinfo = "";
- senddal.SendS10F3(mac.FCode, $"Recipe download fail [{orgprogramname}] unknow error", ref temperrorinfo);
- return result;
- }
- temperrorinfo = "";
- senddal.SendS10F3(mac.FCode, $"Recipe download success [{orgprogramname}]", ref temperrorinfo);
- return 1;
- }
- /// <summary>
- /// 清除程序
- /// </summary>
- /// <param name="maccode"></param>
- /// <param name="errorinfo"></param>
- /// <returns></returns>
- private int ClearProgramAuto(string maccode,ref string errorinfo)
- {
- //if (!string.IsNullOrEmpty(AppConfigurtaionServices.Configuration["Client"])
- // && AppConfigurtaionServices.Configuration["Client"] == "Onsemi")
- //{
- var dal = new Dad3350ProgramDal(CurrDb);
- return dal.ClearProgramAutoDir(maccode, ref errorinfo);
- //}
- //return 1;
- }
- private int DiodesBgDownloadProgram(Machine mac, string orgprogramname, MacOrderSendDal senddal, ref string errorinfo)
- {
- string temperrorinfo = "";
- BgProgramDal bgdal = new BgProgramDal(CurrDb);
- int result = bgdal.DiodesDownloadProgram(mac, orgprogramname, ref errorinfo);
- if (result == -100)
- {
- loger.LogError($"S7F2回复代码为{errorinfo}");
- temperrorinfo = "";
- senddal.SendS10F3(mac.FCode, $"Recipe download fail [{orgprogramname}] S7F1({errorinfo})", ref temperrorinfo);
- return result;
- }
- if (result == -200)
- {
- loger.LogError($"S7F4回复代码为{errorinfo}");
- temperrorinfo = "";
- senddal.SendS10F3(mac.FCode, $"Recipe download fail [{orgprogramname}] S7F3({errorinfo})", ref temperrorinfo);
- return result;
- }
- if (result <= 0)
- {
- loger.LogError($"下载程序错误{errorinfo}");
- temperrorinfo = "";
- senddal.SendS10F3(mac.FCode, $"Recipe download fail [{orgprogramname}] unknow error", ref temperrorinfo);
- return result;
- }
- temperrorinfo = "";
- senddal.SendS10F3(mac.FCode, $"Recipe download success [{orgprogramname}]", ref temperrorinfo);
- result = bgdal.SelectProgram(mac, orgprogramname, ref errorinfo);
- if (result <= 0)
- {
- temperrorinfo = "";
- senddal.SendS10F3(mac.FCode, $"Selcet Recipe fail [{orgprogramname}]", ref temperrorinfo);
- errorinfo = $"选择程序发生错误:{errorinfo}";
- return result;
- }
- temperrorinfo = "";
- senddal.SendS10F3(mac.FCode, $"Selcet Recipe success [{orgprogramname}]", ref temperrorinfo);
- return 1;
- }
- private int Dad3650DownloadProgram(Machine mac, string orgprogramname, MacOrderSendDal senddal, ref string errorinfo)
- {
- string programname = "";
- string temperrorinfo = "";
- Dad3650ProgramDal dal = new Dad3650ProgramDal(CurrDb, loger);
- int result = dal.DownloadProgram(mac, orgprogramname, ref programname, ref errorinfo);
- if (result <= 0)
- {
- temperrorinfo = "";
- senddal.SendS10F3NoAnswer(mac.FCode, $"Recipe download fail [{orgprogramname}]", ref temperrorinfo);
- return result;
- }
- temperrorinfo = "";
- loger.LogError($"发送下载程序成功信息到机台上");
- senddal.SendS10F3NoAnswer(mac.FCode, $"Recipe download success [{orgprogramname}]", ref temperrorinfo);
- loger.LogError($"信息发送完成:{temperrorinfo}开始装载程序......");
- result = dal.SelectProgram(mac, programname, ref errorinfo);
- if (result <= 0)
- {
- temperrorinfo = "";
- senddal.SendS10F3NoAnswer(mac.FCode, $"Selcet Recipe fail [{programname}]", ref temperrorinfo);
- errorinfo = $"选择程序发生错误:{errorinfo}";
- return result;
- }
- temperrorinfo = "";
- senddal.SendS10F3NoAnswer(mac.FCode, $"Selcet Recipe success [{programname}]", ref temperrorinfo);
- return 1;
- }
- public int DownloadProgram(string maccode, string orgprogramname,ref string errorinfo)
- {
- try
- {
- int result = 0;
- string condition = $" and a.fcode='{maccode}'";
- List<Machine> macs = CurrDb.FindListForCondition<Machine>(condition, ref errorinfo).ToList();
- if (macs == null || macs.Count <= 0)
- {
- errorinfo = "未找到机台信息。";
- return -1;
- }
- // 清除原有程序
- //if (ClearProgramAuto(macs[0].FCode, ref errorinfo) < 0)
- // return -1;
- ClearProgramAuto(macs[0].FCode, ref errorinfo);
- errorinfo = "";
- //提示下载程序成功
- MacOrderSendDal senddal = new MacOrderSendDal(CurrDb);
- switch (macs[0].MModeCode.ToLower())
- {
- case "dad3350":
- case "dfd6341":
- case "dfd6340":
- return Dad3350DownloadProgram(macs[0], orgprogramname, senddal, ref errorinfo);
- case "dad3650":
- case "dfd6362":
- return Dad3650DownloadProgram(macs[0], orgprogramname, senddal, ref errorinfo);
- case "dfg8540":
- return BgDownloadProgram(macs[0], orgprogramname, senddal, ref errorinfo);
- case "bg":
- return DiodesBgDownloadProgram(macs[0], orgprogramname, senddal, ref errorinfo);
- default:
- if(macs[0].SupplierFCode.ToLower()=="kns")
- {
- if(macs[0].FCode.ToLower()=="wkb-074")
- {
- return KnsDownloadProgramS7F6(macs[0], orgprogramname, senddal, ref errorinfo);
- }
- else
- {
- return KnsDownloadProgram(macs[0], orgprogramname, senddal, ref errorinfo);
- }
-
- }
- else
- {
- return AsmDownloadProgram(macs[0], orgprogramname, senddal, ref errorinfo);
- }
- }
- }
- catch (Exception ex)
- {
- errorinfo = ex.StackTrace+ ex.Message.ToString();
- return -1;
- }
- }
- public int WBDownloadProgram(Machine mac, string programname,int ver, MacOrderSendDal senddal, ref string errorinfo)
- {
- string temperrorinfo = "";
- Dad3350ProgramDal dal = new Dad3350ProgramDal(CurrDb, loger);
- int result = dal.DownloadProgramForWB(mac, programname,ver, ref errorinfo);
- if (result == -100)
- {
- loger.LogError($"S7F2回复代码为{errorinfo}");
- temperrorinfo = "";
- senddal.SendS10F3(mac.FCode, $"Recipe download fail [{programname}] S7F1({errorinfo})", ref temperrorinfo);
- return result;
- }
- if (result == -200)
- {
- loger.LogError($"S7F4回复代码为{errorinfo}");
- temperrorinfo = "";
- senddal.SendS10F3(mac.FCode, $"Recipe download fail [{programname}] S7F3({errorinfo})", ref temperrorinfo);
- return result;
- }
- if (result <= 0)
- {
- temperrorinfo = "";
- senddal.SendS10F3(mac.FCode, $"Recipe download fail [{programname}]", ref temperrorinfo);
- return result;
- }
- temperrorinfo = "";
- loger.LogError($"发送下载程序成功信息到机台上");
- senddal.SendS10F3(mac.FCode, $"Recipe download success [{programname}]", ref temperrorinfo);
- loger.LogError($"信息发送完成:{temperrorinfo}开始装载程序......");
- result = dal.SelectProgram(mac, programname, ref errorinfo);
- if (result <= 0)
- {
- temperrorinfo = "";
- senddal.SendS10F3(mac.FCode, $"Selcet Recipe fail [{programname}]", ref temperrorinfo);
- errorinfo = $"选择程序发生错误:{errorinfo}";
- return result;
- }
- temperrorinfo = "";
- senddal.SendS10F3(mac.FCode, $"Selcet Recipe success [{programname}]", ref temperrorinfo);
- return 1;
- }
- public int DownloadProgramForLot(string maccode, string programname,int ver, ref string errorinfo)
- {
- try
- {
- int result = 0;
- string condition = $" and a.fcode='{maccode}'";
- List<Machine> macs = CurrDb.FindListForCondition<Machine>(condition, ref errorinfo).ToList();
- if (macs == null || macs.Count <= 0)
- {
- errorinfo = "未找到机台信息。";
- return -1;
- }
- //提示下载程序成功
- MacOrderSendDal senddal = new MacOrderSendDal(CurrDb);
- switch (macs[0].MModeID)
- {
- case 14:
- case 184://WB调程
- return WBDownloadProgram(macs[0], programname,ver, senddal, ref errorinfo);
- default:
- programname = $"{programname}.rcp";
- return DownloadProgramForFile(macs[0], programname, ver, senddal, ref errorinfo);
- //采用文件传输
- }
- }
- catch (Exception ex)
- {
- errorinfo = ex.Message.ToString();
- return -1;
- }
- }
- public int DownloadProgramForLot01(string maccode, string programname, int ver, ref string errorinfo)
- {
- try
- {
- int result = 0;
- string condition = $" and a.fcode='{maccode}'";
- List<Machine> macs = CurrDb.FindListForCondition<Machine>(condition, ref errorinfo).ToList();
- if (macs == null || macs.Count <= 0)
- {
- errorinfo = "未找到机台信息。";
- return -1;
- }
- //提示下载程序成功
- MacOrderSendDal senddal = new MacOrderSendDal(CurrDb);
- switch (macs[0].MModeID)
- {
- case 14:
- case 184://WB调程
- return WBDownloadProgram(macs[0], programname, ver, senddal, ref errorinfo);
- default:
- return DownloadProgramForFile(macs[0], programname, ver, senddal, ref errorinfo);
- //采用文件传输
- }
- }
- catch (Exception ex)
- {
- errorinfo = ex.Message.ToString();
- return -1;
- }
- }
- private int DownloadProgramForFile(Machine mac, string programname, int ver, MacOrderSendDal senddal, ref string errorinfo)
- {
- string temperrorinfo = "";
- Dad3350ProgramDal dal = new Dad3350ProgramDal(CurrDb, loger);
- int result = dal.DownloadProgramForFile(mac, programname, ver, ref errorinfo);
- if (result == -100)
- {
- loger.LogError($"S7F2回复代码为{errorinfo}");
- temperrorinfo = "";
- senddal.SendS10F3(mac.FCode, $"Recipe download fail [{programname}] S7F1({errorinfo})", ref temperrorinfo);
- return result;
- }
- if (result == -200)
- {
- loger.LogError($"S7F4回复代码为{errorinfo}");
- temperrorinfo = "";
- senddal.SendS10F3(mac.FCode, $"Recipe download fail [{programname}] S7F3({errorinfo})", ref temperrorinfo);
- return result;
- }
- if (result <= 0)
- {
- temperrorinfo = "";
- senddal.SendS10F3(mac.FCode, $"Recipe download fail [{programname}]", ref temperrorinfo);
- return result;
- }
- temperrorinfo = "";
- loger.LogError($"发送下载程序成功信息到机台上");
- senddal.SendS10F3(mac.FCode, $"Recipe download success [{programname}]", ref temperrorinfo);
- loger.LogError($"信息发送完成:{temperrorinfo}开始装载程序......");
- result = dal.SelectProgram(mac, programname, ref errorinfo);
- if (result <= 0)
- {
- temperrorinfo = "";
- senddal.SendS10F3(mac.FCode, $"Selcet Recipe fail [{programname}]", ref temperrorinfo);
- errorinfo = $"选择程序发生错误:{errorinfo}";
- return result;
- }
- temperrorinfo = "";
- senddal.SendS10F3(mac.FCode, $"Selcet Recipe success [{programname}]", ref temperrorinfo);
- return 1;
- }
- private int UpProgramForOfilm(OrderBlock entity, string filedir, string usercode, ref string programname, ref string errorinfo)
- {
- try
- {
- List<OrderData> datas = entity.Datalists.Where(t => t.ParentID == 0).OrderBy(t => t.FNum).ToList();
- int parentid = datas[0].ID;//获取L的ID值
- datas = entity.Datalists.Where(t => t.ParentID == parentid).OrderBy(t => t.FNum).ToList();
- programname = datas[0].FContent;
- string remark = programname;
- byte[] filedatas = datas[1].OrgDatas;
- string condition = $" and a.fcode='{entity.MainMsg.McaCode}'";
- List<Machine> macs = CurrDb.FindListForCondition<Machine>(condition, ref errorinfo).ToList();
- if (macs.Count <= 0)
- {
- errorinfo = $"未找到机台编号{entity.MainMsg.McaCode}的信息。";
- return -1;
- }
- switch (macs[0].MModeCode.ToLower())
- {
- case "dad3350":
- case "dad3650":
- case "dfd6362":
- case "dfd6341":
- programname = DiodesProgramFileHelper.GetProgramName01(filedatas, ref errorinfo);
- if (errorinfo != "")
- {
- errorinfo = $"分析文件名称发生错误:{errorinfo}";
- return -1;
- }
- break;
- case "dfg8540":
- programname = Bg8761ProgramFileHelper.GetProgramName01(filedatas, ref errorinfo);
- if (errorinfo != "")
- {
- errorinfo = $"分析文件名称发生错误:{errorinfo}";
- return -1;
- }
- break;
- }
- BusinessFileDal dal = new BusinessFileDal(CurrDb);
- BusinessFile busifile = dal.UpdownFile(filedatas, filedir, programname, macs[0], remark, usercode, ref errorinfo);
- if (busifile == null)
- {
- errorinfo = $"处理文件发生错误:{errorinfo}";
- return -1;
- }
- //添加程序,用于参数比对
- ProgramMstDal pmdal = new ProgramMstDal(CurrDb);
- pmdal.IUProgramMst(macs[0], programname, ref errorinfo);
- //调用MES接口,把程序信息传给MES
- //string temperrorinfo1 = "";
- //MacOrderSendDal senddal1 = new MacOrderSendDal(db);
- //int result=senddal1.SendS10F3(entity.MainMsg.McaCode, $" Recipe upload success {programname}", ref temperrorinfo1);
- //if(result<=0)
- //{
- // log
- //}
- return 1;
- }
- catch (Exception ex)
- {
- errorinfo = ex.Message.ToString();
- return -1;
- }
- }
- public int DownloadProgramS7F6(string maccode, string orgprogramname, ref string errorinfo)
- {
- try
- {
- int result = 0;
- string condition = $" and a.fcode='{maccode}'";
- List<Machine> macs = CurrDb.FindListForCondition<Machine>(condition, ref errorinfo).ToList();
- if (macs == null || macs.Count <= 0)
- {
- errorinfo = "未找到机台信息。";
- return -1;
- }
- MacOrderSendDal senddal = new MacOrderSendDal(CurrDb);
- if (macs[0].SupplierFCode.ToLower() == "kns")
- {
- if(macs[0].FCode.ToLower()=="wkb-074")
- {
- return KnsDownloadProgramS7F6(macs[0], orgprogramname, senddal, ref errorinfo);
- }
- else
- {
- return KnsDownloadProgram(macs[0], orgprogramname, senddal, ref errorinfo);
- }
- }
- else
- {
- return AsmDownloadProgramS7F6(macs[0], orgprogramname, senddal, ref errorinfo);
- }
-
- }
- catch (Exception ex)
- {
- errorinfo = ex.Message.ToString();
- return -1;
- }
- }
- private int AsmDownloadProgramS7F6(Machine mac, string programname, MacOrderSendDal senddal, ref string errorinfo)
- {
- string temperrorinfo = "";
- AsmProgramDal asmdal = new AsmProgramDal(CurrDb);
- int result = DownloadProgramS7F6(mac, programname, ref errorinfo);
- if (result <= 0)
- {
- loger.LogError($"下载程序错误{errorinfo}");
- temperrorinfo = "";
- senddal.SendS10F3(mac.FCode, $"Recipe download fail [{programname}] unknow error", ref temperrorinfo);
- return result;
- }
- temperrorinfo = "";
- loger.LogError($"发送下载程序成功信息到机台上");
- senddal.SendS10F3(mac.FCode, $"Recipe download success [{programname}]", ref temperrorinfo);
- loger.LogError($"信息发送完成:{temperrorinfo}开始装载程序......");
- result = asmdal.SelProgram(mac, programname, ref errorinfo);
- if (result == -300)
- {
- temperrorinfo = "";
- senddal.SendS10F3(mac.FCode, $"Selcet Recipe fail [{programname}] S2F41({errorinfo})", ref temperrorinfo);
- return result;
- }
- if (result <= 0)
- {
- temperrorinfo = "";
- senddal.SendS10F3(mac.FCode, $"Selcet Recipe fail [{programname}] unknow error", ref temperrorinfo);
- errorinfo = $"选择程序发生错误:{errorinfo}";
- return result;
- }
- temperrorinfo = "";
- senddal.SendS10F3(mac.FCode, $"Selcet Recipe success [{programname}]", ref temperrorinfo);
- return 1;
- }
- //private int KnsDownloadProgramS7F6(Machine mac, string programname, MacOrderSendDal senddal, ref string errorinfo)
- //{
- // string temperrorinfo = "";
- // KnsProgramDal asmdal = new KnsProgramDal(CurrDb);
- // int result = DownloadProgramS7F6(mac, programname, ref errorinfo);
- // if (result <= 0)
- // {
- // loger.LogError($"下载程序错误{errorinfo}");
- // temperrorinfo = "";
- // senddal.SendS10F3(mac.FCode, $"Recipe download fail [{programname}] unknow error", ref temperrorinfo);
- // return result;
- // }
- // temperrorinfo = "";
- // loger.LogError($"发送下载程序成功信息到机台上");
- // senddal.SendS10F3(mac.FCode, $"Recipe download success [{programname}]", ref temperrorinfo);
- // loger.LogError($"信息发送完成:{temperrorinfo}开始装载程序......");
- // Thread.Sleep(1000);
- // result = asmdal.SelectProgram(mac, programname, ref errorinfo);
- // if (result == -300)
- // {
- // temperrorinfo = "";
- // senddal.SendS10F3(mac.FCode, $"Selcet Recipe fail [{programname}] S2F41({errorinfo})", ref temperrorinfo);
- // return result;
- // }
- // if (result <= 0)
- // {
- // temperrorinfo = "";
- // senddal.SendS10F3(mac.FCode, $"Selcet Recipe fail [{programname}] unknow error", ref temperrorinfo);
- // errorinfo = $"选择程序发生错误:{errorinfo}";
- // return result;
- // }
- // temperrorinfo = "";
- // senddal.SendS10F3(mac.FCode, $"Selcet Recipe success [{programname}]", ref temperrorinfo);
- // return 1;
- //}
- public int DownloadProgramS7F6(Machine mac, string orgprogramname, ref string errorinfo)
- {
- try
- {
- orgprogramname = orgprogramname.Trim();
- #region
- #endregion
- string programname = orgprogramname;
- int result = 0;
- if (mac.CallPMode <= 2)
- {
- //说明要下载程序
- MacProgramDal macprogramdal = new MacProgramDal(CurrDb);
- int orgtypeid = 1;
- string programdir = AppConfigurtaionServices.Configuration["ProgramDir"];
- if (mac.CallPMode == 1)
- {
- orgtypeid = 1;
- }
- else
- {
- orgtypeid = 2;
- }
- byte[] filedatas = macprogramdal.ReadMacProgram(mac, orgprogramname, orgtypeid, programdir, ref errorinfo);
- if (filedatas == null)
- return -30;
- result = DownloadProgramS7F6(mac, programname, filedatas, ref errorinfo);
- if (result <= 0)
- return result;
- }
- return 1;
- }
- catch (Exception ex)
- {
- errorinfo = ex.Message.ToString();
- return -1;
- }
- }
- public int DownloadProgramS7F6(Machine mac, string programname, byte[] filedatas, ref string errorinfo)
- {
- try
- {
- //要修改程序名称
- OrderDetail order = ReadMachineOrderDetail(mac.ID, 7, 6, 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;
- 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[1].OrgDatas = filedatas;
- HsmsWeb accessmac = new HsmsWeb();
- int result = accessmac.SendOrderNoAnswer(mac.FCode, order, datas, ref errorinfo);
- return result;
- }
- catch (Exception ex)
- {
- errorinfo = ex.Message.ToString();
- return -1;
- }
- }
- }
- }
|