Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Drawing;
- using System.Data;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using MySql.Data.MySqlClient;
- using System.IO;
- namespace RecordManagementSystem
- {
- public partial class TeacherMaintenance : UserControl
- {
- MySqlConnection connection = new MySqlConnection("datasource=localhost;port=3306;username=root;password=");
- public TeacherMaintenance()
- {
- InitializeComponent();
- }
- private void ValidateKeyPress(object sender, KeyPressEventArgs e)
- {//accept only numbers for textboxes with int values.
- if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) &&
- (e.KeyChar != '.'))
- {
- e.Handled = true;
- }
- // only allow one decimal point
- if ((e.KeyChar == '.') && ((sender as TextBox).Text.IndexOf('.') > -1))
- {
- e.Handled = true;
- }
- }
- void keypressvalidation()
- {//list of textboses with int only values.
- contactnumbertb.KeyPress += ValidateKeyPress;
- prcnumbertb.KeyPress += ValidateKeyPress;
- umidnumbertb.KeyPress += ValidateKeyPress;
- tinnumbertb.KeyPress += ValidateKeyPress;
- philhealthtb.KeyPress += ValidateKeyPress;
- gsisnumbertb.KeyPress += ValidateKeyPress;
- bptb.KeyPress += ValidateKeyPress;
- }
- string mySqlCon = "Server=localhost;port=3306;database=rmsdb;Uid=root;pwd=''"; //connection string
- private void addbtn_Click(object sender, EventArgs e)
- {
- MySqlConnection con = new MySqlConnection(mySqlCon);
- MySqlCommand cmd;
- try
- {
- 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)
- {
- 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)";
- cmd = new MySqlCommand(CmdString, con);
- cmd.Parameters.AddWithValue("@TeacherID", teacheridtb.Text);
- cmd.Parameters.AddWithValue("@Firstname", firstnametb.Text);
- cmd.Parameters.AddWithValue("@Lastname", lastnametb.Text);
- cmd.Parameters.AddWithValue("@Address", addresstb.Text);
- cmd.Parameters.AddWithValue("@ContactNumber", contactnumbertb.Text);
- cmd.Parameters.AddWithValue("@Email", emailtb.Text);
- cmd.Parameters.AddWithValue("@Position", positiontb.Text);
- cmd.Parameters.AddWithValue("@EmploymentStatus", empstatustb.Text);
- cmd.Parameters.AddWithValue("@DateOfJoining", dateofjoiningtb.Text);
- cmd.Parameters.AddWithValue("@CompleteItemNumber", comitemnumbertb.Text);
- cmd.Parameters.AddWithValue("@DateofOriginalAppointment", appointmenttb.Text);
- cmd.Parameters.AddWithValue("@PRCNumber", prcnumbertb.Text);
- cmd.Parameters.AddWithValue("@UMIDNumber", umidnumbertb.Text);
- cmd.Parameters.AddWithValue("@TINNumber", tinnumbertb.Text);
- cmd.Parameters.AddWithValue("@PhilhealthNumber", philhealthtb.Text);
- cmd.Parameters.AddWithValue("@CivilServiceEligiblity", civilservicetb.Text);
- cmd.Parameters.AddWithValue("@GSIS", gsisnumbertb.Text);
- cmd.Parameters.AddWithValue("@BPNumber", bptb.Text);
- con.Open();
- int RowsAffected = cmd.ExecuteNonQuery();
- if (RowsAffected > 0)
- {
- MessageBox.Show("Registered Successfully", "System Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
- teacheridtb.Text = "";
- firstnametb.Text = "";
- lastnametb.Text = "";
- addresstb.Text = "";
- contactnumbertb.Text = "";
- emailtb.Text = "";
- positiontb.Text = "";
- empstatustb.Text = "";
- dateofjoiningtb.Text = "";
- comitemnumbertb.Text = "";
- appointmenttb.Text = "";
- prcnumbertb.Text = "";
- umidnumbertb.Text = "";
- tinnumbertb.Text = "";
- philhealthtb.Text = "";
- civilservicetb.Text = "";
- gsisnumbertb.Text = "";
- bptb.Text = "";
- con.Close();
- //clearing textboxes fields.
- }
- }
- else
- {
- MessageBox.Show("Incomplete Data", "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- finally
- {
- if (con.State == ConnectionState.Open)
- {
- con.Close();
- }
- }
- }
- private void addteacher_Click(object sender, EventArgs e)
- {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement