C# CRUD MENU MEDICAL WITH MICROSOFT SQLSERVER 2022
MENU (MEDICAL ) PROGRAM SAMPLE
C# MENU MEDICAL WITH MICROSOFT SQLSERVER 2022
Bismillah :
Pada tahap awal ini untuk membuat aplikasi C# MENU with MICROSOFT SQLSERVER 2022
kita membutuhkan beberapa toll diantara nya adalah :
- SQL Server Management 20 Link Download
Database yang digunakan dalam CRUD C# Menu Medical yaitu dengan nama (hospital)
Tabel-tabel yang digunakan sebagai berikut:
Nama Database : hospital
- AdmitPatienttb
- Doctortb
- Receptiontb
- Medicinetb
- Wardtb
Dengan Sql Query sebagai berikut :
Database : hospital
------------------------
USE [master]
CREATE DATABASE [Hospital]
-------------------------------------------
Tabel AdmitPatienttb
----------------------------
CREATE TABLE [dbo].[AdmitPatienttb](
[AdmitID] [int] IDENTITY(1,1) NOT NULL,
[AdmitPatientName] [varchar](50) NOT NULL,
[AdmitPatientAge] [int] NOT NULL,
[AdmitPatientGender] [varchar](50) NOT NULL,
[AdmitPatientPhoneNo] [varchar](50) NOT NULL,
[AdmitPatientAddress] [varchar](50) NOT NULL,
[AdmitedDate] [date] NOT NULL,
[ReleaseDate] [date] NULL,
[WardNo] [int] NOT NULL,
[TotalDayAdmit] [int] NULL,
[AdmitPatientDisease] [varchar](50) NOT NULL,
[TotalBill] [float] NULL,
CONSTRAINT [PK_AdmitPatienttb] PRIMARY KEY CLUSTERED
(
[AdmitID] ASC
) ON [PRIMARY]
-----------------------------------------------------------------------------------------
Tabel Doctortb
-------------------------
CREATE TABLE [dbo].[Doctortb](
[DoctorID] [int] IDENTITY(1,1) NOT NULL,
[DoctorName] [varchar](50) NOT NULL,
[DoctorPassword] [varchar](50) NOT NULL,
[Department] [varchar](50) NOT NULL,
[DateofBirth] [date] NOT NULL,
[DateofJoining] [date] NOT NULL,
[DoctorGender] [varchar](50) NOT NULL,
[DoctorAddress] [varchar](50) NOT NULL,
[DoctorEmail] [varchar](50) NOT NULL,
[DoctorSalary] [int] NOT NULL,
[DoctorPhoneNo] [varchar](50) NOT NULL,
CONSTRAINT [PK_Doctortb] PRIMARY KEY CLUSTERED
(
[DoctorID] ASC
)
) ON [PRIMARY]
-----------------------------------------------------------------------------------------
Tabel Receptiontb
----------------------------
CREATE TABLE [dbo].[Receptiontb](
[RID] [int] IDENTITY(1,1) NOT NULL,
[ReceptionistName] [varchar](50) NOT NULL,
[ReceptionistPassword] [varchar](50) NOT NULL,
[DateOfBirth] [date] NOT NULL,
[DateOfJoining] [date] NOT NULL,
[ReceptionistGender] [varchar](50) NOT NULL,
[ReceptionistAddress] [varchar](50) NOT NULL,
[ReceptionistEmail] [varchar](50) NOT NULL,
[ReceptionistPhoneNo] [varchar](50) NOT NULL,
[ReceptionistSalary] [int] NOT NULL,
CONSTRAINT [PK_Receptiontb] PRIMARY KEY CLUSTERED
(
[RID] ASC
)
) ON [PRIMARY]
-----------------------------------------------------------------------------------------
Tabel Medicinetb
---------------------------
CREATE TABLE [dbo].[Medicinetb](
[MedicineID] [int] IDENTITY(1,1) NOT NULL,
[MedicineName] [varchar](50) NOT NULL,
CONSTRAINT [PK_Medicinetb] PRIMARY KEY CLUSTERED
(
[MedicineID] ASC
)
) ON [PRIMARY]
-----------------------------------------------------------------------------------------
Tabel Wardtb
----------------------
CREATE TABLE [dbo].[Wardtb](
[WARDID] [int] IDENTITY(1,100) NOT NULL,
[WARDNO] [int] NOT NULL,
CONSTRAINT [PK_Wardtb] PRIMARY KEY CLUSTERED
(
[WARDNO] ASC
)
) ON [PRIMARY]
----------------------------------------------------------------------------------------------------------------------------------------------------------
Tampilan awal masuk connect ke SQL Server Management 20
Program Menu Medical menggunakan beberapa form dalam pembuatan design program dan source code program . berikut tampilan design form program dan source code program :
Menu utama (AdminMainForm)
Source code AdminMainForm.cs
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 Medical
{
public partial class AdminMainForm : Form
{
public AdminMainForm()
{
InitializeComponent();
}
private void dIVISIONDOCTORSToolStripMenuItem_Click(object sender, EventArgs e)
{
AddDoctor aa1 = new AddDoctor();
this.Visible = false;
aa1.ShowDialog();
}
private void aDDRECEPTIONISTToolStripMenuItem_Click(object sender, EventArgs e)
{
AddReceptionis aa2 = new AddReceptionis();
this.Visible = false;
aa2.ShowDialog();
}
private void mEDICINEMANAGEMENTToolStripMenuItem_Click(object sender, EventArgs e)
{
MedicineMainForm aa3 = new MedicineMainForm();
this.Visible = false;
aa3.ShowDialog();
}
private void aDMINPATIENTSToolStripMenuItem_Click(object sender, EventArgs e)
{
AdmitPatientForm aa5 = new AdmitPatientForm();
this.Visible = false;
aa5.ShowDialog();
}
}
}
-----------------------------------------------------------------------------------------------------------------------------
Form Add Doctor ( Menu Division Doctor)
Source code AddDoctor.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Medical
{
public partial class AddDoctor : Form
{
SqlConnection con = new SqlConnection(@"Data Source=LAPTOP-NM70SCK9;Initial Catalog=Hospital;Persist Security Info=True;User ID=sa;Password=12345678;TrustServerCertificate=True");
String Gender = " ";
public AddDoctor()
{
InitializeComponent();
TimeToday.Start();
}
private void TimeToday_Tick(object sender, EventArgs e)
{
DateTime dt = DateTime.Now;
Todaydatetime.Text = dt.ToString();
}
private void Insertbtn_Click(object sender, EventArgs e)
{
con.Open();
try
{
SqlCommand command;
SqlDataAdapter adaptor = new SqlDataAdapter();
String sql = "insert into Doctortb(DoctorName,DoctorPassword,Department,DateOfBirth,DateOfJoining,DoctorGender,DoctorAddress,DoctorEmail,DoctorSalary,DoctorPhoneNo) values ('" + this.AddDoctorNametxt.Text + "','" + this.AddDoctorPassword.Text + "','" + this.AddDoctorDepartment.Text + "','" + this.AddDoctorDOB.Text + "','" + this.JoinindDate.Text + "','" + this.Gender + "','" + this.AddDoctorAddresstxt.Text + "','" + this.AddDoctorEmail.Text + "','" + this.AddDoctorSalary.Text + "','" + this.AddDcotorPhoneNo.Text + "')";
command = new SqlCommand(sql, con);
adaptor.InsertCommand = new SqlCommand(sql, con);
adaptor.InsertCommand.ExecuteNonQuery();
command.Dispose();
con.Close();
MessageBox.Show("Record SuccessFully Inserted");
DoctorDeatils();
this.AddDoctorNametxt.Text = "";
this.AddDoctorPassword.Text = "";
this.AddDoctorDepartment.Text = "";
this.AddDoctorDOB.Text = "";
this.JoinindDate.Text = "";
this.Gender = "";
this.AddDoctorAddresstxt.Text = "";
this.AddDoctorEmail.Text = "";
this.AddDoctorSalary.Text = "";
this.AddDcotorPhoneNo.Text = "";
Searchtxt.Text = "";
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void Updatebtn_Click(object sender, EventArgs e)
{
con.Open();
try
{
String updatecommand = "Update Doctortb set DoctorName = '" + this.AddDoctorNametxt.Text + "' , DoctorPassword = '" + this.AddDoctorPassword.Text + "' , Department = '" + this.AddDoctorDepartment.Text + "' , DateOfBirth = '" + this.AddDoctorDOB.Text + "' , DateOfJoining = '" + this.JoinindDate.Text + "' , DoctorGender = '" + this.Gender + "' , DoctorAddress = '" + this.AddDoctorAddresstxt.Text + "' , DoctorEmail = '" + this.AddDoctorEmail.Text + "' , DoctorSalary = '" + this.AddDoctorSalary.Text + "' , DoctorPhoneNo = '" + this.AddDcotorPhoneNo.Text + "' where DoctorID = '" + this.Searchtxt.Text + "';";
SqlCommand updatecommand1;
updatecommand1 = new SqlCommand(updatecommand, con);
SqlDataAdapter Updateadaptor = new SqlDataAdapter(updatecommand, con);
Updateadaptor.UpdateCommand = new SqlCommand(updatecommand, con);
Updateadaptor.UpdateCommand.ExecuteNonQuery();
con.Close();
MessageBox.Show("Record SuccessFully Updated");
DoctorDeatils();
this.AddDoctorNametxt.Text = "";
this.AddDoctorPassword.Text = "";
this.AddDoctorDepartment.Text = "";
this.AddDoctorDOB.Text = "";
this.JoinindDate.Text = "";
this.Gender = "";
this.AddDoctorAddresstxt.Text = "";
this.AddDoctorEmail.Text = "";
this.AddDoctorSalary.Text = "";
this.AddDcotorPhoneNo.Text = "";
Searchtxt.Text = "";
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void Deletebtn_Click(object sender, EventArgs e)
{
con.Open();
try
{
string deletestr = "delete from Doctortb WHERE DoctorID = '" + Searchtxt.Text + "'";
SqlCommand deletecommand;
deletecommand = new SqlCommand(deletestr, con);
SqlDataAdapter deleteadaptor = new SqlDataAdapter(deletestr, con);
deleteadaptor.DeleteCommand = new SqlCommand(deletestr, con);
deleteadaptor.DeleteCommand.ExecuteNonQuery();
con.Close();
MessageBox.Show("Records Successfully Delete");
DoctorDeatils();
this.AddDoctorNametxt.Text = "";
this.AddDoctorPassword.Text = "";
this.AddDoctorDepartment.Text = "";
this.AddDoctorDOB.Text = "";
this.JoinindDate.Text = "";
this.Gender = "";
this.AddDoctorAddresstxt.Text = "";
this.AddDoctorEmail.Text = "";
this.AddDoctorSalary.Text = "";
this.AddDcotorPhoneNo.Text = "";
Searchtxt.Text = "";
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void Cleartxtbtn_Click(object sender, EventArgs e)
{
this.AddDoctorNametxt.Text = "";
this.AddDoctorPassword.Text = "";
this.AddDoctorDepartment.Text = "";
this.AddDoctorDOB.Text = "";
this.JoinindDate.Text = "";
this.Gender = "";
this.AddDoctorAddresstxt.Text = "";
this.AddDoctorEmail.Text = "";
this.AddDoctorSalary.Text = "";
this.AddDcotorPhoneNo.Text = "";
Searchtxt.Text = "";
}
private void Searchbtn_Click(object sender, EventArgs e)
{
con.Open();
string str = "select * from Doctortb WHERE DoctorID = '" + Searchtxt.Text + "'";
SqlCommand cmd = new SqlCommand(str, con);
SqlDataReader sdr;
sdr = cmd.ExecuteReader();
if (sdr.Read())
{
this.AddDoctorNametxt.Text = sdr["DoctorName"].ToString();
this.AddDoctorPassword.Text = sdr["DoctorPassword"].ToString();
this.AddDoctorDepartment.Text = sdr["Department"].ToString();
this.AddDoctorDOB.Text = sdr["DateOfBirth"].ToString();
this.JoinindDate.Text = sdr["DateOfJoining"].ToString();
this.Gender = sdr["DoctorGender"].ToString();
this.AddDoctorAddresstxt.Text = sdr["DoctorAddress"].ToString();
this.AddDoctorEmail.Text = sdr["DoctorEmail"].ToString();
this.AddDoctorSalary.Text = sdr["DoctorSalary"].ToString();
this.AddDcotorPhoneNo.Text = sdr["DoctorPhoneNo"].ToString();
}
else
{
MessageBox.Show("Record Not Found");
}
con.Close();
}
private void AddDoctor_Load(object sender, EventArgs e)
{
DoctorDeatils();
}
public void DoctorDeatils()
{
using (SqlConnection c1 = new SqlConnection(@"Data Source=LAPTOP-NM70SCK9;Initial Catalog=Hospital;Integrated Security=True;TrustServerCertificate=True"))
{
c1.Open();
// Create new DataAdapter
using (SqlDataAdapter a1 = new SqlDataAdapter("SELECT * FROM Doctortb", con))
{
// Use DataAdapter to fill DataTable
DataTable t1 = new DataTable();
a1.Fill(t1);
// Render data onto the screen
Doctorsdt.DataSource = t1;
}
c1.Close();
}
}
private void DoctorGenderMale_CheckedChanged(object sender, EventArgs e)
{
Gender = "Male";
}
private void DoctorGenderFemale_CheckedChanged(object sender, EventArgs e)
{
Gender = "Female";
}
private void aDDRECEPTIONISTToolStripMenuItem_Click(object sender, EventArgs e)
{
AddReceptionis aa2 = new AddReceptionis();
this.Visible = false;
aa2.ShowDialog();
}
private void mEDICINEMANAGEMENTToolStripMenuItem_Click(object sender, EventArgs e)
{
MedicineMainForm aa3 = new MedicineMainForm();
this.Visible = false;
aa3.ShowDialog();
}
private void aDMINPATIENTSToolStripMenuItem_Click(object sender, EventArgs e)
{
AdmitPatientForm aa5 = new AdmitPatientForm();
this.Visible = false;
aa5.ShowDialog();
}
private void bACKTOMENUToolStripMenuItem_Click(object sender, EventArgs e)
{
AdminMainForm aa6 = new AdminMainForm();
this.Visible = false;
aa6.ShowDialog();
}
}
}
-----------------------------------------------------------------------------------------------------------------------------
Form Add Receptionist ( Menu ADD RECEPTIONIS)
Source code Add Reception.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.TaskbarClock;
namespace Medical
{
public partial class AddReceptionis : Form
{
SqlConnection con = new SqlConnection(@"Data Source=LAPTOP-NM70SCK9;Initial Catalog=Hospital;Persist Security Info=True;User ID=sa;Password=12345678;TrustServerCertificate=True");
String Gender = " ";
public AddReceptionis()
{
InitializeComponent();
TimeToday.Start();
}
private void TimeToday_Tick(object sender, EventArgs e)
{
DateTime dt = DateTime.Now;
Todaydatetime.Text = dt.ToString();
}
private void Insertbtn_Click(object sender, EventArgs e)
{
con.Open();
try
{
SqlCommand commandR;
SqlDataAdapter adaptorR = new SqlDataAdapter();
String sqlr = "insert into Receptiontb (ReceptionistName,ReceptionistPassword,DateOfBirth,DateOfJoining,ReceptionistGender,ReceptionistAddress,ReceptionistEmail,ReceptionistPhoneNo,ReceptionistSalary) values ('" + this.ReceptionistNametxt.Text + "','" + this.ReceptionistPasswordtxt.Text + "','" + this.DOBOfReceptionist.Text + "','" + this.DOJOfReceptionist.Text + "','" + this.Gender + "','" + this.ReceptionistAddresstxt.Text + "','" + this.ReceptionistEmailtxt.Text + "','" + this.ReceptionistPhoneNo.Text + "','" + this.ReceptionistSalary.Text + "')";
commandR = new SqlCommand(sqlr, con);
adaptorR.InsertCommand = new SqlCommand(sqlr, con);
adaptorR.InsertCommand.ExecuteNonQuery();
commandR.Dispose();
con.Close();
ReceptionistDetails();
ReceptionistNametxt.Text = "";
ReceptionistPasswordtxt.Text = "";
ReceptionistPhoneNo.Text = "";
ReceptionistSalary.Text = "";
ReceptionistAddresstxt.Text = "";
ReceptionistSearchtxt.Text = "";
MessageBox.Show("Record SuccessFully Inserted");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void Updatebtn_Click(object sender, EventArgs e)
{
con.Open();
try
{
String updatere = "Update Receptiontb set ReceptionistName = '" + this.ReceptionistNametxt.Text + "' , ReceptionistPassword = '" + this.ReceptionistPasswordtxt.Text + "' , DateOfBirth = '" + this.DOBOfReceptionist.Text + "' , DateOfJoining = '" + this.DOJOfReceptionist.Text + "' , ReceptionistGender = '" + this.Gender + "' , ReceptionistAddress = '" + this.ReceptionistAddresstxt.Text + "' , ReceptionistEmail = '" + this.ReceptionistEmailtxt.Text + "' , ReceptionistPhoneNo = '" + this.ReceptionistPhoneNo.Text + "' , ReceptionistSalary = '" + this.ReceptionistSalary.Text + "' where RID = '" + this.ReceptionistSearchtxt.Text + "';";
SqlCommand updatecommand12;
updatecommand12 = new SqlCommand(updatere, con);
SqlDataAdapter UpdateadaptorR = new SqlDataAdapter(updatere, con);
UpdateadaptorR.UpdateCommand = new SqlCommand(updatere, con);
UpdateadaptorR.UpdateCommand.ExecuteNonQuery();
con.Close();
ReceptionistDetails();
ReceptionistNametxt.Text = "";
ReceptionistPasswordtxt.Text = "";
ReceptionistPhoneNo.Text = "";
ReceptionistSalary.Text = "";
ReceptionistAddresstxt.Text = "";
ReceptionistSearchtxt.Text = "";
MessageBox.Show("Record SuccessFully Updated");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void Deletebtn_Click(object sender, EventArgs e)
{
con.Open();
try
{
string deletere = "delete from receptiontb WHERE RID = '" + ReceptionistSearchtxt.Text + "'";
SqlCommand deletecommand1;
deletecommand1 = new SqlCommand(deletere, con);
SqlDataAdapter deleteadaptor01 = new SqlDataAdapter(deletere, con);
deleteadaptor01.DeleteCommand = new SqlCommand(deletere, con);
deleteadaptor01.DeleteCommand.ExecuteNonQuery();
con.Close();
ReceptionistDetails();
ReceptionistNametxt.Text = "";
ReceptionistPasswordtxt.Text = "";
ReceptionistPhoneNo.Text = "";
ReceptionistSalary.Text = "";
ReceptionistAddresstxt.Text = "";
ReceptionistSearchtxt.Text = "";
MessageBox.Show("Record Delete SuccessFully");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void Cleartxtbtn_Click(object sender, EventArgs e)
{
ReceptionistNametxt.Text = "";
Gender = "";
DOBOfReceptionist.Text = "";
DOJOfReceptionist.Text = "";
ReceptionistPasswordtxt.Text = "";
ReceptionistPhoneNo.Text = "";
ReceptionistSalary.Text = "";
ReceptionistEmailtxt.Text = "";
ReceptionistAddresstxt.Text = "";
ReceptionistSearchtxt.Text = "";
}
private void Searchbtn_Click(object sender, EventArgs e)
{
con.Open();
string st = "select * from Receptiontb WHERE RID = '" + ReceptionistSearchtxt.Text + "'";
SqlCommand cmdr = new SqlCommand(st, con);
SqlDataReader sd;
sd = cmdr.ExecuteReader();
if (sd.Read())
{
this.ReceptionistNametxt.Text = sd["ReceptionistName"].ToString();
this.ReceptionistPasswordtxt.Text = sd["ReceptionistPassword"].ToString();
this.DOBOfReceptionist.Text = sd["DateOfBirth"].ToString();
this.DOJOfReceptionist.Text = sd["DateOfJoining"].ToString();
this.Gender = sd["ReceptionistGender"].ToString();
this.ReceptionistAddresstxt.Text = sd["ReceptionistAddress"].ToString();
this.ReceptionistEmailtxt.Text = sd["ReceptionistEmail"].ToString();
this.ReceptionistPhoneNo.Text = sd["ReceptionistPhoneNo"].ToString();
this.ReceptionistSalary.Text = sd["ReceptionistSalary"].ToString();
}
else
{
MessageBox.Show("Record Not Found");
}
con.Close();
}
private void AddReceptionis_Load(object sender, EventArgs e)
{
ReceptionistDetails();
}
public void ReceptionistDetails()
{
using (SqlConnection c2 = new SqlConnection(@"Data Source=LAPTOP-NM70SCK9;Initial Catalog=Hospital;Integrated Security=True;TrustServerCertificate=True"))
{
c2.Open();
// Create new DataAdapter
using (SqlDataAdapter a2 = new SqlDataAdapter("SELECT * FROM Receptiontb", con))
{
// Use DataAdapter to fill DataTable
DataTable t2 = new DataTable();
a2.Fill(t2);
// Render data onto the screen
AddReceptionistDetails.DataSource = t2;
}
c2.Close();
}
}
private void ReceptionistGenderMale_CheckedChanged(object sender, EventArgs e)
{
Gender = "Male";
}
private void receptionistGenderFemale_CheckedChanged(object sender, EventArgs e)
{
Gender = "Female";
}
private void dIVISIONDOCTORSToolStripMenuItem_Click(object sender, EventArgs e)
{
AddDoctor aa1 = new AddDoctor();
this.Visible = false;
aa1.ShowDialog();
}
private void mEDICINEMANAGEMENTToolStripMenuItem_Click(object sender, EventArgs e)
{
MedicineMainForm aa3 = new MedicineMainForm();
this.Visible = false;
aa3.ShowDialog();
}
private void aDMINPATIENTSToolStripMenuItem_Click(object sender, EventArgs e)
{
AdmitPatientForm aa5 = new AdmitPatientForm();
this.Visible = false;
aa5.ShowDialog();
}
private void bACKTOMENUToolStripMenuItem_Click(object sender, EventArgs e)
{
AdminMainForm aa6 = new AdminMainForm();
this.Visible = false;
aa6.ShowDialog();
}
}
}
-----------------------------------------------------------------------------------------------------------------------------
Form MedicineMainForm ( Menu MEDICINE AND ROOM)
Source code MedicineMainForm.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Medical
{
public partial class MedicineMainForm : Form
{
SqlConnection conn = new SqlConnection(@"Data Source=LAPTOP-NM70SCK9;Initial Catalog=Hospital;Persist Security Info=True;User ID=sa;Password=12345678;TrustServerCertificate=True");
public MedicineMainForm()
{
InitializeComponent();
TimeToday.Start();
}
private void TimeToday_Tick(object sender, EventArgs e)
{
DateTime dt = DateTime.Now;
Todaydatetime.Text = dt.ToString();
}
private void Insertbtn_Click(object sender, EventArgs e)
{
conn.Open();
try
{
SqlCommand commandm;
SqlDataAdapter adaptorm = new SqlDataAdapter();
String sql = "insert into Medicinetb (MedicineName) values ('" + MedicineNametxt.Text + "')";
commandm = new SqlCommand(sql, conn);
adaptorm.InsertCommand = new SqlCommand(sql, conn);
adaptorm.InsertCommand.ExecuteNonQuery();
commandm.Dispose();
medicinedt();
MessageBox.Show("Record Insert Successfully");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
conn.Close();
}
private void Updatebtn_Click(object sender, EventArgs e)
{
conn.Open();
try
{
String updatecommand = "Update Medicinetb set MedicineName = '" + this.MedicineNametxt.Text + "' where MedicineID = '" + this.Medicineidtxt.Text + "';";
SqlCommand updatecommand1;
updatecommand1 = new SqlCommand(updatecommand, conn);
SqlDataAdapter Updateadaptm = new SqlDataAdapter(updatecommand, conn);
Updateadaptm.UpdateCommand = new SqlCommand(updatecommand, conn);
Updateadaptm.UpdateCommand.ExecuteNonQuery();
medicinedt();
MessageBox.Show("Record Updates SuccessFully");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
conn.Close();
}
private void Deletebtn_Click(object sender, EventArgs e)
{
conn.Open();
try
{
string deletestm = "delete from Medicinetb WHERE MedicineID = '" + Medicineidtxt.Text + "'";
SqlCommand deletecommand;
deletecommand = new SqlCommand(deletestm, conn);
SqlDataAdapter deleteadaptor = new SqlDataAdapter(deletestm, conn);
deleteadaptor.DeleteCommand = new SqlCommand(deletestm, conn);
deleteadaptor.DeleteCommand.ExecuteNonQuery();
medicinedt();
MessageBox.Show("Record delete SuccessFully");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
conn.Close();
}
private void MedicineMainForm_Load(object sender, EventArgs e)
{
medicinedt();
warddt();
}
public void medicinedt()
{
using (SqlConnection cm = new SqlConnection(@"Data Source=LAPTOP-NM70SCK9;Initial Catalog=HospitalDB;Integrated Security=True;TrustServerCertificate=True"))
{
cm.Open();
// Create new DataAdapter
using (SqlDataAdapter am = new SqlDataAdapter("SELECT * FROM Medicinetb", conn))
{
// Use DataAdapter to fill DataTable
DataTable tm = new DataTable();
am.Fill(tm);
// Render data onto the screen
MedicineDetails.DataSource = tm;
}
cm.Close();
}
}
private void Cleartxtbtn_Click(object sender, EventArgs e)
{
this.Medicineidtxt.Text = "";
this.MedicineNametxt.Text = "";
this.WardIDtxt.Text = "";
this.WardNotxt.Text = "";
String a = "";
DoctorMainForm dd = new DoctorMainForm(a);
dd.ShowDialog();
this.Close();
}
private void Addbtn_Click(object sender, EventArgs e)
{
conn.Open();
try
{
SqlCommand commandw;
SqlDataAdapter adaptorw = new SqlDataAdapter();
String sql = "insert into Wardtb (WARDNO) values ('" + WardNotxt.Text + "')";
commandw = new SqlCommand(sql, conn);
adaptorw.InsertCommand = new SqlCommand(sql, conn);
adaptorw.InsertCommand.ExecuteNonQuery();
commandw.Dispose();
warddt();
MessageBox.Show("Record Insert SuccessFully");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
conn.Close();
}
private void Deletewbtn_Click(object sender, EventArgs e)
{
conn.Open();
try
{
string deletestw = "delete from Wardtb WHERE WARDID = '" + WardIDtxt.Text + "'";
SqlCommand deletecommanw;
deletecommanw = new SqlCommand(deletestw, conn);
SqlDataAdapter deleteadaptor = new SqlDataAdapter(deletestw, conn);
deleteadaptor.DeleteCommand = new SqlCommand(deletestw, conn);
deleteadaptor.DeleteCommand.ExecuteNonQuery();
warddt();
MessageBox.Show("Record Delete SuccessFully");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
conn.Close();
}
public void warddt()
{
using (SqlConnection cmw = new SqlConnection(@"Data Source=LAPTOP-NM70SCK9;Initial Catalog=Hospital;Persist Security Info=True;User ID=sa;Password=12345678;TrustServerCertificate=True"))
{
cmw.Open();
// Create new DataAdapter
using (SqlDataAdapter amw = new SqlDataAdapter("SELECT * FROM Wardtb", conn))
{
// Use DataAdapter to fill DataTable
DataTable tmw = new DataTable();
amw.Fill(tmw);
// Render data onto the screen
Wards.DataSource = tmw;
}
cmw.Close();
}
}
private void aDDRECEPTIONISTToolStripMenuItem_Click(object sender, EventArgs e)
{
AddReceptionis aa2 = new AddReceptionis();
this.Visible = false;
aa2.ShowDialog();
}
private void dIVISIONDOCTORSToolStripMenuItem_Click(object sender, EventArgs e)
{
AddDoctor aa1 = new AddDoctor();
this.Visible = false;
aa1.ShowDialog();
}
private void aDMINPATIENTSToolStripMenuItem_Click(object sender, EventArgs e)
{
AdmitPatientForm aa5 = new AdmitPatientForm();
this.Visible = false;
aa5.ShowDialog();
}
private void bACKTOMENUToolStripMenuItem_Click(object sender, EventArgs e)
{
AdminMainForm aa6 = new AdminMainForm();
this.Visible = false;
aa6.ShowDialog();
}
}
}
-----------------------------------------------------------------------------------------------------------------------------
Form AdmitPatientForm( Menu ADMIN PATIENTS)
Source code AdmitPatientForm.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Medical
{
public partial class AdmitPatientForm : Form
{
public AdmitPatientForm()
{
InitializeComponent();
timer1.Start();
}
SqlConnection con = new SqlConnection(@"Data Source=LAPTOP-NM70SCK9;Initial Catalog=Hospital;Persist Security Info=True;User ID=sa;Password=12345678;TrustServerCertificate=True");
String Gender = " ";
public void AdmitPatientDetails()
{
using (SqlConnection c1 = new SqlConnection(@"Data Source=LAPTOP-NM70SCK9;Initial Catalog=Hospital;Persist Security Info=True;User ID=sa;Password=12345678;TrustServerCertificate=True"))
{
c1.Open();
// Create new DataAdapter
using (SqlDataAdapter a1 = new SqlDataAdapter("SELECT * FROM AdmitPatienttb", con))
{
// Use DataAdapter to fill DataTable
DataTable t1 = new DataTable();
a1.Fill(t1);
// Render data onto the screen
AdmitPatientDetail.DataSource = t1;
}
c1.Close();
}
}
private void Insertbtn_Click(object sender, EventArgs e)
{
con.Open();
try
{
SqlCommand commandad;
SqlDataAdapter adaptor = new SqlDataAdapter();
String sql = "insert into AdmitPatienttb (AdmitPatientName,AdmitPatientAge," +
"AdmitPatientGender,AdmitPatientPhoneNo,AdmitPatientAddress," +
"AdmitedDate,WardNo,TotalDayAdmit,AdmitPatientDisease,TotalBill) " +
"values ('" + this.ADpatientnametxt.Text + "'," +
"'" + this.ADpatientage.Text + "'," +
"'" + this.Gender + "','" + this.ADpatientPhoneNo.Text + "'," +
"'" + this.ADpatientAddress.Text + "','" + this.Timetoday.Text + "'," +
"'" + this.ADpatientWardNo.Text + "','" + " " + "'," +
"'" + this.ADpatientAddress.Text + "','" + " " + "')";
commandad = new SqlCommand(sql, con);
adaptor.InsertCommand = new SqlCommand(sql, con);
adaptor.InsertCommand.ExecuteNonQuery();
commandad.Dispose();
AdmitPatientDetails();
ADmitID.Text = "";
ADpatientage.Text = "";
ADpatientAddress.Text = "";
ADpatientDisease.Text = "";
ADpatientnametxt.Text = "";
ADpatientPhoneNo.Text = "";
MessageBox.Show("Record Insert SuccessFully");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
con.Close();
}
private void Updatebtn_Click(object sender, EventArgs e)
{
con.Open();
try
{
String updatecommandad = "Update AdmitPatienttb set AdmitPatientName = '" + this.ADpatientnametxt.Text + "' , AdmitPatientAge = '" + this.ADpatientage.Text + "' , AdmitPatientGender = '" + this.Gender + "' , AdmitPatientPhoneNo = '" + this.ADpatientPhoneNo.Text + "' , AdmitPatientAddress = '" + this.ADpatientAddress.Text + "' , AdmitedDate = '" + this.Timetoday.Text + "' , ReleaseDate = '" + " " + "' , WardNo = '" + this.ADpatientWardNo.Text + "' , TotalDayAdmit = '" + " " + "' , AdmitPatientDisease = '" + this.ADpatientDisease.Text + "' , TotalBill = '" + " " + "' where AdmitID = '" + this.ADmitID.Text + "';";
SqlCommand updatecommand1ad;
updatecommand1ad = new SqlCommand(updatecommandad, con);
SqlDataAdapter Updateadaptor = new SqlDataAdapter(updatecommandad, con);
Updateadaptor.UpdateCommand = new SqlCommand(updatecommandad, con);
Updateadaptor.UpdateCommand.ExecuteNonQuery();
AdmitPatientDetails();
ADmitID.Text = "";
ADpatientage.Text = "";
ADpatientAddress.Text = "";
ADpatientDisease.Text = "";
ADpatientnametxt.Text = "";
ADpatientPhoneNo.Text = "";
MessageBox.Show("Record Update SuccessFully");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
con.Close();
}
private void timer1_Tick(object sender, EventArgs e)
{
DateTime dt = DateTime.Now;
Timetoday.Text = dt.ToString();
}
private void Deletebtn_Click(object sender, EventArgs e)
{
con.Open();
try
{
string deletead = "delete from AdmitPatienttb WHERE AdmitID = '" + ADmitID.Text + "'";
SqlCommand deletecommand;
deletecommand = new SqlCommand(deletead, con);
SqlDataAdapter deleteadaptor = new SqlDataAdapter(deletead, con);
deleteadaptor.DeleteCommand = new SqlCommand(deletead, con);
deleteadaptor.DeleteCommand.ExecuteNonQuery();
AdmitPatientDetails();
ADmitID.Text = "";
ADpatientage.Text = "";
ADpatientAddress.Text = "";
ADpatientDisease.Text = "";
ADpatientnametxt.Text = "";
ADpatientPhoneNo.Text = "";
MessageBox.Show("Record Delete SuccessFully");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
con.Close();
}
private void Cleartxtbtn_Click(object sender, EventArgs e)
{
ADmitID.Text = "";
ADpatientage.Text = "";
ADpatientAddress.Text = "";
ADpatientDisease.Text = "";
ADpatientnametxt.Text = "";
ADpatientPhoneNo.Text = "";
}
private void AdmitPatientForm_Load(object sender, EventArgs e)
{
AdmitPatientDetails();
ward();
}
private void Searchbtn_Click(object sender, EventArgs e)
{
con.Open();
try
{
string str = "select * from AdmitPatienttb WHERE AdmitID = '" + ADmitID.Text + "'";
SqlCommand cmd = new SqlCommand(str, con);
SqlDataReader sdr;
sdr = cmd.ExecuteReader();
if (sdr.Read())
{
this.ADpatientnametxt.Text = sdr["AdmitPatientName"].ToString();
this.ADpatientage.Text = sdr["AdmitPatientAge"].ToString();
this.ADpatientPhoneNo.Text = sdr["AdmitPatientPhoneNo"].ToString();
this.ADpatientDisease.Text = sdr["AdmitPatientDisease"].ToString();
this.ADpatientAddress.Text = sdr["AdmitPatientAddress"].ToString();
this.Gender = sdr["AdmitPatientGender"].ToString();
}
else
{
MessageBox.Show("Record Not Found");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
con.Close();
}
public void ward()
{
con.Open();
string str1 = "select WARDNO from Wardtb ";
SqlCommand cmd = new SqlCommand(str1, con);
SqlDataReader sdr1;
sdr1 = cmd.ExecuteReader();
while (sdr1.Read())
{
String abc = sdr1["WARDNO"].ToString();
ADpatientWardNo.Items.Add(abc);
}
con.Close();
}
private void ADpatientmale_CheckedChanged(object sender, EventArgs e)
{
Gender = "Male";
}
private void ADpatientFemale_CheckedChanged(object sender, EventArgs e)
{
Gender = "Female";
}
private void dIVISIONDOCTORSToolStripMenuItem_Click(object sender, EventArgs e)
{
AddDoctor aa1 = new AddDoctor();
this.Visible = false;
aa1.ShowDialog();
}
private void aDDRECEPTIONISTToolStripMenuItem_Click(object sender, EventArgs e)
{
AddReceptionis aa2 = new AddReceptionis();
this.Visible = false;
aa2.ShowDialog();
}
private void mEDICINEMANAGEMENTToolStripMenuItem_Click(object sender, EventArgs e)
{
MedicineMainForm aa3 = new MedicineMainForm();
this.Visible = false;
aa3.ShowDialog();
}
private void bACKTOMENUToolStripMenuItem_Click(object sender, EventArgs e)
{
AdminMainForm aa3 = new AdminMainForm();
this.Visible = false;
aa3.ShowDialog();
}
}
}
-----------------------------------------------------------------------------------------------------------------------------
Untuk setting connection Visual Studio 2022 ke SQL Server Management 20 terlihat seperti gambar dibawah berikut :
Source code Connection Visual Studio 2022 ke SQL Server Management 20 pada App.Confiq
Alhamdulillah
semoga bermanfaat
selamat Mencoba.
Komentar
Posting Komentar