Ejemplo n.º 1
0
        private void DoBind()
        {
            int clientID = 0;

            clientID = SessionHelper.getClientId();

            var predicate = PredicateBuilder.True <CRM.Data.Entities.Leads>();
            int userLead  = Convert.ToInt32(Session["UserId"]);

            if (!String.IsNullOrWhiteSpace(hfFromDate.Value))
            {
                DateTime sDate = new DateTime(Convert.ToInt32(hfFromDate.Value.Trim().Substring(6, 4)), Convert.ToInt32(hfFromDate.Value.Trim().Substring(3, 2)), Convert.ToInt32(hfFromDate.Value.Trim().Substring(0, 2)));

                var datefrom = Convert.ToDateTime(sDate);
                predicate = predicate.And(Lead => Lead.OriginalLeadDate >= datefrom
                                          );
            }
            if (!String.IsNullOrWhiteSpace(hfToDate.Value))
            {
                DateTime sDate = new DateTime(Convert.ToInt32(hfToDate.Value.Trim().Substring(6, 4)), Convert.ToInt32(hfToDate.Value.Trim().Substring(3, 2)), Convert.ToInt32(hfToDate.Value.Trim().Substring(0, 2)));

                var dateto = Convert.ToDateTime(sDate);
                predicate = predicate.And(Lead => Lead.OriginalLeadDate <= dateto
                                          );
            }


            predicate = predicate.And(Lead => Lead.UserId == userLead);

            // 2013-10-22
            predicate = predicate.And(Lead => Lead.LeadPolicy.Any(x => x.IsActive));

            // tortega 2013-08-02 - get lead for client id
            if ((roleID == (int)UserRole.Client || roleID == (int)UserRole.SiteAdministrator) && clientID > 0)
            {
                predicate = predicate.And(Lead => Lead.ClientID == clientID);
            }


            objLead = LeadsManager.GetPredicate(predicate);

            if (objLead != null && objLead.Count > 0)
            {
                gvUserLeads.DataSource = objLead;
                gvUserLeads.DataBind();
            }
            else
            {
                gvUserLeads.DataSource = null;
                gvUserLeads.DataBind();
            }
            bindAllLeads();

            // 2013-07-17
            bindTasks();
        }
