Beispiel #1
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 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
            {}
        }
Beispiel #3
0
 /// <summary>
 /// Boc tach thong tin phan hoi tu actor
 /// </summary>
 /// <param name="data"></param>
 public void convertImformationActor(string data)
 {
     try
     {
         db = new Database();
         actor.Mac = data.Substring(8, 2);
         van.VanID = int.Parse(data.Substring(11, 1), System.Globalization.NumberStyles.HexNumber);
         int check = int.Parse(data.Substring(10, 1));
         if (check == 8)
         {
             actor.StatusActor = true;
             if(van.VanID == 15)
             {
                 db.setValOn();
             }
             else
             {
                 db.setStateVal(van.VanID, "on");
             }
         }
         else
         {
             actor.StatusActor = false;
             if(van.VanID == 15)
             {
                 db.setValOff();
             }
             else
             {
                 db.setStateVal(van.VanID,"off");
             }
         }
     }
     catch (Exception ex)
     {
         ERR = ex.Message;
     }
 }
Beispiel #4
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.PicboxImage = picboxImage;
            comPort.TimerInit();
            comPort.Time_control = db.getTimeActor();
            comPort.Time_alarm = db.getTimeAlarm();
            db.setFalseBC();
            db.setValOff();
            db.setAllFalse();

#region tabpicture begin
            cbnodeImg.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;
                    cbnodeImg.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;
                    cbnodeImg.Items.Add(str);
                }
            }
#endregion 

#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");
                }
        }
 //****************************************************
 private void Emboard_Load(object sender,EventArgs e)
 {
     Database myDatabase = new Database();
     send = new Thread(new ThreadStart(comPort.SendRS));
     send.Start();
     comPort.TimerInt();
     #if ACTOR_COOR
     myDatabase.setAllFalse();
     cbMalenh.Items.Clear();
     cbMalenh.Items.Add("Lay nhiet do, do am");
     cbMalenh.Items.Add("Bat van so 1");
     cbMalenh.Items.Add("Bat van so 2");
     cbMalenh.Items.Add("Bat van so 3");
     cbMalenh.Items.Add("Bat van so 4");
     cbMalenh.Items.Add("Bat van so 5");
     cbMalenh.Items.Add("Bat van so 6");
     cbMalenh.Items.Add("Bat tat ca cac van");
     cbMalenh.Items.Add("Tat van so 1");
     cbMalenh.Items.Add("Tat van so 2");
     cbMalenh.Items.Add("Tat van so 3");
     cbMalenh.Items.Add("Tat van so 4");
     cbMalenh.Items.Add("Tat van so 5");
     cbMalenh.Items.Add("Tat van so 6");
     cbMalenh.Items.Add("Tat tat ca cac van");
     #endif
     
     #if BC_COOR
     myDatabase.setFalseActor();
     myDatabase.setNetworkIpActor("B1","0000");
     cbMalenh.Items.Clear();
     cbMalenh.Items.Add("Lay nhiet do, do am");
     cbMalenh.Items.Add("Bat canh bao muc 1");
     cbMalenh.Items.Add("Bat canh bao muc 2");
     cbMalenh.Items.Add("Bat canh bao muc 3");
     cbMalenh.Items.Add("Bat canh bao muc 4");
     cbMalenh.Items.Add("Bat canh bao muc 5");
     #endif
     
     myDatabase.setFalseBC();
     myDatabase.setValOff();
     myDatabase.setTimeVan(1, 0);
     myDatabase.setTimeVan(2, 0);
     myDatabase.setTimeVan(3, 0);
     myDatabase.setTimeVan(4,0);
     myDatabase.setTimeVan(5, 0);
     comPort.Time_alarm = myDatabase.getTimeAlarm();
     comPort.Time_control = myDatabase.getTimeActor();
     comPort.mypanel = pnShow;
     comPort.mytext = txtshow;
     comPort.tb = tbShow;
     txtmac.Hide();
     pnShow.Hide();
     btexit.Enabled = true;
     try
     {
         comPort.pictureBox = pictureBox1;
         comPort.reload(comPort.pictureBox);
     }
     catch
     {
         MessageBox.Show("Khong the load ban do");
     }
   
 }