예제 #1
0
        private void buttonSerialize_Click(object sender, EventArgs e)
        {
            if (cbSerialize.SelectedIndex == 0)
            {
                BinaryFormatter formatter = new BinaryFormatter();
                using (FileStream fs = new FileStream("Issues.dat", FileMode.OpenOrCreate))
                {
                    formatter.Serialize(fs, Issues);
                }
                toEncode("Issues.dat");
            }
            else if (cbSerialize.SelectedIndex == 1)
            {
                XmlSerializer formatter = new XmlSerializer(typeof(List <Issue>),
                                                            new Type[] { typeof(Book), typeof(Journal), typeof(Mini_Issue), typeof(Brochure) });
                using (FileStream fs = new FileStream("Issues.xml", FileMode.OpenOrCreate))
                {
                    formatter.Serialize(fs, Issues);
                }
                toEncode("Issues.xml");
            }
            else if (cbSerialize.SelectedIndex == 2)
            {
                string infoText = String.Empty;
                for (int i = 0; i < Issues.Count; i++)
                {
                    if (Issues[i] is Book)
                    {
                        Book curr = Issues[i] as Book;
                        infoText += $"'Книга'|'{curr.Category.NatureOfInfo}'|'{curr.Category.Originality}'" +
                                    $"|'{curr.Category.TargetAudience}'|'{curr.Name}'|'{curr.Edition}'|" +
                                    $"'{curr.Periodicity}'|'{curr.Author}'|'{curr.Binding}'|'{curr.IllustratedBookend}'\r\n";
                    }
                    else if (Issues[i] is Journal)
                    {
                        Journal curr = Issues[i] as Journal;
                        infoText += $"'Журнал'|'{curr.Category.NatureOfInfo}'|'{curr.Category.Originality}'" +
                                    $"|'{curr.Category.TargetAudience}'|'{curr.Name}'|'{curr.Edition}'|" +
                                    $"'{curr.Periodicity}'|'{curr.SerialNumber}'|'{curr.Topic}'|'{curr.Redactors}'\r\n";
                    }
                    else if (Issues[i] is Mini_Issue)
                    {
                        Mini_Issue curr = Issues[i] as Mini_Issue;
                        infoText += $"'Мини-издание'|'{curr.Category.NatureOfInfo}'|'{curr.Category.Originality}'" +
                                    $"|'{curr.Category.TargetAudience}'|'{curr.Name}'|'{curr.Edition}'|" +
                                    $"'{curr.Periodicity}'|'{curr.Kind}'\r\n";
                    }
                    else if (Issues[i] is Brochure)
                    {
                        Brochure curr = Issues[i] as Brochure;
                        infoText += $"'Брошюра'|'{curr.Category.NatureOfInfo}'|'{curr.Category.Originality}'" +
                                    $"|'{curr.Category.TargetAudience}'|'{curr.Name}'|'{curr.Edition}'|" +
                                    $"'{curr.Periodicity}'|'{curr.IsCatalog}'\r\n";
                    }
                    else
                    {
                        Issue curr = Issues[i] as Issue;
                        infoText += $"'Не уточнено'|'{curr.Category.NatureOfInfo}'|'{curr.Category.Originality}'" +
                                    $"|'{curr.Category.TargetAudience}'|'{curr.Name}'|'{curr.Edition}'|" +
                                    $"'{curr.Periodicity}'\r\n";
                    }
                }

                using (FileStream fs = new FileStream("Issues.txt", FileMode.OpenOrCreate))
                {
                    byte[] array = Encoding.Default.GetBytes(infoText);
                    fs.Write(array, 0, array.Length);
                }
                toEncode("Issues.txt");
            }
        }
예제 #2
0
        private void dataGridView_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            listBoxInfo.Items.Clear();
            FillTextBoxes();
            try
            {
                listBoxInfo.Items.Add($"Название: { Issues[dataGridView.SelectedCells[0].RowIndex].Name}");
                listBoxInfo.Items.Add($"Тираж: { Issues[dataGridView.SelectedCells[0].RowIndex].Edition}");
                if (Issues[dataGridView.SelectedCells[0].RowIndex].Periodicity)
                {
                    listBoxInfo.Items.Add("Периодично");
                }
                else
                {
                    listBoxInfo.Items.Add("Не периодично");
                }
                listBoxInfo.Items.Add($"Категория: { Issues[dataGridView.SelectedCells[0].RowIndex].Category.NatureOfInfo}");
                listBoxInfo.Items.Add($"{ Issues[dataGridView.SelectedCells[0].RowIndex].Category.TargetAudience}");
                if (Issues[dataGridView.SelectedCells[0].RowIndex].Category.Originality)
                {
                    listBoxInfo.Items.Add("Оригинальное");
                }
                else
                {
                    listBoxInfo.Items.Add("Переведено");
                }


                if (Issues[dataGridView.SelectedCells[0].RowIndex] is Book)
                {
                    Book curr = Issues[dataGridView.SelectedCells[0].RowIndex] as Book;
                    listBoxInfo.Items.Add("Тип издания - книга");
                    listBoxInfo.Items.Add($"Автор: { curr.Author}");
                    listBoxInfo.Items.Add($"Переплёт: { curr.Binding}");
                    if (curr.IllustratedBookend)
                    {
                        listBoxInfo.Items.Add("Иллюстрированный форзац");
                    }
                    else
                    {
                        listBoxInfo.Items.Add("Форзац не иллюстрирован");
                    }
                }
                else if (Issues[dataGridView.SelectedCells[0].RowIndex] is Journal)
                {
                    Journal curr = Issues[dataGridView.SelectedCells[0].RowIndex] as Journal;
                    listBoxInfo.Items.Add("Тип издания - журнал");
                    listBoxInfo.Items.Add($"Тема: { curr.Topic}");
                    listBoxInfo.Items.Add($"Серийный номер: { curr.SerialNumber}");
                    listBoxInfo.Items.Add($"Редакторы: { curr.Redactors}");
                }
                else if (Issues[dataGridView.SelectedCells[0].RowIndex] is Mini_Issue)
                {
                    Mini_Issue curr = Issues[dataGridView.SelectedCells[0].RowIndex] as Mini_Issue;
                    listBoxInfo.Items.Add("Тип издания - мини-издание");
                    listBoxInfo.Items.Add($"Вид мини-издания: { curr.Kind}");
                }
                else if (Issues[dataGridView.SelectedCells[0].RowIndex] is Brochure)
                {
                    Brochure curr = Issues[dataGridView.SelectedCells[0].RowIndex] as Brochure;
                    listBoxInfo.Items.Add("Тип издания - брошюра");
                    if (curr.IsCatalog)
                    {
                        listBoxInfo.Items.Add("Является каталогом");
                    }
                    else
                    {
                        listBoxInfo.Items.Add("Не является каталогом");
                    }
                }
                else
                {
                    listBoxInfo.Items.Add("Издание");
                }
            }
            catch
            {
                MessageBox.Show("Выберите издание!");
            }
        }