75 lines
2.6 KiB
C#
75 lines
2.6 KiB
C#
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using MaterialDesignThemes.Wpf;
|
|
using Seyounth.Hyosung.Data.Models;
|
|
using Seyounth.Hyosung.Data.Services.Hyosung;
|
|
using Seyounth.Hyosung.Runtime;
|
|
using Seyounth.Hyosung.ViewModels;
|
|
|
|
namespace Seyounth.Hyosung.Views.Pages
|
|
{
|
|
/// <summary>
|
|
/// HomeViewPage.xaml 的交互逻辑
|
|
/// </summary>
|
|
public partial class HomeViewPage : Page
|
|
{
|
|
public HomeViewModel ViewModel { get; set; }
|
|
|
|
private readonly IHyosungRuntime _runtime;
|
|
|
|
private readonly IHyosungWmsService _wmsService;
|
|
|
|
public HomeViewPage(HomeViewModel viewModel, IHyosungRuntime runtime, IHyosungWmsService wmsService)
|
|
{
|
|
_wmsService = wmsService;
|
|
_runtime = runtime;
|
|
ViewModel = viewModel;
|
|
DataContext = this;
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void ChangeVarietyButton_OnClick(object sender, RoutedEventArgs e)
|
|
{
|
|
var variety = VarietyComboBox.SelectedItem as Variety;
|
|
if (variety == null)
|
|
{
|
|
MessageBox.Show("请选择要切换的品种");
|
|
return;
|
|
}
|
|
|
|
ChangeVarietyButton.Content = "切换中";
|
|
ButtonProgressAssist.SetIsIndicatorVisible(ChangeVarietyButton, true);
|
|
ChangeVarietyButton.IsEnabled = false;
|
|
|
|
variety.YarnCarSide = 1;
|
|
variety.YarnCarType = YarnCarTypeComboBox.SelectedIndex + 1;
|
|
_runtime.SendVarietyToPlcAsync(variety)
|
|
.ContinueWith(task =>
|
|
{
|
|
Dispatcher.Invoke(() =>
|
|
{
|
|
if (!task.IsCompletedSuccessfully)
|
|
{
|
|
MessageBox.Show(task.Exception?.Message, "切换失败");
|
|
}
|
|
|
|
ChangeVarietyButton.Content = "切换";
|
|
ButtonProgressAssist.SetIsIndicatorVisible(ChangeVarietyButton, false);
|
|
ChangeVarietyButton.IsEnabled = true;
|
|
});
|
|
});
|
|
}
|
|
|
|
private async void VarietyComboBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
{
|
|
var selectedItem = VarietyComboBox.SelectedItem;
|
|
if (selectedItem != null)
|
|
{
|
|
var variety = selectedItem as Variety;
|
|
var info = await _wmsService.GetItemInfoByItemCode(variety.Code);
|
|
var controlNo = await _wmsService.GetControlNo(variety, info.GRADE);
|
|
variety.ControlNo = controlNo;
|
|
}
|
|
}
|
|
}
|
|
} |