/// <summary> /// открытие файла /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void MenuItemOpentxtFile_Click(object sender, RoutedEventArgs e) { OpenMatrixWindow openDialog = new OpenMatrixWindow(".txt"); if (openDialog.ShowDialog() == true) { Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog(); dlg.DefaultExt = ".txt"; dlg.Filter = "Text documents (.txt)|*.txt"; Nullable <bool> result = dlg.ShowDialog(); if (result == true) { List <List <string> > items = await presenter.OpentxtFile(dlg.FileName); CreateTable(items.Select(x => x.Count).Max()); for (int i = 0; i < items.Count; i++) { List <string> item = items[i]; for (int j = 0; j < items[i].Count; j++) { dgvTable[i, j].Value = items[i][j]; } dgvTable.Update(); dgvTable.EndEdit(); } } else { MessageBox.Show("При открытии файла произошла ошибка.", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error); } } else { return; } }
/// <summary> /// открытие файла /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void MenuItemOpenExcelFile_Click(object sender, RoutedEventArgs e) { OpenMatrixWindow openDialog = new OpenMatrixWindow(".excel"); if (openDialog.ShowDialog() == true) { Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog(); dlg.DefaultExt = ".xlsx"; dlg.Filter = "Excel documents (.xlsx)|*.xlsx"; Nullable <bool> result = dlg.ShowDialog(); if (result == true) { string[,] items = presenter.OpenExcelFile(dlg.FileName); CreateTable(items.GetLength(0) > items.GetLength(1)?items.GetLength(0): items.GetLength(1)); for (int i = 0; i < items.GetLength(0); i++) { for (int j = 0; j < items.GetLength(1); j++) { dgvTable[i, j].Value = items[i, j]; } } } else { MessageBox.Show("При открытии файла произошла ошибка.", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error); } } else { return; } }