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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
using DataEntity.Device;
using DataEntity.Share;
using DataRWDAL.Device;
using HandyControl.Data;
using HxEnum;
using System;
using System.Data;
using System.Linq;
using System.Windows;
using System.Windows.Input;
using XCommon;
using XCommon.Log;
using XCommon.Tip;
using XHandler.View.Dialog;
 
namespace XHandler.View.Device
{
    /// <summary>
    /// 方法参数编辑 页面
    /// </summary>
    public partial class DeviceMethodParametersAdd : System.Windows.Window
    {
        #region 参数
        /// <summary>
        /// 操作类型(添加、修改)
        /// </summary>
        public string OperationType = "";
 
        /// <summary>
        /// 主键ID
        /// </summary>
        public string MethodParameterId = "";
 
        /// <summary>
        /// 设备ID
        /// </summary>
        public string DeviceconfigId = "";
 
        /// <summary>
        /// 委托列表数据
        /// </summary>
        public delegate void DelegateForm();
        /// <summary>
        /// 委托方法名称
        /// </summary>
        public event DelegateForm LoadListEveForm;
        #endregion
 
        #region 构造函数
        /// <summary>
        /// 构造函数
        /// </summary>
        public DeviceMethodParametersAdd()
        {
            InitializeComponent();
        }
        #endregion
 
        #region 初始化
        /// <summary>
        /// 初始化
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                #region 数据类型
                cBoxDataType.ItemsSource = ComUtility.GetDropDownList<ParameterDataTypeEnum>();
                cBoxDataType.SelectedIndex = 0;
                #endregion
 
                #region 类别
                cBoxType.ItemsSource = ComUtility.GetDropDownList<ParameterTypeEnum>();
                cBoxType.SelectedIndex = 0;
                #endregion
 
                if (OperationType == OperationTypeEnum.OperationType_Enum.EditEnum.ToString())
                {
                    var model = DeviceConfigMethodParametersDB.GetInfodById(MethodParameterId);
                    if (model != null)
                    {
                        // 数据类型
                        cBoxDataType.SelectedValue = Convert.ToInt32(model.DataType);
                        // 类别
                        cBoxType.SelectedValue = Convert.ToInt32(model.Type);
                        // 参数中文名称
                        tBoxParameterChName.Text = model.Name;
                        // 参数英文名称
                        tBoxParameterEnName.Text = model.ParameterName;
                        // 参数值
                        tBoxValue.Text = model.Value;
                        // 排序
                        tBoxSort.Text = model.Sort.ToString();
                        // 备注
                        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;
            }
 
            DeviceConfigMethodParametersModel deviceconfigMethodParametersModel = new DeviceConfigMethodParametersModel();
            int updateCnt = 0;
 
            if (OperationType == OperationTypeEnum.OperationType_Enum.EditEnum.ToString())
            {
                deviceconfigMethodParametersModel = DeviceConfigMethodParametersDB.GetInfodById(MethodParameterId);
                deviceconfigMethodParametersModel.Id = MethodParameterId;
                deviceconfigMethodParametersModel.ModifyName = Shared.User.username;
                deviceconfigMethodParametersModel.ModifyTime = DateTime.Now;
            }
            else
            {
                deviceconfigMethodParametersModel.Id = Guid.NewGuid().ToString();
                deviceconfigMethodParametersModel.DeviceconfigId = DeviceconfigId;
                deviceconfigMethodParametersModel.DeviceconfigMethodId = MethodParameterId;
                deviceconfigMethodParametersModel.ProjectId = Shared.SoftwareInformation.software_information_id;
                deviceconfigMethodParametersModel.CreateTime = DateTime.Now;
                deviceconfigMethodParametersModel.CreatName = Shared.User.username;
            }
 
            deviceconfigMethodParametersModel.DataType = Convert.ToInt32(cBoxDataType.SelectedValue);
            deviceconfigMethodParametersModel.Type = Convert.ToInt32(cBoxType.SelectedValue);
            deviceconfigMethodParametersModel.Name = tBoxParameterChName.Text;
            deviceconfigMethodParametersModel.ParameterName = tBoxParameterEnName.Text;
            deviceconfigMethodParametersModel.Value = tBoxValue.Text;
            deviceconfigMethodParametersModel.Sort = Convert.ToInt32(tBoxSort.Text);
            deviceconfigMethodParametersModel.Remark = tBoxRemark.Text;
            deviceconfigMethodParametersModel.IsSocketNonstandard = EnumManagement.GetEnumValue(IsSocketNonstandardEnum.TypeBEnum);
 
            if (OperationType == OperationTypeEnum.OperationType_Enum.EditEnum.ToString())
            {
                updateCnt = DeviceConfigMethodParametersDB.Update(deviceconfigMethodParametersModel);
            }
            else
            {
                updateCnt = DeviceConfigMethodParametersDB.Add(deviceconfigMethodParametersModel);
            }
 
            if (updateCnt > 0)
            {
                LoadListEveForm();
                //new MessageDialog("保存成功").ShowDialog();
                ShowTip.ShowNotice("保存成功", InfoType.Success);
                this.Close();
            }
        }
 
        /// <summary>
        /// 检查输入数据
        /// </summary>
        /// <returns></returns>
        private bool CheckData()
        {
            if (string.IsNullOrWhiteSpace(tBoxParameterChName.Text))
            {
                //new MessageDialog("请填写参数中文名称").ShowDialog();
                ShowTip.ShowNotice("请填写参数中文名称", InfoType.Warning);
                tBoxParameterChName.Focus();
                return false;
            }
            if (string.IsNullOrWhiteSpace(tBoxParameterEnName.Text))
            {
                //new MessageDialog("请填写参数英文名称").ShowDialog();
                ShowTip.ShowNotice("请填写参数英文名称", InfoType.Warning);
                tBoxParameterEnName.Focus();
                return false;
            }
 
            var devMethodParametersModel = DeviceConfigMethodParametersDB.GetInfo(DeviceconfigId, MethodParameterId, Convert.ToInt32(cBoxType.SelectedValue),
                tBoxParameterEnName.Text);
            if (OperationType == OperationTypeEnum.OperationType_Enum.EditEnum.ToString())
            {
                if (devMethodParametersModel != null && devMethodParametersModel.Count > 0)
                {
                    var tempList = devMethodParametersModel.Where(x => x.Id != MethodParameterId);
                    if (tempList != null && tempList.Count() > 0)
                    {
                        //new MessageDialog("参数英文名已存在").ShowDialog();
                        ShowTip.ShowNotice("参数英文名已存在", InfoType.Warning);
                        tBoxParameterEnName.Focus();
                        return false;
                    }
                }
            }
            else
            {
                if (devMethodParametersModel != null && devMethodParametersModel.Count > 0)
                {
                    //new MessageDialog("参数英文名已存在").ShowDialog();
                    ShowTip.ShowNotice("参数英文名已存在", InfoType.Warning);
                    tBoxParameterEnName.Focus();
                    return false;
                }
            }
 
            if (string.IsNullOrWhiteSpace(tBoxSort.Text))
            {
                //new MessageDialog("请填写排序号").ShowDialog();
                ShowTip.ShowNotice("请填写排序号", InfoType.Warning);
                tBoxSort.Focus();
                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
    }
}