Ejemplo n.º 1
0
        void item_Click(object sender, RoutedEventArgs e)
        {
            selected_instructor = ((Instructor)((MenuItem)sender).Tag);
            SelectedInstructorLabel.Content = selected_instructor.ToString();
            NameTextBox.Text = ((MenuItem)sender).Header.ToString();

        }
Ejemplo n.º 2
0
 public Group(String name, String description, timeperiod time, DateTime date, Instructor instructor, GymRoom room)
 {
     this.Name = name;
     this.Description = description;
     this.Time = time;
     this.Date = date;
     this.Instructor = instructor;
     this.Room = room;
     this.Clients = new List<Client>();
 }
Ejemplo n.º 3
0
 private bool CompareForAutoComplete(string input, Instructor instructor)
 {
     if (instructor.Name.ToLower().StartsWith(input.ToLower()) || instructor.LastName.ToLower().StartsWith(input.ToLower()))
     {
         return true;
     }
     else
     {
         return false;
     }
 }
Ejemplo n.º 4
0
        private List<Group> LoadGroupsForInstructor(Instructor instructor)
        {
            List<Group> groups = new List<Group>();
            using (DataSet ds = DataAccess.GetGroupsForInstructor(instructor, connection))
            {
                int id;
                string name;
                string lastName;
                string description;
                timeperiod time;
                DateTime date;
                GymRoom room;

                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    room = new GymRoom();
                    id = ((int)ds.Tables[0].Rows[i]["Id"]);
                    name = ds.Tables[0].Rows[i]["Name"].ToString();
                    description = ds.Tables[0].Rows[i]["Description"].ToString();
                    time = (timeperiod)ds.Tables[0].Rows[i]["TimePeriod"];
                    date = (DateTime)ds.Tables[0].Rows[i]["Date"];
                    using (DataSet roomds = DataAccess.GetRoom(ds.Tables[0].Rows[i]["RoomID"].ToString(), connection))
                    {
                        for (int y = 0; y < roomds.Tables[0].Rows.Count; y++)//Should go over it only once
                        {
                            room.Id = ((int)roomds.Tables[0].Rows[y]["Id"]);
                            room.Type = roomds.Tables[0].Rows[y]["Type"].ToString();
                        }
                    }
                    groups.Add(new Group(id, name, description, (timeperiod)time, date, instructor, room));
                }

                foreach (Group item in groups)
                {
                    using (DataSet data = DataAccess.GetClientsForTheGroup(item.Id, connection))
                    {
                        for (int i = 0; i < data.Tables[0].Rows.Count; i++)
                        {
                            id = ((int)data.Tables[0].Rows[i]["Id"]);
                            name = data.Tables[0].Rows[i]["Name"].ToString();
                            lastName = data.Tables[0].Rows[i]["LastName"].ToString();
                            item.Clients.Add(new Client(id, name, lastName));
                        }

                    }
                }
            }
            return groups;
        }
Ejemplo n.º 5
0
 private void InstructorList_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     if (((ListView)sender).SelectedItem != null)
     {
         selected_instructor = ((Instructor)((ListView)sender).SelectedItem);
         SelectedInstructorLabel.Content = selected_instructor.ToString();
     }
 }
Ejemplo n.º 6
0
        private void LoadAllGroups()
        {

            using (DataSet ds = DataAccess.GetAllTableElements("Groups", connection))//We get all groups from DB
            {
                //temporary variables to store data before it is saved in Groups collection
                int id;
                string name;
                string lastName;
                string description;
                timeperiod time;
                DateTime date;
                Instructor instructor;
                GymRoom room;

                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)//For all rows in resulting datatable
                {
                    instructor = new Instructor();//Initialized here to avoid linked type weirdness
                    room = new GymRoom();//
                    id = ((int)ds.Tables[0].Rows[i]["Id"]);//Placing all the relevant data into temporary vars
                    name = ds.Tables[0].Rows[i]["Name"].ToString();
                    description = ds.Tables[0].Rows[i]["Description"].ToString();
                    time = (timeperiod)ds.Tables[0].Rows[i]["TimePeriod"];
                    date = (DateTime)ds.Tables[0].Rows[i]["Date"];
                    using (DataSet secondary_ds = DataAccess.GetInstructor(ds.Tables[0].Rows[i]["InstructorID"].ToString(), connection))
                    {//Getting isntructor by ID, that we have in groups table, it will be only one in any case, thus no for cycle;
                            instructor.Id = (int)secondary_ds.Tables[0].Rows[0]["Id"];
                            instructor.Name = secondary_ds.Tables[0].Rows[0]["Name"].ToString();
                            instructor.LastName = secondary_ds.Tables[0].Rows[0]["LastName"].ToString();   
                    }
                    using (DataSet secondary_ds = DataAccess.GetRoom(ds.Tables[0].Rows[i]["RoomID"].ToString(), connection))
                    {//Getting room by id, that we have in groups table, it will be only one in any case, thus no for cycle;
                            room.Id = ((int)secondary_ds.Tables[0].Rows[0]["Id"]);
                            room.Type = secondary_ds.Tables[0].Rows[0]["Type"].ToString();
                    }

                    //adding new group to collection based on temp variables
                    groups.Add(new Group(id, name, description, (timeperiod)time, date, instructor, room));
                }

                foreach (Group item in groups)
                {//And basically in the same way we get all clients that are "subscribed" to this group
                    using (DataSet data = DataAccess.GetClientsForTheGroup(item.Id, connection))
                    {
                        for (int i = 0; i < data.Tables[0].Rows.Count; i++)
                        {
                            id = ((int)data.Tables[0].Rows[i]["Id"]);
                            name = data.Tables[0].Rows[i]["Name"].ToString();
                            lastName = data.Tables[0].Rows[i]["LastName"].ToString();
                            item.Clients.Add(new Client(id, name, lastName));
                        }
                    }
                }
            }
        }
