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; }
private void backupToolStripMenuItem1_Click(object sender, EventArgs e) { LockerFactory lockerFactory = new LockerFactory(); LockerXMLGateway <Locker> lg = (LockerXMLGateway <Locker>)lockerFactory.GetLocker(); TrainingFactory trainingFactory = new TrainingFactory(); TrainingGateway <Training> tg = (TrainingGateway <Training>)trainingFactory.GetTraining(); PurchaseFactory purchaseFactory = new PurchaseFactory(); PurchaseGateway <Purchase> pg = (PurchaseGateway <Purchase>)purchaseFactory.GetPurchase(); TrainerFactory trainerFactory = new TrainerFactory(); TrainerGateway <Trainer> trainerg = (TrainerGateway <Trainer>)trainerFactory.GetTrainer(); TrainerRatingFactory trainerRatingFactory = new TrainerRatingFactory(); TrainerRatingGateway <TrainerRating> tr = (TrainerRatingGateway <TrainerRating>)trainerRatingFactory.GetTrainerRating(); TicketFactory ticketFactory = new TicketFactory(); TicketGateway <Ticket> ticketg = (TicketGateway <Ticket>)ticketFactory.GetTicket(); // Backup button XDocument xDoc = new XDocument(); XElement xRoot = new XElement("Database"); ClientFactory clientFactory = new ClientFactory(); ClientGateway <Client> cg = (ClientGateway <Client>)clientFactory.GetClient(); Collection <Client> clients = cg.Select(); XElement xClients = new XElement("Clients"); foreach (var client in clients) { xClients.Add(ClientXMLGateway <Client> .Instance.Insert(client)); } DiscountFactory discountFactory = new DiscountFactory(); DiscountGateway <DiscountCard> dg = (DiscountGateway <DiscountCard>)discountFactory.GetCard(); Collection <DiscountCard> cards = dg.Select(); XElement xCards = new XElement("Cards"); foreach (var card in cards) { xCards.Add(DiscountXMLGateway <DiscountCard> .Instance.Insert(card)); } Collection <Locker> lockers = lg.Select(); XElement xLockers = new XElement("Lockers"); foreach (var locker in lockers) { xLockers.Add(LockerXMLGateway <Locker> .Instance.Insert(locker)); } Collection <Purchase> purchases = pg.Select(); XElement xPurchases = new XElement("Purchases"); foreach (var purchase in purchases) { xPurchases.Add(PurchaseXMLGateway <Purchase> .Instance.Insert(purchase)); } Collection <Ticket> tickets = ticketg.Select(); XElement xTickets = new XElement("Tickets"); foreach (var ticket in tickets) { xTickets.Add(TicketXMLGateway <Ticket> .Instance.Insert(ticket)); } Collection <TrainerRating> ratings = tr.Select(); XElement xRatings = new XElement("TrainerRatings"); foreach (var rating in ratings) { xRatings.Add(TrainerRatingXMLGateway <TrainerRating> .Instance.Insert(rating)); } Collection <Trainer> trainers = trainerg.Select(); XElement xTrainers = new XElement("Trainers"); foreach (var trainer in trainers) { xTrainers.Add(TrainerXMLGateway <Trainer> .Instance.Insert(trainer)); } Collection <Training> trainings = tg.Select(); XElement xTrainings = new XElement("Trainings"); foreach (var training in trainings) { xTrainings.Add(TrainingXMLGateway <Training> .Instance.Insert(training)); } xRoot.Add(xClients); xRoot.Add(xCards); xRoot.Add(xLockers); xRoot.Add(xPurchases); xRoot.Add(xTickets); xRoot.Add(xRatings); xRoot.Add(xTrainers); xRoot.Add(xTrainings); xDoc.Add(xRoot); if (!Directory.Exists(Connective.Backup.Paths.FolderPath)) { Directory.CreateDirectory(Connective.Backup.Paths.FolderPath); } using (StreamWriter sw = new StreamWriter(Connective.Backup.Paths.FilePath)) { sw.Write(xDoc.ToString()); } MessageBox.Show("Backed up!"); }