Ejemplo n.º 2
0
        public void SortGrid(string expression, bool fromSort, string Grid)
        {
            int userLead  = Convert.ToInt32(Session["UserId"]);
            var predicate = PredicateBuilder.True <CRM.Data.Entities.Leads>();

            if (!String.IsNullOrWhiteSpace(hfFromDate.Value))
            {
                DateTime sDate = new DateTime(Convert.ToInt32(hfFromDate.Value.Trim().Substring(6, 4)), Convert.ToInt32(hfFromDate.Value.Trim().Substring(3, 2)), Convert.ToInt32(hfFromDate.Value.Trim().Substring(0, 2)));

                var datefrom = Convert.ToDateTime(sDate);
                predicate = predicate.And(Lead => Lead.OriginalLeadDate >= datefrom
                                          );
            }
            if (!String.IsNullOrWhiteSpace(hfToDate.Value))
            {
                DateTime sDate = new DateTime(Convert.ToInt32(hfToDate.Value.Trim().Substring(6, 4)), Convert.ToInt32(hfToDate.Value.Trim().Substring(3, 2)), Convert.ToInt32(hfToDate.Value.Trim().Substring(0, 2)));

                var dateto = Convert.ToDateTime(sDate);
                predicate = predicate.And(Lead => Lead.OriginalLeadDate <= dateto
                                          );
            }


            predicate = predicate.And(Lead => Lead.Status != 0);
            if (Grid == "gvUser")
            {
                predicate = predicate.And(Lead => Lead.UserId == userLead);
            }
            else
            {
                predicate = predicate.And(Lead => Lead.UserId == 0);
            }
            var objLead1 = LeadsManager.GetPredicate(predicate).ToList().AsEnumerable();

            string sortExpression = expression;
            string direction      = string.Empty;

            if (fromSort)
            {
                if (SortDirection == SortDirection.Ascending)
                {
                    SortDirection = SortDirection.Descending;
                }
                else
                {
                    SortDirection = SortDirection.Ascending;
                }
            }


            if (SortDirection == SortDirection.Ascending)
            {
                if (objLead1 != null)
                {
                    switch (expression)
                    {
                    case "SecUser.UserName":
                        objLead1 = objLead1.OrderBy(x => x.SecUser != null ? x.SecUser.UserName : "").ToList();
                        break;

                    case "OriginalLeadDate":
                        objLead1 = objLead1.OrderBy(x => x.OriginalLeadDate).ToList();
                        break;

                    case "ClaimsNumber":
                        objLead1 = objLead1.OrderBy(x => x.ClaimsNumber).ToList();
                        break;
                    //////////////////////////////////////
                    //case "StatusMaster.StatusName":

                    //	objLead1 = objLead1.OrderBy(x => x.StatusMaster != null ? x.StatusMaster.StatusName : "").ToList();
                    //	break;
                    //case "SubStatusMaster.SubStatusName":
                    //	objLead1 = objLead1.OrderBy(x => x.SubStatusMaster != null ? x.SubStatusMaster.SubStatusName : "").ToList();
                    //	break;
                    case "SiteSurveyDate":
                        objLead1 = objLead1.OrderBy(x => x.SiteSurveyDate).ToList();
                        break;

                    //case "AllDocumentsOnFile":
                    //	objLead1 = objLead1.OrderBy(x => x.AllDocumentsOnFile).ToList();
                    //	break;
                    case "ClaimantFirstName":
                        objLead1 = objLead1.OrderBy(x => x.ClaimantFirstName).ToList();
                        break;

                    case "ClaimantLastName":
                        objLead1 = objLead1.OrderBy(x => x.ClaimantLastName).ToList();
                        break;

                    case "CityMaster_1.CityName":
                        objLead1 = objLead1.OrderBy(x => x.CityMaster != null ? x.CityMaster.CityName : "").ToList();
                        break;

                    case "StateMaster1.StateCode":
                        objLead1 = objLead1.OrderBy(x => x.StateMaster != null ? x.StateMaster.StateCode : "").ToList();
                        break;

                    case "Zip":
                        objLead1 = objLead1.OrderBy(x => x.Zip).ToList();
                        break;

                    case "LeadSourceMaster.LeadSourceName":
                        objLead1 = objLead1.OrderBy(x => x.LeadSourceMaster != null ? x.LeadSourceMaster.LeadSourceName : "").ToList();
                        break;

                    case "TypeOfDamageText":
                        objLead1 = objLead1.OrderBy(x => x.TypeofDamageText).ToList();
                        break;

                    case "TypeOfPropertyMaster.TypeOfProperty":
                        objLead1 = objLead1.OrderBy(x => x.TypeOfPropertyMaster != null ? x.TypeOfPropertyMaster.TypeOfProperty : "").ToList();
                        break;
                    }
                }
            }
            else
            {
                if (objLead1 != null)
                {
                    switch (expression)
                    {
                    case "SecUser.UserName":

                        objLead1 = objLead1.OrderByDescending(x => x.SecUser != null ? x.SecUser.UserName : "").ToList();
                        break;

                    case "OriginalLeadDate":
                        objLead1 = objLead1.OrderByDescending(x => x.OriginalLeadDate).ToList();
                        break;

                    case "ClaimsNumber":
                        objLead1 = objLead1.OrderByDescending(x => x.ClaimsNumber).ToList();
                        break;

                    //case "StatusMaster.StatusName":
                    //	objLead1 = objLead1.OrderByDescending(x => x.StatusMaster != null ? x.StatusMaster.StatusName : "").ToList();
                    //	break;
                    //case "SubStatusMaster.SubStatusName":
                    //	objLead1 = objLead1.OrderByDescending(x => x.SubStatusMaster != null ? x.SubStatusMaster.SubStatusName : "").ToList();
                    //	break;
                    case "SiteSurveyDate":
                        objLead1 = objLead1.OrderByDescending(x => x.SiteSurveyDate).ToList();
                        break;

                    //case "AllDocumentsOnFile":
                    //	objLead1 = objLead1.OrderByDescending(x => x.AllDocumentsOnFile).ToList();
                    //	break;
                    case "ClaimantFirstName":
                        objLead1 = objLead1.OrderByDescending(x => x.ClaimantFirstName).ToList();
                        break;

                    case "ClaimantLastName":
                        objLead1 = objLead1.OrderByDescending(x => x.ClaimantLastName).ToList();
                        break;

                    case "CityMaster_1.CityName":
                        objLead1 = objLead1.OrderByDescending(x => x.CityMaster != null ? x.CityMaster.CityName : "").ToList();
                        break;

                    case "StateMaster1.StateCode":
                        objLead1 = objLead1.OrderByDescending(x => x.StateMaster != null ? x.StateMaster.StateCode : "").ToList();
                        break;

                    case "Zip":
                        objLead1 = objLead1.OrderByDescending(x => x.Zip).ToList();
                        break;

                    case "LeadSourceMaster.LeadSourceName":
                        objLead1 = objLead1.OrderByDescending(x => x.LeadSourceMaster != null ? x.LeadSourceMaster.LeadSourceName : "").ToList();
                        break;

                    case "TypeOfDamageText":
                        objLead1 = objLead1.OrderByDescending(x => x.TypeofDamageText).ToList();
                        break;

                    case "TypeOfPropertyMaster.TypeOfProperty":
                        objLead1 = objLead1.OrderBy(x => x.TypeOfPropertyMaster != null ? x.TypeOfPropertyMaster.TypeOfProperty : "").ToList();
                        break;
                    }
                }
            }
            if (Grid == "gvUser")
            {
                gvUserLeads.DataSource = objLead1;
                gvUserLeads.DataBind();
            }
            else
            {
                grdAllLead.DataSource = objLead1;
                grdAllLead.DataBind();
            }
        }
        protected void bindReport()
        {
            List <Leads> objLead   = null;
            var          predicate = PredicateBuilder.True <CRM.Data.Entities.Leads>();

            if (Cache["FromDate"] != null && Cache["FromDate"].ToString() != "")
            {
                DateTime sDate = new DateTime(Convert.ToInt32(Cache["FromDate"].ToString().Trim().Substring(6, 4)), Convert.ToInt32(Cache["FromDate"].ToString().Trim().Substring(3, 2)), Convert.ToInt32(Cache["FromDate"].ToString().Trim().Substring(0, 2)));

                var datefrom = Convert.ToDateTime(sDate);
                predicate = predicate.And(Lead => Lead.DateSubmitted >= datefrom
                                          );
            }
            if (Cache["ToDate"] != null && Cache["ToDate"].ToString() != "")
            {
                DateTime sDate = new DateTime(Convert.ToInt32(Cache["ToDate"].ToString().Trim().Substring(6, 4)), Convert.ToInt32(Cache["ToDate"].ToString().Trim().Substring(3, 2)), Convert.ToInt32(Cache["ToDate"].ToString().Trim().Substring(0, 2)));

                var dateto = Convert.ToDateTime(sDate);
                predicate = predicate.And(Lead => Lead.DateSubmitted <= dateto
                                          );
            }
            if (Cache["Criteria"] != null && Cache["Criteria"].ToString() != "")
            {
                var user = Cache["Criteria"].ToString();
                predicate = predicate.And(Lead => Lead.SecUser.UserName == user);
            }
            objLead = LeadsManager.GetPredicate(predicate);

            List <AllUserLeads> resAllUserLeads    = new List <AllUserLeads>();
            AllUserLeads        objAllUserLeadsGet = null;

            foreach (var get in objLead)
            {
                objAllUserLeadsGet = new AllUserLeads();


                objAllUserLeadsGet.LeadId   = get.LeadId;
                objAllUserLeadsGet.UserId   = (int)get.UserId;
                objAllUserLeadsGet.UserName = get.SecUser.UserName;
                //objAllUserLeadsGet.DateSubmitted = (DateTime?)get.DateSubmitted;
                objAllUserLeadsGet.DateSubmitted = get.DateSubmitted == null ? "" : Convert.ToDateTime(get.DateSubmitted).ToString("dd/MMM/yy");
                objAllUserLeadsGet.LFUUID        = get.LFUUID;
                //objAllUserLeadsGet.OriginalLeadDate = (DateTime)get.OriginalLeadDate;
                objAllUserLeadsGet.OriginalLeadDate = get.OriginalLeadDate == null ? "" : Convert.ToDateTime(get.OriginalLeadDate).ToString("dd/MMM/yy");
                objAllUserLeadsGet.ClaimsNumber     = get.ClaimsNumber == null ? 0 : (int)get.ClaimsNumber;
                //objAllUserLeadsGet.ClaimantName = get.ClaimantName;
                objAllUserLeadsGet.ClaimantName = get.ClaimantFirstName + get.ClaimantLastName;

                //if (get.LeadSourceMaster != null)
                //	objAllUserLeadsGet.LeadStatus = get.LeadSourceMaster.LeadSourceName == null ? "" : get.LeadSourceMaster.LeadSourceName;

                objAllUserLeadsGet.EmailAddress = get.EmailAddress;

                //if (get.AdjusterMaster != null)
                //	objAllUserLeadsGet.Adjuster = get.AdjusterMaster.AdjusterName == null ? "" : get.AdjusterMaster.AdjusterName;
                ////objAllUserLeadsGet.LeadSource = get.LeadSource;

                if (get.LeadSourceMaster != null)
                {
                    objAllUserLeadsGet.LeadSource = get.LeadSourceMaster.LeadSourceName == null ? "" : get.LeadSourceMaster.LeadSourceName;
                }

                if (get.PrimaryProducerId != null)
                {
                    objAllUserLeadsGet.PrimaryProducerId = (int)get.PrimaryProducerId;
                }

                if (get.ProducerMaster != null)
                {
                    objAllUserLeadsGet.PrimaryProducerName = get.ProducerMaster.ProducerName;
                }

                objAllUserLeadsGet.SecondaryProducerId = (int)(get.SecondaryProducerId ?? 0);
                //objAllUserLeadsGet.SecondaryProducerName = get.ProducerMaster1.ProducerName;

                if (get.SecondaryProducerMaster != null)
                {
                    objAllUserLeadsGet.SecondaryProducerName = get.SecondaryProducerMaster.SecondaryProduceName == null ? "" : get.SecondaryProducerMaster.SecondaryProduceName;
                }

                objAllUserLeadsGet.EmailAddress = get.EmailAddress;

                if (get.InspectorMaster != null)
                {
                    objAllUserLeadsGet.InspectorName = get.InspectorMaster.InspectorName == null ? "" : get.InspectorMaster.InspectorName;
                }

                objAllUserLeadsGet.InspectorCell  = get.InspectorCell;
                objAllUserLeadsGet.InspectorEmail = get.InspectorEmail;
                objAllUserLeadsGet.PhoneNumber    = get.PhoneNumber;

                //if (get.WebformSourceMaster != null)
                //	objAllUserLeadsGet.WebformSource = get.WebformSourceMaster.WebformSource == null ? "" : get.WebformSourceMaster.WebformSource;

                objAllUserLeadsGet.ClaimantComments = get.ClaimantComments;
                //objAllUserLeadsGet.TypeOfDamage = get.TypeOfDamageMaster.TypeOfDamage == null ? "" : get.TypeOfDamageMaster.TypeOfDamage;
                objAllUserLeadsGet.TypeOfDamage = get.TypeofDamageText == null ? "" : get.TypeofDamageText;
                //objAllUserLeadsGet.TypeOfProperty = (int)get.TypeOfProperty;
                //objAllUserLeadsGet.TypeOfProperty = get.TypeOfProperty == 1 ? "Home" : "Hotel";

                if (get.TypeOfPropertyMaster != null)
                {
                    objAllUserLeadsGet.TypeOfProperty = get.TypeOfPropertyMaster.TypeOfProperty == null ? "" : get.TypeOfPropertyMaster.TypeOfProperty;
                }

                //objAllUserLeadsGet.ReporterToInsurer = get.ReporterToInsurer == null ? "NO" : get.ReporterToInsurer.ToString() == "Y" ? "YES" : "NO";
                if (get.ReportedToInsurerMaster != null)
                {
                    objAllUserLeadsGet.ReporterToInsurer = get.ReportedToInsurerMaster.ReportedToInsurer == null ? "" : get.ReportedToInsurerMaster.ReportedToInsurer;
                }

                resAllUserLeads.Add(objAllUserLeadsGet);
            }



            ListtoDataTableConverter converter = new ListtoDataTableConverter();
            DataTable dt      = converter.ToDataTable(resAllUserLeads);
            string    xmlpath = Request.MapPath("~/Protected/Reports") + "/AllUserLeads.xml";

            dt.WriteXml(xmlpath);


            if (dt != null && dt.Rows.Count > 0)
            {
                ReportDocument RptDoc           = new ReportDocument();
                string         ReportFolderPath = System.Configuration.ConfigurationManager.AppSettings["ReportPath"].ToString();
                RptDoc.Load(Request.MapPath(ReportFolderPath + "crptAllUserLeads1.rpt"));                //CrystalReport1.rpt
                RptDoc.SetDataSource(dt);
                CrystalReportViewer1.ReportSource = RptDoc;
                CrystalReportViewer1.DataBind();
            }
            else
            {
                CrystalReportViewer1.ReportSource = null;
                CrystalReportViewer1.DataBind();
            }
        }