| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720 |
-
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using Curtain.DataAccess;
- using Curtain.Extension.ExObjectConvert;
- using Curtain.Extension.ExSystemData;
- using Curtain.Framework.Json;
- using Curtain.Helpers;
- using Curtain.Log;
- using Curtain.Net.Sockets.PLC;
- using Curtain.Net.Sockets.PLC.Model;
- using Curtain.Net.Sockets.PLC.Model.Siemens;
- using PLC_S.Proxy;
- namespace PLC_S.ServerModel
- {
- /// <summary>
- /// 自动返回产品型号等信息 xuwei add 2022-01-10
- /// </summary>
- public class GoodsAuto : SocketServer<SimpleSocketServerModel>, IShowFormLog, IWindowsServer
- {
- public Dictionary<string, PLC_S_GA> PLC_FLAGS = new Dictionary<string, PLC_S_GA>();
- public const string M_NAME = "GA";
- private MES_S _mes_s = null;
- private readonly Logger logger = Logger.CreateLogger(M_NAME);
- private readonly LogInfo logger_t = new LogInfo();
- private readonly LogInfo logger_e = new LogInfo();
- private bool _S_STOP = false;
- public int Interval
- {
- get;
- set;
- }
- public string EPTS_CODE
- {
- get;
- set;
- }
- public GoodsAuto()
- {
- logger.FileExistDays = 30;
- logger.FilePrefix = "";
- logger.FileSuffix = M_NAME;
- logger.LevelOneFile = true;
- logger.FileNameWithoutDate = true;
- logger_t.SubFolderFormat = "<name>";
- logger_t.FileExistDays = 30;
- logger_t.LevelOneFile = true;
- logger_e.FileExistDays = 10;
- this.Model.FormatType = CommandFormatType.StartStopChar;
- this.ServerStarting += ServerSocket_ServerStarting;
- this.ServerStarted += ServerSocket_ServerStarted;
- this.ServerStoping += ServerSocket_ServerStoping;
- this.ServerStoped += ServerSocket_ServerStoped;
- this.ServerMessage += ServerSocket_ServerMessage;
- this.Received += ServerSocket_Received;
- _mes_s = MES_S.Get();
- }
- #region Server
- public IFormLogShow FormLogShow
- {
- get;
- set;
- }
- private void ServerSocket_ServerStarting(object sender, CancelEventArgs e)
- {
- try
- {
- _S_STOP = false;
- logger.OutputTrace($"{M_NAME}_ServerStarting");
- }
- catch { }
- }
- private void ServerSocket_ServerStarted(object sender, EventArgs e)
- {
- try
- {
- _S_STOP = false;
- logger.OutputTrace($"{M_NAME}_ServerStarted");
- }
- catch { }
- }
- private void ServerSocket_ServerStoping(object sender, CancelEventArgs e)
- {
- try
- {
- _S_STOP = false;
- logger.OutputTrace($"{M_NAME}_ServerStoping");
- }
- catch { }
- }
- private void ServerSocket_ServerStoped(object sender, EventArgs e)
- {
- try
- {
- _S_STOP = false;
- logger.OutputTrace($"{M_NAME}_ServerStoped");
- }
- catch { }
- }
- private void ServerSocket_ServerMessage(object sender, ServerMessageEventArgs e)
- {
- try
- {
- _S_STOP = false;
- string message = e.ToString();
- string cip = e?.Client?.IP;
- if (e.Type == ServerMessageType.Debug)
- {
- Logger.Debug(message, $"{M_NAME}-T[{cip}]", logger_t);
- }
- if (e.Type == ServerMessageType.Error)
- {
- Logger.Error(e.Exception, message, $"{M_NAME}-E[{cip}]", logger_e);
- }
- if (e.Type == ServerMessageType.Trace)
- {
- Logger.Trace(message, $"{M_NAME}-T[{cip}]", logger_t);
- }
- if (e.Type == ServerMessageType.Warning)
- {
- Logger.Warn(message, $"{M_NAME}-E[{cip}]", logger_e);
- }
- FormLogShow?.ShowLog("ServerMessage=" + message);
- }
- catch { }
- }
- #endregion
- /// <summary>
- /// 返回产品型号
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void ServerSocket_Received(object sender, ReceiveSession e)
- {
- PLC_S_GA plc_s = null;
- string cIP = e?.Client?.IP;
- string logKeyT = $"{M_NAME}-T[{cIP}]";
- string logKeyE = $"{M_NAME}-E[{cIP}]";
- _S_STOP = false;
- SocketClient<SiemensS7_1200Model> plc = null;
- Logger LoggerT = null;
- try
- {
- LoggerT = Logger.CreateLogger(logKeyT, logger_t);
- lock (LoggerT)
- {
- LoggerT.BeginTracking();
- string outputMessage = e.ToString();
- Logger.Trace(outputMessage, logKeyT, logger_t);
- FormLogShow?.ShowLog(outputMessage);
- #region 【必须】判断接收数据是否为空
- if (string.IsNullOrWhiteSpace(e.Content))
- {
- outputMessage = "接收数据为空";
- Logger.Warn(outputMessage, logKeyT, logger_t);
- Logger.Warn(outputMessage, logKeyE, logger_e);
- FormLogShow?.ShowLog(outputMessage);
- return;
- }
- #endregion
- #region 【必须】判断接收设备代码是否为空
- outputMessage = e.Content;
- Logger.Trace(outputMessage, logKeyT, logger_t);
- FormLogShow?.ShowLog(outputMessage);
- string[] c = e.Content.Split('#');
- string flag = null;
- if (c.Length > 0)
- {
- flag = c[0];
- }
- string barCode = null;
- if (c.Length > 1)
- {
- barCode = c[1];
- }
- if (string.IsNullOrWhiteSpace(flag))
- {
- outputMessage = $"[{e.Content}]接收设备代码为空";
- Logger.Warn(outputMessage, logKeyT, logger_t);
- Logger.Warn(outputMessage, logKeyE, logger_e);
- FormLogShow?.ShowLog(outputMessage);
- return;
- }
- #endregion
- #region 【必须】读取INI配置文件
- plc_s = GetPLC_S_GA(flag, e, logKeyE);
- if (plc_s == null)
- {
- outputMessage = $"[{e.Content}]设备代码[{flag}]未找到ini配置或有错误";
- Logger.Error(null, outputMessage, logKeyT, logger_t);
- Logger.Error(null, outputMessage, logKeyE, logger_e);
- FormLogShow?.ShowLog(outputMessage);
- return;
- }
- #endregion
- #region 【必须】建立PLC连接
- if (!string.IsNullOrEmpty(plc_s.PLC_IP))
- {
- outputMessage = $"[{e.Content}]PLC_Connect={JsonHelper.FromObject(plc_s)}";
- Logger.Trace(outputMessage, logKeyT, logger_t);
- FormLogShow?.ShowLog(outputMessage);
- plc = new SocketClient<SiemensS7_1200Model>();
- plc.Connect(plc_s.PLC_IP, plc_s.PLC_PORT);
- }
- else
- {
- Logger.Trace("PLC地址未设置,测试数据使用!", logKeyT, logger_t);
- }
- PLCResult p_r;
- #endregion
- #region 【必须】判断接收条码格式是否正确
- if (string.IsNullOrWhiteSpace(barCode) ||
- barCode == "0" ||
- barCode.Length != 11 ||
- barCode.StartsWith("0") ||
- barCode.StartsWith("ERROR")
- )
- {
- outputMessage = $"[{e.Content}]接收条码格式错误";
- Logger.Warn(outputMessage, logKeyT, logger_t);
- Logger.Warn(outputMessage, logKeyE, logger_e);
- FormLogShow?.ShowLog(outputMessage);
- SendCode(plc_s, e, logKeyT, logKeyE, plc, 2);
- return;
- }
- #endregion
- #region 【可选】产品型号写入
- if (!string.IsNullOrEmpty(plc_s.PLC_GOODSCODE_CODE) && !string.IsNullOrEmpty(plc_s.PLC_GOODSCODE_CODENUM))
- {
- string goodsCode = GetGoodsCode(barCode, e, logKeyE);
- if (goodsCode == null)
- {
- outputMessage = $"[{e.Content}]此条码[{barCode}]不存在";
- Logger.Warn(outputMessage, logKeyT, logger_t);
- Logger.Warn(outputMessage, logKeyE, logger_e);
- FormLogShow?.ShowLog(outputMessage);
- if (!string.IsNullOrEmpty(plc_s.PLC_IP)) SendCode(plc_s, e, logKeyT, logKeyE, plc, 2);
- return;
- }
- if (!string.IsNullOrEmpty(plc_s.PLC_IP))
- {
- outputMessage = $"[{e.Content}]SET_GOODSCODE=[{goodsCode}]{plc_s.PLC_GOODSCODE_CODE + plc_s.PLC_GOODSCODE_CODENUM}";
- Logger.Trace(outputMessage, logKeyT, logger_t);
- FormLogShow?.ShowLog(outputMessage);
- p_r = plc.Write<string>(plc_s.PLC_GOODSCODE_CODE, plc_s.PLC_GOODSCODE_CODENUM, goodsCode);
- outputMessage = $"[{e.Content}]END_GOODSCODE=[{p_r}]{plc_s.PLC_GOODSCODE_CODE + plc_s.PLC_GOODSCODE_CODENUM}";
- Logger.Trace(outputMessage, logKeyT, logger_t);
- FormLogShow?.ShowLog(outputMessage);
- }
- else
- {
- outputMessage = $"[{e.Content}]产品型号=[{goodsCode}]";
- Logger.Trace(outputMessage, logKeyT, logger_t);
- FormLogShow?.ShowLog(outputMessage);
- }
- }
- #endregion
- #region 【可选】产品型号代码写入
- if (!string.IsNullOrEmpty(plc_s.PLC_SEATCOVER_CODE) && !string.IsNullOrEmpty(plc_s.PLC_SEATCOVER_CODENUM))
- {
- string intCode = GetSeatCoverCode(barCode, e, logKeyE);
- if (intCode == null)
- {
- outputMessage = $"[{e.Content}]此条码[{barCode}]不存在";
- Logger.Warn(outputMessage, logKeyT, logger_t);
- Logger.Warn(outputMessage, logKeyE, logger_e);
- FormLogShow?.ShowLog(outputMessage);
- if (!string.IsNullOrEmpty(plc_s.PLC_IP)) SendCode(plc_s, e, logKeyT, logKeyE, plc, 2);
- return;
- }
- if (string.IsNullOrWhiteSpace(intCode))
- {
- outputMessage = $"[{e.Content}]此条码[{barCode}]未设置型号代码";
- Logger.Error(null, outputMessage, logKeyT, logger_t);
- Logger.Error(null, outputMessage, logKeyE, logger_e);
- FormLogShow?.ShowLog(outputMessage);
- if (!string.IsNullOrEmpty(plc_s.PLC_IP)) SendCode(plc_s, e, logKeyT, logKeyE, plc, 2);
- return;
- }
- if (!string.IsNullOrEmpty(plc_s.PLC_IP))
- {
- outputMessage = $"[{e.Content}]SET_SEATCOVER=[{intCode}]{plc_s.PLC_SEATCOVER_CODE + plc_s.PLC_SEATCOVER_CODENUM}";
- Logger.Trace(outputMessage, logKeyT, logger_t);
- FormLogShow?.ShowLog(outputMessage);
- p_r = plc.Write<short>(plc_s.PLC_SEATCOVER_CODE, plc_s.PLC_SEATCOVER_CODENUM, (short)(intCode.ToInt32()));
- outputMessage = $"[{e.Content}]END_SEATCOVER=[{p_r}]{plc_s.PLC_SEATCOVER_CODE + plc_s.PLC_SEATCOVER_CODENUM}";
- Logger.Trace(outputMessage, logKeyT, logger_t);
- FormLogShow?.ShowLog(outputMessage);
- }
- else
- {
- outputMessage = $"[{e.Content}]产品型号=[{intCode}]";
- Logger.Trace(outputMessage, logKeyT, logger_t);
- FormLogShow?.ShowLog(outputMessage);
- }
- }
- #endregion
-
- #region 【可选】产品类型写入
- if (!string.IsNullOrEmpty(plc_s.PLC_GOODSTYPE_CODE) && !string.IsNullOrEmpty(plc_s.PLC_GOODSTYPE_CODENUM))
- {
- Int16 goodsType = Convert.ToInt16(GetGoodsType(barCode, e, logKeyT));
- if (!string.IsNullOrEmpty(plc_s.PLC_IP))
- {
- outputMessage = $"[{e.Content}]SET_GoodsType=[{goodsType}]{plc_s.PLC_GOODSTYPE_CODE + plc_s.PLC_GOODSTYPE_CODENUM}";
- Logger.Trace(outputMessage, logKeyT, logger_t);
- FormLogShow?.ShowLog(outputMessage);
- p_r = plc?.Write<short>(plc_s.PLC_GOODSTYPE_CODE, plc_s.PLC_GOODSTYPE_CODENUM, goodsType);
- outputMessage = $"[{e.Content}]END_GoodsType=[{p_r.ToString()}]{plc_s.PLC_GOODSTYPE_CODE + plc_s.PLC_GOODSTYPE_CODENUM}";
- Logger.Trace(outputMessage, logKeyT, logger_t);
- FormLogShow?.ShowLog(outputMessage);
- }
- else
- {
- outputMessage = $"[{e.Content}]产品类型=[{goodsType}]";
- Logger.Trace(outputMessage, logKeyT, logger_t);
- FormLogShow?.ShowLog(outputMessage);
- }
- }
- #endregion
- #region 【可选】产品条码写入(字符串)
- if (!string.IsNullOrEmpty(plc_s.PLC_BARCODE_CODE) && !string.IsNullOrEmpty(plc_s.PLC_BARCODE_CODENUM))
- {
- if (!string.IsNullOrEmpty(plc_s.PLC_IP))
- {
- outputMessage = $"[{e.Content}]SET_BarCode=[{barCode}]{plc_s.PLC_BARCODE_CODE + plc_s.PLC_BARCODE_CODENUM}";
- Logger.Trace(outputMessage, logKeyT, logger_t);
- FormLogShow?.ShowLog(outputMessage);
- p_r = plc.Write<string>(plc_s.PLC_BARCODE_CODE, plc_s.PLC_BARCODE_CODENUM, barCode);
- outputMessage = $"[{e.Content}]END_BarCode=[{p_r}]{plc_s.PLC_BARCODE_CODE + plc_s.PLC_BARCODE_CODENUM}";
- Logger.Trace(outputMessage, logKeyT, logger_t);
- FormLogShow?.ShowLog(outputMessage);
- }
- else
- {
- outputMessage = $"[{e.Content}]产品条码=[{barCode}]";
- Logger.Trace(outputMessage, logKeyT, logger_t);
- FormLogShow?.ShowLog(outputMessage);
- }
- }
- #endregion
- #region 【可选】产品条码写入(长数字)
- if (!string.IsNullOrEmpty(plc_s.PLC_BARCODENUM_CODE) && !string.IsNullOrEmpty(plc_s.PLC_BARCODENUM_CODENUM))
- {
- if (!string.IsNullOrEmpty(plc_s.PLC_IP))
- {
- outputMessage = $"[{e.Content}]SET_BarCodeNum=[{barCode}]{plc_s.PLC_BARCODENUM_CODE + plc_s.PLC_BARCODENUM_CODENUM}";
- Logger.Trace(outputMessage, logKeyT, logger_t);
- FormLogShow?.ShowLog(outputMessage);
- p_r = plc.Write<float>(plc_s.PLC_BARCODENUM_CODE, plc_s.PLC_BARCODENUM_CODENUM, Convert.ToSingle(barCode));
- outputMessage = $"[{e.Content}]END_BarCodeNum=[{p_r}]{plc_s.PLC_BARCODENUM_CODE + plc_s.PLC_BARCODENUM_CODENUM}";
- Logger.Trace(outputMessage, logKeyT, logger_t);
- FormLogShow?.ShowLog(outputMessage);
- }
- else
- {
- outputMessage = $"[{e.Content}]产品条码=[{barCode}]";
- Logger.Trace(outputMessage, logKeyT, logger_t);
- FormLogShow?.ShowLog(outputMessage);
- }
- }
- #endregion
- #region 【可选】半检返工标识写入
- if (!string.IsNullOrEmpty(plc_s.PLC_SEMIREWORK_CODE) && !string.IsNullOrEmpty(plc_s.PLC_SEMIREWORK_CODENUM))
- {
- Int16 goodsType = Convert.ToInt16(GetSemiReWork(barCode, e, logKeyT));
- if (!string.IsNullOrEmpty(plc_s.PLC_IP))
- {
- outputMessage = $"[{e.Content}]SET_SemiRework=[{goodsType}]{plc_s.PLC_SEMIREWORK_CODE + plc_s.PLC_SEMIREWORK_CODENUM}";
- Logger.Trace(outputMessage, logKeyT, logger_t);
- FormLogShow?.ShowLog(outputMessage);
- p_r = plc?.Write<short>(plc_s.PLC_SEMIREWORK_CODE, plc_s.PLC_SEMIREWORK_CODENUM, goodsType);
- outputMessage = $"[{e.Content}]END_SemiRework=[{p_r.ToString()}]{plc_s.PLC_SEMIREWORK_CODE + plc_s.PLC_SEMIREWORK_CODENUM}";
- Logger.Trace(outputMessage, logKeyT, logger_t);
- FormLogShow?.ShowLog(outputMessage);
- }
- else
- {
- outputMessage = $"[{e.Content}]半检返工标识=[{goodsType}]";
- Logger.Trace(outputMessage, logKeyT, logger_t);
- FormLogShow?.ShowLog(outputMessage);
- }
- }
- #endregion
- #region 【可选】产品等级写入
- if (!string.IsNullOrEmpty(plc_s.PLC_GOODSLEVEL_CODE) && !string.IsNullOrEmpty(plc_s.PLC_GOODSLEVEL_CODENUM))
- {
- Int16 goodsLevel = Convert.ToInt16(GetGoodsLevel(barCode, e, logKeyT));
- //如果有裸瓷标识,那么产品等级区分是否为裸瓷正品,裸瓷标识1+正品=91;裸瓷+副品=92 。非裸瓷为原逻辑
- if (!string.IsNullOrEmpty(plc_s.PLC_LUOCI) && plc_s.PLC_LUOCI == "1")
- {
- Int16 luoci = Convert.ToInt16(GetLuociFlag(barCode, e, logKeyT));
- if (luoci == 1 && goodsLevel == 4)
- {
- goodsLevel = 91;
- }
- if (luoci == 1 && goodsLevel == 5)
- {
- goodsLevel = 92;
- }
- }
- if (!string.IsNullOrEmpty(plc_s.PLC_IP))
- {
- outputMessage = $"[{e.Content}]SET_GoodsLevel=[{goodsLevel}]{plc_s.PLC_GOODSLEVEL_CODE + plc_s.PLC_GOODSLEVEL_CODENUM}";
- Logger.Trace(outputMessage, logKeyT, logger_t);
- FormLogShow?.ShowLog(outputMessage);
- p_r = plc?.Write<short>(plc_s.PLC_GOODSLEVEL_CODE, plc_s.PLC_GOODSLEVEL_CODENUM, goodsLevel);
- outputMessage = $"[{e.Content}]END_GoodsLevel=[{p_r.ToString()}]{plc_s.PLC_GOODSLEVEL_CODE + plc_s.PLC_GOODSLEVEL_CODENUM}";
- Logger.Trace(outputMessage, logKeyT, logger_t);
- FormLogShow?.ShowLog(outputMessage);
- }
- else
- {
- outputMessage = $"[{e.Content}]产品等级=[{goodsLevel}]";
- Logger.Trace(outputMessage, logKeyT, logger_t);
- FormLogShow?.ShowLog(outputMessage);
- }
- }
- #endregion
- #region 【可选】半检补土(适用于官塘)
- if (!string.IsNullOrEmpty(plc_s.PLC_SEMIREPAIR_CODE) && !string.IsNullOrEmpty(plc_s.PLC_SEMIREPAIR_CODENUM))
- {
- Int16 semiRepair = Convert.ToInt16(GetSemiRepair(barCode, e, logKeyT));
- if (!string.IsNullOrEmpty(plc_s.PLC_IP))
- {
- outputMessage = $"[{e.Content}]SET_SemiRepair=[{semiRepair}]{plc_s.PLC_SEMIREPAIR_CODE + plc_s.PLC_SEMIREPAIR_CODENUM}";
- Logger.Trace(outputMessage, logKeyT, logger_t);
- FormLogShow?.ShowLog(outputMessage);
- p_r = plc?.Write<short>(plc_s.PLC_SEMIREPAIR_CODE, plc_s.PLC_SEMIREPAIR_CODENUM, semiRepair);
- outputMessage = $"[{e.Content}]END_SemiRepair=[{p_r.ToString()}]{plc_s.PLC_SEMIREPAIR_CODE + plc_s.PLC_SEMIREPAIR_CODENUM}";
- Logger.Trace(outputMessage, logKeyT, logger_t);
- FormLogShow?.ShowLog(outputMessage);
- }
- else
- {
- outputMessage = $"[{e.Content}]半检补土=[{semiRepair}]";
- Logger.Trace(outputMessage, logKeyT, logger_t);
- FormLogShow?.ShowLog(outputMessage);
- }
- }
- #endregion
- #region 【可选】产品等级写入(重烧过的产品写6,非重烧的写4)(适用于官塘)
- if (!string.IsNullOrEmpty(plc_s.PLC_GOODSLEVEL2_CODE) && !string.IsNullOrEmpty(plc_s.PLC_GOODSLEVEL2_CODENUM))
- {
- Int16 goodsLevel = Convert.ToInt16(GetGoodsLevel(barCode, e, logKeyT));
- //如果判定为重烧不算重烧品,暂时当副品,重烧过才真正算重烧
- if (goodsLevel == 6) goodsLevel = 5;
- goodsLevel = Convert.ToInt16(GetAutoFireID(barCode, goodsLevel.ToString(), "6", e, logKeyT));
- if (!string.IsNullOrEmpty(plc_s.PLC_IP))
- {
- outputMessage = $"[{e.Content}]SET_GoodsLevel2=[{goodsLevel}]{plc_s.PLC_GOODSLEVEL2_CODE + plc_s.PLC_GOODSLEVEL2_CODENUM}";
- Logger.Trace(outputMessage, logKeyT, logger_t);
- FormLogShow?.ShowLog(outputMessage);
- p_r = plc?.Write<short>(plc_s.PLC_GOODSLEVEL2_CODE, plc_s.PLC_GOODSLEVEL2_CODENUM, goodsLevel);
- outputMessage = $"[{e.Content}]END_GoodsLevel2=[{p_r.ToString()}]{plc_s.PLC_GOODSLEVEL2_CODE + plc_s.PLC_GOODSLEVEL2_CODENUM}";
- Logger.Trace(outputMessage, logKeyT, logger_t);
- FormLogShow?.ShowLog(outputMessage);
- }
- else
- {
- outputMessage = $"[{e.Content}]产品等级=[{goodsLevel}]";
- Logger.Trace(outputMessage, logKeyT, logger_t);
- FormLogShow?.ShowLog(outputMessage);
- }
- }
- #endregion
- #region 【可选】产品重烧标识写入
- if (!string.IsNullOrEmpty(plc_s.PLC_ISREFIRE_CODE) && !string.IsNullOrEmpty(plc_s.PLC_ISREFIRE_CODENUM))
- {
- Int16 isRefire = Convert.ToInt16(GetAutoFireID(barCode, "1", "6", e, logKeyT));
- if (!string.IsNullOrEmpty(plc_s.PLC_IP))
- {
- outputMessage = $"[{e.Content}]SET_IsRefire=[{isRefire}]{plc_s.PLC_ISREFIRE_CODE + plc_s.PLC_ISREFIRE_CODENUM}";
- Logger.Trace(outputMessage, logKeyT, logger_t);
- FormLogShow?.ShowLog(outputMessage);
- p_r = plc?.Write<short>(plc_s.PLC_ISREFIRE_CODE, plc_s.PLC_ISREFIRE_CODENUM, isRefire);
- outputMessage = $"[{e.Content}]END_IsRefire=[{p_r.ToString()}]{plc_s.PLC_ISREFIRE_CODE + plc_s.PLC_ISREFIRE_CODENUM}";
- Logger.Trace(outputMessage, logKeyT, logger_t);
- FormLogShow?.ShowLog(outputMessage);
- }
- else
- {
- outputMessage = $"[{e.Content}]产品重烧=[{isRefire}]";
- Logger.Trace(outputMessage, logKeyT, logger_t);
- FormLogShow?.ShowLog(outputMessage);
- }
- }
- #endregion
- #region 【可选】质量登记返修写入(官塘厂)
- if (!string.IsNullOrEmpty(plc_s.PLC_GOODSREPAIR_CODE) && !string.IsNullOrEmpty(plc_s.PLC_GOODSREPAIR_CODENUM))
- {
- Int16 goodsRepair = Convert.ToInt16(GetGoodsRepair(barCode, e, logKeyT));
- if (!string.IsNullOrEmpty(plc_s.PLC_IP))
- {
- outputMessage = $"[{e.Content}]SET_GoodsLevel=[{goodsRepair}]{plc_s.PLC_GOODSREPAIR_CODE + plc_s.PLC_GOODSREPAIR_CODENUM}";
- Logger.Trace(outputMessage, logKeyT, logger_t);
- FormLogShow?.ShowLog(outputMessage);
- p_r = plc?.Write<short>(plc_s.PLC_GOODSREPAIR_CODE, plc_s.PLC_GOODSREPAIR_CODENUM, goodsRepair);
- outputMessage = $"[{e.Content}]END_GoodsLevel=[{p_r.ToString()}]{plc_s.PLC_GOODSREPAIR_CODE + plc_s.PLC_GOODSREPAIR_CODENUM}";
- Logger.Trace(outputMessage, logKeyT, logger_t);
- FormLogShow?.ShowLog(outputMessage);
- }
- else
- {
- outputMessage = $"[{e.Content}]返修=[{goodsRepair}]";
- Logger.Trace(outputMessage, logKeyT, logger_t);
- FormLogShow?.ShowLog(outputMessage);
- }
- }
- #endregion
- #region 【可选】智能连体重烧写入,智能重烧253,连体重烧254,其他返回立库配置代码,未配置返回252(官塘厂)
- if (!string.IsNullOrEmpty(plc_s.PLC_GOODSTYPEISREFIRE_CODE) && !string.IsNullOrEmpty(plc_s.PLC_GOODSTYPEISREFIRE_CODENUM))
- {
- //产品代码读取
- string intCode = GetWareHouse(barCode, e, logKeyE);
- if (intCode == "") intCode = "252";
- //2022-10-13 xuwei modify
- /* 取消重烧分类(智能连体重烧写入,智能重烧253,连体重烧254)
-
- //重烧识别读取
- Int16 isRefire = Convert.ToInt16(GetAutoFireID(barCode, "1", "6", e, logKeyT));
- //重烧产品返回 智能253,连体254
- if (isRefire == 6)
- {
- //智能连体读取
- Int16 goodsType = Convert.ToInt16(GetGoodsType(barCode, e, logKeyT));
- if (goodsType == 1) intCode = "253";
- if (goodsType == 2) intCode = "254";
- }
- */
- //写入智能连体重烧标识
- if (!string.IsNullOrEmpty(plc_s.PLC_IP))
- {
- outputMessage = $"[{e.Content}]SET_GOODSTYPEISREFIRE=[{intCode}]{plc_s.PLC_GOODSTYPEISREFIRE_CODE + plc_s.PLC_GOODSTYPEISREFIRE_CODENUM}";
- Logger.Trace(outputMessage, logKeyT, logger_t);
- FormLogShow?.ShowLog(outputMessage);
- p_r = plc.Write<short>(plc_s.PLC_GOODSTYPEISREFIRE_CODE, plc_s.PLC_GOODSTYPEISREFIRE_CODENUM, (short)(intCode.ToInt32()));
- outputMessage = $"[{e.Content}]END_GOODSTYPEISREFIRE=[{p_r}]{plc_s.PLC_GOODSTYPEISREFIRE_CODE + plc_s.PLC_GOODSTYPEISREFIRE_CODENUM}";
- Logger.Trace(outputMessage, logKeyT, logger_t);
- FormLogShow?.ShowLog(outputMessage);
- }
- else
- {
- outputMessage = $"[{e.Content}]智能连体重烧=[{intCode}]";
- Logger.Trace(outputMessage, logKeyT, logger_t);
- FormLogShow?.ShowLog(outputMessage);
- }
- }
- #endregion
- #region 【可选】产品缺陷类别写入
- if (!string.IsNullOrEmpty(plc_s.PLC_GOODSDEFECTTYPE_CODE) && !string.IsNullOrEmpty(plc_s.PLC_GOODSDEFECTTYPE_CODENUM))
- {
- Int16 goodsDefectType = Convert.ToInt16(GetDefectTypeId(barCode, e, logKeyT));
- //如果是重烧产品写入 16 代替产品缺陷类别
- //goodsDefectType = Convert.ToInt16(GetAutoFireID(barCode, goodsDefectType.ToString(), "16", e, logKeyT));
- if (!string.IsNullOrEmpty(plc_s.PLC_IP))
- {
- outputMessage = $"[{e.Content}]SET_DefectType=[{goodsDefectType}]{plc_s.PLC_GOODSDEFECTTYPE_CODE + plc_s.PLC_GOODSDEFECTTYPE_CODENUM}";
- Logger.Trace(outputMessage, logKeyT, logger_t);
- FormLogShow?.ShowLog(outputMessage);
- p_r = plc?.Write<short>(plc_s.PLC_GOODSDEFECTTYPE_CODE, plc_s.PLC_GOODSDEFECTTYPE_CODENUM, goodsDefectType);
- outputMessage = $"[{e.Content}]END_DefectType=[{p_r.ToString()}]{plc_s.PLC_GOODSDEFECTTYPE_CODE + plc_s.PLC_GOODSDEFECTTYPE_CODENUM}";
- Logger.Trace(outputMessage, logKeyT, logger_t);
- FormLogShow?.ShowLog(outputMessage);
- }
- else
- {
- outputMessage = $"[{e.Content}]缺陷类别=[{goodsDefectType}]";
- Logger.Trace(outputMessage, logKeyT, logger_t);
- FormLogShow?.ShowLog(outputMessage);
- }
- }
- #endregion
- #region 【可选】成型工号写入
- if (!string.IsNullOrEmpty(plc_s.PLC_GROUTINGUSER_CODE) && !string.IsNullOrEmpty(plc_s.PLC_GROUTINGUSER_CODENUM))
- {
- Int16 groutinguserCode = Convert.ToInt16(GetGroutingUserCode(barCode, e, logKeyT));
-
- if (!string.IsNullOrEmpty(plc_s.PLC_IP))
- {
- outputMessage = $"[{e.Content}]SET_GROUTINGUSER=[{groutinguserCode}]{plc_s.PLC_GROUTINGUSER_CODE + plc_s.PLC_GROUTINGUSER_CODENUM}";
- Logger.Trace(outputMessage, logKeyT, logger_t);
- FormLogShow?.ShowLog(outputMessage);
- p_r = plc?.Write<short>(plc_s.PLC_GROUTINGUSER_CODE, plc_s.PLC_GROUTINGUSER_CODENUM, groutinguserCode);
- outputMessage = $"[{e.Content}]END_GROUTINGUSER=[{p_r.ToString()}]{plc_s.PLC_GROUTINGUSER_CODE + plc_s.PLC_GROUTINGUSER_CODENUM}";
- Logger.Trace(outputMessage, logKeyT, logger_t);
- FormLogShow?.ShowLog(outputMessage);
- }
- else
- {
- outputMessage = $"[{e.Content}]成型工号=[{groutinguserCode}]";
- Logger.Trace(outputMessage, logKeyT, logger_t);
- FormLogShow?.ShowLog(outputMessage);
- }
- }
- #endregion
- #region 【可选】工序验证
- if (!string.IsNullOrEmpty(plc_s.PROCEDURE_CHECKID))
- {
- Int16 plc_flag = Convert.ToInt16(GetProcedureCheck(barCode, plc_s.PROCEDURE_CHECKID, e, logKeyT, logKeyE));
- if (!string.IsNullOrEmpty(plc_s.PLC_IP))
- {
- SendCode(plc_s, e, logKeyT, logKeyE, plc, plc_flag);
- }
- else
- {
- outputMessage = $"[{e.Content}]工序=[{plc_s.PROCEDURE_CHECKID}]工序验证=[{plc_flag}]";
- Logger.Trace(outputMessage, logKeyT, logger_t);
- FormLogShow?.ShowLog(outputMessage);
- }
- return;
- }
- #endregion
- #region 【可选】工序计件
- if (!string.IsNullOrEmpty(plc_s.PROCEDURE_ID) && (!string.IsNullOrEmpty(plc_s.PROCEDURE_USERCODE) || !string.IsNullOrEmpty(plc_s.WORKSTATION_ID)) )
- {
- //如果是重烧产品使用重烧ID
- if (!string.IsNullOrEmpty(plc_s.PROCEDURE_AUTOREFIRE_ID))
- {
- plc_s.PROCEDURE_ID = GetAutoFireID(barCode, plc_s.PROCEDURE_ID, plc_s.PROCEDURE_AUTOREFIRE_ID, e, logKeyE);
- }
- string p_id = GetFlowId(barCode, e, logKeyE);
- Int16 plc_flag = 0;
- if (p_id != plc_s.PROCEDURE_ID.ToString())
- {
- string userCode = "";
- //默认读取userCode
- if(!string.IsNullOrEmpty(plc_s.PROCEDURE_USERCODE))
- {
- userCode = plc_s.PROCEDURE_USERCODE;
- }
- //优先从工位取userCode
- if (!string.IsNullOrEmpty(plc_s.WORKSTATION_ID))
- {
- userCode = GetUserCodeFromWorkStation(plc_s.WORKSTATION_ID, e, logKeyE);
- outputMessage = $"[{e.Content}]DB_UserCode=[{userCode}]";
- Logger.Trace(outputMessage, logKeyT, logger_t);
- FormLogShow?.ShowLog(outputMessage);
- }
- //工序计件
- string result = SmartDeviceProxy.Instance.Invoke<string>(
- p => p.AddWorkPieceByStatus3(
- _mes_s.AccountCode,
- userCode,
- null,
- Convert.ToInt32(plc_s.PROCEDURE_ID),
- barCode,
- null));
- outputMessage = $"[{e.Content}]工序=[{plc_s.PROCEDURE_ID}]工号=[{userCode}]工序计件=[{result}]";
- Logger.Trace(outputMessage, logKeyT, logger_t);
- FormLogShow?.ShowLog(outputMessage);
- // 返回状态(成功、失败)
- if (result != "OK")
- {
- plc_flag = 3;
- if (result == "EE")
- {
- plc_flag = 4;
- outputMessage = $"MES服务端异常(详情参见MES端日志)";
- }
- else if (result == "EU-01")
- {
- outputMessage = $"无效的帐套或工号(详情参见MES端日志)";
- }
- else
- {
- outputMessage = $"其他错误(详情参见MES端日志)[{result}]";
- }
- Logger.Error(null, outputMessage, logKeyT, logger_t);
- Logger.Error(null, outputMessage, logKeyE, logger_e);
- FormLogShow?.ShowLog(outputMessage);
- if (!string.IsNullOrEmpty(plc_s.PLC_IP))
- {
- SendCode(plc_s, e, logKeyT, logKeyE, plc, plc_flag);
- }
- return;
- }
- }
- }
- #endregion
- #region 【可选】工序计件,二检交接,干补过给6,未干补过正常计件
- if (!string.IsNullOrEmpty(plc_s.PROCEDURE_DRYREPAIR_ID) && (!string.IsNullOrEmpty(plc_s.PROCEDURE_USERCODE) || !string.IsNullOrEmpty(plc_s.WORKSTATION_ID)))
- {
- string dryRepair = GetDryRepair(barCode, e, logKeyE);
- if(dryRepair == "0")
- {
- string p_id = GetFlowId(barCode, e, logKeyE);
- Int16 plc_flag = 0;
- if (p_id != plc_s.PROCEDURE_DRYREPAIR_ID.ToString())
- {
- string userCode = "";
- //默认读取userCode
- if (!string.IsNullOrEmpty(plc_s.PROCEDURE_USERCODE))
- {
- userCode = plc_s.PROCEDURE_USERCODE;
- }
- //优先从工位取userCode
- if (!string.IsNullOrEmpty(plc_s.WORKSTATION_ID))
- {
- userCode = GetUserCodeFromWorkStation(plc_s.WORKSTATION_ID, e, logKeyE);
- outputMessage = $"[{e.Content}]DB_UserCode=[{userCode}]";
- Logger.Trace(outputMessage, logKeyT, logger_t);
- FormLogShow?.ShowLog(outputMessage);
- }
- //工序计件
- string result = SmartDeviceProxy.Instance.Invoke<string>(
- p => p.AddWorkPieceByStatus3(
- _mes_s.AccountCode,
- userCode,
- null,
- Convert.ToInt32(plc_s.PROCEDURE_DRYREPAIR_ID),
- barCode,
- null));
- outputMessage = $"[{e.Content}]工序=[{plc_s.PROCEDURE_DRYREPAIR_ID}]工号=[{userCode}]工序计件=[{result}]";
- Logger.Trace(outputMessage, logKeyT, logger_t);
- FormLogShow?.ShowLog(outputMessage);
- // 返回状态(成功、失败)
- if (result != "OK")
- {
- plc_flag = 3;
- if (result == "EE")
- {
- plc_flag = 4;
- outputMessage = $"MES服务端异常(详情参见MES端日志)";
- }
- else if (result == "EU-01")
- {
- outputMessage = $"无效的帐套或工号(详情参见MES端日志)";
- }
- else
- {
- outputMessage = $"其他错误(详情参见MES端日志)[{result}]";
- }
- Logger.Error(null, outputMessage, logKeyT, logger_t);
- Logger.Error(null, outputMessage, logKeyE, logger_e);
- FormLogShow?.ShowLog(outputMessage);
- if (!string.IsNullOrEmpty(plc_s.PLC_IP))
- {
- SendCode(plc_s, e, logKeyT, logKeyE, plc, plc_flag);
- }
- return;
- }
- }
- }
- if(dryRepair == "1")
- {
- SendCode(plc_s, e, logKeyT, logKeyE, plc, 6);
- return;
- }
- }
- #endregion
- #region 【可选】工序计件(产品等级判定为重烧的产品自动重烧交接工序计件)(官塘厂)
- if (!string.IsNullOrEmpty(plc_s.PROCEDURE_REFIRE_RECIVE_ID) && (!string.IsNullOrEmpty(plc_s.PROCEDURE_REFIRE_RECIVE_USERCODE) ))
- {
- //识别是否判定为重烧的产品
- Int16 goodsLevel = Convert.ToInt16(GetGoodsLevel(barCode, e, logKeyT));
- if(goodsLevel == 6)
- {
- string p_id = GetFlowId(barCode, e, logKeyE);
- Int16 plc_flag = 0;
- if (p_id != plc_s.PROCEDURE_REFIRE_RECIVE_ID.ToString())
- {
- string userCode = "";
- //默认读取userCode
- if (!string.IsNullOrEmpty(plc_s.PROCEDURE_REFIRE_RECIVE_USERCODE))
- {
- userCode = plc_s.PROCEDURE_REFIRE_RECIVE_USERCODE;
- }
- //工序计件
- string result = SmartDeviceProxy.Instance.Invoke<string>(
- p => p.AddWorkPieceByStatus3(
- _mes_s.AccountCode,
- userCode,
- null,
- Convert.ToInt32(plc_s.PROCEDURE_REFIRE_RECIVE_ID),
- barCode,
- null));
- outputMessage = $"[{e.Content}]工序=[{plc_s.PROCEDURE_REFIRE_RECIVE_ID}]工号=[{userCode}]工序计件=[{result}]";
- Logger.Trace(outputMessage, logKeyT, logger_t);
- FormLogShow?.ShowLog(outputMessage);
- // 返回状态(成功、失败)
- if (result != "OK")
- {
- plc_flag = 3;
- if (result == "EE")
- {
- plc_flag = 4;
- outputMessage = $"MES服务端异常(详情参见MES端日志)";
- }
- else if (result == "EU-01")
- {
- outputMessage = $"无效的帐套或工号(详情参见MES端日志)";
- }
- else
- {
- outputMessage = $"其他错误(详情参见MES端日志)[{result}]";
- }
- Logger.Error(null, outputMessage, logKeyT, logger_t);
- Logger.Error(null, outputMessage, logKeyE, logger_e);
- FormLogShow?.ShowLog(outputMessage);
- if (!string.IsNullOrEmpty(plc_s.PLC_IP))
- {
- SendCode(plc_s, e, logKeyT, logKeyE, plc, plc_flag);
- }
- return;
- }
- }
- }
- }
- #endregion
- #region 【可选】(传入其他PLC数据)
- if (!string.IsNullOrEmpty(plc_s.PLC_IP_NEW))
- {
- //创建新的PLC连接
- SocketClient<SiemensS7_1200Model> plcnew = new SocketClient<SiemensS7_1200Model>();
- plcnew.Connect(plc_s.PLC_IP_NEW, plc_s.PLC_PORT);
- string intCode = "";
- //产品型号代码
- if (!string.IsNullOrEmpty(plc_s.PLC_SEATCOVER_CODE_OTHER) && !string.IsNullOrEmpty(plc_s.PLC_SEATCOVER_CODENUM_OTHER))
- {
- intCode = GetSeatCoverCode(barCode, e, logKeyE);
- if (string.IsNullOrWhiteSpace(intCode))
- {
- outputMessage = $"[{e.Content}]此条码[{barCode}]未设置型号代码";
- Logger.Error(null, outputMessage, logKeyT, logger_t);
- Logger.Error(null, outputMessage, logKeyE, logger_e);
- FormLogShow?.ShowLog(outputMessage);
- string outputMessages = $"[{e.Content}]SET_FLAG_CODE_OTHER[{2}]{plc_s.PLC_FLAG_CODE_OTHER + plc_s.PLC_FLAG_CODENUM_OTHER}";
- Logger.Trace(outputMessages, logKeyT, logger_t);
- FormLogShow?.ShowLog(outputMessages);
- plcnew?.Write<short>(plc_s.PLC_FLAG_CODE_OTHER, plc_s.PLC_FLAG_CODENUM_OTHER, 2);
- Logger.Trace(outputMessages, logKeyT, logger_t);
- FormLogShow?.ShowLog(outputMessage);
- return;
- }
- outputMessage = $"[{e.Content}]SET_SEATCOVER_OTHER=[{intCode}]{plc_s.PLC_SEATCOVER_CODE_OTHER + plc_s.PLC_SEATCOVER_CODENUM_OTHER}";
- Logger.Trace(outputMessage, logKeyT, logger_t);
- FormLogShow?.ShowLog(outputMessage);
- p_r = plcnew.Write<short>(plc_s.PLC_SEATCOVER_CODE_OTHER, plc_s.PLC_SEATCOVER_CODENUM_OTHER, (short)(intCode.ToInt32()));
- p_r = plcnew.Write<short>(plc_s.PLC_SEATCOVER_CODE_OTHER, plc_s.PLC_SEATCOVER_CODENUM_OTHER, intCode.ToInt16());
- outputMessage = $"[{e.Content}]END_SEATCOVER_OTHER=[{p_r.ToString()}]{plc_s.PLC_SEATCOVER_CODE_OTHER + plc_s.PLC_SEATCOVER_CODENUM_OTHER}";
- Logger.Trace(outputMessage, logKeyT, logger_t);
- FormLogShow?.ShowLog(outputMessage);
- }
- //产品型号
- if (!string.IsNullOrEmpty(plc_s.PLC_GOODSCODE_CODE_OTHER) && !string.IsNullOrEmpty(plc_s.PLC_GOODSCODE_CODENUM_OTHER))
- {
- string goodsCode = GetGoodsCode(barCode, e, logKeyE);
-
- outputMessage = $"[{e.Content}]SET_GOODSCODE_OTHER=[{goodsCode}]{plc_s.PLC_GOODSCODE_CODE_OTHER + plc_s.PLC_GOODSCODE_CODENUM_OTHER}";
- Logger.Trace(outputMessage, logKeyT, logger_t);
- FormLogShow?.ShowLog(outputMessage);
- p_r = plcnew.Write<string>(plc_s.PLC_GOODSCODE_CODE_OTHER, plc_s.PLC_GOODSCODE_CODENUM_OTHER, goodsCode);
- //再传一遍
- p_r = plcnew.Write<short>(plc_s.PLC_SEATCOVER_CODE_OTHER, plc_s.PLC_SEATCOVER_CODENUM_OTHER, intCode.ToInt16());
- outputMessage = $"[{e.Content}]END_GOODSCODE_OTHER=[{p_r}]{plc_s.PLC_GOODSCODE_CODE_OTHER + plc_s.PLC_GOODSCODE_CODENUM_OTHER}";
- Logger.Trace(outputMessage, logKeyT, logger_t);
- FormLogShow?.ShowLog(outputMessage);
-
- }
- //当前条码
- if (!string.IsNullOrEmpty(plc_s.PLC_BARCODE_CODE_OTHER) && !string.IsNullOrEmpty(plc_s.PLC_BARCODE_CODENUM_OTHER))
- {
- outputMessage = $"[{e.Content}]SET_BarCode_OTHER=[{barCode}]{plc_s.PLC_BARCODE_CODE_OTHER + plc_s.PLC_BARCODE_CODENUM_OTHER}";
- Logger.Trace(outputMessage, logKeyT, logger_t);
- FormLogShow?.ShowLog(outputMessage);
- p_r = plcnew.Write<string>(plc_s.PLC_BARCODE_CODE_OTHER, plc_s.PLC_BARCODE_CODENUM_OTHER, barCode);
- outputMessage = $"[{e.Content}]END_BarCode_OTHER=[{p_r}]{plc_s.PLC_BARCODE_CODE_OTHER + plc_s.PLC_BARCODE_CODENUM_OTHER}";
- Logger.Trace(outputMessage, logKeyT, logger_t);
- FormLogShow?.ShowLog(outputMessage);
-
- }
- //产品等级
- if (!string.IsNullOrEmpty(plc_s.PLC_GOODSLEVEL_CODE_OTHER) && !string.IsNullOrEmpty(plc_s.PLC_GOODSLEVEL_CODENUM_OTHER))
- {
- Int16 goodsLevel = Convert.ToInt16(GetGoodsLevel(barCode, e, logKeyT));
- //如果有裸瓷标识,那么产品等级区分是否为裸瓷正品,裸瓷标识1+正品=91;裸瓷+副品=92 。非裸瓷为原逻辑
- if (!string.IsNullOrEmpty(plc_s.PLC_LUOCI_OTHER) && plc_s.PLC_LUOCI_OTHER == "1")
- {
- Int16 luoci = Convert.ToInt16(GetLuociFlag(barCode, e, logKeyT));
- if (luoci == 1 && goodsLevel == 4)
- {
- goodsLevel = 91;
- }
- if (luoci == 1 && goodsLevel == 5)
- {
- goodsLevel = 92;
- }
- }
-
- outputMessage = $"[{e.Content}]SET_GoodsLevel_OTHER=[{goodsLevel}]{plc_s.PLC_GOODSLEVEL_CODE_OTHER + plc_s.PLC_GOODSLEVEL_CODENUM_OTHER}";
- Logger.Trace(outputMessage, logKeyT, logger_t);
- FormLogShow?.ShowLog(outputMessage);
- p_r = plc?.Write<short>(plc_s.PLC_GOODSLEVEL_CODE_OTHER, plc_s.PLC_GOODSLEVEL_CODENUM_OTHER, goodsLevel);
- outputMessage = $"[{e.Content}]END_GoodsLevel_OTHER=[{p_r.ToString()}]{plc_s.PLC_GOODSLEVEL_CODE_OTHER + plc_s.PLC_GOODSLEVEL_CODENUM_OTHER}";
- Logger.Trace(outputMessage, logKeyT, logger_t);
- FormLogShow?.ShowLog(outputMessage);
- }
- //扫码结果
- if (!string.IsNullOrEmpty(plc_s.PLC_FLAG_CODE_OTHER) && !string.IsNullOrEmpty(plc_s.PLC_FLAG_CODENUM_OTHER))
- {
- string outputMessages = $"[{e.Content}]SET_FLAG_CODE_OTHER[{1}]{plc_s.PLC_FLAG_CODE_OTHER + plc_s.PLC_FLAG_CODENUM_OTHER}";
- Logger.Trace(outputMessages, logKeyT, logger_t);
- FormLogShow?.ShowLog(outputMessages);
- p_r = plcnew?.Write<short>(plc_s.PLC_FLAG_CODE_OTHER, plc_s.PLC_FLAG_CODENUM_OTHER, 1);
- outputMessage = $"[{e.Content}]SET_FLAG_CODE_OTHER=[{p_r}]{plc_s.PLC_FLAG_CODE_OTHER + plc_s.PLC_FLAG_CODENUM_OTHER}";
- Logger.Trace(outputMessages, logKeyT, logger_t);
- FormLogShow?.ShowLog(outputMessage);
- }
- plcnew.Close();
- }
- #endregion
- #region 【可选】写入PLC扫码结果 【1:通过,2:扫码异常,3:工序异常,0:复位】
- if (!string.IsNullOrEmpty(plc_s.PLC_FLAG_CODE) && !string.IsNullOrEmpty(plc_s.PLC_FLAG_CODENUM))
- {
- if (!string.IsNullOrEmpty(plc_s.PLC_IP))
- {
- SendCode(plc_s, e, logKeyT, logKeyE, plc, 1);
- }
- else
- {
- outputMessage = $"[{e.Content}]PLC标识=[1]";
- Logger.Trace(outputMessage, logKeyT, logger_t);
- FormLogShow?.ShowLog(outputMessage);
- }
- }
- #endregion
- }
- }
- catch (Exception ex)
- {
- FormLogShow?.ShowLog($"[{e.Content}]ERROR={ex.Message}");
- if (plc_s != null)
- {
- Logger.Error(ex, $"[{e.Content}]ERROR", logKeyT, logger_t);
- Logger.Error(ex, $"[{e.Content}]ERROR", logKeyE, logger_e);
- SendCode(plc_s, e, logKeyT, logKeyE, plc, 2);
- }
- else
- {
- Logger.Error(ex, $"[{e.Content}]ERROR-NOFLAG", logKeyT, logger_t);
- Logger.Error(ex, $"[{e.Content}]ERROR-NOFLAG", logKeyE, logger_e);
- }
- }
- finally
- {
- LoggerT?.EndTracking();
- plc?.Disconnect();
- plc?.Close();
- }
- }
- private void SendCode(PLC_S_GA plc_s, ReceiveSession e, string loggerNameT, string loggerNameE, SocketClient<SiemensS7_1200Model> plc, short code)
- {
- try
- {
- string outputMessage = $"[{e.Content}]SET_FLAG_CODE=[{code}]{plc_s.PLC_FLAG_CODE + plc_s.PLC_FLAG_CODENUM}";
- Logger.Trace(outputMessage, loggerNameT, logger_t);
- FormLogShow?.ShowLog(outputMessage);
- PLCResult p_r = plc?.Write<short>(plc_s.PLC_FLAG_CODE, plc_s.PLC_FLAG_CODENUM, (short)code);
- outputMessage = $"[{e.Content}]SET_FLAG_CODE=[{p_r}]{plc_s.PLC_FLAG_CODE + plc_s.PLC_FLAG_CODENUM}";
- Logger.Trace(outputMessage, loggerNameT, logger_t);
- FormLogShow?.ShowLog(outputMessage);
- }
- catch (Exception ex)
- {
- Logger.Error(ex, $"[{e.Content}]ERROR-SendCode", loggerNameT, logger_t);
- Logger.Error(ex, $"[{e.Content}]ERROR-SendCode", loggerNameE, logger_e);
- FormLogShow?.ShowLog($"[{e.Content}]ERROR-SendCode={ex.Message}");
- }
- }
- private string GetGoodsCode(string barCode, ReceiveSession e, string loggerName)
- {
- try
- {
- using (IDataAccess conn = PLC_S_DataAccess.GetDataAccess(e))
- {
- string sqlStr = @"
- SELECT
- GDD.GOODSCODE
- FROM
- TP_PM_GROUTINGDAILYDETAIL GDD
- WHERE
- GDD.BARCODE = :BARCODE
- ";
- object result = conn.ExecuteScalar(sqlStr, new CDAParameter(":BARCODE", barCode));
- return result == null ? "" : result.ToString();
- }
- }
- catch (Exception ex)
- {
- Logger.Error(ex, $"[{e.Content}]ERROR-GetGoodsCode", loggerName, logger_e);
- FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetGoodsCode={ex.Message}");
- return null;
- }
- }
- private string GetSeatCoverCode(string barCode, ReceiveSession e, string loggerName)
- {
- try
- {
- using (IDataAccess conn = PLC_S_DataAccess.GetDataAccess(e))
- {
- string sqlStr = @"
- SELECT
- G.SEATCOVERCODE
- FROM
- TP_PM_GROUTINGDAILYDETAIL GDD
- INNER JOIN TP_MST_GOODS G ON G.GOODSID = GDD.GOODSID
- WHERE
- GDD.BARCODE = :BARCODE
- ";
- object result = conn.ExecuteScalar(sqlStr, new CDAParameter(":BARCODE", barCode));
- return result == null ? "" : result.ToString();
- }
- }
- catch (Exception ex)
- {
- Logger.Error(ex, $"[{e.Content}]ERROR-GetSeatCoverCode", loggerName, logger_e);
- FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetSeatCoverCode={ex.Message}");
- return null;
- }
- }
- private string GetGoodsType(string barCode, ReceiveSession e, string loggerName)
- {
- try
- {
- using (IDataAccess conn = PLC_S_DataAccess.GetDataAccess(e))
- {
- string sqlStr = @"
- SELECT
- -- G.GOODSCODE,
- -- G.SEATCOVERCODE,
- CASE
- WHEN T.GOODSTYPECODE = '001001001' THEN 2 --连体
- WHEN T.GOODSTYPECODE = '001001002' THEN 3 --分体
- WHEN T.GOODSTYPECODE = '001001003' THEN 1 --智能
- WHEN T.GOODSTYPECODE = '001001004' THEN 1 --智能高压
- ELSE 0 --其他
- END AS GOODSTYPE
- FROM
- TP_PM_GROUTINGDAILYDETAIL GDD
- INNER JOIN TP_MST_GOODS G ON G.GOODSID = GDD.GOODSID
- INNER JOIN TP_MST_GOODSTYPE T ON G.GOODSTYPEID = T.GOODSTYPEID
- WHERE
- GDD.BARCODE = :BARCODE --'10006800247'
- ";
- string goodsType = conn.ExecuteScalar(sqlStr, new CDAParameter(":BARCODE", barCode)).ToString();
- return goodsType;
- }
- }
- catch (Exception ex)
- {
- Logger.Error(ex, $"[{e.Content}]ERROR-GetGoodsType", loggerName, logger_e);
- FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetGoodsType={ex.Message}");
- return "0";
- }
- }
- private string GetFlowId(string barCode, ReceiveSession e, string loggerName)
- {
- try
- {
- using (IDataAccess conn = PLC_S_DataAccess.GetDataAccess())
- {
- string sqlStr = @"
- SELECT
- GDD.FLOWPROCEDUREID
- FROM
- TP_PM_INPRODUCTION GDD
- WHERE
- GDD.BARCODE = :BARCODE
- ";
- object result = conn.ExecuteScalar(sqlStr, new CDAParameter(":BARCODE", barCode));
- return result == null ? "0" : result.ToString();
- }
- }
- catch (Exception ex)
- {
- Logger.Error(ex, $"[{e.Content}]ERROR-GetFlowId", loggerName, logger_e);
- FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetFlowId={ex.Message}");
- return "0";
- }
- }
- private string GetAutoFireID(string barCode, string procedureId, string autoFireId, ReceiveSession e, string loggerName)
- {
- try
- {
- using (IDataAccess conn = PLC_S_DataAccess.GetDataAccess(e))
- {
- string sqlStr = @"
- SELECT T.ISREFIRE
- FROM TP_PM_INPRODUCTION T
- WHERE T.BARCODE = :BARCODE
- UNION
- SELECT T.ISREFIRE
- FROM TP_PM_INPRODUCTIONTRASH T
- WHERE T.BARCODE = :BARCODE
- ";
- string result = conn.ExecuteScalar(sqlStr, new CDAParameter(":BARCODE", barCode)).ToString();
- if (result == "6")
- return autoFireId;
- else
- return procedureId;
- }
- }
- catch (Exception ex)
- {
- Logger.Error(ex, $"[{e.Content}]ERROR-GetAutoFireID", loggerName, logger_e);
- FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetAutoFireID={ex.Message}");
- return "0";
- }
- }
- private string GetUserCodeFromWorkStation(string workStationId, ReceiveSession e, string loggerName)
- {
- try
- {
- using (IDataAccess conn = PLC_S_DataAccess.GetDataAccess())
- {
- string sqlStr = @"
- SELECT
- T.USERCODE
- FROM
- TP_MST_WORKSTATION T
- INNER JOIN TP_MST_USER U ON U.USERCODE = T.USERCODE
- WHERE
- T.WORKSTATIONID = :WORKSTATIONID
- ";
- object result = conn.ExecuteScalar(sqlStr, new CDAParameter(":WORKSTATIONID", workStationId));
- return result == null ? "0" : result.ToString();
- }
- }
- catch (Exception ex)
- {
- Logger.Error(ex, $"[{e.Content}]ERROR-GetUserCodeFromWorkStation", loggerName, logger_e);
- FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetUserCodeFromWorkStation={ex.Message}");
- return "0";
- }
- }
-
- private string GetSemiReWork(string barCode, ReceiveSession e, string loggerName)
- {
- try
- {
- using (IDataAccess conn = PLC_S_DataAccess.GetDataAccess())
- {
- string sqlStr = @"
- SELECT
- P.ISREWORKFLAG
- FROM
- TP_PM_INPRODUCTION P
- WHERE
- P.BARCODE = :BARCODE
- ";
- object result = conn.ExecuteScalar(sqlStr, new CDAParameter(":BARCODE", barCode));
- //返工标识(0:正常,1:半检返工中, 2:半检返修)
- //没找到记录表明产品报废写 3
- string resultFlag = "0";
- if(result !=null)
- {
- if (result.ToString() == "0") resultFlag = "1"; //正常
- if (result.ToString() == "1" || result.ToString() == "2") resultFlag = "2";//返工
- }
- else
- {
- resultFlag = "3";//报废
- }
- return resultFlag;
- }
- }
- catch (Exception ex)
- {
- Logger.Error(ex, $"[{e.Content}]ERROR-GetSemiReWork", loggerName, logger_e);
- FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetSemiReWork={ex.Message}");
- return "0";
- }
- }
- private string GetGoodsLevel(string barCode, ReceiveSession e, string loggerName)
- {
- try
- {
- using (IDataAccess conn = PLC_S_DataAccess.GetDataAccess())
- {
- string sqlStr = @"
- SELECT GL.GOODSLEVELTYPEID
- FROM TP_PM_GROUTINGDAILYDETAIL GDD
- LEFT JOIN TP_MST_GOODSLEVEL GL
- ON GDD.GOODSLEVELTYPEID = GL.GOODSLEVELTYPEID
- WHERE GDD.BARCODE = :BARCODE
- ";
- object result = conn.ExecuteScalar(sqlStr, new CDAParameter(":BARCODE", barCode));
- return result == null ? "0" : result.ToString();
- }
- }
- catch (Exception ex)
- {
- Logger.Error(ex, $"[{e.Content}]ERROR-GetGoodsLevel", loggerName, logger_e);
- FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetGoodsLevel={ex.Message}");
- return "0";
- }
- }
- private string GetLuociFlag(string barCode, ReceiveSession e, string loggerName)
- {
- try
- {
- using (IDataAccess conn = PLC_S_DataAccess.GetDataAccess())
- {
- string sqlStr = @"
- SELECT TO_CHAR(DECODE(GDD.LUOCIFLAG , '1', '1','0')) LUOCIFLAG
- FROM TP_PM_GROUTINGDAILYDETAIL GDD
- WHERE GDD.BARCODE = :BARCODE
- ";
- object result = conn.ExecuteScalar(sqlStr, new CDAParameter(":BARCODE", barCode));
- return result == null ? "0" : result.ToString();
- }
- }
- catch (Exception ex)
- {
- Logger.Error(ex, $"[{e.Content}]ERROR-GetGoodsLevel", loggerName, logger_e);
- FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetGoodsLevel={ex.Message}");
- return "0";
- }
- }
- private string GetGoodsRepair(string barCode, ReceiveSession e, string loggerName)
- {
- try
- {
- using (IDataAccess conn = PLC_S_DataAccess.GetDataAccess())
- {
- string sqlStr = @"
- SELECT
- DECODE( GR.REPAIRPATH, NULL, GDD.GOODSLEVELTYPEID, 0, GDD.GOODSLEVELTYPEID, GR.REPAIRPATH )
- FROM
- TP_PM_GROUTINGDAILYDETAIL GDD
- LEFT JOIN TP_PM_GOODSREPAIR GR ON GDD.BARCODE = GR.BARCODE
- AND GR.VALUEFLAG = 1
- WHERE
- GDD.VALUEFLAG = 1
- AND GDD.BARCODE = @BARCODE@
- ";
- object result = conn.ExecuteScalar(sqlStr, new CDAParameter(":BARCODE", barCode));
- return result == null ? "0" : result.ToString();
- }
- }
- catch (Exception ex)
- {
- Logger.Error(ex, $"[{e.Content}]ERROR-GetGoodsRepair", loggerName, logger_e);
- FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetGoodsRepair={ex.Message}");
- return "0";
- }
- }
- private string GetProcedureCheck(string barCode,string procedureId, ReceiveSession e, string loggerNameT, string loggerNameE)
- {
- try
- {
- using (IDataAccess dataAccess = PLC_S_DataAccess.GetDataAccess())
- {
- CDAParameter[] parameters = new CDAParameter[]
- {
- new CDAParameter("in_procedureid", procedureId),
- new CDAParameter("in_barcode", barCode),
- new CDAParameter("out_errType",DataType.Int32, ParameterDirection.Output),
- new CDAParameter("out_errMsg",DataType.VarChar, 4000, ParameterDirection.Output),
- new CDAParameter("out_goodsID",DataType.Int32, ParameterDirection.Output),
- new CDAParameter("out_goodsCode",DataType.VarChar, 400, ParameterDirection.Output),
- new CDAParameter("out_goodsType",DataType.Int32, ParameterDirection.Output),
- };
-
- int ii = dataAccess.ExecuteSPNonQuery("PRO_PM_CheckBarcode_PLC", parameters);
- Int16 plc_flag = 0;
- if (!int.TryParse(parameters[2].Value + "", out int errtype))
- {
- errtype = 4;
- }
- // 其他情况显示MES异常
- if (errtype == 4)
- {
- plc_flag = 4;
- }
- else if (errtype == 0)
- {
- plc_flag = 1;
- }
- else // errtype == 1 || errtype == 2 || errtype == 3
- {
- // 无效条码,显示不可到达
- plc_flag = 3;
- }
- string outputMessage = $"[{e.Content}]MESSAGE=[{errtype}][{parameters[3].Value}]";
- Logger.Trace(outputMessage, loggerNameT, logger_t);
- FormLogShow?.ShowLog(outputMessage);
- return plc_flag.ToString();
- }
- }
- catch (Exception ex)
- {
- Logger.Error(ex, $"[{e.Content}]ERROR-GetProcedureCheck", loggerNameE, logger_e);
- FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetProcedureCheck={ex.Message}");
- return "0";
- }
- }
- private string GetDefectTypeId(string barCode, ReceiveSession e, string loggerName)
- {
- try
- {
- using (IDataAccess conn = PLC_S_DataAccess.GetDataAccess())
- {
- string sqlStr = @"
- SELECT D.DEFECTCODE, D.DEFECTNAME, DT.DEFECTTYPENAME, DT.DEFECTTYPEID, DT.REMARKS
- FROM TP_PM_DEFECT PD
- LEFT JOIN TP_MST_DEFECT D
- ON PD.DEFECTID = D.DEFECTID
- LEFT JOIN TP_MST_DEFECTTYPE DT
- ON D.DEFECTTYPEID = DT.DEFECTTYPEID
- WHERE D.VALUEFLAG = 1
- AND PD.VALUEFLAG = 1
- AND DT.DEFECTTYPEID <> 21
- AND BARCODE = :BARCODE
- ORDER BY D.CREATETIME DESC
- ";
- DataTable dt = conn.ExecuteDatatable(sqlStr, new CDAParameter(":BARCODE", barCode));
- if (dt.Rows.Count > 0)
- {
- return dt.Rows[0]["REMARKS"].ToString();
- }
- else
- {
- return "0";
- }
- }
- }
- catch (Exception ex)
- {
- Logger.Error(ex, $"[{e.Content}]ERROR-GetDefectTypeId", loggerName, logger_e);
- FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetDefectTypeId={ex.Message}");
- return "0";
- }
- }
- //查询成型工号
- private int GetGroutingUserCode(string barCode, ReceiveSession e, string loggerName)
- {
- try
- {
- using (IDataAccess conn = PLC_S_DataAccess.GetDataAccess())
- {
- string sqlStr = @"
- SELECT substr(GDD.USERCODE,2 ) USERCODE
- FROM TP_PM_GROUTINGDAILYDETAIL GDD
- WHERE GDD.BARCODE = :BARCODE
- ";
- DataTable dt = conn.ExecuteDatatable(sqlStr, new CDAParameter(":BARCODE", barCode));
- if (dt.Rows.Count > 0)
- {
- string usercode = dt.Rows[0]["USERCODE"].ToString();
- return Convert.ToInt16(usercode);
- }
- else
- {
- return 0;
- }
- }
- }
- catch (Exception ex)
- {
- Logger.Error(ex, $"[{e.Content}]ERROR-GetDefectTypeId", loggerName, logger_e);
- FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetDefectTypeId={ex.Message}");
- return 0;
- }
- }
- private string GetSemiRepair(string barCode,ReceiveSession e,string loggerName)
- {
- try
- {
- using (IDataAccess conn = PLC_S_DataAccess.GetDataAccess())
- {
- string sqlStr = @"
- SELECT GL.GOODSLEVELTYPEID
- FROM TP_PM_GROUTINGDAILYDETAIL GDD
- LEFT JOIN TP_MST_GOODSLEVEL GL
- ON GDD.GOODSLEVELTYPEID = GL.GOODSLEVELTYPEID
- WHERE GDD.BARCODE = :BARCODE
- ";
- object goodsLevel = conn.ExecuteScalar(sqlStr, new CDAParameter(":BARCODE", barCode));
- sqlStr = @"
- SELECT
- 99
- FROM
- TP_PM_INPRODUCTION
- WHERE
- BARCODE = :BARCODE
- AND PROCEDUREID = 64 --完成的最后一个工序是1#二检补土时直接return 99(作为二检补土识别)
- ";
- object semiRepair = conn.ExecuteScalar(sqlStr, new CDAParameter(":BARCODE", barCode));
- if (semiRepair != null)
- {
- return semiRepair.ToString();
- }
- else
- {
- return goodsLevel.ToString();
- }
- }
- }
- catch (Exception ex)
- {
- Logger.Error(ex, $"[{e.Content}]ERROR-GetSemiReWork", loggerName, logger_e);
- FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetSemiReWork={ex.Message}");
- return "0";
- }
- }
- private string GetWareHouse(string barCode, ReceiveSession e, string loggerName)
- {
- try
- {
- using (IDataAccess conn = PLC_S_DataAccess.GetDataAccess(e))
- {
- string sqlStr = @"
- SELECT
- PART
- FROM
- (
- SELECT
- T.PART,','
- || LISTAGG ( T.GOODSID1, ',' ) WITHIN GROUP ( ORDER BY T.PART ) || ','
- || LISTAGG ( T.GOODSID2, ',' ) WITHIN GROUP ( ORDER BY T.PART ) || ','
- || LISTAGG ( T.GOODSID3, ',' ) WITHIN GROUP ( ORDER BY T.PART ) || ','
- || LISTAGG ( T.GOODSID4, ',' ) WITHIN GROUP ( ORDER BY T.PART ) || ','
- || LISTAGG ( T.GOODSID5, ',' ) WITHIN GROUP ( ORDER BY T.PART ) || ','
- || LISTAGG ( T.GOODSID6, ',' ) WITHIN GROUP ( ORDER BY T.PART ) || ','
- || LISTAGG ( T.GOODSID7, ',' ) WITHIN GROUP ( ORDER BY T.PART ) || ','
- || LISTAGG ( T.GOODSID8, ',' ) WITHIN GROUP ( ORDER BY T.PART ) || ','
- || LISTAGG ( T.GOODSID9, ',' ) WITHIN GROUP ( ORDER BY T.PART ) || ','
- || LISTAGG ( T.GOODSID10, ',' ) WITHIN GROUP ( ORDER BY T.PART ) || ',' AS SQLSTR
- FROM
- (
- SELECT
- m.SETTINGNO AS part,
- M.GOODSID1,
- M.GOODSID2,
- M.GOODSID3,
- M.GOODSID4,
- M.GOODSID5,
- M.GOODSID6,
- M.GOODSID7,
- M.GOODSID8,
- M.GOODSID9,
- M.GOODSID10
- FROM
- TP_MST_WAREHOUSESETTING M
- ) T
- GROUP BY
- T.PART
- ) TT
- WHERE
- INSTR( TT.SQLSTR, ',' || ( SELECT GOODSID FROM TP_PM_GROUTINGDAILYDETAIL WHERE BARCODE = :BARCODE) || ',' ) > 0
- ";
- string wareHouse = conn.ExecuteScalar(sqlStr, new CDAParameter(":BARCODE", barCode)).ToString();
- return wareHouse;
- }
- }
- catch (Exception ex)
- {
- Logger.Error(ex, $"[{e.Content}]ERROR-GetWareHouse", loggerName, logger_e);
- FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetWareHouse={ex.Message}");
- return "0";
- }
- }
- private string GetDryRepair(string barCode, ReceiveSession e, string loggerName)
- {
- try
- {
- using (IDataAccess conn = PLC_S_DataAccess.GetDataAccess())
- {
- string sqlStr = @"
- SELECT
- CASE WHEN PROCEDUREID = 65 THEN '1' ELSE '0' END AS DRY
- FROM
- TP_PM_PRODUCTIONDATA
- WHERE
- BARCODE = @BARCODE@
- AND ROWNUM = 1
- ORDER BY
- PRODUCTIONDATAID DESC
- ";
- object result = conn.ExecuteScalar(sqlStr, new CDAParameter(":BARCODE", barCode));
- return result == null ? "0" : result.ToString();
- }
- }
- catch (Exception ex)
- {
- Logger.Error(ex, $"[{e.Content}]ERROR-GetDryRepair", loggerName, logger_e);
- FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetDryRepair={ex.Message}");
- return "0";
- }
- }
- private PLC_S_GA GetPLC_S_GA(string flag, ReceiveSession e, string loggerName)
- {
- try
- {
- flag = M_NAME + flag;
- if (PLC_FLAGS.ContainsKey(flag))
- {
- return PLC_FLAGS[flag];
- }
- else
- {
- PLC_S_GA plc_s = new PLC_S_GA();
- INIHelper ini = INIHelper.Create($@"PLC_S_INI\PLC_S_{M_NAME}.ini");
- plc_s.PLC_IP = ini.Read(flag, "PLC_IP");
- plc_s.PLC_PORT = ini.Read(flag, "PLC_PORT").ToInt32();
- plc_s.PLC_FLAG_CODE = ini.Read(flag, "PLC_FLAG_CODE");
- plc_s.PLC_FLAG_CODENUM = ini.Read(flag, "PLC_FLAG_CODENUM");
- plc_s.PLC_SEATCOVER_CODE = ini.Read(flag, "PLC_SEATCOVER_CODE");
- plc_s.PLC_SEATCOVER_CODENUM = ini.Read(flag, "PLC_SEATCOVER_CODENUM");
- plc_s.PLC_BARCODE_CODE = ini.Read(flag, "PLC_BARCODE_CODE");
- plc_s.PLC_BARCODE_CODENUM = ini.Read(flag, "PLC_BARCODE_CODENUM");
- plc_s.PLC_BARCODENUM_CODE = ini.Read(flag, "PLC_BARCODENUM_CODE");
- plc_s.PLC_BARCODENUM_CODENUM = ini.Read(flag, "PLC_BARCODENUM_CODENUM");
- plc_s.PLC_GOODSCODE_CODE = ini.Read(flag, "PLC_GOODSCODE_CODE");
- plc_s.PLC_GOODSCODE_CODENUM = ini.Read(flag, "PLC_GOODSCODE_CODENUM");
- plc_s.PLC_GOODSTYPE_CODE = ini.Read(flag, "PLC_GOODSTYPE_CODE");
- plc_s.PLC_GOODSTYPE_CODENUM = ini.Read(flag, "PLC_GOODSTYPE_CODENUM");
- plc_s.PLC_SEMIREWORK_CODE = ini.Read(flag, "PLC_SEMIREWORK_CODE");
- plc_s.PLC_SEMIREWORK_CODENUM = ini.Read(flag, "PLC_SEMIREWORK_CODENUM");
- plc_s.PLC_SEMIREPAIR_CODE = ini.Read(flag, "PLC_SEMIREPAIR_CODE");
- plc_s.PLC_SEMIREPAIR_CODENUM = ini.Read(flag, "PLC_SEMIREPAIR_CODENUM");
- plc_s.PLC_GOODSLEVEL_CODE = ini.Read(flag, "PLC_GOODSLEVEL_CODE");
- plc_s.PLC_GOODSLEVEL_CODENUM = ini.Read(flag, "PLC_GOODSLEVEL_CODENUM");
- plc_s.PLC_GOODSLEVEL2_CODE = ini.Read(flag, "PLC_GOODSLEVEL2_CODE");
- plc_s.PLC_GOODSLEVEL2_CODENUM = ini.Read(flag, "PLC_GOODSLEVEL2_CODENUM");
- plc_s.PLC_ISREFIRE_CODE = ini.Read(flag, "PLC_ISREFIRE_CODE");
- plc_s.PLC_ISREFIRE_CODENUM = ini.Read(flag, "PLC_ISREFIRE_CODENUM");
- plc_s.PLC_GOODSTYPEISREFIRE_CODE = ini.Read(flag, "PLC_GOODSTYPEISREFIRE_CODE");
- plc_s.PLC_GOODSTYPEISREFIRE_CODENUM = ini.Read(flag, "PLC_GOODSTYPEISREFIRE_CODENUM");
- plc_s.PLC_GOODSREPAIR_CODE = ini.Read(flag, "PLC_GOODSREPAIR_CODE");
- plc_s.PLC_GOODSREPAIR_CODENUM = ini.Read(flag, "PLC_GOODSREPAIR_CODENUM");
- plc_s.PLC_GOODSDEFECTTYPE_CODE = ini.Read(flag, "PLC_GOODSDEFECTTYPE_CODE");
- plc_s.PLC_GOODSDEFECTTYPE_CODENUM = ini.Read(flag, "PLC_GOODSDEFECTTYPE_CODENUM");
- plc_s.PROCEDURE_ID = ini.Read(flag, "PROCEDURE_ID");
- plc_s.PROCEDURE_USERCODE = ini.Read(flag, "PROCEDURE_USERCODE");
- plc_s.PROCEDURE_DRYREPAIR_ID = ini.Read(flag, "PROCEDURE_DRYREPAIR_ID");
- plc_s.PROCEDURE_REFIRE_RECIVE_ID = ini.Read(flag, "PROCEDURE_REFIRE_RECIVE_ID");
- plc_s.PROCEDURE_REFIRE_RECIVE_USERCODE = ini.Read(flag, "PROCEDURE_REFIRE_RECIVE_USERCODE");
- plc_s.WORKSTATION_ID = ini.Read(flag, "WORKSTATION_ID");
- plc_s.WORKSTATION_NAME = ini.Read(flag, "WORKSTATION_NAME");
- plc_s.PLC_IP_NEW = ini.Read(flag, "PLC_IP_NEW");
- plc_s.PLC_SEATCOVER_CODE_OTHER = ini.Read(flag, "PLC_SEATCOVER_CODE_OTHER");
- plc_s.PLC_SEATCOVER_CODENUM_OTHER = ini.Read(flag, "PLC_SEATCOVER_CODENUM_OTHER");
- plc_s.PLC_GOODSCODE_CODE_OTHER = ini.Read(flag, "PLC_GOODSCODE_CODE_OTHER");
- plc_s.PLC_GOODSCODE_CODENUM_OTHER = ini.Read(flag, "PLC_GOODSCODE_CODENUM_OTHER");
- plc_s.PLC_BARCODE_CODE_OTHER = ini.Read(flag, "PLC_BARCODE_CODE_OTHER");
- plc_s.PLC_BARCODE_CODENUM_OTHER = ini.Read(flag, "PLC_BARCODE_CODENUM_OTHER");
- plc_s.PLC_FLAG_CODE_OTHER = ini.Read(flag, "PLC_FLAG_CODE_OTHER");
- plc_s.PLC_FLAG_CODENUM_OTHER = ini.Read(flag, "PLC_FLAG_CODENUM_OTHER");
- plc_s.PLC_GROUTINGUSER_CODE = ini.Read(flag, "PLC_GROUTINGUSER_CODE");
- plc_s.PLC_GROUTINGUSER_CODENUM = ini.Read(flag, "PLC_GROUTINGUSER_CODENUM");
- plc_s.PLC_LUOCI = ini.Read(flag, "PLC_LUOCI");
-
- plc_s.PLC_GOODSLEVEL_CODE_OTHER = ini.Read(flag, "PLC_GOODSLEVEL_CODE_OTHER");
- plc_s.PLC_GOODSLEVEL_CODENUM_OTHER = ini.Read(flag, "PLC_GOODSLEVEL_CODENUM_OTHER");
- plc_s.PLC_LUOCI_OTHER = ini.Read(flag, "PLC_LUOCI_OTHER");
- PLC_FLAGS.Add(flag, plc_s);
- return plc_s;
- }
- }
- catch (Exception ex)
- {
- Logger.Error(ex, $"[{e.Content}]ERROR-GetPLC_S_GA", loggerName, logger_e);
- FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetPLC_S_GA={ex.Message}");
- return null;
- }
- }
- }
- }
|