Refactorization : BenchControl -> Rig
This commit is contained in:
@@ -0,0 +1,289 @@
|
||||
///
|
||||
/// Copyright (c) 2015-2020 Sensus Slovensko a.s.
|
||||
///
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Windows.Forms;
|
||||
using log4net;
|
||||
using Config.Entities;
|
||||
using Results.Output.Printers;
|
||||
using TBF.Rig.Generic;
|
||||
using TBF.Rig.Configs;
|
||||
|
||||
namespace TBF.Rig.Output.Printers.Label
|
||||
{
|
||||
public partial class PrinterCfgCtrl : ConfigCtrlUtils, 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();
|
||||
}
|
||||
}
|
||||
|
||||
string[] itemsToPrint;
|
||||
|
||||
public PrinterCfgCtrl()
|
||||
{
|
||||
InitializeComponent();
|
||||
Localize();
|
||||
|
||||
orientationComboBox.Items.Add(PageOrientation.Portrait.ToString());
|
||||
orientationComboBox.Items.Add(PageOrientation.Landscape.ToString());
|
||||
|
||||
foreach (var ff in System.Drawing.FontFamily.Families)
|
||||
{
|
||||
fontFamilyComboBox.Items.Add(ff.Name);
|
||||
}
|
||||
|
||||
for (BarcodeType bt = BarcodeType.None; bt < BarcodeType.Count; bt++)
|
||||
{
|
||||
barcodeTypeComboBox.Items.Add(bt.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
private void PrinterCfgCtrl_Load(object sender, EventArgs e)
|
||||
{
|
||||
for (Culture s = 0; s < Culture.Count; s++) cultureComboBox.Items.Add(s.ToString());
|
||||
|
||||
itemsToPrint = config.ItemsToPrint;
|
||||
|
||||
Redraw();
|
||||
}
|
||||
|
||||
void Localize()
|
||||
{
|
||||
}
|
||||
|
||||
public void Closing()
|
||||
{
|
||||
}
|
||||
|
||||
void Redraw()
|
||||
{
|
||||
if (config == null) return; /// Control was not loaded, settings were not changed
|
||||
classNameLabel.Text = config.Factory.ClassName;
|
||||
nameTextBox.Text = config.Name;
|
||||
templateTextBox.Text = config.Template;
|
||||
orientationComboBox.Text = config.PageOrientation.ToString();
|
||||
paperWidthTextBox.Text = config.PaperWidth.ToString();
|
||||
paperHeightTextBox.Text = config.PaperHeight.ToString();
|
||||
|
||||
fontFamilyComboBox.Text = config.FontFamily;
|
||||
fontSizeTextBox.Text = config.FontSize.ToString();
|
||||
boldCheckBox.Checked = ((config.FontStyle & (int)System.Drawing.FontStyle.Bold) != 0);
|
||||
italicCheckBox.Checked = ((config.FontStyle & (int)System.Drawing.FontStyle.Italic) != 0);
|
||||
|
||||
cultureComboBox.Text = config.Culture.ToString();
|
||||
nrOfCopiesTextBox.Text = config.NrOfCopies.ToString();
|
||||
goodOnlyCheckBox.Checked = config.GoodOnly;
|
||||
|
||||
barcodeTypeComboBox.Text = config.BarcodeType.ToString();
|
||||
barcodeLeftTextBox.Text = config.BarcodeLeft.ToString();
|
||||
barcodeTopTextBox.Text = config.BarcodeTop.ToString();
|
||||
barcodeWidthTextBox.Text = config.BarcodeWidth.ToString();
|
||||
barcodeHeightTextBox.Text = config.BarcodeHeight.ToString();
|
||||
}
|
||||
|
||||
public void Unlock()
|
||||
{
|
||||
nameTextBox.Enabled = true;
|
||||
templateTextBox.Enabled = true;
|
||||
orientationComboBox.Enabled = true;
|
||||
paperWidthTextBox.Enabled = true;
|
||||
paperHeightTextBox.Enabled = true;
|
||||
itemsToPrintButton.Enabled = true;
|
||||
fontFamilyComboBox.Enabled = true;
|
||||
fontSizeTextBox.Enabled = true;
|
||||
boldCheckBox.Enabled = true;
|
||||
italicCheckBox.Enabled = true;
|
||||
cultureComboBox.Enabled = true;
|
||||
nrOfCopiesTextBox.Enabled = true;
|
||||
goodOnlyCheckBox.Enabled = true;
|
||||
|
||||
barcodeTypeComboBox.Enabled = true;
|
||||
barcodeLeftTextBox.Enabled = true;
|
||||
barcodeTopTextBox.Enabled = true;
|
||||
barcodeWidthTextBox.Enabled = true;
|
||||
barcodeHeightTextBox.Enabled = true;
|
||||
}
|
||||
|
||||
public CfgUpdateFlags VerifyCfg(ref string message)
|
||||
{
|
||||
CfgUpdateFlags flags = CfgUpdateFlags.None;
|
||||
|
||||
if (!string.IsNullOrEmpty(templateTextBox.Text) && !File.Exists(Path.Combine("C:\\TBF\\Templates", templateTextBox.Text)))
|
||||
{
|
||||
message += Environment.NewLine + "Template file missing";
|
||||
flags |= CfgUpdateFlags.Error;
|
||||
}
|
||||
|
||||
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 (!int.TryParse(fontSizeTextBox.Text, out dummy) || dummy < 6 || dummy > 48)
|
||||
{
|
||||
message += Environment.NewLine + "Font size' should be between 6 and 48";
|
||||
flags |= CfgUpdateFlags.Error;
|
||||
}
|
||||
if (!cultureComboBox.Items.Contains(cultureComboBox.Text))
|
||||
{
|
||||
message += Environment.NewLine + "Invalid culture";
|
||||
flags |= CfgUpdateFlags.Error;
|
||||
}
|
||||
if (!int.TryParse(nrOfCopiesTextBox.Text, out dummy) || dummy < 0 || dummy > 9)
|
||||
{
|
||||
message += Environment.NewLine + "'Number of copies' should be between 0 and 9";
|
||||
flags |= CfgUpdateFlags.Error;
|
||||
}
|
||||
|
||||
if (!barcodeTypeComboBox.Items.Contains(barcodeTypeComboBox.Text))
|
||||
{
|
||||
message += Environment.NewLine + "Invalid barcode type";
|
||||
flags |= CfgUpdateFlags.Error;
|
||||
}
|
||||
if (!int.TryParse(barcodeLeftTextBox.Text, out dummy) || dummy < 0 || dummy > 2000)
|
||||
{
|
||||
message += Environment.NewLine + "Barcode 'Left' should be between 0 and 2000";
|
||||
flags |= CfgUpdateFlags.Error;
|
||||
}
|
||||
if (!int.TryParse(barcodeTopTextBox.Text, out dummy) || dummy < 0 || dummy > 2000)
|
||||
{
|
||||
message += Environment.NewLine + "Barcode 'Top' should be between 0 and 2000";
|
||||
flags |= CfgUpdateFlags.Error;
|
||||
}
|
||||
if (!int.TryParse(barcodeWidthTextBox.Text, out dummy) || dummy < 0 || dummy > 200)
|
||||
{
|
||||
message += Environment.NewLine + "Barcode 'Width' should be between 0 and 200";
|
||||
flags |= CfgUpdateFlags.Error;
|
||||
}
|
||||
if (!int.TryParse(barcodeHeightTextBox.Text, out dummy) || dummy < 0 || dummy > 200)
|
||||
{
|
||||
message += Environment.NewLine + "Barcode 'Height' should be between 0 and 200";
|
||||
flags |= CfgUpdateFlags.Error;
|
||||
}
|
||||
|
||||
return flags;
|
||||
}
|
||||
|
||||
public CfgUpdateFlags UpdateCfg()
|
||||
{
|
||||
CfgUpdateFlags flags = CfgUpdateFlags.None;
|
||||
|
||||
if (config == null) return CfgUpdateFlags.Error; /// Control was not loaded, settings were not changed
|
||||
|
||||
|
||||
if (config.Name != nameTextBox.Text)
|
||||
{
|
||||
config.Name = nameTextBox.Text;
|
||||
flags |= (CfgUpdateFlags.RestartRqrd | CfgUpdateFlags.AnyChange);
|
||||
}
|
||||
|
||||
flags |= UpdateDifferent(ref config.Template, templateTextBox.Text, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
|
||||
|
||||
if (config.PageOrientation != GetOrientation(orientationComboBox.Text))
|
||||
{
|
||||
config.PageOrientation = GetOrientation(orientationComboBox.Text);
|
||||
flags |= (CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
|
||||
}
|
||||
|
||||
flags |= UpdateDifferent(ref config.PaperWidth, paperWidthTextBox.Text, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
|
||||
flags |= UpdateDifferent(ref config.PaperHeight, paperHeightTextBox.Text, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
|
||||
|
||||
flags |= UpdateDifferent(ref config.ItemsToPrint, itemsToPrint, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
|
||||
|
||||
/// Body font properties
|
||||
flags |= UpdateDifferent(ref config.FontFamily, fontFamilyComboBox.Text, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
|
||||
flags |= UpdateDifferent(ref config.FontSize, int.Parse(fontSizeTextBox.Text), CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
|
||||
int tmp = (boldCheckBox.Checked ? (int)System.Drawing.FontStyle.Bold : 0)
|
||||
+ (italicCheckBox.Checked ? (int)System.Drawing.FontStyle.Italic : 0);
|
||||
flags |= UpdateDifferent(ref config.FontStyle, tmp, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
|
||||
|
||||
for (Culture i = 0; i < Culture.Count; i++)
|
||||
{
|
||||
if (i.ToString().Equals(cultureComboBox.Text) && (config.Culture != i))
|
||||
{
|
||||
config.Culture = i;
|
||||
flags |= (CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
flags |= UpdateDifferent(ref config.NrOfCopies, nrOfCopiesTextBox.Text, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
|
||||
flags |= UpdateDifferent(ref config.GoodOnly, goodOnlyCheckBox.Checked, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
|
||||
|
||||
for (BarcodeType bt = BarcodeType.None; bt < BarcodeType.Count; bt++)
|
||||
{
|
||||
if (bt.ToString().Equals(barcodeTypeComboBox.Text))
|
||||
{
|
||||
config.BarcodeType = bt;
|
||||
flags |= (CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
|
||||
break;
|
||||
}
|
||||
}
|
||||
flags |= UpdateDifferent(ref config.BarcodeLeft, barcodeLeftTextBox.Text, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
|
||||
flags |= UpdateDifferent(ref config.BarcodeTop, barcodeTopTextBox.Text, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
|
||||
flags |= UpdateDifferent(ref config.BarcodeWidth, barcodeWidthTextBox.Text, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
|
||||
flags |= UpdateDifferent(ref config.BarcodeHeight, barcodeHeightTextBox.Text, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
|
||||
|
||||
if ((flags & CfgUpdateFlags.InvokeCfgChange) != 0)
|
||||
{
|
||||
Printer.OnCfgChange(this, new CfgChangeArgs(CfgChangeCmd.CfgChange, config));
|
||||
}
|
||||
|
||||
return flags;
|
||||
}
|
||||
|
||||
private void itemsToPrintButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
Results.Forms.ResultsConfigDlg dlg = new Results.Forms.ResultsConfigDlg()
|
||||
{
|
||||
SelectedItems = Results.WMeterRsltItemSpec.FromStrArray(itemsToPrint),
|
||||
};
|
||||
|
||||
if (dlg.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
itemsToPrint = Results.WMeterRsltItemSpec.ToStrArray(dlg.SelectedItems);
|
||||
}
|
||||
}
|
||||
|
||||
#region Configuration Change Handling
|
||||
|
||||
public static void OnCmdResponse(object sender, CmdResponseArgs args)
|
||||
{
|
||||
if (CmdResponseHandler == null) return;
|
||||
try { CmdResponseHandler(sender, args); }
|
||||
catch (Exception e) { log.Error("CmdResponseHandler(...) failed", e); }
|
||||
}
|
||||
|
||||
public static event EventHandler<CmdResponseArgs> CmdResponseHandler;
|
||||
|
||||
public void StartResponseHandler() { }
|
||||
public void StopResponseHandler() { }
|
||||
|
||||
#endregion Configuration Change Handling
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user