123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
- using Prism.Commands;
- using Prism.Events;
- using ProjectManagementSystem.Common.Config;
- using ProjectManagementSystem.Common.Function;
- using ProjectManagementSystem.Common.Models;
- using ProjectManagementSystem.Language;
- using ProjectManagementSystemView.Infrastructure;
- using ProjectManagementSystemView.Infrastructure.Extensions;
- using PropertyChanged;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ProjectManagementSystemView.ViewModels
- {
- [AddINotifyPropertyChangedInterface]
- public class Wms2DViewModel : WmsQueryViewModel
- {
- private int sWidth;
- private int sHeight;
- private double multipleX;
- private double multipleY;
- private double offsetX;
- private double offsetY;
- public double GridHeight { get; set; }
- public double GridWidth { get; set; }
- public double Scale { get; set; }
- public double TranslateX { get; set; }
- public double TranslateY { get; set; }
- public DelegateCommand ResetLayoutCommand { get; private set; }
- public DelegateCommand SaveLayoutCommand { get; private set; }
- public Wms2DViewModel(IDialogHostService dialogService, IEventAggregator eventAggregator) : base(dialogService, eventAggregator)
- {
- sWidth = AppSetting.TryGetValue<int>("StationUIWidth");
- sHeight = AppSetting.TryGetValue<int>("StationUIHeight");
- Scale = AppSetting.TryGetValue<double>(nameof(Scale));
- TranslateX = AppSetting.TryGetValue<double>(nameof(TranslateX));
- TranslateY = AppSetting.TryGetValue<double>(nameof(TranslateY));
- Scale = Scale <= 0 ? 1 : Scale;
- ResetLayoutCommand = new DelegateCommand(ResetLayout);
- SaveLayoutCommand = new DelegateCommand(SaveLayout);
- }
- protected override void UpdateVmDatas(List<LocationPropertyDto> dataList)
- {
- var buttonPropertyDict = ExcelConfig.Instance.ButtonPropertyDict;
- var routeConfifDict = ExcelConfig.Instance.RouteConfigDictionary;
- VmDatas.Update(dataList, (s, v) => s.LocationCode == v.LocationCode,
- (s, v) =>
- {
- if (buttonPropertyDict.TryGetValue(v.LocationCode, out CButton cButton))
- {
- if (v.X == 0 && v.Y == 0)
- {
- v.X = cButton.LocationX;
- v.Y = cButton.LocationY;
- }
- }
- else
- {
- if (routeConfifDict.TryGetValue(v.LocationCode, out RouteConfig config))
- {
- v.X = (Math.Abs(config.X + offsetX) * multipleX) + 5;
- v.Y = (Math.Abs(config.Y + offsetY) * multipleY) + 5;
- var cb = new CButton()
- {
- ButtonName = v.LocationCode,
- LocationX = v.X,
- LocationY = v.Y
- };
- buttonPropertyDict.Add(v.LocationCode, cb);
- }
- }
- v.XLength = sWidth;
- v.YLength = sHeight;
- });
- }
- private void GetLocationXY()
- {
- if (GridWidth == 0 && GridHeight == 0) return;
- var configList = string.IsNullOrEmpty(WareHouseCode) ?
- ExcelConfig.Instance.RouteConfigList.Where(d => !string.IsNullOrEmpty(d.Area)).ToList() :
- ExcelConfig.Instance.RouteConfigList.Where(d => d.Area == WareHouseCode).ToList();
- if (configList.Count == 0) return;
- double MinX = configList.Min(d => d.X);
- double MaxX = configList.Max(d => d.X);
- double MinY = configList.Min(d => d.Y);
- double MaxY = configList.Max(d => d.Y);
- if (MinX == 0 && MaxX == 0 && MinY == 0 && MaxY == 0)
- {
- return;
- }
- double DistanceX = Math.Abs(MaxX - MinX);
- double DistanceY = Math.Abs(MaxY - MinY);
- if (DistanceX < GridWidth) DistanceX = GridWidth * 10;
- if (DistanceY < GridHeight) DistanceY = GridHeight * 10;
- multipleX = GridWidth * 0.85 / DistanceX;
- multipleY = GridHeight * 0.85 / DistanceY;
- multipleX = multipleX < 0.03 ? 0.03 : multipleX;
- multipleY = multipleY < 0.03 ? 0.03 : multipleY;
- offsetX = 0 - MinX;
- offsetY = 0 - MaxY;
- }
- protected override void Loaded()
- {
- GetLocationXY();
- }
- protected override void ReloadLayout()
- {
- GetLocationXY();
- VmDatas.Clear();
- }
- private void ResetLayout()
- {
- GetLocationXY();
- var buttonPropertyDict = ExcelConfig.Instance.ButtonPropertyDict;
- for (int i = 0; i < VmDatas.Count; i++)
- {
- string locationCode = VmDatas[i].LocationCode;
- if (!string.IsNullOrEmpty(locationCode))
- {
- buttonPropertyDict.Remove(locationCode);
- }
- }
- var config = string.IsNullOrEmpty(WareHouseCode) ?
- ExcelConfig.Instance.RouteConfigList.FirstOrDefault(d => !string.IsNullOrEmpty(d.Area)) :
- ExcelConfig.Instance.RouteConfigList.FirstOrDefault(d => d.Area == WareHouseCode);
- Scale = 1;
- TranslateX = config == null ? 0 : 0 - (Math.Abs(config.X + offsetX) * multipleX);
- TranslateY = config == null ? 0 : 0 - (Math.Abs(config.Y + offsetY) * multipleY);
- VmDatas.Clear();
- }
- private void SaveLayout()
- {
- var buttonPropertyDict = ExcelConfig.Instance.ButtonPropertyDict;
- foreach (var v in VmDatas)
- {
- if (buttonPropertyDict.TryGetValue(v.LocationCode, out CButton cButton))
- {
- cButton.LocationX = v.X;
- cButton.LocationY = v.Y;
- }
- }
- if (!ExcelConfig.Instance.SaveButtonPropertyList())
- {
- HandyControl.Controls.Growl.Error(Langs.SaveLayoutFailed);
- }
- var dict = new Dictionary<string, string>();
- dict.Add(nameof(Scale), Scale.ToString());
- dict.Add(nameof(TranslateX), TranslateX.ToString());
- dict.Add(nameof(TranslateY), TranslateY.ToString());
- if (!AppSetting.TrySaveValues(dict))
- {
- HandyControl.Controls.Growl.Error($"AppSetting:{Langs.SaveLayoutFailed}");
- }
- VmDatas.Clear();
- }
- }
- }
|