Sic.Framework/MECF.Framework.UI.Client/TrayThickness/HistoryData/HistoryDataViewModel.cs

146 lines
4.6 KiB
C#
Raw Normal View History

2023-05-22 18:32:18 +08:00
using Aitex.Core.RT.OperationCenter;
2023-05-22 18:32:18 +08:00
using MECF.Framework.UI.Client.ClientBase;
using System;
using System.Collections.Generic;
using System.Globalization;
2023-05-22 18:32:18 +08:00
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media;
2023-05-22 18:32:18 +08:00
namespace MECF.Framework.UI.Client.TrayThickness.HistoryData
{
public class HistoryDataViewModel : UiViewModelBase, ISupportMultipleSystem
{
/// <summary>
/// 返回ViewModel绑定的视图对象。
/// </summary>
public UserControl View { get; private set; }
public DateTime StartDateTime
{
get => ((HistoryDataView)View).wfTimeFrom.Value;
set
{
((HistoryDataView)View).wfTimeFrom.Value = value;
NotifyOfPropertyChange(nameof(StartDateTime));
}
}
2023-05-22 18:32:18 +08:00
public DateTime EndDateTime
{
get => ((HistoryDataView)View).wfTimeTo.Value;
set
{
((HistoryDataView)View).wfTimeTo.Value = value;
NotifyOfPropertyChange(nameof(EndDateTime));
}
}
public bool TimeChecked { get; set; }
public bool Unit { get; set; }
public bool Entirety { get; set; }
HistoryCoatingSqlHelp HistoryCoatingSqlHelp = new HistoryCoatingSqlHelp();
2023-05-22 18:32:18 +08:00
public List<CoatingData> CoatingData { get; set; } = new List<CoatingData>();
protected override void OnViewLoaded(object _view)
2023-05-22 18:32:18 +08:00
{
base.OnViewLoaded(_view);
View = (UserControl)_view;
StartDateTime = DateTime.Now.Date;
EndDateTime = DateTime.Now.Date.AddDays(1).AddTicks(-1);
2023-05-22 18:32:18 +08:00
}
public void QueryTime(string time)
2023-05-22 18:32:18 +08:00
{
if (StartDateTime > EndDateTime)
{
MessageBox.Show("time range invalid, start time should be early than end time.", "Error",
MessageBoxButton.OK,
MessageBoxImage.Error);
return;
}
CoatingData = HistoryCoatingSqlHelp.QueryUpdateTime(StartDateTime.ToString(), EndDateTime.ToString());
Refresh();
}
public void QueryAll()
{
CoatingData = HistoryCoatingSqlHelp.QueryUpdateAll();
Refresh();
2023-05-22 18:32:18 +08:00
}
public void QueryName(string name)
2023-05-22 18:32:18 +08:00
{
string _starTimme = "";
string _endTimme = "";
if (TimeChecked)
{
if (StartDateTime > EndDateTime)
{
MessageBox.Show("time range invalid, start time should be early than end time.", "Error",
MessageBoxButton.OK,
MessageBoxImage.Error);
return;
}
_starTimme = StartDateTime.ToString();
_endTimme = EndDateTime.ToString();
}
if (Unit)
CoatingData = HistoryCoatingSqlHelp.QueryUnitName(name, _starTimme, _endTimme,true);
else if (Entirety)
CoatingData = HistoryCoatingSqlHelp.QueryEntirety(name, _starTimme, _endTimme,true);
else
CoatingData = HistoryCoatingSqlHelp.QueryUnitName(name);
2023-05-22 18:32:18 +08:00
Refresh();
}
}
/// <summary>
/// 检测厚度是否大于最大值
/// </summary>
class ColorConverter : IMultiValueConverter
{
public object Convert(object[] value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
try
{
if (value[0] == null || value[1] == null)
{
return new SolidColorBrush(Colors.Black);
}
double _current;
if (!double.TryParse(value[0].ToString(), out _current))
return new SolidColorBrush(Colors.Red);
double _max;
if (!double.TryParse(value[1].ToString(), out _max))
return new SolidColorBrush(Colors.Black);
if (_current > _max)
{
return new SolidColorBrush(Colors.Red);
}
else
{
return new SolidColorBrush(Colors.Black);
}
}
catch (Exception)
{
return new SolidColorBrush(Colors.Red);
}
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
return null;
}
}
2023-05-22 18:32:18 +08:00
}