/* * Event Handler for Adding Category to the Invetory */ private void CategoryButton_Click(object sender, EventArgs e) { StreamWriter FileWriter; FileWriter = File.AppendText(CATEGORYDATABASEFILENAME); if (CategoryNameTextBox.Text == "") { MessageBox.Show("Please enter Category Name"); CategoryNameTextBox.Focus(); CategoryNameTextBox.SelectAll(); } else { if (CategoryList.Contains(CategoryNameTextBox.Text)) { MessageBox.Show("Category already Exist"); CategoryNameTextBox.Focus(); CategoryNameTextBox.SelectAll(); } else { CategoryList.Add(CategoryNameTextBox.Text); FileWriter.WriteLine(CategoryNameTextBox.Text); FileWriter.Close(); MessageBox.Show("Category Added Successfully to the Database"); CategoryNameTextBox.Text = ""; } } }
private void CategoryNameTextBox_Validating(object sender, CancelEventArgs e) { if (string.IsNullOrWhiteSpace(CategoryNameTextBox.Text)) { e.Cancel = true; CategoryNameTextBox.Focus(); CategoryNameTextBoxErrorProvider.SetError(CategoryNameTextBox, "Field is mandatory!"); } else { e.Cancel = false; CategoryNameTextBoxErrorProvider.SetError(CategoryNameTextBox, ""); } }