예제 #1
0
 public override void SelectDocument(CopyMachine copyMachine, int document)
 {
     if (document < 0 || copyMachine.SelectedDevice.DocumentCount <= document)
     {
         throw new IndexOutOfRangeException("Invalid document");
     }
     copyMachine.SelectedDocument = document;
 }
예제 #2
0
        public override int TakeChange(CopyMachine copyMachine)
        {
            Console.WriteLine($"Take the change of {copyMachine.Coins} coins");
            var change = copyMachine.Coins;

            copyMachine.Coins = 0;
            copyMachine.State = new CompleteState();
            return(change);
        }
예제 #3
0
 public override void AddCash(CopyMachine copyMachine)
 {
     ConsolePrintHelper.WriteLineLabel("Добро пожаловать!");
     ConsolePrintHelper.WriteLabel("Цена одной страницы : ");
     ConsolePrintHelper.WriteLineValue(copyMachine.CostOfPage.ToString());
     ConsolePrintHelper.WriteLineLabel("Внесите сумму:");
     copyMachine.Cash  = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture);
     copyMachine.State = new ChooseDeviceState();
     copyMachine.State.ChooseDevice(copyMachine);
 }
예제 #4
0
        public override void Print(CopyMachine copyMachine)
        {
            if (copyMachine.MoneyCount < copyMachine.PricePerDocument)
            {
                throw new Exception("Not enough money");
            }

            copyMachine.MoneyCount -= copyMachine.PricePerDocument;
            Console.Write(copyMachine.SelectedDevice.GetDocument(copyMachine.SelectedDocument));
            copyMachine.State = new SelectedDeviceState();
        }
예제 #5
0
 public override void SelectDocument(CopyMachine copyMachine, int docNumber)
 {
     if (copyMachine.Coins > 0)
     {
         Console.WriteLine($"Selected document number {docNumber}");
         copyMachine.State = new PrintState();
     }
     else
     {
         Console.WriteLine("Sorry, deposit is empty for printing documents");
         copyMachine.State = new CompleteState();
     }
 }
예제 #6
0
        static void Main(string[] args)
        {
            var copyMachine = new CopyMachine();

            copyMachine.DepositCoins(1);
            copyMachine.SelectStorageMedia(StorageMedia.UsbFlashDrive);
            copyMachine.SelectDocument(1);
            copyMachine.Print();
            copyMachine.SelectDocument(3);
            copyMachine.Print();
            copyMachine.TakeChange();
            copyMachine.Complete();
        }
            public override void ChooseDocument(CopyMachine copyMachine)
            {
                ConsolePrintHelper.WriteLineLabel("Выберите документ:");
                foreach (var document in copyMachine.Device.Documents)
                {
                    ConsolePrintHelper.WriteLabel($"{nameof(document.Id)} : ");
                    ConsolePrintHelper.WriteValue(document.Id.ToString());
                    ConsolePrintHelper.WriteLabel("; ");
                    ConsolePrintHelper.WriteLabel($"{nameof(document.Name)} : ");
                    ConsolePrintHelper.WriteLineValue(document.Name);
                }
                var documentId = int.Parse(Console.ReadLine());

                copyMachine.Document = copyMachine.Device.Documents.First(i => i.Id == documentId);
                copyMachine.State    = new PrintDocumentState();
                copyMachine.State.PrintDocument(copyMachine);
            }
            public override void ChooseDevice(CopyMachine copyMachine)
            {
                ConsolePrintHelper.WriteLineLabel("Выберите устройство:");
                foreach (var device in Program.Devices)
                {
                    ConsolePrintHelper.WriteLabel($"{nameof(device.Id)} : ");
                    ConsolePrintHelper.WriteValue(device.Id.ToString());
                    ConsolePrintHelper.WriteLabel("; ");
                    ConsolePrintHelper.WriteLabel($"{nameof(device.Name)} : ");
                    ConsolePrintHelper.WriteLineValue(device.Name);
                }
                var deviceId = int.Parse(Console.ReadLine());

                copyMachine.Device = Program.Devices.First(i => i.Id == deviceId);
                copyMachine.State  = new ChooseDocumentState();
                copyMachine.State.ChooseDocument(copyMachine);
            }
            public override void PrintDocument(CopyMachine copyMachine)
            {
                var cost = copyMachine.Document.AmountOfPages * copyMachine.CostOfPage;

                if (copyMachine.Cash - cost < 0)
                {
                    copyMachine.Error = "Внесенных средств недостаточно";
                    copyMachine.State = new ErrorState();
                    copyMachine.State.PrintError(copyMachine);
                    return;
                }
                copyMachine.Cash       -= cost;
                Console.ForegroundColor = ConsoleColor.Cyan;
                Console.WriteLine($"Печать документа: \"{copyMachine.Document.Name}\"");
                Console.ResetColor();
                copyMachine.State = new AskTheQuestionState();
                copyMachine.State.AskTheQuestion(copyMachine);
            }
            public override void AskTheQuestion(CopyMachine copyMachine)
            {
                ConsolePrintHelper.WriteLineLabel("Хотите распечатать еще документ?");
                ConsolePrintHelper.WriteLabel("1 : ");
                ConsolePrintHelper.WriteLineValue("Да");
                ConsolePrintHelper.WriteLabel("2 : ");
                ConsolePrintHelper.WriteLineValue("Нет");

                var result = int.Parse(Console.ReadLine());

                if (result == 1)
                {
                    copyMachine.State = new ChooseDocumentState();
                    copyMachine.State.ChooseDocument(copyMachine);
                    return;
                }
                copyMachine.State = new ReturnDeliveryState();
                copyMachine.State.ReturnDelivery(copyMachine);
            }
