private Training GetSelectedTraining() { if (trainingsGrid.SelectedRows.Count == 1) { TrainGrid trainGrid = trainingsGrid.SelectedRows[0].DataBoundItem as TrainGrid; Training trn = new Training(); trn.LockerId = trainGrid.LockerId; trn.ToGender = trainGrid.ToGender; trn.TimeFrom = trainGrid.Start; trn.TimeTo = trainGrid.End; return(trn); } else { return(null); } }
protected void RefreshData() { TrainingFactory trainingFactory = new TrainingFactory(); TrainingGateway <Training> tg = (TrainingGateway <Training>)trainingFactory.GetTraining(); TicketFactory ticketFactory = new TicketFactory(); TicketGateway <Ticket> ticketg = (TicketGateway <Ticket>)ticketFactory.GetTicket(); ClientFactory clientFactory = new ClientFactory(); ClientGateway <Client> cg = (ClientGateway <Client>)clientFactory.GetClient(); TrainerFactory trainerFactory = new TrainerFactory(); TrainerGateway <Trainer> trainerg = (TrainerGateway <Trainer>)trainerFactory.GetTrainer(); Collection <Training> trainings = tg.Select(); Collection <TrainGrid> trainGrid = new Collection <TrainGrid>(); foreach (Training t in trainings) { TrainGrid tgrid = new TrainGrid(); tgrid.LockerId = t.LockerId; tgrid.ToGender = t.ToGender; tgrid.Start = t.TimeFrom; tgrid.End = t.TimeTo; // using factory to get data Client c = cg.Select(t.ClientId); tgrid.ClientName = c.Name + " " + c.Surname; int tempId; if (t.TrainerId.HasValue) { tempId = t.TrainerId.Value; Trainer tr = trainerg.Select(tempId); tgrid.TrainerName = tr.Name + " " + tr.Surname; } else { tgrid.TrainerName = ""; } trainGrid.Add(tgrid); } BindingList <TrainGrid> bindingList = new BindingList <TrainGrid>(trainGrid); trainingsGrid.AutoGenerateColumns = false; trainingsGrid.DataSource = bindingList; }