| | |
| | | using HMI.AlarmInfoManage.Entity; |
| | | using HMI.Core.Entity; |
| | | using HMI.Core.Util; |
| | | using HMI.UI.DpUtil; |
| | | using HMI.UI.Util; |
| | | using HMI.Util.Alarm; |
| | | using log4net; |
| | | using Panuon.WPF.UI; |
| | | using System; |
| | | using System.Collections.ObjectModel; |
| | | using System.ComponentModel; |
| | | using System.Linq; |
| | | using System.Windows; |
| | | |
| | | namespace HMI.AlarmInfoManage |
| | | { |
| | |
| | | InitializeComponent(); |
| | | } |
| | | private ILog log; |
| | | public string FilePath { get; private set; } |
| | | private bool isBlock; |
| | | public int DataIndex { get; private set; } |
| | | public AlarmSetting Data { get; private set; } |
| | | public ObservableCollection<AlarmSetting> Datasource { get; private set; } |
| | |
| | | public bool ValidateDBAddress(object value, out string err) |
| | | { |
| | | err = null; |
| | | int dbAddress = Convert.ToInt32(value); |
| | | if (Datasource.FirstOrDefault(e => e.DBAddress == dbAddress) != null) |
| | | var target = Datasource?.FirstOrDefault(e => e.DBAddress == value); |
| | | if (target != null && target != Data) |
| | | { |
| | | err = this.lang("App.MustBeUnique", this.lang("Alm.DbAddress")); |
| | | return false; |
| | |
| | | bool flag = FormGroupHelper.ValidateForm(formPanel); |
| | | if (flag) |
| | | { |
| | | Data.DBAddress = Convert.ToInt32(dbAddress.Value); |
| | | Data.StartAddress = Convert.ToInt32(startAddress.Value); |
| | | Data.DBAddress = dbAddress.Text; |
| | | Data.StartAddress = startAddress.Text; |
| | | Data.Length = Convert.ToInt32(length.Value); |
| | | Data.AlarmCode = TbCode.Text; |
| | | Data.Level = NiLevel.Value ?? 0d; |
| | | Data.Description = TbDesc.Text; |
| | | } |
| | | return flag; |
| | | } |
| | | |
| | | public bool? Open(int index, AlarmSetting data, |
| | | ObservableCollection<AlarmSetting> dataSource, |
| | | string filePath) |
| | | ObservableCollection<AlarmSetting> dataSource, bool isBlock) |
| | | { |
| | | FilePath = filePath; |
| | | this.isBlock = isBlock; |
| | | FgCode.Visibility = isBlock ? Visibility.Visible : Visibility.Collapsed; |
| | | DataIndex = index; |
| | | Data = data; |
| | | Datasource = dataSource; |
| | | dbAddress.Value = Data.DBAddress; |
| | | startAddress.Value = Data.StartAddress; |
| | | dbAddress.Text = Data.DBAddress; |
| | | startAddress.Text = Data.StartAddress; |
| | | length.Value = Data.Length; |
| | | TbCode.Text = Data.AlarmCode; |
| | | NiLevel.Value = Data.Level; |
| | | TbDesc.Text = Data.Description; |
| | | return this.ShowDialog(); |
| | | } |
| | | |
| | |
| | | public void InsertData(AlarmSetting data) |
| | | { |
| | | Datasource.Add(data); |
| | | XmlHelper.SerializeToXml(FilePath, Datasource); |
| | | if (this.isBlock) |
| | | { |
| | | AlarmUtil.UpdateBlockSettings(Datasource); |
| | | } |
| | | else |
| | | { |
| | | AlarmUtil.UpdateMarkSettings(Datasource); |
| | | } |
| | | } |
| | | |
| | | public void UpdateData(int index, AlarmSetting data) |
| | | { |
| | | Datasource[index] = data; |
| | | XmlHelper.SerializeToXml(FilePath, Datasource); |
| | | if (this.isBlock) |
| | | { |
| | | AlarmUtil.UpdateBlockSettings(Datasource); |
| | | } |
| | | else |
| | | { |
| | | AlarmUtil.UpdateMarkSettings(Datasource); |
| | | } |
| | | } |
| | | } |
| | | } |