SafeDispatch/Safedispatch_4_0/maptab/UIClasses/VisualSettings.cs

466 lines
17 KiB
C#
Raw Permalink Normal View History

2024-02-22 16:43:59 +00:00
using Safedispatch_4_0;
using SafeMobileLib;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Windows.Forms;
using Telerik.WinControls.UI;
namespace Dispatcher.maptab.UIClasses
{
public class VisualSettings
{
public static Hashtable ChangedSettingsHash = new Hashtable();
public static void SetFavoriteInMessages(Int32 sipID, bool isFavorite)
{
string key = "isFavInMessages" + "_" + sipID;
if (!ChangedSettingsHash.Contains(key))
ChangedSettingsHash.Add(key, isFavorite + "");
else
ChangedSettingsHash[key] = isFavorite + "";
}
#region FILTER INDEX IN LIVE TAB
private const String LiveFilterTypeIndex = "liveFilterTypeIndex";
/// <summary>
/// Set the selected index for the Drop Down Filter Type in Live Tab
/// </summary>
/// <param name="index">Drop down list selected index</param>
/// <param name="tabName">Live tab instance name in which the control is located</param>
public static void SetLiveFilterTypeIndex(int index, String tabName)
{
string key = $"{LiveFilterTypeIndex}_{tabName}";
updateSettingValue(key, index + "");
}
/// <summary>
/// Get the selected index for the Drop Down Filter Type in Live Tab
/// </summary>
/// <param name="tabName">Live tab instance name in which the control is located</returns>
public static int GetLiveFilterTypeIndex(String tabName)
{
try
{
string key = $"{LiveFilterTypeIndex}_{tabName}";
if (!MainForm2.HashVal.ContainsKey(key))
return 0;
return int.Parse(MainForm2.HashVal[key] + "");
}
catch (Exception ex)
{
Utils.WriteLine("GetLiveFilterTypeIndex Exception: " + ex.ToString(), ConsoleColor.Red);
}
return 0;
}
#endregion
#region LIVE TAB VISIBILITY
private const String LiveTabVisibility = "liveTabVisibility";
private const String LiveTabLocation = "liveTabLocation";
private const String LiveTabFloating = "liveTabFloating";
/// <summary>
/// Set if a live tab instance is visible or not
/// </summary>
/// <param name="tabName">Live tab instance name</param>
/// <param name="isVisible">Boolean telling if the tab should be visible or not</param>
public static void SetLiveTabVisibility(String tabName, bool isVisible)
{
string key = $"{LiveTabVisibility}_{tabName}";
updateSettingValue(key, isVisible + "");
}
/// <summary>
/// Find if a live tab instance is visible or not
/// </summary>
/// <param name="tabName">Name of the live tab instance</param>
/// <returns>Boolean telling if the tab should be visible or not</returns>
public static bool? isLiveTabVisible(String tabName)
{
string key = $"{LiveTabVisibility}_{tabName}";
if (!MainForm2.HashVal.ContainsKey(key))
return null;
return Boolean.Parse(MainForm2.HashVal[key] + "");
}
public static Tuple<System.Drawing.Point, System.Drawing.Size> GetLastTabLocation(String tabName)
{
string key = $"{LiveTabLocation}_{tabName}";
String[] loc = new string[0];
if (MainForm2.HashVal.ContainsKey(key))
2024-06-07 13:20:57 +00:00
loc = MainForm2.HashVal[key].ToString().Split(";".ToCharArray());
2024-02-22 16:43:59 +00:00
System.Drawing.Point location = loc.Length > 2 ? new System.Drawing.Point(int.Parse(loc[0]), int.Parse(loc[1])) : new System.Drawing.Point(0, 0);
System.Drawing.Size size = loc.Length > 3 ? new System.Drawing.Size(int.Parse(loc[2]), int.Parse(loc[3])) : new System.Drawing.Size(800, 640);
return new Tuple<System.Drawing.Point, System.Drawing.Size>(location, size);
}
public static void SetLiveTabFloating(String tabName, bool isFloating)
{
string key = $"{LiveTabFloating}_{tabName}";
updateSettingValue(key, isFloating + "");
}
public static bool? IsLiveTabFloating(String tabName)
{
string key = $"{LiveTabFloating}_{tabName}";
if (!MainForm2.HashVal.ContainsKey(key))
return null;
return Boolean.Parse(MainForm2.HashVal[key] + "");
}
/// <summary>
/// Get all Live Tabs that were oppened in the last SD Session
/// </summary>
/// <returns>Array containing all tab names for visible Live Tabs in previous session</returns>
public static List<String> GetAllVisibleLiveTabs()
{
List<String> tabNames = new List<string>();
foreach (DictionaryEntry pair in MainForm2.HashVal)
{
// detect live tabs that are visible
if (pair.Key.ToString().StartsWith(LiveTabVisibility + "_") && Boolean.Parse(pair.Value.ToString()))
tabNames.Add(pair.Key.ToString().Replace(LiveTabVisibility + "_", ""));
}
return tabNames;
}
/// <summary>
/// Return the total number of live tabs that were generated from the begining of SD
/// </summary>
/// <returns>Number of live tab instances ever created</returns>
public static int GetTotalNumberOfLiveTabs()
{
int count = 0;
foreach (DictionaryEntry pair in MainForm2.HashVal)
{
// add live tab to the count
if (pair.Key.ToString().StartsWith(LiveTabVisibility + "_"))
count++;
}
return count;
}
#endregion
#region UNIT VISIBILITY ON LIVE TAB
private const String OnMapUnit = "onMapUnit";
/// <summary>
/// Set if the unit needs to be visible or not in a specific live tab instance
/// </summary>
/// <param name="sipID">The unique identifier for the unit</param>
/// <param name="isDiplayed">Boolean telling if the unit is visible or not</param>
/// <param name="tabName">Live tab instance name in which the unit changes it's visibility</param>
public static void SetDisplayedInLiveTab(Int32 sipID, bool isDiplayed, String tabName)
{
string key = $"{OnMapUnit}_{tabName}_{sipID}";
updateSettingValue(key, isDiplayed + "");
}
/// <summary>
/// Detect if a particular unit is visible or not in a specific live tab instance
/// </summary>
/// <param name="sipID">The unique identifier for the unit</param>
/// <param name="tabName">Live tab instance name in which the unit's visibility is requested</param>
/// <returns>Boolean telling if the unit is visible or not</returns>
public static bool IsDisplayedInLiveTab(Int32 sipID, String tabName)
{
try
{
string key = $"{OnMapUnit}_{tabName}_{sipID}";
if (!MainForm2.HashVal.ContainsKey(key))
return false;
return Boolean.Parse(MainForm2.HashVal[key] + "");
}
catch (Exception ex)
{
Utils.WriteLine("IsDisplayedInLiveTab Exception: " + ex.ToString(), ConsoleColor.Red);
}
return false;
}
#endregion
#region GROUP VISIBILITY ON LIVE TAB
/// <summary>
/// Set if the group needs to be visible or not in the grid for a specific live tab instance
/// </summary>
/// <param name="groupName">Group name for the group</param>
/// <param name="isDiplayed">Boolean telling if the group is visible or not</param>
/// <param name="tabName">Live tab instance name in which the group changes it's visibility</param>
public static void SetGroupDisplayedInLiveTab(String groupName, bool isDiplayed, String tabName)
{
string key = "onMapGroup" + "_" + tabName + "_" + groupName;
updateSettingValue(key, isDiplayed + "");
}
/// <summary>
/// Detect if a particular group is visible or not in the grid for a specific live tab instance
/// </summary>
/// <param name="groupName">Group name for the group</param>
/// <param name="tabName">Live tab instance name in which the group visibility is requested</param>
/// <returns>Boolean telling if the group is visible or not</returns>
public static bool? IsGroupDisplayedInLiveTab(String groupName, String tabName)
{
try
{
String key = "onMapGroup" + "_" + tabName + "_" + groupName;
if (!MainForm2.HashVal.ContainsKey(key))
return null;
return Boolean.Parse(MainForm2.HashVal[key] + "");
}
catch (Exception ex)
{
Utils.WriteLine("IsGroupDisplayedInLiveTab Exception: " + ex.ToString(), ConsoleColor.Red);
}
return null;
}
#endregion
#region GROUP EXPANDED STATE ON LIVE TAB
/// <summary>
/// Set if the group needs to be expanded or not in the grid for a specific live tab instance
/// </summary>
/// <param name="groupKey">Unique identifier for the group</param>
/// <param name="isExpanded">Boolean telling if the group is expanded or not</param>
/// <param name="tabName">Live tab instance name in which the group changes it's expanded state</param>
public static void SetGroupExpandedInLiveTab(String groupKey, bool isExpanded, String tabName)
{
string key = "ExpandGroupingHT" + "_" + tabName + "_" + groupKey;
updateSettingValue(key, isExpanded + "");
}
/// <summary>
/// Detect if a particular group is expanded or not in the grid for a specific live tab instance
/// </summary>
/// <param name="groupKey">Group name for the group</param>
/// <param name="tabName">Live tab instance name in which the group expanded is requested</param>
/// <returns>Boolean telling if the group is expanded or not</returns>
public static bool? IsGroupExpandedInLiveTab(String groupKey, String tabName)
{
try
{
String key = "ExpandGroupingHT" + "_" + tabName + "_" + groupKey;
if (!MainForm2.HashVal.ContainsKey(key))
return null;
return Boolean.Parse(MainForm2.HashVal[key] + "");
}
catch (Exception ex)
{
Utils.WriteLine("IsGroupExpandedInLiveTab Exception: " + ex.ToString(), ConsoleColor.Red);
}
return null;
}
#endregion
#region GROUPING TYPE ON LIVE TAB
private const String LiveGroypingType = "liveGroupingType";
/// <summary>
/// Set the grouping type in the grid for a specific live tab instance
/// </summary>
/// <param name="type">The type of the grouping</param>
/// <param name="tabName">Live tab instance name in which the grouping state is applied</param>
public static void SetGroupingTypeInLiveTab(String type, String tabName)
{
string key = LiveGroypingType + "_" + tabName;
updateSettingValue(key, type + "");
}
/// <summary>
/// Detect the grouping type in the grid for a specific live tab instance
/// </summary>
/// <param name="tabName">Live tab instance name in which the group expanded is requested</param>
/// <returns>Boolean telling if the group is expanded or not</returns>
public static String GetGroupingTypeInLiveTab(String tabName)
{
try
{
String key = LiveGroypingType + "_" + tabName;
if (!MainForm2.HashVal.ContainsKey(key))
return null;
return MainForm2.HashVal[key] + "";
}
catch (Exception ex)
{
Utils.WriteLine("GetGroupingTypeInLiveTab Exception: " + ex.ToString(), ConsoleColor.Red);
}
return null;
}
#endregion
#region DISPATCHER LANGUAGE
private const String DispatcherLanguage = "dispatcherLanguage";
/// <summary>
/// Set the language name for the desired dispatcher
/// </summary>
/// <param name="dispatcherSipId">Dispatcher sip Id/param>
/// <param name="languageName">Language which is set for current dispatcher</param>
public static void SetDispatcherLanguage(int dispatcherSipId, String languageName)
{
string key = $"{DispatcherLanguage}";
updateSettingValue(key, languageName + "");
}
/// <summary>
/// Get the language name for the desired dispatcher
/// </summary>
/// <param name="dispatcherSipId">The Sip Id for the dispatcher for which the language needs to be obtained</returns>
public static int GetDispatcherLanguage(int dispatcherSipId)
{
try
{
string key = $"{DispatcherLanguage}";
if (!MainForm2.HashVal.ContainsKey(key))
return 0;
return int.Parse(MainForm2.HashVal[key] + "");
}
catch (Exception ex)
{
Utils.WriteLine("GetDispatcherLanguage Exception: " + ex.ToString(), ConsoleColor.Red);
}
return 0;
}
#endregion
/// <summary>
/// Update a particular setting from the hashtables
/// </summary>
/// <param name="key">Settings unique identifier or key</param>
/// <param name="value">New value for the setting</param>
private static void updateSettingValue(String key, String value)
{
if (!MainForm2.HashVal.Contains(key))
MainForm2.HashVal.Add(key, value);
else
MainForm2.HashVal[key] = value;
if (!ChangedSettingsHash.Contains(key))
ChangedSettingsHash.Add(key, value);
else
ChangedSettingsHash[key] = value;
}
public static void InsertUpdateHTforVisualItems(string parentForm, string controlName, string value)
{
string key = parentForm + (controlName.Length > 0 ? ("_" + controlName) : "");
if (!ChangedSettingsHash.Contains(key))
ChangedSettingsHash.Add(key, value);
else
ChangedSettingsHash[key] = value;
}
public static void InsertUpdateHTforVisualItems(string key, string value)
{
if (!ChangedSettingsHash.Contains(key))
ChangedSettingsHash.Add(key, value);
else
ChangedSettingsHash[key] = value;
}
public static void loadUserVisualSettings(string parent, Control Ctrl, Hashtable HT)
{
string key = string.Empty;
foreach (Control x in Ctrl.Controls)
{
switch (x.GetType().Name)
{
case "RadSpinEditor":
key = parent + "_" + ((RadSpinEditor)x).Name;
if (HT.Contains(key))
((RadSpinEditor)x).Value = Convert.ToDecimal(HT[key].ToString());
break;
case "RadCheckBox":
key = parent + "_" + ((RadCheckBox)x).Name;
if (HT.Contains(key))
((RadCheckBox)x).Checked = Convert.ToBoolean(HT[key].ToString());
break;
case "RadRadioButton":
key = parent + "_" + ((RadRadioButton)x).Name;
if (HT.Contains(key))
((RadRadioButton)x).IsChecked = Convert.ToBoolean(HT[key].ToString());
break;
case "RadListView":
key = parent + "_" + ((RadListView)x).Name;
if (HT.Contains(key))
((RadListView)x).SelectedIndex = Convert.ToInt32(HT[key].ToString());
break;
case "RadTextBox":
key = parent + "_" + ((RadTextBox)x).Name;
if (HT.Contains(key))
((RadTextBox)x).Text = HT[key].ToString();
break;
case "RadCheckedDropDownList":
key = parent + "_" + ((RadCheckedDropDownList)x).Name;
if (HT.Contains(key))
{
((RadCheckedDropDownList)x).Text = "";
((RadCheckedDropDownList)x).Text += HT[key].ToString();
}
break;
}
}
}
}
}