Skip to content

Commit

Permalink
AddCategory form code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
M-Zuber committed Dec 28, 2015
1 parent fed9760 commit 167da4c
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions MyHome.UI/AddCategoryUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,15 @@ public AddCategoryUI(CategoryType categoryType)
private void btnSave_Click(object sender, EventArgs e)
{
// If the category name is blank shows the user an error message
if (txtCategoryName.Text == "")
if (string.IsNullOrWhiteSpace(txtCategoryName.Text))
{
MessageBox.Show("Please fill in a name for the category",
"Error",
MessageBoxButtons.OK,
MessageBoxIcon.Warning,
MessageBoxDefaultButton.Button1);
// Clear out the textbox in case it has whitespace
txtCategoryName.Text = "";
txtCategoryName.Focus();
}
else if (_categoryService.CategoryHandlers[CategoryType].Exists(txtCategoryName.Text))
Expand All @@ -74,7 +76,7 @@ private void btnSave_Click(object sender, EventArgs e)
}
else
{
_categoryService.CategoryHandlers[CategoryType].Create(txtCategoryName.Text);
_categoryService.CategoryHandlers[CategoryType].Create(txtCategoryName.Text.Trim());

Close();
}
Expand All @@ -88,7 +90,7 @@ private void btnSave_Click(object sender, EventArgs e)
private void AddCategoryUI_FormClosing(object sender, FormClosingEventArgs e)
{
// Checks if a category had been saved before asking if the user wants to add another one
if (txtCategoryName.Text != "")
if (!string.IsNullOrWhiteSpace(txtCategoryName.Text))
{
// Asks if more data is being entered
DialogResult = MessageBox.Show("The entry was saved" +
Expand Down Expand Up @@ -121,6 +123,5 @@ protected override void OnClosed(EventArgs e)
}

#endregion

}
}

0 comments on commit 167da4c

Please sign in to comment.