171 lines
5.6 KiB
C#
171 lines
5.6 KiB
C#
///
|
|
/// Copyright (c) 2021-2023 Sensus Slovensko a.s.
|
|
///
|
|
using System;
|
|
using System.Windows.Forms;
|
|
using Common;
|
|
using TBF.Rig.Output.Printers.Label;
|
|
using LabelPrinting.Resources;
|
|
|
|
namespace LabelPrinting
|
|
{
|
|
public partial class SettingsDlg : Form
|
|
{
|
|
private readonly LocalSettings ls;
|
|
private readonly Factory factory;
|
|
|
|
public SettingsDlg()
|
|
{
|
|
InitializeComponent();
|
|
factory = new Factory();
|
|
}
|
|
|
|
public SettingsDlg(LocalSettings localSettings)
|
|
: this()
|
|
{
|
|
this.ls = localSettings;
|
|
}
|
|
|
|
void Localize()
|
|
{
|
|
Text = Strings.Settings;
|
|
modeGroupBox.Text = Strings.Mode;
|
|
standaloneRadioButton.Text = "20 char s/n - " + Strings.Standalone;
|
|
withDBRadioButton.Text = "20 char s/n - " + Strings.With_database;
|
|
languageLabel.Text = Strings.Language_etc;
|
|
delayLabel.Text = Strings.Delay_between_labes;
|
|
loginRequiredCheckBox.Text = Strings.User_login_is_required;
|
|
saveButton.Text = Strings.Save;
|
|
cancelButton.Text = Strings.Cancel;
|
|
connStrForTracingGroupBox.Text = Strings.Connection_string_tracing_DB;
|
|
connStrForUsersGroupBox.Text = Strings.Connection_string_users_DB;
|
|
}
|
|
|
|
private void SettingsDlg_Load(object sender, EventArgs e)
|
|
{
|
|
Localize();
|
|
|
|
languageComboBox.Items.Add("CS");
|
|
languageComboBox.Items.Add("DE");
|
|
languageComboBox.Items.Add("EN");
|
|
languageComboBox.Items.Add("SK");
|
|
languageComboBox.Items.Add("ZH_CN");
|
|
languageComboBox.Text = ls.Language;
|
|
|
|
if (ls == null) return;
|
|
|
|
tbfLabelPrinterRadioButton.Checked = (ls.Mode == Mode.TbfLabelPrinter);
|
|
standaloneRadioButton.Checked = (ls.Mode == Mode.Standalone);
|
|
withDBRadioButton.Checked = (ls.Mode == Mode.WithDatabase);
|
|
|
|
loginRequiredCheckBox.Checked = ls.IsUserLoginRequired;
|
|
|
|
delayTextBox.Text = ls.DelayBetweenLabels.ToString();
|
|
|
|
tracingDBConnStringTextBox.Text = ls.TracingDBConnString;
|
|
usersDBConnStringTextBox.Text = ls.UsersDBConnString;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Verifies UI content
|
|
/// </summary>
|
|
/// <returns>None-empty string (message) when invalid</returns>
|
|
string IsUIContentValid()
|
|
{
|
|
if (!languageComboBox.Items.Contains(languageComboBox.Text))
|
|
{
|
|
return Strings.Invalid_language;
|
|
}
|
|
|
|
int idummy;
|
|
if (!int.TryParse(delayTextBox.Text, out idummy) || idummy < 0 || idummy > 5000)
|
|
{
|
|
return string.Format("{0} {1}", Strings.Invalid, delayLabel.Text);
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Updates settings, checks for differences compared to previous setrtings
|
|
/// </summary>
|
|
/// <returns>true when settings are different</returns>
|
|
bool UpdateSettings()
|
|
{
|
|
if (ls == null) return false;
|
|
|
|
bool isDifferent = false;
|
|
|
|
Mode mode = tbfLabelPrinterRadioButton.Checked ? Mode.TbfLabelPrinter : standaloneRadioButton.Checked ? Mode.Standalone : Mode.WithDatabase;
|
|
if (ls.Mode != mode)
|
|
{
|
|
ls.Mode = mode;
|
|
isDifferent = true;
|
|
}
|
|
|
|
if (ls.Language != languageComboBox.Text)
|
|
{
|
|
ls.Language = languageComboBox.Text;
|
|
isDifferent = true;
|
|
}
|
|
|
|
if (ls.IsUserLoginRequired != loginRequiredCheckBox.Checked)
|
|
{
|
|
ls.IsUserLoginRequired = loginRequiredCheckBox.Checked;
|
|
isDifferent = true;
|
|
}
|
|
|
|
if (ls.TracingDBConnString != tracingDBConnStringTextBox.Text)
|
|
{
|
|
ls.TracingDBConnString = tracingDBConnStringTextBox.Text;
|
|
isDifferent = true;
|
|
}
|
|
|
|
if (ls.UsersDBConnString != usersDBConnStringTextBox.Text)
|
|
{
|
|
ls.UsersDBConnString = usersDBConnStringTextBox.Text;
|
|
isDifferent = true;
|
|
}
|
|
|
|
return isDifferent;
|
|
}
|
|
|
|
private void saveButton_Click(object sender, EventArgs e)
|
|
{
|
|
string message = IsUIContentValid();
|
|
if (string.IsNullOrEmpty(message))
|
|
{
|
|
UpdateSettings();
|
|
DialogResult = DialogResult.OK;
|
|
Close();
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show(message);
|
|
}
|
|
}
|
|
|
|
private void cancelButton_Click(object sender, EventArgs e)
|
|
{
|
|
DialogResult = DialogResult.Cancel;
|
|
Close();
|
|
}
|
|
|
|
private void labelPrinterConfigButton_Click(object sender, EventArgs e)
|
|
{
|
|
var cmpntEntity = Config.Entities.Component.CreateFromCfg("Printer", factory.ClassName, string.Empty, 1,
|
|
DebugMode.Normal, LogLevel.Off, ls.LabelPrinterCfg);
|
|
|
|
var cfgForm = new TBF.UI.Bench.Components.ComponentParametersDlg(this);
|
|
cfgForm.ComponentCfgCtrl = new PrinterCfgCtrl();
|
|
cfgForm.ComponentCfgCtrl.Config = factory.CmpntCfgFromCmpntEntity(cmpntEntity);
|
|
cfgForm.UnlockAfterStart = true;
|
|
|
|
if (cfgForm.ShowDialog() == DialogResult.OK)
|
|
{
|
|
ls.LabelPrinterCfg = cfgForm.ComponentCfgCtrl.Config.CreateDbEntity().Parameters;
|
|
}
|
|
}
|
|
}
|
|
}
|