Ejemplo n.º 1
0
 public Diet(CatHerder controller, Cat cat, List<Nom> currentDiet)
 {
     _controller = controller;
     _cat = cat;
     _dietInProgress = currentDiet;
     InitializeComponent();
 }
Ejemplo n.º 2
0
 public CatProperties(Cat cat)
 {
     _cat = cat;
     InitializeComponent();
 }
Ejemplo n.º 3
0
 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);
 }
Ejemplo n.º 4
0
 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;
     }
 }
Ejemplo n.º 5
0
 private void WeighACatWithBindings(Cat cat, Weight weight)
 {
     Scale dlg = new Scale(weight);
     if (DialogResult.OK == dlg.ShowDialog())
     {
         _model.SaveObject<Weight>(weight);
         cat.CurrentWeight = weight;
     }
 }
Ejemplo n.º 6
0
 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);
 }
Ejemplo n.º 7
0
 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);
 }
Ejemplo n.º 8
0
 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;
 }
Ejemplo n.º 9
0
 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();
     }
 }
Ejemplo n.º 10
0
 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);
 }
Ejemplo n.º 11
0
 public Owner GetOwner(Cat inCat)
 {
     Owner owner = new Owner
     {
         Name = _model.DefaultOwnerName,
     };
     if (Equals(null, inCat)) return owner;
     return _model.GetOwner(inCat);
 }
Ejemplo n.º 12
0
 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);
 }
Ejemplo n.º 13
0
 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);
 }
Ejemplo n.º 14
0
 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);
         }
     }
 }