Пример #1
0
        void checknodeDown()
        {
            Class.NW_Device clsnode  = new Class.NW_Device();
            DataTable       dt       = clsnode.NW_Device_GetStatic();
            int             checkloi = 0;

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (dt.Rows[i]["Description"].ToString().Length > 3)
                {
                    if (dt.Rows[i]["Description"].ToString().IndexOf(',') > 0)
                    {
                        if (dt.Rows[i]["Value1"].ToString() == "0")
                        {
                            checkloi = 1;
                        }
                    }
                }
            }

            if (checkloi == 0)
            {
                NodeToMaps();
            }
            else
            {
                webControl.Navigate("http://127.0.0.1:100/nodewarning.html?" + DateTime.Now.Millisecond);
                while (webControl.ReadyState != WebBrowserReadyState.Complete)
                {
                    Application.DoEvents();
                    System.Threading.Thread.Sleep(50);
                }
                webControl.Refresh();
            }
        }
Пример #2
0
 private void btnAdd_Click(object sender, EventArgs e)
 {
     if (gridItemDetailNode.SelectedRowsCount > 0)
     {
         if (gridItemDetailNode.FocusedRowHandle > -1)
         {
             string          Node = gridItemDetailNode.GetFocusedRowCellValue(colNodeCode).ToString();
             Class.NW_Device cls  = new Class.NW_Device();
             for (int i = 0; i < Data.Rows.Count; i++)
             {
                 if (Data.Rows[i]["Checked"] != DBNull.Value)
                 {
                     if ((bool)Data.Rows[i]["Checked"])
                     {
                         cls.MacAddress  = Data.Rows[i]["MacAddress"].ToString();
                         cls.NodeCode    = Node;
                         cls.Description = "";
                         if (!cls.Insert())
                         {
                             MessageBox.Show("Không thêm được mac : " + cls.MacAddress);
                         }
                     }
                 }
             }
             MessageBox.Show(" Hoàn thành quá trình thực hiện thêm .!");
             this.Close();
         }
     }
 }
Пример #3
0
        void checknodeDown()
        {
            Class.NW_Device clsnode = new Class.NW_Device();
            DataTable dt = clsnode.NW_Device_GetStatic();
            int checkloi=0;
            for( int i=0;i<dt.Rows.Count;i++)
            {
                if (dt.Rows[i]["Description"].ToString().Length > 3)
                {
                    if (dt.Rows[i]["Description"].ToString().IndexOf(',') > 0)
                    {
                        if (dt.Rows[i]["Value1"].ToString() == "0")
                        {
                            checkloi = 1;
                        }
                    }
                }
            }

            if (checkloi == 0)
            {
                NodeToMaps();
            }
            else
            {
                webControl.Navigate("http://127.0.0.1:100/nodewarning.html?"+DateTime.Now.Millisecond);
                while (webControl.ReadyState != WebBrowserReadyState.Complete)
                {
                    Application.DoEvents();
                    System.Threading.Thread.Sleep(50);
                }
                webControl.Refresh();
            }
        }
Пример #4
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            Class.NW_Device cls = new Class.NW_Device();
            DataTable       dtt = cls.NW_Device_GetStatic();

            if (dtt.Rows.Count > 0)
            {
                int    dem = 0;
                string tb  = "Cảnh báo node mất tín hiệu: \r\n";
                for (int i = 0; i < dtt.Rows.Count; i++)
                {
                    if ((int)dtt.Rows[i]["Value1"] == 0)
                    {
                        tb += dtt.Rows[i]["NodeName"].ToString() + "\r\n";
                        dem++;
                    }
                }
                if (dem > 0)
                {
                    if (File.Exists(Application.StartupPath + @"/media/buzz.wav"))
                    {
                        System.Media.SoundPlayer player = new System.Media.SoundPlayer();

                        player.SoundLocation = Application.StartupPath + "/media/buzz.wav";
                        player.Play();
                    }
                    alertControl.Show(this, "Cảnh báo tín hiệu :", tb);
                }
            }
        }
Пример #5
0
 private void btnAdd_Click(object sender, EventArgs e)
 {
     if (gridItemDetailNode.SelectedRowsCount > 0)
     {
         if (gridItemDetailNode.FocusedRowHandle > -1)
         {
             string Node = gridItemDetailNode.GetFocusedRowCellValue(colNodeCode).ToString();
             Class.NW_Device cls = new Class.NW_Device();
             for (int i = 0; i < Data.Rows.Count; i++)
             {
                 if (Data.Rows[i]["Checked"] != DBNull.Value)
                 {
                     if ((bool)Data.Rows[i]["Checked"])
                     {
                         cls.MacAddress = Data.Rows[i]["MacAddress"].ToString();
                         cls.NodeCode = Node;
                         cls.Description = "";
                         if (!cls.Insert())
                         {
                             MessageBox.Show("Không thêm được mac : " + cls.MacAddress);
                         }
                     }
                 }
             }
             MessageBox.Show(" Hoàn thành quá trình thực hiện thêm .!");
             this.Close();
         }
     }
 }
