コード例 #1
0
ファイル: BookLoader.cs プロジェクト: KompeNnet/Lab_3.3
        }    // selectedItems (data & type), serialize json { type: "Type", book: Object }, write in file

        private void BtnDeserialize_Click(object sender, RoutedEventArgs e)
        {
            GroupBox gr           = GetMainGroupBox(sender);
            Grid     g            = (Grid)gr.Parent;
            ListView bookListForm = g.Children.OfType <ListView>().First(x => x.Name == "BookListForm");

            OpenFileDialog dlg = new OpenFileDialog()
            {
                Filter = "JSON files | *.json"
            };

            if (dlg.ShowDialog() == true)
            {
                StreamReader reader = new StreamReader(dlg.OpenFile());
                string       item;
                while ((item = reader.ReadLine()) != null)
                {
                    // indexof(':')?
                    string[] words = item.Split(':');
                    item = item.Substring(words[0].Length + 1, item.Length - words[0].Length - 1);
                    var  loader = LoaderManager.GetLoader(words[0]);
                    Book book   = loader.Deserialize(item);
                    bookListForm.Items.Add(new ItemInList {
                        Type = words[0], Name = book.Name, Author = book.Author, Data = book
                    });
                }
                reader.Dispose();
                reader.Close();
            }
        }
コード例 #2
0
        private void BookListForm_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (BookListForm.SelectedIndex != -1)
            {
                MainGrid.Children.RemoveAt(1);

                ItemInList elem = (ItemInList)BookListForm.Items.GetItemAt(BookListForm.SelectedIndex);

                var loader = LoaderManager.GetLoader(elem.Type);

                GroupBox newGroupBox = FormCreator.CreateGroupBox("MainGroup", "Book", new Thickness(0, 0, 0, 0), 887, 384);
                Grid     g           = loader.Load(elem.Data);
                g.Children.Add(loader.CreateButtonsGroup(elem.Type));
                newGroupBox.Content = g;

                MainGrid.Children.Add(newGroupBox);
            }
        }
コード例 #3
0
ファイル: BookLoader.cs プロジェクト: KompeNnet/Lab_3.3
        protected void SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (((ComboBox)sender).IsDropDownOpen)
            {
                string selectedText = ((ComboBox)sender).SelectedValue.ToString();

                GroupBox oldGroupBox = GetMainGroupBox(sender);           // MainGroupBox
                Grid     p           = (Grid)oldGroupBox.Parent;          // MainGrid
                p.Children.Remove(oldGroupBox);                           // delete old MainGroupBox

                var b = LoaderManager.GetLoader(selectedText);            // select Loader

                Grid newGrid = b.Load(b.BaseCreate(oldGroupBox));         // create new Grid
                newGrid.Children.Add(b.CreateButtonsGroup(selectedText)); // add buttons on it

                GroupBox newGroupBox = FormCreator.CreateGroupBox("MainGroup", "Book", new Thickness(0, 0, 0, 0), 887, 384);
                newGroupBox.Content = newGrid;                      // wrap Grid into new MainGroupBox

                p.Children.Add(newGroupBox);                        // add to MainGrid
            }
        }