2017-05-04 14:31:40 +00:00
|
|
|
|
///
|
|
|
|
|
|
/// Copyright (c) 2017 Sensus Metering Systems
|
|
|
|
|
|
///
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
|
using System.Windows.Forms;
|
2017-05-05 20:15:47 +00:00
|
|
|
|
using log4net;
|
2017-05-04 14:31:40 +00:00
|
|
|
|
using TBF.Resources;
|
|
|
|
|
|
|
2021-10-26 09:23:57 +00:00
|
|
|
|
namespace TBF.Rig.Elde.CoverTest
|
2017-05-04 14:31:40 +00:00
|
|
|
|
{
|
2018-09-18 13:25:31 +00:00
|
|
|
|
public partial class CoverTestForm : Form
|
2017-05-04 14:31:40 +00:00
|
|
|
|
{
|
2017-05-05 20:15:47 +00:00
|
|
|
|
ILog bypassLog;
|
|
|
|
|
|
string message;
|
|
|
|
|
|
|
2017-05-04 14:31:40 +00:00
|
|
|
|
/// Set to 'true' when the form closes
|
|
|
|
|
|
public bool Completed { get { return completed; } }
|
|
|
|
|
|
bool completed;
|
|
|
|
|
|
|
2021-09-23 09:46:40 +00:00
|
|
|
|
Common.GID[] bypassLevel;
|
2017-05-04 14:31:40 +00:00
|
|
|
|
|
2021-09-23 09:46:40 +00:00
|
|
|
|
public CoverTestForm(string message, Common.GID[] bypassLevel, ILog bypassLog)
|
2017-05-04 14:31:40 +00:00
|
|
|
|
{
|
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
ControlBox = false;
|
|
|
|
|
|
|
2017-05-05 20:15:47 +00:00
|
|
|
|
this.message = message;
|
2017-05-04 14:31:40 +00:00
|
|
|
|
this.bypassLevel = bypassLevel;
|
2017-05-05 20:15:47 +00:00
|
|
|
|
this.bypassLog = bypassLog;
|
2017-05-04 14:31:40 +00:00
|
|
|
|
|
|
|
|
|
|
Localize();
|
2017-05-05 20:15:47 +00:00
|
|
|
|
messageLabel.Text = this.message;
|
2017-05-04 14:31:40 +00:00
|
|
|
|
|
|
|
|
|
|
float textWidth = Graphics.FromImage(new Bitmap(1, 1)).MeasureString(messageLabel.Text, messageLabel.Font).Width;
|
|
|
|
|
|
int rqrdFormWidth = (int)textWidth + 80; /// Form width calculated from the text width
|
|
|
|
|
|
|
|
|
|
|
|
if (rqrdFormWidth > Width)
|
|
|
|
|
|
{
|
|
|
|
|
|
int shift = (rqrdFormWidth - Width) / 2;
|
|
|
|
|
|
Width = rqrdFormWidth;
|
|
|
|
|
|
bypassButton.Left += shift;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
completed = false;
|
|
|
|
|
|
StartForceCloseHandler();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Localize()
|
|
|
|
|
|
{
|
|
|
|
|
|
Text = Strings.Message;
|
|
|
|
|
|
bypassButton.Text = Strings.Bypass;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void bypassButton_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
2022-05-23 08:38:14 +00:00
|
|
|
|
if (!Users.CurrentUser.IsMemberOf(bypassLevel))
|
2017-05-04 20:44:04 +00:00
|
|
|
|
{
|
2022-05-23 08:38:14 +00:00
|
|
|
|
if ((new Users.Forms.LoginDlg(bypassLevel, this)).ShowDialog() != DialogResult.OK)
|
2017-05-05 20:15:47 +00:00
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2022-05-23 08:38:14 +00:00
|
|
|
|
|
|
|
|
|
|
Program.MainWnd.UpdateUser();
|
2017-05-04 20:44:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-05-23 08:38:14 +00:00
|
|
|
|
bypassLog.InfoFormat("{0} bypassed by {1}", message, Users.CurrentUser.UserName());
|
2017-05-04 14:31:40 +00:00
|
|
|
|
|
|
|
|
|
|
completed = true;
|
|
|
|
|
|
Close();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#region Forced close handling
|
|
|
|
|
|
|
2018-09-18 13:25:31 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Used by CoverTest, AskYesNoOp and MessageBoxOp.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public void OnCloseThisForm(object sender, EventArgs args)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (CloseThisFormHandler == null) return;
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
CloseThisFormHandler(sender, null);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public event EventHandler<EventArgs> CloseThisFormHandler;
|
|
|
|
|
|
|
2017-05-04 14:31:40 +00:00
|
|
|
|
public void StartForceCloseHandler()
|
|
|
|
|
|
{
|
2018-09-18 13:25:31 +00:00
|
|
|
|
CloseThisFormHandler += delegate(object sender, EventArgs args)
|
2017-05-04 14:31:40 +00:00
|
|
|
|
{
|
2018-09-18 13:25:31 +00:00
|
|
|
|
if (InvokeRequired)
|
|
|
|
|
|
Invoke(new EventHandler<EventArgs>(OnForceClose), sender, args);
|
|
|
|
|
|
else
|
|
|
|
|
|
OnForceClose(sender, args);
|
2017-05-04 14:31:40 +00:00
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnForceClose(object sender, EventArgs args)
|
|
|
|
|
|
{
|
|
|
|
|
|
DialogResult = DialogResult.Cancel;
|
|
|
|
|
|
Close();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
2022-05-23 08:38:14 +00:00
|
|
|
|
|
|
|
|
|
|
private void CoverTestForm_FormClosing(object sender, FormClosingEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (Users.CurrentUser.Restore(this)) Program.MainWnd.UpdateUser();
|
|
|
|
|
|
}
|
2017-05-04 14:31:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|