Beispiel #1
0
        } // save in file

        private void button_outInfo_File_Click(object sender, EventArgs e)
        {
            try
            {
                var           fileBooks = SerializateInfo.Deserialize <CollectionBooks>("books.xml");
                StringBuilder ountline  = new StringBuilder();
                foreach (var item in fileBooks.books)
                {
                    ountline.AppendLine($"Название: {item.Name}");
                    ountline.AppendLine($"Формат: {item.Format}");
                    ountline.AppendLine($"Размер файла: {item.SizeFile}Кб");
                    ountline.AppendLine($"УДК: {item.UDK}");
                    ountline.AppendLine($"Количество страниц: {item.CountPages}");
                    ountline.AppendLine($"Издательство: {item.Publishing}");
                    ountline.AppendLine($"Дата загрузки: {item.ReleaseDate}");
                    StringBuilder authors = new StringBuilder();
                    foreach (var author in item.Authors.authors)
                    {
                        authors.Append($"{author.SN}({author.ID}); ");
                    }
                    ountline.AppendLine($"Список авторов: {authors}");
                    ountline.AppendLine($"-----------------------------------------------------------------------------------------");
                }
                txtBox_fromFile.Text = ountline.ToString();
                toolStripStatusLabel_Last_do.Text = "Последние действие: Вывод с файла";
            }
            catch (Exception x)
            {
                MessageBox.Show($"Ошибка: {x.Message}");
            }
        } // out int from file
Beispiel #2
0
 private void ToolStripMenuItem_Save_Search_Sort_Click(object sender, EventArgs e)
 {
     if (form_search.result_Search.Count > 0 || form_sort.result_Sort.Count > 0)
     {
         try
         {
             SerializateInfo.Serialize <List <Book> >(form_search.result_Search, "result_Search.xml");
             SerializateInfo.Serialize <List <Book> >(form_sort.result_Sort, "result_Sort.xml");
             MessageBox.Show("Успешно сохранено!");
             toolStripStatusLabel_Last_do.Text = "Последние действие: Сохранения поисков";
         }
         catch (Exception x)
         {
             MessageBox.Show($"Ошибка: {x.Message}");
         }
     }
 }
Beispiel #3
0
        } // refrashing comBox's

        private void button_Dessereliz_Click(object sender, EventArgs e)
        {
            #region TryDesserialize

            try
            {
                infoFromFile = SerializateInfo.Deserialize <CollectionBooks>("books.xml");
                MessageBox.Show("Успешно");
                succesDesserializ = true;
            }
            catch (Exception x)
            {
                MessageBox.Show($"Ошибка: {x.Message}");
                exepDesserializ = true;
            }

            #endregion
            toolStripStatusLabel_Last_do.Text = "Последние действие: Дисериализация";
        } // Deserialize file for refrash
Beispiel #4
0
 private void timer_Tick(object sender, EventArgs e)
 {
     countLabel.Text = "Количетсов обьектов в файле = " + SerializateInfo.Deserialize <CollectionBooks>("books.xml").books.Count.ToString();
     dateLabel.Text  = DateTime.Now.ToLongDateString();
     timeLabel.Text  = DateTime.Now.ToLongTimeString();
 }
