294 lines
9.5 KiB
C#
294 lines
9.5 KiB
C#
using Microsoft.Win32;
|
|
using OrpaonVision.ConfigApp.ViewModels;
|
|
using OrpaonVision.Core.Abstractions;
|
|
using OrpaonVision.Model.Production;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Input;
|
|
|
|
namespace OrpaonVision.ConfigApp.Views;
|
|
|
|
/// <summary>
|
|
/// 产品会话管理窗口。
|
|
/// </summary>
|
|
public partial class ProductionSessionManagementWindow : Window
|
|
{
|
|
private readonly ProductionSessionManagementViewModel _viewModel;
|
|
|
|
/// <summary>
|
|
/// 构造函数。
|
|
/// </summary>
|
|
public ProductionSessionManagementWindow(ProductionSessionManagementViewModel viewModel)
|
|
{
|
|
_viewModel = viewModel;
|
|
InitializeComponent();
|
|
DataContext = _viewModel;
|
|
|
|
InitializeControls();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 初始化控件。
|
|
/// </summary>
|
|
private void InitializeControls()
|
|
{
|
|
// 初始化筛选条件
|
|
InitializeFilterControls();
|
|
|
|
// 绑定数据
|
|
SessionsDataGrid.ItemsSource = _viewModel.Sessions;
|
|
ProductTypeStatisticsDataGrid.ItemsSource = _viewModel.Statistics?.ByProductType;
|
|
StationStatisticsDataGrid.ItemsSource = _viewModel.Statistics?.ByStation;
|
|
OperatorStatisticsDataGrid.ItemsSource = _viewModel.Statistics?.ByOperator;
|
|
|
|
// 订阅属性变化事件
|
|
_viewModel.PropertyChanged += (sender, e) =>
|
|
{
|
|
if (e.PropertyName == nameof(_viewModel.Sessions))
|
|
{
|
|
SessionsDataGrid.ItemsSource = _viewModel.Sessions;
|
|
UpdatePageInfo();
|
|
UpdateRecordCount();
|
|
}
|
|
else if (e.PropertyName == nameof(_viewModel.Statistics))
|
|
{
|
|
UpdateStatisticsDisplay();
|
|
}
|
|
else if (e.PropertyName == nameof(_viewModel.StatusText))
|
|
{
|
|
StatusTextBlock.Text = _viewModel.StatusText;
|
|
}
|
|
};
|
|
|
|
UpdatePageInfo();
|
|
UpdateRecordCount();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 初始化筛选控件。
|
|
/// </summary>
|
|
private void InitializeFilterControls()
|
|
{
|
|
// 产品类型
|
|
ProductTypeComboBox.Items.Add(new ComboBoxItem { Content = "全部", Tag = "" });
|
|
ProductTypeComboBox.Items.Add(new ComboBoxItem { Content = "VFD-001", Tag = "VFD-001" });
|
|
ProductTypeComboBox.Items.Add(new ComboBoxItem { Content = "VFD-002", Tag = "VFD-002" });
|
|
ProductTypeComboBox.SelectedIndex = 0;
|
|
|
|
// 工位
|
|
StationComboBox.Items.Add(new ComboBoxItem { Content = "全部", Tag = "" });
|
|
StationComboBox.Items.Add(new ComboBoxItem { Content = "装配工位1", Tag = "ST-001" });
|
|
StationComboBox.Items.Add(new ComboBoxItem { Content = "装配工位2", Tag = "ST-002" });
|
|
StationComboBox.SelectedIndex = 0;
|
|
|
|
// 操作员
|
|
OperatorComboBox.Items.Add(new ComboBoxItem { Content = "全部", Tag = "" });
|
|
OperatorComboBox.Items.Add(new ComboBoxItem { Content = "张三", Tag = "OP-001" });
|
|
OperatorComboBox.Items.Add(new ComboBoxItem { Content = "李四", Tag = "OP-002" });
|
|
OperatorComboBox.Items.Add(new ComboBoxItem { Content = "王五", Tag = "OP-003" });
|
|
OperatorComboBox.SelectedIndex = 0;
|
|
|
|
// 状态
|
|
StatusComboBox.SelectedIndex = 0;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查询按钮点击事件。
|
|
/// </summary>
|
|
private async void OnQueryClicked(object sender, RoutedEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
await _viewModel.QuerySessionsAsync();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show($"查询失败: {ex.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 重置按钮点击事件。
|
|
/// </summary>
|
|
private void OnResetClicked(object sender, RoutedEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
_viewModel.ResetFilters();
|
|
ProductTypeComboBox.SelectedIndex = 0;
|
|
StationComboBox.SelectedIndex = 0;
|
|
OperatorComboBox.SelectedIndex = 0;
|
|
StatusComboBox.SelectedIndex = 0;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show($"重置失败: {ex.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 导出Excel按钮点击事件。
|
|
/// </summary>
|
|
private async void OnExportExcelClicked(object sender, RoutedEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
var saveFileDialog = new SaveFileDialog
|
|
{
|
|
Filter = "Excel文件|*.xlsx|所有文件|*.*",
|
|
Title = "导出Excel文件",
|
|
FileName = $"产品会话记录_{DateTime.Now:yyyyMMdd_HHmmss}.xlsx"
|
|
};
|
|
|
|
if (saveFileDialog.ShowDialog() == true)
|
|
{
|
|
await _viewModel.ExportSessionsAsync(saveFileDialog.FileName, ExportFormat.Excel);
|
|
MessageBox.Show("导出成功!", "成功", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show($"导出Excel失败: {ex.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 导出CSV按钮点击事件。
|
|
/// </summary>
|
|
private async void OnExportCsvClicked(object sender, RoutedEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
var saveFileDialog = new SaveFileDialog
|
|
{
|
|
Filter = "CSV文件|*.csv|所有文件|*.*",
|
|
Title = "导出CSV文件",
|
|
FileName = $"产品会话记录_{DateTime.Now:yyyyMMdd_HHmmss}.csv"
|
|
};
|
|
|
|
if (saveFileDialog.ShowDialog() == true)
|
|
{
|
|
await _viewModel.ExportSessionsAsync(saveFileDialog.FileName, ExportFormat.Csv);
|
|
MessageBox.Show("导出成功!", "成功", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show($"导出CSV失败: {ex.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查看统计按钮点击事件。
|
|
/// </summary>
|
|
private async void OnViewStatisticsClicked(object sender, RoutedEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
await _viewModel.LoadStatisticsAsync();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show($"加载统计信息失败: {ex.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 会话双击事件。
|
|
/// </summary>
|
|
private void OnSessionDoubleClicked(object sender, MouseButtonEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
if (SessionsDataGrid.SelectedItem is ProductionSessionModel session)
|
|
{
|
|
_viewModel.ViewSessionDetail(session);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show($"查看会话详情失败: {ex.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 上一页按钮点击事件。
|
|
/// </summary>
|
|
private async void OnPreviousPageClicked(object sender, RoutedEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
await _viewModel.GoToPreviousPageAsync();
|
|
UpdatePageInfo();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show($"翻页失败: {ex.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 下一页按钮点击事件。
|
|
/// </summary>
|
|
private async void OnNextPageClicked(object sender, RoutedEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
await _viewModel.GoToNextPageAsync();
|
|
UpdatePageInfo();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show($"翻页失败: {ex.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新分页信息。
|
|
/// </summary>
|
|
private void UpdatePageInfo()
|
|
{
|
|
PageInfoTextBlock.Text = $"第 {_viewModel.CurrentPage} 页,共 {_viewModel.TotalPages} 页";
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新记录数。
|
|
/// </summary>
|
|
private void UpdateRecordCount()
|
|
{
|
|
RecordCountTextBlock.Text = $"记录数: {_viewModel.Sessions?.Count ?? 0}";
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新统计显示。
|
|
/// </summary>
|
|
private void UpdateStatisticsDisplay()
|
|
{
|
|
if (_viewModel.Statistics == null) return;
|
|
|
|
// 总体统计
|
|
TotalSessionsTextBlock.Text = _viewModel.Statistics.TotalSessions.ToString();
|
|
OkSessionsTextBlock.Text = _viewModel.Statistics.OkSessions.ToString();
|
|
NgSessionsTextBlock.Text = _viewModel.Statistics.NgSessions.ToString();
|
|
PassRateTextBlock.Text = $"{_viewModel.Statistics.PassRate:P1}";
|
|
AvgProcessingTimeTextBlock.Text = $"{_viewModel.Statistics.AverageProcessingTimeSeconds:F1} 秒";
|
|
ThroughputTextBlock.Text = $"{_viewModel.Statistics.ThroughputPerHour:F1}";
|
|
InProgressSessionsTextBlock.Text = _viewModel.Statistics.InProgressSessions.ToString();
|
|
CancelledSessionsTextBlock.Text = _viewModel.Statistics.CancelledSessions.ToString();
|
|
|
|
// 分组统计
|
|
ProductTypeStatisticsDataGrid.ItemsSource = _viewModel.Statistics.ByProductType;
|
|
StationStatisticsDataGrid.ItemsSource = _viewModel.Statistics.ByStation;
|
|
OperatorStatisticsDataGrid.ItemsSource = _viewModel.Statistics.ByOperator;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 窗口关闭事件。
|
|
/// </summary>
|
|
protected override void OnClosed(EventArgs e)
|
|
{
|
|
_viewModel.Dispose();
|
|
base.OnClosed(e);
|
|
}
|
|
}
|