Пример #6
0
        private void btnDel_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            int[] selectedRows = gridItemDetail.GetSelectedRows();
            if (selectedRows.Length > 1)
            {
                if (Class.App.ConfirmDeletionMulti() == DialogResult.No)
                {
                    return;
                }
                Class.NW_Device cls = new Class.NW_Device();
                for (int i = 0; i < selectedRows.Length; i++)
                {
                    int    rowHandle = selectedRows[i];
                    string mac       = "";
                    if (!gridItemDetail.IsGroupRow(rowHandle))
                    {
                        mac = gridItemDetail.GetRowCellValue(rowHandle, colMacAdress).ToString();
                    }

                    cls.MacAddress = mac;
                    if (cls.Delete())
                    {
                        // Class.App.DeleteSuccessfully(mac);
                    }
                    else
                    {
                        Class.App.DeleteNotSuccessfully();
                    }
                }
                MessageBox.Show(" Hoàn thành thao tác xóa !");
                NW_Device_GetByNodeCode();
            }
            else
            {
                int SelectedRow = gridItemDetail.FocusedRowHandle;
                if (SelectedRow >= 0)
                {
                    DataRow drow        = gridItemDetail.GetDataRow(SelectedRow);
                    string  _MacAddress = drow["MacAddress"].ToString();
                    if (Class.App.ConfirmDeletion() == DialogResult.No)
                    {
                        return;
                    }

                    Class.NW_Device cls = new Class.NW_Device();
                    cls.MacAddress = _MacAddress;
                    if (cls.Delete())
                    {
                        Class.App.DeleteSuccessfully();
                        NW_Device_GetByNodeCode();
                    }
                    else
                    {
                        Class.App.DeleteNotSuccessfully();
                    }
                }
            }
        }
Пример #7
0
 void NW_Device_GetList()
 {
     Class.NW_Device cls = new Class.NW_Device();
     dt = cls.NW_Device_GetList();
     gridItem.DataSource = dt;
     cls.MacAddress      = "";
     dtRe  = cls.NW_Device_GetByMac();
     dtPhy = cls.NW_Device_GetByMac();
 }
Пример #8
0
        private void btnDel_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            int[] selectedRows = gridItemDetail.GetSelectedRows();
            if (selectedRows.Length > 1)
            {
                if (Class.App.ConfirmDeletionMulti() == DialogResult.No)
                    return;
                Class.NW_Device cls = new Class.NW_Device();
                for (int i = 0; i < selectedRows.Length; i++)
                {
                    int rowHandle = selectedRows[i];
                    string mac="";
                    if (!gridItemDetail.IsGroupRow(rowHandle))
                    {
                        mac = gridItemDetail.GetRowCellValue(rowHandle, colMacAdress).ToString();
                    }

                    cls.MacAddress = mac;
                    if (cls.Delete())
                    {
                       // Class.App.DeleteSuccessfully(mac);
                    }
                    else
                    {
                        Class.App.DeleteNotSuccessfully();
                    }
                }
                MessageBox.Show(" Hoàn thành thao tác xóa !");
                NW_Device_GetByNodeCode();

            }
            else
            {
                int SelectedRow = gridItemDetail.FocusedRowHandle;
                if (SelectedRow >= 0)
                {
                    DataRow drow = gridItemDetail.GetDataRow(SelectedRow);
                    string _MacAddress = drow["MacAddress"].ToString();
                    if (Class.App.ConfirmDeletion() == DialogResult.No)
                        return;

                    Class.NW_Device cls = new Class.NW_Device();
                    cls.MacAddress = _MacAddress;
                    if (cls.Delete())
                    {
                        Class.App.DeleteSuccessfully();
                        NW_Device_GetByNodeCode();
                    }
                    else
                    {
                        Class.App.DeleteNotSuccessfully();
                    }
                }
            }
        }
Пример #9
0
        public void NW_Device_GetByNodeCode()
        {
            int SelectedRow = gridItemDetailNode.FocusedRowHandle;
             if (SelectedRow >= 0)
             {
                 DataRow drow = gridItemDetailNode.GetDataRow(SelectedRow);
                 string _NodeCode = drow["NodeCode"].ToString();

                 Class.NW_Device cls = new Class.NW_Device();
                 cls.NodeCode = _NodeCode;
                 DataTable dt = cls.NW_Device_GetByNodeCode();
                 gridItem.DataSource = dt;
             }
        }
