private void btapplythreshold_Click(object sender, System.EventArgs e)
 {
     try
     {
         if (txtTemThresh.Text != "" && txtHumiThresh.Text != "" && txtPhoneThresh.Text != "")
         {
             Database myDatabase = new Database();
             int id = cbSelectVan.SelectedIndex + 1;
             int a = myDatabase.setTempVan(id,float.Parse(txtTemThresh.Text));
             int b = myDatabase.setHumiVan(id,float.Parse(txtHumiThresh.Text));
             int c = myDatabase.setPhoneNumber(txtPhoneThresh.Text);
             if(a == 1 && b == 1 && c == 1)
             {
                 MessageBox.Show("Save successful", "Imformation");
             }
             else
             {
                 MessageBox.Show("Not successful","Imformation");
             }
         }
         else
         {
             MessageBox.Show("Not enough imformation", "Error");
         }
     }
     catch { }
 }
Ejemplo n.º 2
0
        //Draw sensor
        public void DrawSensor(string mac)
        {
            try
            {
                Database myDatabase = new Database();
                Bitmap icon_true;
                Bitmap icon_false;
#if ACTOR_BAOCHAY
                int pixel_x = Convert.ToInt32(myDatabase.getSensorBCPixel_x(mac));
                int pixel_y = Convert.ToInt32(myDatabase.getSensorBCPixel_y(mac));
                string status = myDatabase.getStatusSensorBC(mac);
#else
                int pixel_x = Convert.ToInt32(myDatabase.getSensorPixel_x(mac));
                int pixel_y = Convert.ToInt32(myDatabase.getSensorPixel_y(mac));
                string status = myDatabase.getStatusSensor(mac);
#endif
                icon_true = new Bitmap(path_icon_sensor_true);
                icon_false = new Bitmap(path_icon_sensor_false);
                
                if (status == "true" || status == "True")
                {
                    gr.DrawImage(icon_true, pixel_x, pixel_y);
                }
                else
                {
                    gr.DrawImage(icon_false, pixel_x, pixel_y);
                }
                gr.DrawString(mac, draw_font, draw_brush, pixel_x, pixel_y);
            }
            catch
            { }
        }
 private void btConnect_Click(object sender, EventArgs e)
 {
     try
     {
         Database myDatabase = new Database();
         int checkCom = comPort.OpenPort("COM2",19200,"None","One",8);
         comPort.OpenSerialPort2();
         if (checkCom == -1)
         {
             comPort.DisplayData("Connecting......", tbShow);
         }
         else
         {
             btConnect.Enabled = false;
             btSend.Enabled = true;
             cbnode.Enabled = true;
             cbMalenh.Enabled = true;
             btDisconnect.Enabled = true;
             comPort.DisplayData("(" + DateTime.Now + "): Da mo cong COM", tbShow);
         }
         comPort.ThreadRequest();
         comPort.ThreadSend();
     }
     catch
     {
     }
 }
