private void btnOK_Click(object sender, EventArgs e) { frmPatientManagement frm = new frmPatientManagement(); bool fail = false; frm.MdiParent = MdiParent; load_table(); if (appointments.Rows.Count == 1) { if (appointments.Rows[0].ItemArray[1].ToString() == txtPass.Text) { frm.Show(); username = txtName.Text; txtName.Clear(); txtPass.Clear(); } else { fail = true; } } else { fail = true; } if (fail) { MessageBox.Show("Incorrect credentials submitted", "Login failure", MessageBoxButtons.OK, MessageBoxIcon.Error); txtPass.Clear(); txtPass.Focus(); } }
private void searchPatientToolStripMenuItem_Click(object sender, EventArgs e) { //display the result of a search //prevent index out of range related crashes try { string input = Interaction.InputBox("Please enter a patiants name or telephone number", "search user"); clsDB_conn myDb_Con = new clsDB_conn(); appointments = myDb_Con.db_query("SELECT * FROM patients WHERE patient_name = '" + input + "' OR patient_telephone = '" + input + "'", "doctor_m.mdb"); frmPatientManagement frm = new frmPatientManagement(); if (appointments.Rows.Count > 0) { for (int i = 0; i < appointments.Rows.Count; i++) { listBox1.Items.Add("Patient Details:"); for (int j = 1; j < 5; j++) { listBox1.Items.Add("\t" + appointments.Rows[i].ItemArray[j]); } } } else { MessageBox.Show("Patient not found", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (IndexOutOfRangeException m) { MessageBox.Show(m.Message + "\nPlease contact the administrator.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
//allows you to view all patients in the form of a report. private void allPatientsToolStripMenuItem_Click(object sender, EventArgs e) { //save the report to a file. clsDB_conn myDb_Con = new clsDB_conn(); DataTable temp = myDb_Con.db_query("SELECT * FROM patients", "doctor_m.mdb"); string path; SaveFileDialog sf = new SaveFileDialog(); sf.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal); sf.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*"; if (sf.ShowDialog(this) == DialogResult.OK) { path = sf.FileName; frmPatientManagement frm = new frmPatientManagement(); ///prevent io releted crashes try { if (temp.Rows.Count > 0) { if (File.Exists(path)) { File.Delete(path); } using (StreamWriter wr = File.AppendText(path)) { for (int j = 1; j < temp.Rows.Count; j++) { wr.WriteLine("Patient : " + temp.Rows[j].ItemArray[1] + " " + temp.Rows[j].ItemArray[2]); for (int i = 3; i < 5; i++) { wr.WriteLine("\t" + temp.Rows[j].ItemArray[i]); } } } MessageBox.Show("Save Successful", "write to file", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("No Patients found", "write to file", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (IOException a) { MessageBox.Show(a.Message + "\nFailed to open file,\nPlease try again.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }