124 lines
3.4 KiB
C#
124 lines
3.4 KiB
C#
///
|
|
/// Copyright (c) 2013-2016 Sensus Metering Systems
|
|
///
|
|
using System;
|
|
using System.Windows.Forms;
|
|
using log4net;
|
|
using Config.Entities;
|
|
using TBF.BenchControl.Generic;
|
|
|
|
namespace TBF.BenchControl.ResultsPrinters.Basic
|
|
{
|
|
public partial class PrinterCfgCtrl : UserControl, IComponentCfgCtrl
|
|
{
|
|
static readonly ILog log = LogManager.GetLogger(typeof(PrinterCfgCtrl));
|
|
|
|
public bool ShowMore { get { return false; } }
|
|
|
|
PrinterCfg config;
|
|
public IComponentCfg Config
|
|
{
|
|
get { return config as IComponentCfg; }
|
|
set
|
|
{
|
|
config = value as PrinterCfg;
|
|
Redraw();
|
|
}
|
|
}
|
|
|
|
public PrinterCfgCtrl()
|
|
{
|
|
InitializeComponent();
|
|
|
|
orientationComboBox.Items.Add(PageOrientation.Portrait.ToString());
|
|
orientationComboBox.Items.Add(PageOrientation.Landscape.ToString());
|
|
}
|
|
|
|
private void PrinterCfgCtrl_Load(object sender, EventArgs e)
|
|
{
|
|
Redraw();
|
|
}
|
|
|
|
public void Closing()
|
|
{
|
|
}
|
|
|
|
PageOrientation GetOrientation(string str)
|
|
{
|
|
if (str.Equals(PageOrientation.Landscape.ToString())) return PageOrientation.Landscape;
|
|
if (str.Equals(PageOrientation.Portrait.ToString())) return PageOrientation.Portrait;
|
|
return (PageOrientation)(-1);
|
|
}
|
|
|
|
void Redraw()
|
|
{
|
|
if (config == null) return; /// Control was not loaded, settings were not changed
|
|
classNameLabel.Text = config.Factory.ClassName;
|
|
nameTextBox.Text = config.Name;
|
|
orientationComboBox.Text = config.PageOrientation.ToString();
|
|
topMarginTextBox.Text = config.TopMargin.ToString();
|
|
bottomMarginTextBox.Text = config.BottomMargin.ToString();
|
|
leftMarginTextBox.Text = config.LeftMargin.ToString();
|
|
supressPrintingCheckBox.Checked = config.SupressPrinting;
|
|
}
|
|
|
|
public void Unlock()
|
|
{
|
|
nameTextBox.Enabled = true;
|
|
orientationComboBox.Enabled = true;
|
|
topMarginTextBox.Enabled = true;
|
|
bottomMarginTextBox.Enabled = true;
|
|
leftMarginTextBox.Enabled = true;
|
|
supressPrintingCheckBox.Enabled = true;
|
|
}
|
|
|
|
public CfgUpdateFlags VerifyCfg(ref string message)
|
|
{
|
|
CfgUpdateFlags flags = CfgUpdateFlags.None;
|
|
|
|
if ((int)GetOrientation(orientationComboBox.Text) < 0)
|
|
{
|
|
message += Environment.NewLine + "Invalid 'Page orientation'";
|
|
flags |= CfgUpdateFlags.Error;
|
|
}
|
|
|
|
int dummy;
|
|
if (!int.TryParse(topMarginTextBox.Text, out dummy) || dummy < 0 || dummy > 500)
|
|
{
|
|
message += Environment.NewLine + "'Top margin' should be between 0 and 500";
|
|
flags |= CfgUpdateFlags.Error;
|
|
}
|
|
|
|
if (!int.TryParse(bottomMarginTextBox.Text, out dummy) || dummy < 0 || dummy > 200)
|
|
{
|
|
message += Environment.NewLine + "'Bottom margin' should be between 0 and 200";
|
|
flags |= CfgUpdateFlags.Error;
|
|
}
|
|
|
|
if (!int.TryParse(leftMarginTextBox.Text, out dummy) || dummy < 0 || dummy > 200)
|
|
{
|
|
message += Environment.NewLine + "Left margin' should be between 0 and 200";
|
|
flags |= CfgUpdateFlags.Error;
|
|
}
|
|
|
|
return flags;
|
|
}
|
|
|
|
public CfgUpdateFlags UpdateCfg()
|
|
{
|
|
CfgUpdateFlags flags = CfgUpdateFlags.RestartRqrd;
|
|
|
|
if (config == null) return CfgUpdateFlags.Error; /// Control was not loaded, settings were not changed
|
|
|
|
config.Name = nameTextBox.Text;
|
|
config.PageOrientation = GetOrientation(orientationComboBox.Text);
|
|
config.TopMargin = int.Parse(topMarginTextBox.Text);
|
|
config.BottomMargin = int.Parse(bottomMarginTextBox.Text);
|
|
config.LeftMargin = int.Parse(leftMarginTextBox.Text);
|
|
config.SupressPrinting = supressPrintingCheckBox.Checked;
|
|
|
|
return flags;
|
|
}
|
|
}
|
|
}
|