Пример #10
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            if (txtCode.Text.Length < 1)
            {
                Class.App.InputNotAccess();
                return;
            }

            if (txtCode.Text.Length != 14)
            {
                MessageBox.Show("Địa chỉ Mac Address chưa đúng định dạng, Vui lòng nhập lại.!", "Cảnh Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            string[] kt = txtCode.Text.Split('.');
            if (kt.Length != 3)
            {
                MessageBox.Show("Địa chỉ Mac Address chưa đúng định dạng, Vui lòng nhập lại.!", "Cảnh Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            Class.NW_Device cls = new Class.NW_Device();
            cls.MacAddress  = txtCode.Text;
            cls.NodeCode    = _NodeCode;
            cls.Description = txtDescription.Text;
            if (txtCode.Enabled == true)
            {
                if (cls.Insert())
                {
                    Class.App.SaveSuccessfully();
                }
                else
                {
                    Class.App.SaveNotSuccessfully();
                }
            }
            //else
            //{
            //    if (cls.Update())
            //    {
            //        Class.App.SaveSuccessfully();
            //    }
            //    else
            //    {
            //        Class.App.SaveNotSuccessfully();
            //    }
            //}
            (this.Owner as frmDeviceList).NW_Device_GetByNodeCode();
            this.Close();
        }
Пример #11
0
        public void NW_Device_GetByNodeCode()
        {
            int SelectedRow = gridItemDetailNode.FocusedRowHandle;

            if (SelectedRow >= 0)
            {
                DataRow drow      = gridItemDetailNode.GetDataRow(SelectedRow);
                string  _NodeCode = drow["NodeCode"].ToString();

                Class.NW_Device cls = new Class.NW_Device();
                cls.NodeCode = _NodeCode;
                DataTable dt = cls.NW_Device_GetByNodeCode();
                gridItem.DataSource = dt;
            }
        }
Пример #12
0
        void LoadBieuDoNode()
        {
            Class.NW_Node   clsN     = new Class.NW_Node();
            Class.NW_Device clsDe    = new Class.NW_Device();
            DataTable       dtDevice = new DataTable();
            DataTable       dtNode   = clsN.NW_Node_GetList();

            dtNode.Columns.Add("TotalOn");
            dtNode.Columns.Add("TotalOff");
            int on  = 0;
            int off = 0;

            for (int i = 0; i < dtNode.Rows.Count; i++)
            {
                on             = 0; off = 0;
                clsDe.NodeCode = dtNode.Rows[i]["NodeCode"].ToString();
                dtDevice       = clsDe.NW_Device_GetByNodeCode();

                for (int j = 0; j < dtDevice.Rows.Count; j++)
                {
                    if (dtDevice.Rows[j]["Status"].ToString() == "online")
                    {
                        on++;
                    }
                    else
                    {
                        off++;
                    }
                }
                dtNode.Rows[i]["TotalOn"]  = on;
                dtNode.Rows[i]["TotalOff"] = off;
            }
            // load bieu do
            frmSignalChartDetail frm = new frmSignalChartDetail(dtNode);

            frm.ShowDialog();
        }
Пример #13
0
 private void btnUpdateNew_Click(object sender, EventArgs e)
 {
     if (txtCode.Text.Length < 1)
     {
         Class.App.InputNotAccess();
         return;
     }
     if (txtCode.Text.Length != 14)
     {
         MessageBox.Show("Địa chỉ Mac Address chưa đúng định dạng, Vui lòng nhập lại.!", "Cảnh Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         return;
     }
     string[] kt = txtCode.Text.Split('.');
     if (kt.Length != 3)
     {
         MessageBox.Show("Địa chỉ Mac Address chưa đúng định dạng, Vui lòng nhập lại.!", "Cảnh Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         return;
     }
     Class.NW_Device cls = new Class.NW_Device();
     cls.MacAddress = txtCode.Text;
     cls.NodeCode = _NodeCode;
     cls.Description = txtDescription.Text;
     if (txtCode.Enabled == true)
     {
         if (cls.Insert())
         {
             Class.App.SaveSuccessfully();
         }
         else
         {
             Class.App.SaveNotSuccessfully();
         }
     }
     (this.Owner as frmDeviceList).NW_Device_GetByNodeCode();
     txtCode.Text = "";
     txtDescription.Text = "";
 }
Пример #14
0
 void NW_Device_GetList()
 {
     Class.NW_Device cls = new Class.NW_Device();
     dt = cls.NW_Device_GetList();
     gridItem.DataSource = dt;
     cls.MacAddress = "";
     dtRe = cls.NW_Device_GetByMac();
     dtPhy = cls.NW_Device_GetByMac();
 }
Пример #15
0
        string updateNodeDown(string txt)
        {
            Class.NW_Device clsnode = new Class.NW_Device();
            DataTable dt = clsnode.NW_Device_GetStatic();
            string _list = "";
            string lat = "";
            string lng = "";
            string lat1 = "";
            string lng1 = "";
            string firstload = "";
            string listinfo = "";
            string path = "";
            string line="";
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (dt.Rows[i]["Description"].ToString().Length > 3)
                {
                    if (dt.Rows[i]["Description"].ToString().IndexOf(',') > 0)
                    {
                        if (dt.Rows[i]["Value1"].ToString() == "0")
                        {
                            lat = dt.Rows[i]["Description"].ToString().Substring(0, dt.Rows[i]["Description"].ToString().IndexOf(','));
                            lng = dt.Rows[i]["Description"].ToString().Substring(dt.Rows[i]["Description"].ToString().IndexOf(',') + 1);
                            _list += "" + dt.Rows[i]["NodeCode"].ToString() + ": {\n" +
                                        "center: { lat: "+lat+", lng: "+lng+" },\n"+
                                        "population: 2\n"+
                                         "} \n,";

                            firstload = "var first = new google.maps.LatLng("+lat+", "+lng+");";
                            listinfo += "var first = new google.maps.LatLng(" + lat + ", " + lng + ");\n"+
                                         " var coordInfoWindow = new google.maps.InfoWindow();\n"+
                                          "coordInfoWindow.setContent(createInfoWindowContent(first, map.getZoom(),'<span style=color:red><B>CẢNH BÁO MẤT TÍN HIỆU:</B></span><BR> NODE: " + dt.Rows[i]["NodeName"].ToString() + "<br>Online/Offline: " + dt.Rows[i]["Value1"].ToString() + "/" + dt.Rows[i]["Value2"].ToString() + " <br> LastSync: " + dt.Rows[i]["DateTime"].ToString()+ "'));\n" +
                                          "coordInfoWindow.setPosition(first);\n"+
                                          "coordInfoWindow.open(map);\n"+
                                          "map.addListener('zoom_changed', function() {\n"+
                                            "coordInfoWindow.setContent(createInfoWindowContent(first, map.getZoom(),'<span style=color:red><B>CẢNH BÁO MẤT TÍN HIỆU:</B></span><BR> NODE: " + dt.Rows[i]["NodeName"].ToString() + "<br>Online/Offline: " + dt.Rows[i]["Value1"].ToString() + "/" + dt.Rows[i]["Value2"].ToString() + " <br> LastSync: " + dt.Rows[i]["DateTime"].ToString() + "'));\n" +
                                           " coordInfoWindow.open(map);	\n"+
                                          "}); \n";
                            //kiem tra xem co Path ko
                            if (dt.Rows[i]["Path"].ToString().Length > 5)
                            {
                                string _path = dt.Rows[i]["Path"].ToString();
                                string[] catpath = _path.Split(';');

                                path+="var path"+dt.Rows[i]["NodeCode"].ToString()+" = [";

                                line += "var flightPath = new google.maps.Polygon({ \n" +
                                        "paths: path" + dt.Rows[i]["NodeCode"].ToString() + ",\n" +
                                        "strokeColor: '#FF00FF',\n" +
                                        "strokeOpacity: 0.8,\n" +
                                       " strokeWeight: 2,\n" +
                                        "fillColor: '#0033CC',\n" +
                                        "fillOpacity: 0.2,\n" +
                                        "strokeWeight: 2\n"+
                                      "});\n"+
                                      "flightPath.setMap(map);\n";

                                for (int j = 0; j < catpath.Length; j++)
                                {
                                    lat1 = catpath[j].ToString().Substring(0, catpath[j].ToString().IndexOf(','));
                                    lng1 = catpath[j].ToString().Substring(catpath[j].IndexOf(',') + 1);
                                    path += "\n{lat:" + lat1 + ",lng: " + lng1 + "} ,";
                                }
                                path = path.TrimEnd(',');
                                path += "\n];\n";
                            }
                        }
                    }
                }
            }
            /*  chicago: {
                    center: {lat: _lat , lng: _lng },
                    population: 0.01
                  }
             */
            //var first = new google.maps.LatLng(41.850, -87.650);
            /*
            var coordInfoWindow = new google.maps.InfoWindow();
              coordInfoWindow.setContent(createInfoWindowContent(first, map.getZoom(),'chao'));
              coordInfoWindow.setPosition(first);
              coordInfoWindow.open(map);

              map.addListener('zoom_changed', function() {
                coordInfoWindow.setContent(createInfoWindowContent(first, map.getZoom(),'chào'));
                coordInfoWindow.open(map);
              });
            */
            _list = _list.TrimEnd(',');
            txt = txt.Replace("_node", _list);
            txt = txt.Replace("_first", firstload);
            txt = txt.Replace("_addinfo", listinfo);
            if (path != "")
            {
                txt = txt.Replace("_addpath", path);
                txt = txt.Replace("_addline", line);
            }
            else
            {
                txt = txt.Replace("_addpath", "");
                txt = txt.Replace("_addline", "");
            }
            return txt;
        }
Пример #16
0
        void LoadBieuDoNode()
        {
            Class.NW_Node clsN= new Class.NW_Node();
            Class.NW_Device clsDe= new Class.NW_Device();
            DataTable dtDevice = new DataTable();
            DataTable dtNode = clsN.NW_Node_GetList();
            dtNode.Columns.Add("TotalOn");
            dtNode.Columns.Add("TotalOff");
            int on = 0;
            int off = 0;
            for (int i = 0; i < dtNode.Rows.Count; i++)
            {
                on = 0; off = 0;
                clsDe.NodeCode=dtNode.Rows[i]["NodeCode"].ToString();
                dtDevice = clsDe.NW_Device_GetByNodeCode();

                for (int j = 0; j < dtDevice.Rows.Count; j++)
                {
                    if (dtDevice.Rows[j]["Status"].ToString() == "online")
                        on++;
                    else
                        off++;
                }
                dtNode.Rows[i]["TotalOn"] = on;
                dtNode.Rows[i]["TotalOff"] = off;
            }
            // load bieu do
            frmSignalChartDetail frm = new frmSignalChartDetail(dtNode);
            frm.ShowDialog();
        }
Пример #17
0
 private void frmDeviceList_Request_Static_Load(object sender, EventArgs e)
 {
     Class.NW_Device cls = new Class.NW_Device();
     gridItem.DataSource = cls.NW_Device_GetStatic();
 }
Пример #18
0
        public void Start()
        {
            try
            {
                server.Prefixes.Add("http://127.0.0.1:100/");
                //  server.Prefixes.Add("http://localhost:100/");
                //server.Prefixes.Add(localhost);

                // server.Start();
                try
                {
                    server.Start(); //Throws Exception
                }
                catch (HttpListenerException ex)
                {
                    if (ex.Message.Contains("Access is denied"))
                    {
                        return;
                    }
                    else
                    {
                        throw;
                    }
                }
                Console.WriteLine("Listening...");

                while (true)
                {
                    HttpListenerContext context = server.GetContext();
                    HttpListenerResponse response = context.Response;

                    string page = context.Request.Url.ToString();

                    //page = context.Request.Url.LocalPath; ;
                    //   if (page == string.Empty)
                    if (page.Contains("nodewarning.html"))
                    {
                        TextReader tr = new StreamReader("nodewarning.txt");
                        string msg = tr.ReadToEnd();
                        // replae meta
                        msg = msg.Replace("_meta", "");
                        msg = msg.Replace("_loadfun", "");
                        msg = msg.Replace("_loadauto", "");
                        msg = updateNodeDown(msg);

                        byte[] buffer = Encoding.UTF8.GetBytes(msg);

                        response.ContentLength64 = buffer.Length;
                        Stream st = response.OutputStream;
                        st.Write(buffer, 0, buffer.Length);
                        st.Close();
                        tr.Close();
                    }
                    else if (page.Contains("node.html"))
                    {
                        TextReader tr = new StreamReader("node.txt");
                        string msg = tr.ReadToEnd();
                        msg = msg.Replace("_meta", "");
                        msg = msg.Replace("_loadfun", "");
                        msg = msg.Replace("_loadauto", "");
                        msg = updateNode(msg,"all");
                        //msg = updateLocation(lat, lng, detail, msg);

                        byte[] buffer = Encoding.UTF8.GetBytes(msg);

                        response.ContentLength64 = buffer.Length;
                        Stream st = response.OutputStream;
                        st.Write(buffer, 0, buffer.Length);
                        st.Close();
                        tr.Close();
                    }
                    else if (page.Contains("index.html"))
                    {
                        // kiem tra loi truoc khi tra ket qua ve
                        Class.NW_Device clsnode = new Class.NW_Device();
                        DataTable dt = clsnode.NW_Device_GetStatic();
                        int checkloi = 0;
                        for (int i = 0; i < dt.Rows.Count; i++)
                        {
                            if (dt.Rows[i]["Description"].ToString().Length > 3)
                            {
                                if (dt.Rows[i]["Description"].ToString().IndexOf(',') > 0)
                                {
                                    if (dt.Rows[i]["Value1"].ToString() == "0")
                                    {
                                        checkloi = 1;
                                    }
                                }
                            }
                        }

                        if (checkloi == 0)
                        {
                            TextReader tr = new StreamReader("node.txt");
                            string msg = tr.ReadToEnd();
                            // replae meta
                            msg = msg.Replace("_meta", "<meta http-equiv='refresh' content='120'>");
                            msg = msg.Replace("_loadfun", "onload='setInterval(function(){moveview()},10000);'");
                            msg = msg.Replace("_loadauto", "var binhthanh = {lat: 10.813224, lng: 106.700382};\n"+
                                                             "var binhthanh2 = {lat: 10.804199, lng: 106.696475};\n" +
                                                              "var binhthanh3 = {lat: 10.795778, lng: 106.710085};\n" +
                                                               "var binhthanh4 = {lat: 10.818256, lng: 106.723091};\n" +
                                                                "var govap = {lat: 10.847446, lng: 106.656770};\n" +
                                                                 "var govap2 = {lat: 10.838564, lng: 106.675493};\n" +
                                                            "var govap3 = {lat: 10.827463, lng: 106.687889};\n" +
                                                            "var thuduc = {lat: 10.857030, lng: 106.745129};\n"+
                                                            "var thuduc2 = {lat: 10.885092, lng: 106.721829};\n" +
                                                            "var thuduc3 = {lat: 10.882226, lng: 106.777018};\n" +
                                                           " function moveview(){\n"+
                                                           /*
                                                           "var rand=Math.floor(Math.random() * 3 + 1);\n"+
                                                                "if(rand==1)\n"+
                                                               "map.setCenter(binhthanh);\n"+
                                                                "if(rand==2)\n"+
                                                                "map.setCenter(govap);\n"+
                                                                "if(rand==3)\n"+
                                                               " map.setCenter(thuduc);\n"+
                                                                    */
                                                               "if(tomap==0){\n"+
                                                                "map.setCenter(binhthanh);\n"+
                                                                "tomap=1;\n"+
                                                                "}\n"+
                                                                "else if(tomap==1){\n"+
                                                                "map.setCenter(binhthanh2);\n" +
                                                                "tomap=2;\n"+
                                                                "}\n"+
                                                                "else if(tomap==2){\n"+
                                                                "map.setCenter(binhthanh3);\n" +
                                                                "tomap=3;\n"+
                                                                "}\n"+
                                                                "else if(tomap==3){\n" +
                                                                "map.setCenter(binhthanh4);\n" +
                                                                "tomap=4;\n" +
                                                                "}\n" +
                                                                "else if(tomap==4){\n" +
                                                                "map.setCenter(thuduc);\n" +
                                                                "tomap=5;\n" +
                                                                "}\n" +
                                                                "else if(tomap==5){\n" +
                                                                "map.setCenter(thuduc2);\n" +
                                                                "tomap=6;\n" +
                                                                "}\n" +
                                                                "else if(tomap==6){\n" +
                                                                "map.setCenter(thuduc3);\n" +
                                                                "tomap=7;\n" +
                                                                "}\n" +
                                                                 "else if(tomap==7){\n" +
                                                                "map.setCenter(govap);\n" +
                                                                "tomap=8;\n" +
                                                                "}\n" +
                                                                 "else if(tomap==8){\n" +
                                                                "map.setCenter(govap2);\n" +
                                                                "tomap=9;\n" +
                                                                "}\n" +
                                                                 "else if(tomap==9){\n" +
                                                                "map.setCenter(govap3);\n" +
                                                                "tomap=0;\n" +
                                                                "}\n" +
                                                            "};");
                            msg = updateNode(msg," ");

                            //msg = updateLocation(lat, lng, detail, msg);

                            byte[] buffer = Encoding.UTF8.GetBytes(msg);

                            response.ContentLength64 = buffer.Length;
                            Stream st = response.OutputStream;
                            st.Write(buffer, 0, buffer.Length);
                            st.Close();
                            tr.Close();
                        }
                        else  /// loi
                        {

                            TextReader tr = new StreamReader("nodewarning.txt");
                            string msg = tr.ReadToEnd();
                            // replae meta
                            msg = msg.Replace("_meta", "<meta http-equiv='refresh' content='120'>");
                            msg = updateNodeDown(msg);

                            byte[] buffer = Encoding.UTF8.GetBytes(msg);

                            response.ContentLength64 = buffer.Length;
                            Stream st = response.OutputStream;
                            st.Write(buffer, 0, buffer.Length);
                            st.Close();
                            tr.Close();

                        }

                    }
                    else
                    {
                        string msg = "Access Deny !";

                        byte[] buffer = Encoding.UTF8.GetBytes(msg);

                        response.ContentLength64 = buffer.Length;
                        Stream st = response.OutputStream;
                        st.Write(buffer, 0, buffer.Length);
                        st.Close();
                    }

                    context.Response.Close();
                }
            }
            catch { }
        }
Пример #19
0
 private void frmDeviceList_Request_Static_Load(object sender, EventArgs e)
 {
     Class.NW_Device cls = new Class.NW_Device();
     gridItem.DataSource = cls.NW_Device_GetStatic();
 }
Пример #20
0
        public void Start()
        {
            try
            {
                server.Prefixes.Add("http://127.0.0.1:100/");
                //  server.Prefixes.Add("http://localhost:100/");
                //server.Prefixes.Add(localhost);

                // server.Start();
                try
                {
                    server.Start(); //Throws Exception
                }
                catch (HttpListenerException ex)
                {
                    if (ex.Message.Contains("Access is denied"))
                    {
                        return;
                    }
                    else
                    {
                        throw;
                    }
                }
                Console.WriteLine("Listening...");

                while (true)
                {
                    HttpListenerContext  context  = server.GetContext();
                    HttpListenerResponse response = context.Response;

                    string page = context.Request.Url.ToString();

                    //page = context.Request.Url.LocalPath; ;
                    //   if (page == string.Empty)
                    if (page.Contains("nodewarning.html"))
                    {
                        TextReader tr  = new StreamReader("nodewarning.txt");
                        string     msg = tr.ReadToEnd();
                        // replae meta
                        msg = msg.Replace("_meta", "");
                        msg = msg.Replace("_loadfun", "");
                        msg = msg.Replace("_loadauto", "");
                        msg = updateNodeDown(msg);

                        byte[] buffer = Encoding.UTF8.GetBytes(msg);

                        response.ContentLength64 = buffer.Length;
                        Stream st = response.OutputStream;
                        st.Write(buffer, 0, buffer.Length);
                        st.Close();
                        tr.Close();
                    }
                    else if (page.Contains("node.html"))
                    {
                        TextReader tr  = new StreamReader("node.txt");
                        string     msg = tr.ReadToEnd();
                        msg = msg.Replace("_meta", "");
                        msg = msg.Replace("_loadfun", "");
                        msg = msg.Replace("_loadauto", "");
                        msg = updateNode(msg, "all");
                        //msg = updateLocation(lat, lng, detail, msg);

                        byte[] buffer = Encoding.UTF8.GetBytes(msg);

                        response.ContentLength64 = buffer.Length;
                        Stream st = response.OutputStream;
                        st.Write(buffer, 0, buffer.Length);
                        st.Close();
                        tr.Close();
                    }
                    else if (page.Contains("index.html"))
                    {
                        // kiem tra loi truoc khi tra ket qua ve
                        Class.NW_Device clsnode  = new Class.NW_Device();
                        DataTable       dt       = clsnode.NW_Device_GetStatic();
                        int             checkloi = 0;
                        for (int i = 0; i < dt.Rows.Count; i++)
                        {
                            if (dt.Rows[i]["Description"].ToString().Length > 3)
                            {
                                if (dt.Rows[i]["Description"].ToString().IndexOf(',') > 0)
                                {
                                    if (dt.Rows[i]["Value1"].ToString() == "0")
                                    {
                                        checkloi = 1;
                                    }
                                }
                            }
                        }

                        if (checkloi == 0)
                        {
                            TextReader tr  = new StreamReader("node.txt");
                            string     msg = tr.ReadToEnd();
                            // replae meta
                            msg = msg.Replace("_meta", "<meta http-equiv='refresh' content='120'>");
                            msg = msg.Replace("_loadfun", "onload='setInterval(function(){moveview()},10000);'");
                            msg = msg.Replace("_loadauto", "var binhthanh = {lat: 10.813224, lng: 106.700382};\n" +
                                              "var binhthanh2 = {lat: 10.804199, lng: 106.696475};\n" +
                                              "var binhthanh3 = {lat: 10.795778, lng: 106.710085};\n" +
                                              "var binhthanh4 = {lat: 10.818256, lng: 106.723091};\n" +
                                              "var govap = {lat: 10.847446, lng: 106.656770};\n" +
                                              "var govap2 = {lat: 10.838564, lng: 106.675493};\n" +
                                              "var govap3 = {lat: 10.827463, lng: 106.687889};\n" +
                                              "var thuduc = {lat: 10.857030, lng: 106.745129};\n" +
                                              "var thuduc2 = {lat: 10.885092, lng: 106.721829};\n" +
                                              "var thuduc3 = {lat: 10.882226, lng: 106.777018};\n" +
                                              " function moveview(){\n" +

                                              /*
                                               * "var rand=Math.floor(Math.random() * 3 + 1);\n"+
                                               *   "if(rand==1)\n"+
                                               *  "map.setCenter(binhthanh);\n"+
                                               *   "if(rand==2)\n"+
                                               *   "map.setCenter(govap);\n"+
                                               *   "if(rand==3)\n"+
                                               *  " map.setCenter(thuduc);\n"+
                                               */
                                              "if(tomap==0){\n" +
                                              "map.setCenter(binhthanh);\n" +
                                              "tomap=1;\n" +
                                              "}\n" +
                                              "else if(tomap==1){\n" +
                                              "map.setCenter(binhthanh2);\n" +
                                              "tomap=2;\n" +
                                              "}\n" +
                                              "else if(tomap==2){\n" +
                                              "map.setCenter(binhthanh3);\n" +
                                              "tomap=3;\n" +
                                              "}\n" +
                                              "else if(tomap==3){\n" +
                                              "map.setCenter(binhthanh4);\n" +
                                              "tomap=4;\n" +
                                              "}\n" +
                                              "else if(tomap==4){\n" +
                                              "map.setCenter(thuduc);\n" +
                                              "tomap=5;\n" +
                                              "}\n" +
                                              "else if(tomap==5){\n" +
                                              "map.setCenter(thuduc2);\n" +
                                              "tomap=6;\n" +
                                              "}\n" +
                                              "else if(tomap==6){\n" +
                                              "map.setCenter(thuduc3);\n" +
                                              "tomap=7;\n" +
                                              "}\n" +
                                              "else if(tomap==7){\n" +
                                              "map.setCenter(govap);\n" +
                                              "tomap=8;\n" +
                                              "}\n" +
                                              "else if(tomap==8){\n" +
                                              "map.setCenter(govap2);\n" +
                                              "tomap=9;\n" +
                                              "}\n" +
                                              "else if(tomap==9){\n" +
                                              "map.setCenter(govap3);\n" +
                                              "tomap=0;\n" +
                                              "}\n" +
                                              "};");
                            msg = updateNode(msg, " ");

                            //msg = updateLocation(lat, lng, detail, msg);

                            byte[] buffer = Encoding.UTF8.GetBytes(msg);

                            response.ContentLength64 = buffer.Length;
                            Stream st = response.OutputStream;
                            st.Write(buffer, 0, buffer.Length);
                            st.Close();
                            tr.Close();
                        }
                        else  /// loi
                        {
                            TextReader tr  = new StreamReader("nodewarning.txt");
                            string     msg = tr.ReadToEnd();
                            // replae meta
                            msg = msg.Replace("_meta", "<meta http-equiv='refresh' content='120'>");
                            msg = updateNodeDown(msg);

                            byte[] buffer = Encoding.UTF8.GetBytes(msg);

                            response.ContentLength64 = buffer.Length;
                            Stream st = response.OutputStream;
                            st.Write(buffer, 0, buffer.Length);
                            st.Close();
                            tr.Close();
                        }
                    }
                    else
                    {
                        string msg = "Access Deny !";

                        byte[] buffer = Encoding.UTF8.GetBytes(msg);

                        response.ContentLength64 = buffer.Length;
                        Stream st = response.OutputStream;
                        st.Write(buffer, 0, buffer.Length);
                        st.Close();
                    }

                    context.Response.Close();
                }
            }
            catch { }
        }
Пример #21
0
        string updateNodeDown(string txt)
        {
            Class.NW_Device clsnode   = new Class.NW_Device();
            DataTable       dt        = clsnode.NW_Device_GetStatic();
            string          _list     = "";
            string          lat       = "";
            string          lng       = "";
            string          lat1      = "";
            string          lng1      = "";
            string          firstload = "";
            string          listinfo  = "";
            string          path      = "";
            string          line      = "";

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (dt.Rows[i]["Description"].ToString().Length > 3)
                {
                    if (dt.Rows[i]["Description"].ToString().IndexOf(',') > 0)
                    {
                        if (dt.Rows[i]["Value1"].ToString() == "0")
                        {
                            lat    = dt.Rows[i]["Description"].ToString().Substring(0, dt.Rows[i]["Description"].ToString().IndexOf(','));
                            lng    = dt.Rows[i]["Description"].ToString().Substring(dt.Rows[i]["Description"].ToString().IndexOf(',') + 1);
                            _list += "" + dt.Rows[i]["NodeCode"].ToString() + ": {\n" +
                                     "center: { lat: " + lat + ", lng: " + lng + " },\n" +
                                     "population: 2\n" +
                                     "} \n,";

                            firstload = "var first = new google.maps.LatLng(" + lat + ", " + lng + ");";
                            listinfo += "var first = new google.maps.LatLng(" + lat + ", " + lng + ");\n" +
                                        " var coordInfoWindow = new google.maps.InfoWindow();\n" +
                                        "coordInfoWindow.setContent(createInfoWindowContent(first, map.getZoom(),'<span style=color:red><B>CẢNH BÁO MẤT TÍN HIỆU:</B></span><BR> NODE: " + dt.Rows[i]["NodeName"].ToString() + "<br>Online/Offline: " + dt.Rows[i]["Value1"].ToString() + "/" + dt.Rows[i]["Value2"].ToString() + " <br> LastSync: " + dt.Rows[i]["DateTime"].ToString() + "'));\n" +
                                        "coordInfoWindow.setPosition(first);\n" +
                                        "coordInfoWindow.open(map);\n" +
                                        "map.addListener('zoom_changed', function() {\n" +
                                        "coordInfoWindow.setContent(createInfoWindowContent(first, map.getZoom(),'<span style=color:red><B>CẢNH BÁO MẤT TÍN HIỆU:</B></span><BR> NODE: " + dt.Rows[i]["NodeName"].ToString() + "<br>Online/Offline: " + dt.Rows[i]["Value1"].ToString() + "/" + dt.Rows[i]["Value2"].ToString() + " <br> LastSync: " + dt.Rows[i]["DateTime"].ToString() + "'));\n" +
                                        " coordInfoWindow.open(map);	\n"+
                                        "}); \n";
                            //kiem tra xem co Path ko
                            if (dt.Rows[i]["Path"].ToString().Length > 5)
                            {
                                string   _path   = dt.Rows[i]["Path"].ToString();
                                string[] catpath = _path.Split(';');

                                path += "var path" + dt.Rows[i]["NodeCode"].ToString() + " = [";

                                line += "var flightPath = new google.maps.Polygon({ \n" +
                                        "paths: path" + dt.Rows[i]["NodeCode"].ToString() + ",\n" +
                                        "strokeColor: '#FF00FF',\n" +
                                        "strokeOpacity: 0.8,\n" +
                                        " strokeWeight: 2,\n" +
                                        "fillColor: '#0033CC',\n" +
                                        "fillOpacity: 0.2,\n" +
                                        "strokeWeight: 2\n" +
                                        "});\n" +
                                        "flightPath.setMap(map);\n";


                                for (int j = 0; j < catpath.Length; j++)
                                {
                                    lat1  = catpath[j].ToString().Substring(0, catpath[j].ToString().IndexOf(','));
                                    lng1  = catpath[j].ToString().Substring(catpath[j].IndexOf(',') + 1);
                                    path += "\n{lat:" + lat1 + ",lng: " + lng1 + "} ,";
                                }
                                path  = path.TrimEnd(',');
                                path += "\n];\n";
                            }
                        }
                    }
                }
            }

            /*  chicago: {
             *      center: {lat: _lat , lng: _lng },
             *      population: 0.01
             *    }
             */
            //var first = new google.maps.LatLng(41.850, -87.650);

            /*
             * var coordInfoWindow = new google.maps.InfoWindow();
             * coordInfoWindow.setContent(createInfoWindowContent(first, map.getZoom(),'chao'));
             * coordInfoWindow.setPosition(first);
             * coordInfoWindow.open(map);
             *
             * map.addListener('zoom_changed', function() {
             *  coordInfoWindow.setContent(createInfoWindowContent(first, map.getZoom(),'chào'));
             *  coordInfoWindow.open(map);
             * });
             */
            _list = _list.TrimEnd(',');
            txt   = txt.Replace("_node", _list);
            txt   = txt.Replace("_first", firstload);
            txt   = txt.Replace("_addinfo", listinfo);
            if (path != "")
            {
                txt = txt.Replace("_addpath", path);
                txt = txt.Replace("_addline", line);
            }
            else
            {
                txt = txt.Replace("_addpath", "");
                txt = txt.Replace("_addline", "");
            }
            return(txt);
        }
Пример #22
0
        private void timerMaps_Tick(object sender, EventArgs e)
        {
            try
            {
                 int Min = DateTime.Now.Minute;
                 if ( Min == 10 ||  Min == 30 ||  Min == 50)
                 {
                     timerMaps.Enabled = false;
                     btnConnect_Click(null, null);
                     Thread.Sleep(10);
                     if (Min == 10)
                     {
                         btnDeviceStatus_Click(null, null);
                     }
                     Thread.Sleep(10);
                     btnRemote_Click(null, null);
                     Thread.Sleep(10);
                     btnDisconnect_Click(null, null);
                     loadDevice();
                     gridItem.DataSource = dtDevice;
                     Class.NW_Device de = new Class.NW_Device();
                     // dung snmp

                     Waiting.ShowWaitForm();
                     Waiting.SetWaitFormDescription("Tiến trình lưu dữ liệu !");
                     for (int i = 0; i < dtDevice.Rows.Count; i++)
                     {
                         Waiting.SetWaitFormDescription("Tiến trình lưu dữ liệu ! (" + i.ToString() + ")");
                         de.MacAddress = dtDevice.Rows[i]["MacAddress"].ToString();
                         de.Value1 = dtDevice.Rows[i]["Value1"].ToString();
                         de.Value2 = dtDevice.Rows[i]["Value2"].ToString();
                         de.Value3 = dtDevice.Rows[i]["Value3"].ToString();
                         de.DateTime = (DateTime)dtDevice.Rows[i]["DateTime"];
                         de.Status = dtDevice.Rows[i]["Status"].ToString();
                         de.Update();
                     }

                     if (DateTime.Now.Hour == 3 && Min == 30)
                     {
                         btnGetSNRLow_Click(null, null);
                     }
                     Waiting.CloseWaitForm();

                     timerMaps.Enabled = true;
                 }
            }
            catch (Exception ex)
            {
                timerMaps.Enabled = true;
                Class.App.Log_WriteApp(ex.Message.ToString());
                btnDisconnect_Click(null, null);

                //timer10.Enabled = true;
            }
        }
Пример #23
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            Class.NW_Device cls = new Class.NW_Device();
                DataTable dtt = cls.NW_Device_GetStatic();
                if (dtt.Rows.Count > 0)
                {
                    int dem = 0;
                    string tb = "Cảnh báo node mất tín hiệu: \r\n";
                    for (int i = 0; i < dtt.Rows.Count; i++)
                    {
                        if ((int)dtt.Rows[i]["Value1"] == 0)
                        {
                            tb += dtt.Rows[i]["NodeName"].ToString() + "\r\n";
                            dem++;
                        }
                    }
                    if (dem > 0)
                    {
                        if (File.Exists(Application.StartupPath + @"/media/buzz.wav"))
                        {
                            System.Media.SoundPlayer player = new System.Media.SoundPlayer();

                            player.SoundLocation = Application.StartupPath + "/media/buzz.wav";
                            player.Play();
                        }
                        alertControl.Show(this, "Cảnh báo tín hiệu :", tb);
                    }

                }
        }
Пример #24
0
 void loadDevice()
 {
     dtDevice.Rows.Clear();
     Class.NW_Device dev = new Class.NW_Device();
     dtDevice = dev.NW_Device_GetList();
     DataRow[] result = null;
     string txt = "";
     for (int i = 0; i < dtDevice.Rows.Count; i++)
     {
         txt = dtDevice.Rows[i]["MacAddress"].ToString();
         result = dt.Select("MacAddress ='" + txt + "'");
         if (result.Length > 0)
         {
             foreach (DataRow row in result)
             {
                 dtDevice.Rows[i]["Status"] = row["Status"].ToString();
                 dtDevice.Rows[i]["Value1"] = row["Value1"].ToString();
                 dtDevice.Rows[i]["Value2"] = row["Value2"].ToString();
                 dtDevice.Rows[i]["Value3"] = row["Value3"].ToString();
                 dtDevice.Rows[i]["DateTime"] = (DateTime)row["DateTime"];
             }
         }
         else
         {
             dtDevice.Rows[i]["Status"] = "offline";
         }
     }
 }
Пример #25
0
 void NW_Device_GetList()
 {
     Class.NW_Device cls = new Class.NW_Device();
     cls.MacAddress = " ";
     dt = cls.NW_Device_GetByMac();
     dtPHY = cls.NW_Device_GetByMac();
     dtIP=cls.NW_Device_GetByMac();
     dtIPPublic = cls.NW_Device_GetByMac();
     dtTraffic = cls.NW_Device_GetByMac();
 }