コード例 #1
0
        /// <summary>
        /// 修改XML中的DeviceControl
        /// </summary>
        /// <param name="station"></param>
        /// <returns></returns>
        private bool EditDeviceControlFromXML(XML_DeviceControl _device)
        {
            try
            {
                XmlDocument XDoc = new XmlDocument();
                XDoc.Load(Path); //加载XML文档

                XmlElement ListTestEl = (XmlElement)XDoc.SelectSingleNode(@"/ClientConfig/DeviceControl");

                if (ListTestEl != null)
                {
                    foreach (XmlNode item in ListTestEl.ChildNodes)
                    {
                        XmlElement xe = (XmlElement)item;
                        if (xe.GetAttribute("UniqueId") == _device.UniqueId.ToString())
                        {
                            xe.SetAttribute("StationUniqueId", _device.StationUniqueId.ToString());
                            xe.SetAttribute("Number", _device.Number.ToString());
                            xe.SetAttribute("DeviceId", _device.DeviceId.ToString());
                        }
                    }
                }
                XDoc.Save(Path);
            }
            catch (Exception ex)
            {
                LogMg.AddError(ex);
                return(false);
            }
            return(true);
        }
コード例 #2
0
        /// <summary>
        /// 从XML删除DeviceControl
        /// </summary>
        /// <param name="uniqueId"></param>
        /// <returns></returns>
        private bool DelDeviceControlFromXML(int uniqueId)
        {
            try
            {
                XmlDocument XDoc = new XmlDocument();
                XDoc.Load(Path); //加载XML文档

                XmlElement ListTestEl = (XmlElement)XDoc.SelectSingleNode(@"/ClientConfig/DeviceControl");

                if (ListTestEl != null)
                {
                    foreach (XmlNode item in ListTestEl.ChildNodes)
                    {
                        XmlElement xe = (XmlElement)item;
                        if (xe.GetAttribute("UniqueId") == uniqueId.ToString())
                        {
                            ListTestEl.RemoveChild(item);
                        }
                    }
                }

                XDoc.Save(Path);
            }
            catch (Exception ex)
            {
                LogMg.AddError(ex);
                return(false);
            }
            return(true);
        }
コード例 #3
0
        /// <summary>
        /// 获取所有Test
        /// </summary>
        /// <returns></returns>
        public List <Clazz.Config.XML_Test> GetAllTests()
        {
            List <Clazz.Config.XML_Test> ListTest = new List <Clazz.Config.XML_Test>();

            try
            {
                XmlNodeList nodeList = Utility.XmlHelper.GetXmlNodeListByXpath(PATH, "/Config/Tests/Test");
                foreach (XmlNode item in nodeList)
                {
                    XmlElement            xel  = (XmlElement)item;
                    Clazz.Config.XML_Test test = new Clazz.Config.XML_Test();
                    test.StationUnique  = int.Parse(xel.GetAttribute("StationUnique"));
                    test.StationId      = int.Parse(xel.GetAttribute("StationId"));
                    test.RegisterNo     = ushort.Parse(xel.GetAttribute("RegisterNo"));
                    test.TestId         = int.Parse(xel.GetAttribute("TestId"));
                    test.Multiple       = double.Parse(xel.GetAttribute("Multiple"));
                    test.FunctionCode   = Convert.ToInt32(xel.GetAttribute("FunctionCode"));
                    test.ReceiveTimeout = Convert.ToInt32(xel.GetAttribute("ReceiveTimeout"));
                    test.DataType       = xel.GetAttribute("DataType");
                    test.Address        = byte.Parse(xel.GetAttribute("Address"));
                    test.DecodeOrder    = xel.GetAttribute("DecodeOrder");
                    test.Min            = double.Parse(xel.GetAttribute("Min"));
                    test.Max            = double.Parse(xel.GetAttribute("Max"));
                    test.AddNumber      = double.Parse(xel.GetAttribute("AddNumber"));
                    ListTest.Add(test);
                }
            }
            catch (Exception ex)
            {
                LogMg.AddError(ex);
                DEBUG.ThrowException(ex);
            }
            return(ListTest);
        }
