You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

126 lines
4.4 KiB
C#

using MaterialTraceability.Business;
using MaterialTraceability.Entity.DAO;
using MaterialTraceability.Entity.DTO;
using MaterialTraceability.SqlSugar;
using MaterialTraceability.SqlSugar.ServiceImpl;
using MaterialTraceabilityUI.Common;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
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 MaterialTraceabilityUI
{
/// <summary>
/// LogRecordControl.xaml 的交互逻辑
/// </summary>
public partial class ReadRecordControl : UserControl
{
private IBaseServices<ProReadRecord> baseServices = new BaseServices<ProReadRecord>();
public ReadRecordControl()
{
InitializeComponent();
List<String> isAlarm = new List<string>() { "是", "否", "" };
this.isAlarmInfo.ItemsSource = isAlarm;
}
private void Seach_Click(object sender, RoutedEventArgs e)
{
Refresh();
}
private void Refresh()
{
Expression<Func<ProReadRecord, bool>> exp = s1 => true;
if (this.beginTime.Text.ToString() != "")
{
DateTime beginTime = Convert.ToDateTime(this.beginTime.Text.ToString());
exp = exp.And(x => Convert.ToDateTime(x.ReadTime) >= beginTime);
}
if (this.endTime.Text.ToString() != "")
{
DateTime endTime = Convert.ToDateTime(this.endTime.Text.ToString());
exp = exp.And(x => Convert.ToDateTime(x.ReadTime) <= endTime);
}
if (Convert.ToString(this.isAlarmInfo.SelectedItem) != "")
{
string isAlarm = Convert.ToString(this.isAlarmInfo.SelectedItem) == "是" ? "1" : "0";
exp = exp.And(x => x.Result == isAlarm);
}
if (StringExtension.IsNotBlank(this.rfidText.Text))
{
exp = exp.And(x => x.ReadEPC.Contains(this.rfidText.Text));
}
//exp = exp.And(x => x.MachineID == Convert.ToInt32(ConfigHelper.GetConfig("MachineID")));
List<ProReadRecord> recordLogInfos = this.SelectReadRecords(exp).Result;
recordLogInfos.ForEach(x =>
{
x.Result = x.Result == "1" ? "成功" : "失败";
x.PositionID = recordLogInfos.IndexOf(x) + 1;
});
this.ReadRecordDataGrid.ItemsSource = recordLogInfos;
}
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
this.beginTime.Text = DateTime.Now.ToLongDateString();
this.endTime.Text = DateTime.Now.AddDays(1).ToLongDateString();
Refresh();
}
private AppConfigDto appConfig = AppConfigDto.Instance;
private async Task<List<ProReadRecord>> SelectReadRecords(Expression<Func<ProReadRecord, bool>> exp)
{
try
{
Expression<Func<ProReadRecord, ProEquip, Object[]>> joinTable = (s1, s2) => new object[]
{
JoinType.Left,
s2.machineId == appConfig.machineId && s2.positionId == s1.PositionID
};
Expression<Func<ProReadRecord, ProEquip, ProReadRecord>> selectWhere = (s1, s2) => new ProReadRecord
{
Id = s2.equipName,
EquipID = s1.EquipID,
MachineID = s1.MachineID,
PositionID = s1.PositionID,
Result = s1.Result,
Ant = s1.Ant,
ReadEPC = s1.ReadEPC,
ReadTime = s1.ReadTime,
};
//exp = exp.And(x => x.MachineID == Convert.ToInt32(ConfigHelper.GetConfig("MachineID")));
List<ProReadRecord> info = await baseServices.QueryMuch<ProReadRecord, ProEquip, ProReadRecord>(joinTable, selectWhere, exp);
return info;
}
catch (Exception ex)
{
LogHelperBusiness.LogError("读取记录查询异常", ex);
return null;
}
}
}
}