12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619 |
- using Cksoft.Data;
- using Cksoft.Data.Repository;
- using Cksoft.Unity;
- using DllEapCommon.Notice;
- using DllEapDal;
- using DllEapDal.OFILM;
- using DllEapDal.OFILM.MES;
- using DllEapDal.Onsemi;
- using DllEapEntity;
- using DllEapEntity.Onsemi;
- using DllEapEntity.Rms;
- using DllHsms;
- using DllSocketFile;
- using DllStatusShowDal;
- using Microsoft.Extensions.Logging;
- using Newtonsoft.Json;
- using RabbitMQ.Client;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- using WebStatusToolkit.Notice;
- namespace WebStatusToolkit
- {
- public class CallFunction
- {
- private static string mesApiPrefix = AppConfigurtaionServices.Configuration["mesApiPrefix"];
- //public static string MesApiPrefix
- //{
- // get
- // {
- // if (string.IsNullOrEmpty(mesApiPrefix))
- // mesApiPrefix = AppConfigurtaionServices.Configuration["mesApiPrefix"];
- // return mesApiPrefix;
- // }
- //}
- // private static string mesApiPrefix = "http://192.168.51.100:8080/ofilm/eap/";
- public static string CurrDbCode = "eap";
- public static string ReadDbCode = "eapslave";
- public static MacStatus CallIMacStatus(IModel channel, MacStatus entity, string usercode, ref string errorinfo)
- {
- IDatabase CurrDb = null;
- try
- {
- // entity.ProgramName = AppConfigurtaionServices.Configuration["SystemCode"];
- CurrDb = DbFactory.Base(CurrDbCode);
- CurrDb.BeginTrans();
- MacStatusDal tempdal = new MacStatusDal(CurrDb);
- MacStatus laststatus = tempdal.GetLastStatus(entity.MacCode, ref errorinfo);
- // 当机台的上一个状态是待机程序上传的并且该状态还未结束时,应等待待机程序解除状态,
- // 未解除时从队列上获取到的新状态不再插入数据库
- //if (laststatus != null && laststatus.ETime.ToString("yyyy-MM-dd HH:mm:ss") == "0001-01-01 00:00:00"
- // && (laststatus.ProgramName == "待机程序" || laststatus.ProgramName == "EAPWeb程序") && (laststatus.StatusID == 10 ||
- // laststatus.StatusID > 200000) && entity.ProgramName != "待机程序"
- // && entity.ProgramName != "EAPWeb程序")
- if (laststatus != null && laststatus.IsCover == -1 && entity.ProgramName != "待机程序"
- && entity.ProgramName != "EAPWeb程序")
- {
- errorinfo = $"当前机台【{laststatus.MacCode}】的前一状态为【{laststatus.StatusFName}】且该状态未解除," +
- $"该状态已被配置为不可覆盖," +
- $"不再插入队列中的新状态";
- return null;
- }
- if (laststatus != null && laststatus.StatusID == 204906 && entity.StatusID == 1)
- {
- errorinfo = $"当前机台【{laststatus.MacCode}】的前一状态为【{laststatus.StatusFName}】且该状态未解除," +
- $"且当前状态为离线," +
- $"不再插入队列中的新状态";
- return null;
- }
- if (laststatus != null)
- {
- if (string.IsNullOrEmpty(entity.Remark))
- {
- if (!string.IsNullOrEmpty(laststatus.Remark) && laststatus.Remark != "\0")
- {
- entity.Remark = laststatus.Remark;
- }
- else
- {
- var recipeS = CurrDb.FindListForCondition<MacStatus>($" and a.Maccode='{entity.MacCode}' " +
- $"and a.remark is not null and a.remark !='\0'", ref errorinfo).FirstOrDefault();
- if (recipeS != null)
- {
- entity.Remark = recipeS.Remark;
- }
- }
- }
- }
- //插入最后状态
- int result = tempdal.AddMacStatus01(entity, usercode, ref errorinfo);
- if (result <= 0)
- {
- errorinfo = $"添加MacStatus01发生错误:{errorinfo}";
- return null;
- }
- if (laststatus != null)//说明最后的状态与当前状态相同,直接返回
- {
- if (laststatus.Remark != entity.Remark)
- {
- laststatus.Remark = entity.Remark;
- if (CurrDb.UpdateFor<MacStatus>(laststatus, usercode) < 0)
- {
- errorinfo = $"机台【{laststatus.MacCode}】更新机种信息【{entity.Remark}】失败";
- return null;
- }
- if (NeedUpdateRecipe(laststatus.Remark, entity.Remark))
- {
- PushStatusData(channel, CurrDb, entity, errorinfo);
- }
- }
- if (laststatus.StatusID == entity.StatusID)
- {
- if (entity.StatusID == 6)
- {
- if (entity.AlarmCode == "SVID")
- {
- return entity;
- }
- else
- {
- int alarmTimeSpan = Convert.ToInt32(AppConfigurtaionServices.Configuration["SVIDTimeSpan"]);
- if (laststatus.AlarmCode == "0000")
- {
- if ((entity.STime - laststatus.STime).TotalSeconds <= alarmTimeSpan)
- {
- var res = tempdal.UpdateLastSvidAlarm(laststatus, entity, string.Empty, ref errorinfo);
- if (res == null)
- {
- CurrDb.Rollback();
- return null;
- }
- }
- }
- else
- {
- entity = tempdal.IMacStatus(entity, usercode, ref errorinfo, true);
- if (entity == null)
- {
- CurrDb.Rollback();
- return null;
- }
- PushStatusData(channel, CurrDb, entity, errorinfo);
- CurrDb.Commit();
- return entity;
- }
- }
- }
- // 当上一个状态与当前状态间隔时间大于5分钟时 结束上个状态,插入当前状态
- if ((entity.STime - laststatus.STime).TotalMinutes > 5)
- {
- entity = tempdal.IMacStatus(entity, usercode, ref errorinfo, false);
- if (entity == null)
- {
- CurrDb.Rollback();
- return null;
- }
- }
- CurrDb.Commit();
- return entity;
- }
- else
- {
- if (entity.AlarmCode == "SVID")
- {
- entity.AlarmCode = "0000";
- entity.AlarmDescribe = "No Description Alarm";
- }
- }
- }
- else
- {
- if (entity.AlarmCode == "SVID")
- {
- entity.AlarmCode = "0000";
- entity.AlarmDescribe = "No Description Alarm";
- }
- }
- entity = tempdal.IMacStatus(entity, usercode, ref errorinfo, true);
- if (entity == null)
- {
- CurrDb.Rollback();
- return null;
- }
- PushStatusData(channel, CurrDb, entity, errorinfo);
- CurrDb.Commit();
- // 调用蓝信接口发送断线通知给相关人员
- if (entity.StatusID == 1 && AppConfigurtaionServices.Configuration["Client"] != null
- && AppConfigurtaionServices.Configuration["Client"] == "Ofilm")
- {
- var machine = CurrDb.FindListForCondition<Machine>($" and a.fcode='{entity.MacCode}'", ref errorinfo).FirstOrDefault();
- //if (machine.FactoryId == 8)
- //{
- Task.Run(() =>
- {
- string error = string.Empty;
- OfilmLanxinNoticeService.NoticeDisconn(machine, entity, error);
- });
- //}
- }
- return entity;
- }
- catch (Exception ex)
- {
- errorinfo = ex.Message.ToString();
- return null;
- }
- finally
- {
- if (CurrDb != null)
- CurrDb.Close();
- }
- }
- /// <summary>
- /// 程序参数比较
- /// </summary>
- /// <param name="maccode"></param>
- /// <param name="usercode"></param>
- /// <param name="errorinfo"></param>
- /// <returns></returns>
- //public static int CompareParams(string maccode,string usercode, ref string errorinfo)
- //{
- // IDatabase CurrDb = null;
- // try
- // {
- // CurrDb = DbFactory.Base(CurrDbCode);
- // CurrDb.BeginTrans();
- // //读取机台信息
- // string condition = $" and a.FCode='{maccode}'";
- // Machine mac = CurrDb.FindListForCondition<Machine>(condition, ref errorinfo).ToList()[0];
- // if (mac.IsControl <= 0)
- // {
- // //说明此机台没有开启参数比对功能,无需比对
- // CurrDb.Commit();
- // return 1;
- // }
- // //string programname = (string)imputds["programname"];
- // ParamsComMstDal comdal = new ParamsComMstDal(CurrDb);
- // //string programname = comdal.GetMacProgram(maccode, ref errorinfo);
- // //if (string.IsNullOrEmpty(programname))
- // //{
- // // errorinfo = $"未找到机台【{maccode}】对应的程序。{errorinfo}";
- // // CurrDb.Rollback();
- // // return -1;
- // //}
- // ProgramMst programmst = comdal.GetMacProgram(mac, ref errorinfo);
- // if (programmst==null)
- // {
- // errorinfo = $"未找到机台【{maccode}】对应的程序。{errorinfo}";
- // CurrDb.Rollback();
- // return -1;
- // }
- // //比较文件参数
- // ParamsComMst mst = comdal.CompareParams(mac, programmst, ref errorinfo);
- // if (mst == null)
- // {
- // errorinfo = $"未找到机台【{maccode}】程序【{programmst.FName}】对应的比对主档。{errorinfo}";
- // CurrDb.Rollback();
- // return -1;
- // }
- // //插入比对记录
- // mst = comdal.IUParamsComMst(mst, usercode, ref errorinfo);
- // if (mst == null)
- // {
- // errorinfo = $"插入比对结果发生错误:{errorinfo}";
- // CurrDb.Rollback();
- // return -1;
- // }
- // CurrDb.Commit();
- // //如果参数不对,就发送停机指令
- // if (mst.IsPass <= 0)
- // {
- // int result = comdal.SendStopMac(maccode, ref errorinfo);
- // if (result <= 0)
- // {
- // errorinfo = $"发送停机指令发生错误,错误信息为:{errorinfo}";
- // return -1;
- // }
- // }
- // return 1;
- // }
- // catch (Exception ex)
- // {
- // errorinfo = ex.Message.ToString();
- // CurrDb.Rollback();
- // return -1;
- // }
- // finally
- // {
- // if (CurrDb != null)
- // CurrDb.Close();
- // }
- //}
- //public static int CompareParams(string maccode, string usercode, ref string errorinfo)
- //{
- // IDatabase CurrDb = null;
- // try
- // {
- // CurrDb = DbFactory.Base(CurrDbCode);
- // CurrDb.BeginTrans();
- // MacOrderSendDal macdal = new MacOrderSendDal(CurrDb);
- // Machine mac = macdal.ReadMachine(maccode, ref errorinfo);
- // if (mac == null)
- // {
- // //string logerrorinfo = "";
- // //WriteLog.WriteLogStr(maccode, "", DateTime.Now, $"读取机台错误:{errorinfo}", ref logerrorinfo);
- // CurrDb.Rollback();
- // return -1;
- // }
- // if(mac.SupplierFCode.ToLower()=="kns")
- // {
- // List<OrderData> datas = macdal.SendOrder(mac, 2, 15, "s2f15", ref errorinfo);
- // }
- // string partcode = MesDal.GetProductCode(maccode, ref errorinfo);
- // if (!string.IsNullOrEmpty(errorinfo))
- // {
- // errorinfo = $"从MES中获取产品发生错误,错误信息为:{errorinfo}";
- // return -1;
- // }
- // //没有找到产品编号,说明没有正在进行的任务,直接返回
- // if (string.IsNullOrEmpty(partcode))
- // return 1;
- // ProgramDal programdal = new ProgramDal(CurrDb);
- // ProgramMst programmst = programdal.FindProgram(mac, partcode, mac.PCode, ref errorinfo);
- // if (programmst == null)
- // {
- // //string logerrorinfo = "";
- // //WriteLog.WriteLogStr(maccode, "", DateTime.Now, $"查找程序错误:{errorinfo}", ref logerrorinfo);
- // CurrDb.Rollback();
- // return -1;
- // }
- // ParamsComMst mst = null;
- // //比较机台程序名称
- // ParamsComMstDal comdal = new ParamsComMstDal(CurrDb);
- // string programname = comdal.GetMacProgramName(mac, ref errorinfo);
- // if(programmst.FName!=programname)
- // {
- // //errorinfo = $"当前产品{partcode}使用的程序为{programmst.FName},而实际程序名称为{programname}";
- // //CurrDb.Rollback();
- // //return -1;
- // mst = new ParamsComMst();
- // mst.MacID = mac.ID;
- // mst.ProgramID = programmst.ID;
- // mst.IsPass = -1;
- // mst.Remark = $"当前产品{partcode}使用的程序为{programmst.FName},而实际程序名称为{programname}";
- // mst.CurrDetails = new List<ParamsComDetail>();
- // }
- // else
- // {
- // //比对程序参数
- // mst = comdal.CompareParams(mac, programmst, ref errorinfo);
- // if (mst == null)
- // {
- // errorinfo = $"未找到机台【{maccode}】程序【{programmst.FName}】对应的比对主档。{errorinfo}";
- // CurrDb.Rollback();
- // return -1;
- // }
- // }
- // //插入比对记录
- // mst = comdal.IUParamsComMst(mst, usercode, ref errorinfo);
- // if (mst == null)
- // {
- // errorinfo = $"插入比对结果发生错误:{errorinfo}";
- // CurrDb.Rollback();
- // return -1;
- // }
- // CurrDb.Commit();
- // //如果参数不对,就发送停机指令
- // if (mst.IsPass <= 0)
- // {
- // MacOrderDal macorderdal = new MacOrderDal(CurrDb);
- // int result = macorderdal.SendStopMac(maccode, ref errorinfo);
- // if (result <= 0)
- // {
- // errorinfo = $"发送停机指令发生错误,错误信息为:{errorinfo}";
- // return -1;
- // }
- // }
- // return 1;
- // }
- // catch (Exception ex)
- // {
- // errorinfo =ex.Message.ToString();
- // CurrDb.Rollback();
- // return -1;
- // }
- // finally
- // {
- // if (CurrDb != null)
- // CurrDb.Close();
- // }
- //}
- // 判断是否需要推送更新机种信息给BI
- private static bool NeedUpdateRecipe(string lastRemark, string currentRemark)
- {
- if (string.IsNullOrEmpty(currentRemark))
- return false;
- if (string.IsNullOrEmpty(lastRemark))
- return true;
- var separators = new char[] { ' ', '-', '_', '.' };
- var oldRecipe = lastRemark.Split(separators).FirstOrDefault();
- var newRecipe = lastRemark.Split(separators).FirstOrDefault();
- return oldRecipe != newRecipe;
- }
- private static void PushStatusData(IModel channel, IDatabase db, MacStatus entity, string errorinfo)
- {
- if (AppConfigurtaionServices.Configuration["CallMesInterface"] != null
- && Convert.ToBoolean(AppConfigurtaionServices.Configuration["CallMesInterface"]))
- {
- channel.QueueDeclare("BIStatus", false, false, false, null);
- byte[] queuedata = EntityHelper.SerializeBytes<MacStatus>(entity);
- channel.BasicPublish("", "BIStatus", null, queuedata);
- //var biDal = new BICollectDal(db);
- //biDal.PushStatusToBI(new List<MacStatus>() { entity }, errorinfo);
- }
- }
- public static int CompareParams(string maccode, string usercode, ref string errorinfo)
- {
- IDatabase CurrDb = null;
- try
- {
- CurrDb = DbFactory.Base(CurrDbCode);
- CurrDb.BeginTrans();
- #region 注销代码
- // MacOrderSendDal macdal = new MacOrderSendDal(CurrDb);
- // Machine mac = macdal.ReadMachine(maccode, ref errorinfo);
- // if (mac == null)
- // {
- // //string logerrorinfo = "";
- // //WriteLog.WriteLogStr(maccode, "", DateTime.Now, $"读取机台错误:{errorinfo}", ref logerrorinfo);
- // CurrDb.Rollback();
- // return -1;
- // }
- // if(mac.IsControl<=0)
- // {
- // CurrDb.Rollback();
- // return 1;
- // }
- //if(mac.MModeCode.ToLower()=="dad3350")
- // {
- // Dad3350ProgramDal dal = new Dad3350ProgramDal(CurrDb);
- // int result = dal.CompareParams(mac, "", ref errorinfo);
- // if(result<=0)
- // {
- // CurrDb.Commit();
- // return -1;
- // }
- // }
- // if (mac.MModeCode.ToLower() == "dfd6341")
- // {
- // Dfd6341ProgramDal dal = new Dfd6341ProgramDal(CurrDb);
- // int result = dal.CompareParams(mac, "", ref errorinfo);
- // if (result <= 0)
- // {
- // CurrDb.Commit();
- // return -1;
- // }
- // }
- #endregion
- string logerrorinfo = "";
- WriteLog.WriteLogStr(maccode, "", DateTime.Now, $"开始比对参数", ref logerrorinfo);
- int result = CompareParamsFor(CurrDb, maccode, usercode, ref errorinfo);
- CurrDb.Commit();
- WriteLog.WriteLogStr(maccode, "", DateTime.Now, $"比对参数结束:{errorinfo}", ref logerrorinfo);
- if (result <= 0)
- {
- WriteLog.WriteLogStr(maccode, "", DateTime.Now, $"比对参数失败001:{errorinfo}", ref logerrorinfo);
- string temperrorinfo = "";
- MacOrderSendDal macorderdal = new MacOrderSendDal(CurrDb);
- #region 台湾亿光停机
- if (AppConfigurtaionServices.Configuration["Client"] != null && AppConfigurtaionServices.Configuration["Client"].ToLower() == "everlight")
- {
- Machine mac = macorderdal.ReadMachine(maccode, ref temperrorinfo);
- EverLightStopMac stopMac = new EverLightStopMac();
- stopMac.StopMac(maccode, mac.IPAddress);
- result = macorderdal.SendS10F3(maccode, "Parameter comparison failed", ref temperrorinfo);
- if (result <= 0)
- {
- //WriteLog.WriteLogStr(maccode, "", DateTime.Now, $"给机台发送消息失败:{errorinfo}", ref logerrorinfo);
- errorinfo = $"{errorinfo},{temperrorinfo}";
- }
- }
- #endregion
- else
- {
- result = macorderdal.SendStopMac(maccode, ref temperrorinfo);
- if (result <= 0)
- {
- errorinfo = $"发送停机指令发生错误,错误信息为:{errorinfo},{temperrorinfo}";
- //WriteLog.WriteLogStr(maccode, "", DateTime.Now, $"发送停止指令失败:{errorinfo}", ref logerrorinfo);
- return -1;
- }
- result = macorderdal.SendS10F3(maccode, "Parameter comparison failed", ref temperrorinfo);
- if (result <= 0)
- {
- //WriteLog.WriteLogStr(maccode, "", DateTime.Now, $"给机台发送消息失败:{errorinfo}", ref logerrorinfo);
- errorinfo = $"{errorinfo},{temperrorinfo}";
- }
- //string client = AppConfigurtaionServices.Configuration["Client"];
- string resume = AppConfigurtaionServices.Configuration["Resume"];
- if (int.Parse(resume) > 0)
- {
- //发送resume指令
- macorderdal.SendResumeMac(maccode, ref temperrorinfo);
- }
- }
- return -1;
- }
- WriteLog.WriteLogStr(maccode, "", DateTime.Now, $"参数比对完成", ref logerrorinfo);
- return 1;
- }
- catch (Exception ex)
- {
- errorinfo = $"比对参数发生异常:{ex.Message.ToString()}";
- return -1;
- }
- finally
- {
- if (CurrDb != null)
- CurrDb.Close();
- }
- }
- public static int CompareParamsForOfilm(string maccode, string usercode, ref string errorinfo)
- {
- var callMesInterface = AppConfigurtaionServices.Configuration["CallMesInterface"];
- if (callMesInterface == null || !Convert.ToBoolean(callMesInterface))
- {
- return 1;
- }
- try
- {
- //调用欧菲MES运行接口
- string url = $"{mesApiPrefix}equipmentStartUp";
- var paras = new Dictionary<string, string>();
- paras.Add("equipmentID", maccode);
- var response = HttpRequestHelper<OfilmMesApiResponse>.Get(url, paras, ref errorinfo);
- errorinfo = $"调用欧非MES设备运行接口equipmentStartUp,传入的参数:{JsonConvert.SerializeObject(paras)}," +
- $"接收到的值为:{JsonConvert.SerializeObject(response)}";
- return 1;
- }
- catch (Exception ex)
- {
- errorinfo = $"比对参数发生异常:{ex.Message.ToString()}";
- return -1;
- }
- finally
- {
- }
- }
- public static int CompareParamsFor(IDatabase CurrDb, string maccode, string usercode, ref string errorinfo)
- {
- try
- {
- MacOrderSendDal macdal = new MacOrderSendDal(CurrDb);
- Machine mac = macdal.ReadMachine(maccode, ref errorinfo);
- if (mac == null)
- {
- //string logerrorinfo = "";
- //WriteLog.WriteLogStr(maccode, "", DateTime.Now, $"读取机台错误:{errorinfo}", ref logerrorinfo);
- return -1;
- }
- if (mac.IsControl <= 0)
- {
- return 1;
- }
- int result = 0;
- switch (mac.MModeCode.ToLower())
- {
- case "dad3350":
- Dad3350ProgramDal dal = new Dad3350ProgramDal(CurrDb);
- result = dal.CompareParams(mac, "", ref errorinfo);
- if (result <= 0)
- {
- return -1;
- }
- return 1;
- case "dfd6341":
- Dfd6341ProgramDal dal6341 = new Dfd6341ProgramDal(CurrDb);
- result = dal6341.CompareParams(mac, "", ref errorinfo);
- if (result <= 0)
- {
- return -1;
- }
- return 1;
- case "dad3650":
- case "dfd6362":
- Dad3650ProgramDal dal3650 = new Dad3650ProgramDal(CurrDb);
- result = dal3650.CompareParams(mac, "", ref errorinfo);
- if (result <= 0)
- {
- return -1;
- }
- return 1;
- case "dfg8540":
- BgProgramDal bgdal = new BgProgramDal(CurrDb);
- result = bgdal.CompareParams(mac, "", ref errorinfo);
- if (result <= 0)
- {
- return -1;
- }
- return 1;
- default:
- string logerrorinfo = "";
- WriteLog.WriteLogStr(maccode, "", DateTime.Now, $"开始比对ASM参数......", ref logerrorinfo);
- Ad830PlusProgramDal tempdal = new Ad830PlusProgramDal(CurrDb);
- result = tempdal.CompareParams(mac, "", ref errorinfo);
- if (result <= 0)
- {
- WriteLog.WriteLogStr(maccode, "", DateTime.Now, $"ASM参数比对失败{errorinfo}", ref logerrorinfo);
- return -1;
- }
- return 1;
- }
- }
- catch (Exception ex)
- {
- errorinfo = ex.Message.ToString();
- return -1;
- }
- }
- //public static int CompareParams(string maccode, string usercode, ref string errorinfo)
- //{
- // IDatabase CurrDb = null;
- // try
- // {
- // CurrDb = DbFactory.Base(CurrDbCode);
- // CurrDb.BeginTrans();
- // MacOrderSendDal macdal = new MacOrderSendDal(CurrDb);
- // Machine mac = macdal.ReadMachine(maccode, ref errorinfo);
- // if (mac == null)
- // {
- // //string logerrorinfo = "";
- // //WriteLog.WriteLogStr(maccode, "", DateTime.Now, $"读取机台错误:{errorinfo}", ref logerrorinfo);
- // CurrDb.Rollback();
- // return -1;
- // }
- // if (mac.IsControl <= 0)
- // {
- // CurrDb.Rollback();
- // return 1;
- // }
- // if (mac.MModeCode.ToLower() == "dad3350")
- // {
- // Dad3350ProgramDal dal = new Dad3350ProgramDal(CurrDb);
- // int result = dal.CompareParams(mac, "", ref errorinfo);
- // if (result <= 0)
- // {
- // CurrDb.Commit();
- // return -1;
- // }
- // }
- // if (mac.MModeCode.ToLower() == "dfd6341")
- // {
- // Dfd6341ProgramDal dal = new Dfd6341ProgramDal(CurrDb);
- // int result = dal.CompareParams(mac, "", ref errorinfo);
- // if (result <= 0)
- // {
- // CurrDb.Commit();
- // return -1;
- // }
- // }
- // return 1;
- // }
- // catch (Exception ex)
- // {
- // errorinfo = ex.Message.ToString();
- // CurrDb.Rollback();
- // return -1;
- // }
- // finally
- // {
- // if (CurrDb != null)
- // CurrDb.Close();
- // }
- //}
- /// <summary>
- /// <summary>
- /// 文件参数比较
- /// </summary>
- /// <param name="maccode"></param>
- /// <param name="usercode"></param>
- /// <param name="errorinfo"></param>
- /// <returns></returns>
- public static int CompareFileParams(string maccode, string usercode, ref string errorinfo)
- {
- IDatabase CurrDb = null;
- try
- {
- CurrDb = DbFactory.Base(CurrDbCode);
- CurrDb.BeginTrans();
- //读取机台信息
- string condition = $" and a.FCode='{maccode}'";
- Machine mac = CurrDb.FindListForCondition<Machine>(condition, ref errorinfo).ToList()[0];
- if (mac.IsControl <= 0)
- {
- //说明此机台没有开启参数比对功能,无需比对
- CurrDb.Commit();
- return 1;
- }
- if (mac.SupplierFCode != "KNS")
- {
- //只有KNS机台才开启文件比对
- CurrDb.Commit();
- return 1;
- }
- //string programname = (string)imputds["programname"];
- ParamsComMstDal comdal = new ParamsComMstDal(CurrDb);
- ProgramMst programmst = comdal.GetMacProgram(mac, ref errorinfo);
- if (programmst == null)
- {
- errorinfo = $"未找到机台【{maccode}】对应的程序。{errorinfo}";
- CurrDb.Rollback();
- return -1;
- }
- //从机台上读取文件并保存
- string programdir = AppConfigurtaionServices.Configuration["ProgramDir"];
- KnsProgramDal knsdal = new KnsProgramDal(CurrDb);
- MacProgram macprogram = knsdal.SaveProgramFromMac(mac, programmst.FName, programdir, ref errorinfo);
- if (macprogram == null)
- {
- CurrDb.Rollback();
- return -1;
- }
- CurrDb.Commit();//先提交保存程序文件记录
- CurrDb.BeginTrans();
- //比较文件参数
- FileParamsComMst mst = comdal.CompareFileParams(mac, programmst, macprogram, ref errorinfo);
- if (mst == null)
- {
- errorinfo = $"未找到机台【{maccode}】程序【{programmst.FName}】对应的比对主档。{errorinfo}";
- CurrDb.Rollback();
- return -1;
- }
- //插入比对记录
- mst = comdal.IUFileParamsComMst(mst, usercode, ref errorinfo);
- if (mst == null)
- {
- errorinfo = $"插入比对结果发生错误:{errorinfo}";
- CurrDb.Rollback();
- return -1;
- }
- CurrDb.Commit();
- //如果参数不对,就发送停机指令
- if (mst.IsPass <= 0)
- {
- MacOrderDal macorderdal = new MacOrderDal(CurrDb);
- int result = macorderdal.SendStopMac(maccode, ref errorinfo);
- if (result <= 0)
- {
- errorinfo = $"发送停机指令发生错误,错误信息为:{errorinfo}";
- return -1;
- }
- }
- return 1;
- }
- catch (Exception ex)
- {
- errorinfo = ex.Message.ToString();
- CurrDb.Rollback();
- return -1;
- }
- finally
- {
- if (CurrDb != null)
- CurrDb.Close();
- }
- }
- public static int UpProgram(OrderBlock entitys, string filedir, string usercode, ref string errorinfo)
- {
- IDatabase CurrDb = null;
- try
- {
- CurrDb = DbFactory.Base(CurrDbCode);
- CurrDb.BeginTrans();
- string temperrorinfo1 = "";
- MacOrderSendDal senddal1 = new MacOrderSendDal(CurrDb);
- //上传文件
- string programname = "";
- int result = UpProgram(CurrDb, entitys, filedir, usercode, ref programname, ref errorinfo);
- if (result == -100)
- {
- //提示机台只能上传当前运行的程序
- senddal1.SendS10F3(entitys.MainMsg.McaCode, $"Upload recipe fail,Please check Loading again.", ref temperrorinfo1);
- CurrDb.Rollback();
- return result;
- }
- if (result <= 0)
- {
- senddal1.SendS10F3(entitys.MainMsg.McaCode, $" Recipe upload fail {programname}", ref temperrorinfo1);
- CurrDb.Rollback();
- return result;
- }
- //调MES上传程序接口
- //string actionName = "uploadRecipe";
- //string fullUrl = mesApiPrefix + actionName;
- //IDictionary<string, string> dic = new Dictionary<string, string>();
- //dic.Add("equipmentID", entitys.MainMsg.McaCode);
- //dic.Add("recipeName", programname);
- //dic.Add("version", result.ToString());
- //var response = HttpRequestHelper<OfilmMesApiResponse>.Get(fullUrl, dic, ref errorinfo);
- //errorinfo = $"调用MES上传程序接口:uploadRecipe,传入的参数:{JsonConvert.SerializeObject(dic)}," +
- // $"接收到的值为:{JsonConvert.SerializeObject(response)}";
- senddal1.SendS10F3(entitys.MainMsg.McaCode, $" Recipe upload success {programname}", ref temperrorinfo1);
- CurrDb.Commit();
- CallMesuploadRecipe(entitys.MainMsg.McaCode, programname, result, ref errorinfo);
- return 1;
- }
- catch (Exception ex)
- {
- errorinfo = ex.Message.ToString();
- CurrDb.Rollback();
- return -1;
- }
- finally
- {
- if (CurrDb != null)
- CurrDb.Close();
- }
- }
- /// <summary>
- /// 文件方式上传程序
- /// </summary>
- /// <param name="entitys"></param>
- /// <param name="filedir"></param>
- /// <param name="usercode"></param>
- /// <param name="errorinfo"></param>
- /// <returns></returns>
- public static int UpProgramForFile(OrderBlock entitys, string filedir, string usercode, ref string errorinfo)
- {
- IDatabase CurrDb = null;
- try
- {
- CurrDb = DbFactory.Base(CurrDbCode);
- CurrDb.BeginTrans();
- string temperrorinfo1 = "";
- MacOrderSendDal senddal1 = new MacOrderSendDal(CurrDb);
- //剔除WB机型
- string checkMachineForWB = string.Format($"SELECT COUNT(1) from machine WHERE MModeID in('14','184','187') and FCode='{entitys.MainMsg.McaCode}' ");
- int resultCheck = CurrDb.ExecuteBySql(checkMachineForWB);
- if (resultCheck > 0)
- return 1;
- //上传文件
- string programname = "";
- int result = UpProgramForFile(CurrDb, entitys, filedir, usercode, ref programname, ref errorinfo);
- //CallMesuploadRecipe(entitys.MainMsg.McaCode, programname, result, ref errorinfo);
- if (result == -100)
- {
- //提示机台只能上传当前运行的程序
- senddal1.SendS10F3(entitys.MainMsg.McaCode, $"Upload recipe fail,Please check Loading again.", ref temperrorinfo1);
- CurrDb.Rollback();
- return result;
- }
- if (result <= 0)
- {
- senddal1.SendS10F3(entitys.MainMsg.McaCode, $" Recipe upload fail {programname}", ref temperrorinfo1);
- CurrDb.Rollback();
- return result;
- }
- senddal1.SendS10F3(entitys.MainMsg.McaCode, $" Recipe upload success {programname}", ref temperrorinfo1);
- CurrDb.Commit();
- //调MES上传程序接口
- //string actionName = "uploadRecipe";
- //string fullUrl = mesApiPrefix + actionName;
- //IDictionary<string, string> dic = new Dictionary<string, string>();
- //dic.Add("equipmentID", entitys.MainMsg.McaCode);
- //dic.Add("recipeName", programname);
- //dic.Add("version", result.ToString());
- //var response = HttpRequestHelper<OfilmMesApiResponse>.Get(fullUrl, dic, ref errorinfo);
- //errorinfo = $"调用MES上传程序接口:uploadRecipe,传入的参数:{JsonConvert.SerializeObject(dic)}," +
- // $"接收到的值为:{JsonConvert.SerializeObject(response)}";
- CallMesuploadRecipe(entitys.MainMsg.McaCode, programname, result, ref errorinfo);
- return 1;
- }
- catch (Exception ex)
- {
- errorinfo = ex.Message.ToString();
- CurrDb.Rollback();
- return -1;
- }
- finally
- {
- if (CurrDb != null)
- CurrDb.Close();
- }
- }
- private static int CallMesuploadRecipe(string maccode, string programname, int version, ref string errorinfo)
- {
- var callMesInterface = AppConfigurtaionServices.Configuration["CallMesInterface"];
- if (callMesInterface == null || !Convert.ToBoolean(callMesInterface))
- {
- return 1;
- }
- try
- {
- //处理程序名称,传给MES的程序名称不能含.RCP扩展名称
- if (programname.Length > 4)
- {
- string extname = programname.Substring(programname.Length - 4, 4);
- if (extname == ".rcp")
- programname = programname.Substring(0, programname.Length - 4);
- }
- string actionName = "uploadRecipe";
- string fullUrl = mesApiPrefix + actionName;
- IDictionary<string, string> dic = new Dictionary<string, string>();
- dic.Add("equipmentID", maccode);
- dic.Add("recipeName", programname);
- dic.Add("version", version.ToString());
- var response = HttpRequestHelper<OfilmMesApiResponse>.Get(fullUrl, dic, ref errorinfo);
- errorinfo = $"调用MES上传程序接口:{fullUrl},传入的参数:{JsonConvert.SerializeObject(dic)}," +
- $"接收到的值为:{JsonConvert.SerializeObject(response)}";
- return 1;
- }
- catch (Exception ex)
- {
- errorinfo = ex.ToString();
- return -1;
- }
- }
- public static int ClearProgram(OrderBlock entitys, string usercode, ref string errorinfo)
- {
- IDatabase CurrDb = null;
- try
- {
- CurrDb = DbFactory.Base(CurrDbCode);
- CurrDb.BeginTrans();
- string condition = $" and a.FCode='{entitys.MainMsg.McaCode}'";
- List<Machine> macs = CurrDb.FindListForCondition<Machine>(condition, ref errorinfo).ToList();
- if (macs[0].IsRemoveProgram <= 0)
- {
- errorinfo = $"机台【{entitys.MainMsg.McaCode}】设置为不清除程序。";
- return -1;
- }
- int result = 0;
- switch (macs[0].MModeCode.ToLower())
- {
- case "dad3350"://未测试
- case "dfd6340-wash":
- case "dfd6341-wash":
- case "dfd6341":
- case "dfd6340":
- Dad3350ProgramDal dad3350 = new Dad3350ProgramDal(CurrDb);
- if (AppConfigurtaionServices.Configuration["Client"] == "Onsemi")
- {
- result = dad3350.ClearProgramAutoDir(entitys.MainMsg.McaCode, ref errorinfo);
- }
- else
- {
- result = dad3350.ClearProgram(entitys.MainMsg.McaCode, ref errorinfo);
- }
- if (result <= 0)
- {
- CurrDb.Rollback();
- return -1;
- }
- break;
- default:
- MacProgramDal dal = new MacProgramDal(CurrDb);
- result = dal.ClearProgram(entitys.MainMsg.McaCode, ref errorinfo);
- if (result <= 0)
- {
- CurrDb.Rollback();
- return -1;
- }
- break;
- }
- CurrDb.Commit();
- return 1;
- }
- catch (Exception ex)
- {
- errorinfo = ex.Message.ToString();
- CurrDb.Rollback();
- return -1;
- }
- finally
- {
- if (CurrDb != null)
- CurrDb.Close();
- }
- }
- private static int UpProgram(IDatabase db, 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 = db.FindListForCondition<Machine>(condition, ref errorinfo).ToList();
- if (macs.Count <= 0)
- {
- errorinfo = $"未找到机台编号{entity.MainMsg.McaCode}的信息。";
- return -1;
- }
- if (macs[0].MModeCode == "ADT7900DUO")
- {
- // ADT 设备没有上传程序按钮,也没法通过共享文件的形式上传。故不响应上传事件,全部使用WEP-Web端业务进行处理。
- return 1;
- }
- if (AppConfigurtaionServices.Configuration["CallMesInterface"] != null && Convert.ToBoolean(AppConfigurtaionServices.Configuration["CallMesInterface"]))
- {
- string currprogramname = CallFunction.GetProgramName(macs[0].FCode, ref errorinfo);
- if (currprogramname == "")
- {
- return -1;
- }
- if (programname != currprogramname)
- {
- errorinfo = $"当前程序名称={currprogramname},上传程序名称={programname},只能上传当前运行的程序......";
- return -100;
- }
- }
- string logerrorinfo = "";
- WriteLog.WriteLogStr(macs[0].FCode, "", DateTime.Now, $"机台型号={macs[0].MModeCode.Trim().ToLower()}", ref logerrorinfo);
- switch (macs[0].MModeCode.Trim().ToLower())
- {
- case "dad3350":
- case "dad3650":
- case "dfd6362":
- case "dfd6341":
- case "dfd6340":
- case "dfd6340-001":
- WriteLog.WriteLogStr(macs[0].FCode, "", DateTime.Now, $"开始解析disco程序名称", ref logerrorinfo);
- programname = DiodesProgramFileHelper.GetProgramName01(filedatas, ref errorinfo);
- if (errorinfo != "")
- {
- errorinfo = $"分析文件名称发生错误:{errorinfo}";
- return -1;
- }
- WriteLog.WriteLogStr(macs[0].FCode, "", DateTime.Now, $"解析程序名称完成,解析后程序名称={programname}", ref logerrorinfo);
- break;
- case "dfg8540":
- programname = Bg8761ProgramFileHelper.GetProgramName01(filedatas, ref errorinfo);
- if (errorinfo != "")
- {
- errorinfo = $"分析文件名称发生错误:{errorinfo}";
- return -1;
- }
- break;
- }
- BusinessFileDal dal = new BusinessFileDal(db);
- BusinessFile busifile = dal.UpdownFile(filedatas, filedir, programname, macs[0], remark, usercode, ref errorinfo);
- if (busifile == null)
- {
- errorinfo = $"处理文件发生错误:{errorinfo}";
- return -1;
- }
- //添加程序,用于参数比对
- ProgramMstDal pmdal = new ProgramMstDal(db);
- pmdal.IUProgramMst(macs[0], programname, ref errorinfo);
- return busifile.Version;
- }
- catch (Exception ex)
- {
- errorinfo = ex.Message.ToString();
- return -1;
- }
- }
- private static int UpProgramForFile(IDatabase db, 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;
- string condition = $" and a.fcode='{entity.MainMsg.McaCode}'";
- List<Machine> macs = db.FindListForCondition<Machine>(condition, ref errorinfo).ToList();
- if (macs.Count <= 0)
- {
- errorinfo = $"未找到机台编号{entity.MainMsg.McaCode}的信息。";
- return -1;
- }
- string currprogramname = CallFunction.GetProgramName(macs[0].FCode, ref errorinfo);
- currprogramname = $"{currprogramname}.rcp";
- if (currprogramname == "")
- {
- return -1;
- }
- //if (programname != currprogramname)
- //{
- // errorinfo = $"当前程序名称={currprogramname},上传程序名称={programname},只能上传当前运行的程序......";
- // return -100;
- //}
- //调用文件上传模式
- SocketFile dal = new SocketFile();
- BusinessFile busifile = dal.UploadFile(macs[0], programname, ref errorinfo);
- if (busifile == null)
- {
- errorinfo = $"处理文件发生错误:{errorinfo}";
- return -1;
- }
- //添加程序,用于参数比对
- ProgramMstDal pmdal = new ProgramMstDal(db);
- pmdal.IUProgramMst(macs[0], programname, ref errorinfo);
- return busifile.Version;
- }
- catch (Exception ex)
- {
- errorinfo = ex.Message.ToString();
- return -1;
- }
- }
- private static int UpProgram001(IDatabase db, OrderBlock entity, string usercode, 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();
- string programname = datas[0].FContent;
- //string filepath = datas[1].FContent;
- //查找程序表,是否存在此程序名称的记录
- string condition = $" and {EntityAttribute.GetPropertyCondition<ProgramMst>(nameof(ProgramMst.FName))}='{programname}'";
- List<ProgramMst> programmst = db.FindListForCondition<ProgramMst>(condition, ref errorinfo).ToList();
- ProgramMst programentity = null;
- if (programmst.Count <= 0)
- {
- //添加程序记录
- programentity = new ProgramMst();
- errorinfo = $"未找到程序【{programname}】,请先配置程序及其比对的参数。";
- return -1;
- }
- else
- {
- programentity = programmst[0];
- }
- //读取机台
- condition = $" and a.FCode='{entity.MainMsg.McaCode}'";
- Machine mac = db.FindListForCondition<Machine>(condition, ref errorinfo).ToList()[0];
- if (mac == null)
- {
- //说明此机台没有开启参数比对功能,无需比对
- errorinfo = $"未找到机台【{entity.MainMsg.McaCode}】";
- return -1;
- }
- //比对参数,并保存比对结果
- ParamsComMstDal comparedal = new ParamsComMstDal(db);
- ParamsComMst commst = comparedal.CompareParams(mac, programentity, ref errorinfo);
- if (commst == null)
- return -1;
- commst = comparedal.IUParamsComMst(commst, usercode, ref errorinfo);
- if (commst == null)
- return -1;
- if (commst.IsPass <= 0)
- {
- errorinfo = "参数比对没有通过。";
- return -100;
- }
- //programentity.ServerPath = filepath;
- ////更新服务器程序路径
- //int result = db.UpdateFor<ProgramMst>(programentity, usercode);
- //if (result <= 0)
- // return -1;
- return 1;
- }
- catch (Exception ex)
- {
- errorinfo = ex.Message.ToString();
- return -1;
- }
- }
- //private static int UpProgram(IDatabase db, OrderBlock entity, string usercode, ref string errorinfo)
- //{
- // try
- // {
- // string filedir = AppConfigurtaionServices.Configuration["ProgramDir"];
- // 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();
- // string programname = datas[0].FContent;
- // string programdata = datas[1].FContent;
- // byte[] filedatas = datas[1].OrgDatas;
- // //查找程序表,是否存在此程序名称的记录
- // string condition = $" and {EntityAttribute.GetPropertyCondition<ProgramMst>(nameof(ProgramMst.FName))}='{programname}'";
- // List<ProgramMst> programmst = db.FindListForCondition<ProgramMst>(condition, ref errorinfo).ToList();
- // ProgramMst programentity = null;
- // if (programmst.Count <= 0)
- // {
- // //添加程序记录
- // programentity = new ProgramMst();
- // errorinfo = $"未找到程序【{programname}】,请先配置程序及其比对的参数。";
- // return -1;
- // }
- // else
- // {
- // programentity = programmst[0];
- // }
- // //比对参数,并保存比对结果
- // ParamsComMstDal comparedal = new ParamsComMstDal(db);
- // ParamsComMst commst = comparedal.CompareParams(entity.MainMsg.McaCode, programentity.ID, ref errorinfo);
- // if (commst == null)
- // return -1;
- // //if(commst.IsPass<=0)
- // //{
- // // errorinfo = "参数比对没有通过。";
- // // return -100;
- // //}
- // commst = comparedal.IUParamsComMst(commst, usercode, ref errorinfo);
- // if (commst == null)
- // return -1;
- // if (commst.IsPass <= 0)
- // {
- // errorinfo = "参数比对没有通过。";
- // return -100;
- // }
- // programentity.ServerPath = filedir + $"\\{programentity.ID}";
- // int result = UnityHelper.WriteFile(programentity.ServerPath, filedatas, ref errorinfo);
- // if (result <= 0)
- // return -1;
- // //更新服务器程序路径
- // result = db.UpdateFor<ProgramMst>(programentity, usercode);
- // if (result <= 0)
- // return -1;
- // return 1;
- // }
- // catch (Exception ex)
- // {
- // errorinfo = ex.Message.ToString();
- // return -1;
- // }
- //}
- /// <summary>
- /// 计算机台产量
- /// </summary>
- /// <param name="maccode"></param>
- /// <param name="usercode"></param>
- /// <param name="errorinfo"></param>
- /// <returns></returns>
- public static int AccountMacCount(string maccode, string usercode, ref string errorinfo)
- {
- IDatabase CurrDb = null;
- try
- {
- CurrDb = DbFactory.Base(CurrDbCode);
- CurrDb.BeginTrans();
- MacCountDal dal = new MacCountDal(CurrDb);
- List<Machine> macs = CurrDb.FindListForCondition<Machine>($" and a.fcode='{maccode}'", ref errorinfo).ToList();
- int result = dal.IMacCount(macs[0], usercode, ref errorinfo);
- if (result < 0)
- {
- CurrDb.Rollback();
- return -1;
- }
- CurrDb.Commit();
- return result;
- }
- catch (Exception ex)
- {
- errorinfo = ex.Message.ToString();
- CurrDb.Rollback();
- return -1;
- }
- finally
- {
- if (CurrDb != null)
- CurrDb.Close();
- }
- }
- /// <summary>
- /// 保存机台程序
- /// </summary>
- /// <param name="maccode"></param>
- /// <param name="usercode"></param>
- /// <param name="errorinfo"></param>
- /// <returns></returns>
- public static int SaveProgram(string maccode, string usercode, ref string errorinfo)
- {
- IDatabase CurrDb = null;
- try
- {
- CurrDb = DbFactory.Base(CurrDbCode);
- CurrDb.BeginTrans();
- //读取机台信息
- string condition = $" and a.FCode='{maccode}'";
- Machine mac = CurrDb.FindListForCondition<Machine>(condition, ref errorinfo).ToList()[0];
- if (mac == null)
- {
- CurrDb.Rollback();
- return -1;
- }
- //从机台上读取文件并保存
- string programdir = AppConfigurtaionServices.Configuration["ProgramDir"];
- if (mac.SupplierFCode == "KNS")
- {
- KnsProgramDal knsdal = new KnsProgramDal(CurrDb);
- MacProgram macprogram = knsdal.SaveProgram(maccode, usercode, ref errorinfo);
- if (macprogram == null)
- {
- CurrDb.Rollback();
- return -1;
- }
- }
- else
- {
- AsmProgramDal knsdal = new AsmProgramDal(CurrDb);
- MacProgram macprogram = knsdal.SaveProgram(maccode, usercode, ref errorinfo);
- if (macprogram == null)
- {
- CurrDb.Rollback();
- return -1;
- }
- }
- CurrDb.Commit();//先提交保存程序文件记录
- return 1;
- }
- catch (Exception ex)
- {
- errorinfo = ex.Message.ToString();
- CurrDb.Rollback();
- return -1;
- }
- finally
- {
- if (CurrDb != null)
- CurrDb.Close();
- }
- }
- public static MacOrder GetMacOrder(string maccode, ref string errorinfo)
- {
- IDatabase CurrDb = null;
- try
- {
- CurrDb = DbFactory.Base(CurrDbCode);
- CurrDb.BeginTrans();
- //读取机台信息
- string condition = $" and b.FCode='{maccode}'";
- List<MacOrder> mac = CurrDb.FindListForCondition<MacOrder>(condition, ref errorinfo).ToList();
- if (mac.Count <= 0)
- {
- errorinfo = $"未找到机台【{maccode}】对应的指令信息。";
- return null;
- }
- CurrDb.Commit();
- return mac[0];
- }
- catch (Exception ex)
- {
- errorinfo = $"读取机台【{maccode}】指令发生错误,错误信息为【{ex.Message.ToString()}】";
- CurrDb.Rollback();
- return null;
- }
- finally
- {
- if (CurrDb != null)
- CurrDb.Close();
- }
- }
- public static Machine GetMachine(string maccode, ref string errorinfo)
- {
- IDatabase CurrDb = null;
- try
- {
- CurrDb = DbFactory.Base(CurrDbCode);
- CurrDb.BeginTrans();
- //读取机台信息
- string condition = $" and a.FCode='{maccode}'";
- List<Machine> mac = CurrDb.FindListForCondition<Machine>(condition, ref errorinfo).ToList();
- if (mac.Count <= 0)
- {
- errorinfo = $"未找到机台【{maccode}】。";
- return null;
- }
- CurrDb.Commit();
- return mac[0];
- }
- catch (Exception ex)
- {
- errorinfo = $"读取机台【{maccode}】指令发生错误,错误信息为【{ex.Message.ToString()}】";
- CurrDb.Rollback();
- return null;
- }
- finally
- {
- if (CurrDb != null)
- CurrDb.Close();
- }
- }
- public static List<OrderStatus> GetOrderStatus(int orderid, ref string errorinfo)
- {
- IDatabase CurrDb = null;
- try
- {
- CurrDb = DbFactory.Base(CurrDbCode);
- CurrDb.BeginTrans();
- //读取机台信息
- string condition = $" and a.PreID={orderid}";
- List<OrderStatus> entitys = CurrDb.FindListForCondition<OrderStatus>(condition, ref errorinfo).ToList();
- if (entitys == null)
- {
- CurrDb.Rollback();
- return null;
- }
- CurrDb.Commit();
- return entitys;
- }
- catch (Exception ex)
- {
- errorinfo = $"读取指令状态发生错误,错误信息为【{ex.Message.ToString()}】";
- CurrDb.Rollback();
- return null;
- }
- finally
- {
- if (CurrDb != null)
- CurrDb.Close();
- }
- }
- public static int AutoTrackOut(OrderBlock entitys, ref string errorinfo)
- {
- IDatabase CurrDb = null;
- try
- {
- CurrDb = DbFactory.Base(CurrDbCode);
- CurrDb.BeginTrans();
- string condition = $" and a.FCode='{entitys.MainMsg.McaCode}'";
- List<Machine> macs = CurrDb.FindListForCondition<Machine>(condition, ref errorinfo).ToList();
- StepTrackDal dal = new StepTrackDal(CurrDb);
- int result = dal.AutoTrackOut(macs[0], ref errorinfo);
- if (result <= 0)
- {
- CurrDb.Rollback();
- return -1;
- }
- CurrDb.Commit();
- return 1;
- }
- catch (Exception ex)
- {
- errorinfo = ex.Message.ToString();
- CurrDb.Rollback();
- return -1;
- }
- finally
- {
- if (CurrDb != null)
- CurrDb.Close();
- }
- }
- public static string GetProgramName(string maccode, ref string errorinfo)
- {
- IDatabase CurrDb = null;
- try
- {
- CurrDb = DbFactory.Base(ReadDbCode);
- //读取机台信息
- string condition = $" and a.FCode='{maccode}'";
- List<Machine> mac = CurrDb.FindListForCondition<Machine>(condition, ref errorinfo).ToList();
- if (mac.Count <= 0)
- {
- errorinfo = $"未找到机台【{maccode}】。";
- return null;
- }
- switch (mac[0].MModeCode.ToLower())
- {
- case "dad3650":
- case "dfd6362":
- Dad3650ProgramDal dal3650 = new Dad3650ProgramDal(CurrDb);
- return dal3650.GetProgramName(mac[0], ref errorinfo);
- case "dfg8540":
- BgProgramDal bgdal = new BgProgramDal(CurrDb);
- return bgdal.GetProgramName(mac[0], ref errorinfo);
- default:
- Ad830PlusProgramDal dal = new Ad830PlusProgramDal(CurrDb);
- return dal.GetProgramName(mac[0], ref errorinfo);
- }
- }
- catch (Exception ex)
- {
- errorinfo = $"读取机台【{maccode}】程序名称发生错误,错误信息为【{ex.Message.ToString()}】";
- return null;
- }
- finally
- {
- if (CurrDb != null)
- CurrDb.Close();
- }
- }
- public static int RequestProgram(OrderBlock entitys, ILogger loger, ref string errorinfo)
- {
- IDatabase CurrDb = null;
- try
- {
- CurrDb = DbFactory.Base(CurrDbCode);
- CurrDb.BeginTrans();
- string programname = entitys.Datalists[0].FContent.Trim();
- //根据程序名称获取程序数据
- ProgramDal dal = new ProgramDal(CurrDb, loger);
- //int result = dal.DownloadProgramS7F6(entitys.MainMsg.McaCode, programname, ref errorinfo);
- int result = dal.DownloadProgram(entitys.MainMsg.McaCode, programname, ref errorinfo);
- return result;
- }
- catch (Exception ex)
- {
- errorinfo = ex.StackTrace + ex.Message.ToString();
- CurrDb.Rollback();
- return -1;
- }
- finally
- {
- if (CurrDb != null)
- CurrDb.Close();
- }
- }
- /// <summary>
- /// 请求strip map
- /// </summary>
- /// <param name="entitys"></param>
- /// <param name="errorinfo"></param>
- /// <returns></returns>
- public static int RequestStripmap(OrderBlock entitys, ref string errorinfo)
- {
- IDatabase CurrDb = null;
- try
- {
- CurrDb = DbFactory.Base(CurrDbCode);
- CurrDb.BeginTrans();
- StripMapDal dal = new StripMapDal(CurrDb);
- int result = dal.RequestStripmapE142(entitys, ref errorinfo);
- if (result <= 0)
- {
- CurrDb.Rollback();
- return -1;
- }
- CurrDb.Commit();
- return 1;
- }
- catch (Exception ex)
- {
- errorinfo = ex.Message.ToString();
- CurrDb.Rollback();
- return -1;
- }
- finally
- {
- if (CurrDb != null)
- CurrDb.Close();
- }
- }
- public static int RequestUploadStripMap(OrderBlock entities, List<ReportDetail> reportDetails, ref string errorinfo)
- {
- IDatabase CurrDb = null;
- try
- {
- CurrDb = DbFactory.Base(CurrDbCode);
- CurrDb.BeginTrans();
- StripMapDal dal = new StripMapDal(CurrDb);
- int result = dal.RequestUploadStripMapE142(entities, reportDetails, ref errorinfo);
- if (result <= 0)
- {
- CurrDb.Rollback();
- return -1;
- }
- CurrDb.Commit();
- return 1;
- }
- catch (Exception ex)
- {
- errorinfo = ex.Message.ToString();
- CurrDb.Rollback();
- return -1;
- }
- finally
- {
- if (CurrDb != null)
- CurrDb.Close();
- }
- }
- }
- }
|