-
Notifications
You must be signed in to change notification settings - Fork 0
/
PatientDetails.aspx.cs
174 lines (143 loc) · 5.89 KB
/
PatientDetails.aspx.cs
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web.Services;
using System.Web.Script.Services;
using System.Windows.Forms;
using System.IO;
namespace HospitalsDashboard
{
public partial class PatientDetails : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.BindRow();
}
}
private void BindRow()
{
DataTable data = new DataTable();
data.Columns.Add("PatientId");
data.Columns.Add("FirstName");
data.Columns.Add("LastName");
data.Columns.Add("Age");
data.Columns.Add("Gender");
data.Columns.Add("Nationality");
data.Columns.Add("cpr");
data.Columns.Add("Number");
data.Columns.Add("Email");
data.Rows.Add();
gvCustomers.DataSource = data;
gvCustomers.DataBind();
}
[WebMethod]
public static string GetPatients()
{
string query = "SELECT PatientId, FirstName,LastName,Age,Gender,Nationality,cpr,Number,Email FROM dbo.PatientDetails";
using (SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["con"].ConnectionString))
{
SqlCommand cmd = new SqlCommand(query);
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = conn;
sda.SelectCommand = cmd;
using (DataSet ds = new DataSet())
{
sda.Fill(ds);
return ds.GetXml();
}
}
}
}
[WebMethod]
public static string UpdatePatient(int PatientId, string fname, string lname, string gender, string country,string cpr,long number,string email)
{
string constr = ConfigurationManager.ConnectionStrings["con"].ConnectionString;
using (SqlConnection conn = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("UPDATE dbo.PatientDetails SET FirstName = @Name,LastName=@lname, Gender=@Gender,Nationality = @Country,cpr=@cpr,Number=@number,Email=@email WHERE PatientId = @PatientId"))
{
cmd.Parameters.AddWithValue("@PatientId", PatientId);
cmd.Parameters.AddWithValue("@Name", fname);
cmd.Parameters.AddWithValue("@lname", lname);
cmd.Parameters.AddWithValue("@Gender", gender);
cmd.Parameters.AddWithValue("@Country", country);
cmd.Parameters.AddWithValue("@Number", number);
cmd.Parameters.AddWithValue("@Email", email);
cmd.Parameters.AddWithValue("@cpr", cpr);
cmd.Connection = conn;
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
}
}
return "success";
}
[WebMethod]
public static int DeletePatient(int patientId)
{
try
{
string constr = ConfigurationManager.ConnectionStrings["con"].ConnectionString;
using (SqlConnection conn = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("DELETE FROM dbo.PatientDetails WHERE PatientId = @PatientId"))
{
cmd.Parameters.AddWithValue("@PatientId", patientId);
cmd.Connection = conn;
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
}
}
return 1;
}
catch (Exception e)
{
return 0;
}
}
protected void DownloadFile(object sender, EventArgs e)
{
int id = int.Parse((sender as LinkButton).CommandArgument);
byte[] bytes;
string constr = ConfigurationManager.ConnectionStrings["con"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = "select Proof from dbo.PatientDetails where Proof=@Proof";
cmd.Parameters.AddWithValue("@Id", id);
cmd.Connection = con;
con.Open();
using (SqlDataReader sdr = cmd.ExecuteReader())
{
sdr.Read();
bytes = (byte[])sdr["Proof"];
}
con.Close();
}
}
Response.Clear();
Response.Buffer = true;
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
// Response.ContentType = contentType;
// Response.AppendHeader("Content-Disposition", "attachment; filename=" + fileName);
Response.BinaryWrite(bytes);
Response.Flush();
Response.End();
}
protected void gvCustomers_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
}