private bool insertPatient() { Connect connect = new Connect(); MySqlCommand command = new MySqlCommand(); command.Connection = connect.getConnection(); command.Parameters.Add("@fname", MySqlDbType.VarChar).Value = txtFullName.Text; command.Parameters.Add("@faddress", MySqlDbType.VarChar).Value = txtFullAddress.Text; command.Parameters.Add("@username", MySqlDbType.VarChar).Value = txtUserName.Text; command.Parameters.Add("@password", MySqlDbType.VarChar).Value = txtPassword.Text; connect.openConnection(); String insertQuery = "INSERT INTO `patient`(`username`, `password`, `fullName`, `fullAddress`) VALUES (@username,@password,@fname,@faddress)"; command.CommandText = insertQuery; if (command.ExecuteNonQuery() == 1) { MessageBox.Show("Successfully Signed Up"); } else { MessageBox.Show("Unexpected Error. Please try again"); } connect.closeConnection(); return(true); }
private void CmdAddPatient_Click(object sender, EventArgs e) { Connect connect = new Connect(); DataTable table = new DataTable(); MySqlDataAdapter adapter = new MySqlDataAdapter(); MySqlCommand command = new MySqlCommand(); string query = "SELECT * FROM `doctors` WHERE `username` = @usn AND `password` = @pass "; command.CommandText = query; command.Connection = connect.getConnection(); command.Parameters.Add("@usn", MySqlDbType.VarChar).Value = txtDocAddUserId.Text; command.Parameters.Add("@pass", MySqlDbType.VarChar).Value = txtDocAddPassword.Text; adapter.SelectCommand = command; adapter.Fill(table); if (table.Rows.Count > 0) { try { MySqlCommand addPatientCommand = new MySqlCommand(" INSERT INTO `patientstreat`(`fullName`, `problem`, `doctorid`, `userid`) VALUES (@patientName,@patientProblem,@usnn,@patientUserId)", connect.getConnection()); addPatientCommand.Parameters.Add("@usnn", MySqlDbType.VarChar).Value = txtDocAddUserId.Text; addPatientCommand.Parameters.Add("@patientName", MySqlDbType.VarChar).Value = txtPatientFullName.Text; addPatientCommand.Parameters.Add("@patientProblem", MySqlDbType.VarChar).Value = txtPatientProblem.Text; addPatientCommand.Parameters.Add("@patientUserId", MySqlDbType.VarChar).Value = txtPatientUserId.Text; connect.openConnection(); if (addPatientCommand.ExecuteNonQuery() == 1) { MySqlCommand fetchPatientCommand = new MySqlCommand("SELECT fullName, problem, userid FROM `patientstreat` WHERE `doctorid` = @usn", connect.getConnection()); fetchPatientCommand.Parameters.Add("@usn", MySqlDbType.VarChar).Value = txtDocAddUserId.Text; MySqlDataAdapter newAdapter = new MySqlDataAdapter(); DataTable dataTable = new DataTable(); newAdapter.SelectCommand = fetchPatientCommand; newAdapter.Fill(dataTable); dataGridView1.DataSource = dataTable; MessageBox.Show("Inserted Successfully"); } } catch (MySqlException ex) { MessageBox.Show(ex.ToString()); } txtPatientFullName.Clear(); txtPatientProblem.Clear(); txtPatientUserId.Clear(); txtDocAddUserId.Clear(); txtDocAddPassword.Clear(); } }
private void CmdRemDoctor_Click(object sender, EventArgs e) { Connect connect = new Connect(); DataTable table = new DataTable(); MySqlDataAdapter adapter = new MySqlDataAdapter(); MySqlCommand command = new MySqlCommand(); string query = "SELECT * FROM `admin` WHERE `username` = @usn AND `password` = @pass "; command.CommandText = query; command.Connection = connect.getConnection(); command.Parameters.Add("@usn", MySqlDbType.VarChar).Value = txtAdminRemUserId.Text; command.Parameters.Add("@pass", MySqlDbType.VarChar).Value = txtAdminRemPassword.Text; adapter.SelectCommand = command; adapter.Fill(table); if (table.Rows.Count > 0) { txtAdminRemUserId.Clear(); txtAdminRemPassword.Clear(); txtDoctorUserIdForRemove.Clear(); MySqlCommand remDoctorCommand = new MySqlCommand(" DELETE FROM `doctors` WHERE `username` = @usnn", connect.getConnection()); remDoctorCommand.Parameters.Add("@usnn", MySqlDbType.VarChar).Value = txtDoctorUserIdForRemove.Text; connect.openConnection(); if (remDoctorCommand.ExecuteNonQuery() == 1) { MySqlCommand fetchDoctorCommand = new MySqlCommand("SELECT username, fullName, fullAddress FROM `doctors`", connect.getConnection()); MySqlDataAdapter newAdapter2 = new MySqlDataAdapter(); DataTable dataTable2 = new DataTable(); newAdapter2.SelectCommand = fetchDoctorCommand; newAdapter2.Fill(dataTable2); dataGridView2.DataSource = dataTable2; MessageBox.Show("Removed Successfully"); } } }
private void CmdRemovePatient_Click(object sender, EventArgs e) { Connect connect = new Connect(); DataTable table = new DataTable(); MySqlDataAdapter adapter = new MySqlDataAdapter(); MySqlCommand command = new MySqlCommand(); string query = "SELECT * FROM `doctors` WHERE `username` = @usn AND `password` = @pass "; command.CommandText = query; command.Connection = connect.getConnection(); command.Parameters.Add("@usn", MySqlDbType.VarChar).Value = txtDocRemUserId.Text; command.Parameters.Add("@pass", MySqlDbType.VarChar).Value = txtDocRemPassword.Text; adapter.SelectCommand = command; adapter.Fill(table); if (table.Rows.Count > 0) { MySqlCommand remPatientCommand = new MySqlCommand(" DELETE FROM `patientstreat` WHERE `doctorid` = @usnn AND `userid` = @patientUserId", connect.getConnection()); remPatientCommand.Parameters.Add("@usnn", MySqlDbType.VarChar).Value = txtDocRemUserId.Text; remPatientCommand.Parameters.Add("@patientUserId", MySqlDbType.VarChar).Value = txtPatientUserIdForRemove.Text; connect.openConnection(); if (remPatientCommand.ExecuteNonQuery() == 1) { MySqlCommand fetchPatientCommand = new MySqlCommand("SELECT fullName, problem, userid FROM `patientstreat` WHERE `doctorid` = @usn", connect.getConnection()); fetchPatientCommand.Parameters.Add("@usn", MySqlDbType.VarChar).Value = txtDocRemUserId.Text; MySqlDataAdapter newAdapter = new MySqlDataAdapter(); DataTable dataTable = new DataTable(); newAdapter.SelectCommand = fetchPatientCommand; newAdapter.Fill(dataTable); dataGridView1.DataSource = dataTable; MessageBox.Show("Deleted Successfully"); } } }