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.Shapes; using Sln.Wcs.Model.Domain; using SqlSugar; namespace Sln_Wpf.Page { /// /// LocationStatisticsWindow.xaml 的交互逻辑 /// public partial class LocationStatisticsWindow : Window { private readonly ISqlSugarClient _db; public LocationStatisticsWindow(ISqlSugarClient db) { InitializeComponent(); _db = db; LoadStatistics(); } /// /// 加载统计数据 /// private async void LoadStatistics() { try { // 查询所有库位数据 var locations = await _db.Queryable().ToListAsync(); int total = locations.Count; int occupied = locations.Count(x => x.LocationStatus == 1); // 1-占用 int free = locations.Count(x => x.LocationStatus == 0); // 0-空闲 int maintenance = locations.Count(x => x.LocationStatus == 2); // 2-维护 // 更新显示 TxtTotalLocations.Text = total.ToString(); TxtOccupiedLocations.Text = occupied.ToString(); TxtFreeLocations.Text = free.ToString(); TxtMaintenanceLocations.Text = maintenance.ToString(); // 计算使用率 double usageRate = total > 0 ? (double)occupied / total * 100 : 0; TxtUsageRate.Text = $"{usageRate:F1}%"; UsageProgressBar.Value = usageRate; // 根据使用率改变进度条颜色 if (usageRate < 50) { UsageProgressBar.Foreground = new System.Windows.Media.SolidColorBrush( (System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#27AE60")); } else if (usageRate < 80) { UsageProgressBar.Foreground = new System.Windows.Media.SolidColorBrush( (System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#F39C12")); } else { UsageProgressBar.Foreground = new System.Windows.Media.SolidColorBrush( (System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#E74C3C")); } } catch (Exception ex) { MessageBox.Show($"加载统计数据失败: {ex.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error); } } /// /// 刷新按钮点击 /// private void BtnRefresh_Click(object sender, RoutedEventArgs e) { LoadStatistics(); } /// /// 关闭按钮点击 /// private void BtnClose_Click(object sender, RoutedEventArgs e) { this.Close(); } private void BtnCloseBottom_Click(object sender, RoutedEventArgs e) { this.Close(); } /// /// 窗口拖拽 /// private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { if (e.ButtonState == MouseButtonState.Pressed) { this.DragMove(); } } } }