Advertisement
Guest User

Untitled

a guest
Nov 11th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.49 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using MySql.Data.MySqlClient;
  11. using System.IO;
  12.  
  13. namespace RecordManagementSystem
  14. {
  15. public partial class TeacherMaintenance : UserControl
  16. {
  17. MySqlConnection connection = new MySqlConnection("datasource=localhost;port=3306;username=root;password=");
  18.  
  19. public TeacherMaintenance()
  20. {
  21. InitializeComponent();
  22. }
  23.  
  24. private void ValidateKeyPress(object sender, KeyPressEventArgs e)
  25. {//accept only numbers for textboxes with int values.
  26. if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) &&
  27. (e.KeyChar != '.'))
  28. {
  29. e.Handled = true;
  30. }
  31. // only allow one decimal point
  32. if ((e.KeyChar == '.') && ((sender as TextBox).Text.IndexOf('.') > -1))
  33. {
  34. e.Handled = true;
  35. }
  36. }
  37. void keypressvalidation()
  38. {//list of textboses with int only values.
  39. contactnumbertb.KeyPress += ValidateKeyPress;
  40. prcnumbertb.KeyPress += ValidateKeyPress;
  41. umidnumbertb.KeyPress += ValidateKeyPress;
  42. tinnumbertb.KeyPress += ValidateKeyPress;
  43. philhealthtb.KeyPress += ValidateKeyPress;
  44. gsisnumbertb.KeyPress += ValidateKeyPress;
  45. bptb.KeyPress += ValidateKeyPress;
  46.  
  47. }
  48.  
  49. string mySqlCon = "Server=localhost;port=3306;database=rmsdb;Uid=root;pwd=''"; //connection string
  50. private void addbtn_Click(object sender, EventArgs e)
  51. {
  52. MySqlConnection con = new MySqlConnection(mySqlCon);
  53. MySqlCommand cmd;
  54.  
  55. try
  56. {
  57. if (teacheridtb.Text.Length > 0 && firstnametb.Text.Length > 0 && lastnametb.Text.Length > 0 && addresstb.Text.Length > 0 && contactnumbertb.Text.Length > 0 && positiontb.Text.Length > 0 && emailtb.Text.Length > 0 && empstatustb.Text.Length > 0 && dateofjoiningtb.Text.Length > 0 && comitemnumbertb.Text.Length > 0 && appointmenttb.Text.Length > 0 && prcnumbertb.Text.Length > 0 && umidnumbertb.Text.Length > 0 && tinnumbertb.Text.Length > 0 && philhealthtb.Text.Length > 0 && civilservicetb.Text.Length > 0 && gsisnumbertb.Text.Length > 0 && bptb.Text.Length > 0 && teacheridtb.Text.Length > 0)
  58. {
  59.  
  60. string CmdString = "INSERT INTO teacherstable(TeacherID, Firstname, Lastname, Address, ContactNumber, Email, Position, EmploymentStatus, DateOfJoining, CompeleteItemNumber, DateOfOriginalAppointment, PRCNumber, UMIDNumber, TINNumber, PhilhealthNumber, CivilServiceEligibility, GSIS, BPNumber) values (@TeacherID, @Firstname, @Lastname, @Address, @ContactNumber, @Email, @Position, @EmploymentStatus, @DateOfJoining, @CompeleteItemNumber, @DateOfOriginalAppointment, @PRCNumber, @UMIDNumber, @TINNumber, @PhilhealthNumber, @CivilServiceEligibility, @GSIS, @BPNumber)";
  61. cmd = new MySqlCommand(CmdString, con);
  62. cmd.Parameters.AddWithValue("@TeacherID", teacheridtb.Text);
  63. cmd.Parameters.AddWithValue("@Firstname", firstnametb.Text);
  64. cmd.Parameters.AddWithValue("@Lastname", lastnametb.Text);
  65. cmd.Parameters.AddWithValue("@Address", addresstb.Text);
  66. cmd.Parameters.AddWithValue("@ContactNumber", contactnumbertb.Text);
  67. cmd.Parameters.AddWithValue("@Email", emailtb.Text);
  68. cmd.Parameters.AddWithValue("@Position", positiontb.Text);
  69. cmd.Parameters.AddWithValue("@EmploymentStatus", empstatustb.Text);
  70. cmd.Parameters.AddWithValue("@DateOfJoining", dateofjoiningtb.Text);
  71. cmd.Parameters.AddWithValue("@CompleteItemNumber", comitemnumbertb.Text);
  72. cmd.Parameters.AddWithValue("@DateofOriginalAppointment", appointmenttb.Text);
  73. cmd.Parameters.AddWithValue("@PRCNumber", prcnumbertb.Text);
  74. cmd.Parameters.AddWithValue("@UMIDNumber", umidnumbertb.Text);
  75. cmd.Parameters.AddWithValue("@TINNumber", tinnumbertb.Text);
  76. cmd.Parameters.AddWithValue("@PhilhealthNumber", philhealthtb.Text);
  77. cmd.Parameters.AddWithValue("@CivilServiceEligiblity", civilservicetb.Text);
  78. cmd.Parameters.AddWithValue("@GSIS", gsisnumbertb.Text);
  79. cmd.Parameters.AddWithValue("@BPNumber", bptb.Text);
  80.  
  81.  
  82. con.Open();
  83. int RowsAffected = cmd.ExecuteNonQuery();
  84. if (RowsAffected > 0)
  85. {
  86. MessageBox.Show("Registered Successfully", "System Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
  87. teacheridtb.Text = "";
  88. firstnametb.Text = "";
  89. lastnametb.Text = "";
  90. addresstb.Text = "";
  91. contactnumbertb.Text = "";
  92. emailtb.Text = "";
  93. positiontb.Text = "";
  94. empstatustb.Text = "";
  95. dateofjoiningtb.Text = "";
  96. comitemnumbertb.Text = "";
  97. appointmenttb.Text = "";
  98. prcnumbertb.Text = "";
  99. umidnumbertb.Text = "";
  100. tinnumbertb.Text = "";
  101. philhealthtb.Text = "";
  102. civilservicetb.Text = "";
  103. gsisnumbertb.Text = "";
  104. bptb.Text = "";
  105. con.Close();
  106. //clearing textboxes fields.
  107.  
  108.  
  109. }
  110. }
  111. else
  112. {
  113. MessageBox.Show("Incomplete Data", "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
  114.  
  115. }
  116. }
  117. catch (Exception ex)
  118. {
  119. MessageBox.Show(ex.Message);
  120. }
  121. finally
  122. {
  123. if (con.State == ConnectionState.Open)
  124. {
  125. con.Close();
  126. }
  127. }
  128.  
  129. }
  130.  
  131.  
  132. private void addteacher_Click(object sender, EventArgs e)
  133. {
  134.  
  135. }
  136.  
  137. }
  138. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement