using MySql.Data.MySqlClient; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Globalization; using System.Linq; using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace EMSystem.Forms { public partial class AddTaskForm : Form { //constructor public AddTaskForm() { InitializeComponent(); // declaring borderstyle, so there is no possiblity to change size or close without pressing exit button FormBorderStyle = FormBorderStyle.None; } //methods // 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 topPanel_MouseDown(object sender, MouseEventArgs e) { ReleaseCapture(); SendMessage(this.Handle, 0x112, 0xf012, 0); } // exit button private void exitBtn_Click(object sender, EventArgs e) { // closes form not application this.Close(); } //minimize button private void minBtn_Click(object sender, EventArgs e) { WindowState = FormWindowState.Minimized; } private void addBtn_Click(object sender, EventArgs e) { try { //connection configuration for connection to database server string MyConnection3 = "server=127.0.0.1;database=ems;username=root;password="; // query to insert the data DateTime datePicker = DateTime.Now; string date = datePicker.ToString("yyyy-MM-dd"); string Query2 = "INSERT INTO `tasklist` (`Task`, `Due Date`, `Priority`, `Description`) VALUES ('" + this.taskTextBox.Text + "', " + date + ", '" + this.prioComboBox.Text + "', '" + this.descTextBox.Text + "');"; MySqlConnection MyConn3 = new MySqlConnection(MyConnection3); // opens connection MyConn3.Open(); MySqlCommand MyCommand3 = new MySqlCommand(Query2, MyConn3); MyCommand3.ExecuteReader(); //popup window after succesful adding of employee MessageBox.Show("Task Added!", "Update", MessageBoxButtons.OK, MessageBoxIcon.Information); // closes connection MyConn3.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } //clears the textboxes after adding the employee to list taskTextBox.Text = ""; prioComboBox.Text = ""; descTextBox.Text = ""; } } }