private void LoadMe() { var list = new[] { new { Number = 1, Name = "Pre-school" }, new { Number = 2, Name = "Elementary" }, new { Number = 3, Name = "Secondary" } }; cmbCategory.DataSource = list; cmbCategory.ValueMember = "Number"; cmbCategory.DisplayMember = "Name"; txtDescription.Text = String.Empty; chkCurrent.Checked = true; ITraitService traitService = new TraitService(); ExistingTraits = new List<Trait>(traitService.GetAllTraits()); }
public void LoadTraits() { ITraitService traitService = new TraitService(); string message = String.Empty; try { var traits = traitService.GetAllTraits(); traitList = new List<Trait>(traits); gvTraits.DataSource = traitList; gvTraits.Refresh(); if (gvTraits.RowCount != 0) gvTraits.Rows[0].IsSelected = true; } catch (Exception ex) { message = "Error Loading Traits List"; MessageBox.Show(ex.ToString()); } }
private void Save() { IRegistrationService regService = new RegistrationService(); ITraitService traitService = new TraitService(); Boolean ret = false; string message = String.Empty; Trait trait = new Trait() { Description = txtDescription.Text.ToString(), CurrTrait = chkCurrent.Checked, Category = Int32.Parse(cmbCategory.SelectedValue.ToString()) }; if (ExistingTraits.Exists(t => t.Category == trait.Category && t.Description == trait.Description && t.CurrTrait==trait.CurrTrait)) { MessageBox.Show(this, "Trait for that Category already Exists", "Trait Exists"); } else { if (Op.Equals("edit")) { trait.TraitsID = SelectedTrait.TraitsID; ret = traitService.UpdateTrait(ref trait, ref message); } else { ret = traitService.CreateTrait(ref trait, ref message); if (ret && trait.CurrTrait) { List<Trait> updatedTraits = new List<Trait>(traitService.GetAllTraits()); Trait savedTrait = new Trait(); savedTrait = updatedTraits.Find(t => t.Category == trait.Category && t.Description == trait.Description && t.CurrTrait == trait.CurrTrait); ret = regService.UpdateStudentCharacters(savedTrait); } } if (ret) MessageBox.Show(this, "Saved Successfully"); } this.Close(); }