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.

249 lines
6.9 KiB
C#

using Admin.Core.IService;
using Admin.Core.Model;
using Aucma.Scada.UI.Common;
using Aucma.Scada.UI.Page.AssemblyPlan;
using Aucma.Scada.UI;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using SqlSugar;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Input;
namespace Aucma.Scada.UI.ViewModel.AssemblyPlan
{
public partial class PlanInfoEditViewModel : ObservableObject
{
private AssemblyPlanBusiness assemblyPlanBusiness = new AssemblyPlanBusiness();// AssemblyPlanBusiness.Instance;
public ObservableCollection<string> RadioOptions { get; set; }
private AppConfig appConfig = new AppConfig();//AppConfig.Instance;
public PlanInfoEditViewModel()
{
//RadioOptions = new ObservableCollection<string>
//{
// "Option 1",
// "Option 2",
// "Option 3",
// "Option 4",
// "Option 5",
// "Option 6",
// "Option 7",
// "Option 8",
// "Option 9",
// "Option 10"
//};
init();
Query();
}
#region 参数定义
private string _search = string.Empty;
public string Search
{
get => _search;
set => SetProperty(ref _search, value);
}
/// <summary>
/// 下拉框
/// </summary>
public string _materialTypeCombox;
public string MaterialTypeCombox
{
get => _materialTypeCombox;
set => SetProperty(ref _materialTypeCombox, value);
}
/// <summary>
/// 生产计划编号
/// </summary>
private string _ProductPlanCode = string.Empty;
public string ProductPlanCode
{
get => _ProductPlanCode;
set => SetProperty(ref _ProductPlanCode, value);
}
/// <summary>
/// 物料编号
/// </summary>
private string _MaterialCode = string.Empty;
public string MaterialCode
{
get => _MaterialCode;
set => SetProperty(ref _MaterialCode, value);
}
/// <summary>
/// 物料编号
/// </summary>
private int _TransmitAmount = 0;
public int TransmitAmount
{
get => _TransmitAmount;
set => SetProperty(ref _TransmitAmount, value);
}
private ProductPlanInfo selectedDataItem;
public ProductPlanInfo SelectedDataItem
{
get => selectedDataItem;
set => SetProperty(ref selectedDataItem, value);
}
/// <summary>
/// 计划列表DataGrid
/// </summary>
private ObservableCollection<ProductPlanInfo> planInfoDataGrid;
public ObservableCollection<ProductPlanInfo> PlanInfoDataGrid
{
get => planInfoDataGrid;
set => SetProperty(ref planInfoDataGrid, value);
}
private ObservableCollection<string> _configurations = new ObservableCollection<string>();
public ObservableCollection<string> Configurations
{
get => _configurations;
set => SetProperty(ref _configurations, value);
}
#endregion
private void init()
{
Configurations = new ObservableCollection<string>();
var searchItems = appConfig.searchItems;
var split = searchItems.Trim().Split('%');
foreach (var item in split)
{
if (string.IsNullOrEmpty(item.Trim())) continue;
Configurations.Add(item);
}
}
[RelayCommand]
public async void RadioButtonClicked(string selectedOption)
{
List<ProductPlanInfo> planInfos =await assemblyPlanBusiness.GetProductPlanInfosByProductLineCode(_search);
if (planInfos != null)
{
PlanInfoDataGrid = new ObservableCollection<ProductPlanInfo>();
if (planInfos.Count > 0)
{
planInfos.ForEach(
arg =>
{
if (arg.MaterialName.Contains(selectedOption))
{
PlanInfoDataGrid.Add(arg);
}
});
}
}
}
/// <summary>
/// 箱壳入库任务列表查询
/// </summary>
[RelayCommand]
public async void Query()
{
init();
List<ProductPlanInfo> planInfos =await assemblyPlanBusiness.GetProductPlanInfosByProductLineCode(_search);
PlanInfoDataGrid = new ObservableCollection<ProductPlanInfo>();
if (planInfos != null)
{
planInfos.ForEach(
arg =>
{
PlanInfoDataGrid.Add(arg);
});
}
}
/// <summary>
/// 重置
/// </summary>
[RelayCommand]
public void Reset()
{
init();
Search = string.Empty;
MaterialTypeCombox = string.Empty;
this.Query();
}
/// <summary>
/// 搜索条件设置
/// </summary>
[RelayCommand]
public void SearchCriteriaSet()
{
SearchCriteriaWindow searchCriteriaWindow = new SearchCriteriaWindow();
bool? dialogResult = searchCriteriaWindow.ShowDialog();
if (dialogResult == false) // 用户点击了“取消”按钮或关闭窗口
{
init();
}
}
[RelayCommand]
private async void PlanInfoTransmit()
{
bool result =await assemblyPlanBusiness.PlanTransmitByProductPlan(_ProductPlanCode, _TransmitAmount);
if (result)
{
MessageBox.Show("执行计划维护成功", "提示", MessageBoxButton.OK, MessageBoxImage.Information, MessageBoxResult.OK, MessageBoxOptions.DefaultDesktopOnly);
}
}
[RelayCommand]
public void MouseClick(object obj)
{
//TransmitAmount = 0;
var info = SelectedDataItem as ProductPlanInfo;
if (info != null)
{
//ProductPlanCode = info.planCode;
//MaterialCode = info.materialName;
QuantityIssuedWindow quantityIssuedWindow = new QuantityIssuedWindow(info);
quantityIssuedWindow.ShowDialog();
}
}
[RelayCommand]
private void CloseWindow(object parameter)
{
var window = parameter as Window;
if (window != null)
{
window.Close();
}
}
}
}