コード例 #4
0
        private void DeviceControlCallBack(Socket socket, string json)
        {
            C_To_S_Data <CSDataStandard.Transfer.DeviceControl> receiveObj = Utility.JsonHelper.JsonDeserialize <C_To_S_Data <CSDataStandard.Transfer.DeviceControl> >(json);

            //获取所有Org
            Clazz.Config.XML_Org org = SysConfig.orgConfig.GetOrgByOrgId(receiveObj.OrgId);
            if (org == null)  //判断Org是否存在
            {
                string msg = "OrgId:" + receiveObj.OrgId + "不存在";
                LogMg.AddError(msg);
                lb_msg.Items.Add(msg);
            }
            else
            {
                try
                {
                    SWSDataContext  db          = new SWSDataContext(ServerSocketHelper.GetConnection(org.DBName));
                    string          stationName = "未知的客户端";
                    country_station station     = db.country_station.SingleOrDefault(c => c.id == receiveObj.StationId);
                    if (station != null)
                    {
                        stationName = station.name;
                    }

                    saveData(db, receiveObj, stationName);

                    sendData(db, socket, stationName, receiveObj.StationId);
                }
                catch (Exception ex)
                {
                    LogMg.AddError(ex);
                    DEBUG.MsgBox(ex.ToString());
                }
            }
        }
コード例 #5
0
ファイル: JBT_DTU.cs プロジェクト: zhaobf1990/ControlServer
 public static bool CheckProtocolByRegisterData(byte[] pack, int len)
 {
     try
     {
         int i;
         for (i = 0; i < len; i++)
         {
             if (pack[i] == JBT_DTU.Head0 && pack[i + 1] == JBT_DTU.Head1)    //先找到头
             {
                 break;
             }
         }
         if (i == len)
         {
             return(false);
         }
         if (pack[i + 17] != DTU_to_Server_Register)
         {
             return(false);
         }
         return(CheckCheckCode(pack.Skip(i).Take(20).ToArray()));
     }
     catch (Exception ex)
     {
         LogMg.AddError(ex);
         return(false);
     }
 }
コード例 #6
0
        public void Save(Socket socket, string json)
        {
            C_To_S_Data <object> obj = Utility.JsonHelper.JsonDeserialize <C_To_S_Data <object> >(json);

            Clazz.Config.XML_Org _org = SysConfig.orgConfig.GetOrgByOrgId(obj.OrgId);

            if (_org == null)
            {
                //将信息写入到日志文件中    orgid为***的污水厂不存在
                LogMg.AddError("OrgId:\"{0}\"不存在");
                //isSuccess = false;
            }
            else
            {
                try
                {
                    SWSDataContext  SWS     = new SWSDataContext(ServerSocketHelper.GetConnection(_org.DBName)); //建立一个分厂数据源提供程序实例
                    country_station station = SWS.country_station.SingleOrDefault(c => c.id == obj.StationId);
                    if (station == null)
                    {
                        LogMg.AddError("StationId: " + obj.StationId + " 不存在");
                    }
                    else
                    {
                        station.ip = obj.Data[0].ToString();     //保存客户端IP地址
                        SWS.SubmitChanges();
                    }
                }
                catch (Exception ex)
                {
                    LogMg.AddError(ex);
                }
            }
        }
コード例 #7
0
        /// <summary>
        /// 返回所有站点
        /// </summary>
        /// <returns></returns>
        public List <Clazz.Config.ClientConfig.XML_Station> GetAllStation()
        {
            List <Clazz.Config.ClientConfig.XML_Station> list = new List <Clazz.Config.ClientConfig.XML_Station>();

            try
            {
                XmlNodeList ListNode = Utility.XmlHelper.GetXmlNodeListByXpath(Path, "/ClientConfig/Stations/Station");
                foreach (XmlNode item in ListNode)
                {
                    XmlElement xe = (XmlElement)item;

                    Clazz.Config.ClientConfig.XML_Station _station = new Clazz.Config.ClientConfig.XML_Station();
                    _station.UniqueId     = int.Parse(xe.GetAttribute("UniqueId"));
                    _station.TransferCode = xe.GetAttribute("TransferCode");
                    _station.StationId    = int.Parse(xe.GetAttribute("StationId"));
                    _station.OrgId        = xe.GetAttribute("OrgId");
                    _station.StationName  = xe.GetAttribute("站点名称");
                    list.Add(_station);
                }
            }
            catch (Exception ex)
            {
                LogMg.AddError(ex);
            }
            return(list);
        }
コード例 #8
0
        /// <summary>
        /// 获取mcgstest
        /// </summary>
        /// <returns></returns>
        public List <XML_MCGSTest> GetAllMCGSTest()
        {
            List <XML_MCGSTest> _listMcgsTest = new List <XML_MCGSTest>();

            try
            {
                XmlNodeList nodeList = Utility.XmlHelper.GetXmlNodeListByXpath(Path, "/ClientConfig/MCGS/Test");

                foreach (XmlNode item in nodeList)
                {
                    XmlElement   xel  = (XmlElement)item;
                    XML_MCGSTest mcgs = new XML_MCGSTest();
                    mcgs.UniqueId        = int.Parse(xel.GetAttribute("UniqueId"));
                    mcgs.StationUniqueId = int.Parse(xel.GetAttribute("StationUniqueId"));
                    mcgs.TestId          = int.Parse(xel.GetAttribute("TestId"));
                    mcgs.ColumnName      = xel.GetAttribute("ColumnName");
                    mcgs.TestName        = xel.GetAttribute("TestName");

                    _listMcgsTest.Add(mcgs);
                }
            }
            catch (Exception ex)
            {
                LogMg.AddError(ex);
                DEBUG.ThrowException(ex);
            }
            return(_listMcgsTest);
        }