예제 #11
0
 public virtual void AddCash(CopyMachine copyMachine)
 {
     ThrowException();
 }
예제 #12
0
 public virtual void Cancel(CopyMachine copyMachine)
 {
     ThrowException();
 }
예제 #13
0
 public virtual void PrintError(CopyMachine copyMachine)
 {
     ThrowException();
 }
예제 #14
0
 public virtual void ReturnDelivery(CopyMachine copyMachine)
 {
     ThrowException();
 }
예제 #15
0
 public virtual void SayGoodbye(CopyMachine copyMachine)
 {
     ThrowException();
 }
예제 #16
0
 public virtual void PrintDocument(CopyMachine copyMachine)
 {
     ThrowException();
 }
예제 #17
0
 public virtual void AskTheQuestion(CopyMachine copyMachine)
 {
     ThrowException();
 }
예제 #18
0
 public override void Print(CopyMachine copyMachine)
 {
     throw new Exception("Device not selected");
 }
예제 #19
0
 public virtual void SelectDocument(CopyMachine copyMachine, int docNumber)
 {
     throw new Exception("It's impossible to select document now");
 }
예제 #20
0
 public virtual void DepositCoins(CopyMachine copyMachine, int coins)
 {
     throw new Exception("It's impossible to deposit coins now");
 }
예제 #21
0
 public virtual void Print(CopyMachine copyMachine)
 {
     throw new Exception("It's impossible to print documents now");
 }
예제 #22
0
 public virtual int TakeChange(CopyMachine copyMachine)
 {
     throw new Exception("It's impossible to take change now");
 }
예제 #23
0
 public override void DepositCoins(CopyMachine copyMachine, int coins)
 {
     Console.WriteLine($"{coins} coins were deposited");
     copyMachine.Coins += coins;
 }
예제 #24
0
 public override void SelectStorageMedia(CopyMachine copyMachine, StorageMedia storageMedia)
 {
     throw new Exception("You haven't deposited any coins yet");
 }
예제 #25
0
 public override void DepositCoins(CopyMachine copyMachine, int coins)
 {
     copyMachine.Coins += coins;
     Console.WriteLine($"{coins} coins were deposited");
     copyMachine.State = new SelectStorageMediaState();
 }
예제 #26
0
 public virtual void Complete(CopyMachine copyMachine)
 {
     Console.WriteLine("Thank you for using the copy machine :)");
     copyMachine.State = new InitState();
 }
예제 #27
0
 public override void SelectDocument(CopyMachine copyMachine, int document)
 {
     throw new Exception("Device not selected");
 }
예제 #28
0
 public virtual void ChooseDevice(CopyMachine copyMachine)
 {
     ThrowException();
 }
예제 #29
0
 public virtual void ChooseDocument(CopyMachine copyMachine)
 {
     ThrowException();
 }
예제 #30
0
 public virtual void SelectStorageMedia(CopyMachine copyMachine, StorageMedia storageMedia)
 {
     throw new Exception("It's impossible to select storage media now");
 }