-
Notifications
You must be signed in to change notification settings - Fork 0
/
ShowAd.aspx.cs
executable file
·351 lines (302 loc) · 11.2 KB
/
ShowAd.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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
using System;
using System.Text;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using AspNet.StarterKits.Classifieds.BusinessLogicLayer;
using AspNet.StarterKits.Classifieds.Web;
public partial class ShowAd_aspx : System.Web.UI.Page
{
public int AdId
{
get
{
if (ViewState["AdId"] != null)
return (int)ViewState["AdId"];
else
return 0;
}
set
{
ViewState["AdId"] = value;
}
}
public int CurrentPhotoIndex
{
get
{
if (ViewState["CurrentPhotoIndex"] != null)
return (int)ViewState["CurrentPhotoIndex"];
else
return -1;
}
set
{
ViewState["CurrentPhotoIndex"] = value;
}
}
public int NumPostBacks
{
get
{
if (ViewState["NumPostBacks"] != null)
return (int)ViewState["NumPostBacks"];
else
{
ViewState["NumPostBacks"] = 0;
return 0;
}
}
set
{
ViewState["NumPostBacks"] = value;
}
}
protected void Page_Load(object sender, EventArgs e)
{
// Check if the URL querystring contains a valid ad.
int adId = DefaultValues.IdNullValue;
string adIdQs = Request.QueryString["id"];
if (adIdQs != null && !Int32.TryParse(adIdQs, out adId))
{
Response.Redirect("~/Search.aspx");
}
if (!Page.IsPostBack)
{
if (User.Identity.IsAuthenticated)
{
this.ResponseContactEmailTextBox.Text =
this.EmailSenderAddressTextBox.Text =
Membership.GetUser().Email;
this.ResponseContactNameTextBox.Text =
this.EmailSenderNameTextBox.Text =
Profile.FirstName + " " + Profile.LastName;
}
}
}
protected void AdsDataSource_Selected(object sender, ObjectDataSourceStatusEventArgs e)
{
AdsDataComponent.AdsRow ad = e.ReturnValue as AdsDataComponent.AdsRow;
if (ad == null)
{
Response.Redirect("~/Search.aspx", true);
}
else
{
// Save the AdId to ViewState for future reference
this.AdId = ad.Id;
// fill in Form Details for "Email Form" form
StringBuilder msg = new StringBuilder();
msg.Append("Form: ");
msg.AppendLine(ad.Title);
msg.Append("Category: ");
msg.AppendLine(ad.CategoryName);
msg.Append("Code: ");
msg.AppendFormat("{0:c}", ad.Code);
msg.AppendLine();
msg.AppendLine();
msg.Append("URL: ");
msg.Append(ClassifiedsHttpApplication.SiteUrl);
if (!ClassifiedsHttpApplication.SiteUrl.EndsWith("/"))
msg.Append("/");
msg.Append("ShowAd.aspx?id=");
msg.AppendLine(ad.Id.ToString());
msg.AppendLine();
SiteSettings settings = SiteSettings.GetSharedSettings();
msg.AppendLine(settings.SiteName);
msg.AppendLine(ClassifiedsHttpApplication.SiteUrl);
EmailMessageTextBox.Text = msg.ToString();
EmailSubjectTextBox.Text = "Take a look at: " + ad.Title;
CategoryListingsLink.Text = ad.CategoryName;
CategoryListingsLink.NavigateUrl = "~/Search.aspx?c=" + ad.CategoryId.ToString();
MemberListingsLink.Text = "Other Forms posted by " + ad.MemberName;
MemberListingsLink.NavigateUrl = "~/Search.aspx?member=" + ad.MemberName;
CommonCategoryDropDown.CurrentCategoryId = ad.CategoryId;
CategoryPath.CurrentCategoryId = ad.CategoryId;
}
}
protected void RespondButton_Click(object sender, EventArgs e)
{
SetActivePanel(ResponsePanel);
}
protected void EmailAdButton_Click(object sender, EventArgs e)
{
SetActivePanel(EmailPanel);
}
protected void SaveAdButton_Click(object sender, EventArgs e)
{
if (User.Identity.IsAuthenticated)
{
AdsDB.InsertSavedAd(AdId, Profile.MemberId);
SetActivePanel(AdSavedPanel);
}
else
{
FormsAuthentication.RedirectToLoginPage();
}
}
protected void ResponseSubmitButton_Click(object sender, EventArgs e)
{
ResponseEmailRequired1.Validate();
if (Page.IsValid)
{
bool EmailSentBool =
AdsDB.SendResponse(AdId, Server.HtmlEncode(ResponseContactNameTextBox.Text), Server.HtmlEncode(ResponseContactEmailTextBox.Text), Server.HtmlEncode(ResponseCommentsTextBox.Text));
if (EmailSentBool)
SetActivePanel(EmailSentPanel);
else
SetActivePanel(EmailNotSentPanel);
}
}
protected void PhotoList_ItemCommand(object source, DataListCommandEventArgs e)
{
if (e.CommandName.Equals("ShowFullSize"))
{
int photoId = Convert.ToInt32(e.CommandArgument);
ShowFullSizePhoto(photoId);
CurrentPhotoIndex = e.Item.ItemIndex;
}
}
protected void ShowFullSizePhoto(int photoId)
{
PhotoPanel.Visible = true;
FullSizePhoto.ImageUrl = "~/PhotoDisplay.ashx?size=full&photoid=" + photoId.ToString();
SetActivePanel(PhotoPanel);
}
protected void ShowNextPhoto()
{
int currPhotoIndex = CurrentPhotoIndex;
if (currPhotoIndex != -1)
{
int nextIndex = (currPhotoIndex + 1) % PhotoList.DataKeys.Count;
int nextPhotoId = Convert.ToInt32(PhotoList.DataKeys[nextIndex]);
ShowFullSizePhoto(nextPhotoId);
CurrentPhotoIndex = nextIndex;
}
}
protected void FullSizePhoto_Click(object sender, ImageClickEventArgs e)
{
ShowNextPhoto();
}
protected void AdDetails_ItemCommand(object sender, EventArgs e)
{
/*undefined so far*/
}
protected void SetActivePanel(Panel panel)
{
if (panel == null)
return;
ResponsePanel.Visible = false;
EmailPanel.Visible = false;
PhotoPanel.Visible = false;
EmailSentPanel.Visible = false;
EmailNotSentPanel.Visible = false;
AdSavedPanel.Visible = false;
panel.Visible = true;
Page.SetFocus(AdDetailsPanel);
}
protected void HidePanel(Panel panel)
{
panel.Visible = false;
Page.SetFocus(AdDetailsPanel);
}
protected void EmailSubmitButton_Click(object sender, EventArgs e)
{
//if they enter an email
//EmailSenderAddressTextBoxValidator1.Validate();
//validate recipient
EmailRecipientAddressTextBoxValidator1.Validate();
if (Page.IsValid)
{
bool EmailSentBool =
AdsDB.SendAdInEmail(AdId, Server.HtmlEncode(EmailSenderNameTextBox.Text), Server.HtmlEncode(EmailSenderAddressTextBox.Text), Server.HtmlEncode(EmailRecipientAddressTextBox.Text), Server.HtmlEncode(EmailSubjectTextBox.Text), Server.HtmlEncode(EmailMessageTextBox.Text));
if (EmailSentBool)
SetActivePanel(EmailSentPanel);
else
SetActivePanel(EmailNotSentPanel);
}
}
protected void HidePhotoPanel_Click(object sender, EventArgs e)
{
HidePanel(PhotoPanel);
}
protected void CancelResponseButton_Click(object sender, EventArgs e)
{
HidePanel(ResponsePanel);
}
protected void CancelEmailButton_Click(object sender, EventArgs e)
{
HidePanel(EmailPanel);
}
protected void CategoryPath_CategorySelectionChanged(object sender, CategorySelectionChangedEventArgs e)
{
Response.Redirect("~/Search.aspx?c=" + e.CategoryId.ToString());
}
protected void AdDetails_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
RepeaterItem item = e.Item;
AdsDataComponent.AdsRow ad = item.DataItem as AdsDataComponent.AdsRow;
if (ad != null)
{
AdTitleLabel.Text = ad.Title;
//AdPriceLabel.Text = String.Format("{0:c}", ad.Price);
//Label ExpirationLabel = item.FindControl("ExpirationLabel") as Label;
HyperLink URLLink = item.FindControl("URLLink") as HyperLink;
//Code Block
//Label AdCodeLabel = item.FindControl("AdCodeLabel") as Label;
AdCodeLabel.Text = ad.Code;
//SYNONYM BLOCK
Label LabelSyn1 = item.FindControl("LabelSyn1") as Label;
Label LabelSyn2 = item.FindControl("LabelSyn2") as Label;
Label LabelSyn3 = item.FindControl("LabelSyn3") as Label;
Label LabelSyn4 = item.FindControl("LabelSyn4") as Label;
Label LabelSyn5 = item.FindControl("LabelSyn5") as Label;
if (!Convert.IsDBNull(ad.Syn1)) //check for DBNull
{ LabelSyn1.Text = ad.Syn1; }
if (!Convert.IsDBNull(ad.Syn2))
{ LabelSyn2.Text = ad.Syn2; }
if (!Convert.IsDBNull(ad.Syn3))
{ LabelSyn3.Text = ad.Syn3; }
if (!Convert.IsDBNull(ad.Syn4))
{ LabelSyn4.Text = ad.Syn4; }
if (!Convert.IsDBNull(ad.Syn5))
{ LabelSyn5.Text = ad.Syn5; }
//URL BLOCK
if (ad.URL.Equals(String.Empty))
{
URLLink.Text = "N/A";
}
else
{
URLLink.NavigateUrl =
URLLink.NavigateUrl = ad.URL;
URLLink.Target = "_blank";
}
//STATUS BLOCK
if ((AdStatus)ad.AdStatus == AdStatus.Activated)
{
if (Profile.MemberId != ad.MemberId)
{
// check if the user has recently viewed this page
// by looking in a special cookie we set:
string adCookieKey = ad.Id.ToString();
if (Request.Cookies["ShowAd_ViewCountCookie"] == null || Request.Cookies["ShowAd_ViewCountCookie"][adCookieKey] == null)
{
Response.Cookies["ShowAd_ViewCountCookie"][adCookieKey] = String.Empty; // String.Empty is not treated as 'null' but saves a byte
Response.Cookies["ShowAd_ViewCountCookie"].Expires = DateTime.Now.AddDays(1);
AdsDB.IncrementViewCount(ad.Id);
}
}
}
else
{
AdNotActivePanel.Visible = true;
AdActions.Visible = false;
}
}
}
protected string ObjToStr(object obj)
{
return "Hi!";
}
}