コード例 #9
0
        /// <summary>
        /// 保存配置到XML
        /// </summary>
        /// <returns></returns>
        private bool AddCountryTestToXML(XML_CountryTest test)
        {
            try
            {
                XmlDocument XDoc = new XmlDocument();
                XDoc.Load(Path); //加载XML文档

                XmlElement ListTestEl = (XmlElement)XDoc.SelectSingleNode(@"/ClientConfig/CountryTest");

                XmlElement xe = XDoc.CreateElement("Test");
                xe.SetAttribute("UniqueId", test.UniqueId.ToString());
                xe.SetAttribute("StationUniqueId", test.StationUniqueId.ToString());
                xe.SetAttribute("NodeId", test.NodeId.ToString());
                xe.SetAttribute("TestId", test.TestId.ToString());
                xe.SetAttribute("备注", test.Remark);
                xe.SetAttribute("Multiple", test.Multiple.ToString());
                ListTestEl.AppendChild(xe);

                XDoc.Save(Path);
            }
            catch (Exception ex)
            {
                LogMg.AddError(ex);
                return(false);
            }
            return(true);
        }
コード例 #10
0
        /// <summary>
        /// 修改XML中的countrytest
        /// </summary>
        /// <param name="station"></param>
        /// <returns></returns>
        private bool EditCountryTestFromXML(XML_CountryTest _test)
        {
            try
            {
                XmlDocument XDoc = new XmlDocument();
                XDoc.Load(Path); //加载XML文档

                XmlElement ListTestEl = (XmlElement)XDoc.SelectSingleNode(@"/ClientConfig/CountryTest");

                if (ListTestEl != null)
                {
                    foreach (XmlNode item in ListTestEl.ChildNodes)
                    {
                        XmlElement xe = (XmlElement)item;
                        if (xe.GetAttribute("UniqueId") == _test.UniqueId.ToString())
                        {
                            xe.SetAttribute("StationUniqueId", _test.StationUniqueId.ToString());
                            xe.SetAttribute("NodeId", _test.NodeId.ToString());
                            xe.SetAttribute("TestId", _test.TestId.ToString());
                            xe.SetAttribute("备注", _test.Remark);
                            xe.SetAttribute("Multiple", _test.Multiple.ToString());
                        }
                    }
                }
                XDoc.Save(Path);
            }
            catch (Exception ex)
            {
                LogMg.AddError(ex);
                return(false);
            }
            return(true);
        }
コード例 #11
0
        public bool AddCountryTest(XML_CountryTest ct, ref string msg)
        {
            bool flag = true;

            try
            {
                if (AllCountryTest.Exists(c => c.StationUniqueId == ct.StationUniqueId && c.NodeId == ct.NodeId))
                {
                    msg  = ct.StationName + " 站点已经存在 " + ct.Remark + " 检测节点";
                    flag = false;
                }
                else if (AllCountryTest.Exists(c => c.StationUniqueId == ct.StationUniqueId && c.TestId == ct.TestId))
                {
                    msg  = ct.StationName + " 站点已经存在testid= " + ct.Remark + " 检测节点";
                    flag = false;
                }
                else
                {
                    lock (AllCountryTest)
                    {
                        int uniqueId = AllCountryTest.Max(c => c.UniqueId);
                        ct.UniqueId = uniqueId + 1;
                        AllCountryTest.Add(ct);
                        flag = AddCountryTestToXML(ct);
                    }
                }
            }
            catch (Exception ex)
            {
                flag = false;
                LogMg.AddError(ex);
            }
            return(flag);
        }
