274 lines
13 KiB
C#
274 lines
13 KiB
C#
///
|
|
/// Copyright (c) 2021 Sensus Slovensko a.s.
|
|
///
|
|
using System;
|
|
using System.Globalization;
|
|
using System.Windows.Forms;
|
|
using RecordProcessing;
|
|
using SharedDatabase;
|
|
using Workplace.Resources;
|
|
|
|
namespace Workplace.Forms
|
|
{
|
|
public partial class SettingsDlg : Form
|
|
{
|
|
static readonly DateTime MinTime = new DateTime(1753, 1, 1, 0, 0, 0);
|
|
|
|
private LocalSettings ls;
|
|
|
|
|
|
/// <summary>
|
|
/// Basic configuration dialog
|
|
/// </summary>
|
|
public SettingsDlg()
|
|
{
|
|
InitializeComponent();
|
|
|
|
languageComboBox.Items.Add("EN");
|
|
languageComboBox.Items.Add("ZH_CN");
|
|
languageComboBox.Items.Add("DE");
|
|
languageComboBox.Items.Add("SK");
|
|
|
|
for (RecordType rt = RecordType.None; rt < RecordType.Count; rt++)
|
|
{
|
|
processedRecordsComboBox.Items.Add(rt.ToString());
|
|
}
|
|
|
|
for (MassMethod mm = 0; mm < MassMethod.Count; mm++)
|
|
{
|
|
massMethodComboBox.Items.Add(mm.ToString());
|
|
}
|
|
|
|
extraBatteryLifetimeTextBox.Text = "0";
|
|
|
|
timePicker1.Format = DateTimePickerFormat.Custom;
|
|
timePicker1.CustomFormat = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.ShortTimePattern;
|
|
|
|
timePicker2.Format = DateTimePickerFormat.Custom;
|
|
timePicker2.CustomFormat = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.ShortTimePattern;
|
|
|
|
timePicker3.Format = DateTimePickerFormat.Custom;
|
|
timePicker3.CustomFormat = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.ShortTimePattern;
|
|
}
|
|
|
|
public SettingsDlg(LocalSettings localSettings)
|
|
: this()
|
|
{
|
|
this.ls = localSettings;
|
|
}
|
|
|
|
void Localize()
|
|
{
|
|
Text = Strings.Settings;
|
|
workstepNameGroupBox.Text = Strings.Workplace_name;
|
|
connStrForTracingGroupBox.Text = Strings.Connection_str_for_production_tracing;
|
|
connStrForUsersGroupBox.Text = Strings.Connection_string_for_users;
|
|
modeGroupBox.Text = Strings.Mode_of_function;
|
|
radioButton1.Text = Strings.Production + " ST";
|
|
radioButton2.Text = Strings.Test + " ST";
|
|
radioButton3.Text = Strings.Production + " LU";
|
|
radioButton4.Text = Strings.Test + " LU";
|
|
logoutTimesGroupBox.Text = Strings.Logout_times;
|
|
label1.Text = Strings.Do_not_log_out;
|
|
saveCmpntsToOracleCheckBox.Text = Strings.Save_components_to_Oracle;
|
|
checkPcbIsInOracleCheckBox.Text = Strings.Verify_whether_PCB_was_already_assembled;
|
|
searchOtherProcessFlowtubeCheckBox.Text = Strings.Search_for_flowtubes_from_other_processes;
|
|
searchHeTestInOracleCheckBox.Text = Strings.Search_for_Helium_test_results_in_Oracle;
|
|
workplaceOptionsGroupBox.Text = Strings.Workplace_options;
|
|
activateAfterProcessingGroupBox.Text = Strings.Process_records_Then_activate;
|
|
saveButton.Text = Strings.Save;
|
|
cancelButton.Text = Strings.Cancel;
|
|
}
|
|
|
|
private void SettingsDlg_Load(object sender, EventArgs e)
|
|
{
|
|
Localize();
|
|
|
|
if (ls == null) return;
|
|
|
|
languageComboBox.Text = ls.Language;
|
|
workplaceNameTextBox.Text = ls.WorkplaceId;
|
|
switch (ls.LocalWorkplacesCount)
|
|
{
|
|
default:
|
|
case 1: radioButton5.Checked = true; break;
|
|
case 2: radioButton6.Checked = true; break;
|
|
case 3: radioButton7.Checked = true; break;
|
|
}
|
|
workplace1TextBox.Text = ls.LocalWorkplace1;
|
|
workplace2TextBox.Text = ls.LocalWorkplace2;
|
|
workplace3TextBox.Text = ls.LocalWorkplace3;
|
|
|
|
connectionStringTextBox.Text = ls.ConnectionString;
|
|
usersDBConnStringTextBox.Text = ls.UsersDBConnString;
|
|
|
|
saveCmpntsToOracleCheckBox.Checked = ls.OracleBattery;
|
|
checkPcbIsInOracleCheckBox.Checked = ls.CheckPcbIsInOracle;
|
|
searchOtherProcessFlowtubeCheckBox.Checked = ls.SearchOtherProcessFlowtube;
|
|
searchHeTestInOracleCheckBox.Checked = ls.SearchForHeTestResultsInOracle;
|
|
readFromOracleCheckBox.Checked = ls.ReadFromOracle;
|
|
|
|
serialPortTextBox.Text = ls.ScaleSerialPort.ToString();
|
|
massRepeatsTextBox.Text = ls.MassRepeats.ToString();
|
|
massMethodComboBox.Text = ls.MassMethod.ToString();
|
|
massSpreadTextBox.Text = ls.MassSpread.ToString();
|
|
|
|
processedRecordsComboBox.Text = ls.RecordProcessing.ToString();
|
|
windowClassNameToActivateTextBox.Text = ls.WindowClassNameToActivate;
|
|
|
|
radioButton1.Checked = (ls.Mode == Mode.Production);
|
|
radioButton2.Checked = (ls.Mode == Mode.Test);
|
|
radioButton3.Checked = (ls.Mode == Mode.ProductionLU);
|
|
radioButton4.Checked = (ls.Mode == Mode.TestLU);
|
|
|
|
timePicker1.Value = (ls.LogoutTime1.CompareTo(MinTime) < 0) ? MinTime : ls.LogoutTime1;
|
|
timePicker2.Value = (ls.LogoutTime2.CompareTo(MinTime) < 0) ? MinTime : ls.LogoutTime2;
|
|
timePicker3.Value = (ls.LogoutTime3.CompareTo(MinTime) < 0) ? MinTime : ls.LogoutTime3;
|
|
|
|
okDurationTextBox.Text = ls.OkFlashDuration.ToString();
|
|
nokDurationTextBox.Text = ls.NokFlashDuration.ToString();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Verifies UI content
|
|
/// </summary>
|
|
/// <returns>None-empty string (message) when invalid</returns>
|
|
string IsUIContentValid()
|
|
{
|
|
if (!languageComboBox.Items.Contains(languageComboBox.Text)) return "Invalid language";
|
|
if (string.IsNullOrEmpty(workplaceNameTextBox.Text)) return "Missing workplace name";
|
|
|
|
int idummy;
|
|
if (!int.TryParse(serialPortTextBox.Text, out idummy) || idummy < 0) return "Invalid serial port for a scale";
|
|
if (!int.TryParse(massRepeatsTextBox.Text, out idummy) || idummy < 5) return "Invalid mass repeats";
|
|
|
|
double massSpread;
|
|
if (!double.TryParse(massSpreadTextBox.Text, NumberStyles.AllowDecimalPoint, CultureInfo.CurrentCulture, out massSpread) &&
|
|
!double.TryParse(massSpreadTextBox.Text, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out massSpread))
|
|
{
|
|
return "Invalid Mass spread";
|
|
}
|
|
|
|
if (!massMethodComboBox.Items.Contains(massMethodComboBox.Text)) return "Invalid mass method";
|
|
if (!processedRecordsComboBox.Items.Contains(processedRecordsComboBox.Text)) return "Invalid RecordProcessing";
|
|
|
|
if (!int.TryParse(okDurationTextBox.Text, out idummy) || idummy < 200 || idummy > 5000) return "Invalid OK flash duration";
|
|
if (!int.TryParse(nokDurationTextBox.Text, out idummy) || idummy < 200 || idummy > 5000) return "Invalid NOK flash duration";
|
|
|
|
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;
|
|
|
|
if (ls.Language != languageComboBox.Text) { ls.Language = languageComboBox.Text; isDifferent = true; }
|
|
if (ls.WorkplaceId != workplaceNameTextBox.Text) { ls.WorkplaceId = workplaceNameTextBox.Text; isDifferent = true; }
|
|
|
|
int wrkplacesCount = radioButton7.Checked ? 3 : (radioButton6.Checked ? 2 : 1);
|
|
if (ls.LocalWorkplacesCount != wrkplacesCount) { ls.LocalWorkplacesCount = wrkplacesCount; isDifferent = true; }
|
|
if (ls.LocalWorkplace1 != workplace1TextBox.Text) { ls.LocalWorkplace1 = workplace1TextBox.Text; isDifferent = true; }
|
|
if (ls.LocalWorkplace2 != workplace2TextBox.Text) { ls.LocalWorkplace2 = workplace2TextBox.Text; isDifferent = true; }
|
|
if (ls.LocalWorkplace3 != workplace3TextBox.Text) { ls.LocalWorkplace3 = workplace3TextBox.Text; isDifferent = true; }
|
|
|
|
if (ls.ConnectionString != connectionStringTextBox.Text) { ls.ConnectionString = connectionStringTextBox.Text; isDifferent = true; }
|
|
if (ls.UsersDBConnString != usersDBConnStringTextBox.Text) { ls.UsersDBConnString = usersDBConnStringTextBox.Text; isDifferent = true; }
|
|
|
|
if (ls.OracleBattery != saveCmpntsToOracleCheckBox.Checked) { ls.OracleBattery = saveCmpntsToOracleCheckBox.Checked; isDifferent = true; }
|
|
if (ls.CheckPcbIsInOracle != checkPcbIsInOracleCheckBox.Checked) { ls.CheckPcbIsInOracle = checkPcbIsInOracleCheckBox.Checked; isDifferent = true; }
|
|
if (ls.SearchOtherProcessFlowtube != searchOtherProcessFlowtubeCheckBox.Checked) { ls.SearchOtherProcessFlowtube = searchOtherProcessFlowtubeCheckBox.Checked; isDifferent = true; }
|
|
if (ls.SearchForHeTestResultsInOracle != searchHeTestInOracleCheckBox.Checked) { ls.SearchForHeTestResultsInOracle = searchHeTestInOracleCheckBox.Checked; isDifferent = true; }
|
|
if (ls.ReadFromOracle != readFromOracleCheckBox.Checked) { ls.ReadFromOracle = readFromOracleCheckBox.Checked; isDifferent = true; }
|
|
|
|
int scaleSerialPort = int.Parse(serialPortTextBox.Text);
|
|
if (ls.ScaleSerialPort != scaleSerialPort) { ls.ScaleSerialPort = scaleSerialPort; isDifferent = true; }
|
|
|
|
int massRepeats = int.Parse(massRepeatsTextBox.Text);
|
|
if (ls.MassRepeats != massRepeats) { ls.MassRepeats = massRepeats; isDifferent = true; }
|
|
|
|
var mm = MassMethod.Scale;
|
|
for (MassMethod m = 0; m < MassMethod.Count; m++)
|
|
if (massMethodComboBox.Text == m.ToString()) { mm = m; break; }
|
|
if (ls.MassMethod != mm) { ls.MassMethod = mm; isDifferent = true; }
|
|
|
|
double massSpread;
|
|
if (double.TryParse(massSpreadTextBox.Text, NumberStyles.AllowDecimalPoint, CultureInfo.CurrentCulture, out massSpread) ||
|
|
double.TryParse(massSpreadTextBox.Text, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out massSpread))
|
|
{
|
|
if (ls.MassSpread != massSpread) { ls.MassSpread = massSpread; isDifferent = true; }
|
|
}
|
|
|
|
var rtype = RecordType.None;
|
|
for (RecordType rt = RecordType.None; rt < RecordType.Count; rt++)
|
|
if (processedRecordsComboBox.Text == rt.ToString()) { rtype = rt; break; }
|
|
if (ls.RecordProcessing != rtype) { ls.RecordProcessing = rtype; isDifferent = true; }
|
|
|
|
if (ls.WindowClassNameToActivate != windowClassNameToActivateTextBox.Text) { ls.WindowClassNameToActivate = windowClassNameToActivateTextBox.Text; isDifferent = true; }
|
|
|
|
Mode mode = radioButton1.Checked ? Mode.Production
|
|
: radioButton2.Checked ? Mode.Test
|
|
: radioButton3.Checked ? Mode.ProductionLU : Mode.TestLU;
|
|
if (ls.Mode != mode) { ls.Mode = mode; isDifferent = true; }
|
|
|
|
if (ls.LogoutTime1 != timePicker1.Value) { ls.LogoutTime1 = timePicker1.Value; isDifferent = true; }
|
|
if (ls.LogoutTime2 != timePicker2.Value) { ls.LogoutTime2 = timePicker2.Value; isDifferent = true; }
|
|
if (ls.LogoutTime3 != timePicker3.Value) { ls.LogoutTime3 = timePicker3.Value; isDifferent = true; }
|
|
|
|
int idummy = int.Parse(okDurationTextBox.Text);
|
|
if (ls.OkFlashDuration != idummy) { ls.OkFlashDuration = idummy; isDifferent = true; }
|
|
idummy = int.Parse(nokDurationTextBox.Text);
|
|
if (ls.NokFlashDuration != idummy) { ls.NokFlashDuration = idummy; isDifferent = true; }
|
|
|
|
return isDifferent;
|
|
}
|
|
|
|
|
|
private void saveButton_Click(object sender, EventArgs e)
|
|
{
|
|
string message = IsUIContentValid();
|
|
if (string.IsNullOrEmpty(message))
|
|
{
|
|
DialogResult = UpdateSettings() ? DialogResult.OK : DialogResult.Cancel;
|
|
Close();
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show(message);
|
|
}
|
|
}
|
|
|
|
private void cancelButton_Click(object sender, EventArgs e)
|
|
{
|
|
DialogResult = DialogResult.Cancel;
|
|
Close();
|
|
}
|
|
|
|
private void radioButton5_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
workplace1TextBox.Enabled = true;
|
|
workplace2TextBox.Enabled = false;
|
|
workplace3TextBox.Enabled = false;
|
|
}
|
|
|
|
private void radioButton6_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
workplace1TextBox.Enabled = true;
|
|
workplace2TextBox.Enabled = true;
|
|
workplace3TextBox.Enabled = false;
|
|
}
|
|
|
|
private void radioButton7_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
workplace1TextBox.Enabled = true;
|
|
workplace2TextBox.Enabled = true;
|
|
workplace3TextBox.Enabled = true;
|
|
}
|
|
}
|
|
}
|