| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- /*******************************************************************************
- * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
- * 类的信息:
- * 1.程序名称:PLCModuleLogic.cs
- * 2.功能描述:PLC相关处理。
- * 编辑履历:
- * 作者 日期 版本 修改内容
- * 陈晓野 2018/10/18 1.00 新建
- *******************************************************************************/
- using System;
- using System.Data;
- using Dongke.IBOSS.PRD.Basics.DataAccess;
- using Dongke.IBOSS.PRD.Service.DataModels;
- using Oracle.DataAccess.Client;
- using PCLCommunication;
- namespace Dongke.IBOSS.PRD.Service.PDAModuleLogic
- {
- /// <summary>
- /// PLC相关处理
- /// </summary>
- public class PLCModuleLogic
- {
- public static int SendGoodsCodeToPLCBySeatCover(string barcode, SUserInfo sUserInfo)
- {
- //filePath = INIUtility.Instance(INIUtility.IniFile.Config).ReadIniData("PathSetting", filePath);
- IDBConnection con = ClsDbFactory.CreateDBConnection(DataBaseType.ORACLE, DataManager.ConnectionString);
- try
- {
- con.Open();
- string sqlString = "select u.plcid, p.ip, p.port,p.PLCDescription from tp_mst_user u " +
- "inner join tp_mst_plc p on p.plcid = u.plcid where u.userid = :userid and p.valueflag='1'";
- OracleParameter[] paras = new OracleParameter[]
- {
- new OracleParameter(":userid",OracleDbType.Int32, sUserInfo.UserID,ParameterDirection.Input),
- };
- DataTable plc = con.GetSqlResultToDt(sqlString, paras);
- if (plc == null || plc.Rows.Count == 0)
- {
- return 4;
- }
- string ip = plc.Rows[0]["ip"].ToString();
- int port = Convert.ToInt32(plc.Rows[0]["port"]);
- string dec = plc.Rows[0]["PLCDescription"].ToString();
- if (string.IsNullOrWhiteSpace(ip) || port == 0 || string.IsNullOrWhiteSpace(dec))
- {
- return 5;
- }
- sqlString = @"select FUN_CMN_GetBarCode(:barcode,null,:accountid) From DUAL";
- OracleParameter[] paras1 = new OracleParameter[]
- {
- new OracleParameter(":barcode",OracleDbType.Varchar2, barcode,ParameterDirection.Input),
- new OracleParameter(":accountid",OracleDbType.Int32, sUserInfo.AccountID,ParameterDirection.Input),
- };
- barcode = con.GetSqlResultToStr(sqlString, paras1);
- if (string.IsNullOrEmpty(barcode))
- {
- return 1;
- }
- sqlString = "SELECT g.goodscode, g.seatcovercode\n" +
- " FROM tp_pm_groutingdailydetail t\n" +
- " INNER JOIN tp_mst_goods g\n" +
- " ON g.goodsid = t.goodsid\n" +
- " WHERE t.barcode = :barcode";
- OracleParameter[] paras2 = new OracleParameter[]
- {
- new OracleParameter(":barcode",OracleDbType.Varchar2, barcode,ParameterDirection.Input),
- };
- DataTable code = con.GetSqlResultToDt(sqlString, paras2);
- if (code == null || code.Rows.Count == 0)
- {
- return 2;
- }
- object sccode = code.Rows[0]["seatcovercode"];
- if (sccode == null || sccode == DBNull.Value)
- {
- return 3;
- }
- //using (MelsecA1EAscii melsec = new MelsecA1EAscii(ip, port))
- using (MelsecA1EAsciiSocket melsec = new MelsecA1EAsciiSocket(ip, port))
- {
- int icode = Convert.ToInt32(sccode);
- string type = dec[0].ToString();
- int begin = Convert.ToInt32(dec.Substring(1));
- // 写入
- //bool result = melsec.SetData("D", 1000, 1, icode.ToString("X4"));
- bool result = melsec.SetData(type, begin, 1, icode.ToString("X4"));
- //// 写入 产品编码
- //byte[] byteCode = Encoding.ASCII.GetBytes(goodscode);
- //result = melsec.SetData("D", 1001, 10, byteCode);
- if (result)
- {
- return 0;
- }
- }
- return -1;
- }
- catch (Exception ex)
- {
- throw ex;
- }
- finally
- {
- if (con.ConnState == ConnectionState.Open)
- {
- con.Close();
- }
- }
- }
- }
- }
|