コード例 #12
0
        /// <summary>
        /// 返回所有农村项目检测点
        /// </summary>
        /// <returns></returns>
        public List <XML_CountryTest> GetAllCountryTest()
        {
            List <XML_CountryTest> _listCountryTest = new List <XML_CountryTest>();

            try
            {
                XmlNodeList nodeList = Utility.XmlHelper.GetXmlNodeListByXpath(Path, "/ClientConfig/CountryTest/Test");

                foreach (XmlNode item in nodeList)
                {
                    XmlElement      xel         = (XmlElement)item;
                    XML_CountryTest countryTest = new XML_CountryTest();

                    countryTest.UniqueId        = int.Parse(xel.GetAttribute("UniqueId"));
                    countryTest.StationUniqueId = int.Parse(xel.GetAttribute("StationUniqueId"));
                    countryTest.NodeId          = xel.GetAttribute("NodeId");
                    countryTest.TestId          = int.Parse(xel.GetAttribute("TestId"));
                    countryTest.Multiple        = double.Parse(xel.GetAttribute("Multiple"));
                    countryTest.Remark          = xel.GetAttribute("备注");

                    _listCountryTest.Add(countryTest);
                }
            }
            catch (Exception ex)
            {
                LogMg.AddError(ex);
                DEBUG.ThrowException(ex);
            }
            return(_listCountryTest);
        }
コード例 #13
0
        /// <summary>
        /// 获取所有检测节点
        /// </summary>
        /// <returns></returns>
        public List <XML_CountryNode> GetAllCountryNode()
        {
            List <XML_CountryNode> _listCountryTest = new List <XML_CountryNode>();

            try
            {
                XmlNodeList nodeList = Utility.XmlHelper.GetXmlNodeListByXpath(Path, "/ClientConfig/CountryTest/Nodes/Node");
                foreach (XmlNode item in nodeList)
                {
                    XmlElement      xel  = (XmlElement)item;
                    XML_CountryNode node = new XML_CountryNode();

                    node.NodeId = xel.GetAttribute("NodeId");
                    node.Remark = xel.GetAttribute("备注");

                    _listCountryTest.Add(node);
                }
            }
            catch (Exception ex)
            {
                LogMg.AddError(ex);
                DEBUG.ThrowException(ex);
            }
            return(_listCountryTest);
        }
コード例 #14
0
ファイル: FormPMQC.cs プロジェクト: zhaobf1990/ControlServer
        //接收到客户端发来的数据,并向客户端返回消息
        private void RecieveCallBack(Socket RSocket, string msg)
        {
            try
            {
                //Socket RSocket = (Socket)ar.AsyncState;

                bool flag = this.Save(msg);   //序列化json  并保存到数据库

                S_To_C_Data <object> s_to_c_data = new S_To_C_Data <object>();
                s_to_c_data.Flag    = HandleFlag.PMQC;
                s_to_c_data.Success = flag;
                string json = Utility.JsonHelper.JsonSerializer <S_To_C_Data <object> >(s_to_c_data);

                RSocket.Send(Encoding.Unicode.GetBytes(json), SocketFlags.None);  //保存成功返回1    ,反之则0
                //把消息输出到页面上
                lb_msg.Items.Add(flag ? "保存成功" : "保存失败");
                //同时接收客户端回发的数据,用于回发
                //RSocket.BeginReceive(MsgBuffer, 0, MsgBuffer.Length, 0, new AsyncCallback(RecieveCallBack), RSocket);
            }
            catch (Exception ex)
            {
                LogMg.AddError(ex);
                DEBUG.ThrowException(ex);
            }
        }
コード例 #15
0
        /// <summary>
        /// 保存配置到XML
        /// </summary>
        /// <returns></returns>
        private bool AddStationToXML(Clazz.Config.ClientConfig.XML_Station station)
        {
            try
            {
                XmlDocument XDoc = new XmlDocument();
                XDoc.Load(Path); //加载XML文档

                XmlElement ListTestEl = (XmlElement)XDoc.SelectSingleNode(@"/ClientConfig/Stations");

                XmlElement xe = XDoc.CreateElement("Station");
                xe.SetAttribute("UniqueId", station.UniqueId.ToString());
                xe.SetAttribute("TransferCode", station.TransferCode);
                xe.SetAttribute("StationId", station.StationId.ToString());
                xe.SetAttribute("OrgId", station.OrgId);
                xe.SetAttribute("站点名称", station.StationName);
                ListTestEl.AppendChild(xe);

                XDoc.Save(Path);
            }
            catch (Exception ex)
            {
                LogMg.AddError(ex);
                return(false);
            }
            return(true);
        }
