예제 #1
0
파일: Program.cs 프로젝트: Hukumishe/bruh
        static void Main(string[] args)
        {
            Random random = new Random();

            List <Free>       freeCopies       = new List <Free>();
            List <Commercial> commercialCopies = new List <Commercial>();
            List <Shareware>  sharewareCopies  = new List <Shareware>();

            for (int i = 0; i < random.Next(1, 100); i++)
            {
                Free       freeCopy       = new Free();
                Commercial commercialCopy = new Commercial();
                Shareware  sharewareCopy  = new Shareware();


                freeCopy.Name         = string.Format("Name_{0}", random.Next(1, 30));
                freeCopy.Manufacturer = string.Format("Manufacturer_{0}", random.Next(1, 30));

                commercialCopy.Name             = string.Format("Name_{0}", random.Next(1, 30));
                commercialCopy.Manufacturer     = string.Format("Manufacturer{0}", random.Next(1, 50));
                commercialCopy.InstallationDate = DateTime.Now.AddDays(-random.Next(10000));
                commercialCopy.UsagePeriod      = DateTime.Now.AddDays(random.Next(10000));
                commercialCopy.Cost             = random.Next(1, 10000);

                sharewareCopy.Name             = string.Format("Name_{0}", random.Next(1, 30));
                sharewareCopy.Manufacturer     = string.Format("Manufacturer{0}", random.Next(1, 50));
                sharewareCopy.InstallationDate = DateTime.Now.AddDays(-random.Next(10000));
                sharewareCopy.UsagePeriod      = DateTime.Now.AddDays(random.Next(10000));


                freeCopies.Add(freeCopy);
                commercialCopies.Add(commercialCopy);
                sharewareCopies.Add(sharewareCopy);
            }


            Console.WriteLine(" -- Результат поиска -- ");
            bool isFind = false;

            Console.WriteLine("Бесплатное ПО");
            foreach (Free freeCopy in freeCopies)
            {
                freeCopy.ShowInfo();
                isFind = true;
                Console.WriteLine();
            }


            Console.WriteLine();
            Console.WriteLine("Условно-бесплатное ПО");
            foreach (Shareware sharewareCopy in sharewareCopies)
            {
                if (sharewareCopy.CheckDate() == true)
                {
                    sharewareCopy.ShowInfo();
                    isFind = true;
                    Console.WriteLine();
                }
            }

            Console.WriteLine();
            Console.WriteLine("Платное ПО");
            foreach (Commercial commercialCopy in commercialCopies)
            {
                if (commercialCopy.CheckDate() == true)
                {
                    commercialCopy.ShowInfo();
                    isFind = true;
                    Console.WriteLine();
                }
            }

            Console.WriteLine();
            if (!isFind)
            {
                Console.WriteLine("----------------------------------");
                Console.WriteLine();
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Подобного ПО у нас нет!");
                Console.WriteLine();
                Console.WriteLine("----------------------------------");
            }
            Console.WriteLine();

            Console.ReadLine();
        }
예제 #2
0
        static void Main(string[] args)
        {
            PO[] soft = null;
            try
            {
                //string res;
                string[] Text = File.ReadAllLines("input.txt");
                int      n    = Int32.Parse(Text[0]);
                if (n > Text.Count <string>() - 1)
                {
                    throw new IOException();
                }
                soft = new PO[n];
                string[] temp;
                Regex    r_free       = new Regex("^free, ");
                Regex    r_shareware  = new Regex("^shareware, ");
                Regex    r_commercial = new Regex("^commercial, ");
                for (int i = 1; i <= n; i++)
                {
                    if (r_free.IsMatch(Text[i]))
                    {
                        temp        = Regex.Split(Text[i], ", ");
                        soft[i - 1] = new Free(temp[1], temp[2]);
                    }
                    else if (r_shareware.IsMatch(Text[i]))
                    {
                        temp        = Regex.Split(Text[i], ", ");
                        soft[i - 1] = new Shareware(temp[1], temp[2], temp[3], Byte.Parse(temp[4]), Int32.Parse(temp[5]));
                    }
                    else if (r_commercial.IsMatch(Text[i]))
                    {
                        temp        = Regex.Split(Text[i], ", ");
                        soft[i - 1] = new Commercial(temp[1], temp[2], temp[3], Byte.Parse(temp[4]), Int32.Parse(temp[5]), Int32.Parse(temp[6]));
                    }
                }
            }
            catch (FileNotFoundException)
            {
                Console.WriteLine("Файл input.txt не найден");
                Console.ReadKey();
                return;
            }
            catch (IOException)
            {
                Console.WriteLine("Неверный формат входного файла");
                Console.ReadKey();
                return;
            }


            XmlSerializer formatter = new XmlSerializer(typeof(PO[]));

            using (FileStream fs = new FileStream("data.xml", FileMode.OpenOrCreate))
            {
                formatter.Serialize(fs, soft);
            }


            Console.WriteLine("Доступное ПО:");
            Console.WriteLine("-------------------------------------------------");
            foreach (PO p in soft)
            {
                p.Info();
            }

            Console.WriteLine("ПО готовое к использованию: ");
            Console.WriteLine("-------------------------------------------------");
            foreach (PO p in soft)
            {
                if (p.ItIsAWorks())
                {
                    Console.WriteLine(p.ProgramName);
                }
            }

            Console.ReadLine();
        }