-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDoctors.aspx.vb
More file actions
137 lines (113 loc) · 5.67 KB
/
Doctors.aspx.vb
File metadata and controls
137 lines (113 loc) · 5.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
Imports System.Data
Imports Oracle.ManagedDataAccess.Client
Public Class Doctors
Inherits System.Web.UI.Page
Private Const connectionString As String = "User Id=SYS;Password=system;Data Source=Aniket10;DBA Privilege=SYSDBA"
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
' Any initial load logic if needed
Dim updater As New Doctors()
updater.AddStatusColumnAndSetDefault()
End If
End Sub
Protected Sub btnViewProfile_Click(sender As Object, e As EventArgs)
Dim doctorID As String = txtDoctorID.Text.Trim()
If Not String.IsNullOrEmpty(doctorID) Then
LoadDoctorProfile(doctorID)
Dim doctorName As String = GetDoctorNameByID(doctorID)
If Not String.IsNullOrEmpty(doctorName) Then
LoadDoctorAppointments(doctorName)
End If
End If
End Sub
Private Function GetDoctorNameByID(doctorID As String) As String
Dim doctorName As String = String.Empty
Dim query As String = "SELECT Name FROM Doctors WHERE ID = :doctorID"
Using conn As New OracleConnection(connectionString)
Using cmd As New OracleCommand(query, conn)
cmd.Parameters.Add(New OracleParameter("ID", doctorID))
conn.Open()
Dim result As Object = cmd.ExecuteScalar()
If result IsNot DBNull.Value Then
doctorName = result.ToString()
End If
End Using
End Using
Return doctorName
End Function
Private Sub LoadDoctorProfile(doctorID As String)
Dim query As String = "SELECT Name, Specialisation, PhoneNo FROM Doctors WHERE ID = :DoctorID"
Using conn As New OracleConnection(connectionString)
Using cmd As New OracleCommand(query, conn)
cmd.Parameters.Add(New OracleParameter("ID", doctorID))
conn.Open()
Using reader As OracleDataReader = cmd.ExecuteReader()
If reader.Read() Then
lblDoctorProfile.Text = "Doctor Name: " & reader("Name").ToString() & "<br />" &
"Specialisation: " & reader("Specialisation").ToString() & "<br />" &
"Phone No: " & reader("PhoneNo").ToString()
Else
lblDoctorProfile.Text = "No doctor found with ID: " & doctorID
End If
End Using
End Using
End Using
End Sub
Private Sub LoadDoctorAppointments(doctorName As String)
Dim query As String = "SELECT e.AppointmentID, e.DependentName, e.AppointmentDate, e.Slot,e.Status FROM Appointments e, Doctors d WHERE d.Name = e.Doctor AND d.Name =:doctorName and e.Doctor =:doctorName"
Using conn As New OracleConnection(connectionString)
Using cmd As New OracleCommand(query, conn)
cmd.Parameters.Add(New OracleParameter("Name", doctorName))
conn.Open()
Using adapter As New OracleDataAdapter(cmd)
Dim appointments As New DataTable()
adapter.Fill(appointments)
gvAppointments.DataSource = appointments
gvAppointments.DataBind()
End Using
End Using
End Using
End Sub
Protected Sub chkStatus_CheckedChanged(sender As Object, e As EventArgs)
Dim chkStatus As CheckBox = CType(sender, CheckBox)
Dim Row As GridViewRow = CType(chkStatus.NamingContainer, GridViewRow)
Dim appointmentID As String = gvAppointments.DataKeys(Row.RowIndex).Value.ToString()
Dim status As String = If(chkStatus.Checked, "Yes", "No")
UpdateAppointmentStatus(appointmentID, status)
End Sub
Private Sub UpdateAppointmentStatus(appointmentID As String, status As String)
Dim query As String = "UPDATE Appointments SET Status = :Status WHERE AppointmentID = :AppointmentID"
Using conn As New OracleConnection(connectionString)
Using cmd As New OracleCommand(query, conn)
cmd.Parameters.Add(New OracleParameter("Status", status))
cmd.Parameters.Add(New OracleParameter("AppointmentID", appointmentID))
conn.Open()
cmd.ExecuteNonQuery()
End Using
End Using
End Sub
Public Sub AddStatusColumnAndSetDefault()
Using conn As New OracleConnection(connectionString)
conn.Open()
' Add the Status column if it does not exist
Dim addColumnQuery As String = "ALTER TABLE Appointments ADD (Status VARCHAR2(10) DEFAULT 'No' NOT NULL)"
Using cmd As New OracleCommand(addColumnQuery, conn)
Try
cmd.ExecuteNonQuery()
Catch ex As OracleException When ex.Number = 1430 ' ORA-01430: column being added already exists
' Column already exists, do nothing
End Try
End Using
' Update all rows to set Status to 'No' if they are NULL
Dim updateColumnQuery As String = "UPDATE Appointments SET Status = 'No' WHERE Status IS NULL"
Using cmd As New OracleCommand(updateColumnQuery, conn)
cmd.ExecuteNonQuery()
End Using
End Using
End Sub
Protected Sub gvAppointments_RowDataBound(sender As Object, e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
e.Row.Cells(0).Text = (e.Row.RowIndex + 1).ToString()
End If
End Sub
End Class