-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDealerQuickLookup.aspx.cs
368 lines (312 loc) · 12.6 KB
/
DealerQuickLookup.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
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Mechsoft.GeneralUtilities;
using System.Data;
using log4net;
using Mechsoft.FleetDeal;
public partial class DealerQuickLookup : System.Web.UI.Page
{
static ILog logger = LogManager.GetLogger(typeof(DealerQuickLookup));
DataTable dtNew = null;
#region Page Load
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
txtQuickPCode.Text = "";
Label lblHeader = (Label)Master.FindControl("lblHeader");
lblHeader.Text = "Dealer Quick Lookup";
ddl_NoRecords.SelectedValue = Convert.ToString(Cls_Constants.NO_OF_ROWS_IN_REPORT);
gvDealerDetails.PageSize = Convert.ToInt32(ddl_NoRecords.SelectedValue.ToString());
ViewState[Cls_Constants.VIEWSTATE_SORTEXPRESSION] = "TotalPoints1";
ViewState[Cls_Constants.VIEWSTATE_SORTDIRECTION] = Cls_Constants.VIEWSTATE_DESC;
FillMake();
ViewState[Cls_Constants.VIEWSTATE_SORTEXPRESSION] = "FinalPoints";
ViewState[Cls_Constants.VIEWSTATE_SORTDIRECTION] = Cls_Constants.VIEWSTATE_DESC;
//btnSendBulkEnquiry.Enabled = false;
}
pnlQuick.DefaultButton = "btnSearchDealers";
}
#endregion
#region Methods
private void FillMake()
{
logger.Debug("FillMake Method Start");
Cls_MakeHelper objMake = new Cls_MakeHelper();
try
{
//get all active make
if (Cache["MAKES"] == null)
Mechsoft.GeneralUtilities.PreLoad.LoadMake();
DataTable dt = Cache["MAKES"] as DataTable;
if (dt != null)
{
//clear make dropdown
ddlQuickMake.Items.Clear();
//fill make dropdown
ddlQuickMake.DataSource = dt;
ddlQuickMake.DataTextField = "Make";
ddlQuickMake.DataValueField = "id";
ddlQuickMake.DataBind();
}
//insert default item in make dropdown
ddlQuickMake.Items.Insert(0, new ListItem("-Select Make-", "-Select-"));
}
catch (Exception ex)
{
logger.Debug("Error : " + ex.Message);
throw;
}
finally
{
logger.Debug("FillMake Method End");
}
}
public void DealerDetails()
{
Cls_Dealer objDealer = new Cls_Dealer();
DataTable dt = null;
try
{
objDealer.PostalCode = txtQuickPCode.Text;
objDealer.MakeID = Convert.ToInt32(ddlQuickMake.SelectedValue);
dt = objDealer.SearchDealersForMakeInCities();
ViewState["dtDealers"] = dt;
if (dt.Rows.Count > 0)
{
pnlDealerDetails.Visible = true;
}
//dtNew = new DataTable();
//dtNew = dt.Copy();//(DataTable)ViewState["dtDealers"];
DataColumn dcFinalPoints = new DataColumn("FinalPoints");
dcFinalPoints.DataType = typeof(Double);
dt.Columns.Add(dcFinalPoints);
//dtNew.Columns.Add(dcFinalPoints);
//dtNew.Columns[0].AllowDBNull = true;
//dtNew.Columns[7].AllowDBNull = true;
//dtNew.Columns[11].AllowDBNull = true;
//dtNew.Columns[12].AllowDBNull = true;
//dtNew.Columns[14].AllowDBNull = true;
//dtNew.Columns[15].AllowDBNull = true;
Int32 i = 0;
foreach (DataRow dr in dt.Rows)
{
#region Added by Archana : On 16 April 2012
bool IsOutsideDealer = Convert.ToBoolean((Convert.ToString(dr["IsOutsideDealer"]).ToLower()));
bool IsHotDealer = !string.IsNullOrEmpty(Convert.ToString(dr["IsHotDealer"])) ? Convert.ToBoolean(Convert.ToString(dr["IsHotDealer"])) : false;
Double FinalPoints = 1, _totRating = 0;
if (!String.IsNullOrEmpty(Convert.ToString(dr["Rating"])))
{
_totRating = Math.Round(Convert.ToDouble(Convert.ToString(dr["Rating"])), 1);
}
Double kms = !String.IsNullOrEmpty(Convert.ToString(dr["kms"])) ? Convert.ToDouble(Convert.ToString(dr["kms"])) : 0;
Double TotalPoints = Convert.ToDouble(Convert.ToString(dr["TotalPoints"]));
if (kms > 100)
{
FinalPoints = (0.75 * FinalPoints);
}
if (_totRating > 8 && Convert.ToInt32(Convert.ToString(dr["Total"])) >= 5)
{
FinalPoints = (1.5 * FinalPoints);
}
if (_totRating < 5 && Convert.ToInt32(Convert.ToString(dr["Total"])) >= 5)
{
FinalPoints = (0.5 * FinalPoints);
}
FinalPoints = IsHotDealer ? 1.5 * FinalPoints : FinalPoints;
FinalPoints = IsOutsideDealer ? 0.6 * FinalPoints : FinalPoints;
FinalPoints = TotalPoints * FinalPoints;
// if (dtNew != null)
// {
dt.Rows[i]["FinalPoints"] = FinalPoints;
// }
i++;
#endregion
}
// DataView dvFinal = dtNew.DefaultView;
DataView dvFinal = dt.DefaultView;
dvFinal.Sort = string.Format("{0} {1}", ViewState[Cls_Constants.VIEWSTATE_SORTEXPRESSION].ToString(), ViewState[Cls_Constants.VIEWSTATE_SORTDIRECTION].ToString());
DataTable dtDealersDetails = dvFinal.ToTable();
gvDealerDetails.DataSource = dtDealersDetails;
gvDealerDetails.DataBind();
}
catch (Exception ex)
{
logger.Error("btnSearchDealers_Click Event : " + ex.Message);
}
}
private void DefineSortDirection()
{
if (ViewState[Cls_Constants.VIEWSTATE_SORTEXPRESSION] != null)
{
if (ViewState[Cls_Constants.VIEWSTATE_SORTDIRECTION].ToString() == Cls_Constants.VIEWSTATE_ASC)
{
ViewState[Cls_Constants.VIEWSTATE_SORTDIRECTION] = Cls_Constants.VIEWSTATE_DESC;
}
else
{
ViewState[Cls_Constants.VIEWSTATE_SORTDIRECTION] = Cls_Constants.VIEWSTATE_ASC;
}
}
}
public void hidePopupDiv()
{
divpopID.Visible = false;
}
#endregion
#region Events
protected void btnSearchDealers_Click(object sender, ImageClickEventArgs e)
{
DealerDetails();
}
protected void gvDealerDetails_RowDataBound(object sender, GridViewRowEventArgs e)
{
try
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
ImageButton btnSelect = (ImageButton)e.Row.FindControl("btnSelect");
//for rating of dealer
Label lblRating = (Label)e.Row.FindControl("lblRating");
if (lblRating.Text != String.Empty && lblRating.Text != null)
{
string tot = Convert.ToString(Math.Round(Convert.ToDouble(lblRating.Text), 1)) + "<sub>(" + Convert.ToString(((HiddenField)e.Row.FindControl("hdfTot")).Value) + ")</sub>";
lblRating.Text = tot;
}
else
{
lblRating.Text = "--";
lblRating.ToolTip = "Yet not Rated";
}
string showbtn = DataBinder.Eval(e.Row.DataItem, "ShowSelectButton").ToString();
if (showbtn.ToLower().ToString() == "true")
{
btnSelect.Enabled = true;
btnSelect.ImageUrl = "~/Images/Select_dealer.gif";
}
else
{
btnSelect.Enabled = false;
btnSelect.ImageUrl = "~/Images/Select_dealer_disabled.gif";
}
if (((System.Data.DataRowView)(e.Row.DataItem)).Row.ItemArray[12].ToString().ToLower() == "true")
{
// e.Row.CssClass = "datalistHotDealer";
e.Row.Cells[0].CssClass = "temp"; // add css for hot dealer to add Flame image
}
else if (((System.Data.DataRowView)(e.Row.DataItem)).Row.ItemArray[24].ToString().ToLower() == "true")
{
e.Row.Cells[0].CssClass = "temp1";
}
if (((System.Data.DataRowView)(e.Row.DataItem)).Row.ItemArray[15].ToString().ToLower() == "true")
{
e.Row.CssClass = "datalistOutSideDealer";
}
else
{
e.Row.CssClass = "datalistNormalDealer";
}
CheckBox chk = (CheckBox)e.Row.FindControl("chkSelect");
chk.Attributes.Add("onclick", "javascript:EnableBulkEnq('" + chk.ClientID + "')");
//chk.Attributes.Add("onclick", "javascript:SelectAll();");
}
}
catch (Exception ex)
{
logger.Error("gvDealerDetails_RowDataBound_Event :" + ex.Message);
}
}
protected void gvDealerDetails_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
try
{
gvDealerDetails.PageIndex = e.NewPageIndex;
gvDealerDetails.DataSource = (DataTable)ViewState["dtDealers"];
gvDealerDetails.DataBind();
// BindDealers((DataTable)ViewState["dtDealers"]);
}
catch (Exception ex)
{
logger.Error("gvDealerDetails_PageIndexChanging Event :" + ex.Message);
}
}
protected void gvDealerDetails_Sorting(object sender, GridViewSortEventArgs e)
{
ViewState[Cls_Constants.VIEWSTATE_SORTEXPRESSION] = e.SortExpression;
//Swap sort direction
this.DefineSortDirection();
DealerDetails();
}
protected void ddl_NoRecords_SelectedIndexChanged(object sender, EventArgs e)
{
gvDealerDetails.PageIndex = 0;
if (ddl_NoRecords.SelectedValue.ToString() == "All")
{
gvDealerDetails.DataSource = (DataTable)ViewState["dtDealers"];
gvDealerDetails.PageSize = gvDealerDetails.PageCount * gvDealerDetails.Rows.Count;
gvDealerDetails.DataBind();
}
else
{
gvDealerDetails.DataSource = (DataTable)ViewState["dtDealers"];
gvDealerDetails.PageSize = Convert.ToInt32(ddl_NoRecords.SelectedValue.ToString());
gvDealerDetails.DataBind();
}
}
protected void btnSendBulkEnquiry_Click(object sender, EventArgs e)
{
ConfigValues objConfigue = new ConfigValues();
objConfigue.Key = "NO_OF_DEALERS_TO_SEND_MAIL";
int LimitDealerCnt = Convert.ToInt16(objConfigue.GetValue(objConfigue.Key));
int count = 0;
Page page = HttpContext.Current.Handler as Page;
foreach (GridViewRow gr in gvDealerDetails.Rows)
{
CheckBox chk = (CheckBox)gr.FindControl("chkSelect");
if (chk.Checked)
{
count++;
}
}
if (count < 1)
{
ScriptManager.RegisterStartupScript(page, page.GetType(), "err_msg", "alert('Please select atleast one dealer to send mail.');", true);
return;
}
string str = "Total number of dealers should not exceeds " + LimitDealerCnt.ToString();
if (count > LimitDealerCnt)
{
ScriptManager.RegisterStartupScript(page, page.GetType(), "err_msg", "alert('" + str + "');", true);
return;
}
else
{
btnSendBulkEnquiry.Enabled = true;
DataTable dt = new DataTable();
DataColumn dcID = new DataColumn("DealerID");
DataColumn dcEmailID = new DataColumn("DealerEmailID");
dt.Columns.Add(dcID);
dt.Columns.Add(dcEmailID);
DataRow dr;
foreach (GridViewRow gr in gvDealerDetails.Rows)
{
CheckBox chk = (CheckBox)gr.FindControl("chkSelect");
if (chk.Checked)
{
dr = dt.NewRow();
dr["DealerID"] = (((HiddenField)gr.FindControl("hfDealerID")).Value).ToString();
dr["DealerEmailID"] = (((Label)gr.FindControl("lblEmail")).Text).ToString();
dt.Rows.Add(dr);
}
}
Session["DealerInfo"] = dt;
divpopID.Visible = true;
UCEnquiry.ShowHideDivs();
}
}
#endregion
}