public ServiceCartridge() { InitializeComponent(); CloseTabButton.Barcode = CloseTabButton.RegisterControl((c) => this.NavigateToMainPage()); DateBox.Text = DateTime.Now.ToString("dd.MM.yyyy"); WorkerBox.Text = SessionManager.WorkerName; GuiController.ControlCallback SessionCallback = delegate(string code) { ICodeButton sender = GuiController.GetAssociatedControl(code); sender.Checked = !sender.Checked; }; string[] actions = DatabaseHelper.GetCartridgeActionTypes().ToArray(); // !!!!! List <QRButton> buttons = new List <QRButton>(); int index = 0; foreach (string action in actions) { QRButton button = new QRButton(); button.ButtonText = action; button.Barcode = button.RegisterControl(SessionCallback); button.Anchor = AnchorStyles.Left | AnchorStyles.Top; button.ButtonForeColor = Color.White; button.ButtonFont = new Font(FontFactory.GetFontFamilyByName("Century Gothic"), 12.25F, FontStyle.Bold); button.TabIndex = index; button.Margin = new Padding(0, 0, ContentMargins, ContentMargins); //button.SetCustomData(type); buttons.Add(button); index++; } ContentLayoutPanel.Controls.AddRange(buttons.ToArray()); }
/// <summary> /// /// </summary> /// <param name="control"></param> public static void UnregisterControl(this ICodeButton control) { string code = GetCode(control); if (!string.IsNullOrEmpty(code)) { ControlsDictionary.Remove(code); ControlsCallbacks.Remove(code); } }
/// <summary> /// /// </summary> /// <param name="control"></param> /// <param name="code"></param> /// <param name="callback"></param> /// <returns></returns> public static string RegisterControl(this ICodeButton control, long code, ControlCallback callback) { string strCode = code.ToString(); if (ControlsDictionary.ContainsKey(strCode)) { throw new ArgumentException("Элемент с кодом '" + strCode + "' уже зарегистрирован"); } ControlsDictionary.Add(strCode, control); ControlsCallbacks.Add(strCode, callback); (control as ICodeButton).ButtonClick += (s, e) => callback.Invoke(strCode); ; return(strCode); }
/// <summary> /// /// </summary> /// <param name="control"></param> /// <param name="callback"></param> /// <returns></returns> public static string RegisterControl(this ICodeButton control, ControlCallback callback) { string strCode = GenerateCode().ToString(); long counter = 0; while (ControlsDictionary.ContainsKey(strCode)) { if (counter >= END_RANGE) { break; } strCode = GenerateCode().ToString(); counter++; } ControlsDictionary.Add(strCode, control); ControlsCallbacks.Add(strCode, callback); (control as ICodeButton).ButtonClick += (s, e) => callback.Invoke(strCode); ; return(strCode); }
/// <summary> /// /// </summary> /// <param name="control"></param> /// <returns></returns> private static string GetCode(ICodeButton control) { return(ControlsDictionary.FirstOrDefault(x => x.Value.GetHashCode() == control.GetHashCode()).Key); }
public AddNewCartridge() { GuiController.IsMainActionsAllowed = false; InitializeComponent(); Disposed += (s, e) => AppHelper.ComListener.BarcodeReaded -= CartridgeCodeReaded; AppHelper.ComListener.BarcodeReaded += CartridgeCodeReaded; DateBox.Text = DateTime.Now.ToString("dd.MM.yyyy"); WorkerBox.Text = SessionManager.WorkerName; CloseTabButton.Barcode = CloseTabButton.RegisterControl((c) => this.NavigateToMainPage()); SaveButton.Barcode = SaveButton.RegisterControl((c) => this.NavigateToMainPage()); GuiController.ControlCallback SessionCallback = delegate(string code) { ICodeButton sender = GuiController.GetAssociatedControl(code); sender.Checked = !sender.Checked; }; string[] types = DatabaseHelper.GetCartridgeTypes().ToArray(); List <LinearButton> buttons = new List <LinearButton>(); int index = 0; foreach (string type in types) { LinearButton button = new LinearButton(); button.ButtonText = type; button.Barcode = button.RegisterControl(SessionCallback); button.Anchor = AnchorStyles.Left | AnchorStyles.Top; button.CompactMode = true; button.TabIndex = index; button.Margin = new Padding(0, 0, 0, ContentMargins); button.SetCustomData(type); buttons.Add(button); index++; } TypeLayoutPanel.Controls.AddRange(buttons.ToArray()); string[] models = DatabaseHelper.GetCartridgeModels().ToArray(); buttons = new List <LinearButton>(); index = 0; foreach (string model in models) { LinearButton button = new LinearButton(); button.ButtonText = model; button.Barcode = button.RegisterControl(SessionCallback); button.Anchor = AnchorStyles.Left | AnchorStyles.Top; button.CompactMode = true; button.TabIndex = index; button.Margin = new Padding(0, 0, ContentMargins, ContentMargins); button.SetCustomData(model); buttons.Add(button); index++; } ModelsLayoutPanel.Controls.AddRange(buttons.ToArray()); LocationsBox.LoadContentPage += delegate(AlphabetBox sender, char[] words) { string[] locations = DatabaseHelper.GetCartridgeLocations().ToArray(); locations = locations.Where(x => words.Contains(char.ToLowerInvariant(x.First()))).ToArray(); buttons = new List <LinearButton>(); index = 0; foreach (string location in locations) { LinearButton button = new LinearButton(); button.ButtonText = location; button.Barcode = button.RegisterControl(SessionCallback); button.Anchor = AnchorStyles.Left | AnchorStyles.Top; button.CompactMode = true; button.TabIndex = index; button.Margin = new Padding(0, 0, ContentMargins, ContentMargins); button.SetCustomData(location); buttons.Add(button); index++; } LinearButton backButton = new LinearButton(); backButton.ButtonText = "Вернуться назад"; backButton.Image = Properties.Resources.back_64; backButton.Barcode = backButton.RegisterControl((c) => sender.LoadMainPage()); backButton.ButtonBackColor = Color.LightSkyBlue; backButton.Anchor = AnchorStyles.Left | AnchorStyles.Top; backButton.CompactMode = true; backButton.FontSize = 9.25F; backButton.TabIndex = index; backButton.Margin = new Padding(0, 0, ContentMargins, ContentMargins); buttons.Add(backButton); sender.ContentControls.AddRange(buttons.ToArray()); }; }