using HMI.UI.DpUtil;
|
using HMI.UI.Util;
|
using HMI.Util;
|
using Microsoft.Win32;
|
using Panuon.WPF.UI;
|
using Plugin.CurrentSensorControl.Entity;
|
using System.Collections.ObjectModel;
|
using System.ComponentModel;
|
using System.Windows.Controls;
|
|
namespace Plugin.CurrentSensorControl
|
{
|
/// <summary>
|
/// ModalWindow.xaml 的交互逻辑
|
/// </summary>
|
public partial class BurnInSettingModal : WindowX
|
{
|
public BurnInSettingModal()
|
{
|
this.DataContext = this;
|
InitializeComponent();
|
}
|
|
private ObservableCollection<PLCTagData> datasource;
|
|
public ObservableCollection<PLCTagData> Datasource
|
{
|
get => datasource;
|
set
|
{
|
Set(ref datasource, value);
|
}
|
}
|
|
private bool _isProcessing;
|
|
protected override void OnClosing(CancelEventArgs e)
|
{
|
//Press Continue Button
|
if (DialogResult == true)
|
{
|
if (_isProcessing)
|
{
|
e.Cancel = true;
|
return;
|
}
|
var okButton = WindowXModalDialog.GetOKButton(this);
|
try
|
{
|
_isProcessing = true;
|
ButtonHelper.SetIsPending(okButton, true);
|
|
}
|
catch (Exception ex)
|
{
|
ToastHelper.Error(this, $"Error!{ex.Message}");
|
e.Cancel = true;
|
return;
|
}
|
finally
|
{
|
_isProcessing = false;
|
ButtonHelper.SetIsPending(okButton, false);
|
}
|
}
|
base.OnClosing(e);
|
}
|
|
private bool ValidateName(object value, out string err)
|
{
|
err = null;
|
//string group = TbGroup.Text;
|
//var temp = Datasource.FirstOrDefault(d => d.Group == group && d.Name == value.ToString());
|
//if (temp != null && temp != Data)
|
//{
|
// err = this.lang("App.MustBeUnique", $"{this.lang("doc.group")},{this.lang("doc.name")}");
|
// return false;
|
//}
|
return true;
|
}
|
|
private bool ValidateAddress(object value, out string err)
|
{
|
err = null;
|
//string group = TbGroup.Text;
|
//var temp = Datasource.FirstOrDefault(d => d.Address == value.ToString());
|
//if (temp != null && temp != Data)
|
//{
|
// err = this.lang("App.MustBeUnique", this.lang("doc.Address"));
|
// return false;
|
//}
|
return true;
|
}
|
|
public bool? Open( ObservableCollection<PLCTagData> datasource)
|
{
|
this.Datasource = datasource;
|
return this.ShowDialog();
|
}
|
|
private void DoExport()
|
{
|
SaveFileDialog sfd = new SaveFileDialog();
|
if (sfd.ShowDialog() == true)
|
{
|
ExcelHelper.ExportExcel(sfd.FileName, Datasource);
|
}
|
}
|
|
private void DoImport()
|
{
|
OpenFileDialog ofd = new OpenFileDialog();
|
if (ofd.ShowDialog() == true)
|
{
|
try
|
{
|
Datasource = new ObservableCollection<PLCTagData>(ExcelHelper.ReadFromExcel<PLCTagData>(ofd.FileName));
|
}
|
catch (Exception ex)
|
{
|
ControlPage.Logger.Error("Import Error.", ex);
|
ToastHelper.Error(ex.Message);
|
}
|
}
|
}
|
|
private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
|
{
|
var btn = sender as Button;
|
switch (btn.Name) {
|
case "exportBtn":
|
DoExport();
|
break;
|
case "importBtn":
|
DoImport();
|
break;
|
default:
|
break;
|
}
|
|
}
|
}
|
}
|