コード例 #1
0
 protected override BankWindow createOperations(int number, OperationManager manager)
 {
     OperationFactory factory = new OperationFactory();
     BankWindow bankWindow = new BankWindow(number, manager);
     Random r = new Random();
     List<int> operations = new List<int>();
     int count = r.Next(1, NUMBER_OF_OPERATION + 1);
     while (true)
     {
         bool flag = true;
         int numberOperation = r.Next(1, NUMBER_OF_OPERATION + 1);
         for (int k = 0; k < operations.Count; k++)
         {
             if (numberOperation == operations[k])
                 flag = false;
         }
         if (flag)
         {
             bankWindow.addOperation(factory.createOperation(numberOperation));
             operations.Add(numberOperation);
             count--;
         }
         if (count == 0) break;
     }
     return bankWindow;
 }
コード例 #2
0
 protected override BankWindow createOperations(int number, OperationManager manager)
 {
     OperationFactory factory = new OperationFactory();
     BankWindow bankWindow = new BankWindow(number, manager, new BankWindowFreeState());
     bankWindow.addOperation(factory.createOperation(Transfer.TRANSFER));
     bankWindow.addOperation(factory.createOperation(Payment.PAYMENT));
     return bankWindow;
 }
コード例 #3
0
 protected override BankWindow createOperations(int number)
 {
     OperationFactory factory = new OperationFactory();
     BankWindow bankWindow = new BankWindow(number, new BankWindowFreeState());
     bankWindow.addOperation(factory.createOperation(Credit.CREDIT));
     bankWindow.addOperation(factory.createOperation(Deposit.DEPOSIT));
     return bankWindow;
 }
コード例 #4
0
ファイル: Bank.cs プロジェクト: SergeyStaroletov/Patterns15
 //изменение операций окна
 public void changeOperationBankWindow(int number, List<int> operations)
 {
     OperationFactory factory = new OperationFactory();
     for (int i = 0; i < operations.Count; i++)
     {
         this.listBankWindows[number].addOperation(factory.createOperation(operations[i]));
     }
 }
コード例 #5
0
 protected override BankWindow createOperations(int number)
 {
     OperationFactory factory = new OperationFactory();
     BankWindow bankWindow = new BankWindow(number, new BankWindowFreeState());
     bankWindow.addOperation(factory.createOperation(Deposit.DEPOSIT));
     bankWindow.addOperation(factory.createOperation(Card.CARD));
     bankWindow.addOperation(factory.createOperation(Transfer.TRANSFER));
     return bankWindow;
 }
コード例 #6
0
 protected override BankWindow createOperations(int number, OperationManager manager)
 {
     OperationFactory factory = new OperationFactory();
     BankWindow bankWindow = new BankWindow(number, manager);
     bankWindow.addOperation(factory.createOperation(Credit.CREDIT));
     bankWindow.addOperation(factory.createOperation(Deposit.DEPOSIT));
     bankWindow.addOperation(factory.createOperation(Card.CARD));
     bankWindow.addOperation(factory.createOperation(Transfer.TRANSFER));
     bankWindow.addOperation(factory.createOperation(Payment.PAYMENT));
     return bankWindow;
 }
コード例 #7
0
 public IOperation getOperation(int number)
 {
     int count = this.operations.Count;
     for (int i = 0; i < count; i++)
     {
         if (operations[i].getNumberOperation() == number)
         {
             IOperation op = operations[i];
             operations.RemoveAt(i);
             return op;
         }
     }
     OperationFactory factory = new OperationFactory();
     return factory.createOperation(number);
 }
コード例 #8
0
 private void buttonApply_Click(object sender, EventArgs e)
 {
     OperationFactory factory = new OperationFactory();
     List<BankWindow> bankWindows = this.facade.getListBankWindows();
     bankWindows[numberWindow].deleteAllOperations();
     if (this.checkBoxCredit.Checked == true)
         bankWindows[numberWindow].addOperation(factory.createOperation(Credit.CREDIT));
     if (this.checkBoxDeposit.Checked == true)
         bankWindows[numberWindow].addOperation(factory.createOperation(Deposit.DEPOSIT));
     if (this.checkBoxCard.Checked == true)
         bankWindows[numberWindow].addOperation(factory.createOperation(Card.CARD));
     if (this.checkBoxTransfer.Checked == true)
         bankWindows[numberWindow].addOperation(factory.createOperation(Transfer.TRANSFER));
     if (this.checkBoxPayment.Checked == true)
         bankWindows[numberWindow].addOperation(factory.createOperation(Payment.PAYMENT));
     this.Close();
 }
