| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Collections.ObjectModel; |
| | | using System.ComponentModel; |
| | | using System.Linq; |
| | | using System.Reflection; |
| | | using System.Windows; |
| | | using HMI.Core.Entity; |
| | | using HMI.ParameterManage.Model; |
| | | using HMI.UI.DpUtil; |
| | | using HMI.UI.Util; |
| | | using Microsoft.Win32; |
| | | using Panuon.WPF.UI; |
| | | using HMI.Core.Annotation; |
| | | using HMI.Core.Entity; |
| | | using HMI.Core.Exceptions; |
| | | using HMI.Core.Util; |
| | | using HMI.ParameterManage.Entity; |
| | | using HMI.UI; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.ComponentModel; |
| | | using System.Windows.Controls; |
| | | |
| | | namespace HMI.ParameterManage |
| | | { |
| | |
| | | /// </summary> |
| | | public partial class ParameterModal : WindowX |
| | | { |
| | | public ParameterModal() |
| | | private XmlModel DataModel; |
| | | public ParameterModal(XmlModel model) |
| | | { |
| | | DataModel = model; |
| | | this.DataContext = this; |
| | | InitializeComponent(); |
| | | } |
| | | |
| | | public ParameterData Data { get; set; } |
| | | |
| | | public SqliteHelper sqliteHelper { get; set; } |
| | | |
| | | private bool _isProcessing; |
| | | |
| | |
| | | return; |
| | | } |
| | | |
| | | SaveOrUpdateData(); |
| | | DataModel.SaveOrUpdateParameter(Data); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | Panuon.WPF.UI.Toast.Show(this, "Error!", ToastPosition.Top); |
| | | ToastHelper.Error(this, $"Error: {ex.Message}"); |
| | | e.Cancel = true; |
| | | return; |
| | | } |
| | |
| | | |
| | | public bool ValidateName(object value, out string err) |
| | | { |
| | | err = null; |
| | | string segment = string.IsNullOrEmpty(Data.Id) ? "" : $" AND id!='{Data.Id}'"; |
| | | string sql = $"SELECT 1 FROM parameter WHERE name='{TbName.Text}' AND productName='{Data.ProductName}'{segment};"; |
| | | if (sqliteHelper.HasData(sql)) |
| | | { |
| | | err = "参数名称不能重复"; |
| | | return false; |
| | | } |
| | | return true; |
| | | return DataModel.ValidateParameterName(value, out err); |
| | | } |
| | | |
| | | private bool ValidateForm() |
| | | { |
| | | bool flag = FormGroupHelper.ValidateForm(formPanel); |
| | | bool flag = FormGroupHelper.ValidateForm(formPanel, new Dictionary<string, object> { |
| | | { "FgValue",GetTargetValue()} |
| | | }); |
| | | if (flag) |
| | | { |
| | | Data.Name = TbName.Text; |
| | | Data.Value = TbValue.Text; |
| | | Data.Type = CbType.Text; |
| | | Data.Value = GetTargetValue(); |
| | | Data.Unit = TbUnit.Text; |
| | | Data.Description = TbDescription.Text; |
| | | Data.ProductName = TbProductName.Text; |
| | | Data.PGroup = TbPGroup.Text; |
| | | Data.PGroup = CbGroup.Text; |
| | | } |
| | | return flag; |
| | | } |
| | | |
| | | public bool? Open(ParameterData data) |
| | | public bool? Open(string productName, ParameterData data, List<string> groups) |
| | | { |
| | | Data = data; |
| | | TbName.Text = Data.Name; |
| | | TbValue.Text = Data.Value; |
| | | CbType.SelectedValue = Data.Type; |
| | | CbGroup.ItemsSource = groups; |
| | | UpdateWindow(Data.Type); |
| | | UpdateForm(Data); |
| | | TbUnit.Text = Data.Unit; |
| | | TbProductName.Text = Data.ProductName; |
| | | TbProductName.Text = productName; |
| | | TbDescription.Text = Data.Description; |
| | | TbPGroup.Text = Data.PGroup; |
| | | CbGroup.Text = Data.PGroup; |
| | | return this.ShowDialog(); |
| | | } |
| | | |
| | | private void SaveOrUpdateData() |
| | | private string GetTargetValue() |
| | | { |
| | | if (string.IsNullOrEmpty(Data.Id)) |
| | | if (CbType.Text == "Int" || Data.Type == "Double") |
| | | { |
| | | InsertData(Data); |
| | | return NiNumberValue.Text; |
| | | } |
| | | else if (CbType.Text == "Bool") |
| | | { |
| | | return CbBoolValue.Text; |
| | | } |
| | | else |
| | | { |
| | | UpdateData(Data); |
| | | return TbStringValue.Text; |
| | | } |
| | | } |
| | | |
| | | public void InsertData(ParameterData data) |
| | | private void UpdateForm(ParameterData data) |
| | | { |
| | | string sql = $@"INSERT INTO parameter (name,value,unit,description,productName,pGroup) |
| | | VALUES |
| | | ('{data.Name}','{data.Value}','{data.Unit}','{data.Description}','{data.ProductName}','{data.PGroup}');"; |
| | | sqliteHelper.ExecuteSql(sql); |
| | | if (Data.Type == "Int" || Data.Type == "Int") |
| | | { |
| | | NiNumberValue.Text = Data.Value; |
| | | } |
| | | else if (Data.Type == "Bool") |
| | | { |
| | | CbBoolValue.SelectedValue = Data.Value; |
| | | } |
| | | else |
| | | { |
| | | TbStringValue.Text = Data.Value; |
| | | } |
| | | } |
| | | |
| | | public void UpdateData(ParameterData data) |
| | | private void UpdateWindow(string type) |
| | | { |
| | | string sql = $@"UPDATE parameter SET name='{data.Name}',value='{data.Value}',unit='{data.Unit}', |
| | | description='{data.Description}',productName='{data.ProductName}',pGroup='{data.PGroup}' WHERE id='{data.Id}';"; |
| | | sqliteHelper.ExecuteSql(sql); |
| | | if (type == "Int" || type == "Double") |
| | | { |
| | | NiNumberValue.Visibility = System.Windows.Visibility.Visible; |
| | | StringValueGrid.Visibility = System.Windows.Visibility.Collapsed; |
| | | CbBoolValue.Visibility = System.Windows.Visibility.Collapsed; |
| | | } |
| | | else if (type == "Bool") |
| | | { |
| | | NiNumberValue.Visibility = System.Windows.Visibility.Collapsed; |
| | | StringValueGrid.Visibility = System.Windows.Visibility.Collapsed; |
| | | CbBoolValue.Visibility = System.Windows.Visibility.Visible; |
| | | } |
| | | else |
| | | { |
| | | NiNumberValue.Visibility = System.Windows.Visibility.Collapsed; |
| | | StringValueGrid.Visibility = System.Windows.Visibility.Visible; |
| | | CbBoolValue.Visibility = System.Windows.Visibility.Collapsed; |
| | | } |
| | | } |
| | | |
| | | private void CbType_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e) |
| | | { |
| | | string val = null; |
| | | if (e.AddedItems != null && e.AddedItems.Count > 0) |
| | | { |
| | | val = ((ComboBoxItem)e.AddedItems[0]).Content.ToString(); |
| | | } |
| | | UpdateWindow(val); |
| | | } |
| | | |
| | | private void Button_Click(object sender, System.Windows.RoutedEventArgs e) |
| | | { |
| | | OpenFileDialog ofd = new OpenFileDialog(); |
| | | if (ofd.ShowDialog() == true) |
| | | { |
| | | TbStringValue.Text = ofd.FileName; |
| | | } |
| | | } |
| | | } |
| | | } |