Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void btnSave_Click(object sender, EventArgs e)
- {
- //create = false;
- //Has max and min of year.
- NumericUpDown year = new NumericUpDown();
- year.Minimum = 1900;
- year.Maximum = 2017;
- //Below creates message boxes in case textboxes aren't filled with information.
- if (string.IsNullOrEmpty(txtTitle.Text))
- {
- MessageBox.Show("Enter a text title", "Error");
- txtTitle.Focus();
- }//Checks for ISBN.
- else if (txtISBN.Text.ToString().Length !=13)
- {
- MessageBox.Show("Enter a valid ISBN", "Error");
- txtISBN.Focus();
- }
- else if ( string.IsNullOrEmpty(txtYear.Text))
- {
- MessageBox.Show("Please enter a valid year", "Error");
- txtYear.Focus();
- }
- //It should allow nothing to be placed into the year but it doesn't work without it so I made users have to put in a valid year.
- else if (int.Parse(txtYear.Text) < year.Minimum || int.Parse(txtYear.Text) > year.Maximum )
- {
- MessageBox.Show("Enter a valid year", "Error");
- txtYear.Focus();
- }
- //Checks for publisher
- else if( cmbPublisher.SelectedIndex == -1)
- {
- MessageBox.Show("Select a publisher", "Error");
- cmbPublisher.Focus();
- }
- else
- {
- Exit = true;
- titlesBindingSource.EndEdit(); //Saves new data
- _books_Spring2017_A2DataSet.PublishersRow books;
- books = this._books_Spring2017_A2DataSet.Publishers[area];
- changeButtons();
- changeText();
- statusLabel();
- lblPublisher.Visible = false;
- cmbPublisher.Visible = false;
- stsInfo.Text = "";
- btnSave.Enabled = false;
- btnEdit.Enabled = true;
- btnAdd.Enabled = true;
- btnUndo.Enabled = false;
- btnDelete.Enabled = true;
- btnExit.Enabled = true;
- //Changes textboxes to read only.
- txtTitle.ReadOnly = true;
- txtISBN.ReadOnly = true;
- txtDescription.ReadOnly = true;
- txtSubject.ReadOnly = true;
- txtPages.ReadOnly = true;
- txtYear.ReadOnly = true;
- txtPrice.ReadOnly = true;
- try
- {
- //Code here should be working but it crashes if you try adding something at the very end of the database.
- try
- {
- books.Name = txtPublisher.Text;
- }
- catch
- {
- txtPublisher.Text = null;
- }
- try
- {
- books.Address = txtAddress.Text;
- }
- catch
- {
- txtAddress.Text = null;
- }
- try
- {
- books.City = txtCity.Text;
- }
- catch
- {
- txtCity.Text = null;
- }
- try
- {
- books.State = txtState.Text;
- }
- catch
- {
- txtState.Text = null;
- }
- try
- {
- books.Zip = txtZip.Text;
- }
- catch
- {
- txtZip.Text = null;
- }
- }
- //exceptions
- catch (StrongTypingException except)
- {
- MessageBox.Show(except.Message, "Strong Typing Exeption");
- }
- try //Should update entire database and it works on one of my laptops but not the other.
- {
- this.titlesTableAdapter.Update(this._books_Spring2017_A2DataSet.Titles);
- }
- catch (Exception except)
- {
- MessageBox.Show(except.Message, except.GetType().ToString());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement