コード例 #1
0
        private void NewFileCopy_Click(object sender, RoutedEventArgs e)
        {
            if (CheckItemsListContent() == false)
            {
                MessageBox.Show("List is empty");
            }
            else
            {
                string[] tempText = TXTtoObservableCollection.ReturnOnlyLines(filePath);
                string   tempName = CreateFileName.Method();

                string tempPath = "saves/" + tempName + ".txt";

                WorkPage workPage = new WorkPage(tempPath, mp, tempText);

                workPage.ItemsCollection = TXTtoObservableCollection.fillingMethod(tempText);

                mp._mainWindow.Main.Content = workPage;

                string textToFile = ObservableCollectionToTXT.Method(workPage.ItemsCollection);

                using (StreamWriter sw = File.CreateText(tempPath))
                {
                    sw.Write(textToFile);
                    sw.Close();
                }

                DataGridView.ItemsSource = ItemsCollection;

                MessageBox.Show("Successfully created new list named: " + tempName);
            }
        }
コード例 #2
0
        public WorkPage(string s, MainPage mainPage) // Existing page
        {
            InitializeComponent();
            DataContext = _vm;

            filePath = s;

            ItemsCollection = TXTtoObservableCollection.Method(filePath);

            DataGridView.ItemsSource = ItemsCollection;

            mp = mainPage;
        }
コード例 #3
0
        public WorkPage(string s, MainPage mainPage, string[] text) // Existing page with text
        {
            InitializeComponent();
            DataContext = _vm;

            filePath = s;

            StreamWriter sw = File.CreateText(filePath);

            sw.Close();

            ItemsCollection = TXTtoObservableCollection.fillingMethod(text);

            DataGridView.ItemsSource = ItemsCollection;

            mp = mainPage;
        }
コード例 #4
0
        public WorkPage(MainPage mainPage) // New page
        {
            InitializeComponent();
            DataContext = _vm;

            filePath = "saves/" + CreateFileName.Method() + ".txt";

            StreamWriter sw = File.CreateText(filePath);

            sw.Close();

            ItemsCollection = TXTtoObservableCollection.Method(filePath);

            DataGridView.ItemsSource = ItemsCollection;

            mp = mainPage;
        }
コード例 #5
0
        private void ChoiceListView_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            var item = sender as ListViewItem;

            if (item != null && item.IsSelected)
            {
                switch (userTypeOfSaveChoice)
                {
                case UserTypeOfSaveChoice.Copy:     //Copy
                {
                    ChoiceListView.Visibility = Visibility.Hidden;

                    string[] currentPartOfText = TXTtoObservableCollection.ReturnOnlyLines(filePath);
                    string   pickedPath        = item.DataContext.ToString();
                    string[] pickedPartOfText  = TXTtoObservableCollection.ReturnOnlyLines(pickedPath);
                    string[] resultArray       = ConnectTwoStringArrays.Method(currentPartOfText, pickedPartOfText);

                    using (StreamWriter sw = File.CreateText(pickedPath))
                    {
                        for (int i = 0; i < resultArray.Length - 1; i++)
                        {
                            sw.WriteLine(resultArray[i]);
                        }
                        sw.Close();
                    }

                    WorkPage workPage = new WorkPage(pickedPath, mp);

                    workPage.ItemsCollection = TXTtoObservableCollection.Method(pickedPath);

                    mp._mainWindow.Main.Content = workPage;

                    DataGridView.ItemsSource = ItemsCollection;

                    MessageBox.Show("Successfully created new list named: " + pickedPath);

                    break;
                }

                case UserTypeOfSaveChoice.Overwrite:     // Overwrite
                {
                    ChoiceListView.Visibility = Visibility.Hidden;
                    string[] currentPartOfText = TXTtoObservableCollection.ReturnOnlyLines(filePath);
                    string   pickedPath        = item.DataContext.ToString();

                    using (StreamWriter sw = File.CreateText(pickedPath))
                    {
                        for (int i = 0; i < currentPartOfText.Length; i++)
                        {
                            sw.WriteLine(currentPartOfText[i]);
                        }
                        sw.Close();
                    }

                    WorkPage workPage = new WorkPage(pickedPath, mp);

                    workPage.ItemsCollection = TXTtoObservableCollection.Method(pickedPath);

                    mp._mainWindow.Main.Content = workPage;

                    DataGridView.ItemsSource = ItemsCollection;

                    MessageBox.Show("Successfully created new list named: " + pickedPath);

                    break;
                }
                }
            }
        }