Ejemplo n.º 4
0
 //lenh lay hinh anh
 private void btTakephoto_Click(object sender, System.EventArgs e)
 {
     try
     {
         Database myDatabase = new Database();
         int now = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second;
         InformationNode.timeDapUng.Remove(sensor.Mac);
         InformationNode.timeDapUng.Add(sensor.Mac, now);
         sensor.Mac = cbnodeImg.Text.Substring(7, 2);
         if (sensor.Mac[0] == '0')
         {
             sensor.Ip = myDatabase.getNetworkIpSensor(sensor.Mac);
         }
         else
         {
             sensor.Ip = myDatabase.getNetworkIpSensorBC(sensor.Mac);
         }
         sensor.Command = sensor.Ip + "444$";    //lenh chup anh o sensor.Ip
         byte[] commandbyte = comPort.ConvertTobyte(sensor.Command);
         comPort.DisplayData("(" + comPort.showTime() + "): Gui lenh chup anh!! (" + sensor.Mac + "):\r\n Ma lenh : " + commandbyte.ToString(), tbShow2);
         comPort.writeByteData(commandbyte);
     }
     catch
     {
         MessageBox.Show("Ban chua nhap thong tin node", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
     }
 }
Ejemplo n.º 5
0
        //****************************************************
        private void Emboard_Load(object sender,EventArgs e)
        {
            Database db = new Database();
            comPort.pic = pictureBox1;
            db.setAllFalse();
            txtmac.Hide();
            pnShow.Hide();
            btexit.Enabled = true;
            comPort.txtShowData = tbShow;
            comPort.TimerInit();
            comPort.Time_control = db.getTimeActor();
            comPort.Time_alarm = db.getTimeAlarm();
            db.setFalseBC();
            db.setValOff();
            db.setAllFalse();
#if ACTOR_BAOCHAY
            cbMalenh.Items.Clear();
            cbMalenh.Items.Add("Lay nhiet do, do am");
            for (int i = 1; i < 6; i++)
            {
                cbMalenh.Items.Add("Gui canh bao muc "+i);
            }
#else
            cbMalenh.Items.Clear();
            cbMalenh.Items.Add("Lay nhiet do, do am");
            for (int i = 1; i < 7; i++)
            {
                cbMalenh.Items.Add("Bat van so "+i);
            }
            cbMalenh.Items.Add("Bat tat ca cac van");
            for (int i = 1; i < 7; i++)
            {
                cbMalenh.Items.Add("Tat van so " + i);
            }
            cbMalenh.Items.Add("Tat tat ca cac van");
#endif
            try
                {
                    drawImage.pictureBox = pictureBox1;
                    drawImage.reload(drawImage.pictureBox);
                }
                catch
                {
                    MessageBox.Show("Khong the load ban do");
                }
        }
 public void TrangThaiNode(string mesg)
 {
     try
     {
         Database mydatabase = new Database();
         string ss = mesg.Substring(10, 2);
         switch (ss)
         {
             case "02":
                 DisplayData("(" + DateTime.Now + "):Canh bao chay tai node " + mesg.Substring(8, 2) +"(" + mesg.Substring(4, 4) + ") \r\n", tb);
                 //string command = CreateCommand(true, "B1", "V5");
                 //string command = "0000051$";
                 //byte[] com = ConvertTobyte(command);
                 //WriteData(com);
                 string SDT = mydatabase.getPhoneNumber();
                 string MAC = mesg.Substring(8, 2);//mydatabase.getMacSensor(mesg.Substring(4, 4));
                 AutoSendSMS(SDT, MAC);
                 int timenow = DateTime.Now.Hour*3600 + DateTime.Now.Minute*60 + DateTime.Now.Second;
                 timeDapung.Remove("V5");
                 timeDapung.Add("V5", timenow);
                 break;
             case "03":
                 DisplayData("(" + DateTime.Now + "):Het nang luong tai node " + mesg.Substring(8, 2) + "(" + mesg.Substring(4, 4) + ") \r\n", tb);
                 break;
             case "04":
                 DisplayData("(" + DateTime.Now + "): Phat hien xam nhap tai node " + mesg.Substring(8, 2) + "(" + mesg.Substring(4, 4) + ") \r\n", tb);
                 break;
         }
     }
     catch
     {}
 }
 private void cbSelectVan_SelectedIndexChanged(object sender, System.EventArgs e)
 {
     try
     {
     Database mydatabase = new Database();
     int id = cbSelectVan.SelectedIndex + 1;
     txtTemThresh.Text = mydatabase.getTempVan(id).ToString();
     txtHumiThresh.Text = mydatabase.getHumiVan(id).ToString();
     }
     catch{}
 }
Ejemplo n.º 8
0
        //Load ban do
        public void reload(PictureBox pic)
        {
            pic.Invoke(new EventHandler(delegate
            {
                try
                {
                    Database myDatabase = new Database();
                    Bitmap image = new Bitmap(path);
                    gr.DrawImage(image, 0, 0);
#if ACTOR_BAOCHAY
                    XmlNodeList node = (myDatabase.xml_bc).GetElementsByTagName("node");
#else
                    XmlNodeList node = (myDatabase.xml).GetElementsByTagName("node");
                    XmlNodeList val = (myDatabase.xml).GetElementsByTagName("val");
                    foreach (XmlNode valchild in val)
                    {
                        int id = Int32.Parse(valchild.Attributes["id"].Value);
                        DrawVan(id);
                    }
#endif

                    foreach (XmlNode nodechild in node)
                    {
                        string mac = nodechild.Attributes["mac"].Value;
                        if (mac == "00" || mac[0] == 'B')
                        {
                            DrawActor(mac);
                        }
                        else
                        {
                            DrawSensor(mac);
                        }
                    }
                    
                    pic.Image = bit;
                }
                catch
                {}
            }));
        }
Ejemplo n.º 9
0
 //Draw actor
 public void DrawActor(string mac)
 {
     try
     {
         Database myDatabase = new Database();
         Bitmap icon_true;
         Bitmap icon_false;
         int pixel_x = Convert.ToInt32(myDatabase.getActorPixel_x(mac));
         int pixel_y = Convert.ToInt32(myDatabase.getActorPixel_y(mac));
         icon_true = new Bitmap(path_icon_actor_true);
         icon_false = new Bitmap(path_icon_actor_false);
         string status = myDatabase.getStatusActor(mac);
         if (status == "true" || status == "True")
         {
             gr.DrawImage(icon_true, pixel_x, pixel_y);
         }
         else
         {
             gr.DrawImage(icon_false, pixel_x, pixel_y);
         }
         gr.DrawString(mac, draw_font, draw_brush, pixel_x, pixel_y);
     }
     catch
     {
     }
 }
Ejemplo n.º 10
0
 private void tattatca_Click(object sender, System.EventArgs e)
 {
     try
     {
         Database myDatabase = new Database();
         actor.Ip = myDatabase.getNetworkIpActor("00");
         actor.Command = actor.Ip + "150$";
         //DisplayData(MessageType.Incoming, "Command " + command + " sent at: " + DateTime.Now + "\r\n", tbShow);
         comPort.DisplayData("(" + DateTime.Now + "): Gui lenh dieu khien actor:\r\nMa lenh: " + actor.Command, tbShow);
         byte[] commandbyte = comPort.ConvertTobyte(actor.Command);
         comPort.writeByteData(commandbyte);
     }
     catch
     {
     }
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Su kien khi kich nut gui (send) lenh tren giao dien xuong actor
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btSend_Click(object sender, EventArgs e)
        {
            try
            {
                Database myDatabase = new Database();
                int timenow = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second;
               
                if (cbMalenh.SelectedIndex == 0)
                {
                    sensor.Mac = cbnode.Text.Substring(7, 2);
                    int now = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second;
                    ImformationNode.timeDapUng.Remove(sensor.Mac);
                    ImformationNode.timeDapUng.Add(sensor.Mac,now);
                    if (sensor.Mac[0] == '0')
                    {
                        sensor.Ip = myDatabase.getNetworkIpSensor(sensor.Mac);
                    }
                    else
                    {
                        sensor.Ip = myDatabase.getNetworkIpSensorBC(sensor.Mac);
                    }
                    sensor.Command = sensor.Ip + "000$";
                    comPort.DisplayData("(" + comPort.showTime()+ "): Gui lenh lay du lieu sensor (" + sensor.Mac + "):\r\n Ma lenh : " + sensor.Command, tbShow);
                    if (sensor.Command.Length == 8)
                    {
                        cbMalenh.SelectedIndex = -1;
                        cbnode.Items.Clear();
                        cbnode.Text = "";
                        byte[] commandbyte = comPort.ConvertTobyte(sensor.Command);
                        comPort.writeByteData(commandbyte);
                    }
                }
                else if (cbMalenh.SelectedIndex == 16)  //lenh lay dia chi sensor canh thiet bi android
                {
                    int now = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second;
                    ImformationNode.timeDapUng.Remove(sensor.Mac);
                    ImformationNode.timeDapUng.Add(sensor.Mac, now);
                    sensor.Mac = cbMalenh.SelectedItem.ToString();
                    //sensor.Command = "FFFF333$";
                    //byte[] commandbyte = comPort.ConvertTobyte(sensor.Command);   //ham khong dung de chuyen doi kieu lenh nay
                    byte[] commandbyte = {0xFF,0xFF,3,3,3};
                    comPort.DisplayData("(" + comPort.showTime() + "): Gui lenh dia chi MAC cac Node lan can Node (" + sensor.Mac + "):\r\n Ma lenh : " + commandbyte.ToString(), tbShow);
                    comPort.writeByteData(commandbyte);
                }
                else if (cbMalenh.SelectedIndex == 17)  //lenh lay hinh anh
                {
                    int now = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second;
                    ImformationNode.timeDapUng.Remove(sensor.Mac);
                    ImformationNode.timeDapUng.Add(sensor.Mac, now);
                    sensor.Mac = cbMalenh.SelectedItem.ToString();
                    //sensor.Command = "FFFF444$";
                    //byte[] commandbyte = comPort.ConvertTobyte(sensor.Command);   //ham khong dung de chuyen doi kieu lenh nay
                    byte[] commandbyte = { 0xFF, 0xFF, 4, 4, 4};
                    comPort.DisplayData("(" + comPort.showTime() + "): Gui lenh dia chi MAC cac Node lan can Node (" + sensor.Mac + "):\r\n Ma lenh : " + commandbyte.ToString(), tbShow);
                    comPort.writeByteData(commandbyte);
                }
                else
                {
                    actor.Ip = myDatabase.getNetworkIpActor(actor.Mac);
                    int now = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second;
                    ImformationNode.timeDapUng.Remove(actor.Mac);
                    ImformationNode.timeDapUng.Add(actor.Mac, now);
                    int id = cbMalenh.SelectedIndex;
                    if (id < 8)
                    {
                        if (id == 7)
                        {
                            actor.Command = actor.commandOnActor(15, "0000");
                            comPort.DisplayData("(" + comPort.showTime() + "): Bat tat ca cac van:\r\n Ma lenh : " + actor.Command, tbShow);
                        }
                        else
                        {
                            actor.Command = actor.commandOnActor(id, "0000");
#if ACTOR_BAOCHAY
                            comPort.DisplayData("(" + comPort.showTime() + "): Gui canh bao muc " + id + ":\r\n Ma lenh : " + actor.Command, tbShow);

#else
                            comPort.DisplayData("(" + comPort.showTime() + "): Bat van so " + id + ":\r\n Ma lenh : " + actor.Command, tbShow);
#endif

                        }
                    }
                    else
                    {
                        int vanoff = id - 7;
                        if (vanoff == 7)
                        {
                            actor.Command = actor.commandOffActor(15, "0000");
                            comPort.DisplayData("(" + comPort.showTime() + "): Tat tat ca cac van:\r\n Ma lenh : " + actor.Command, tbShow);
                        }
                        else
                        {
                            actor.Command = actor.commandOffActor(vanoff, "0000");
                            comPort.DisplayData("(" + comPort.showTime() + "): Tat van so " + vanoff + ":\r\n Ma lenh : " + actor.Command, tbShow);

                        }

                    }
                    if (actor.Command.Length == 8)
                    {
                        cbMalenh.SelectedIndex = -1;
                        cbnode.Items.Clear();
                        cbnode.Text = "";
                        byte[] commandbyte = comPort.ConvertTobyte(actor.Command);
                        comPort.writeByteData(commandbyte);
                    }
                }
            }
            catch
            {
                MessageBox.Show("Ban chua chon du thong tin o Commnad hoac Node", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
            }
        }
Ejemplo n.º 12
0
 public void Request()
 {
     try
     {
         string[] url = connection.Confix();
         string uriCom = url[4];
         while (true)
         {
             //comReadWeb = getdata_from_server(uriCom);
             comReadWeb = getDataServer(uriCom);
             if (comReadWeb != "")
             {
                 if(comReadWeb[0] == '#')
                 {
                     Database myDatabase = new Database();
                     int van = int.Parse(comReadWeb.Substring(1,1));
                     float temp = float.Parse(comReadWeb.Substring(2,2));
                     float humi = float.Parse(comReadWeb.Substring(4,2));
                     myDatabase.setHumiVan(van,humi);
                     myDatabase.setTempVan(van,temp);
                     DisplayData("(" + DateTime.Now + "): Cai dat nguong tu WEB:", tb);
                     DisplayData("Van so : " + van, tb);
                     DisplayData("Nhiet do : " + temp + "°C", tb);
                     DisplayData("Do am : " + humi+ "%", tb);
                 }
                 else
                 { 
                     DisplayData("(" + DateTime.Now + "): Lenh gui tu WEB:", tb);
                     DisplayData("Ma lenh :" + comReadWeb, tb);
                     byte[] commandWeb = ConvertTobyte(comReadWeb);
                     WriteData(commandWeb);
                 }
                 comReadWeb = "";
             }
             Thread.Sleep(1000);
         }
     }
     catch
     {
         //DisplayData(MessageType.Error, "Khong the lay du lieu tu WEB", tb);
     }
 }
Ejemplo n.º 13
0
        public void TuoiCayVal1(object sender, EventArgs e)
        {
            #if ACTOR_COOR
            for (int i = 1; i < 13; i++)
            {
                timePing[i]++;
                if (timePing[i] == 120)
                {
                    Database myDatabase = new Database();
                    byte[] bCommand = new byte[4];
                    string sHex = i.ToString("x").ToUpper();
                    sHex = "0" + sHex;
                    if (myDatabase.getStatusSensor(sHex) == "true" || myDatabase.getStatusSensor(sHex) == "True")
                    {
                        string sIp = myDatabase.getNetworkIpSensor(sHex);
                        int byte0 = int.Parse(sIp.Substring(0,2), System.Globalization.NumberStyles.HexNumber);
                        int byte1 = int.Parse(sIp.Substring(2,2), System.Globalization.NumberStyles.HexNumber);
                        bCommand[0] = (byte)byte0;
                        bCommand[1] = (byte)byte1;
                        bCommand[2] = (byte)255;
                        bCommand[3] = (byte)36;
                        DisplayData("Gui lenh ping node: "+ sHex,tb);
                        WriteData(bCommand);
                        checkPing[i] = true;
                    }
                    
                }

                if (checkPing[i] == true)
                {
                    countTime[i]++;
                    if (countTime[i] == 12)
                    {
                        Database myDatabase = new Database();
                        string sHex = i.ToString("x").ToUpper();
                        sHex = "0" + sHex;
                        myDatabase.setActiveSensor(sHex, false);
                        DisplayData("Sensor "+sHex+" khong con trong mang",tb);
                        countTime[i] = 0;
                        checkPing[i] = false;
                        reload(pictureBox);
                    }
                }
            }
            #endif
            count++;
            #if BC_COOR
            count_BC++;
            if (count_BC > Time_alarm * 12)
            {
                AutoSendCanhBao();
                count_BC = 0;
            }
            #endif
            #if ACTOR_COOR
            if (onofVal1 == true)
            {
                try
                {
                    time_count_val1++;
                    if(time_count_val1 > Time_control *12)
                    {
                        //gui lenh tat van 1
                        Database mydatabase = new Database();
                        string command = mydatabase.getNetworkIpActor("00");

                        command += "010$";
                        byte[] com = ConvertTobyte(command);
                        WriteData(com);

                        onofVal1 = false;
                    }
                }
                catch
                {
                    DisplayData("Khong gui duoc lenh tat van so 1 " + DateTime.Now, tb);
                }
            }
            if (onofVal2 == true)
            {
                try
                {
                    time_count_val2++;
                    if(time_count_val2 > Time_control *12)
                    {
                        //gui lenh tat van 2
                        Database mydatabase = new Database();
                        string command = mydatabase.getNetworkIpActor("00");

                        command += "020$";
                        byte[] com = ConvertTobyte(command);
                        WriteData(com);

                        onofVal2 = false;
                    }
                }
                catch
                {
                    DisplayData("Khong gui duoc lenh tat van so 2 " + DateTime.Now, tb);
                }
            }
            if (onofVal3 == true)
            {
                try
                {
                    time_count_val3++;
                    if(time_count_val3 > Time_control * 12)
                    {
                        //gui lenh tat van 3
                        Database mydatabase = new Database();
                        string command = mydatabase.getNetworkIpActor("00");

                        command += "030$";
                        byte[] com = ConvertTobyte(command);
                        WriteData(com);

                        onofVal3 = false;
                    }
                }
                catch
                {
                    DisplayData("Khong gui duoc lenh tat van so 3 " + DateTime.Now, tb);
                }
            }
            if (onofVal4 == true)
            {
                try
                {
                    time_count_val4++;
                    if(time_count_val4 > Time_control * 12)
                    {
                        //gui lenh tat van 4
                        Database mydatabase = new Database();
                        string command = mydatabase.getNetworkIpActor("00");

                        command += "040$";
                        byte[] com = ConvertTobyte(command);
                        WriteData(com);

                        onofVal4 = false;
                    }
                }
                catch
                {
                    DisplayData("Khong gui duoc lenh tat van so 4 " + DateTime.Now, tb);
                }
            }
            if (onofVal5 == true)
            {
                try
                {
                    time_count_val5++;
                    if(time_count_val5 > Time_control *12)
                    {
                        //gui lenh tat van 5
                        Database mydatabase = new Database();
                        string command = mydatabase.getNetworkIpActor("00");

                        command += "050$";
                        byte[] com = ConvertTobyte(command);
                        WriteData(com);

                        onofVal5 = false;
                    }
                }
                catch
                {
                    DisplayData("Khong gui duoc lenh tat van so 5 " + DateTime.Now, tb);
                }
            }
            if (onofVal6 == true)
            {
                try
                {
                    time_count_val6++;
                    if (time_count_val6 > Time_control * 12)
                    {
                        //gui lenh tat van 6
                        Database mydatabase = new Database();
                        string command = mydatabase.getNetworkIpActor("00");

                        command += "060$";
                        byte[] com = ConvertTobyte(command);
                        WriteData(com);

                        onofVal6 = false;
                    }
                }
                catch
                {
                    DisplayData("Khong gui duoc lenh tat van so 6 " + DateTime.Now, tb);
                }
            }
            #endif
        }
Ejemplo n.º 14
0
 public string CreateCommand(bool OnorOff, string mac,string Val)
 {
     try
     {
         Database mydatabase = new Database();
         string command = "";
         command = mydatabase.getNetworkIpActor(mac);
         if (OnorOff == true) //lenh bat cac van
         {
             switch (Val)
             {
                 case "V1":
                     command += "011$";
                     break;
                 case "V2":
                     command += "021$";
                     break;
                 case "V3":
                     command += "031$";
                     break;
                 case "V4":
                     command += "041$";
                     break;
                 case "V5":
                     command += "051$";
                     break;
                 case "V6":
                     command += "061$";
                     break;
             }
         }
         else        //gui lenh tat cac van
         {
             switch (Val)
             {
                 case "V1":
                     command += "010$";
                     break;
                 case "V2":
                     command += "020$";
                     break;
                 case "V3":
                     command += "030$";
                     break;
                 case "V4":
                     command += "040$";
                     break;
                 case "V5":
                     command += "050$";
                     break;
                 case "V6":
                     command += "060$";
                     break;
             }
         }
         return command;
     }
     catch
     {
         return "";
     }
 }
        /************************************************************************
        ** Code panel Threshold
        ************************************************************************/
        private void linkthreshold_Click(object sender, System.EventArgs e)
        {
            try
            {
                Database myDatabase = new Database();
                lbNode.Enabled = true;
                lbGeneral.Enabled = true;
                linkthreshold.Enabled = false;
                linksetup.Enabled = true;

                pnGeneral.Visible = false;
                pnNode.Visible = false;
                pnthreshold.Visible = true;
                pnsetup.Visible = false;

                panel2.Visible = true;
                panel2.Controls.Add(pnthreshold);
                pnthreshold.Location = new Point(0, 0);
                txtTemThresh.Text = myDatabase.getTempMax().ToString();
                txtHumiThresh.Text = myDatabase.getHumiMax().ToString();
                txtPhoneThresh.Text = myDatabase.getPhoneNumber().ToString();
                cbSmokeThresh.SelectedIndex = -1;
                cbSelectVan.Items.Clear();
                XmlNodeList van = (myDatabase.xml).GetElementsByTagName("val");
                foreach (XmlNode idVan in van)
                {
                    string str = idVan.Attributes["id"].Value;
                    cbSelectVan.Items.Add("Van "+str);
                }
                cbSelectVan.SelectedIndex = 0;
                txtTemThresh.Text = myDatabase.getTempVan(1).ToString();
                txtHumiThresh.Text = myDatabase.getHumiVan(1).ToString();
            }
            catch { }
        }
        /************************************************************
         * code panel setup
         * **********************************************************/
        private void linksetup_Click(object sender, System.EventArgs e)
        {
            try
            {
                Database mydatabase = new Database();
                lbNode.Enabled = true;
                lbGeneral.Enabled = true;
                linkthreshold.Enabled = true;
                linksetup.Enabled = false;

                pnGeneral.Visible = false;
                pnNode.Visible = false;
                pnthreshold.Visible = false;
                pnsetup.Visible = true;
                cbSetupFinish.Items.Clear();
                for (int i = 0; i < 24; i++)
                {
                    cbSetupBegin.Items.Add(i + " h");
                }
                cbSetupBegin.Text = mydatabase.getTimeStart().ToString() + " h";
                int index = mydatabase.getTimeStart() + 1;
                for (int i = index; i < 24; i++)
                {
                    cbSetupFinish.Items.Add(i + " h");
                }
                cbSetupFinish.Text = mydatabase.getTimeFinish().ToString() + " h";
            }
            catch { }
        }
        private void btApply_Click(object sender, EventArgs e)
        {
            try
            {
                if(cbMode.SelectedIndex == 0)
                {
                        comPort.DisplayData("("+DateTime.Now+")Sensor chuyen sang che do thuc ngu!", tbShow);
                        comPort.WriteData(confixcmd);
                        MessageBox.Show("Sent successful!", "Infomations");
                }
                if(cbMode.SelectedIndex == 1)
                {
                    if (cbPeriod.SelectedIndex != -1)
                    {
                            comPort.DisplayData("(" + DateTime.Now + ")Dieu chinh thoi gian gui du lieu dinh ky!", tbShow);
                            comPort.WriteData(confixcmd);
                            MessageBox.Show("Sent successful!", "Infomations");
                        }
                        else
                        {
                            MessageBox.Show("Not enough imformation","Error");
                        }
                 }
                if (cbMode.SelectedIndex == 2)
                {
                    if (cbtimecontrol.SelectedIndex != -1)
                    {
                        Database myDatabase = new Database();
                        int value = cbtimecontrol.SelectedIndex + 1;
                        int a = myDatabase.setTimeActor(value);
                        if(a == 1)
                            MessageBox.Show("Save successful!", "Infomations");
                        comPort.Time_control = myDatabase.getTimeActor();
                    }
                    else
                    {
                        MessageBox.Show("Not enough imformation", "Error");
                    }
                }
                if (cbMode.SelectedIndex == 3)
                {
                    if (cbSmokeThresh.SelectedIndex != -1)
                    {
                        comPort.WriteData(confixcmd);
                        comPort.DisplayData("(" + DateTime.Now + ")Thiet lap nong do nguong khoi", tbShow);
                        MessageBox.Show("Sent successful", "Imformation");
                    }
                    else
                    {
                        MessageBox.Show("Not enough imformation", "Error");
                    }
                }
                if (cbMode.SelectedIndex == 4)
                {
                    if (cbalarm.SelectedIndex != -1)
                    {
                        Database myDatabase = new Database();
                        int value = (cbalarm.SelectedIndex + 1)*5;
                        int a = myDatabase.setTimeAlarm(value);
                        if (a == 1)
                            MessageBox.Show("Save successful!", "Infomations");
                        comPort.Time_alarm = myDatabase.getTimeAlarm();
                    }
                    else
                    {
                        MessageBox.Show("Not enough imformation", "Error");
                    }
                }

            }
            catch { }
        }
Ejemplo n.º 18
0
        public void ThongTinActor(string mesg)
        {
            try
            {
                Database mydatabase = new Database();
                string ss1 = mesg.Substring(10, 2);
                string mac_actor = mesg.Substring(8, 2);
                int tt = int.Parse(ss1, System.Globalization.NumberStyles.HexNumber);
                int vanbom = tt - 128;
                if (tt > 128 && tt < 170)
                {
                    if (vanbom == 15)
                    {
                    #if USE_CANBANGTAI
                        if (mydatabase.getStateVal(1) == "off" || mydatabase.getStateVal(1) == "Off")
                        {
                            timeval1 = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second;
                        }
                        if (mydatabase.getStateVal(2) == "off" || mydatabase.getStateVal(2) == "Off")
                        {
                            timeval2 = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second;
                        }
                        if (mydatabase.getStateVal(3) == "off" || mydatabase.getStateVal(3) == "Off")
                        {
                            timeval3 = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second;
                        }
                        if (mydatabase.getStateVal(4) == "off" || mydatabase.getStateVal(4) == "Off")
                        {
                            timeval4 = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second;
                        }
                        if (mydatabase.getStateVal(5) == "off" || mydatabase.getStateVal(5) == "Off")
                        {
                            timeval5 = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second;
                        }
                    #endif
                        try
                        {
                            int timenow = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second;
                            int dapung = 0;
                            dapung = timenow - (int)timeDapung[mac_actor];
                            timeDapung.Remove(mac_actor);
                            DisplayData("(" + DateTime.Now + "):Tat ca cac van da bat! \r\n(Dap ung dieu khien bang tay: " + dapung + " giay)\r\n", tb);
                        }
                        catch
                        {
                            DisplayData("(" + DateTime.Now + "):Tat ca cac van da bat!\r\n", tb);
                        }
                         mydatabase.setValOn();
                    }
                    else
                    {
                        if (mac_actor == "00")
                        {
                        #if USE_CANBANGTAI
                            switch (vanbom)
                            {
                                case 1:
                                    if (mydatabase.getStateVal(1) == "off" || mydatabase.getStateVal(1) == "Off")
                                    {
                                        timeval1 = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second;
                                    }
                                    break;
                                case 2:
                                    if (mydatabase.getStateVal(2) == "off" || mydatabase.getStateVal(2) == "Off")
                                    {
                                        timeval2 = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second;
                                    }
                                    break;
                                case 3:
                                    if (mydatabase.getStateVal(3) == "off" || mydatabase.getStateVal(3) == "Off")
                                    {
                                        timeval3 = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second;
                                    }
                                    break;
                                case 4:
                                    if (mydatabase.getStateVal(4) == "off" || mydatabase.getStateVal(4) == "Off")
                                    {
                                        timeval4 = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second;
                                    }
                                        break;
                                case 5:
                                        if (mydatabase.getStateVal(5) == "off" || mydatabase.getStateVal(5) == "Off")
                                        {
                                            timeval5 = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second;
                                        }
                                        break;
                            }
                            #endif
                            int timenow = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second;
                            int dapung = 0;
                            try
                            {
                                dapung = timenow - (int)timeDapung[mac_actor];
                                timeDapung.Remove(mac_actor);
                                DisplayData("(" + DateTime.Now + "): Van so " + vanbom.ToString() + " da bat!\r\n(Dap ung dieu khien bang tay: " + dapung + " giay)\r\n", tb);
                            }
                            catch
                            {
                                try
                                {
                                    dapung = timenow - (int)timeDapung["V" + vanbom.ToString()];
                                    timeDapung.Remove("V" + vanbom.ToString());
                                    DisplayData("(" + DateTime.Now + "): Van so " + vanbom.ToString() + " da bat!\r\n(Dap ung dieu khien tu dong: " + dapung + " giay)\r\n", tb);

                                }
                                catch
                                {
                                    DisplayData("(" + DateTime.Now + "): Van so " + vanbom.ToString() + " da bat!\r\n", tb);
                                }
                            }
                            
                            mydatabase.setStateVal(vanbom, "on");
                        }
                        if (mac_actor == "B1")
                        {
                            //DisplayData(MessageType.Incoming, comread, tb);
                            int timenow = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second;
                            int dapung = 0;
                            try
                            {
                                dapung = timenow - (int)timeDapung[mac_actor];
                                timeDapung.Remove(mac_actor);
                                DisplayData("(" + DateTime.Now + "): Da bat canh bao muc " + vanbom.ToString() + "\r\n(Dap ung dieu khien bang tay: " + dapung + " giay)\r\n", tb);
                            }
                            catch
                            {
                                try
                                {
                                    dapung = timenow - (int)timeDapung["V5"];
                                    timeDapung.Remove("V5");
                                    DisplayData("(" + DateTime.Now + "): Da bat canh bao muc " + vanbom.ToString() + "\r\n(Dap ung phat hien chay: " + dapung + "giay)", tb);
                                }
                                catch 
                                {
                                    DisplayData("(" + DateTime.Now + "): Da bat canh bao muc " + vanbom.ToString() + "\r\n", tb);
                                }
                            }
                            
                        }
                    }
                    showVanOn(vanbom, mac_actor, mytext);
                }
                else
                {
                    if (tt > 64 && tt < 128)
                    {
                        int vantat = tt - 64;
                        if (vantat == 15)
                        {
                            DisplayData("(" + DateTime.Now + "): Tat ca cac van da tat tu dong!\r\n", tb);
                            mydatabase.setValOff();
                        }
                        else
                        {
                            DisplayData("(" + DateTime.Now + "): Van so " + vantat.ToString() + " da tat tu dong!\r\n", tb);
                            mydatabase.setStateVal(vantat, "off");
                        }
                    }
                    if(tt < 64)
                    {
                        if (tt == 15)
                        {
                        #if USE_CANBANGTAI
                            if (mydatabase.getStateVal(1) == "on")
                            {
                                int time1 = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second - timeval1;
                                time1 = time1 + mydatabase.getTimeVan(1);
                                mydatabase.setTimeVan(1, time1);
                            }
                            if (mydatabase.getStateVal(2) == "on")
                            {
                                int time2 = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second - timeval2;
                                time2 = time2 + mydatabase.getTimeVan(2);
                                mydatabase.setTimeVan(2, time2);
                            }
                            if (mydatabase.getStateVal(3) == "on")
                            {
                                int time3 = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second - timeval3;
                                time3 = time3 + mydatabase.getTimeVan(3);
                                mydatabase.setTimeVan(3, time3);
                            }
                            if (mydatabase.getStateVal(4) == "on")
                            {
                                int time4 = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second - timeval4;
                                time4 = time4 + mydatabase.getTimeVan(4);
                                mydatabase.setTimeVan(4, time4);
                            }
                            if (mydatabase.getStateVal(5) == "on")
                            {
                                int time5 = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second - timeval5;
                                time5 = time5 + mydatabase.getTimeVan(5);
                                mydatabase.setTimeVan(5, time5);
                            }
                         #endif
                            int timenow = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second;
                            int dapung = 0;
                            try
                            {
                                dapung = timenow - (int)timeDapung[mac_actor];
                                timeDapung.Remove(mac_actor);
                                DisplayData("(" + DateTime.Now + "): Tat ca cac van da tat!\r\n(Dap ung dieu khien bang tay: " + dapung + " giay)\r\n", tb);
                            }
                            catch
                            {
                                DisplayData("(" + DateTime.Now + "): Tat ca cac van da tat!\r\n", tb);
                            }
                            mydatabase.setValOff();
                        }
                        else
                        {
                         #if USE_CANBANGTAI
                            switch (tt)
                            {
                                case 1:
                                    if (mydatabase.getStateVal(1) == "on")
                                    {
                                        int time1 = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second - timeval1;
                                        time1 = time1 + mydatabase.getTimeVan(1);
                                        mydatabase.setTimeVan(1, time1);
                                    }
                                    break;
                                case 2:
                                    if (mydatabase.getStateVal(2) == "on")
                                    {
                                        int time2 = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second - timeval2;
                                        time2 = time2 + mydatabase.getTimeVan(2);
                                        mydatabase.setTimeVan(2, time2);
                                    }
                                    break;
                                case 3:
                                    if (mydatabase.getStateVal(3) == "on")
                                    {
                                        int time3 = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second - timeval3;
                                        time3 = time3 + mydatabase.getTimeVan(3);
                                        mydatabase.setTimeVan(3, time3);
                                    }
                                    break;
                                case 4:
                                    if (mydatabase.getStateVal(4) == "on")
                                    {
                                        int time4 = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second - timeval4;
                                        time4 = time4 + mydatabase.getTimeVan(4);
                                        mydatabase.setTimeVan(4, time4);
                                    }
                                    break;
                                case 5:
                                    if (mydatabase.getStateVal(5) == "on")
                                    {
                                        int time5 = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second - timeval5;
                                        time5 = time5 + mydatabase.getTimeVan(5);
                                        mydatabase.setTimeVan(5, time5);
                                    }
                                    break;
                            }
                            #endif
                            int timenow = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second;
                            int dapung = 0;
                            try
                            {
                                dapung = timenow - (int)timeDapung[mac_actor];
                                timeDapung.Remove(mac_actor);
                                DisplayData("(" + DateTime.Now + "): Van so " + tt.ToString() + " da tat!\r\n(Dap ung dieu khien bang tay: " + dapung + " giay)\r\n", tb);
                            }
                            catch {
                                DisplayData("(" + DateTime.Now + "): Van so " + tt.ToString() + " da tat\r\n", tb);
                            }
                            mydatabase.setStateVal(tt, "off");
                        }
                        showVanOff(tt, mytext);
                        if (tt == 1)
                        { onofVal1 = false; }
                        if (tt == 2)
                        { onofVal2 = false; }
                        if (tt == 3)
                        { onofVal3 = false; }
                        if (tt == 4)
                        { onofVal4 = false; }
                        if (tt == 5)
                        { onofVal5 = false; }
                        if (tt == 6)
                        { onofVal6 = false; }
                        if (tt == 15)
                        { onofVal1 = false; onofVal2 = false; onofVal3 = false; onofVal4 = false; onofVal5 = false; onofVal6 = false; }
                    }
                    }
            }
            catch
            {}
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Bat su kien lua chon combobox
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cbMalenh_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                int index_malenh = cbMalenh.SelectedIndex;
                if (index_malenh == 0)
                {
                    cbnode.Items.Clear();
                    Database my_Database = new Database();
                    //Hien thi danh sach sensor khu vuon lan
                    XmlNodeList nodeSensor = ((XmlElement)my_Database.sensor).GetElementsByTagName("node");
                    foreach (XmlNode node in nodeSensor)
                    {
                        if (node.Attributes["status"].Value == "true" || node.Attributes["status"].Value == "True")
                        {
                            string str = "Sensor " + node.Attributes["mac"].Value;
                            cbnode.Items.Add(str);
                        }
                    }
                    XmlNodeList nodeSensor_BC = ((XmlElement)my_Database.sensor_bc).GetElementsByTagName("node");
                    foreach (XmlNode node_BC in nodeSensor_BC)
                    {
                        if (node_BC.Attributes["status"].Value == "true" || node_BC.Attributes["status"].Value == "True")
                        {
                            string str = "Sensor " + node_BC.Attributes["mac"].Value;
                            cbnode.Items.Add(str);
                        }
                    }
                }
                else
                {
                    cbnode.Items.Clear();
                    Database my_Database = new Database();
                    XmlNodeList nodeActor = ((XmlElement)my_Database.actor).GetElementsByTagName("node");
                    foreach (XmlNode node in nodeActor)
                    {
                        if (node.Attributes["status"].Value == "true" || node.Attributes["status"].Value == "True")
                        {

                            string str = "";
#if ACTOR_BAOCHAY
                            str = "Actor bao chay";
#else
                            str = "Actor bom tuoi";
#endif
                            cbnode.Items.Add(str);
                            actor.Mac = "00";
                            break;
                            
                        }
                    }
                }
            }
            catch { }
        }
Ejemplo n.º 20
0
 /******************************************
  * Giai ma ban tin tra ve tu cong COM
  * Tham so dau vao: Chuoi du lieu nhan tu cong COM
  * Kieu tra ve : void
  * Dinh dang ban tin tra ve:
  * #JN:NNNN MM  Ban tin join mang
  * #AD:NNNN MM D1D2D3D4 D5D6D7D8 E1E2E3E4 Ban tin du lieu dinh ky
  * #RD:NNNN MM D1D2D3D4 D5D6D7D8 E1E2E3E4 Ban tin du lieu theo yeu cau
  * #VL:MM Ban tin thong bao ngu cua mot sensor
  * #OK:NNNN MM SS Ban tin thong bao trang thai actor
  * #SN: NNNN MM SS  Ban tin thong bao trang thai sensor
  * ***************************************/
 public void Converter(string mesg)
 {
     try
     {
         Database myDatabase = new Database();
         switch (mesg[1])
         {
             case 'J':
                 JoinMang(mesg);
                 reload(pictureBox);
                 break;
             case 'A':
                 // VD #AD: NNNN MM D1D2D3D4 D5D6D7D8 EEEE
                 string mac = mesg.Substring(8,2);
                 string status = "";
                 if (mac[0] == '0')
                 {
                     status = myDatabase.getStatusSensor(mac);
                 }
                 AutoData(mesg);
                 if (status != "true" && status != "True")
                 {
                     reload(pictureBox);
                 }
                 break;
             case 'S':
                 // VD: #SN: NNNN MM SS
                 TrangThaiNode(mesg);
                 break;
             case 'V':
                 try
                 {
                     DisplayData("(" + DateTime.Now + "): Sensor " + mesg.Substring(4, 2) + " da vao che do ngu\r\n", tb);
                     myDatabase.setActiveSensor(mesg.Substring(4, 2), false);
                     reload(pictureBox);
                 }
                 catch
                 {
                     DisplayData("Error", tb);
                 }
                 break;
             case 'O':
                 // VD: #OK:NNNN MM SS
                 ThongTinActor(mesg);
                 reload(pictureBox);
                 break;
             case 'R':
                 // VD #RD: NNNN MM D1D2D3D4 D5D6D7D8 EEEE
                 RequestData(mesg);
                 break;
             case 'P':
                 PingNode(mesg);
                 break;
         }
     }
     catch
     {
         DisplayData("Khong the giai ma du lieu", tb);
     }
 }
Ejemplo n.º 21
0
 private void tatvan_Click(object sender, System.EventArgs e)
 {
     try
     {
         Database myDatabase = new Database();
         actor.Ip = myDatabase.getNetworkIpActor("00");
         switch (id)
         {
             case 1:
                 actor.Command = actor.Ip + "010$";
                 break;
             case 2:
                 actor.Command = actor.Ip + "020$";
                 break;
             case 3:
                 actor.Command = actor.Ip + "030$";
                 break;
             case 4:
                 actor.Command = actor.Ip + "040$";
                 break;
             case 5:
                 actor.Command = actor.Ip + "050$";
                 break;
             case 6:
                 actor.Command = actor.Ip + "060$";
                 break;
              default:
                 actor.Command = actor.Ip + "010$";
                 break;
         }
         comPort.DisplayData("(" + DateTime.Now + "): Gui lenh dieu khien actor:\r\nMa lenh: " + actor.Command, tbShow);
         //commandbyte = comPort.ConvertTobyte(command);
         //comPort.WriteData(commandbyte);
         byte[] commandbyte = comPort.ConvertTobyte(actor.Command);
         comPort.writeByteData(commandbyte);
     }
     catch
     {
     }
 }
Ejemplo n.º 22
0
 //Ham boc tach thong so khi join mang
 public void JoinMang(string mesg)
 {
     try
     {
         Database mydatabase = new Database();
         string check = mesg.Substring(8, 2);
         int chck = int.Parse(check, System.Globalization.NumberStyles.HexNumber);
         if (chck < 160 && chck > 0)
         {
             DisplayData("(" + DateTime.Now + "): Thong tin gia nhap mang: \r\n Sensor " + mesg.Substring(4, 4) + " (" + check + ") " + " : \r\n Da gia nhap vao mang !!!\r\n", tb);
             if (check[0] == '3')
             {
                 if (mydatabase.CheckSensorBC(check) == "true")
                 {
                     mydatabase.setNetworkIpSensorBC(check, mesg.Substring(4, 4));
                     mydatabase.setStatusSensorBC(check, true);
                 }
                 else
                 {
                     mydatabase.setSensor_bc(check, mesg.Substring(4, 4), true);
                 }
             }
             else
             {
                 timePing[chck] = 0;
                 if (mydatabase.CheckSensor(check) == "true")
                 {
                     mydatabase.setNetworkIpSensor(check, mesg.Substring(4, 4));
                     mydatabase.setActiveSensor(check, true);
                 }
                 else
                 {
                     mydatabase.setNodeSensor(check, mesg.Substring(4, 4), true);
                 }
             }
         }
         if ((160 < chck && chck < 255) || chck == 0)
         {
             DisplayData("(" + DateTime.Now + "): Thong tin trang thai Actor: \r\n Actor " + mesg.Substring(4, 4) + " (" + check + ") " + " : \r\n Van hoat dong trong mang !!!\r\n", tb);
             if (mydatabase.CheckActor(check) == "true")
             {
                 mydatabase.setNetworkIpActor(check, mesg.Substring(4, 4));
                 mydatabase.setStatusActor(check, true);
             }
             else
             {
                 mydatabase.setNodeActor(check, mesg.Substring(4, 4), true);
             }
         }
     }
     catch
     {
         DisplayData("Error Join mang", tb);
     }
 }
Ejemplo n.º 23
0
 private void mnReset_Click(object sender, System.EventArgs e)
 {
     try
     {
         Database mydatabase = new Database();
         actor.Ip = mydatabase.getNetworkIpActor("00");
         actor.Command = actor.Ip + "031$";
         byte[] commandbyte = comPort.ConvertTobyte(actor.Command);
         comPort.writeByteData(commandbyte);
     }
     catch
     {
     }
 }
Ejemplo n.º 24
0
  //Hamf boc tach ban tin ping node mang
 public void PingNode(string mesg)
 {
     try
     {
         Database mydatabase = new Database();
         string check = mesg.Substring(8, 2);
         int chck = int.Parse(check, System.Globalization.NumberStyles.HexNumber);
         if (chck < 160 && chck > 0)
         {
             DisplayData("(" + DateTime.Now + "): Thong tin ping node mang: \r\n Sensor " + mesg.Substring(4, 4) + " (" + check + ") " + " : \r\n Van hoat dong trong mang !!!\r\n", tb);
             if (check[0] == '3')
             {
                  mydatabase.setNetworkIpSensorBC(check, mesg.Substring(4, 4));
                  mydatabase.setStatusSensorBC(check, true);
             }
             else
             {
                 timePing[chck] = 0;
                 checkPing[chck] = false;
                 countTime[chck] = 0;
                 mydatabase.setNetworkIpSensor(check, mesg.Substring(4, 4));
                 mydatabase.setActiveSensor(check, true);
             }
         }
     }
     catch
     {
         DisplayData("Error Ping node", tb);
     }
 }
Ejemplo n.º 25
0
        private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
        {
            try
            {
                Database myDatabase = new Database();
                bool check = false;
#if ACTOR_BAOCHAY
                XmlNodeList node = (myDatabase.xml_bc).GetElementsByTagName("node");
#else
                XmlNodeList node = (myDatabase.xml).GetElementsByTagName("node");
#endif
                foreach (XmlNode nodechild in node)
                {
                    pixel_x = Int32.Parse(nodechild.Attributes["pixel_x"].Value);
                    pixel_y = Int32.Parse(nodechild.Attributes["pixel_y"].Value);
                    actor.Mac = nodechild.Attributes["mac"].Value;
                    status = nodechild.Attributes["status"].Value;
                    if (e.Button == MouseButtons.Right && e.X > pixel_x && e.X < pixel_x + WIDTH && e.Y > pixel_y && e.Y < pixel_y + HEIGHT)
                    {
                        if (actor.Mac == "00")
                        {
                            if (status == "true" || status == "True")
                            {
                                battatca.Enabled = true;
                                MNstatusA.Enabled = true;
                                tattatca.Enabled = true;
                            }
                            else
                            {
                                battatca.Enabled = false;
                                MNstatusA.Enabled = false;
                                tattatca.Enabled = false;
                            }
                            MNstatusA.Text = "Trang thai : " + nodechild.Attributes["status"].Value;
                            ctMenuActor.Show(pictureBox1, new Point(e.X, e.Y));
                        }
                        else if (actor.Mac[0] == 'B')
                        {
                            if (status == "true" || status == "True")
                            {
                                mnReset.Enabled = true;
                            }
                            else
                            {
                                mnReset.Enabled = false;
                            }
                            ctxMenuReset.Show(pictureBox1, new Point(e.X, e.Y));
                        }
                        else
                        {
                            sensor.Ip = nodechild.Attributes["network_ip"].Value;
                            MNstatusS.Text = "Trang thai: " + nodechild.Attributes["status"].Value;
                            if (status == "true" || status == "True")
                            {
                                laydulieu.Enabled = true;
                                MNstatusS.Enabled = true;
                                menuTemp.Enabled = true;
                                menuHumi.Enabled = true;
                                menuTemp.Text = "Nhiet do: " + nodechild.Attributes["temperature"].Value + "°C";
                                menuHumi.Text = "Do am: " + nodechild.Attributes["humidity"].Value + "%";
                            }
                            else
                            {
                                menuTemp.Text = "Nhiet do:  0°C";
                                menuHumi.Text = "Do am: 0%";
                                laydulieu.Enabled = false;
                                MNstatusS.Enabled = false;
                                menuTemp.Enabled = false;
                                menuHumi.Enabled = false;
                            }
                            ctMenuSensor.Show(pictureBox1, new Point(e.X, e.Y));
                        }
                        check = true;
                        break;
                    }
                }
                if (!check)
                {
#if ACTOR_BAOCHAY
#else
                    XmlNodeList val = (myDatabase.xml).GetElementsByTagName("val");
                    status = myDatabase.getStatusActor("00");
                    foreach (XmlNode valchild in val)
                    {
                        pixel_x = Int32.Parse(valchild.Attributes["pixel_x"].Value);
                        pixel_y = Int32.Parse(valchild.Attributes["pixel_y"].Value);
                        if (e.Button == MouseButtons.Right && e.X > pixel_x && e.X < pixel_x + WIDTH && e.Y > pixel_y && e.Y < pixel_y + HEIGHT)
                        {
                            if (status == "true" || status == "True")
                            {
                                batvan.Enabled = true;
                                tatvan.Enabled = true;
                                MNstatusV.Enabled = true;
                            }
                            else
                            {
                                batvan.Enabled = false;
                                tatvan.Enabled = false;
                                MNstatusV.Enabled = false;
                            }
                            id = Int32.Parse(valchild.Attributes["id"].Value);
                            MNstatusV.Text = "Trang thai : " + valchild.Attributes["state"].Value;
                            ctMenuVan.Show(pictureBox1, new Point(e.X, e.Y));
                            break;
                        }
                    }
#endif
                }
            }
            catch { }
        }
Ejemplo n.º 26
0
 //Ham boc tach du lieu khi nhan du lieu dinh ky
 public void AutoData(string mesg)
 {
     try
     {
         Database mydatabase = new Database();
         string mac = mesg.Substring(8, 2);
         DataSensor(mesg, ref temperature, ref humidity, ref energy);
         DisplayData("(" + DateTime.Now + "): Du lieu dinh ky :\r\n Sensor " + mesg.Substring(4, 4) + "(" + mac + "): \r\n     Nhiet do: " + Temperature + "\r\n     Do am: " + Humidity + "\r\n     Nang luong : " + Energy + "\r\n", tb);
         string time = DateTime.Now.ToString();
         if (mac[0] == '3')
         {
             if (mydatabase.CheckSensorBC(mac) == "true")
             {
                 mydatabase.setNetworkIpSensorBC(mac, mesg.Substring(4, 4));
                 mydatabase.setStatusSensorBC(mac, true);
             }
             else
             {
                 mydatabase.setSensor_bc(mac, mesg.Substring(4, 4), true);
             }
             mydatabase.SaveDataDB(Temperature, Humidity);
         }
         else
         {
             int iIndex = int.Parse(mac,System.Globalization.NumberStyles.HexNumber);
             timePing[iIndex] = 0;
             if (mydatabase.CheckSensor(mac) == "true")
             {
                 mydatabase.setNetworkIpSensor(mac, mesg.Substring(4, 4));
                 mydatabase.setActiveSensor(mac, true);
             }
             else
             {
                 mydatabase.setNodeSensor(mac, mesg.Substring(4, 4), true);
             }
             string Val = mydatabase.getVanSensor(mac);
             int van = Int32.Parse(Val.Substring(1,1));
             float tempmax = mydatabase.getTempVan(van);
             float humimax = mydatabase.getHumiVan(van);
             bool test = ((Temperature > tempmax) && (Humidity < humimax));
             if (test) //Dieu kien thoa man
             {
             if (DateTime.Now.Hour >= mydatabase.getTimeStart() && DateTime.Now.Hour < mydatabase.getTimeFinish())
              {
              #if USE_CANBANGTAI
                 
                  DisplayData("Thoa man dieu kien bat van (" + mydatabase.getTimeStart() + " h - " + mydatabase.getTimeFinish() + " h)", tb);
                 if(Val == "V6")
                 {
                     DisplayData("Thoa man dieu kien bat van 6 (" + mydatabase.getTimeStart() + " h - " + mydatabase.getTimeFinish() + " h)", tb);
                     AutoBatVan(Val, mesg);
                 }
                 else if (Val == "V5")
                 {
                     int tvan4 = mydatabase.getTimeVan(4);
                     int tvan5 = mydatabase.getTimeVan(5);
                     if (tvan4 > 60)
                     {
                         int tv4phut = tvan4 / 60;
                         int tv4giay = tvan4 - tv4phut * 60;
                         DisplayData("Thoi gian da bat van 4 la:" + tv4phut + " phut "+ tv4giay + " giay", tb);
                     }
                     else
                     {
                         DisplayData("Thoi gian da bat van 4 la:" + tvan4 + " giay", tb);
                     }
                     if (tvan5 > 60)
                     {
                         int tv5phut = tvan5 / 60;
                         int tv5giay = tvan5 - tv5phut * 60;
                         DisplayData("Thoi gian da bat van 5 la:" + tv5phut + " phut " + tv5giay + " giay", tb);
                     }
                     else
                     {
                         DisplayData("Thoi gian da bat van 5 la:" + tvan5 + " giay", tb);
                     }
                     if (tvan4 > tvan5)
                     {
                         DisplayData("Quyet dinh ban van 5:", tb);
                         AutoBatVan("V5", mesg);
                     }
                     else
                     {
                         DisplayData("Quyet dinh ban van 4:", tb);
                         AutoBatVan("V4", mesg);
                         Val = "V4";
                     }
                 }
                 else if (Val == "V1")
                 {
                     int tvan1 = mydatabase.getTimeVan(1);
                     int tvan2 = mydatabase.getTimeVan(2);
                     if (tvan1 > 60)
                     {
                         int tv1phut = tvan1 / 60;
                         int tv1giay = tvan1 - tv1phut * 60;
                         DisplayData("Thoi gian da bat van 1 la:" + tv1phut + " phut " + tv1giay + " giay", tb);
                     }
                     else
                     {
                         DisplayData("Thoi gian da bat van 1 la:" + tvan1 + " giay", tb);
                     }
                     if (tvan2 > 60)
                     {
                         int tv2phut = tvan2 / 60;
                         int tv2giay = tvan2 - tv2phut * 60;
                         DisplayData("Thoi gian da bat van 2 la:" + tv2phut + " phut " + tv2giay + " giay", tb);
                     }
                     else
                     {
                         DisplayData("Thoi gian da bat van 2 la:" + tvan2 + " giay", tb);
                     }
                     if (tvan1 > tvan2)
                     {
                         DisplayData("Quyet dinh ban van 2:", tb);
                         AutoBatVan("V2", mesg);
                         Val = "V2";
                     }
                     else
                     {
                         DisplayData("Quyet dinh ban van 1:", tb);
                         AutoBatVan("V1", mesg);
                     }
                 }
                 else
                 {
                     string val = Val.Substring(1,1);
                     //int van = int.Parse(val);
                     int vantruoc = van - 1;
                     int vansau = van + 1;
                     int timevan = mydatabase.getTimeVan(van);
                     int timevanTruoc = mydatabase.getTimeVan(vantruoc);
                     int timevanSau = mydatabase.getTimeVan(vansau);
                     if (timevan > 60)
                     {
                         int tvphut = timevan / 60;
                         int tvgiay = timevan - tvphut * 60;
                         DisplayData("Thoi gian da bat van "+van+" la:" + tvphut + " phut " + tvgiay + " giay", tb);
                     }
                     else
                     {
                         DisplayData("Thoi gian da bat van " + van+" la:" + timevan + " giay", tb);
                     }
                     if (timevanTruoc > 60)
                     {
                         int tvTphut = timevanTruoc / 60;
                         int tvTgiay = timevanTruoc - tvTphut * 60;
                         DisplayData("Thoi gian da bat van " + vantruoc + " la:" + tvTphut + " phut " + tvTgiay + " giay", tb);
                     }
                     else
                     {
                         DisplayData("Thoi gian da bat van "+ vantruoc +" la:" + timevanTruoc + " giay", tb);
                     }
                     if (timevanSau > 60)
                     {
                         int tvSphut = timevanSau / 60;
                         int tvSgiay = timevanSau - tvSphut * 60;
                         DisplayData("Thoi gian da bat van " + vansau + " la:" + tvSphut + " phut " + tvSgiay + " giay", tb);
                     }
                     else
                     {
                         DisplayData("Thoi gian da bat van " + vansau + " la:" + timevanSau + " giay", tb);
                     }
                     if(timevan > timevanTruoc)
                     {
                         if(timevanTruoc > timevanSau)
                         {
                             DisplayData("Quyet dinh bat van"+vansau+":",tb);
                             AutoBatVan("V"+vansau,mesg);
                             Val = "V" + vansau;
                         }
                         else
                         {
                             DisplayData("Quyet dinh bat van" + vantruoc + ":", tb);
                             AutoBatVan("V" + vantruoc, mesg);
                             Val = "V" + vantruoc;
                         }
                     }
                     else
                     {
                         if (timevan > timevanSau)
                         {
                             DisplayData("Quyet dinh bat van" + vansau + ":", tb);
                             AutoBatVan("V" + vansau, mesg);
                             Val = "V" + vansau;
                         }
                         else
                         {
                             DisplayData("Quyet dinh bat van" + van + ":", tb);
                             AutoBatVan("V" + van, mesg);
                             Val = "V" + van;
                         }
                     }
                 }
                 int timenow = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second - 1;
                 timeDapung.Remove(Val);
                 timeDapung.Add(Val, timenow);
              #endif
              #if NO_CANBANGTAI
                 DisplayData("Thoa man dieu kien bat van "+id+" (" + mydatabase.getTimeStart() + " h - " + mydatabase.getTimeFinish() + " h)", tb);
                 AutoBatVan(Val, mesg);
             #endif
              }
              else
              {
                    DisplayData("Khong phai khoang thoi gian bat bom (" + mydatabase.getTimeStart() + " h - "+mydatabase.getTimeFinish()+" h)",tb);
              }
             }
         }
     }
     catch
     { }
 }
Ejemplo n.º 27
0
 //Draw van
 public void DrawVan(int id)
 {
     try
     {
         Database myDatabase = new Database();
         Bitmap icon_on;
         Bitmap icon_off;
         int pixel_x = Convert.ToInt32(myDatabase.getValPixel_x(id));
         int pixel_y = Convert.ToInt32(myDatabase.getValPixel_y(id));
         icon_on = new Bitmap(path_icon_val_on);
         icon_off = new Bitmap(path_icon_val_off);
         string status = myDatabase.getStateVal(id);
         if (status == "on")
         {
             gr.DrawImage(icon_on, pixel_x, pixel_y);
         }
         else
         {
             gr.DrawImage(icon_off, pixel_x, pixel_y);
         }
         gr.DrawString("V" + id, draw_font, draw_brush, pixel_x, pixel_y);
     }
     catch
     { }
 }
Ejemplo n.º 28
0
 public void AutoSendCanhBao()
 {
     try
     {
         Database mydatabase = new Database();
         float nhietdotb = mydatabase.SumTemp();
         float doamtb = mydatabase.SumHumi();
             float level = doamtb / (float)20 - (float)(27 - nhietdotb) / (float)10;
             if (level > 4)
             {
                 string command = CreateCommand(true,"B1","V4");
                 byte[] com1 = ConvertTobyte(command);
                 WriteData(com1);
                 mydatabase.DeleteData();
                 DisplayData("(" + DateTime.Now + "): Tu dong gui canh bao muc 4\r\n", tb);
             }
             if ((2.5 < level) && (level < 4))
             {
                 string command = CreateCommand(true,"B1","V3");
                 byte[] com = ConvertTobyte(command);
                 WriteData(com);    
                 mydatabase.DeleteData();
                 DisplayData("(" + DateTime.Now + "): Tu dong gui canh bao muc 3\r\n", tb);
             }
             if ((2 < level) && (level < 2.5))
             {
                 string command = CreateCommand(true,"B1","V2");
                 byte[] com = ConvertTobyte(command);
                 WriteData(com);
                 mydatabase.DeleteData();
                 DisplayData("(" + DateTime.Now + "): Tu dong gui canh bao muc 2\r\n", tb);
             }
             if (level < 2)
             {
                 string command = CreateCommand(true,"B1","V1");
                 byte[] com = ConvertTobyte(command);
                 WriteData(com);
                 mydatabase.DeleteData();
                 DisplayData("(" + DateTime.Now + "): Tu dong gui canh bao muc 1\r\n", tb);
             }
         }
     catch
     {
         DisplayData("Khong the gui muc canh bao", tb);
     }
 }
Ejemplo n.º 29
0
        //Ham boc tach du lieu theo yeu cau
        public void RequestData(string mesg)
        {
            try
            {
                Database mydatabase = new Database();
                DataSensor(mesg, ref temperature, ref humidity, ref energy);
                string _mac = mesg.Substring(8, 2);
                string time1 = DateTime.Now.ToString();
                try
                {
                    int timenow = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second;
                    int dapung = timenow - (int)timeDapung[_mac];
                    timeDapung.Remove(_mac);
                    DisplayData("(" + DateTime.Now + "): Du lieu yeu cau (Dap ung: " + dapung + " giay): \r\n Sensor " + mesg.Substring(4, 4) + "(" + _mac + "): \r\n     Nhiet do: " + Temperature + "\r\n     Do am: " + Humidity + "\r\n     Nang luong : " + Energy + "\r\n", tb);
                }
                catch
                {
                    DisplayData("(" + DateTime.Now + "): Du lieu yeu cau: \r\n Sensor " + mesg.Substring(4, 4) + "(" + _mac + "): \r\n     Nhiet do: " + Temperature + "\r\n     Do am: " + Humidity + "\r\n     Nang luong : " + Energy + "\r\n", tb);
 
                }
                mydatabase.updateSensor(_mac, mesg.Substring(4, 4), Temperature, Humidity, Energy, time1);
                showdata(_mac, mesg.Substring(4, 4), Temperature, Humidity, Energy, mytext);
                if (_mac[0] == '3')
                {
                    mydatabase.SaveDataDB(Temperature, Humidity);
                }
                else {
                    int iIndex = Int32.Parse(_mac, System.Globalization.NumberStyles.HexNumber);
                    timePing[iIndex] = 0;
                }
            }
            catch
            {
                DisplayData("Error du lieu yeu cau", tb);
            }
        }
        private void cbSelectNode_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                cbSelectNode.DropDownStyle = ComboBoxStyle.DropDownList;
                tbLatitude.Text = string.Empty;
                tbLongitude.Text = string.Empty;
                tbActor.Text = string.Empty;
                int index = cbSelectNode.SelectedIndex;
                if (index == 0)
                {
                    cbmac.Items.Clear();
                    cbmac.Text = "";
                    tbActor.Enabled = true;
                    lbActor.Enabled = true;
                    Database my_Database = new Database();
                    XmlNodeList nodeSensor = ((XmlElement)my_Database.sensor).GetElementsByTagName("node");
                    foreach (XmlNode node in nodeSensor)
                    {
                        string str = node.Attributes["mac"].Value;
                        cbmac.Items.Add(str);
                    }
                }
                else
                {
                    cbmac.Items.Clear();
                    cbmac.Text = "";
                    tbActor.Enabled = false;
                    lbActor.Enabled = false;
                    Database my_Database = new Database();
                    XmlNodeList nodeActor = ((XmlElement)my_Database.actor).GetElementsByTagName("node");
                    foreach (XmlNode node in nodeActor)
                    {
                        string str = node.Attributes["mac"].Value;
                        cbmac.Items.Add(str);
                    }

                }
            }
            catch { }
        }