SafeDispatch/Safedispatch_4_0/maptab/MenuControl.cs

645 lines
24 KiB
C#
Raw Permalink Normal View History

2024-02-22 16:43:59 +00:00
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Safedispatch_4_0;
namespace Dispatcher.maptab
{
public partial class MenuControl : UserControl
{
public enum UITheme { Blue, Light, Teal };
[Description("Theme"), Category("Data")]
private UITheme _theme;
public UITheme Theme
{
get { return _theme; }
set
{
_theme = value;
ApplyThemeToUI(_theme);
}
}
private int rowCount = 0;
private Tabs previousTab;
public MenuControl()
{
InitializeComponent();
previousTab = Tabs.LIVE;
// create the toolTip that will be displayed
toolTip = new ToolTip();
toolTip.AutoPopDelay = 500;
toolTip.InitialDelay = 500;
toolTip.ReshowDelay = 500;
toolTip.IsBalloon = false;
toolTip.ShowAlways = true;
//this.SuspendLayout();
AddMenuButton(menuLive);
AddMenuButton(menuGeofence);
AddMenuButton(menuHistory);
AddMenuButton(menuText);
AddMenuButton(menuTicketing);
AddMenuButton(menuReports);
AddMenuButton(menuVoice);
AddMenuButton(menuTelemetry);
AddMenuButton(menuSystem);
//this.ResumeLayout();
}
/// <summary>
/// Add a menu button to the table panel
/// </summary>
/// <param name="button">Button which needs to be added</param>
private void AddMenuButton(MenuButton button)
{
//rowCount = tablePanel.RowCount;
RowStyle style = new RowStyle(SizeType.AutoSize);
tablePanel.RowStyles.Add(style);
//tablePanel.RowCount = tablePanel.RowStyles.Count;
// add button to the panel
tablePanel.Controls.Add(button, 0, rowCount++);
}
/// <summary>
/// Event handler for when the button is clicked. This will change
/// the UI for all others buttons
/// </summary>
/// <param name="sender">The menu button which was clicked</param>
private void MenuButton_Click(object sender, EventArgs e)
{
// go through all the controls in order to get
// the menu buttons
foreach (Control ctr in tablePanel.Controls)
{
// check if current control is a Menu Button
if (ctr is MenuButton)
{
// select or deselect it depending on it's state
MenuButton bt = ctr as MenuButton;
if ((MenuButton)sender == bt)
{
ChangeTab(bt, true);
}
else
bt.IsSelected = false;
}
}
}
/// <summary>
/// Event handler for when the button is clicked. This will change
/// the UI for all others buttons
/// </summary>
/// <param name="sender">The menu button which was double clicked</param>
private void MenuButton_DoubleClick(object sender, EventArgs e)
{
// trigger the menu button click in order to change the state of this button
//MenuButton_Click(sender, e);
// go through all the controls in order to get
// the menu buttons
foreach (Control ctr in tablePanel.Controls)
{
// check if current control is a Menu Button
if (ctr is MenuButton)
{
// select or deselect it depending on it's state
MenuButton bt = ctr as MenuButton;
if ((MenuButton)sender == bt)
{
// raise the event for when the Live button is Double Clicked
if (bt == menuLive)
this.OnLiveDoubleClicked(new MenuClickEventArgs() { PreviousTab = previousTab });
// raise the event for when the Geofence button is Double Clicked
else if (bt == menuGeofence)
this.OnGeofenceDoubleClicked(new MenuClickEventArgs() { PreviousTab = previousTab });
// raise the event for when the History button is Double Clicked
else if (bt == menuHistory)
this.OnHistoryDoubleClicked(new MenuClickEventArgs() { PreviousTab = previousTab });
// raise the event for when the Text button is Double Clicked
else if (bt == menuText)
this.OnTextDoubleClicked(new MenuClickEventArgs() { PreviousTab = previousTab });
// raise the event for when the Ticketing button is Double Clicked
else if (bt == menuTicketing)
this.OnTicketingDoubleClicked(new MenuClickEventArgs() { PreviousTab = previousTab });
// raise the event for when the Reports button is Double Clicked
else if (bt == menuReports)
this.OnReportsDoubleClicked(new MenuClickEventArgs() { PreviousTab = previousTab });
// raise the event for when the Voice button is Double Clicked
else if (bt == menuVoice)
this.OnVoiceDoubleClicked(new MenuClickEventArgs() { PreviousTab = previousTab });
// raise the event for when the Telemetry button is Double Clicked
else if (bt == menuTelemetry)
this.OnTelemetryDoubleClicked(new MenuClickEventArgs() { PreviousTab = previousTab });
// raise the event for when the System button is Double Clicked
else if (bt == menuSystem)
this.OnSystemDoubleClicked(new MenuClickEventArgs() { PreviousTab = previousTab });
}
}
}
}
/// <summary>
/// Handle the Alerts click
/// </summary>
private void pbAlerts_Click(object sender, EventArgs e)
{
// raise the event for when the Alerts are clicked
this.OnAlertsClicked(new AlertsEventArgs() { Empty = "" });
}
/// <summary>
/// Change the UI style
/// </summary>
/// <param name="theme"></param>
private void ApplyThemeToUI(UITheme theme)
{
if (theme == UITheme.Light)
{
pbAlerts.Image = Dispatcher.Properties.Resources.t_alert_b;
pbSettings.Image = Dispatcher.Properties.Resources.t_settings_b;
labelSettings.ForeColor = Color.FromArgb(0, 0, 0);
labelAlert.ForeColor = Color.FromArgb(0, 0, 0);
panelTop.BackColor = Color.FromArgb(255, 255, 255);
}
else if (theme == UITheme.Blue)
{
pbAlerts.Image = Dispatcher.Properties.Resources.t_alert;
pbSettings.Image = Dispatcher.Properties.Resources.t_settings;
labelSettings.ForeColor = Color.FromArgb(162, 229, 255);
labelAlert.ForeColor = Color.FromArgb(162, 229, 255);
panelTop.BackColor = Color.FromArgb(12, 121, 203);
}
menuLive.Theme = (theme == UITheme.Light ? MenuButton.ThemeStyle.Light : MenuButton.ThemeStyle.Blue);
menuGeofence.Theme = (theme == UITheme.Light ? MenuButton.ThemeStyle.Light : MenuButton.ThemeStyle.Blue);
menuHistory.Theme = (theme == UITheme.Light ? MenuButton.ThemeStyle.Light : MenuButton.ThemeStyle.Blue);
menuText.Theme = (theme == UITheme.Light ? MenuButton.ThemeStyle.Light : MenuButton.ThemeStyle.Blue);
menuTicketing.Theme = (theme == UITheme.Light ? MenuButton.ThemeStyle.Light : MenuButton.ThemeStyle.Blue);
menuReports.Theme = (theme == UITheme.Light ? MenuButton.ThemeStyle.Light : MenuButton.ThemeStyle.Blue);
menuVoice.Theme = (theme == UITheme.Light ? MenuButton.ThemeStyle.Light : MenuButton.ThemeStyle.Blue);
menuTelemetry.Theme = (theme == UITheme.Light ? MenuButton.ThemeStyle.Light : MenuButton.ThemeStyle.Blue);
menuSystem.Theme = (theme == UITheme.Light ? MenuButton.ThemeStyle.Light : MenuButton.ThemeStyle.Blue);
}
private void ChangeTab(MenuButton bt, bool raiseEvent)
{
// raise the event for when the Live button is clicked
if (bt == menuLive)
{
if(raiseEvent)
this.OnLiveClicked(new MenuClickEventArgs() { PreviousTab = previousTab });
previousTab = Tabs.LIVE;
}
// raise the event for when the Geofence button is clicked
else if (bt == menuGeofence)
{
if (raiseEvent)
this.OnGeofenceClicked(new MenuClickEventArgs() { PreviousTab = previousTab });
previousTab = Tabs.GEOFENCE;
}
// raise the event for when the History button is clicked
else if (bt == menuHistory)
{
if (raiseEvent)
this.OnHistoryClicked(new MenuClickEventArgs() { PreviousTab = previousTab });
previousTab = Tabs.HISTORY;
}
// raise the event for when the Text button is clicked
else if (bt == menuText)
{
if (raiseEvent)
this.OnTextClicked(new MenuClickEventArgs() { PreviousTab = previousTab });
previousTab = Tabs.TEXT;
}
// raise the event for when the Ticketing button is clicked
else if (bt == menuTicketing)
{
if (raiseEvent)
this.OnTicketingClicked(new MenuClickEventArgs() { PreviousTab = previousTab });
previousTab = Tabs.TICKETING;
}
// raise the event for when the Reports button is clicked
else if (bt == menuReports)
{
if (raiseEvent)
this.OnReportsClicked(new MenuClickEventArgs() { PreviousTab = previousTab });
previousTab = Tabs.REPORTS;
}
// raise the event for when the Voice button is clicked
else if (bt == menuVoice)
{
if (raiseEvent)
this.OnVoiceClicked(new MenuClickEventArgs() { PreviousTab = previousTab });
previousTab = Tabs.VOICE;
}
// raise the event for when the Telemetry button is clicked
else if (bt == menuTelemetry)
{
if (raiseEvent)
this.OnTelemetryClicked(new MenuClickEventArgs() { PreviousTab = previousTab });
previousTab = Tabs.TELEMETRY;
}
// raise the event for when the System button is clicked
else if (bt == menuSystem)
{
if (raiseEvent)
this.OnSystemClicked(new MenuClickEventArgs() { PreviousTab = previousTab });
previousTab = Tabs.SYSTEM;
}
bt.IsSelected = true;
}
/// <summary>
/// Set the desired Tab as a consequence of a programmatically
/// change of the tab
/// </summary>
/// <param name="tab">Desired tab which needs to be activated</param>
public void SetTab(Tabs tab, bool raiseEvent)
{
if (tab == Tabs.LIVE)
ChangeTab(menuLive, false);
else if (tab == Tabs.GEOFENCE)
ChangeTab(menuGeofence, false);
else if (tab == Tabs.HISTORY)
ChangeTab(menuHistory, false);
else if (tab == Tabs.TEXT)
ChangeTab(menuText, false);
else if (tab == Tabs.TICKETING)
ChangeTab(menuTicketing, false);
else if (tab == Tabs.REPORTS)
ChangeTab(menuReports, false);
else if (tab == Tabs.VOICE)
ChangeTab(menuVoice, false);
else if (tab == Tabs.TELEMETRY)
ChangeTab(menuTelemetry, false);
else if (tab == Tabs.SYSTEM)
ChangeTab(menuSystem, false);
}
/// <summary>
/// Change the name of the dispatcher inside the menu control
/// </summary>
/// <param name="dispatcher">Name of the logged in dispatcher</param>
public void SetDispatcherName(String dispatcher)
{
labelDispatcher.Text = dispatcher.ToUpper();
}
#region EVENTS
public class AlertsEventArgs : EventArgs
{
public String Empty { get; set; }
}
public event EventHandler AlertsClicked;
/// <summary>
/// Event raise for when the alerts are clicked
/// </summary>
protected virtual void OnAlertsClicked(AlertsEventArgs e)
{
EventHandler handler = this.AlertsClicked;
if (handler != null)
handler(this, e);
}
public class MenuClickEventArgs : EventArgs
{
public Tabs PreviousTab { get; set; }
//public Tabs SelectedTab { get; set; }
}
public event EventHandler MenuButtonClicked;
/// <summary>
/// Event raise for when a menu button is Clicked
/// </summary>
protected virtual void OnMenuButtonClicked(MenuClickEventArgs e)
{
EventHandler handler = this.MenuButtonClicked;
if (handler != null)
handler(this, e);
}
/// <summary>
/// Event raise for when live button is Clicked & DoubleClicked
/// </summary>
public event EventHandler<MenuClickEventArgs> LiveClicked;
public event EventHandler<MenuClickEventArgs> LiveDoubleClicked;
protected virtual void OnLiveClicked(MenuClickEventArgs e)
{
EventHandler<MenuClickEventArgs> handler = this.LiveClicked;
if (handler != null)
handler(this, e);
}
protected virtual void OnLiveDoubleClicked(MenuClickEventArgs e)
{
EventHandler<MenuClickEventArgs> handler = this.LiveDoubleClicked;
if (handler != null)
handler(this, e);
}
/// <summary>
/// Event raise for when geofence button is Clicked & DoubleClicked
/// </summary>
public event EventHandler<MenuClickEventArgs> GeofenceClicked;
public event EventHandler<MenuClickEventArgs> GeofenceDoubleClicked;
protected virtual void OnGeofenceClicked(MenuClickEventArgs e)
{
EventHandler<MenuClickEventArgs> handler = this.GeofenceClicked;
if (handler != null)
handler(this, e);
}
protected virtual void OnGeofenceDoubleClicked(MenuClickEventArgs e)
{
EventHandler<MenuClickEventArgs> handler = this.GeofenceDoubleClicked;
if (handler != null)
handler(this, e);
}
/// <summary>
/// Event raise for when history button is Clicked & DoubleClicked
/// </summary>
public event EventHandler<MenuClickEventArgs> HistoryClicked;
public event EventHandler<MenuClickEventArgs> HistoryDoubleClicked;
protected virtual void OnHistoryClicked(MenuClickEventArgs e)
{
EventHandler<MenuClickEventArgs> handler = this.HistoryClicked;
if (handler != null)
handler(this, e);
}
protected virtual void OnHistoryDoubleClicked(MenuClickEventArgs e)
{
EventHandler<MenuClickEventArgs> handler = this.HistoryDoubleClicked;
if (handler != null)
handler(this, e);
}
/// <summary>
/// Event raise for when text button is Clicked & DoubleClicked
/// </summary>
public event EventHandler<MenuClickEventArgs> TextClicked;
public event EventHandler<MenuClickEventArgs> TextDoubleClicked;
protected virtual void OnTextClicked(MenuClickEventArgs e)
{
EventHandler<MenuClickEventArgs> handler = this.TextClicked;
if (handler != null)
handler(this, e);
}
protected virtual void OnTextDoubleClicked(MenuClickEventArgs e)
{
EventHandler<MenuClickEventArgs> handler = this.TextDoubleClicked;
if (handler != null)
handler(this, e);
}
/// <summary>
/// Event raise for when text button is Clicked & DoubleClicked
/// </summary>
public event EventHandler<MenuClickEventArgs> TicketingClicked;
public event EventHandler<MenuClickEventArgs> TicketingDoubleClicked;
protected virtual void OnTicketingClicked(MenuClickEventArgs e)
{
EventHandler<MenuClickEventArgs> handler = this.TicketingClicked;
if (handler != null)
handler(this, e);
}
protected virtual void OnTicketingDoubleClicked(MenuClickEventArgs e)
{
EventHandler<MenuClickEventArgs> handler = this.TicketingDoubleClicked;
if (handler != null)
handler(this, e);
}
/// <summary>
/// Event raise for when reports button is Clicked & DoubleClicked
/// </summary>
public event EventHandler<MenuClickEventArgs> ReportsClicked;
public event EventHandler<MenuClickEventArgs> ReportsDoubleClicked;
protected virtual void OnReportsClicked(MenuClickEventArgs e)
{
EventHandler<MenuClickEventArgs> handler = this.ReportsClicked;
if (handler != null)
handler(this, e);
}
protected virtual void OnReportsDoubleClicked(MenuClickEventArgs e)
{
EventHandler<MenuClickEventArgs> handler = this.ReportsDoubleClicked;
if (handler != null)
handler(this, e);
}
/// <summary>
/// Event raise for when voice button is Clicked & DoubleClicked
/// </summary>
public event EventHandler<MenuClickEventArgs> VoiceClicked;
public event EventHandler<MenuClickEventArgs> VoiceDoubleClicked;
protected virtual void OnVoiceClicked(MenuClickEventArgs e)
{
EventHandler<MenuClickEventArgs> handler = this.VoiceClicked;
if (handler != null)
handler(this, e);
}
protected virtual void OnVoiceDoubleClicked(MenuClickEventArgs e)
{
EventHandler<MenuClickEventArgs> handler = this.VoiceDoubleClicked;
if (handler != null)
handler(this, e);
}
/// <summary>
/// Event raise for when Telemetry button is Clicked & DoubleClicked
/// </summary>
public event EventHandler<MenuClickEventArgs> TelemetryClicked;
public event EventHandler<MenuClickEventArgs> TelemetryDoubleClicked;
protected virtual void OnTelemetryClicked(MenuClickEventArgs e)
{
EventHandler<MenuClickEventArgs> handler = this.TelemetryClicked;
if (handler != null)
handler(this, e);
}
protected virtual void OnTelemetryDoubleClicked(MenuClickEventArgs e)
{
EventHandler<MenuClickEventArgs> handler = this.TelemetryDoubleClicked;
if (handler != null)
handler(this, e);
}
/// <summary>
/// Event raise for when System button is Clicked & DoubleClicked
/// </summary>
public event EventHandler<MenuClickEventArgs> SystemClicked;
public event EventHandler<MenuClickEventArgs> SystemDoubleClicked;
protected virtual void OnSystemClicked(MenuClickEventArgs e)
{
EventHandler<MenuClickEventArgs> handler = this.SystemClicked;
if (handler != null)
handler(this, e);
}
protected virtual void OnSystemDoubleClicked(MenuClickEventArgs e)
{
EventHandler<MenuClickEventArgs> handler = this.SystemDoubleClicked;
if (handler != null)
handler(this, e);
}
#endregion
private Size largeSize = new Size(242, 814);
private Point pbMenuLocation = new Point();
private Point pbAlertsLocation = new Point();
private Point pbSettingsLocation = new Point();
/// <summary>
/// Intercept the click on the menu picture box
/// in order to enlrage or shrink the menu, move the pictureboxex
/// and hide/show others ui elements
/// </summary>
private void pbMenu_Click(object sender, EventArgs e)
{
if(pbMenu.Tag.Equals("large"))
{
this.SuspendLayout();
// save the current size
largeSize = this.Size;
// save current locations for pbMenu and others
pbSettingsLocation = pbSettings.Location;
pbAlertsLocation = pbAlerts.Location;
pbMenuLocation = pbMenu.Location;
// shrink the size
this.Size = new Size(55, largeSize.Height);
this.ResumeLayout();
pbMenu.Tag = "small";
pbIcon.Visible = false;
labelDispatcher.Visible = false;
labelWelcome.Visible = false;
labelAlert.Visible = false;
labelSettings.Visible = false;
pbMenu.Location = new Point(7, 13);
pbAlerts.Location = new Point(7, 59);
pbSettings.Location = new Point(7, 105);
}
else
{
this.SuspendLayout();
// restore the size
this.Size = new Size(largeSize.Width + 9, largeSize.Height);
this.ResumeLayout();
pbMenu.Tag = "large";
pbIcon.Visible = true;
labelDispatcher.Visible = true;
labelWelcome.Visible = true;
labelAlert.Visible = true;
labelSettings.Visible = true;
pbMenu.Location = pbMenuLocation;
pbAlerts.Location = pbAlertsLocation;
pbSettings.Location = pbSettingsLocation;
}
}
#region TOOLTIP
private void PictureBox_MouseEnter(object sender, EventArgs e)
{
if (sender is PictureBox)
{
PictureBox box = (PictureBox)sender;
DisplayToolTip(sender,
(box == pbAlerts ? " " + "Alerts" + " " :
(box == pbSettings ? " " + "Settings" + " " :
" " + "Menu" + " ")));
}
}
private void PictureBox_MouseHover(object sender, EventArgs e)
{
if (sender is PictureBox)
{
PictureBox box = (PictureBox)sender;
DisplayToolTip(sender,
(box == pbAlerts ? " " + "Alerts" + " " :
(box == pbSettings ? " " + "Settings" + " " :
" " + "Menu" + " ")));
}
}
private void PictureBox_MouseLeave(object sender, EventArgs e)
{
if (sender is PictureBox)
toolTip.Hide((PictureBox)sender);
}
/// <summary>
/// Show a tooltip with the desired message to a specific control
/// </summary>
/// <param name="sender">Control to which the tooltip is attached</param>
/// <param name="message">Message which is written inside the tooltip</param>
private void DisplayToolTip(object sender, string message)
{
toolTip.Show(" " + message + " ", (Control)sender, 15000);
}
#endregion
}
}