Ejemplo n.º 7
0
        private void LoadGroups()
        {
            groups.Clear();
            String tablename = "Groups";
            DataSet ds = DataAccess.GetAllTableElements(tablename, connection);
            int id;
            string name;
            string description;
            timeperiod time;
            DateTime date;
            Instructor instructor;
            GymRoom room;

            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                instructor = new Instructor();
                room = new GymRoom();

                id = ((int)ds.Tables[0].Rows[i]["Id"]);
                name = ds.Tables[0].Rows[i]["Name"].ToString();
                description = ds.Tables[0].Rows[i]["Description"].ToString();
                time = (timeperiod)ds.Tables[0].Rows[i]["TimePeriod"];
                date = (DateTime)ds.Tables[0].Rows[i]["Date"];

                using (DataSet secondary_ds = DataAccess.GetInstructor(ds.Tables[0].Rows[i]["InstructorID"].ToString(), connection))
                {
                    instructor.Id = (int)secondary_ds.Tables[0].Rows[0]["Id"];
                    instructor.Name = secondary_ds.Tables[0].Rows[0]["Name"].ToString();
                    instructor.LastName = secondary_ds.Tables[0].Rows[0]["LastName"].ToString();
                }

                using (DataSet secondary_ds = DataAccess.GetRoom(ds.Tables[0].Rows[i]["RoomID"].ToString(), connection))
                {
                    room.Id = ((int)secondary_ds.Tables[0].Rows[0]["Id"]);
                    room.Type = secondary_ds.Tables[0].Rows[0]["Type"].ToString();
                }

                groups.Add(new Group(id, name, description, (timeperiod)time, date, instructor, room));
            }
        }
Ejemplo n.º 8
0
 private void AddButton_Click(object sender, RoutedEventArgs e)
 {
     Instructor instructor = new Instructor(NameTextBox.Text, LastNameTextBox.Text);
     DataAccess.CreateNewInstructor(connection, instructor);
     this.Close();
 }
Ejemplo n.º 9
0
 public static void DeleteInstructor(SqlConnection connection, Instructor instructor)
 {
     using (SqlCommand command = new SqlCommand("DeleteInstructor", connection))
     {
         command.CommandType = CommandType.StoredProcedure;
         command.Parameters.AddWithValue("@targetId", instructor.Id);
         command.ExecuteNonQuery();
     }
 }
Ejemplo n.º 10
0
 public static void CreateNewInstructor(SqlConnection connection, Instructor instructor)
 {
     using (SqlCommand command = new SqlCommand("AddInstructor", connection))
     {
         command.CommandType = CommandType.StoredProcedure;
         command.Parameters.AddWithValue("@name", instructor.Name);
         command.Parameters.AddWithValue("@lastname", instructor.LastName);
         command.ExecuteNonQuery();
     }
 }
Ejemplo n.º 11
0
 public static DataSet GetGroupsForInstructor(Instructor instructor, SqlConnection connection)
 {
     string query = "Select * from Groups where InstructorID =" + instructor.Id;
     using (DataSet ds = new DataSet())
     {
         using (SqlCommand command = new SqlCommand(query, connection))
         {
             SqlDataAdapter adapter = new SqlDataAdapter(command);
             adapter.Fill(ds);
             return ds;
         }
     }
 }