Exemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the DataViewModel class.
        /// </summary>
        public DataViewModel(MainViewModel parent, Family family)
        {
            _parent = parent;
            _family = family;

            FamilySubmitCommand = new RelayCommand(FamilySubmit, CanSubmitFamily);
            BackUpCommand = new RelayCommand(BackUpSelected);
            AddFamilyMemberCommand = new RelayCommand(AddFamilyMember);
            DeleteSelectedCommand = new RelayCommand(DeleteSelectedMember, CanDeleteSelected);

            if (_family.FamilyMembers.Count == 0)
            {
                // No default Family member, create them.
                _family.AddFamilyMember(new Person("", "", PersonType.Child, 0.0));
            }

            _selectedFamilyMember = _family.FamilyMembers[0];
        }
Exemplo n.º 2
0
        /// <summary>
        /// Returns a list of all Families in the database.  Does not include associated
        /// family members
        /// </summary>
        /// <returns></returns>
        public List<Family> GetFamilies()
        {
            List<Family> families = new List<Family>();

            try
            {
                using (SqlCeConnection dbConnection = new SqlCeConnection(
                      "Data Source=\"SKDDatabase.sdf\""))
                {
                    dbConnection.Open();

                    SqlCeCommand getFamilyCommand = new SqlCeCommand(
                    @"SELECT * FROM family", dbConnection);

                    SqlCeDataReader dbFamilyReader = getFamilyCommand.ExecuteReader();

                    while (dbFamilyReader.Read())
                    {
                        Family family = new Family
                        {
                            FamilyNumber = dbFamilyReader.IsDBNull(0) ? (int?) null : dbFamilyReader.GetInt32(0),
                            AssignedTime = dbFamilyReader.IsDBNull(1) ? (DateTime?) null : dbFamilyReader.GetDateTime(1),
                            NoShow = (dbFamilyReader.IsDBNull(2) ? (bool?) null : dbFamilyReader.GetByte(2) != 0),
                            CheckinTime = dbFamilyReader.IsDBNull(3) ? (DateTime?) null : dbFamilyReader.GetDateTime(3),
                            EmployeeAssignedBy = dbFamilyReader.IsDBNull(4) ? null : dbFamilyReader.GetString(4),
                            Guid = dbFamilyReader.IsDBNull(5) ? (Guid?) null : dbFamilyReader.GetGuid(5),
                            Notes = dbFamilyReader.IsDBNull(6) ? null : dbFamilyReader.GetString(6)
                        };

                        SqlCeCommand getPeopleCommand = new SqlCeCommand(
                            @"SELECT * FROM people INNER JOIN family ON family.fam_id = people.fam_id WHERE family.fam_id = " + family.FamilyNumber, dbConnection);
                        SqlCeDataReader dbPeopleReader = getPeopleCommand.ExecuteReader();

                        while (dbPeopleReader.Read())
                        {
                            Person person = new Person
                            {
                                FamilyId = dbPeopleReader.IsDBNull(0) ? (int?) null : dbPeopleReader.GetInt32(0),
                                FirstName = dbPeopleReader.IsDBNull(1) ? null : dbPeopleReader.GetString(1),
                                LastName = dbPeopleReader.IsDBNull(3) ? null : dbPeopleReader.GetString(3),
                                PersonType = dbPeopleReader.IsDBNull(4) ? (PersonType?) null : (PersonType) dbPeopleReader.GetInt16(4),
                                Weight = dbPeopleReader.IsDBNull(5) ? (double?) null : dbPeopleReader.GetDouble(5),
                                Guid = dbPeopleReader.IsDBNull(6) ? (Guid?) null : dbPeopleReader.GetGuid(6),
                                Notes = dbPeopleReader.IsDBNull(7) ? null : dbPeopleReader.GetString(7)
                            };

                            family.AddFamilyMember(person);
                        }

                        families.Add(family);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Unexpected error:  " + e.Message);
            }

            return families;
        }
Exemplo n.º 3
0
 public void NewChild()
 {
     Family newFam = new Family();
     Person firstPerson = new Person("Test", "Member", PersonType.Child, 0.0) {Guid = Guid.NewGuid()};
     newFam.AddFamilyMember(firstPerson);
     CurrentView = new DataViewModel(this, newFam);
 }