schangxiang@126.com
2025-11-04 f5ed29dc26c7cd952d56ec5721a2efc43cd25992
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
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
    }
}