コード例 #1
0
        public MagazineEditForm(Magazine magazine, List <Author> authors)
        {
            InitializeComponent();

            this.magazine = magazine;
            this.authors  = authors;
            if (magazine.getArticles() != null)
            {
                articles = new BindingList <Article>(magazine.getArticles());
            }

            comboBox1.DataSource = Enum.GetValues(typeof(Period));

            textBox1.Text          = magazine.getName();
            comboBox1.SelectedItem = magazine.getPeriod();
            listBox1.DataSource    = articles;
        }
コード例 #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            Magazine         magazine     = new Magazine();
            MagazineEditForm magazineForm = new MagazineEditForm(magazine, authors);

            var res = magazineForm.ShowDialog();

            if (res == DialogResult.OK)
            {
                listBox1.Items.Add(magazine);
                magazines.Add(magazine);
            }
            else if (res != DialogResult.Abort)
            {
                MessageBox.Show("Nothing changed");
            }
        }
コード例 #3
0
        public Dictionary <string, int> GetTime(Magazine search)
        {
            var  time      = new Dictionary <string, int>();
            int  n         = edition.Count;
            long startTime = DateTime.UtcNow.Ticks;

            edition.Contains(search.EditionValues);
            time.Add("edition", (int)(DateTime.UtcNow.Ticks - startTime));

            startTime = DateTime.UtcNow.Ticks;
            strEdition.Contains(search.EditionValues.ToString());
            time.Add("strEdition", (int)(DateTime.UtcNow.Ticks - startTime));

            startTime = DateTime.UtcNow.Ticks;
            editionAndMagazine.ContainsKey(search.EditionValues);
            time.Add("E&M_Key", (int)(DateTime.UtcNow.Ticks - startTime));

            startTime = DateTime.UtcNow.Ticks;
            strMagazine.ContainsKey(search.EditionValues.ToString());
            time.Add("str&M_Key", (int)(DateTime.UtcNow.Ticks - startTime));

            startTime = DateTime.UtcNow.Ticks;
            editionAndMagazine.ContainsValue(search);
            time.Add("E&M_Value", (int)(DateTime.UtcNow.Ticks - startTime));

            startTime = DateTime.UtcNow.Ticks;
            strMagazine.ContainsValue(search);
            time.Add("str&M_Value", (int)(DateTime.UtcNow.Ticks - startTime));
            if (strMagazine.ContainsKey(search.EditionValues.ToString()))
            {
                Console.WriteLine("Exist");
            }
            else
            {
                Console.WriteLine("Such Magazine not found");
            }
            return(time);
        }
コード例 #4
0
        static void Main(string[] args)
        {
            //Завдання 1
            MagazineCollection m         = new MagazineCollection();
            Magazine           magazine  = new Magazine("name", new DateTime(), 100, Frequency.Yearly);
            Magazine           magazine2 = new Magazine("Archy", new DateTime(2013, 01, 01), 10000, Frequency.Weekly);

            magazine.AddArticles(new Article(new Person(), "smth", 10));
            magazine2.AddArticles(new Article(new Person(), "Shoo", 5));
            m.AddDefaults();
            m.AddMagazines(magazine);
            m.AddMagazines(magazine2);
            Console.WriteLine(m);
            //Завдання 2
            Console.WriteLine("SortByName");
            m.SortByName();
            Console.WriteLine("SortByDate\n{0}", m);
            m.SortByDate();
            Console.WriteLine("SortByCount\n{0}", m);
            m.SortByCount();
            Console.WriteLine(m);
            //Завдання 3
            Console.WriteLine("Max Avarage Rating is " + m.GetMaxAvgRating);
            Console.WriteLine("Monthly magazines\n");
            foreach (Magazine a in m.MonthlyMagazines)
            {
                Console.WriteLine(a);
            }
            Console.WriteLine("Enter min rating");
            int k = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine("Rating >= {0} :\n", k);
            try
            {
                foreach (Magazine rat in m.RatingGroup(k))
                {
                    Console.WriteLine(rat);
                }
            }
            catch { Console.WriteLine("No such magazines"); }
            //Завдання 4
            int n = 0;

            while (n < 1)
            {
                Console.WriteLine("Enter positive integer ");
                try
                {
                    n = Convert.ToInt32(Console.ReadLine());
                }
                catch
                {
                    Console.WriteLine("Incorrect value");
                }
            }
            TestCollections          t = new TestCollections(n);
            Dictionary <string, int> time;

            Console.WriteLine("0-first,1-average,2-last,default-random");
            int selection = Convert.ToInt32(Console.ReadLine());

            switch (selection)
            {
            case 0:
                time = t.GetTime(t.editionAndMagazine[t.edition[0]]);
                break;

            case 1:
                time = t.GetTime(t.editionAndMagazine[t.edition[n / 2]]);
                break;

            case 2:
                time = t.GetTime(t.editionAndMagazine[t.edition[n - 1]]);
                break;

            default:
                time = t.GetTime(new Magazine("didnt EXIST", new DateTime(), 100, Frequency.Yearly));
                break;
            }
            foreach (KeyValuePair <string, int> kvp in time)
            {
                Console.WriteLine("{0},\tTime is {1}",
                                  kvp.Key, kvp.Value);
            }
            Console.ReadKey();
        }