using _20230724_MBJC_upperpc.Common;
using _20230724_MBJC_upperpc.Models;
using Google.Protobuf.WellKnownTypes;
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;
namespace _20230724_MBJC_upperpc.Views
{
///
/// AnchorPointView.xaml 的交互逻辑
///
public partial class AnchorPointView : UserControl
{
public AnchorPointView()
{
InitializeComponent();
}
private void DataPicker1_SelectedDateChanged(object sender, SelectionChangedEventArgs e)
{
if (DataPicker1.SelectedDate == null)
return;
//如果结束时间没有选
if (DataPicker2.SelectedDate == null)
return;
if (DataPicker1.SelectedDate > DataPicker2.SelectedDate)
{
MessageBox.Show("所选日期不能在起始日期之后!");
DataPicker1.SelectedDate = null;
}
//通过日期查询历史数据
bool IsChange = MainWindow.viewModel.SearchHisData((DateTime)DataPicker1.SelectedDate, ((DateTime)DataPicker2.SelectedDate).AddHours(23).AddMinutes(59).AddSeconds(59), int.Parse(ID.Text));
if (IsChange)
this.DataContext = MainWindow.viewModel.Beacon_Search;
}
private void DatePicker_SelectedDateChanged(object sender, SelectionChangedEventArgs e)
{
if (DataPicker2.SelectedDate == null)
return;
//如果起始时间没有选
if (DataPicker1.SelectedDate == null)
return;
//如果起始时间大于结束时间
if (DataPicker1.SelectedDate > DataPicker2.SelectedDate)
{
MessageBox.Show("所选日期不能在起始日期之前!");
DataPicker2.SelectedDate = null;
}
//通过日期查询历史数据
bool IsChange = MainWindow.viewModel.SearchHisData((DateTime)DataPicker1.SelectedDate, ((DateTime)DataPicker2.SelectedDate).AddHours(23).AddMinutes(59).AddSeconds(59), int.Parse(ID.Text));
if (IsChange)
this.DataContext = MainWindow.viewModel.Beacon_Search;
}
private void slider_ValueChanged(object sender, RoutedPropertyChangedEventArgs e)
{
if (string.IsNullOrEmpty(ID.Text))
return;
if ((int)this.slider.Value >= 0 && (int)this.slider.Value < MainWindow.viewModel.Beacon_Search.BeaconList.Count)
{
MainWindow.viewModel.Beacon_Search.SelectedTime = MainWindow.viewModel.Beacon_Search.BeaconList[(int)this.slider.Value].Datetime.ToString("yyyy-MM-dd HH:mm:ss");
}
}
private void slider_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
MainWindow.viewModel.Beacon_Search.Beacon = MainWindow.viewModel.Beacon_Search.BeaconList[(int)this.slider.Value];
}
///
/// 恢复实时数据显示按钮
///
///
///
private void Button_Click(object sender, RoutedEventArgs e)
{
if (int.Parse(ID.Text) == int.Parse(tools.GetAppSetting("Beacon1")))
{
this.DataContext = MainWindow.viewModel.Beacon1;
}
else if (int.Parse(ID.Text) == int.Parse(tools.GetAppSetting("Beacon2")))
{
this.DataContext = MainWindow.viewModel.Beacon2;
}
else if (int.Parse(ID.Text) == int.Parse(tools.GetAppSetting("Beacon3")))
{
this.DataContext = MainWindow.viewModel.Beacon3;
}
else if (int.Parse(ID.Text) == int.Parse(tools.GetAppSetting("Beacon4")))
{
this.DataContext = MainWindow.viewModel.Beacon4;
}
else if (int.Parse(ID.Text) == int.Parse(tools.GetAppSetting("Beacon5")))
{
this.DataContext = MainWindow.viewModel.Beacon5;
}
else if (int.Parse(ID.Text) == int.Parse(tools.GetAppSetting("Beacon6")))
{
this.DataContext = MainWindow.viewModel.Beacon6;
}
else if (int.Parse(ID.Text) == int.Parse(tools.GetAppSetting("Beacon7")))
{
this.DataContext = MainWindow.viewModel.Beacon7;
}
else if (int.Parse(ID.Text) == int.Parse(tools.GetAppSetting("Beacon8")))
{
this.DataContext = MainWindow.viewModel.Beacon8;
}
this.DataPicker1.SelectedDate = null;
this.DataPicker2.SelectedDate = null;
}
}
}