From 5dbcb2f8a969ca041f0a5e1bf7edf4a685d98c13 Mon Sep 17 00:00:00 2001 From: liuwf Date: Tue, 2 Jul 2024 16:23:12 +0800 Subject: [PATCH] =?UTF-8?q?change-=E4=BF=AE=E6=94=B9=E7=95=8C=E9=9D=A2?= =?UTF-8?q?=E6=97=A5=E5=8E=86=E6=98=BE=E7=A4=BA=E4=B8=8D=E5=85=A8=EF=BC=8C?= =?UTF-8?q?=E9=85=8D=E6=96=B9=E7=AE=A1=E7=90=86=E6=B7=BB=E5=8A=A0=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ILogoIdentifyService.cs | 2 +- .../service/Impl/LogoIdentifyImpl.cs | 23 ++---- SlnMesnac.WPF/SlnMesnac.WPF.csproj | 2 +- .../ViewModel/FormulaWindowViewModel.cs | 73 ++++++++++++++++++- .../ViewModel/StatisticsPageViewModel.cs | 71 ++++++++++-------- SlnMesnac.WPF/Views/FormulaWindow.xaml | 7 +- SlnMesnac.WPF/Views/StatisticsPageView.xaml | 16 ++-- .../Views/StatisticsPageView.xaml.cs | 3 +- 8 files changed, 132 insertions(+), 65 deletions(-) diff --git a/SlnMesnac.Repository/service/ILogoIdentifyService.cs b/SlnMesnac.Repository/service/ILogoIdentifyService.cs index 6f582d0..41147d8 100644 --- a/SlnMesnac.Repository/service/ILogoIdentifyService.cs +++ b/SlnMesnac.Repository/service/ILogoIdentifyService.cs @@ -22,7 +22,7 @@ namespace SlnMesnac.Repository.service /// 时间段条件查询 /// /// - Task> QueryAllByTime(string time1, string time2); + Task> QueryAllByTime(DateTime beginTime, DateTime endTime); /// diff --git a/SlnMesnac.Repository/service/Impl/LogoIdentifyImpl.cs b/SlnMesnac.Repository/service/Impl/LogoIdentifyImpl.cs index 862c0c5..a8324b2 100644 --- a/SlnMesnac.Repository/service/Impl/LogoIdentifyImpl.cs +++ b/SlnMesnac.Repository/service/Impl/LogoIdentifyImpl.cs @@ -38,28 +38,15 @@ namespace SlnMesnac.Repository.service.Impl /// 时间段条件查询 /// /// - public async Task> QueryAllByTime(string time1, string time2) + public async Task> QueryAllByTime(DateTime time1, DateTime time2) { try { List list = null; - if(time1 == null && time2 == null){ - list = await _rep.Context.Ado.SqlQueryAsync("select ID,PRODUCT_CODE,MATERIAL_TYPE,IS_CHECKED,RESULT,RECORD_TIME,MATERIAL_NAME from LOGO_IDENTIFY where RECORD_TIME >= @RecordTime ", new { RecordTime = DateTime.Now.AddDays(-1) }); - } - else if (time1 == null) - { - list = await _rep.Context.Ado.SqlQueryAsync("select ID,PRODUCT_CODE,MATERIAL_TYPE,IS_CHECKED,RESULT,RECORD_TIME,MATERIAL_NAME from LOGO_IDENTIFY where RECORD_TIME <= @RecordTime ", new { RecordTime = DateTime.Parse(time2) }); - // list = _rep.GetList().Where(x => x.RecordTime <= DateTime.Parse(time2)).ToList(); - }else if (time2 == null) - { - list = await _rep.Context.Ado.SqlQueryAsync("select ID,PRODUCT_CODE,MATERIAL_TYPE,IS_CHECKED,RESULT,RECORD_TIME,MATERIAL_NAME from LOGO_IDENTIFY where RECORD_TIME >= @RecordTime ", new { RecordTime = DateTime.Parse(time1) }); - // list = _rep.GetList().Where(x => x.RecordTime >= DateTime.Parse(time1)).ToList(); - } - else - { - list = await _rep.Context.Ado.SqlQueryAsync("select ID,PRODUCT_CODE,MATERIAL_TYPE,IS_CHECKED,RESULT,RECORD_TIME,MATERIAL_NAME from LOGO_IDENTIFY where RECORD_TIME >= @RecordTime1 AND RECORD_TIME <= @RecordTime2 ", new { RecordTime1 = DateTime.Parse(time1), RecordTime2 = DateTime.Parse(time2) }); - // list = _rep.GetList().Where(x=>x.RecordTime >= DateTime.Parse(time1) && x.RecordTime <= DateTime.Parse(time2)).ToList(); - } + + + list = await _rep.Context.Ado.SqlQueryAsync("select ID,PRODUCT_CODE,MATERIAL_TYPE,IS_CHECKED,RESULT,RECORD_TIME,MATERIAL_NAME from LOGO_IDENTIFY where RECORD_TIME >= @RecordTime1 AND RECORD_TIME <= @RecordTime2 ", new { RecordTime1 = time1, RecordTime2 = time2 }); + return list; } diff --git a/SlnMesnac.WPF/SlnMesnac.WPF.csproj b/SlnMesnac.WPF/SlnMesnac.WPF.csproj index 189ca9e..a0923b6 100644 --- a/SlnMesnac.WPF/SlnMesnac.WPF.csproj +++ b/SlnMesnac.WPF/SlnMesnac.WPF.csproj @@ -1,7 +1,7 @@  - Exe + WinExe net6.0-windows enable true diff --git a/SlnMesnac.WPF/ViewModel/FormulaWindowViewModel.cs b/SlnMesnac.WPF/ViewModel/FormulaWindowViewModel.cs index d180e7e..781ed6d 100644 --- a/SlnMesnac.WPF/ViewModel/FormulaWindowViewModel.cs +++ b/SlnMesnac.WPF/ViewModel/FormulaWindowViewModel.cs @@ -24,6 +24,7 @@ namespace SlnMesnac.WPF.ViewModel { formulaService = App.ServiceProvider.GetService(); AddCommand = new RelayCommand(AddRecord); + UpdateCommand = new RelayCommand(UpdateRecord); DeleteCommand = new RelayCommand(t => DeleteRecord(t)); LoadDataAsync(); @@ -77,8 +78,7 @@ namespace SlnMesnac.WPF.ViewModel MessageBox.Show("两个值都不能为空"); return; } - List list = await formulaService.GetListAsync(); - if (list == null || list.Count == 0) return; + try { @@ -90,6 +90,8 @@ namespace SlnMesnac.WPF.ViewModel MessageBox.Show("Key必须为数字"); return; } + List list = await formulaService.GetListAsync(); + if (list == null || list.Count == 0) return; LogoFormula formula = list.FirstOrDefault(t => t.Key == int.Parse(key)); if (formula != null) @@ -106,12 +108,71 @@ namespace SlnMesnac.WPF.ViewModel LoadDataAsync(); } } + } + + + private async void UpdateRecord() + { + string key = KeyTxt; + string value = ValueTxt; + if (string.IsNullOrEmpty(key) || string.IsNullOrEmpty(value)) + { + MessageBox.Show("两个值都不能为空"); + return; + } + try + { + int result = int.Parse(key); + Console.WriteLine("转换成功,结果是:" + result); + } + catch (FormatException) + { + MessageBox.Show("Key必须为数字"); + return; + } + List list = await formulaService.GetListAsync(); + if (list == null || list.Count == 0) return; + LogoFormula formula = list.FirstOrDefault(t => t.Key == int.Parse(key)); + if (formula != null) + { + formula.Value = value; + bool result = await formulaService.UpdateAsync(formula); + if (result) + { + MessageBox.Show("修改成功"); + LoadDataAsync(); + } + } + else + { + MessageBox.Show("Key不存在,无法更新"); + return; + } } + + #region 属性 + private LogoFormula _selectedRow; + public LogoFormula SelectedRow + { + get { return _selectedRow; } + set { + _selectedRow = value; RaisePropertyChanged(); + if(_selectedRow != null) + { + KeyTxt = _selectedRow.Key.ToString(); + ValueTxt = _selectedRow.Value; + } + } + + } + + + /// /// Key /// @@ -149,10 +210,14 @@ namespace SlnMesnac.WPF.ViewModel #endregion /// - /// 查询事件 + /// 添加事件 /// public RelayCommand AddCommand { get; set; } - + /// + /// 添加事件 + /// + public RelayCommand UpdateCommand { get; set; } + /// /// 更新检测类型事件 /// diff --git a/SlnMesnac.WPF/ViewModel/StatisticsPageViewModel.cs b/SlnMesnac.WPF/ViewModel/StatisticsPageViewModel.cs index 0bb4c6b..a74952d 100644 --- a/SlnMesnac.WPF/ViewModel/StatisticsPageViewModel.cs +++ b/SlnMesnac.WPF/ViewModel/StatisticsPageViewModel.cs @@ -32,6 +32,10 @@ namespace SlnMesnac.WPF.ViewModel #region 加载DataGrid数据 private async void LoadData() { + // 查询条件初始化 + BeginDate = DateTime.Now.AddDays(-1); + EndDate = DateTime.Now; + await Task.Run(async () => { List list = await logoIdentifyService.GetAllRecordAsync(); @@ -105,6 +109,32 @@ namespace SlnMesnac.WPF.ViewModel } #endregion + private DateTime _BeginDate; + public DateTime BeginDate + { + get { return _BeginDate; } + set + { + if (_BeginDate != value) + { + _BeginDate = value; + RaisePropertyChanged();//属性通知 + } + } + } + private DateTime _EndDate; + public DateTime EndDate + { + get { return _EndDate; } + set + { + if (_EndDate != value) + { + _EndDate = value; + RaisePropertyChanged();//属性通知 + } + } + } /// /// 查询事件 @@ -113,10 +143,7 @@ namespace SlnMesnac.WPF.ViewModel #region 查询 - /// - /// 查询 - /// - + private async Task Query(object obj) { List list; @@ -124,35 +151,19 @@ namespace SlnMesnac.WPF.ViewModel { LogoIdentifyDataGrid.Clear(); var result = (StatisticModel)obj; - if (string.IsNullOrEmpty(result.BeginTime) && string.IsNullOrEmpty(result.EndTime)) - { - list = await logoIdentifyService.QueryAllByTime(null, null); - } - else if (string.IsNullOrEmpty(result.BeginTime)) - { - list = await logoIdentifyService.QueryAllByTime(null, result.EndTime); - } - else if (string.IsNullOrEmpty(result.EndTime)) - { - list = await logoIdentifyService.QueryAllByTime(result.BeginTime, null); - } - else - { - DateTime theBeginTime = Convert.ToDateTime(result.BeginTime); - DateTime theEndTime = Convert.ToDateTime(result.EndTime); - if (theBeginTime > theEndTime) - { - MessageBox.Show("结束时间要大于开始时间!"); - return; - } - list = await logoIdentifyService.QueryAllByTime(result.BeginTime, result.EndTime); - } - - if (list!= null && list.Count > 0) + + if (EndDate <= BeginDate) + { + MessageBox.Show("结束时间要大于开始时间!"); + return; + } + list = await logoIdentifyService.QueryAllByTime(BeginDate, EndDate); + + if (list != null && list.Count > 0) { await App.Current.Dispatcher.BeginInvoke((Action)(() => { - + list = list.OrderByDescending(x => x.RecordTime).ToList(); foreach (LogoIdentify verify in list) { diff --git a/SlnMesnac.WPF/Views/FormulaWindow.xaml b/SlnMesnac.WPF/Views/FormulaWindow.xaml index eae59f5..d2b0253 100644 --- a/SlnMesnac.WPF/Views/FormulaWindow.xaml +++ b/SlnMesnac.WPF/Views/FormulaWindow.xaml @@ -79,7 +79,10 @@ + +