Пример #1
0
        protected override void RefreshData()
        {
            DiscountFactory discountFactory   = new DiscountFactory();
            DiscountGateway <DiscountCard> dg = (DiscountGateway <DiscountCard>)discountFactory.GetCard();

            Collection <DiscountCard> cards  = dg.Select();
            Collection <ExtendedCard> ecards = new Collection <ExtendedCard>();

            foreach (DiscountCard dc in cards)
            {
                ExtendedCard ec = new ExtendedCard();
                ec.CardId = dc.RecordId;
                ec.Credit = dc.Credit;
                if (dc.ClientId != null)
                {
                    ClientFactory          clientFactory = new ClientFactory();
                    ClientGateway <Client> cg            = (ClientGateway <Client>)clientFactory.GetClient();
                    Client c = cg.Select((int)dc.ClientId);
                    ec.Name     = c.Name + " " + c.Surname;
                    ec.ClientId = (int)dc.ClientId;
                }
                ecards.Add(ec);
            }
            BindingList <ExtendedCard> bindingList = new BindingList <ExtendedCard>(ecards);

            cardsGrid.AutoGenerateColumns = false;
            cardsGrid.DataSource          = bindingList;
        }
Пример #2
0
        protected override bool DeleteRecord()
        {
            DiscountFactory discountFactory   = new DiscountFactory();
            DiscountGateway <DiscountCard> dg = (DiscountGateway <DiscountCard>)discountFactory.GetCard();

            dg.Delete(card.RecordId);
            return(true);
        }
Пример #3
0
        protected override bool DeleteRecord()
        {
            DiscountFactory discountFactory   = new DiscountFactory();
            DiscountGateway <DiscountCard> dg = (DiscountGateway <DiscountCard>)discountFactory.GetCard();

            DiscountCard c = dg.Select((int)client.CardId);

            c.ClientId = null;
            dg.Update(c);
            ClientFactory          clientFactory = new ClientFactory();
            ClientGateway <Client> cg            = (ClientGateway <Client>)clientFactory.GetClient();

            cg.Delete(client.RecordId);
            return(true);
        }
Пример #4
0
        public override bool OpenRecord(object primaryKey)
        {
            DiscountFactory discountFactory   = new DiscountFactory();
            DiscountGateway <DiscountCard> dg = (DiscountGateway <DiscountCard>)discountFactory.GetCard();

            if (primaryKey != null)
            {
                int idCard = (int)primaryKey;
                card      = dg.Select(idCard);
                newRecord = false;
            }
            else
            {
                card      = new DiscountCard();
                newRecord = true;
            }
            BindData();
            return(true);
        }
Пример #5
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();
        }
Пример #6
0
        protected override bool SaveRecord()
        {
            DiscountFactory discountFactory   = new DiscountFactory();
            DiscountGateway <DiscountCard> dg = (DiscountGateway <DiscountCard>)discountFactory.GetCard();

            if (GetData())
            {
                if (newRecord)
                {
                    dg.Insert(card);
                }
                else
                {
                    dg.Update(card);
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #7
0
        private void acceptButton_Click(object sender, System.EventArgs e)
        {
            DiscountFactory discountFactory   = new DiscountFactory();
            DiscountGateway <DiscountCard> dg = (DiscountGateway <DiscountCard>)discountFactory.GetCard();

            decimal result;

            if (decimal.TryParse(toSubstract.Text, out result))
            {
                if (result < card.Credit)
                {
                    card.Credit -= result;
                    dg.Update(card);
                    MessageBox.Show("Credit was updated succesfully!", "Success", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("Client does not have enought credit!", "Error", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
                }
                this.Dispose();
            }
        }
Пример #8
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!");
        }
Пример #9
0
        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();
        }