コード例 #16
0
        public List <XML_MobileDetection> GetAllMobileDetection()
        {
            List <XML_MobileDetection> list = new List <XML_MobileDetection>();

            try
            {
                XmlNodeList ListNode = Utility.XmlHelper.GetXmlNodeListByXpath(Path, "/ClientConfig/MobileDetection/Test");
                foreach (XmlNode item in ListNode)
                {
                    XmlElement xe = (XmlElement)item;

                    XML_MobileDetection _test = new XML_MobileDetection();
                    _test.UniqueId        = int.Parse(xe.GetAttribute("UniqueId"));
                    _test.StationUniqueId = int.Parse(xe.GetAttribute("StationUniqueId"));
                    _test.TestId          = int.Parse(xe.GetAttribute("TestId"));
                    _test.TestTarger      = xe.GetAttribute("检测指标");

                    list.Add(_test);
                }
            }
            catch (Exception ex)
            {
                LogMg.AddError(ex);
            }
            return(list);
        }
コード例 #17
0
        private bool EditStationFromXML(XML_Station station)
        {
            try
            {
                XmlDocument XDoc = new XmlDocument();
                XDoc.Load(Path); //加载XML文档

                XmlElement ListTestEl = (XmlElement)XDoc.SelectSingleNode(@"/ClientConfig/Stations");

                if (ListTestEl != null)
                {
                    foreach (XmlNode item in ListTestEl.ChildNodes)
                    {
                        XmlElement xe = (XmlElement)item;
                        if (xe.GetAttribute("UniqueId") == station.UniqueId.ToString())
                        {
                            xe.SetAttribute("TransferCode", station.TransferCode);
                            xe.SetAttribute("StationId", station.StationId.ToString());
                            xe.SetAttribute("OrgId", station.OrgId.ToString());
                            xe.SetAttribute("站点名称", station.StationName);
                        }
                    }
                }

                XDoc.Save(Path);
            }
            catch (Exception ex)
            {
                LogMg.AddError(ex);
                return(false);
            }
            return(true);
        }
コード例 #18
0
ファイル: JBT_DTU.cs プロジェクト: zhaobf1990/ControlServer
        /// <summary>
        /// 回应注册
        /// </summary>
        /// <param name="ReceiveBuffer">接收到的注册数据或心跳数据</param>
        /// <param name="len">接收到的字节数</param>
        public static bool Response_Reigster(Socket socket, string tel)
        {
            try
            {
                byte[] sendBytes = new byte[20];
                //两字节的头
                sendBytes[0] = 0xA8;
                sendBytes[1] = 0x81;
                //11个字节的手机号
                if (tel == null && tel.Length != 11)
                {
                    return(false);
                }
                Buffer.BlockCopy(Encoding.ASCII.GetBytes(tel), 0, sendBytes, 2, 11);
                //四个字节的区号
                sendBytes[13] = 0x30;
                sendBytes[14] = 0x30;
                sendBytes[15] = 0x30;
                sendBytes[16] = 0x30;
                //一个字节的功能码
                sendBytes[17] = JBT_DTU.Server_to_DTU_Register;
                //一个字节的区号启用标志
                sendBytes[18] = 0x00;
                //生成校验码
                GenerateCheckCode(sendBytes);
                int n = socket.Send(sendBytes, sendBytes.Length, SocketFlags.None);

                return(n > 0);
            }
            catch (Exception ex)
            {
                LogMg.AddError(ex);
                return(false);
            }
        }
コード例 #19
0
        public List <XML_DeviceControl> GetAllDeviceControl()
        {
            List <XML_DeviceControl> list = new List <XML_DeviceControl>();

            try
            {
                XmlNodeList ListNode = Utility.XmlHelper.GetXmlNodeListByXpath(Path, "/ClientConfig/DeviceControl/Device");
                foreach (XmlNode item in ListNode)
                {
                    XmlElement xe = (XmlElement)item;

                    XML_DeviceControl _device = new XML_DeviceControl();
                    _device.UniqueId        = int.Parse(xe.GetAttribute("UniqueId"));
                    _device.StationUniqueId = int.Parse(xe.GetAttribute("StationUniqueId"));
                    _device.Number          = xe.GetAttribute("Number");
                    _device.DeviceId        = int.Parse(xe.GetAttribute("DeviceId"));

                    list.Add(_device);
                }
            }
            catch (Exception ex)
            {
                LogMg.AddError(ex);
            }
            return(list);
        }
コード例 #20
0
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_Edit_Click(object sender, EventArgs e)
        {
            try
            {
                DataGridViewSelectedRowCollection rows = dataGridView1.SelectedRows;
                if (rows == null || rows.Count <= 0)
                {
                    MessageBox.Show("请先选择要修改的行", "提示");
                    return;
                }
                DataGridViewRow row = rows[0];

                DeviceControlModify edit = new DeviceControlModify();
                edit.UniqueId = Convert.ToInt32(row.Cells["UniqueId"].Value);

                edit.ShowDialog();

                dataGridView1.DataSource = null;
                dataGridView1.DataSource = SysConfig.clientConfig.AllDevice;
            }
            catch (Exception ex)
            {
                LogMg.AddError(ex);
            }
        }
