Repository navigation
Expand file tree
/
Copy pathnotifications.aspx.cs
More file actions
202 lines (174 loc) · 6.86 KB
/
Copy pathnotifications.aspx.cs
File metadata and controls
202 lines (174 loc) · 6.86 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
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
191
192
193
194
195
196
197
198
199
200
201
202
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace JenStore
{
public partial class notifications1 : System.Web.UI.Page
{
string con_str = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
SqlConnection con;
SqlDataAdapter da;
DataSet ds;
SqlCommand cmd;
protected void Page_Load(object sender, EventArgs e)
{
getcon();
if (Session["UserID"] == null)
{
Response.Redirect("login_register.aspx");
return;
}
if (!IsPostBack)
{
BindAllData();
}
}
void getcon()
{
con = new SqlConnection(con_str);
con.Open();
}
void BindAllData()
{
string userId = Session["UserID"].ToString();
// Get all notifications
string query = "select * from notifications where user_id = " + userId + " order by created_date desc";
da = new SqlDataAdapter(query, con);
ds = new DataSet();
da.Fill(ds);
// Separate data into two views
DataView orderUpdates = new DataView(ds.Tables[0]);
orderUpdates.RowFilter = "notification_type = 'order'";
DataView generalUpdates = new DataView(ds.Tables[0]);
generalUpdates.RowFilter = "notification_type <> 'order'";
// Bind Order Updates
dlOrderUpdates.DataSource = orderUpdates;
dlOrderUpdates.DataBind();
pnlNoOrders.Visible = (orderUpdates.Count == 0);
// Bind General Updates
dlGeneralNotifications.DataSource = generalUpdates;
dlGeneralNotifications.DataBind();
pnlNoGeneral.Visible = (generalUpdates.Count == 0);
// Update badge counts
int orderUnread = 0;
int generalUnread = 0;
foreach (DataRow row in ds.Tables[0].Rows)
{
if (Convert.ToBoolean(row["is_read"]) == false)
{
if (row["notification_type"].ToString() == "order")
orderUnread++;
else
generalUnread++;
}
}
lblOrderBadge.Text = orderUnread.ToString();
lblOrderBadge.Visible = (orderUnread > 0);
lblGeneralBadge.Text = generalUnread.ToString();
lblGeneralBadge.Visible = (generalUnread > 0);
}
// --- Tab Switching Logic ---
protected void tab_Click(object sender, EventArgs e)
{
LinkButton clickedTab = (LinkButton)sender;
// Reset all tabs
tabOrders.CssClass = "tab-button";
tabGeneral.CssClass = "tab-button";
pnlOrders.CssClass = "tab-content";
pnlGeneral.CssClass = "tab-content";
// Set the active tab
if (clickedTab.CommandName == "Orders")
{
tabOrders.CssClass = "tab-button active";
pnlOrders.CssClass = "tab-content active";
}
else
{
tabGeneral.CssClass = "tab-button active";
pnlGeneral.CssClass = "tab-content active";
}
}
// --- Notification Actions ---
protected void dlNotifications_ItemCommand(object source, DataListCommandEventArgs e)
{
string notificationId = e.CommandArgument.ToString();
string userId = Session["UserID"].ToString();
if (e.CommandName == "MarkRead")
{
cmd = new SqlCommand("update notifications set is_read = 1 where notification_id = " + notificationId + " and user_id = " + userId, con);
cmd.ExecuteNonQuery();
}
else if (e.CommandName == "Delete")
{
cmd = new SqlCommand("delete from notifications where notification_id = " + notificationId + " and user_id = " + userId, con);
cmd.ExecuteNonQuery();
}
BindAllData(); // Refresh the list
}
protected void btnMarkAllRead_Click(object sender, EventArgs e)
{
string userId = Session["UserID"].ToString();
cmd = new SqlCommand("update notifications set is_read = 1 where user_id = " + userId + " and is_read = 0", con);
cmd.ExecuteNonQuery();
BindAllData(); // Refresh the list
}
// --- Helper Methods for Display ---
public string GetUnreadClass(object isRead)
{
return Convert.ToBoolean(isRead) ? "" : "unread";
}
public string GetTypeClass(object type)
{
switch (type.ToString().ToLower())
{
case "order": return "order-update";
case "feedback_reply": return "feedback";
case "admin": return "admin-message";
case "general": return "general";
case "promotional": return "admin-message";
default: return "general";
}
}
public string GetIconForType(object type)
{
// This is a special case for the order tab
if (type.ToString().Contains("shipped")) return "fas fa-truck";
if (type.ToString().Contains("delivered")) return "fas fa-check-circle";
if (type.ToString().Contains("processing")) return "fas fa-clock";
// This is for the general tab
switch (type.ToString().ToLower())
{
case "feedback_reply": return "fas fa-reply";
case "admin": return "fas fa-bullhorn";
case "promotional": return "fas fa-gift";
default: return "fas fa-info-circle";
}
}
public string GetTitleForType(object type)
{
switch (type.ToString().ToLower())
{
case "feedback_reply": return "Reply to Your Feedback";
case "admin": return "Message from Admin";
case "promotional": return "A Special Offer for You!";
case "general": return "General Update";
default: return "Notification";
}
}
public string GetTitleForOrder(object message)
{
string msg = message.ToString().ToLower();
if (msg.Contains("shipped")) return "Order Shipped";
if (msg.Contains("delivered")) return "Order Delivered";
if (msg.Contains("processing")) return "Order Processing";
if (msg.Contains("cancelled")) return "Order Cancelled";
return "Order Update";
}
}
}