internal AnimalDetailsForm(Animal animal)
 {
     InitializeComponent();
     RestoreWindow();
     Animal = animal;
     CurrentUser = Environment.UserDomainName + @"\" + Environment.UserName;
     LoadDataContext();
 }
 public AddCollarDeploymentForm(Collar collar = null, Animal animal = null)
 {
     InitializeComponent();
     Collar = collar;
     Animal = animal;
     CurrentUser = Environment.UserDomainName + @"\" + Environment.UserName;
     LoadDataContext();
     LoadDefaultFormContents();
 }
 private bool CanDeleteAnimal(Animal animal)
 {
     //An animal can't have any locations without a deployment
     return !Database.CollarDeployments.Any(d => d.Animal == animal);
 }
 private static string GetName(Animal animal)
 {
     var currentCollar = animal.CollarDeployments.FirstOrDefault(cd => cd.RetrievalDate == null);
     var name = currentCollar == null
                ? animal.AnimalId
                : animal.AnimalId + " (" + currentCollar.Collar + ")";
     if (animal.MortalityDate != null)
         name = String.Format("{0} (mort:{1:M/d/yy})", name, animal.MortalityDate.Value.ToLocalTime());
     return name;
 }
        private void CreateButton_Click(object sender, EventArgs e)
        {
            string animalId = AnimalIdTextBox.Text.NullifyIfEmpty();

            if (Database.Animals.Any(a => a.Project == Project && a.AnimalId == animalId))
            {
                MessageBox.Show("The animal Id is not unique.  Try again", "Database Error", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                AnimalIdTextBox.Focus();
                CreateButton.Enabled = false;
                return;
            }
            var animal = new Animal
            {
                Project = Project,
                AnimalId = AnimalIdTextBox.Text,
                LookupGender = (LookupGender)GenderComboBox.SelectedItem,
                LookupSpecies = (LookupSpecies)SpeciesComboBox.SelectedItem,
                MortalityDate = MortatlityDateTimePicker.Checked ? MortatlityDateTimePicker.Value.ToUniversalTime() : (DateTime?)null,
                GroupName = GroupTextBox.Text,
                Description = DescriptionTextBox.Text
            };
            Database.Animals.InsertOnSubmit(animal);
            if (!SubmitChanges())
            {
                AnimalIdTextBox.Focus();
                CreateButton.Enabled = false;
                return;
            }
            OnDatabaseChanged();
            Close();
        }