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 { /// /// 设备编辑 页面 /// public partial class DeviceMehtodAdd : System.Windows.Window { #region 参数 /// /// 操作类型(添加、修改) /// public string OperationType = ""; /// /// 主键ID /// public string DeviceMethodId = ""; /// /// 设备ID /// public string DeviceconfigId = ""; /// /// 委托列表数据 /// public delegate void DelegateForm(); /// /// 委托方法名称 /// public event DelegateForm LoadListEveForm; #endregion #region 构造函数 /// /// 构造函数 /// public DeviceMehtodAdd() { InitializeComponent(); } #endregion #region 初始化 /// /// 初始化 /// /// /// 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 确定 /// /// 确定 /// /// /// 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(); } } /// /// 检查输入数据 /// /// 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 拖动窗体 /// /// 拖动窗体 /// /// /// private void Grid_MouseDown(object sender, MouseButtonEventArgs e) { if (e.ChangedButton == MouseButton.Left) { this.DragMove(); } } #endregion #region 关闭页面 /// /// 关闭页面 /// /// /// private void btnClose_Click(object sender, RoutedEventArgs e) { this.Close(); } #endregion #region ESC关闭画面 /// /// ESC关闭画面 /// /// /// private void Window_PreviewKeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Escape) { this.Close(); } } #endregion } }