121 lines
2.9 KiB
C#
121 lines
2.9 KiB
C#
///
|
|
/// Copyright (c) 2017-2022 Sensus Slovensko a.s.
|
|
///
|
|
using System;
|
|
using System.Drawing;
|
|
using System.Windows.Forms;
|
|
using log4net;
|
|
using Common;
|
|
using TBF.Resources;
|
|
|
|
namespace TBF.Rig.Various.CoverTest
|
|
{
|
|
public partial class CoverTestForm : Form
|
|
{
|
|
ILog bypassLog;
|
|
string message;
|
|
|
|
/// Set to 'true' when the form closes
|
|
public bool Completed { get { return completed; } }
|
|
bool completed;
|
|
|
|
GID[] bypassLevel;
|
|
|
|
public CoverTestForm(string message, GID[] bypassLevel, ILog bypassLog)
|
|
{
|
|
InitializeComponent();
|
|
|
|
this.Icon = Properties.Resources.TBF_icon;
|
|
|
|
ControlBox = false;
|
|
|
|
this.message = message;
|
|
this.bypassLevel = bypassLevel;
|
|
this.bypassLog = bypassLog;
|
|
|
|
Localize();
|
|
messageLabel.Text = this.message;
|
|
|
|
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)
|
|
{
|
|
if (!CurrentUser.IsMemberOf(bypassLevel))
|
|
{
|
|
if ((new SharedDatabase.Forms.LoginDlg(bypassLevel, this)).ShowDialog() != DialogResult.OK)
|
|
{
|
|
return;
|
|
}
|
|
|
|
Program.MainWnd.UpdateUser();
|
|
}
|
|
|
|
bypassLog.InfoFormat("{0} bypassed by {1}", message, CurrentUser.UserName());
|
|
|
|
completed = true;
|
|
Close();
|
|
}
|
|
|
|
#region Forced close handling
|
|
|
|
/// <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)
|
|
{
|
|
}
|
|
}
|
|
|
|
public event EventHandler<EventArgs> CloseThisFormHandler;
|
|
|
|
public void StartForceCloseHandler()
|
|
{
|
|
CloseThisFormHandler += delegate(object sender, EventArgs args)
|
|
{
|
|
if (InvokeRequired)
|
|
Invoke(new EventHandler<EventArgs>(OnForceClose), sender, args);
|
|
else
|
|
OnForceClose(sender, args);
|
|
};
|
|
}
|
|
|
|
private void OnForceClose(object sender, EventArgs args)
|
|
{
|
|
DialogResult = DialogResult.Cancel;
|
|
Close();
|
|
}
|
|
|
|
#endregion
|
|
|
|
private void CoverTestForm_FormClosing(object sender, FormClosingEventArgs e)
|
|
{
|
|
if (CurrentUser.Restore(this)) Program.MainWnd.UpdateUser();
|
|
}
|
|
}
|
|
}
|