Esempio n. 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);
            }
        }
Esempio n. 2
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;
                }
                }
            }
        }