|
|
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 Sln.Wcs.Function;
|
|
|
using SqlSugar;
|
|
|
using Sln.Wcs.Function.Functions;
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
using Sln.Wcs.Repository.@base;
|
|
|
using Sln.Wcs.Repository;
|
|
|
|
|
|
namespace Sln_Wpf.Page
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// AddEquipWindow.xaml 的交互逻辑
|
|
|
/// </summary>
|
|
|
public partial class AddEquipWindow : Window
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// 返回结果:新增的设备信息
|
|
|
/// </summary>
|
|
|
public BaseEquipInfo NewDevice { get; private set; }
|
|
|
private ISqlSugarClient? sqlSugarClient;
|
|
|
private BaseServiceImpl<BaseEquipInfo> baseService;
|
|
|
private equipInfoSqlFunction EquipInfoSqlFunction;
|
|
|
private int WorkingType;
|
|
|
|
|
|
public AddEquipWindow()
|
|
|
{
|
|
|
InitializeComponent();
|
|
|
sqlSugarClient = App.ServiceProvider.GetService<ISqlSugarClient>();
|
|
|
baseService = new BaseServiceImpl<BaseEquipInfo>(new Repository<BaseEquipInfo>(sqlSugarClient));
|
|
|
EquipInfoSqlFunction = new equipInfoSqlFunction(App.ServiceProvider);
|
|
|
WorkingType = 0;
|
|
|
}
|
|
|
|
|
|
public AddEquipWindow(BaseEquipInfo equipInfo)
|
|
|
{
|
|
|
InitializeComponent();
|
|
|
sqlSugarClient = App.ServiceProvider.GetService<ISqlSugarClient>();
|
|
|
baseService = new BaseServiceImpl<BaseEquipInfo>(new Repository<BaseEquipInfo>(sqlSugarClient));
|
|
|
WorkingType = 1;
|
|
|
TxtEquipNo.Text = equipInfo.EquipNo;
|
|
|
TxtEquipName.Text = equipInfo.EquipName;
|
|
|
CmbEquipType.SelectedIndex = 0;
|
|
|
SetComboBoxByContent(TypeInttoString(equipInfo.EquipType));
|
|
|
TxtServerIp.Text = equipInfo.ServerIp;
|
|
|
TxtServerPort.Text = equipInfo.ServerPort.ToString();
|
|
|
foreach (ComboBoxItem item in CmbWorkshopLevel.Items)
|
|
|
{
|
|
|
if (item.Content.ToString() == (equipInfo.WorkshopLevel.ToString() + "F"))
|
|
|
{
|
|
|
CmbEquipType.SelectedItem = item;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
ChkUseFlag.IsChecked = equipInfo.UseFlag == 1 ? true : false;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 确认添加按钮
|
|
|
/// </summary>
|
|
|
private void BtnConfirm_Click(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
if (WorkingType == 0)
|
|
|
AddFunction();
|
|
|
else
|
|
|
{
|
|
|
UpdateFunction();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void UpdateFunction()
|
|
|
{
|
|
|
int Typeflag = 0;
|
|
|
int level = Convert.ToInt32(((CmbWorkshopLevel.SelectedItem as ComboBoxItem)?.Content.ToString() ?? "1F").Substring(0, 1));
|
|
|
Typeflag = StringTypetoInt();
|
|
|
NewDevice = new BaseEquipInfo {
|
|
|
EquipNo = TxtEquipNo.Text.Trim(),
|
|
|
EquipName = TxtEquipName.Text.Trim(),
|
|
|
EquipType = Typeflag,
|
|
|
ServerIp = TxtServerIp.Text.Trim(),
|
|
|
ServerPort = Convert.ToInt32(TxtServerPort.Text),
|
|
|
WorkshopLevel = level,
|
|
|
UseFlag = ChkUseFlag.IsChecked == true ? 1 : 0,
|
|
|
};
|
|
|
baseService.Update(NewDevice, $"equip_no = '{TxtEquipNo.Text.Trim()}'");
|
|
|
DialogResult = true;
|
|
|
Close();
|
|
|
}
|
|
|
|
|
|
private void AddFunction()
|
|
|
{
|
|
|
// 验证输入
|
|
|
if (!ValidateInput())
|
|
|
return;
|
|
|
int Typeflag = 0;
|
|
|
Typeflag = StringTypetoInt();
|
|
|
// 创建设备信息对象
|
|
|
NewDevice = new BaseEquipInfo
|
|
|
{
|
|
|
EquipNo = TxtEquipNo.Text.Trim(),
|
|
|
EquipName = TxtEquipName.Text.Trim(),
|
|
|
EquipType = Typeflag,
|
|
|
ServerIp = TxtServerIp.Text.Trim(),
|
|
|
ServerPort = Convert.ToInt32(TxtServerPort.Text),
|
|
|
WorkshopLevel = Convert.ToInt32(((CmbWorkshopLevel.SelectedItem as ComboBoxItem)?.Content.ToString() ?? "1F").Substring(0, 1)),
|
|
|
UseFlag = ChkUseFlag.IsChecked == true ? 1 : 0,
|
|
|
};
|
|
|
baseService.Insert(NewDevice);
|
|
|
DialogResult = true;
|
|
|
Close();
|
|
|
}
|
|
|
|
|
|
private int StringTypetoInt()
|
|
|
{
|
|
|
int Typeflag;
|
|
|
var EquipType = (CmbEquipType.SelectedItem as ComboBoxItem)?.Content.ToString();
|
|
|
switch (EquipType)
|
|
|
{
|
|
|
case "提升机":
|
|
|
Typeflag = 3;
|
|
|
break;
|
|
|
case "AGV":
|
|
|
Typeflag = 1;
|
|
|
break;
|
|
|
default:
|
|
|
Typeflag = 0;
|
|
|
break;
|
|
|
}
|
|
|
return Typeflag;
|
|
|
}
|
|
|
|
|
|
private string TypeInttoString(int EquipType)
|
|
|
{
|
|
|
string Typeflag;
|
|
|
switch (EquipType)
|
|
|
{
|
|
|
case 1:
|
|
|
Typeflag = "AGV";
|
|
|
break;
|
|
|
case 2:
|
|
|
Typeflag = "机台";
|
|
|
break;
|
|
|
case 3:
|
|
|
Typeflag = "提升机";
|
|
|
break;
|
|
|
default:
|
|
|
Typeflag = "其他";
|
|
|
break;
|
|
|
}
|
|
|
return Typeflag;
|
|
|
}
|
|
|
|
|
|
private void SetComboBoxByContent(string content)
|
|
|
{
|
|
|
foreach (ComboBoxItem item in CmbEquipType.Items)
|
|
|
{
|
|
|
if (item.Content.ToString() == content)
|
|
|
{
|
|
|
CmbEquipType.SelectedItem = item;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// 取消按钮
|
|
|
/// </summary>
|
|
|
private void BtnCancel_Click(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
DialogResult = false;
|
|
|
Close();
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 验证输入
|
|
|
/// </summary>
|
|
|
private bool ValidateInput()
|
|
|
{
|
|
|
// 验证设备编号
|
|
|
if (string.IsNullOrWhiteSpace(TxtEquipNo.Text))
|
|
|
{
|
|
|
MessageBox.Show("请输入设备编号", "验证失败", MessageBoxButton.OK, MessageBoxImage.Warning);
|
|
|
TxtEquipNo.Focus();
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
// 验证设备名称
|
|
|
if (string.IsNullOrWhiteSpace(TxtEquipName.Text))
|
|
|
{
|
|
|
MessageBox.Show("请输入设备名称", "验证失败", MessageBoxButton.OK, MessageBoxImage.Warning);
|
|
|
TxtEquipName.Focus();
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
// 验证IP地址格式(简单验证)
|
|
|
string ip = TxtServerIp.Text.Trim();
|
|
|
if (string.IsNullOrWhiteSpace(ip))
|
|
|
{
|
|
|
MessageBox.Show("请输入设备IP地址", "验证失败", MessageBoxButton.OK, MessageBoxImage.Warning);
|
|
|
TxtServerIp.Focus();
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
// 简单IP格式验证
|
|
|
System.Net.IPAddress ipAddress;
|
|
|
if (!System.Net.IPAddress.TryParse(ip, out ipAddress))
|
|
|
{
|
|
|
MessageBox.Show("请输入正确的IP地址格式\n例如: 192.168.1.100", "验证失败", MessageBoxButton.OK, MessageBoxImage.Warning);
|
|
|
TxtServerIp.Focus();
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
// 验证端口号
|
|
|
string port = TxtServerPort.Text.Trim();
|
|
|
if (string.IsNullOrWhiteSpace(port))
|
|
|
{
|
|
|
MessageBox.Show("请输入设备端口号", "验证失败", MessageBoxButton.OK, MessageBoxImage.Warning);
|
|
|
TxtServerPort.Focus();
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
int portNum;
|
|
|
if (!int.TryParse(port, out portNum) || portNum < 1 || portNum > 65535)
|
|
|
{
|
|
|
MessageBox.Show("请输入正确的端口号(1-65535)", "验证失败", MessageBoxButton.OK, MessageBoxImage.Warning);
|
|
|
TxtServerPort.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();
|
|
|
}
|
|
|
}
|
|
|
}
|