tbf/TBF/BenchControl/ComponentParametersDlg.cs

142 lines
3.6 KiB
C#

///
/// Copyright (c) 2013-2015 Sensus Slovensko a.s.
///
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Config.Entities;
using TBF.BenchControl;
using TBF.BenchControl.Generic;
using TBF.Resources;
using TBF.UI.Shared;
namespace TBF.BenchControl
{
public partial class ComponentParametersDlg : Form
{
public IComponentCfgCtrl ComponentCfgCtrl;
const int ComponentCfgCtrlHeight = 350;
const int ComponentCfgCtrlMoreHeight = 250;
public IComponentCfg Config
{
get
{
if (ComponentCfgCtrl == null) return null;
return ComponentCfgCtrl.Config;
}
}
public CfgUpdateFlags Flags;
public bool UnlockAfterStart;
/// <summary>
/// List of components (=component configuration instances)
/// </summary>
public IList<Config.Entities.Component> TbfComponents;
public ComponentParametersDlg()
{
InitializeComponent();
Flags = CfgUpdateFlags.None;
/// SharedDlgButtons configuration
sharedButtons.RequiredGroupMembership = new Users.Grp.GID[] { global::Users.Grp.GID.Metrologists };
sharedButtons.MoreButtonTop = ComponentCfgCtrlHeight - 45;
sharedButtons.OptionalButtons = SharedButtons.Buttons.None;
sharedButtons.Unlocked += Unlock;
sharedButtons.OKClicked += okButton_Click;
sharedButtons.CancelClicked += cancelButton_Click;
sharedButtons.MoreClicked += moreButton_Click;
}
private void ComponentCfgForm_Load(object sender, EventArgs e)
{
Text = Strings.Properties;
if (ComponentCfgCtrl != null)
{
splitContainer.Panel1.Controls.Add((UserControl)ComponentCfgCtrl);
}
if ((ComponentCfgCtrl != null) && ComponentCfgCtrl.ShowMore)
{
sharedButtons.OptionalButtons = SharedButtons.Buttons.More;
}
if (UnlockAfterStart)
{
sharedButtons.UnlockButtons();
ComponentCfgCtrl.Unlock();
}
}
/// <summary>
/// Handler of the Unlock button click
/// </summary>
private void Unlock(object sender, EventArgs e)
{
ComponentCfgCtrl.Unlock();
}
public CfgUpdateFlags VerifyCfg(ref string message)
{
if (ComponentCfgCtrl == null) return CfgUpdateFlags.None; /// Nothing to verify -> OK
return ComponentCfgCtrl.VerifyCfg(ref message);
}
private void okButton_Click(object sender, EventArgs e)
{
string message = string.Empty;
CfgUpdateFlags flags = VerifyCfg(ref message);
if ((flags & CfgUpdateFlags.Error) == CfgUpdateFlags.Error)
{
MessageBox.Show(Strings.Please_change_the_following_settings + message,
Strings.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (ComponentCfgCtrl != null)
{
flags = ComponentCfgCtrl.UpdateCfg();
if ((flags & CfgUpdateFlags.RestartRqrd) == CfgUpdateFlags.RestartRqrd)
{
MessageBox.Show(Strings.Program_restart_is_required_to_apply_some_settings,
Strings.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
ComponentCfgCtrl.Closing();
}
Flags = flags;
DialogResult = DialogResult.OK;
Close();
return;
}
private void cancelButton_Click(object sender, EventArgs e)
{
if (ComponentCfgCtrl != null) ComponentCfgCtrl.Closing();
DialogResult = DialogResult.Cancel;
Close();
return;
}
private void moreButton_Click(object sender, EventArgs e)
{
ComponentCfgCtrl.Unlock();
if (sharedButtons.MoreActive)
{
Height = Height + ComponentCfgCtrlMoreHeight;
}
else
{
Height = Height - ComponentCfgCtrlMoreHeight;
}
return;
}
}
}