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"; /// /// Set the selected index for the Drop Down Filter Type in Live Tab /// /// Drop down list selected index /// Live tab instance name in which the control is located public static void SetLiveFilterTypeIndex(int index, String tabName) { string key = $"{LiveFilterTypeIndex}_{tabName}"; updateSettingValue(key, index + ""); } /// /// Get the selected index for the Drop Down Filter Type in Live Tab /// /// Live tab instance name in which the control is located 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"; /// /// Set if a live tab instance is visible or not /// /// Live tab instance name /// Boolean telling if the tab should be visible or not public static void SetLiveTabVisibility(String tabName, bool isVisible) { string key = $"{LiveTabVisibility}_{tabName}"; updateSettingValue(key, isVisible + ""); } /// /// Find if a live tab instance is visible or not /// /// Name of the live tab instance /// Boolean telling if the tab should be visible or not 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 GetLastTabLocation(String tabName) { string key = $"{LiveTabLocation}_{tabName}"; String[] loc = new string[0]; if (MainForm2.HashVal.ContainsKey(key)) loc = MainForm2.HashVal[key].ToString().Split(';'); 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(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] + ""); } /// /// Get all Live Tabs that were oppened in the last SD Session /// /// Array containing all tab names for visible Live Tabs in previous session public static List GetAllVisibleLiveTabs() { List tabNames = new List(); 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; } /// /// Return the total number of live tabs that were generated from the begining of SD /// /// Number of live tab instances ever created 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"; /// /// Set if the unit needs to be visible or not in a specific live tab instance /// /// The unique identifier for the unit /// Boolean telling if the unit is visible or not /// Live tab instance name in which the unit changes it's visibility public static void SetDisplayedInLiveTab(Int32 sipID, bool isDiplayed, String tabName) { string key = $"{OnMapUnit}_{tabName}_{sipID}"; updateSettingValue(key, isDiplayed + ""); } /// /// Detect if a particular unit is visible or not in a specific live tab instance /// /// The unique identifier for the unit /// Live tab instance name in which the unit's visibility is requested /// Boolean telling if the unit is visible or not 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 /// /// Set if the group needs to be visible or not in the grid for a specific live tab instance /// /// Group name for the group /// Boolean telling if the group is visible or not /// Live tab instance name in which the group changes it's visibility public static void SetGroupDisplayedInLiveTab(String groupName, bool isDiplayed, String tabName) { string key = "onMapGroup" + "_" + tabName + "_" + groupName; updateSettingValue(key, isDiplayed + ""); } /// /// Detect if a particular group is visible or not in the grid for a specific live tab instance /// /// Group name for the group /// Live tab instance name in which the group visibility is requested /// Boolean telling if the group is visible or not 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 /// /// Set if the group needs to be expanded or not in the grid for a specific live tab instance /// /// Unique identifier for the group /// Boolean telling if the group is expanded or not /// Live tab instance name in which the group changes it's expanded state public static void SetGroupExpandedInLiveTab(String groupKey, bool isExpanded, String tabName) { string key = "ExpandGroupingHT" + "_" + tabName + "_" + groupKey; updateSettingValue(key, isExpanded + ""); } /// /// Detect if a particular group is expanded or not in the grid for a specific live tab instance /// /// Group name for the group /// Live tab instance name in which the group expanded is requested /// Boolean telling if the group is expanded or not 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"; /// /// Set the grouping type in the grid for a specific live tab instance /// /// The type of the grouping /// Live tab instance name in which the grouping state is applied public static void SetGroupingTypeInLiveTab(String type, String tabName) { string key = LiveGroypingType + "_" + tabName; updateSettingValue(key, type + ""); } /// /// Detect the grouping type in the grid for a specific live tab instance /// /// Live tab instance name in which the group expanded is requested /// Boolean telling if the group is expanded or not 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"; /// /// Set the language name for the desired dispatcher /// /// Dispatcher sip Id/param> /// Language which is set for current dispatcher public static void SetDispatcherLanguage(int dispatcherSipId, String languageName) { string key = $"{DispatcherLanguage}"; updateSettingValue(key, languageName + ""); } /// /// Get the language name for the desired dispatcher /// /// The Sip Id for the dispatcher for which the language needs to be obtained 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 /// /// Update a particular setting from the hashtables /// /// Settings unique identifier or key /// New value for the setting 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; } } } } }