Example #1
0
        /// <summary>
        /// 通过tcp通知控制系统删除生产登记
        /// </summary>
        /// <param name="dispatch"></param>
        /// <returns></returns>
        ResultInfo DeleteDispatchListTcp(DispatchList dispatch)
        {
            string IP = GetControlSystemIP(dispatch.ProductLineID);

            //未指定该生产线IP,不使用TCP通讯,始终返回true;
            if (string.IsNullOrEmpty(IP))
            {
                logger.WarnFormat("未配置该生产线[{0}]的IP,不使用TCP通讯[DeleteDispatchListTcp],直接返回true。", dispatch.ProductLineID);
                return(new ResultInfo
                {
                    Result = true,
                    Message = "未配置该生产线IP,不使用TCP通讯。"
                });
            }
            DataTable dt = new DataTable();

            dt.Columns.Add("ID");
            DataRow Dr = dt.NewRow();

            Dr["ID"] = dispatch.ID;
            dt.Rows.Add(Dr);
            string CMD = "102";

            string Num = IP + ":" + DateTime.Now.ToString("yyyyMMddHHmmss");
            string XML = TcpIpHelper.CombinSendXML(Num, 1, CMD, "ProductRegist", "", dt);

            return(TcpIpHelper.TcpSend(XML, CMD, IP));
        }
Example #2
0
        public static ResultInfo TcpSend(string XML, string CMD, string ip)
        {
            ////TCP
            // XML = "<?xml version='1.0' encoding='utf-8' ?>< Root><Head><Num>192.168.0.1:XXXXX </ Num ><SystemType>1</SystemType><CMD>101</CMD> <Table>ProductRegist</Table> <Count>1</Count> <User>SupperUser</ User > </Head><Data><ID>1</ID></Data></ Root >";
            byte[] nedata = new byte[8 * 1024];
            DefaultEncoding.GetBytes(XML, 0, XML.Length, nedata, 0);
            byte[] Senddata = TcpIpHelper.CreateDataPacket("中联重科", 0, 0, CMD, 1, "", nedata);
            return(TcpIpHelper.SendMessage(ip, Senddata));

            //UDP
            //UdpHelper checker = new UdpHelper("127.0.0.1");//目标主机IP,也是超时后备用机要切换的IP
            //checker.StartCheck();
        }
