123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233 |
- using Mapster;
- using MaterialDesignThemes.Wpf;
- using Prism.Commands;
- using Prism.Services.Dialogs;
- using ProjectManagementSystem.Common.Config;
- using ProjectManagementSystem.Common.Extenions;
- using ProjectManagementSystem.Common.Models;
- using ProjectManagementSystem.Common.Service;
- using ProjectManagementSystemView.Infrastructure;
- using ProjectManagementSystemView.Infrastructure.Models;
- using PropertyChanged;
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ProjectManagementSystemView.ViewModels.Dialogs
- {
- [AddINotifyPropertyChangedInterface]
- public class SimpleTaskViewModel : IDialogHostAware
- {
- public ObservableCollection<string> WareHouseCodeCollection1 { get; set; }
- public ObservableCollection<string> LocationCodeCollection1 { get; set; }
- public ObservableCollection<string> MaterialIdCollection { get; set; }
- public ObservableCollection<string> WareHouseCodeCollection2 { get; set; }
- public ObservableCollection<string> LocationCodeCollection2 { get; set; }
- public string Title { get; set; }
- public bool IsTaskCall { get; set; }
- public bool IsTaskTransport { get; set; }
- [OnChangedMethod(nameof(OnSourceWareHouseCodeChanged))]
- public string SourceWareHouseCode { get; set; }
- [OnChangedMethod(nameof(OnSourceLocationCodeChanged))]
- public string SourceLocationCode { get; set; }
- public string SourceMaterialId { get; set; }
- [OnChangedMethod(nameof(OnTargetWareHouseCodeChanged))]
- public string TargetWareHouseCode { get; set; }
- public string TargetLocationCode { get; set; }
- public string DialogHostName { get; set; }
- public DelegateCommand SaveCommand { get; set; }
- public DelegateCommand CancelCommand { get; set; }
- public SimpleTaskViewModel()
- {
- WareHouseCodeCollection1 = new ObservableCollection<string>();
- LocationCodeCollection1 = new ObservableCollection<string>();
- MaterialIdCollection = new ObservableCollection<string>();
- WareHouseCodeCollection2 = new ObservableCollection<string>();
- LocationCodeCollection2 = new ObservableCollection<string>();
- SaveCommand = new DelegateCommand(Save);
- CancelCommand = new DelegateCommand(Cancel);
- }
- private void OnSourceWareHouseCodeChanged()
- {
- LocationCodeCollection1.Clear();
- var res = Crms.PmsTaskService.GetLocationProperty(new LocationPropertyQueryDto() { WareHouseCode = SourceWareHouseCode });
- var dataList = res?.data as List<LocationPropertyDto>;
- dataList?.ForEach(p => LocationCodeCollection1.Add(p.LocationCode));
- LocationCodeCollection1.Add("");
- MaterialIdCollection.Clear();
- var mDataList = dataList.Where(d => !string.IsNullOrEmpty(d.MaterialId)).Select(d => d.MaterialId).Distinct().ToList();
- mDataList.ForEach(p => MaterialIdCollection.Add(p));
- MaterialIdCollection.Add("");
- }
- private void OnTargetWareHouseCodeChanged()
- {
- LocationCodeCollection2.Clear();
- var res = Crms.PmsTaskService.GetLocationProperty(new LocationPropertyQueryDto() { WareHouseCode = TargetWareHouseCode });
- var dataList = res?.data as List<LocationPropertyDto>;
- dataList?.ForEach(p => LocationCodeCollection2.Add(p.LocationCode));
- LocationCodeCollection2.Add("");
- }
- private void OnSourceLocationCodeChanged()
- {
- if (string.IsNullOrEmpty(SourceLocationCode))
- {
- OnSourceWareHouseCodeChanged();
- return;
- }
- var res = Crms.PmsTaskService.GetLocationProperty(new LocationPropertyQueryDto() { LocationCode = SourceLocationCode });
- var dataList = res?.data as List<LocationPropertyDto>;
- var data = dataList?.FirstOrDefault();
- if (data != null)
- {
- MaterialIdCollection.Clear();
- MaterialIdCollection.Add(data.MaterialId);
- SourceMaterialId = data.MaterialId;
- }
- }
- /// <summary>
- /// 取消
- /// </summary>
- private void Cancel()
- {
- if (DialogHost.IsDialogOpen(DialogHostName))
- DialogHost.Close(DialogHostName, new DialogResult(ButtonResult.No)); //取消返回NO告诉操作结束
- }
- /// <summary>
- /// 确定
- /// </summary>
- private void Save()
- {
- if (DialogHost.IsDialogOpen(DialogHostName))
- {
- var model1 = new VmLocationProperty()
- {
- WareHouseCode = SourceWareHouseCode,
- LocationCode = SourceLocationCode,
- MaterialId = SourceMaterialId
- };
- var model2 = new VmLocationProperty()
- {
- WareHouseCode = TargetWareHouseCode,
- LocationCode = TargetLocationCode
- };
- //确定时,把编辑的实体返回并且返回OK
- DialogParameters param = new DialogParameters();
- param.Add("Value1", model1);
- param.Add("Value2", model2);
- DialogHost.Close(DialogHostName, new DialogResult(ButtonResult.OK, param));
- }
- }
- public void OnDialogOpend(IDialogParameters parameters)
- {
- if (parameters.ContainsKey("Value1") && parameters.ContainsKey("Value2"))
- {
- Title = parameters.GetValue<string>("Title");
- var data1 = parameters.GetValue<VmLocationProperty>("Value1");
- var data2 = parameters.GetValue<VmLocationProperty>("Value2");
- WareHouseCodeCollection1.Clear();
- LocationCodeCollection1.Clear();
- MaterialIdCollection.Clear();
- WareHouseCodeCollection2.Clear();
- LocationCodeCollection2.Clear();
- IsTaskCall = data1 == null && data2 != null;
- IsTaskTransport = data1 != null && data2 == null;
- if (IsTaskTransport)
- {
- WareHouseCodeCollection1.Add(data1.WareHouseCode);
- LocationCodeCollection1.Add(data1.LocationCode);
- MaterialIdCollection.Add(data1.MaterialId);
- SourceWareHouseCode = data1.WareHouseCode;
- SourceLocationCode = data1.LocationCode;
- SourceMaterialId = data1.MaterialId;
- var targetLocations = data1.LocationCode.GetLocationMember("目标仓位").ToValueArray<string>();
- if (targetLocations.Length > 0)
- {
- foreach (var location in targetLocations)
- {
- LocationCodeCollection2.Add(location);
- }
- TargetLocationCode = targetLocations.First();
- }
- else
- {
- var arr = data1.LocationCode.GetLocationMember("目标仓库").ToValueArray<string>();
- for (int i = 0; i < arr.Length; i++)
- {
- WareHouseCodeCollection2.Add(arr[i]);
- }
- if (arr.Length > 0)
- {
- TargetWareHouseCode = arr[0];
- }
- }
- }
- if (IsTaskCall)
- {
- var sourceLocations = data2.LocationCode.GetLocationMember("源仓位").ToValueArray<string>();
- if (sourceLocations.Length > 0)
- {
- foreach (var location in sourceLocations)
- {
- LocationCodeCollection1.Add(location);
- }
- SourceLocationCode = sourceLocations.First();
- }
- else
- {
- var arr = data2.LocationCode.GetLocationMember("源仓库").ToValueArray<string>();
- for (int i = 0; i < arr.Length; i++)
- {
- WareHouseCodeCollection1.Add(arr[i]);
- }
- if (arr.Length > 0)
- {
- SourceWareHouseCode = arr[0];
- }
- }
- WareHouseCodeCollection2.Add(data2.WareHouseCode);
- LocationCodeCollection2.Add(data2.LocationCode);
- TargetWareHouseCode = data2.WareHouseCode;
- TargetLocationCode = data2.LocationCode;
- }
- }
- }
- }
- }
|