123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260 |
- using Mapster;
- using Prism.Commands;
- using Prism.Events;
- using Prism.Services.Dialogs;
- using ProjectManagementSystem.Common.Config;
- using ProjectManagementSystem.Common.Extenions;
- using ProjectManagementSystem.Common.Function;
- using ProjectManagementSystem.Common.Logger;
- using ProjectManagementSystem.Common.Models;
- using ProjectManagementSystem.Common.Models.Crms;
- using ProjectManagementSystem.Common.Service;
- using ProjectManagementSystem.Language;
- using ProjectManagementSystemView.Infrastructure;
- using ProjectManagementSystemView.Infrastructure.Events;
- using ProjectManagementSystemView.Infrastructure.Extensions;
- 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
- {
- [AddINotifyPropertyChangedInterface]
- public class WmsQueryViewModel
- {
- private List<string> wareHouses;
- protected readonly IDialogHostService dialogService;
- public bool IsVisible { get; set; }
- [OnChangedMethod(nameof(ReloadLayout))]
- public string WareHouseCode { get; set; }
- public VmLocationProperty SelectedVmData { get; set; }
- public ObservableCollection<VmLocationProperty> VmDatas { get; set; } = new ObservableCollection<VmLocationProperty>();
- public ObservableCollection<string> WareHouseCollection { get; set; } = new ObservableCollection<string>();
- public DelegateCommand LoadedCommand { get; private set; }
- public DelegateCommand ModifyCommand { get; private set; }
- public DelegateCommand<string> TaskCallCommand { get; private set; }
- public DelegateCommand<string> TaskTransportCommand { get; private set; }
- public DelegateCommand ReleaseAgvCommand { get; private set; }
- public WmsQueryViewModel(IDialogHostService dialogService, IEventAggregator eventAggregator)
- {
- this.dialogService = dialogService;
- var wareHouseFilters = AppSetting.TryGetValue<string>("WareHouseFilter1").ToValueArray<string>().ToList();
- var wareHouseList = ExcelConfig.Instance.RouteConfigList
- .Where(d => !string.IsNullOrEmpty(d.Area))
- .Where(d =>
- {
- if (wareHouseFilters.Count == 0) return true;
- return wareHouseFilters.Contains(d.Area);
- })
- .GroupBy(d => d.Area)
- .Select(d => d.Key)
- .OrderBy(d => wareHouseFilters.IndexOf(d));
- wareHouses = wareHouseFilters.Count == 0 ?
- wareHouseList.OrderBy(d => d).ToList() :
- wareHouseList.ToList();
- wareHouses.ForEach(p => WareHouseCollection.Add(p));
- if (wareHouseFilters.Count == 0)
- {
- WareHouseCollection.Add(string.Empty);
- WareHouseCode = WareHouseCollection.Last();
- }
- else
- {
- WareHouseCode = WareHouseCollection.First();
- }
- LoadedCommand = new DelegateCommand(Loaded);
- ModifyCommand = new DelegateCommand(ModifyAsync);
- TaskCallCommand = new DelegateCommand<string>((arg) => SimpleTaskAddAsync(arg, null, SelectedVmData));
- TaskTransportCommand = new DelegateCommand<string>((arg) => SimpleTaskAddAsync(arg, SelectedVmData, null));
- ReleaseAgvCommand = new DelegateCommand(ReleaseAgv);
- ResourceService.Current.CultureChanged += d => ReloadLayout();
- eventAggregator.GetEvent<UpdateViewEvent>().Subscribe(Read);
- }
- private void Read()
- {
- if (!IsVisible) return;
- try
- {
- var res = Crms.PmsTaskService.GetLocationProperty(new LocationPropertyQueryDto() { Area = WareHouseCode });
- var dataList = res?.data as List<LocationPropertyDto>;
- UpdateVmDatas(dataList);
- }
- catch (Exception ex)
- {
- HandyControl.Controls.Growl.Error(ex.Message);
- }
- }
- protected virtual void UpdateVmDatas(List<LocationPropertyDto> dataList)
- {
- VmDatas.Update(dataList, (s, v) => s.LocationCode == v.LocationCode);
- }
- protected virtual void Loaded()
- {
- }
- protected virtual void ReloadLayout()
- {
- VmDatas.Clear();
- }
- private async void ModifyAsync()
- {
- try
- {
- if (SelectedVmData == null) return;
- DialogParameters param = new DialogParameters();
- param.Add("Value", SelectedVmData);
- var dialogResult = await dialogService.ShowDialog("ModifyWmsView", param);
- if (dialogResult.Result == ButtonResult.OK)
- {
- var data = dialogResult.Parameters.GetValue<VmLocationProperty>("Value");
- UpdateLocation(data);
- }
- }
- catch (Exception ex)
- {
- CLog.Instance.SystemLog.WriteExceptionCaller(ex);
- }
- }
- private async void SimpleTaskAddAsync(string arg, VmLocationProperty value1, VmLocationProperty value2)
- {
- try
- {
- if (value1 == null && value2 == null) return;
- if (value1 != null && value2 == null)
- {
- var temp = value1.LocationCode.GetLocationMember("目标仓库");
- var temp2 = value1.LocationCode.GetLocationMember("目标仓位");
- if (string.IsNullOrEmpty(temp) && string.IsNullOrEmpty(temp2))
- {
- HandyControl.Controls.Growl.Info($"{value1.LocationCode} {Langs.TargetWarehouseNotConfigured}");
- return;
- }
- }
- if (value1 == null && value2 != null)
- {
- var temp = value2.LocationCode.GetLocationMember("源仓库");
- var temp2 = value2.LocationCode.GetLocationMember("源仓位");
- if (string.IsNullOrEmpty(temp) && string.IsNullOrEmpty(temp2))
- {
- HandyControl.Controls.Growl.Info($"{value2.LocationCode} {Langs.SourceWarehouseNotConfigured}");
- return;
- }
- }
- DialogParameters param = new DialogParameters();
- param.Add("Title", arg);
- param.Add("Value1", value1);
- param.Add("Value2", value2);
- var dialogResult = await dialogService.ShowDialog("SimpleTaskView", param);
- if (dialogResult.Result == ButtonResult.OK)
- {
- try
- {
- var data1 = dialogResult.Parameters.GetValue<VmLocationProperty>("Value1");
- var data2 = dialogResult.Parameters.GetValue<VmLocationProperty>("Value2");
- var dto = new PmsTaskInfoDto();
- dto.WareHouseCode = data1.WareHouseCode;
- dto.LocationCode = data1.LocationCode;
- dto.MaterialId = data1.MaterialId;
- dto.TargetWareHouseCode = data2.WareHouseCode;
- dto.TargetLocationCode = data2.LocationCode;
- var result = PmsCustomApi.Post<object>("TaskAdd", dto);
- if (result.code == 20000)
- {
- HandyControl.Controls.Growl.Success(result.message);
- }
- else
- {
- HandyControl.Controls.Growl.Warning(result.message);
- }
- }
- catch (Exception ex)
- {
- CLog.Instance.SystemLog.WriteExceptionCaller(ex);
- }
- }
- }
- catch (Exception ex)
- {
- CLog.Instance.SystemLog.WriteExceptionCaller(ex);
- }
- }
- private void UpdateLocation(VmLocationProperty locationData)
- {
- try
- {
- if (string.IsNullOrEmpty(locationData?.LocationCode)) return;
- var dto = locationData.Adapt<LocationPropertyUpdateDto>();
- var result = PmsCustomApi.Post<object>("UpdateLocationProperty", dto);
- if (result.code == 20000)
- {
- HandyControl.Controls.Growl.Success(result.message);
- }
- else
- {
- HandyControl.Controls.Growl.Warning(result.message);
- }
- }
- catch (Exception ex)
- {
- CLog.Instance.SystemLog.WriteExceptionCaller(ex);
- }
- }
- private void ReleaseAgv()
- {
- try
- {
- var dto = new { LocationCode = SelectedVmData?.LocationCode };
- var result = PmsCustomApi.Post<object>("ReleaseAgv", dto);
- if (result.code == 20000)
- {
- HandyControl.Controls.Growl.Success(result.message);
- }
- else
- {
- HandyControl.Controls.Growl.Warning(result.message);
- }
- }
- catch (Exception ex)
- {
- CLog.Instance.SystemLog.WriteExceptionCaller(ex);
- }
- }
- }
- }
|