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.

242 lines
8.2 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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 Dm.util;
using Microsoft.Extensions.DependencyInjection;
using Sln.Wcs.Function.Functions;
using Sln.Wcs.Model.Domain;
using SqlSugar;
namespace Sln_Wpf.Page.AddWindows
{
/// <summary>
/// AddSubtaskWindow.xaml 的交互逻辑
/// </summary>
public partial class AddSubtaskWindow : Window
{
/// <summary>
/// 返回结果:新增的子任务信息
/// </summary>
public BaseSubtaskTemplate NewSubtask { get; private set; }
private ISqlSugarClient? sqlSugarClient;
private subtaskSqlFunction AddSqlFunction;
private int WorkingType;
public AddSubtaskWindow()
{
InitializeComponent();
AddSqlFunction = new subtaskSqlFunction(App.ServiceProvider);
WorkingType = 0;
}
public AddSubtaskWindow(BaseSubtaskTemplate baseSubtaskTemplate)
{
NewSubtask = baseSubtaskTemplate;
sqlSugarClient = App.ServiceProvider.GetService<ISqlSugarClient>();
InitializeComponent();
Init(baseSubtaskTemplate);
AddSqlFunction = new subtaskSqlFunction(App.ServiceProvider);
WorkingType = 1;
}
public void Init(BaseSubtaskTemplate baseSubtaskTemplate)
{
TxtSubtaskCode.Text = baseSubtaskTemplate.SubtaskCode;
TxtSubtaskName.Text = baseSubtaskTemplate.SubtaskName;
SetComboBoxIndexByValue(CmbSubtaskType, baseSubtaskTemplate.SubtaskType);
SetComboBoxIndexByValue(CmbDeviceType, baseSubtaskTemplate.DeviceType);
SetComboBoxIndexByValue(CmbDeviceAction, baseSubtaskTemplate.DeviceAction);
SetComboBoxIndexByValue(CmbSourceLocationType, baseSubtaskTemplate.SourceLocationType);
TxtSourceLocationCode.Text = baseSubtaskTemplate.SourceLocationCode;
SetComboBoxIndexByValue(CmbTargetLocationType, baseSubtaskTemplate.TargetLocationType);
TxtTargetLocationCode.Text = baseSubtaskTemplate.TargetLocationCode;
SetComboBoxIndexByValue(CmbMaterialAction, baseSubtaskTemplate.MaterialAction);
SetComboBoxIndexByValue(CmbContainerType, baseSubtaskTemplate.ContainerType);
SetComboBoxIndexByValue(CmbIsCarryMaterial, baseSubtaskTemplate.IsCarryMaterial.toString());
TxtRequiredParams.Text = baseSubtaskTemplate.RequiredParams;
SetComboBoxIndexByValue(CmbStatus, baseSubtaskTemplate.Status.toString());
}
/// <summary>
/// 获取 ComboBox 选中项的 Tag 值
/// </summary>
private string GetSelectedTagValue(ComboBox comboBox)
{
var selectedItem = comboBox.SelectedItem as ComboBoxItem;
if (selectedItem != null && selectedItem.Tag != null)
{
return selectedItem.Tag.ToString();
}
return "";
}
/// <summary>
/// 获取 ComboBox 选中项的显示文本
/// </summary>
private string GetSelectedDisplayText(ComboBox comboBox)
{
var selectedItem = comboBox.SelectedItem as ComboBoxItem;
return selectedItem?.Content?.ToString() ?? "";
}
/// <summary>
/// 获取状态值INT类型0-禁用 1-启用)
/// </summary>
private int GetStatusValue()
{
var selectedItem = CmbStatus.SelectedItem as ComboBoxItem;
if (selectedItem != null && selectedItem.Tag != null)
{
return Convert.ToInt32(selectedItem.Tag);
}
return 1;
}
/// <summary>
/// 获取是否携带物料值
/// </summary>
private bool GetIsCarryMaterialValue()
{
var selectedItem = CmbIsCarryMaterial.SelectedItem as ComboBoxItem;
if (selectedItem != null && selectedItem.Tag != null)
{
return Convert.ToBoolean(selectedItem.Tag);
}
return false;
}
private void CmbSelectFunction(ComboBox comboBox, string content)
{
foreach (ComboBoxItem item in comboBox.Items)
{
if (item.Content.ToString() == content)
{
comboBox.SelectedItem = item;
break;
}
}
}
private void SetComboBoxIndexByValue(ComboBox comboBox, string value)
{
foreach (ComboBoxItem item in comboBox.Items)
{
if (item.Tag.ToString() == value)
{
comboBox.SelectedItem = item;
break;
}
}
}
/// <summary>
/// 确认添加按钮
/// </summary>
private void BtnConfirm_Click(object sender, RoutedEventArgs e)
{
// 验证输入
if (!ValidateInput())
return;
// 创建子任务对象
NewSubtask = new BaseSubtaskTemplate
{
SubtaskCode = TxtSubtaskCode.Text.Trim(),
SubtaskName = TxtSubtaskName.Text.Trim(),
SubtaskType = GetSelectedTagValue(CmbSubtaskType),
DeviceType = GetSelectedTagValue(CmbDeviceType),
DeviceAction = GetSelectedTagValue(CmbDeviceAction),
SourceLocationType = GetSelectedTagValue(CmbSourceLocationType),
SourceLocationCode = TxtSourceLocationCode.Text.Trim(),
TargetLocationType = GetSelectedTagValue(CmbTargetLocationType),
TargetLocationCode = TxtTargetLocationCode.Text.Trim(),
MaterialAction = GetSelectedTagValue(CmbMaterialAction),
ContainerType = GetSelectedTagValue(CmbContainerType),
IsCarryMaterial = GetIsCarryMaterialValue(),
RequiredParams = TxtRequiredParams.Text.Trim(),
// INT类型字段
Status = GetStatusValue(),
// 设置默认值
CreateTime = DateTime.Now,
UpdateTime = DateTime.Now
};
AddSqlFunction.insertFunction(NewSubtask);
DialogResult = true;
Close();
}
/// <summary>
/// 取消按钮
/// </summary>
private void BtnCancel_Click(object sender, RoutedEventArgs e)
{
DialogResult = false;
Close();
}
/// <summary>
/// 验证输入
/// </summary>
private bool ValidateInput()
{
// 验证子任务编码
if (string.IsNullOrWhiteSpace(TxtSubtaskCode.Text))
{
MessageBox.Show("请输入子任务编码", "验证失败", MessageBoxButton.OK, MessageBoxImage.Warning);
TxtSubtaskCode.Focus();
return false;
}
// 验证子任务名称
if (string.IsNullOrWhiteSpace(TxtSubtaskName.Text))
{
MessageBox.Show("请输入子任务名称", "验证失败", MessageBoxButton.OK, MessageBoxImage.Warning);
TxtSubtaskName.Focus();
return false;
}
return true;
}
/// <summary>
/// 窗口拖拽
/// </summary>
private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (e.ButtonState == MouseButtonState.Pressed)
{
this.DragMove();
}
}
/// <summary>
/// 最小化
/// </summary>
private void BtnMinimize_Click(object sender, RoutedEventArgs e)
{
this.WindowState = WindowState.Minimized;
}
/// <summary>
/// 关闭
/// </summary>
private void BtnClose_Click(object sender, RoutedEventArgs e)
{
DialogResult = false;
Close();
}
}
}