using Support.Models; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace Support { public partial class Main : Form { private enum ControlTypes { DASHBOARD, DEVICES, LABS, SETTINGS } private Control CurrentControl = null; private Appsettings Appsettings = null; public Main() { InitializeComponent(); this.Initialize(true); } public void Initialize(bool changeView = false) { this.Appsettings = Models.Appsettings.Load(); if(this.Appsettings != null) { this.btnDashboard.Visible = true; this.btnDevices.Visible = true; if(changeView) { this.AddControl(this.GetControl(ControlTypes.DASHBOARD)); } } else { this.btnDashboard.Visible = false; this.btnDevices.Visible = false; if (changeView) { this.AddControl(this.GetControl(ControlTypes.SETTINGS)); } } } private void AddControl(UserControl control) { if(this.CurrentControl != null) { if (this.CurrentControl.GetType() == typeof(Controls.Dashboard)) { ((Controls.Dashboard)this.CurrentControl).Stop(); } } this.CurrentControl = control; this.pnlContent.Controls.Clear(); control.Dock = DockStyle.Fill; this.pnlContent.Controls.Add(control); } private UserControl GetControl(ControlTypes type) { switch(type) { case ControlTypes.DEVICES: return new Controls.Devices(this.Appsettings, this); case ControlTypes.LABS: return new Controls.Labs(); case ControlTypes.SETTINGS: return new Controls.Settings(this.Appsettings, this); default: return new Controls.Dashboard(this.Appsettings, this); } } private void btnSettings_Click(object sender, EventArgs e) { this.AddControl(GetControl(ControlTypes.SETTINGS)); } private void btnDashboard_Click(object sender, EventArgs e) { this.AddControl(GetControl(ControlTypes.DASHBOARD)); } private void Main_FormClosing(object sender, FormClosingEventArgs e) { try { if(this.CurrentControl != null) { if(this.CurrentControl.GetType() == typeof(Controls.Dashboard)) { ((Controls.Dashboard)this.CurrentControl).Stop(); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } } public void ShowLoading() { this.pbLoading.Visible = true; } public void HideLoading() { this.pbLoading.Visible = false; } private void Main_KeyUp(object sender, KeyEventArgs e) { if(e.KeyCode == Keys.F5) { if (this.CurrentControl != null) { if (this.CurrentControl.GetType() == typeof(Controls.Dashboard)) { ((Controls.Dashboard)this.CurrentControl).Refresh(); } } } } private void btnDevices_Click(object sender, EventArgs e) { this.AddControl(GetControl(ControlTypes.DEVICES)); } } }