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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
using DataEntity.Share;
using DataRWDAL;
using DataRWDalDrive.DB;
using DataRWDalDrive.Model;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
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.Navigation;
using System.Windows.Shapes;
using XCommon;
using XCommon.Log;
using XHandler.Class;
using XHandler.Class.DataEx;
using XHandler.View.Consumables;
using XHandler.View.MethodProperty;
using XImagingXhandler.XDAL;
 
namespace XHandler.View.Liquids
{
    /// <summary>
    /// NewLiquid.xaml 的交互逻辑
    /// </summary>
    public partial class NewLiquid : UserControl
    {
 
        public event EventHandler closeEvent;
        public MainWindow mainWindow = null;
 
        ObservableCollection<LiquidType> liquidTypes;
 
        public NewLiquid()
        {
            InitializeComponent();
 
            liquidTypes = DataModule.getInstance().GetLiquidTypes();
            cbLiquidType.ItemsSource = liquidTypes;
            List<DeviceArm> armList = DataModule.getInstance().GetDeviceArm();
            cbLiquidRange.ItemsSource = armList;
            ObservableCollection<LiquidRange> liquidRanges = DataModule.getInstance().GetLiquidRanges();
            cbTipType.ItemsSource = liquidRanges;
        }
 
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            cbLiquidType.SelectedIndex = 0;
            cbLiquidRange.SelectedIndex = 0;
            cbTipType.SelectedIndex = 0;
            textboxLabel.Focus();
        }
 
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (EventResponseController.Instance.CanExecute() == false)
                return;
 