コード例 #21
0
        public bool AddDeviceControl(XML_DeviceControl device, ref string msg)
        {
            bool flag = true;

            try
            {
                if (AllDevice.Exists(c => c.StationUniqueId == device.StationUniqueId && c.Number == device.Number))
                {
                    msg  = "该站点已存在设备编号:" + device.Number;
                    flag = false;
                }
                else if (AllDevice.Exists(c => c.StationUniqueId == device.StationUniqueId && c.DeviceId == device.DeviceId))
                {
                    msg  = "该站点已存在寄存器编号:" + device.DeviceId;
                    flag = false;
                }
                else
                {
                    lock (AllDevice)
                    {
                        int uniqueId = AllDevice.Max(c => c.UniqueId);
                        device.UniqueId = uniqueId + 1;
                        AllDevice.Add(device);
                        flag = AddDeviceControlToXML(device);
                    }
                }
            }
            catch (Exception ex)
            {
                flag = false;
                LogMg.AddError(ex);
            }
            return(flag);
        }
コード例 #22
0
        /// <summary>
        /// 返回所有的Station
        /// </summary>
        /// <returns></returns>
        private List <Clazz.Config.XML_Station> GetAllStation()
        {
            List <Clazz.Config.XML_Station> ListStation = new List <Clazz.Config.XML_Station>();

            try
            {
                XmlNodeList nodeList = Utility.XmlHelper.GetXmlNodeListByXpath(PATH, "/Config/Stations/Station");
                foreach (XmlNode item in nodeList)
                {
                    XmlElement xel = (XmlElement)item;
                    Clazz.Config.XML_Station station = new Clazz.Config.XML_Station();
                    station.Unique    = int.Parse(xel.GetAttribute("Unique"));    //主键
                    station.StationId = int.Parse(xel.GetAttribute("StationId")); //站点Id
                    station.Name      = xel.GetAttribute("Name");                 //站点名称
                    station.OrgId     = xel.GetAttribute("OrgId");
                    station.Tel       = xel.GetAttribute("Tel");                  //手机号码
                    station.Protocol  = xel.GetAttribute("Protocol");             //手机号码
                    ListStation.Add(station);
                }
            }
            catch (Exception ex)
            {
                LogMg.AddError(ex);
                DEBUG.ThrowException(ex);
            }
            return(ListStation);
        }
コード例 #23
0
        /// <summary>
        /// 保存配置到XML
        /// </summary>
        /// <returns></returns>
        private bool AddDeviceControlToXML(XML_DeviceControl device)
        {
            try
            {
                XmlDocument XDoc = new XmlDocument();
                XDoc.Load(Path); //加载XML文档

                XmlElement ListTestEl = (XmlElement)XDoc.SelectSingleNode(@"/ClientConfig/DeviceControl");

                XmlElement xe = XDoc.CreateElement("Device");
                xe.SetAttribute("UniqueId", device.UniqueId.ToString());
                xe.SetAttribute("StationUniqueId", device.StationUniqueId.ToString());
                xe.SetAttribute("Number", device.Number.ToString());
                xe.SetAttribute("DeviceId", device.DeviceId.ToString());
                ListTestEl.AppendChild(xe);

                XDoc.Save(Path);
            }
            catch (Exception ex)
            {
                LogMg.AddError(ex);
                return(false);
            }
            return(true);
        }
コード例 #24
0
        /// <summary>
        /// 接收数据
        /// </summary>
        /// <param name="obj"></param>
        private void ReceiveMessage(object obj)
        {
            IPEndPoint remoteIpep = new IPEndPoint(IPAddress.Any, 0);

            while (true)
            {
                try
                {
                    byte[] bytRecv = udpcRecv.Receive(ref remoteIpep);
                    //  string message = Encoding.ASCII.GetString(bytRecv, 0, bytRecv.Length);


                    V88CommunicationThread.getInstance().receiveTask(bytRecv);
                    //  LogManager.AddDebug("入口接收的数据=============     " + message);

                    byte[] sendBtyes = Encoding.ASCII.GetBytes("@222");  //需要回发这几个字符
                    udpcRecv.Send(sendBtyes, sendBtyes.Length, remoteIpep);
                }
                catch (Exception ex)
                {
                    LogMg.AddError(ex.ToString());
                    break;
                }
            }
        }
