コード例 #1
0
ファイル: MainForm.cs プロジェクト: b0ran0v/EnergyMonitor
        private void Monitor()
        {
            int  status        = 0;
            bool isRecommended = false;

            while (true)
            {
                Thread.Sleep(5000);
                isRecommended = !Windmills.isRecommended();
                if (wm_chb.Checked != isRecommended)
                {
                    checBoxSetCheckState(wm_chb, isRecommended);
                    checBoxSetTextValue(wm_chb, wm_chb.Checked ? "Turned on" : "Turned off");
                    status = wm_chb.Checked ? 1 : 0;
                    try
                    {
                        conn.Open();
                        query = $"UPDATE Energy SET Enabled={status} WHERE TypeId=2";
                        command.CommandText = query;
                        command.ExecuteNonQuery();
                        conn.Close();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.ToString());
                    }
                }
            }
        }
コード例 #2
0
ファイル: MainForm.cs プロジェクト: b0ran0v/EnergyMonitor
        public void checkBox_Checked(Object sender, EventArgs e)
        {
            int      typeId   = 0;
            CheckBox checkBox = sender as CheckBox;

            switch (checkBox.Name)
            {
            case "sp_chb":
                sp_chb.Text = sp_chb.Checked ? "Turned on" : "Turned off";
                typeId      = 1;
                break;

            case "wm_chb":
                wm_chb.Text = wm_chb.Checked ? "Turned on" : "Turned off";
                typeId      = 2;
                break;

            case "gr_checkbox":
                gr_chb.Text = gr_chb.Checked ? "Turned on" : "Turned off";
                typeId      = 3;
                break;
            }

            int status = checkBox.Checked ? 1 : 0;

            if (status == 1)
            {
                if (typeId == 1 && !Windmills.isRecommended())
                {
                    MessageBox.Show("Solar panels are not recommended to be turned on");
                }
                else if (typeId == 2 && !Windmills.isRecommended())
                {
                    MessageBox.Show("Windmills are not recommended to be turned on");
                }
                else if (typeId == 3 && !Windmills.isRecommended())
                {
                    MessageBox.Show("Grids are not recommended to be turned on");
                }
            }

            try
            {
                conn.Open();
                query = $"UPDATE Energy SET Enabled={status} WHERE TypeId={typeId}";
                command.CommandText = query;
                command.ExecuteNonQuery();
                conn.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }