Imports System.Data.Oledb Imports System.IO Imports System.Web.Mail Public Class doctor_res Inherits System.Web.UI.Page #Region " Web Form Designer Generated Code " 'This call is required by the Web Form Designer. Private Sub InitializeComponent() End Sub Protected WithEvents Label3 As System.Web.UI.WebControls.Label Protected WithEvents lnkhome As System.Web.UI.WebControls.LinkButton Protected WithEvents lnklogout As System.Web.UI.WebControls.LinkButton Protected WithEvents TD1 As System.Web.UI.HtmlControls.HtmlTableCell Protected WithEvents TD2 As System.Web.UI.HtmlControls.HtmlTableCell Protected WithEvents lblpatient As System.Web.UI.WebControls.Label Protected WithEvents lblcomments As System.Web.UI.WebControls.Label Protected WithEvents txtcomments As System.Web.UI.WebControls.TextBox Protected WithEvents cmdadd As System.Web.UI.WebControls.Button Protected WithEvents lblfile As System.Web.UI.WebControls.Label Protected WithEvents lnkremove As System.Web.UI.WebControls.LinkButton Protected WithEvents cmdsubmit As System.Web.UI.WebControls.Button Protected WithEvents cmdCancel As System.Web.UI.WebControls.Button Protected WithEvents file2 As System.Web.UI.HtmlControls.HtmlInputFile Protected WithEvents lbldname As System.Web.UI.WebControls.Label 'NOTE: The following placeholder declaration is required by the Web Form Designer. 'Do not delete or move it. Private designerPlaceholderDeclaration As System.Object Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init 'CODEGEN: This method call is required by the Web Form Designer 'Do not modify it using the code editor. InitializeComponent() End Sub #End Region Dim con As New ConClass, con1 As New ConClass, con2 As New ConClass Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load If Not IsPostBack() Then Dim dt() As String, freq, arp(50) As Long, ard(50) As Long, totp, totd, i, j, k Dim cmd As New OleDbCommand, Rs As OleDbDataReader Dim cmd1 As New OleDbCommand, Rs1 As OleDbDataReader, pname = "" TD1.InnerHtml = "" lbldname.Text = Session("DoctorCode") & " - " & Session("Doctorname") i = 0 cmd1.CommandText = "Select * from DoctorRequest where DoctorCode='" & Trim(Session("DoctorCode")) & "' order by ReqId" cmd1.Connection = con1.Create(Server.MapPath("db")) Rs1 = cmd1.ExecuteReader While Rs1.Read arp(i) = Rs1.GetValue(0) i = i + 1 End While Rs1.Close() cmd1.Dispose() con1.Close() totp = i If totp < 0 Then totp = 0 i = 0 cmd1.CommandText = "Select * from AdminResponse where DoctorCode='" & Trim(Session("DoctorCode")) & "' order by ResId" cmd1.Connection = con1.Create(Server.MapPath("db")) Rs1 = cmd1.ExecuteReader While Rs1.Read ard(i) = Rs1.GetValue(0) i = i + 1 End While Rs1.Close() cmd1.Dispose() con1.Close() totd = i If totd < 0 Then totd = 0 j = 0 k = 0 For i = 0 To totd + totp If arp(j) < ard(k) And arp(j) <> 0 Then freq = arp(j) j = j + 1 Else freq = ard(k) k = k + 1 End If If k < totd And j > totp Then freq = ard(k) k = k + 1 End If If j < totp And k > totd Then freq = arp(j) j = j + 1 End If cmd.CommandText = "Select * from DoctorRequest where ReqId=" & freq & " and DoctorCode='" & Trim(Session("DoctorCode")) & "'" cmd.Connection = con.Create(Server.MapPath("db")) Rs = cmd.ExecuteReader If Rs.Read Then dt = Split(Rs("dtreq"), "/") TD1.InnerHtml = TD1.InnerHtml & "On " & dt(1) & "/" & dt(0) & "/" & dt(2) & ", " & Rs("tm") & " " & Session("Doctorname") & " wrote:

" & Rs("req") & "

" End If Rs.Close() cmd.Dispose() con.Close() cmd.CommandText = "Select * from AdminResponse where ResId=" & freq & " and DoctorCode='" & Trim(Session("DoctorCode")) & "'" cmd.Connection = con.Create(Server.MapPath("db")) Rs = cmd.ExecuteReader If Rs.Read Then dt = Split(Rs("dtres"), "/") TD1.InnerHtml = TD1.InnerHtml & "On " & dt(1) & "/" & dt(0) & "/" & dt(2) & ", " & Rs("tm") & " Administrator wrote:

" & Rs("res") & "