コード例 #25
0
        /// <summary>
        /// 获取所有屏幕取词的检测点
        /// </summary>
        /// <returns></returns>
        public List <XML_PMQCTest> GetAllPMQCTest()
        {
            List <XML_PMQCTest> list = new List <XML_PMQCTest>();

            try
            {
                XmlNodeList ListNode = Utility.XmlHelper.GetXmlNodeListByXpath(Path, "/ClientConfig/PMQC/Test");
                foreach (XmlNode item in ListNode)
                {
                    XmlElement xe = (XmlElement)item;

                    XML_PMQCTest _test = new XML_PMQCTest();
                    _test.UniqueId        = int.Parse(xe.GetAttribute("UniqueId"));
                    _test.StationUniqueId = int.Parse(xe.GetAttribute("StationUniqueId"));
                    _test.Id     = int.Parse(xe.GetAttribute("Id"));
                    _test.Name   = xe.GetAttribute("Name");
                    _test.X      = int.Parse(xe.GetAttribute("X"));
                    _test.Y      = int.Parse(xe.GetAttribute("Y"));
                    _test.TestId = int.Parse(xe.GetAttribute("TestId"));
                    list.Add(_test);
                }
            }
            catch (Exception ex)
            {
                LogMg.AddError(ex);
            }
            return(list);
        }
コード例 #26
0
        /// <summary>
        /// 保存客户端的IP地址
        /// </summary>
        /// <param name="socket"></param>
        /// <param name="c_to_s_data"></param>
        public void SaveClientIp(Socket socket, C_To_S_Data <CSDataStandard.Transfer.RealRec> c_to_s_data)
        {
            IPEndPoint ipEndPoint = (IPEndPoint)socket.RemoteEndPoint;
            string     ip         = ipEndPoint.Address.ToString();

            Clazz.Config.XML_Org _org = SysConfig.orgConfig.GetOrgByOrgId(c_to_s_data.OrgId);

            if (_org == null)
            {
                //将信息写入到日志文件中    orgid为***的污水厂不存在
                LogMg.AddError(String.Format("OrgId:{0}  不存在", c_to_s_data.OrgId));
                //isSuccess = false;
            }
            else
            {
                try
                {
                    SWSDataContext  SWS     = new SWSDataContext(ServerSocketHelper.GetConnection(_org.DBName)); //建立一个分厂数据源提供程序实例
                    country_station station = SWS.country_station.SingleOrDefault(c => c.id == c_to_s_data.StationId);
                    if (station == null)
                    {
                        LogMg.AddError("StationId: " + c_to_s_data.StationId + " 不存在");
                    }
                    else
                    {
                        station.ip = ip;     //保存客户端IP地址
                        SWS.SubmitChanges();
                    }
                }
                catch (Exception ex)
                {
                    LogMg.AddError(ex);
                }
            }
        }
コード例 #27
0
ファイル: OrgConfig.cs プロジェクト: zhaobf1990/ControlServer
        /// <summary>
        /// 获取所有的Org
        /// </summary>
        /// <returns></returns>
        private List <Clazz.Config.XML_Org> GetAllOrg()
        {
            List <Clazz.Config.XML_Org> list = new List <Clazz.Config.XML_Org>();

            try
            {
                XmlNodeList xnl = Utility.XmlHelper.GetXmlNodeListByXpath(filePath, "/Config/Orgs/Org");
                foreach (XmlNode item in xnl)
                {
                    XmlElement           xe  = (XmlElement)item;
                    Clazz.Config.XML_Org org = new Clazz.Config.XML_Org();
                    org.OrgId       = xe.GetAttribute("OrgId");
                    org.Name        = xe.GetAttribute("Name");
                    org.DBName      = xe.GetAttribute("DBName");
                    org.gdServerCfg = xe.GetAttribute("gdServerCfg");
                    list.Add(org);
                }
            }
            catch (Exception e)
            {
                LogMg.AddError(e);
                DEBUG.MsgBox(e.ToString());
            }
            return(list);
        }
コード例 #28
0
        /// <summary>
        /// 将数据解析成键值对
        /// </summary>
        /// <param name="datas"></param>
        /// <returns></returns>
        private List <Dictionary <string, string> > parseDataV88(List <String> datas, ref DateTime date)
        {
            List <Dictionary <string, string> > list = new List <Dictionary <string, string> >();

            foreach (string one in datas)
            {
                Dictionary <string, string> dir = new Dictionary <string, string>();
                try
                {
                    int first = one.IndexOf(";") + 1;
                    int two   = one.IndexOf(";", first);
                    date = DateTime.Parse(one.Substring(first, two - first));
                }
                catch (Exception e)
                {
                    LogMg.AddError(e);
                }

                string[] arr = one.Split(';');
                for (int i = 0; i < arr.Length; i++)
                {
                    if (i != 1)
                    {
                        string[] arr2 = arr[i].Split(':');
                        //  Console.WriteLine("key=" + arr2[0] + "   value=" + arr2[1]);
                        dir.Add(arr2[0], arr2[1]);
                    }
                }
                Console.WriteLine();
                list.Add(dir);
            }
            return(list);
        }