Example #3
0
        ResultInfo SendConsmixpropTcp(ConsMixprop cm, IList <ConsMixpropItem> cmItems)
        {
            string IP = GetControlSystemIP(cm.ProductLineID);

            //未指定该生产线IP,不使用TCP通讯,始终返回true;
            //if (string.IsNullOrEmpty(IP))
            if (true)
            {
                logger.WarnFormat("未配置该生产线[{0}]的IP,不使用TCP通讯[UpdateDispatchListTcp],直接返回true。", cm.ProductLineID);
                return(new ResultInfo
                {
                    Result = true,
                    Message = "未配置该生产线IP,不使用TCP通讯。"
                });
            }
            DataTable dtcm = new DataTable();

            dtcm.Columns.Add("ID");
            dtcm.Columns.Add("PTaskListID");
            dtcm.Columns.Add("ProductLineID");
            dtcm.Columns.Add("FormulaName");
            dtcm.Columns.Add("SeepLevel");

            dtcm.Columns.Add("FlexStrength");
            dtcm.Columns.Add("AdditiveRate");
            dtcm.Columns.Add("WaterGlue");
            dtcm.Columns.Add("SandRate");
            dtcm.Columns.Add("FType");
            dtcm.Columns.Add("MixingTime");
            dtcm.Columns.Add("Volume");
            dtcm.Columns.Add("XZBool");
            dtcm.Columns.Add("XZRecord");
            dtcm.Columns.Add("Version");
            dtcm.Columns.Add("CreateTime");
            dtcm.Columns.Add("UpdateTime");
            dtcm.Columns.Add("CreaterID");
            dtcm.Columns.Add("UpdaterID");
            dtcm.Columns.Add("Status");

            DataRow Dr = dtcm.NewRow();

            Dr["ID"]            = cm.ID;
            Dr["PTaskListID"]   = cm.TaskID;
            Dr["ProductLineID"] = "00000" + cm.ProductLineID;// 系统中数据库已经将机组线号改成8位
            //Dr["ProductLineID"] = cm.ProductLineID;
            Dr["FormulaName"]  = cm.ConStrength;
            Dr["SeepLevel"]    = null;
            Dr["FlexStrength"] = null;
            Dr["AdditiveRate"] = 0.00;
            Dr["WaterGlue"]    = cm.WCRate;
            Dr["SandRate"]     = cm.SCRate;
            Dr["FType"]        = cm.IsSlurry ? 2 : 1;
            Dr["MixingTime"]   = cm.MixingTime;
            Dr["Volume"]       = cm.Weight;
            Dr["XZBool"]       = null;
            Dr["XZRecord"]     = null;
            Dr["Version"]      = 1;
            Dr["CreateTime"]   = cm.BuildTime.ToString("yyyy-MM-dd HH:mm:ss");
            Dr["UpdateTime"]   = Convert.ToDateTime(cm.ModifyTime).ToString("yyyy-MM-dd HH:mm:ss");
            Dr["CreaterID"]    = cm.Builder;
            Dr["UpdaterID"]    = cm.Modifier;
            Dr["Status"]       = 0;

            dtcm.Rows.Add(Dr);


            DataTable dtcmitems = new DataTable();

            dtcmitems.Columns.Add("ID");
            dtcmitems.Columns.Add("FormulaMessageID");
            dtcmitems.Columns.Add("SiloID");
            dtcmitems.Columns.Add("StuffID");
            dtcmitems.Columns.Add("TypeAmount");
            dtcmitems.Columns.Add("Version");
            dtcmitems.Columns.Add("Status");

            foreach (ConsMixpropItem cmItem in cmItems)
            {
                DataRow DrcmItem = dtcmitems.NewRow();
                DrcmItem["ID"] = cmItem.ID;
                DrcmItem["FormulaMessageID"] = cmItem.ConsMixpropID;
                DrcmItem["SiloID"]           = cmItem.SiloID;
                DrcmItem["StuffID"]          = cmItem.Silo.StuffID;
                DrcmItem["TypeAmount"]       = cmItem.Amount;
                DrcmItem["Version"]          = 1;
                DrcmItem["Status"]           = 0;
                dtcmitems.Rows.Add(DrcmItem);
            }
            string CMD = "201";

            string Num = IP + ":" + DateTime.Now.ToString("yyyyMMddHHmmss");
            string XML = TcpIpHelper.CombinSendXML(Num, 1, CMD, "FormulaItems", dtcmitems.Rows.Count, "", dtcm, dtcmitems);

            return(TcpIpHelper.TcpSend(XML, CMD, IP));
        }
