Пример #1
0
        private void setAsBackgroundImageButton_Click(object sender, RoutedEventArgs e)
        {
            ReadCountStage stage = this.stageListBox.SelectedItem as ReadCountStage;

            if (stage == null)
            {
                return;
            }

            ImageItem imageItem = this.backgroundImageListBox.SelectedItem as ImageItem;

            if (imageItem == null)
            {
                return;
            }

            stage.BackgroundImage = imageItem.File;
        }
Пример #2
0
        private void loadButton_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog openFileDlg = new OpenFileDialog();

            openFileDlg.Filter = "*.xml|*.xml";
            if (openFileDlg.ShowDialog().Value)
            {
                try
                {
                    string path           = System.IO.Path.GetDirectoryName(openFileDlg.FileName);
                    string backgroundPath = System.IO.Path.Combine(path, "Background");
                    string goodsPath      = System.IO.Path.Combine(path, "Goods");
                    string musicPath      = System.IO.Path.Combine(path, "Music");

                    ReadCountStageCollection stages = SerializerHelper <ReadCountStageCollection> .XmlDeserialize(openFileDlg.FileName);

                    foreach (ReadCountStage stage in stages.StageCollection)
                    {
                        this.stageCollection.Add(stage);

                        bool found = false;
                        stage.BackgroundImage = System.IO.Path.Combine(backgroundPath, stage.BackgroundImage);
                        foreach (ImageItem bk in this.backgroundImageCollection)
                        {
                            if (bk.File == stage.BackgroundImage)
                            {
                                found = true;
                                break;
                            }
                        }

                        if (!found)
                        {
                            ImageItem bkItem = new ImageItem();
                            bkItem.File  = stage.BackgroundImage;
                            bkItem.Title = System.IO.Path.GetFileNameWithoutExtension(bkItem.File);
                            this.backgroundImageCollection.Add(bkItem);
                        }

                        foreach (ReadCountItem item in stage.Items)
                        {
                            item.GoodsImage = System.IO.Path.Combine(goodsPath, item.GoodsImage);

                            found = false;
                            foreach (ImageItem temp in this.goodsImageCollection)
                            {
                                if (temp.File == item.GoodsImage)
                                {
                                    found = true;
                                    break;
                                }
                            }

                            if (found)
                            {
                                continue;
                            }

                            ImageItem imageItem = new ImageItem();
                            imageItem.File  = item.GoodsImage;
                            imageItem.Title = System.IO.Path.GetFileNameWithoutExtension(imageItem.File);
                            this.goodsImageCollection.Add(imageItem);
                        }
                    }

                    for (int i = 0; i < stages.BackgroundMusicList.Count; i++)
                    {
                        stages.BackgroundMusicList[i] = System.IO.Path.Combine(musicPath, stages.BackgroundMusicList[i]);
                        ImageItem musicItem = new ImageItem();
                        musicItem.File  = stages.BackgroundMusicList[i];
                        musicItem.Title = System.IO.Path.GetFileName(stages.BackgroundMusicList[i]);
                        this.musicCollection.Add(musicItem);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }