You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Sln.Wcs/Sln_Wpf/Page/LocationStatisticsWindow.xa...

115 lines
3.7 KiB
C#

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
{
/// <summary>
/// LocationStatisticsWindow.xaml 的交互逻辑
/// </summary>
public partial class LocationStatisticsWindow : Window
{
private readonly ISqlSugarClient _db;
public LocationStatisticsWindow(ISqlSugarClient db)
{
InitializeComponent();
_db = db;
LoadStatistics();
}
/// <summary>
/// 加载统计数据
/// </summary>
private async void LoadStatistics()
{
try
{
// 查询所有库位数据
var locations = await _db.Queryable<BaseLocation>().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);
}
}
/// <summary>
/// 刷新按钮点击
/// </summary>
private void BtnRefresh_Click(object sender, RoutedEventArgs e)
{
LoadStatistics();
}
/// <summary>
/// 关闭按钮点击
/// </summary>
private void BtnClose_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
private void BtnCloseBottom_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
/// <summary>
/// 窗口拖拽
/// </summary>
private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (e.ButtonState == MouseButtonState.Pressed)
{
this.DragMove();
}
}
}
}