using MySql.Data.MySqlClient; using System; using System.Runtime.InteropServices; using System.Windows.Forms; namespace EMSystem.Forms { public partial class AddEmpForm : Form { //constructor public AddEmpForm() { InitializeComponent(); // declaring borderstyle, so there is no possiblity to change size, minimize etc FormBorderStyle = FormBorderStyle.None; } // exit button function private void exitBtn_Click(object sender, EventArgs e) { //closes currently used form this.Close(); } // ability to drag around the open popup form [DllImport("user32.DLL", EntryPoint = "ReleaseCapture")] private extern static void ReleaseCapture(); [DllImport("user32.DLL", EntryPoint = "SendMessage")] private extern static void SendMessage(System.IntPtr hWnd, int wMsg, int wParam, int lParam); private void bgPanel_MouseDown(object sender, MouseEventArgs e) { ReleaseCapture(); SendMessage(this.Handle, 0x112, 0xf012, 0); } //add button functionality private void addBtn_Click(object sender, EventArgs e) { try { //connection configuration for connection to database server string MyConnection2 = "server=127.0.0.1;database=ems;username=root;password="; // query to insert the data string Query = "INSERT INTO `employeelist` (`Name`, `Age`,`Phone Number`,`E-Mail`, `Address`,`Job Title`,`Wage`) VALUES('" + this.nameTxtBox.Text + "'," + Convert.ToInt32(this.ageTxtBox.Text) + "," + Convert.ToInt32(this.phoneTxtBox.Text) + ",'" + this.emailTxtBox.Text + "', '" + this.addressTxtBox.Text + "', '" + this.jobTitleTxtBox.Text + "', " + Convert.ToInt32(this.wageTxtBox.Text) + ");"; MySqlConnection MyConn2 = new MySqlConnection(MyConnection2); // opens connection MyConn2.Open(); MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2); MyCommand2.ExecuteReader(); //popup window after succesful adding of employee MessageBox.Show("Employee Added!", "Update", MessageBoxButtons.OK, MessageBoxIcon.Information); // closes connection MyConn2.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } //clears the textboxes after adding the employee to list nameTxtBox.Text = ""; ageTxtBox.Text = ""; phoneTxtBox.Text = ""; emailTxtBox.Text = ""; addressTxtBox.Text = ""; jobTitleTxtBox.Text = ""; wageTxtBox.Text = ""; } } }