Example #4
0
        ResultInfo UpdateDispatchListTcp(DispatchList dispatch)
        {
            string IP = GetControlSystemIP(dispatch.ProductLineID);

            //未指定该生产线IP,不使用TCP通讯,始终返回true;
            if (string.IsNullOrEmpty(IP))
            {
                logger.WarnFormat("未配置该生产线[{0}]的IP,不使用TCP通讯[UpdateDispatchListTcp],直接返回true。", dispatch.ProductLineID);
                return(new ResultInfo
                {
                    Result = true,
                    Message = "未配置该生产线IP,不使用TCP通讯。"
                });
            }

            DataTable dt = new DataTable();

            dt.Columns.Add("ID");
            dt.Columns.Add("PRegOrder");
            dt.Columns.Add("TaskID");
            dt.Columns.Add("CarID");
            dt.Columns.Add("Driver");

            dt.Columns.Add("CurCarProductNum");
            dt.Columns.Add("CurCarNum");
            dt.Columns.Add("FirNum");
            dt.Columns.Add("FirTrayNum");
            dt.Columns.Add("SecNum");
            dt.Columns.Add("SecTrayNum");
            dt.Columns.Add("IsContRun");
            dt.Columns.Add("RunproductCarNum");
            dt.Columns.Add("CompletetCarNum");
            dt.Columns.Add("ConcreteTrayNum");
            dt.Columns.Add("TraySumNum");
            dt.Columns.Add("FirMortarNum");
            dt.Columns.Add("FirMortarTrayNum");
            dt.Columns.Add("SecMortarTrayNum");
            dt.Columns.Add("SecMortarNum");
            dt.Columns.Add("MortarTrayNum");
            dt.Columns.Add("MortarTraySumNum");
            dt.Columns.Add("ConcreteSumNum");
            dt.Columns.Add("MortarNum");
            dt.Columns.Add("StartTime");
            dt.Columns.Add("EndTime");
            dt.Columns.Add("IsDivideAvg");
            dt.Columns.Add("TrayRate");
            dt.Columns.Add("ProductLineID");
            dt.Columns.Add("PrintStatus");
            dt.Columns.Add("RestStuffNum");
            dt.Columns.Add("TicketNum");
            dt.Columns.Add("FormulaCont");
            dt.Columns.Add("FormulaMor");
            dt.Columns.Add("FinishedAutoDel");
            dt.Columns.Add("Version");
            dt.Columns.Add("CreateTime");
            dt.Columns.Add("UpdateTime");
            dt.Columns.Add("CreaterID");
            dt.Columns.Add("UpdaterID");
            dt.Columns.Add("Status");
            dt.Columns.Add("PrintNum");
            dt.Columns.Add("PrintCarNum");
            dt.Columns.Add("BYField1");
            dt.Columns.Add("BYField2");
            dt.Columns.Add("BYField3");
            dt.Columns.Add("BYField4");
            dt.Columns.Add("BYField5");
            dt.Columns.Add("ShipDocID");

            DataRow Dr = dt.NewRow();

            Dr["ID"]               = dispatch.ID;
            Dr["PRegOrder"]        = dispatch.DispatchOrder;
            Dr["TaskID"]           = dispatch.TaskID;
            Dr["CarID"]            = dispatch.CarID;
            Dr["Driver"]           = dispatch.Driver;
            Dr["CompletetCarNum"]  = dispatch.ProvidedTimes;
            Dr["CurCarProductNum"] = dispatch.ProvidedCube;
            Dr["CurCarNum"]        = dispatch.ProduceCube;
            Dr["FirNum"]           = dispatch.OneCube;
            Dr["FirTrayNum"]       = dispatch.BNextPot;
            Dr["SecNum"]           = dispatch.TwoCube;
            Dr["SecTrayNum"]       = dispatch.BTotalPot - dispatch.BNextPot;
            Dr["IsContRun"]        = 0;
            Dr["RunproductCarNum"] = 0;
            Dr["ConcreteTrayNum"]  = dispatch.BTotalPot;
            Dr["TraySumNum"]       = dispatch.BTotalPot + dispatch.STotalPot;
            Dr["FirMortarNum"]     = dispatch.OneSlurryCube;
            Dr["FirMortarTrayNum"] = dispatch.SNextPot;
            Dr["SecMortarNum"]     = dispatch.TwoSlurryCube;
            Dr["SecMortarTrayNum"] = dispatch.STotalPot - dispatch.SNextPot;
            Dr["MortarTrayNum"]    = dispatch.STotalPot;
            Dr["MortarTraySumNum"] = dispatch.STotalPot;
            Dr["ConcreteSumNum"]   = dispatch.BetonCount;
            Dr["MortarNum"]        = dispatch.SlurryCount;
            Dr["StartTime"]        = null;
            Dr["EndTime"]          = null;
            Dr["IsDivideAvg"]      = dispatch.IsAverage;
            Dr["TrayRate"]         = dispatch.PCRate;
            Dr["ProductLineID"]    = "00000" + dispatch.ProductLineID;// 系统中数据库已经将机组线号改成8位
            //Dr["ProductLineID"] = dispatch.ProductLineID;
            Dr["PrintStatus"]     = 0;
            Dr["RestStuffNum"]    = 0;
            Dr["TicketNum"]       = dispatch.ParCube;
            Dr["FormulaCont"]     = dispatch.BetonFormula;
            Dr["FormulaMor"]      = dispatch.SlurryFormula;
            Dr["FinishedAutoDel"] = 0;
            Dr["Version"]         = 1;

            Dr["CreateTime"] = dispatch.BuildTime;
            Dr["UpdateTime"] = dispatch.ModifyTime;
            Dr["CreaterID"]  = dispatch.Builder;
            Dr["UpdaterID"]  = dispatch.Modifier;

            //Dr["Status"] = 0;//ERP修改调度不修改控制系统的生产状态
            Dr["PrintNum"]    = dispatch.ProvidedCube;
            Dr["PrintCarNum"] = dispatch.ProvidedTimes;
            Dr["BYField1"]    = dispatch.ParCube;                                                                //备用1:出票方量
            Dr["BYField2"]    = dispatch.ProvidedTimes;                                                          //备用2:累计车次
            Dr["BYField3"]    = dispatch.ProvidedCube;                                                           //备用3:已供方量
            Dr["BYField4"]    = dispatch.ConStrength;                                                            //备用4:砼强度
            Dr["BYField5"]    = string.IsNullOrEmpty(dispatch.PumpName) ? dispatch.CastMode : dispatch.PumpName; //备用5:浇筑方式或泵名称
            Dr["ShipDocID"]   = dispatch.ShipDocID;

            dt.Rows.Add(Dr);
            string CMD = "103";

            string Num = IP + ":" + DateTime.Now.ToString("yyyyMMddHHmmss");
            string XML = TcpIpHelper.CombinSendXML(Num, 1, CMD, "ProductRegist", "", dt);

            return(TcpIpHelper.TcpSend(XML, CMD, IP));
        }
