Ejemplo n.º 1
0
        public VideoGameCatalogView(VideoGameCatalog videoGameCatalog, string fileDirectory)
        {
            InitializeComponent();

            directoryOfFile = fileDirectory;

            foreach (VideoGame game in videoGameCatalog.getVideoGameList())
            {
                if ((tabList.Exists(x => x.Name == game.Platform)) == false)
                {
                    // create new tab item
                    TabItem tab = new TabItem();
                    tab.Header = string.Format("{0}", game.Platform);
                    tab.Name   = string.Format("{0}", game.Platform);

                    // add controls to tab item
                    ListBox listBox = new ListBox();
                    listBox.Name = "ListBox";

                    foreach (VideoGame videoGame in videoGameCatalog.getVideoGameList())
                    {
                        if ((string)tab.Header == videoGame.Platform)
                        {
                            listBox.Items.Add(videoGame.Name + "\t\t\t\t\t\t\t\t\t\t\t" + videoGame.Form);
                        }
                    }

                    tab.Content = listBox;

                    // add new tab to TabList
                    this.tabList.Add(tab);
                }
            }

            foreach (TabItem tabItem in this.tabList)
            {
                tabControlPanel.Items.Add(tabItem);
            }

            /*
             * How to acess information within the list box:
             *  var x = tabList[0].Content as ListBox;
             *  var y = x.Items;
             *
             *   foreach (var item in y)
             *   {
             *  // TODO
             *   }
             *
             *
             */
        }
        private void LoadExcelFileOnClick(object sender, RoutedEventArgs e)
        {
            string fileDirectory = null;

            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.InitialDirectory = "c:\\";
            openFileDialog1.Filter           = "xlsx files (*.xlsx)|*.xlsx|All files (*.*)|*.*";
            openFileDialog1.FilterIndex      = 2;
            openFileDialog1.RestoreDirectory = true;

            if (openFileDialog1.ShowDialog() == true)
            {
                fileDirectory = openFileDialog1.FileName;
                VideoGameCatalog videoGameCatalog = ReadFromExcel.getVideoGames(fileDirectory);

                VideoGameCatalogView videoGameCatalogView = new VideoGameCatalogView(videoGameCatalog, fileDirectory);

                App.Current.MainWindow = videoGameCatalogView;
                this.Close();
                videoGameCatalogView.Show();
            }
        }