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 { /// /// LogRecordControl.xaml 的交互逻辑 /// public partial class ReadRecordControl : UserControl { private IBaseServices baseServices = new BaseServices(); public ReadRecordControl() { InitializeComponent(); List isAlarm = new List() { "是", "否", "" }; this.isAlarmInfo.ItemsSource = isAlarm; } private void Seach_Click(object sender, RoutedEventArgs e) { Refresh(); } private void Refresh() { Expression> 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 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> SelectReadRecords(Expression> exp) { try { Expression> joinTable = (s1, s2) => new object[] { JoinType.Left, s2.machineId == appConfig.machineId && s2.positionId == s1.PositionID }; Expression> 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 info = await baseServices.QueryMuch(joinTable, selectWhere, exp); return info; } catch (Exception ex) { LogHelperBusiness.LogError("读取记录查询异常", ex); return null; } } } }