| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769 |
- <%@ 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 = "172.18.36.95";
- public static int plcPort = 102;
- public static string dbBarcode = "151.2"; //151.0 => 151.2
- public static string dbGoodsId = "151.14";
- public static string dbGoodsNum = "151.16";
- public static string dbResult = "151.18";
- public static string dbLogoId = "151.22";//替换产品等级
- public static string dbMaterialcode = "151.30";
- public static string dbRead = "151.26";
- public static string[] dbBarcodeBlock = { "150.2", "150.32", "150.62", "150.92", "150.122", "150.152", "150.182", "150.212", "150.242", "150.272", "150.302", "150.332" };
- public static string dbBanMa = "150.362";//150.360 => 150.362
- }
- 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 = "924D8A5B-D55B-4436-AE57-26EE5E435639";
- public static string procedureID = "107"; //3#包装
- public static bool debug = true;
- }
- public bool resultFlag = false;
- public JArray result = new JArray();
- //打开PLC
- public int PlcOpen()
- {
- try
- {
- SiemensS7.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()
- {
- SiemensS7.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(SiemensS7.Read<short>(PLC.dbRead));
- result.Add(new JObject(new JProperty("PLC读取(读取标识)", PLC.dbRead + " = " + read.ToString())));
- resultFlag = true;
- return read;
- }
- catch (Exception e)
- {
- result.Add(new JObject(new JProperty("PLC错误信息", e.Message)));
- resultFlag = false;
- return -1;
- }
- }
- //读取PLC产品ID
- public int PlcReadGoodsid()
- {
- if (!resultFlag) return -1;
- try
- {
- int read = Convert.ToInt16(SiemensS7.Read<short>(PLC.dbGoodsId));
- result.Add(new JObject(new JProperty("PLC读取(产品ID)", PLC.dbGoodsId + " = " + read.ToString())));
- resultFlag = true;
- return read;
- }
- catch (Exception e)
- {
- result.Add(new JObject(new JProperty("PLC错误信息", e.Message)));
- resultFlag = false;
- return -1;
- }
- }
- //读取装板数量
- public int PlcReadGoodsnum()
- {
- if (!resultFlag) return -1;
- try
- {
- int read = Convert.ToInt16(SiemensS7.Read<short>(PLC.dbGoodsNum));
- result.Add(new JObject(new JProperty("PLC读取(装板数量)", PLC.dbGoodsNum + " = " + read.ToString())));
- resultFlag = true;
- return read;
- }
- catch (Exception e)
- {
- result.Add(new JObject(new JProperty("PLC错误信息", e.Message)));
- resultFlag = false;
- return -1;
- }
- }
- //读取PLC商标ID
- public int PlcReadLogoid()
- {
- if (!resultFlag) return -1;
- try
- {
- int read = Convert.ToInt16(SiemensS7.Read<short>(PLC.dbLogoId));
- result.Add(new JObject(new JProperty("PLC读取(产品ID)", PLC.dbLogoId + " = " + read.ToString())));
- resultFlag = true;
- return read;
- }
- catch (Exception e)
- {
- result.Add(new JObject(new JProperty("PLC错误信息", 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] = SiemensS7.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读取(产品条码)", obj)));
- resultFlag = true;
- return barCodes;
- }
- catch (Exception e)
- {
- result.Add(new JObject(new JProperty("PLC错误信息", e.Message)));
- resultFlag = false;
- return null;
- }
- }
- //读取板码
- public string PlcReadBanma()
- {
- if (!resultFlag) return "";
- try
- {
- string read = SiemensS7.Read<string>(PLC.dbBanMa, 8).ToString();
- result.Add(new JObject(new JProperty("PLC读取(板码)", PLC.dbBanMa + " = " + read.ToString())));
- resultFlag = true;
- return read;
- }
- catch (Exception e)
- {
- result.Add(new JObject(new JProperty("PLC错误信息", e.Message)));
- resultFlag = false;
- return "";
- }
- }
- //写入条码
- public int PlcWriteBarcode(string barCode)
- {
- if (!resultFlag) return -1;
- try
- {
- SiemensS7.Write<string>(PLC.dbBarcode, barCode);
- result.Add(new JObject(new JProperty("PLC写入(条码)", PLC.dbBarcode + " = " + barCode)));
- resultFlag = true;
- return 1;
- }
- catch (Exception e)
- {
- result.Add(new JObject(new JProperty("PLC错误信息", e.Message)));
- resultFlag = false;
- return -1;
- }
- }
- //写入物料码
- public int PlcWriteMaterialcode(string materialCode)
- {
- if (!resultFlag) return -1;
- try
- {
- SiemensS7.Write<string>(PLC.dbMaterialcode, materialCode);
- result.Add(new JObject(new JProperty("PLC写入(物料码)", PLC.dbMaterialcode + " = " + materialCode)));
- resultFlag = true;
- return 1;
- }
- catch (Exception e)
- {
- result.Add(new JObject(new JProperty("PLC错误信息", e.Message)));
- resultFlag = false;
- return -1;
- }
- }
- //写入产品ID
- public int PlcWriteGoodsid(Int16 goodsId)
- {
- if (!resultFlag) return -1;
- try
- {
- SiemensS7.Write<short>(PLC.dbGoodsId, goodsId);
- result.Add(new JObject(new JProperty("PLC写入(产品ID)", PLC.dbGoodsId + " = " + goodsId)));
- resultFlag = true;
- return 1;
- }
- catch (Exception e)
- {
- result.Add(new JObject(new JProperty("PLC错误信息", e.Message)));
- resultFlag = false;
- return -1;
- }
- }
- //写入商标ID
- public int PlcWriteLogoid(Int16 logoId)
- {
- if (!resultFlag) return -1;
- try
- {
- SiemensS7.Write<short>(PLC.dbLogoId, logoId);
- result.Add(new JObject(new JProperty("PLC写入(商标ID)", PLC.dbLogoId + " = " + logoId)));
- resultFlag = true;
- return 1;
- }
- catch (Exception e)
- {
- result.Add(new JObject(new JProperty("PLC错误信息", e.Message)));
- resultFlag = false;
- return -1;
- }
- }
- //写入装板数量
- public int PlcWriteGoodsnum(Int16 goodsNum)
- {
- if (!resultFlag) return -1;
- try
- {
- SiemensS7.Write<short>(PLC.dbGoodsNum, goodsNum);
- result.Add(new JObject(new JProperty("PLC写入(装板数量)", PLC.dbGoodsNum + " = " + goodsNum)));
- resultFlag = true;
- return 1;
- }
- catch (Exception e)
- {
- result.Add(new JObject(new JProperty("PLC错误信息", e.Message)));
- resultFlag = false;
- return -1;
- }
- }
- //写入执行结果
- public int PlcWriteResult(Int16 flag)
- {
- try
- {
- SiemensS7.Write<short>(PLC.dbResult, flag);
- result.Add(new JObject(new JProperty("PLC写入(执行结果)", PLC.dbResult + " = " + flag.ToString())));
- return 1;
- }
- catch (Exception e)
- {
- result.Add(new JObject(new JProperty("PLC错误信息", 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调用(条码状态)", "操作成功!"),
- 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调用(条码状态)", "操作失败!"),
- 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调用(条码状态)", "系统异常!"),
- 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);
- if (json["d"]["Status"].ToString() == "0")
- {
- result.Add(new JObject(
- new JProperty("API调用(条码验证)", "操作成功!"),
- 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调用(条码验证)", "操作失败!"),
- 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调用(条码验证)", "系统异常!"),
- 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)
- {
- 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 = Convert.ToInt32(goods["PlatelitNum"]);
- //int goodsNum = Convert.ToInt32(goods["PlatelitNumNew"]);
- result.Add(new JObject(
- new JProperty("API调用(装板数量)", 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调用(装板数量)", "操作失败!"),
- 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调用(装板数量)", "系统异常!"),
- 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);
- if (json["d"]["Status"].ToString() == "0")
- {
- result.Add(new JObject(
- new JProperty("API调用(包装码垛)", "操作成功!"),
- 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调用(包装码垛)", "操作失败!"),
- 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调用(包装码垛)", "系统异常!"),
- 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()));
- obj.Add(new JProperty("GOODSNUM", dt.Rows[0]["GOODSNUM"].ToString()));
- result.Add(new JObject(new JProperty("MES读取(产品信息)", obj)));
- return dt.Rows[0];
- }
- else
- {
- resultFlag = false;
- result.Add(new JObject(new JProperty("MES读取(产品信息)","产品未找到!")));
- return null;
- }
- }
- }
- catch (Exception e)
- {
- resultFlag = false;
- result.Add(new JObject(new JProperty("系统异常", 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)
- {
- 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"]);
- //接口验证条码状态
- int status = ApiGetStatusBarcode(barCode);
- //接口验证可到达
- int check = ApiCheckBarcode(barCode);
- //写验证结果
- if (status == -1 || check == -1) PlcWriteResult(3);
- //获取装板数量
- goodsNum = Convert.ToInt16(ApiFinishedLoadingCar(barCode, logoId, goodsId));
- }
- }
- //首个条码处理
- if (readFlag == 1 && resultFlag)
- {
- //写PLC
- PlcWriteBarcode(barCode);
- PlcWriteMaterialcode(materialCode);
- //PlcWriteGoodsid(goodsId);
- //PlcWriteLogoid(logoId);
- PlcWriteGoodsnum(goodsNum);
- //写结果
- if (resultFlag) PlcWriteResult(1); else PlcWriteResult(4);
- }
- //过程条码处理
- if (readFlag == 0 && resultFlag)
- {
- //写PLC
- PlcWriteBarcode(barCode);
- PlcWriteMaterialcode(materialCode);
- //PlcWriteGoodsid(goodsId);
- //PlcWriteLogoid(logoId);
- //PlcWriteGoodsnum(goodsNum);
- //写结果
- if (resultFlag) PlcWriteResult(1); 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();
- //绑板处理
- if(readFlag == 2 || readFlag == 3)
- {
- String[] barCodes = PlcReadBarcodes(goodsNum);
- string banMa = "";
- if (readFlag == 3) banMa = PlcReadBanma();
- //绑板处理
- ApiAddWorkPiece(barCodes, banMa, goodsNum);
- //写入结果
- PlcWriteResult(6);
- }
- //强制绑板完成
- 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;
- }
- }
- }
|