Beispiel #1
0
            public void ViewProductBuy()
            {
                try
                {
                    using (FileStream Stream = new FileStream("B:\\TEMPFORMPT\\BuyProduct.pro", FileMode.Open, FileAccess.Read))
                        using (BinaryReader FP = new BinaryReader(Stream)) { }
                }
                catch
                {
                    Console.WriteLine("\nОШИБКА!\nПродукты не найдены!");
                    AddProduct();
                    goto ViewProductBuy;
                }
                Money.MoneyAccount moneyAccount = new Money.MoneyAccount();
ViewProductBuy:

                int count = 0;

                using (FileStream Stream = new FileStream("B:\\TEMPFORMPT\\BuyProduct.pro", FileMode.Open, FileAccess.Read))
                    using (BinaryReader FP = new BinaryReader(Stream))
                    {
                        while (FP.PeekChar() != -1)
                        {
                            ID    = FP.ReadInt32();
                            NAME  = FP.ReadString();
                            PRICE = FP.ReadInt32();
                            count++;
                        }
                    }
                string[] ProductName  = new string[count + 2];
                int[]    ProductPrice = new int[count];
                int      ind          = 0;

                using (FileStream Stream = new FileStream("B:\\TEMPFORMPT\\BuyProduct.pro", FileMode.Open, FileAccess.Read))
                    using (BinaryReader FP = new BinaryReader(Stream))
                    {
                        while (FP.PeekChar() != -1)
                        {
                            ID                = FP.ReadInt32();
                            NAME              = FP.ReadString();
                            PRICE             = FP.ReadInt32();
                            ProductName[ind]  = NAME;
                            ProductPrice[ind] = PRICE;
                            ind++;
                        }
                    }
                ProductName[count]     = "Добавить продукт";
                ProductName[count + 1] = "Вернуться к просмотру";
                cursor = 0;
                do
                {
                    Console.Clear();

                    for (int i = 0; i < ProductName.Length; i++)
                    {
                        if (cursor == i)
                        {
                            Console.Write(">> ");
                        }
                        else
                        {
                            Console.Write("   ");
                        }
                        if (i == ProductName.Length - 1 || i == ProductName.Length - 2)
                        {
                            Console.WriteLine(ProductName[i]);
                        }
                        else
                        {
                            Console.WriteLine(ProductName[i] + "   " + ProductPrice[i]);
                        }
                    }
                    key = Console.ReadKey();
                    if (key.Key == ConsoleKey.DownArrow)
                    {
                        cursor += 1;
                        if (cursor >= ProductName.Length)
                        {
                            cursor = 0;
                        }
                    }
                    if (key.Key == ConsoleKey.UpArrow)
                    {
                        cursor -= 1;
                        if (cursor < 0)
                        {
                            cursor = ProductName.Length - 1;
                        }
                    }
                    if (key.Key == ConsoleKey.Escape)
                    {
                        Environment.Exit(0);
                    }
                } while (key.Key != ConsoleKey.Enter);
                Console.Clear();
                if (cursor == ProductName.Length - 2)
                {
                    AddProduct();
                    goto ViewProductBuy;
                }
                else
                {
                    if (cursor == ProductName.Length - 1)
                    {
                        Products();
                        goto ViewProductBuy;
                    }
                    Buy(cursor);
                    goto ViewProductBuy;
                }
            }
