public void insert(MessageInfo info)
 {
     DataTable dt = helper.getDs("select * from Logs_Data", "Logs_Data").Tables[0];
     DataRow dr = dt.NewRow();
     dr[0] = frmMain.IpAndName[info.Address];
     dr[1] = info.Allmessage;
     dr[2] = info.Time;
     dr[3] = info.Type;
     dt.Rows.Add(dr);
     OleDbDataAdapter da = helper.adapter("select * from Logs_Data");
     da.Update(dt);
 }
Exemplo n.º 2
0
        private void backgroundWorker2_DoWork(object sender, DoWorkEventArgs e)
        {
            string strMsg = formatcommand();//发送设防命令
            //将要发送的字符串 转成 utf8对应的字节数组

            //获得列表中 选中的KEY
            byte[] data = Encoding.GetEncoding("GBK").GetBytes(strMsg.Trim());
            if (client.SendAcy(listView1.CheckedItems[0].SubItems[1].Text, data))
            {
                MessageBox.Show("设置成功");
                MessageInfo info = new MessageInfo(strMsg, listView1.CheckedItems[0].SubItems[1].Text,"设置操作",DateTime.Now.ToString());
                insert.insert(info);
            }
            else
            {
                MessageBox.Show("设置失败");
            }
        }
Exemplo n.º 3
0
        private void backgroundWorker4_DoWork(object sender, DoWorkEventArgs e)
        {
            string strMsg = "+打开警报\r\n";//指令
            //将要发送的字符串 转成 utf8对应的字节数组

            //获得列表中 选中的KEY
            byte[] data = Encoding.GetEncoding("GBK").GetBytes(strMsg.Trim());
            string GJ = "-OK";
            if (client.SendAcy(listView1.CheckedItems[0].SubItems[1].Text, data, GJ))
            {
                MessageBox.Show("成功打开");
                strMsg = "[成功打开警报声音]";
                // MessageInfo info = new MessageInfo(strMsg, listView1.CheckedItems[0].SubItems[1].Text, "查询操作", DateTime.Now.ToString());
                //insert.insert(info);
            }
            else
            {
                MessageBox.Show("打开警报操作失败!");
                strMsg = "[打开警报失败!超时?]";
            }
            MessageInfo info = new MessageInfo(strMsg, listView1.CheckedItems[0].SubItems[1].Text, "查询操作", DateTime.Now.ToString());
            insert.insert(info);
        }
Exemplo n.º 4
0
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            string strMsg = "+查询主机\r\n";//指令
            //将要发送的字符串 转成 utf8对应的字节数组

            //获得列表中 选中的KEY
            byte[] data = Encoding.GetEncoding("GBK").GetBytes(strMsg.Trim());
            string GJ = "-OK";
            if (client.SendAcy(listView1.CheckedItems[0].SubItems[1].Text, data,GJ))
            {
                MessageBox.Show("查询成功");
                strMsg ="[查询成功-Query Success]";
               // MessageInfo info = new MessageInfo(strMsg, listView1.CheckedItems[0].SubItems[1].Text, "查询操作", DateTime.Now.ToString());
                //insert.insert(info);
            }
            else
            {
                MessageBox.Show("查询失败");
                strMsg = "[查询失败-Query Failure]";
            }
            MessageInfo info = new MessageInfo(strMsg, listView1.CheckedItems[0].SubItems[1].Text, "查询操作", DateTime.Now.ToString());
            insert.insert(info);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 用于判别返回结果
        /// </summary>
        /// <param name="command">返回结果的字符串</param>
        private void ContorlCommand(string command, string ip)
        {
            recflag = "";
            if (command.IndexOf("SHOW-2") != -1)
            {
                //MessageBox.Show(command);
                recflag = command;
                RecTimeout.Set();
                Show.ShwStuatsforView(frmMain.FormList, handle.QueryHandle(command), ip);
                //MessageInfo info = new MessageInfo(command, ip, "查询返回", DateTime.Now.ToString());
                //Database.insert(info);//写入数据库
            }
            else if (command.IndexOf("+主机设防") != -1)
            {
                MessageBox.Show("设防命令");
                //MessageInfo info = new MessageInfo(command, ip, "设防返回", DateTime.Now.ToString());
                //Database.insert(info);
            }
            else if (command.IndexOf("SHOW-6") != -1)
            {
                //MessageBox.Show("更新命令");
                Show.ShwStuatsforView(frmMain.FormList, handle.QueryHandle(command), ip);
                //MessageInfo info = new MessageInfo(command, ip, "更新返回", DateTime.Now.ToString());
                //Database.insert(info);
            }
            else if (command.IndexOf("SHOW-8[") != -1)
            {
                // MessageBox.Show("转发命令"
                command = "+" + command;
               string[] str= command.Split('[', ']');
               MessageInfo info = new MessageInfo(frmMain.Decode(str[1]), ip, "警报", DateTime.Now.ToString());//将转发记录转码后保存
                Database.insert(info);
                byte[] bytearray = Encoding.Unicode.GetBytes(command);
                foreach (string host in frmMain.HostIp)
                {
                    for (int i = 0; i < 3; i++)
                    {
                        if (SendAcy(host, bytearray))
                        {
                            MessageBox.Show("转发成功");
                            break;
                        }
                        else
                        {

                            continue;
                        }

                    }
                }

            }
            else if (command.IndexOf("SHOW-8-OK") != -1)
            {
                recflag = command;

                RecTimeout.Set();

            }
            else if (command.IndexOf("SHOW-1[") != -1)
            {
                recflag = command;

                RecTimeout.Set();
            }
        }
