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>(); }
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; }
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)); } } } } }
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)); } }