コード例 #1
0
 private void BatteryManagement()
 {
     new Thread(() =>
     {
         while (true)
         {
             if ((ClockModel.Time.Hour >= 3) && (ClockModel.Time.Hour < 6))
             {
                 battery.StartCharging();
             }
             else if ((ClockModel.Time.Hour >= 14) && (ClockModel.Time.Hour <= 17))
             {
                 battery.StartDischarging();
             }
             else
             {
                 battery.StartIdle();
             }
             lock (BatteryViewModel.Batteries)
             {
                 BatteryViewModel.Refresh();
             }
         }
     }).Start();
 }
コード例 #2
0
        private void ButtonAdd_Click(object sender, RoutedEventArgs e)
        {
            if (Validate(textBoxName) && Validate(textBoxMaxPower) && Validate(textBoxCapacity))
            {
                bool   p = false, c = false;
                double pp = 0, cc = 0;
                p = double.TryParse(textBoxMaxPower.Text, out pp);
                c = double.TryParse(textBoxCapacity.Text, out cc);
                if (p && c && pp >= 0 && cc >= 0)
                {
                    lock (BatteryViewModel.Batteries)
                    {
                        BatteryViewModel.Batteries.Add(new BatteryModel(textBoxName.Text, Double.Parse(textBoxMaxPower.Text), Double.Parse(textBoxCapacity.Text), 0));

                        using (dbSHESEntities entity = new dbSHESEntities())
                        {
                            BatteryTable bmt = new BatteryTable()
                            {
                                Name            = textBoxName.Text,
                                MaxPower        = Double.Parse(textBoxMaxPower.Text),
                                Capacity        = Double.Parse(textBoxCapacity.Text),
                                CurrentCapacity = 0,
                                CapacityMin     = 0,
                                State           = Enums.BatteryEnum.IDLE.ToString()
                            };
                            entity.BatteryTables.Add(bmt);
                            entity.SaveChanges();
                        }

                        BatteryViewModel.Refresh();
                    }
                }
                else
                {
                    MessageBox.Show("Incorrect input", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            else
            {
                MessageBox.Show("Incorrect input", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }