-
Notifications
You must be signed in to change notification settings - Fork 1
/
Register.aspx.cs
114 lines (98 loc) · 4.14 KB
/
Register.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
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;
namespace FoodFest
{
public partial class Register : System.Web.UI.Page
{
DBConnect conn = new DBConnect();
protected void Page_Load(object sender, EventArgs e)
{
if ((Session["LoggedInUserName"] != null))
{
LinkButton LinkButton1 = (LinkButton)Master.FindControl("LinkButton1");
LinkButton1.Visible = false;
LinkButton LinkButton2 = (LinkButton)Master.FindControl("LinkButton2");
LinkButton2.Visible = false;
Label Welcome_label = (Label)Master.FindControl("Welcome_label");
Welcome_label.Text = "Welcome " + Session["LoggedInUserName"];
Welcome_label.Visible = false;
LinkButton LinkButton3 = (LinkButton)Master.FindControl("LinkButton3");
LinkButton3.Visible = false;
}
else
{
LinkButton LinkButton1 = (LinkButton)Master.FindControl("LinkButton1");
LinkButton1.Visible = false;
LinkButton LinkButton2 = (LinkButton)Master.FindControl("LinkButton2");
LinkButton2.Visible = false;
LinkButton LinkButton3 = (LinkButton)Master.FindControl("LinkButton3");
LinkButton3.Visible = false;
}
}
protected void RegisterButton_Click(object sender, EventArgs e)
{
string message = "";
bool exist = false;
try
{
conn.SqlConnectionObj.Open();
string query = String.Format("Select UserEmail from user_tbl");
conn.SqlCommandObj.CommandText = query;
SqlDataReader reader = conn.SqlCommandObj.ExecuteReader();
while (reader.Read())
{
if ( reader.GetString(0) == EmailTextBox.Text.ToString())
{
exist = true;
break;
}
else
exist = false;
}
conn.SqlConnectionObj.Close();
if (exist == false)
{
conn.SqlConnectionObj.Open();
string query2 = String.Format("INSERT INTO user_tbl(UserName,UserEmail,UserPassword,UserAddress,UserPhone,UserLevel) VALUES('{0}','{1}','{2}','{3}','{4}','{5}')", NameTextBox.Text, EmailTextBox.Text, PasswordTextBox.Text, AddressTextBox.Text, PhoneTextBox.Text,"Customer");
conn.SqlCommandObj.CommandText = query2;
conn.SqlCommandObj.ExecuteNonQuery();
message = "You have registered successfully";
msgLabel.Text = message;
}
else
msgLabel.Text = "User already exists.";
}
catch (Exception ex)
{
throw new Exception("Error occurred during user save operation. Try again", ex);
}
finally
{
if (conn.SqlConnectionObj != null && conn.SqlConnectionObj.State == ConnectionState.Open)
{
conn.SqlConnectionObj.Close();
}
NameTextBox.Text = "";
EmailTextBox.Text = "";
PasswordTextBox.Text = "";
PhoneTextBox.Text = "";
AddressTextBox.Text = "";
}
}
public bool EmailAlreadyExists(string userEmail)
{
conn.SqlConnectionObj.Open();
string query = String.Format("Select * from user_tbl where UserEmail='{0}'", userEmail);
conn.SqlCommandObj.CommandText = query;
SqlDataReader reader = conn.SqlCommandObj.ExecuteReader();
conn.SqlConnectionObj.Close();
return false;
}
}
}