Exemplo n.º 1
0
        public static void AddProd()
        {
            ProductsCollection productsCollection = new ProductsCollection();
            Storage            storage            = new Storage();

            while (true)
            {
                Console.Write("name ");
                string name = Console.ReadLine();
                if (name == "quit")
                {
                    break;
                }

                Console.Write("Section ");
                string       sectionStr = Console.ReadLine();
                MenuSections sections   = MenuSections.Гарниры;

                if (sectionStr == "1")
                {
                    sections = MenuSections.Первое;
                }
                else if (sectionStr == "2")
                {
                    sections = MenuSections.Гарниры;
                }
                else if (sectionStr == "3")
                {
                    sections = MenuSections.Салаты;
                }
                else if (sectionStr == "4")
                {
                    sections = MenuSections.Десерты;
                }
                else if (sectionStr == "5")
                {
                    sections = MenuSections.Напитки;
                }

                Console.Write("price ");
                double price = double.Parse(Console.ReadLine());

                productsCollection.Add(new Product(name, sections, price));
                Console.WriteLine(new String('-', 30));
            }

            foreach (Product product in productsCollection)
            {
                Console.Write(product.Name + " Quantity ");
                int quantity = int.Parse(Console.ReadLine());

                storage.Add(product.ProductId, quantity);
            }

            DataBaseController.AllProductsSave(productsCollection);
            DataBaseController.StorageBaseSave(storage);

            Console.ReadKey();
        }
Exemplo n.º 2
0
        //Для клиента этот метод не нужен, добавил его чтобы заполнить и сохранить колекцию
        public static void AllProductsSave(ProductsCollection allProducts)
        {
            FileStream      allProductsFileStream = new FileStream("allProducts.dat", FileMode.OpenOrCreate, FileAccess.Write);
            BinaryFormatter formatter             = new BinaryFormatter();

            formatter.Serialize(allProductsFileStream, allProducts);
            allProductsFileStream.Close();
        }
Exemplo n.º 3
0
        public static ProductsCollection AllProductsLoad()
        {
            ProductsCollection allProducts;

            if (File.Exists("allProducts.dat"))
            {
                FileStream      allProductsFileStream = new FileStream("allProducts.dat", FileMode.Open, FileAccess.ReadWrite);
                BinaryFormatter formatter             = new BinaryFormatter();
                allProducts = formatter.Deserialize(allProductsFileStream) as ProductsCollection;
                allProductsFileStream.Close();
            }
            else
            {
                allProducts = new ProductsCollection();

                FileStream      allProductsFileStream = new FileStream("allProducts.dat", FileMode.OpenOrCreate, FileAccess.Write);
                BinaryFormatter formatter             = new BinaryFormatter();
                formatter.Serialize(allProductsFileStream, allProducts);
                allProductsFileStream.Close();
            }

            return(allProducts);
        }
Exemplo n.º 4
0
 public Menu(ProductsCollection allProducts, Storage storage)
 {
     this.allProducts = allProducts;
     this.storage     = storage;
 }