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 DownMaterialRecord : UserControl { private IBaseServices uprecordServices = new BaseServices(); private AppConfigDto appConfig = AppConfigDto.Instance; public DownMaterialRecord() { InitializeComponent(); } private void Seach_Click(object sender, RoutedEventArgs e) { Refresh(); } private void UserControl_Loaded(object sender, RoutedEventArgs e) { Refresh(); this.beginTime.Text = DateTime.Now.ToLongDateString(); this.endTime.Text = DateTime.Now.AddDays(1).ToLongDateString(); } 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.SelectDownRecords(exp).Result; proUpRecords.ForEach(x => { x.DownMaterialId = x.IsProduction == 1 ? "已生产" : "未生产"; x.IsProduction = proUpRecords.IndexOf(x)+1; if (appConfig.machineId == 4) { if (x.Id.Contains("左")) { x.Id = x.Id.Replace("左", "右"); } else if (x.Id.Contains("右")) { x.Id = x.Id.Replace("右", "左"); } } }); this.UpMaterialDataGrid.ItemsSource = proUpRecords; } private async Task> SelectDownRecords(Expression> exp) { try { Expression> joinTable = (s1, s2) => new object[] { JoinType.Left, s2.machineId == appConfig.machineId && s2.positionId == s1.PositionId }; Expression> selectWhere = (s1, s2) => new ProDownRecord { 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; } } } }