|
|
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;
|
|
|
|
|
|
namespace Sln_Wpf.Page
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// AddEquipWindow.xaml 的交互逻辑
|
|
|
/// </summary>
|
|
|
public partial class AddParameterWindow : Window
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// 返回结果:新增的参数信息
|
|
|
/// </summary>
|
|
|
public BaseEquipParameter equipParameter { get; private set; }
|
|
|
private ISqlSugarClient? sqlSugarClient;
|
|
|
private equipParameterSqlFunction AddSqlFunction;
|
|
|
private int WorkingType;
|
|
|
|
|
|
/// <summary>
|
|
|
/// 构造函数
|
|
|
/// </summary>
|
|
|
public AddParameterWindow()
|
|
|
{
|
|
|
InitializeComponent();
|
|
|
AddSqlFunction = new equipParameterSqlFunction(App.ServiceProvider);
|
|
|
WorkingType = 0;
|
|
|
}
|
|
|
|
|
|
public AddParameterWindow(BaseEquipParameter baseEquipParameter)
|
|
|
{
|
|
|
InitializeComponent();
|
|
|
sqlSugarClient = App.ServiceProvider.GetService<ISqlSugarClient>();
|
|
|
AddSqlFunction = new equipParameterSqlFunction(App.ServiceProvider);
|
|
|
TxtEquipCode.Text = baseEquipParameter.EquipCode;
|
|
|
TxtEquipName.Text = baseEquipParameter.EquipName;
|
|
|
CmbSelectFunction(CmbEquipType, baseEquipParameter.EquipType);
|
|
|
CmbSelectFunction(CmbParamUnit, baseEquipParameter.ParamUnit);
|
|
|
CmbSelectFunction(CmbParamType, baseEquipParameter.ParamType);
|
|
|
TxtUpdateTime.Text = baseEquipParameter.UpdateTime.ToString("yyyy-MM-dd HH:mm:ss");
|
|
|
WorkingType = 1;
|
|
|
}
|
|
|
|
|
|
private void CmbSelectFunction(ComboBox comboBox, string content)
|
|
|
{
|
|
|
foreach (ComboBoxItem item in comboBox.Items)
|
|
|
{
|
|
|
if (item.Content.ToString() == content)
|
|
|
{
|
|
|
comboBox.SelectedItem = item;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 确认添加按钮
|
|
|
/// </summary>
|
|
|
private void BtnConfirm_Click(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
if (WorkingType == 0)
|
|
|
{
|
|
|
// 验证输入
|
|
|
if (!ValidateInput())
|
|
|
return;
|
|
|
|
|
|
// 获取参数类型(string/int/bool)
|
|
|
string paramDataType = (CmbParamType.SelectedItem as ComboBoxItem)?.Tag?.ToString() ?? "string";
|
|
|
string paramValue = TxtParamValue.Text.Trim();
|
|
|
|
|
|
// 根据数据类型验证参数值格式
|
|
|
if (!ValidateParamValueByType(paramValue, paramDataType))
|
|
|
return;
|
|
|
|
|
|
// 创建参数信息对象
|
|
|
equipParameter = new BaseEquipParameter
|
|
|
{
|
|
|
EquipCode = TxtEquipCode.Text.Trim(),
|
|
|
EquipName = TxtEquipName.Text.Trim(),
|
|
|
EquipType = (CmbEquipType.SelectedItem as ComboBoxItem)?.Content.ToString() ?? "无",
|
|
|
ParamKey = TxtParamKey.Text.Trim(),
|
|
|
ParamValue = paramValue,
|
|
|
ParamType = paramDataType,
|
|
|
ParamUnit = (CmbParamUnit.SelectedItem as ComboBoxItem)?.Content.ToString() ?? "无",
|
|
|
UpdateTime = DateTime.Now
|
|
|
};
|
|
|
|
|
|
AddSqlFunction.insertFunction(equipParameter);
|
|
|
DialogResult = true;
|
|
|
Close();
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
if (!ValidateInput())
|
|
|
return;
|
|
|
|
|
|
// 获取参数类型(string/int/bool)
|
|
|
string paramDataType = (CmbParamType.SelectedItem as ComboBoxItem)?.Tag?.ToString() ?? "string";
|
|
|
string paramValue = TxtParamValue.Text.Trim();
|
|
|
var tempType = (CmbEquipType.SelectedItem as ComboBoxItem)?.Content.ToString() ?? "无";
|
|
|
var tempUnit = (CmbParamUnit.SelectedItem as ComboBoxItem)?.Content.ToString() ?? "无";
|
|
|
|
|
|
// 根据数据类型验证参数值格式
|
|
|
if (!ValidateParamValueByType(paramValue, paramDataType))
|
|
|
return;
|
|
|
|
|
|
sqlSugarClient.Updateable<BaseEquipParameter>().Where(it => it.EquipCode == TxtEquipCode.Text.Trim()).SetColumns(it => new BaseEquipParameter()
|
|
|
{
|
|
|
EquipCode = TxtEquipCode.Text.Trim(),
|
|
|
EquipName = TxtEquipName.Text.Trim(),
|
|
|
EquipType = tempType,
|
|
|
ParamKey = TxtParamKey.Text.Trim(),
|
|
|
ParamValue = paramValue,
|
|
|
ParamType = paramDataType,
|
|
|
ParamUnit = tempUnit,
|
|
|
UpdateTime = DateTime.Now
|
|
|
}).ExecuteCommand();
|
|
|
DialogResult = true;
|
|
|
Close();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 根据数据类型验证参数值格式
|
|
|
/// </summary>
|
|
|
private bool ValidateParamValueByType(string value, string dataType)
|
|
|
{
|
|
|
switch (dataType)
|
|
|
{
|
|
|
case "int":
|
|
|
if (!int.TryParse(value, out _))
|
|
|
{
|
|
|
MessageBox.Show("参数类型为 Int(整数),请输入有效的整数值", "格式错误",
|
|
|
MessageBoxButton.OK, MessageBoxImage.Warning);
|
|
|
TxtParamValue.Focus();
|
|
|
return false;
|
|
|
}
|
|
|
break;
|
|
|
case "bool":
|
|
|
if (!bool.TryParse(value, out _))
|
|
|
{
|
|
|
MessageBox.Show("参数类型为 Bool(布尔值),请输入 true 或 false", "格式错误",
|
|
|
MessageBoxButton.OK, MessageBoxImage.Warning);
|
|
|
TxtParamValue.Focus();
|
|
|
return false;
|
|
|
}
|
|
|
break;
|
|
|
case "string":
|
|
|
default:
|
|
|
// 字符串类型无需额外验证
|
|
|
break;
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 取消按钮
|
|
|
/// </summary>
|
|
|
private void BtnCancel_Click(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
DialogResult = false;
|
|
|
Close();
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 验证输入
|
|
|
/// </summary>
|
|
|
private bool ValidateInput()
|
|
|
{
|
|
|
// 验证设备ID
|
|
|
if (string.IsNullOrWhiteSpace(TxtEquipCode.Text))
|
|
|
{
|
|
|
MessageBox.Show("请输入设备ID", "验证失败", MessageBoxButton.OK, MessageBoxImage.Warning);
|
|
|
TxtEquipCode.Focus();
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
// 验证设备名称
|
|
|
if (string.IsNullOrWhiteSpace(TxtEquipName.Text))
|
|
|
{
|
|
|
MessageBox.Show("请输入设备名称", "验证失败", MessageBoxButton.OK, MessageBoxImage.Warning);
|
|
|
TxtEquipName.Focus();
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
// 验证参数名称
|
|
|
if (string.IsNullOrWhiteSpace(TxtParamKey.Text))
|
|
|
{
|
|
|
MessageBox.Show("请输入参数名称", "验证失败", MessageBoxButton.OK, MessageBoxImage.Warning);
|
|
|
TxtParamKey.Focus();
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
// 验证参数值
|
|
|
if (string.IsNullOrWhiteSpace(TxtParamValue.Text))
|
|
|
{
|
|
|
MessageBox.Show("请输入参数值", "验证失败", MessageBoxButton.OK, MessageBoxImage.Warning);
|
|
|
TxtParamValue.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();
|
|
|
}
|
|
|
}
|
|
|
}
|