添加项目文件。
This commit is contained in:
211
SamplePreSystem.UI/ViewModel/Child/ImportSampleViewModel.cs
Normal file
211
SamplePreSystem.UI/ViewModel/Child/ImportSampleViewModel.cs
Normal file
@@ -0,0 +1,211 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using Models.Models;
|
||||
using SamplePre.Models.Ext;
|
||||
using SamplePre.ProcessBll.SampleSequence;
|
||||
using SamplePreSystem.UI.ViewModel.SampleManager;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using static MaterialDesignThemes.Wpf.Theme;
|
||||
|
||||
namespace SamplePreSystem.UI.ViewModel.Child
|
||||
{
|
||||
public partial class ImportSampleViewModel: ObservableObject
|
||||
{
|
||||
|
||||
SampleSequenceBll sampleSequenceBll = new SampleSequenceBll();
|
||||
|
||||
|
||||
|
||||
SampleExecViewModel sampleExecViewModel;
|
||||
|
||||
// 关闭窗口的委托
|
||||
public Action<bool> CloseAction { get; set; }
|
||||
|
||||
|
||||
|
||||
public ImportSampleViewModel(SampleExecViewModel _sampleExecViewModel)
|
||||
{
|
||||
GetData();
|
||||
|
||||
sampleExecViewModel = _sampleExecViewModel;
|
||||
}
|
||||
|
||||
|
||||
private DateTime _startDate = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00");
|
||||
|
||||
public DateTime StartDate
|
||||
{
|
||||
get { return _startDate; }
|
||||
set
|
||||
{
|
||||
|
||||
|
||||
SetProperty(ref _startDate, value);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private DateTime _endDate = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00");
|
||||
|
||||
public DateTime EndDate
|
||||
{
|
||||
get { return _endDate; }
|
||||
set
|
||||
{
|
||||
|
||||
SetProperty(ref _endDate, value);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private List<tube_input_ext> _sampleList = new List<tube_input_ext>();
|
||||
|
||||
|
||||
public List<tube_input_ext> SampleList
|
||||
{
|
||||
get { return _sampleList; }
|
||||
set {
|
||||
|
||||
SetProperty(ref _sampleList, value);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void GetData()
|
||||
{
|
||||
//DateTime dt1 = DateTime.Parse(dt_start.DateTime.ToString("yyyy-MM-dd") + " 00:00:00");
|
||||
//DateTime dt2 = DateTime.Parse(dt_end.DateTime.ToString("yyyy-MM-dd") + " 23:00:00");
|
||||
|
||||
var templist = sampleSequenceBll.GetTubeData(StartDate, EndDate); ///
|
||||
|
||||
List<tube_input_ext> samples = new List<tube_input_ext>();
|
||||
|
||||
foreach(var item in templist)
|
||||
{
|
||||
item.bach_no = $"批号:{item.bach_no}";
|
||||
|
||||
tube_input_ext model = new tube_input_ext();
|
||||
model.qrcode = item.qrcode;
|
||||
model.item_name = item.item_name;
|
||||
model.tube_type = item.tube_type;
|
||||
model.standrad_id = item.standrad_id;
|
||||
model.standrad = item.standrad;
|
||||
model.input_user = item.input_user;
|
||||
model.input_date = item.input_date;
|
||||
model.weight = item.weight;
|
||||
model.tube_count = item.tube_count;
|
||||
model.bach_no = $"批号:{item.bach_no}";
|
||||
model.IsSelected = false;
|
||||
samples.Add(model);
|
||||
}
|
||||
|
||||
SampleList = samples;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public bool? IsAllItems1Selected
|
||||
{
|
||||
get
|
||||
{
|
||||
var selected = SampleList.Select(item => item.IsSelected).Distinct().ToList();
|
||||
return selected.Count == 1 ? selected.Single() : false;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value.HasValue)
|
||||
{
|
||||
SelectAll(value.Value, SampleList);
|
||||
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 选择所有
|
||||
/// </summary>
|
||||
/// <param name="select"></param>
|
||||
/// <param name="models"></param>
|
||||
private static void SelectAll(bool select, IEnumerable<tube_input_ext> models)
|
||||
{
|
||||
foreach (var model in models)
|
||||
{
|
||||
model.IsSelected = select;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 选择组内数据
|
||||
/// </summary>
|
||||
/// <param name="bachCode"></param>
|
||||
/// <param name="isSelect"></param>
|
||||
public void SelectGroupData(string bachCode, bool isSelect)
|
||||
{
|
||||
foreach (var item in SampleList.Where(p => p.bach_no == bachCode))
|
||||
{
|
||||
item.IsSelected = isSelect;
|
||||
}
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
public void FindClick()
|
||||
{
|
||||
|
||||
GetData();
|
||||
|
||||
ListCollectionView view = (ListCollectionView)CollectionViewSource.GetDefaultView(SampleList);//获取数据视图
|
||||
//分组
|
||||
view.GroupDescriptions.Add(new PropertyGroupDescription("bach_no"));
|
||||
}
|
||||
|
||||
|
||||
[RelayCommand]
|
||||
public void ImportClick()
|
||||
{
|
||||
List<tube_input> samples = new List<tube_input>();
|
||||
foreach (var tube in SampleList)
|
||||
{
|
||||
|
||||
if (tube.IsSelected)
|
||||
{
|
||||
samples.Add(tube);
|
||||
}
|
||||
}
|
||||
|
||||
this.sampleExecViewModel.TubeInputs = samples;
|
||||
|
||||
CloseAction?.Invoke(true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 选中导入项
|
||||
/// </summary>
|
||||
[RelayCommand]
|
||||
public void CheckBoxClick(object groupName)
|
||||
{
|
||||
System.Windows.Controls.CheckBox checkBox = groupName as System.Windows.Controls.CheckBox;
|
||||
if (checkBox != null)
|
||||
{
|
||||
bool select = (bool)checkBox.IsChecked;
|
||||
string code = checkBox.Content.ToString();
|
||||
|
||||
SelectGroupData(code, select);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user