123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- using DryIoc.FastExpressionCompiler.LightExpression;
- using ProximaAnalizer.Data;
- using System.Collections.ObjectModel;
- using System.Net.NetworkInformation;
- using System.Windows;
- namespace ProximaAnalizer.ViewModels;
- internal partial class RecipeStepNaviViewModel(IEventAggregator eventAggregator, SqlSugarCustom sqlSugar, TraceData traceData) : ObservableObject
- {
- [ObservableProperty]
- private DateTime _SelectedTime = DateTime.Now;
- [ObservableProperty]
- private Visibility _Masking = Visibility.Hidden;
- [ObservableProperty]
- private ObservableCollection<ProcessData> _ProcessData = [];
- partial void OnSelectedTimeChanged(DateTime value)
- {
- this.Search();
- }
- [RelayCommand]
- private void Navi(ProcessData process)
- {
- this.Masking = Visibility.Visible;
- traceData.ProcessData = process;
- Task.Factory.StartNew(() =>
- {
- try
- {
- Thread.Sleep(200);
- App.Current.Dispatcher.Invoke(() =>
- {
- eventAggregator.GetEvent<WindowSwitch>().Page = Pages.MainWindow;
- eventAggregator.GetEvent<WindowSwitch>().Publish();
- eventAggregator.GetEvent<RefreshRecipeData>().Publish();
- });
- }
- finally
- {
- this.Masking = Visibility.Collapsed;
- }
- });
- }
- [RelayCommand]
- private void DayOperator(string para)
- {
- this.SelectedTime = para switch
- {
- "+" => this.SelectedTime.AddDays(1),
- "-" => this.SelectedTime.AddDays(-1),
- _ => this.SelectedTime
- };
- }
- [RelayCommand]
- private void Search()
- {
- if (sqlSugar.Client is null)
- return;
- this.ProcessData ??= [];
- this.ProcessData.Clear();
- this.Masking = Visibility.Visible;
- Task.Factory.StartNew(() =>
- {
- try
- {
- var t = sqlSugar.Client.Queryable<ProcessData>().Where(t =>
- t.Process_Begin_Time >= SelectedTime &&
- t.Process_Begin_Time < SelectedTime.AddDays(1)).AS("process_data").ToArray();
- foreach (var item in t)
- {
- App.Current.Dispatcher.Invoke(() =>
- {
- this.ProcessData.Add(item);
- });
- Thread.Sleep(1);
- }
- }
- finally
- {
- this.Masking = Visibility.Collapsed;
- }
- });
- }
- [RelayCommand]
- private void NameSearch(string name)
- {
- if (sqlSugar.Client is null)
- return;
- if (string.IsNullOrEmpty(name))
- return;
- this.ProcessData ??= [];
- this.ProcessData.Clear();
- this.Masking = Visibility.Visible;
- Task.Factory.StartNew(() =>
- {
- try
- {
- var t = sqlSugar.Client.Queryable<ProcessData>()
- .Where(t => (string.IsNullOrEmpty(t.Recipe_Name) ? string.Empty : t.Recipe_Name).ToLower().Contains(name.ToLower()))
- .AS("process_data").ToArray()
- .OrderBy(t => t.Process_Begin_Time);
- foreach (var item in t)
- {
- App.Current.Dispatcher.Invoke(() =>
- {
- this.ProcessData.Add(item);
- });
- Thread.Sleep(1);
- }
- }
- finally
- {
- this.Masking = Visibility.Collapsed;
- }
- });
- }
- }
|