-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRegistration.aspx.cs
174 lines (153 loc) · 5.89 KB
/
Registration.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.Drawing;
using System.Data.SqlClient;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Globalization;
public partial class Registration : System.Web.UI.Page
{
// read the coonection string from web.config
string conString = ConfigurationManager.ConnectionStrings["DatabaseConnecting"].ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{
CheckUsername();
CheckEmail();
if(!IsPostBack)
{
DropListEducationLv();
}
}
protected void DropListEducationLv()
{
SqlConnection con = new SqlConnection(conString);
SqlCommand cmd = new SqlCommand("SELECT * FROM [Tbl_EduLevel]", con);
con.Open();
//education droplist
DropEducation.DataSource = cmd.ExecuteReader();
DropEducation.DataValueField = "EduLevelID";
DropEducation.DataTextField = "EduLevelName";
DropEducation.DataBind();
DropEducation.Items.Insert(0, new ListItem("Select Educational level", "0"));
con.Close();
}
protected void btnsignup_Click(object sender, EventArgs e)
{
try
{
if (txtname.BackColor == Color.LightCoral || txtname.BackColor == Color.LightCoral)
{
Response.Write("<script> alert('there are name or email are used!'); </script>");
}
else if (txtname.BackColor == Color.LightGreen || txtname.BackColor == Color.LightGreen)
{
Session["Name"] = txtname.Text;
SqlConnection con = new SqlConnection(conString);
SqlCommand cmd = new SqlCommand("Insert into Tbl_User (FName,LName,Username,Email,Password,Phone,UserType,EduLevel,Level,Status,DateTime) values (N'" + txtFname.Text.Trim() + "', N'" + txtLname.Text.Trim() + "', '" + txtname.Text.Trim() + "','" + txtemail.Text.Trim() + "',N'" + txtpassword.Text.Trim() + "','" + txtPhone.Text.Trim() + "','student','" + DropEducation.SelectedItem + "','" + DropLevel.SelectedItem+ "','0','" + DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss tt", CultureInfo.InvariantCulture) + "')", con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
Response.Redirect("Login.aspx");
}
else
{
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Javascript", "alert('Error : there is problem!'); ", true);
}
}
catch(Exception e1)
{
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Javascript", "alert('Error : " + e1.Message + "'); ", true);
}
}
//*****************************************//costractor to take value in session to display in other page;*************//
protected void txtname_TextChanged(object sender, EventArgs e)
{
CheckUsername();
}
protected void txtemail_TextChanged(object sender, EventArgs e)
{
CheckEmail();
}
//*******************method check data******************************//
protected void CheckUsername()
{
SqlConnection con = new SqlConnection(conString);
//confirm from user on database!!
SqlCommand cmd = new SqlCommand("select * from Tbl_User where Username='" + txtname.Text.Trim() + "'", con);
con.Open();
SqlDataReader read = cmd.ExecuteReader();
if (string.IsNullOrWhiteSpace(txtname.Text))
{
txtname.BackColor = Color.Empty;
}
else
{
if (read.HasRows)
{
txtname.BackColor = Color.LightCoral;
txtname.ToolTip = "Not Available ❌";
txtname.Focus();
}
else
{
txtname.BackColor = Color.LightGreen;
txtname.ToolTip = "Available ✔";
}
}
con.Close();
}
//*******************method check data******************************//
protected void CheckEmail()
{
SqlConnection con = new SqlConnection(conString);
//confirm from email on database!!
SqlCommand cmd = new SqlCommand("select * from Tbl_User where Email='" + txtemail.Text.Trim() + "'", con);
con.Open();
SqlDataReader read = cmd.ExecuteReader();
if (string.IsNullOrWhiteSpace(txtemail.Text))
{
txtemail.BackColor = Color.Empty;
}
else
{
if (read.HasRows)
{
txtemail.BackColor = Color.LightCoral;
txtemail.ToolTip = "Not Available ❌";
txtemail.Focus();
}
else
{
txtemail.BackColor = Color.LightGreen;
txtemail.ToolTip = "Available ✔";
}
}
con.Close();
}
protected void DropEducation_SelectedIndexChanged(object sender, EventArgs e)
{
if (DropEducation.SelectedIndex != 0)
{
DropLevel.Enabled = true;
}
SqlConnection con = new SqlConnection(conString);
SqlCommand cmd = new SqlCommand("SELECT * FROM [Tbl_Level] WHERE [EduLevelID] = '" + DropEducation.SelectedValue + "'", con);
con.Open();
//education droplist
DropLevel.DataSource = cmd.ExecuteReader();
DropLevel.DataValueField = "LevelID";
DropLevel.DataTextField = "LevelNumber";
DropLevel.DataBind();
DropLevel.Items.Insert(0, new ListItem("Select Level", "0"));
con.Close();
}
protected override void OnPreRender(EventArgs e) //to keep password in filed
{
txtpassword.Attributes.Add("value", txtpassword.Text);
txtcpassword.Attributes.Add("value", txtcpassword.Text);
base.OnPreRender(e);
}
}