-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPatientRegistration.aspx.cs
More file actions
122 lines (113 loc) · 3.75 KB
/
PatientRegistration.aspx.cs
File metadata and controls
122 lines (113 loc) · 3.75 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
public partial class PatientRegistration : System.Web.UI.Page
{
SqlConnection con;
SqlCommand cmd;
SqlDataReader rs;
void autonumber()
{
cmd = new SqlCommand("select isnull(max(pid), 1000)+1 from ptable", con);
TextBox1.Text = cmd.ExecuteScalar().ToString();
cmd.Dispose();
}
protected void Page_Load(object sender, EventArgs e)
{
try
{
Label1.Text = "";
Menu m1 = (Menu)Master.FindControl("Menu1");
m1.Visible = true;
con = new SqlConnection(ConfigurationManager.ConnectionStrings["connection"].ConnectionString);
con.Open();
if (!IsPostBack)
autonumber();
}
catch (Exception ex)
{
Label1.Text = ex.Message;
}
}
private string GenerateKey()//3
{
string s = "";
Random random = new Random();
int length = 8;
for (int i = 0; i < length; i++)
{
if (i == 3)
{
s += random.Next(1, 5);
}
if (random.Next(0, 4) == 0)
{
s += ((char)random.Next(97, 122)).ToString();
}
else if (random.Next(0, 3) == 1)
{
s += random.Next(0, 9);
}
else
{
s += ((char)random.Next(65, 90)).ToString();
}
}
return s.Trim();
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
try
{
cmd = new SqlCommand("select pid from ptable where pid=@pid", con);
cmd.Parameters.AddWithValue("pid", TextBox1.Text);
rs = cmd.ExecuteReader();
bool b = rs.Read();
rs.Close();
cmd.Dispose();
if (b)
{
Label1.Text = "Patient ID Already Found.....";
return;
}
string pkey = GenerateKey();
cmd = new SqlCommand("insert into ptable values(@pid,@pname,@gender,@age,@address,@city,@mno,@emailid,@pword,@pkey)", con);
cmd.Parameters .AddWithValue ("pid",TextBox1 .Text );
cmd.Parameters .AddWithValue ("pname",TextBox2 .Text );
cmd.Parameters .AddWithValue ("gender",RadioButtonList1 .SelectedItem .Text );
cmd.Parameters .AddWithValue ("age",TextBox3 .Text );
cmd.Parameters .AddWithValue ("address",TextBox4 .Text );
cmd.Parameters .AddWithValue ("city",TextBox5 .Text );
cmd.Parameters .AddWithValue ("mno",TextBox6 .Text );
cmd.Parameters .AddWithValue ("emailid",TextBox7 .Text );
cmd.Parameters .AddWithValue ("pword",TextBox8 .Text );
cmd.Parameters.AddWithValue("pkey", pkey);
cmd.ExecuteNonQuery();
cmd.Dispose();
Label1.Text = "Your Details Successfully Registered.Your Private Key is :" + pkey;
}
catch (Exception ex)
{
Label1.Text = ex.Message;
}
}
protected void LinkButton2_Click(object sender, EventArgs e)
{
TextBox1.Text = "";
TextBox2.Text = "";
RadioButtonList1.SelectedIndex = -1;
TextBox3.Text = "";
TextBox4.Text = "";
TextBox5.Text = "";
TextBox6.Text = "";
TextBox7.Text = "";
TextBox8.Text = "";
autonumber();
TextBox2.Focus();
}
}