tbf/TBF/UI/ResultsMI/SendAgainDBAndWMSelectionForm.cs

150 lines
5.1 KiB
C#

///
/// Copyright (c) 2021-2023 Sensus Slovensko a.s.
///
using System;
using System.Windows.Forms;
using TBF.Rig.Output.DB.SensusOracle;
using TBF.Resources;
using System.Drawing;
using static TBF.UI.Shared.SharedButtons;
using Common;
namespace TBF.UI.ResultsMI
{
public partial class SendAgainDBAndWMSelectionForm : Form
{
public bool SaveToOracle;
public DBUsed SelectedDB;
public WMKind SelectedWM;
public bool SaveToProductionTracing;
bool unlocked = false;
GID[] RequiredGroupMembership = new GID[] { GID.TestingSpecialists, GID.Metrologists };
public SendAgainDBAndWMSelectionForm()
{
InitializeComponent();
ManageCheckGroupBox(oracleDbCheckBox, oracleDbGroupBox);
Localize();
databaseComboBox.Items.Add(DBUsed.Production);
databaseComboBox.Items.Add(DBUsed.Test);
databaseComboBox.Items.Add(DBUsed.Quality);
databaseComboBox.Text = databaseComboBox.Items[0].ToString();
waterMetersComboBox.Items.Add(WMKind.iPERL);
waterMetersComboBox.Items.Add(WMKind.Mechanical);
waterMetersComboBox.Text = waterMetersComboBox.Items[0].ToString();
}
void Localize()
{
Text = Strings.Database_and_water_meters_selection;
databaseLabel.Text = Strings.Database;
waterMetersLabel.Text = Strings.Water_meters;
okButton.Text = Strings.OkBtnText;
cancelButton.Text = Strings.CancelBtnText;
}
private void okButton_Click(object sender, EventArgs e)
{
bool isValid = true;
SaveToOracle = oracleDbCheckBox.Checked;
SaveToProductionTracing = productionTracingCheckBox.Checked;
if (SaveToOracle)
{
isValid = false;
for (DBUsed db = DBUsed.Production; db < DBUsed.Count; db++)
{
if (db.ToString() == databaseComboBox.Text)
{
SelectedDB = db;
for (WMKind wm = WMKind.iPERL; wm < WMKind.Count; wm++)
{
if (wm.ToString() == waterMetersComboBox.Text)
{
SelectedWM = wm;
isValid = true;
}
}
}
}
}
if (isValid)
{
DialogResult = DialogResult.OK;
Close();
}
else
{
MessageBox.Show("Invalid selection");
}
}
private void cancelButton_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
private void ManageCheckGroupBox(CheckBox chk, GroupBox grp)
{
/// Make sure the CheckBox isn't in the GroupBox. This will only happen the first time.
if (chk.Parent == grp)
{
grp.Parent.Controls.Add(chk); /// Reparent the CheckBox so it's not in the GroupBox.
chk.Location = new Point(chk.Left + grp.Left, chk.Top + grp.Top); /// Adjust the CheckBox's location.
chk.BringToFront(); /// Move the CheckBox to the top of the stacking order.
}
/// Enable or disable the GroupBox.
grp.Enabled = chk.Checked;
}
private void oracleDbCheckBox_CheckedChanged(object sender, EventArgs e)
{
ManageCheckGroupBox(oracleDbCheckBox, oracleDbGroupBox);
}
private void unlockButton_Click(object sender, EventArgs e)
{
if (!unlocked)
{
if (!Users.CurrentUser.IsMemberOf(RequiredGroupMembership))
{
if (new Users.Forms.LoginDlg(TBF.DB.UserSessionFactories,
RequiredGroupMembership, this).ShowDialog() != DialogResult.OK)
return;
}
else if (Program.LocalSettings.AlwaysAskPasswdWhenUnlocking)
{
if (new Users.Forms.LoginDlg(TBF.DB.UserSessionFactories,
Users.CurrentUser.UserName(),
RequiredGroupMembership, this).ShowDialog() != DialogResult.OK)
return;
}
if (Program.MainWnd != null) Program.MainWnd.UpdateUser();
oracleDbCheckBox.Enabled = true;
oracleDbGroupBox.Enabled = true;
productionTracingCheckBox.Enabled = true;
unlockButton.Enabled = false;
unlocked = true;
}
}
private void SendAgainDBAndWMSelectionForm_FormClosing(object sender, FormClosingEventArgs e)
{
if (Users.CurrentUser.Restore(this)) Program.MainWnd.UpdateUser();
}
}
}