Exemplo n.º 6
0
        public void Testonline(object ListIp)
        {
            List<ClientInfo> list = (List<ClientInfo>)ListIp;
            while (true)
            {
                foreach (ClientInfo info in list)
                {
                    //Thread.Sleep(1000);
                    if (PingTest(info.Ip))
                    {
                        if (!FindIsExist(info.Ip)&&!IsApplyRetry[info.Ip])
                        {
                            IsApplyRetry[info.Ip] = true;

                            ParameterizedThreadStart pts = new ParameterizedThreadStart(Retry);
                            Thread thradRecMsg = new Thread(pts);
                            thradRecMsg.IsBackground = true;
                            thradRecMsg.Start(info);
                        }
                    }
                    else
                    {
                        if (FindIsExist(info.Ip)&&!IsApplyRetry[info.Ip])
                        {
                            int len = Findipname(frmMain.FormList,info.Ip);
                            FaiSong_Led(len, frmMain.FormList.Items[len].SubItems[3].Text, 0);
                            MessageInfo messageinfo = new MessageInfo("强行断线", info.Ip, "断网记录", DateTime.Now.ToString());//将转发记录转码后保存
                            Database.insert(messageinfo);
                            IsApplyRetry[info.Ip] = true;
                            ThreadPool[info.Ip].Abort();
                            ThreadPool.Remove(info.Ip);
                            dict[info.Ip].Socket.Close();
                            dict[info.Ip].Socket.Dispose();
                            dict.Remove(info.Ip);
                            ShowIpStauts(info.Ip, DisConnection);
                            MessageBox.Show(DisConnection);
                            ParameterizedThreadStart pts = new ParameterizedThreadStart(Retry);
                            Thread thradRecMsg = new Thread(pts);
                            thradRecMsg.IsBackground = true;
                            thradRecMsg.Start(info);
                        }
                        
                    }
                }
               

                

            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// 用于判别返回结果
        /// </summary>
        /// <param name="command">返回结果的字符串</param>
        private void ContorlCommand(object obj)
        {
           
            SocketInfo socketinfo=(SocketInfo)obj;
            string command = socketinfo.Command;
            string ip = socketinfo.Ip;
            Show.SetIpAndRec(command, ip);
            if (command.IndexOf("SHOW-2") != -1)
            {

               
                Show.ShwStuatsforView(frmMain.FormList, handle.QueryHandle(command), ip);
                //MessageInfo info = new MessageInfo(command, ip, "查询返回", DateTime.Now.ToString());
                //Database.insert(info);
                // Database.insert(info);//写入数据库

            }
            else if (command.IndexOf("+主机设防") != -1)
            {
               
                MessageInfo info = new MessageInfo(command, ip, "设防返回", DateTime.Now.ToString());
                Database.insert(info);
            }
            else if (command.IndexOf("SHOW-6") != -1)
            {

                Show.ShwStuatsforView(frmMain.FormList, handle.QueryHandle(command), ip);

            }
            //--------------------------------------------------------------
            else if (command.IndexOf("SHOW-9[") != -1)
            {
                DateTime dt = DateTime.Now;
                command = "+" + command;
                string[] str = command.Split('[', ']');
                MessageInfo info = new MessageInfo(frmMain.Decode(str[1]), ip, "警报", DateTime.Now.ToString());//将转发记录转码后保存
                Database.insert(info);

            }
            //--------------------------------------------------------------------------------
            else if (command.IndexOf("SHOW-8[") != -1)
            {
               
                DateTime dt = DateTime.Now;
                command = "+" + command;
                string[] str = command.Split('[', ']');
                MessageInfo info = new MessageInfo(frmMain.Decode(str[1]), ip, "警报", DateTime.Now.ToString());//将转发记录转码后保存
                Database.insert(info);
                //-------------------------------------------------------------向主机发数据--------------------------
                byte[] bytearray = Encoding.Unicode.GetBytes(command);
                foreach (string host in frmMain.HostIp)
                {
                    for (int i = 0; i < 3; i++)
                    {
                        string GJ = "-OK";

                        if (SendAcy(host, bytearray, GJ))
                        {
                            //MessageBox.Show("转发成功");
                            break;
                        }
                        else
                        {
                            Thread.Sleep(2000);
                            continue;
                        }

                    }
                }


            }
            else if (command.IndexOf("SWT-OK") != -1)
            {
                recflag = command;
                   DictRecoutObject[socketinfo.Ip].Set();

            }
            else if (command.IndexOf("REC-OK") != -1)
            {

                recflag = command;
                DictRecoutObject[socketinfo.Ip].Set();

            }
            else if (command.IndexOf("LedGengXin") != -1)
            {
                recflag = command;
                DictRecoutObject[socketinfo.Ip].Set();
                frmMain.fm.GengXin_OK();
                Thread.Sleep(1000);

            }
            else if (command.IndexOf("CHK-OK") != -1)
            {
                recflag = command;
                DictRecoutObject[socketinfo.Ip].Set();
            }
            else if (command.IndexOf("OAL-OK") != -1)
            {
                recflag = command;
                DictRecoutObject[socketinfo.Ip].Set();
            }
            else if (command.IndexOf("CAL-OK") != -1)
            {
                recflag = command;
                DictRecoutObject[socketinfo.Ip].Set();
            }
            else if (command.IndexOf("LED-OK") != -1)
            {
                recflag = command;
                DictRecoutObject[socketinfo.Ip].Set();
            }

        }