-
Notifications
You must be signed in to change notification settings - Fork 0
/
homepage.aspx.cs
190 lines (140 loc) · 5.92 KB
/
homepage.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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace DB_Prpject
{
public partial class homepage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
}
Session["addproduct"] = false;
if (TextBox1.Text == "")
{
allProducts();
}
}
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
if(TextBox1.Text.Trim()!= null)
{
ViewSearchedProducts();
}
else
{
//do nothing
}
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
void ViewSearchedProducts()
{
string strconnect = "Data Source=AKKHAN;Initial Catalog=dbproject;Integrated Security=True";
SqlConnection con = new SqlConnection(strconnect);
string quere = "select p.namep, p.ID , p.price,b._name ,i.Stock, p._image from product_info as p join brand as b on p.brandid = b.ID join Categorey as c on p.cid= c.ID join inventory as i on i.productID=p.ID where ( p.namep like '%' + @name + '%' OR b._name like '%' + @brand + '%' OR p.ID like '%' + @id + '%' OR c.namec like '%' + @Cname + '%' + @price+ '%')";
SqlCommand comm = new SqlCommand(quere, con);
comm.Parameters.Add("@name", SqlDbType.NVarChar).Value = TextBox1.Text;
comm.Parameters.Add("@brand", SqlDbType.NVarChar).Value = TextBox1.Text;
comm.Parameters.Add("@id", SqlDbType.NVarChar).Value = TextBox1.Text;
comm.Parameters.Add("@Cname", SqlDbType.NVarChar).Value = TextBox1.Text;
comm.Parameters.Add("@price", SqlDbType.NVarChar).Value = TextBox1.Text;
DataTable dt = new DataTable();
con.Open();
comm.ExecuteNonQuery();
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = comm;
DataSet ds = new DataSet();
da.Fill(ds);
DataList1.DataSourceID = null;
DataList1.DataSource = ds;
DataList1.DataBind();
con.Close();
}
protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
{
allProducts();
}
void allProducts()
{
string strconnect = "Data Source=AKKHAN;Initial Catalog=dbproject;Integrated Security=True";
SqlConnection con = new SqlConnection(strconnect);
string quere = "select p.namep, p.ID , p.price,b._name , p._image, i.Stock from product_info as p join brand as b on p.brandid = b.ID join inventory as i on p.ID=i.productID ";
SqlCommand comm = new SqlCommand(quere, con);
DataTable dt = new DataTable();
con.Open();
comm.ExecuteNonQuery();
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = comm;
DataSet ds = new DataSet();
da.Fill(ds);
DataList1.DataSourceID = null;
DataList1.DataSource = ds;
DataList1.DataBind();
con.Close();
}
protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
{
if (e.CommandName == "details")
{
Response.Redirect("details.aspx?id=" + e.CommandArgument.ToString());
}
if (e.CommandName == "cart")
{
if(Session["role"]==null || Session["role"].ToString()=="")
{
Response.Redirect("login.aspx");
Response.Write("<script>alert('Login First');</script>");
}
else if (Session["role"].Equals("customer"))
{
string strconnect = "Data Source=AKKHAN;Initial Catalog=dbproject;Integrated Security=True";
SqlConnection con = new SqlConnection(strconnect);
SqlCommand cmd = new SqlCommand("insertintocart", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@pid", e.CommandArgument);
cmd.Parameters.AddWithValue("cid", Session["login_id"].ToString());
SqlParameter retval = cmd.Parameters.Add("@sf", SqlDbType.Int, 16);
cmd.Parameters["@sf"].Direction = ParameterDirection.Output;
con.Open();
cmd.ExecuteNonQuery();
int retunvalue = Convert.ToInt16(cmd.Parameters["@sf"].Value);
if (retunvalue == 0)
{
Response.Write("<script>alert('Out of Stock');</script>");
}
else
{
Response.Redirect("AddtoCart.aspx");
}
}
else if(Session["role"].Equals("seller"))
{
Response.Write("<script>alert('You can't buy as a seller');</script>");
}
}
}
protected void ImageButton3_Click(object sender, ImageClickEventArgs e)
{
if (Session["role"]==null || Session["role"].ToString()=="")
{
Response.Redirect("login.aspx");
Response.Write("<script>alert('Login as a customer first');</script>");
}
else if (Session["role"].Equals("customer"))
{
Response.Redirect("AddtoCart.aspx");
}
}
protected void Button1_Click(object sender, EventArgs e)
{
}
}
}