using DataEntity.Device;
|
using DataEntity.Share;
|
using DataRWDAL.Device;
|
using HandyControl.Data;
|
using HxEnum;
|
using System;
|
using System.Linq;
|
using System.Windows;
|
using System.Windows.Input;
|
using XCommon.Log;
|
using XCommon.Tip;
|
using XHandler.View.Dialog;
|
|
namespace XHandler.View.Device
|
{
|
/// <summary>
|
/// 设备编辑 页面
|
/// </summary>
|
public partial class DeviceMehtodAdd : System.Windows.Window
|
{
|
#region 参数
|
/// <summary>
|
/// 操作类型(添加、修改)
|
/// </summary>
|
public string OperationType = "";
|
|
/// <summary>
|
/// 主键ID
|
/// </summary>
|
public string DeviceMethodId = "";
|
|
/// <summary>
|
/// 设备ID
|
/// </summary>
|
public string DeviceconfigId = "";
|
|
/// <summary>
|
/// 委托列表数据
|
/// </summary>
|
public delegate void DelegateForm();
|
|
/// <summary>
|
/// 委托方法名称
|
/// </summary>
|
public event DelegateForm LoadListEveForm;
|
#endregion
|
|
#region 构造函数
|
/// <summary>
|
/// 构造函数
|
/// </summary>
|
public DeviceMehtodAdd()
|
{
|
InitializeComponent();
|
}
|
#endregion
|
|
#region 初始化
|
/// <summary>
|
/// 初始化
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void Window_Loaded(object sender, RoutedEventArgs e)
|
{
|
try
|
{
|
if (OperationType == OperationTypeEnum.OperationType_Enum.EditEnum.ToString())
|
{
|
var model = DeviceConfigMethodDB.GetInfodById(DeviceMethodId);
|
if (model != null)
|
{
|
tBoxMethodChName.Text = model.Name;
|
tBoxMethodEnName.Text = model.ParameterName;
|
tBoxRemark.Text = model.Remark;
|
}
|
}
|
}
|
catch (Exception ex)
|
{
|
LoggerHelper.ErrorLog("ERROR:", ex);
|
}
|
}
|
#endregion
|
|
#region 确定
|
/// <summary>
|
/// 确定
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void btnOk_Click(object sender, RoutedEventArgs e)
|
{
|
if (!CheckData())
|
{
|
return;
|
}
|
|
DeviceConfigMethodModel deviceConfigMethodModel = new DeviceConfigMethodModel();
|
int updateCnt = 0;
|
|
if (OperationType == OperationTypeEnum.OperationType_Enum.EditEnum.ToString())
|
{
|
deviceConfigMethodModel = DeviceConfigMethodDB.GetInfodById(DeviceMethodId);
|
deviceConfigMethodModel.Name = tBoxMethodChName.Text;
|
deviceConfigMethodModel.ParameterName = tBoxMethodEnName.Text;
|
deviceConfigMethodModel.Remark = tBoxRemark.Text;
|
deviceConfigMethodModel.Id = DeviceMethodId;
|
deviceConfigMethodModel.ModifyTime = DateTime.Now;
|
deviceConfigMethodModel.ModifyName = Shared.User.username;
|
updateCnt = DeviceConfigMethodDB.Update(deviceConfigMethodModel);
|
}
|
else
|
{
|
deviceConfigMethodModel.ProjectId = Shared.SoftwareInformation.software_information_id;
|
deviceConfigMethodModel.Name = tBoxMethodChName.Text;
|
deviceConfigMethodModel.ParameterName = tBoxMethodEnName.Text;
|
deviceConfigMethodModel.Remark = tBoxRemark.Text;
|
deviceConfigMethodModel.Id = Guid.NewGuid().ToString();
|
deviceConfigMethodModel.DeviceconfigId = DeviceconfigId;
|
deviceConfigMethodModel.CreateTime = DateTime.Now;
|
deviceConfigMethodModel.CreatName = Shared.User.username;
|
updateCnt = DeviceConfigMethodDB.Add(deviceConfigMethodModel);
|
}
|
|
if (updateCnt > 0)
|
{
|
LoadListEveForm();
|
//new MessageDialog("保存成功").ShowDialog();
|
ShowTip.ShowNotice("保存成功", InfoType.Success);
|
this.Close();
|
}
|
}
|
|
/// <summary>
|
/// 检查输入数据
|
/// </summary>
|
/// <returns></returns>
|
private bool CheckData()
|
{
|
if (string.IsNullOrWhiteSpace(tBoxMethodChName.Text))
|
{
|
//new MessageDialog("请填写方法中文名").ShowDialog();
|
ShowTip.ShowNotice("请填写方法中文名", InfoType.Warning);
|
tBoxMethodChName.Focus();
|
return false;
|
}
|
|
if (string.IsNullOrWhiteSpace(tBoxMethodEnName.Text))
|
{
|
//new MessageDialog("请填写方法英文名").ShowDialog();
|
ShowTip.ShowNotice("请填写方法英文名", InfoType.Warning);
|
tBoxMethodEnName.Focus();
|
return false;
|
}
|
|
// 获取设备方法信息
|
var devMethodModel = DeviceConfigMethodDB.GetInfo(DeviceconfigId, tBoxMethodEnName.Text);
|
if (OperationType == OperationTypeEnum.OperationType_Enum.EditEnum.ToString())
|
{
|
if (devMethodModel != null && devMethodModel.Count > 0)
|
{
|
var tempList = devMethodModel.Where(x => x.Id != DeviceMethodId);
|
if (tempList != null && tempList.Count() > 0)
|
{
|
//new MessageDialog("设备参数名称已存在").ShowDialog();
|
ShowTip.ShowNotice("设备参数名称已存在", InfoType.Warning);
|
return false;
|
}
|
}
|
}
|
else
|
{
|
if (devMethodModel != null && devMethodModel.Count > 0)
|
{
|
//new MessageDialog("设备参数名称已存在").ShowDialog();
|
ShowTip.ShowNotice("设备参数名称已存在", InfoType.Warning);
|
return false;
|
}
|
}
|
|
return true;
|
}
|
#endregion
|
|
#region 拖动窗体
|
/// <summary>
|
/// 拖动窗体
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void Grid_MouseDown(object sender, MouseButtonEventArgs e)
|
{
|
if (e.ChangedButton == MouseButton.Left)
|
{
|
this.DragMove();
|
}
|
}
|
#endregion
|
|
#region 关闭页面
|
/// <summary>
|
/// 关闭页面
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void btnClose_Click(object sender, RoutedEventArgs e)
|
{
|
this.Close();
|
}
|
#endregion
|
|
#region ESC关闭画面
|
/// <summary>
|
/// ESC关闭画面
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void Window_PreviewKeyDown(object sender, KeyEventArgs e)
|
{
|
if (e.Key == Key.Escape)
|
{
|
this.Close();
|
}
|
}
|
#endregion
|
}
|
}
|