change-修改界面日历显示不全,配方管理添加修改功能

master
liuwf 4 months ago
parent d7df1a4240
commit 5dbcb2f8a9

@ -22,7 +22,7 @@ namespace SlnMesnac.Repository.service
/// 时间段条件查询 /// 时间段条件查询
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
Task<List<LogoIdentify>> QueryAllByTime(string time1, string time2); Task<List<LogoIdentify>> QueryAllByTime(DateTime beginTime, DateTime endTime);
/// <summary> /// <summary>

@ -38,28 +38,15 @@ namespace SlnMesnac.Repository.service.Impl
/// 时间段条件查询 /// 时间段条件查询
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public async Task<List<LogoIdentify>> QueryAllByTime(string time1, string time2) public async Task<List<LogoIdentify>> QueryAllByTime(DateTime time1, DateTime time2)
{ {
try try
{ {
List<LogoIdentify> list = null; List<LogoIdentify> list = null;
if(time1 == null && time2 == null){
list = await _rep.Context.Ado.SqlQueryAsync<LogoIdentify>("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) });
} list = await _rep.Context.Ado.SqlQueryAsync<LogoIdentify>("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 });
else if (time1 == null)
{
list = await _rep.Context.Ado.SqlQueryAsync<LogoIdentify>("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<LogoIdentify>("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<LogoIdentify>("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();
}
return list; return list;
} }

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework> <TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<UseWPF>true</UseWPF> <UseWPF>true</UseWPF>

@ -24,6 +24,7 @@ namespace SlnMesnac.WPF.ViewModel
{ {
formulaService = App.ServiceProvider.GetService<ILogoFormulaService>(); formulaService = App.ServiceProvider.GetService<ILogoFormulaService>();
AddCommand = new RelayCommand(AddRecord); AddCommand = new RelayCommand(AddRecord);
UpdateCommand = new RelayCommand(UpdateRecord);
DeleteCommand = new RelayCommand<int>(t => DeleteRecord(t)); DeleteCommand = new RelayCommand<int>(t => DeleteRecord(t));
LoadDataAsync(); LoadDataAsync();
@ -77,8 +78,7 @@ namespace SlnMesnac.WPF.ViewModel
MessageBox.Show("两个值都不能为空"); MessageBox.Show("两个值都不能为空");
return; return;
} }
List<LogoFormula> list = await formulaService.GetListAsync();
if (list == null || list.Count == 0) return;
try try
{ {
@ -90,6 +90,8 @@ namespace SlnMesnac.WPF.ViewModel
MessageBox.Show("Key必须为数字"); MessageBox.Show("Key必须为数字");
return; return;
} }
List<LogoFormula> list = await formulaService.GetListAsync();
if (list == null || list.Count == 0) return;
LogoFormula formula = list.FirstOrDefault(t => t.Key == int.Parse(key)); LogoFormula formula = list.FirstOrDefault(t => t.Key == int.Parse(key));
if (formula != null) if (formula != null)
@ -106,12 +108,71 @@ namespace SlnMesnac.WPF.ViewModel
LoadDataAsync(); 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<LogoFormula> 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 属性 #region 属性
private LogoFormula _selectedRow;
public LogoFormula SelectedRow
{
get { return _selectedRow; }
set {
_selectedRow = value; RaisePropertyChanged();
if(_selectedRow != null)
{
KeyTxt = _selectedRow.Key.ToString();
ValueTxt = _selectedRow.Value;
}
}
}
/// <summary> /// <summary>
/// Key /// Key
/// </summary> /// </summary>
@ -149,10 +210,14 @@ namespace SlnMesnac.WPF.ViewModel
#endregion #endregion
/// <summary> /// <summary>
/// 查询事件 /// 添加事件
/// </summary> /// </summary>
public RelayCommand AddCommand { get; set; } public RelayCommand AddCommand { get; set; }
/// <summary>
/// 添加事件
/// </summary>
public RelayCommand UpdateCommand { get; set; }
/// <summary> /// <summary>
/// 更新检测类型事件 /// 更新检测类型事件
/// </summary> /// </summary>

@ -32,6 +32,10 @@ namespace SlnMesnac.WPF.ViewModel
#region 加载DataGrid数据 #region 加载DataGrid数据
private async void LoadData() private async void LoadData()
{ {
// 查询条件初始化
BeginDate = DateTime.Now.AddDays(-1);
EndDate = DateTime.Now;
await Task.Run(async () => await Task.Run(async () =>
{ {
List<LogoIdentify> list = await logoIdentifyService.GetAllRecordAsync(); List<LogoIdentify> list = await logoIdentifyService.GetAllRecordAsync();
@ -105,6 +109,32 @@ namespace SlnMesnac.WPF.ViewModel
} }
#endregion #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();//属性通知
}
}
}
/// <summary> /// <summary>
/// 查询事件 /// 查询事件
@ -113,10 +143,7 @@ namespace SlnMesnac.WPF.ViewModel
#region 查询 #region 查询
/// <summary>
/// 查询
/// </summary>
private async Task Query(object obj) private async Task Query(object obj)
{ {
List<LogoIdentify> list; List<LogoIdentify> list;
@ -124,35 +151,19 @@ namespace SlnMesnac.WPF.ViewModel
{ {
LogoIdentifyDataGrid.Clear(); LogoIdentifyDataGrid.Clear();
var result = (StatisticModel)obj; var result = (StatisticModel)obj;
if (string.IsNullOrEmpty(result.BeginTime) && string.IsNullOrEmpty(result.EndTime))
{ if (EndDate <= BeginDate)
list = await logoIdentifyService.QueryAllByTime(null, null); {
} MessageBox.Show("结束时间要大于开始时间!");
else if (string.IsNullOrEmpty(result.BeginTime)) return;
{ }
list = await logoIdentifyService.QueryAllByTime(null, result.EndTime); list = await logoIdentifyService.QueryAllByTime(BeginDate, EndDate);
}
else if (string.IsNullOrEmpty(result.EndTime)) if (list != null && list.Count > 0)
{
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)
{ {
await App.Current.Dispatcher.BeginInvoke((Action)(() => await App.Current.Dispatcher.BeginInvoke((Action)(() =>
{ {
list = list.OrderByDescending(x => x.RecordTime).ToList(); list = list.OrderByDescending(x => x.RecordTime).ToList();
foreach (LogoIdentify verify in list) foreach (LogoIdentify verify in list)
{ {

@ -79,7 +79,10 @@
<TextBox Text="{Binding ValueTxt,Mode=TwoWay}" Width="300" FontSize="20" Foreground="White" Margin="0 0 30 0" /> <TextBox Text="{Binding ValueTxt,Mode=TwoWay}" Width="300" FontSize="20" Foreground="White" Margin="0 0 30 0" />
<Button <Button
Content="添 加" Command="{Binding AddCommand}" Content="添 加" Command="{Binding AddCommand}"
Style="{StaticResource MaterialDesignRaisedSecondaryDarkButton}" Background="LimeGreen" Margin="0 0 100 0"/> Style="{StaticResource MaterialDesignRaisedSecondaryDarkButton}" Background="LimeGreen" Margin="0 0 30 0"/>
<Button
Content="修 改" Command="{Binding UpdateCommand}"
Style="{StaticResource MaterialDesignRaisedSecondaryDarkButton}" Background="DeepSkyBlue" Margin="0 0 30 0"/>
</StackPanel> </StackPanel>
<UniformGrid Grid.Row="1"> <UniformGrid Grid.Row="1">
<DataGrid x:Name="listDataGrid" Grid.Row="0" ItemsSource="{Binding LogoFormulaDataGrid}" Background="#00000000" <DataGrid x:Name="listDataGrid" Grid.Row="0" ItemsSource="{Binding LogoFormulaDataGrid}" Background="#00000000"
@ -87,7 +90,7 @@
RowHeight="50" AutoGenerateColumns="False" RowHeaderWidth="0" FontSize="20" RowHeight="50" AutoGenerateColumns="False" RowHeaderWidth="0" FontSize="20"
GridLinesVisibility="None" ScrollViewer.HorizontalScrollBarVisibility="Auto" LoadingRow="dgvMH_LoadingRow" GridLinesVisibility="None" ScrollViewer.HorizontalScrollBarVisibility="Auto" LoadingRow="dgvMH_LoadingRow"
ScrollViewer.VerticalScrollBarVisibility="Auto" BorderThickness="0" CanUserAddRows="False" SelectionMode="Single" IsReadOnly="True" ScrollViewer.VerticalScrollBarVisibility="Auto" BorderThickness="0" CanUserAddRows="False" SelectionMode="Single" IsReadOnly="True"
Foreground="White" > Foreground="White" SelectedItem="{Binding SelectedRow}" >
<!--修改选中字体颜色--> <!--修改选中字体颜色-->
<DataGrid.Columns> <DataGrid.Columns>
<DataGridTemplateColumn Width="55" Header="序号" > <DataGridTemplateColumn Width="55" Header="序号" >

@ -5,6 +5,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:cvt="clr-namespace:SlnMesnac.WPF.ConvertTo" xmlns:cvt="clr-namespace:SlnMesnac.WPF.ConvertTo"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:local="clr-namespace:SlnMesnac.WPF.Views" xmlns:local="clr-namespace:SlnMesnac.WPF.Views"
mc:Ignorable="d" mc:Ignorable="d"
d:DesignHeight="900" d:DesignWidth="1700"> d:DesignHeight="900" d:DesignWidth="1700">
@ -30,8 +31,7 @@
<!-- 设置前景色(文本颜色) --> <!-- 设置前景色(文本颜色) -->
<Setter Property="Foreground" Value="Black"></Setter> <Setter Property="Foreground" Value="Black"></Setter>
<!-- 设置日历的样式 -->
<Setter Property="CalendarStyle" Value="{StaticResource CustomCalendarStyle}"></Setter>
</Style> </Style>
@ -130,12 +130,12 @@
<TextBlock Text="开始时间" Margin="10 0" Foreground="White" FontSize="18" VerticalAlignment="Center"/> <TextBlock Text="开始时间" Margin="10 0" Foreground="White" FontSize="18" VerticalAlignment="Center"/>
<DatePicker Style="{StaticResource CustomDatePicker}" <DatePicker Style="{StaticResource CustomDatePicker}"
x:Name="BeginTime" FontSize="18" FontFamily="Arial" x:Name="BeginTime" FontSize="18"
Width="170" Margin="5 0" BorderBrush="White" Width="170" Margin="10 0" BorderBrush="White"
materialDesign:CalendarAssist.IsHeaderVisible="False"> materialDesign:CalendarAssist.IsHeaderVisible="False">
<DatePicker.SelectedDate> <DatePicker.SelectedDate >
<Binding <Binding
Path="FutureValidatingDate" Path="BeginDate"
UpdateSourceTrigger="PropertyChanged"> UpdateSourceTrigger="PropertyChanged">
<Binding.ValidationRules> <Binding.ValidationRules>
</Binding.ValidationRules> </Binding.ValidationRules>
@ -151,7 +151,7 @@
materialDesign:CalendarAssist.IsHeaderVisible="False"> materialDesign:CalendarAssist.IsHeaderVisible="False">
<DatePicker.SelectedDate> <DatePicker.SelectedDate>
<Binding <Binding
Path="FutureValidatingDate" Path="EndDate"
UpdateSourceTrigger="PropertyChanged"> UpdateSourceTrigger="PropertyChanged">
<Binding.ValidationRules> <Binding.ValidationRules>
</Binding.ValidationRules> </Binding.ValidationRules>
@ -179,6 +179,8 @@
Style="{StaticResource MaterialDesignRaisedSecondaryDarkButton}" Click="model_Click"> Style="{StaticResource MaterialDesignRaisedSecondaryDarkButton}" Click="model_Click">
</Button> </Button>
<TextBlock Text="记录数:" Foreground="White" FontSize="25" Margin="650 0 0 0"/>
<TextBlock Text="{Binding LogoIdentifyDataGrid.Count}" Foreground="White" FontSize="25" Margin="10 0 0 0"/>
</WrapPanel> </WrapPanel>
<UniformGrid Grid.Row="1"> <UniformGrid Grid.Row="1">
<DataGrid x:Name="listDataGrid" Grid.Row="0" ItemsSource="{Binding LogoIdentifyDataGrid}" Background="#00000000" <DataGrid x:Name="listDataGrid" Grid.Row="0" ItemsSource="{Binding LogoIdentifyDataGrid}" Background="#00000000"

@ -26,8 +26,7 @@ namespace SlnMesnac.WPF.Views
InitializeComponent(); InitializeComponent();
this.DataContext = new StatisticsPageViewModel(); this.DataContext = new StatisticsPageViewModel();
//BeginTime.SelectedDate = DateTime.Today.Date;
//EndTime.SelectedDate = DateTime.Today.Date.AddDays(1);
} }
//在载入行的时候在行表头添加编号 //在载入行的时候在行表头添加编号

Loading…
Cancel
Save