示例#1
0
 private void button1_Click(object sender, EventArgs e)
 {
     if (button1.BackColor == Color.Red)
     {
         button1.BackColor   = Color.Green;
         button1.Text        = "打开定时";
         this.timer1.Enabled = false;
         longt.Enabled       = true;
         lait.Enabled        = true;
         times.Text          = string.Empty;
         rise.Text           = string.Empty;
         set.Text            = string.Empty;
         log.Info("关闭定时");
     }
     else
     {
         if (string.IsNullOrEmpty(longt.Text.ToString().Trim()) || string.IsNullOrEmpty(lait.Text.ToString().Trim()))
         {
             MessageBox.Show("经度或纬度不能为空");
             return;
         }
         longt.Enabled       = false;
         lait.Enabled        = false;
         button1.BackColor   = Color.Red;
         button1.Text        = "关闭定时";
         this.timer1.Enabled = true;
         longitude           = double.Parse(longt.Text.ToString().Trim());
         latitude            = double.Parse(lait.Text.ToString().Trim());
         times.Text          = DateTime.Now.ToString("yyyy-MM-dd");
         GetSunTime          = SunTimes.GetSunTime(DateTime.Now, longitude, latitude);
         rise.Text           = GetSunTime.SunriseTime.ToString("HH:mm:ss");
         set.Text            = GetSunTime.SunsetTime.ToString("HH:mm:ss");
         log.Info("打开定时");
     }
 }
示例#2
0
        private void button7_Click(object sender, EventArgs e)
        {
            DateTime time = DateTime.Now;

            SunTimes.GetSunTime(time, 120, 26);
        }
示例#3
0
        public void StartOne()
        {
            if (!string.IsNullOrEmpty(ip1.Text.ToString().Trim()) && !string.IsNullOrEmpty(port1.Text.ToString().Trim()))
            {
                ipone   = ip1.Text.ToString().Trim();
                portone = port1.Text.ToString().Trim();
                // Send(ipone,int.Parse(portone), "state=?");
                if (Send(ipone, int.Parse(portone), "state=?"))
                {
                    lab1.Text        = JsonDate();
                    ip1.Enabled      = false;
                    port1.Enabled    = false;
                    butone.BackColor = Color.Red;
                    butone.Text      = "断开";
                }
            }


            if (!string.IsNullOrEmpty(ip2.Text.ToString().Trim()) && !string.IsNullOrEmpty(port2.Text.ToString().Trim()))
            {
                iptwo   = ip2.Text.ToString().Trim();
                porttwo = port2.Text.ToString().Trim();
                if (Send(iptwo, int.Parse(porttwo), "state=?"))
                {
                    lab2.Text        = JsonDate();
                    ip2.Enabled      = false;
                    port2.Enabled    = false;
                    buttwo.BackColor = Color.Red;
                    buttwo.Text      = "断开";
                }
            }


            if (!string.IsNullOrEmpty(ip3.Text.ToString().Trim()) && !string.IsNullOrEmpty(port3.Text.ToString().Trim()))
            {
                //   MessageBox.Show("IP或端口不能为空");
                ipthree   = ip3.Text.ToString().Trim();
                portthree = port3.Text.ToString().Trim();
                if (Send(ipthree, int.Parse(portthree), "state=?"))
                {
                    lab3.Text          = JsonDate();
                    ip3.Enabled        = false;
                    port3.Enabled      = false;
                    butthree.BackColor = Color.Red;
                    butthree.Text      = "断开";
                }
            }



            if (!string.IsNullOrEmpty(ip4.Text.ToString().Trim()) && !string.IsNullOrEmpty(port4.Text.ToString().Trim()))
            {
                ipfour   = ip4.Text.ToString().Trim();
                portfour = port4.Text.ToString().Trim();
                if (Send(ipfour, int.Parse(portfour), "state=?"))
                {
                    lab4.Text         = JsonDate();
                    ip4.Enabled       = false;
                    port4.Enabled     = false;
                    butfour.BackColor = Color.Red;
                    butfour.Text      = "断开";
                }
            }


            if (!string.IsNullOrEmpty(ip5.Text.ToString().Trim()) && !string.IsNullOrEmpty(port5.Text.ToString().Trim()))
            {
                ipfive   = ip5.Text.ToString().Trim();
                portfive = port5.Text.ToString().Trim();
                if (Send(ipfive, int.Parse(portfive), "state=?"))
                {
                    lab5.Text         = JsonDate();
                    ip5.Enabled       = false;
                    port5.Enabled     = false;
                    butfive.BackColor = Color.Red;
                    butfive.Text      = "断开";
                }
            }

            if (!string.IsNullOrEmpty(ip6.Text.ToString().Trim()) && !string.IsNullOrEmpty(port6.Text.ToString().Trim()))
            {
                ipsix   = ip6.Text.ToString().Trim();
                portsix = port6.Text.ToString().Trim();
                if (Send(ipsix, int.Parse(portsix), "state=?"))
                {
                    lab6.Text        = JsonDate();
                    ip6.Enabled      = false;
                    port6.Enabled    = false;
                    butsix.BackColor = Color.Red;
                    butsix.Text      = "断开";
                }
            }



            if (!string.IsNullOrEmpty(ip7.Text.ToString().Trim()) && !string.IsNullOrEmpty(port7.Text.ToString().Trim()))
            {
                ipseven   = ip7.Text.ToString().Trim();
                portseven = port7.Text.ToString().Trim();
                if (Send(ipseven, int.Parse(portseven), "state=?"))
                {
                    lab7.Text          = JsonDate();
                    ip7.Enabled        = false;
                    port7.Enabled      = false;
                    butseven.BackColor = Color.Red;
                    butseven.Text      = "断开";
                }
            }



            if (!string.IsNullOrEmpty(ip8.Text.ToString().Trim()) && !string.IsNullOrEmpty(port8.Text.ToString().Trim()))
            {
                //   MessageBox.Show("IP或端口不能为空");
                ipeight   = ip8.Text.ToString().Trim();
                porteight = port8.Text.ToString().Trim();

                if (Send(ipeight, int.Parse(porteight), "state=?"))
                {
                    lab8.Text          = JsonDate();
                    ip8.Enabled        = false;
                    port8.Enabled      = false;
                    buteight.BackColor = Color.Red;
                    buteight.Text      = "断开";
                }
            }


            if (!string.IsNullOrEmpty(longt.Text.ToString().Trim()) && !string.IsNullOrEmpty(lait.Text.ToString().Trim()))
            {
                longt.Enabled       = false;
                lait.Enabled        = false;
                button1.BackColor   = Color.Red;
                button1.Text        = "关闭定时";
                this.timer1.Enabled = true;
                longitude           = double.Parse(longt.Text.ToString().Trim());
                latitude            = double.Parse(lait.Text.ToString().Trim());
                times.Text          = DateTime.Now.ToString("yyyy-MM-dd");
                GetSunTime          = SunTimes.GetSunTime(DateTime.Now, longitude, latitude);
                rise.Text           = GetSunTime.SunriseTime.ToString("HH:mm:ss");
                set.Text            = GetSunTime.SunsetTime.ToString("HH:mm:ss");
                log.Info("打开定时");
            }
            else
            {
                MessageBox.Show("经度或纬度不能为空");
            }
        }
