Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 Smart_Journal.Data;
- namespace Smart_Journal.Controls
- {
- public partial class ComboBoxControl : UserControl
- {
- public String Token { private get; set; }
- public String[] Content { get; set; }
- public int Index { get; set; }
- public EIdentifierType Identifier { private get; set; }
- public ComboBoxControl()
- {
- InitializeComponent();
- DisableEdit();
- }
- public ComboBoxControl(String name, String[] content)
- {
- InitializeComponent();
- labelName.Text = name;
- comboboxContentField.DataSource = null;
- comboboxContentField.DataSource = content;
- Content = content;
- DisableEdit();
- }
- public ComboBoxControl(String name, String[] content, int index)
- {
- InitializeComponent();
- labelName.Text = name;
- comboboxContentField.DataSource = null;
- comboboxContentField.DataSource = content;
- Content = content;
- comboboxContentField.SelectedIndex = index;
- DisableEdit();
- }
- public void SetDisplay(int index)
- {
- if (index > Content.Length || index < 0)
- {
- Console.WriteLine("Illegal Værdi forsøgt sat i ComboboxControl: " + labelName.Text);
- }
- else
- {
- comboboxContentField.SelectedIndex = index;
- Index = index;
- }
- }
- private void buttonEdit_Click(object sender, EventArgs e)
- {
- EnableEdit();
- }
- private void buttonAccept_Click(object sender, EventArgs e)
- {
- if (comboboxContentField.SelectedIndex != Index)
- {
- bool IsSuccess = Facade.UpdateIntValue(Identifier, Token, Index);
- if (IsSuccess)
- {
- Index = comboboxContentField.SelectedIndex;
- MessageBox.Show("Oplysningerne blev opdateret!", "Information");
- DisableEdit();
- }
- else
- {
- MessageBox.Show("Der skete desværrer en fejl under opdatering af data. Kontakt venligst support.", "Fejl");
- }
- }
- else
- {
- buttonCancel_Click(null, null);
- }
- }
- private void buttonCancel_Click(object sender, EventArgs e)
- {
- comboboxContentField.SelectedIndex = Index;
- DisableEdit();
- }
- private void EnableEdit()
- {
- buttonEdit.Enabled = false;
- buttonAccept.Enabled = true;
- buttonCancel.Enabled = true;
- comboboxContentField.Enabled = true;
- }
- private void DisableEdit()
- {
- buttonEdit.Enabled = true;
- buttonAccept.Enabled = false;
- buttonCancel.Enabled = false;
- comboboxContentField.Enabled = false;
- }
- public override String ToString()
- {
- return Identifier + ", " + Token + ", " + Content.ToString();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement