private void Copy_Click(object sender, RoutedEventArgs e) { try { if (location == "1") { string path = TBadres.Text + ListMain.SelectedItem.ToString(); string newPath = TBadres2.Text + ListMain.SelectedItem.ToString(); FileInfo fileInfo = new FileInfo(path); FileInfo fileInfo2 = new FileInfo(newPath); if (fileInfo.Exists && !fileInfo2.Exists) { File.Copy(path, newPath, true); ListForCopy.ItemsSource = CorrectFile.methodForList(TBadres2.Text, ""); } } if (location == "2") { string path = TBadres2.Text + ListMain.SelectedItem.ToString(); string newPath = TBadres.Text + ListMain.SelectedItem.ToString(); FileInfo fileInfo = new FileInfo(path); FileInfo fileInfo2 = new FileInfo(newPath); if (fileInfo.Exists && !fileInfo2.Exists) { File.Copy(path, newPath, true); ListMain.ItemsSource = CorrectFile.methodForList(TBadres.Text, ""); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Критическая ошибка."); } }
public void ListMain_MouseDoubleClick(object sender, MouseButtonEventArgs e) { try { OpenTXTFile openTXTFile = new OpenTXTFile(); if (location == "1") { ForSavePath += Convert.ToString(ListMain.SelectedItem) + "\\"; if (Directory.Exists(ForSavePath)) { ListMain.ItemsSource = CorrectFile.methodForList(TBadres.Text, ListMain.SelectedItem); TBadres.Text = ForSavePath; } else { ForSavePath1 = ListMain.SelectedItem.ToString(); string path = TBadres.Text + ListMain.SelectedItem.ToString(); FileInfo info = new FileInfo(path); if (info.Extension == ".txt") { pathForCreate = path; StreamReader sr = new StreamReader(path, Encoding.Default); openTXTFile.Show(); openTXTFile.TBtxt.Text = sr.ReadToEnd(); proverka = openTXTFile.TBtxt.Text; } } } else if (location == "2") { ForSavePath2 += Convert.ToString(ListForCopy.SelectedItem) + "\\"; if (System.IO.Directory.Exists(ForSavePath2)) { ListForCopy.ItemsSource = CorrectFile.methodForList(TBadres2.Text, ListForCopy.SelectedItem); TBadres2.Text = ForSavePath2; } else if (System.IO.File.Exists(ForSavePath2)) { ForSavePath1 = ListMain.SelectedItem.ToString(); string path = TBadres2.Text + ListMain.SelectedItem.ToString(); FileInfo info = new FileInfo(path); if (info.Extension == ".txt") { pathForCreate = path; StreamReader sr = new StreamReader(path, Encoding.Default); openTXTFile.Show(); openTXTFile.TBtxt.Text = sr.ReadToEnd(); proverka = openTXTFile.TBtxt.Text; } } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Критическая ошибка."); } }
private void Delete_Click(object sender, RoutedEventArgs e) { try { if (location == "1") { string path = TBadres.Text + Convert.ToString(ListMain.SelectedItem); pathForCopyAndDeleteFile = path; FileInfo info = new FileInfo(path); if (info.Exists) { MessageBoxResult result = MessageBox.Show( "You seriously want to delete this file: " + info.Name, "Delete", MessageBoxButton.YesNo); if (result == MessageBoxResult.Yes) { info.Delete(); ListMain.ItemsSource = CorrectFile.methodForList(TBadres.Text, ""); } } } if (location == "2") { string path = TBadres2.Text + Convert.ToString(ListForCopy.SelectedItem); pathForCopyAndDeleteFile = path; FileInfo info = new FileInfo(path); if (info.Exists) { MessageBoxResult result = MessageBox.Show( "You seriously want to delete the file: " + info.Name, "Delete", MessageBoxButton.YesNo); if (result == MessageBoxResult.Yes) { info.Delete(); ListForCopy.ItemsSource = CorrectFile.methodForList(TBadres2.Text, ""); } } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Критическая ошибка."); } }
private void CMB_SelectionChanged(object sender, SelectionChangedEventArgs e) { try { if (location == "1") { TBadres.Text = ""; ListMain.ItemsSource = CorrectFile.methodForList(TBadres.Text, CMB.SelectedValue.ToString()); TBadres.Text = CMB.SelectedValue.ToString() + "\\"; ForSavePath = TBadres.Text; } else if (location == "2") { TBadres2.Text = ""; ListForCopy.ItemsSource = CorrectFile.methodForList(TBadres2.Text, CMB2.SelectedValue.ToString()); TBadres2.Text = CMB2.SelectedValue.ToString() + "\\"; ForSavePath2 = TBadres2.Text; } } catch (Exception ex) { MessageBox.Show(ex.Message, "Критическая ошибка."); } }