using DevExpress.XtraEditors;
|
using IStation.Unit;
|
using System.Collections.Generic;
|
using System.Data;
|
using System.Linq;
|
|
namespace IStation.WinFrmUI.Basic
|
{
|
public partial class SignalTypeMgrPage : DocumentPage
|
{
|
public SignalTypeMgrPage()
|
{
|
InitializeComponent();
|
this.PageTitle.Caption = "信号类型";
|
|
this.gridView1.SetNormalView();
|
this.gridView1.RegistCustomDrawRowIndicator();
|
this.gridView1.ShowViewCaption();
|
this.gridView1.OptionsView.ShowViewCaption = false;
|
|
this.gridView1.OptionsBehavior.Editable = true;
|
this.gridView1.FocusRectStyle = DevExpress.XtraGrid.Views.Grid.DrawFocusRectStyle.CellFocus;
|
}
|
|
#region 当前视图
|
|
public class CurrentViewModel
|
{
|
public CurrentViewModel() { }
|
public CurrentViewModel(Model.SignalType rhs)
|
{
|
this.ID = rhs.Id;
|
this.Identifier = rhs.Identifier;
|
this.GroupID = rhs.GroupId;
|
this.Name = rhs.Name;
|
this.UnitType = rhs.UnitType.GetDisplayText();
|
|
var dict = UnitHelper.GetEnUnitDict(rhs.UnitType);
|
if (dict == null || dict.Count < 1)
|
{
|
this.UnitValue = rhs.UnitValue;
|
}
|
else
|
{
|
if (int.TryParse(rhs.UnitValue, out int unitValue))
|
{
|
if (dict.ContainsKey(unitValue))
|
{
|
this.UnitValue = dict[unitValue];
|
}
|
}
|
}
|
this.DecimalPlaces = rhs.DecimalPlaces;
|
this.ValueType = rhs.ValueType.GetDisplayText();
|
this.ValueSettings = rhs.GetSingleDisplayValueSettings();
|
this.TagName = rhs.TagName;
|
this.SortCode = rhs.SortCode;
|
this.Description = rhs.Description;
|
this.Model = rhs;
|
}
|
|
public void Reset(Model.SignalType rhs)
|
{
|
this.ID = rhs.Id;
|
this.Identifier = rhs.Identifier;
|
this.GroupID = rhs.GroupId;
|
this.Name = rhs.Name;
|
this.UnitType = rhs.UnitType.GetDisplayText();
|
|
var dict = UnitHelper.GetEnUnitDict(rhs.UnitType);
|
if (dict == null || dict.Count < 1)
|
{
|
this.UnitValue = rhs.UnitValue;
|
}
|
else
|
{
|
if (int.TryParse(rhs.UnitValue, out int unitValue))
|
{
|
if (dict.ContainsKey(unitValue))
|
{
|
this.UnitValue = dict[unitValue];
|
}
|
}
|
}
|
this.DecimalPlaces = rhs.DecimalPlaces;
|
this.ValueType = rhs.ValueType.GetDisplayText();
|
this.ValueSettings = rhs.GetSingleDisplayValueSettings();
|
this.TagName = rhs.TagName;
|
this.SortCode = rhs.SortCode;
|
this.Description = rhs.Description;
|
this.Model = rhs;
|
}
|
|
public long ID { get; set; }
|
public string Identifier { get; set; }
|
public long GroupID { get; set; }
|
public string Name { get; set; }
|
public string UnitType { get; set; }
|
public string UnitValue { get; set; }
|
public int? DecimalPlaces { get; set; }
|
public string ValueType { get; set; }
|
public string ValueSettings { get; set; }
|
public string TagName { get; set; }
|
public int SortCode { get; set; }
|
public string Description { get; set; }
|
|
public Model.SignalType Model { get; set; }
|
|
}
|
|
#endregion
|
|
private List<CurrentViewModel> _allList = null;//所有列表
|
private List<CurrentViewModel> _allBindingList = null;//所有绑定的列表
|
private Model.SignalTypeGroup _group = null;//当前分组
|
|
public override void InitialDataSource()
|
{
|
var all = new BLL.Scatl.SignalType().GetAll();
|
if (all == null)
|
{
|
all = new List<Model.SignalType>();
|
}
|
_allList = all.Select(x => new CurrentViewModel(x)).ToList();
|
this.signalTypeGroupMgrCtrl1.SetBindingData();
|
}
|
|
public override void RefreshDataSource()
|
{
|
InitialDataSource();
|
var group = this.signalTypeGroupMgrCtrl1.GetFocused();
|
SelectGroup(group);
|
}
|
|
private void RefreshData()
|
{
|
WaitFrmHelper.ShowWaitForm("正在加载数据,请稍后...");
|
RefreshDataSource();
|
WaitFrmHelper.HideWaitForm();
|
}
|
|
//选择组
|
private void SelectGroup(Model.SignalTypeGroup obj)
|
{
|
_group = obj;
|
this.barBtnAddChildGroup.Enabled = obj != null;
|
this.barBtnEditGroup.Enabled = obj != null;
|
this.barBtnDeleteGroup.Enabled = obj != null;
|
this.barBtnViewGroup.Enabled = obj != null;
|
if (obj == null)
|
{
|
_allBindingList = new List<CurrentViewModel>();
|
this.currentViewModelBindingSource.DataSource = _allBindingList;
|
this.currentViewModelBindingSource.ResetBindings(false);
|
this.gridView1.OptionsView.ShowViewCaption = false;
|
return;
|
}
|
_allBindingList = _allList.Where(x => x.GroupID == obj.Id).OrderBy(x => x.SortCode).ToList();
|
this.currentViewModelBindingSource.DataSource = _allBindingList;
|
this.currentViewModelBindingSource.ResetBindings(false);
|
this.gridView1.ViewCaption = $" {obj.Name}";
|
this.gridView1.OptionsView.ShowViewCaption = true;
|
}
|
|
//选择组改变
|
private void signalTypeGroupMgrCtrl1_FocusedChangedEvent(Model.SignalTypeGroup obj)
|
{
|
SelectGroup(obj);
|
}
|
|
//添加根分组
|
private void barBtnAddRootGroup_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
this.signalTypeGroupMgrCtrl1.AddRoot();
|
}
|
|
//添加子分组
|
private void barBtnAddChildGroup_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
this.signalTypeGroupMgrCtrl1.AddChild();
|
}
|
|
//编辑分组
|
private void barBtnEditGroup_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
this.signalTypeGroupMgrCtrl1.Edit();
|
}
|
|
//删除分组
|
private void barBtnDeleteGroup_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
this.signalTypeGroupMgrCtrl1.Delete();
|
}
|
|
//查看分组
|
private void barBtnViewGroup_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
this.signalTypeGroupMgrCtrl1.View();
|
}
|
|
//添加数值类型
|
private void barBtnAddNumeric_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
if (_group == null)
|
return;
|
var sort_code = _allBindingList.Count > 0 ? _allBindingList.Max(x => x.SortCode) + 1 : 1;
|
WaitFrmHelper.ShowWaitForm();
|
var dlg = new AddNumericSignalTypeDlg();
|
dlg.Shown += delegate { WaitFrmHelper.HideWaitForm(); };
|
dlg.SetBindingData(_group.Id, sort_code);
|
dlg.ValidIdentifierUniqueEvent += (tagname) =>
|
{
|
return !_allList.Exists(x => x.TagName == tagname);
|
};
|
dlg.ReloadDataEvent += (rhs) =>
|
{
|
var vm = new CurrentViewModel(rhs);
|
_allList.Add(vm);
|
SelectGroup(_group);
|
XtraMessageBox.Show("添加成功!");
|
};
|
dlg.ShowDialog();
|
}
|
|
//添加枚举类型
|
private void barBtnAddEnum_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
if (_group == null)
|
return;
|
var sort_code = _allBindingList.Count > 0 ? _allBindingList.Max(x => x.SortCode) + 1 : 1;
|
WaitFrmHelper.ShowWaitForm();
|
var dlg = new AddEnumSignalTypeDlg();
|
dlg.Shown += delegate { WaitFrmHelper.HideWaitForm(); };
|
dlg.SetBindingData(_group.Id, sort_code);
|
dlg.ValidIdentifierUniqueEvent += (tagname) =>
|
{
|
return !_allList.Exists(x => x.TagName == tagname);
|
};
|
dlg.ReloadDataEvent += (rhs) =>
|
{
|
var vm = new CurrentViewModel(rhs);
|
_allList.Add(vm);
|
SelectGroup(_group);
|
XtraMessageBox.Show("添加成功!");
|
};
|
dlg.ShowDialog();
|
}
|
|
//添加集合类型
|
private void barBtnAddNumericList_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
if (_group == null)
|
return;
|
var sort_code = _allBindingList.Count > 0 ? _allBindingList.Max(x => x.SortCode) + 1 : 1;
|
WaitFrmHelper.ShowWaitForm();
|
var dlg = new AddNumericListSignalTypeDlg();
|
dlg.Shown += delegate { WaitFrmHelper.HideWaitForm(); };
|
dlg.SetBindingData(_group.Id, sort_code);
|
dlg.ValidIdentifierUniqueEvent += (tagname) =>
|
{
|
return !_allList.Exists(x => x.TagName == tagname);
|
};
|
dlg.ReloadDataEvent += (rhs) =>
|
{
|
var vm = new CurrentViewModel(rhs);
|
_allList.Add(vm);
|
SelectGroup(_group);
|
XtraMessageBox.Show("添加成功!");
|
};
|
dlg.ShowDialog();
|
}
|
|
//添加集成类型
|
private void barBtnAddIntegration_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
if (_group == null)
|
return;
|
var sort_code = _allBindingList.Count > 0 ? _allBindingList.Max(x => x.SortCode) + 1 : 1;
|
WaitFrmHelper.ShowWaitForm();
|
var dlg = new AddIntegrationSignalTypeDlg();
|
dlg.Shown += delegate { WaitFrmHelper.HideWaitForm(); };
|
dlg.SetBindingData(_group.Id, sort_code);
|
dlg.ValidIdentifierUniqueEvent += (tagname) =>
|
{
|
return !_allList.Exists(x => x.TagName == tagname);
|
};
|
dlg.ReloadDataEvent += (rhs) =>
|
{
|
var vm = new CurrentViewModel(rhs);
|
_allList.Add(vm);
|
SelectGroup(_group);
|
XtraMessageBox.Show("添加成功!");
|
};
|
dlg.ShowDialog();
|
}
|
|
//编辑类型
|
private void barBtnEdit_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
if (_group == null)
|
return;
|
var vm = this.gridView1.GetCurrentViewModel(_allBindingList);
|
if (vm == null)
|
{
|
XtraMessageBox.Show("请选择数据行!");
|
return;
|
}
|
WaitFrmHelper.ShowWaitForm();
|
switch (vm.Model.ValueType)
|
{
|
case Model.Monitor.eValueType.Numeric:
|
{
|
var dlg = new EditNumericSignalTypeDlg();
|
dlg.Shown += delegate { WaitFrmHelper.HideWaitForm(); };
|
dlg.SetBindingData(vm.Model);
|
dlg.ValidIdentifierUniqueEvent += (id, tagname) =>
|
{
|
return !_allList.Exists(x => x.ID != id && x.TagName == tagname);
|
};
|
dlg.ReloadDataEvent += (rhs) =>
|
{
|
vm.Reset(rhs);
|
SelectGroup(_group);
|
XtraMessageBox.Show("更新成功!");
|
};
|
dlg.ShowDialog();
|
}
|
break;
|
case Model.Monitor.eValueType.Enum:
|
{
|
var dlg = new EditEnumSignalTypeDlg();
|
dlg.Shown += delegate { WaitFrmHelper.HideWaitForm(); };
|
dlg.SetBindingData(vm.Model);
|
dlg.ValidIdentifierUniqueEvent += (id, tagname) =>
|
{
|
return !_allList.Exists(x => x.ID != id && x.TagName == tagname);
|
};
|
dlg.ReloadDataEvent += (rhs) =>
|
{
|
vm.Reset(rhs);
|
SelectGroup(_group);
|
XtraMessageBox.Show("更新成功!");
|
};
|
dlg.ShowDialog();
|
}
|
break;
|
case Model.Monitor.eValueType.Array:
|
{
|
var dlg = new EditNumericListSignalTypeDlg();
|
dlg.Shown += delegate { WaitFrmHelper.HideWaitForm(); };
|
dlg.SetBindingData(vm.Model);
|
dlg.ValidIdentifierUniqueEvent += (id, tagname) =>
|
{
|
return !_allList.Exists(x => x.ID != id && x.TagName == tagname);
|
};
|
dlg.ReloadDataEvent += (rhs) =>
|
{
|
vm.Reset(rhs);
|
SelectGroup(_group);
|
XtraMessageBox.Show("更新成功!");
|
};
|
dlg.ShowDialog();
|
}
|
break;
|
case Model.Monitor.eValueType.Integration:
|
{
|
var dlg = new EditIntegrationSignalTypeDlg();
|
dlg.Shown += delegate { WaitFrmHelper.HideWaitForm(); };
|
dlg.SetBindingData(vm.Model);
|
dlg.ValidIdentifierUniqueEvent += (id, tagname) =>
|
{
|
return !_allList.Exists(x => x.ID != id && x.TagName == tagname);
|
};
|
dlg.ReloadDataEvent += (rhs) =>
|
{
|
vm.Reset(rhs);
|
SelectGroup(_group);
|
XtraMessageBox.Show("更新成功!");
|
};
|
dlg.ShowDialog();
|
}
|
break;
|
default: break;
|
}
|
}
|
|
//删除类型
|
private void barBtnDelete_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
if (_group == null)
|
return;
|
var vm = this.gridView1.GetCurrentViewModel(_allBindingList);
|
if (vm == null)
|
{
|
XtraMessageBox.Show("请选择数据行!");
|
return;
|
}
|
XtraMessageBox.Show("正在开发中,敬请期待...");
|
}
|
|
//查看类型
|
private void barBtnView_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
if (_group == null)
|
return;
|
var vm = this.gridView1.GetCurrentViewModel(_allBindingList);
|
if (vm == null)
|
{
|
XtraMessageBox.Show("请选择数据行!");
|
return;
|
}
|
WaitFrmHelper.ShowWaitForm();
|
var dlg = new ViewSignalTypeDlg();
|
dlg.Shown += delegate { WaitFrmHelper.HideWaitForm(); };
|
dlg.SetBindingData(vm.Model);
|
dlg.ShowDialog();
|
}
|
|
//更新排序码
|
private void barBtnSortCode_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
if (_group == null)
|
return;
|
var vm = this.gridView1.GetCurrentViewModel(_allBindingList);
|
if (vm == null)
|
{
|
XtraMessageBox.Show("请选择数据行!");
|
return;
|
}
|
WaitFrmHelper.ShowWaitForm();
|
var dlg = new SetSortCodeDlg();
|
dlg.Shown += delegate { WaitFrmHelper.HideWaitForm(); };
|
dlg.SetBindingData(vm.SortCode);
|
dlg.ReloadDataEvent += (sortcode) =>
|
{
|
var bll = new BLL.Scatl.SignalType();
|
vm.SortCode = vm.Model.SortCode = sortcode;
|
var result = bll.Update(vm.Model);
|
if (result)
|
{
|
var model = bll.GetById(vm.Model.Id);
|
vm.Reset(model);
|
SelectGroup(_group);
|
}
|
return result;
|
};
|
dlg.ShowDialog();
|
}
|
|
//更新 TagName
|
private void barBtnTagName_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
if (_group == null)
|
return;
|
var vm = this.gridView1.GetCurrentViewModel(_allBindingList);
|
if (vm == null)
|
{
|
XtraMessageBox.Show("请选择数据行!");
|
return;
|
}
|
WaitFrmHelper.ShowWaitForm();
|
var dlg = new SetTagNameDlg();
|
dlg.Shown += delegate { WaitFrmHelper.HideWaitForm(); };
|
dlg.SetBindingData(vm.TagName);
|
dlg.ReloadDataEvent += (tagname) =>
|
{
|
var bll = new BLL.Scatl.SignalType();
|
vm.TagName = vm.Model.TagName = tagname;
|
var result = bll.Update(vm.Model);
|
if (result)
|
{
|
var model = bll.GetById(vm.Model.Id);
|
vm.Reset(model);
|
SelectGroup(_group);
|
}
|
return result;
|
};
|
dlg.ShowDialog();
|
}
|
|
//切换分组
|
private void barBtnChangeGroup_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
if (_group == null)
|
return;
|
var vm = this.gridView1.GetCurrentViewModel(_allBindingList);
|
if (vm == null)
|
{
|
XtraMessageBox.Show("请选择数据行!");
|
return;
|
}
|
var dlg = new SelectSignalTypeGroupDlg();
|
dlg.SetBindingData();
|
dlg.ReloadDataEvent += (rhs) =>
|
{
|
var bll = new BLL.Scatl.SignalType();
|
vm.GroupID = vm.Model.GroupId = rhs.Id;
|
var result = bll.Update(vm.Model);
|
if (result)
|
{
|
var model = bll.GetById(vm.Model.Id);
|
vm.Reset(model);
|
SelectGroup(_group);
|
}
|
};
|
dlg.ShowDialog();
|
|
}
|
|
}
|
}
|