Esempio n. 1
0
        static Supermarket GetFiles()
        {
            if (Directory.Exists(supermarketXmlPath))
            {
                //DirectoryInfo dirInfo= new DirectoryInfo(supermarketXmlPath);
                string[] filesFullPath = Directory.GetFiles(supermarketXmlPath);

                Supermarket supermarket = new Supermarket();
                if (filesFullPath.Length > 0)
                {
                    string fileName;
                    foreach (string st in filesFullPath)
                    {
                        fileName = Path.GetFileName(st);

                        if (fileName.Contains("supermarket", StringComparison.OrdinalIgnoreCase))
                        {
                            supermarket.Deserialize(supermarketXmlPath + "\\" + fileName);
                            return(supermarket);
                        }
                    }
                    return(null);
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                Directory.CreateDirectory(supermarketXmlPath);
                return(null);
            }
        }
Esempio n. 2
0
        public void Deserialize(string path = defaultPath + "supermarket.xml")
        {
            //XmlSerializer ser = new XmlSerializer(typeof(SectionGoods[]));
            XmlSerializer ser = new XmlSerializer(typeof(Supermarket));

            using (FileStream st = new FileStream(path, FileMode.OpenOrCreate))
            {
                //SectionGoods[] super = (SectionGoods[])ser.Deserialize(st);
                Supermarket sp = (Supermarket)ser.Deserialize(st);

                this.Name          = sp.Name;
                this.SectionAmount = sp.SectionAmount;
                this.front         = sp.front;
                this.rear          = sp.rear;
                Array.Resize <SectionGoods>(ref this.sectionsQueue, sp.QueueSize);
                for (int i = 0; i < sp.sectionsQueue.Length; i++)
                {
                    this.sectionsQueue[i] = sp.sectionsQueue[i];
                }
                //if (super.Length > 0)
                //{
                //
                //    this.Name = "NAME";
                //
                //}
                //if(SectionAmount > 0)
                //{
                //    front = front + SectionAmount;
                //    rear = front + SectionAmount;
                //}
            }
        }
Esempio n. 3
0
 //  ДЕСЕРИАЛИЗАЦИЯ СУПЕРМАРКЕТА  //
 static void DeserializeSupermarketMenu()
 {
     Console.WriteLine("Введите полный путь к файлу: ");
     mainMarket = new Supermarket();
     if (Console.ReadKey(intercept: true).Key != ConsoleKey.Escape)
     {
         mainMarket.Deserialize(Console.ReadLine());
     }
     else
     {
         Console.MoveBufferArea(0, Console.CursorTop - 2, Console.BufferWidth, 1, Console.BufferWidth, Console.CursorTop - 2, ' ', Console.ForegroundColor, Console.BackgroundColor);
         Console.MoveBufferArea(0, Console.CursorTop - 1, Console.BufferWidth, 1, Console.BufferWidth, Console.CursorTop - 1, ' ', Console.ForegroundColor, Console.BackgroundColor);
         currentMenu.level--;
         currentMenu.index = 0;
     }
 }
Esempio n. 4
0
        //  СОЗДАНИЕ НОВОГО СУПЕРМАРКЕТА  //
        static void CreateSupermarketMenu()
        {
            Console.WriteLine("Введите название супермаркета и количество отделов\nНазвание: ");
            string name = Console.ReadLine();
            int    amount;

            Console.WriteLine("Количество отделов");
            while (!int.TryParse(Console.ReadLine(), out amount))
            {
                Console.MoveBufferArea(0, Console.CursorTop - 2, Console.BufferWidth, 1, Console.BufferWidth, Console.CursorTop - 2, ' ', Console.ForegroundColor, Console.BackgroundColor);
                Console.MoveBufferArea(0, Console.CursorTop - 1, Console.BufferWidth, 1, Console.BufferWidth, Console.CursorTop - 1, ' ', Console.ForegroundColor, Console.BackgroundColor);
                Console.SetCursorPosition(Console.CursorLeft, Console.CursorTop - 2);
                Console.WriteLine("Неверное значение. Введите количество отделов.");
            }
            mainMarket      = new Supermarket(amount);
            mainMarket.Name = name;
        }
Esempio n. 5
0
        static void Main(string[] args)
        {
            MenuInit();
            Supermarket sp = new Supermarket();

            sp.AddNewSection("бытовая химия");
            sp.Name = "пятерочка";
            sp.AddNewSection("бытовая химия");
            sp.AddNewSection("бытовая");
            sp.Serialize();

            ShowMenu(0, 0);
            while (true)
            {
                ReadUserKey();
            }


            //Supermarket sptry = GetFiles();
            //Console.WriteLine(sptry.ToString());



            //Goods serGood = new Goods("chocolate", 42.3);
            //Console.WriteLine(serGood.ToString());
            //Stream goodStream = File.Open("Good.dat", FileMode.Create);
            //BinaryFormatter binary = new BinaryFormatter();
            //binary.Serialize(goodStream, serGood);
            //goodStream.Close();
            //serGood = null;

            //goodStream = File.Open("Good.dat", FileMode.Open);
            //binary = new BinaryFormatter();
            //serGood = (Goods)binary.Deserialize(goodStream);
            //goodStream.Close();
            //Console.WriteLine("Результат десериализации: " + serGood.ToString());


            //Console.WriteLine("");

            ////Console.WriteLine("Супермаркет \"{}\"", );
            ////cout << "Добавить ";

            //Supermarket sp = new Supermarket(6);

            //sp.AddNewSection("бытовая химия");
            //sp.Name = "пятерочка";
            //sp.AddNewSection("бытовая химия");
            //sp.AddNewSection("бытовая");


            //sp.Deserialize(sp.Serialize());
            //Console.WriteLine(sp.ToString());
            //SectionGoods section_1 = sp.GetSection("Бытовая химия");

            //if (section_1 != null)
            //{
            //    section_1.GetTotalSectionPrice();
            //    section_1.AddGoodAtPosition(12);
            //}

            //section_1.GetElementByPosition(section_1.AddGoodAtPosition(4)).Name = "Thanks";
            //section_1.AddGoodAtPosition(4);

            //section_1.GetElementByPosition(section_1.AddGoodAtPosition(4)).Name = "Хамелеон";
            //section_1.GetElementByPosition(section_1.AddGoodAtPosition(5)).Name = "Усургут";
            //Console.WriteLine(section_1.ToString());
            //section_1.DeleteGood("Thanks");
            ////section_1.ShowAllGoods();
            //section_1.GetElementByPosition(section_1.AddGoodAtPosition(1)).Name = "WOW";
            //Console.WriteLine(section_1.ToString());

            //section_1.Serialize();
            //section_1.Deserialize();
            //section_1.ToString();

            //sp.Serialize();
            //sp.Deserialize();
            //Console.WriteLine(sp.ToString());

            Console.WriteLine("Hello World!");
        }