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 { /// /// NewLiquid.xaml 的交互逻辑 /// public partial class NewLiquid : UserControl { public event EventHandler closeEvent; public MainWindow mainWindow = null; ObservableCollection liquidTypes; public NewLiquid() { InitializeComponent(); liquidTypes = DataModule.getInstance().GetLiquidTypes(); cbLiquidType.ItemsSource = liquidTypes; List armList = DataModule.getInstance().GetDeviceArm(); cbLiquidRange.ItemsSource = armList; ObservableCollection 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(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(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(wnd); UIElement element = sender as UIElement; grid.Children.Remove(element); } } }