Splash Page Code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Hospital_Management_System
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int startpoint = 0;
private void timer1_Tick(object sender, EventArgs e)
{
startpoint += 1;
ProgressBar1.Value = startpoint;
if(ProgressBar1.Value == 100)
{
ProgressBar1.Value = 0;
timer1.Stop();
Login l = new Login();
l.Show();
this.Hide();
}
}
private void Form1_Load(object sender, EventArgs e)
{
timer1.Start();
}
}
}
Login Page Code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace Hospital_Management_System
{
public partial class Login : Form
{
SqlConnection Con = new SqlConnection(@”Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\Pacify Technology\Desktop\Hospital Management System\Hospital Management System\HospitalManagementSystemDatabase.mdf;Integrated Security=True”);
public Login()
{
InitializeComponent();
}
private void btnClose_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void btnClear_Click(object sender, EventArgs e)
{
txtUsername.Text = "";
txtPassword.Text = "";
}
private void btnLogin_Click(object sender, EventArgs e)
{
if (txtUsername.Text == "" || txtPassword.Text == "")
MessageBox.Show("Enter Username and Password to Proceed");
else
{
Con.Open();
SqlDataAdapter sda = new SqlDataAdapter("select Count(*) from DoctorsTbl where DoctorName='"+txtUsername.Text+"' and DoctorPassword='"+txtPassword.Text+"'",Con);
DataTable dt = new DataTable();
sda.Fill(dt);
if(dt.Rows[0][0].ToString()=="1")
{
Home h = new Home();
h.Show();
this.Hide();
}
else
{
MessageBox.Show("Wrong Username and Password");
}
Con.Close();
}
}
}
}
Doctor Page Code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace Hospital_Management_System
{
public partial class Doctors : Form
{
SqlConnection Con = new SqlConnection(@”Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\Pacify Technology\Desktop\Hospital Management System\Hospital Management System\HospitalManagementSystemDatabase.mdf;Integrated Security=True”);
public Doctors()
{
InitializeComponent();
}
void populate()
{
Con.Open();
string query = “select * from DoctorsTbl”;
SqlDataAdapter da = new SqlDataAdapter(query, Con);
SqlCommandBuilder builder = new SqlCommandBuilder(da);
var ds = new DataSet();
da.Fill(ds);
DGVDoctors.DataSource = ds.Tables[0];
Con.Close();
}
private void btnHome_Click(object sender, EventArgs e)
{
Home h = new Home();
h.Show();
this.Hide();
}
private void btnClose_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void btnAdd_Click(object sender, EventArgs e)
{
if (txtDoctorId.Text == "" || txtDoctorName.Text == "" || txtYearsofExperience.Text == "" || txtPassword.Text == "")
MessageBox.Show("Missing Information ! See Carefully");
else
{
Con.Open();
string query = "insert into DoctorsTbl values(" + txtDoctorId.Text + ",'" + txtDoctorName.Text + "'," + txtYearsofExperience.Text + ",'" + txtPassword.Text + "')";
SqlCommand cmd = new SqlCommand(query, Con);
cmd.ExecuteNonQuery();
MessageBox.Show("Doctor Successfully Added");
Con.Close();
populate();
}
}
private void DGVDoctors_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
txtDoctorId.Text = DGVDoctors.SelectedRows[0].Cells[0].Value.ToString();
txtDoctorName.Text = DGVDoctors.SelectedRows[0].Cells[1].Value.ToString();
txtYearsofExperience.Text = DGVDoctors.SelectedRows[0].Cells[2].Value.ToString();
txtPassword.Text = DGVDoctors.SelectedRows[0].Cells[3].Value.ToString();
}
private void Doctors_Load(object sender, EventArgs e)
{
populate();
}
private void btnUpdate_Click(object sender, EventArgs e)
{
Con.Open();
string query = "update DoctorsTbl set DoctorName = '" + txtDoctorName.Text + "',DoctorExp = '" + txtYearsofExperience.Text + "',DoctorPassword = '"+txtPassword.Text+"' where DoctorId = "+txtDoctorId.Text+"";
SqlCommand cmd = new SqlCommand(query, Con);
cmd.ExecuteNonQuery();
MessageBox.Show("Doctor Successfully Updated");
Con.Close();
populate();
}
private void btnDelete_Click(object sender, EventArgs e)
{
if (txtDoctorId.Text == "")
MessageBox.Show("Enter the Doctor Id");
else
{
Con.Open();
string query = "delete from DoctorsTbl where DoctorId=" + txtDoctorId.Text + "";
SqlCommand cmd = new SqlCommand(query, Con);
cmd.ExecuteNonQuery();
MessageBox.Show("Doctor Successfully Deleted");
Con.Close();
populate();
}
}
private void btnReload_Click(object sender, EventArgs e)
{
populate();
}
}
}
Patient Page Code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace Hospital_Management_System
{
public partial class Patients : Form
{
SqlConnection Con = new SqlConnection(@”Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\Pacify Technology\Desktop\Hospital Management System\Hospital Management System\HospitalManagementSystemDatabase.mdf;Integrated Security=True”);
public Patients()
{
InitializeComponent();
}
void populate()
{
Con.Open();
string query = “select * from PatientsTbl”;
SqlDataAdapter da = new SqlDataAdapter(query, Con);
SqlCommandBuilder builder = new SqlCommandBuilder(da);
var ds = new DataSet();
da.Fill(ds);
DGVPatients.DataSource = ds.Tables[0];
Con.Close();
}
private void btnHome_Click(object sender, EventArgs e)
{
Home h = new Home();
h.Show();
this.Hide();
}
private void btnClose_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void btnAdd_Click(object sender, EventArgs e)
{
if (txtPatientId.Text == "" || txtPatientName.Text == "" || txtPatientAddress.Text == "" || txtPatientPhone.Text == "" || txtPatientAge.Text == "" || txtMajorDisease.Text == "")
MessageBox.Show("Missing Information ! See Carefully");
else
{
Con.Open();
string query = "insert into PatientsTbl values(" + txtPatientId.Text + ",'" + txtPatientName.Text + "','" + txtPatientAddress.Text + "','" + txtPatientPhone.Text + "',"+txtPatientAge.Text+",'"+GenderCb.SelectedItem.ToString()+"','"+BloodGroupCb.SelectedItem.ToString()+"','"+txtMajorDisease.Text+"')";
SqlCommand cmd = new SqlCommand(query, Con);
cmd.ExecuteNonQuery();
MessageBox.Show("Patient Successfully Added");
Con.Close();
populate();
}
}
private void Patients_Load(object sender, EventArgs e)
{
populate();
}
private void btnUpdate_Click(object sender, EventArgs e)
{
Con.Open();
string query = "update PatientsTbl set PatientName = '" + txtPatientName.Text + "',PatientAddress = '" + txtPatientAddress.Text + "',PatientPhone = '" + txtPatientPhone.Text + "',PatientAge = "+txtPatientAge.Text+",PatientGender = '"+GenderCb.SelectedItem.ToString()+"',PatientBG = '"+BloodGroupCb.SelectedItem.ToString()+"' where PatientId = " + txtPatientId.Text + "";
SqlCommand cmd = new SqlCommand(query, Con);
cmd.ExecuteNonQuery();
MessageBox.Show("Patient Successfully Updated");
Con.Close();
populate();
}
private void btnDelete_Click(object sender, EventArgs e)
{
if (txtPatientId.Text == "")
MessageBox.Show("Enter the Patient Id");
else
{
Con.Open();
string query = "delete from PatientsTbl where PatientId=" + txtPatientId.Text + "";
SqlCommand cmd = new SqlCommand(query, Con);
cmd.ExecuteNonQuery();
MessageBox.Show("Patient Successfully Deleted");
Con.Close();
populate();
}
}
private void btnReload_Click(object sender, EventArgs e)
{
populate();
}
private void DGVPatients_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
txtPatientId.Text = DGVPatients.SelectedRows[0].Cells[0].Value.ToString();
txtPatientName.Text = DGVPatients.SelectedRows[0].Cells[1].Value.ToString();
txtPatientAddress.Text = DGVPatients.SelectedRows[0].Cells[2].Value.ToString();
txtPatientPhone.Text = DGVPatients.SelectedRows[0].Cells[3].Value.ToString();
txtPatientAge.Text = DGVPatients.SelectedRows[0].Cells[4].Value.ToString();
txtMajorDisease.Text = DGVPatients.SelectedRows[0].Cells[7].Value.ToString();
}
}
}
Medicine Page Code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace Hospital_Management_System
{
public partial class Medicines : Form
{
SqlConnection Con = new SqlConnection(@”Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\Pacify Technology\Desktop\Hospital Management System\Hospital Management System\HospitalManagementSystemDatabase.mdf;Integrated Security=True”);
public Medicines()
{
InitializeComponent();
}
void populate()
{
Con.Open();
string query = “select * from MedicineTbl”;
SqlDataAdapter da = new SqlDataAdapter(query, Con);
SqlCommandBuilder builder = new SqlCommandBuilder(da);
var ds = new DataSet();
da.Fill(ds);
DGVMedicines.DataSource = ds.Tables[0];
Con.Close();
}
private void btnHome_Click(object sender, EventArgs e)
{
Home h = new Home();
h.Show();
this.Hide();
}
private void btnClose_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void btnAdd_Click(object sender, EventArgs e)
{
if (txtMedicineId.Text == "" || txtMedicineName.Text == "" || txtMedicineType.Text == "" || txtByDoctor.Text == "")
MessageBox.Show("Missing Information ! See Carefully");
else
{
Con.Open();
string query = "insert into MedicineTbl values(" + txtMedicineId.Text + ",'" + txtMedicineName.Text + "','" + txtMedicineType.Text + "','" + txtByDoctor.Text + "')";
SqlCommand cmd = new SqlCommand(query, Con);
cmd.ExecuteNonQuery();
MessageBox.Show("Medicine Successfully Added");
Con.Close();
populate();
}
}
private void DGVMedicines_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
txtMedicineId.Text = DGVMedicines.SelectedRows[0].Cells[0].Value.ToString();
txtMedicineName.Text = DGVMedicines.SelectedRows[0].Cells[1].Value.ToString();
txtMedicineType.Text = DGVMedicines.SelectedRows[0].Cells[2].Value.ToString();
txtByDoctor.Text = DGVMedicines.SelectedRows[0].Cells[3].Value.ToString();
}
private void btnUpdate_Click(object sender, EventArgs e)
{
Con.Open();
string query = "update MedicineTbl set MedicineName = '" + txtMedicineName.Text + "',MedicineType = '" + txtMedicineType.Text + "',ByDoctor = '" + txtByDoctor.Text + "' where MedicineId = " + txtMedicineId.Text + "";
SqlCommand cmd = new SqlCommand(query, Con);
cmd.ExecuteNonQuery();
MessageBox.Show("Medicine Successfully Updated");
Con.Close();
populate();
}
private void btnDelete_Click(object sender, EventArgs e)
{
if (txtMedicineId.Text == "")
MessageBox.Show("Enter the Medicine Id");
else
{
Con.Open();
string query = "delete from MedicineTbl where MedicineId=" + txtMedicineId.Text + "";
SqlCommand cmd = new SqlCommand(query, Con);
cmd.ExecuteNonQuery();
MessageBox.Show("Medicine Successfully Deleted");
Con.Close();
populate();
}
}
private void btnReload_Click(object sender, EventArgs e)
{
populate();
}
}
}
Diagnosis Page Code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace Hospital_Management_System
{
public partial class Diagnosis : Form
{
SqlConnection Con = new SqlConnection(@”Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\Pacify Technology\Desktop\Hospital Management System\Hospital Management System\HospitalManagementSystemDatabase.mdf;Integrated Security=True”);
public Diagnosis()
{
InitializeComponent();
}
void populateId()
{
string sql = “select * from PatientsTbl”;
SqlCommand cmd = new SqlCommand(sql, Con);
SqlDataReader rdr;
try
{
Con.Open();
DataTable dt = new DataTable();
dt.Columns.Add(“PatientId”, typeof(int));
rdr = cmd.ExecuteReader();
dt.Load(rdr);
PatientIdCb.ValueMember = “PatientId”;
PatientIdCb.DataSource = dt;
Con.Close();
}
catch
{
}
}
string PatientName;
void FetchPatientName()
{
Con.Open();
string mysql = "select * from PatientsTbl where PatientId="+PatientIdCb.SelectedValue.ToString()+"";
SqlCommand cmd = new SqlCommand(mysql, Con);
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
foreach(DataRow dr in dt.Rows)
{
PatientName = dr["PatientName"].ToString();
txtPatientName.Text = PatientName;
}
Con.Close();
}
void populate()
{
Con.Open();
string query = "select * from DiagnosisTbl";
SqlDataAdapter da = new SqlDataAdapter(query, Con);
SqlCommandBuilder builder = new SqlCommandBuilder(da);
var ds = new DataSet();
da.Fill(ds);
DGVDiagnosis.DataSource = ds.Tables[0];
Con.Close();
}
private void btnHome_Click(object sender, EventArgs e)
{
Home h = new Home();
h.Show();
this.Hide();
}
private void btnClose_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void btnAdd_Click(object sender, EventArgs e)
{
if (txtDiagnosisId.Text == "" || txtPatientName.Text == "" || txtSymptoms.Text == "" || txtDiagnosis.Text == "" || txtMedicines.Text == "")
MessageBox.Show("Missing Information ! See Carefully");
else
{
Con.Open();
string query = "insert into DiagnosisTbl values(" + txtDiagnosisId.Text + "," + PatientIdCb.SelectedValue.ToString() + ",'" + txtPatientName.Text + "','" + txtSymptoms.Text + "','" + txtDiagnosis.Text + "','" + txtMedicines.Text + "')";
SqlCommand cmd = new SqlCommand(query, Con);
cmd.ExecuteNonQuery();
MessageBox.Show("Diagnosis Successfully Added");
Con.Close();
populate();
}
}
private void btnUpdate_Click(object sender, EventArgs e)
{
Con.Open();
string query = "update DiagnosisTbl set PatientId = " + PatientIdCb.SelectedValue.ToString() + ",PatientName = '" + txtPatientName.Text + "',Symptoms = '" + txtSymptoms.Text + "',Diagnosis = '"+txtDiagnosis.Text+"',Medicines = '"+txtMedicines.Text+"' where DiagnosisId = " + txtDiagnosisId.Text + "";
SqlCommand cmd = new SqlCommand(query, Con);
cmd.ExecuteNonQuery();
MessageBox.Show("Diagnosis Successfully Updated");
Con.Close();
populate();
}
private void btnDelete_Click(object sender, EventArgs e)
{
if (txtDiagnosisId.Text == "")
MessageBox.Show("Enter the Diagnosis Id");
else
{
Con.Open();
string query = "delete from DiagnosisTbl where DiagnosisId=" + txtDiagnosisId.Text + "";
SqlCommand cmd = new SqlCommand(query, Con);
cmd.ExecuteNonQuery();
MessageBox.Show("Diagnosis Successfully Deleted");
Con.Close();
populate();
}
}
private void Diagnosis_Load(object sender, EventArgs e)
{
populateId();
populate();
}
private void PatientIdCb_SelectionChangeCommitted(object sender, EventArgs e)
{
FetchPatientName();
}
private void DGVDiagnosis_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
txtDiagnosisId.Text = DGVDiagnosis.SelectedRows[0].Cells[0].Value.ToString();
PatientIdCb.SelectedValue = DGVDiagnosis.SelectedRows[0].Cells[1].Value.ToString();
txtPatientName.Text = DGVDiagnosis.SelectedRows[0].Cells[2].Value.ToString();
txtSymptoms.Text = DGVDiagnosis.SelectedRows[0].Cells[3].Value.ToString();
txtDiagnosis.Text = DGVDiagnosis.SelectedRows[0].Cells[4].Value.ToString();
txtMedicines.Text = DGVDiagnosis.SelectedRows[0].Cells[5].Value.ToString();
lblPatientName.Text = DGVDiagnosis.SelectedRows[0].Cells[2].Value.ToString();
lblSymptoms.Text = DGVDiagnosis.SelectedRows[0].Cells[3].Value.ToString();
lblDiagnosis.Text = DGVDiagnosis.SelectedRows[0].Cells[4].Value.ToString();
lblMedicines.Text = DGVDiagnosis.SelectedRows[0].Cells[5].Value.ToString();
}
private void PrintDocument_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
e.Graphics.DrawString(label4.Text, new Font("Century Gothic", 25, FontStyle.Bold), Brushes.LimeGreen, new Point(230));
e.Graphics.DrawString(lblPatientName.Text +"\n"+ lblSymptoms.Text +"\n"+ lblDiagnosis.Text + "\n" + lblMedicines.Text, new Font("Century Gothic", 16, FontStyle.Bold), Brushes.Black, new Point(130,150));
e.Graphics.DrawString(label10.Text + "\n"+ label5.Text, new Font("Century Gothic", 20, FontStyle.Bold), Brushes.LimeGreen, new Point(230,380));
}
private void lblPrint_Click(object sender, EventArgs e)
{
if(PrintPreviewDialog.ShowDialog()==DialogResult.OK)
{
PrintDocument.Print();
}
}
private void btnReload_Click(object sender, EventArgs e)
{
populate();
}
}
}
Home Page Code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Hospital_Management_System
{
public partial class Home : Form
{
public Home()
{
InitializeComponent();
}
private void btnClose_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void btnDoctors_Click(object sender, EventArgs e)
{
Doctors d = new Doctors();
d.Show();
this.Hide();
}
private void btnDiagnosis_Click(object sender, EventArgs e)
{
Diagnosis di = new Diagnosis();
di.Show();
this.Hide();
}
private void btnPatients_Click(object sender, EventArgs e)
{
Patients p = new Patients();
p.Show();
this.Hide();
}
private void btnMedicines_Click(object sender, EventArgs e)
{
Medicines m = new Medicines();
m.Show();
this.Hide();
}
private void btnLogout_Click(object sender, EventArgs e)
{
Login l = new Login();
l.Show();
this.Hide();
}
}
}