Skip to content

Commit

Permalink
Some changes made to the Error handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
showmik committed Jan 15, 2023
1 parent a23e86e commit f08872e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 35 deletions.
37 changes: 21 additions & 16 deletions HtmlTableGenerator/Services/GeneratorTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,26 +117,31 @@ public static void CreateTextBoxes(Grid grid, TableData tableData)

public static async Task<string[]?> ReadCsv(string filePath)
{
string[] strings;
try
if (!string.IsNullOrEmpty(filePath))
{
strings = await File.ReadAllLinesAsync(filePath);
}
catch (FileNotFoundException ex)
{
MessageBox.Show("Error: The file could not be found. " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
return null;
}
catch (ArgumentException)
{
MessageBox.Show("Error: Path cannot be empty. ", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
return null;
string[] strings;
try
{
strings = await File.ReadAllLinesAsync(filePath);
}
catch (FileNotFoundException ex)
{
MessageBox.Show("Error: The file could not be found. " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
return null;
}
catch (Exception ex)
{
MessageBox.Show("Error: An error occurred.\n" + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
return null;
}
return strings;
}
catch (Exception ex)
else
{
MessageBox.Show("Error: An error occurred.\n" + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
MessageBox.Show("Warning: Path must not be empty.", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
return null;
}
return strings;


}
}
30 changes: 11 additions & 19 deletions HtmlTableGenerator/ViewModel/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using HtmlTableGenerator.View;
using Microsoft.Win32;
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;

Expand All @@ -25,8 +24,8 @@ public partial class MainViewModel : ObservableObject

public MainViewModel()
{
rowText = "0";
columnText = "0";
rowText = "1";
columnText = "1";
filePath = string.Empty;
tableData = new TableData();
}
Expand Down Expand Up @@ -73,24 +72,17 @@ private void ProcessTableContent()
int row = int.Parse(RowText);
int column = int.Parse(ColumnText);

if (row > 0 && column > 0)
{
tableData.Row = row;
tableData.Column = column;
tableData.Row = row;
tableData.Column = column;

TableInputWindow tableInputWindow = new();
Grid grid = tableInputWindow.TableGrid;
TableInputWindow tableInputWindow = new();
Grid grid = tableInputWindow.TableGrid;

GeneratorTools.AdjustGrid(row, column, grid);
GeneratorTools.CreateHeaders(grid, row, column);
GeneratorTools.CreateTextBoxes(grid, tableData);
SendTableData(tableData);
tableInputWindow.Show();
}
else
{
MessageBox.Show("Row and Column must greater than 0.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
GeneratorTools.AdjustGrid(row, column, grid);
GeneratorTools.CreateHeaders(grid, row, column);
GeneratorTools.CreateTextBoxes(grid, tableData);
SendTableData(tableData);
tableInputWindow.Show();
}

private void SendTableData(TableData tableData) => WeakReferenceMessenger.Default.Send(tableData);
Expand Down

0 comments on commit f08872e

Please sign in to comment.