示例#1
0
        private void HandleUserTrainingProgram()
        {
            //Lazy loading
            if (this.trainFactory == null)
            {
                this.trainFactory = new TrainingFactory();
            }

            string currentRegimen = this.currentUser.Regimen.GetType().Name;

            this.Renderer.RenderMessage(Messages.ChooseIntensityMessage);
            int       intensityChoose = int.Parse(Console.ReadLine());
            Intensity intensity;

            switch (intensityChoose)
            {
            case 3: intensity = Intensity.ThreeDays; break;

            case 4: intensity = Intensity.FourDays; break;

            case 5: intensity = Intensity.FiveDays; break;

            case 6: intensity = Intensity.SixDays; break;

            default: throw new ArgumentException("Invalid intensity value");
            }

            this.currentUser.Regimen.Program = trainFactory.CreateTrainingProgram("Unknown", intensity, currentRegimen);
            this.Renderer.RenderMessage(Messages.SuccessfulTrainingSetMessage);
            this.trainFactory = null;
        }
        public void firstInitialize()
        {
            ClientFactory                  clientFactory   = new ClientFactory();
            ClientGateway <Client>         cg              = (ClientGateway <Client>)clientFactory.GetClient();
            TrainingFactory                trainingFactory = new TrainingFactory();
            TrainingGateway <Training>     tg              = (TrainingGateway <Training>)trainingFactory.GetTraining();
            DiscountFactory                discountFactory = new DiscountFactory();
            DiscountGateway <DiscountCard> dg              = (DiscountGateway <DiscountCard>)discountFactory.GetCard();
            PurchaseFactory                purchaseFactory = new PurchaseFactory();
            PurchaseGateway <Purchase>     pg              = (PurchaseGateway <Purchase>)purchaseFactory.GetPurchase();
            TicketFactory                  ticketFactory   = new TicketFactory();
            TicketGateway <Ticket>         ticketg         = (TicketGateway <Ticket>)ticketFactory.GetTicket();


            Client client = cg.Select(tg.SelectLast().ClientId);


            clientName.Text = client.ToString();

            if (client.CardId != null)
            {
                int toSetId = client.CardId ?? default(int);
                card = dg.Select(toSetId);
            }
            Ticket t = ticketg.Select(pg.SelectLast(card.RecordId).TicketId);

            ticketType.Text = t.Type;
            credit.Text     = card.Credit.ToString();
        }
示例#3
0
        //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!");
            }
        }
        private void acceptButton_Click(object sender, System.EventArgs e)
        {
            TrainingFactory            trainingFactory = new TrainingFactory();
            TrainingGateway <Training> tg = (TrainingGateway <Training>)trainingFactory.GetTraining();
            Training tr = tg.SelectLast(clients[comboClient.SelectedIndex].RecordId);

            tr.TimeTo = DateTime.Now;

            tg.Update(tr);
            MessageBox.Show("Training was ended Successfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
            this.Dispose();
        }
        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;
        }
示例#6
0
        private void acceptButton_Click(object sender, EventArgs e)
        {
            Training t = new Training();

            t.LockerId  = lockers[comboLocker.SelectedIndex].RecordId;
            t.ClientId  = clients[comboClient.SelectedIndex].RecordId;
            t.TrainerId = trainers[comboTrainer.SelectedIndex].RecordId;
            t.ToGender  = clients[comboClient.SelectedIndex].Gender;
            t.TimeFrom  = DateTime.Now;

            ClientFactory          clientFactory = new ClientFactory();
            ClientGateway <Client> cg            = (ClientGateway <Client>)clientFactory.GetClient();
            Client c = cg.Select(t.ClientId);

            DiscountFactory discountFactory   = new DiscountFactory();
            DiscountGateway <DiscountCard> dg = (DiscountGateway <DiscountCard>)discountFactory.GetCard();

            DiscountCard card = new DiscountCard();

            if (c.CardId != null)
            {
                int toSetId = c.CardId ?? 0;
                card = dg.Select(toSetId);
            }
            TrainingFactory            trainingFactory = new TrainingFactory();
            TrainingGateway <Training> tg = (TrainingGateway <Training>)trainingFactory.GetTraining();

            tg.Insert(t);

            if (card != null && card.Credit > 0)
            {
                Forms.ChangeCredit form = new Forms.ChangeCredit();
                form.ShowDialog();
            }
            else
            {
                MessageBox.Show("Training was added successfully but client " + c.Name + " " + c.Surname + " has no credit on card!", "Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
            }
            this.Dispose();
        }
示例#7
0
        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!");
        }
示例#8
0
 public TrainingController(TrainingFactory trainingFactory)
 {
     TrainingFactory = trainingFactory;
 }