· 10 years ago · Aug 08, 2016, 02:57 AM
1$(function () {
2 $("#btnAddEmploymentDetailSave").click(function () {
3 var status = $('#Employment_Dialog_Employment_Status').val();
4 if ($('#Employment_Dialog_Applicant').val().trim() == '') {
5 $('#emp_dial').html('Applicant(s) details not entered.');
6 $('#Employment_Dialog_Applicant').focus();
7 return false;
8 }
9 $('#Add_Employment_Dialog').modal('hide');
10 if (status == "1") {
11 EditEmployment(-1);
12 }
13 else if (status == "2") {
14 EditUnEmployment(-1);
15 }
16 else if (status == "3") {
17 EditSelfEmployed(-1);
18 }
19
20 });
21});
22
23
24
25$(function () {
26 $("#btnAddEmploymentDetailSave").click(function () {
27 var status = $('#Employment_Dialog_Employment_Status').val();
28 if ($('#Employment_Dialog_Applicant').val().trim() == '') {
29 $('#emp_dial').html('Applicant(s) details not entered.');
30 $('#Employment_Dialog_Applicant').focus();
31 return false;
32 }
33 $('#Add_Employment_Dialog').modal('hide');
34 if (status == "1") {
35 EditEmployment(-1);
36 }
37 else if (status == "2") {
38 EditUnEmployment(-1);
39 }
40 else if (status == "3") {
41 EditSelfEmployed(-1);
42 }
43
44 });
45});
46
47 $("#btnAddEditEmploymentSave").click(function () {
48 if (Validate_Employed()) {
49 //post address data
50 var employmentData = $("#frmEmployed").serializeArray();
51
52 $.ajax({
53 url: $("#AddEmployed").val(),
54 type: "POST",
55 data: employmentData,
56 success: function (sdata1, textStatus, jqXHR) {
57
58 //// bind partial
59 $.ajax({
60 url: $("#GetEmploymentList").val(),
61 type: "GET",
62 data: { ClientRegistrationID: $("#ClientRegistrationID").val() },
63 success: function (sdata, textStatus, jqXHR) {
64 $("#dv_Employment").html(sdata);
65 }
66 });
67
68 // close dialog
69 $("#EmploymentDialog").modal('hide');
70 }
71 });
72 }
73 else {
74 $("#AddEditEmployed_error").html('Please fill mandatory fields !');
75 }
76 });
77
78
79 public List<ContentTypeModels> BindLongTermAuthenticatedList(Int64 PlanBinId)
80 {
81 List<ContentTypeModels> ContentTypeModelList = new List<ContentTypeModels>();
82 try
83 {
84 DataSet ds = repo.GetContentTypeForReport(PlanBinId);
85 if (ds != null && ds.Tables.Count > 0)
86 {
87 if (ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0)
88 {
89 foreach (DataRow row in ds.Tables[0].Rows)
90 {
91 ContentTypeModels contenttypemodel = new ContentTypeModels();
92 contenttypemodel.IdPlanTitleContentTypeNew = Utility.UserAuthorize.Data(row, "ID_PLAN_TITLE_CONTENT_TYPE") != null ? Convert.ToInt64(Utility.UserAuthorize.Data(row, "ID_PLAN_TITLE_CONTENT_TYPE")) : 0;
93 contenttypemodel.ContentTypeName = Utility.UserAuthorize.Data(row, "TITLE_CONTENT_TYPE") != null ? Convert.ToString(Utility.UserAuthorize.Data(row, "TITLE_CONTENT_TYPE")) : string.Empty;
94 contenttypemodel.Quality = Utility.UserAuthorize.Data(row, "CONTENT_QTY") != null ? Convert.ToString(Utility.UserAuthorize.Data(row, "CONTENT_QTY")) : string.Empty;
95 contenttypemodel.FrequencyId = Utility.UserAuthorize.Data(row, "RID_CONTENT_TYPE_FREQUENCY") != null ? Convert.ToInt32(Utility.UserAuthorize.Data(row, "RID_CONTENT_TYPE_FREQUENCY")) : 0;
96 contenttypemodel.LogFromOnlyAuthenticatedId = Utility.UserAuthorize.Data(row, "RID_LONG_FORM_AUTHENTICATED") != null ? Convert.ToInt32(Utility.UserAuthorize.Data(row, "RID_LONG_FORM_AUTHENTICATED")) : 0;
97 contenttypemodel.FrequencyName = Utility.UserAuthorize.Data(row, "frequencyval") != null ? Convert.ToString(Utility.UserAuthorize.Data(row, "frequencyval")) : string.Empty;
98 contenttypemodel.LongFormName = Utility.UserAuthorize.Data(row, "longformval") != null ? Convert.ToString(Utility.UserAuthorize.Data(row, "longformval")) : string.Empty;
99 ContentTypeModelList.Add(contenttypemodel);
100 }
101 }
102 }
103 }
104 catch (Exception ex)
105 {
106
107 }
108
109 return ContentTypeModelList;
110
111
112 }
113
114 }
115
116
117
118 public List<SelectListItem> refreshTypeList { get; set; }
119public void ContentSourceModelInitialize()
120 {
121 refreshTypeList = refreshTypeRepo.getRefreshType().Select(s => new SelectListItem
122 {
123 Text = s.RefreshTypeItem,
124 Value = s.RefreshTypeId.ToString()
125 }).ToList();
126
127
128public List<SelectListItem> SubContentTypeList(int ContentTypeId)
129 {
130 SubContentTypes subContentRepo = new SubContentTypes();
131 var subContentType = subContentRepo.getSubContentType(ContentTypeId).ToList();
132 List<SelectListItem> subContentTypeItem = subContentType.Select(m => new SelectListItem()
133 {
134 Text = m.SubContentTypeItem,
135 Value = m.SubContenTypeItemId.ToString(),
136 }).ToList();
137 return subContentTypeItem;
138 }
139 }
140
141
142using System;
143using System.Collections.Generic;
144using System.ComponentModel.DataAnnotations;
145using System.Linq;
146using System.Web;
147using System.Web.Mvc;
148using DigitalPlanning.Repository;
149
150namespace DigitalPlanning.Models.Proposal
151{
152
153
154 #region CreatePartySection
155 /// <summary>
156 /// Done By: Rishu
157 /// Date:31/12/15
158 /// Properties to bind with create party page
159 /// </summary>
160 public class CreatePartyModel
161 {
162 private CountryRepository countryRepo;
163 private StateProvinceRepository stateprovinceRepo;
164 private CommunicationTypeRepository communicationTypeRepo;
165 private ProposalPartyRepository proposalPartyRepo;
166 private PartyTypeRepository partyTyperepo;
167 #region CreatePartyContructor
168 public CreatePartyModel()
169 {
170 countryRepo = new CountryRepository();
171 stateprovinceRepo = new StateProvinceRepository();
172 communicationTypeRepo = new CommunicationTypeRepository();
173 proposalPartyRepo = new ProposalPartyRepository();
174 partyTyperepo = new PartyTypeRepository();
175 }
176 #endregion
177
178 #region RegionSection
179
180 public Int64 partyId { get; set; }
181 [Required(ErrorMessage = "Please enter company name")]
182 [Display(Name = "*Company Name")]
183 public string companyName { get; set; }
184 [Display(Name = "Address line 1")]
185 public string Address1 { get; set; }
186 [Display(Name = "Address line 2")]
187 public string Address2 { get; set; }
188 [Display(Name = "City")]
189 public string cityName { get; set; }
190 [Display(Name = "Country")]
191 public int countryId { get; set; }
192 public List<SelectListItem> countryList { get; set; }
193 [Display(Name = "State/Province")]
194 public int stateProvinceId { get; set; }
195 public List<SelectListItem> stateprovinceList { get; set; }
196 [Display(Name = "Zip Code")]
197 public string zipCode { get; set; }
198 [Display(Name = "Party Type")]
199 public int partyTypeId { get; set; }
200 public List<SelectListItem> partyTypeList { get; set; }
201
202 #endregion
203
204 #region CommunicationSection
205 public string commsubType1 { get; set; }
206 [Display(Name = "Primary Email")]
207 [EmailAddress(ErrorMessage = "Please enter a valid email address")]
208 public string commValue1 { get; set; }
209
210 [Display(Name = "Business Phone")]
211 [MaxLength(10, ErrorMessage = "Phone should not be greater than 10.")]
212 public string bussinessPhone { get; set; }
213
214 public int commsubType2 { get; set; }
215 public List<SelectListItem> communicationTypeList { get; set; }
216 public string commsubtypevalues { get; set; }
217 #endregion
218
219 public void initialize()
220 {
221 countryList = countryRepo.GetCountry().Select(s => new SelectListItem
222 {
223 Text = s.CountryName,
224 Value = s.CountryId.ToString()
225 }).ToList();
226 countryList.Add(new SelectListItem
227 {
228 Text = "Select One",
229 Value = "0",
230 Selected = true
231 });
232
233 communicationTypeList = communicationTypeRepo.getCommunicationType().Select(s => new SelectListItem
234 {
235 Text = s.CommunicationTypeName,
236 Value = s.CommunicationTypeId.ToString()
237 }).ToList();
238 communicationTypeList.Add(new SelectListItem
239 {
240 Text = "Select One",
241 Value = "0",
242 Selected = true
243 });
244
245 partyTypeList = partyTyperepo.GetPartyType().Select(s => new SelectListItem
246 {
247 Text = s.PartyTypeName,
248 Value = s.PartyTypeId.ToString()
249 }).ToList();
250
251 }
252
253 /// <summary>
254 /// method to return state/province list
255 /// </summary>
256 /// <param name="countryId"></param>
257 /// <returns></returns>
258 [HttpGet]
259 public List<SelectListItem> LoadState(int countryId)
260 {
261
262 stateprovinceList = stateprovinceRepo.GetStateProvince(countryId).Select(s => new SelectListItem
263 {
264 Text = s.StateprovinceName,
265 Value = s.StateprovinceId.ToString(),
266 Selected = true
267 }).ToList();
268 stateprovinceList.Add(new SelectListItem
269 {
270 Text = "Select One",
271 Value = "0",
272 Selected = true
273 });
274
275 return stateprovinceList;
276 }
277
278 public List<CreatePartyModel> ViewParty(Int64 PartyId)
279 {
280 List<CreatePartyModel> viewPartyDetail = proposalPartyRepo.getPartySearchViewOnId(PartyId).Select(s => new CreatePartyModel
281 {
282 partyId = s.PartyId,
283 partyTypeId =s.PartyTypeId,
284 companyName = s.CompanyName,
285 Address1 = s.Address1,
286 Address2 = s.Address2,
287 bussinessPhone = s.CommSubTypeValue1,
288 cityName = s.CityName,
289 countryId = s.CountryId,
290 stateProvinceId = s.StateProvinceId,
291 zipCode = s.ZipCode,
292 commValue1 = s.CommSubTypeValue2,
293 commsubtypevalues = s.CommSubTypeValue3,
294 commsubType2 = s.CommSubType3
295
296
297 }).ToList();
298 return viewPartyDetail;
299 }
300
301 }
302 #endregion
303
304 #region SearchParty
305
306 /// <summary>
307 /// Party search model
308 /// </summary>
309 public class PartySearchDetail
310 {
311 private ProposalPartyRepository partyRepo;
312
313 public PartySearchDetail()
314 {
315 partyRepo = new ProposalPartyRepository();
316 }
317
318 /// <summary>
319 /// Party Id
320 /// </summary>
321 public int PartyId { get; set; }
322
323 /// <summary>
324 /// Search Text
325 /// </summary>
326 [Required(ErrorMessage = "Please enter search text")]
327 public string SearchText { get; set; }
328
329 /// <summary>
330 /// Search should be exact match or not
331 /// </summary>
332 [Display(Name = "Exact Match")]
333 public bool IsExactmatch { get; set; }
334
335 /// <summary>
336 /// Party Name
337 /// </summary>
338 public string PartyName { get; set; }
339
340 /// <summary>
341 /// Type
342 /// </summary>
343 public string Type { get; set; }
344
345 /// <summary>
346 /// Address Type
347 /// </summary>
348 public string AddressType { get; set; }
349
350 /// <summary>
351 /// Address
352 /// </summary>
353 public string Address { get; set; }
354
355 /// <summary>
356 /// get party search data on the basis of search text
357 /// </summary>
358 /// <param name="searchText"></param>
359 /// <returns></returns>
360 public List<PartySearchDetail> PartySearchOnText(string searchText, bool isexactmatch)
361 {
362 char exactMatch = isexactmatch ? 'y' : 'n';
363 List<PartySearchDetail> partySearchResult = partyRepo.getPartySearchResultOnText(searchText, exactMatch).Select(s => new PartySearchDetail
364 {
365 Address = s.Address,
366 AddressType = s.AddressType,
367 PartyId = s.PartyId,
368 PartyName = s.PartyName,
369 Type = s.Type
370 }).ToList();
371 return partySearchResult;
372 }
373
374 /// <summary>
375 /// get party search data on the basis of party Id
376 /// </summary>
377 /// <param name="searchText"></param>
378 /// <returns></returns>
379 public List<PartySearchDetail> PartySearchOnPartyId(Int64 partyId)
380 {
381 List<PartySearchDetail> partySearchResult = partyRepo.getPartySearchResultOnId(partyId).Select(s => new PartySearchDetail
382 {
383 Address = s.Address,
384 AddressType = s.AddressType,
385 PartyId = s.PartyId,
386 PartyName = s.PartyName,
387 Type = s.Type
388 }).ToList();
389 return partySearchResult;
390 }
391 }
392
393
394 #endregion
395}
396
397
398 #region Reset Password
399
400 public int ChangePassword(int loggedinuserid, int userid, string oldpassword, string newpassword)
401 {
402 bool result = false;
403 int status = 0;
404 try
405 {
406 if (loggedinuserid > 0)
407 {
408 int loggedinuser = loggedinuserid;
409 int userType = 0;
410 QSettings.GetUserType(loggedinuser, out userType);
411 if (userType == 1)
412 {
413 result = QSettings.ChangeLoggedUserPassword(userid, oldpassword.Trim(), newpassword.Trim());
414 //Sending mail
415 if (result)
416 {
417 if (loggedinuserid == userid)//self
418 {
419 status = 3;
420 }
421 else if (!ctx.tblusers.Where(c => c.userid == userid).Any())
422 {
423 status = 2;
424 }
425 else
426 {
427 var data = ctx.tblusers.Where(c => c.userid == userid).FirstOrDefault();
428 if (data != null)
429 {
430 string body = "Hi, <br /><br />";
431 body += "New OCC application password details are given below. <br />";
432 body += "User Name: " + data.brokername + "<br />";
433 body += "User Email: " + data.username + "<br />";
434 body += "Password: " + data.password + "<br />";
435 body += "Regards: <br />";
436 body += "Administrator <br />";
437 body += "OCC Finance<br />";
438
439 string adminEmail = ctx.tblusers.Where(x => x.userid == loggedinuser).FirstOrDefault().username;
440 List<ManDRILLModel> _mandrillOBJ = new List<ManDRILLModel>();
441
442 var _mailDrilEmails = new List<Mandrill.EmailAddress>();
443 Mandrill.EmailAddress objEm = new Mandrill.EmailAddress();
444 objEm.email = data.username;
445 objEm.name = "";
446 _mailDrilEmails.Add(objEm);
447 Mandrill.EmailAddress objEm1 = new Mandrill.EmailAddress();
448 objEm1.email = adminEmail;
449 objEm1.name = "";
450 _mailDrilEmails.Add(objEm1);
451
452 //Man DRILL ********************************************************************
453
454 var domain = "occfinance.com";
455 Mandrill.EmailMessage message = new Mandrill.EmailMessage();
456 var _mandrillMessage = new List<Mandrill.EmailMessage>();
457
458 message.to = _mailDrilEmails;
459 message.html = body;
460 message.from_email = ConfigurationManager.AppSettings["SMTP_FROM"].ToString();
461 message.from_name = "OCC";
462 message.subject = "New Password";
463 message.inline_css = true;
464 message.signing_domain = domain;
465 message.AddHeader("X-MC-SigningDomain", domain);
466 message.AddHeader("X-MC-TrackingDomain", domain);
467 _mandrillMessage.Add(message);
468
469 //********************************************************************************
470
471 // Manage The ManDRILLModel - 25-07-2014
472
473 var objMAN = new ManDRILLModel();
474 objMAN.contactId = 0;
475 objMAN.financeid = 0;
476 objMAN.mailcontent = body;
477 objMAN.MandrillMSG = message;
478 objMAN.IsAppContact = false;
479
480 objMAN.notemsg = "";
481
482 _mandrillOBJ.Add(objMAN);
483
484 WebUtility.SendMailViaManDRILL(_mandrillOBJ, loggedinuserid);
485 //------------------------------------------------------------
486 status = 1;
487 }
488 }
489 }
490 //Sending mail End
491 }
492 }
493 return status;
494 }
495 catch (Exception ex)
496 {
497 return status;
498 }
499 }
500
501 #endregion Reset Password
502
503
504
505
506 #region [Send Isuue Email]
507 /// <summary>
508 /// Sending Issue Email
509 /// </summary>
510 /// <param name="name"></param>
511 /// <param name="email"></param>
512 /// <param name="issue"></param>
513 /// <param name="steps"></param>
514 public bool SendIssueEmail(string name, string email, string issue, string steps, int loggedinuserid)
515 {
516 bool status = false;
517 try
518 {
519 var issueemail = Convert.ToString(ConfigurationManager.AppSettings["IssueEmail"] ?? "crispy50@hotmail.com");
520 var supportemail = Convert.ToString(ConfigurationManager.AppSettings["SupportEmail"] ?? "team@occfinance.com");
521 var ccmail = Convert.ToString(ConfigurationManager.AppSettings["CCEmail"] ?? "crispy50@hotmail.com");
522 var bccemail = Convert.ToString(ConfigurationManager.AppSettings["BCCEmail"] ?? "team@occfinance.com");
523
524 string body = "Hi, <br /><br />";
525 body += "I got an issue, need your support.<br /><br/>";
526 body += "Below is the issue details.<br /><br />";
527 body += "Issue: " + issue + "<br />";
528 body += "Step(s): " + steps + "<br /><br />";
529 body += "Regards: <br />";
530 body += name + "<br />";
531 body += email + "<br />";
532
533
534 string bodyuser = "Hi , " + name + " <br /><br />";
535 bodyuser += "Thanks for your feedbacks.<br />";
536 bodyuser += "We will definately short this out earliest.<br /><br />";
537 bodyuser += "Regards: <br />";
538 bodyuser += "Administrator<br />";
539 bodyuser += "OCC Finance<br />";
540
541 #region [Sending Issue Email]
542 List<ManDRILLModel> _mandrillIssueOBJ = new List<ManDRILLModel>();
543 var _mailDrilIssueEmails = new List<EmailAddress>();
544 EmailAddress objIssueEm = new EmailAddress();
545
546 objIssueEm.email = supportemail;
547 objIssueEm.name = "";
548 _mailDrilIssueEmails.Add(objIssueEm);
549 //Man DRILL ********************************************************************
550
551 var domain = "occfinance.com";
552 EmailMessage Issuemessage = new EmailMessage();
553 var _mandrillIssueMessage = new List<EmailMessage>();
554
555 Issuemessage.to = _mailDrilIssueEmails;
556 Issuemessage.html = body;
557 Issuemessage.from_email = ConfigurationManager.AppSettings["SMTP_FROM"].ToString();
558 Issuemessage.from_name = "OCC";
559 Issuemessage.subject = "ISSUE ON AppTrack";
560 Issuemessage.inline_css = true;
561 Issuemessage.signing_domain = domain;
562 Issuemessage.AddHeader("X-MC-SigningDomain", domain);
563 Issuemessage.AddHeader("X-MC-TrackingDomain", domain);
564 _mandrillIssueMessage.Add(Issuemessage);
565
566 //********************************************************************************
567
568 // Manage The ManDRILLModel - 25-07-2014
569
570 var objIssueMAN = new ManDRILLModel();
571 objIssueMAN.contactId = 0;
572 objIssueMAN.financeid = 0;
573 objIssueMAN.mailcontent = body;
574 objIssueMAN.MandrillMSG = Issuemessage;
575 objIssueMAN.IsAppContact = false;
576 objIssueMAN.notemsg = "";
577 _mandrillIssueOBJ.Add(objIssueMAN);
578 WebUtility.SendMailViaManDRILL(_mandrillIssueOBJ, loggedinuserid);
579 #endregion
580
581
582 #region [Sending Reply Email]
583 List<ManDRILLModel> _mandrillOBJ = new List<ManDRILLModel>();
584 var _mailDrilEmails = new List<EmailAddress>();
585 EmailAddress objEm = new EmailAddress();
586
587 objEm.email = email;
588 objEm.name = "";
589 _mailDrilEmails.Add(objEm);
590 objEm = new EmailAddress();
591 objEm.email = bccemail;
592 objEm.name = "";
593 objEm.type = "bcc";
594 _mailDrilEmails.Add(objEm);
595
596 //Man DRILL ********************************************************************
597
598
599 EmailMessage message = new EmailMessage();
600 var _mandrillMessage = new List<EmailMessage>();
601
602 message.to = _mailDrilEmails;
603 message.html = bodyuser;
604 message.from_email = ConfigurationManager.AppSettings["SMTP_FROM"].ToString();
605 message.from_name = "OCC";
606 message.subject = "Reply Mail from OCC Finance";
607 message.inline_css = true;
608 message.signing_domain = domain;
609 message.AddHeader("X-MC-SigningDomain", domain);
610 message.AddHeader("X-MC-TrackingDomain", domain);
611 _mandrillMessage.Add(message);
612
613 //********************************************************************************
614
615 // Manage The ManDRILLModel - 25-07-2014
616
617 var objMAN = new ManDRILLModel();
618 objMAN.contactId = 0;
619 objMAN.financeid = 0;
620 objMAN.mailcontent = bodyuser;
621 objMAN.MandrillMSG = message;
622 objMAN.IsAppContact = false;
623
624 objMAN.notemsg = "";
625
626 _mandrillOBJ.Add(objMAN);
627
628 int userId = loggedinuserid;
629 WebUtility.SendMailViaManDRILL(_mandrillOBJ, userId);
630 #endregion
631 status = true;
632 }
633 catch (Exception ex)
634 {
635 Helper.ErrorLog(ex.InnerException, "clswebServiceHelper", "SendIssueEmail", ex.Message);
636 }
637
638 return status;
639
640 }
641 #endregion
642
643
644
645
646
647 public class CookieWrapper
648 {
649 private const string ApplicationName = "Occfinance";
650
651 private enum CookieItem
652 {
653 CheckDesktop,
654 UserId,
655 ClientRegistrationID
656
657 }
658 /**************
659 All cookie values are accessible by public static methods.
660 No typos/duplicates are possible from calling code!
661 **************/
662
663 private static string GetCookieValUser(CookieItem item)
664 {
665 HttpCookie cookie = GetAppCookie(false); //get the existing cookie
666 return (cookie != null && (cookie.Values[item.ToString()] != null)) //value or empty if doesn't exist
667 ? cookie.Values[item.ToString()]
668 : string.Empty;
669 }
670
671
672 public static int UserId
673 {
674 get
675 {
676 int userId;
677 try
678 {
679 userId = Convert.ToInt32(string.IsNullOrWhiteSpace(GetCookieVal(CookieItem.UserId)) ? "0" : GetCookieValUser(CookieItem.UserId));
680 }
681 catch
682 {
683 userId = 0;
684 }
685 return userId;
686 }
687 set { UpdateCookieVal(CookieItem.UserId, value.ToString(), 40); }
688 }
689
690 public static int ClientRegistrationID
691 {
692 get { return Convert.ToInt32(string.IsNullOrWhiteSpace(GetCookieVal(CookieItem.ClientRegistrationID)) ? "0" : GetCookieValUser(CookieItem.ClientRegistrationID)); }
693 set { UpdateCookieVal(CookieItem.ClientRegistrationID, value.ToString(), 40); }
694 }
695
696
697 public static string CheckDesktop
698 {
699 get { return GetCookieVal(CookieItem.CheckDesktop) ?? string.Empty; }
700 set { UpdateCookieVal(CookieItem.CheckDesktop, value.ToString(), 40); }
701 }
702
703 private static string GetCookieVal(CookieItem item)
704 {
705 HttpCookie cookie = GetAppCookie(false); //get the existing cookie
706 return (cookie != null && (cookie.Values[item.ToString()] != null)) //value or empty if doesn't exist
707 ? cookie.Values[item.ToString()]
708 : "True";
709 }
710
711 private static void UpdateCookieVal(CookieItem item, string val, int expireDays)
712 {
713 //get the existing cookie (or new if not exists)
714 HttpCookie cookie = GetAppCookie(true);
715
716 //modify its contents & meta.
717 cookie.Expires = DateTime.Now.AddDays(expireDays);
718 cookie.Values[item.ToString()] = val;
719
720 //add back to the http response to send back to the browser
721 HttpContext.Current.Response.Cookies.Add(cookie);
722 }
723
724 private static HttpCookie GetAppCookie(bool createIfDoesntExist)
725 {
726 if (HttpContext.Current == null)
727 return null;
728 //get the cookie or a new one if indicated
729 return HttpContext.Current.Request.Cookies[ApplicationName] ?? ((createIfDoesntExist) ? new HttpCookie(ApplicationName) : null);
730 }
731 }
732
733
734
735 /****************************** Module Header ******************************
736Author : <1302>
737Date : Monday, Sept 30,2013 1:00:00 PM
738Notes : This is the helper class for RouteDecorator & Image Conversion.
739***************************************************************************/
740
741using System;
742using System.Collections.Generic;
743using System.Linq;
744using System.Web;
745using System.Text;
746using System.Collections.Specialized;
747using System.Web.Mvc;
748using System.Text.RegularExpressions;
749using System.ComponentModel;
750using System.IO;
751using System.Drawing;
752using System.Drawing.Drawing2D;
753using System.Reflection;
754using System.Data;
755using System.Web.Routing;
756using System.Web.Mvc.Html;
757using System.Web.Helpers;
758
759using System.Linq.Expressions;
760using System.Runtime.InteropServices;
761using System.Drawing.Imaging;
762namespace Codes
763{
764 public static class SystemTime
765 {
766 public static DateTime Now
767 {
768 get
769 {
770 return DateTime.Now;
771 }
772 }
773 }
774
775
776 public static class Extensions
777 {
778
779 public static string TruncateAt(this string s, int maxLength)
780 {
781 if (string.IsNullOrEmpty(s)) return s;
782 if (s.Length <= maxLength) return s;
783
784 if (s.Length > 3 && maxLength <= 3) return "...";
785 return s.Substring(0, maxLength - 3) + "...";
786 }
787
788 public static string GetString(this string str)
789 {
790 if(string.IsNullOrEmpty(str))
791 {
792 return string.Empty;
793 }
794 else if (string.IsNullOrWhiteSpace(str))
795 {
796 return string.Empty;
797 }
798 else
799 {
800 return str;
801 }
802 }
803
804
805
806 public static string Mailtemplates(string AppTrackImg, string AppTrackLogo, string Content, string FooterCopyRight, string SupportFooter, string AppTrackSiteUrl)
807 {
808 StringBuilder strBuilder = new StringBuilder();
809
810 string content = System.IO.File.ReadAllText(HttpContext.Current.Server.MapPath(@"~\Content\template.html"));
811 // string FileName = "TVRFP";
812 StringBuilder _tempate = new StringBuilder();
813 _tempate.Append(content);
814 _tempate = _tempate
815 .Replace("{AppTrackImg}", AppTrackImg)
816 .Replace("{AppTrackLogo}", AppTrackLogo)
817 .Replace("{Content}", Content)
818 .Replace("{FooterCopyRight}", FooterCopyRight)
819 .Replace("{SupportFooter}", SupportFooter)
820 .Replace("{AppTrackSiteUrl}", AppTrackSiteUrl);
821
822 return _tempate.ToString();
823 }
824
825 [Description("Retrieves an IEnumerable<SelectListItem> from type of enum.")]
826 public static IEnumerable<SelectListItem> SelectList<T>(this Type o, bool isDesc = false, bool isEnumText = false)
827 {
828 if (o.IsEnum)
829 {
830 return Enum.GetValues(typeof(T)).Cast<T>().Select(v => new SelectListItem()
831 {
832 Text = isDesc ? (v.GetType()
833 .GetField(v.ToString())
834 .GetCustomAttributes(typeof(DescriptionAttribute), false)
835 .SingleOrDefault() as DescriptionAttribute).Description
836 : v.ToString(),
837 Value = isEnumText ? v.ToString() : Convert.ToInt32(v).ToString()
838 });
839 }
840 return null;
841
842
843
844 }
845
846 public static string Desciption(this Enum o)
847 {
848 DescriptionAttribute attribute = o.GetType()
849 .GetField(o.ToString())
850 .GetCustomAttributes(typeof(DescriptionAttribute), false)
851 .SingleOrDefault() as DescriptionAttribute;
852 return attribute == null ? o.ToString() : attribute.Description;
853 }
854
855
856
857 }
858 /// <summary>
859 /// Jsonp Class
860 /// </summary>
861 public class JsonpResult : ActionResult
862 {
863 public string CallbackFunction { get; set; }
864 public Encoding ContentEncoding { get; set; }
865 public string ContentType { get; set; }
866 public object Data { get; set; }
867
868 public JsonpResult(object data) : this(data, null) { }
869 public JsonpResult(object data, string callbackFunction)
870 {
871 Data = data;
872 CallbackFunction = callbackFunction;
873 }
874
875
876 public override void ExecuteResult(ControllerContext context)
877 {
878 if (context == null) throw new ArgumentNullException("context");
879
880 HttpResponseBase response = context.HttpContext.Response;
881
882 response.ContentType = string.IsNullOrEmpty(ContentType) ? "application/x-javascript" : ContentType;
883
884 if (ContentEncoding != null) response.ContentEncoding = ContentEncoding;
885
886 if (Data != null)
887 {
888 HttpRequestBase request = context.HttpContext.Request;
889
890 var callback = CallbackFunction ?? request.Params["callback"] ?? "callback";
891
892#pragma warning disable 0618 // JavaScriptSerializer is no longer obsolete
893 var serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
894 serializer.MaxJsonLength = Int32.MaxValue;
895 serializer.RecursionLimit = 100;
896 response.Write(string.Format("{0}({1});", callback, serializer.Serialize(Data)));
897#pragma warning restore 0618
898 }
899 }
900 }
901
902
903
904 /*
905 * Author : Anupam
906 * IEuqlityComparer for distinct
907 * Date Created : 30 03 2015
908 */
909 public class EqualityComparer<T> : IEqualityComparer<T>
910 {
911
912 Func<T, T, bool> _equalsFunction;
913 Func<T, int> _hashCodeFunction;
914
915 public EqualityComparer(Func<T, T, bool> equalsFunction, Func<T, int> hashCodeFunction)
916 {
917 if (equalsFunction == null) throw new ArgumentNullException();
918 if (hashCodeFunction == null) throw new ArgumentNullException();
919
920 _equalsFunction = equalsFunction;
921 _hashCodeFunction = hashCodeFunction;
922 }
923
924 public bool Equals(T x, T y)
925 {
926 return _equalsFunction(x, y);
927 }
928
929 public int GetHashCode(T obj)
930 {
931 return _hashCodeFunction(obj);
932 }
933
934
935 }
936
937
938
939
940}
941
942using Occfinance_Data;
943using System;
944using System.Collections.Generic;
945using System.Linq;
946using System.Web;
947using Occfinance.Models;
948using System.Data.SqlClient;
949using System.Data;
950using Occfinance.Helpers;
951using System.Data.Entity.Infrastructure;
952using System.Web.Mvc;
953
954namespace Occfinance.Code
955{
956 public static class JsTreeSource
957 {
958 /// <summary>
959 /// Get client tree data source
960 /// </summary>
961 /// <returns></returns>
962 public static string GetClientTreeSource()
963 {
964 List<JsTreeClientModel> model = new List<JsTreeClientModel>();
965 JsTreeClientModel obj = new JsTreeClientModel();
966 obj.id = "0";
967 obj.parent = "#";
968 obj.text = "All";
969 obj.icon = "http://secure.occfinance.com/images/buildingplus.png";
970 try
971 {
972 using (db_occfinance_5572Entities DB = new db_occfinance_5572Entities())
973 {
974 model = DB.Database.SqlQuery<JsTreeClientModel>("Exec dbo.GetClientTreeData").ToList();
975 if (model == null) { model = new List<JsTreeClientModel>(); }
976 model.Insert(0, obj);
977 }
978 }
979 catch (Exception ex)
980 {
981 Helper.ErrorLog(ex.InnerException, "JsTreeSource", "GetClientTreeSource", ex.Message);
982 }
983 return new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(model);
984 }
985
986 /// <summary>
987 /// Get broker tree data source
988 /// </summary>
989 /// <param name="userId"></param>
990 /// <returns></returns>
991 public static string GetBrokerTreeSource(int userId)
992 {
993 List<JsTreeClientModel> model = new List<JsTreeClientModel>();
994 int userType = 0;
995 var Id = GetUserTypeAndId(userId, out userType);
996 try
997 {
998 SqlParameter[] Param = new SqlParameter[2];
999 Param[0] = new SqlParameter("@UserType", userType);
1000 Param[1] = new SqlParameter("@ID", Id);
1001 DataTable dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "GetBrokerTreeData", Param);
1002 model = (from DataRow row in dt.Rows
1003 select new JsTreeClientModel
1004 {
1005 id = ((row["id"] == DBNull.Value || row["id"] == null) ? "" : row["id"]).ToString(),
1006 text = ((row["text"] == DBNull.Value || row["text"] == null) ? "" : row["text"]).ToString(),
1007 parent = ((row["parent"] == DBNull.Value || row["parent"] == null) ? "" : row["parent"]).ToString(),
1008 icon = ((row["icon"] == DBNull.Value || row["icon"] == null) ? "" : row["icon"]).ToString()
1009 }).ToList();
1010 }
1011 catch (Exception ex)
1012 {
1013 Helper.ErrorLog(ex.InnerException, "JsTreeSource", "GetBrokerTreeSource", ex.Message);
1014 }
1015 return new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(model);
1016 }
1017
1018 /// <summary>
1019 /// Get user type and id accordingly.
1020 /// </summary>
1021 /// <param name="userId"></param>
1022 /// <param name="userType"></param>
1023 /// <returns></returns>
1024 public static object GetUserTypeAndId(int userId, out int userType)
1025 {
1026 int Id = 0;
1027 try
1028 {
1029 SqlParameter[] Param = new SqlParameter[1] { new SqlParameter("@UserId", userId) };
1030 DataTable dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "GetUserType", Param);
1031 Id = Convert.ToInt32(dt.Rows[0]["Id"]);
1032 userType = Convert.ToInt32(dt.Rows[0]["userType"]);
1033 }
1034 catch (Exception ex)
1035 {
1036 Helper.ErrorLog(ex.InnerException, "Q_Report", "GetUserTypeAndId", ex.Message);
1037 throw;
1038 }
1039 return Id;
1040 }
1041 }
1042}
1043
1044/****************************** Module Header ******************************
1045Author : <AT SYNAPSE INDIA>
1046Date : Monday, Sept 30,2013 1:00:00 PM
1047Notes : This is the MailHelper class to send mail.
1048***************************************************************************/
1049
1050
1051using System.Net.Mail;
1052using Occfinance.Code;
1053using System.Web.Mail;
1054using System.Text;
1055using System.Configuration;
1056public class MailHelper
1057{
1058 public static bool SendMailMessage(System.String To, System.String Bcc, System.String Cc, System.String Subject, System.String Message, string attachmentPath = "", string frommail = "")
1059 {
1060
1061 if (
1062 string.IsNullOrEmpty(To) ||
1063 string.IsNullOrEmpty(Subject) ||
1064 string.IsNullOrEmpty(Message)
1065 )
1066 return false;
1067
1068
1069 System.String From = !string.IsNullOrWhiteSpace(frommail) ? frommail : ConfigurationManager.AppSettings["SMTP_FROM"].ToString();
1070
1071 try
1072 {
1073 SendNetMail(From, To, Bcc, Cc, Subject, Message, attachmentPath);
1074 return true;
1075 }
1076 catch
1077 {
1078 try
1079 {
1080 SendWebMail(From, To, Bcc, Cc, Subject, Message, attachmentPath);
1081 return true;
1082 }
1083 catch
1084 {
1085 try
1086 {
1087 System.Web.Mail.MailMessage MM = new System.Web.Mail.MailMessage();
1088 MM.From = From;
1089 MM.Subject = Subject;
1090 MM.To = To;
1091 if (!string.IsNullOrEmpty(Cc))
1092 MM.Cc = Cc;
1093 if (!string.IsNullOrEmpty(Bcc))
1094 MM.Bcc = Bcc;
1095 if (!string.IsNullOrEmpty(attachmentPath))
1096 {
1097 System.Web.Mail.MailAttachment attch = new MailAttachment(attachmentPath);
1098 MM.Attachments.Add(attch);
1099 }
1100 MM.Body = Message;
1101 MM.BodyFormat = System.Web.Mail.MailFormat.Html;
1102 System.Web.Mail.SmtpMail.Send(MM);
1103 return true;
1104 }
1105 catch
1106 {
1107 return false;
1108 }
1109 }
1110 }
1111
1112 }
1113
1114 private static void SendWebMail(System.String from, System.String to, System.String bcc, System.String cc, System.String subject, System.String body, string attachment)
1115 {
1116 System.Web.Mail.MailMessage mail = new System.Web.Mail.MailMessage();
1117 mail.From = from;
1118 mail.Subject = subject;
1119 mail.To = to;
1120 if (!string.IsNullOrEmpty(cc))
1121 mail.Cc = cc;
1122 if (!string.IsNullOrEmpty(bcc))
1123 mail.Bcc = bcc;
1124 mail.Body = body;
1125 if (!string.IsNullOrEmpty(attachment))
1126 {
1127 System.Web.Mail.MailAttachment at = new MailAttachment(attachment);
1128 mail.Attachments.Add(at);
1129 }
1130 mail.BodyFormat = System.Web.Mail.MailFormat.Html;
1131 mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //basic authentication
1132 mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", ConfigurationManager.AppSettings["SMTP_USER"]); //set your username here
1133 mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", ConfigurationManager.AppSettings["SMTP_PASSWORD"]); //set your password here
1134 System.Web.Mail.SmtpMail.SmtpServer = ConfigurationManager.AppSettings["SMTP_SERVER"]; //your real server goes here
1135 System.Web.Mail.SmtpMail.Send(mail);
1136 }
1137
1138 private static void SendNetMail(System.String from, System.String to, System.String bcc, System.String cc, System.String subject, System.String body, string attachment)
1139 {
1140 using (System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage())
1141 {
1142 msg.From = new System.Net.Mail.MailAddress(from);
1143 msg.Subject = subject;
1144 msg.SubjectEncoding = System.Text.Encoding.UTF8;
1145 msg.To.Add(to);
1146 if (!string.IsNullOrEmpty(cc))
1147 msg.CC.Add(cc);
1148 if (!string.IsNullOrEmpty(bcc))
1149 msg.Bcc.Add(bcc);
1150 msg.Body = body;
1151 msg.BodyEncoding = System.Text.Encoding.UTF8;
1152
1153 if (!string.IsNullOrEmpty(attachment))
1154 msg.Attachments.Add(new Attachment(attachment));
1155
1156 msg.IsBodyHtml = true;
1157
1158 msg.Priority = System.Net.Mail.MailPriority.High;
1159 System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
1160 client.EnableSsl = true;
1161 client.Credentials = new System.Net.NetworkCredential
1162 (
1163 ConfigurationManager.AppSettings["SMTP_USER"],
1164 ConfigurationManager.AppSettings["SMTP_PASSWORD"]
1165 );
1166 client.Port = System.Convert.ToInt32(ConfigurationManager.AppSettings["SMTP_PORT"] ?? "25");
1167 client.Host = ConfigurationManager.AppSettings["SMTP_SERVER"];
1168 client.Send(msg);
1169 }
1170 }
1171
1172 public static bool SendMailMessageWithMultipleAttachments(System.String To, System.String Bcc, System.String Cc, System.String Subject, System.String Message, string[] attachmentPath, string frommail = "")
1173 {
1174
1175 if (
1176 string.IsNullOrEmpty(To) ||
1177 string.IsNullOrEmpty(Subject) ||
1178 string.IsNullOrEmpty(Message)
1179 )
1180 return false;
1181
1182
1183 System.String From = !string.IsNullOrWhiteSpace(frommail) ? frommail : ConfigurationManager.AppSettings["SMTP_FROM"].ToString();
1184
1185 try
1186 {
1187 SendNetMailithMultipleAttachments(From, To, Bcc, Cc, Subject, Message, attachmentPath);
1188 return true;
1189 }
1190 catch
1191 {
1192 try
1193 {
1194 SendWebMailithMultipleAttachments(From, To, Bcc, Cc, Subject, Message, attachmentPath);
1195 return true;
1196 }
1197 catch
1198 {
1199 try
1200 {
1201 System.Web.Mail.MailMessage MM = new System.Web.Mail.MailMessage();
1202 MM.From = From;
1203 MM.Subject = Subject;
1204 MM.To = To;
1205 if (!string.IsNullOrEmpty(Cc))
1206 MM.Cc = Cc;
1207 if (!string.IsNullOrEmpty(Bcc))
1208 MM.Bcc = Bcc;
1209
1210 if (attachmentPath != null && attachmentPath.Length > 0)
1211 {
1212 for (int i = 0; i < attachmentPath.Length; i++)
1213 {
1214 System.Web.Mail.MailAttachment attch = new MailAttachment(attachmentPath[i].ToString());
1215 MM.Attachments.Add(attch);
1216 }
1217 }
1218
1219 MM.Body = Message;
1220 MM.BodyFormat = System.Web.Mail.MailFormat.Html;
1221 System.Web.Mail.SmtpMail.Send(MM);
1222 return true;
1223 }
1224 catch
1225 {
1226 return false;
1227 }
1228 }
1229 }
1230
1231 }
1232
1233 private static void SendWebMailithMultipleAttachments(System.String from, System.String to, System.String bcc, System.String cc, System.String subject, System.String body, string[] attachment)
1234 {
1235 System.Web.Mail.MailMessage mail = new System.Web.Mail.MailMessage();
1236 mail.From = from;
1237 mail.Subject = subject;
1238 mail.To = to;
1239 if (!string.IsNullOrEmpty(cc))
1240 mail.Cc = cc;
1241 if (!string.IsNullOrEmpty(bcc))
1242 mail.Bcc = bcc;
1243 mail.Body = body;
1244 if (attachment != null && attachment.Length > 0)
1245 {
1246 for (int i = 0; i < attachment.Length; i++)
1247 {
1248 System.Web.Mail.MailAttachment at = new MailAttachment(attachment[i].ToString());
1249 mail.Attachments.Add(at);
1250 }
1251 }
1252 mail.BodyFormat = System.Web.Mail.MailFormat.Html;
1253 mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //basic authentication
1254 mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", ConfigurationManager.AppSettings["SMTP_USER"]); //set your username here
1255 mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", ConfigurationManager.AppSettings["SMTP_PASSWORD"]); //set your password here
1256 System.Web.Mail.SmtpMail.SmtpServer = ConfigurationManager.AppSettings["SMTP_SERVER"]; //your real server goes here
1257 System.Web.Mail.SmtpMail.Send(mail);
1258 }
1259
1260 private static void SendNetMailithMultipleAttachments(System.String from, System.String to, System.String bcc, System.String cc, System.String subject, System.String body, string[] attachment)
1261 {
1262 using (System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage())
1263 {
1264 msg.From = new System.Net.Mail.MailAddress(from);
1265 msg.Subject = subject;
1266 msg.SubjectEncoding = System.Text.Encoding.UTF8;
1267 msg.To.Add(to);
1268 if (!string.IsNullOrEmpty(cc))
1269 msg.CC.Add(cc);
1270 if (!string.IsNullOrEmpty(bcc))
1271 msg.Bcc.Add(bcc);
1272 msg.Body = body;
1273 msg.BodyEncoding = System.Text.Encoding.UTF8;
1274
1275 if (attachment != null && attachment.Length > 0)
1276 {
1277 for (int i = 0; i < attachment.Length; i++)
1278 {
1279 Attachment _att = new Attachment(attachment[i].ToString());
1280 msg.Attachments.Add(_att);
1281 }
1282 }
1283 msg.IsBodyHtml = true;
1284
1285 msg.Priority = System.Net.Mail.MailPriority.High;
1286 System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
1287 client.EnableSsl = true;
1288 client.Credentials = new System.Net.NetworkCredential
1289 (
1290 ConfigurationManager.AppSettings["SMTP_USER"],
1291 ConfigurationManager.AppSettings["SMTP_PASSWORD"]
1292 );
1293 client.Port = System.Convert.ToInt32(ConfigurationManager.AppSettings["SMTP_PORT"] ?? "25");
1294 client.Host = ConfigurationManager.AppSettings["SMTP_SERVER"];
1295 client.Send(msg);
1296 }
1297 }
1298
1299
1300 public static bool SendMailMessageTwo(System.String To, System.String Bcc, System.String Cc, System.String Subject, System.String Message, string attachmentPath = "", string attachmentPath2 = "")
1301 {
1302
1303 if (
1304 string.IsNullOrEmpty(To) ||
1305 string.IsNullOrEmpty(Subject) ||
1306 string.IsNullOrEmpty(Message)
1307 )
1308 return false;
1309
1310
1311 System.String From = ConfigurationManager.AppSettings["SMTP_FROM"].ToString();
1312
1313 try
1314 {
1315 SendNetMailTwo(From, To, Bcc, Cc, Subject, Message, attachmentPath, attachmentPath2);
1316 return true;
1317 }
1318 catch
1319 {
1320 try
1321 {
1322 SendWebMailTwo(From, To, Bcc, Cc, Subject, Message, attachmentPath, attachmentPath2);
1323 return true;
1324 }
1325 catch
1326 {
1327 try
1328 {
1329 System.Web.Mail.MailMessage MM = new System.Web.Mail.MailMessage();
1330 MM.From = From;
1331 MM.Subject = Subject;
1332 MM.To = To;
1333 if (!string.IsNullOrEmpty(Cc))
1334 MM.Cc = Cc;
1335 if (!string.IsNullOrEmpty(Bcc))
1336 MM.Bcc = Bcc;
1337 if (!string.IsNullOrEmpty(attachmentPath))
1338 {
1339 System.Web.Mail.MailAttachment attch = new MailAttachment(attachmentPath);
1340 MM.Attachments.Add(attch);
1341 }
1342
1343 if (!string.IsNullOrEmpty(attachmentPath2))
1344 {
1345 System.Web.Mail.MailAttachment attch = new MailAttachment(attachmentPath2);
1346 MM.Attachments.Add(attch);
1347 }
1348
1349 MM.Body = Message;
1350 MM.BodyFormat = System.Web.Mail.MailFormat.Html;
1351 System.Web.Mail.SmtpMail.Send(MM);
1352 return true;
1353 }
1354 catch
1355 {
1356 return false;
1357 }
1358 }
1359 }
1360
1361 }
1362
1363 private static void SendWebMailTwo(System.String from, System.String to, System.String bcc, System.String cc, System.String subject, System.String body, string attachment, string attachmentPath2 = "")
1364 {
1365 System.Web.Mail.MailMessage mail = new System.Web.Mail.MailMessage();
1366 mail.From = from;
1367 mail.Subject = subject;
1368 mail.To = to;
1369 if (!string.IsNullOrEmpty(cc))
1370 mail.Cc = cc;
1371 if (!string.IsNullOrEmpty(bcc))
1372 mail.Bcc = bcc;
1373 mail.Body = body;
1374 if (!string.IsNullOrEmpty(attachment))
1375 {
1376 System.Web.Mail.MailAttachment at = new MailAttachment(attachment);
1377 mail.Attachments.Add(at);
1378 }
1379
1380 if (!string.IsNullOrEmpty(attachmentPath2))
1381 {
1382 System.Web.Mail.MailAttachment at = new MailAttachment(attachmentPath2);
1383 mail.Attachments.Add(at);
1384 }
1385
1386 mail.BodyFormat = System.Web.Mail.MailFormat.Html;
1387 mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //basic authentication
1388 mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", ConfigurationManager.AppSettings["SMTP_USER"]); //set your username here
1389 mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", ConfigurationManager.AppSettings["SMTP_PASSWORD"]); //set your password here
1390 System.Web.Mail.SmtpMail.SmtpServer = ConfigurationManager.AppSettings["SMTP_SERVER"]; //your real server goes here
1391 System.Web.Mail.SmtpMail.Send(mail);
1392 }
1393
1394 private static void SendNetMailTwo(System.String from, System.String to, System.String bcc, System.String cc, System.String subject, System.String body, string attachment, string attachmentPath2 = "")
1395 {
1396 using (System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage())
1397 {
1398 msg.From = new System.Net.Mail.MailAddress(from);
1399 msg.Subject = subject;
1400 msg.SubjectEncoding = System.Text.Encoding.UTF8;
1401 msg.To.Add(to);
1402 if (!string.IsNullOrEmpty(cc))
1403 msg.CC.Add(cc);
1404 if (!string.IsNullOrEmpty(bcc))
1405 msg.Bcc.Add(bcc);
1406 msg.Body = body;
1407 msg.BodyEncoding = System.Text.Encoding.UTF8;
1408
1409 if (!string.IsNullOrEmpty(attachment))
1410 msg.Attachments.Add(new Attachment(attachment));
1411
1412 if (!string.IsNullOrEmpty(attachmentPath2))
1413 msg.Attachments.Add(new Attachment(attachmentPath2));
1414
1415 msg.IsBodyHtml = true;
1416 msg.Priority = System.Net.Mail.MailPriority.High;
1417 System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
1418 client.EnableSsl = true;
1419 client.Credentials = new System.Net.NetworkCredential
1420 (
1421 ConfigurationManager.AppSettings["SMTP_USER"],
1422 ConfigurationManager.AppSettings["SMTP_PASSWORD"]
1423 );
1424 client.Port = System.Convert.ToInt32(ConfigurationManager.AppSettings["SMTP_PORT"] ?? "25");
1425 client.Host = ConfigurationManager.AppSettings["SMTP_SERVER"];
1426 client.Send(msg);
1427 }
1428 }
1429
1430
1431
1432}
1433
1434using System;
1435using System.Collections.Generic;
1436using System.Data;
1437using System.Data.SqlClient;
1438using System.Linq;
1439using System.Web;
1440using Occfinance.Models;
1441
1442namespace Occfinance.Code
1443{
1444 public class Q_AgentFeeSetting
1445 {
1446
1447 public int AgentFeeSettingAddUpdate(AgentFeeSetting model)
1448 {
1449 int _chk = 0;
1450 try
1451 {
1452 using (SqlConnection con = new SqlConnection(Convert.ToString(System.Configuration.ConfigurationManager.ConnectionStrings["ConString1"])))
1453 {
1454 con.Open();
1455 SqlDataAdapter com = new SqlDataAdapter("AgentFeeSettingAddUpdate", con);
1456 com.SelectCommand.CommandType = CommandType.StoredProcedure;
1457 com.SelectCommand.Parameters.AddWithValue("@AgentId", model.AgentId);
1458 com.SelectCommand.Parameters.AddWithValue("@AccountId", model.AccountId);
1459 com.SelectCommand.Parameters.AddWithValue("@ProcFee", model.ProcFee);
1460 com.SelectCommand.Parameters.AddWithValue("@ClientFee", model.ClientFee);
1461 com.SelectCommand.Parameters.AddWithValue("@EntryBy", model.EntryBy);
1462
1463 SqlParameter outParam1 = com.SelectCommand.Parameters.Add("@Chk", SqlDbType.Int);
1464 outParam1.Direction = ParameterDirection.Output;
1465
1466 com.SelectCommand.ExecuteNonQuery();
1467 _chk = Convert.ToInt32((outParam1.SqlValue != DBNull.Value || outParam1.SqlValue != null) ? outParam1.SqlValue.ToString() : "0");
1468
1469 }
1470 }
1471 catch
1472 {
1473 _chk = 0;
1474 }
1475 return _chk;
1476 }
1477
1478 public IEnumerable<AgentFeeSetting> GetAgentFeeSetting(int AccountId)
1479 {
1480 IEnumerable<AgentFeeSetting> _AgentFeeSettingList = null;
1481 try
1482 {
1483 SqlParameter[] Param = new SqlParameter[1];
1484 Param[0] = new SqlParameter("@AccountId", AccountId);
1485
1486 string _procName = "GetAgentFeeSetting";
1487
1488 DataTable dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, _procName, Param);
1489
1490 if (dt != null && dt.Rows.Count > 0)
1491 {
1492 _AgentFeeSettingList = (from DataRow row in dt.Rows
1493 select new AgentFeeSetting
1494 {
1495 AgentFeeId = Convert.ToInt32(((row["AgentFeeId"] == DBNull.Value || row["AgentFeeId"] == null) ? "0" : row["AgentFeeId"]).ToString()),
1496 AccountId = Convert.ToInt32(((row["AccountId"] == DBNull.Value || row["AccountId"] == null) ? "0" : row["AccountId"]).ToString()),
1497 AgentId = Convert.ToInt32(((row["AgentId"] == DBNull.Value || row["AgentId"] == null) ? "0" : row["AgentId"]).ToString()),
1498 ProcFee = Convert.ToDecimal(((row["ProcFee"] == DBNull.Value || row["ProcFee"] == null) ? "0" : row["ProcFee"]).ToString()),
1499 ClientFee = Convert.ToDecimal(((row["ClientFee"] == DBNull.Value || row["ClientFee"] == null) ? "0" : row["ClientFee"]).ToString()),
1500 AgentName = Convert.ToString(((row["AgentName"] == DBNull.Value || row["AgentName"] == null) ? "" : row["AgentName"]).ToString()),
1501
1502
1503 });
1504 }
1505
1506 }
1507 catch
1508 {
1509 }
1510 return _AgentFeeSettingList;
1511 }
1512
1513
1514 }
1515}
1516
1517using System;
1518using System.Collections.Generic;
1519using System.Linq;
1520using System.Web;
1521using Occfinance_Data;
1522using Occfinance.Models;
1523using System.Net;
1524using System.Data.SqlClient;
1525using System.Data;
1526using Occfinance.Helpers;
1527using System.Globalization;
1528
1529namespace Occfinance.Code
1530{
1531 public class Q_Attendance
1532 {
1533 public db_occfinance_5572Entities ctx = new db_occfinance_5572Entities();
1534 System.Web.HttpContext con = HttpContext.Current;
1535
1536 public List<Attendance> GetUserDayWiseAttendanceReport(int UserType, int Id, int UserId, string ActivityDate, int TeamId)
1537 {
1538
1539 List<Attendance> _teams = new List<Attendance>();
1540 string activitydate = System.DateTime.Now.ToString("MM/dd/yyyy");
1541 if (!string.IsNullOrWhiteSpace(ActivityDate))
1542 activitydate = ActivityDate.GetDate().Value.ToString("MM/dd/yyyy");
1543
1544 try
1545 {
1546 SqlParameter[] Param = new SqlParameter[5];
1547 Param[0] = new SqlParameter("@UserType", UserType);
1548 Param[1] = new SqlParameter("@Id", Id);
1549 if (UserId > 0)
1550 Param[2] = new SqlParameter("@UserId", UserId);
1551 if (TeamId > 0)
1552 Param[3] = new SqlParameter("@TeamId", TeamId);
1553 if (!string.IsNullOrWhiteSpace(ActivityDate))
1554 Param[4] = new SqlParameter("@ActivityDate", activitydate);
1555
1556 DataTable dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "GetUserDayWiseAttendanceReport", Param);
1557 _teams = (from DataRow row in dt.Rows
1558 select new Attendance
1559 {
1560 clientid = Convert.ToInt32(((row["clientid"] == DBNull.Value || row["clientid"] == null) ? "0" : row["clientid"]).ToString()),
1561 TeamId = Convert.ToInt32(((row["TeamId"] == DBNull.Value || row["TeamId"] == null) ? "0" : row["TeamId"]).ToString()),
1562 parent = Convert.ToInt32(((row["parent"] == DBNull.Value || row["parent"] == null) ? "0" : row["parent"]).ToString()),
1563 address = Convert.ToInt32(((row["address"] == DBNull.Value || row["address"] == null) ? "0" : row["address"]).ToString()),
1564 userid = Convert.ToInt32(((row["userid"] == DBNull.Value || row["userid"] == null) ? "0" : row["userid"]).ToString()),
1565 AdminId = Convert.ToInt32(((row["AdminId"] == DBNull.Value || row["AdminId"] == null) ? "0" : row["AdminId"]).ToString()),
1566 TotalDaysHoursUsed = Convert.ToDecimal(((row["TotalDaysHoursUsed"] == DBNull.Value || row["TotalDaysHoursUsed"] == null) ? "0" : row["TotalDaysHoursUsed"]).ToString()),
1567 DaysOffAbsentType = Convert.ToInt32(((row["DaysOffAbsentType"] == DBNull.Value || row["DaysOffAbsentType"] == null) ? "0" : row["DaysOffAbsentType"]).ToString()),
1568 DayWiseAtendanceId = Convert.ToInt32(((row["DayWiseAtendanceId"] == DBNull.Value || row["DayWiseAtendanceId"] == null) ? "0" : row["DayWiseAtendanceId"]).ToString()),
1569 companyname = Convert.ToString(((row["companyname"] == DBNull.Value || row["companyname"] == null) ? "" : row["companyname"]).ToString()),
1570 TeamName = Convert.ToString(((row["TeamName"] == DBNull.Value || row["TeamName"] == null) ? "" : row["TeamName"]).ToString()),
1571 affiliateid = Convert.ToString(((row["affiliateid"] == DBNull.Value || row["affiliateid"] == null) ? "" : row["affiliateid"]).ToString()),
1572 telephone = Convert.ToString(((row["telephone"] == DBNull.Value || row["telephone"] == null) ? "" : row["telephone"]).ToString()),
1573 email = Convert.ToString(((row["email"] == DBNull.Value || row["email"] == null) ? "" : row["email"]).ToString()),
1574 contactname = Convert.ToString(((row["contactname"] == DBNull.Value || row["contactname"] == null) ? "" : row["contactname"]).ToString()),
1575 ActivityDate = (row["ActivityStartDate"] == DBNull.Value || row["ActivityStartDate"] == null) ? System.DateTime.Now : Convert.ToDateTime(row["ActivityStartDate"]),
1576 Start = (row["ActivityStartDate"] == DBNull.Value || row["ActivityStartDate"] == null) ? System.DateTime.Now : Convert.ToDateTime(row["ActivityStartDate"]),
1577 End = (row["ActivityEndDate"] == DBNull.Value || row["ActivityEndDate"] == null) ? System.DateTime.Now : Convert.ToDateTime(row["ActivityEndDate"]),
1578 IsAllDay = true,
1579 Title = Convert.ToString(((row["contactname"] == DBNull.Value || row["contactname"] == null) ? "" : row["contactname"]).ToString())
1580
1581 }).ToList();
1582 }
1583 catch (Exception)
1584 {
1585
1586 }
1587 return _teams;
1588 }
1589
1590 public List<Attendance> GetUserDayWiseAttendanceReportByBrokerName(int UserType, int Id, string BrokerName, string ActivityDate, int TeamId, int ViewType, string AttendanceTypes, int Year)
1591 {
1592 int accountid = Convert.ToInt32(con.Session["LoggedInUserAccountId"]);
1593 List<Attendance> _teams = new List<Attendance>();
1594 string activitydate = System.DateTime.Now.ToString("dd/MM/yyyy");
1595 if (!string.IsNullOrWhiteSpace(ActivityDate))
1596 activitydate = ActivityDate.GetDate().Value.ToString("dd/MM/yyyy");
1597
1598 try
1599 {
1600 SqlParameter[] Param = new SqlParameter[9];
1601 Param[0] = new SqlParameter("@UserType", UserType);
1602 Param[1] = new SqlParameter("@Id", Id);
1603 Param[2] = new SqlParameter("@UserId", BrokerName);
1604 if (TeamId > 0)
1605 Param[3] = new SqlParameter("@TeamId", TeamId);
1606 if (!string.IsNullOrWhiteSpace(ActivityDate))
1607 Param[4] = new SqlParameter("@ActivityDate", activitydate);
1608 Param[5] = new SqlParameter("@ViewType", ViewType);
1609 Param[6] = new SqlParameter("@AccountId", accountid);
1610 if (!string.IsNullOrWhiteSpace(AttendanceTypes))
1611 Param[7] = new SqlParameter("@AttendanceTypes", AttendanceTypes);
1612 Param[8] = new SqlParameter("@Year", Year);
1613
1614 DataTable dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "USPGetUserDayWiseAttendanceReportByBrokerName", Param);
1615 _teams = (from DataRow row in dt.Rows
1616 select new Attendance
1617 {
1618 clientid = Convert.ToInt32(((row["clientid"] == DBNull.Value || row["clientid"] == null) ? "0" : row["clientid"]).ToString()),
1619 TeamId = Convert.ToInt32(((row["TeamId"] == DBNull.Value || row["TeamId"] == null) ? "0" : row["TeamId"]).ToString()),
1620 parent = Convert.ToInt32(((row["parent"] == DBNull.Value || row["parent"] == null) ? "0" : row["parent"]).ToString()),
1621 address = Convert.ToInt32(((row["address"] == DBNull.Value || row["address"] == null) ? "0" : row["address"]).ToString()),
1622 userid = Convert.ToInt32(((row["userid"] == DBNull.Value || row["userid"] == null) ? "0" : row["userid"]).ToString()),
1623 AdminId = Convert.ToInt32(((row["AdminId"] == DBNull.Value || row["AdminId"] == null) ? "0" : row["AdminId"]).ToString()),
1624 TotalDaysHoursUsed = Convert.ToDecimal(((row["TotalDaysHoursUsed"] == DBNull.Value || row["TotalDaysHoursUsed"] == null) ? "0" : row["TotalDaysHoursUsed"]).ToString()),
1625 DaysOffAbsentType = Convert.ToInt32(((row["DaysOffAbsentType"] == DBNull.Value || row["DaysOffAbsentType"] == null) ? Occfinance.Helpers.eAttendenceType.FullDayPresent : row["DaysOffAbsentType"]).ToString()),
1626 DayWiseAtendanceId = Convert.ToInt32(((row["DayWiseAtendanceId"] == DBNull.Value || row["DayWiseAtendanceId"] == null) ? "0" : row["DayWiseAtendanceId"]).ToString()),
1627 companyname = Convert.ToString(((row["companyname"] == DBNull.Value || row["companyname"] == null) ? "" : row["companyname"]).ToString()),
1628 TeamName = Convert.ToString(((row["TeamName"] == DBNull.Value || row["TeamName"] == null) ? "" : row["TeamName"]).ToString()),
1629 affiliateid = Convert.ToString(((row["affiliateid"] == DBNull.Value || row["affiliateid"] == null) ? "" : row["affiliateid"]).ToString()),
1630 telephone = Convert.ToString(((row["telephone"] == DBNull.Value || row["telephone"] == null) ? "" : row["telephone"]).ToString()),
1631 email = Convert.ToString(((row["email"] == DBNull.Value || row["email"] == null) ? "" : row["email"]).ToString()),
1632 contactname = Convert.ToString(((row["contactname"] == DBNull.Value || row["contactname"] == null) ? "" : row["contactname"]).ToString()),
1633 ActivityDate = (row["ActivityDate"] == DBNull.Value || row["ActivityDate"] == null) ? System.DateTime.Now : Convert.ToDateTime(row["ActivityDate"].ToString()),
1634 ActivityStartTime = (row["ActivityStartTime"] == DBNull.Value || row["ActivityStartTime"] == null) ? System.DateTime.Now : Convert.ToDateTime(row["ActivityStartTime"].ToString()),
1635 ActivityEndTime = (row["ActivityEndTime"] == DBNull.Value || row["ActivityEndTime"] == null) ? System.DateTime.Now : Convert.ToDateTime(row["ActivityEndTime"].ToString()),
1636 Start = (row["ActivityDate"] == DBNull.Value || row["ActivityDate"] == null) ? System.DateTime.Now : Convert.ToDateTime(row["ActivityStartTime"]),
1637 End = (row["ActivityDate"] == DBNull.Value || row["ActivityDate"] == null) ? System.DateTime.Now : Convert.ToDateTime(row["ActivityEndTime"]),
1638 IsAllDay = true,
1639 Title = row["IsHoliday"].ToString() != "1" ? (Convert.ToString(((row["contactname"] == DBNull.Value || row["contactname"] == null) ? "" : row["contactname"]).ToString())) : Convert.ToString(((row["HolidayTitle"] == DBNull.Value || row["HolidayTitle"] == null) ? "" : row["HolidayTitle"]).ToString()),
1640 IsHoliday = Convert.ToInt32(((row["IsHoliday"] == DBNull.Value || row["IsHoliday"] == null) ? "0" : row["IsHoliday"]).ToString()),
1641 Holiday = (row["Holiday"] == DBNull.Value || row["Holiday"] == null || row["Holiday"] == "") ? (DateTime?)null : Convert.ToDateTime(row["Holiday"]),
1642 HolidayTitle = Convert.ToString(((row["HolidayTitle"] == DBNull.Value || row["HolidayTitle"] == null) ? "" : row["HolidayTitle"]).ToString()),
1643 HolidayDescription = Convert.ToString(((row["HolidayDescription"] == DBNull.Value || row["HolidayDescription"] == null) ? "" : row["HolidayDescription"]).ToString()),
1644
1645 }).ToList();
1646 }
1647 catch (Exception)
1648 {
1649
1650 }
1651 return _teams;
1652 }
1653
1654
1655 public int UpdateAttendanceMultipleUsers(string FromDate, string ToDate, int AttendanceType, decimal _usedHours , int userid, int loggedinuser, int accountid)
1656 {
1657 int _chk = 0;
1658 try
1659 {
1660
1661 using (SqlConnection con = new SqlConnection(Convert.ToString(System.Configuration.ConfigurationManager.ConnectionStrings["ConString1"])))
1662 {
1663 con.Open();
1664 SqlDataAdapter com = new SqlDataAdapter("UserMultiAttendanceReportAddUpdate", con);
1665 com.SelectCommand.CommandType = CommandType.StoredProcedure;
1666 com.SelectCommand.Parameters.AddWithValue("@UserId", userid);
1667 com.SelectCommand.Parameters.AddWithValue("@TotalDaysHoursUsed", _usedHours);
1668 com.SelectCommand.Parameters.AddWithValue("@DaysOffAbsentType", AttendanceType);
1669 com.SelectCommand.Parameters.AddWithValue("@FirstDate", FromDate.GetDate().Value.ToString("MM/dd/yyyy"));
1670 com.SelectCommand.Parameters.AddWithValue("@LastDate", ToDate.GetDate().Value.ToString("MM/dd/yyyy"));
1671 com.SelectCommand.Parameters.AddWithValue("@EntryBy", loggedinuser);
1672 com.SelectCommand.Parameters.AddWithValue("@IsActive", true);
1673 com.SelectCommand.Parameters.AddWithValue("@IsDelete", false);
1674 com.SelectCommand.Parameters.AddWithValue("@ActionType", 2);
1675 com.SelectCommand.Parameters.AddWithValue("@AccountId", accountid);
1676 SqlParameter outParam1 = com.SelectCommand.Parameters.Add("@Chk", SqlDbType.Int);
1677 outParam1.Direction = ParameterDirection.Output;
1678 var x = com.SelectCommand.ExecuteNonQuery();
1679 _chk += x;
1680
1681 }
1682 }
1683 catch { }
1684
1685 return _chk;
1686 }
1687
1688 }
1689}
1690
1691public int AddUpdateDependant(tblDependant dependent, bool useTransaction, SqlTransaction tran, SqlConnection con)
1692 {
1693 int completed = 0;
1694
1695 if (dependent.DependantID == 0)
1696 {
1697 SqlParameter[] par = new SqlParameter[]
1698 {
1699 new SqlParameter("@Applicant", dependent.Applicant),
1700 new SqlParameter("@DOB", !string.IsNullOrWhiteSpace(dependent.StrDependentDOB) ? Helper.GetDate(dependent.StrDependentDOB) : null),
1701 new SqlParameter("@ClientRegistrationID", dependent.ClientRegistrationID),//set clientid in model after model binding
1702 new SqlParameter("@AddDate", DateTime.Now),
1703 new SqlParameter("@result", SqlDbType.Int){Direction = ParameterDirection.Output},
1704 new SqlParameter("@ReferId", dependent.ReferId),
1705 new SqlParameter("@Name", dependent.Name)
1706 };
1707 if (useTransaction)
1708 { SqlHelper.ExecuteNonQueryWithTransaction(CommandType.StoredProcedure, "tblInsertDependant", tran, con, par); }
1709 else
1710 { SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "tblInsertDependant", par); }
1711 completed = Convert.ToInt32(par[4] != null ? par[4].SqlValue.ToString() : "0");
1712 }
1713 else
1714 {
1715 SqlParameter[] par = new SqlParameter[]
1716 {
1717 new SqlParameter("@Applicant", dependent.Applicant),
1718 new SqlParameter("@DOB", !string.IsNullOrWhiteSpace(dependent.StrDependentDOB) ? Helper.GetDate(dependent.StrDependentDOB) : null),
1719 new SqlParameter("@UpdateDate", DateTime.Now),
1720 new SqlParameter("@UpdateBy", dependent.UpdateBy),//set updated by id in model after model binding
1721 new SqlParameter("@result", SqlDbType.Int){Direction = ParameterDirection.Output},
1722 new SqlParameter("@DependantID", dependent.DependantID),
1723 new SqlParameter("@ReferId", dependent.ReferId),
1724 new SqlParameter("@ClientRegistrationID", dependent.ClientRegistrationID),
1725 new SqlParameter("@Name", dependent.Name)
1726 };
1727 if (useTransaction)
1728 { SqlHelper.ExecuteNonQueryWithTransaction(CommandType.StoredProcedure, "tblUpdateDependant", tran, con, par); }
1729 else
1730 { SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "tblUpdateDependant", par); }
1731 completed = Convert.ToInt32(par[4] != null ? par[4].SqlValue.ToString() : "0");
1732
1733 }
1734
1735 return completed;
1736 }
1737
1738using Occfinance_Data;
1739using System;
1740using System.Collections.Generic;
1741using System.Linq;
1742using System.Web;
1743
1744namespace Occfinance.Code
1745{
1746 public class Q_mortgagerate
1747 {
1748 public db_occfinance_5572Entities ctx = new db_occfinance_5572Entities();
1749 System.Web.HttpContext con = HttpContext.Current;
1750
1751 #region Add Broker
1752
1753 public bool AddMortgageRate(string RateValue, string inpLTV, out int mortgageid)
1754 {
1755 bool result = false;
1756 mortgageid = 0;
1757 try
1758 {
1759 if (con.Session["LoggedInUserAccountId"] != null)
1760 {
1761
1762 tblaccount_mortgagerates mortgageRate = new tblaccount_mortgagerates();
1763 mortgageRate.rate = Convert.ToDouble(RateValue);
1764 mortgageRate.ltv = Convert.ToInt32(inpLTV);
1765 mortgageRate.accountid = Convert.ToInt32(con.Session["LoggedInUserAccountId"]);
1766 ctx.tblaccount_mortgagerates.Add(mortgageRate);
1767 ctx.SaveChanges();
1768 result = true;
1769 mortgageid = mortgageRate.accountid ;
1770 }
1771
1772
1773
1774 return result;
1775 }
1776 catch (Exception)
1777 {
1778 return result;
1779 }
1780 }
1781 #endregion
1782
1783 #region Delete Broker
1784
1785 public bool DeleteMortgageRate(int Mortgageid)
1786 {
1787 bool result = false;
1788 try
1789 {
1790 if (con.Session["LoggedInUserAccountId"] != null)
1791 {
1792 int parentaccountId = Convert.ToInt32(con.Session["LoggedInUserAccountId"]);
1793 var _MortgageRate = ctx.tblaccount_mortgagerates.Where(a => a.accountid == parentaccountId && a.ltv == Mortgageid).Select(a => a).FirstOrDefault();
1794 if (_MortgageRate != null)
1795 {
1796
1797
1798 ctx.tblaccount_mortgagerates.Remove(_MortgageRate);
1799 ctx.SaveChanges();
1800 result = true;
1801
1802 }
1803 }
1804 return result;
1805 }
1806 catch (Exception)
1807 {
1808 return result;
1809 }
1810 }
1811
1812 #endregion
1813 }
1814}
1815
1816using System;
1817using System.Collections.Generic;
1818using System.Linq;
1819using System.Web;
1820using Occfinance_Data;
1821using Occfinance.Models;
1822using Occfinance.Helpers;
1823using System.Data;
1824using System.Data.SqlClient;
1825
1826namespace Occfinance.Code
1827{
1828 public class Q_NewLead
1829 {
1830 public db_occfinance_5572Entities ctx = new db_occfinance_5572Entities();
1831
1832 System.Web.HttpContext con = HttpContext.Current;
1833
1834 #region Find contacts for account
1835
1836 public List<tblcontact> FindContactsForAccount(int accountid)
1837 {
1838 var cntlists = ctx.tblcontacts.Where(c => c.account.HasValue && c.account.Value == accountid).Select(c => c).ToList();
1839 return cntlists;
1840 }
1841
1842 #endregion
1843
1844 #region Save lead information to database
1845
1846 public bool SaveNewLead(tblcontact data, tblfinance_mortgage dataM, tblOtherApplicant _objO, out int _contactid, int mstatusid = 1, string Note = "", string mortage_date = "", string mortage_time = "",int subStatusId = 0)
1847 {
1848 bool result = false;
1849 try
1850 {
1851 #region [Add branch and negotiators 2015-11-02]
1852
1853 data.BranchId = GetBranchId(data.branch);
1854 data.NegrefId = GetNegotiatorId(data.negref);
1855 data.branch = string.Empty;
1856 data.negref = string.Empty;
1857
1858 #endregion [Add branch and negotiators 2015-11-02]
1859
1860 ctx.tblcontacts.Add(data);
1861 ctx.SaveChanges();
1862 int cntid = _contactid = data.contactid;
1863 if (cntid > 0)
1864 {
1865 //Save Finance information to database
1866 tblfinance dataFinance = new tblfinance();
1867 dataFinance.contact = cntid;
1868 dataFinance.status = mstatusid;
1869 dataFinance.type = 1;
1870 dataFinance.subFinanceStatus = subStatusId;
1871 dataFinance.created = System.DateTime.Now;
1872
1873 try
1874 {
1875 if (!string.IsNullOrWhiteSpace(mortage_date))
1876 dataFinance.followup = Helper.GetFollowUp(mortage_date, string.IsNullOrWhiteSpace(mortage_time) ? (DateTime.Now.Hour + ":" + DateTime.Now.Minute + ":" + DateTime.Now.Second).ToString() : mortage_time);
1877 }
1878 catch (Exception ex)
1879 {
1880 Helper.ErrorLog(ex.InnerException, "Q_NewLead", "SaveNewLead", ex.Message);
1881 }
1882
1883 ctx.tblfinances.Add(dataFinance);
1884 ctx.SaveChanges();
1885 int financeid = dataFinance.financeid;
1886 if (financeid > 0)
1887 {
1888 //Save mortgage information to database
1889 tblfinance_mortgage dataFinanceMortgage = new tblfinance_mortgage();
1890
1891 dataFinanceMortgage.financeid = financeid;
1892 dataFinanceMortgage.purchase = dataM.purchase;
1893 dataFinanceMortgage.rterm = dataM.rterm;
1894 dataFinanceMortgage.deposit = dataM.deposit;
1895 dataFinanceMortgage.income = dataM.income;
1896 ctx.tblfinance_mortgage.Add(dataFinanceMortgage);
1897 ctx.SaveChanges();
1898 //Add Note While get registered from New Lead page***********************
1899 try
1900 {
1901 if (!string.IsNullOrWhiteSpace(Note))
1902 {
1903 int loggedinuserid = Convert.ToInt32(con.Session["LoggedInUserId"] ?? "0");
1904 tblnote _note = new tblnote();
1905 Q_Application _qA = new Q_Application();
1906 _note.financeid = financeid;
1907 _note.contact = cntid;
1908 _note.note = Note;
1909 _note.created = System.DateTime.Now;
1910 _note.UserId = loggedinuserid;
1911 ctx.tblnotes.Add(_note);
1912 ctx.SaveChanges();
1913 }
1914 }
1915 catch (Exception ex)
1916 {
1917 Helper.ErrorLog(ex.InnerException, "Q_NewLead", "SaveNewLead", ex.Message);
1918 }
1919 //********************************
1920 }
1921
1922 if (_objO != null && (!string.IsNullOrWhiteSpace(_objO.FirstName) || !string.IsNullOrWhiteSpace(_objO.SurName) || !string.IsNullOrWhiteSpace(_objO.Email) || !string.IsNullOrWhiteSpace(_objO.MobileNumber)))
1923 {
1924 _objO.MainContactId = cntid;
1925 ctx.tblOtherApplicants.Add(_objO);
1926 ctx.SaveChanges();
1927 }
1928 }
1929 result = true;
1930 return result;
1931 }
1932 catch (Exception ex)
1933 {
1934 _contactid = 0;
1935 Helper.ErrorLog(ex.InnerException,"Q_NewLead","SaveNewLead",ex.Message);
1936 return result;
1937 }
1938 }
1939
1940
1941
1942 // Updated on 20-10-2014 for Individual Product TYpe Entry
1943 public bool SaveNewLeadForLife(tblcontact data, tblfinance_mortgage dataM, tblOtherApplicant _objO, out int _contactid, decimal amount = 0, decimal premium = 0, decimal commission = 0, string policyreference = "", int mstatusid = 1, int lstatusid = 10, string Note = "", string life_followupdate = "", string life_followuptime = "",bool IsPolicyForOtherApplicant=false )
1944 {
1945 bool result = false;
1946 try
1947 {
1948 #region [Add branch and negotiators 2015-11-02]
1949
1950 data.BranchId = GetBranchId(data.branch);
1951 data.NegrefId = GetNegotiatorId(data.negref);
1952 data.branch = string.Empty;
1953 data.negref = string.Empty;
1954
1955 #endregion [Add branch and negotiators 2015-11-02]
1956
1957 ctx.tblcontacts.Add(data);
1958 ctx.SaveChanges();
1959 int cntid = _contactid = data.contactid;
1960 if (cntid > 0)
1961 {
1962
1963
1964 //Save Finance information to database Fopr Mortgage
1965 tblfinance dataFinanceM = new tblfinance();
1966 dataFinanceM.contact = cntid;
1967 dataFinanceM.status = mstatusid;
1968 dataFinanceM.type = 1;
1969 dataFinanceM.created = System.DateTime.Now;
1970 ctx.tblfinances.Add(dataFinanceM);
1971 ctx.SaveChanges();
1972
1973 int financeid = dataFinanceM.financeid;
1974 if (financeid > 0)
1975 {
1976 //Save mortgage information to database
1977 tblfinance_mortgage dataFinanceMortgage = new tblfinance_mortgage();
1978
1979 dataFinanceMortgage.financeid = financeid;
1980 dataFinanceMortgage.purchase = dataM.purchase;
1981 dataFinanceMortgage.rterm = dataM.rterm;
1982 dataFinanceMortgage.deposit = dataM.deposit;
1983 dataFinanceMortgage.income = dataM.income;
1984 ctx.tblfinance_mortgage.Add(dataFinanceMortgage);
1985 ctx.SaveChanges();
1986
1987
1988 }
1989
1990 //Save Finance information to database For Life
1991 tblfinance dataFinance = new tblfinance();
1992 dataFinance.contact = cntid;
1993 dataFinance.status = lstatusid; // For Life New Lead................
1994 dataFinance.type = 2; // When finance type is Life
1995
1996 //While Life ------------------
1997 dataFinance.amount = amount;
1998 dataFinance.commission = commission;
1999 dataFinance.premium = premium;
2000 dataFinance.policyreference = policyreference;
2001 //added on 04-04-2015
2002 dataFinance.isPolicyForOtherApplicant = IsPolicyForOtherApplicant;
2003
2004 try
2005 {
2006 if (!string.IsNullOrWhiteSpace(life_followupdate))
2007 dataFinance.followup = Helper.GetFollowUp(life_followupdate, string.IsNullOrWhiteSpace(life_followuptime) ? (DateTime.Now.Hour + ":" + DateTime.Now.Minute + ":" + DateTime.Now.Second).ToString() : life_followuptime);
2008
2009 }
2010 catch { }
2011
2012 dataFinance.created = System.DateTime.Now;
2013 ctx.tblfinances.Add(dataFinance);
2014 ctx.SaveChanges();
2015
2016 int financeidL = dataFinance.financeid;
2017 if (financeidL > 0)
2018 {
2019 //Save To Life table************************************************************
2020 tblfinance_insurance dataLife = new tblfinance_insurance();
2021 dataLife.financeid = financeidL;
2022 dataLife.smoker = false;
2023
2024
2025 ctx.tblfinance_insurance.Add(dataLife);
2026 ctx.SaveChanges();
2027 //******************************************************************************
2028
2029 //Add Note While get registered from New Lead page***********************
2030 try
2031 {
2032 if (!string.IsNullOrWhiteSpace(Note))
2033 {
2034 int loggedinuserid = Convert.ToInt32(con.Session["LoggedInUserId"] ?? "0");
2035 tblnote _note = new tblnote();
2036 Q_Application _qA = new Q_Application();
2037 //int _noteid = _qA.getNoteID();
2038 //_note.noteid = _noteid;
2039 _note.financeid = financeidL;
2040 _note.contact = cntid;
2041 _note.note = Note;
2042 _note.created = System.DateTime.Now;
2043 _note.UserId = loggedinuserid;
2044 ctx.tblnotes.Add(_note);
2045 ctx.SaveChanges();
2046 }
2047 }
2048 catch { }
2049 //********************************
2050 }
2051
2052
2053 if (_objO != null && (!string.IsNullOrWhiteSpace(_objO.FirstName) || !string.IsNullOrWhiteSpace(_objO.SurName) || !string.IsNullOrWhiteSpace(_objO.Email) || !string.IsNullOrWhiteSpace(_objO.MobileNumber)))
2054 {
2055 _objO.MainContactId = cntid;
2056 ctx.tblOtherApplicants.Add(_objO);
2057 ctx.SaveChanges();
2058 }
2059 }
2060 result = true;
2061 return result;
2062 }
2063 catch (Exception ex)
2064 {
2065 _contactid = 0;
2066 return result;
2067 }
2068 }
2069 // Updated on 20-10-2014 for Individual Product TYpe Entry
2070 #endregion
2071
2072 #region Save lead information to database For Mobile
2073
2074 public bool Mobile_SaveNewLead(int userId,tblcontact data, tblfinance_mortgage dataM, tblOtherApplicant _objO, out int _contactid, int mstatusid = 1, string Note = "", string mortage_date = "", string mortage_time = "")
2075 {
2076 bool result = false;
2077 try
2078 {
2079 #region [Add branch and negotiators 2015-11-02]
2080
2081 data.BranchId = GetBranchId(data.branch);
2082 data.NegrefId = GetNegotiatorId(data.negref);
2083 data.branch = string.Empty;
2084 data.negref = string.Empty;
2085
2086 #endregion [Add branch and negotiators 2015-11-02]
2087
2088 ctx.tblcontacts.Add(data);
2089 ctx.SaveChanges();
2090 int cntid = _contactid = data.contactid;
2091 if (cntid > 0)
2092 {
2093 //Save Finance information to database
2094 tblfinance dataFinance = new tblfinance();
2095 dataFinance.contact = cntid;
2096 dataFinance.status = mstatusid;
2097 dataFinance.type = 1;
2098 dataFinance.created = System.DateTime.Now;
2099
2100 try
2101 {
2102 if (!string.IsNullOrWhiteSpace(mortage_date))
2103 dataFinance.followup = Helper.GetFollowUp(mortage_date, string.IsNullOrWhiteSpace(mortage_time) ? (DateTime.Now.Hour + ":" + DateTime.Now.Minute + ":" + DateTime.Now.Second).ToString() : mortage_time);
2104 }
2105 catch { }
2106
2107 ctx.tblfinances.Add(dataFinance);
2108 ctx.SaveChanges();
2109 int financeid = dataFinance.financeid;
2110 if (financeid > 0)
2111 {
2112 //Save mortgage information to database
2113 tblfinance_mortgage dataFinanceMortgage = new tblfinance_mortgage();
2114
2115 dataFinanceMortgage.financeid = financeid;
2116 dataFinanceMortgage.purchase = dataM.purchase;
2117 dataFinanceMortgage.rterm = dataM.rterm;
2118 dataFinanceMortgage.deposit = dataM.deposit;
2119 dataFinanceMortgage.income = dataM.income;
2120 ctx.tblfinance_mortgage.Add(dataFinanceMortgage);
2121 ctx.SaveChanges();
2122
2123
2124
2125 //Add Note While get registered from New Lead page***********************
2126 try
2127 {
2128 if (!string.IsNullOrWhiteSpace(Note))
2129 {
2130 int loggedinuserid = userId;
2131 tblnote _note = new tblnote();
2132 Q_Application _qA = new Q_Application();
2133 //int _noteid = _qA.getNoteID();
2134 //_note.noteid = _noteid;
2135 _note.financeid = financeid;
2136 _note.contact = cntid;
2137 _note.note = Note;
2138 _note.created = System.DateTime.Now;
2139 _note.UserId = loggedinuserid;
2140 ctx.tblnotes.Add(_note);
2141 ctx.SaveChanges();
2142 }
2143 }
2144 catch { }
2145 //********************************
2146 }
2147
2148 if (_objO != null && (!string.IsNullOrWhiteSpace(_objO.FirstName) || !string.IsNullOrWhiteSpace(_objO.SurName) || !string.IsNullOrWhiteSpace(_objO.Email) || !string.IsNullOrWhiteSpace(_objO.MobileNumber)))
2149 {
2150 _objO.MainContactId = cntid;
2151 ctx.tblOtherApplicants.Add(_objO);
2152 ctx.SaveChanges();
2153 }
2154 }
2155 result = true;
2156 return result;
2157 }
2158 catch (Exception ex)
2159 {
2160 _contactid = 0;
2161 return result;
2162 }
2163 }
2164
2165 public bool Mobile_SaveNewLeadForLife(int userId,tblcontact data, tblfinance_mortgage dataM, tblOtherApplicant _objO, out int _contactid, decimal amount = 0, decimal premium = 0, decimal commission = 0, string policyreference = "", int mstatusid = 1, int lstatusid = 10, string Note = "", string life_followupdate = "", string life_followuptime = "", bool IsPolicyForOtherApplicant = false)
2166 {
2167 bool result = false;
2168 try
2169 {
2170 #region [Add branch and negotiators 2015-11-02]
2171
2172 data.BranchId = GetBranchId(data.branch);
2173 data.NegrefId = GetNegotiatorId(data.negref);
2174 data.branch = string.Empty;
2175 data.negref = string.Empty;
2176
2177 #endregion [Add branch and negotiators 2015-11-02]
2178
2179 ctx.tblcontacts.Add(data);
2180 ctx.SaveChanges();
2181 int cntid = _contactid = data.contactid;
2182 if (cntid > 0)
2183 {
2184
2185
2186 //Save Finance information to database Fopr Mortgage
2187 tblfinance dataFinanceM = new tblfinance();
2188 dataFinanceM.contact = cntid;
2189 dataFinanceM.status = mstatusid;
2190 dataFinanceM.type = 1;
2191 dataFinanceM.created = System.DateTime.Now;
2192 ctx.tblfinances.Add(dataFinanceM);
2193 ctx.SaveChanges();
2194
2195 int financeid = dataFinanceM.financeid;
2196 if (financeid > 0)
2197 {
2198 //Save mortgage information to database
2199 tblfinance_mortgage dataFinanceMortgage = new tblfinance_mortgage();
2200
2201 dataFinanceMortgage.financeid = financeid;
2202 dataFinanceMortgage.purchase = dataM.purchase;
2203 dataFinanceMortgage.rterm = dataM.rterm;
2204 dataFinanceMortgage.deposit = dataM.deposit;
2205 dataFinanceMortgage.income = dataM.income;
2206 ctx.tblfinance_mortgage.Add(dataFinanceMortgage);
2207 ctx.SaveChanges();
2208
2209
2210 }
2211
2212 //Save Finance information to database For Life
2213 tblfinance dataFinance = new tblfinance();
2214 dataFinance.contact = cntid;
2215 dataFinance.status = lstatusid; // For Life New Lead................
2216 dataFinance.type = 2; // When finance type is Life
2217
2218 //While Life ------------------
2219 dataFinance.amount = amount;
2220 dataFinance.commission = commission;
2221 dataFinance.premium = premium;
2222 dataFinance.policyreference = policyreference;
2223 //added on 04-04-2015
2224 dataFinance.isPolicyForOtherApplicant = IsPolicyForOtherApplicant;
2225 try
2226 {
2227 if (!string.IsNullOrWhiteSpace(life_followupdate))
2228 dataFinance.followup = Helper.GetFollowUp(life_followupdate, string.IsNullOrWhiteSpace(life_followuptime) ? (DateTime.Now.Hour + ":" + DateTime.Now.Minute + ":" + DateTime.Now.Second).ToString() : life_followuptime);
2229
2230 }
2231 catch { }
2232
2233 dataFinance.created = System.DateTime.Now;
2234 ctx.tblfinances.Add(dataFinance);
2235 ctx.SaveChanges();
2236
2237 int financeidL = dataFinance.financeid;
2238 if (financeidL > 0)
2239 {
2240 //Save To Life table************************************************************
2241 tblfinance_insurance dataLife = new tblfinance_insurance();
2242 dataLife.financeid = financeidL;
2243 dataLife.smoker = false;
2244
2245
2246 ctx.tblfinance_insurance.Add(dataLife);
2247 ctx.SaveChanges();
2248 //******************************************************************************
2249
2250 //Add Note While get registered from New Lead page***********************
2251 try
2252 {
2253 if (!string.IsNullOrWhiteSpace(Note))
2254 {
2255 int loggedinuserid = userId;
2256 tblnote _note = new tblnote();
2257 Q_Application _qA = new Q_Application();
2258 //int _noteid = _qA.getNoteID();
2259 //_note.noteid = _noteid;
2260 _note.financeid = financeidL;
2261 _note.contact = cntid;
2262 _note.note = Note;
2263 _note.created = System.DateTime.Now;
2264 _note.UserId = loggedinuserid;
2265 ctx.tblnotes.Add(_note);
2266 ctx.SaveChanges();
2267 }
2268 }
2269 catch { }
2270 //********************************
2271 }
2272
2273
2274 if (_objO != null && (!string.IsNullOrWhiteSpace(_objO.FirstName) || !string.IsNullOrWhiteSpace(_objO.SurName) || !string.IsNullOrWhiteSpace(_objO.Email) || !string.IsNullOrWhiteSpace(_objO.MobileNumber)))
2275 {
2276 _objO.MainContactId = cntid;
2277 ctx.tblOtherApplicants.Add(_objO);
2278 ctx.SaveChanges();
2279 }
2280 }
2281 result = true;
2282 return result;
2283 }
2284 catch (Exception ex)
2285 {
2286 _contactid = 0;
2287 return result;
2288 }
2289 }
2290
2291 #endregion
2292
2293 #region [Add/Fetch Branch and Negotiator 2015-11-02]
2294
2295 /// <summary>
2296 /// Get negotiator id on the basis of negotiator name. If not already exist then add a new negotiator.
2297 /// </summary>
2298 /// <param name="negotiatorName"></param>
2299 /// <returns></returns>
2300 public int GetNegotiatorId(string negotiatorName)
2301 {
2302 if (string.IsNullOrEmpty(negotiatorName))
2303 return 0;
2304 var negotiatorId = 0;
2305 try
2306 {
2307 negotiatorId = ctx.tblNegotiators.Where(negt => negt.Negotiator == negotiatorName).Select(negt => negt.Id).FirstOrDefault();
2308 if (negotiatorId == null || negotiatorId == 0)
2309 {
2310 tblNegotiators negt = new tblNegotiators();
2311 negt.Negotiator = negotiatorName;
2312 ctx.tblNegotiators.Add(negt);
2313 ctx.SaveChanges();
2314 negotiatorId = negt.Id;
2315 }
2316 }
2317 catch (Exception ex)
2318 {
2319 Helper.ErrorLog(ex.InnerException, "Q_NewLead", "GetNegotiatorId", ex.Message);
2320 }
2321 return negotiatorId;
2322 }
2323
2324 /// <summary>
2325 /// Get branch id on the basis of branch name. add new branch if it does not already exist.
2326 /// </summary>
2327 /// <param name="branchName"></param>
2328 /// <returns></returns>
2329 public int GetBranchId(string branchName)
2330 {
2331 if (string.IsNullOrEmpty(branchName))
2332 return 0;
2333 var branchId = 0;
2334 try
2335 {
2336 branchId = ctx.tblBranches.Where(brn => brn.Branch == branchName).Select(brn => brn.Id).FirstOrDefault();
2337 if (branchId == null || branchId == 0)
2338 {
2339 tblBranches objBranch = new tblBranches();
2340 objBranch.Branch = branchName;
2341 ctx.tblBranches.Add(objBranch);
2342 ctx.SaveChanges();
2343 branchId = objBranch.Id;
2344 }
2345 }
2346 catch (Exception ex)
2347 {
2348 Helper.ErrorLog(ex.InnerException, "Q_NewLead", "GetBranchId", ex.Message);
2349 }
2350 return branchId;
2351 }
2352
2353 /// <summary>
2354 /// Get branch names on the basis of branch ids.
2355 /// </summary>
2356 /// <param name="contactlists"></param>
2357 /// <returns></returns>
2358 public List<string> GetBranchNamesFromBranchIds(List<tblcontact> contactlists)
2359 {
2360 List<string> branchLists = new List<string>();
2361 var branchIds = contactlists.Select(brn=>brn.BranchId);
2362 try
2363 {
2364 branchLists = ctx.tblBranches.Where(brn => branchIds.Contains(brn.Id)).Select(brn => brn.Branch).Distinct().ToList();
2365 }
2366 catch (Exception ex)
2367 {
2368 Helper.ErrorLog(ex.InnerException, "Q_NewLead", "GetBranchNamesFromBranchIds", ex.Message);
2369 }
2370 return branchLists;
2371 }
2372
2373 /// <summary>
2374 /// Get negotiator names on the basis of negotiator ids.
2375 /// </summary>
2376 /// <param name="contactlists"></param>
2377 /// <returns></returns>
2378 public List<string> GetNegotiatorNamesFromNegotiatorIds(List<tblcontact> contactlists)
2379 {
2380 List<string> negotitorLists = new List<string>();
2381 var negotiatorIds = contactlists.Select(brn => brn.NegrefId);
2382 try
2383 {
2384 negotitorLists = ctx.tblNegotiators.Where(negt => negotiatorIds.Contains(negt.Id)).Select(negt => negt.Negotiator).Distinct().ToList();
2385 }
2386 catch (Exception ex)
2387 {
2388 Helper.ErrorLog(ex.InnerException, "Q_NewLead", "GetBranchNamesFromBranchIds", ex.Message);
2389 }
2390 return negotitorLists;
2391 }
2392
2393
2394 public DataSet GetBranchAndNegotiatorByAccountId(int accountId)
2395 {
2396 SqlParameter[] Param = new SqlParameter[1];
2397 Param[0] = new SqlParameter("@accountId", accountId);
2398 DataSet ds = SqlHelper.ExecuteDataset(CommandType.StoredProcedure, "GetBranchAndNegotiatorByAccountId", Param);
2399 return ds;
2400 }
2401
2402
2403 #endregion [Add/Fetch Branch and Negotiator 2015-11-02]
2404
2405
2406
2407 }
2408}
2409
2410
2411using Occfinance_Data;
2412using System;
2413using System.Collections.Generic;
2414using System.Linq;
2415using System.Web;
2416using Occfinance.Models;
2417using System.Data.SqlClient;
2418using System.Data;
2419using Occfinance.Helpers;
2420using System.Data.Entity.Infrastructure;
2421
2422namespace Occfinance.Code
2423{
2424 public class Q_ReportsDataForScreen
2425 {
2426
2427 public db_occfinance_5572Entities ctx = new db_occfinance_5572Entities();
2428 System.Web.HttpContext con = HttpContext.Current;
2429 #region [Methods For Big screen]
2430 #region [All CLients]
2431 public List<DashboardClients> FindDashboardClients(int parentuserid, int userId = 0)
2432 {
2433 List<DashboardClients> clients = new List<DashboardClients>();
2434 try
2435 {
2436
2437 SqlParameter[] Param = new SqlParameter[2];
2438 Param[0] = new SqlParameter("@parentuserid", parentuserid);
2439 Param[1] = new SqlParameter("@filteredaccount", null);
2440
2441 DataTable dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "GetAgentAndBranchListForScreen", Param);
2442
2443 clients = (from DataRow row in dt.Rows
2444 select new DashboardClients
2445 {
2446 clientid = Convert.ToInt32(((row["accountid"] == DBNull.Value || row["accountid"] == null) ? "0" : row["accountid"]).ToString()),
2447 companyname = ((row["companyname"] == DBNull.Value || row["companyname"] == null) ? " " : row["companyname"]).ToString(),
2448 averageLeads = Convert.ToInt32(((row["average"] == DBNull.Value || row["average"] == null) ? "0" : row["average"]).ToString()),
2449 countLeads = Convert.ToInt32(((row["total"] == DBNull.Value || row["total"] == null) ? "0" : row["total"]).ToString()),
2450 thisMonthLeads = Convert.ToInt32(((row["last30days"] == DBNull.Value || row["last30days"] == null) ? "0" : row["last30days"]).ToString()),
2451 lastLeadDate = (row["lastleaddate"] == DBNull.Value || row["lastleaddate"] == null) ? (DateTime?)null : Convert.ToDateTime(row["lastleaddate"]),
2452
2453 }).OrderBy(c => c.companyname).ToList();
2454
2455 return clients;
2456 }
2457 catch (Exception ex)
2458 {
2459 return clients;
2460 }
2461 }
2462 #endregion
2463 #region [All Brokers]
2464 public List<DashboardBrokers> FindDashboardBrokers(int parentuserid, int userId = 0)
2465 {
2466 bool flag = false;
2467 List<DashboardBrokers> clients = new List<DashboardBrokers>();
2468 try
2469 {
2470
2471 var userAccount = ctx.tblaccounts.Where(u => u.parent.HasValue && u.parent.Value == parentuserid).Select(u => u.accountid).ToList();
2472 var account = ctx.tblusers.Where(u => u.broker.HasValue && u.broker.Value == true && u.account == parentuserid).Select(u => u).ToList();
2473
2474 SqlParameter[] Param = new SqlParameter[1];
2475 Param[0] = new SqlParameter("@parentuserid", parentuserid);
2476 DataTable dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "GetBrokerListForScreen", Param);
2477
2478 if (dt != null)
2479 {
2480 clients = (from DataRow row1 in dt.Rows
2481 select new DashboardBrokers()
2482 {
2483 contactname = Convert.ToString(row1["brokername"] == null ? "" : row1["brokername"].ToString()),
2484 Completion_Average = Convert.ToInt32(row1["exaverage"] == null ? "0" : row1["exaverage"].ToString()),
2485 Completion_Total = Convert.ToInt32(row1["extotal"] == null ? "0" : row1["extotal"].ToString()),
2486 Completion_Last30 = Convert.ToInt32(row1["exlast30days"] == null ? "0" : row1["exlast30days"].ToString()),
2487 Completion_Change = Convert.ToInt32(row1["exChange"] == null ? "0" : row1["exChange"].ToString()),
2488 Decision_in_principle_Average = Convert.ToInt32(row1["dipaverage"] == null ? "0" : row1["dipaverage"].ToString()),
2489 Decision_in_principle_Total = Convert.ToInt32(row1["diptotal"] == null ? "0" : row1["diptotal"].ToString()),
2490 Decision_in_principle_Last30 = Convert.ToInt32(row1["diplast30days"] == null ? "0" : row1["diplast30days"].ToString()),
2491 Decision_in_principle_Change = Convert.ToInt32(row1["dipChange"] == null ? "0" : row1["dipChange"].ToString()),
2492 ApplicationsSubmitted_Average = Convert.ToInt32(row1["appsubaverage"] == null ? "0" : row1["appsubaverage"].ToString()),
2493 ApplicationsSubmitted_Total = Convert.ToInt32(row1["appsubtotal"] == null ? "0" : row1["appsubtotal"].ToString()),
2494 ApplicationsSubmitted_Last30 = Convert.ToInt32(row1["appsublast30days"] == null ? "0" : row1["appsublast30days"].ToString()),
2495 ApplicationsSubmitted_Change = Convert.ToInt32(row1["appChange"] == null ? "0" : row1["appChange"].ToString())
2496
2497 }).ToList();
2498 }
2499
2500
2501 return clients;
2502 }
2503 catch (Exception ex)
2504 {
2505 return clients;
2506 }
2507 }
2508 #endregion
2509 #region [Get Mortgage Report For Screen]
2510 public DataSet GetMortgageCaseWrittenReportForScreen(string type, DateTime fromdate, DateTime todate, int userid, int brokerId = 0, string Negotiator = "", string brokers = "", string Company = "", string Branches = "", int productTypeID = 0)
2511 {
2512 SqlParameter[] Param = new SqlParameter[9];
2513 Param[0] = new SqlParameter("@CurrentUserId", userid);
2514 Param[1] = new SqlParameter("@FromDate", fromdate.ToString("dd/MMM/yyyy"));
2515 Param[2] = new SqlParameter("@ToDate", todate.ToString("dd/MMM/yyyy"));
2516 if (!string.IsNullOrEmpty(Negotiator))
2517 {
2518 Param[3] = new SqlParameter("@Negotiator", Negotiator.Trim());
2519 Param[4] = new SqlParameter("@Company", Company.Trim());
2520 Param[5] = new SqlParameter("@Branches", Branches.Trim());
2521 }
2522 if (!string.IsNullOrWhiteSpace(brokers))
2523 {
2524 Param[6] = new SqlParameter("@BrokerId", brokers);
2525 }
2526 if (!string.IsNullOrWhiteSpace(type))
2527 {
2528 Param[7] = new SqlParameter("@MortgageType", type);
2529 }
2530
2531 Param[8] = new SqlParameter("@productTypeID", productTypeID);
2532
2533 DataSet ds = SqlHelper.ExecuteDataset(CommandType.StoredProcedure, "GetMortgageCaseWrittenForScreen_Update", Param);
2534 return ds;
2535
2536 }
2537 #endregion [Get Mortgage Report For Screen]
2538 #region [Get Mortgage Completed Report For Screen]
2539
2540 public DataSet GetMortgageCompletedReportForScreen(string type, DateTime fromdate, DateTime todate, int userid, int brokerId = 0, string Negotiator = "", string brokers = "", string Company = "", string Branches = "", int productTypeID = 0)
2541 {
2542 SqlParameter[] Param = new SqlParameter[9];
2543 Param[0] = new SqlParameter("@CurrentUserId", userid);
2544 Param[1] = new SqlParameter("@FromDate", fromdate.ToString("dd/MMM/yyyy"));
2545 Param[2] = new SqlParameter("@ToDate", todate.ToString("dd/MMM/yyyy"));
2546 if (!string.IsNullOrEmpty(Negotiator))
2547 {
2548 Param[3] = new SqlParameter("@Negotiator", Negotiator.Trim());
2549 Param[4] = new SqlParameter("@Company", Company.Trim());
2550 Param[5] = new SqlParameter("@Branches", Branches.Trim());
2551 }
2552 if (!string.IsNullOrWhiteSpace(brokers))
2553 {
2554 Param[6] = new SqlParameter("@BrokerId", brokers);
2555 }
2556 if (!string.IsNullOrWhiteSpace(type))
2557 {
2558 Param[7] = new SqlParameter("@MortgageType", type);
2559 }
2560
2561 Param[8] = new SqlParameter("@productTypeID", productTypeID);
2562
2563 DataSet ds = SqlHelper.ExecuteDataset(CommandType.StoredProcedure, "GetMortgageCompletedReportForScreen_Update", Param);
2564 return ds;
2565 }
2566
2567 #endregion [Get Mortgage Completed Report For Screen]
2568 #region [Get Insurance Written Report For screen]
2569
2570 /// <summary>
2571 /// method for InsuranceCaseWrittenForScreen
2572 /// </summary>
2573 /// <param name="type"></param>
2574 /// <param name="fromdate"></param>
2575 /// <param name="todate"></param>
2576 /// <param name="userid"></param>
2577 /// <param name="brokerId"></param>
2578 /// <param name="Negotiator"></param>
2579 /// <param name="brokers"></param>
2580 /// <param name="Company"></param>
2581 /// <param name="Branches"></param>
2582 /// <param name="productTypeID"></param>
2583 /// <returns></returns>
2584 public DataSet GetInsuranceCaseWrittenReportForScreen(string type, DateTime fromdate, DateTime todate, int userid, int brokerId = 0, string Negotiator = "", string brokers = "", string Company = "", string Branches = "", int productTypeID = 0)
2585 {
2586 SqlParameter[] Param = new SqlParameter[9];
2587 Param[0] = new SqlParameter("@CurrentUserId", userid);
2588 Param[1] = new SqlParameter("@FromDate", fromdate.ToString("dd/MMM/yyyy"));
2589 Param[2] = new SqlParameter("@ToDate", todate.ToString("dd/MMM/yyyy"));
2590 if (!string.IsNullOrEmpty(Negotiator))
2591 {
2592 Param[3] = new SqlParameter("@Negotiator", Negotiator.Trim());
2593 Param[4] = new SqlParameter("@Company", Company.Trim());
2594 Param[5] = new SqlParameter("@Branches", Branches.Trim());
2595 }
2596 if (!string.IsNullOrWhiteSpace(brokers))
2597 {
2598 Param[6] = new SqlParameter("@BrokerId", brokers);
2599 }
2600 if (!string.IsNullOrWhiteSpace(type))
2601 {
2602 Param[7] = new SqlParameter("@InsuranceType", type);
2603 }
2604 Param[8] = new SqlParameter("@productTypeID", productTypeID);
2605
2606 DataSet ds = SqlHelper.ExecuteDataset(CommandType.StoredProcedure, "GetInsuranceCaseWrittenForScreen_Update", Param);
2607 return ds;
2608 }
2609
2610 #endregion [Get Insurance Written Report For screen]
2611 #region [Get insurance Completed Report for Screen]
2612 public DataSet GetInsuranceCompletedReportForScreen(string type, DateTime fromdate, DateTime todate, int userid, int brokerId = 0, string Negotiator = "", string brokers = "", string Company = "", string Branches = "", int productTypeID = 0)
2613 {
2614 SqlParameter[] Param = new SqlParameter[9];
2615 Param[0] = new SqlParameter("@CurrentUserId", userid);
2616 Param[1] = new SqlParameter("@FromDate", fromdate.ToString("dd/MMM/yyyy"));
2617 Param[2] = new SqlParameter("@ToDate", todate.ToString("dd/MMM/yyyy"));
2618 if (!string.IsNullOrEmpty(Negotiator))
2619 {
2620 Param[3] = new SqlParameter("@Negotiator", Negotiator.Trim());
2621 Param[4] = new SqlParameter("@Company", Company.Trim());
2622 Param[5] = new SqlParameter("@Branches", Branches.Trim());
2623 }
2624 if (!string.IsNullOrWhiteSpace(brokers))
2625 {
2626 Param[6] = new SqlParameter("@BrokerId", brokers);
2627 }
2628 if (!string.IsNullOrWhiteSpace(type))
2629 {
2630 Param[7] = new SqlParameter("@InsuranceType", type);
2631 }
2632 Param[8] = new SqlParameter("@productTypeID", productTypeID);
2633
2634 DataSet ds = SqlHelper.ExecuteDataset(CommandType.StoredProcedure, "GetInsuranceCompletedReportForScreen_Update", Param);
2635 return ds;
2636 }
2637 #endregion [Get insurance Completed Report for Screen]
2638 #region [Get Total Writeen Report For Screen]
2639 public DataSet GetTotalWrittenReportForScreen(string type, DateTime fromdate, DateTime todate, int userid, int brokerId = 0, string Negotiator = "", string brokers = "", string Company = "", string Branches = "", int productTypeID = 0)
2640 {
2641 SqlParameter[] Param = new SqlParameter[7];
2642 Param[0] = new SqlParameter("@CurrentUserId", userid);
2643 Param[1] = new SqlParameter("@FromDate", fromdate.ToString("dd/MMM/yyyy"));
2644 Param[2] = new SqlParameter("@ToDate", todate.ToString("dd/MMM/yyyy"));
2645 if (!string.IsNullOrEmpty(Negotiator))
2646 {
2647 Param[3] = new SqlParameter("@Negotiator", Negotiator.Trim());
2648 Param[4] = new SqlParameter("@Company", Company.Trim());
2649 Param[5] = new SqlParameter("@Branches", Branches.Trim());
2650 }
2651 if (!string.IsNullOrWhiteSpace(brokers))
2652 {
2653 Param[6] = new SqlParameter("@BrokerId", brokers);
2654 }
2655
2656
2657 DataSet ds = SqlHelper.ExecuteDataset(CommandType.StoredProcedure, "GetTotalWrittenForScreen_Update", Param);
2658 return ds;
2659 }
2660 #endregion [Get Total Completed Report For Screen]
2661 #region [Get Total Completed Report For Screen]
2662 public DataSet GetTotalWrittenReportCompleted(string type, DateTime fromdate, DateTime todate, int userid, int brokerId = 0, string Negotiator = "", string brokers = "", string Company = "", string Branches = "", int productTypeID = 0)
2663 {
2664 SqlParameter[] Param = new SqlParameter[7];
2665 Param[0] = new SqlParameter("@CurrentUserId", userid);
2666 Param[1] = new SqlParameter("@FromDate", fromdate.ToString("dd/MMM/yyyy"));
2667 Param[2] = new SqlParameter("@ToDate", todate.ToString("dd/MMM/yyyy"));
2668 if (!string.IsNullOrEmpty(Negotiator))
2669 {
2670 Param[3] = new SqlParameter("@Negotiator", Negotiator.Trim());
2671 Param[4] = new SqlParameter("@Company", Company.Trim());
2672 Param[5] = new SqlParameter("@Branches", Branches.Trim());
2673 }
2674 if (!string.IsNullOrWhiteSpace(brokers))
2675 {
2676 Param[6] = new SqlParameter("@BrokerId", brokers);
2677 }
2678
2679
2680 DataSet ds = SqlHelper.ExecuteDataset(CommandType.StoredProcedure, "GetTotalWrittenCompleted_Update", Param);
2681 return ds;
2682 }
2683 #endregion [Get Total Written Report For Screen]
2684 #region [Get Total Writeen Month For Screen]
2685 public DataSet GetTotalWrittenMonthReportForScreen(string type, DateTime fromdate, DateTime todate, int userid, int brokerId = 0, string Negotiator = "", string brokers = "", string Company = "", string Branches = "", int productTypeID = 0)
2686 {
2687 SqlParameter[] Param = new SqlParameter[7];
2688 Param[0] = new SqlParameter("@CurrentUserId", userid);
2689 Param[1] = new SqlParameter("@FromDate", fromdate.ToString("dd/MMM/yyyy"));
2690 Param[2] = new SqlParameter("@ToDate", todate.ToString("dd/MMM/yyyy"));
2691 if (!string.IsNullOrEmpty(Negotiator))
2692 {
2693 Param[3] = new SqlParameter("@Negotiator", Negotiator.Trim());
2694 Param[4] = new SqlParameter("@Company", Company.Trim());
2695 Param[5] = new SqlParameter("@Branches", Branches.Trim());
2696 }
2697 if (!string.IsNullOrWhiteSpace(brokers))
2698 {
2699 Param[6] = new SqlParameter("@BrokerId", brokers);
2700 }
2701
2702
2703 DataSet ds = SqlHelper.ExecuteDataset(CommandType.StoredProcedure, "GetTotalWrittenMonthForScreen_Update", Param);
2704 return ds;
2705 }
2706 #endregion [Get Total Written Month For Screen]
2707 #region [Condition For Animation]
2708 public BrokerDetailForScreen ConditionForProductSubmitted()
2709 {
2710 BrokerDetailForScreen submittedBrokerDetail = null;// = new SubmittedBrokerDetailForScreen();
2711 try
2712 {
2713 SqlParameter[] Param = new SqlParameter[0];
2714 DataSet ds = SqlHelper.ExecuteDataset(CommandType.StoredProcedure, "SubmittedConditionForScreen", Param);
2715 submittedBrokerDetail = (from System.Data.DataRow row in ds.Tables[0].Rows
2716 select new BrokerDetailForScreen
2717 {
2718 brokerId = Convert.ToInt32((row["brokerId"] == DBNull.Value || row["brokerId"] == null) ? "" : row["brokerId"]),
2719 brokerName = ((row["brokerName"] == DBNull.Value || row["brokerName"] == null) ? "" : row["brokerName"]).ToString(),
2720 commision = (decimal)((row["commision"] == DBNull.Value || row["commision"] == null) ? (decimal)0 : Convert.ToDecimal(row["commision"])),
2721 dealSize = (decimal)((row["dealSize"] == DBNull.Value || row["dealSize"] == null) ? (decimal)0 : Convert.ToDecimal(row["dealSize"])),
2722 financeId = Convert.ToInt32((row["financeId"] == DBNull.Value || row["financeId"] == null) ? "0" : row["financeId"]),
2723 type = Convert.ToInt32((row["type"] == DBNull.Value || row["type"] == null) ? "0" : row["type"]),
2724 }).FirstOrDefault();
2725 }
2726 catch
2727 {
2728
2729 }
2730 return submittedBrokerDetail;
2731 }
2732
2733 public BrokerDetailForScreen ConditionForProductCompleted()
2734 {
2735 BrokerDetailForScreen completedBrokerDetail = null;
2736 try
2737 {
2738 SqlParameter[] Param = new SqlParameter[0];
2739 DataSet ds = SqlHelper.ExecuteDataset(CommandType.StoredProcedure, "CompletedConditionForScreen", Param);
2740 completedBrokerDetail = (from System.Data.DataRow row in ds.Tables[0].Rows
2741 select new BrokerDetailForScreen
2742 {
2743 brokerId = Convert.ToInt32((row["brokerId"] == DBNull.Value || row["brokerId"] == null) ? "" : row["brokerId"]),
2744 brokerName = ((row["brokerName"] == DBNull.Value || row["brokerName"] == null) ? "" : row["brokerName"]).ToString(),
2745 commision = (decimal)((row["commision"] == DBNull.Value || row["commision"] == null) ? (decimal)0 : Convert.ToDecimal(row["commision"])),
2746 dealSize = (decimal)((row["dealSize"] == DBNull.Value || row["dealSize"] == null) ? (decimal)0 : Convert.ToDecimal(row["dealSize"])),
2747 financeId = Convert.ToInt32((row["financeId"] == DBNull.Value || row["financeId"] == null) ? "0" : row["financeId"]),
2748 type = Convert.ToInt32((row["type"] == DBNull.Value || row["type"] == null) ? "0" : row["type"]),
2749 }).FirstOrDefault();
2750 }
2751 catch
2752 {
2753
2754 }
2755 return completedBrokerDetail;
2756 }
2757 public BrokerDetailForScreen ConditionForAnimation(out int animationType)
2758 {
2759
2760 animationType = 0;
2761 var submittedBrokerDetail = ConditionForProductSubmitted();
2762 var completedBrokerDetail = ConditionForProductCompleted();
2763 BrokerDetailForScreen brokerDetail = null;
2764 try
2765 {
2766 if (submittedBrokerDetail != null && completedBrokerDetail == null)
2767 {
2768 if (submittedBrokerDetail.type == 1 && submittedBrokerDetail.commision >= 1500)
2769 {
2770 animationType = 1; // fireworks
2771
2772 }
2773 else if (submittedBrokerDetail.type == 1 && submittedBrokerDetail.commision < 1500)
2774 {
2775 animationType = 2; //champagne
2776 }
2777 else if ((submittedBrokerDetail.type == 2 || submittedBrokerDetail.type == 3) && submittedBrokerDetail.commision >= 1000)
2778 {
2779 animationType = 1; // fireworks
2780
2781 }
2782 else if ((submittedBrokerDetail.type == 2 || submittedBrokerDetail.type == 3) && submittedBrokerDetail.commision < 1000)
2783 {
2784 animationType = 2; // champagne
2785
2786 }
2787 brokerDetail = submittedBrokerDetail;
2788 SaveRecordForBigScreen(brokerDetail, 1);
2789 }
2790 else if (submittedBrokerDetail == null && completedBrokerDetail != null)
2791 {
2792 animationType = 3; //stack of money
2793 brokerDetail = completedBrokerDetail;
2794 SaveRecordForBigScreen(brokerDetail, 2);
2795 }
2796 else if (submittedBrokerDetail != null && completedBrokerDetail != null)
2797 {
2798 animationType = 3; // stack of money
2799 brokerDetail = completedBrokerDetail;
2800 SaveRecordForBigScreen(brokerDetail, 2);
2801 }
2802 else
2803 {
2804 animationType = 0;
2805 brokerDetail = null;
2806
2807 }
2808 }
2809 catch
2810 {
2811
2812 }
2813 return brokerDetail;
2814
2815 }
2816 #endregion [Condition For Animation]
2817
2818 #region [Saving record in Bigscreen Table for maintain history]
2819 public int SaveRecordForBigScreen(BrokerDetailForScreen detail, int status)
2820 {
2821 int result = 0;
2822 try
2823 {
2824 if (detail != null)
2825 {
2826 tblBigScreenRecords bigScreen = new tblBigScreenRecords();
2827 bigScreen.financeId = detail.financeId;
2828 bigScreen.status = status;
2829 bigScreen.createdDate = DateTime.Now;
2830 ctx.tblBigScreenRecords.Add(bigScreen);
2831 result = ctx.SaveChanges();
2832 }
2833 }
2834 catch
2835 {
2836
2837 }
2838 return result;
2839
2840 }
2841 #endregion [Saving record in Bigscreen Table for maintain history]
2842
2843 #region[Getting Clients for dropdown]
2844 public List<Clients> FindClients(int parentuserid, int UserId = 0)
2845 {
2846 List<Clients> clients = new List<Clients>();
2847 try
2848 {
2849
2850 //Check User Type
2851 Q_Application _obj = new Q_Application();
2852 int teamId = 0;
2853 string brokersIds = "";
2854 int _userType = 0;
2855 int _accountId = 0;
2856 _userType = _obj.CheckUserType(UserId, out teamId, out _accountId, out brokersIds);
2857 //**************************************
2858
2859 SqlParameter[] Param = new SqlParameter[2];
2860 Param[0] = new SqlParameter("@UserType", _userType);
2861 Param[1] = new SqlParameter("@ParentId", parentuserid); ;
2862 DataTable dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "GetAllClientsForScreen", Param);
2863
2864 clients = (from DataRow row in dt.Rows
2865 select new Clients
2866 {
2867 clientid = Convert.ToInt32(((row["accountid"] == DBNull.Value || row["accountid"] == null) ? "0" : row["accountid"]).ToString()),
2868 parent = Convert.ToInt32(((row["parent"] == DBNull.Value || row["parent"] == null) ? "0" : row["parent"]).ToString()),
2869 companyname = ((row["companyname"] == DBNull.Value || row["companyname"] == null) ? " " : row["companyname"]).ToString(),
2870 affiliateid = ((row["affiliateid"] == DBNull.Value || row["affiliateid"] == null) ? " " : row["affiliateid"]).ToString(),
2871 telephone = ((row["telephone"] == DBNull.Value || row["telephone"] == null) ? " " : row["telephone"]).ToString(),
2872 email = ((row["email"] == DBNull.Value || row["email"] == null) ? " " : row["email"]).ToString(),
2873 contactname = ((row["contactname"] == DBNull.Value || row["contactname"] == null) ? " " : row["contactname"]).ToString(),
2874 address = Convert.ToInt32(((row["address"] == DBNull.Value || row["address"] == null) ? "0" : row["address"]).ToString()),
2875 countLeads = Convert.ToInt32(((row["countLeads"] == DBNull.Value || row["countLeads"] == null) ? "0" : row["countLeads"]).ToString())
2876 }).ToList();
2877 return clients;
2878 }
2879 catch (Exception ex)
2880 {
2881 return clients;
2882 }
2883 }
2884 #endregion [Getiing clients for dropdown]
2885 #region[Getting Brokers For dropdown]
2886 public List<Clients> FindBrokerForLoggedInUserWithUserId(int accid, int userid)
2887 {
2888 bool flag = false;
2889 List<Clients> brokers = new List<Clients>();
2890 Q_Application _obj = new Q_Application();
2891
2892 try
2893 {
2894
2895 int teamId = 0;
2896 string brokersIds = "";
2897 int _userType = 0;
2898 int _accountId = 0;
2899 _userType = _obj.CheckUserType(userid, out teamId, out _accountId, out brokersIds);
2900
2901 //Updated With Store Procedure For Navigation Delay ********* 7/7/2014 ********************************************
2902
2903 var _Id = 0;
2904
2905 if (_userType == 1)
2906 _Id = _accountId;
2907 else if (_userType == 2)
2908 _Id = teamId;
2909 else if (_userType == 3)
2910 _Id = userid;
2911 else if (_userType == 4)
2912 {
2913 int account = ctx.tblaccounts.Where(u => u.accountid == userid).Select(u => u.parent.HasValue ? u.parent.Value : 0).FirstOrDefault();
2914 _Id = account;
2915 }
2916
2917 SqlParameter[] Param = new SqlParameter[2];
2918 Param[0] = new SqlParameter("@UserType", _userType);
2919 Param[1] = new SqlParameter("@ID", _Id);
2920 DataTable dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "FindBrokerForLoggedInUserWithUserIdForScreen", Param);
2921
2922 brokers = (from DataRow row in dt.Rows
2923 select new Clients
2924 {
2925 clientid = Convert.ToInt32(((row["clientid"] == DBNull.Value || row["clientid"] == null) ? "0" : row["clientid"]).ToString()),
2926 parent = Convert.ToInt32(((row["parent"] == DBNull.Value || row["parent"] == null) ? "0" : row["parent"]).ToString()),
2927 companyname = ((row["companyname"] == DBNull.Value || row["companyname"] == null) ? " " : row["companyname"]).ToString(),
2928 TeamName = ((row["TeamName"] == DBNull.Value || row["TeamName"] == null) ? " " : row["TeamName"]).ToString(),
2929 TeamId = Convert.ToInt32(((row["TeamId"] == DBNull.Value || row["TeamId"] == null) ? "0" : row["TeamId"]).ToString()),
2930 affiliateid = ((row["affiliateid"] == DBNull.Value || row["affiliateid"] == null) ? " " : row["affiliateid"]).ToString(),
2931 telephone = ((row["telephone"] == DBNull.Value || row["telephone"] == null) ? " " : row["telephone"]).ToString(),
2932 email = ((row["email"] == DBNull.Value || row["email"] == null) ? " " : row["email"]).ToString(),
2933 contactname = ((row["contactname"] == DBNull.Value || row["contactname"] == null) ? " " : row["contactname"]).ToString(),
2934 address = Convert.ToInt32(((row["address"] == DBNull.Value || row["address"] == null) ? "0" : row["address"]).ToString()),
2935 userid = Convert.ToInt32(((row["userid"] == DBNull.Value || row["userid"] == null) ? "0" : row["userid"]).ToString()),
2936 AdminId = Convert.ToInt32(((row["AdminId"] == DBNull.Value || row["AdminId"] == null) ? "0" : row["AdminId"]).ToString()),
2937 countLeads = Convert.ToInt32(((row["countLeads"] == DBNull.Value || row["countLeads"] == null) ? "0" : row["countLeads"]).ToString()),
2938 }).ToList();
2939
2940 //**********************************************************************************
2941
2942 return brokers;
2943 }
2944 catch (Exception)
2945 {
2946 return brokers;
2947 }
2948 }
2949 #endregion[Getting Brokers for dropdown]
2950
2951 #region [Get Monthly lead flow]
2952 public List<MonthlyLeadFlowBrokers> GetMonthlyLeadReportForScreen(int parentuserid, int userId = 0)
2953 {
2954
2955 List<MonthlyLeadFlowBrokers> brokers = new List<MonthlyLeadFlowBrokers>();
2956 try
2957 {
2958 SqlParameter[] Param = new SqlParameter[2];
2959 Param[0] = new SqlParameter("@parentuserid", parentuserid);
2960 Param[1] = new SqlParameter("@filteredaccount", null);
2961 DataTable dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "GetMonthlyLeadFlowForScreen", Param);
2962
2963 if (dt != null)
2964 {
2965 brokers = (from DataRow row1 in dt.Rows
2966 select new MonthlyLeadFlowBrokers()
2967 {
2968 BrokerName = Convert.ToString(row1["brokername"] == null ? "" : row1["brokername"].ToString()),
2969 Rank = Convert.ToInt32(row1["Ranking"] == null ? "0" : row1["Ranking"].ToString()),
2970 BrokerId = Convert.ToInt32(row1["userid"] == null ? "0" : row1["userid"].ToString()),
2971 Total = Convert.ToInt32(row1["total"] == null ? "0" : row1["total"].ToString()),
2972
2973 }).ToList();
2974 }
2975
2976
2977 return brokers;
2978 }
2979 catch (Exception ex)
2980 {
2981 return brokers;
2982 }
2983 }
2984 #endregion [Get Monthly lead flow]
2985
2986
2987 #endregion [methods for big screen]
2988
2989
2990
2991 }
2992}
2993
2994
2995using Occfinance_Data;
2996using System;
2997using System.Collections.Generic;
2998using System.Linq;
2999using System.Web;
3000using Occfinance.Models;
3001using System.Data.SqlClient;
3002using System.Data;
3003using Occfinance.Helpers;
3004using System.Data.Entity.Infrastructure;
3005using System.Web.Mvc;
3006using System.Configuration;
3007
3008namespace Occfinance.Code
3009{
3010 public class Q_Reports
3011 {
3012 public db_occfinance_5572Entities ctx = new db_occfinance_5572Entities();
3013 System.Web.HttpContext con = HttpContext.Current;
3014
3015 /// <summary>
3016 /// Set the jsTree data format
3017 /// </summary>
3018 /// <param name="hdnnamearray"></param>
3019 /// <param name="hdnnamearrayparents"></param>
3020 public void FormatJsTreeData(ref string hdnnamearray, ref string hdnnamearrayparents)
3021 {
3022 if (!string.IsNullOrEmpty(hdnnamearray))
3023 {
3024 var negIds = string.Empty;
3025 var compbranchIds = string.Empty;
3026
3027 foreach (var ids in hdnnamearray.Split(','))
3028 {
3029 var splitIds = ids.ToString().Split('_');
3030 if (splitIds.Length == 3)
3031 {
3032
3033 negIds += splitIds[2].ToString() + ",";
3034 compbranchIds += splitIds[0].ToString() + "®" + splitIds[1].ToString() + ",";
3035 }
3036
3037 }
3038 hdnnamearray = negIds.Substring(0, negIds.Length - 1);
3039 hdnnamearrayparents = compbranchIds.Substring(0, compbranchIds.Length - 1);
3040 }
3041 }
3042 /// <summary>
3043 /// Set company, branch and negotiator ids
3044 /// </summary>
3045 /// <param name="hdnnamearray"></param>
3046 /// <param name="_allNamesparents"></param>
3047 /// <param name="CompanyIds"></param>
3048 /// <param name="BranchIds"></param>
3049 /// <param name="NegotiatorIds"></param>
3050 public void SetCompanyBranchAndNegotiatorIds(string hdnnamearray, string[] _allNamesparents, out List<int> CompanyIds, out List<int> BranchIds, out List<int> NegotiatorIds)
3051 {
3052 // 2015-10-29 Negotiators, Branches and Companies Ids
3053 CompanyIds = new List<int>();
3054 BranchIds = new List<int>();
3055 NegotiatorIds = new List<int>();
3056
3057 if (_allNamesparents.Length > 0)
3058 {
3059 foreach (var comp_branch in _allNamesparents)
3060 {
3061 if (!string.IsNullOrEmpty(comp_branch))
3062 {
3063 CompanyIds.Add(Convert.ToInt32(comp_branch.Split('®')[0]));
3064 BranchIds.Add(Convert.ToInt32(comp_branch.Split('®')[1]));
3065 }
3066 }
3067
3068 CompanyIds = CompanyIds.Distinct().ToList();
3069 BranchIds = BranchIds.Distinct().ToList();
3070 if (!string.IsNullOrEmpty(hdnnamearray))
3071 NegotiatorIds = hdnnamearray.Split(',').Select(Int32.Parse).Distinct().ToList();
3072 }
3073 }
3074 /// <summary>
3075 /// Get product type details
3076 /// </summary>
3077 /// <returns></returns>
3078 public List<SelectListItem> GetProductTypeDetails()
3079 {
3080
3081 var objTblfinancetype = (from ftype in ctx.tblfinancetypes
3082 select new ProductType
3083 {
3084 ProductId = ftype.financetypeid,
3085 ProductName = ftype.type
3086 }).ToList();
3087 var productitems = new List<SelectListItem>();
3088 foreach (var x in objTblfinancetype)
3089 {
3090 productitems.Add(new SelectListItem { Value = x.ProductId.ToString(), Text = x.ProductName });
3091 }
3092 productitems.OrderBy(m => m.Value).ToList();
3093 return productitems;
3094 }
3095 /// <summary>
3096 /// Get all finance type
3097 /// </summary>
3098 /// <returns></returns>
3099 public List<ProductType> GetAllFinanceType()
3100 {
3101 var objTblfinancetype = (from ftype in ctx.tblfinancetypes
3102 select new ProductType
3103 {
3104 ProductId = ftype.financetypeid,
3105 ProductName = ftype.type
3106 }).ToList();
3107
3108
3109 return objTblfinancetype;
3110 }
3111
3112 /// <summary>
3113 /// Find negotiation report by contactid
3114 /// </summary>
3115 /// <returns></returns>
3116 public List<contactTbl> FindNegotiationReportByContactId()
3117 {
3118 List<contactTbl> negotiationReportList = new List<contactTbl>();
3119 try
3120 {
3121 SqlParameter[] Param = new SqlParameter[0];
3122 DataTable dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "GetNegotiationReportList_Update", Param);
3123 negotiationReportList = (from DataRow row in dt.Rows
3124 select new contactTbl
3125 {
3126 negref = row["negref"].ToString()
3127 }).ToList();
3128 // result = ctx.tblcontacts.Where(u => u.contactid == id).Select(u => new contactTbl() { negref=u.negref}).ToList();
3129 return negotiationReportList;
3130 }
3131 catch (Exception)
3132 {
3133 return negotiationReportList;
3134 }
3135 }
3136 /// <summary>
3137 /// Getting dataset from the database for Negotiator Report
3138 /// </summary>
3139 /// <param name="fromdate">From Date</param>
3140 /// <param name="todate">To Date</param>
3141 /// <param name="userid">User Id</param>
3142 /// <param name="pageNo">Page no</param>
3143 /// <param name="pageSize">Page size</param>
3144 /// <param name="brokerId">Broker Id</param>
3145 /// <param name="Negotiator">Negotiator</param>
3146 /// <param name="brokers">Brokers</param>
3147 /// <param name="Company">Companies</param>
3148 /// <param name="Branches">Branches</param>
3149 /// <param name="productTypeID">Product type</param>
3150 /// <returns></returns>
3151 public DataSet GetNegotiatorResult(DateTime fromdate, DateTime todate, int userid, int pageNo, int pageSize, int brokerId = 0, string Negotiator = "", string brokers = "", string Company = "", string Branches = "", int productTypeID = 0)
3152 {
3153 DataSet ds;
3154 List<Negotiation> negotiationlist = new List<Models.Negotiation>();
3155 try
3156 {
3157 SqlParameter[] Param = new SqlParameter[10];
3158 Param[0] = new SqlParameter("@CurrentUserId", userid);
3159 Param[1] = new SqlParameter("@Negotiator", (string.IsNullOrEmpty(Negotiator) ? null : Negotiator.Trim()));
3160 Param[2] = new SqlParameter("@Company", (string.IsNullOrEmpty(Company) ? null : Company.Trim()));
3161 Param[3] = new SqlParameter("@Branches", (string.IsNullOrEmpty(Branches) ? null : Branches.Trim()));
3162 Param[4] = new SqlParameter("@BrokerId", (string.IsNullOrEmpty(brokers) ? null : brokers));
3163 Param[5] = new SqlParameter("@FromDate", fromdate.ToString(Helper.ddMMMyyyy));
3164 Param[6] = new SqlParameter("@ToDate", todate.ToString(Helper.ddMMMyyyy));
3165 Param[7] = new SqlParameter("@PageNo", pageNo);
3166 Param[8] = new SqlParameter("@PageSize", pageSize);
3167 Param[9] = new SqlParameter("@productTypeID", productTypeID);
3168 ds = SqlHelper.ExecuteDataset("GetNegotiatorReport", Param);
3169 return ds;
3170 }
3171 catch (Exception ex)
3172 {
3173 Helper.ErrorLog(ex.InnerException, "Q_Report.cs", "GetNegotiatorResult", ex.Message);
3174 return ds = new DataSet();
3175 }
3176 }
3177 /// <summary>
3178 /// Getting dataset for Negotiator Report with page no
3179 /// </summary>
3180 /// <param name="fromdate">from date</param>
3181 /// <param name="todate">to date</param>
3182 /// <param name="userid">user Id</param>
3183 /// <param name="pageNo">page no</param>
3184 /// <param name="pageSize">page size</param>
3185 /// <param name="brokerId">broker Id</param>
3186 /// <param name="Negotiator">Negotiator</param>
3187 /// <param name="brokers">Brokers</param>
3188 /// <param name="Company">Company</param>
3189 /// <param name="Branches">Branches</param>
3190 /// <returns></returns>
3191 public ReportsDataModel GetNegotiatorDataResult(DateTime fromdate, DateTime todate, int userid, int pageNo, int pageSize, int brokerId = 0, string Negotiator = "", string brokers = "", string Company = "", string Branches = "")
3192 {
3193
3194 ReportsDataModel dataResult = new ReportsDataModel();
3195 dataResult.Negotiation = new List<Negotiation>();
3196 dataResult.NegotiationNotes = new List<NegotiationNotes>();
3197 try
3198 {
3199 SqlParameter[] Param = new SqlParameter[9];
3200 Param[0] = new SqlParameter("@CurrentUserId", userid);
3201 Param[1] = new SqlParameter("@Negotiator", (string.IsNullOrEmpty(Negotiator) ? null : Negotiator.Trim()));
3202 Param[2] = new SqlParameter("@Company", (string.IsNullOrEmpty(Company) ? null : Company.Trim()));
3203 Param[3] = new SqlParameter("@Branches", (string.IsNullOrEmpty(Branches) ? null : Branches.Trim()));
3204 Param[4] = new SqlParameter("@BrokerId", (string.IsNullOrEmpty(brokers) ? null : brokers));
3205 Param[5] = new SqlParameter("@FromDate", fromdate.ToString(Helper.ddMMMyyyy));
3206 Param[6] = new SqlParameter("@ToDate", todate.ToString(Helper.ddMMMyyyy));
3207 Param[7] = new SqlParameter("@PageNo", pageNo);
3208 Param[8] = new SqlParameter("@PageSize", pageSize);
3209 SqlDataReader reader = SqlHelper.ExecuteReaderNext(CommandType.StoredProcedure, "GetNegotiatorReport", Param);
3210 ctx.Database.Initialize(force: false);
3211 ctx.Database.Connection.Open();
3212 dataResult.Negotiation = ((IObjectContextAdapter)ctx).ObjectContext.Translate<Negotiation>(reader).ToList();
3213 reader.NextResult();
3214 dataResult.NegotiationNotes = ((IObjectContextAdapter)ctx).ObjectContext.Translate<NegotiationNotes>(reader).ToList();
3215 ctx.Database.Connection.Close();
3216 if (!reader.IsClosed)
3217 {
3218 reader.Close();
3219 }
3220 }
3221 catch (Exception ex)
3222 {
3223 Helper.ErrorLog(ex.InnerException, "Q_Report", "GetNegotiatorDataResult", ex.Message);
3224 }
3225 return dataResult;
3226 }
3227 /// <summary>
3228 /// Getting the dataset for Notes Data
3229 /// </summary>
3230 /// <param name="userId">User Id</param>
3231 /// <param name="pageNo">Page No</param>
3232 /// <param name="pageSize">Page Size</param>
3233 /// <param name="fromDate">FRom Date</param>
3234 /// <param name="toDate">To Date</param>
3235 /// <param name="negotiators">Negotiators</param>
3236 /// <param name="company">Companies</param>
3237 /// <param name="branches">branches</param>
3238 /// <param name="brokers">Brokers</param>
3239 /// <param name="productTypeID">Product type</param>
3240 /// <returns></returns>
3241 public ReadNotes GetNotesData(int userId, int pageNo, int pageSize, DateTime fromDate, DateTime toDate, string negotiators = "", string company = "", string branches = "", string brokers = "", int productTypeID = 0)
3242 {
3243 var reportsDN = new ReadNotes();
3244 try
3245 {
3246 DataTable notes = new DataTable();
3247 SqlParameter[] Param = new SqlParameter[10];
3248 Param[0] = new SqlParameter("@Negotiator", (string.IsNullOrEmpty(negotiators) ? null : negotiators.Trim()));
3249 Param[1] = new SqlParameter("@Company", (string.IsNullOrEmpty(company) ? null : company.Trim()));
3250 Param[2] = new SqlParameter("@Branches", (string.IsNullOrEmpty(branches) ? null : branches.Trim()));
3251 Param[3] = new SqlParameter("@BrokerIds", (string.IsNullOrEmpty(brokers) ? null : brokers));
3252 Param[4] = new SqlParameter("@FromDate", fromDate.ToString("dd/MMM/yyyy"));
3253 Param[5] = new SqlParameter("@ToDate", toDate.ToString("dd/MMM/yyyy"));
3254 Param[6] = new SqlParameter("@CurrentUserId", userId);
3255 Param[7] = new SqlParameter("@PageNo", pageNo);
3256 Param[8] = new SqlParameter("@PageSize", pageSize);
3257 Param[9] = new SqlParameter("@productTypeID", productTypeID);
3258 SqlDataReader reader = SqlHelper.ExecuteReaderNext(CommandType.StoredProcedure, "Usp_GetNotesData", Param);
3259 ctx.Database.Initialize(force: false);
3260 ctx.Database.Connection.Open();
3261 reportsDN.AdvisorNotes = ((IObjectContextAdapter)ctx).ObjectContext.Translate<NegotiationNotes>(reader).ToList();
3262 reader.NextResult();
3263 reportsDN.AgentNotes = ((IObjectContextAdapter)ctx).ObjectContext.Translate<NegotiationNotes>(reader).ToList();
3264 ctx.Database.Connection.Close();
3265 if (!reader.IsClosed)
3266 {
3267 reader.Close();
3268 }
3269 }
3270 catch (Exception ex)
3271 {
3272 Helper.ErrorLog(ex.InnerException, "Q_Report", "GetNotesData", ex.Message);
3273 }
3274 return reportsDN; ;
3275 }
3276 //added on 2015-02-03
3277 /// <summary>
3278 /// Getting Weekly created notes data
3279 /// </summary>
3280 /// <param name="fromdate">From Date</param>
3281 /// <param name="todate">To Date</param>
3282 /// <param name="userid">User Id</param>
3283 /// <param name="brokerId">Broker Id</param>
3284 /// <param name="Negotiator">Negotiator</param>
3285 /// <param name="brokers">Brokers</param>
3286 /// <param name="Company">Company</param>
3287 /// <param name="Branches">Branches</param>
3288 /// <param name="productTypeID">Product Type</param>
3289 /// <returns></returns>
3290 public DataSet GetNegotiatorWeeklyCreatedNotes(DateTime fromdate, DateTime todate, int userid, int brokerId = 0, string Negotiator = "", string brokers = "", string Company = "", string Branches = "", int productTypeID = 0)
3291 {
3292 DataSet ds;
3293 List<Negotiation> negotiationlist = new List<Models.Negotiation>();
3294 try
3295 {
3296 SqlParameter[] Param = new SqlParameter[8];
3297 Param[0] = new SqlParameter("@CurrentUserId", userid);
3298 Param[1] = new SqlParameter("@Negotiator", (string.IsNullOrEmpty(Negotiator) ? null : Negotiator.Trim()));
3299 Param[2] = new SqlParameter("@Company", (string.IsNullOrEmpty(Company) ? null : Company.Trim()));
3300 Param[3] = new SqlParameter("@Branches", (string.IsNullOrEmpty(Branches) ? null : Branches.Trim()));
3301 Param[4] = new SqlParameter("@BrokerId", (string.IsNullOrEmpty(brokers) ? null : brokers));
3302 Param[5] = new SqlParameter("@FromDate", fromdate.ToString("dd/MMM/yyyy"));
3303 Param[6] = new SqlParameter("@ToDate", todate.ToString("dd/MMM/yyyy"));
3304 Param[7] = new SqlParameter("@productTypeID", productTypeID);
3305 ds = SqlHelper.ExecuteDataset("GetNegotiatorReportWeeklyNoteCreated", Param);
3306 return ds;
3307 }
3308 catch (Exception ex)
3309 {
3310 Helper.ErrorLog(ex.InnerException, "Q_Report", "GetNegotiatorWeeklyCreatedNotes", ex.Message);
3311 ds = new DataSet();
3312 return ds;
3313 }
3314 }
3315
3316 //added on 2015-02-03
3317 /// <summary>
3318 /// Getting weekly updated notes
3319 /// </summary>
3320 /// <param name="fromdate">From Date</param>
3321 /// <param name="todate">To date</param>
3322 /// <param name="userid">User Id</param>
3323 /// <param name="brokerId">Broker Id</param>
3324 /// <param name="Negotiator">Negotiator</param>
3325 /// <param name="brokers">Brokers</param>
3326 /// <param name="Company">Company</param>
3327 /// <param name="Branches">Branches</param>
3328 /// <param name="productTypeID">Product Type</param>
3329 /// <returns></returns>
3330 public DataSet GetNegotiatorWeeklyUpdatedNotes(DateTime fromdate, DateTime todate, int userid, int brokerId = 0, string Negotiator = "", string brokers = "", string Company = "", string Branches = "", int productTypeID = 0)
3331 {
3332 DataSet ds;
3333 List<Negotiation> negotiationlist = new List<Models.Negotiation>();
3334 try
3335 {
3336 SqlParameter[] Param = new SqlParameter[8];
3337 Param[0] = new SqlParameter("@CurrentUserId", userid);
3338 Param[1] = new SqlParameter("@Negotiator", (string.IsNullOrEmpty(Negotiator) ? null : Negotiator.Trim()));
3339 Param[2] = new SqlParameter("@Company", (string.IsNullOrEmpty(Company) ? null : Company.Trim()));
3340 Param[3] = new SqlParameter("@Branches", (string.IsNullOrEmpty(Branches) ? null : Branches.Trim()));
3341 Param[4] = new SqlParameter("@BrokerId", (string.IsNullOrEmpty(brokers) ? null : brokers));
3342 Param[5] = new SqlParameter("@FromDate", fromdate.ToString("dd/MMM/yyyy"));
3343 Param[6] = new SqlParameter("@ToDate", todate.ToString("dd/MMM/yyyy"));
3344 Param[7] = new SqlParameter("@productTypeID", productTypeID);
3345 ds = SqlHelper.ExecuteDataset("GetNegotiatorReportWeeklyNoteUpdated", Param);
3346 return ds;
3347 }
3348 catch (Exception ex)
3349 {
3350 Helper.ErrorLog(ex.InnerException, "Q_Report", "GetNegotiatorWeeklyUpdatedNotes", ex.Message);
3351 ds = new DataSet();
3352 return ds;
3353 }
3354 }
3355
3356 /// <summary>
3357 /// Getting negotiator data for PDF
3358 /// </summary>
3359 /// <param name="fromdate">From Date</param>
3360 /// <param name="todate">To Date</param>
3361 /// <param name="userid">User Id</param>
3362 /// <param name="brokerId">Broker Id</param>
3363 /// <param name="Negotiator">Negotiator</param>
3364 /// <param name="brokers">Brokers</param>
3365 /// <param name="Company">Company</param>
3366 /// <param name="Branches">Branches</param>
3367 /// <param name="productTypeID">Product Type</param>
3368 /// <returns></returns>
3369 public DataSet GetNegotiator(DateTime fromdate, DateTime todate, int userid, int brokerId = 0, string Negotiator = "", string brokers = "", string Company = "", string Branches = "", int productTypeID = 0)
3370 {
3371 DataSet ds;
3372 try
3373 {
3374 List<Negotiation> negotiationlist = new List<Models.Negotiation>();
3375 SqlParameter[] Param = new SqlParameter[8];
3376 Param[0] = new SqlParameter("@CurrentUserId", userid);
3377
3378 Param[1] = new SqlParameter("@Negotiator", (string.IsNullOrEmpty(Negotiator) ? null : Negotiator.Trim()));
3379 Param[2] = new SqlParameter("@Company", (string.IsNullOrEmpty(Company) ? null : Company.Trim()));
3380 Param[3] = new SqlParameter("@Branches", (string.IsNullOrEmpty(Branches) ? null : Branches.Trim()));
3381 Param[4] = new SqlParameter("@BrokerId", (string.IsNullOrEmpty(brokers) ? null : brokers));
3382 Param[5] = new SqlParameter("@FromDate", fromdate.ToString("dd/MMM/yyyy"));
3383 Param[6] = new SqlParameter("@ToDate", todate.ToString("dd/MMM/yyyy"));
3384 Param[7] = new SqlParameter("@productTypeID", productTypeID);
3385 ds = SqlHelper.ExecuteDataset("GetNegotiatorReport", Param);
3386 }
3387 catch (Exception ex)
3388 {
3389 ds = new DataSet();
3390 Helper.ErrorLog(ex.InnerException, "Q_Report", "GetNegotiator", ex.Message);
3391 }
3392 return ds;
3393 }
3394 /********************************************************************
3395 * Code Updatd : 24/01/2015
3396 *
3397 * Description : Method added for weekly report helper for GetNegotiator
3398 *
3399 * Optimized code block added
3400 * ******************************************************************/
3401 /// <summary>
3402 /// Getting negotiator weekly report
3403 /// </summary>
3404 /// <param name="fromdate">From date</param>
3405 /// <param name="todate">To date</param>
3406 /// <param name="userid">User Id</param>
3407 /// <param name="brokerId">Broker Id</param>
3408 /// <param name="Negotiator">Negotiator</param>
3409 /// <param name="brokers">Brokers</param>
3410 /// <param name="Company">Companies</param>
3411 /// <param name="Branches">Branches</param>
3412 /// <param name="productTypeID">Product Type</param>
3413 /// <returns></returns>
3414 public DataSet GetNegotiatorweekly(DateTime fromdate, DateTime todate, int userid, int brokerId = 0, string Negotiator = "", string brokers = "", string Company = "", string Branches = "", int productTypeID = 0)
3415 {
3416 DataSet ds;
3417 try
3418 {
3419 List<Negotiation> negotiationlist = new List<Models.Negotiation>();
3420 SqlParameter[] Param = new SqlParameter[8];
3421 Param[0] = new SqlParameter("@CurrentUserId", userid);
3422 Param[1] = new SqlParameter("@Negotiator", (string.IsNullOrEmpty(Negotiator) ? null : Negotiator.Trim()));
3423 Param[2] = new SqlParameter("@Company", (string.IsNullOrEmpty(Company) ? null : Company.Trim()));
3424 Param[3] = new SqlParameter("@Branches", (string.IsNullOrEmpty(Branches) ? null : Branches.Trim()));
3425 Param[4] = new SqlParameter("@BrokerId", (string.IsNullOrEmpty(brokers) ? null : brokers));
3426 Param[5] = new SqlParameter("@FromDate", fromdate.ToString("dd/MMM/yyyy"));
3427 Param[6] = new SqlParameter("@ToDate", todate.ToString("dd/MMM/yyyy"));
3428 Param[7] = new SqlParameter("@productTypeID", productTypeID);
3429 ds = SqlHelper.ExecuteDataset("GetNegotiatorReportWeekly", Param);
3430 }
3431 catch (Exception ex)
3432 {
3433 Helper.ErrorLog(ex.InnerException, "Q_Report", "GetNegotiatorweekly", ex.Message);
3434 ds = new DataSet();
3435
3436 }
3437 return ds;
3438 }
3439 /// <summary>
3440 /// Getting Adviser Report Dataset
3441 /// </summary>
3442 /// <param name="fromdate">From date</param>
3443 /// <param name="todate">To Date</param>
3444 /// <param name="userid">User Id</param>
3445 /// <param name="brokerId">Broker Id</param>
3446 /// <param name="type">Type Id</param>
3447 /// <param name="Negotiator">Negotiator</param>
3448 /// <param name="brokers">Brokers</param>
3449 /// <param name="Company">Company</param>
3450 /// <param name="Branches">branches</param>
3451 /// <returns></returns>
3452 public DataSet GetAdvisorReport(DateTime fromdate, DateTime todate, int userid, int brokerId = 0, int type = 1, string Negotiator = "", string brokers = "", string Company = "", string Branches = "")
3453 {
3454 DataSet ds;
3455 try
3456 {
3457 List<Negotiation> negotiationlist = new List<Models.Negotiation>();
3458 SqlParameter[] Param = new SqlParameter[8];
3459 Param[0] = new SqlParameter("@CurrentUserId", userid);
3460 if (!string.IsNullOrEmpty(Negotiator))
3461 {
3462 Param[1] = new SqlParameter("@Negotiator", Negotiator.Trim());
3463 Param[6] = new SqlParameter("@Company", Company.Trim());
3464 Param[7] = new SqlParameter("@Branches", Branches.Trim());
3465 }
3466 Param[2] = new SqlParameter("@FromDate", fromdate.ToString("dd/MMM/yyyy"));
3467 Param[3] = new SqlParameter("@ToDate", todate.ToString("dd/MMM/yyyy"));
3468 if (!string.IsNullOrWhiteSpace(brokers))
3469 Param[4] = new SqlParameter("@BrokerId", brokers);
3470 Param[5] = new SqlParameter("@Type", type);
3471 ds = SqlHelper.ExecuteDataset(CommandType.StoredProcedure, "GetAdvisorReport", Param);
3472 }
3473 catch (Exception ex)
3474 {
3475 ds = new DataSet();
3476 Helper.ErrorLog(ex.InnerException, "Q_Report", "GetAdviserReport", ex.Message);
3477 }
3478 return ds;
3479 }
3480 /// <summary>
3481 /// Getting Branch Report
3482 /// </summary>
3483 /// <param name="fromdate">from date</param>
3484 /// <param name="todate">to date</param>
3485 /// <param name="Branch">Brnach Name</param>
3486 /// <returns></returns>
3487 public DataSet GetBranchReport(DateTime fromdate, DateTime todate, string Branch = "")
3488 {
3489 DataSet ds;
3490 try
3491 {
3492 List<Negotiation> negotiationlist = new List<Models.Negotiation>();
3493 SqlParameter[] Param = new SqlParameter[3];
3494 Param[0] = new SqlParameter("@Branch", Branch.Trim());
3495 Param[1] = new SqlParameter("@FromDate", fromdate);
3496 Param[2] = new SqlParameter("@ToDate", todate);
3497 ds = SqlHelper.ExecuteDataset(CommandType.StoredProcedure, "GetBranchReport", Param);
3498 }
3499 catch (Exception ex)
3500 {
3501 Helper.ErrorLog(ex.InnerException, "Q_Report", "GetBranchReport", ex.Message);
3502 ds = new DataSet();
3503 }
3504 return ds;
3505 }
3506
3507 //modified on 23-12-2014
3508 /// <summary>
3509 /// Get dataset for Mortgage case written report
3510 /// </summary>
3511 /// <param name="type">type id</param>
3512 /// <param name="fromdate">from date</param>
3513 /// <param name="todate">to date</param>
3514 /// <param name="userid">user id</param>
3515 /// <param name="brokerId">Broker Id</param>
3516 /// <param name="Negotiator">Negotiator</param>
3517 /// <param name="brokers">brokers</param>
3518 /// <param name="Company">company</param>
3519 /// <param name="Branches">Branches</param>
3520 /// <param name="productTypeID">ProductTypeId</param>
3521 /// <returns></returns>
3522 public DataSet GetMortgageCaseWrittenReport(string type, DateTime fromdate, DateTime todate, int userid, int brokerId = 0, string Negotiator = "", string brokers = "", string Company = "", string Branches = "", int productTypeID = 0)
3523 {
3524 DataSet ds;
3525 try
3526 {
3527 SqlParameter[] Param = new SqlParameter[9];
3528 Param[0] = new SqlParameter("@CurrentUserId", userid);
3529 Param[1] = new SqlParameter("@FromDate", fromdate.ToString("dd/MMM/yyyy"));
3530 Param[2] = new SqlParameter("@ToDate", todate.ToString("dd/MMM/yyyy"));
3531 if (!string.IsNullOrEmpty(Negotiator))
3532 {
3533 Param[3] = new SqlParameter("@Negotiator", Negotiator.Trim());
3534 Param[4] = new SqlParameter("@Company", Company.Trim());
3535 Param[5] = new SqlParameter("@Branches", Branches.Trim());
3536 }
3537 if (!string.IsNullOrWhiteSpace(brokers))
3538 {
3539 Param[6] = new SqlParameter("@BrokerId", brokers);
3540 }
3541 if (!string.IsNullOrWhiteSpace(type))
3542 {
3543 Param[7] = new SqlParameter("@MortgageType", type);
3544 }
3545
3546 Param[8] = new SqlParameter("@productTypeID", productTypeID);
3547
3548 ds = SqlHelper.ExecuteDataset(CommandType.StoredProcedure, "GetMortgageCaseWritten", Param);
3549 }
3550 catch (Exception ex)
3551 {
3552 ds = new DataSet();
3553 Helper.ErrorLog(ex.InnerException, "Q_Report", "GetMortgageCaseWrittenReport", ex.Message);
3554 }
3555 return ds;
3556 }
3557 /// <summary>
3558 /// Getting dataset for overall conversion report for Introducer Report
3559 /// </summary>
3560 /// <param name="totalLeads">Total Leads output parameter</param>
3561 /// <param name="totalApps">Total Apps Output parameter</param>
3562 /// <param name="fromdate">from date</param>
3563 /// <param name="todate">to date</param>
3564 /// <param name="userid">user Id</param>
3565 /// <param name="brokerId">broker Id</param>
3566 /// <param name="Negotiator">Negotiator</param>
3567 /// <param name="brokers">Brokers</param>
3568 /// <param name="Company">Companies</param>
3569 /// <param name="Branches">Branches</param>
3570 /// <param name="productTypeID">Product Type Id</param>
3571 public void GetOverAllConversionReport(out int totalLeads, out int totalApps, DateTime fromdate, DateTime todate, int userid, int brokerId = 0, string Negotiator = "", string brokers = "", string Company = "", string Branches = "", int productTypeID = 0)
3572 {
3573 DataSet ds;
3574 totalLeads = 0;
3575 totalApps = 0;
3576 try
3577 {
3578 List<Negotiation> negotiationlist = new List<Models.Negotiation>();
3579 SqlParameter[] Param = new SqlParameter[8];
3580 Param[0] = new SqlParameter("@CurrentUserId", userid);
3581 if (!string.IsNullOrEmpty(Negotiator))
3582 {
3583 Param[1] = new SqlParameter("@Negotiator", "'" + Negotiator.TrimEnd(',') + "'");
3584 Param[2] = new SqlParameter("@Company", "'" + Company.TrimEnd(',') + "'");
3585 Param[3] = new SqlParameter("@Branches", "'" + Branches.TrimEnd(',') + "'");
3586 }
3587 if (!string.IsNullOrWhiteSpace(brokers))
3588 {
3589 Param[4] = new SqlParameter("@BrokerId", brokers);
3590 }
3591 Param[5] = new SqlParameter("@FromDate", fromdate.ToString("dd/MMM/yyyy"));
3592 Param[6] = new SqlParameter("@ToDate", todate.ToString("dd/MMM/yyyy"));
3593 Param[7] = new SqlParameter("@productTypeID", productTypeID);
3594 ds = SqlHelper.ExecuteDataset(CommandType.StoredProcedure, "GetOverAllConversionForIntroducer", Param);
3595 if (ds.Tables[0].Rows.Count > 0)
3596 {
3597 totalLeads = Convert.ToInt32(ds.Tables[0].Rows[0]["TotalCount"].ToString());
3598 }
3599 if (ds.Tables[1].Rows.Count > 0)
3600 {
3601 totalApps = Convert.ToInt32(ds.Tables[1].Rows[0]["TotalCount"].ToString());
3602 }
3603 }
3604 catch (Exception ex)
3605 {
3606 ds = new DataSet();
3607 Helper.ErrorLog(ex.InnerException, "Q_Report", "GetOverAllConversionReport", ex.Message);
3608 }
3609
3610 }
3611
3612
3613 #region [Get Insurance Written Report 2014-12-23]
3614
3615 /// <summary>
3616 /// method for InsuranceCaseWritten
3617 /// created on : 03/11/2014
3618 ///modified on 23-12-2014
3619 /// </summary>
3620 /// <param name="type">type</param>
3621 /// <param name="fromdate">from date</param>
3622 /// <param name="todate">to date</param>
3623 /// <param name="userid">user id</param>
3624 /// <param name="brokerId">broker id</param>
3625 /// <param name="Negotiator">negotiator</param>
3626 /// <param name="brokers">brokers</param>
3627 /// <param name="Company">company</param>
3628 /// <param name="Branches">branches</param>
3629 /// <param name="productTypeID">product type Id</param>
3630 /// <returns></returns>
3631 public DataSet GetInsuranceCaseWrittenReport(string type, DateTime fromdate, DateTime todate, int userid, int brokerId = 0, string Negotiator = "", string brokers = "", string Company = "", string Branches = "", int productTypeID = 0)
3632 {
3633 DataSet ds;
3634 try
3635 {
3636 SqlParameter[] Param = new SqlParameter[9];
3637 Param[0] = new SqlParameter("@CurrentUserId", userid);
3638 Param[1] = new SqlParameter("@FromDate", fromdate.ToString("dd/MMM/yyyy"));
3639 Param[2] = new SqlParameter("@ToDate", todate.ToString("dd/MMM/yyyy"));
3640 if (!string.IsNullOrEmpty(Negotiator))
3641 {
3642 Param[3] = new SqlParameter("@Negotiator", Negotiator.Trim());
3643 Param[4] = new SqlParameter("@Company", Company.Trim());
3644 Param[5] = new SqlParameter("@Branches", Branches.Trim());
3645 }
3646 if (!string.IsNullOrWhiteSpace(brokers))
3647 {
3648 Param[6] = new SqlParameter("@BrokerId", brokers);
3649 }
3650 if (!string.IsNullOrWhiteSpace(type))
3651 {
3652 Param[7] = new SqlParameter("@InsuranceType", type);
3653 }
3654 Param[8] = new SqlParameter("@productTypeID", productTypeID);
3655
3656 ds = SqlHelper.ExecuteDataset(CommandType.StoredProcedure, "GetInsuranceCaseWritten", Param);
3657 }
3658 catch (Exception ex)
3659 {
3660 Helper.ErrorLog(ex.InnerException, "Q_Report", "GetInsuranceCaseWrittenReport", ex.Message);
3661 ds = new DataSet();
3662 }
3663 return ds;
3664 }
3665
3666 #endregion [Get Insurance Written Report 2014-12-23]
3667
3668 #region [Get Mortgage Completed Report 2015-03-30]
3669 /// <summary>
3670 /// Getting dataset for Mortgage completed report
3671 /// </summary>
3672 /// <param name="type">type</param>
3673 /// <param name="fromdate">from date</param>
3674 /// <param name="todate">to date</param>
3675 /// <param name="userid">user id</param>
3676 /// <param name="brokerId">broker id</param>
3677 /// <param name="Negotiator">negotiator</param>
3678 /// <param name="brokers">brokers</param>
3679 /// <param name="Company">company</param>
3680 /// <param name="Branches">branches</param>
3681 /// <param name="productTypeID">product type id</param>
3682 /// <returns></returns>
3683 public DataSet GetMortgageCompletedReport(string type, DateTime fromdate, DateTime todate, int userid, int brokerId = 0, string Negotiator = "", string brokers = "", string Company = "", string Branches = "", int productTypeID = 0)
3684 {
3685 DataSet ds;
3686 try
3687 {
3688 SqlParameter[] Param = new SqlParameter[9];
3689 Param[0] = new SqlParameter("@CurrentUserId", userid);
3690 Param[1] = new SqlParameter("@FromDate", fromdate.ToString("dd/MMM/yyyy"));
3691 Param[2] = new SqlParameter("@ToDate", todate.ToString("dd/MMM/yyyy"));
3692 if (!string.IsNullOrEmpty(Negotiator))
3693 {
3694 Param[3] = new SqlParameter("@Negotiator", Negotiator.Trim());
3695 Param[4] = new SqlParameter("@Company", Company.Trim());
3696 Param[5] = new SqlParameter("@Branches", Branches.Trim());
3697 }
3698 if (!string.IsNullOrWhiteSpace(brokers))
3699 {
3700 Param[6] = new SqlParameter("@BrokerId", brokers);
3701 }
3702 if (!string.IsNullOrWhiteSpace(type))
3703 {
3704 Param[7] = new SqlParameter("@MortgageType", type);
3705 }
3706
3707 Param[8] = new SqlParameter("@productTypeID", productTypeID);
3708
3709 ds = SqlHelper.ExecuteDataset(CommandType.StoredProcedure, "GetMortgageCompletedReport", Param);
3710 }
3711 catch (Exception ex)
3712 {
3713 ds = new DataSet();
3714 Helper.ErrorLog(ex.InnerException, "Q_Report", "GetMortgageCompletedReport", ex.Message);
3715 }
3716 return ds;
3717 }
3718 #endregion [Get Mortgage Completed Report 2015-03-30]
3719
3720 #region [Get Insurance Completed Report 2015-03-30]
3721 /// <summary>
3722 /// Dataset for Insurance Completed Report
3723 /// </summary>
3724 /// <param name="type">type</param>
3725 /// <param name="fromdate">from date</param>
3726 /// <param name="todate">to date</param>
3727 /// <param name="userid">user id</param>
3728 /// <param name="brokerId">broker id</param>
3729 /// <param name="Negotiator">negotiator</param>
3730 /// <param name="brokers">brokers</param>
3731 /// <param name="Company">company</param>
3732 /// <param name="Branches">branches</param>
3733 /// <param name="productTypeID">product type Id</param>
3734 /// <returns></returns>
3735 public DataSet GetInsuranceCompletedReport(string type, DateTime fromdate, DateTime todate, int userid, int brokerId = 0, string Negotiator = "", string brokers = "", string Company = "", string Branches = "", int productTypeID = 0)
3736 {
3737 DataSet ds;
3738 try
3739 {
3740 SqlParameter[] Param = new SqlParameter[9];
3741 Param[0] = new SqlParameter("@CurrentUserId", userid);
3742 Param[1] = new SqlParameter("@FromDate", fromdate.ToString("dd/MMM/yyyy"));
3743 Param[2] = new SqlParameter("@ToDate", todate.ToString("dd/MMM/yyyy"));
3744 if (!string.IsNullOrEmpty(Negotiator))
3745 {
3746 Param[3] = new SqlParameter("@Negotiator", Negotiator.Trim());
3747 Param[4] = new SqlParameter("@Company", Company.Trim());
3748 Param[5] = new SqlParameter("@Branches", Branches.Trim());
3749 }
3750 if (!string.IsNullOrWhiteSpace(brokers))
3751 {
3752 Param[6] = new SqlParameter("@BrokerId", brokers);
3753 }
3754 if (!string.IsNullOrWhiteSpace(type))
3755 {
3756 Param[7] = new SqlParameter("@InsuranceType", type);
3757 }
3758 Param[8] = new SqlParameter("@productTypeID", productTypeID);
3759
3760 ds = SqlHelper.ExecuteDataset(CommandType.StoredProcedure, "GetInsuranceCompletedReport", Param);
3761 }
3762 catch (Exception ex)
3763 {
3764 Helper.ErrorLog(ex.InnerException, "Q_Report", "GetInsuranceCompletedReport", ex.Message);
3765 ds = new DataSet();
3766 }
3767 return ds;
3768 }
3769
3770 #endregion [Get Insurance Completed Report 2015-03-30]
3771
3772 // method for InsuranceCaseWritten
3773 // created on : 12/11/2014
3774 /// <summary>
3775 /// Getting WOCC Report
3776 /// </summary>
3777 /// <param name="type">type</param>
3778 /// <param name="fromdate">from date</param>
3779 /// <param name="todate">to date</param>
3780 /// <param name="userid">user id</param>
3781 /// <param name="brokerId">broker id</param>
3782 /// <param name="Negotiator">negotiator</param>
3783 /// <param name="brokers">brokers</param>
3784 /// <param name="Company">company</param>
3785 /// <param name="Branches">branches</param>
3786 /// <returns></returns>
3787 public DataSet GetPipelineReviewReport(string type, DateTime fromdate, DateTime todate, int userid, int brokerId = 0, string Negotiator = "", string brokers = "", string Company = "", string Branches = "")
3788 {
3789 DataSet ds;
3790 try
3791 {
3792 SqlParameter[] Param = new SqlParameter[8];
3793 Param[0] = new SqlParameter("@CurrentUserId", userid);
3794 Param[1] = new SqlParameter("@FromDate", fromdate.ToString("dd/MMM/yyyy"));
3795 Param[2] = new SqlParameter("@ToDate", todate.ToString("dd/MMM/yyyy"));
3796 if (!string.IsNullOrEmpty(Negotiator))
3797 {
3798 Param[3] = new SqlParameter("@Negotiator", Negotiator.Trim());
3799 Param[4] = new SqlParameter("@Company", Company.Trim());
3800 Param[5] = new SqlParameter("@Branches", Branches.Trim());
3801 }
3802 if (!string.IsNullOrWhiteSpace(brokers))
3803 {
3804 Param[6] = new SqlParameter("@BrokerId", brokers);
3805 }
3806 if (!string.IsNullOrWhiteSpace(type))
3807 {
3808 Param[7] = new SqlParameter("@MortgageType", type);
3809 }
3810
3811 ds = SqlHelper.ExecuteDataset(CommandType.StoredProcedure, "GetMortgageCaseWritten", Param);
3812 }
3813 catch (Exception ex)
3814 {
3815 Helper.ErrorLog(ex.InnerException, "Q_Report", "GetPipelineReviewReport", ex.Message);
3816 ds = new DataSet();
3817 }
3818 return ds;
3819 }
3820
3821 /// <summary>
3822 /// Get new financial information report!
3823 /// </summary>
3824 /// <param name="type">type</param>
3825 /// <param name="fromdate">from date</param>
3826 /// <param name="todate">to date</param>
3827 /// <param name="userid">user id</param>
3828 /// <param name="brokerId">broker id</param>
3829 /// <param name="Negotiator">negotiator</param>
3830 /// <param name="brokers">brokers</param>
3831 /// <param name="Company">company</param>
3832 /// <param name="Branches">Branches</param>
3833 /// <returns></returns>
3834 //modified on 23-12-2014
3835 public DataSet GetNewFinancialInformationReport(string type, DateTime fromdate, DateTime todate, int userid, int brokerId = 0, string Negotiator = "", string brokers = "", string Company = "", string Branches = "", int FinType = 0)
3836 {
3837 DataSet ds;
3838 try
3839 {
3840 SqlParameter[] Param = new SqlParameter[8];
3841 Param[0] = new SqlParameter("@CurrentUserId", userid);
3842 Param[1] = new SqlParameter("@FromDate", fromdate.ToString("dd/MMM/yyyy"));
3843 Param[2] = new SqlParameter("@ToDate", todate.ToString("dd/MMM/yyyy"));
3844 if (!string.IsNullOrEmpty(Negotiator))
3845 {
3846 Param[3] = new SqlParameter("@Negotiator", Negotiator.Trim());
3847 Param[4] = new SqlParameter("@Company", Company.Trim());
3848 Param[5] = new SqlParameter("@Branches", Branches.Trim());
3849 }
3850 if (!string.IsNullOrWhiteSpace(brokers))
3851 {
3852 Param[6] = new SqlParameter("@BrokerId", brokers);
3853 }
3854 if (!string.IsNullOrWhiteSpace(type))
3855 {
3856 Param[7] = new SqlParameter("@InsuranceType", type);
3857 }
3858 Param[7] = new SqlParameter("@FinanceType", FinType);
3859
3860 ds = SqlHelper.ExecuteDataset(CommandType.StoredProcedure, "GetWOCCReport", Param);
3861 }
3862 catch (Exception ex)
3863 {
3864 Helper.ErrorLog(ex.InnerException, "Q_Report", "GetNewFinancialInformationReport", ex.Message);
3865 ds = new DataSet();
3866 }
3867 return ds;
3868 }
3869 /// <summary>
3870 /// Getting Dataset for Remortgage Report
3871 /// </summary>
3872 /// <param name="totalApps">Return total apps</param>
3873 /// <param name="userid">User Id</param>
3874 /// <param name="brokerId">Broker Id</param>
3875 /// <param name="Year">Year filter</param>
3876 /// <param name="Month">Month filter</param>
3877 /// <returns></returns>
3878 public DataSet GetReMortgageReport(out int totalApps, int userid, int brokerId = 0, int Year = 0, int Month = 0)
3879 {
3880 DataSet ds;
3881 totalApps = 0;
3882 try
3883 {
3884 SqlParameter[] Param = new SqlParameter[4];
3885 Param[0] = new SqlParameter("@CurrentUserId", userid);
3886 Param[1] = new SqlParameter("@BrokerId", brokerId);
3887 Param[2] = new SqlParameter("@Year", Year);
3888 Param[3] = new SqlParameter("@Month", Month);
3889
3890 ds = SqlHelper.ExecuteDataset(CommandType.StoredProcedure, "GetReMortgageReport_Update", Param);
3891 if (ds.Tables[1].Rows.Count > 0)
3892 {
3893 totalApps = Convert.ToInt32(ds.Tables[1].Rows[0]["TotalApps"].ToString());
3894 }
3895 }
3896 catch (Exception ex)
3897 {
3898 Helper.ErrorLog(ex.InnerException, "Q_Report", "GetRemortgageReport", ex.Message);
3899 ds = new DataSet();
3900 }
3901 return ds;
3902 }
3903
3904 /// <summary>
3905 /// Used to return reports data model for mortgage case written view
3906 /// </summary>
3907 /// <param name="userId"></param>
3908 /// <param name="loggedInUserId"></param>
3909 /// <returns></returns>
3910 public ReportsDataModel GetMortgageCaseWrittenDetails(int userId, int loggedInUserId)
3911 {
3912 var reportsDM = new ReportsDataModel();
3913 try
3914 {
3915 reportsDM.MortgageTreeModel = new MortgageTreeModel();
3916 reportsDM.MortgageTreeModel.IsSubmit = 0;
3917 reportsDM.MortgageTreeModel.Purchase = "Residential Purchase";
3918 var qSettings = new Q_settings();
3919 var clients = qSettings.FindBrokerForLoggedInUserWithUserId(userId, loggedInUserId);
3920 if (clients == null)
3921 {
3922 reportsDM.MortgageTreeModel.BItems = new List<Clients>();
3923 }
3924 reportsDM.MortgageTreeModel.BItems = clients;
3925 var qClients = new Q_Client();
3926 reportsDM.MortgageTreeModel.ClientsOrderBy = qClients.FindClients(userId, loggedInUserId).OrderBy(c => c.companyname).ToList();
3927 reportsDM.MortgageTreeModel.BrokersWithTeams = qSettings.GetBrokersWithTeams(loggedInUserId);
3928 reportsDM.MortgageTreeModel.ProductTypeList = GetAllFinanceType();
3929 }
3930 catch (Exception ex)
3931 {
3932 Helper.ErrorLog(ex.InnerException, "Q_Report", "GetMortgageCaseWrittenDetails", ex.Message);
3933 }
3934 return reportsDM;
3935 }
3936
3937 /// <summary>
3938 /// Used to return contact list by account number.
3939 /// </summary>
3940 /// <param name="acccountNumber"></param>
3941 /// <returns></returns>
3942 public List<tblcontact> GetContactByAccount(int acccountNumber)
3943 {
3944 var qNewLeads = new Q_NewLead();
3945 return qNewLeads.FindContactsForAccount(acccountNumber);
3946 }
3947
3948 /// <summary>
3949 /// Get all companies details
3950 /// </summary>
3951 /// <returns></returns>
3952 public List<clsCompanyDetails> GetAllCompaniesDetails()
3953 {
3954 List<clsCompanyDetails> lstCompanyDetails;
3955 try
3956 {
3957 DataTable dtCompanyDetails = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "GetAllCompaniesInfo_Update");
3958 lstCompanyDetails = new List<clsCompanyDetails>(dtCompanyDetails.Rows.Count);
3959 foreach (DataRow row in dtCompanyDetails.Rows)
3960 {
3961 var values = row.ItemArray;
3962 var category = new clsCompanyDetails()
3963 {
3964 AccountId = Convert.ToInt32(values[0]),
3965 CompanyName = Convert.ToString(values[1]),
3966 Branch = Convert.ToString(values[2]),
3967 BranchId = Convert.ToInt32(values[3]),
3968 Negotiator = Convert.ToString(values[4]),
3969 NegotiatorId = Convert.ToInt32(values[5])
3970 };
3971 lstCompanyDetails.Add(category);
3972 }
3973 }
3974 catch (Exception)
3975 {
3976 throw;
3977 }
3978 return lstCompanyDetails;
3979 }
3980 #region Total written Report
3981 /// <summary>
3982 /// Returning dataset for total written report
3983 /// </summary>
3984 /// <param name="type">Type</param>
3985 /// <param name="fromdate">From Date</param>
3986 /// <param name="todate">To date</param>
3987 /// <param name="userid">User Id</param>
3988 /// <param name="brokerId">Broker Id</param>
3989 /// <param name="Negotiator">Negotiator</param>
3990 /// <param name="brokers">Brokers</param>
3991 /// <param name="Company">Company</param>
3992 /// <param name="Branches">branches</param>
3993 /// <param name="productTypeID">ProductType Id</param>
3994 /// <returns></returns>
3995 public DataSet GetTotalWrittenReport(string type, DateTime fromdate, DateTime todate, int userid, int brokerId = 0, string Negotiator = "", string brokers = "", string Company = "", string Branches = "", int productTypeID = 0)
3996 {
3997 DataSet ds;
3998 try
3999 {
4000 SqlParameter[] Param = new SqlParameter[7];
4001 Param[0] = new SqlParameter("@CurrentUserId", userid);
4002 Param[1] = new SqlParameter("@FromDate", fromdate.ToString("dd/MMM/yyyy"));
4003 Param[2] = new SqlParameter("@ToDate", todate.ToString("dd/MMM/yyyy"));
4004 if (!string.IsNullOrEmpty(Negotiator))
4005 {
4006 Param[3] = new SqlParameter("@Negotiator", Negotiator.Trim());
4007 Param[4] = new SqlParameter("@Company", Company.Trim());
4008 Param[5] = new SqlParameter("@Branches", Branches.Trim());
4009 }
4010 if (!string.IsNullOrWhiteSpace(brokers))
4011 {
4012 Param[6] = new SqlParameter("@BrokerId", brokers);
4013 }
4014 ds = SqlHelper.ExecuteDataset(CommandType.StoredProcedure, "GetTotalWritten", Param);
4015 }
4016 catch (Exception ex)
4017 {
4018 Helper.ErrorLog(ex.InnerException, "Q_Report", "GetTotalWrittenReport", ex.Message);
4019 ds = new DataSet();
4020 }
4021 return ds;
4022 }
4023 #endregion
4024
4025 #region [Optimized Code of Mortgage Case Written Report 2015-01-22]
4026
4027 /********************************************************
4028 * Code Updated on : 23/01/2015
4029 * Report related methods taked from settings
4030 *
4031 *
4032 * *******************************************************/
4033
4034 /// <summary>
4035 /// Get all broker details
4036 /// </summary>
4037 /// <param name="accid"></param>
4038 /// <param name="userId"></param>
4039 /// <returns></returns>
4040 public List<Clients> GetAllBrokerDetails(int accid, int userId)
4041 {
4042 List<Clients> lstBrokers = new List<Clients>();
4043 try
4044 {
4045 int userType = 0;
4046 var Id = GetUserTypeAndId(userId, out userType);
4047
4048 SqlParameter[] Param = new SqlParameter[2];
4049 Param[0] = new SqlParameter("@UserType", userType);
4050 Param[1] = new SqlParameter("@ID", Id);
4051 DataTable dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "FindBrokerForLoggedInUserWithUserId", Param);
4052
4053 lstBrokers = (from DataRow row in dt.Rows
4054 select new Clients
4055 {
4056 clientid = Convert.ToInt32(row["clientid"]),
4057 parent = Convert.ToInt32(row["parent"]),
4058 companyname = Convert.ToString(row["companyname"]),
4059 TeamName = Convert.ToString(row["TeamName"]),
4060 TeamId = Convert.ToInt32(row["TeamId"]),
4061 affiliateid = Convert.ToString(row["affiliateid"]),
4062 telephone = Convert.ToString(row["telephone"]),
4063 email = Convert.ToString(row["email"]),
4064 contactname = Convert.ToString(row["contactname"]),
4065 address = Convert.ToInt32(row["address"]),
4066 userid = Convert.ToInt32(row["userid"]),
4067 AdminId = Convert.ToInt32(row["AdminId"]),
4068 countLeads = Convert.ToInt32(row["countLeads"])
4069 }).ToList();
4070 }
4071 catch (Exception ex)
4072 {
4073 Helper.ErrorLog(ex.InnerException, "Q_Report", "GetAllBrokerDetails", ex.Message);
4074 throw;
4075 }
4076 return lstBrokers;
4077 }
4078
4079 /// <summary>
4080 /// Get broker details with team
4081 /// </summary>
4082 /// <param name="userId"></param>
4083 /// <returns></returns>
4084 public List<Clients> GetBrokersWithTeams(int userId)
4085 {
4086 List<Clients> lstBrokerTeam = new List<Clients>();
4087 int userType = 0;
4088 var Id = GetUserTypeAndId(userId, out userType);
4089 try
4090 {
4091 SqlParameter[] Param = new SqlParameter[2];
4092 Param[0] = new SqlParameter("@UserType", userType);
4093 Param[1] = new SqlParameter("@ID", Id);
4094 DataTable dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "GetBrokersWithTeams", Param);
4095 lstBrokerTeam = (from DataRow row in dt.Rows
4096 select new Clients
4097 {
4098 clientid = Convert.ToInt32(row["clientid"]),
4099 parent = Convert.ToInt32(row["parent"]),
4100 companyname = Convert.ToString(row["companyname"]),
4101 TeamName = Convert.ToString(row["TeamName"]),
4102 TeamId = Convert.ToInt32(row["TeamId"]),
4103 affiliateid = Convert.ToString(row["affiliateid"]),
4104 telephone = Convert.ToString(row["telephone"]),
4105 email = Convert.ToString(row["email"]),
4106 contactname = Convert.ToString(row["contactname"]),
4107 address = Convert.ToInt32(row["address"]),
4108 userid = Convert.ToInt32(row["userid"])
4109 }).ToList();
4110 }
4111 catch (Exception ex)
4112 {
4113 Helper.ErrorLog(ex.InnerException, "Q_Report", "GetBrokersWithTeams", ex.Message);
4114 throw;
4115 }
4116 return lstBrokerTeam;
4117 }
4118
4119 /// <summary>
4120 /// Get user type and id accordingly.
4121 /// </summary>
4122 /// <param name="userId"></param>
4123 /// <param name="userType"></param>
4124 /// <returns></returns>
4125 private object GetUserTypeAndId(int userId, out int userType)
4126 {
4127 int Id = 0;
4128 try
4129 {
4130 SqlParameter[] Param = new SqlParameter[1] { new SqlParameter("@UserId", userId) };
4131 DataTable dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "GetUserType", Param);
4132 Id = Convert.ToInt32(dt.Rows[0]["Id"]);
4133 userType = Convert.ToInt32(dt.Rows[0]["userType"]);
4134 }
4135 catch (Exception ex)
4136 {
4137 Helper.ErrorLog(ex.InnerException, "Q_Report", "GetUserTypeAndId", ex.Message);
4138 throw;
4139 }
4140 return Id;
4141 }
4142
4143 #endregion [Optimized Code of Mortgage Case Written Report 2015-01-22]
4144 //Insurance Referral report
4145 /// <summary>
4146 /// Insurance Referral Report
4147 /// </summary>
4148 /// <param name="fromdate">From date</param>
4149 /// <param name="todate">To date</param>
4150 /// <param name="userid">User Id</param>
4151 /// <param name="brokerId">broker id</param>
4152 /// <param name="Negotiator">Negotiator</param>
4153 /// <param name="brokers">brokers</param>
4154 /// <param name="Company">Company</param>
4155 /// <param name="Branches">Branches</param>
4156 /// <param name="ProductTypeId">ProductType</param>
4157 /// <returns></returns>
4158 public DataSet GetInsuranceReferralResult(DateTime fromdate, DateTime todate, int userid, int brokerId = 0, string Negotiator = "", string brokers = "", string Company = "", string Branches = "", int ProductTypeId = 0)
4159 {
4160 DataSet ds;
4161 try
4162 {
4163 List<Insurancereferral> negotiationlist = new List<Models.Insurancereferral>();
4164 SqlParameter[] Param = new SqlParameter[8];
4165 Param[0] = new SqlParameter("@CurrentUserId", userid);
4166 Param[1] = new SqlParameter("@Negotiator", (string.IsNullOrEmpty(Negotiator) ? null : Negotiator.Trim()));
4167 Param[2] = new SqlParameter("@Company", (string.IsNullOrEmpty(Company) ? null : Company.Trim()));
4168 Param[3] = new SqlParameter("@Branches", (string.IsNullOrEmpty(Branches) ? null : Branches.Trim()));
4169 Param[4] = new SqlParameter("@BrokerId", (string.IsNullOrEmpty(brokers) ? null : brokers));
4170 Param[5] = new SqlParameter("@FromDate", fromdate.ToString("dd/MMM/yyyy"));
4171 Param[6] = new SqlParameter("@ToDate", todate.ToString("dd/MMM/yyyy"));
4172 Param[7] = new SqlParameter("@ProductTypeId", ProductTypeId);
4173 ds = SqlHelper.ExecuteDataset("GetInsuranceReferralReport", Param);
4174 }
4175 catch (Exception ex)
4176 {
4177 Helper.ErrorLog(ex.InnerException, "Q_Report", "GetInsuranceReferralResult", ex.Message);
4178 ds = new DataSet();
4179 }
4180 return ds;
4181 }
4182
4183 #region [Client Referrals 2015-04-18]
4184
4185
4186 /// <summary>
4187 /// Getting count for referral for contact Id
4188 /// </summary>
4189 /// <param name="contactId">Contact Id</param>
4190 /// <returns></returns>
4191 public int ClientReferralsCount(string contactId)
4192 {
4193 var con = contactId.Split('_').ToList();
4194 int ContactId = 0;
4195 var contactids = new List<int>();
4196 if (con.Count() > 1)
4197 {
4198 ContactId = Convert.ToInt32(con[0]);
4199 contactids = ctx.tblcontacts.Where(x => x.parentNegId == ContactId && x.account != 1582971 && x.account == 1583028).Select(x => x.contactid).ToList();
4200 }
4201 else
4202 {
4203 ContactId = Convert.ToInt32(contactId);
4204 contactids = ctx.tblcontacts.Where(x => x.parentContactId == ContactId && x.account != 1582971 && x.account == 1583028).Select(x => x.contactid).ToList();
4205 }
4206
4207 //var contactids = ctx.tblcontacts.Where(x => x.parentContactId == contactId && x.account != 1582971 && x.account == 1583028).Select(x => x.contactid).ToList();
4208 int count = 0;
4209 if (contactids.Count > 0)
4210 {
4211 count++;
4212 contactids = ctx.tblcontacts.Where(x => contactids.Contains(x.parentContactId ?? 0) && x.account != 1582971 && x.account == 1583028).Select(x => x.contactid).ToList();
4213 while (contactids.Count > 0)
4214 {
4215 contactids = ctx.tblcontacts.Where(x => contactids.Contains(x.parentContactId ?? 0) && x.account != 1582971 && x.account == 1583028).Select(x => x.contactid).ToList();
4216 count++;
4217 }
4218 }
4219
4220 return count;
4221
4222
4223 }
4224
4225 /// <summary>
4226 /// Getting Dataset for Client Referral Report
4227 /// </summary>
4228 /// <param name="ContactId">Contact Id</param>
4229 /// <param name="referralLevel">Referral Level</param>
4230 /// <param name="referralType">Referral Type</param>
4231 /// <returns></returns>
4232 public List<ClientReferralsInfo> ClientReferralInfo(string ContactId = "", int referralLevel = 0, int referralType = 0)
4233 {
4234 int contactId = 0;
4235 var contactids = new List<int>();
4236 var con = ContactId.Split('_').ToList();
4237 if (con.Count > 1)
4238 {
4239 contactId = Convert.ToInt32(con[0]);
4240 contactids = ctx.tblcontacts.Where(x => x.parentNegId == contactId && x.account != 1582971 && x.account == 1583028).Select(x => x.contactid).ToList();
4241 }
4242 else
4243 {
4244 contactId = Convert.ToInt32(ContactId);
4245 contactids = ctx.tblcontacts.Where(x => x.parentContactId == contactId && x.account != 1582971 && x.account == 1583028).Select(x => x.contactid).ToList();
4246 }
4247
4248
4249
4250 int count = 0;
4251 List<ClientReferralsInfo> referralList = new List<ClientReferralsInfo>();
4252
4253 if (contactids.Count > 0)
4254 {
4255 count++;
4256 //if (referralLevel >= count || referralLevel == 0)
4257 //{
4258 foreach (var c in contactids)
4259 {
4260 ClientReferralsInfo objClient = new ClientReferralsInfo();
4261 objClient.ContactId = c.ToString();
4262 objClient.ReferralLevel = count;
4263 referralList.Add(objClient);
4264 }
4265 // }
4266 contactids = ctx.tblcontacts.Where(x => contactids.Contains(x.parentContactId ?? 0) && x.account != 1582971 && x.account == 1583028).Select(x => x.contactid).ToList();
4267 while (contactids.Count > 0)
4268 {
4269 count++;
4270 //if (referralLevel >= count || referralLevel == 0)
4271 //{
4272 foreach (var c in contactids)
4273 {
4274 ClientReferralsInfo objClient = new ClientReferralsInfo();
4275 objClient.ContactId = c.ToString();
4276 objClient.ReferralLevel = count;
4277 referralList.Add(objClient);
4278 }
4279 //}
4280 contactids = ctx.tblcontacts.Where(x => contactids.Contains(x.parentContactId ?? 0) && x.account != 1582971 && x.account == 1583028).Select(x => x.contactid).ToList();
4281
4282 }
4283 }
4284
4285 referralList = referralList.OrderBy(x => x.ReferralLevel).ToList();
4286 //adding parent contact
4287 ClientReferralsInfo objClient1 = new ClientReferralsInfo();
4288 objClient1.ContactId = ContactId;
4289 objClient1.ReferralLevel = 0;
4290 referralList.Insert(0, objClient1);
4291 //adding parent contact
4292 foreach (var v in referralList)
4293 {
4294 var conn = v.ContactId.Split('_').ToList();
4295 if (conn.Count == 1)
4296 {
4297 int cont = Convert.ToInt32(v.ContactId);
4298 var WrittenCommission = (from f in ctx.tblfinances
4299 join fs in ctx.tblfinance_statusdate on f.financeid equals fs.financeid
4300 where f.status != 34 && f.status != 35 && f.status != 36 && f.status != 37 && f.status != 38
4301 && (fs.status == 6 || fs.status == 13) && f.contact == cont
4302 select new
4303 {
4304 f.commission
4305 }).Sum(x => x.commission);
4306
4307 var WrittenMortgage = (from f in ctx.tblfinances
4308 join fs in ctx.tblfinance_statusdate on f.financeid equals fs.financeid
4309 where f.status != 34 && f.status != 35 && f.status != 36 && f.status != 37 && f.status != 38
4310 && (fs.status == 6) && f.contact == cont
4311 select new
4312 {
4313 f.amount
4314 }).Sum(x => x.amount);
4315
4316 var IssuedCommission = (from f in ctx.tblfinances
4317 join fs in ctx.tblfinance_statusdate on f.financeid equals fs.financeid
4318 where f.status != 34 && f.status != 35 && f.status != 36 && f.status != 37 && f.status != 38
4319 && (fs.status == 8 || fs.status == 14) && f.contact == cont
4320 select new
4321 {
4322 f.commission
4323 }).Sum(x => x.commission);
4324
4325 var Issuedmortgage = (from f in ctx.tblfinances
4326 join fs in ctx.tblfinance_statusdate on f.financeid equals fs.financeid
4327 where f.status != 34 && f.status != 35 && f.status != 36 && f.status != 37 && f.status != 38
4328 && (fs.status == 8) && f.contact == cont
4329 select new
4330 {
4331 f.amount
4332 }).Sum(x => x.amount);
4333 var name = ctx.tblcontacts.Where(x => x.contactid == cont).Select(x => new { x.firstname, x.lastname, x.parentContactId }).FirstOrDefault();
4334 var ReferrerName = ctx.tblcontacts.Where(x => x.contactid == name.parentContactId).Select(x => new { x.firstname, x.lastname }).FirstOrDefault();
4335 v.WrittenCommission = WrittenCommission ?? 0;
4336 v.WrittenMortgage = WrittenMortgage ?? 0;
4337 v.IssuedCommission = IssuedCommission ?? 0;
4338 v.IssuedMortgage = Issuedmortgage ?? 0;
4339 v.ContactName = (name.firstname ?? "") + " " + (name.lastname ?? "");
4340
4341 if (ReferrerName != null)
4342 v.ReferrerName = (ReferrerName.firstname ?? "") + " " + (ReferrerName.lastname ?? "");
4343 else
4344 v.ReferrerName = "";
4345
4346 string parent = "";
4347
4348 parent = ctx.tblcontacts.Where(x => x.contactid == cont && v.ContactId != ContactId && x.parentContactId != 0).Select(x => x.parentContactId).FirstOrDefault().ToString();
4349
4350 if (parent == "")
4351 {
4352 parent = ctx.tblcontacts.Where(x => x.contactid == cont && v.ContactId != ContactId && x.parentNegId != 0).Select(x => x.parentNegId).FirstOrDefault().ToString();
4353 if (parent != string.Empty)
4354 parent = parent + "_neg";
4355 else
4356 parent = null;
4357 }
4358 v.ParentContactId = parent;
4359 }
4360 else
4361 {
4362 int neg = Convert.ToInt32(conn[0]);
4363 v.ContactName = ctx.tblClientReferralNeg.Where(x => x.NegId == neg).FirstOrDefault().NegName;
4364
4365 }
4366
4367 }
4368 referralList = referralList.OrderBy(x => x.ReferralLevel).ThenByDescending(x => x.WrittenCommission).ToList();
4369
4370 //for new dropdown list of referral type
4371 int loop = referralType;
4372 if (referralType == 0)
4373 {
4374 loop = referralList.Select(x => x.ReferralLevel).Max();
4375 }
4376 foreach (var v in referralList)
4377 {
4378 int i = 1;
4379
4380 var cIds = referralList.Where(x => x.ParentContactId == v.ContactId).Select(x => x.ContactId).ToList();
4381
4382 var writMort = referralList.Where(x => cIds.Contains(x.ContactId)).Select(x => x.WrittenMortgage).Sum();
4383 var writComm = referralList.Where(x => cIds.Contains(x.ContactId)).Select(x => x.WrittenCommission).Sum();
4384 var Issumort = referralList.Where(x => cIds.Contains(x.ContactId)).Select(x => x.IssuedMortgage).Sum();
4385 var IssuComm = referralList.Where(x => cIds.Contains(x.ContactId)).Select(x => x.IssuedCommission).Sum();
4386
4387 while (i < loop)
4388 {
4389 cIds = referralList.Where(x => cIds.Contains(x.ParentContactId)).Select(x => x.ContactId).ToList();
4390 if (referralType == 0)
4391 {
4392 writMort += referralList.Where(x => cIds.Contains(x.ContactId)).Select(x => x.WrittenMortgage).Sum();
4393 writComm += referralList.Where(x => cIds.Contains(x.ContactId)).Select(x => x.WrittenCommission).Sum();
4394 Issumort += referralList.Where(x => cIds.Contains(x.ContactId)).Select(x => x.IssuedMortgage).Sum();
4395 IssuComm += referralList.Where(x => cIds.Contains(x.ContactId)).Select(x => x.IssuedCommission).Sum();
4396 }
4397 if (cIds.Count > 0)
4398 {
4399 i++;
4400 }
4401 else
4402 {
4403 break;
4404 }
4405
4406 }
4407 if (referralType == 0)
4408 {
4409 v.RefWrittenMortgage = writMort;
4410 v.RefWrittenCommission = writComm;
4411 v.RefIssuedMortgage = Issumort;
4412 v.RefIssuedCommission = IssuComm;
4413 }
4414 else
4415 {
4416 v.RefWrittenMortgage = referralList.Where(x => cIds.Contains(x.ContactId)).Select(x => x.WrittenMortgage).Sum();
4417 v.RefWrittenCommission = referralList.Where(x => cIds.Contains(x.ContactId)).Select(x => x.WrittenCommission).Sum();
4418 v.RefIssuedMortgage = referralList.Where(x => cIds.Contains(x.ContactId)).Select(x => x.IssuedMortgage).Sum();
4419 v.RefIssuedCommission = referralList.Where(x => cIds.Contains(x.ContactId)).Select(x => x.IssuedCommission).Sum();
4420 }
4421 }
4422
4423
4424 if (referralLevel > 0)
4425 {
4426 referralList = referralList.Where(x => x.ReferralLevel <= referralLevel).ToList();
4427 }
4428
4429
4430 return referralList;
4431 }
4432
4433
4434 #endregion [Client Referrals 2015-04-18]
4435
4436 #region[Business report]
4437 /// <summary>
4438 /// Getting Business report
4439 /// </summary>
4440 /// <param name="fromdate">From date</param>
4441 /// <param name="todate">To date</param>
4442 /// <param name="type">type</param>
4443 /// <param name="userid">user id</param>
4444 /// <param name="brokerId">broker id</param>
4445 /// <param name="Negotiator">negotiator</param>
4446 /// <param name="brokers">brokers</param>
4447 /// <param name="Company">company</param>
4448 /// <param name="Branches">Branches</param>
4449 /// <param name="productTypeID">ProductTypeId</param>
4450 /// <returns></returns>
4451 public DataSet GetBusinessReport(DateTime fromdate, DateTime todate, string type, int userid, int brokerId = 0, string Negotiator = "", string brokers = "", string Company = "", string Branches = "", int productTypeID = 0)
4452 {
4453 DataSet ds;
4454 try
4455 {
4456 SqlParameter[] Param = new SqlParameter[8];
4457 Param[0] = new SqlParameter("@CurrentUserId", userid);
4458 Param[1] = new SqlParameter("@FromDate", fromdate.ToString("dd/MMM/yyyy"));
4459 Param[2] = new SqlParameter("@ToDate", todate.ToString("dd/MMM/yyyy"));
4460 if (!string.IsNullOrEmpty(Negotiator))
4461 {
4462 Param[3] = new SqlParameter("@Negotiator", Negotiator.Trim());
4463 Param[4] = new SqlParameter("@Company", Company.Trim());
4464 Param[5] = new SqlParameter("@Branches", Branches.Trim());
4465 }
4466 if (!string.IsNullOrWhiteSpace(brokers))
4467 {
4468 Param[6] = new SqlParameter("@BrokerId", brokers);
4469 }
4470
4471 Param[7] = new SqlParameter("@productTypeID", productTypeID);
4472
4473 ds = SqlHelper.ExecuteDataset(CommandType.StoredProcedure, "GetBusinessReport", Param);
4474 }
4475 catch (Exception ex)
4476 {
4477 Helper.ErrorLog(ex.InnerException, "Q_report", "GetBusinessReport", ex.Message);
4478 ds = new DataSet();
4479 }
4480 return ds;
4481 }
4482 #endregion
4483
4484 #region[Most Valuable referrer report]
4485 /// <summary>
4486 /// Getting most valuable referral Report
4487 /// </summary>
4488 /// <param name="type">type</param>
4489 /// <param name="userid">user id</param>
4490 /// <param name="brokerId">broker id</param>
4491 /// <param name="Negotiator">Negotiator</param>
4492 /// <param name="brokers">Brokers</param>
4493 /// <param name="Company">Company</param>
4494 /// <param name="Branches">Branches</param>
4495 /// <param name="productTypeID">Product type Id</param>
4496 /// <returns></returns>
4497 public DataSet GetMostValuableReport(string type, int userid, int brokerId = 0, string Negotiator = "", string brokers = "", string Company = "", string Branches = "", int productTypeID = 0)
4498 {
4499 DataSet ds;
4500 try
4501 {
4502 SqlParameter[] Param = new SqlParameter[5];
4503 Param[0] = new SqlParameter("@CurrentUserId", userid);
4504
4505 if (!string.IsNullOrEmpty(Negotiator))
4506 {
4507 Param[1] = new SqlParameter("@Negotiator", Negotiator.Trim());
4508 Param[2] = new SqlParameter("@Company", Company.Trim());
4509 Param[3] = new SqlParameter("@Branches", Branches.Trim());
4510 }
4511 if (!string.IsNullOrWhiteSpace(brokers))
4512 {
4513 Param[4] = new SqlParameter("@BrokerId", brokers);
4514 }
4515 ds = SqlHelper.ExecuteDataset(CommandType.StoredProcedure, "GetMostValuableReferrersreport", Param);
4516 }
4517 catch (Exception ex)
4518 {
4519 ds = new DataSet();
4520 Helper.ErrorLog(ex.InnerException, "Q_Report", "GetMostValuableReport", ex.Message);
4521 }
4522 return ds;
4523 }
4524 #endregion
4525
4526 #region [Updated Code of Reports Data Access Methods 2015-10-21]
4527
4528 #region [Adviser Report]
4529
4530 /// <summary>
4531 /// Updated data access code of adviser report. It fetched data on the basis of negotiator, branch and company ids. Updated on 2015-10-21
4532 /// </summary>
4533 /// <param name="NegotiatorIds">Contains negotiator's ids</param>
4534 /// <param name="BranchIds">Contain branch's ids</param>
4535 /// <param name="CompanyIds">Contain company's ids</param>
4536 /// <param name="fromdate">From date</param>
4537 /// <param name="todate">To date</param>
4538 /// <param name="userid">User id</param>
4539 /// <param name="brokerId">Broker ids</param>
4540 /// <param name="type">Type</param>
4541 /// <param name="Negotiator">Negotiators</param>
4542 /// <param name="brokers">Brokers</param>
4543 /// <param name="Company">Companies</param>
4544 /// <param name="Branches">Branches</param>
4545 /// <returns></returns>
4546 public DataSet GetAdvisorReportByIds(List<int> NegotiatorIds, List<int> BranchIds, List<int> CompanyIds, DateTime fromdate, DateTime todate, int userid, int brokerId = 0, int type = 1, string Negotiator = "", string brokers = "", string Company = "", string Branches = "")
4547 {
4548 DataSet ds = new DataSet();
4549 try
4550 {
4551 List<Negotiation> negotiationlist = new List<Models.Negotiation>();
4552 SqlParameter[] Param = new SqlParameter[11];
4553 Param[0] = new SqlParameter("@CurrentUserId", userid);
4554 if (!string.IsNullOrEmpty(Negotiator))
4555 {
4556 Param[1] = new SqlParameter("@Negotiator", Negotiator.Trim());
4557 Param[6] = new SqlParameter("@Company", Company.Trim());
4558 Param[7] = new SqlParameter("@Branches", Branches.Trim());
4559
4560 //Convert Negotiator, Branch and Company Ids list into datatable and pass them into sql procedure parameter value. -20151021
4561 DataTable dtNegotiatorIds = Helper.FillDataTable(NegotiatorIds);
4562 Param[8] = new SqlParameter("@NegotiatorIds", dtNegotiatorIds);
4563
4564 DataTable dtBranchIds = Helper.FillDataTable(BranchIds);
4565 Param[9] = new SqlParameter("@BranchIds", dtBranchIds);
4566
4567 DataTable dtCompanyIds = Helper.FillDataTable(CompanyIds);
4568 Param[10] = new SqlParameter("@CompanyIds", dtCompanyIds);
4569 }
4570 Param[2] = new SqlParameter("@FromDate", fromdate.ToString("dd/MMM/yyyy"));
4571 Param[3] = new SqlParameter("@ToDate", todate.ToString("dd/MMM/yyyy"));
4572 if (!string.IsNullOrWhiteSpace(brokers))
4573 Param[4] = new SqlParameter("@BrokerId", brokers);
4574
4575 Param[5] = new SqlParameter("@Type", type);
4576
4577
4578 ds = SqlHelper.ExecuteDataset(CommandType.StoredProcedure, "GetAdvisorReport_Updated", Param);
4579 }
4580 catch (Exception ex)
4581 {
4582 Helper.ErrorLog(ex.InnerException, "Q_Reports", "GetAdvisorReportByIds", ex.Message);
4583 }
4584 return ds;
4585 }
4586
4587 #endregion [Adviser Report]
4588
4589 #region [Mortgage Written Report]
4590
4591 /// <summary>
4592 /// Get mortgage case written report by ids.
4593 /// </summary>
4594 /// <param name="NegotiatorIds"></param>
4595 /// <param name="BranchIds"></param>
4596 /// <param name="CompanyIds"></param>
4597 /// <param name="type"></param>
4598 /// <param name="fromdate"></param>
4599 /// <param name="todate"></param>
4600 /// <param name="userid"></param>
4601 /// <param name="brokerId"></param>
4602 /// <param name="Negotiator"></param>
4603 /// <param name="brokers"></param>
4604 /// <param name="Company"></param>
4605 /// <param name="Branches"></param>
4606 /// <param name="productTypeID"></param>
4607 /// <returns></returns>
4608 public DataSet GetMortgageCaseWrittenReportByIds(List<int> NegotiatorIds, List<int> BranchIds, List<int> CompanyIds, string type, DateTime fromdate, DateTime todate, int userid, int brokerId = 0, string Negotiator = "", string brokers = "", string Company = "", string Branches = "", int productTypeID = 0)
4609 {
4610 DataSet ds = new DataSet();
4611 try
4612 {
4613 SqlParameter[] Param = new SqlParameter[12];
4614 Param[0] = new SqlParameter("@CurrentUserId", userid);
4615 Param[1] = new SqlParameter("@FromDate", fromdate.ToString("dd/MMM/yyyy"));
4616 Param[2] = new SqlParameter("@ToDate", todate.ToString("dd/MMM/yyyy"));
4617 if (!string.IsNullOrEmpty(Negotiator))
4618 {
4619 Param[3] = new SqlParameter("@Negotiator", Negotiator.Trim());
4620 Param[4] = new SqlParameter("@Company", Company.Trim());
4621 Param[5] = new SqlParameter("@Branches", Branches.Trim());
4622
4623 //Convert Negotiator, Branch and Company Ids list into datatable and pass them into sql procedure parameter value. -20151021
4624 DataTable dtNegotiatorIds = Helper.FillDataTable(NegotiatorIds);
4625 Param[9] = new SqlParameter("@NegotiatorIds", dtNegotiatorIds);
4626
4627 DataTable dtBranchIds = Helper.FillDataTable(BranchIds);
4628 Param[10] = new SqlParameter("@BranchIds", dtBranchIds);
4629
4630 DataTable dtCompanyIds = Helper.FillDataTable(CompanyIds);
4631 Param[11] = new SqlParameter("@CompanyIds", dtCompanyIds);
4632 }
4633 if (!string.IsNullOrWhiteSpace(brokers))
4634 {
4635 Param[6] = new SqlParameter("@BrokerId", brokers);
4636 }
4637 if (!string.IsNullOrWhiteSpace(type))
4638 {
4639 Param[7] = new SqlParameter("@MortgageType", type);
4640 }
4641
4642 Param[8] = new SqlParameter("@productTypeID", productTypeID);
4643
4644 ds = SqlHelper.ExecuteDataset(CommandType.StoredProcedure, "GetMortgageCaseWritten_Update", Param);
4645 }
4646 catch (Exception ex)
4647 {
4648 Helper.ErrorLog(ex.InnerException, "Q_Reports", "GetMortgageCaseWrittenReportByIds", ex.Message);
4649 }
4650 return ds;
4651 }
4652
4653 #endregion [Mortgage Written Report]
4654
4655 #region [Insurance Case Written Report]
4656
4657 /// <summary>
4658 /// method for InsuranceCaseWritten
4659 /// created on : 03/11/2014
4660 ///modified on 23-12-2014
4661 /// </summary>
4662 /// <param name="type"></param>
4663 /// <param name="fromdate"></param>
4664 /// <param name="todate"></param>
4665 /// <param name="userid"></param>
4666 /// <param name="brokerId"></param>
4667 /// <param name="Negotiator"></param>
4668 /// <param name="brokers"></param>
4669 /// <param name="Company"></param>
4670 /// <param name="Branches"></param>
4671 /// <param name="productTypeID"></param>
4672 /// <returns></returns>
4673 public DataSet GetInsuranceCaseWrittenReportByIds(List<int> NegotiatorIds, List<int> BranchIds, List<int> CompanyIds, string type, DateTime fromdate, DateTime todate, int userid, int brokerId = 0, string Negotiator = "", string brokers = "", string Company = "", string Branches = "", int productTypeID = 0)
4674 {
4675 DataSet ds = new DataSet();
4676 try
4677 {
4678 SqlParameter[] Param = new SqlParameter[12];
4679 Param[0] = new SqlParameter("@CurrentUserId", userid);
4680 Param[1] = new SqlParameter("@FromDate", fromdate.ToString("dd/MMM/yyyy"));
4681 Param[2] = new SqlParameter("@ToDate", todate.ToString("dd/MMM/yyyy"));
4682 if (!string.IsNullOrEmpty(Negotiator))
4683 {
4684 Param[3] = new SqlParameter("@Negotiator", Negotiator.Trim());
4685 Param[4] = new SqlParameter("@Company", Company.Trim());
4686 Param[5] = new SqlParameter("@Branches", Branches.Trim());
4687
4688 //Convert Negotiator, Branch and Company Ids list into datatable and pass them into sql procedure parameter value. -20151021
4689 DataTable dtNegotiatorIds = Helper.FillDataTable(NegotiatorIds);
4690 Param[9] = new SqlParameter("@NegotiatorIds", dtNegotiatorIds);
4691
4692 DataTable dtBranchIds = Helper.FillDataTable(BranchIds);
4693 Param[10] = new SqlParameter("@BranchIds", dtBranchIds);
4694
4695 DataTable dtCompanyIds = Helper.FillDataTable(CompanyIds);
4696 Param[11] = new SqlParameter("@CompanyIds", dtCompanyIds);
4697 }
4698 if (!string.IsNullOrWhiteSpace(brokers))
4699 {
4700 Param[6] = new SqlParameter("@BrokerId", brokers);
4701 }
4702 if (!string.IsNullOrWhiteSpace(type))
4703 {
4704 Param[7] = new SqlParameter("@InsuranceType", type);
4705 }
4706 Param[8] = new SqlParameter("@productTypeID", productTypeID);
4707
4708 ds = SqlHelper.ExecuteDataset(CommandType.StoredProcedure, "GetInsuranceCaseWritten_Update", Param);
4709 }
4710 catch (Exception ex)
4711 {
4712 Helper.ErrorLog(ex.InnerException, "Q_Reports", "GetInsuranceCaseWrittenReportByIds", ex.Message);
4713 }
4714 return ds;
4715 }
4716
4717 #endregion [Insurance Case Written Report]
4718
4719 #region [Mortgage Completed Report]
4720
4721 /// <summary>
4722 /// Get mortgage completed report by ids.
4723 /// </summary>
4724 /// <param name="NegotiatorIds"></param>
4725 /// <param name="BranchIds"></param>
4726 /// <param name="CompanyIds"></param>
4727 /// <param name="type"></param>
4728 /// <param name="fromdate"></param>
4729 /// <param name="todate"></param>
4730 /// <param name="userid"></param>
4731 /// <param name="brokerId"></param>
4732 /// <param name="Negotiator"></param>
4733 /// <param name="brokers"></param>
4734 /// <param name="Company"></param>
4735 /// <param name="Branches"></param>
4736 /// <param name="productTypeID"></param>
4737 /// <returns></returns>
4738 public DataSet GetMortgageCompletedReportByIds(List<int> NegotiatorIds, List<int> BranchIds, List<int> CompanyIds, string type, DateTime fromdate, DateTime todate, int userid, int brokerId = 0, string Negotiator = "", string brokers = "", string Company = "", string Branches = "", int productTypeID = 0)
4739 {
4740 DataSet ds = new DataSet();
4741 try
4742 {
4743 SqlParameter[] Param = new SqlParameter[12];
4744 Param[0] = new SqlParameter("@CurrentUserId", userid);
4745 Param[1] = new SqlParameter("@FromDate", fromdate.ToString("dd/MMM/yyyy"));
4746 Param[2] = new SqlParameter("@ToDate", todate.ToString("dd/MMM/yyyy"));
4747 if (!string.IsNullOrEmpty(Negotiator))
4748 {
4749 Param[3] = new SqlParameter("@Negotiator", Negotiator.Trim());
4750 Param[4] = new SqlParameter("@Company", Company.Trim());
4751 Param[5] = new SqlParameter("@Branches", Branches.Trim());
4752
4753 //Convert Negotiator, Branch and Company Ids list into datatable and pass them into sql procedure parameter value. -20151021
4754 DataTable dtNegotiatorIds = Helper.FillDataTable(NegotiatorIds);
4755 Param[9] = new SqlParameter("@NegotiatorIds", dtNegotiatorIds);
4756
4757 DataTable dtBranchIds = Helper.FillDataTable(BranchIds);
4758 Param[10] = new SqlParameter("@BranchIds", dtBranchIds);
4759
4760 DataTable dtCompanyIds = Helper.FillDataTable(CompanyIds);
4761 Param[11] = new SqlParameter("@CompanyIds", dtCompanyIds);
4762 }
4763 if (!string.IsNullOrWhiteSpace(brokers))
4764 {
4765 Param[6] = new SqlParameter("@BrokerId", brokers);
4766 }
4767 if (!string.IsNullOrWhiteSpace(type))
4768 {
4769 Param[7] = new SqlParameter("@MortgageType", type);
4770 }
4771
4772 Param[8] = new SqlParameter("@productTypeID", productTypeID);
4773
4774 ds = SqlHelper.ExecuteDataset(CommandType.StoredProcedure, "GetMortgageCompletedReport_Update", Param);
4775 }
4776 catch (Exception ex)
4777 {
4778 Helper.ErrorLog(ex.InnerException, "Q_Reports", "GetMortgageCompletedReportByIds", ex.Message);
4779 }
4780 return ds;
4781 }
4782
4783 #endregion [Mortgage Completed Report]
4784
4785 #region [Insurance Completed Report]
4786
4787 /// <summary>
4788 /// Get insurance completed report by ids.
4789 /// </summary>
4790 /// <param name="NegotiatorIds"></param>
4791 /// <param name="BranchIds"></param>
4792 /// <param name="CompanyIds"></param>
4793 /// <param name="type"></param>
4794 /// <param name="fromdate"></param>
4795 /// <param name="todate"></param>
4796 /// <param name="userid"></param>
4797 /// <param name="brokerId"></param>
4798 /// <param name="Negotiator"></param>
4799 /// <param name="brokers"></param>
4800 /// <param name="Company"></param>
4801 /// <param name="Branches"></param>
4802 /// <param name="productTypeID"></param>
4803 /// <returns></returns>
4804 public DataSet GetInsuranceCompletedReportByIds(List<int> NegotiatorIds, List<int> BranchIds, List<int> CompanyIds, string type, DateTime fromdate, DateTime todate, int userid, int brokerId = 0, string Negotiator = "", string brokers = "", string Company = "", string Branches = "", int productTypeID = 0)
4805 {
4806 DataSet ds = new DataSet();
4807 try
4808 {
4809 SqlParameter[] Param = new SqlParameter[12];
4810 Param[0] = new SqlParameter("@CurrentUserId", userid);
4811 Param[1] = new SqlParameter("@FromDate", fromdate.ToString("dd/MMM/yyyy"));
4812 Param[2] = new SqlParameter("@ToDate", todate.ToString("dd/MMM/yyyy"));
4813 if (!string.IsNullOrEmpty(Negotiator))
4814 {
4815 Param[3] = new SqlParameter("@Negotiator", Negotiator.Trim());
4816 Param[4] = new SqlParameter("@Company", Company.Trim());
4817 Param[5] = new SqlParameter("@Branches", Branches.Trim());
4818
4819 //Convert Negotiator, Branch and Company Ids list into datatable and pass them into sql procedure parameter value. -20151021
4820 DataTable dtNegotiatorIds = Helper.FillDataTable(NegotiatorIds);
4821 Param[9] = new SqlParameter("@NegotiatorIds", dtNegotiatorIds);
4822
4823 DataTable dtBranchIds = Helper.FillDataTable(BranchIds);
4824 Param[10] = new SqlParameter("@BranchIds", dtBranchIds);
4825
4826 DataTable dtCompanyIds = Helper.FillDataTable(CompanyIds);
4827 Param[11] = new SqlParameter("@CompanyIds", dtCompanyIds);
4828 }
4829 if (!string.IsNullOrWhiteSpace(brokers))
4830 {
4831 Param[6] = new SqlParameter("@BrokerId", brokers);
4832 }
4833 if (!string.IsNullOrWhiteSpace(type))
4834 {
4835 Param[7] = new SqlParameter("@InsuranceType", type);
4836 }
4837 Param[8] = new SqlParameter("@productTypeID", productTypeID);
4838
4839 ds = SqlHelper.ExecuteDataset(CommandType.StoredProcedure, "GetInsuranceCompletedReport_Update", Param);
4840 }
4841 catch (Exception ex)
4842 {
4843 Helper.ErrorLog(ex.InnerException, "Q_Reports", "GetInsuranceCompletedReportByIds", ex.Message);
4844 }
4845 return ds;
4846 }
4847 #endregion [Insurance Completed Report]
4848
4849 #region [Pipeline Review Report]
4850
4851 /// <summary>
4852 /// Get pipeline review report by ids.
4853 /// </summary>
4854 /// <param name="NegotiatorIds"></param>
4855 /// <param name="BranchIds"></param>
4856 /// <param name="CompanyIds"></param>
4857 /// <param name="type"></param>
4858 /// <param name="fromdate"></param>
4859 /// <param name="todate"></param>
4860 /// <param name="userid"></param>
4861 /// <param name="brokerId"></param>
4862 /// <param name="Negotiator"></param>
4863 /// <param name="brokers"></param>
4864 /// <param name="Company"></param>
4865 /// <param name="Branches"></param>
4866 /// <returns></returns>
4867 public DataSet GetPipelineReviewReportByIds(List<int> NegotiatorIds, List<int> BranchIds, List<int> CompanyIds, string type, DateTime fromdate, DateTime todate, int userid, int brokerId = 0, string Negotiator = "", string brokers = "", string Company = "", string Branches = "")
4868 {
4869 DataSet ds = new DataSet();
4870 try
4871 {
4872 SqlParameter[] Param = new SqlParameter[11];
4873 Param[0] = new SqlParameter("@CurrentUserId", userid);
4874 Param[1] = new SqlParameter("@FromDate", fromdate.ToString("dd/MMM/yyyy"));
4875 Param[2] = new SqlParameter("@ToDate", todate.ToString("dd/MMM/yyyy"));
4876 if (!string.IsNullOrEmpty(Negotiator))
4877 {
4878 Param[3] = new SqlParameter("@Negotiator", Negotiator.Trim());
4879 Param[4] = new SqlParameter("@Company", Company.Trim());
4880 Param[5] = new SqlParameter("@Branches", Branches.Trim());
4881
4882 //Convert Negotiator, Branch and Company Ids list into datatable and pass them into sql procedure parameter value. -20151021
4883 DataTable dtNegotiatorIds = Helper.FillDataTable(NegotiatorIds);
4884 Param[8] = new SqlParameter("@NegotiatorIds", dtNegotiatorIds);
4885
4886 DataTable dtBranchIds = Helper.FillDataTable(BranchIds);
4887 Param[9] = new SqlParameter("@BranchIds", dtBranchIds);
4888
4889 DataTable dtCompanyIds = Helper.FillDataTable(CompanyIds);
4890 Param[10] = new SqlParameter("@CompanyIds", dtCompanyIds);
4891 }
4892 if (!string.IsNullOrWhiteSpace(brokers))
4893 {
4894 Param[6] = new SqlParameter("@BrokerId", brokers);
4895 }
4896 if (!string.IsNullOrWhiteSpace(type))
4897 {
4898 Param[7] = new SqlParameter("@MortgageType", type);
4899 }
4900
4901 ds = SqlHelper.ExecuteDataset(CommandType.StoredProcedure, "GetMortgageCaseWritten_Update", Param);
4902 }
4903 catch (Exception ex)
4904 {
4905 Helper.ErrorLog(ex.InnerException, "Q_Reports", "GetPipelineReviewReportByIds", ex.Message);
4906 }
4907 return ds;
4908 }
4909
4910 #endregion [Pipeline Review Report]
4911
4912 #region [WOCC Report]
4913
4914 /// <summary>
4915 /// Get WOCC report by ids.
4916 /// </summary>
4917 /// <param name="NegotiatorIds"></param>
4918 /// <param name="BranchIds"></param>
4919 /// <param name="CompanyIds"></param>
4920 /// <param name="type"></param>
4921 /// <param name="fromdate"></param>
4922 /// <param name="todate"></param>
4923 /// <param name="userid"></param>
4924 /// <param name="brokerId"></param>
4925 /// <param name="Negotiator"></param>
4926 /// <param name="brokers"></param>
4927 /// <param name="Company"></param>
4928 /// <param name="Branches"></param>
4929 /// <param name="FinType"></param>
4930 /// <returns></returns>
4931 public DataSet GetNewFinancialInformationReportByIds(List<int> NegotiatorIds, List<int> BranchIds, List<int> CompanyIds, string type, DateTime fromdate, DateTime todate, int userid, int brokerId = 0, string Negotiator = "", string brokers = "", string Company = "", string Branches = "", int FinType = 0)
4932 {
4933 DataSet ds = new DataSet();
4934 try
4935 {
4936 SqlParameter[] Param = new SqlParameter[11];
4937 Param[0] = new SqlParameter("@CurrentUserId", userid);
4938 Param[1] = new SqlParameter("@FromDate", fromdate.ToString("dd/MMM/yyyy"));
4939 Param[2] = new SqlParameter("@ToDate", todate.ToString("dd/MMM/yyyy"));
4940 if (!string.IsNullOrEmpty(Negotiator))
4941 {
4942 Param[3] = new SqlParameter("@Negotiator", Negotiator.Trim());
4943 Param[4] = new SqlParameter("@Company", Company.Trim());
4944 Param[5] = new SqlParameter("@Branches", Branches.Trim());
4945
4946 //Convert Negotiator, Branch and Company Ids list into datatable and pass them into sql procedure parameter value. -20151021
4947 DataTable dtNegotiatorIds = Helper.FillDataTable(NegotiatorIds);
4948 Param[8] = new SqlParameter("@NegotiatorIds", dtNegotiatorIds);
4949
4950 DataTable dtBranchIds = Helper.FillDataTable(BranchIds);
4951 Param[9] = new SqlParameter("@BranchIds", dtBranchIds);
4952
4953 DataTable dtCompanyIds = Helper.FillDataTable(CompanyIds);
4954 Param[10] = new SqlParameter("@CompanyIds", dtCompanyIds);
4955 }
4956 if (!string.IsNullOrWhiteSpace(brokers))
4957 {
4958 Param[6] = new SqlParameter("@BrokerId", brokers);
4959 }
4960 if (!string.IsNullOrWhiteSpace(type))
4961 {
4962 Param[7] = new SqlParameter("@InsuranceType", type);
4963 }
4964 Param[7] = new SqlParameter("@FinanceType", FinType);
4965
4966 ds = SqlHelper.ExecuteDataset(CommandType.StoredProcedure, "GetWOCCReport_Update", Param);
4967 }
4968 catch (Exception ex)
4969 {
4970 Helper.ErrorLog(ex.InnerException, "Q_Report", "GetNewFinancialInformationReportByIds", ex.Message);
4971 }
4972 return ds;
4973 }
4974
4975 #endregion [WOCC Report]
4976
4977 #region [Total written Report]
4978 /// <summary>
4979 /// Get total written report by ids.
4980 /// </summary>
4981 /// <param name="type"></param>
4982 /// <param name="fromdate"></param>
4983 /// <param name="todate"></param>
4984 /// <param name="userid"></param>
4985 /// <param name="brokerId"></param>
4986 /// <param name="Negotiator"></param>
4987 /// <param name="brokers"></param>
4988 /// <param name="Company"></param>
4989 /// <param name="Branches"></param>
4990 /// <param name="productTypeID"></param>
4991 /// <returns></returns>
4992 public DataSet GetTotalWrittenReportByIds(List<int> NegotiatorIds, List<int> BranchIds, List<int> CompanyIds, string type, DateTime fromdate, DateTime todate, int userid, int brokerId = 0, string Negotiator = "", string brokers = "", string Company = "", string Branches = "", int productTypeID = 0)
4993 {
4994 DataSet ds = new DataSet();
4995 try
4996 {
4997 SqlParameter[] Param = new SqlParameter[10];
4998 Param[0] = new SqlParameter("@CurrentUserId", userid);
4999 Param[1] = new SqlParameter("@FromDate", fromdate.ToString("dd/MMM/yyyy"));
5000 Param[2] = new SqlParameter("@ToDate", todate.ToString("dd/MMM/yyyy"));
5001 if (!string.IsNullOrEmpty(Negotiator))
5002 {
5003 Param[3] = new SqlParameter("@Negotiator", Negotiator.Trim());
5004 Param[4] = new SqlParameter("@Company", Company.Trim());
5005 Param[5] = new SqlParameter("@Branches", Branches.Trim());
5006
5007 //Convert Negotiator, Branch and Company Ids list into datatable and pass them into sql procedure parameter value. -20151021
5008 DataTable dtNegotiatorIds = Helper.FillDataTable(NegotiatorIds);
5009 Param[7] = new SqlParameter("@NegotiatorIds", dtNegotiatorIds);
5010
5011 DataTable dtBranchIds = Helper.FillDataTable(BranchIds);
5012 Param[8] = new SqlParameter("@BranchIds", dtBranchIds);
5013
5014 DataTable dtCompanyIds = Helper.FillDataTable(CompanyIds);
5015 Param[9] = new SqlParameter("@CompanyIds", dtCompanyIds);
5016 }
5017 if (!string.IsNullOrWhiteSpace(brokers))
5018 {
5019 Param[6] = new SqlParameter("@BrokerId", brokers);
5020 }
5021
5022 ds = SqlHelper.ExecuteDataset(CommandType.StoredProcedure, "GetTotalWritten_Update", Param);
5023 }
5024 catch (Exception ex)
5025 {
5026 Helper.ErrorLog(ex.InnerException, "Q_Reports", "GetTotalWrittenReportByIds", ex.Message);
5027 }
5028 return ds;
5029 }
5030
5031 #endregion [Total written Report]
5032
5033 #region [Insurance Referral report]
5034 /// <summary>
5035 /// Get insurance referral results by ids.
5036 /// </summary>
5037 /// <param name="NegotiatorIds"></param>
5038 /// <param name="BranchIds"></param>
5039 /// <param name="CompanyIds"></param>
5040 /// <param name="fromdate"></param>
5041 /// <param name="todate"></param>
5042 /// <param name="userid"></param>
5043 /// <param name="brokerId"></param>
5044 /// <param name="Negotiator"></param>
5045 /// <param name="brokers"></param>
5046 /// <param name="Company"></param>
5047 /// <param name="Branches"></param>
5048 /// <param name="ProductTypeId"></param>
5049 /// <returns></returns>
5050 public DataSet GetInsuranceReferralResultByIds(List<int> NegotiatorIds, List<int> BranchIds, List<int> CompanyIds, DateTime fromdate, DateTime todate, int userid, int brokerId = 0, string Negotiator = "", string brokers = "", string Company = "", string Branches = "", int ProductTypeId = 0)
5051 {
5052
5053 List<Insurancereferral> negotiationlist = new List<Models.Insurancereferral>();
5054 DataSet ds = new DataSet();
5055 try
5056 {
5057 SqlParameter[] Param = new SqlParameter[11];
5058 Param[0] = new SqlParameter("@CurrentUserId", userid);
5059
5060 Param[1] = new SqlParameter("@Negotiator", (string.IsNullOrEmpty(Negotiator) ? null : Negotiator.Trim()));
5061 Param[2] = new SqlParameter("@Company", (string.IsNullOrEmpty(Company) ? null : Company.Trim()));
5062 Param[3] = new SqlParameter("@Branches", (string.IsNullOrEmpty(Branches) ? null : Branches.Trim()));
5063 Param[4] = new SqlParameter("@BrokerId", (string.IsNullOrEmpty(brokers) ? null : brokers));
5064 Param[5] = new SqlParameter("@FromDate", fromdate.ToString("dd/MMM/yyyy"));
5065 Param[6] = new SqlParameter("@ToDate", todate.ToString("dd/MMM/yyyy"));
5066 Param[7] = new SqlParameter("@ProductTypeId", ProductTypeId);
5067
5068 //Convert Negotiator, Branch and Company Ids list into datatable and pass them into sql procedure parameter value. -20151021
5069 DataTable dtNegotiatorIds = Helper.FillDataTable(NegotiatorIds);
5070 Param[8] = new SqlParameter("@NegotiatorIds", dtNegotiatorIds);
5071
5072 DataTable dtBranchIds = Helper.FillDataTable(BranchIds);
5073 Param[9] = new SqlParameter("@BranchIds", dtBranchIds);
5074
5075 DataTable dtCompanyIds = Helper.FillDataTable(CompanyIds);
5076 Param[10] = new SqlParameter("@CompanyIds", dtCompanyIds);
5077
5078 ds = SqlHelper.ExecuteDataset("GetInsuranceReferralReport_Update", Param);
5079 }
5080 catch (Exception ex)
5081 {
5082 Helper.ErrorLog(ex.InnerException, "Q_Reports", "GetInsuranceReferralResultByIds", ex.Message);
5083 }
5084 return ds;
5085 }
5086 #endregion [Insurance Referral report]
5087
5088 #region[Business report]
5089
5090 /// <summary>
5091 /// Get business report by ids.
5092 /// </summary>
5093 /// <param name="fromdate"></param>
5094 /// <param name="todate"></param>
5095 /// <param name="type"></param>
5096 /// <param name="userid"></param>
5097 /// <param name="brokerId"></param>
5098 /// <param name="Negotiator"></param>
5099 /// <param name="brokers"></param>
5100 /// <param name="Company"></param>
5101 /// <param name="Branches"></param>
5102 /// <param name="productTypeID"></param>
5103 /// <returns></returns>
5104 public DataSet GetBusinessReportByIds(List<int> NegotiatorIds, List<int> BranchIds, List<int> CompanyIds, DateTime fromdate, DateTime todate, string type, int userid, int brokerId = 0, string Negotiator = "", string brokers = "", string Company = "", string Branches = "", int productTypeID = 0)
5105 {
5106 DataSet ds = new DataSet();
5107 try
5108 {
5109 SqlParameter[] Param = new SqlParameter[11];
5110 Param[0] = new SqlParameter("@CurrentUserId", userid);
5111 Param[1] = new SqlParameter("@FromDate", fromdate.ToString("dd/MMM/yyyy"));
5112 Param[2] = new SqlParameter("@ToDate", todate.ToString("dd/MMM/yyyy"));
5113 if (!string.IsNullOrEmpty(Negotiator))
5114 {
5115 Param[3] = new SqlParameter("@Negotiator", Negotiator.Trim());
5116 Param[4] = new SqlParameter("@Company", Company.Trim());
5117 Param[5] = new SqlParameter("@Branches", Branches.Trim());
5118
5119 //Convert Negotiator, Branch and Company Ids list into datatable and pass them into sql procedure parameter value. -20151021
5120 DataTable dtNegotiatorIds = Helper.FillDataTable(NegotiatorIds);
5121 Param[8] = new SqlParameter("@NegotiatorIds", dtNegotiatorIds);
5122
5123 DataTable dtBranchIds = Helper.FillDataTable(BranchIds);
5124 Param[9] = new SqlParameter("@BranchIds", dtBranchIds);
5125
5126 DataTable dtCompanyIds = Helper.FillDataTable(CompanyIds);
5127 Param[10] = new SqlParameter("@CompanyIds", dtCompanyIds);
5128 }
5129 if (!string.IsNullOrWhiteSpace(brokers))
5130 {
5131 Param[6] = new SqlParameter("@BrokerId", brokers);
5132 }
5133
5134 Param[7] = new SqlParameter("@productTypeID", productTypeID);
5135
5136 ds = SqlHelper.ExecuteDataset(CommandType.StoredProcedure, "GetBusinessReport_Update", Param);
5137 }
5138 catch (Exception ex)
5139 {
5140 Helper.ErrorLog(ex.InnerException, "Q_Reports", "GetBusinessReportByIds", ex.Message);
5141 }
5142 return ds;
5143 }
5144 #endregion
5145
5146 #region[Most Valuable referrer report]
5147
5148 /// <summary>
5149 /// Get most valuable report by ids.
5150 /// </summary>
5151 /// <param name="type"></param>
5152 /// <param name="userid"></param>
5153 /// <param name="brokerId"></param>
5154 /// <param name="Negotiator"></param>
5155 /// <param name="brokers"></param>
5156 /// <param name="Company"></param>
5157 /// <param name="Branches"></param>
5158 /// <param name="productTypeID"></param>
5159 /// <returns></returns>
5160 public DataSet GetMostValuableReportByIds(List<int> NegotiatorIds, List<int> BranchIds, List<int> CompanyIds, string type, int userid, int brokerId = 0, string Negotiator = "", string brokers = "", string Company = "", string Branches = "", int productTypeID = 0)
5161 {
5162 DataSet ds = new DataSet();
5163 try
5164 {
5165 SqlParameter[] Param = new SqlParameter[8];
5166 Param[0] = new SqlParameter("@CurrentUserId", userid);
5167
5168 if (!string.IsNullOrEmpty(Negotiator))
5169 {
5170 Param[1] = new SqlParameter("@Negotiator", Negotiator.Trim());
5171 Param[2] = new SqlParameter("@Company", Company.Trim());
5172 Param[3] = new SqlParameter("@Branches", Branches.Trim());
5173
5174 //Convert Negotiator, Branch and Company Ids list into datatable and pass them into sql procedure parameter value. -20151021
5175 DataTable dtNegotiatorIds = Helper.FillDataTable(NegotiatorIds);
5176 Param[5] = new SqlParameter("@NegotiatorIds", dtNegotiatorIds);
5177
5178 DataTable dtBranchIds = Helper.FillDataTable(BranchIds);
5179 Param[6] = new SqlParameter("@BranchIds", dtBranchIds);
5180
5181 DataTable dtCompanyIds = Helper.FillDataTable(CompanyIds);
5182 Param[7] = new SqlParameter("@CompanyIds", dtCompanyIds);
5183 }
5184 if (!string.IsNullOrWhiteSpace(brokers))
5185 {
5186 Param[4] = new SqlParameter("@BrokerId", brokers);
5187 }
5188
5189
5190 ds = SqlHelper.ExecuteDataset(CommandType.StoredProcedure, "GetMostValuableReferrersreport_Update", Param);
5191 }
5192 catch (Exception ex)
5193 {
5194 Helper.ErrorLog(ex.InnerException, "Q_Reports", "GetBusinessReportByIds", ex.Message);
5195 }
5196 return ds;
5197 }
5198 #endregion
5199
5200 #region [Negotiator Weekly Report]
5201
5202 /// <summary>
5203 /// Getting negotiator weekly report
5204 /// </summary>
5205 /// <param name="fromdate">From date</param>
5206 /// <param name="todate">To date</param>
5207 /// <param name="userid">User Id</param>
5208 /// <param name="brokerId">Broker Id</param>
5209 /// <param name="Negotiator">Negotiator</param>
5210 /// <param name="brokers">Brokers</param>
5211 /// <param name="Company">Companies</param>
5212 /// <param name="Branches">Branches</param>
5213 /// <param name="productTypeID">Product Type</param>
5214 /// <returns></returns>
5215 public DataSet GetNegotiatorweeklyByIds(List<int> NegotiatorIds, List<int> BranchIds, List<int> CompanyIds, DateTime fromdate, DateTime todate, int userid, int brokerId = 0, string Negotiator = "", string brokers = "", string Company = "", string Branches = "", int productTypeID = 0)
5216 {
5217 DataSet ds;
5218 try
5219 {
5220 List<Negotiation> negotiationlist = new List<Models.Negotiation>();
5221 SqlParameter[] Param = new SqlParameter[11];
5222 Param[0] = new SqlParameter("@CurrentUserId", userid);
5223 Param[1] = new SqlParameter("@Negotiator", (string.IsNullOrEmpty(Negotiator) ? null : Negotiator.Trim()));
5224 Param[2] = new SqlParameter("@Company", (string.IsNullOrEmpty(Company) ? null : Company.Trim()));
5225 Param[3] = new SqlParameter("@Branches", (string.IsNullOrEmpty(Branches) ? null : Branches.Trim()));
5226 Param[4] = new SqlParameter("@BrokerId", (string.IsNullOrEmpty(brokers) ? null : brokers));
5227 Param[5] = new SqlParameter("@FromDate", fromdate.ToString("dd/MMM/yyyy"));
5228 Param[6] = new SqlParameter("@ToDate", todate.ToString("dd/MMM/yyyy"));
5229 Param[7] = new SqlParameter("@productTypeID", productTypeID);
5230
5231 //Convert Negotiator, Branch and Company Ids list into datatable and pass them into sql procedure parameter value. -20151021
5232 DataTable dtNegotiatorIds = Helper.FillDataTable(NegotiatorIds);
5233 Param[8] = new SqlParameter("@NegotiatorIds", dtNegotiatorIds);
5234
5235 DataTable dtBranchIds = Helper.FillDataTable(BranchIds);
5236 Param[9] = new SqlParameter("@BranchIds", dtBranchIds);
5237
5238 DataTable dtCompanyIds = Helper.FillDataTable(CompanyIds);
5239 Param[10] = new SqlParameter("@CompanyIds", dtCompanyIds);
5240
5241 ds = SqlHelper.ExecuteDataset("GetNegotiatorReportWeekly_Update", Param);
5242 }
5243 catch (Exception ex)
5244 {
5245 Helper.ErrorLog(ex.InnerException, "Q_Report", "GetNegotiatorweekly_Update");
5246 ds = new DataSet();
5247
5248 }
5249 return ds;
5250 }
5251
5252 #endregion [Negotiator Weekly Report]
5253
5254 #region [Negotiator Result]
5255
5256 /// <summary>
5257 /// Getting dataset from the database for Negotiator Report
5258 /// </summary>
5259 /// <param name="fromdate">From Date</param>
5260 /// <param name="todate">To Date</param>
5261 /// <param name="userid">User Id</param>
5262 /// <param name="pageNo">Page no</param>
5263 /// <param name="pageSize">Page size</param>
5264 /// <param name="brokerId">Broker Id</param>
5265 /// <param name="Negotiator">Negotiator</param>
5266 /// <param name="brokers">Brokers</param>
5267 /// <param name="Company">Companies</param>
5268 /// <param name="Branches">Branches</param>
5269 /// <param name="productTypeID">Product type</param>
5270 /// <returns></returns>
5271 public DataSet GetNegotiatorResultByIds(List<int> NegotiatorIds, List<int> BranchIds, List<int> CompanyIds, DateTime fromdate, DateTime todate, int userid, int pageNo, int pageSize, int brokerId = 0, string Negotiator = "", string brokers = "", string Company = "", string Branches = "", int productTypeID = 0)
5272 {
5273 DataSet ds;
5274 List<Negotiation> negotiationlist = new List<Models.Negotiation>();
5275 try
5276 {
5277 SqlParameter[] Param = new SqlParameter[13];
5278 Param[0] = new SqlParameter("@CurrentUserId", userid);
5279 Param[1] = new SqlParameter("@Negotiator", (string.IsNullOrEmpty(Negotiator) ? null : Negotiator.Trim()));
5280 Param[2] = new SqlParameter("@Company", (string.IsNullOrEmpty(Company) ? null : Company.Trim()));
5281 Param[3] = new SqlParameter("@Branches", (string.IsNullOrEmpty(Branches) ? null : Branches.Trim()));
5282 Param[4] = new SqlParameter("@BrokerId", (string.IsNullOrEmpty(brokers) ? null : brokers));
5283 Param[5] = new SqlParameter("@FromDate", fromdate.ToString("dd/MMM/yyyy"));
5284 Param[6] = new SqlParameter("@ToDate", todate.ToString("dd/MMM/yyyy"));
5285 Param[7] = new SqlParameter("@PageNo", pageNo);
5286 Param[8] = new SqlParameter("@PageSize", pageSize);
5287 Param[9] = new SqlParameter("@productTypeID", productTypeID);
5288
5289 //Convert Negotiator, Branch and Company Ids list into datatable and pass them into sql procedure parameter value. -20151021
5290 DataTable dtNegotiatorIds = Helper.FillDataTable(NegotiatorIds);
5291 Param[10] = new SqlParameter("@NegotiatorIds", dtNegotiatorIds);
5292
5293 DataTable dtBranchIds = Helper.FillDataTable(BranchIds);
5294 Param[11] = new SqlParameter("@BranchIds", dtBranchIds);
5295
5296 DataTable dtCompanyIds = Helper.FillDataTable(CompanyIds);
5297 Param[12] = new SqlParameter("@CompanyIds", dtCompanyIds);
5298
5299 ds = SqlHelper.ExecuteDataset("GetNegotiatorReport_Update", Param);
5300 return ds;
5301 }
5302 catch (Exception ex)
5303 {
5304 Helper.ErrorLog(ex.InnerException, "Q_Report.cs", "GetNegotiatorResult", ex.Message);
5305 return ds = new DataSet();
5306 }
5307 }
5308
5309 #endregion [Negotiator Result]
5310
5311 #region [Negotiator Data Result]
5312
5313 /// <summary>
5314 /// Get negotiator data result by Ids.
5315 /// </summary>
5316 /// <param name="NegotiatorIds"></param>
5317 /// <param name="BranchIds"></param>
5318 /// <param name="CompanyIds"></param>
5319 /// <param name="fromdate"></param>
5320 /// <param name="todate"></param>
5321 /// <param name="userid"></param>
5322 /// <param name="pageNo"></param>
5323 /// <param name="pageSize"></param>
5324 /// <param name="brokerId"></param>
5325 /// <param name="Negotiator"></param>
5326 /// <param name="brokers"></param>
5327 /// <param name="Company"></param>
5328 /// <param name="Branches"></param>
5329 /// <returns></returns>
5330 public ReportsDataModel GetNegotiatorDataResultByIds(List<int> NegotiatorIds, List<int> BranchIds, List<int> CompanyIds, DateTime fromdate, DateTime todate, int userid, int pageNo, int pageSize, int brokerId = 0, string Negotiator = "", string brokers = "", string Company = "", string Branches = "")
5331 {
5332
5333 ReportsDataModel dataResult = new ReportsDataModel();
5334 dataResult.Negotiation = new List<Negotiation>();
5335 dataResult.NegotiationNotes = new List<NegotiationNotes>();
5336 SqlParameter[] Param = new SqlParameter[9];
5337 Param[0] = new SqlParameter("@CurrentUserId", userid);
5338 Param[1] = new SqlParameter("@Negotiator", (string.IsNullOrEmpty(Negotiator) ? null : Negotiator.Trim()));
5339 Param[2] = new SqlParameter("@Company", (string.IsNullOrEmpty(Company) ? null : Company.Trim()));
5340 Param[3] = new SqlParameter("@Branches", (string.IsNullOrEmpty(Branches) ? null : Branches.Trim()));
5341 Param[4] = new SqlParameter("@BrokerId", (string.IsNullOrEmpty(brokers) ? null : brokers));
5342 Param[5] = new SqlParameter("@FromDate", fromdate.ToString("dd/MMM/yyyy"));
5343 Param[6] = new SqlParameter("@ToDate", todate.ToString("dd/MMM/yyyy"));
5344 Param[7] = new SqlParameter("@PageNo", pageNo);
5345 Param[8] = new SqlParameter("@PageSize", pageSize);
5346
5347 //Convert Negotiator, Branch and Company Ids list into datatable and pass them into sql procedure parameter value. -20151021
5348 DataTable dtNegotiatorIds = Helper.FillDataTable(NegotiatorIds);
5349 Param[9] = new SqlParameter("@NegotiatorIds", dtNegotiatorIds);
5350
5351 DataTable dtBranchIds = Helper.FillDataTable(BranchIds);
5352 Param[10] = new SqlParameter("@BranchIds", dtBranchIds);
5353
5354 DataTable dtCompanyIds = Helper.FillDataTable(CompanyIds);
5355 Param[11] = new SqlParameter("@CompanyIds", dtCompanyIds);
5356
5357 SqlDataReader reader = SqlHelper.ExecuteReaderNext(CommandType.StoredProcedure, "GetNegotiatorReport_Update", Param);
5358 ctx.Database.Initialize(force: false);
5359
5360 ctx.Database.Connection.Open();
5361 dataResult.Negotiation = ((IObjectContextAdapter)ctx).ObjectContext.Translate<Negotiation>(reader).ToList();
5362 reader.NextResult();
5363 dataResult.NegotiationNotes = ((IObjectContextAdapter)ctx).ObjectContext.Translate<NegotiationNotes>(reader).ToList();
5364 ctx.Database.Connection.Close();
5365 if (!reader.IsClosed)
5366 {
5367 reader.Close();
5368 }
5369 return dataResult;
5370 }
5371
5372 #endregion [Negotiator Data Result]
5373
5374 #region [Notes Data]
5375
5376 /// <summary>
5377 /// Getting the dataset for Notes Data
5378 /// </summary>
5379 /// <param name="userId">User Id</param>
5380 /// <param name="pageNo">Page No</param>
5381 /// <param name="pageSize">Page Size</param>
5382 /// <param name="fromDate">FRom Date</param>
5383 /// <param name="toDate">To Date</param>
5384 /// <param name="negotiators">Negotiators</param>
5385 /// <param name="company">Companies</param>
5386 /// <param name="branches">branches</param>
5387 /// <param name="brokers">Brokers</param>
5388 /// <param name="productTypeID">Product type</param>
5389 /// <returns></returns>
5390 public ReadNotes GetNotesDataByIds(List<int> NegotiatorIds, List<int> BranchIds, List<int> CompanyIds, int userId, int pageNo, int pageSize, DateTime fromDate, DateTime toDate, string negotiators = "", string company = "", string branches = "", string brokers = "", int productTypeID = 0)
5391 {
5392 var reportsDN = new ReadNotes();
5393 try
5394 {
5395 DataTable notes = new DataTable();
5396 SqlParameter[] Param = new SqlParameter[13];
5397 Param[0] = new SqlParameter("@Negotiator", (string.IsNullOrEmpty(negotiators) ? null : negotiators.Trim()));
5398 Param[1] = new SqlParameter("@Company", (string.IsNullOrEmpty(company) ? null : company.Trim()));
5399 Param[2] = new SqlParameter("@Branches", (string.IsNullOrEmpty(branches) ? null : branches.Trim()));
5400 Param[3] = new SqlParameter("@BrokerIds", (string.IsNullOrEmpty(brokers) ? null : brokers));
5401 Param[4] = new SqlParameter("@FromDate", fromDate.ToString("dd/MMM/yyyy"));
5402 Param[5] = new SqlParameter("@ToDate", toDate.ToString("dd/MMM/yyyy"));
5403 Param[6] = new SqlParameter("@CurrentUserId", userId);
5404 Param[7] = new SqlParameter("@PageNo", pageNo);
5405 Param[8] = new SqlParameter("@PageSize", pageSize);
5406 Param[9] = new SqlParameter("@productTypeID", productTypeID);
5407
5408 //Convert Negotiator, Branch and Company Ids list into datatable and pass them into sql procedure parameter value. -20151021
5409 DataTable dtNegotiatorIds = Helper.FillDataTable(NegotiatorIds);
5410 Param[10] = new SqlParameter("@NegotiatorIds", dtNegotiatorIds);
5411
5412 DataTable dtBranchIds = Helper.FillDataTable(BranchIds);
5413 Param[11] = new SqlParameter("@BranchIds", dtBranchIds);
5414
5415 DataTable dtCompanyIds = Helper.FillDataTable(CompanyIds);
5416 Param[12] = new SqlParameter("@CompanyIds", dtCompanyIds);
5417
5418 SqlDataReader reader = SqlHelper.ExecuteReaderNext(CommandType.StoredProcedure, "Usp_GetNotesData_Update", Param);
5419 ctx.Database.Initialize(force: false);
5420 ctx.Database.Connection.Open();
5421 reportsDN.AdvisorNotes = ((IObjectContextAdapter)ctx).ObjectContext.Translate<NegotiationNotes>(reader).ToList();
5422 reader.NextResult();
5423 reportsDN.AgentNotes = ((IObjectContextAdapter)ctx).ObjectContext.Translate<NegotiationNotes>(reader).ToList();
5424 ctx.Database.Connection.Close();
5425 if (!reader.IsClosed)
5426 {
5427 reader.Close();
5428 }
5429 }
5430 catch (Exception ex)
5431 {
5432 Helper.ErrorLog(ex.InnerException, "Q_Report", "GetNotesDataByIds", ex.Message);
5433 }
5434 return reportsDN; ;
5435 }
5436
5437 #endregion [Notes Data]
5438
5439 #region [Negotiator Weekly Notes Created]
5440 //added on 2015-02-03
5441 /// <summary>
5442 /// Getting Weekly created notes data
5443 /// </summary>
5444 /// <param name="fromdate">From Date</param>
5445 /// <param name="todate">To Date</param>
5446 /// <param name="userid">User Id</param>
5447 /// <param name="brokerId">Broker Id</param>
5448 /// <param name="Negotiator">Negotiator</param>
5449 /// <param name="brokers">Brokers</param>
5450 /// <param name="Company">Company</param>
5451 /// <param name="Branches">Branches</param>
5452 /// <param name="productTypeID">Product Type</param>
5453 /// <returns></returns>
5454 public DataSet GetNegotiatorWeeklyCreatedNotesByIds(List<int> NegotiatorIds, List<int> BranchIds, List<int> CompanyIds, DateTime fromdate, DateTime todate, int userid, int brokerId = 0, string Negotiator = "", string brokers = "", string Company = "", string Branches = "", int productTypeID = 0)
5455 {
5456 DataSet ds;
5457 List<Negotiation> negotiationlist = new List<Models.Negotiation>();
5458 try
5459 {
5460 SqlParameter[] Param = new SqlParameter[11];
5461 Param[0] = new SqlParameter("@CurrentUserId", userid);
5462 Param[1] = new SqlParameter("@Negotiator", (string.IsNullOrEmpty(Negotiator) ? null : Negotiator.Trim()));
5463 Param[2] = new SqlParameter("@Company", (string.IsNullOrEmpty(Company) ? null : Company.Trim()));
5464 Param[3] = new SqlParameter("@Branches", (string.IsNullOrEmpty(Branches) ? null : Branches.Trim()));
5465 Param[4] = new SqlParameter("@BrokerId", (string.IsNullOrEmpty(brokers) ? null : brokers));
5466 Param[5] = new SqlParameter("@FromDate", fromdate.ToString("dd/MMM/yyyy"));
5467 Param[6] = new SqlParameter("@ToDate", todate.ToString("dd/MMM/yyyy"));
5468 Param[7] = new SqlParameter("@productTypeID", productTypeID);
5469
5470 //Convert Negotiator, Branch and Company Ids list into datatable and pass them into sql procedure parameter value. -20151021
5471 DataTable dtNegotiatorIds = Helper.FillDataTable(NegotiatorIds);
5472 Param[8] = new SqlParameter("@NegotiatorIds", dtNegotiatorIds);
5473
5474 DataTable dtBranchIds = Helper.FillDataTable(BranchIds);
5475 Param[9] = new SqlParameter("@BranchIds", dtBranchIds);
5476
5477 DataTable dtCompanyIds = Helper.FillDataTable(CompanyIds);
5478 Param[10] = new SqlParameter("@CompanyIds", dtCompanyIds);
5479
5480 ds = SqlHelper.ExecuteDataset("GetNegotiatorReportWeeklyNoteCreated_Update", Param);
5481 return ds;
5482 }
5483 catch (Exception ex)
5484 {
5485 Helper.ErrorLog(ex.InnerException, "Q_Report", "GetNegotiatorWeeklyCreatedNotesByIds", ex.Message);
5486 ds = new DataSet();
5487 return ds;
5488 }
5489 }
5490
5491 #endregion [Negotiator Weekly Notes Created]
5492
5493 #region [Negotiator Weekly Notes Updated]
5494
5495 //added on 2015-02-03
5496 /// <summary>
5497 /// Getting weekly updated notes
5498 /// </summary>
5499 /// <param name="fromdate">From Date</param>
5500 /// <param name="todate">To date</param>
5501 /// <param name="userid">User Id</param>
5502 /// <param name="brokerId">Broker Id</param>
5503 /// <param name="Negotiator">Negotiator</param>
5504 /// <param name="brokers">Brokers</param>
5505 /// <param name="Company">Company</param>
5506 /// <param name="Branches">Branches</param>
5507 /// <param name="productTypeID">Product Type</param>
5508 /// <returns></returns>
5509 public DataSet GetNegotiatorWeeklyUpdatedNotesByIds(List<int> NegotiatorIds, List<int> BranchIds, List<int> CompanyIds, DateTime fromdate, DateTime todate, int userid, int brokerId = 0, string Negotiator = "", string brokers = "", string Company = "", string Branches = "", int productTypeID = 0)
5510 {
5511 DataSet ds;
5512 List<Negotiation> negotiationlist = new List<Models.Negotiation>();
5513 try
5514 {
5515 SqlParameter[] Param = new SqlParameter[11];
5516 Param[0] = new SqlParameter("@CurrentUserId", userid);
5517 Param[1] = new SqlParameter("@Negotiator", (string.IsNullOrEmpty(Negotiator) ? null : Negotiator.Trim()));
5518 Param[2] = new SqlParameter("@Company", (string.IsNullOrEmpty(Company) ? null : Company.Trim()));
5519 Param[3] = new SqlParameter("@Branches", (string.IsNullOrEmpty(Branches) ? null : Branches.Trim()));
5520 Param[4] = new SqlParameter("@BrokerId", (string.IsNullOrEmpty(brokers) ? null : brokers));
5521 Param[5] = new SqlParameter("@FromDate", fromdate.ToString("dd/MMM/yyyy"));
5522 Param[6] = new SqlParameter("@ToDate", todate.ToString("dd/MMM/yyyy"));
5523 Param[7] = new SqlParameter("@productTypeID", productTypeID);
5524
5525 //Convert Negotiator, Branch and Company Ids list into datatable and pass them into sql procedure parameter value. -20151021
5526 DataTable dtNegotiatorIds = Helper.FillDataTable(NegotiatorIds);
5527 Param[8] = new SqlParameter("@NegotiatorIds", dtNegotiatorIds);
5528
5529 DataTable dtBranchIds = Helper.FillDataTable(BranchIds);
5530 Param[9] = new SqlParameter("@BranchIds", dtBranchIds);
5531
5532 DataTable dtCompanyIds = Helper.FillDataTable(CompanyIds);
5533 Param[10] = new SqlParameter("@CompanyIds", dtCompanyIds);
5534
5535 ds = SqlHelper.ExecuteDataset("GetNegotiatorReportWeeklyNoteUpdated_Update", Param);
5536 return ds;
5537 }
5538 catch (Exception ex)
5539 {
5540 Helper.ErrorLog(ex.InnerException, "Q_Report", "GetNegotiatorWeeklyUpdatedNotesByIds", ex.Message);
5541 ds = new DataSet();
5542 return ds;
5543 }
5544 }
5545
5546 #endregion [Negotiator Weekly Notes Updated]
5547
5548 #region [Negotiator Report]
5549
5550 /// <summary>
5551 /// Getting negotiator data for PDF
5552 /// </summary>
5553 /// <param name="fromdate">From Date</param>
5554 /// <param name="todate">To Date</param>
5555 /// <param name="userid">User Id</param>
5556 /// <param name="brokerId">Broker Id</param>
5557 /// <param name="Negotiator">Negotiator</param>
5558 /// <param name="brokers">Brokers</param>
5559 /// <param name="Company">Company</param>
5560 /// <param name="Branches">Branches</param>
5561 /// <param name="productTypeID">Product Type</param>
5562 /// <returns></returns>
5563 public DataSet GetNegotiatorByIds(List<int> NegotiatorIds, List<int> BranchIds, List<int> CompanyIds, DateTime fromdate, DateTime todate, int userid, int brokerId = 0, string Negotiator = "", string brokers = "", string Company = "", string Branches = "", int productTypeID = 0)
5564 {
5565 DataSet ds;
5566 try
5567 {
5568 List<Negotiation> negotiationlist = new List<Models.Negotiation>();
5569 SqlParameter[] Param = new SqlParameter[11];
5570 Param[0] = new SqlParameter("@CurrentUserId", userid);
5571
5572 Param[1] = new SqlParameter("@Negotiator", (string.IsNullOrEmpty(Negotiator) ? null : Negotiator.Trim()));
5573 Param[2] = new SqlParameter("@Company", (string.IsNullOrEmpty(Company) ? null : Company.Trim()));
5574 Param[3] = new SqlParameter("@Branches", (string.IsNullOrEmpty(Branches) ? null : Branches.Trim()));
5575 Param[4] = new SqlParameter("@BrokerId", (string.IsNullOrEmpty(brokers) ? null : brokers));
5576 Param[5] = new SqlParameter("@FromDate", fromdate.ToString("dd/MMM/yyyy"));
5577 Param[6] = new SqlParameter("@ToDate", todate.ToString("dd/MMM/yyyy"));
5578 Param[7] = new SqlParameter("@productTypeID", productTypeID);
5579
5580 //Convert Negotiator, Branch and Company Ids list into datatable and pass them into sql procedure parameter value. -20151021
5581 DataTable dtNegotiatorIds = Helper.FillDataTable(NegotiatorIds);
5582 Param[8] = new SqlParameter("@NegotiatorIds", dtNegotiatorIds);
5583
5584 DataTable dtBranchIds = Helper.FillDataTable(BranchIds);
5585 Param[9] = new SqlParameter("@BranchIds", dtBranchIds);
5586
5587 DataTable dtCompanyIds = Helper.FillDataTable(CompanyIds);
5588 Param[10] = new SqlParameter("@CompanyIds", dtCompanyIds);
5589
5590 ds = SqlHelper.ExecuteDataset("GetNegotiatorReport_Update", Param);
5591 }
5592 catch (Exception ex)
5593 {
5594 ds = new DataSet();
5595 Helper.ErrorLog(ex.InnerException, "Q_Report", "GetNegotiatorByIds", ex.Message);
5596 }
5597 return ds;
5598 }
5599
5600 #endregion [Negotiator Report]
5601
5602 #region [Overall Conversion Report]
5603
5604 /// <summary>
5605 /// Getting dataset for overall conversion report for Introducer Report
5606 /// </summary>
5607 /// <param name="totalLeads">Total Leads output parameter</param>
5608 /// <param name="totalApps">Total Apps Output parameter</param>
5609 /// <param name="fromdate">from date</param>
5610 /// <param name="todate">to date</param>
5611 /// <param name="userid">user Id</param>
5612 /// <param name="brokerId">broker Id</param>
5613 /// <param name="Negotiator">Negotiator</param>
5614 /// <param name="brokers">Brokers</param>
5615 /// <param name="Company">Companies</param>
5616 /// <param name="Branches">Branches</param>
5617 /// <param name="productTypeID">Product Type Id</param>
5618 public void GetOverAllConversionReportByIds(List<int> NegotiatorIds, List<int> BranchIds, List<int> CompanyIds, out int totalLeads, out int totalApps, DateTime fromdate, DateTime todate, int userid, int brokerId = 0, string Negotiator = "", string brokers = "", string Company = "", string Branches = "", int productTypeID = 0)
5619 {
5620 DataSet ds;
5621 totalLeads = 0;
5622 totalApps = 0;
5623 try
5624 {
5625 List<Negotiation> negotiationlist = new List<Models.Negotiation>();
5626 SqlParameter[] Param = new SqlParameter[11];
5627 Param[0] = new SqlParameter("@CurrentUserId", userid);
5628 if (!string.IsNullOrEmpty(Negotiator))
5629 {
5630 Param[1] = new SqlParameter("@Negotiator", "'" + Negotiator.TrimEnd(',') + "'");
5631 Param[2] = new SqlParameter("@Company", "'" + Company.TrimEnd(',') + "'");
5632 Param[3] = new SqlParameter("@Branches", "'" + Branches.TrimEnd(',') + "'");
5633
5634 //Convert Negotiator, Branch and Company Ids list into datatable and pass them into sql procedure parameter value. -20151021
5635 DataTable dtNegotiatorIds = Helper.FillDataTable(NegotiatorIds);
5636 Param[8] = new SqlParameter("@NegotiatorIds", dtNegotiatorIds);
5637
5638 DataTable dtBranchIds = Helper.FillDataTable(BranchIds);
5639 Param[9] = new SqlParameter("@BranchIds", dtBranchIds);
5640
5641 DataTable dtCompanyIds = Helper.FillDataTable(CompanyIds);
5642 Param[10] = new SqlParameter("@CompanyIds", dtCompanyIds);
5643 }
5644 if (!string.IsNullOrWhiteSpace(brokers))
5645 {
5646 Param[4] = new SqlParameter("@BrokerId", brokers);
5647 }
5648 Param[5] = new SqlParameter("@FromDate", fromdate.ToString("dd/MMM/yyyy"));
5649 Param[6] = new SqlParameter("@ToDate", todate.ToString("dd/MMM/yyyy"));
5650 Param[7] = new SqlParameter("@productTypeID", productTypeID);
5651 ds = SqlHelper.ExecuteDataset(CommandType.StoredProcedure, "GetOverAllConversionForIntroducer_Update", Param);
5652 if (ds.Tables[0].Rows.Count > 0)
5653 {
5654 totalLeads = Convert.ToInt32(ds.Tables[0].Rows[0]["TotalCount"].ToString());
5655 }
5656 if (ds.Tables[1].Rows.Count > 0)
5657 {
5658 totalApps = Convert.ToInt32(ds.Tables[1].Rows[0]["TotalCount"].ToString());
5659 }
5660 }
5661 catch (Exception ex)
5662 {
5663 ds = new DataSet();
5664 Helper.ErrorLog(ex.InnerException, "Q_Report", "GetOverAllConversionReportByIds", ex.Message);
5665 }
5666
5667 }
5668
5669 ///// <summary>
5670 ///// Get introducer visit notes on the basis of filters.
5671 ///// </summary>
5672 ///// <returns></returns>
5673 //public List<IntroducerVisitNotes> GetIntroducerVisitNoteDetails(List<int> companyIds, string brokers, DateTime fromdate, DateTime todate)
5674 //{
5675 // List<int> brokerids = new List<int>();
5676 // if (!string.IsNullOrEmpty(brokers))
5677 // {
5678 // brokerids = brokers.Split(',').Select(Int32.Parse).ToList();
5679 // }
5680 // var lstIntroducerNotes = new List<IntroducerVisitNotes>();
5681 // db_occfinance_5572Entities _context = new db_occfinance_5572Entities();
5682 // try
5683 // {
5684 // if (!string.IsNullOrEmpty(brokers) && companyIds!=null && companyIds.Count>0)
5685 // {
5686 // lstIntroducerNotes = (from intNotes in _context.tblIntroducerVisitNotes
5687 // join usr in _context.tblusers on intNotes.CreatedBy equals usr.userid
5688 // join acct in _context.tblaccounts on usr.account equals acct.accountid
5689 // where companyIds.Contains(acct.accountid)
5690 // && brokerids.Contains(usr.userid)
5691 // select new IntroducerVisitNotes
5692 // {
5693 // Id = intNotes.Id,
5694 // Account = intNotes.Account,
5695 // UserName = usr.brokername,
5696 // CreatedOn = intNotes.Created,
5697 // CreatedBy = intNotes.CreatedBy,
5698 // Note = intNotes.Note,
5699 // Introducer = acct.companyname
5700 // }).ToList();
5701 // }
5702 // else if(string.IsNullOrEmpty(brokers) && companyIds != null && companyIds.Count > 0)
5703 // {
5704 // lstIntroducerNotes = (from intNotes in _context.tblIntroducerVisitNotes
5705 // join usr in _context.tblusers on intNotes.CreatedBy equals usr.userid
5706 // join acct in _context.tblaccounts on usr.account equals acct.accountid
5707 // where companyIds.Contains(acct.accountid)
5708 // select new IntroducerVisitNotes
5709 // {
5710 // Id = intNotes.Id,
5711 // Account = intNotes.Account,
5712 // UserName = usr.brokername,
5713 // CreatedOn = intNotes.Created,
5714 // CreatedBy = intNotes.CreatedBy,
5715 // Note = intNotes.Note,
5716 // Introducer = acct.companyname
5717 // }).ToList();
5718 // }
5719 // if (lstIntroducerNotes != null && lstIntroducerNotes.Count > 0)
5720 // {
5721 // foreach (var intNote in lstIntroducerNotes)
5722 // {
5723 // intNote.Created = Convert.ToDateTime(intNote.CreatedOn).ToString("dd/MM/yyyy hh:mm");
5724 // }
5725 // }
5726 // }
5727 // catch (Exception ex)
5728 // {
5729 // Helper.ErrorLog(ex.InnerException, "Q_Reports.cs", "GetIntroducerVisitNoteDetails", ex.Message);
5730 // }
5731 // return lstIntroducerNotes;
5732 //}
5733
5734 /// <summary>
5735 /// Get introducer appointment details.
5736 /// </summary>
5737 /// <returns></returns>
5738 public List<IntroducerVisitNotes> GetIntroducerVisitNoteDetails(List<int> companyIds, string brokers, DateTime fromdate, DateTime todate)
5739 {
5740 List<IntroducerVisitNotes> introducerVisits = new List<IntroducerVisitNotes>();
5741 DataSet dsIntroducerVisits;
5742 try
5743 {
5744 SqlParameter[] Param = new SqlParameter[10];
5745 Param[0] = new SqlParameter("@CurrentUserId", null);
5746
5747 Param[1] = new SqlParameter("@Negotiator", null);
5748 Param[2] = new SqlParameter("@Company", null);
5749 Param[3] = new SqlParameter("@Branches", null);
5750 Param[4] = new SqlParameter("@BrokerId", (string.IsNullOrEmpty(brokers) ? null : brokers));
5751
5752 //Convert Negotiator, Branch and Company Ids list into datatable and pass them into sql procedure parameter value. -20151021
5753 DataTable dtCompanyIds = Helper.FillDataTable(companyIds);
5754 Param[5] = new SqlParameter("@CompanyIds", dtCompanyIds);
5755
5756 Param[6] = new SqlParameter("@BranchIds", null);
5757
5758 Param[7] = new SqlParameter("@NegotiatorIds", null);
5759 Param[8] = new SqlParameter("@FromDate", fromdate.ToString("dd/MMM/yyyy"));
5760 Param[9] = new SqlParameter("@ToDate", todate.ToString("dd/MMM/yyyy"));
5761
5762 dsIntroducerVisits = SqlHelper.ExecuteDataset("GetIntroducerVisitsNoteDetails", Param);
5763
5764
5765 if (dsIntroducerVisits.Tables.Count > 0 && dsIntroducerVisits.Tables[0].Rows.Count > 0)
5766 {
5767 introducerVisits = DataTableHelper.CreateListFromTableForAll<IntroducerVisitNotes>(dsIntroducerVisits.Tables[0]).ToList();
5768
5769 foreach (var intNote in introducerVisits)
5770 {
5771 intNote.CreateOn = Convert.ToDateTime(intNote.CreatedOn).ToString("dd/MM/yyyy hh:mm");
5772 }
5773 }
5774 }
5775 catch (Exception ex)
5776 {
5777 Helper.ErrorLog(ex.InnerException, "Q_Reports.cs", "GetIntroducerVisitNoteDetails", ex.Message);
5778 }
5779 return introducerVisits;
5780 }
5781
5782 #endregion [Overall Conversion Report]
5783
5784 #region [Conversion Rate For Insurance Referrals]
5785 public DataSet GetConversionRateForInsuranceReferrals(List<int> NegotiatorIds, List<int> BranchIds, List<int> CompanyIds, string type, DateTime fromdate, DateTime todate, int userid, int brokerId = 0, string Negotiator = "", string brokers = "", string Company = "", string Branches = "", int productTypeID = 0)
5786 {
5787 DataSet ds = new DataSet();
5788 try
5789 {
5790 SqlParameter[] Param = new SqlParameter[11];
5791 Param[0] = new SqlParameter("@CurrentUserId", userid);
5792 Param[1] = new SqlParameter("@FromDate", fromdate.ToString("dd/MMM/yyyy"));
5793 Param[2] = new SqlParameter("@ToDate", todate.ToString("dd/MMM/yyyy"));
5794 if (!string.IsNullOrEmpty(Negotiator))
5795 {
5796 Param[3] = new SqlParameter("@Negotiator", Negotiator.Trim());
5797 Param[4] = new SqlParameter("@Company", Company.Trim());
5798 Param[5] = new SqlParameter("@Branches", Branches.Trim());
5799
5800 //Convert Negotiator, Branch and Company Ids list into datatable and pass them into sql procedure parameter value. -20151021
5801 DataTable dtNegotiatorIds = Helper.FillDataTable(NegotiatorIds);
5802 Param[8] = new SqlParameter("@NegotiatorIds", dtNegotiatorIds);
5803
5804 DataTable dtBranchIds = Helper.FillDataTable(BranchIds);
5805 Param[9] = new SqlParameter("@BranchIds", dtBranchIds);
5806
5807 DataTable dtCompanyIds = Helper.FillDataTable(CompanyIds);
5808 Param[10] = new SqlParameter("@CompanyIds", dtCompanyIds);
5809 }
5810 if (!string.IsNullOrWhiteSpace(brokers))
5811 {
5812 Param[6] = new SqlParameter("@BrokerId", brokers);
5813 }
5814 if (!string.IsNullOrWhiteSpace(type))
5815 {
5816 Param[7] = new SqlParameter("@MortgageType", type);
5817 }
5818
5819 //Param[8] = new SqlParameter("@productTypeID", productTypeID);
5820
5821 ds = SqlHelper.ExecuteDataset(CommandType.StoredProcedure, "GetConversionRateForInsuranceReferrals", Param);
5822 }
5823 catch (Exception ex)
5824 {
5825 Helper.ErrorLog(ex.InnerException, "Q_Reports", "GetConversionRateForInsuranceReferrals", ex.Message);
5826 }
5827 return ds;
5828 }
5829
5830 #endregion [Conversion Rate For Insurance Referrals]
5831
5832
5833
5834 #endregion [Updated Code of Reports Data Access Methods 2015-10-21]
5835
5836 #region [Get Selected Companies With Broker 2015-10-21]
5837
5838 /// <summary>
5839 /// Get selected companies with brokers by ids
5840 /// </summary>
5841 /// <param name="_allNamesparents"></param>
5842 /// <returns></returns>
5843 public string GetSelectedCompaniesWithBrokerByIds(string[] _allNamesparents)
5844 {
5845 var allNamesparents = string.Empty;
5846 var distinctList = _allNamesparents.Distinct().ToList();
5847 List<SelectListItem> _list = new List<SelectListItem>();
5848 for (int i = 0; i < distinctList.Count(); i++)
5849 {
5850
5851 if (distinctList[i].Contains("®"))
5852 {
5853 string companyName;
5854 string branchName;
5855 GetCompanyAndBranchNameByIds(distinctList, i, out companyName, out branchName);
5856
5857 _list.Add(new SelectListItem
5858 {
5859 Text = System.Text.RegularExpressions.Regex.Replace(companyName, "[^a-zA-Z0-9)]+", "", System.Text.RegularExpressions.RegexOptions.Compiled),
5860 Value = branchName
5861 });
5862 }
5863 }
5864 // System.Globalization.TextInfo myTI = new System.Globalization.CultureInfo("en-US", false).TextInfo;
5865
5866 var _companieslist = (from r in _list
5867 select new
5868 {
5869 companyname = System.Text.RegularExpressions.Regex.Replace(r.Text, "[^a-zA-Z0-9)]+", "", System.Text.RegularExpressions.RegexOptions.Compiled).Trim()
5870
5871 }).Distinct().ToList();
5872 for (int i = 0; i < _companieslist.Count(); i++)
5873 {
5874 var s = string.Join(", ", _list.Where(p => p.Text == _companieslist[i].companyname).Select(p => p.Value.ToString()));
5875 allNamesparents += string.Format(" <b> {0} </b>( {1} )", _companieslist.ElementAtOrDefault(i).companyname, s);
5876 }
5877 return allNamesparents;
5878 }
5879
5880 /// <summary>
5881 /// Get company and branch names by id.
5882 /// </summary>
5883 /// <param name="companyAndBranchList"></param>
5884 /// <param name="index"></param>
5885 /// <param name="companyName"></param>
5886 /// <param name="branchName"></param>
5887 public void GetCompanyAndBranchNameByIds(List<string> companyAndBranchList, int index, out string companyName, out string branchName)
5888 {
5889 try
5890 {
5891 db_occfinance_5572Entities ctx = new db_occfinance_5572Entities();
5892 var companyId = Convert.ToInt32(companyAndBranchList[index].Split('®')[0]);
5893 var branchId = Convert.ToInt32(companyAndBranchList[index].Split('®')[1]);
5894 companyName = ctx.tblaccounts.Where(com => com.accountid == companyId).Select(com => com.companyname).FirstOrDefault();
5895 branchName = ctx.tblBranches.Where(br => br.Id == branchId).Select(br => br.Branch).FirstOrDefault();
5896 }
5897 catch (Exception ex)
5898 {
5899 companyName = string.Empty;
5900 branchName = string.Empty;
5901 Helper.ErrorLog(ex.InnerException, "ReportsController", "GetCompanyAndBranchNameByIds", ex.Message);
5902 }
5903 }
5904
5905 /// <summary>
5906 /// Get negotiator name by ids
5907 /// </summary>
5908 /// <param name="NegotiatorIds"></param>
5909 /// <returns></returns>
5910 public string[] GetNegotiatorsNameByIds(List<int> NegotiatorIds)
5911 {
5912 string[] negotiatorNames = new string[NegotiatorIds.Count()];
5913 try
5914 {
5915 db_occfinance_5572Entities ctx = new db_occfinance_5572Entities();
5916 negotiatorNames = ctx.tblNegotiators.Where(neg => NegotiatorIds.Contains(neg.Id)).Select(neg => neg.Negotiator).ToList().ToArray();
5917
5918 }
5919 catch (Exception ex)
5920 {
5921 Helper.ErrorLog(ex.InnerException, "ReportsController", "GetNegotiatorName", ex.Message);
5922 }
5923 return negotiatorNames;
5924 }
5925
5926
5927
5928
5929
5930 #endregion [Get Selected Companies With Broker 2015-10-21]
5931
5932 #region [Introducer Visits]
5933
5934 /// <summary>
5935 /// Get introducer appointment details.
5936 /// </summary>
5937 /// <returns></returns>
5938 public List<IntroducerVisitsModel> GetIntroducerVisitsForAppointment(List<int> companyIds, string brokers, DateTime fromdate, DateTime todate)
5939 {
5940 List<IntroducerVisitsModel> introducerVisits = new List<IntroducerVisitsModel>();
5941 DataSet dsIntroducerVisits;
5942 try
5943 {
5944 SqlParameter[] Param = new SqlParameter[10];
5945 Param[0] = new SqlParameter("@CurrentUserId", null);
5946
5947 Param[1] = new SqlParameter("@Negotiator", null);
5948 Param[2] = new SqlParameter("@Company", null);
5949 Param[3] = new SqlParameter("@Branches", null);
5950 Param[4] = new SqlParameter("@BrokerId", (string.IsNullOrEmpty(brokers) ? null : brokers));
5951
5952 //Convert Negotiator, Branch and Company Ids list into datatable and pass them into sql procedure parameter value. -20151021
5953 DataTable dtCompanyIds = Helper.FillDataTable(companyIds);
5954 Param[5] = new SqlParameter("@CompanyIds", dtCompanyIds);
5955
5956 Param[6] = new SqlParameter("@BranchIds", null);
5957
5958 Param[7] = new SqlParameter("@NegotiatorIds", null);
5959 Param[8] = new SqlParameter("@FromDate", fromdate.ToString("dd/MMM/yyyy"));
5960 Param[9] = new SqlParameter("@ToDate", todate.ToString("dd/MMM/yyyy"));
5961
5962 dsIntroducerVisits = SqlHelper.ExecuteDataset("GetIntroducerVisitsDetails", Param);
5963 }
5964 catch (Exception ex)
5965 {
5966 dsIntroducerVisits = new DataSet();
5967 Helper.ErrorLog(ex.InnerException, "Q_Report", "GetIntroducerVisitsDetails", ex.Message);
5968 }
5969
5970 if (dsIntroducerVisits.Tables.Count > 0 && dsIntroducerVisits.Tables[0].Rows.Count > 0)
5971 introducerVisits = DataTableHelper.CreateListFromTableForAll<IntroducerVisitsModel>(dsIntroducerVisits.Tables[0]).ToList();
5972 return introducerVisits;
5973 }
5974
5975 /// <summary>
5976 /// Get Introducer Visits for admin
5977 /// </summary>
5978 /// <param name="companyIds"></param>
5979 /// <param name="userid"></param>
5980 /// <param name="brokers"></param>
5981 /// <returns></returns>
5982 public List<IntroducerVisitsModel> GetIntroducerVisitsForAdmin(List<int> companyIds, int userid, string brokers, List<int> BranchIds, bool IsBroker)
5983 {
5984 List<IntroducerVisitsModel> introducerVisits = new List<IntroducerVisitsModel>();
5985 DataSet dsIntroducerVisits;
5986 try
5987 {
5988 SqlParameter[] Param = new SqlParameter[5];
5989 Param[0] = new SqlParameter("@CurrentUserId", userid);
5990 Param[1] = new SqlParameter("@BrokerId", (string.IsNullOrEmpty(brokers) ? null : brokers));
5991 DataTable dtCompanyIds = Helper.FillDataTable(companyIds);
5992 Param[2] = new SqlParameter("@CompanyIds", dtCompanyIds);
5993 DataTable dtBranchIds = Helper.FillDataTable(BranchIds);
5994 Param[3] = new SqlParameter("@BranchIds", dtBranchIds);
5995 Param[4] = new SqlParameter("@IsBroker", IsBroker);
5996
5997 dsIntroducerVisits = SqlHelper.ExecuteDataset("GetIntroducerVisitsDetailsForAdmin", Param);
5998 }
5999 catch (Exception ex)
6000 {
6001 dsIntroducerVisits = new DataSet();
6002 Helper.ErrorLog(ex.InnerException, "Q_Report", "GetIntroducerVisitsDetailsForAdmin", ex.Message);
6003 }
6004
6005 if (dsIntroducerVisits.Tables.Count > 0 && dsIntroducerVisits.Tables[0].Rows.Count > 0)
6006 introducerVisits = DataTableHelper.CreateListFromTableForAll<IntroducerVisitsModel>(dsIntroducerVisits.Tables[0]).ToList();
6007 return introducerVisits;
6008 }
6009
6010 public bool UpdateIntroducerAppointmentDetails(List<IntroducerVisitsModel> lstIntroducerAppointment)
6011 {
6012 bool result = false;
6013 db_occfinance_5572Entities _context = new db_occfinance_5572Entities();
6014 try
6015 {
6016 lstIntroducerAppointment.RemoveAt(0);//As this contain header of table
6017 foreach (var appointment in lstIntroducerAppointment)
6018 {
6019 //if (appointment.AssignAdvisers == "checked" && appointment.AssignAdviser == 0)
6020 //{
6021
6022 var IsRecordExist = _context.tblIntroducerVisits.Where(x => x.Id == appointment.Id).FirstOrDefault();
6023 if (IsRecordExist != null)
6024 {
6025 try
6026 {
6027 if (appointment.AssignAdviser == 0)
6028 {
6029 IsRecordExist.IsActive = false;
6030 IsRecordExist.IsDeleted = true;
6031 IsRecordExist.Updated = DateTime.Now;
6032 _context.SaveChanges();
6033 }
6034 else
6035 {
6036 IsRecordExist.broker = appointment.broker;
6037 IsRecordExist.Updated = DateTime.Now;
6038 _context.SaveChanges();
6039 }
6040 return true;
6041 }
6042 catch (Exception ex)
6043 {
6044 Helper.ErrorLog(ex.InnerException, "ReportController", "UpdateIntroducerAppointmentDetails", ex.Message);
6045 return false;
6046 }
6047 }
6048 else
6049 {
6050 if (appointment.AssignAdviser == 0)
6051 {
6052 try
6053 {
6054 tblIntroducerVisit objAppointment = new tblIntroducerVisit();
6055 objAppointment.account = appointment.account;
6056 objAppointment.broker = appointment.broker;
6057 objAppointment.FrequencyDay = appointment.FrequencyDay;
6058 objAppointment.FrequencyType = appointment.FrequencyType;
6059 objAppointment.BranchId = appointment.BranchId;
6060 objAppointment.Created = DateTime.Now;
6061 objAppointment.StatusId = 0;
6062 objAppointment.Updated = DateTime.Now;
6063 objAppointment.Created = DateTime.Now;
6064 objAppointment.UpdatedBy = SessionHelper.UserId;
6065 objAppointment.CreatedBy = SessionHelper.UserId;
6066 objAppointment.IsActive = true;
6067 _context.tblIntroducerVisits.Add(objAppointment);
6068 _context.SaveChanges();
6069 result = true;
6070 if (objAppointment.Id > 0)
6071 {
6072 tblIntroducerVisitsStatu objStatus = new tblIntroducerVisitsStatu();
6073 objStatus.IntroducerVisitsId = objAppointment.Id;
6074 objStatus.Status = (int)IntroducerVisitStatusEnum.Pending;
6075 objStatus.CreatedBy = SessionHelper.UserId;
6076 objStatus.CreatedDate = DateTime.Now;
6077 _context.tblIntroducerVisitsStatus.Add(objStatus);
6078 _context.SaveChanges();
6079 if (objStatus.Id > 0)
6080 {
6081 var _introducerVisit = _context.tblIntroducerVisits.Where(x => x.Id == objAppointment.Id).FirstOrDefault();
6082 _introducerVisit.StatusId = objStatus.Id;
6083 }
6084
6085 string _connectionstring = Convert.ToString(ConfigurationManager.ConnectionStrings["ConString1"]);
6086 try
6087 {
6088 var _userId = SessionHelper.UserId;
6089 var _accountId = objAppointment.account;
6090 using (SqlConnection con = new SqlConnection(_connectionstring))
6091 {
6092 using (SqlCommand cmd = new SqlCommand("tblglobalnotesADD", con))
6093 {
6094 string note = "";
6095 note = "A meeting is scheduled with Introducer " + _context.tblaccounts.Where(res => res.accountid == objAppointment.account).Select(res => res.companyname).FirstOrDefault() + " in branch " + _context.tblBranches.Where(x => x.Id == appointment.BranchId).Select(x => x.Branch).FirstOrDefault().ToString() + " on " + DateTime.Now.ToString("dd/MM/yyyy hh:mm");
6096 cmd.CommandType = CommandType.StoredProcedure;
6097 cmd.Parameters.AddWithValue("@UserId", _userId);
6098 cmd.Parameters.AddWithValue("@AccountId", _accountId);
6099 cmd.Parameters.AddWithValue("@Notes", note);
6100 cmd.Parameters.AddWithValue("@PerMission", 1);
6101 cmd.Parameters.AddWithValue("@IsDelete", 0);
6102 cmd.Parameters.AddWithValue("@IsActive", 1);
6103 cmd.Parameters.AddWithValue("@AssignedTo", objAppointment.broker);
6104 cmd.Parameters.AddWithValue("@IsCompleted", 0);
6105 cmd.Parameters.Add("@NoteId", SqlDbType.BigInt);
6106 cmd.Parameters["@NoteId"].Direction = ParameterDirection.Output;
6107 con.Open();
6108 cmd.ExecuteNonQuery();
6109 var chk = Convert.ToInt32(cmd.Parameters["@NoteId"].SqlValue.ToString());
6110 if (chk > 0)
6111 {
6112 objAppointment.NoteId = chk;
6113 _context.SaveChanges();
6114 }
6115 con.Close();
6116 con.Dispose();
6117 }
6118 }
6119 }
6120 catch (Exception ex)
6121 {
6122 Helper.ErrorLog(ex.InnerException, "ReportController", "UpdateIntroducerAppointmentDetails_AddNote", ex.Message);
6123 return false;
6124 }
6125 //}
6126 }
6127 }
6128 catch (Exception ex)
6129 {
6130 Helper.ErrorLog(ex.InnerException, "ReportController", "UpdateIntroducerAppointmentDetails", ex.Message);
6131 return false;
6132 }
6133 }
6134 }
6135 }
6136 }
6137 catch (Exception ex)
6138 {
6139 Helper.ErrorLog(ex.InnerException, "Q_Reports", "UpdateIntroducerAppointmentDetails", ex.Message);
6140 }
6141 return result;
6142 }
6143
6144 #endregion [Introducer Visits]
6145
6146
6147
6148 /// <summary>
6149 /// Get data for London Market Screen Graph.
6150 /// </summary>
6151 /// <returns></returns>
6152 public DataSet GetLondonMarketScreenData()
6153 {
6154 DataSet ds;
6155 try
6156 {
6157 SqlParameter[] Param = new SqlParameter[0];
6158 ds = SqlHelper.ExecuteDataset(CommandType.StoredProcedure, "sp_LondonMarketScreenData", Param);
6159 }
6160 catch (Exception ex)
6161 {
6162 Helper.ErrorLog(ex.InnerException, "Q_report", "sp_LondonMarketScreenData", ex.Message);
6163 ds = new DataSet();
6164 }
6165 return ds;
6166 }
6167
6168 #region Account Visits Report
6169
6170 public AccountVisitsReport GetAccountVisitsReport(List<int> companyIds, int userId, string brokers, List<int> BranchIds, DateTime FromDate, DateTime ToDate)
6171 {
6172 List<clsAccountVisits> accountVisits = new List<clsAccountVisits>();
6173 AccountVisitsReport _reportData = new AccountVisitsReport();
6174 DataSet dsIntroducerVisits;
6175 try
6176 {
6177
6178 SqlParameter[] Param = new SqlParameter[6];
6179 Param[0] = new SqlParameter("@CurrentUserId", userId);
6180 Param[1] = new SqlParameter("@BrokerId", brokers);
6181 DataTable dtCompanyIds = Helper.FillDataTable(companyIds);
6182 Param[2] = new SqlParameter("@CompanyIds", dtCompanyIds);
6183 DataTable dtBranchIds = Helper.FillDataTable(BranchIds);
6184 Param[3] = new SqlParameter("@BranchIds", dtBranchIds);
6185 Param[4] = new SqlParameter("@FromDate", FromDate.ToString("dd/MMM/yyyy"));
6186 Param[5] = new SqlParameter("@ToDate", ToDate.ToString("dd/MMM/yyyy"));
6187 dsIntroducerVisits = SqlHelper.ExecuteDataset("GetAccountVisitsReport", Param);
6188 if (dsIntroducerVisits != null && dsIntroducerVisits.Tables.Count > 0 && dsIntroducerVisits.Tables[0].Rows.Count > 0)
6189 {
6190 foreach (DataRow dr in dsIntroducerVisits.Tables[0].Rows)
6191 {
6192 var av = new clsAccountVisits();
6193 av.Introducer = Convert.ToString(dr["CompanyName"]);
6194 av.Branch = Convert.ToString(dr["Branch"]);
6195 av.Adviser = Convert.ToString(dr["UserName"]);
6196 av.AdviserId = Convert.ToInt32(Convert.ToString(dr["broker"]));
6197 av.IntroducerVisitsId = Convert.ToInt32(Convert.ToString(dr["id"]));
6198 av.TransferToAdviser = Convert.ToString(dr["TransferToAdviser"]);
6199 av.TransferToId = Convert.ToInt32(Convert.ToString(dr["TransferToId"]));
6200 VisitFrequencyEnum vfEnum = (VisitFrequencyEnum)Convert.ToInt32(Convert.ToString(dr["FrequencyType"]));
6201 DayListEnum dlEnum = (DayListEnum)Convert.ToInt32(Convert.ToString(dr["FrequencyDay"]));
6202 IntroducerVisitStatusEnum statusEnum = (IntroducerVisitStatusEnum)Convert.ToInt32(Convert.ToString(dr["Status"]));
6203 av.VisitFrequency = Convert.ToString(vfEnum);
6204 av.VisitFrequencyDay = Convert.ToString(dlEnum);
6205 av.Status = Convert.ToString(statusEnum);
6206 av.Note = Convert.ToString(dr["Notes"]);
6207 accountVisits.Add(av);
6208 }
6209 List<int> transferedIds = accountVisits.Where(x => x.TransferToId > 0 ).Select(x => x.TransferToId).ToList();
6210 if (transferedIds.Count > 0 && transferedIds != null)
6211 {
6212 List<clsAccountVisits> accountVisitsTransfered = new List<clsAccountVisits>();
6213 string _ids = String.Join(",", transferedIds);
6214 DataSet dsIntroducerVisitsTransfer = new DataSet();
6215 SqlParameter[] Param1 = new SqlParameter[1];
6216 Param1[0] = new SqlParameter("@Ids", _ids);
6217 dsIntroducerVisitsTransfer = SqlHelper.ExecuteDataset("GetAccountVistsTransferedData", Param1);
6218 if (dsIntroducerVisitsTransfer != null && dsIntroducerVisitsTransfer.Tables.Count > 0 && dsIntroducerVisitsTransfer.Tables[0].Rows.Count > 0)
6219 {
6220 foreach (DataRow dr in dsIntroducerVisitsTransfer.Tables[0].Rows)
6221 {
6222 var av = new clsAccountVisits();
6223 av.Introducer = Convert.ToString(dr["CompanyName"]);
6224 av.Branch = Convert.ToString(dr["Branch"]);
6225 av.Adviser = Convert.ToString(dr["UserName"]);
6226 av.AdviserId = Convert.ToInt32(Convert.ToString(dr["broker"]));
6227 av.IntroducerVisitsId = Convert.ToInt32(Convert.ToString(dr["id"]));
6228 av.TransferToAdviser = Convert.ToString(dr["TransferToAdviser"]);
6229 av.TransferToId = Convert.ToInt32(Convert.ToString(dr["TransferToId"]));
6230 VisitFrequencyEnum vfEnum = (VisitFrequencyEnum)Convert.ToInt32(Convert.ToString(dr["FrequencyType"]));
6231 DayListEnum dlEnum = (DayListEnum)Convert.ToInt32(Convert.ToString(dr["FrequencyDay"]));
6232 IntroducerVisitStatusEnum statusEnum = (IntroducerVisitStatusEnum)Convert.ToInt32(Convert.ToString(dr["Status"]));
6233 av.VisitFrequency = Convert.ToString(vfEnum);
6234 av.VisitFrequencyDay = Convert.ToString(dlEnum);
6235 av.Status = Convert.ToString(statusEnum);
6236 av.Note = Convert.ToString(dr["Notes"]);
6237 accountVisitsTransfered.Add(av);
6238 }
6239
6240 _reportData.TotalTransferVisitsReport = accountVisitsTransfered;
6241 }
6242
6243 }
6244
6245 _reportData.TotalAccountVisitsReport = accountVisits.Where(x => x.TransferToId == 0 && x.Status != IntroducerVisitStatusEnum.Transfer.ToString()).ToList();
6246 }
6247 }
6248 catch (Exception ex)
6249 {
6250 Helper.ErrorLog(ex.InnerException, "Q_Report", "GetAccountVisitsReport", ex.Message);
6251 }
6252 return _reportData;
6253 }
6254
6255
6256 #endregion Account Visits Report
6257
6258 }
6259}
6260
6261
6262
6263using Occfinance_Data;
6264using System;
6265using System.Data;
6266using System.Data.SqlClient;
6267
6268namespace Occfinance.Code
6269{
6270 /*! Class is used to hold data access for scheduler
6271 * \This classs provides data access facility for shceduler
6272 * \All the fields are declared on top
6273 * \This class may hold large number of methods implementation
6274 */
6275 public class Q_SchedulerAccess
6276 {
6277 #region Fields
6278
6279 public db_occfinance_5572Entities dbCtx = new db_occfinance_5572Entities();
6280 public int taskStatus = 0;
6281
6282 #endregion Fields
6283
6284 #region Methods Implementation
6285
6286 public int TaskOperation(string financeIds, string rIds, DateTime? start)
6287 {
6288 try
6289 {
6290 SqlParameter[] parameters = new SqlParameter[3];
6291 parameters[0] = new SqlParameter("@financeid", string.IsNullOrEmpty(financeIds) ? "" : financeIds);
6292 parameters[1] = new SqlParameter("@ID", string.IsNullOrEmpty(rIds) ? "" : rIds);
6293 parameters[2] = new SqlParameter("@followup", start ?? (object)DBNull.Value);
6294 taskStatus = SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "UpdateFollowupDatefinance", parameters);
6295 }
6296 catch
6297 {
6298 }
6299 return taskStatus;
6300 }
6301
6302 public int TaskOperation(string recurrenceRule, string recurrenceException, int? taskId)
6303 {
6304 try
6305 {
6306 SqlParameter[] parameters = new SqlParameter[3];
6307 parameters[0] = new SqlParameter("@taskid", taskId ?? 0);
6308 parameters[1] = new SqlParameter("@recurrencerule", string.IsNullOrEmpty(recurrenceRule) ? "" : recurrenceRule);
6309 parameters[2] = new SqlParameter("@recurrenceexception", string.IsNullOrEmpty(recurrenceException) ? "" : recurrenceException);
6310 taskStatus = SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "UpdateRecurrenceRuleException", parameters);
6311 }
6312 catch
6313 {
6314 }
6315 return taskStatus;
6316 }
6317
6318 public int TaskOperation(string financeIds, string Ids, string followUp)
6319 {
6320 try
6321 {
6322 SqlParameter[] parameters = new SqlParameter[3];
6323 parameters[0] = new SqlParameter("@ID", string.IsNullOrEmpty(Ids) ? "" : Ids);
6324 parameters[1] = new SqlParameter("@financeid", string.IsNullOrEmpty(financeIds) ? "" : financeIds);
6325 parameters[2] = new SqlParameter("@followup", Convert.ToDateTime(followUp));
6326 taskStatus = SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "UpdateFollowupDateSavedEvent", parameters);
6327 }
6328 catch
6329 {
6330 }
6331 return taskStatus;
6332 }
6333
6334 public int TaskOperation(string financeIds, DateTime? followUp)
6335 {
6336 try
6337 {
6338 SqlParameter[] parameters = new SqlParameter[2];
6339 parameters[0] = new SqlParameter("@ID", string.IsNullOrEmpty(financeIds) ? "" : financeIds);
6340 parameters[1] = new SqlParameter("@followup", followUp ?? (object)DBNull.Value);
6341 taskStatus = SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "UpdateFollowupDateSavedEvent", parameters);
6342 }
6343 catch
6344 {
6345 }
6346 return taskStatus;
6347 }
6348
6349 public int TaskOperation(int financeId, int Type, int Status, DateTime? startEvent, DateTime? endEvent, string recurrenceRule, int recurrenceId, string recurrenceException)
6350 {
6351 try
6352 {
6353 SqlParameter[] parameters = new SqlParameter[8];
6354 parameters[0] = new SqlParameter("financeid", financeId);
6355 parameters[1] = new SqlParameter("type", Type);
6356 parameters[2] = new SqlParameter("status", Status);
6357 parameters[3] = new SqlParameter("startevent", startEvent ?? (object)DBNull.Value);
6358 parameters[4] = new SqlParameter("endevent", endEvent ?? (object)DBNull.Value);
6359 parameters[5] = new SqlParameter("recurrencerule", string.IsNullOrEmpty(recurrenceRule) ? "" : recurrenceRule);
6360 parameters[6] = new SqlParameter("recurrenceID", recurrenceId);
6361 parameters[7] = new SqlParameter("recurrenceexception", string.IsNullOrEmpty(recurrenceException) ? "" : recurrenceException);
6362
6363 taskStatus = SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "SaveEvents", parameters);
6364 }
6365 catch
6366 {
6367 }
6368 return taskStatus;
6369 }
6370
6371 public DataTable GetIcsFiles(int financeId)
6372 {
6373 DataTable icsFiles = null;
6374 SqlParameter[] parameters = new SqlParameter[1];
6375 parameters[0] = new SqlParameter("@financeid", financeId);
6376 icsFiles = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "GetIcsFileForEvent_Update", parameters);
6377 return icsFiles;
6378 }
6379
6380 public DataTable GetIcsFilesForApplicationPage(int financeId)
6381 {
6382 DataTable icsFiles = null;
6383 SqlParameter[] parameters = new SqlParameter[1];
6384 parameters[0] = new SqlParameter("@financeid", financeId);
6385
6386 icsFiles = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "GetIcsFileForEventForApplicationPage_Update", parameters);
6387 return icsFiles;
6388 }
6389
6390 public DataTable GetCompleteIcsFile(string financeId)
6391 {
6392 DataTable icsFiles = null;
6393 SqlParameter[] parameters = new SqlParameter[1];
6394 parameters[0] = new SqlParameter("@financeid", financeId);
6395 icsFiles = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "GetCompleteIcsFileForEvents_Update", parameters);
6396 return icsFiles;
6397 }
6398
6399 #endregion Methods Implementation
6400 }
6401}
6402
6403 public class Q_User
6404 {
6405 public db_occfinance_5572Entities ctx = new db_occfinance_5572Entities();
6406
6407 public bool AuthenticateUser(string username, string password, out int userid)
6408 {
6409 bool result = false;
6410 userid = 0;
6411 result = ctx.tblusers.Any(u => u.username == username.Trim() && u.password == password.Trim() && u.active == true && u.administrator.HasValue && u.administrator.Value == true && (u.broker.HasValue == false || u.broker.Value == false)); // Check Administrator
6412 if (!result)
6413 {
6414 result = ctx.tblusers.Any(u => u.username == username.Trim() && u.password == password.Trim() && u.active == true && u.broker.HasValue && u.broker.Value == true && (u.administrator.HasValue == false || u.administrator.Value == false)); // Check Broker
6415 if (!result)
6416 {
6417 result = ctx.tblusers.Any(u => u.username == username.Trim() && u.password == password.Trim() && u.active == true && (u.administrator.HasValue == false || u.administrator.Value == false) && (u.broker.HasValue == false || u.broker.Value == false)); // Check User
6418 if (!result)
6419 {
6420 result = ctx.tblusers.Any(u => u.username == username.Trim() && u.password == password.Trim() && u.active == true && (u.administrator.HasValue == true && u.administrator.Value == true) && (u.broker.HasValue == true && u.broker.Value == true)); // Check Manager
6421 }
6422 }
6423 }
6424
6425 if (result)
6426 {
6427 userid = ctx.tblusers.Where(u => u.username == username.Trim() && u.password == password.Trim() && u.active == true).Select(u => u.userid).FirstOrDefault();
6428
6429 }
6430 return result;
6431 }
6432 }
6433
6434 public static class SessionWrapper
6435 {
6436
6437 //---------------------------------------------------------------
6438
6439 public static PermissionSession PermissionSession
6440 {
6441 get { return GetFromSession<PermissionSession>("PermissionSession"); }
6442 set { SetInSession<PermissionSession>("PermissionSession", value); }
6443 }
6444
6445 private static T GetFromSession<T>(string key)
6446 {
6447 object obj = HttpContext.Current.Session[key];
6448 if (obj == null)
6449 {
6450 return default(T);
6451 }
6452 return (T)obj;
6453 }
6454 private static void SetInSession<T>(string key, T value)
6455 {
6456 if (value == null)
6457 {
6458 HttpContext.Current.Session.Remove(key);
6459 }
6460 else
6461 {
6462 HttpContext.Current.Session[key] = value;
6463 }
6464 }
6465 private static T GetFromApplication<T>(string key)
6466 {
6467 return (T)HttpContext.Current.Application[key];
6468 }
6469 private static void SetInApplication<T>(string key, T value)
6470 {
6471 if (value == null)
6472 {
6473 HttpContext.Current.Application.Remove(key);
6474 }
6475 else
6476 {
6477 HttpContext.Current.Application[key] = value;
6478 }
6479 }
6480
6481 }
6482
6483using System;
6484using System.Collections.Generic;
6485using System.Configuration;
6486using System.Data;
6487using System.Data.SqlClient;
6488using System.Reflection;
6489using System.Runtime.InteropServices;
6490using System.Transactions;
6491using System.Xml;
6492
6493public sealed class SqlHelper
6494{
6495 private SqlHelper()
6496 {
6497 }
6498
6499 public static SqlDataReader ExecuteReaderNext(CommandType commandType, string commandText, params SqlParameter[] commandParameters)
6500 {
6501 SqlConnection connection = null;
6502 SqlDataReader csReader;
6503 try
6504 {
6505 connection = new SqlConnection(ConnectionString());
6506 connection.Open();
6507 csReader = ExecuteReader(connection, null, commandType, commandText, commandParameters, SqlConnectionOwnership.External);
6508 }
6509 catch
6510 {
6511 if (connection != null)
6512 {
6513 connection.Close();
6514 }
6515 throw;
6516 }
6517 return csReader;
6518 }
6519
6520 private static void AssignParameterValues(SqlParameter[] commandParameters, object[] parameterValues)
6521 {
6522 if ((commandParameters != null) && (parameterValues != null))
6523 {
6524 if (commandParameters.Length != parameterValues.Length)
6525 {
6526 throw new ArgumentException("Parameter count does not match Parameter Value count.");
6527 }
6528 int i = 0;
6529 int j = commandParameters.Length;
6530 while (i < j)
6531 {
6532 if (parameterValues[i] is IDbDataParameter)
6533 {
6534 IDbDataParameter paramInstance = (IDbDataParameter) parameterValues[i];
6535 if (paramInstance.Value == null)
6536 {
6537 commandParameters[i].Value = DBNull.Value;
6538 }
6539 else
6540 {
6541 commandParameters[i].Value = paramInstance.Value;
6542 }
6543 }
6544 else if (parameterValues[i] == null)
6545 {
6546 commandParameters[i].Value = DBNull.Value;
6547 }
6548 else
6549 {
6550 commandParameters[i].Value = parameterValues[i];
6551 }
6552 i++;
6553 }
6554 }
6555 }
6556
6557 private static void AssignParameterValues(SqlParameter[] commandParameters, DataRow dataRow)
6558 {
6559 if ((commandParameters != null) && (dataRow != null))
6560 {
6561 int i = 0;
6562 foreach (SqlParameter commandParameter in commandParameters)
6563 {
6564 if ((commandParameter.ParameterName == null) || (commandParameter.ParameterName.Length <= 1))
6565 {
6566 throw new Exception(string.Format("Please provide a valid parameter name on the parameter #{0}, the ParameterName property has the following value: '{1}'.", i, commandParameter.ParameterName));
6567 }
6568 if (dataRow.Table.Columns.IndexOf(commandParameter.ParameterName.Substring(1)) != -1)
6569 {
6570 commandParameter.Value = dataRow[commandParameter.ParameterName.Substring(1)];
6571 }
6572 i++;
6573 }
6574 }
6575 }
6576
6577 private static void AttachParameters(SqlCommand command, SqlParameter[] commandParameters)
6578 {
6579 if (command == null)
6580 {
6581 throw new ArgumentNullException("command");
6582 }
6583 if (commandParameters != null)
6584 {
6585 foreach (SqlParameter p in commandParameters)
6586 {
6587 if (p != null)
6588 {
6589 if (((p.Direction == ParameterDirection.InputOutput) || (p.Direction == ParameterDirection.Input)) && (p.Value == null))
6590 {
6591 p.Value = DBNull.Value;
6592 }
6593 command.Parameters.Add(p);
6594 }
6595 }
6596 }
6597 }
6598
6599 public static string ConnectionString()
6600 {
6601 string strConnection = string.Empty;
6602 strConnection = ConfigurationManager.ConnectionStrings["ConString1"].ToString();
6603 if ((strConnection == null) || (strConnection.Length == 0))
6604 {
6605 throw new ArgumentNullException("strConnection");
6606 }
6607 return strConnection;
6608 }
6609
6610 /********************************************************************
6611 * Code Updatd : 24/01/2015
6612 *
6613 * Description : Query using dataadapter added for better performance
6614 *
6615 * ******************************************************************/
6616
6617 public static DataSet ExecuteDataset(string commandtext, SqlParameter[] param)
6618 {
6619 using (SqlConnection connection = new SqlConnection(ConnectionString()))
6620 {
6621 try
6622 {
6623
6624 if (connection.State == ConnectionState.Closed)
6625 {
6626 connection.Open();
6627 }
6628
6629 SqlCommand cmd = new SqlCommand(commandtext, connection);
6630 cmd.Parameters.AddRange(param);
6631 cmd.CommandType = CommandType.StoredProcedure;
6632 cmd.CommandTimeout = 900;
6633 using (SqlDataAdapter da = new SqlDataAdapter(cmd))
6634 {
6635 DataSet ds = new DataSet();
6636 da.Fill(ds);
6637 cmd.Parameters.Clear();
6638 connection.Close();
6639 return ds;
6640 }
6641 }
6642 catch (Exception ex)
6643 {
6644 throw new ArgumentNullException(ex.Message);
6645 }
6646 finally
6647 {
6648 connection.Close();
6649 }
6650 }
6651
6652 }
6653
6654 public static DataSet ExecuteDataset(CommandType commandType, string commandText, params SqlParameter[] commandParameters)
6655 {
6656 using (SqlConnection connection = new SqlConnection(ConnectionString()))
6657 {
6658 connection.Open();
6659 return ExecuteDataset(connection, commandType, commandText, commandParameters);
6660 }
6661 }
6662
6663 public static DataSet ExecuteDataset(SqlConnection connection, CommandType commandType, string commandText)
6664 {
6665 return ExecuteDataset(connection, commandType, commandText, null);
6666 }
6667
6668
6669
6670 public static DataSet ExecuteDataset(SqlTransaction transaction, CommandType commandType, string commandText)
6671 {
6672 return ExecuteDataset(transaction, commandType, commandText, null);
6673 }
6674
6675
6676
6677 public static DataSet ExecuteDataset(SqlConnection connection, CommandType commandType, string commandText, params SqlParameter[] commandParameters)
6678 {
6679 if (connection == null)
6680 {
6681 throw new ArgumentNullException("connection");
6682 }
6683 TransactionOptions transOptions = new TransactionOptions() { IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted };
6684 using (new TransactionScope(TransactionScopeOption.Required, transOptions))
6685 {
6686 SqlCommand cmd = new SqlCommand();
6687 cmd.CommandTimeout = 900;
6688 bool mustCloseConnection = false;
6689 PrepareCommand(cmd, connection, null, commandType, commandText, commandParameters, out mustCloseConnection);
6690 using (SqlDataAdapter da = new SqlDataAdapter(cmd))
6691 {
6692 DataSet ds = new DataSet();
6693 da.Fill(ds);
6694 cmd.Parameters.Clear();
6695 if (mustCloseConnection)
6696 {
6697 connection.Close();
6698 }
6699 return ds;
6700 }
6701 }
6702 }
6703
6704 public static DataSet ExecuteDataset(SqlTransaction transaction, CommandType commandType, string commandText, params SqlParameter[] commandParameters)
6705 {
6706 if (transaction == null)
6707 {
6708 throw new ArgumentNullException("transaction");
6709 }
6710 if ((transaction != null) && (transaction.Connection == null))
6711 {
6712 throw new ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "transaction");
6713 }
6714
6715 SqlCommand cmd = new SqlCommand();
6716 bool mustCloseConnection = false;
6717 PrepareCommand(cmd, transaction.Connection, transaction, commandType, commandText, commandParameters, out mustCloseConnection);
6718 using (SqlDataAdapter da = new SqlDataAdapter(cmd))
6719 {
6720 DataSet ds = new DataSet();
6721 da.Fill(ds);
6722 cmd.Parameters.Clear();
6723 return ds;
6724 }
6725 }
6726
6727
6728
6729
6730
6731
6732
6733 public static DataTable ExecuteDatatable(CommandType commandType, string commandText)
6734 {
6735 return ExecuteDatatable(commandType, commandText, null);
6736 }
6737
6738
6739
6740 public static DataTable ExecuteDatatable(CommandType commandType, string commandText, params SqlParameter[] commandParameters)
6741 {
6742 using (SqlConnection connection = new SqlConnection(ConnectionString()))
6743 {
6744 connection.Open();
6745 return ExecuteDatatable(connection, commandType, commandText, commandParameters);
6746 }
6747 }
6748
6749 public static DataTable ExecuteDatatable(SqlConnection connection, CommandType commandType, string commandText)
6750 {
6751 return ExecuteDatatable(connection, commandType, commandText, null);
6752 }
6753
6754
6755
6756 public static DataTable ExecuteDatatable(SqlTransaction transaction, CommandType commandType, string commandText)
6757 {
6758 return ExecuteDatatable(transaction, commandType, commandText, null);
6759 }
6760
6761
6762
6763 public static DataTable ExecuteDatatable(SqlConnection connection, CommandType commandType, string commandText, params SqlParameter[] commandParameters)
6764 {
6765
6766 if (connection == null)
6767 {
6768 throw new ArgumentNullException("connection");
6769 }
6770
6771 TransactionOptions transOptions = new TransactionOptions() { IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted };
6772 using (new TransactionScope(TransactionScopeOption.Required, transOptions))
6773 {
6774
6775 SqlCommand cmd = new SqlCommand();
6776 bool mustCloseConnection = false;
6777 PrepareCommand(cmd, connection, null, commandType, commandText, commandParameters, out mustCloseConnection);
6778 using (SqlDataAdapter da = new SqlDataAdapter(cmd))
6779 {
6780 DataTable dt = new DataTable();
6781 da.Fill(dt);
6782 cmd.Parameters.Clear();
6783 if (mustCloseConnection)
6784 {
6785 connection.Close();
6786 }
6787 return dt;
6788 }
6789 }
6790 }
6791
6792 public static DataTable ExecuteDatatable(SqlTransaction transaction, CommandType commandType, string commandText, params SqlParameter[] commandParameters)
6793 {
6794 if (transaction == null)
6795 {
6796 throw new ArgumentNullException("transaction");
6797 }
6798 if ((transaction != null) && (transaction.Connection == null))
6799 {
6800 throw new ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "transaction");
6801 }
6802
6803 SqlCommand cmd = new SqlCommand();
6804 bool mustCloseConnection = false;
6805 PrepareCommand(cmd, transaction.Connection, transaction, commandType, commandText, commandParameters, out mustCloseConnection);
6806 using (SqlDataAdapter da = new SqlDataAdapter(cmd))
6807 {
6808 DataTable dt = new DataTable();
6809 da.Fill(dt);
6810 cmd.Parameters.Clear();
6811 return dt;
6812 }
6813 }
6814
6815
6816 public static int ExecuteNonQuery(CommandType commandType, string commandText)
6817 {
6818 return ExecuteNonQuery(commandType, commandText, null);
6819 }
6820
6821
6822
6823 public static int ExecuteNonQuery(CommandType commandType, string commandText, params SqlParameter[] commandParameters)
6824
6825 {
6826 using (SqlConnection connection = new SqlConnection(ConnectionString()))
6827 {
6828 connection.Open();
6829 return ExecuteNonQuery(connection, commandType, commandText, commandParameters);
6830 }
6831 }
6832
6833 public static int ExecuteNonQueryWithTransaction(CommandType commandType, string commandText, SqlTransaction tran, SqlConnection connection, params SqlParameter[] commandParameters)
6834 {
6835
6836 if (connection == null)
6837 {
6838 throw new ArgumentNullException("connection");
6839 }
6840 SqlCommand cmd = new SqlCommand();
6841 cmd.Transaction = tran;
6842 bool mustCloseConnection = false;
6843 PrepareCommand(cmd, connection, null, commandType, commandText, commandParameters, out mustCloseConnection);
6844 int retval = 0;
6845 try
6846 {
6847 cmd.CommandTimeout = 0x2710;
6848 retval = cmd.ExecuteNonQuery();
6849 }
6850 catch (Exception)
6851 {
6852 }
6853 finally
6854 {
6855 cmd.Parameters.Clear();
6856 if (mustCloseConnection)
6857 {
6858 connection.Close();
6859 }
6860 }
6861 return retval;
6862
6863 }
6864
6865
6866 public static int ExecuteNonQuery(SqlConnection connection, CommandType commandType, string commandText)
6867 {
6868 return ExecuteNonQuery(connection, commandType, commandText, null);
6869 }
6870
6871
6872
6873 public static int ExecuteNonQuery(SqlTransaction transaction, CommandType commandType, string commandText)
6874 {
6875 return ExecuteNonQuery(transaction, commandType, commandText, null);
6876 }
6877
6878
6879
6880 public static int ExecuteNonQuery(SqlConnection connection, CommandType commandType, string commandText, params SqlParameter[] commandParameters)
6881 {
6882 if (connection == null)
6883 {
6884 throw new ArgumentNullException("connection");
6885 }
6886 SqlCommand cmd = new SqlCommand();
6887 bool mustCloseConnection = false;
6888 PrepareCommand(cmd, connection, null, commandType, commandText, commandParameters, out mustCloseConnection);
6889 int retval = 0;
6890 try
6891 {
6892 cmd.CommandTimeout = 0x2710;
6893 retval = cmd.ExecuteNonQuery();
6894 }
6895 catch (Exception ex)
6896 {
6897 }
6898 finally
6899 {
6900 cmd.Parameters.Clear();
6901 if (mustCloseConnection)
6902 {
6903 connection.Close();
6904 }
6905 }
6906 return retval;
6907 }
6908
6909
6910
6911 public static int ExecuteNonQuery(SqlTransaction transaction, CommandType commandType, string commandText, params SqlParameter[] commandParameters)
6912 {
6913 if (transaction == null)
6914 {
6915 throw new ArgumentNullException("transaction");
6916 }
6917 if ((transaction != null) && (transaction.Connection == null))
6918 {
6919 throw new ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "transaction");
6920 }
6921 SqlCommand cmd = new SqlCommand();
6922 bool mustCloseConnection = false;
6923 PrepareCommand(cmd, transaction.Connection, transaction, commandType, commandText, commandParameters, out mustCloseConnection);
6924 int retval = cmd.ExecuteNonQuery();
6925 cmd.Parameters.Clear();
6926 return retval;
6927 }
6928
6929
6930
6931 public static SqlDataReader ExecuteReader(CommandType commandType, string commandText)
6932 {
6933 return ExecuteReader(commandType, commandText, null);
6934 }
6935
6936
6937
6938 public static SqlDataReader ExecuteReader(CommandType commandType, string commandText, params SqlParameter[] commandParameters)
6939 {
6940 SqlConnection connection = null;
6941 SqlDataReader csReader;
6942 try
6943 {
6944 connection = new SqlConnection(ConnectionString());
6945 connection.Open();
6946 csReader = ExecuteReader(connection, null, commandType, commandText, commandParameters, SqlConnectionOwnership.Internal);
6947 }
6948 catch
6949 {
6950 if (connection != null)
6951 {
6952 connection.Close();
6953 }
6954 throw;
6955 }
6956 return csReader;
6957 }
6958
6959 public static SqlDataReader ExecuteReader(SqlConnection connection, CommandType commandType, string commandText)
6960 {
6961 return ExecuteReader(connection, commandType, commandText, null);
6962 }
6963
6964
6965
6966 public static SqlDataReader ExecuteReader(SqlTransaction transaction, CommandType commandType, string commandText)
6967 {
6968 return ExecuteReader(transaction, commandType, commandText, null);
6969 }
6970
6971
6972
6973 public static SqlDataReader ExecuteReader(SqlConnection connection, CommandType commandType, string commandText, params SqlParameter[] commandParameters)
6974 {
6975 return ExecuteReader(connection, null, commandType, commandText, commandParameters, SqlConnectionOwnership.External);
6976 }
6977
6978 public static SqlDataReader ExecuteReader(SqlTransaction transaction, CommandType commandType, string commandText, params SqlParameter[] commandParameters)
6979 {
6980 if (transaction == null)
6981 {
6982 throw new ArgumentNullException("transaction");
6983 }
6984 if ((transaction != null) && (transaction.Connection == null))
6985 {
6986 throw new ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "transaction");
6987 }
6988 return ExecuteReader(transaction.Connection, transaction, commandType, commandText, commandParameters, SqlConnectionOwnership.External);
6989 }
6990
6991 private static SqlDataReader ExecuteReader(SqlConnection connection, SqlTransaction transaction, CommandType commandType, string commandText, SqlParameter[] commandParameters, SqlConnectionOwnership connectionOwnership)
6992 {
6993 SqlDataReader csReader;
6994 if (connection == null)
6995 {
6996 throw new ArgumentNullException("connection");
6997 }
6998 bool mustCloseConnection = false;
6999 SqlCommand cmd = new SqlCommand();
7000 cmd.CommandTimeout = 0;
7001 try
7002 {
7003 SqlDataReader dataReader;
7004 PrepareCommand(cmd, connection, transaction, commandType, commandText, commandParameters, out mustCloseConnection);
7005 if (connectionOwnership == SqlConnectionOwnership.External)
7006 {
7007 dataReader = cmd.ExecuteReader();
7008 }
7009 else
7010 {
7011 dataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
7012 }
7013 bool canClear = true;
7014 foreach (SqlParameter commandParameter in cmd.Parameters)
7015 {
7016 if (commandParameter.Direction != ParameterDirection.Input)
7017 {
7018 canClear = false;
7019 }
7020 }
7021 if (canClear)
7022 {
7023 cmd.Parameters.Clear();
7024 }
7025 csReader = dataReader;
7026 }
7027 catch
7028 {
7029 if (mustCloseConnection)
7030 {
7031 connection.Close();
7032 }
7033 throw;
7034 }
7035 return csReader;
7036 }
7037
7038
7039
7040
7041
7042 public static object ExecuteScalar(CommandType commandType, string commandText)
7043 {
7044 return ExecuteScalar(commandType, commandText, null);
7045 }
7046
7047
7048
7049 public static object ExecuteScalar(CommandType commandType, string commandText, params SqlParameter[] commandParameters)
7050 {
7051 using (SqlConnection connection = new SqlConnection(ConnectionString()))
7052 {
7053 connection.Open();
7054 return ExecuteScalar(connection, commandType, commandText, commandParameters);
7055 }
7056 }
7057
7058 public static object ExecuteScalar(SqlConnection connection, CommandType commandType, string commandText)
7059 {
7060 return ExecuteScalar(connection, commandType, commandText, null);
7061 }
7062
7063
7064
7065 public static object ExecuteScalar(SqlTransaction transaction, CommandType commandType, string commandText)
7066 {
7067 return ExecuteScalar(transaction, commandType, commandText, null);
7068 }
7069
7070
7071
7072 public static object ExecuteScalar(SqlConnection connection, CommandType commandType, string commandText, params SqlParameter[] commandParameters)
7073 {
7074 if (connection == null)
7075 {
7076 throw new ArgumentNullException("connection");
7077 }
7078 SqlCommand cmd = new SqlCommand();
7079 bool mustCloseConnection = false;
7080 PrepareCommand(cmd, connection, null, commandType, commandText, commandParameters, out mustCloseConnection);
7081 object retval = cmd.ExecuteScalar();
7082 cmd.Parameters.Clear();
7083 if (mustCloseConnection)
7084 {
7085 connection.Close();
7086 }
7087 return retval;
7088 }
7089
7090 public static object ExecuteScalar(SqlTransaction transaction, CommandType commandType, string commandText, params SqlParameter[] commandParameters)
7091 {
7092 if (transaction == null)
7093 {
7094 throw new ArgumentNullException("transaction");
7095 }
7096 if ((transaction != null) && (transaction.Connection == null))
7097 {
7098 throw new ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "transaction");
7099 }
7100 SqlCommand cmd = new SqlCommand();
7101 bool mustCloseConnection = false;
7102 PrepareCommand(cmd, transaction.Connection, transaction, commandType, commandText, commandParameters, out mustCloseConnection);
7103 object retval = cmd.ExecuteScalar();
7104 cmd.Parameters.Clear();
7105 return retval;
7106 }
7107
7108
7109
7110 public static XmlReader ExecuteXmlReader(SqlConnection connection, CommandType commandType, string commandText)
7111 {
7112 return ExecuteXmlReader(connection, commandType, commandText, null);
7113 }
7114
7115
7116
7117 public static XmlReader ExecuteXmlReader(SqlTransaction transaction, CommandType commandType, string commandText)
7118 {
7119 return ExecuteXmlReader(transaction, commandType, commandText, null);
7120 }
7121
7122
7123
7124 public static XmlReader ExecuteXmlReader(SqlConnection connection, CommandType commandType, string commandText, params SqlParameter[] commandParameters)
7125 {
7126 XmlReader csReader;
7127 if (connection == null)
7128 {
7129 throw new ArgumentNullException("connection");
7130 }
7131 bool mustCloseConnection = false;
7132 SqlCommand cmd = new SqlCommand();
7133 try
7134 {
7135 PrepareCommand(cmd, connection, null, commandType, commandText, commandParameters, out mustCloseConnection);
7136 XmlReader retval = cmd.ExecuteXmlReader();
7137 cmd.Parameters.Clear();
7138 csReader = retval;
7139 }
7140 catch
7141 {
7142 if (mustCloseConnection)
7143 {
7144 connection.Close();
7145 }
7146 throw;
7147 }
7148 return csReader;
7149 }
7150
7151 public static XmlReader ExecuteXmlReader(SqlTransaction transaction, CommandType commandType, string commandText, params SqlParameter[] commandParameters)
7152 {
7153 if (transaction == null)
7154 {
7155 throw new ArgumentNullException("transaction");
7156 }
7157 if ((transaction != null) && (transaction.Connection == null))
7158 {
7159 throw new ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "transaction");
7160 }
7161 SqlCommand cmd = new SqlCommand();
7162 bool mustCloseConnection = false;
7163 PrepareCommand(cmd, transaction.Connection, transaction, commandType, commandText, commandParameters, out mustCloseConnection);
7164 XmlReader retval = cmd.ExecuteXmlReader();
7165 cmd.Parameters.Clear();
7166 return retval;
7167 }
7168
7169
7170
7171 public static void FillDataset(CommandType commandType, string commandText, DataSet dataSet, string[] tableNames)
7172 {
7173 if (dataSet == null)
7174 {
7175 throw new ArgumentNullException("dataSet");
7176 }
7177 using (SqlConnection connection = new SqlConnection(ConnectionString()))
7178 {
7179 connection.Open();
7180 FillDataset(connection, commandType, commandText, dataSet, tableNames);
7181 }
7182 }
7183
7184
7185
7186 public static void FillDataset(CommandType commandType, string commandText, DataSet dataSet, string[] tableNames, params SqlParameter[] commandParameters)
7187 {
7188 if (dataSet == null)
7189 {
7190 throw new ArgumentNullException("dataSet");
7191 }
7192 using (SqlConnection connection = new SqlConnection(ConnectionString()))
7193 {
7194 connection.Open();
7195 FillDataset(connection, commandType, commandText, dataSet, tableNames, commandParameters);
7196 }
7197 }
7198
7199 public static void FillDataset(SqlConnection connection, CommandType commandType, string commandText, DataSet dataSet, string[] tableNames)
7200 {
7201 FillDataset(connection, commandType, commandText, dataSet, tableNames, null);
7202 }
7203
7204
7205
7206 public static void FillDataset(SqlTransaction transaction, CommandType commandType, string commandText, DataSet dataSet, string[] tableNames)
7207 {
7208 FillDataset(transaction, commandType, commandText, dataSet, tableNames, null);
7209 }
7210
7211
7212
7213 public static void FillDataset(SqlConnection connection, CommandType commandType, string commandText, DataSet dataSet, string[] tableNames, params SqlParameter[] commandParameters)
7214 {
7215 FillDataset(connection, null, commandType, commandText, dataSet, tableNames, commandParameters);
7216 }
7217
7218 public static void FillDataset(SqlTransaction transaction, CommandType commandType, string commandText, DataSet dataSet, string[] tableNames, params SqlParameter[] commandParameters)
7219 {
7220 FillDataset(transaction.Connection, transaction, commandType, commandText, dataSet, tableNames, commandParameters);
7221 }
7222
7223 private static void FillDataset(SqlConnection connection, SqlTransaction transaction, CommandType commandType, string commandText, DataSet dataSet, string[] tableNames, params SqlParameter[] commandParameters)
7224 {
7225 if (connection == null)
7226 {
7227 throw new ArgumentNullException("connection");
7228 }
7229 if (dataSet == null)
7230 {
7231 throw new ArgumentNullException("dataSet");
7232 }
7233 SqlCommand command = new SqlCommand();
7234 bool mustCloseConnection = false;
7235 PrepareCommand(command, connection, transaction, commandType, commandText, commandParameters, out mustCloseConnection);
7236 using (SqlDataAdapter dataAdapter = new SqlDataAdapter(command))
7237 {
7238 if ((tableNames != null) && (tableNames.Length > 0))
7239 {
7240 string tableName = "Table";
7241 for (int index = 0; index < tableNames.Length; index++)
7242 {
7243 if ((tableNames[index] == null) || (tableNames[index].Length == 0))
7244 {
7245 throw new ArgumentException("The tableNames parameter must contain a list of tables, a value was provided as null or empty string.", "tableNames");
7246 }
7247 dataAdapter.TableMappings.Add(tableName, tableNames[index]);
7248 tableName = tableName + ((index + 1)).ToString();
7249 }
7250 }
7251 dataAdapter.Fill(dataSet);
7252 command.Parameters.Clear();
7253 }
7254 if (mustCloseConnection)
7255 {
7256 connection.Close();
7257 }
7258 }
7259
7260 private static void PrepareCommand(SqlCommand command, SqlConnection connection, SqlTransaction transaction, CommandType commandType, string commandText, SqlParameter[] commandParameters, out bool mustCloseConnection)
7261 {
7262 if (command == null)
7263 {
7264 throw new ArgumentNullException("command");
7265 }
7266 if ((commandText == null) || (commandText.Length == 0))
7267 {
7268 throw new ArgumentNullException("commandText");
7269 }
7270 if (connection.State != ConnectionState.Open)
7271 {
7272 mustCloseConnection = true;
7273 connection.Open();
7274 }
7275 else
7276 {
7277 mustCloseConnection = false;
7278 }
7279 command.Connection = connection;
7280 command.CommandText = commandText;
7281 if (transaction != null)
7282 {
7283 if (transaction.Connection == null)
7284 {
7285 throw new ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "transaction");
7286 }
7287 command.Transaction = transaction;
7288 }
7289 command.CommandType = commandType;
7290 if (commandParameters != null)
7291 {
7292 AttachParameters(command, commandParameters);
7293 }
7294 }
7295
7296 public static void UpdateDataset(SqlCommand insertCommand, SqlCommand deleteCommand, SqlCommand updateCommand, DataSet dataSet, string tableName)
7297 {
7298 if (insertCommand == null)
7299 {
7300 throw new ArgumentNullException("insertCommand");
7301 }
7302 if (deleteCommand == null)
7303 {
7304 throw new ArgumentNullException("deleteCommand");
7305 }
7306 if (updateCommand == null)
7307 {
7308 throw new ArgumentNullException("updateCommand");
7309 }
7310 if ((tableName == null) || (tableName.Length == 0))
7311 {
7312 throw new ArgumentNullException("tableName");
7313 }
7314 using (SqlDataAdapter dataAdapter = new SqlDataAdapter())
7315 {
7316 dataAdapter.UpdateCommand = updateCommand;
7317 dataAdapter.InsertCommand = insertCommand;
7318 dataAdapter.DeleteCommand = deleteCommand;
7319 dataAdapter.Update(dataSet, tableName);
7320 dataSet.AcceptChanges();
7321 }
7322 }
7323
7324 private enum SqlConnectionOwnership
7325 {
7326 Internal,
7327 External
7328 }
7329
7330
7331
7332
7333 /*****************************************************
7334 DataTable helper for MortgageFactFind
7335 Added On : 31/01/2015
7336 Ref :http://www.mroma.net/blog/c-helper-functions-to-map-a-datatable-or-datarow-to-a-class-object/
7337 ******************************************************/
7338
7339 // function that set the given object from the given data row
7340 public static void SetItemFromRow<T>(T item, DataRow row)
7341 where T : new()
7342 {
7343 // go through each column
7344 foreach (DataColumn c in row.Table.Columns)
7345 {
7346 // find the property for the column
7347 PropertyInfo p = item.GetType().GetProperty(c.ColumnName);
7348
7349 // if exists, set the value
7350 if (p != null && row[c] != DBNull.Value)
7351 {
7352 p.SetValue(item, row[c], null);
7353 }
7354 else if (c.DataType.Name == "DateTime")
7355 {
7356 p.SetValue(item, null, null);
7357 }
7358
7359 }
7360 }
7361
7362 // function that creates an object from the given data row
7363 public static T CreateItemFromRow<T>(DataRow row)
7364 where T : new()
7365 {
7366 // create a new object
7367 T item = new T();
7368
7369 // set the item
7370 SetItemFromRow(item, row);
7371
7372 // return
7373 return item;
7374 }
7375
7376
7377 // function that creates a list of an object from the given data table other than fact find
7378 public static List<T> CreateListFromTable<T>(DataTable tbl)
7379 where T : new()
7380 {
7381 // define return list
7382 List<T> lst = new List<T>();
7383
7384 // alocal variable
7385 int count = 0;
7386
7387 // go through each row
7388 foreach (DataRow r in tbl.Rows)
7389 {
7390 // add to the list
7391 lst.Add(CreateItemFromRow<T>(r));
7392 count++;
7393 }
7394
7395 // return the list
7396 return lst;
7397 }
7398
7399
7400
7401}
7402
7403
7404
7405using System;
7406using System.Collections.Generic;
7407using System.Linq;
7408using System.Web;
7409using iTextSharp;
7410using iTextSharp.text;
7411using iTextSharp.text.pdf;
7412using iTextSharp.text.html.simpleparser;
7413using iTextSharp.text.html;
7414using System.IO;
7415using Occfinance.Models;
7416using System.Text;
7417using System.Web.Mvc;
7418using Ionic.Zip;
7419using Mandrill;
7420using Occfinance_Data;
7421using System.Data.SqlClient;
7422using System.Data;
7423using System.Xml.Serialization;
7424using System.Security.Cryptography;
7425using iTextSharp.text;
7426using iTextSharp.text.pdf;
7427using Occfinance.Helpers;
7428
7429
7430namespace Occfinance.Code
7431{
7432 public class WebUtility
7433 {
7434 public static string CreateNewPDF(string Content, string FileName, string logo)
7435 {
7436 //using (MemoryStream myMemoryStream = new MemoryStream())
7437 //{
7438 string attachmentFileName = "";
7439 try
7440 {
7441 var document = new Document();
7442 if (System.IO.File.Exists(HttpContext.Current.Server.MapPath(@"~\Content\PdfReport\TempFiles\" + FileName + ".pdf")))
7443 {
7444 System.IO.File.Delete(HttpContext.Current.Server.MapPath(@"~\Content\PdfReport\TempFiles\" + FileName + ".pdf"));
7445 }
7446 using (FileStream fs = new FileStream((HttpContext.Current.Server.MapPath(@"~\Content\PdfReport\TempFiles\" + FileName + ".pdf")), FileMode.Create))
7447 {
7448 PdfWriter.GetInstance(document, fs);
7449 document.SetPageSize(PageSize.A3.Rotate());
7450 var arial = FontFactory.GetFont("Arial", 6, iTextSharp.text.Color.BLACK);
7451 var arialBold = FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.BOLD, iTextSharp.text.Color.BLACK);
7452
7453 document.Open();
7454
7455 iTextSharp.text.html.simpleparser.StyleSheet styles = new iTextSharp.text.html.simpleparser.StyleSheet();
7456 iTextSharp.text.html.simpleparser.HTMLWorker hw = new iTextSharp.text.html.simpleparser.HTMLWorker(document);
7457 hw.Style = GenerateNewStyleSheet();
7458
7459 //string imagepath = HttpContext.Current.Server.MapPath(@"~\Content\Images");
7460
7461 //Image gif = Image.GetInstance(imagepath + "/" + logo);
7462 //document.Add(gif);
7463
7464 hw.Parse(new StringReader(Content.ToString()));
7465
7466 if (System.IO.File.Exists(HttpContext.Current.Server.MapPath(@"~\Content\PdfReport\TempFiles\" + FileName + ".pdf")))
7467 {
7468 attachmentFileName = HttpContext.Current.Server.MapPath(@"~\Content\PdfReport\TempFiles\" + FileName + ".pdf");
7469 }
7470
7471 document.Close();
7472 }
7473
7474 }
7475 catch (Exception ex)
7476 {
7477 Helper.ErrorLog(ex.InnerException, "WebUtility", "CreateNewPDF", ex.Message);
7478 }
7479 return attachmentFileName;
7480 }
7481
7482 public static string CreateNewPDFCommon(string Content, string FileName, string logo)
7483 {
7484 //using (MemoryStream myMemoryStream = new MemoryStream())
7485 //{
7486 string attachmentFileName = "";
7487 var document = new Document();
7488 try
7489 {
7490
7491 if (System.IO.File.Exists(HttpContext.Current.Server.MapPath(@"~\Content\PdfReport\" + FileName + ".pdf")))
7492 {
7493 System.IO.File.Delete(HttpContext.Current.Server.MapPath(@"~\Content\PdfReport\" + FileName + ".pdf"));
7494 }
7495
7496 using (FileStream fs = new FileStream((HttpContext.Current.Server.MapPath(@"~\Content\PdfReport\" + FileName + ".pdf")), FileMode.Create))
7497 {
7498
7499 PdfWriter.GetInstance(document, fs);
7500 document.SetPageSize(PageSize.A3.Rotate());
7501 var arial = FontFactory.GetFont("Arial", 6, iTextSharp.text.Color.BLACK);
7502 var arialBold = FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.BOLD, iTextSharp.text.Color.BLACK);
7503
7504 document.Open();
7505
7506 iTextSharp.text.html.simpleparser.StyleSheet styles = new iTextSharp.text.html.simpleparser.StyleSheet();
7507 iTextSharp.text.html.simpleparser.HTMLWorker hw = new iTextSharp.text.html.simpleparser.HTMLWorker(document);
7508 hw.Style = GenerateNewStyleSheet();
7509
7510 //string imagepath = HttpContext.Current.Server.MapPath(@"~\Content\Images");
7511
7512 //Image gif = Image.GetInstance(imagepath + "/" + logo);
7513 //document.Add(gif);
7514
7515 hw.Parse(new StringReader(Content.ToString()));
7516
7517 if (System.IO.File.Exists(HttpContext.Current.Server.MapPath(@"~\Content\PdfReport\" + FileName + ".pdf")))
7518 {
7519 attachmentFileName = HttpContext.Current.Server.MapPath(@"~\Content\PdfReport\" + FileName + ".pdf");
7520 }
7521
7522 document.Close();
7523
7524
7525 // HttpContext.Current.Response.AddHeader("Content-Disposition", string.Format("attachment;filename={0}.pdf", FileName));
7526 // HttpContext.Current.Response.BinaryWrite(fs.ToArray());
7527
7528 }
7529 }
7530 catch
7531 {
7532
7533 }
7534 return attachmentFileName;
7535 }
7536
7537 public static void CreateNewPDFDirectly(string Content, string FileName, string logo)
7538 {
7539 var document = new Document();
7540 HttpContext.Current.Response.AddHeader("Content-disposition", "attachment; filename=" + FileName + ".pdf");
7541 HttpContext.Current.Response.ContentType = "application/octet-stream";
7542 try
7543 {
7544
7545 if (System.IO.File.Exists(HttpContext.Current.Server.MapPath(@"~\Content\PdfReport\" + FileName + ".pdf")))
7546 {
7547 System.IO.File.Delete(HttpContext.Current.Server.MapPath(@"~\Content\PdfReport\" + FileName + ".pdf"));
7548 }
7549
7550 using (FileStream fs = new FileStream((HttpContext.Current.Server.MapPath(@"~\Content\PdfReport\" + FileName + ".pdf")), FileMode.Create))
7551 {
7552
7553 PdfWriter.GetInstance(document, fs);
7554 document.SetPageSize(PageSize.A3.Rotate());
7555 //document.SetPageSize(PageSize.A4.Rotate());
7556 var arial = FontFactory.GetFont("Arial", 6, iTextSharp.text.Color.BLACK);
7557 var arialBold = FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.BOLD, iTextSharp.text.Color.BLACK);
7558
7559 document.Open();
7560
7561 iTextSharp.text.html.simpleparser.StyleSheet styles = new iTextSharp.text.html.simpleparser.StyleSheet();
7562 iTextSharp.text.html.simpleparser.HTMLWorker hw = new iTextSharp.text.html.simpleparser.HTMLWorker(document);
7563 hw.Style = GenerateNewStyleSheet();
7564
7565 //string imagepath = HttpContext.Current.Server.MapPath(@"~\Content\Images");
7566
7567 //Image gif = Image.GetInstance(imagepath + "/" + logo);
7568 //document.Add(gif);
7569
7570 hw.Parse(new StringReader(Content.ToString()));
7571 document.Close();
7572 }
7573 }
7574 catch
7575 {
7576
7577 }
7578
7579 }
7580 public static void CreateFactFindPdf(string Content, string FileName, string logo)
7581 {
7582 var document = new Document();
7583 HttpContext.Current.Response.AddHeader("Content-disposition", "attachment; filename=" + FileName + ".pdf");
7584 HttpContext.Current.Response.ContentType = "application/octet-stream";
7585 try
7586 {
7587
7588 if (System.IO.File.Exists(HttpContext.Current.Server.MapPath(@"~\Content\PdfReport\" + FileName + ".pdf")))
7589 {
7590 System.IO.File.Delete(HttpContext.Current.Server.MapPath(@"~\Content\PdfReport\" + FileName + ".pdf"));
7591 }
7592
7593 using (FileStream fs = new FileStream((HttpContext.Current.Server.MapPath(@"~\Content\PdfReport\" + FileName + ".pdf")), FileMode.Create))
7594 {
7595
7596 PdfWriter.GetInstance(document, fs);
7597 document.SetPageSize(PageSize.A3.Rotate());
7598 //document.SetPageSize(PageSize.A4.Rotate());
7599
7600 var arial = FontFactory.GetFont("Arial", 6, iTextSharp.text.Color.BLACK);
7601 var arialBold = FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.BOLD, iTextSharp.text.Color.BLACK);
7602
7603 document.Open();
7604
7605 iTextSharp.text.html.simpleparser.StyleSheet styles = new iTextSharp.text.html.simpleparser.StyleSheet();
7606 iTextSharp.text.html.simpleparser.HTMLWorker hw = new iTextSharp.text.html.simpleparser.HTMLWorker(document);
7607 hw.Style = FactFindStyleSheet();
7608
7609 //string imagepath = HttpContext.Current.Server.MapPath(@"~\Content\Images");
7610
7611 //Image gif = Image.GetInstance(imagepath + "/" + logo);
7612 //document.Add(gif);
7613 //
7614
7615 //
7616 hw.Parse(new StringReader(Content.ToString()));
7617 document.Close();
7618 }
7619 }
7620 catch
7621 {
7622
7623 }
7624
7625 }
7626 public static void CreateApplicationPDF(string Content, string FileName, string logo)
7627 {
7628 var document = new Document();
7629 HttpContext.Current.Response.AddHeader("Content-disposition", "attachment; filename=" + FileName + ".pdf");
7630 HttpContext.Current.Response.ContentType = "application/octet-stream";
7631 try
7632 {
7633
7634 if (System.IO.File.Exists(HttpContext.Current.Server.MapPath(@"~\Content\PdfReport\" + FileName + ".pdf")))
7635 {
7636 System.IO.File.Delete(HttpContext.Current.Server.MapPath(@"~\Content\PdfReport\" + FileName + ".pdf"));
7637 }
7638
7639 using (FileStream fs = new FileStream((HttpContext.Current.Server.MapPath(@"~\Content\PdfReport\" + FileName + ".pdf")), FileMode.Create))
7640 {
7641
7642 PdfWriter.GetInstance(document, fs);
7643 //document.SetPageSize(PageSize.A3.Rotate());
7644 document.SetPageSize(PageSize.A4.Rotate());
7645
7646 var arial = FontFactory.GetFont("Arial", 6, iTextSharp.text.Color.BLACK);
7647 var arialBold = FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.BOLD, iTextSharp.text.Color.BLACK);
7648
7649 document.Open();
7650
7651 iTextSharp.text.html.simpleparser.StyleSheet styles = new iTextSharp.text.html.simpleparser.StyleSheet();
7652 iTextSharp.text.html.simpleparser.HTMLWorker hw = new iTextSharp.text.html.simpleparser.HTMLWorker(document);
7653 hw.Style = FactFindStyleSheet();
7654
7655 //string imagepath = HttpContext.Current.Server.MapPath(@"~\Content\Images");
7656
7657 //Image gif = Image.GetInstance(imagepath + "/" + logo);
7658 //document.Add(gif);
7659 //
7660
7661 //
7662 hw.Parse(new StringReader(Content.ToString()));
7663 document.Close();
7664 }
7665 }
7666 catch (Exception ex)
7667 {
7668
7669 }
7670 }
7671 private static StyleSheet GenerateNewStyleSheet()
7672 {
7673 StyleSheet css = new StyleSheet();
7674 try
7675 {
7676 css.LoadTagStyle(HtmlTags.TABLE, HtmlTags.BACKGROUNDCOLOR, "#FFFFFF");
7677 css.LoadTagStyle(HtmlTags.TABLE, HtmlTags.BORDERWIDTH, "0.5");
7678 css.LoadTagStyle(HtmlTags.TABLE, HtmlTags.BORDERCOLOR, "#000");
7679 css.LoadTagStyle(HtmlTags.TABLE, HtmlTags.CELLPADDING, "5");
7680 css.LoadTagStyle(HtmlTags.TABLE, HtmlTags.RIGHTMARGIN, "50");
7681 css.LoadTagStyle(HtmlTags.TABLE, HtmlTags.LEFTMARGIN, "50");
7682 css.LoadTagStyle(HtmlTags.TABLE, HtmlTags.TOPMARGIN, "50");
7683 css.LoadTagStyle(HtmlTags.TABLE, HtmlTags.BOTTOMMARGIN, "50");
7684 css.LoadTagStyle(HtmlTags.TABLE, HtmlTags.WIDTH, "100%");
7685
7686 }
7687 catch
7688 {
7689 }
7690 return css;
7691 }
7692
7693 private static StyleSheet FactFindStyleSheet()
7694 {
7695 StyleSheet css = new StyleSheet();
7696 try
7697 {
7698 //css.LoadTagStyle(HtmlTags.TABLE, HtmlTags.BACKGROUNDCOLOR, "#FFFFFF");
7699 //css.LoadTagStyle(HtmlTags.TABLE, HtmlTags.BORDERWIDTH, "0.5");
7700 //css.LoadTagStyle(HtmlTags.TABLE, HtmlTags.BORDERCOLOR, "#000");
7701 //css.LoadTagStyle(HtmlTags.TABLE, HtmlTags.CELLPADDING, "5");
7702 //css.LoadTagStyle(HtmlTags.TABLE, HtmlTags.RIGHTMARGIN, "50");
7703 //css.LoadTagStyle(HtmlTags.TABLE, HtmlTags.LEFTMARGIN, "50");
7704 //css.LoadTagStyle(HtmlTags.TABLE, HtmlTags.TOPMARGIN, "50");
7705 //css.LoadTagStyle(HtmlTags.TABLE, HtmlTags.BOTTOMMARGIN, "50");
7706 //css.LoadTagStyle(HtmlTags.TABLE, HtmlTags.WIDTH, "100%");
7707
7708
7709 css.LoadTagStyle(HtmlTags.DIV, HtmlTags.FONT, "inherit");
7710 css.LoadTagStyle(HtmlTags.DIV, HtmlTags.VERTICALALIGN, "baseline");
7711 css.LoadTagStyle(HtmlTags.DIV, HtmlTags.BORDERWIDTH, "0");
7712 css.LoadTagStyle(HtmlTags.DIV, HtmlTags.BOTTOMMARGIN, "0");
7713 css.LoadTagStyle(HtmlTags.DIV, HtmlTags.TOPMARGIN, "0");
7714 css.LoadTagStyle(HtmlTags.DIV, HtmlTags.RIGHTMARGIN, "0");
7715 css.LoadTagStyle(HtmlTags.DIV, HtmlTags.LEFTMARGIN, "0");
7716
7717 css.LoadTagStyle(HtmlTags.BODY, HtmlTags.FONT, "inherit");
7718 css.LoadTagStyle(HtmlTags.BODY, HtmlTags.VERTICALALIGN, "baseline");
7719 css.LoadTagStyle(HtmlTags.BODY, HtmlTags.BORDERWIDTH, "0");
7720 css.LoadTagStyle(HtmlTags.BODY, HtmlTags.BOTTOMMARGIN, "0");
7721 css.LoadTagStyle(HtmlTags.BODY, HtmlTags.TOPMARGIN, "0");
7722 css.LoadTagStyle(HtmlTags.BODY, HtmlTags.RIGHTMARGIN, "0");
7723 css.LoadTagStyle(HtmlTags.BODY, HtmlTags.LEFTMARGIN, "0");
7724
7725 css.LoadTagStyle(HtmlTags.HTML, HtmlTags.FONT, "inherit");
7726 css.LoadTagStyle(HtmlTags.HTML, HtmlTags.VERTICALALIGN, "baseline");
7727 css.LoadTagStyle(HtmlTags.HTML, HtmlTags.BORDERWIDTH, "0");
7728 css.LoadTagStyle(HtmlTags.HTML, HtmlTags.BOTTOMMARGIN, "0");
7729 css.LoadTagStyle(HtmlTags.HTML, HtmlTags.TOPMARGIN, "0");
7730 css.LoadTagStyle(HtmlTags.HTML, HtmlTags.RIGHTMARGIN, "0");
7731 css.LoadTagStyle(HtmlTags.HTML, HtmlTags.LEFTMARGIN, "0");
7732
7733 css.LoadStyle("clear", "clear", "both");
7734
7735 css.LoadStyle("wrapper", "width", "800px");
7736 css.LoadStyle("wrapper", "margin", "25px auto");
7737
7738 css.LoadStyle("pf_title", "padding", "32px 0 10px 0");
7739 css.LoadStyle("pf_title", "font-size", "35px");
7740 css.LoadStyle("pf_title", "color", "#0059a6");
7741 css.LoadStyle("pf_title", "font-weight", "bold");
7742 css.LoadStyle("pf_title", "border-top", "solid 10px #0059a6");
7743 css.LoadStyle("pf_title", "margin", "32px 0 0 0");
7744
7745 css.LoadStyle("protection_facttable", "width", "100%");
7746 css.LoadStyle("protection_facttable", "font-size", "16px");
7747 css.LoadStyle("protection_facttable", "margin", "25px auto");
7748 css.LoadStyle("protection_facttable", "color", "#7f7f7f");
7749
7750 css.LoadStyle("protection_facttable tbody tr td", "padding", "10px");
7751 css.LoadStyle("protection_facttable tbody tr td", "border", "solid 1px #bdbec1");
7752
7753 css.LoadStyle("protection_facttable tbody tr th", "padding", "10px");
7754 css.LoadStyle("protection_facttable tbody tr th", "border", "solid 1px #bdbec1");
7755 css.LoadStyle("protection_facttable tbody tr th", "background", "#0059a6");
7756 css.LoadStyle("protection_facttable tbody tr th", "color", "#fff");
7757 css.LoadStyle("protection_facttable tbody tr th", "font-weight", "bold");
7758
7759
7760 css.LoadStyle("header_section", "padding", "15px 0 0 0");
7761 css.LoadStyle("header_section", "margin", "15px 0");
7762 css.LoadStyle("header_section", "border-top", "solid 5px #0059a6");
7763
7764 css.LoadStyle("header_section ul", "padding", "0");
7765 css.LoadStyle("header_section ul", "margin", "0");
7766 css.LoadStyle("header_section ul", "list-style", "none");
7767
7768 css.LoadStyle("header_section ul li", "padding", "0");
7769 css.LoadStyle("header_section ul li", "margin", "0");
7770 css.LoadStyle("header_section ul li", "font-size", "18px");
7771 css.LoadStyle("header_section ul li", "color", "#0059a6");
7772 css.LoadStyle("header_section ul li", "font-weight", "normal");
7773 css.LoadStyle("header_section ul li", "display", "inline");
7774
7775 css.LoadStyle("header_section ul li:first-child", "background", "#0059a6");
7776 css.LoadStyle("header_section ul li:first-child", "color", "#fff");
7777 css.LoadStyle("header_section ul li:first-child", "padding", "15px 30px");
7778
7779 css.LoadStyle("header_section ul li.mrgn", "margin", "0 180px !important");
7780
7781
7782 }
7783 catch
7784 {
7785 }
7786 return css;
7787 }
7788
7789 public static void DownloadAsZip(string[] filepaths)
7790 {
7791 using (ZipFile zip = new ZipFile())
7792 {
7793 zip.AlternateEncodingUsage = ZipOption.AsNecessary;
7794 zip.AddDirectoryByName("Client Notes");
7795 foreach (var fpath in filepaths)
7796 {
7797 string filePath = fpath;
7798 zip.AddFile(filePath, "Client Notes");
7799 }
7800 HttpContext.Current.Response.Clear();
7801 HttpContext.Current.Response.ClearContent(); // Add this line
7802 HttpContext.Current.Response.ClearHeaders(); // Add this line
7803 HttpContext.Current.Response.BufferOutput = true;
7804 string zipName = String.Format("Client_Notes(Confidential).zip", DateTime.Now.ToString("yyyy-MMM-dd-HHmmss"));
7805 HttpContext.Current.Response.ContentType = "application/zip";
7806 HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=" + zipName);
7807 zip.Save(HttpContext.Current.Response.OutputStream);
7808 HttpContext.Current.Response.End();
7809 }
7810 }
7811 public static void SaveAsZip(string[] filepaths)
7812 {
7813 using (ZipFile zip = new ZipFile())
7814 {
7815 zip.AlternateEncodingUsage = ZipOption.AsNecessary;
7816 zip.AddDirectoryByName("Client Notes");
7817 foreach (var fpath in filepaths)
7818 {
7819 string filePath = fpath;
7820 zip.AddFile(filePath, "Client Notes");
7821 }
7822 //HttpContext.Current.Response.Clear();
7823 //HttpContext.Current.Response.ClearContent(); // Add this line
7824 //HttpContext.Current.Response.ClearHeaders(); // Add this line
7825 //HttpContext.Current.Response.BufferOutput = true;
7826 string zipName = String.Format("Client_Notes(Confidential).zip", DateTime.Now.ToString("yyyy-MMM-dd-HHmmss"));
7827 // HttpContext.Current.Response.ContentType = "application/zip";
7828 //HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=" + zipName);
7829 zip.Save(HttpContext.Current.Server.MapPath(@"~\Content\PdfReport\TempFiles\" + zipName));
7830 //HttpContext.Current.Response.End();
7831 }
7832 }
7833 public static void DownloadAsZip(string[] filepaths, string FileName)
7834 {
7835 using (ZipFile zip = new ZipFile())
7836 {
7837 zip.AlternateEncodingUsage = ZipOption.AsNecessary;
7838 zip.AddDirectoryByName(FileName);
7839 foreach (var fpath in filepaths)
7840 {
7841 string filePath = fpath;
7842 zip.AddFile(filePath, FileName);
7843 }
7844 HttpContext.Current.Response.Clear();
7845 HttpContext.Current.Response.ClearContent(); // Add this line
7846 HttpContext.Current.Response.ClearHeaders(); // Add this line
7847 HttpContext.Current.Response.BufferOutput = true;
7848 string zipName = String.Format(FileName + ".zip", DateTime.Now.ToString("yyyy-MMM-dd-HHmmss"));
7849 HttpContext.Current.Response.ContentType = "application/zip";
7850 HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=" + zipName);
7851 zip.Save(HttpContext.Current.Response.OutputStream);
7852 HttpContext.Current.Response.End();
7853 }
7854 }
7855
7856
7857 public static string GetBreaker(string fileName)
7858 {
7859 string cacheBreaker = null;
7860 try
7861 {
7862 HttpContext.Current.Server.MapPath(fileName.Substring(1));
7863
7864 if (fileName.StartsWith("~"))
7865 {
7866 //fileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, fileName.Remove(0));
7867 fileName = HttpContext.Current.Server.MapPath(fileName.Substring(1));
7868 }
7869 cacheBreaker = File.GetLastWriteTime(fileName).ToFileTime().ToString();
7870 }
7871 catch { }
7872
7873 return string.IsNullOrEmpty(cacheBreaker) ? string.Empty : string.Format("?cachebreaker={0}", cacheBreaker);
7874
7875 }
7876 /// <summary>
7877 /// Converting Company and Branches name fron string to strign array
7878 /// </summary>
7879 /// <param name="companyandBranches">Company and Branches name in string</param>
7880 /// <returns></returns>
7881 public static string[] GetCompaniesAndBranches(string companyandBranches)
7882 {
7883 // Get Company and Branch Names
7884 string[] CompanyBranches = new string[2];
7885 string _allCompBranches = "";
7886 string[] _bandcompanyNames = null;
7887
7888 var cm = "";
7889 var bm = "";
7890 try
7891 {
7892 if (!string.IsNullOrWhiteSpace(companyandBranches))
7893 {
7894 _allCompBranches = companyandBranches;
7895 _bandcompanyNames = _allCompBranches.Split(')');
7896 }
7897 if (_bandcompanyNames != null)
7898 {
7899 foreach (var cname in _bandcompanyNames)
7900 {
7901
7902 if (cname.Split('(').Count() > 0)
7903 {
7904 cm += System.Text.RegularExpressions.Regex.Replace(cname.Split('(')[0].Trim(), @"\s", "") + ",";
7905
7906 if (cname.Split('(').Count() > 1)
7907 {
7908
7909 string allBracnhes = System.Text.RegularExpressions.Regex.Replace(cname.Split('(')[1].Trim(), @"\s", "");
7910 string[] allBracnhesarray = allBracnhes.Split(new char[] { ',' }, 2).Select(c => c.Trim()).Distinct().ToArray();
7911
7912 string updatedValue = "";
7913
7914 if (allBracnhesarray.Count() > 1 && allBracnhesarray[0] == "")
7915 // Check when the first branch is blank mean "Office"
7916 {
7917 updatedValue = System.Text.RegularExpressions.Regex.Replace(cname.Split('(')[0].Trim(), @"\s", "").ToLower() + "office" + "," + allBracnhesarray[1].Trim().Trim(',');
7918 }
7919 else if (allBracnhesarray.Count() == 1 && allBracnhesarray[0] == "")
7920 {
7921 updatedValue = System.Text.RegularExpressions.Regex.Replace(cname.Split('(')[0].Trim(), @"\s", "").ToLower() + "office";
7922 }
7923 else
7924 {
7925 updatedValue = System.Text.RegularExpressions.Regex.Replace(cname.Split('(')[1].Trim().ToLower(), @"\s", "").ToLower();
7926 }
7927 bm += updatedValue + ",";
7928 }
7929 }
7930
7931 }
7932
7933 CompanyBranches[0] = cm.Trim(',').TrimEnd(',');
7934 CompanyBranches[1] = bm.Trim(',').TrimEnd(',');
7935
7936 }
7937 }
7938 catch (Exception ex)
7939 {
7940 Helper.ErrorLog(ex.InnerException, "Webutility", "GetCompaniesAndBranches");
7941 }
7942
7943 return CompanyBranches;
7944 //End *****************************************************************
7945 }
7946 public static bool SendMailViaManDRILL(List<ManDRILLModel> messagelist, int loggedinuserid, bool isFollowUp = false)
7947 {
7948 bool _status = false;
7949 db_occfinance_5572Entities ctx = new db_occfinance_5572Entities();
7950 Q_settings QSetting = new Q_settings();
7951 try
7952 {
7953 if (messagelist != null && messagelist.Count() > 0)
7954 {
7955 Mandrill.MandrillApi mandrillApi = new Mandrill.MandrillApi(System.Configuration.ConfigurationManager.AppSettings["MANDRILLSMTP_PASSWORD"], false);
7956 int i = 0;
7957 foreach (var objMSG in messagelist)
7958 {
7959 var results = mandrillApi.SendMessage(objMSG.MandrillMSG);
7960 if (results != null && results.Count() > 0)
7961 {
7962 if (results[0].Status == EmailResultStatus.Sent || results[0].Status == EmailResultStatus.Queued || results[0].Status == EmailResultStatus.Scheduled)
7963 {
7964
7965 try
7966 {
7967 if (objMSG.financeid > 0 && objMSG.IsAppContact == false)
7968 {
7969 string tName = objMSG.TemplateName ?? "";
7970 Q_Application _qA = new Q_Application();
7971 //int _noteid = _qA.getNoteID();
7972 tblnote _note = new tblnote();
7973 //_note.noteid = _noteid;
7974 _note.financeid = objMSG.financeid;
7975 _note.contact = objMSG.contactId;
7976 _note.note = "Email template (" + tName + ") sent to client on (" + DateTime.Now.ToString("dd/MM/yyyy") + ") at (" + DateTime.Now.ToString("HH:mm") + ")"; //objMSG.notemsg;
7977 _note.created = System.DateTime.Now;
7978 _note.UserId = loggedinuserid;
7979 ctx.tblnotes.Add(_note);
7980 ctx.SaveChanges();
7981
7982 // added on 28 01 2015 for followup
7983 if (isFollowUp)
7984 {
7985 // Update Followupdate 2 days from current date when status is Remortgage********************************************
7986 if (objMSG.Status == 2)
7987 {
7988 tblfinance finance = ctx.tblfinances.Where(x => x.financeid == objMSG.financeid).FirstOrDefault();
7989 //update finance.
7990 if (finance != null)
7991 {
7992 finance.followup = Occfinance.Helpers.Helper.GetFollowUp(DateTime.Now.AddDays(2).ToString("dd/MM/yyyy"), (DateTime.Now.Hour + ":" + DateTime.Now.Minute + ":" + DateTime.Now.Second).ToString());
7993 }
7994 ctx.SaveChanges();
7995 }
7996 //*****************************************************************************************
7997 }
7998 }
7999 }
8000 catch
8001 {
8002 }
8003 if (i == 0)
8004 _status = true;
8005 var email = "";
8006 if (objMSG.MandrillMSG.to != null && objMSG.MandrillMSG.to.Count() > 0)
8007 email = objMSG.MandrillMSG.to.ToList()[0].email;
8008
8009 // Add Into the track Table with sent status
8010 QSetting.EmailTrackingAdd(loggedinuserid, objMSG.contactId, email, objMSG.MandrillMSG.html, objMSG.IsAppContact, loggedinuserid, "", "", "", false, "", 0, "", "", "", 0, false, 2);
8011
8012
8013 }
8014 }
8015 i++;
8016 }
8017 }
8018
8019 }
8020 catch
8021 {
8022 }
8023 return _status;
8024 }
8025 public static bool SendMailViaManDRILLForBulkEmail(List<ManDRILLModel> messagelist, int loggedinuserid, bool isFollowUp = false)
8026 {
8027 bool _status = false;
8028 db_occfinance_5572Entities ctx = new db_occfinance_5572Entities();
8029 Q_settings QSetting = new Q_settings();
8030 try
8031 {
8032
8033 if (messagelist != null && messagelist.Any())
8034 {
8035 // Mandrill.MandrillApi mandrillApi = new Mandrill.MandrillApi(System.Configuration.ConfigurationManager.AppSettings["MANDRILLSMTP_PASSWORD"], false);
8036 int i = 0;
8037 foreach (var objMSG in messagelist)
8038 {
8039 //var results = mandrillApi.SendMessage(objMSG.MandrillMSG);
8040 //if (results != null && results.Count() > 0)
8041 //{
8042 //if (results[0].Status == EmailResultStatus.Sent || results[0].Status == EmailResultStatus.Queued || results[0].Status == EmailResultStatus.Scheduled)
8043 //{
8044 //try
8045 //{
8046 //if (objMSG.financeid > 0 && objMSG.IsAppContact == false)
8047 //{
8048 // string tName = objMSG.TemplateName ?? "";
8049 // Q_Application _qA = new Q_Application();
8050 // //int _noteid = _qA.getNoteID();
8051 // tblnote _note = new tblnote();
8052 // //_note.noteid = _noteid;
8053 // _note.financeid = objMSG.financeid;
8054 // _note.contact = objMSG.contactId;
8055 // _note.note = "Email template (" + tName + ") sent to client on (" + DateTime.Now.ToString("dd/MM/yyyy") + ") at (" + DateTime.Now.ToString("HH:mm") + ")"; //objMSG.notemsg;
8056 // _note.created = System.DateTime.Now;
8057 // _note.UserId = loggedinuserid;
8058 // ctx.tblnotes.Add(_note);
8059 // ctx.SaveChanges();
8060
8061 // // added on 28 01 2015 for followup
8062 // if (isFollowUp)
8063 // {
8064 // // Update Followupdate 2 days from current date when status is Remortgage********************************************
8065 // if (objMSG.Status == 2)
8066 // {
8067 // tblfinance finance = ctx.tblfinances.Where(x => x.financeid == objMSG.financeid).FirstOrDefault();
8068 // //update finance.
8069 // if (finance != null)
8070 // {
8071 // finance.followup = Occfinance.Helpers.Helper.GetFollowUp(DateTime.Now.AddDays(2).ToString("dd/MM/yyyy"), (DateTime.Now.Hour + ":" + DateTime.Now.Minute + ":" + DateTime.Now.Second).ToString());
8072 // }
8073 // ctx.SaveChanges();
8074 // }
8075 // //*****************************************************************************************
8076 // }
8077 //}
8078 // }
8079 // catch
8080 //{
8081 // }
8082 //if (i == 0)
8083 //_status = true;
8084 var email = "";
8085 if (objMSG.MandrillMSG.to != null && objMSG.MandrillMSG.to.Count() > 0)
8086 email = objMSG.MandrillMSG.to.ToList()[0].email;
8087
8088 // Add Into the track Table with pending status
8089 QSetting.EmailTrackingAdd(loggedinuserid, objMSG.contactId, email, objMSG.MandrillMSG.html, objMSG.IsAppContact, loggedinuserid, objMSG.MandrillMSG.from_email, objMSG.MandrillMSG.from_name, objMSG.MandrillMSG.subject, objMSG.MandrillMSG.inline_css, objMSG.MandrillMSG.signing_domain, objMSG.financeid, objMSG.mailcontent, objMSG.notemsg, objMSG.TemplateName, objMSG.Status, isFollowUp, 1, objMSG.MandrillMSG.to);
8090 _status = true;
8091
8092
8093 // }
8094 // }
8095 //i++;
8096 }
8097
8098
8099 }
8100
8101 }
8102 catch
8103 {
8104 _status = false;
8105 }
8106 return _status;
8107 }
8108
8109
8110 #region [Unsubscribe Email]
8111
8112 /// <summary>
8113 /// Unsubscribed email for a contact
8114 /// </summary>
8115 /// <param name="contactId">contact id</param>
8116 /// <param name="Type">Insert -1, Delete -2</param>
8117 /// <returns></returns>
8118 public static int UnsubscribeEmail(int contactId, int type)
8119 {
8120 int result = 0;
8121 SqlParameter[] Param = new SqlParameter[2];
8122 Param[0] = new SqlParameter("@ContactId", contactId);
8123 Param[1] = new SqlParameter("@Type", type);
8124 DataTable dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "proc_InsertOrDeleteUnsubscribedListDetails", Param);
8125 result = Convert.ToInt32(dt.Rows[0][0]);
8126 return result;
8127 }
8128
8129 #endregion [Unsubscribe Email]
8130 #region[Encrypt and Decrypt]
8131 const string passphrase = "password";
8132 public static string EncryptData(string Message)
8133 {
8134
8135 byte[] Results;
8136 System.Text.UTF8Encoding UTF8 = new System.Text.UTF8Encoding();
8137 MD5CryptoServiceProvider HashProvider = new MD5CryptoServiceProvider();
8138 byte[] TDESKey = HashProvider.ComputeHash(UTF8.GetBytes(passphrase));
8139 TripleDESCryptoServiceProvider TDESAlgorithm = new TripleDESCryptoServiceProvider();
8140 TDESAlgorithm.Key = TDESKey;
8141 TDESAlgorithm.Mode = CipherMode.ECB;
8142 TDESAlgorithm.Padding = PaddingMode.PKCS7;
8143 byte[] DataToEncrypt = UTF8.GetBytes(Message);
8144 try
8145 {
8146 ICryptoTransform Encryptor = TDESAlgorithm.CreateEncryptor();
8147 Results = Encryptor.TransformFinalBlock(DataToEncrypt, 0, DataToEncrypt.Length);
8148 }
8149 finally
8150 {
8151 TDESAlgorithm.Clear();
8152 HashProvider.Clear();
8153 }
8154 return Convert.ToBase64String(Results);
8155 }
8156 public static string DecryptString(string Message)
8157 {
8158
8159 byte[] Results;
8160 System.Text.UTF8Encoding UTF8 = new System.Text.UTF8Encoding();
8161 MD5CryptoServiceProvider HashProvider = new MD5CryptoServiceProvider();
8162 byte[] TDESKey = HashProvider.ComputeHash(UTF8.GetBytes(passphrase));
8163 TripleDESCryptoServiceProvider TDESAlgorithm = new TripleDESCryptoServiceProvider();
8164 TDESAlgorithm.Key = TDESKey;
8165 TDESAlgorithm.Mode = CipherMode.ECB;
8166 TDESAlgorithm.Padding = PaddingMode.PKCS7;
8167 byte[] DataToDecrypt = Convert.FromBase64String(Message);
8168 try
8169 {
8170 ICryptoTransform Decryptor = TDESAlgorithm.CreateDecryptor();
8171 Results = Decryptor.TransformFinalBlock(DataToDecrypt, 0, DataToDecrypt.Length);
8172 }
8173 finally
8174 {
8175 TDESAlgorithm.Clear();
8176 HashProvider.Clear();
8177 }
8178 return UTF8.GetString(Results);
8179 }
8180 #endregion[Encrypt and Decrypt]
8181
8182
8183 }
8184}
8185
8186using System.Web;
8187
8188namespace Occfinance.Common
8189{
8190 public static class ApplicationContext
8191 {
8192
8193 public static LoggedInUserDetails LoggedInUser
8194 {
8195 get
8196 {
8197 if (HttpContext.Current.Session["LoggedInUserDetails"] == null)
8198 {
8199 return null;
8200 }
8201 else
8202 {
8203 return (LoggedInUserDetails)HttpContext.Current.Session["LoggedInUserDetails"];
8204 }
8205 }
8206 set
8207 {
8208 HttpContext.Current.Session["LoggedInUserDetails"] = value;
8209 }
8210 }
8211
8212 public static UseOnReport ReportUses
8213 {
8214 get
8215 {
8216 if (HttpContext.Current.Session["UseOnReport"] == null)
8217 {
8218 return null;
8219 }
8220 else
8221 {
8222 return (UseOnReport)HttpContext.Current.Session["UseOnReport"];
8223 }
8224 }
8225 set
8226 {
8227 HttpContext.Current.Session["UseOnReport"] = value;
8228 }
8229 }
8230 }
8231}