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 { /// /// UpMaterialRecord.xaml 的交互逻辑 /// public partial class UpMaterialRecord : UserControl { private AppConfigDto appConfig = AppConfigDto.Instance; private IBaseServices uprecordServices = new BaseServices(); public UpMaterialRecord() { InitializeComponent(); } private void Seach_Click(object sender, RoutedEventArgs e) { Refresh(); } private void UserControl_Loaded(object sender, RoutedEventArgs e) { this.beginTime.Text = DateTime.Now.ToLongDateString(); this.endTime.Text = DateTime.Now.AddDays(1).ToLongDateString(); Refresh(); } public 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.RecordTime) >= beginTime); } if (this.endTime.Text.ToString() != "") { DateTime endTime = Convert.ToDateTime(this.endTime.Text.ToString()); exp = exp.And(x => Convert.ToDateTime(x.RecordTime) <= endTime); } if (this.rfidText.Text.ToString() != "") { exp = exp.And(x => x.Rfid.Contains(this.rfidText.Text.ToString())); } if (this.sfcText.Text.ToString() != "") { exp = exp.And(x => x.Sfc.Contains(this.sfcText.Text.ToString())); } if (appConfig.processId == "AB") { exp = exp.And(x => x.MachineId == appConfig.machineId); } Expression> order = x => x.beginTime; List proUpRecords = this.SelectUpRecords(exp).Result; proUpRecords.ForEach(x => { x.UpMaterialId = x.IsProduction == 1 ? "已生产" : "未生产"; x.IsProduction = proUpRecords.IndexOf(x)+1; }); this.UpMaterialDataGrid.ItemsSource = proUpRecords; } private async Task> SelectUpRecords(Expression> exp) { AppConfigDto appConfig = AppConfigDto.Instance; try { Expression> joinTable = (s1, s2) => new object[] { JoinType.Left, s2.machineId == appConfig.machineId && s2.positionId == s1.PositionId }; Expression> selectWhere = (s1, s2) => new ProUpRecord { Id = s2.equipName, MachineId = s1.MachineId, PositionId = s1.PositionId, Rfid = s1.Rfid, Sfc = s1.Sfc, IsProduction = s1.IsProduction, isFinish = s1.isFinish, RecordTime = s1.RecordTime, eaValue = s1.eaValue, beginTime = s1.beginTime, endTime = s1.endTime, }; List info = await uprecordServices.QueryMuch(joinTable, selectWhere, exp); return info; }catch(Exception ex) { LogHelperBusiness.LogError("上料记录查询异常", ex); return null; } } } }