Beispiel #5
0
        }// Function - add author in collection

        private void button_Save_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(txtBox_Name_book.Text) && !string.IsNullOrEmpty(comBox_format_file.Text) &&
                !string.IsNullOrEmpty(txtBox_UDK.Text) && !string.IsNullOrEmpty(txtBox_Count_pages.Text) &&
                !string.IsNullOrEmpty(comBox_publishing.Text) &&
                collectionAuthors.authors.Count > 0 && trBar_size_file.Value > 0) // проверка на заполнение полей
            {
                #region ChecksDesserialize

                if (succesDesserializ) // добавляем в дессир. коллекцию ещё один обьект
                {
                    bool checkUDK = false;
                    foreach (var item in infoFromFile.books)
                    {
                        if (item.UDK.ToString() == txtBox_UDK.Text.ToString())
                        {
                            checkUDK = true;
                        }
                    }
                    if (!checkUDK) // проверка на UDK
                    {
                        #region CreateNewBook

                        book = new Book(txtBox_Name_book.Text, txtBox_UDK.Text, comBox_publishing.Text,
                                        trBar_size_file.Value, int.Parse(txtBox_Count_pages.Text),
                                        comBox_format_file.Text, dateTimePicker1.Text, collectionAuthors);
                        var copy = book.Clone();
                        #endregion
                        infoFromFile.books.Add(book);                                           // добавляем книгу в коллекцию
                        SerializateInfo.Serialize <CollectionBooks>(infoFromFile, "books.xml"); // сериализуем коллекцию
                        collectionAuthors = new ContenerAuthors();                              // clearing
                        MessageBox.Show("Сохранено!");
                        toolStripStatusLabel_Last_do.Text = "Последние действие: Сохранение в файл";
                    }
                    else
                    {
                        MessageBox.Show("Такой UDK уже используется");
                    }
                }// Успешно дессириализовано
                else if (!succesDesserializ && !exepDesserializ)
                {
                    MessageBox.Show("Проведите Дессериализацию");
                }// Дессириализация не была проведена
                else if (!succesDesserializ && exepDesserializ) //
                {
                    DialogResult dialogResult = MessageBox.Show("Будет создана новая коллекция в сериализуемом файле!\n" +
                                                                " Желаете продолжить?", "Exception Dessialiaze", MessageBoxButtons.YesNo);
                    if (dialogResult == DialogResult.Yes)
                    {
                        #region CreateNewBook

                        book = new Book(txtBox_Name_book.Text, txtBox_UDK.Text, comBox_publishing.Text,
                                        trBar_size_file.Value, int.Parse(txtBox_Count_pages.Text),
                                        comBox_format_file.Text, dateTimePicker1.Text, collectionAuthors);

                        #endregion
                        collectionBooks.books.Add(book);                                           // добавляем книгу в коллекцию
                        SerializateInfo.Serialize <CollectionBooks>(collectionBooks, "books.xml"); // сериализуем коллекцию
                        MessageBox.Show("Сохранено!");
                        toolStripStatusLabel_Last_do.Text = "Последние действие: Сохранение в файл";
                    }
                    if (dialogResult == DialogResult.No)
                    {
                        MessageBox.Show("Закрыто!");
                    }
                }// Ошибка дессириализации

                #endregion
            }
            else
            {
                MessageBox.Show("Заполните все поля");
            }
        } // save in file
 private void button_Search_Click(object sender, EventArgs e)
 {
     if (combBox_Sort_by.Text == string.Empty)
     {
         MessageBox.Show("Выбирете сбособ сортировки");
     }
     else if (combBox_Sort_by.Text == "Названию")
     {
         try
         {
             result_Sort = new List <Book>();
             StringBuilder ountline     = new StringBuilder();
             var           infoFromFile = SerializateInfo.Deserialize <CollectionBooks>("books.xml");
             var           result_sort  = infoFromFile.books.OrderBy(i => i.Name);
             foreach (var item in result_sort)
             {
                 ountline.AppendLine($"Название: {item.Name}");
                 ountline.AppendLine($"Формат: {item.Format}");
                 ountline.AppendLine($"Размер файла: {item.SizeFile}Кб");
                 ountline.AppendLine($"УДК: {item.UDK}");
                 ountline.AppendLine($"Количество страниц: {item.CountPages}");
                 ountline.AppendLine($"Издательство: {item.Publishing}");
                 ountline.AppendLine($"Дата загрузки: {item.ReleaseDate}");
                 StringBuilder authors = new StringBuilder();
                 foreach (var author in item.Authors.authors)
                 {
                     authors.Append($"{author.SN}({author.ID}); ");
                 }
                 ountline.AppendLine($"Список авторов: {authors}");
                 ountline.AppendLine($"----------------------------------------------------------------");
                 result_Sort.Add(item);
             }
             txtBox_Result.Text = ountline.ToString();
         }
         catch (Exception x)
         {
             MessageBox.Show($"Ошибка: {x.Message}");
         }
     }
     else if (combBox_Sort_by.Text == "Дате загрузки")
     {
         try
         {
             result_Sort = new List <Book>();
             StringBuilder ountline     = new StringBuilder();
             var           infoFromFile = SerializateInfo.Deserialize <CollectionBooks>("books.xml");
             var           result_sort  = infoFromFile.books.OrderBy(i => i.ReleaseDate.Substring(i.ReleaseDate.Length - 5));
             foreach (var item in result_sort)
             {
                 ountline.AppendLine($"Название: {item.Name}");
                 ountline.AppendLine($"Формат: {item.Format}");
                 ountline.AppendLine($"Размер файла: {item.SizeFile}Кб");
                 ountline.AppendLine($"УДК: {item.UDK}");
                 ountline.AppendLine($"Количество страниц: {item.CountPages}");
                 ountline.AppendLine($"Издательство: {item.Publishing}");
                 ountline.AppendLine($"Дата загрузки: {item.ReleaseDate}");
                 StringBuilder authors = new StringBuilder();
                 foreach (var author in item.Authors.authors)
                 {
                     authors.Append($"{author.SN}({author.ID}); ");
                 }
                 ountline.AppendLine($"Список авторов: {authors}");
                 ountline.AppendLine($"----------------------------------------------------------------");
                 result_Sort.Add(item);
             }
             txtBox_Result.Text = ountline.ToString();
         }
         catch (Exception x)
         {
             MessageBox.Show($"Ошибка: {x.Message}");
         }
     }
     else
     {
         MessageBox.Show("Ошибка");
     }
 }
        private void button_Search_Click(object sender, EventArgs e)
        {
            CollectionBooks books;

            try
            {
                books = SerializateInfo.Deserialize <CollectionBooks>("books.xml");
                if (combBox_Search_by.Text == string.Empty)
                {
                    MessageBox.Show("Выберите способ поиска и введите данные");
                }
                else if (combBox_Search_by.Text == "Издательству") // Search by Publiching
                {
                    if (txtBox_Publishing.Text == string.Empty)
                    {
                        MessageBox.Show("Заполните данные");
                        txtBox_Result.Text = string.Empty;
                    }
                    else
                    {
                        StringBuilder ountline = new StringBuilder();
                        foreach (var item in books.books)
                        {
                            if (txtBox_Publishing.Text.ToLower() == item.Publishing.ToString().ToLower() ||
                                item.Publishing.ToString().ToLower().StartsWith(txtBox_Publishing.Text.ToLower()))
                            {
                                result_Search.Add(item);
                                ountline.AppendLine($"Название: {item.Name}");
                                ountline.AppendLine($"Формат: {item.Format}");
                                ountline.AppendLine($"Размер файла: {item.SizeFile}Кб");
                                ountline.AppendLine($"УДК: {item.UDK}");
                                ountline.AppendLine($"Количество страниц: {item.CountPages}");
                                ountline.AppendLine($"Издательство: {item.Publishing}");
                                ountline.AppendLine($"Дата загрузки: {item.ReleaseDate}");
                                StringBuilder authors = new StringBuilder();
                                foreach (var author in item.Authors.authors)
                                {
                                    authors.Append($"{author.SN}({author.ID}); ");
                                }
                                ountline.AppendLine($"Список авторов: {authors}");
                                ountline.AppendLine($"----------------------------------------------------------------");
                                txtBox_Result.Text = ountline.ToString();
                            } // == or StartsWith
                        }     //checking conditions
                        if (txtBox_Result.Text == string.Empty)
                        {
                            MessageBox.Show("Не найдено");
                        }
                    }
                }
                else if (combBox_Search_by.Text == "Году издания") // Search by Relize Date
                {
                    if (dateTimePicker_realeze.Text == string.Empty)
                    {
                        MessageBox.Show("Заполните данные");
                        txtBox_Result.Text = string.Empty;
                    }
                    else
                    {
                        foreach (var item in books.books)
                        {
                            StringBuilder ountline = new StringBuilder();
                            if (dateTimePicker_realeze.Text.ToLower() == item.ReleaseDate.ToString().ToLower())
                            {
                                result_Search.Add(item);
                                ountline.AppendLine($"Название: {item.Name}");
                                ountline.AppendLine($"Формат: {item.Format}");
                                ountline.AppendLine($"Размер файла: {item.SizeFile}Кб");
                                ountline.AppendLine($"УДК: {item.UDK}");
                                ountline.AppendLine($"Количество страниц: {item.CountPages}");
                                ountline.AppendLine($"Издательство: {item.Publishing}");
                                ountline.AppendLine($"Дата загрузки: {item.ReleaseDate}");
                                StringBuilder authors = new StringBuilder();
                                foreach (var author in item.Authors.authors)
                                {
                                    authors.Append($"{author.SN}({author.ID}); ");
                                }
                                ountline.AppendLine($"Список авторов: {authors}");
                                ountline.AppendLine($"----------------------------------------------------------------");
                                txtBox_Result.Text = ountline.ToString();
                            }
                        }//checking conditions
                        if (txtBox_Result.Text == string.Empty)
                        {
                            MessageBox.Show("Не найдено");
                        }
                    }
                }
                else if (combBox_Search_by.Text == "Диапазону страниц") // Search by Range Pages
                {
                    if (txtBox_rangeFrom.Text == string.Empty || txtBox_rangeTo.Text == string.Empty)
                    {
                        MessageBox.Show("Заполните данные");
                        txtBox_Result.Text = string.Empty;
                    }
                    else
                    {
                        StringBuilder ountline = new StringBuilder();
                        foreach (var item in books.books)
                        {
                            if (item.CountPages >= int.Parse(txtBox_rangeFrom.Text) && item.CountPages <= int.Parse(txtBox_rangeTo.Text))
                            {
                                result_Search.Add(item);
                                ountline.AppendLine($"Название: {item.Name}");
                                ountline.AppendLine($"Формат: {item.Format}");
                                ountline.AppendLine($"Размер файла: {item.SizeFile}Кб");
                                ountline.AppendLine($"УДК: {item.UDK}");
                                ountline.AppendLine($"Количество страниц: {item.CountPages}");
                                ountline.AppendLine($"Издательство: {item.Publishing}");
                                ountline.AppendLine($"Дата загрузки: {item.ReleaseDate}");
                                StringBuilder authors = new StringBuilder();
                                foreach (var author in item.Authors.authors)
                                {
                                    authors.Append($"{author.SN}({author.ID}); ");
                                }
                                ountline.AppendLine($"Список авторов: {authors}");
                                ountline.AppendLine($"----------------------------------------------------------------");
                                txtBox_Result.Text = ountline.ToString();
                            }
                        }//checking conditions
                        if (txtBox_Result.Text == string.Empty)
                        {
                            MessageBox.Show("Не найдено");
                        }
                    }
                }
            }
            catch (Exception x)
            {
                MessageBox.Show($"Ошибка: {x.Message}");
            }
        }