public TimeSetWindow(TimeSettings TimeSet)
        {
            InitializeComponent();
            DataContext = this;

            Days = new ObservableCollection <string>(MainWindow.WeekDaysStrings);
            TimeZonesListBox.ItemsSource   = SystemTimeZones;
            TimeZonesListBox.SelectedIndex = 0;

            for (int TimeZoneItemIndex = 0; TimeZoneItemIndex < SystemTimeZones.Count; TimeZoneItemIndex++)
            {
                if (SystemTimeZones[TimeZoneItemIndex].Id == TimeZoneInfo.Local.Id)
                {
                    TimeZonesListBox.SelectedIndex = TimeZoneItemIndex;
                    break;
                }
            }

            this.TimeSet = TimeSet;

            if (TimeSet.Hours < 10)
            {
                TimeTextBlock.Text += "0";
            }
            TimeTextBlock.Text += TimeSet.Hours.ToString() + ":";
            if (TimeSet.Minutes < 10)
            {
                TimeTextBlock.Text += "0";
            }
            TimeTextBlock.Text += TimeSet.Minutes.ToString() + ":";
            if (TimeSet.Seconds < 10)
            {
                TimeTextBlock.Text += "0";
            }
            TimeTextBlock.Text += TimeSet.Seconds.ToString();

            if (TimeSet.Date < 10)
            {
                DateTextBlock.Text += "0";
            }
            DateTextBlock.Text += TimeSet.Date.ToString() + ".";
            if (TimeSet.Month < 10)
            {
                DateTextBlock.Text += "0";
            }
            DateTextBlock.Text += TimeSet.Month.ToString() + ".";
            DateTextBlock.Text += (TimeSet.Year + 2000).ToString();

            DayTextBlock.Text += MainWindow.WeekDaysStrings[TimeSet.WeekDay - 1];

            if (TimeSet.TimeZoneId >= SystemTimeZones.Count)
            {
                TimeZoneTextBlock.Text += TimeZoneNotSetString;
            }
            else
            {
                TimeZoneTextBlock.Text += "\n";
                TimeZoneTextBlock.Text += SystemTimeZones[TimeSet.TimeZoneId].ToString();
            }
        }
        private void TimeSetButton_Click(object sender, RoutedEventArgs e)
        {
            TimeSettings TimeSet = new TimeSettings();

            byte[] USBPacket = new byte[USB_PACKET_SIZE];
            USBPacket[0]                   = USB_REPORT_ID;
            USBPacket[USB_CMD_POS]         = USB_CMD_TIME;
            USBPacket[USB_TIME_SUBCMD_POS] = TIME_SUBCMD_GET;

            Boolean USBSuccess = USB_device.Write(USBPacket);

            ShowConnectionState(USBSuccess);
            if (USBSuccess == false)
            {
                return;
            }

            USBSuccess = USB_device.Read(USBPacket);

            TimeSet.Seconds    = USBPacket[USB_TIME_SECONDS_POS];
            TimeSet.Minutes    = USBPacket[USB_TIME_MINUTES_POS];
            TimeSet.Hours      = USBPacket[USB_TIME_HOURS_POS];
            TimeSet.WeekDay    = USBPacket[USB_TIME_WEEKDAY_POS];
            TimeSet.Date       = USBPacket[USB_TIME_DATE_POS];
            TimeSet.Month      = USBPacket[USB_TIME_MONTH_POS];
            TimeSet.Year       = USBPacket[USB_TIME_YEAR_POS];
            TimeSet.TimeZoneId = USBPacket[USB_TIME_ZONE_POS];

            TimeSetWindow TimeSettings = new TimeSetWindow(TimeSet);

            TimeSettings.Owner = this;
            bool?SetResult = TimeSettings.ShowDialog();

            if (SetResult == true)
            {
                USBPacket                       = new byte[USB_PACKET_SIZE];
                USBPacket[0]                    = USB_REPORT_ID;
                USBPacket[USB_CMD_POS]          = USB_CMD_TIME;
                USBPacket[USB_TIME_SUBCMD_POS]  = TIME_SUBCMD_SET;
                USBPacket[USB_TIME_SECONDS_POS] = TimeSet.Seconds;
                USBPacket[USB_TIME_MINUTES_POS] = TimeSet.Minutes;
                USBPacket[USB_TIME_HOURS_POS]   = TimeSet.Hours;
                USBPacket[USB_TIME_WEEKDAY_POS] = TimeSet.WeekDay;
                USBPacket[USB_TIME_DATE_POS]    = TimeSet.Date;
                USBPacket[USB_TIME_MONTH_POS]   = TimeSet.Month;
                USBPacket[USB_TIME_YEAR_POS]    = TimeSet.Year;
                USBPacket[USB_TIME_ZONE_POS]    = TimeSet.TimeZoneId;

                USBSuccess = USB_device.Write(USBPacket);

                ShowConnectionState(USBSuccess);
                if (USBSuccess == false)
                {
                    return;
                }
            }
        }
Ejemplo n.º 3
0
        public TimeSetWindow(TimeSettings TimeSet)
        {
            InitializeComponent();

            Days = new ObservableCollection <string>(MainWindow.WeekDaysStrings);
            TimeZonesListBox.ItemsSource  = SystemTimeZones;
            TimeZonesListBox.SelectedItem = TimeZoneInfo.Local;

            DataContext = this;

            this.TimeSet = TimeSet;

            if (TimeSet.Hours < 10)
            {
                TimeTextBlock.Text += "0";
            }
            TimeTextBlock.Text += TimeSet.Hours.ToString() + ":";
            if (TimeSet.Minutes < 10)
            {
                TimeTextBlock.Text += "0";
            }
            TimeTextBlock.Text += TimeSet.Minutes.ToString() + ":";
            if (TimeSet.Seconds < 10)
            {
                TimeTextBlock.Text += "0";
            }
            TimeTextBlock.Text += TimeSet.Seconds.ToString();

            if (TimeSet.Date < 10)
            {
                DateTextBlock.Text += "0";
            }
            DateTextBlock.Text += TimeSet.Date.ToString() + ".";
            if (TimeSet.Month < 10)
            {
                DateTextBlock.Text += "0";
            }
            DateTextBlock.Text += TimeSet.Month.ToString() + ".";
            DateTextBlock.Text += (TimeSet.Year + 2000).ToString();

            DayTextBlock.Text += MainWindow.WeekDaysStrings[TimeSet.WeekDay - 1];

            if (TimeSet.TimeZoneId >= TIME_ZONE_MAX)
            {
                TimeZoneTextBlock.Text += TimeZoneNotSetString;
            }
            else
            {
                TimeZoneTextBlock.Text += "\n";
                TimeZoneTextBlock.Text += SystemTimeZones[TimeSet.TimeZoneId].ToString();
            }
        }