" End If Rs.Close() cmd.Dispose() con.Close() Next End If End Sub Private Sub cmdadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdadd.Click If file2.PostedFile.FileName = "" Then Response.Write("") Exit Sub End If Dim dir As System.IO.DirectoryInfo = New System.IO.DirectoryInfo(Server.MapPath("Attachments\Doctor") & "\" & Session("PCode")) Try dir.Create() Catch ex As Exception Response.Write(ex.ToString()) End Try If dir.Exists Then Dim file() As System.IO.FileInfo = dir.GetFiles("*.*") If file.Length > 0 Then Response.Write("") Else Dim strFilename As String strFilename = file2.PostedFile.FileName strFilename = System.IO.Path.GetFileName(strFilename) file2.PostedFile.SaveAs(dir.FullName & "\" & strFilename) lblfile.Text = strFilename End If End If End Sub Private Sub lnkremove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lnkremove.Click If lblfile.Text = "" Then Exit Sub End If Dim dir As System.IO.DirectoryInfo = New System.IO.DirectoryInfo(Server.MapPath("Attachments\Doctor") & "\" & Session("Pcode")) If dir.Exists Then Dim file As System.IO.FileInfo = New System.IO.FileInfo(Server.MapPath("Attachments\Doctor") & "\" & Session("Pcode") & "\" & lblfile.Text) If file.Exists Then file.Delete() lblfile.Text = "" dir.Delete() End If End If End Sub Private Sub cmdsubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdsubmit.Click Dim cmd As New OleDbCommand, Rs As OleDbDataReader, pms As OleDbParameterCollection, strFilename As String Dim Rpid, Rdid, Rid cmd.CommandText = "Select max(ReqId) from DoctorRequest where DoctorCode='" & Trim(Session("DoctorCode")) & "'" cmd.Connection = con.Create(Server.MapPath("db")) Rs = cmd.ExecuteReader() If Rs.Read Then Rpid = Rs.GetValue(0) End If Rs.Close() cmd.Dispose() con.Close() If IsDBNull(Rpid) Then Rpid = 0 End If cmd.CommandText = "Select max(ResId) from AdminResponse where DoctorCode='" & Trim(Session("DoctorCode")) & "'" cmd.Connection = con.Create(Server.MapPath("db")) Rs = cmd.ExecuteReader() If Rs.Read Then Rdid = Rs.GetValue(0) End If Rs.Close() cmd.Dispose() con.Close() If IsDBNull(Rdid) Then Rdid = 0 End If If Rpid = 0 And Rdid = 0 Then Rid = 1 Else If Rpid > Rdid Then Rid = Rpid + 1 Else Rid = Rdid + 1 End If End If If lblfile.Text <> "" Then Dim dir As System.IO.DirectoryInfo = New System.IO.DirectoryInfo(Server.MapPath("Attachments\Doctor") & "\" & Session("PCode")) Try dir.Create() Catch ex As Exception Response.Write(ex.ToString()) End Try strFilename = lblfile.Text If dir.Exists Then Dim path As String = dir.FullName & "\" & strFilename Dim file As System.IO.FileInfo = New System.IO.FileInfo(path) Dim FSize = file.Length If file.Exists Then Dim binReader As BinaryReader = New BinaryReader(file.Open(FileMode.Open, FileAccess.Read)) binReader.BaseStream.Position = 0 Dim binFile As Byte() = binReader.ReadBytes(Convert.ToInt32(binReader.BaseStream.Length)) binReader.Close() pms = cmd.Parameters pms.Add("@ReqId", OleDbType.Numeric) pms.Add("@PatientCode", OleDbType.VarChar, 50) pms.Add("@Dtreq", OleDbType.Date) pms.Add("@patreq", OleDbType.LongVarChar) pms.Add("@Attachment", OleDbType.VarBinary) pms.Add("@FileName", OleDbType.VarChar, 100) pms.Add("@tm", OleDbType.VarChar, 100) pms("@ReqId").Value = Rid pms("@PatientCode").Value = Session("DoctorCode") pms("@Dtreq").Value = Today() pms("@patreq").Value = Trim(txtcomments.Text) pms("@Attachment").Value = binFile pms("@FileName").Value = strFilename pms("@tm").Value = Hour(Now()) & ":" & Minute(Now()) & ":" & Second(Now()) cmd.CommandType = CommandType.Text cmd.CommandText = "insert into DoctorRequest (ReqId,DoctorCode,dtReq,req,Attachment,FileName,tm) values(@ReqId,@PatientCode,@Dtreq,@patreq,@Attachment,@FileName,@tm)" cmd.Connection = con.Create(Server.MapPath("db")) cmd.ExecuteNonQuery() pms = Nothing cmd.Dispose() file.Delete() dir.Delete() con.Close() End If End If Else pms = cmd.Parameters pms.Add("@ReqId", OleDbType.Numeric) pms.Add("@PatientCode", OleDbType.VarChar, 50) pms.Add("@Dtreq", OleDbType.Date) pms.Add("@patreq", OleDbType.LongVarChar) pms.Add("@tm", OleDbType.VarChar, 100) pms("@ReqId").Value = Rid pms("@PatientCode").Value = Session("DoctorCode") pms("@Dtreq").Value = Today() pms("@patreq").Value = Trim(txtcomments.Text) pms("@tm").Value = Hour(Now()) & ":" & Minute(Now()) & ":" & Second(Now()) cmd.CommandType = CommandType.Text cmd.CommandText = "insert into DoctorRequest (ReqId,DoctorCode,dtReq,req,tm) values(@ReqId,@PatientCode,@Dtreq,@patreq,@tm)" cmd.Connection = con.Create(Server.MapPath("db")) cmd.ExecuteNonQuery() pms = Nothing cmd.Dispose() con.Close() End If 'Dim mail As New MailMessage 'mail.To = "drakabraham@gmail.com" 'mail.From = Session("email") 'mail.BodyFormat = MailFormat.Text 'mail.Subject = "Message from Patient" 'mail.Body = vbCrLf & "Dear Doctor" & vbCrLf & vbCrLf & "A Message has been submitted by " & Session("pname") & vbCrLf & "Patient Details:" & vbCrLf & "Patient Code:" & Session("pcode") & vbCrLf & "Patient name:" & Session("pname") 'Try ' SmtpMail.Send(mail) 'Catch ex As Exception 'End Try 'mail = Nothing Server.Transfer("doc_res.aspx") End Sub Private Sub lnkhome_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lnkhome.Click Server.Transfer("dochome.aspx") End Sub Private Sub lnklogout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lnklogout.Click Session.Abandon() Server.Transfer("default.aspx") End Sub Private Sub cmdCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCancel.Click Server.Transfer("dochome.aspx") End Sub End Class