Advertisement
Guest User

Untitled

a guest
Feb 1st, 2015
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.45 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using Smart_Journal.Data;
  11.  
  12. namespace Smart_Journal.Controls
  13. {
  14.     public partial class ComboBoxControl : UserControl
  15.     {
  16.         public String Token { private get; set; }
  17.         public String[] Content { get; set; }
  18.         public int Index { get; set; }
  19.         public EIdentifierType Identifier { private get; set; }
  20.  
  21.         public ComboBoxControl()
  22.         {
  23.             InitializeComponent();
  24.             DisableEdit();
  25.         }
  26.  
  27.         public ComboBoxControl(String name, String[] content)
  28.         {
  29.             InitializeComponent();
  30.             labelName.Text = name;
  31.             comboboxContentField.DataSource = null;
  32.             comboboxContentField.DataSource = content;
  33.             Content = content;
  34.             DisableEdit();
  35.         }
  36.  
  37.         public ComboBoxControl(String name, String[] content, int index)
  38.         {
  39.             InitializeComponent();
  40.             labelName.Text = name;
  41.             comboboxContentField.DataSource = null;
  42.             comboboxContentField.DataSource = content;
  43.             Content = content;
  44.             comboboxContentField.SelectedIndex = index;
  45.             DisableEdit();
  46.         }
  47.  
  48.         public void SetDisplay(int index)
  49.         {
  50.             if (index > Content.Length || index < 0)
  51.             {
  52.                 Console.WriteLine("Illegal Værdi forsøgt sat i ComboboxControl: " + labelName.Text);
  53.             }
  54.             else
  55.             {
  56.                 comboboxContentField.SelectedIndex = index;
  57.                 Index = index;
  58.             }
  59.         }
  60.  
  61.         private void buttonEdit_Click(object sender, EventArgs e)
  62.         {
  63.             EnableEdit();
  64.         }
  65.  
  66.         private void buttonAccept_Click(object sender, EventArgs e)
  67.         {
  68.             if (comboboxContentField.SelectedIndex != Index)
  69.             {
  70.                 bool IsSuccess = Facade.UpdateIntValue(Identifier, Token, Index);
  71.                 if (IsSuccess)
  72.                 {
  73.                     Index = comboboxContentField.SelectedIndex;
  74.                     MessageBox.Show("Oplysningerne blev opdateret!", "Information");
  75.                     DisableEdit();
  76.                 }
  77.                 else
  78.                 {
  79.                     MessageBox.Show("Der skete desværrer en fejl under opdatering af data. Kontakt venligst support.", "Fejl");
  80.                 }
  81.             }
  82.             else
  83.             {
  84.                 buttonCancel_Click(null, null);
  85.             }
  86.         }
  87.  
  88.         private void buttonCancel_Click(object sender, EventArgs e)
  89.         {
  90.             comboboxContentField.SelectedIndex = Index;
  91.             DisableEdit();
  92.         }
  93.  
  94.         private void EnableEdit()
  95.         {
  96.             buttonEdit.Enabled = false;
  97.             buttonAccept.Enabled = true;
  98.             buttonCancel.Enabled = true;
  99.             comboboxContentField.Enabled = true;
  100.         }
  101.  
  102.         private void DisableEdit()
  103.         {
  104.             buttonEdit.Enabled = true;
  105.             buttonAccept.Enabled = false;
  106.             buttonCancel.Enabled = false;
  107.             comboboxContentField.Enabled = false;
  108.         }
  109.  
  110.         public override String ToString()
  111.         {
  112.             return Identifier + ", " + Token + ", " + Content.ToString();
  113.         }
  114.  
  115.     }
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement