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); } }
private void Exit_Click(object sender, RoutedEventArgs e) { using (StreamWriter sw = File.CreateText(filePath)) { sw.Write(ObservableCollectionToTXT.Method(ItemsCollection)); sw.Close(); } MainPage mainPage = new MainPage(mp._mainWindow); mp._mainWindow.Main.Content = mainPage; }
private void DownButton_Click(object sender, RoutedEventArgs e) { item selectedItem = (item)DataGridView.SelectedItem; if (selectedItem != null) { ItemsCollection = ChangeOrder.Method(ItemsCollection, selectedItem, Direction.DOWN); } using (StreamWriter sw = File.CreateText(filePath)) { sw.Write(ObservableCollectionToTXT.Method(ItemsCollection)); sw.Close(); } }
private void AcceptButton_Click(object sender, RoutedEventArgs e) { DataGridView.ItemsSource = ItemsCollection; string temporaryText = TextBox.Text; bool temporaryBool = false; // true - adding blocked if (temporaryText == "") { temporaryBool = true; } int length = temporaryText.Length; for (int i = 0; i < length; i++) { if (temporaryText[i] == ';') { temporaryBool = true; break; } } foreach (var item in ItemsCollection) { if (item.Text == temporaryText) { temporaryBool = true; } } if (temporaryBool == false) { ItemsCollection.Add(new item() { Statement = false, Text = TextBox.Text }); using (StreamWriter sw = File.CreateText(filePath)) { sw.Write(ObservableCollectionToTXT.Method(ItemsCollection)); sw.Close(); } int n = DataGridView.Columns.Count; if (DataGridView.Columns.Count > 0) { DataGridView.Columns[0].IsReadOnly = true; } TextBox.Text = ""; } else { using (StreamWriter sw = File.CreateText(filePath)) { sw.Write(ObservableCollectionToTXT.Method(ItemsCollection)); sw.Close(); } } }