コード例 #9
0
        public string getInfoAboutWindow(int i)
        {
            OperationFactory factory = new OperationFactory();
            List<BankWindow> bankWindows = this.bank.getListBankWindows();
            string infoWindow = "Выполняемые операции: ";
            List<IOperation> operations = bankWindows[i].getProcessOperation();
            for (int k = 0; k < operations.Count; k++)
            {
                infoWindow += "\n  " + factory.createOperation(operations[k].getNumberOperation()).getNameOperation();
            }
            infoWindow += "\n\nОбслужено операций: " + bankWindows[i].getCountAllOperations();
            infoWindow += "\n  Кредитов: " + bankWindows[i].getCountCredits();
            infoWindow += "\n  Вкладов: " + bankWindows[i].getCountDeposits();
            infoWindow += "\n  Карт: " + bankWindows[i].getCountCards();
            infoWindow += "\n  Переводов: " + bankWindows[i].getCountTransfers();
            infoWindow += "\n  Платежей: " + bankWindows[i].getCountPayments();

            return infoWindow;
        }
コード例 #10
0
        private void buttonApply_Click(object sender, EventArgs e)
        {
            OperationFactory factory = new OperationFactory();
            List<BankWindow> bankWindows = this.facade.getListBankWindows();
            bankWindows[numberWindow].deleteAllOperations();

            List<int> operations = new List<int>();
            if (this.checkBoxCredit.Checked == true)
                operations.Add(Credit.CREDIT);
            if (this.checkBoxDeposit.Checked == true)
                operations.Add(Deposit.DEPOSIT);
            if (this.checkBoxCard.Checked == true)
                operations.Add(Card.CARD);
            if (this.checkBoxTransfer.Checked == true)
                operations.Add(Transfer.TRANSFER);
            if (this.checkBoxPayment.Checked == true)
                operations.Add(Payment.PAYMENT);

            this.facade.changeOperationBankWindow(numberWindow, operations);
            this.Close();
        }
コード例 #11
0
ファイル: Bank.cs プロジェクト: SergeyStaroletov/Patterns15
 //изменение операций окна
 public void changeOperationBankWindow(int number, List<int> operations)
 {
     OperationFactory factory = new OperationFactory();
     for (int i = 0; i < operations.Count; i++)
     {
         this.listBankWindows[number].addOperation(factory.createOperation(operations[i]));
     }
     List<IOperation> operation = this.listBankWindows[number].getProcessOperation();
     for (int i = 0; i < operation.Count; i++)
     {
         if (this.listBankWindows[number].getBuilder().GetType() == typeof(EngBuilder))
         {
             switch (operation[i].getNumberOperation())
             {
                 case Credit.CREDIT: operation[i].setNameOperation("Credits"); break;
                 case Deposit.DEPOSIT: operation[i].setNameOperation("Deposits"); break;
                 case Card.CARD: operation[i].setNameOperation("Cards"); break;
                 case Transfer.TRANSFER: operation[i].setNameOperation("Transfers"); break;
                 case Payment.PAYMENT: operation[i].setNameOperation("Payments"); break;
             }
         }
     }
 }
コード例 #12
0
 //задать клиента
 public void setClient(Client client)
 {
     OperationFactory factory = new OperationFactory();
     this.client = client;
     if (this.client != null)
     {
         switch (client.getNumberOperation())
         {
             case Credit.CREDIT: currentOperation = factory.createOperation(Credit.CREDIT); break;
             case Deposit.DEPOSIT: currentOperation = factory.createOperation(Deposit.DEPOSIT); break;
             case Card.CARD: currentOperation = factory.createOperation(Card.CARD); break;
             case Transfer.TRANSFER: currentOperation = factory.createOperation(Transfer.TRANSFER); break;
             case Payment.PAYMENT: currentOperation = factory.createOperation(Payment.PAYMENT); break;
         }
         Random r = new Random();
         this.currentOperation.setTimeOperation(r.Next(this.currentOperation.getMinTimeOperation(), this.currentOperation.getMinTimeOperation()));
         this.state = new BankWindowBusyState();
     }
     notify();
 }