Example #5
0
        /// <summary>
        /// 发送字节流
        /// </summary>
        /// <param name="server">targetIP</param>
        /// <param name="message">byte[] message</param>
        /// <returns></returns>
        public static ResultInfo SendMessage(string server, byte[] message)
        {
            bool   status        = false;
            int    resultCode    = 0;
            string Num           = string.Empty;
            string CMD           = string.Empty;
            string resultMessage = string.Empty;

            TcpClient     client = new TcpIpHelper(server).Connect();
            NetworkStream ns     = client.GetStream();

            try
            {
                Byte[] sendData = message;
                log.DebugFormat("发送消息到【{0}】,内容为:{1},\r\n*********len:{2}", server, DefaultEncoding.GetString(message), sendData.Length);
                ns.Write(sendData, 0, sendData.Length);//写入字节流

                //接收服务端的响应数据
                byte[] recieveData  = new Byte[1024];
                string responseData = string.Empty;
                ns.ReadTimeout = RECEIVE_TIMEOUT;//读取服务端返回信息超时时间(ms),建议配置在webconfig中 xyl 2013-03-07
                Int32 bytes = ns.Read(recieveData, 0, recieveData.Length);

                responseData = System.Text.Encoding.Default.GetString(recieveData, 0, bytes);
                log.DebugFormat("接收消息到【{0}】,内容为:{1}", server, responseData);
                //处理返回信息,返回数据为xml格式的字串
                //1、操作成功:status = true
                GetResultXML(responseData, out Num, out CMD, out status, out resultCode, out resultMessage);
                //status = true;
                //resultMessage = "操作成功";

                //2、操作失败:status = false
                //status = false;
                //resultMessage = "从返回结果中解析并说明失败原因";
            }

            catch (Exception e)
            {
                //异常处理
                SocketException se  = (SocketException)e.InnerException.GetBaseException();
                string          msg = string.Empty;
                switch (se.ErrorCode)
                {
                case 10060:
                    msg = string.Format(" 连接<font color=blue>控制系统 <b>{0}</b></font>处理超时",
                                        server);
                    break;

                case 10061:
                    msg = string.Format(" 连接<font color=blue>控制系统 <b>{0}</b></font> 超时,可能原因是机器或打料系统未启动",
                                        server);
                    break;

                case 10065:
                    msg = string.Format(" 无法连接<font color=blue>控制系统 <b>{0}</b></font>,可能网线没有插好,请检查网络连接!",
                                        server);
                    break;

                default:
                    msg = se.Message;
                    break;
                }
                log.Error(msg);
                throw new Exception(msg);
            }
            finally
            {
                //关闭流
                ns.Close();
                //关闭连接
                client.Close();
            }
            return(new ResultInfo
            {
                Result = status,
                ResultCode = resultCode,
                Message = "[控制系统:" + server + "]" + resultMessage
            });
        }