            closeEvent?.Invoke(this, EventArgs.Empty);
        }
 
        private void btnOK_Click(object sender, RoutedEventArgs e)
        {
            bool bResult = false;
            try
            {
 
                if (EventResponseController.Instance.CanExecute() == false)
                    return;
 
                if (string.IsNullOrEmpty(textboxLabel.Text.Trim()))
                {
                    textboxLabel.Text = "";
                    textboxLabel.BorderThickness = new Thickness(1, 1, 1, 1);
                    return;
                }
                string typeID = "";
                //检查type是否存在,不存在插入新的
                if (textboxNewType.Visibility == Visibility.Visible)
                {
                    string typeName = textboxNewType.Text.Trim();
                    if (string.IsNullOrEmpty(typeName))
                    {
                        textboxNewType.Text = "";
                        textboxNewType.BorderThickness = new Thickness(1, 1, 1, 1);
                        return;
                    }
                    LiquidType type = liquidTypes.Where(x => x.liquid_type_name == typeName).FirstOrDefault();
                    if (type == null)
                    {
                        //插入新的type
                        LiquidType liquidType = new LiquidType();
                        liquidType.liquid_type_id = Guid.NewGuid().ToString();
                        liquidType.liquid_type_name = typeName;
                        liquidType.liquid_type_name_en = typeName;
                        liquidType.is_default_type = 0;
                        liquidType.liquid_type_status = 1;
                        int result=LiquidTypeDB.AddLiquidTypeIntodb(liquidType);
                        liquidTypes.Add(liquidType);
 
                        Hashtable hashtable = mainWindow.liquidManagement.logAduitHelper.AddObj(liquidType);
                        string operateContent = string.Empty;
                        foreach (DictionaryEntry d in hashtable)
                        {
                            operateContent += d.Key.ToString() + ":" + d.Value.ToString() + "\r\n";
                        }
                        if (result==1)
                        {
                            OperateAuditLogDB.AddOperateAuditLogIntodb(mainWindow.liquidManagement.operateAuditLogBll.GenerateOperateAuditLog("添加", operateContent, Shared.User.username, "液体管理", "", "", "液体类型[id:" + liquidType.liquid_type_id + "]", "成功"));
                        }
                        else
                        {
                            OperateAuditLogDB.AddOperateAuditLogIntodb(mainWindow.liquidManagement.operateAuditLogBll.GenerateOperateAuditLog("添加", operateContent, Shared.User.username, "液体管理", "", "", "液体类型[id:" + liquidType.liquid_type_id + "]", "失败"));
                        }
 
                        typeID = liquidType.liquid_type_id;
                    }
                }
                else
                    typeID = cbLiquidType.SelectedValue.ToString();
 
                string armID = cbLiquidRange.SelectedValue.ToString();
                string rangeID = cbTipType.SelectedValue.ToString();
                //重名检查
                LiquidTypeRSRange liquidTypeRSRange = new LiquidTypeRSRange();
                liquidTypeRSRange.liquid_range_id = rangeID;
                liquidTypeRSRange.liquid_type_id = typeID;
                liquidTypeRSRange.device_arm_id = Convert.ToInt32(armID);
                int iResult = Convert.ToInt32(LiquidDB.IsExistSameNameLiquidTypeRSRangeIntodb(liquidTypeRSRange, textboxLabel.Text));
                if (iResult == 0)//没有重名的可以添加
                {
                    //先添加到Liquid表
                    //然后添加关系到RSrange表
                    Liquid liquid = new Liquid();
                    liquid.liquid_id = ComUtility.GetGuid();
                    liquid.liquid_name = textboxLabel.Text;
                    liquid.liquid_status = 1;
                    liquid.is_default_type = 0;
                    iResult = LiquidDB.AddLiquidIntodb(liquid);
                    int flag = 0;
                    if (iResult == 1)
                    {
                        liquidTypeRSRange.liquid_id = liquid.liquid_id;
                        liquidTypeRSRange.liquid_rs_status = 1;
                        flag = LiquidTypeRSRangeDB.AddLiquidTypeRSRangeIntodb(liquidTypeRSRange);
                        if (flag == 1)
                        {
                            bResult = true;
                        }
                    }
                    Hashtable hashtable = mainWindow.liquidManagement.logAduitHelper.AddObj(liquid);
                    string operateContent = string.Empty;
                    foreach (DictionaryEntry d in hashtable)
                    {
                        operateContent += d.Key.ToString() + ":" + d.Value.ToString() + "\r\n";
                    }
 
                    if (iResult == 1 && flag == 1)
                    {
                        PlsSetProperty plsSetProperty = new PlsSetProperty($"液体:{liquid.liquid_name} 添加成功", false);
                        plsSetProperty.closeEvent += PlsSetProperty_closeEvent;
                        Window wnd = Application.Current.MainWindow;
                        Grid parent = Utilities.FindVisualChild<Grid>(wnd);
                        parent.Children.Add(plsSetProperty);
                        OperateAuditLogDB.AddOperateAuditLogIntodb(mainWindow.liquidManagement.operateAuditLogBll.GenerateOperateAuditLog("添加", operateContent, Shared.User.username, "液体管理", "", "", "液体[id:" + liquid.liquid_id + "]", "成功"));
                    }
                    else
                    {
                        PlsSetProperty plsSetProperty = new PlsSetProperty($"液体:{liquid.liquid_name} 添加失败", false);
                        plsSetProperty.closeEvent += PlsSetProperty_closeEvent;
                        Window wnd = Application.Current.MainWindow;
                        Grid parent = Utilities.FindVisualChild<Grid>(wnd);
                        parent.Children.Add(plsSetProperty);
                        OperateAuditLogDB.AddOperateAuditLogIntodb(mainWindow.liquidManagement.operateAuditLogBll.GenerateOperateAuditLog("添加", operateContent, Shared.User.username, "液体管理", "", "", "液体[id:" + liquid.liquid_id + "]", "失败"));
                    }
 
                    //
                    if (EventResponseController.Instance.CanExecute() == false)
                        return;
                    closeEvent?.Invoke(this, EventArgs.Empty);
 
 
                }
                else if (iResult > 0)
                {
                    textboxLabel.BorderThickness = new Thickness(1, 1, 1, 1);
                    tbTips.Text = "名称重复";
                    return;
                }
            }
            catch (Exception ex)
            {
                LoggerHelper.ErrorLog("ERROR:", ex);
            }
            finally
            {
                if (bResult)
                {
                    closeEvent?.Invoke(this, EventArgs.Empty);
                }
                mainWindow.liquidManagement.GetLiquidTree();
                mainWindow.SetObserverNode(mainWindow.testDesign.rootMethod);
                mainWindow.liquidManagement.Update();
            }
        }
 
        private void btnClear_Click(object sender, RoutedEventArgs e)
        {
            textboxNewType.Visibility = Visibility.Collapsed;
            btnClear.Visibility = Visibility.Collapsed;
            cbLiquidType.Visibility = Visibility.Visible;
            btnCustome.Visibility = Visibility.Visible;
        }
 
        private void btnCustome_Click(object sender, RoutedEventArgs e)
        {
            textboxNewType.Visibility = Visibility.Visible;
            btnClear.Visibility = Visibility.Visible;
            cbLiquidType.Visibility = Visibility.Collapsed;
            btnCustome.Visibility = Visibility.Collapsed;
            textboxNewType.Focus();
        }
 
        private void textboxLabel_LostFocus(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(textboxLabel.Text.Trim()))
            {
                textboxLabel.Text = "";
                textboxLabel.BorderThickness = new Thickness(1, 1, 1, 1);
                tbTips.Text = "不能为空";
            }
            else if (textboxLabel.Text.Contains(" "))
            {
                textboxLabel.Text = "";
                textboxLabel.BorderThickness = new Thickness(1, 1, 1, 1);
                tbTips.Text = "名称不能包含空格";
            }
            else if (textboxLabel.Text.Trim().Length > 200)
            {
                textboxLabel.Text = textboxLabel.Text.Substring(0, 200);
                textboxLabel.BorderThickness = new Thickness(1, 1, 1, 1);
                tbTips.Text = "长度超出200";
            }
            else
            {
                textboxLabel.BorderThickness = new Thickness(0, 0, 0, 0);
                tbTips.Text = "";
            }
        }
 
        private void textboxNewType_LostFocus(object sender, RoutedEventArgs e)
        {
            string typeName = textboxNewType.Text.Trim();
 
            if (string.IsNullOrEmpty(typeName))
            {
                textboxNewType.Text = "";
                textboxNewType.BorderThickness = new Thickness(1, 1, 1, 1);
                tbTips.Text = "不能为空";
            }
            else if (typeName.Length > 200)
            {
                textboxNewType.Text = textboxNewType.Text.Substring(0, 200);
                textboxNewType.BorderThickness = new Thickness(1, 1, 1, 1);
                tbTips.Text = "长度超出200";
            }
            else if (Convert.ToInt32(LiquidDB.IsExistLiquidTypeIntodb(typeName)) > 0)
            {
                textboxNewType.Text = "";
                textboxNewType.BorderThickness = new Thickness(1, 1, 1, 1);
                tbTips.Text = "自定义类型重复";
            }
            else
            {
                textboxNewType.BorderThickness = new Thickness(0, 0, 0, 0);
            }
        }
 
        private void PlsSetProperty_closeEvent(object sender, EventArgs e)
        {
            Window wnd = Application.Current.MainWindow;
            Grid grid = Utilities.FindVisualChild<Grid>(wnd);
 
            UIElement element = sender as UIElement;
            grid.Children.Remove(element);
        }
    }
}