コード例 #13
0
ファイル: Bank.cs プロジェクト: SergeyStaroletov/Patterns15
        //выполняем работу по таймеру
        private void OnTimedEvent(Object source, System.Timers.ElapsedEventArgs e)
        {
            //System.Windows.Forms.MessageBox.Show("работаю", "");
            ObjectPoolClient pool = ObjectPoolClient.getInstance();
            OperationFactory factory = new OperationFactory();
            Random r = new Random();
            int numberOfClients = r.Next(this.numberOfNewClients + 1);
            for (int i = 0; i < numberOfClients; i++)
            {
                Client client = pool.acquireClient();
                int numberName = r.Next(this.nameClients.Count);
                switch (r.Next(1,NUMBER_OF_OPERATION+1))
                {
                    case 1: client.setName(this.nameClients[numberName]);
                        client.setNumberOperation(Credit.CREDIT);
                        client.setNameOperation(factory.createOperation(Credit.CREDIT).getNameOperation());
                        break;
                    case 2: client.setName(this.nameClients[numberName]);
                        client.setNumberOperation(Deposit.DEPOSIT);
                        client.setNameOperation(factory.createOperation(Deposit.DEPOSIT).getNameOperation());
                        break;
                    case 3: client.setName(this.nameClients[numberName]);
                        client.setNumberOperation(Card.CARD);
                        client.setNameOperation(factory.createOperation(Card.CARD).getNameOperation());
                        break;
                    case 4: client.setName(this.nameClients[numberName]);
                        client.setNumberOperation(Transfer.TRANSFER);
                        client.setNameOperation(factory.createOperation(Transfer.TRANSFER).getNameOperation());
                        break;
                    case 5: client.setName(this.nameClients[numberName]);
                        client.setNumberOperation(Payment.PAYMENT);
                        client.setNameOperation(factory.createOperation(Payment.PAYMENT).getNameOperation());
                        break;
                }
                this.clientQueue.addToQueue(client);
            }

            for (int i = 0; i < this.listBankWindows.Count; i++)
            {
                //если окно свободно и в очереди есть клиенты, то выбираем клиента из очереди и отправлям к окну
                if ((this.listBankWindows[i].getState().GetType() == typeof(BankWindowFreeState))  && this.clientQueue.getClientCount() != 0)
                {
                    List<IOperation> processOperation = this.listBankWindows[i].getProcessOperation();
                    for (int j = 0; j < this.clientQueue.getClientCount(); j++)
                    {
                        Client client = this.clientQueue.takeFromQueue(j);
                        for (int k = 0; k < processOperation.Count; k++)
                        {
                            if (client.getNumberOperation() == processOperation[k].getNumberOperation())
                            {
                                this.listBankWindows[i].setClient(client);
                                this.clientQueue.removeFromQueue(j);
                                break;
                            }
                        }
                        if (this.listBankWindows[i].getState().GetType() == typeof(BankWindowBusyState))
                        {
                            break;
                        }
                    }
                }
                //если окно не свободно, то работаем
               // if (this.listBankWindows[i].getState().GetType() == typeof(BankWindowBusyState))
                //{
                    this.listBankWindows[i].performOperation();
                //}
            }
        }
コード例 #14
0
ファイル: Bank.cs プロジェクト: SergeyStaroletov/Patterns15
        //выполняем работу по таймеру
        private void OnTimedEvent(Object source, System.Timers.ElapsedEventArgs e)
        {
            OperationFactory factory = new OperationFactory();
            Random r = new Random();
            int numberOfClients = r.Next(this.numberOfNewClients + 1);
            for (int i = 0; i < numberOfClients; i++)
            {
                int numberName = r.Next(this.nameClients.Count);
                switch (r.Next(1,NUMBER_OF_OPERATION+1))
                {
                    case 1: this.clientQueue.addToQueue(new Client(this.nameClients[numberName], Credit.CREDIT, factory.createOperation(Credit.CREDIT).getNameOperation())); break;
                    case 2: this.clientQueue.addToQueue(new Client(this.nameClients[numberName], Deposit.DEPOSIT, factory.createOperation(Deposit.DEPOSIT).getNameOperation())); break;
                    case 3: this.clientQueue.addToQueue(new Client(this.nameClients[numberName], Card.CARD, factory.createOperation(Card.CARD).getNameOperation())); break;
                    case 4: this.clientQueue.addToQueue(new Client(this.nameClients[numberName], Transfer.TRANSFER, factory.createOperation(Transfer.TRANSFER).getNameOperation())); break;
                    case 5: this.clientQueue.addToQueue(new Client(this.nameClients[numberName], Payment.PAYMENT, factory.createOperation(Payment.PAYMENT).getNameOperation())); break;
                }
            }

            for (int i = 0; i < this.listBankWindows.Count; i++)
            {
                //если окно свободно и в очереди есть клиенты, то выбираем клиента из очереди и отправлям к окну
                if (this.listBankWindows[i].isFree && this.clientQueue.getClientCount() != 0)
                {
                    List<IOperation> processOperation = this.listBankWindows[i].getProcessOperation();
                    for (int j = 0; j < this.clientQueue.getClientCount(); j++)
                    {
                        Client client = this.clientQueue.takeFromQueue(j);
                        for (int k = 0; k < processOperation.Count; k++)
                        {
                            if (client.getNameOperation() == processOperation[k].getNameOperation())
                            {
                                this.listBankWindows[i].setClient(client);
                                this.clientQueue.removeFromQueue(j);
                                break;
                            }
                        }
                        if (!this.listBankWindows[i].isFree)
                        {
                            break;
                        }
                    }
                }
                //если окно не свободно, то работаем
                if (!this.listBankWindows[i].isFree)
                {
                    this.listBankWindows[i].performOperation();
                }
            }
        }