Beispiel #1
0
        public Schedule()
        {
            InitializeComponent();
            this._value = new GraphicValue(this.InitializeGraphic());
            this.uiMonther.SelectedIndex = 0;
            this.CityList = new List <string>();
            this.CoordinatesDictionary = new Dictionary <string, CityCoordinates>();
            InitializeCityDictionary();
            this.SelectedCity = CityList.First();
            this.UpdateBinding();


            this.uiLatitude.Text           = Latitude.ToString();
            this.uiLongitude.Text          = Longitude.ToString();
            this.uiCityList.ItemsSource    = CityList.ToList();
            this.uiCityList.SelectedItem   = CityList.First();
            this.uiCalculateButton.Command = CalculateScheduleCommand;

            //if(Name== "uiLightingSchedule")
            //{
            //    uiSolarExpander.Visibility = Visibility.Visible;
            //}
            //else
            //{
            //    uiSolarExpander.Visibility = Visibility.Collapsed;
            //}
        }
Beispiel #2
0
 private void uiOpen_Click(object sender, RoutedEventArgs e)
 {
     uiExport.IsEnabled = uiImport.IsEnabled = uiOpen.IsEnabled = uiSave.IsEnabled = uiClearAll.IsEnabled = false;
     if (this.OpenFromFile != null)
     {
         var result = this.OpenFromFile(typeof(GraphicValue));
         if (result != null)
         {
             if (this.StartWork != null)
             {
                 this.StartWork();
             }
             this._value = (GraphicValue)result;
             this.UpdateBinding();
             if (this.StopWork != null)
             {
                 this.StopWork();
             }
         }
     }
     if (MainWindow.isAutonomus == true)
     {
         uiClearAll.IsEnabled = uiExport.IsEnabled = uiImport.IsEnabled = false;
         uiOpen.IsEnabled     = uiSave.IsEnabled = true;
     }
     else
     {
         uiExport.IsEnabled = uiImport.IsEnabled = uiOpen.IsEnabled = uiSave.IsEnabled = uiClearAll.IsEnabled = true;
     }
 }
Beispiel #3
0
        private void ImportComplete(ushort[] value)
        {
            //    if (value != null)
            //    {
            //if (value.First() == 0xFF)
            //{
            //    this.ShowMessage("График пуст",
            //           "Чтение графика", MessageBoxImage.Information);
            //}
            //else
            //{
            this._value = GraphicValue.SetValue(this.InitializeGraphic(), value);
            this.UpdateBinding();

            //}
            //}
            //else
            //{
            //    if (this.ShowMessage != null)
            //    {
            //        this.ShowMessage("Во время чтения графика из устройства произошла ошибка.",
            //            "Чтение графика", MessageBoxImage.Error);
            //    }
            //}
            uiExport.IsEnabled = uiImport.IsEnabled = uiOpen.IsEnabled = uiSave.IsEnabled = uiClearAll.IsEnabled = true;
        }
Beispiel #4
0
 private void SetGraphicValue(ushort[] value)
 {
     /*Подправить для экономии*/
     if (value is Array)
     {
         this._value = GraphicValue.SetValue(this.InitializeGraphic(), value);
         this.UpdateBinding();
     }
 }
Beispiel #5
0
        public static GraphicValue SetValue(List <GraphicMonth> months, ushort[] value)
        {
            GraphicValue tmp        = new GraphicValue(months);
            int          tmpCounter = 0;

            foreach (var month in tmp.Month)
            {
                foreach (var day in month.Days)
                {
                    var timeValue = BitConverter.GetBytes(value[tmpCounter]);
                    day.TurnOffTime.Hour   = timeValue[1];
                    day.TurnOffTime.Minute = timeValue[0];
                    timeValue             = BitConverter.GetBytes(value[tmpCounter + 1]);
                    day.TurnOnTime.Hour   = timeValue[1];
                    day.TurnOnTime.Minute = timeValue[0];
                    tmpCounter            = tmpCounter + 2;
                }
                var savingValue = BitConverter.GetBytes(value[tmpCounter]);
                month.MonthSaving.TurnOffTime.Hour   = savingValue[1];
                month.MonthSaving.TurnOffTime.Minute = savingValue[0];
                savingValue = BitConverter.GetBytes(value[tmpCounter + 1]);
                month.MonthSaving.TurnOnTime.Hour   = savingValue[1];
                month.MonthSaving.TurnOnTime.Minute = savingValue[0];
                tmpCounter = tmpCounter + 2;
            }
            var yearSavingValue = BitConverter.GetBytes(value[tmpCounter]);

            if (yearSavingValue[0] == 0)
            {
                tmp.IsSavingTurnOn          = false;
                tmp.YearSaving.TurnOffMonth = 1;
                tmp.YearSaving.TurnOffDay   = 1;
                tmp.YearSaving.TurnOnDay    = 1;
                tmp.YearSaving.TurnOnMonth  = 1;
                /*Заглушка для экономии*/
                tmp.MonthSaving = new GraphicMonthSaveing();
            }
            else
            {
                tmp.IsSavingTurnOn          = true;
                tmp.YearSaving.TurnOffMonth = yearSavingValue[1];
                tmp.YearSaving.TurnOffDay   = yearSavingValue[0];
                yearSavingValue             = BitConverter.GetBytes(value[tmpCounter + 1]);
                tmp.YearSaving.TurnOnMonth  = yearSavingValue[1];
                tmp.YearSaving.TurnOnDay    = yearSavingValue[0];
                /*Заглушка для экономии*/
                tmp.MonthSaving = tmp.Month[0].MonthSaving;
            }
            return(tmp);
        }
