示例#1
0
        //获取所有plug并显示
        private void RefreshPlugInfo()
        {
            bool success = false;

            PlugDeviceTable = SmartPlugDAL.GetAllPlugDevice(SqliteDBPath, ref success);

            if (success == true)
            {
                int dtrowcount = PlugDeviceTable.Rows.Count;

                AddedDeviceList.Items.Clear();
                DeviceList.Items.Clear();
                DeviceScheList.Items.Clear();

                for (int i = 0; i < dtrowcount; i++)
                {
                    AddedDeviceList.Items.Add(PlugDeviceTable.Rows[i]["PlugName"].ToString());
                    DeviceList.Items.Add(PlugDeviceTable.Rows[i]["PlugName"].ToString());
                    DeviceScheList.Items.Add(PlugDeviceTable.Rows[i]["PlugName"].ToString());
                }
                AddedDeviceList.SelectedIndex = 0;
                DeviceList.SelectedIndex      = 0;
                DeviceScheList.SelectedIndex  = 0;
            }
            else
            {
                MessageBox.Show("无法获取插座列表", "提示", MessageBoxButton.OK);
            }
        }
示例#2
0
        private void btnUpdateSche_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (NightBudgetTextBox.Text == "" || MorningBudgetTextBox.Text == "" || AfternoonBudgetTextBox.Text == "" || EveningBudgetTextBox.Text == "")
                {
                    MessageBox.Show("请输入预算使用的电能量!", "提示", MessageBoxButton.OK);
                    return;
                }
                int selectindex = DeviceScheList.SelectedIndex;

                if (selectindex != -1)
                {
                    PlugDevice plugdev = new PlugDevice();
                    plugdev.PlugID          = Convert.ToInt64(PlugDeviceTable.Rows[selectindex]["PlugID"]);
                    plugdev.NightBudget     = Convert.ToSingle(NightBudgetTextBox.Text);
                    plugdev.MorningBudget   = Convert.ToSingle(MorningBudgetTextBox.Text);
                    plugdev.AfternoonBudget = Convert.ToSingle(AfternoonBudgetTextBox.Text);
                    plugdev.EveningBudget   = Convert.ToSingle(AfternoonBudgetTextBox.Text);
                    plugdev.NightSaving     = NightSavingSwitch.IsChecked;
                    plugdev.MorningSaving   = MorningSavingSwitch.IsChecked;
                    plugdev.AfternoonSaving = AfternoonSavingSwitch.IsChecked;
                    plugdev.EveningSaving   = EveningSavingSwitch.IsChecked;

                    bool success = SmartPlugDAL.UpdatePlugScheduleInfoByPlugID(plugdev, SqliteDBPath);
                    if (success == true)
                    {
                        PlugDeviceTable    = SmartPlugDAL.GetAllPlugDevice(SqliteDBPath, ref success);
                        BudgettedEnergy[0] = Convert.ToSingle(NightBudgetTextBox.Text);
                        BudgettedEnergy[1] = Convert.ToSingle(MorningBudgetTextBox.Text);
                        BudgettedEnergy[2] = Convert.ToSingle(AfternoonBudgetTextBox.Text);
                        BudgettedEnergy[3] = Convert.ToSingle(EveningBudgetTextBox.Text);
                        UpdateBudgettedUsedChart();
                        MessageBox.Show("更新成功!", "提示", MessageBoxButton.OK);
                    }
                    else
                    {
                        MessageBox.Show("无法更新,请检查设置!", "提示", MessageBoxButton.OK);
                    }
                }
            }
            catch (ArgumentException ae)
            {
                MessageBox.Show(ae.Message + " \n\n" + ae.Source + "\n\n" + ae.StackTrace);
            }
            catch (Exception ex)
            {
                //Do any logging operation here if necessary
                throw new Exception(ex.Message);
            }
        }