| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946 |
- <%@ WebHandler Language="C#" Class="autoPacking6151" %>
- using System;
- using System.Web;
- using System.Data;
- using DK.XuWei.WebMes;
- using Curtain.DataAccess;
- using Newtonsoft.Json.Linq;
- /// <summary>
- /// PLC对接使用
- /// 带参数barcode,扫描头处理逻辑;
- /// 不带参数barcode,轮询处理逻辑;
- /// xuwei add 2023-12-31
- /// </summary>
- public class autoPacking6151 : IHttpHandler
- {
- public static class PLC
- {
- public static string plcIp = "192.168.0.250";
- public static int plcPort = 102;
- public static string dbBarcode = "1.2"; //1.0 => 1.2
- public static string dbGoodsId = "1.14";
- public static string dbGoodsNum = "1.16";
- public static string dbResult = "1.18";
- public static string dbLogoId = "1.22";//替换产品等级
- public static string dbMaterialcode = "1.30";
- public static string dbRead = "1.26";
- public static string[] dbBarcodeBlock = { "2.2", "2.32", "2.62", "2.92", "2.122", "2.152", "2.182", "2.212", "2.242", "2.272", "2.302", "2.332" };
- public static string dbBanMa = "2.362";//2.360 => 2.362
- public static string dbUsercode = "2.376"; //150.374 => 150.376
- }
- public static class API
- {
- public static string accountCode = "dongke";
- public static string userId = "1529";
- public static string userCode = "DONGKEXW";
- public static string userName = "徐伟";
- public static string userPassword = "D63AC55256F8048265387A2B0388F1D2";
- public static string sessionKey = "C2A5AE55-8E9B-45F9-A0AF-6A5A1BF3457C";
- public static int procedureID = 107; //3#包装
- public static bool debug = false;
- }
- public bool resultFlag = false;
- public JArray result = new JArray();
- public static S7 s7 = new S7();
- //打开PLC
- public int PlcOpen()
- {
- try
- {
- s7.Open(PLC.plcIp, PLC.plcPort);
- resultFlag = true;
- result.Add(new JObject(new JProperty("PLC连接", PLC.plcIp + ":" + PLC.plcPort + " 连接成功!")));
- }
- catch (Exception e)
- {
- resultFlag = false;
- result.Add(new JObject(new JProperty("PLC连接", PLC.plcIp + ":" + PLC.plcPort + " 连接失败!")));
- result.Add(new JObject(new JProperty("PLC错误信息", e.Message)));
- }
- return 1;
- }
- //关闭PLC
- public int PlcClose()
- {
- s7.Close();
- result.Add(new JObject(new JProperty("PLC关闭", PLC.plcIp + ":" + PLC.plcPort + " 关闭成功!")));
- return 1;
- }
- //读取PLC标识
- public int PlcReadReadFlag()
- {
- if (!resultFlag) return -1;
- try
- {
- int read = Convert.ToInt16(s7.Read<short>(PLC.dbRead));
- result.Add(new JObject(new JProperty("PLC读取(读取标识:OK)", PLC.dbRead + " = " + read.ToString())));
- return read;
- }
- catch (Exception e)
- {
- result.Add(new JObject(new JProperty("PLC错误信息:ERR", e.Message)));
- resultFlag = false;
- return -1;
- }
- }
- //读取PLC产品ID
- public int PlcReadGoodsid()
- {
- if (!resultFlag) return -1;
- try
- {
- int read = Convert.ToInt16(s7.Read<short>(PLC.dbGoodsId));
- result.Add(new JObject(new JProperty("PLC读取(产品ID:OK)", PLC.dbGoodsId + " = " + read.ToString())));
- return read;
- }
- catch (Exception e)
- {
- result.Add(new JObject(new JProperty("PLC错误信息:ERR", e.Message)));
- resultFlag = false;
- return -1;
- }
- }
- //读取装板数量
- public int PlcReadGoodsnum()
- {
- if (!resultFlag) return -1;
- try
- {
- int read = Convert.ToInt16(s7.Read<short>(PLC.dbGoodsNum));
- result.Add(new JObject(new JProperty("PLC读取(装板数量:OK)", PLC.dbGoodsNum + " = " + read.ToString())));
- return read;
- }
- catch (Exception e)
- {
- result.Add(new JObject(new JProperty("PLC错误信息:ERR", e.Message)));
- resultFlag = false;
- return -1;
- }
- }
- //读取PLC商标ID
- public int PlcReadLogoid()
- {
- if (!resultFlag) return -1;
- try
- {
- int read = Convert.ToInt16(s7.Read<short>(PLC.dbLogoId));
- result.Add(new JObject(new JProperty("PLC读取(产品ID:OK)", PLC.dbLogoId + " = " + read.ToString())));
- return read;
- }
- catch (Exception e)
- {
- result.Add(new JObject(new JProperty("PLC错误信息:ERR", e.Message)));
- resultFlag = false;
- return -1;
- }
- }
- public string[] PlcReadBarcodes(int goodsNum)
- {
- if (!resultFlag) return null;
- try
- {
- string[] barCodes = new string[12];
- JObject obj = new JObject();
- for (int i = 0; i < goodsNum; i++)
- {
- barCodes[i] = s7.Read<string>(PLC.dbBarcodeBlock[i], 11).ToString();
- obj.Add(new JProperty("条码" + (i + 1).ToString().PadLeft(2, '0') + "(" + PLC.dbBarcodeBlock[i] + ")", barCodes[i]));
- }
- result.Add(new JObject(new JProperty("PLC读取(产品条码:OK)", obj)));
- return barCodes;
- }
- catch (Exception e)
- {
- result.Add(new JObject(new JProperty("PLC错误信息:ERR", e.Message)));
- resultFlag = false;
- return null;
- }
- }
- //读取板码
- public string PlcReadBanma()
- {
- if (!resultFlag) return "";
- try
- {
- string read = s7.Read<string>(PLC.dbBanMa, 8).ToString();
- result.Add(new JObject(new JProperty("PLC读取(板码:OK)", PLC.dbBanMa + " = " + read.ToString())));
- return read;
- }
- catch (Exception e)
- {
- result.Add(new JObject(new JProperty("PLC错误信息:ERR", e.Message)));
- resultFlag = false;
- return "";
- }
- }
- //读取物料号
- public string PlcReadMaterialcode()
- {
- if (!resultFlag) return "";
- try
- {
- string read = s7.Read<string>(PLC.dbMaterialcode, 14).ToString();
- result.Add(new JObject(new JProperty("PLC读取(物料号:OK)", PLC.dbMaterialcode + " = " + read.ToString())));
- return read;
- }
- catch (Exception e)
- {
- result.Add(new JObject(new JProperty("PLC错误信息:ERR", e.Message)));
- resultFlag = false;
- return "";
- }
- }
- //读取结果标识
- public int PlcReadResultNum()
- {
- if (!resultFlag) return -1;
- try
- {
- int read = Convert.ToInt32(s7.Read<short>(PLC.dbResult));
- result.Add(new JObject(new JProperty("PLC读取(结果:OK)", PLC.dbResult + " = " + read.ToString())));
- return read;
- }
- catch (Exception e)
- {
- result.Add(new JObject(new JProperty("PLC错误信息:ERR", e.Message)));
- resultFlag = false;
- return -1;
- }
- }
- //读取USERCODE
- public string PlcReadUsercode()
- {
- if (!resultFlag) return "";
- try
- {
- string read = s7.Read<string>(PLC.dbUsercode,6).ToString();
- result.Add(new JObject(new JProperty("PLC读取(USECODE:OK)", PLC.dbUsercode + " = " + read.ToString())));
- return read;
- }
- catch (Exception e)
- {
- result.Add(new JObject(new JProperty("PLC错误信息:ERR", e.Message)));
- resultFlag = false;
- return "";
- }
- }
- //写入条码
- public int PlcWriteBarcode(string barCode)
- {
- if (!resultFlag) return -1;
- try
- {
- s7.Write<string>(PLC.dbBarcode, barCode);
- result.Add(new JObject(new JProperty("PLC写入(条码:OK)", PLC.dbBarcode + " = " + barCode)));
- resultFlag = true;
- return 1;
- }
- catch (Exception e)
- {
- result.Add(new JObject(new JProperty("PLC错误信息:ERR", e.Message)));
- resultFlag = false;
- return -1;
- }
- }
- //写入物料码
- public int PlcWriteMaterialcode(string materialCode)
- {
- if (!resultFlag) return -1;
- try
- {
- s7.Write<string>(PLC.dbMaterialcode, materialCode);
- result.Add(new JObject(new JProperty("PLC写入(物料码:OK)", PLC.dbMaterialcode + " = " + materialCode)));
- resultFlag = true;
- return 1;
- }
- catch (Exception e)
- {
- result.Add(new JObject(new JProperty("PLC错误信息:ERR", e.Message)));
- resultFlag = false;
- return -1;
- }
- }
- //写入产品ID
- public int PlcWriteGoodsid(Int16 goodsId)
- {
- if (!resultFlag) return -1;
- try
- {
- s7.Write<short>(PLC.dbGoodsId, goodsId);
- result.Add(new JObject(new JProperty("PLC写入(产品ID:OK)", PLC.dbGoodsId + " = " + goodsId)));
- resultFlag = true;
- return 1;
- }
- catch (Exception e)
- {
- result.Add(new JObject(new JProperty("PLC错误信息:ERR", e.Message)));
- resultFlag = false;
- return -1;
- }
- }
- //写入商标ID
- public int PlcWriteLogoid(Int16 logoId)
- {
- if (!resultFlag) return -1;
- try
- {
- s7.Write<short>(PLC.dbLogoId, logoId);
- result.Add(new JObject(new JProperty("PLC写入(商标ID:OK)", PLC.dbLogoId + " = " + logoId)));
- resultFlag = true;
- return 1;
- }
- catch (Exception e)
- {
- result.Add(new JObject(new JProperty("PLC错误信息:ERR", e.Message)));
- resultFlag = false;
- return -1;
- }
- }
- //写入装板数量
- public int PlcWriteGoodsnum(Int16 goodsNum)
- {
- if (!resultFlag) return -1;
- try
- {
- s7.Write<short>(PLC.dbGoodsNum, goodsNum);
- result.Add(new JObject(new JProperty("PLC写入(装板数量:OK)", PLC.dbGoodsNum + " = " + goodsNum)));
- resultFlag = true;
- return 1;
- }
- catch (Exception e)
- {
- result.Add(new JObject(new JProperty("PLC错误信息:ERR", e.Message)));
- resultFlag = false;
- return -1;
- }
- }
- //写入执行结果
- // 1 通过 2 条码格式错误 3 产品不可到达 4 MES异常 5 条码不一致 6 绑板完成 7 工号读取错误
- public int PlcWriteResult(Int16 flag)
- {
- try
- {
- string message = "";
- switch(flag)
- {
- case 1:message = "扫码通过:OK";break;
- case 2:message = "条码格式错误:ERR";break;
- case 3:message = "产品不可到达:ERR";break;
- case 4:message = "MES异常:ERR";break;
- case 5:message = "条码不一致:ERR";break;
- case 6:message = "绑板完成:ERR";break;
- case 7:message = "工号读取错误:ERR";break;
- default:message = "未定义:ERR";break;
- }
- s7.Write<short>(PLC.dbResult, flag);
- result.Add(new JObject(new JProperty("PLC写入("+message+")", PLC.dbResult + " = " + flag.ToString())));
- return 1;
- }
- catch (Exception e)
- {
- result.Add(new JObject(new JProperty("PLC错误信息:ERROR", e.Message)));
- return -1;
- }
- }
- //加载默认参数
- public static JObject ApiLoadDefaultPara()
- {
- JObject userPara = new JObject();
- userPara.Add(new JProperty("accountCode", API.accountCode));
- userPara.Add(new JProperty("userCode", API.userCode));
- userPara.Add(new JProperty("userPassword", API.userPassword));
- userPara.Add(new JProperty("sessionKey", API.sessionKey));
- return userPara;
- }
- //PDA接口验证条码
- public int ApiGetStatusBarcode(string barCode)
- {
- if (!resultFlag) return -1;
- try
- {
- WCF wcf = new WCF();
- wcf.Para = ApiLoadDefaultPara();
- wcf.Para.Add(new JProperty("procedureID", API.procedureID));
- wcf.Para.Add(new JProperty("barCode", barCode));
- //测试用
- string jsonStr = @"
- {
- 'd': {
- '__type': 'ActionResult:#Dongke.IBOSS.PRD.WCF.DataModels',
- 'Message': '读取成功!',
- 'Result': '{\'data\':[{\'STATUS\':0.0}]}',
- 'Status': 0
- }
- }
- ".Replace("'","\"");
- //正式调用
- if (!API.debug) jsonStr = wcf.Post("/DKService/PDAModuleService/GetStatusByBarcode");
- JObject json = JObject.Parse(jsonStr);
- if (json["d"]["Status"].ToString() == "0")
- {
- result.Add(new JObject(
- new JProperty("API调用(条码状态:OK)", "操作成功!"),
- new JProperty("接口", "/DKService/PDAModuleService/GetStatusByBarcode"),
- new JProperty("参数(procedureID)", API.procedureID),
- new JProperty("参数(barCode)", barCode)
- //,new JProperty("结果", jsonStr)
- )
- );
- return 1;
- }
- else
- {
- resultFlag = false;
- result.Add(new JObject(
- new JProperty("API调用(条码状态:ERR)", json["d"]["Message"].ToString()),
- new JProperty("接口", "/DKService/PDAModuleService/GetStatusByBarcode"),
- new JProperty("参数(procedureID)", API.procedureID),
- new JProperty("参数(barCode)", barCode)
- //,new JProperty("结果", jsonStr)
- )
- );
- return -1;
- }
- }
- catch (Exception e)
- {
- resultFlag = false;
- result.Add(new JObject(
- new JProperty("API调用(条码状态:ERROR)", "系统异常!"),
- new JProperty("接口", "/DKService/PDAModuleService/GetStatusByBarcode"),
- new JProperty("参数(procedureID)", API.procedureID),
- new JProperty("参数(barCode)", barCode),
- new JProperty("异常", e.Message)
- )
- );
- return -1;
- }
- }
- public int ApiCheckBarcode(string barCode)
- {
- if (!resultFlag) return -1;
- try
- {
- WCF wcf = new WCF();
- wcf.Para = ApiLoadDefaultPara();
- wcf.Para.Add(new JProperty("procedureID", API.procedureID));
- wcf.Para.Add(new JProperty("barcode", barCode));
- //测试用
- string jsonStr = @"
- {
- 'd': {
- '__type': 'ActionResult:#Dongke.IBOSS.PRD.WCF.DataModels',
- 'Message': '操作成功',
- 'Result': '[{\'out_errMsg\':\'\',\'out_goodsID\':\'179\',\'out_goodsCode\':\'H0175M\',\'out_goodsName\':\'HC0175PT-305\',\'out_groutingUserCode\':\'SFC035\',\'out_groutingUserName\':null,\'out_groutingUserID\':null,\'out_groutingNum\':\'73\',\'out_mouldCode\':\'C06B11-001\',\'out_ispublicbody\':\'0\',\'out_ispublicbodyTrach\':\'\',\'out_groutingdate\':\'2023/12/30 0:00:00\',\'out_specialRepairFlag\':\'0\',\'out_isReFire\':\'0\',\'out_isLengBu\':\'0\',\'out_missFlag\':\'0\',\'out_logoID\':\'15\',\'out_logoCode\':\'020\',\'out_logoName\':\'HEGII(新)\',\'out_MaterialCode\':\'CT175PD2210B01\',\'out_glazeName\':\'智洁釉\',\'out_deliverLimitCycle\':null,\'out_barcode\':\'00000000001\',\'out_WaterLabelCode\':null,\'out_CodeCheckFlag\':null,\'out_LeakFlag1\':\'\',\'out_LeakFlag2\':\'\',\'out_LeakFlag3\':\'\',\'out_specialRepairFlagName\':\'否\',\'out_isReFireName\':\'否\',\'out_LeakFlag1Name\':\'未检测\',\'out_LeakFlag2Name\':\'未检测\',\'out_LeakFlag3Name\':\'未检测\',\'out_lengBuName\':\'否\',\'out_LeakFlag4\':\'\',\'out_LeakFlag5\':\'\',\'out_LeakFlag4Name\':\'未检测\',\'out_LeakFlag5Name\':\'未检测\',\'GOODSMODELforCheck\':\'CT175PD2210B01#0\',\'PlateLimitNum\':12,\'DefectFlagID\':null,\'pdid\':null,\'InspectionLevel\':\'\',\'PackingDefect\':\'\',\'InspectionGoodsLevel\':\'\',\'offlineFlag\':\'0\',\'recyclingFlag\':\'0\',\'waterLabelCode\':\'http://wl.bbqk.com/2bwta/0.html\',\'PLCWeight\':0.0}]',
- 'Status': 0
- }
- }
- ".Replace("'","\"");
- //正式用
- if (!API.debug) jsonStr = wcf.Post("/DKService/PDAModuleService/CheckBarcode");
- JObject json = JObject.Parse(jsonStr);
- JArray jsonArray = JArray.Parse(json["d"]["Result"].ToString());
- if (json["d"]["Status"].ToString() == "0" && jsonArray[0]["out_errMsg"].ToString()== "")
- {
- result.Add(new JObject(
- new JProperty("API调用(条码验证:OK)", "操作成功!"),
- new JProperty("接口", "/DKService/PDAModuleService/CheckBarcode"),
- new JProperty("参数(procedureID)", API.procedureID),
- new JProperty("参数(barcode)", barCode)
- //,new JProperty("结果", jsonStr)
- )
- );
- return 1;
- }
- else
- {
- resultFlag = false;
- result.Add(new JObject(
- new JProperty("API调用(条码验证:ERR)", json["d"]["Message"].ToString()),
- new JProperty("接口", "/DKService/PDAModuleService/CheckBarcode"),
- new JProperty("参数(procedureID)", API.procedureID),
- new JProperty("参数(barcode)", barCode)
- ,new JProperty("结果", jsonStr)
- )
- );
- return -1;
- }
- }
- catch (Exception e)
- {
- resultFlag = false;
- result.Add(new JObject(
- new JProperty("API调用(条码验证:ERROR)", "系统异常!"),
- new JProperty("接口", "/DKService/PDAModuleService/CheckBarcode"),
- new JProperty("参数(procedureID)", API.procedureID),
- new JProperty("参数(barcode)", barCode),
- new JProperty("异常", e.Message)
- )
- );
- return -1;
- }
- }
- public int ApiFinishedLoadingCar(string barCode,int logoId,int goodsId,int banMa = 0)
- {
- if (!resultFlag) return -1;
- string jsonData = "{\"logoID\":\"" + logoId.ToString() + "\",\"GoodsID\":\"" + goodsId.ToString() + "\"}";
- try
- {
- WCF wcf = new WCF();
- wcf.Para = ApiLoadDefaultPara();
- wcf.Para.Add(new JProperty("procedureID", API.procedureID));
- wcf.Para.Add(new JProperty("barcode", barCode));
- wcf.Para.Add(new JProperty("module", "FinishedLoadingCar"));
- wcf.Para.Add(new JProperty("action", "GetSetting"));
- wcf.Para.Add(new JProperty("jsonData", jsonData));
- //测试用
- string jsonStr = @"
- {
- 'd': {
- '__type': 'ActionResult:#Dongke.IBOSS.PRD.WCF.DataModels',
- 'Message': '操作成功',
- 'Result': '{\'GoodsID\':\'179\',\'logoID\':\'15\',\'S_PM_011\':\'1\',\'S_PM_012\':\'1\',\'S_PM_013\':\'1\',\'PlatelitNum\':12,\'PlatelitNumNew\':2}',
- 'Status': 0
- }
- }
- ".Replace("'","\"");
- //正式用
- if (!API.debug) jsonStr = wcf.Post("/DKService/PDAModuleService/DoAction");
- JObject json = JObject.Parse(jsonStr);
- if (json["d"]["Status"].ToString() == "0")
- {
- JObject goods = JObject.Parse(json["d"]["Result"].ToString());
- int goodsNum = 0;
- //新板
- if(banMa == 1) goodsNum = Convert.ToInt32(goods["PlatelitNumNew"]);
- //旧板
- if(banMa == 0) goodsNum = Convert.ToInt32(goods["PlatelitNum"]);
- result.Add(new JObject(
- new JProperty("API调用(装板数量:OK)", goodsNum.ToString() + "操作成功!"),
- new JProperty("接口", "/DKService/PDAModuleService/DoAction"),
- new JProperty("参数(ACTION)", "GetSetting"),
- new JProperty("参数(MODULE)", "FinishedLoadingCar"),
- new JProperty("参数(jsonData)",jsonData)
- //,new JProperty("结果", jsonStr)
- )
- );
- return goodsNum;
- }
- else
- {
- resultFlag = false;
- result.Add(new JObject(
- new JProperty("API调用(装板数量:ERR)", json["d"]["Message"].ToString()),
- new JProperty("接口", "/DKService/PDAModuleService/DoAction"),
- new JProperty("参数(ACTION)", "GetSetting"),
- new JProperty("参数(MODULE)", "FinishedLoadingCar"),
- new JProperty("参数(jsonData)",jsonData)
- //,new JProperty("结果", jsonStr)
- )
- );
- return -1;
- }
- }
- catch (Exception e)
- {
- resultFlag = false;
- result.Add(new JObject(
- new JProperty("API调用(装板数量:ERROR)", "系统异常!"),
- new JProperty("接口", "/DKService/PDAModuleService/DoAction"),
- new JProperty("参数(ACTION)", "GetSetting"),
- new JProperty("参数(MODULE)", "FinishedLoadingCar"),
- new JProperty("参数(jsonData)",jsonData),
- new JProperty("异常", e.Message)
- )
- );
- return -1;
- }
- }
- public int ApiAddWorkPiece(string[] barCodes, string banMa, int goodsNum)
- {
- if (!resultFlag) return -1;
- JArray productionDataEntitys = new JArray();
- for (int i = 0; i < goodsNum; i++)
- {
- JObject obj = new JObject(
- new JProperty("UserID", API.userId),
- new JProperty("UserCode", API.userCode),
- new JProperty("UserName", API.userName),
- new JProperty("Barcode", barCodes[i]),
- new JProperty("BanMa", banMa)
- );
- productionDataEntitys.Add(obj);
- }
- try
- {
- WCF wcf = new WCF();
- wcf.Para = ApiLoadDefaultPara();
- wcf.Para.Add(new JProperty("procedureID", API.procedureID));
- wcf.Para.Add(new JProperty("productionDataEntitys", productionDataEntitys));
- //测试用
- string jsonStr = @"
- {
- 'd': {
- '__type': 'ActionResult:#Dongke.IBOSS.PRD.WCF.DataModels',
- 'Message': '操作成功',
- 'Result': '[{\'out_errMsg\':\'\',\'out_goodsID\':\'179\',\'out_goodsCode\':\'H0175M\',\'out_goodsName\':\'HC0175PT-305\',\'out_groutingUserCode\':\'SFC035\',\'out_groutingUserName\':null,\'out_groutingUserID\':null,\'out_groutingNum\':null,\'out_mouldCode\':null,\'out_ispublicbody\':null,\'out_ispublicbodyTrach\':null,\'out_groutingdate\':\'\',\'out_specialRepairFlag\':null,\'out_isReFire\':null,\'out_isLengBu\':null,\'out_missFlag\':null,\'out_logoID\':null,\'out_logoCode\':\'\',\'out_logoName\':\'\',\'out_MaterialCode\':null,\'out_glazeName\':null,\'out_deliverLimitCycle\':null,\'out_barcode\':null,\'out_WaterLabelCode\':null,\'out_CodeCheckFlag\':null,\'out_LeakFlag1\':null,\'out_LeakFlag2\':null,\'out_LeakFlag3\':null,\'out_specialRepairFlagName\':null,\'out_isReFireName\':null,\'out_LeakFlag1Name\':null,\'out_LeakFlag2Name\':null,\'out_LeakFlag3Name\':null,\'out_lengBuName\':null,\'out_LeakFlag4\':null,\'out_LeakFlag5\':null,\'out_LeakFlag4Name\':null,\'out_LeakFlag5Name\':null,\'GOODSMODELforCheck\':null,\'PlateLimitNum\':null,\'DefectFlagID\':null,\'pdid\':null,\'InspectionLevel\':null,\'PackingDefect\':null,\'InspectionGoodsLevel\':null,\'offlineFlag\':null,\'recyclingFlag\':null,\'waterLabelCode\':null}]',
- 'Status': 0
- }
- }
- ".Replace("'","\"");
- //正式用
- if (!API.debug) jsonStr = wcf.Post("/DKService/PDAModuleService/AddWorkPiece");
- JObject json = JObject.Parse(jsonStr);
- JArray jsonArray = JArray.Parse(json["d"]["Result"].ToString());
- if (json["d"]["Status"].ToString() == "0" && jsonArray[0]["out_errMsg"].ToString()== "")
- {
- result.Add(new JObject(
- new JProperty("API调用(包装码垛:OK)", "操作成功!"),
- new JProperty("接口", "/DKService/PDAModuleService/AddWorkPiece"),
- new JProperty("参数(procedureID)", API.procedureID),
- new JProperty("参数(productionDataEntitys)", productionDataEntitys)
- //,new JProperty("结果", jsonStr)
- )
- );
- return 1;
- }
- else
- {
- resultFlag = false;
- result.Add(new JObject(
- new JProperty("API调用(包装码垛:ERR)", json["d"]["Message"].ToString()),
- new JProperty("接口", "/DKService/PDAModuleService/AddWorkPiece"),
- new JProperty("参数(procedureID)", API.procedureID),
- new JProperty("参数(productionDataEntitys)", productionDataEntitys)
- ,new JProperty("结果", jsonStr)
- )
- );
- return -1;
- }
- }
- catch (Exception e)
- {
- resultFlag = false;
- result.Add(new JObject(
- new JProperty("API调用(包装码垛:ERROR)", "系统异常!"),
- new JProperty("接口", "/DKService/PDAModuleService/AddWorkPiece"),
- new JProperty("参数(procedureID)", API.procedureID),
- new JProperty("参数(productionDataEntitys)", productionDataEntitys),
- new JProperty("异常", e.Message)
- )
- );
- return -1;
- }
- }
- public DataRow GetGoods(string outCode)
- {
- try
- {
- using (IDataAccess conn = DataAccess.Create())
- {
- DataTable dt = conn.ExecuteDatatable(@"
- SELECT
- gd.OUTLABELCODE,gd.BARCODE,gd.GOODSID,gd.LOGOID,gd.MATERIALCODE
- FROM
- TP_PM_GROUTINGDAILYDETAIL gd
- WHERE
- gd.VALUEFLAG = '1'
- AND gd.OUTLABELCODE = @OUTLABELCODE@
- ",
- new CDAParameter("OUTLABELCODE", outCode)
- );
- if(dt.Rows.Count >0 )
- {
- JObject obj = new JObject();
- obj.Add(new JProperty("OUTLABELCODE", dt.Rows[0]["OUTLABELCODE"].ToString()));
- obj.Add(new JProperty("BARCODE", dt.Rows[0]["BARCODE"].ToString()));
- obj.Add(new JProperty("MATERIALCODE", dt.Rows[0]["MATERIALCODE"].ToString()));
- obj.Add(new JProperty("GOODSID", dt.Rows[0]["GOODSID"].ToString()));
- obj.Add(new JProperty("LOGOID", dt.Rows[0]["LOGOID"].ToString()));
- result.Add(new JObject(new JProperty("MES读取(产品信息:OK)", obj)));
- return dt.Rows[0];
- }
- else
- {
- resultFlag = false;
- result.Add(new JObject(new JProperty("MES读取(产品信息:ERR)","产品未找到!")));
- return null;
- }
- }
- }
- catch (Exception e)
- {
- resultFlag = false;
- result.Add(new JObject(new JProperty("系统异常", e.Message)));
- return null;
- }
- }
- //读取用户信息
- public DataRow GetUserinfo(string userCode)
- {
- try
- {
- using (IDataAccess conn = DataAccess.Create())
- {
- DataTable dt = conn.ExecuteDatatable(@"
- SELECT
- u.ACCOUNTCODE,
- u.USERID,
- u.USERCODE,
- u.USERNAME,
- u.PASSWORD,
- l.SESSIONKEY
- FROM
- TP_MST_USER u
- LEFT JOIN TP_MST_USERLOGIN l ON u.USERID = l.USERID
- WHERE
- u.USERCODE = @USERCODE@
- ",
- new CDAParameter("USERCODE", userCode)
- );
- if(dt.Rows.Count >0 )
- {
- API.accountCode = dt.Rows[0]["ACCOUNTCODE"].ToString();
- API.userId = dt.Rows[0]["USERID"].ToString();
- API.userCode = dt.Rows[0]["USERCODE"].ToString();
- API.userName = dt.Rows[0]["USERNAME"].ToString();
- API.userPassword = dt.Rows[0]["PASSWORD"].ToString();
- API.sessionKey = dt.Rows[0]["SESSIONKEY"].ToString();
- JObject obj = new JObject();
- obj.Add(new JProperty("accountCode", dt.Rows[0]["ACCOUNTCODE"].ToString()));
- obj.Add(new JProperty("userId", dt.Rows[0]["USERID"].ToString()));
- obj.Add(new JProperty("userCode", dt.Rows[0]["USERCODE"].ToString()));
- obj.Add(new JProperty("userName", dt.Rows[0]["USERNAME"].ToString()));
- obj.Add(new JProperty("userPassword", dt.Rows[0]["PASSWORD"].ToString()));
- obj.Add(new JProperty("sessionKey", dt.Rows[0]["SESSIONKEY"].ToString()));
- result.Add(new JObject(new JProperty("MES读取(用户信息:OK)", obj)));
- return dt.Rows[0];
- }
- else
- {
- resultFlag = false;
- result.Add(new JObject(new JProperty("MES读取(用户信息:ERR)","用户未找到!")));
- return null;
- }
- }
- }
- catch (Exception e)
- {
- resultFlag = false;
- result.Add(new JObject(new JProperty("系统异常:ERROR", e.Message)));
- return null;
- }
- }
- //主程序入口
- public void ProcessRequest(HttpContext context)
- {
- context.Response.ContentType = "text/plain";
- if (context.Request["barcode"] is object)
- {
- BarcodeRead(context);
- }
- else
- {
- BarcodeDo(context);
- }
- }
- // 读取条码,对接扫描头使用
- public void BarcodeRead(HttpContext context)
- {
- if (PlcOpen() == 1)
- {
- int readFlag = PlcReadReadFlag();
- string barCode = "";
- string materialCode = "";
- Int16 goodsId = 0;
- Int16 logoId = 0;
- Int16 goodsNum = 0;
- //条码处理
- if(readFlag == 1 || readFlag == 0 || readFlag == 10)
- {
- DataRow dr = GetGoods(context.Request["barcode"].ToString());
- if (resultFlag)
- {
- barCode = dr["BARCODE"].ToString();
- materialCode = dr["MATERIALCODE"].ToString();
- goodsId = Convert.ToInt16(dr["GOODSID"]);
- logoId = Convert.ToInt16(dr["LOGOID"]);
- //读取工号
- string userCode = PlcReadUsercode();
- if (userCode != "")
- {
- GetUserinfo(userCode);
- //接口验证条码状态(非必须取消这个接口)
- //int status = ApiGetStatusBarcode(barCode);
- //接口验证可到达
- int check = ApiCheckBarcode(barCode);
- //写验证结果
- if (check == -1) PlcWriteResult(3);
- }
- else
- {
- //工号错误
- PlcWriteResult(7);
- }
- }
- }
- //首个条码处理
- if ((readFlag == 1 || readFlag == 10) && resultFlag)
- {
- //写PLC
- PlcWriteBarcode(barCode);
- PlcWriteMaterialcode(materialCode);
- //PlcWriteGoodsid(goodsId);
- //PlcWriteLogoid(logoId);
- //获取装板数量
- if(readFlag == 1) goodsNum = Convert.ToInt16(ApiFinishedLoadingCar(barCode, logoId, goodsId,1));
- if(readFlag == 10) goodsNum = Convert.ToInt16(ApiFinishedLoadingCar(barCode, logoId, goodsId,0));
- PlcWriteGoodsnum(goodsNum);
- //写结果
- if (resultFlag) PlcWriteResult(1); else PlcWriteResult(4);
- }
- //过程条码处理
- if (readFlag == 0 && resultFlag)
- {
- //验证条码是否符合装板
- int plcGoodsnum = PlcReadGoodsnum();
- string plcMaterialcode = PlcReadMaterialcode();
- if (resultFlag)
- {
- if(materialCode == plcMaterialcode)
- {
- //写PLC
- PlcWriteBarcode(barCode);
- PlcWriteMaterialcode(materialCode);
- //PlcWriteGoodsid(goodsId);
- //PlcWriteLogoid(logoId);
- //PlcWriteGoodsnum(goodsNum);
- //通过 或 异常
- if (resultFlag) PlcWriteResult(1); else PlcWriteResult(4);
- }
- else
- {
- //条码不一致
- PlcWriteResult(5);
- }
- }
- else
- {
- //异常
- PlcWriteResult(4);
- }
- }
- //PlcClose();
- }
- context.Response.Write(new JsonResult(resultFlag ? JsonStatus.success : JsonStatus.error) { rows = result }.ToJson());
- }
- // 绑板处理,轮询到标识,绑板处理
- public void BarcodeDo(HttpContext context)
- {
- if (PlcOpen() == 1)
- {
- int readFlag = PlcReadReadFlag();
- int goodsNum = PlcReadGoodsnum();
- int resultNum = PlcReadResultNum();
- if(resultNum != 6)
- {
- //绑板处理
- if(readFlag == 2 || readFlag == 3)
- {
- //读取工号
- string userCode = PlcReadUsercode();
- if (userCode != "")
- {
- //读取工号信息
- GetUserinfo(userCode);
- //读取条码
- String[] barCodes = PlcReadBarcodes(goodsNum);
- string banMa = "";
- if (readFlag == 3) banMa = PlcReadBanma();
- //绑板处理
- ApiAddWorkPiece(barCodes, banMa, goodsNum);
- //绑板完成
- PlcWriteResult(6);
- }
- else
- {
- //工号错误
- PlcWriteResult(7);
- }
- }
- //强制绑板完成
- if(readFlag == 4)
- {
- PlcWriteResult(6);
- }
- }
- //PlcClose();
- }
- context.Response.Write(new JsonResult(resultFlag ? JsonStatus.success : JsonStatus.error) { rows = result }.ToJson());
- }
- public bool IsReusable
- {
- get
- {
- return false;
- }
- }
- }
|