|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Drawing.Imaging;
|
|
|
using System.Linq;
|
|
|
using System.Reflection.PortableExecutable;
|
|
|
using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
|
using System.Windows;
|
|
|
using System.Windows.Automation.Text;
|
|
|
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 Microsoft.Extensions.DependencyInjection;
|
|
|
using Sln.Wcs.Function.Functions;
|
|
|
using Sln.Wcs.Model.Domain;
|
|
|
using SqlSugar;
|
|
|
|
|
|
namespace Sln_Wpf.Page.AddWindows
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// AddLocationWindow.xaml 的交互逻辑
|
|
|
/// </summary>
|
|
|
public partial class AddLocationWindow : Window
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// 返回结果:新增的库位信息
|
|
|
/// </summary>
|
|
|
public BaseLocation NewLocation { get; private set; }
|
|
|
private ISqlSugarClient? sqlSugarClient;
|
|
|
private locationSqlFunction AddSqlFunction;
|
|
|
private int WorkingType;
|
|
|
public AddLocationWindow()
|
|
|
{
|
|
|
InitializeComponent();
|
|
|
AddSqlFunction = new locationSqlFunction(App.ServiceProvider);
|
|
|
WorkingType = 0;
|
|
|
}
|
|
|
|
|
|
public AddLocationWindow(BaseLocation baseLocation)
|
|
|
{
|
|
|
InitializeComponent();
|
|
|
AddSqlFunction = new locationSqlFunction(App.ServiceProvider);
|
|
|
sqlSugarClient = App.ServiceProvider.GetService<ISqlSugarClient>();
|
|
|
SetComboBoxIndexByValue(CmbWorkshopID, baseLocation.WorkshopId.ToString());
|
|
|
SetComboBoxIndexByValue(CmbWorkshopLevel, baseLocation.WorkshopLevel.ToString());
|
|
|
SetComboBoxIndexByValue(CmbActiveFlag, baseLocation.ActiveFlag.ToString());
|
|
|
SetComboBoxIndexByValue(CmbLocationStatus, baseLocation.LocationStatus.ToString());
|
|
|
TxtWarehouseID.Text = baseLocation.WarehouseId.ToString();
|
|
|
TxtMachineID.Text = baseLocation.MachineId.ToString();
|
|
|
TxtLocationCode.Text = baseLocation.LocationCode;
|
|
|
TxtAgvPositionCode.Text = baseLocation.AgvPositionCode;
|
|
|
TxtContainerCode.Text = baseLocation.ContainerCode;
|
|
|
WorkingType = 1;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取 ComboBox 选中项的 Tag 值(INT类型)
|
|
|
/// </summary>
|
|
|
private int GetSelectedTagValue(ComboBox comboBox)
|
|
|
{
|
|
|
var selectedItem = comboBox.SelectedItem as ComboBoxItem;
|
|
|
if (selectedItem != null && selectedItem.Tag != null)
|
|
|
{
|
|
|
return Convert.ToInt32(selectedItem.Tag);
|
|
|
}
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
private void SetComboBoxIndexByValue(ComboBox comboBox, string value)
|
|
|
{
|
|
|
foreach (ComboBoxItem item in comboBox.Items)
|
|
|
{
|
|
|
if (item.Tag.ToString() == value)
|
|
|
{
|
|
|
comboBox.SelectedItem = item;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取 ComboBox 选中项的显示文本
|
|
|
/// </summary>
|
|
|
private string GetSelectedDisplayText(ComboBox comboBox)
|
|
|
{
|
|
|
var selectedItem = comboBox.SelectedItem as ComboBoxItem;
|
|
|
return selectedItem?.Content?.ToString() ?? "";
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 确认添加按钮
|
|
|
/// </summary>
|
|
|
private void BtnConfirm_Click(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
if (WorkingType == 0)
|
|
|
{
|
|
|
// 验证输入
|
|
|
if (!ValidateInput())
|
|
|
return;
|
|
|
|
|
|
// 创建库位信息对象
|
|
|
NewLocation = new BaseLocation
|
|
|
{
|
|
|
WarehouseId = Convert.ToInt32(TxtWarehouseID.Text.Trim()),
|
|
|
MachineId = TxtMachineID.Text.Trim(),
|
|
|
LocationCode = TxtLocationCode.Text.Trim(),
|
|
|
AgvPositionCode = TxtAgvPositionCode.Text.Trim(),
|
|
|
ContainerCode = TxtContainerCode.Text.Trim(),
|
|
|
WorkshopId = GetSelectedTagValue(CmbWorkshopID),
|
|
|
WorkshopLevel = GetSelectedTagValue(CmbWorkshopLevel),
|
|
|
ActiveFlag = GetSelectedTagValue(CmbActiveFlag),
|
|
|
LocationStatus = GetSelectedTagValue(CmbLocationStatus),
|
|
|
};
|
|
|
AddSqlFunction.insertFunction(NewLocation);
|
|
|
DialogResult = true;
|
|
|
Close();
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
if (!ValidateInput())
|
|
|
return;
|
|
|
|
|
|
sqlSugarClient.Updateable<BaseLocation>().Where(it => it.LocationCode == TxtLocationCode.Text.Trim()).SetColumns(it => new BaseLocation()
|
|
|
{
|
|
|
WarehouseId = Convert.ToInt32(TxtWarehouseID.Text.Trim()),
|
|
|
MachineId = TxtMachineID.Text.Trim(),
|
|
|
LocationCode = TxtLocationCode.Text.Trim(),
|
|
|
AgvPositionCode = TxtAgvPositionCode.Text.Trim(),
|
|
|
ContainerCode = TxtContainerCode.Text.Trim(),
|
|
|
WorkshopId = GetSelectedTagValue(CmbWorkshopID),
|
|
|
WorkshopLevel = GetSelectedTagValue(CmbWorkshopLevel),
|
|
|
ActiveFlag = GetSelectedTagValue(CmbActiveFlag),
|
|
|
LocationStatus = GetSelectedTagValue(CmbLocationStatus),
|
|
|
}).ExecuteCommand();
|
|
|
|
|
|
//传递之前页面
|
|
|
NewLocation = new BaseLocation
|
|
|
{
|
|
|
WarehouseId = Convert.ToInt32(TxtWarehouseID.Text.Trim()),
|
|
|
MachineId = TxtMachineID.Text.Trim(),
|
|
|
LocationCode = TxtLocationCode.Text.Trim(),
|
|
|
AgvPositionCode = TxtAgvPositionCode.Text.Trim(),
|
|
|
ContainerCode = TxtContainerCode.Text.Trim(),
|
|
|
WorkshopId = GetSelectedTagValue(CmbWorkshopID),
|
|
|
WorkshopLevel = GetSelectedTagValue(CmbWorkshopLevel),
|
|
|
ActiveFlag = GetSelectedTagValue(CmbActiveFlag),
|
|
|
LocationStatus = GetSelectedTagValue(CmbLocationStatus),
|
|
|
};
|
|
|
DialogResult = true;
|
|
|
Close();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 取消按钮
|
|
|
/// </summary>
|
|
|
private void BtnCancel_Click(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
DialogResult = false;
|
|
|
Close();
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 验证输入
|
|
|
/// </summary>
|
|
|
private bool ValidateInput()
|
|
|
{
|
|
|
// 验证仓库编号
|
|
|
if (string.IsNullOrWhiteSpace(TxtWarehouseID.Text))
|
|
|
{
|
|
|
MessageBox.Show("请输入仓库编号", "验证失败", MessageBoxButton.OK, MessageBoxImage.Warning);
|
|
|
TxtWarehouseID.Focus();
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
// 验证机台编号
|
|
|
if (string.IsNullOrWhiteSpace(TxtMachineID.Text))
|
|
|
{
|
|
|
MessageBox.Show("请输入机台编号", "验证失败", MessageBoxButton.OK, MessageBoxImage.Warning);
|
|
|
TxtMachineID.Focus();
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
// 验证位置编号
|
|
|
if (string.IsNullOrWhiteSpace(TxtLocationCode.Text))
|
|
|
{
|
|
|
MessageBox.Show("请输入位置编号", "验证失败", MessageBoxButton.OK, MessageBoxImage.Warning);
|
|
|
TxtLocationCode.Focus();
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
// 验证AGV位置编号
|
|
|
if (string.IsNullOrWhiteSpace(TxtAgvPositionCode.Text))
|
|
|
{
|
|
|
MessageBox.Show("请输入AGV位置编号", "验证失败", MessageBoxButton.OK, MessageBoxImage.Warning);
|
|
|
TxtAgvPositionCode.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();
|
|
|
}
|
|
|
}
|
|
|
} |