Example #6
0
        /// <summary>
        /// 发送字符串
        /// </summary>
        /// <param name="server"></param>
        /// <param name="message">message信息为xml形式的字串</param>
        public static dynamic SendMessage(string server, string message)
        {
            bool   status        = false;
            int    resultCode    = 0;
            string Num           = string.Empty;
            string CMD           = string.Empty;
            string resultMessage = string.Empty;

            try
            {
                TcpClient client = new TcpIpHelper(server).Connect();


                Byte[] sendData = DefaultEncoding.GetBytes(message);

                NetworkStream ns = client.GetStream();

                log.DebugFormat("发送消息到【{0}】,内容为:{1}", server, message);
                ns.Write(sendData, 0, sendData.Length);//写入字节流

                //接收服务端的响应数据
                byte[] recieveData  = new Byte[1024];
                string responseData = string.Empty;
                ns.ReadTimeout = client.ReceiveTimeout;
                Int32 bytes = ns.Read(recieveData, 0, recieveData.Length);
                responseData = System.Text.Encoding.Default.GetString(recieveData, 0, bytes);
                log.DebugFormat("接收消息到【{0}】,内容为:{1}", server, responseData);
                GetResultXML(responseData, out Num, out CMD, out status, out resultCode, out resultMessage);

                //处理返回信息,返回数据为xml格式的字串
                //1、操作成功:status = true
                //status = true;
                //resultMessage = "操作成功";

                //2、操作失败:status = false
                //status = false;
                //resultMessage = "从返回结果中解析并说明失败原因";

                //关闭流
                ns.Close();
                //关闭连接
                client.Close();
            }

            catch (Exception e)
            {
                //异常处理
                SocketException se  = (SocketException)e.InnerException.GetBaseException();
                string          msg = string.Empty;
                switch (se.ErrorCode)
                {
                case 10060:
                    msg = string.Format(" 连接<font color=blue>控制系统 <b>{0}</b></font>处理超时",
                                        server);
                    break;

                case 10061:
                    msg = string.Format(" 连接<font color=blue>控制系统 <b>{0}</b></font> 超时,可能原因是机器或打料系统未启动",
                                        server);
                    break;

                case 10065:
                    msg = string.Format(" 无法连接<font color=blue>控制系统 <b>{0}</b></font>,可能网线没有插好,请检查网络连接!",
                                        server);
                    break;

                default:
                    msg = se.Message;
                    break;
                }
                log.Error(msg);
                throw new Exception(msg);
            }
            return(new
            {
                Status = status,
                ResultCode = resultCode,
                Message = message
            });
        }