Beispiel #2
0
            public void Buy(int cursor)
            {
                Money.MoneyAccount moneyAccount = new Money.MoneyAccount();
                using (FileStream Stream = new FileStream("B:\\TEMPFORMPT\\BuyProduct.pro", FileMode.Open, FileAccess.Read))
                    using (BinaryReader FP = new BinaryReader(Stream))
                    {
                        while (FP.PeekChar() != -1)
                        {
                            ID    = FP.ReadInt32();
                            NAME  = FP.ReadString();
                            PRICE = FP.ReadInt32();
                            if (ID == cursor + 1)
                            {
                                break;
                            }
                        }
                    }

                cursor = 0;

                string[] product = new string[2] {
                    "Закупить", "Вернуться"
                };

                do
                {
                    Console.Clear();
                    Console.WriteLine(ID + "  " + NAME + "\t" + PRICE);
                    for (int i = 0; i < product.Length; i++)
                    {
                        if (cursor == i)
                        {
                            Console.WriteLine(">> " + product[i]);
                        }
                        else
                        {
                            Console.WriteLine("   " + product[i]);
                        }
                    }
                    key = Console.ReadKey();
                    if (key.Key == ConsoleKey.DownArrow)
                    {
                        cursor += 1;
                        if (cursor >= product.Length)
                        {
                            cursor = 0;
                        }
                    }
                    if (key.Key == ConsoleKey.UpArrow)
                    {
                        cursor -= 1;
                        if (cursor < 0)
                        {
                            cursor = product.Length - 1;
                        }
                    }
                    if (key.Key == ConsoleKey.Escape)
                    {
                        Environment.Exit(0);
                    }
                } while (key.Key != ConsoleKey.Enter);
                Console.Clear();
                if (cursor == 1)
                {
                    ViewProductBuy();
                }
                using (FileStream stream = new FileStream("B:\\TEMPFORMPT\\MoneyAccount.pro", FileMode.Open, FileAccess.Read))
                    using (BinaryReader FP = new BinaryReader(stream))
                    {
                        moneyAccount.SumMoney = FP.ReadInt32();
                    }
rep:
                Console.Clear();
                int    lastKey = 1;
                string StCount = "1";
                int    Count   = 1;
                int    cost    = Count * PRICE;

                Console.WriteLine("Количество закупаемого продукта: " + StCount);
                Console.WriteLine("Общая стоимость: " + cost);
                Console.WriteLine("Денег на счету: " + moneyAccount.SumMoney);
                Console.WriteLine("Останется после покупки: " + (moneyAccount.SumMoney - cost));
                Console.WriteLine("Q - выйти\tENTER - продолжить");
                do
                {
                    key = Console.ReadKey(true);
                    Console.Clear();
                    Console.Write("Количество закупаемого продукта: ");

                    if (key.KeyChar >= '0' && key.KeyChar <= '9')
                    {
                        lastKey++;
                        if (StCount == "0")
                        {
                            StCount = StCount.Substring(0, 0);
                        }
                        StCount += key.KeyChar;
                    }
                    if (key.Key == ConsoleKey.Backspace)
                    {
                        if (lastKey > 0)
                        {
                            lastKey--;
                        }
                        if (lastKey != 0)
                        {
                            StCount = StCount.Substring(0, lastKey);
                        }
                        else
                        {
                            StCount = "0";
                        }
                    }
                    if (key.KeyChar == 'Q' || key.KeyChar == 'q')
                    {
                        goto exit;
                    }


                    Console.WriteLine(StCount);

                    Count = Convert.ToInt32(StCount);
                    cost  = Count * PRICE;

                    Console.WriteLine("Общая стоимость: " + cost);
                    Console.WriteLine("Денег на счету: " + moneyAccount.SumMoney);
                    Console.WriteLine("Останется после покупки: " + (moneyAccount.SumMoney - cost));
                    Console.WriteLine("Q - выйти\tENTER - продолжить");
                } while (key.Key != ConsoleKey.Enter);
                if ((moneyAccount.SumMoney - cost) > 0)
                {
                    Console.WriteLine("Товар закуплен!");
                    using (FileStream stream = new FileStream("B:\\TEMPFORMPT\\MoneyAccount.pro", FileMode.Create, FileAccess.Write))
                        using (BinaryWriter FP = new BinaryWriter(stream))
                        {
                            FP.Write(moneyAccount.SumMoney - cost);
                        }

                    int    id    = 0;
                    string name  = "";
                    int    coun  = 0;
                    int    price = 0;

                    using (FileStream stream = new FileStream("B:\\TEMPFORMPT\\Products.pro", FileMode.Open, FileAccess.Read))
                        using (BinaryReader FP = new BinaryReader(stream))
                        {
                            while (FP.PeekChar() != -1)
                            {
                                id    = FP.ReadInt32();
                                name  = FP.ReadString();
                                coun  = FP.ReadInt32();
                                price = FP.ReadInt32();
                            }
                        }
                    using (FileStream Stream = new FileStream("B:\\TEMPFORMPT\\Products.pro", FileMode.Append, FileAccess.Write))
                        using (BinaryWriter FP = new BinaryWriter(Stream))
                        {
                            FP.Write(id + 1);
                            FP.Write(NAME);
                            FP.Write(Count);
                            FP.Write(PRICE / 10 * 13);
                        }
                    Thread.Sleep(1000);
                    ViewProductBuy();
                }
                else
                {
                    Console.WriteLine("Покупка невозможна!\nНедостаточно средств для произведения операции.");
                    Thread.Sleep(1000);
                    goto rep;
                }

                exit :;
            }
