2026-06-05 13:44:39 +09:00

164 lines
5.5 KiB
C#

/*
* Copyright (c) 2022 LG Electronics Inc.
* SPDX-License-Identifier: LicenseRef-LGE-Proprietary
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;
namespace AuroraUIComponent.Util
{
/// <summary>
/// Interaction logic for UCSystemTimeTest.xaml
/// </summary>
public partial class UCSystemTimeTest : UserControl
{
#region properties
public static readonly DependencyProperty TestYearProperty
= DependencyProperty.Register(
nameof(TestYear),
typeof(ushort),
typeof(UCSystemTimeTest),
new FrameworkPropertyMetadata((ushort)0));
public ushort TestYear {
get { return (ushort)GetValue(TestYearProperty); }
set { SetValue(TestYearProperty, value); }
}
public static readonly DependencyProperty TestMonthProperty
= DependencyProperty.Register(
nameof(TestMonth),
typeof(ushort),
typeof(UCSystemTimeTest),
new FrameworkPropertyMetadata((ushort)0));
public ushort TestMonth {
get { return (ushort)GetValue(TestMonthProperty); }
set { SetValue(TestMonthProperty, value); }
}
public static readonly DependencyProperty TestDayProperty
= DependencyProperty.Register(
nameof(TestDay),
typeof(ushort),
typeof(UCSystemTimeTest),
new FrameworkPropertyMetadata((ushort)0));
public ushort TestDay {
get { return (ushort)GetValue(TestDayProperty); }
set { SetValue(TestDayProperty, value); }
}
public static readonly DependencyProperty TestHourProperty
= DependencyProperty.Register(
nameof(TestHour),
typeof(ushort),
typeof(UCSystemTimeTest),
new FrameworkPropertyMetadata((ushort)0));
public ushort TestHour {
get { return (ushort)GetValue(TestHourProperty); }
set { SetValue(TestHourProperty, value); }
}
public static readonly DependencyProperty TestMinuteProperty
= DependencyProperty.Register(
nameof(TestMinute),
typeof(ushort),
typeof(UCSystemTimeTest),
new FrameworkPropertyMetadata((ushort)0));
public ushort TestMinute {
get { return (ushort)GetValue(TestMinuteProperty); }
set { SetValue(TestMinuteProperty, value); }
}
public static readonly DependencyProperty TestSecondProperty
= DependencyProperty.Register(
nameof(TestSecond),
typeof(ushort),
typeof(UCSystemTimeTest),
new FrameworkPropertyMetadata((ushort)0));
public ushort TestSecond {
get { return (ushort)GetValue(TestSecondProperty); }
set { SetValue(TestSecondProperty, value); }
}
public static readonly DependencyProperty TestCurDateTimeProperty
= DependencyProperty.Register(
nameof(TestCurDateTime),
typeof(DateTime),
typeof(UCSystemTimeTest),
new FrameworkPropertyMetadata(DateTime.Now));
public DateTime TestCurDateTime {
get { return (DateTime)GetValue(TestCurDateTimeProperty); }
set { SetValue(TestCurDateTimeProperty, value); }
}
#endregion
private readonly DispatcherTimer MonitorTimer;
public UCSystemTimeTest()
{
InitializeComponent();
MonitorTimer = new DispatcherTimer();
MonitorTimer.Tick += OnMonitoring;
MonitorTimer.Interval = TimeSpan.FromMilliseconds(30);
IsVisibleChanged += OnVisibleChanged;
}
private void OnVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
{
if (e.NewValue is bool isVisible && isVisible == true) {
MonitorTimer.Start();
} else {
MonitorTimer.Stop();
}
}
private void OnMonitoring(object sender, EventArgs e)
{
TestCurDateTime = DateTime.Now;
}
private void Button_Click_Sync(object sender, RoutedEventArgs e)
{
TestYear = (ushort)TestCurDateTime.Year;
TestMonth = (ushort)TestCurDateTime.Month;
TestDay = (ushort)TestCurDateTime.Day;
TestHour = (ushort)TestCurDateTime.Hour;
TestMinute = (ushort)TestCurDateTime.Minute;
TestSecond = (ushort)TestCurDateTime.Second;
}
private void Button_Click_SetLocal(object sender, RoutedEventArgs e)
{
var setTime = new DateTime(TestYear, TestMonth, TestDay, TestHour, TestMinute, TestSecond);
SystemTimeUtil.SetLocalTime(setTime);
}
private void Button_Click_SetUTC(object sender, RoutedEventArgs e)
{
var setTime = new DateTime(TestYear, TestMonth, TestDay, TestHour, TestMinute, TestSecond);
SystemTimeUtil.SetUTCTime(setTime);
}
}
}