public Diet(CatHerder controller, Cat cat, List<Nom> currentDiet) { _controller = controller; _cat = cat; _dietInProgress = currentDiet; InitializeComponent(); }
public CatProperties(Cat cat) { _cat = cat; InitializeComponent(); }
public int CompareTo(Cat other) { if (Equals(null, other)) return 1; if (this.BirthDate > other.BirthDate) return -1; if (this.BirthDate < other.BirthDate) return 1; return String.Compare(this.Name, other.Name, true); }
private void WeighACatNoBindings(Cat cat, Weight weight) { Scale dlg = new Scale(weight.Pounds, weight.Date); if (DialogResult.OK == dlg.ShowDialog()) { weight.Pounds = dlg.Pounds; weight.Date = dlg.WeighDate; _model.SaveObject<Weight>(weight); cat.CurrentWeight = weight; } }
private void WeighACatWithBindings(Cat cat, Weight weight) { Scale dlg = new Scale(weight); if (DialogResult.OK == dlg.ShowDialog()) { _model.SaveObject<Weight>(weight); cat.CurrentWeight = weight; } }
public void SaveAMeal(Meal meal, Cat cat) { if (Equals(null, _model)) return; meal.MyCat = cat; meal.Time = System.DateTime.Now; foreach (NomsThisMeal nom in meal.Noms) _model.SaveObject<NomsThisMeal>(nom); _model.SaveObject<Meal>(meal); }
public void WeighACat(Cat cat) { if (Equals(null, _model)) return; _model.GetCurrentWeight(cat); if (Equals(null, cat.CurrentWeight)) { cat.CurrentWeight = new Weight(); cat.CurrentWeight.CatKey = cat.Id; } Weight newWeight = new Weight(cat.CurrentWeight); WeighACatNoBindings(cat, newWeight); WeighACatWithBindings(cat, newWeight); }
public bool IsAdoptable(Cat inCat) { var owners = from cat in Cats where cat.Id == inCat.Id select cat.MyOwner ; if (owners.Count<Owner>() > 0) return Equals(null, owners.ElementAt<Owner>(0)); return true; }
public void ModifyDiet(Cat cat) { if (Equals(null, _model)) return; _dietInProgress = new List<Nom>(cat.NomsAsList); Diet dlg = new Diet(this, cat, _dietInProgress); try { if (DialogResult.OK == dlg.ShowDialog()) { cat.NomsICanEat.Clear(); foreach (Nom nom in _dietInProgress) cat.NomsICanEat.Add(nom); _model.SaveObject<Cat>(cat); } } finally { dlg.Close(); } }
public List<Cat> GetSiblings(Cat cat) { List<Cat> cats = new List<Cat>(); if (Equals(null, _model) || Equals(null, cat) || Equals(null, cat.MyOwner)) return cats; return _model.GetOwnerCats(cat.MyOwner.Id); }
public Owner GetOwner(Cat inCat) { Owner owner = new Owner { Name = _model.DefaultOwnerName, }; if (Equals(null, inCat)) return owner; return _model.GetOwner(inCat); }
public void FeedACat(Cat cat) { _catInProgress = cat; Meal meal = new Meal { MyCat = cat, Time = System.DateTime.Now }; MealTime dlg = new MealTime(this, meal); string result = String.Empty; MessageBoxIcon icon = MessageBoxIcon.None; if (DialogResult.OK == dlg.ShowDialog()) { result = "Yum!"; icon = MessageBoxIcon.Exclamation; SaveAMeal(dlg.MyMeal, _catInProgress); } else { result = "Yuck!"; icon = MessageBoxIcon.Question; } MessageBox.Show(result, "Feed Me", MessageBoxButtons.OK, icon, MessageBoxDefaultButton.Button1); }
public void CreateACat() { if (Equals(null, _model)) return; Cat cat = new Cat(); CatProperties dlg = new CatProperties(cat); if (DialogResult.OK == dlg.ShowDialog()) { _model.SaveObject<Cat>(cat); // Refresh the cats list Cats.Add(cat); Cats.Sort((catA, catB) => catA.CompareTo(catB)); } if (!Equals(null, OnNewCatsAvailable)) OnNewCatsAvailable(this); }
public void AdoptACat(Cat cat) { if (Equals(null, _model)) return; if (!IsAdoptable(cat)) return; SelectOwner dlg = new SelectOwner(this, false); if (DialogResult.OK == dlg.ShowDialog() && 0 < _ownerNameInProgress.Length) { IEnumerable<Owner> allOwners = _model.GetAll<Owner>(); var owners = from owner in allOwners where 0 == String.Compare(owner.Name, _ownerNameInProgress, true) select owner; if (owners.Count<Owner>() > 0) { cat.MyOwner = owners.ElementAt<Owner>(0); _model.SaveObject<Cat>(cat); } } }