Beispiel #1
0
 private void SelectTypeFromListBox(int typeId)
 {
     foreach (var item in TypeListBox.Items)
     {
         Type types = (Type)item;
         if (types.Id == typeId)
         {
             TypeListBox.SelectedItem = item;
             return;
         }
     }
 }
Beispiel #2
0
        private void TypeListBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (TypeListBox.SelectedIndex > -1)
            {
                //Update textboxes with the new selected item
                Type selectedType = (Type)TypeListBox.SelectedItem;
                //Country selectedType = (Country)TypeListBox.SelectedItem;
                //Currency selectedType = (Currency)TypeListBox.SelectedItem;

                TypeIDTextBox.Text = selectedType.Id.ToString();
                NameTextBox.Text   = selectedType.Name;
            }
        }
Beispiel #3
0
        private void SaveTypeButton_Click(object sender, EventArgs e)
        {
            if (TypeIDTextBox.Text == string.Empty)
            {
                Type t = new Type();
                t.Name = NameTextBox.Text;

                Type savedType = TypesManager.AddType(t);

                MessageBox.Show("A new Type has been added.");

                //refresh the value in the list
                List <Type> typeList = TypesManager.GetTypeList();
                TypeListBox.DataSource = typeList;

                //re-select the chosen type
                SelectTypeFromListBox(savedType.Id);
            }
            else
            {
                //Update existing type entry
                int    typeId   = int.Parse(TypeIDTextBox.Text);
                string typeName = NameTextBox.Text;


                if (TypesManager.UpdateType(typeId, typeName) == 1)
                {
                    //update is successful
                    MessageBox.Show("Type has been updated.");

                    //Get the list of types, and refresh the list box
                    //Re-select the value in the list box
                    List <Type> typeList = TypesManager.GetTypeList();
                    TypeListBox.DataSource = typeList;
                }
                else
                {
                    MessageBox.Show("Type has NOT been updated.");
                }
            }
        }