Beispiel #3
0
            public void StartJob()
            {
                Money.MoneyAccount moneyAccount = new Money.MoneyAccount();
                Console.WriteLine("Касса открыта!");
                try
                {
                    using (FileStream stream = new FileStream("B:\\TEMPFORMPT\\Products.pro", FileMode.Open, FileAccess.Read))
                    {
                    }
                }
                catch
                {
                    for (int i = 10; i >= 0; i--)
                    {
                        Console.Clear();
                        Console.WriteLine("Нет закупленных товаров!\nОбратитесь к работнику склада");
                        Console.WriteLine("Программа закроется через " + i + " сек");
                        Thread.Sleep(1000);
                    }
                    Environment.Exit(0);
                }
conti:
                using (FileStream stream = new FileStream("B:\\TEMPFORMPT\\Products.pro", FileMode.Open, FileAccess.Read))
                    using (BinaryReader FP = new BinaryReader(stream))
                    {
                        while (FP.PeekChar() != -1)
                        {
                            ID           = FP.ReadInt32();
                            PRODUCT_NAME = FP.ReadString();
                            COUNT        = FP.ReadInt32();
                            PRICE        = FP.ReadInt32();
                        }
                    }
                int[]    ids    = new int[ID];
                string[] names  = new string[ID];
                int[]    counts = new int[ID];
                int[]    prices = new int[ID];
                int      z      = 0;

                using (FileStream stream = new FileStream("B:\\TEMPFORMPT\\Products.pro", FileMode.Open, FileAccess.Read))
                    using (BinaryReader FP = new BinaryReader(stream))
                    {
                        while (FP.PeekChar() != -1)
                        {
                            ids[z]    = FP.ReadInt32();
                            names[z]  = FP.ReadString();
                            counts[z] = FP.ReadInt32();
                            prices[z] = FP.ReadInt32();
                            z++;
                        }
                    }

                int cursor = 0;

                do
                {
                    Console.Clear();
                    Console.WriteLine($"   { "ID", 5} {"Наименование",10} {"кол-во",10} {"цена",8}");
                    for (int i = 0; i < ids.Length; i++)
                    {
                        if (cursor == i)
                        {
                            Console.Write(">> ");
                        }
                        else
                        {
                            Console.Write("   ");
                        }
                        Console.WriteLine($"{ids[i],5} {names[i], 10} {counts[i],10} {prices[i],10}");
                    }
                    key = Console.ReadKey();
                    if (key.Key == ConsoleKey.DownArrow)
                    {
                        cursor += 1;
                        if (cursor >= ids.Length)
                        {
                            cursor = 0;
                        }
                    }
                    if (key.Key == ConsoleKey.UpArrow)
                    {
                        cursor -= 1;
                        if (cursor < 0)
                        {
                            cursor = ids.Length - 1;
                        }
                    }
                    if (key.Key == ConsoleKey.Escape)
                    {
                        Environment.Exit(0);
                    }
                } while (key.Key != ConsoleKey.Enter);
                do
                {
                    Console.Clear();
                    Console.WriteLine("Продажа продукта: " + names[cursor]);
                    Console.WriteLine("Количество продукта имеется на складе: " + counts[cursor]);
                    Console.WriteLine("Цена продукта: " + prices[cursor]);
                    Console.WriteLine("Enter - продать\tBackspace - вернуться\tEscape - выход из программы");
                    key = Console.ReadKey();
                    switch (key.Key)
                    {
                    case ConsoleKey.Enter:
                        SaleProduct(ref ids[cursor], ref names[cursor], ref counts[cursor], ref prices[cursor]);
                        break;

                    case ConsoleKey.Backspace:
                        break;

                    case ConsoleKey.Escape:
                        Environment.Exit(0);
                        break;
                    }
                } while (key.Key != ConsoleKey.Enter);

                using (FileStream Stream = new FileStream("B:\\TEMPFORMPT\\Products.pro", FileMode.Create, FileAccess.Write))
                    using (BinaryWriter FP = new BinaryWriter(Stream))
                    {
                        for (int i = 0; i < ids.Length; i++)
                        {
                            if (counts[i] != 0)
                            {
                                FP.Write(ids[i]);
                                FP.Write(names[i]);
                                FP.Write(counts[i]);
                                FP.Write(prices[i]);
                            }
                        }
                    }
                string[] Menu = new string[2] {
                    "Продолжить работу с кассой", "Сдать кассу"
                };
                cursor = 0;
                do
                {
                    Console.Clear();
                    for (int i = 0; i < 2; i++)
                    {
                        if (cursor == i)
                        {
                            Console.WriteLine(">> " + Menu[i]);
                        }
                        else
                        {
                            Console.WriteLine("   " + Menu[i]);
                        }
                    }

                    key = Console.ReadKey();

                    if (key.Key == ConsoleKey.DownArrow)
                    {
                        cursor += 1;
                        if (cursor >= Menu.Length)
                        {
                            cursor = 0;
                        }
                    }
                    if (key.Key == ConsoleKey.UpArrow)
                    {
                        cursor -= 1;
                        if (cursor < 0)
                        {
                            cursor = Menu.Length - 1;
                        }
                    }
                    if (key.Key == ConsoleKey.Escape)
                    {
                        Environment.Exit(0);
                    }
                } while (key.Key != ConsoleKey.Enter);

                switch (cursor)
                {
                case 0:
                    goto conti;

                case 1:
                    moneyAccount.Enroll(MONEY);
                    Environment.Exit(0);
                    break;
                }

                goto conti;
            }