Beispiel #6
0
        public static GraphicValue SetSolarValue(List <GraphicMonth> months, double Latitude, double Longitude)
        {
            GraphicValue tmp         = new GraphicValue(months);
            SolarTimes   solarTimes  = new SolarTimes();
            TimeSpan     sunriseTime = new TimeSpan();
            TimeSpan     sunsetTime  = new TimeSpan();
            TimeSpan     civilDuskM  = new TimeSpan();
            TimeSpan     civilDuskE  = new TimeSpan();
            int          monthIndex  = 0;
            int          dayindex    = 0;


            foreach (var month in tmp.Month)
            {
                dayindex = 0;
                foreach (var day in month.Days)
                {
                    //ебаные гении, кто блять додумался делать коллекцию дней в феврале в 31 элемент, но блять последние делать НЕВИДИМЫМИ
                    //ОНИ ТАМ БЛЯТЬ СОВСЕМ ДВИНУТЫЕ, ИЛИ ЧТО? КАК МНЕ ТЕПЕРЬ С ЭТИМ РАБОТАТЬ ЕБАНЫВРОТБЛЯТЬ
                    //НАХУЯ ДЕЛАТЬ ТАКИЕ КОСТЫЛИ?
                    //мне это блять в кошмарах сниться будет теперь, ну вот зачеееееееееееееееем? просто зачем, блять?
                    try
                    {
                        solarTimes  = new SolarTimes(new DateTime(DateTime.Today.Year, monthIndex + 1, dayindex + 1), Latitude, Longitude);
                        sunriseTime = solarTimes.Sunrise.TimeOfDay;
                        sunsetTime  = solarTimes.Sunset.TimeOfDay;

                        Solar solar = new Solar(Latitude, solarTimes.SolarDeclination);

                        TimeSpan civilDelta = new TimeSpan((int)Math.Abs(Math.Floor(solar.TCivil)),
                                                           (int)Math.Abs((solar.TCivil - Math.Truncate(solar.TCivil)) * 60),
                                                           0);

                        civilDuskM = (sunriseTime - civilDelta);
                        civilDuskE = (sunsetTime + civilDelta);


                        day.TurnOffTime.Hour   = civilDuskM.Hours;
                        day.TurnOffTime.Minute = civilDuskM.Minutes;
                        day.TurnOnTime.Hour    = civilDuskE.Hours;
                        day.TurnOnTime.Minute  = civilDuskE.Minutes;

                        dayindex++;
                    }
                    catch (Exception ex)
                    {
                        //
                    }
                }
                month.MonthSaving.TurnOffTime.Hour   = 0;
                month.MonthSaving.TurnOffTime.Minute = 0;
                month.MonthSaving.TurnOnTime.Hour    = 0;
                month.MonthSaving.TurnOnTime.Minute  = 0;
                monthIndex++;
            }

            tmp.IsSavingTurnOn          = false;
            tmp.YearSaving.TurnOffMonth = 1;
            tmp.YearSaving.TurnOffDay   = 1;
            tmp.YearSaving.TurnOnDay    = 1;
            tmp.YearSaving.TurnOnMonth  = 1;
            /*Заглушка для экономии*/
            tmp.MonthSaving = new GraphicMonthSaveing();


            return(tmp);
        }
Beispiel #7
0
 private void OnCalculateScheduleCommand()
 {
     this._value = GraphicValue.SetSolarValue(this.InitializeGraphic(), Latitude, Longitude);
     this.UpdateBinding();
 }