コード例 #29
0
        /// <summary>
        /// 处理考勤数据
        /// </summary>
        /// <param name="bytes"></param>
        private void handlerAttMsg(byte[] bytes)
        {
            try
            {
                LogMg.AddDebug("udp协议接收的考勤数据=============     " + ToHexString(bytes));
                int      stationNo = 0;
                int      pid       = 0;
                int      state     = 0;
                DateTime date      = DateTime.Now;
                parseDataAtt(bytes, ref stationNo, ref pid, ref state, ref date);
                //找出编号对应的站点
                SWS_DB.guangdai_station_link link = V88StationLink.SingleOrDefault(c => Int32.Parse(c.wsid) == stationNo);
                if (link == null)
                {
                    return;
                }

                SWSDataContext sws = new SWSDataContext(ConnectStringHelper.GetConnection(SysConfig.userProfile.DbAddress, link.db_name, SysConfig.userProfile.DbUserName, SysConfig.userProfile.DbPassword));
                updateStationLine(sws, (int)link.station_id);
                users user = findUserByPid(sws, pid);
                if (user == null)
                {
                    return;
                }
                country_attendance att = sws.country_attendance.Where(c => c.RFID == pid.ToString() && c.station_id == link.station_id && c.edate != null && DateTime.Now.AddHours(-1).CompareTo(c.edate) < 0).OrderByDescending(c => c.id).FirstOrDefault();
                if (att == null)
                {
                    att = new country_attendance();
                    if (user == null)
                    {
                        att.userid = 0;
                    }
                    else
                    {
                        att.userid = user.userid;
                    }
                    att.station_id = link.station_id;
                    att.sdate      = date;
                    att.edate      = date;
                    att.type       = "01";
                    att.remark     = "V88设备的考勤数据";
                    att.RFID       = pid.ToString();
                    sws.country_attendance.InsertOnSubmit(att);
                    sws.SubmitChanges();
                }
                else
                {
                    att.edate = date;
                    sws.SubmitChanges();
                }
            }
            catch (Exception ex)
            {
                LogMg.AddError(ex);
            }
        }
コード例 #30
0
ファイル: HD_DTU.cs プロジェクト: zhaobf1990/ControlServer
        /// <summary>
        /// 拆包
        /// </summary>
        /// <param name="socket"></param>
        /// <param name="pack"></param>
        /// <param name="packLen"></param>
        /// <param name="content"></param>
        /// <param name="conLen"></param>
        /// <param name="type"></param>
        /// <param name="tel"></param>
        /// <returns></returns>
        public static bool UnPack(byte[] pack, int packLen, ref byte[] content, ref int conLen, ref byte type, ref string tel)
        {
            try
            {
                int i;
                for (i = 0; i < packLen; i++)
                {
                    if (pack[i] == HD_DTU.HEAD)
                    {
                        break;
                    }
                }
                type = pack[i + 1];                   //类型
                if (type == HD_DTU.DTU_REGISTER_DATA) //注册数据拆包和
                {
                    //解析接收到的数据
                    int high   = pack[i + 2];      //高8位
                    int low    = pack[i + 3];      //低8位
                    int length = high * 256 + low; //从手机号码到最后的字节数

                    byte[] b_tel = new byte[11];
                    Buffer.BlockCopy(pack, i + 4, b_tel, 0, 11);
                    tel = Encoding.ASCII.GetString(b_tel);
                }
                else if (type == HD_DTU.DTU_User_Data)     //用户数据拆包
                {
                    //解析接收到的数据
                    int high   = pack[i + 2];      //高8位
                    int low    = pack[i + 3];      //低8位
                    int length = high * 256 + low; //从手机号码到最后的字节数

                    byte[] b_tel = new byte[11];
                    Buffer.BlockCopy(pack, i + 4, b_tel, 0, 11);
                    tel = Encoding.ASCII.GetString(b_tel);

                    conLen = length - 16;
                    Buffer.BlockCopy(pack, i + 4 + 11, content, 0, conLen);
                }
                else
                {
                    //日志
                    string str = "";
                    for (int j = 0; j < packLen; j++)
                    {
                        str += pack[j] + " ";
                    }
                    LogMg.AddDebug("收到宏电DTU未知类型的数据:" + str);
                }
            }
            catch (Exception ex)
            {
                LogMg.AddError(ex);
                return(false);
            }
            return(true);
        }