Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.95 KB | None | 0 0
  1. private void btnSave_Click(object sender, EventArgs e)
  2. {
  3.  
  4. //create = false;
  5. //Has max and min of year.
  6. NumericUpDown year = new NumericUpDown();
  7.  
  8. year.Minimum = 1900;
  9. year.Maximum = 2017;
  10.  
  11.  
  12. //Below creates message boxes in case textboxes aren't filled with information.
  13. if (string.IsNullOrEmpty(txtTitle.Text))
  14. {
  15. MessageBox.Show("Enter a text title", "Error");
  16. txtTitle.Focus();
  17. }//Checks for ISBN.
  18. else if (txtISBN.Text.ToString().Length !=13)
  19. {
  20. MessageBox.Show("Enter a valid ISBN", "Error");
  21. txtISBN.Focus();
  22. }
  23.  
  24. else if ( string.IsNullOrEmpty(txtYear.Text))
  25. {
  26. MessageBox.Show("Please enter a valid year", "Error");
  27. txtYear.Focus();
  28. }
  29. //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.
  30. else if (int.Parse(txtYear.Text) < year.Minimum || int.Parse(txtYear.Text) > year.Maximum )
  31.  
  32. {
  33. MessageBox.Show("Enter a valid year", "Error");
  34. txtYear.Focus();
  35.  
  36. }
  37. //Checks for publisher
  38. else if( cmbPublisher.SelectedIndex == -1)
  39. {
  40. MessageBox.Show("Select a publisher", "Error");
  41. cmbPublisher.Focus();
  42. }
  43.  
  44. else
  45. {
  46. Exit = true;
  47.  
  48.  
  49. titlesBindingSource.EndEdit(); //Saves new data
  50.  
  51. _books_Spring2017_A2DataSet.PublishersRow books;
  52. books = this._books_Spring2017_A2DataSet.Publishers[area];
  53.  
  54. changeButtons();
  55. changeText();
  56. statusLabel();
  57. lblPublisher.Visible = false;
  58. cmbPublisher.Visible = false;
  59. stsInfo.Text = "";
  60.  
  61. btnSave.Enabled = false;
  62. btnEdit.Enabled = true;
  63. btnAdd.Enabled = true;
  64. btnUndo.Enabled = false;
  65. btnDelete.Enabled = true;
  66. btnExit.Enabled = true;
  67.  
  68. //Changes textboxes to read only.
  69. txtTitle.ReadOnly = true;
  70. txtISBN.ReadOnly = true;
  71. txtDescription.ReadOnly = true;
  72. txtSubject.ReadOnly = true;
  73. txtPages.ReadOnly = true;
  74. txtYear.ReadOnly = true;
  75. txtPrice.ReadOnly = true;
  76.  
  77. try
  78. {
  79. //Code here should be working but it crashes if you try adding something at the very end of the database.
  80.  
  81. try
  82. {
  83. books.Name = txtPublisher.Text;
  84. }
  85. catch
  86. {
  87. txtPublisher.Text = null;
  88. }
  89.  
  90. try
  91. {
  92. books.Address = txtAddress.Text;
  93. }
  94. catch
  95. {
  96. txtAddress.Text = null;
  97. }
  98. try
  99. {
  100. books.City = txtCity.Text;
  101. }
  102. catch
  103. {
  104. txtCity.Text = null;
  105. }
  106. try
  107. {
  108. books.State = txtState.Text;
  109. }
  110. catch
  111. {
  112. txtState.Text = null;
  113. }
  114. try
  115. {
  116. books.Zip = txtZip.Text;
  117. }
  118. catch
  119. {
  120. txtZip.Text = null;
  121. }
  122. }
  123.  
  124.  
  125. //exceptions
  126. catch (StrongTypingException except)
  127. {
  128. MessageBox.Show(except.Message, "Strong Typing Exeption");
  129. }
  130.  
  131. try //Should update entire database and it works on one of my laptops but not the other.
  132. {
  133. this.titlesTableAdapter.Update(this._books_Spring2017_A2DataSet.Titles);
  134. }
  135. catch (Exception except)
  136. {
  137. MessageBox.Show(except.Message, except.GetType().ToString());
  138. }
  139. }
  140.  
  141. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement