diff --git a/SlnMesnac.WPF/MainWindow.xaml b/SlnMesnac.WPF/MainWindow.xaml index 18342e9..1400919 100644 --- a/SlnMesnac.WPF/MainWindow.xaml +++ b/SlnMesnac.WPF/MainWindow.xaml @@ -72,6 +72,7 @@ + + + + + + + + + + + + + + + + diff --git a/SlnMesnac.WPF/Page/LocationPage.xaml.cs b/SlnMesnac.WPF/Page/LocationPage.xaml.cs new file mode 100644 index 0000000..c0619b2 --- /dev/null +++ b/SlnMesnac.WPF/Page/LocationPage.xaml.cs @@ -0,0 +1,145 @@ +using Microsoft.Extensions.DependencyInjection; +using SlnMesnac.Model.domain; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace SlnMesnac.WPF.Page +{ + /// + /// LocationPage.xaml 的交互逻辑 + /// + public partial class LocationPage : UserControl + { + + private readonly ISqlSugarClient? sqlSugarClient; + public LocationPage() + { + InitializeComponent(); + sqlSugarClient = App.ServiceProvider.GetService(); + this.WareHouseId.ItemsSource = new List + { + "二楼仓库","三楼仓库","五楼仓库" + }; + WareHouseId.SelectedItem = "三楼仓库"; + Refresh(); + } + + private void Refresh() + { + try + { + + string? wareHouse = WareHouseId.SelectedItem.ToString(); + var warehouseId = new List(); + if (wareHouse == "二楼仓库") + { + warehouseId.Add(231); + } + else if (wareHouse == "三楼仓库") + { + warehouseId.Add(311); + } + else if (wareHouse == "五楼仓库") + { + warehouseId.Add(511); + warehouseId.Add(521); + warehouseId.Add(531); + } + List list = sqlSugarClient.AsTenant().GetConnection("mes").Queryable().Where(t => warehouseId.Contains(t.WarehouseId)).ToList(); + if (list != null && list.Count > 0) + { + loadLocations(list); + } + }catch(Exception ex) + { + Console.WriteLine(ex.Message); + } + } + + + private void Refulsh_Click(object sender, RoutedEventArgs e) + { + Refresh(); + } + + + private void WarehouseChanged(object sender, SelectionChangedEventArgs e) + { + Refresh(); + } + + + private void loadLocations(List wmsBaseLocations) + { + try + { + if (wmsBaseLocations == null || wmsBaseLocations.Count == 0) + { + return; + } + Dispatcher.Invoke(() => + { + this.LocaltionGrid.Children.Clear(); + this.LocaltionGrid.RowDefinitions.Clear(); + this.LocaltionGrid.ColumnDefinitions.Clear(); + List list = wmsBaseLocations.Select(t => t.WarehouseId).Distinct().ToList(); + int? column = 0; + for (var i = 0; i < list.Count; i++) + { + this.LocaltionGrid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1.0, GridUnitType.Star) }); + var grid = new Grid(); + List locations = wmsBaseLocations.Where(t => t.WarehouseId == list[i]).ToList(); + var row = locations.Max(t => t.LocRow); + column = locations.Max(t => t.LocColumn); + + for (var j = 0; j < row; j++) + { + grid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1.0, GridUnitType.Star) }); + } + for (var j = 0; j < column; j++) + { + grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1.0, GridUnitType.Star) }); + } + foreach (var location in locations) + { + var button = new Button() + { + Name = $"Location{location.LocationCode}", + Content = location.LocationCode, + Width = 50, + Height = 50, + Margin = new Thickness(2), + Tag = location.LocationId, + Background = string.IsNullOrEmpty(location.ContainerCode) ? new SolidColorBrush((Color)ColorConverter.ConvertFromString("#4789AE")) : new SolidColorBrush((Color)ColorConverter.ConvertFromString("#75F76D")) + }; + // button.Click += OnLocationButton_Click; + Grid.SetColumn(button, location.LocColumn.Value - 1); + Grid.SetRow(button, -(location.LocRow.Value - row.Value)); + grid.Children.Add(button); + } + Grid.SetRow(grid, i); + this.LocaltionGrid.Children.Add(grid); + } + }); + } + catch + { + + } + + } + } +} diff --git a/SlnMesnac.WPF/ViewModel/MainWindowViewModel.cs b/SlnMesnac.WPF/ViewModel/MainWindowViewModel.cs index 2a698bc..2e47543 100644 --- a/SlnMesnac.WPF/ViewModel/MainWindowViewModel.cs +++ b/SlnMesnac.WPF/ViewModel/MainWindowViewModel.cs @@ -31,6 +31,8 @@ namespace SlnMesnac.WPF.ViewModel private readonly DebugConfig debugConfig = DebugConfig.Instance; private readonly DevMonitorPage devMonitorPage = new DevMonitorPage(); private readonly ProdMgmtPage prodMgmtPage = new ProdMgmtPage(); + private readonly LocationPage locationPage = new LocationPage(); + private readonly ProdStatisticsPage prodStatisticsPage = new ProdStatisticsPage(); //代码生成 private readonly GenerateControl generateControl = new GenerateControl(); @@ -344,6 +346,11 @@ namespace SlnMesnac.WPF.ViewModel UserContent = agvAndTaskMonitorPage; PageName = "AGV监听"; break; + case "LocationPage": + UserContent = locationPage; + PageName = "库位信息"; + break; + // 还原 或者 最大化当前窗口 case "Normal": if (Application.Current.MainWindow.WindowState == WindowState.Normal)