tbf/TestBenchFramework/BenchControl/ResultsPrinters/LabelPrinter/PrinterCfgCtrl.cs
2015-12-08 23:44:52 +01:00

124 lines
3.2 KiB
C#

///
/// Copyright (c) 2015 Sensus Metering Systems
///
using System;
using System.IO;
using System.Windows.Forms;
using log4net;
using Config.Entities;
using TBF.BenchControl.Generic;
namespace TBF.BenchControl.ResultsPrinters.LabelPrinter
{
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();
paperWidthTextBox.Text = config.PaperWidth.ToString();
paperHeightTextBox.Text = config.PaperHeight.ToString();
templateTextBox.Text = config.TemplateFile;
supressPrintingCheckBox.Checked = config.SupressPrinting;
}
public void Unlock()
{
nameTextBox.Enabled = true;
orientationComboBox.Enabled = true;
paperWidthTextBox.Enabled = true;
paperHeightTextBox.Enabled = true;
templateTextBox.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(paperWidthTextBox.Text, out dummy) || dummy <= 0)
{
message += Environment.NewLine + "Invalid paper width";
flags |= CfgUpdateFlags.Error;
}
if (!int.TryParse(paperHeightTextBox.Text, out dummy) || dummy <= 0)
{
message += Environment.NewLine + "Invalid paper height";
flags |= CfgUpdateFlags.Error;
}
if (!File.Exists(config.TemplateFile))
{
message += Environment.NewLine + "Template file missing";
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.PaperWidth = int.Parse(paperWidthTextBox.Text);
config.PaperHeight = int.Parse(paperHeightTextBox.Text);
config.TemplateFile = templateTextBox.Text;
config.SupressPrinting = supressPrintingCheckBox.Checked;
return flags;
}
}
}