//Restore button private void restoreToolStripMenuItem_Click(object sender, EventArgs e) { if (MessageBox.Show("Do you really want to restore data from XML? Almost all online data will be lost.", "Restore", MessageBoxButtons.YesNo) == DialogResult.Yes) { LockerFactory lockerFactory = new LockerFactory(); LockerGateway <Locker> lg = (LockerGateway <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(); tg.Delete(); pg.Delete(); tr.Delete(); trainerg.Delete(); lg.Delete(); ticketg.Delete(); foreach (var locker in lg.Select()) { lg.Insert(locker); } foreach (var ticket in TicketXMLGateway <Ticket> .Instance.Select()) { TicketXMLGateway <Ticket> .Instance.Insert(ticket); } foreach (var trainer in TrainerXMLGateway <Trainer> .Instance.Select()) { TrainerXMLGateway <Trainer> .Instance.Insert(trainer); } foreach (var purchase in PurchaseXMLGateway <Purchase> .Instance.Select()) { PurchaseXMLGateway <Purchase> .Instance.Insert(purchase); } foreach (var training in TrainingXMLGateway <Training> .Instance.Select()) { TrainingXMLGateway <Training> .Instance.Insert(training); } foreach (var rating in TrainerRatingXMLGateway <TrainerRating> .Instance.Select()) { TrainerRatingXMLGateway <TrainerRating> .Instance.Insert(rating); } MessageBox.Show("Data restored!"); } }
public void firstInitialize() { ClientFactory clientFactory = new ClientFactory(); ClientGateway <Client> cg = (ClientGateway <Client>)clientFactory.GetClient(); TrainerFactory trainerFactory = new TrainerFactory(); TrainerGateway <Trainer> trainerg = (TrainerGateway <Trainer>)trainerFactory.GetTrainer(); LockerFactory lockerFactory = new LockerFactory(); LockerGateway <Locker> lg = (LockerGateway <Locker>)lockerFactory.GetLocker(); clients = cg.SelectForTrainingStartEnd(true); trainers = trainerg.Select(); lockers = lg.Select(); Collection <string> clientNames = new Collection <string>(); foreach (Client c in clients) { clientNames.Add(c.ToString()); } comboClient.DataSource = clientNames; Collection <Locker> filteredLockers = new Collection <Locker>(); Collection <string> lockerNames = new Collection <string>(); foreach (Locker l in lockers) { if (l.Status != "taken") { filteredLockers.Add(l); } } foreach (Locker l in filteredLockers) { lockerNames.Add(l.ToString()); } comboLocker.DataSource = lockerNames; Collection <string> trainerNames = new Collection <string>(); foreach (Trainer t in trainers) { trainerNames.Add(t.ToString()); } comboTrainer.DataSource = trainerNames; }