626 lines
19 KiB
C#
626 lines
19 KiB
C#
using Xylem.Common.Ui.GenesisToolBox.Ctls;
|
|
using Xylem.Common.Ui.GenesisToolBox.Infrastructure;
|
|
|
|
namespace Xylem.Common.Ui.GenesisToolBox
|
|
{
|
|
using global::GenesisToolBox;
|
|
|
|
using System;
|
|
using System.Diagnostics;
|
|
using System.Drawing;
|
|
using System.IO;
|
|
using System.Windows.Forms;
|
|
|
|
using CommonCore.Consts;
|
|
using Utils.Logging;
|
|
using System.Collections.Generic;
|
|
|
|
internal delegate void UpdateLayout();
|
|
|
|
/// <inheritdoc />
|
|
public partial class FrmMainForm : Form
|
|
{
|
|
/// <summary>
|
|
/// Ctor
|
|
/// </summary>
|
|
public FrmMainForm()
|
|
{
|
|
InitializeComponent();
|
|
InitializeFormState();
|
|
|
|
menuItemOptions.Text = Software.UserName;
|
|
Text = $@"{Text} {SoftwareVersion.Current.VersionString}";
|
|
var logger = NLogHelper.CreateOrGetLogger("GenesisToolBox");
|
|
logger.Info($"GenesisToolBox {SoftwareVersion.Current}");
|
|
|
|
//bool valid = false;
|
|
|
|
//using (System.DirectoryServices.AccountManagement.PrincipalContext context = new PrincipalContext(ContextType.Domain))
|
|
//{
|
|
|
|
// valid = context.ValidateCredentials("drabesch_ro", "password");
|
|
//}
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public sealed override String Text
|
|
{
|
|
get => base.Text;
|
|
set => base.Text = value;
|
|
}
|
|
|
|
private void btnSetup_Click(Object sender, EventArgs e)
|
|
{
|
|
var form = new FrmSetup();
|
|
form.Show();
|
|
form.Closed += Form_Closed;
|
|
Hide();
|
|
}
|
|
|
|
private void Form_Closed(Object sender, EventArgs e)
|
|
{
|
|
Show();
|
|
}
|
|
|
|
private void btnPassword_Click(Object sender, EventArgs e)
|
|
{
|
|
var form = new FrmPassword();
|
|
form.Show();
|
|
form.Closed += Form_Closed;
|
|
Hide();
|
|
}
|
|
|
|
private void btnRegisterStore_Click(Object sender, EventArgs e)
|
|
{
|
|
var form = new FrmRegisterStore();
|
|
form.Show();
|
|
form.Closed += Form_Closed;
|
|
Hide();
|
|
}
|
|
|
|
|
|
|
|
private void FrmMainForm_Load(Object sender, EventArgs e)
|
|
{
|
|
Boolean access;
|
|
|
|
try
|
|
{
|
|
access = Logic.SoftwareAccessHelper.Access.HasAccess(SoftwareVersion.Current.AssemblyName);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
var msg = $"Unable to acquire a valid license for this GTB {SoftwareVersion.Current}!\n\n" +
|
|
"Network access error! " +
|
|
"Please connect to the Xylem network or establish a VPN connection.\n\n" +
|
|
"DEVELOPER INFO - Network feedback: ";
|
|
MessageBox.Show(msg + ex.Message, @"GenesisToolBox (GTB)", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
Close();
|
|
CheckConfigs();
|
|
foreach (var item in Controls)
|
|
{
|
|
if (item is Button btn)
|
|
{
|
|
btn.Enabled = btn.Name == btnSetup.Name || btn.Name == btnRegisterStore.Name;
|
|
}
|
|
}
|
|
return;
|
|
}
|
|
if (!access)
|
|
{
|
|
var msg = $"The GTB {SoftwareVersion.Current} is out of support!\n\n" +
|
|
"Please check for versions on the SharePoint location.";
|
|
MessageBox.Show(msg, @"GenesisToolBox (GTB)", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
Close();
|
|
}
|
|
|
|
//if (System.Diagnostics.Debugger.IsAttached)
|
|
//{
|
|
// btnFiles.Enabled = true;
|
|
//}
|
|
|
|
CheckConfigs();
|
|
|
|
//if (false)
|
|
//{
|
|
|
|
|
|
|
|
// gpLAA.Enabled = false;
|
|
// gbDeveloper.Enabled = false;
|
|
|
|
|
|
// foreach (var item in gpGerneral.Controls)
|
|
// {
|
|
// if (item is Button btn)
|
|
// {
|
|
// btn.Enabled = false;
|
|
// }
|
|
// }
|
|
// btnPressure.Enabled = true;
|
|
//}
|
|
|
|
}
|
|
|
|
private void CheckConfigs()
|
|
{
|
|
var applicationDataFolder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
|
|
var genesisFolder = Directory.CreateDirectory(Path.Combine(applicationDataFolder, "Genesis")).FullName;
|
|
|
|
var nLogFile = Path.Combine(genesisFolder, ProgramConfig.NlogConfig);
|
|
|
|
if (!File.Exists(nLogFile))
|
|
{
|
|
try
|
|
{
|
|
File.Copy(ProgramConfig.NlogConfig, nLogFile);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
MessageBox.Show(@"Unable to create log files!");
|
|
}
|
|
}
|
|
|
|
var configFile = Path.Combine(genesisFolder, ProgramConfig.SerialConfigFileName);
|
|
|
|
if (!File.Exists(configFile))
|
|
{
|
|
btnRegisterStore.Enabled = false;
|
|
btnPassword.Enabled = false;
|
|
var text = "Configuration file cannot be found!\nExecute setup.";
|
|
MessageBox.Show(text);
|
|
}
|
|
}
|
|
|
|
//private void BtnLegacyTestApp_Click(Object sender, EventArgs e)
|
|
//{
|
|
// var form = new FrmLegacyTestApp();
|
|
// form.Show();
|
|
// form.Closed += Form_Closed;
|
|
// Hide();
|
|
//}
|
|
|
|
private void btnAlarm_Click(Object sender, EventArgs e)
|
|
{
|
|
var form = new FrmAlarmMng();
|
|
form.Show();
|
|
form.Closed += Form_Closed;
|
|
Hide();
|
|
}
|
|
|
|
private void btnTempLogger_Click(Object sender, EventArgs e)
|
|
{
|
|
//String command = " -h"; //common help flag for console apps
|
|
//System.Diagnostics.Process pRun;
|
|
//pRun = new System.Diagnostics.Process();
|
|
//pRun.EnableRaisingEvents = true;
|
|
//pRun.Exited += new EventHandler(pRun_Exited);
|
|
//pRun.StartInfo.FileName = "TempLogger.exe";
|
|
//pRun.StartInfo.Arguments = command;
|
|
//pRun.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
|
|
|
|
//pRun.Start();
|
|
//pRun.WaitForExit();
|
|
|
|
var form = new FrmTempMeter();
|
|
form.Show();
|
|
form.Closed += Form_Closed;
|
|
Hide();
|
|
|
|
}
|
|
|
|
//private void pRun_Exited(Object sender, EventArgs e)
|
|
//{
|
|
// //Do Something Here
|
|
//}
|
|
|
|
private void btnRelatePCbID_Click(Object sender, EventArgs e)
|
|
{
|
|
var form = new FrmResearchMapping();
|
|
form.Show();
|
|
form.Closed += Form_Closed;
|
|
Hide();
|
|
}
|
|
|
|
private void btnStreamingQuality_Click(Object sender, EventArgs e)
|
|
{
|
|
var form = new FrmStreamingQuality();
|
|
form.Show();
|
|
form.Closed += Form_Closed;
|
|
Hide();
|
|
}
|
|
|
|
private void btnFwUpdate_Click(Object sender, EventArgs e)
|
|
{
|
|
var form = new FrmFwUpdate();
|
|
form.Show();
|
|
form.Closed += Form_Closed;
|
|
Hide();
|
|
}
|
|
|
|
private void btnCalender_Click(Object sender, EventArgs e)
|
|
{
|
|
var form = new frmCalenderSeconds();
|
|
form.Show();
|
|
form.Closed += Form_Closed;
|
|
Hide();
|
|
}
|
|
|
|
private void btnCustomerText_Click(Object sender, EventArgs e)
|
|
{
|
|
var form = new FrmConfigurations();
|
|
form.Show();
|
|
form.Closed += Form_Closed;
|
|
Hide();
|
|
}
|
|
|
|
private void btnFiles_Click(Object sender, EventArgs e)
|
|
{
|
|
var form = new FrmFileCURD();
|
|
form.Show();
|
|
form.Closed += Form_Closed;
|
|
Hide();
|
|
}
|
|
|
|
//private void btnFWMulti_Click(object sender, EventArgs e)
|
|
//{
|
|
// var form = new FrmMultiUpdate();
|
|
// form.Show();
|
|
// form.Closed += Form_Closed;
|
|
// Hide();
|
|
//}
|
|
|
|
private void btnRegHistory_Click(Object sender, EventArgs e)
|
|
{
|
|
var form = new FrmRegisterHistory();
|
|
form.Show();
|
|
form.Closed += Form_Closed;
|
|
Hide();
|
|
}
|
|
|
|
private void btnCalibrationResult_Click(Object sender, EventArgs e)
|
|
{
|
|
var form = new FrmRawDataInterpreter();
|
|
form.Show();
|
|
form.Closed += Form_Closed;
|
|
Hide();
|
|
}
|
|
|
|
private void BtnFileSplit_Click(Object sender, EventArgs e)
|
|
{
|
|
var form = new FrmLogSplit();
|
|
form.Show();
|
|
form.Closed += Form_Closed;
|
|
Hide();
|
|
}
|
|
|
|
private void btnPara_Click(Object sender, EventArgs e)
|
|
{
|
|
var form = new FrmParameterization();
|
|
form.Show();
|
|
form.Closed += Form_Closed;
|
|
Hide();
|
|
}
|
|
|
|
private void btnLegacyTestApp_Click(Object sender, EventArgs e)
|
|
{
|
|
var form = new FrmLegacyTestApp();
|
|
form.Show();
|
|
form.Closed += Form_Closed;
|
|
Hide();
|
|
}
|
|
|
|
private void btnPressure_Click(Object sender, EventArgs e)
|
|
{
|
|
var form = new FrmPressure();
|
|
form.Show();
|
|
form.Closed += Form_Closed;
|
|
Hide();
|
|
}
|
|
|
|
private void button1_Click(Object sender, EventArgs e)
|
|
{
|
|
var form = new FrmLog();
|
|
form.Show();
|
|
form.Closed += Form_Closed;
|
|
Hide();
|
|
}
|
|
|
|
private void button2_Click(Object sender, EventArgs e)
|
|
{
|
|
var form = new FrmTempMeter();
|
|
form.Show();
|
|
form.Closed += Form_Closed;
|
|
Hide();
|
|
}
|
|
|
|
private void gbDeveloper_Enter(Object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void button2_Click_1(Object sender, EventArgs e)
|
|
{
|
|
var form = new FrmProductionData();
|
|
form.Show();
|
|
form.Closed += Form_Closed;
|
|
Hide();
|
|
}
|
|
|
|
private void btnLutUpdate_Click(Object sender, EventArgs e)
|
|
{
|
|
var form = new FrmLutUpdate();
|
|
form.Show();
|
|
form.Closed += Form_Closed;
|
|
Hide();
|
|
}
|
|
|
|
private void button4_Click(Object sender, EventArgs e)
|
|
{
|
|
var form = new FrmLutManagement();
|
|
form.Show();
|
|
form.Closed += Form_Closed;
|
|
Hide();
|
|
}
|
|
|
|
private void button5_Click(Object sender, EventArgs e)
|
|
{
|
|
var form = new FrmMasterMapping();
|
|
form.Show();
|
|
form.Closed += Form_Closed;
|
|
Hide();
|
|
}
|
|
|
|
private void button1_Click_1(Object sender, EventArgs e)
|
|
{
|
|
var form = new FrmConfigurations();
|
|
form.Show();
|
|
form.Closed += Form_Closed;
|
|
Hide();
|
|
}
|
|
|
|
private void btnLog_Click(Object sender, EventArgs e)
|
|
{
|
|
var form = new FrmLowLevelTools();
|
|
form.Show();
|
|
form.Closed += Form_Closed;
|
|
Hide();
|
|
}
|
|
|
|
#region Form initialization
|
|
|
|
/// <summary>
|
|
/// Hides all currently available controls from the main window.
|
|
/// </summary>
|
|
private void HideContent()
|
|
{
|
|
var controlsToRemove = new List<Control>();
|
|
|
|
foreach (Control control in Controls)
|
|
{
|
|
if (control is GroupBox groupBox)
|
|
{
|
|
groupBox.Hide();
|
|
}
|
|
else if (control is IIdentityForm _ )
|
|
{
|
|
controlsToRemove.Add(control);
|
|
}
|
|
}
|
|
|
|
foreach (var control in controlsToRemove)
|
|
{
|
|
Controls.Remove(control);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gives all buttons that pointing to software function or other forms, tag with specific software function.
|
|
/// </summary>
|
|
private void SetSoftwareFunctions()
|
|
{
|
|
menuItemChangePwd.Enabled = Software.IsAutenticated;
|
|
menuItemLogout.Enabled = Software.IsAutenticated;
|
|
menuItemLogin.Enabled = !Software.IsAutenticated;
|
|
|
|
btnSetup.Tag = SoftwareFunctions.GENERAL_SETUP;
|
|
btnAlarm.Tag = SoftwareFunctions.GENERAL_ALARM;
|
|
btnRegisterStore.Tag = SoftwareFunctions.GENERAL_REGISTER_STORE;
|
|
btnTempLogger.Tag = SoftwareFunctions.GENERAL_TEMP_METER;
|
|
btnStreamingQuality.Tag = SoftwareFunctions.GENERAL_STREAM_QUALITY;
|
|
btnFwUpdate.Tag = SoftwareFunctions.GENERAL_FIRMWARE_UPDATE;
|
|
btnLutUpdate.Tag = SoftwareFunctions.GENERAL_LUT_UPDATE;
|
|
button4.Tag = SoftwareFunctions.GENERAL_LUT_MANAGEMENT;
|
|
btnPressure.Tag = SoftwareFunctions.GENERAL_PRESSURE_LOG;
|
|
button1.Tag = SoftwareFunctions.GENERAL_PULS_CONFIG;
|
|
|
|
btnPassword.Tag = SoftwareFunctions.LAA_PASSWORD;
|
|
btnRegHistory.Tag = SoftwareFunctions.LAA_REGISTER_HISTORY;
|
|
btnQsTool.Tag = SoftwareFunctions.LAA_PARAMETERIZATION;
|
|
button2.Tag = SoftwareFunctions.LAA_PROCESS_PARAMETER;
|
|
button5.Tag = SoftwareFunctions.LAA_MAPPING_NA;
|
|
|
|
btnLegacyTestApp.Tag = SoftwareFunctions.DEV_LEGACY_TEST_APP;
|
|
btnFiles.Tag = SoftwareFunctions.DEV_FILE_CONTROL;
|
|
BtnFileSplit.Tag = SoftwareFunctions.DEV_FILE_SPLIT;
|
|
btnLowLevelTools.Tag = SoftwareFunctions.DEV_LOW_LEVEL_TOOLS;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sets a label with error message that says the UI is not available.
|
|
/// </summary>
|
|
private void UINotAvailable()
|
|
{
|
|
Controls.Add(new Label()
|
|
{
|
|
Dock = DockStyle.Fill,
|
|
Text = @"Genesis toolbox is currently not available.",
|
|
TextAlign = ContentAlignment.MiddleCenter,
|
|
Font = new Font(FontFamily.GenericSansSerif, 10, FontStyle.Bold),
|
|
ForeColor = Color.DarkRed,
|
|
Padding = new Padding(15)
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// Shows all UI controls. Sets control enabled or disabled, having tag that is from type SoftwareFunctions.
|
|
/// For DEBUGGING all buttons will be enabled!
|
|
/// </summary>
|
|
private void ShowAvailableSoftwareFunctions()
|
|
{
|
|
foreach (var control in Controls)
|
|
{
|
|
if (control is GroupBox groupBox)
|
|
{
|
|
foreach (var groupBoxControl in groupBox.Controls)
|
|
{
|
|
if (groupBoxControl is Button button)
|
|
{
|
|
if (button.Tag is SoftwareFunctions softwareFunction)
|
|
{
|
|
// enable all buttons for DEBUGGING, else use access rights of user
|
|
button.Enabled = Debugger.IsAttached || Software.IsEnabled(softwareFunction);
|
|
}
|
|
}
|
|
}
|
|
|
|
groupBox.Show();
|
|
}
|
|
else if (control is MenuStrip menu)
|
|
{
|
|
foreach (var item in menu.Items)
|
|
{
|
|
if (item is ToolStripMenuItem toolStripMenuItem)
|
|
{
|
|
ShowAvailableMenuItems(toolStripMenuItem);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
menuItemOptions.Text = Software.UserName;
|
|
}
|
|
|
|
private void ShowAvailableMenuItems(ToolStripMenuItem toolStripMenuItem)
|
|
{
|
|
if (toolStripMenuItem is null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (toolStripMenuItem.Tag is SoftwareFunctions softwareFunction)
|
|
{
|
|
toolStripMenuItem.Visible = Debugger.IsAttached || Software.IsEnabled(softwareFunction);
|
|
}
|
|
|
|
var dropdownItems = toolStripMenuItem.DropDownItems;
|
|
|
|
if (dropdownItems.Count > 0)
|
|
{
|
|
foreach (var item in dropdownItems)
|
|
{
|
|
if (item is ToolStripMenuItem _toolStripMenuItem)
|
|
{
|
|
ShowAvailableMenuItems(_toolStripMenuItem);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Hides all members but the login form if the app is initialized otherwise shows error message.
|
|
/// In case that the app is initialized and user is authorized shows all buttons as enabled or disabled depending on the user permissions.
|
|
/// </summary>
|
|
private void InitializeFormState(RegisterLDAPUser registerForm = null)
|
|
{
|
|
if (registerForm != null)
|
|
{
|
|
Software.Initialize();
|
|
|
|
Controls.Remove(registerForm);
|
|
}
|
|
|
|
HideContent();
|
|
|
|
if (Software.IsRegistrationPending)
|
|
{
|
|
registerForm = new RegisterLDAPUser(InitializeFormState);
|
|
registerForm.OnCancellation += OnControlCancellation;
|
|
|
|
mainMenu.Hide();
|
|
Controls.Add(registerForm);
|
|
}
|
|
else
|
|
{
|
|
mainMenu.Show();
|
|
SetSoftwareFunctions();
|
|
ShowAvailableSoftwareFunctions();
|
|
}
|
|
}
|
|
|
|
private void OnLogoutClick(Object sender, EventArgs e)
|
|
{
|
|
Software.Logout();
|
|
|
|
InitializeFormState();
|
|
}
|
|
|
|
private void OnLoginClick(Object sender, EventArgs args)
|
|
{
|
|
HideContent();
|
|
|
|
var hasLoginForm = false;
|
|
|
|
foreach (var control in Controls)
|
|
{
|
|
if (control is LoginForm)
|
|
{
|
|
hasLoginForm = true;
|
|
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (!hasLoginForm)
|
|
{
|
|
var loginForm = new LoginForm(OnControlCancellation);
|
|
|
|
Controls.Add(loginForm);
|
|
}
|
|
}
|
|
|
|
private void OnChangePasswordClick(Object _, EventArgs _1)
|
|
{
|
|
HideContent();
|
|
|
|
var control = new ChangePassword(OnControlCancellation);
|
|
|
|
Controls.Add(control);
|
|
}
|
|
|
|
private void OnControlCancellation(Control control)
|
|
{
|
|
if (control != null)
|
|
{
|
|
HideContent();
|
|
|
|
// Software.Initialize();
|
|
}
|
|
|
|
InitializeFormState();
|
|
}
|
|
|
|
#endregion Form initialization
|
|
|
|
private void btnQsTool_Click(Object sender, EventArgs e)
|
|
{
|
|
var form = new FrmQsTool();
|
|
form.Show();
|
|
form.Closed += Form_Closed;
|
|
Hide();
|
|
}
|
|
}
|
|
}
|