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.

128 lines
4.3 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>
/// UpMaterialRecord.xaml 的交互逻辑
/// </summary>
public partial class UpMaterialRecord : UserControl
{
private AppConfigDto appConfig = AppConfigDto.Instance;
private IBaseServices<ProUpRecord> uprecordServices = new BaseServices<ProUpRecord>();
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<Func<ProUpRecord, bool>> 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<Func<ProUpRecord, object>> order = x => x.beginTime;
List<ProUpRecord> 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<List<ProUpRecord>> SelectUpRecords(Expression<Func<ProUpRecord, bool>> exp)
{
AppConfigDto appConfig = AppConfigDto.Instance;
try
{
Expression<Func<ProUpRecord, ProEquip, Object[]>> joinTable = (s1, s2) => new object[]
{
JoinType.Left,
s2.machineId == appConfig.machineId && s2.positionId == s1.PositionId
};
Expression<Func<ProUpRecord, ProEquip, ProUpRecord>> 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<ProUpRecord> info = await uprecordServices.QueryMuch<ProUpRecord, ProEquip, ProUpRecord>(joinTable, selectWhere, exp);
return info;
}catch(Exception ex)
{
LogHelperBusiness.LogError("上料记录查询异常", ex);
return null;
}
}
}
}