示例#4
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            try
            {
                DateTime time = DateTime.Now;
                if (time.ToString("yyyy-MM-dd") != times.Text.ToString().Trim())
                {
                    log.Info("日期变了,前一天;" + times.Text.ToString() + "后一天:" + time.ToString("yyyy-MM-dd"));
                    times.Text = time.ToString("yyyy-MM-dd");
                }
                GetSunTime = SunTimes.GetSunTime(DateTime.Now, longitude, latitude);
                string risetime = GetSunTime.SunriseTime.ToString("HH:mm:ss");
                string settime  = GetSunTime.SunsetTime.ToString("HH:mm:ss");
                if (risetime != rise.Text.ToString().Trim())
                {
                    rise.Text = risetime;
                    set.Text  = settime;
                }


                if (time.ToString("HH:mm:ss") == risetime)
                {
                    if (!on)
                    {
                        if (butone.BackColor == Color.Red)
                        {
                            Send(ipone, int.Parse(portone), "setr=0000xxxxxx");
                            lab1.Text = JsonDate();
                            log.Info("IP:" + ipone + ",端口:" + portone + "-关闭" + ",设备状态:" + lab1.Text);
                        }
                        if (buttwo.BackColor == Color.Red)
                        {
                            Send(iptwo, int.Parse(porttwo), "setr=0000xxxxxx");
                            lab2.Text = JsonDate();
                            log.Info("IP:" + iptwo + ",端口:" + porttwo + "-关闭" + ",设备状态:" + lab2.Text);
                        }
                        if (butthree.BackColor == Color.Red)
                        {
                            Send(ipthree, int.Parse(portthree), "setr=0000xxxxxx");
                            lab3.Text = JsonDate();
                            log.Info("IP:" + ipthree + ",端口:" + portthree + "-关闭" + ",设备状态:" + lab3.Text);
                        }
                        if (butfour.BackColor == Color.Red)
                        {
                            Send(ipfour, int.Parse(portfour), "setr=0000xxxxxx");
                            lab4.Text = JsonDate();
                            log.Info("IP:" + ipfour + ",端口:" + portfour + "-关闭" + ",设备状态:" + lab4.Text);
                        }
                        if (butfive.BackColor == Color.Red)
                        {
                            Send(ipfive, int.Parse(portfive), "setr=0000xxxxxx");
                            lab5.Text = JsonDate();
                            log.Info("IP:" + ipfive + ",端口:" + portfive + "-关闭" + ",设备状态:" + lab5.Text);
                        }
                        if (butsix.BackColor == Color.Red)
                        {
                            Send(ipsix, int.Parse(portsix), "setr=0000xxxxxx");
                            lab6.Text = JsonDate();
                            log.Info("IP:" + ipsix + ",端口:" + portsix + "-关闭" + ",设备状态:" + lab6.Text);
                        }
                        if (butseven.BackColor == Color.Red)
                        {
                            Send(ipseven, int.Parse(portseven), "setr=0000xxxxxx");
                            lab7.Text = JsonDate();
                            log.Info("ipseven:" + iptwo + ",端口:" + portseven + "-关闭" + ",设备状态:" + lab7.Text);
                        }
                        if (buteight.BackColor == Color.Red)
                        {
                            Send(ipeight, int.Parse(porteight), "setr=0000xxxxxx");
                            lab8.Text = JsonDate();
                            log.Info("IP:" + ipeight + ",端口:" + porteight + "-关闭" + ",设备状态:" + lab8.Text);
                        }
                        on = true;
                    }
                }
                else
                {
                    on = false;
                }
                if (time.ToString("HH:mm:ss") == settime)
                {
                    if (!off)
                    {
                        if (butone.BackColor == Color.Red)
                        {
                            Send(ipone, int.Parse(portone), "setr=1111xxxxxx");
                            lab1.Text = JsonDate();
                            log.Info("IP:" + ipone + ",端口:" + portone + "-开启" + ",设备状态:" + lab1.Text);
                        }
                        if (buttwo.BackColor == Color.Red)
                        {
                            Send(iptwo, int.Parse(porttwo), "setr=1111xxxxxx");
                            lab2.Text = JsonDate();
                            log.Info("IP:" + iptwo + ",端口:" + porttwo + "-开启" + ",设备状态:" + lab2.Text);
                        }
                        if (butthree.BackColor == Color.Red)
                        {
                            Send(ipthree, int.Parse(portthree), "setr=1111xxxxxx");
                            lab3.Text = JsonDate();
                            log.Info("IP:" + ipthree + ",端口:" + portthree + "-开启" + ",设备状态:" + lab3.Text);
                        }
                        if (butfour.BackColor == Color.Red)
                        {
                            Send(ipfour, int.Parse(portfour), "setr=1111xxxxxx");
                            lab4.Text = JsonDate();
                            log.Info("IP:" + ipfour + ",端口:" + portfour + "-开启" + ",设备状态:" + lab4.Text);
                        }
                        if (butfive.BackColor == Color.Red)
                        {
                            Send(ipfive, int.Parse(portfive), "setr=1111xxxxxx");
                            lab5.Text = JsonDate();
                            log.Info("IP:" + ipfive + ",端口:" + portfive + "-开启" + ",设备状态:" + lab5.Text);
                        }
                        if (butsix.BackColor == Color.Red)
                        {
                            Send(ipsix, int.Parse(portsix), "setr=1111xxxxxx");
                            lab6.Text = JsonDate();
                            log.Info("IP:" + ipsix + ",端口:" + portsix + "-开启" + ",设备状态:" + lab6.Text);
                        }
                        if (butseven.BackColor == Color.Red)
                        {
                            Send(ipseven, int.Parse(portseven), "setr=1111xxxxxx");
                            lab7.Text = JsonDate();
                            log.Info("IP:" + ipseven + ",端口:" + portseven + "-开启" + ",设备状态:" + lab7.Text);
                        }
                        if (buteight.BackColor == Color.Red)
                        {
                            Send(ipeight, int.Parse(porteight), "setr=1111xxxxxx");
                            lab8.Text = JsonDate();
                            log.Info("IP:" + ipeight + ",端口:" + porteight + "-开启" + ",设备状态:" + lab8.Text);
                        }
                        off = true;
                    }
                }
                else
                {
                    off = false;
                }
            }
            catch (Exception)
            {
                return;
            }
        }