Ejemplo n.º 1
0
        private void SearchProspects()
        {
            // format phone no.
            CommonCode objCommonCode = new CommonCode();

            //saving search parameter
            var    parameterString = new string[17];
            bool   blnReset        = false;
            string roleName        = string.Empty;

            // reset flag
            if (Request["isreset"] != null && Request["isreset"] == "true")
            {
                blnReset = true;
                Session["ParameterStringProspect"] = null;
            }

            if (Session["ParameterStringProspect"] != null && blnReset == false)
            {
                parameterString = (string[])Session["ParameterStringProspect"];
            }

            // prospect name
            if (Request["prospectname"] != null)
            {
                parameterString[0] = Request["prospectname"];
            }
            //start date
            if (Request["startdate"] != null)
            {
                parameterString[1] = Request["startdate"];
            }
            //end date
            if (Request["enddate"] != null)
            {
                parameterString[2] = Request["enddate"];
            }
            //sales person
            if (Request["salesrepid"] != null)
            {
                parameterString[3] = Request["salesrepid"];
            }
            //distance
            if (Request["distance"] != null)
            {
                parameterString[4] = Request["distance"];
            }
            // zipcode
            if (Request["zipcode"] != null)
            {
                parameterString[5] = Request["zipcode"];
            }
            // progress
            if (Request["progress"] != null)
            {
                parameterString[6] = Request["progress"];
            }
            // type
            if (Request["type"] != null)
            {
                parameterString[7] = Request["type"];
            }
            // assigned status
            if (Request["assignedstatus"] != null)
            {
                parameterString[8] = Request["assignedstatus"];
            }
            // territory
            if (Request["territory"] != null)
            {
                parameterString[9] = Request["territory"];
            }
            // page number
            if (Request["pagenumber"] != null)
            {
                parameterString[10] = Request["pagenumber"];
            }
            // page size
            if (Request["pagesize"] != null)
            {
                parameterString[11] = Request["pagesize"];
            }
            // will promote
            if (Request["willpromote"] != null)
            {
                parameterString[12] = Request["willpromote"];
            }
            // will host
            if (Request["willhost"] != null)
            {
                parameterString[13] = Request["willhost"];
            }
            // hosted in past
            if (Request["hostedinpast"] != null)
            {
                parameterString[14] = Request["hostedinpast"];
            }
            // prospect list id
            parameterString[15] = Request["prospectlistid"] ?? "0";
            // Assigned To
            if (Request["assignedTo"] != null)
            {
                parameterString[16] = Request["assignedTo"];
            }
            // login role
            if (Request["role"] != null)
            {
                roleName = Request["role"];
            }
            Session["ParameterStringProspect"] = parameterString;

            long   prospectListId  = 0;
            long   franchiseeid    = 0;
            int    territoryId     = 0;
            string strProspectName = string.Empty;
            string strStartDate    = string.Empty;
            string strEndDate      = string.Empty;
            long   iSalesPersonId  = 0;
            int    istatusId       = 0;
            int    itypeId         = 0;

            string strUserId       = string.Empty;
            string strZipCode      = string.Empty;
            string strDistance     = "0";
            string strNotesToolTip = string.Empty;
            int    isAssigned      = 0;
            string strSortColomn   = "";
            string strSortOrder    = " Asc";
            int    iPageSize       = 5;
            int    iPageIndex      = 1;
            long   iTotalRecord;
            int    iWillPrompte  = 3;
            int    iWillHost     = 3;
            int    iHostedInPast = 3;
            long   assignedTo    = 0;

            Falcon.Entity.Other.EProspect[] objProspects = null;
            var objFranchisorDal = new FranchisorDAL();

            // Prospect ListID
            if (!string.IsNullOrEmpty(parameterString[15]))
            {
                if (parameterString[15] != "0")
                {
                    prospectListId = Convert.ToInt64(parameterString[15]);
                }
            }
            // Prospect Name
            if (!string.IsNullOrEmpty(parameterString[0]))
            {
                strProspectName = parameterString[0];
            }
            // Start Name
            if (!string.IsNullOrEmpty(parameterString[1]))
            {
                strStartDate = parameterString[1];
            }
            // End Name
            if (!string.IsNullOrEmpty(parameterString[2]))
            {
                strEndDate = parameterString[2];
            }
            // SalesPersonId
            if (!string.IsNullOrEmpty(parameterString[3]))
            {
                iSalesPersonId = Convert.ToInt64(parameterString[3]);
            }
            //StatusID
            if (!string.IsNullOrEmpty(parameterString[6]))
            {
                istatusId = Convert.ToInt32(parameterString[6]);
            }
            //TypeId
            if (!string.IsNullOrEmpty(parameterString[7]))
            {
                itypeId = Convert.ToInt32(parameterString[7]);
            }
            // Assign Status
            if (!string.IsNullOrEmpty(parameterString[8]))
            {
                isAssigned = Convert.ToInt32(parameterString[8]);
            }
            if (!string.IsNullOrEmpty(parameterString[4]) && (!string.IsNullOrEmpty(parameterString[5])))
            {
                strDistance = parameterString[4];
                strZipCode  = parameterString[5];
            }
            // Will Promote
            if (!string.IsNullOrEmpty(parameterString[12]))
            {
                iWillPrompte = Convert.ToInt32(parameterString[12]);
            }
            // Will Host
            if (!string.IsNullOrEmpty(parameterString[13]))
            {
                iWillHost = Convert.ToInt32(parameterString[13]);
            }
            // Hosted In Past
            if (!string.IsNullOrEmpty(parameterString[14]))
            {
                iHostedInPast = Convert.ToInt32(parameterString[14]);
            }
            // Get Page Size
            if (!string.IsNullOrEmpty(parameterString[11]))
            {
                iPageSize = Convert.ToInt32(parameterString[11]);
            }
            // Get Page Size
            if (!string.IsNullOrEmpty(parameterString[10]))
            {
                iPageIndex = Convert.ToInt32(parameterString[10]);
            }
            // Franchisee id
            if (!string.IsNullOrEmpty(Request["franchiseeid"]))
            {
                franchiseeid = Convert.ToInt64(Request["franchiseeid"]);
            }
            // Territory id
            if (!string.IsNullOrEmpty(parameterString[9]))
            {
                territoryId = Convert.ToInt32(parameterString[9]);
            }
            // AssignedTo (FranchiFranchiseesUserId)
            if (!string.IsNullOrEmpty(parameterString[16]))
            {
                assignedTo = Convert.ToInt64(parameterString[16]);
            }

            // Get Sort Column
            if (!string.IsNullOrEmpty(Request["sortcolumn"]))
            {
                strSortColomn = Request["sortcolumn"];
            }
            // Get Sort Order
            if (!string.IsNullOrEmpty(Request["sortorder"]))
            {
                strSortOrder = Request["sortorder"];
            }
            if (strSortOrder.Equals("Ascending"))
            {
                strSortOrder = " Asc ";
            }
            if (strSortOrder.Equals("Descending"))
            {
                strSortOrder = " Desc ";
            }
            // Case when prospect list
            if (prospectListId > 0)
            {
                var listProspects = objFranchisorDal.GetProspectsDetailByProspectListID(prospectListId, 1, out iTotalRecord, iPageSize, iPageIndex, strSortColomn, strSortOrder, assignedTo);
                if (listProspects != null)
                {
                    objProspects = listProspects.ToArray();
                }
            }
            // normal case
            else
            {
                //Get data for salesperson selected in dropdown id true else call all data
                if (FranchiseeView)
                {
                    if (strUserId == "" && strZipCode == "" && (strDistance == "" || strDistance == "0"))
                    {
                        var listProspects = objFranchisorDal.GetProspectsDetail(strProspectName, strStartDate,
                                                                                strEndDate, franchiseeid, istatusId,
                                                                                itypeId, 0, "", 0, 0, isAssigned,
                                                                                iSalesPersonId,
                                                                                territoryId, strSortColomn,
                                                                                strSortOrder, iPageSize, iPageIndex,
                                                                                out iTotalRecord, iWillPrompte,
                                                                                iWillHost, iHostedInPast, assignedTo, roleName, 0);
                        if (listProspects != null)
                        {
                            objProspects = listProspects.ToArray();
                        }
                    }
                    else if (strUserId != "" && strZipCode != "" && strDistance != "" && strDistance != "0")
                    {
                        var listProspects = objFranchisorDal.GetProspectsDetail(strProspectName, strStartDate,
                                                                                strEndDate, franchiseeid, istatusId,
                                                                                itypeId, 0, strZipCode,
                                                                                Convert.ToInt32(strDistance), 0,
                                                                                isAssigned,
                                                                                iSalesPersonId,
                                                                                territoryId, strSortColomn, strSortOrder,
                                                                                iPageSize, iPageIndex, out iTotalRecord,
                                                                                iWillPrompte, iWillHost, iHostedInPast, assignedTo, roleName, 0);

                        if (listProspects != null)
                        {
                            objProspects = listProspects.ToArray();
                        }
                    }
                    else
                    {
                        var listProspects = objFranchisorDal.GetProspectsDetail(strProspectName, strStartDate,
                                                                                strEndDate, franchiseeid, istatusId,
                                                                                itypeId, 0, strZipCode,
                                                                                Convert.ToInt32(strDistance), 0,
                                                                                isAssigned,
                                                                                iSalesPersonId,
                                                                                territoryId, strSortColomn, strSortOrder,
                                                                                iPageSize, iPageIndex, out iTotalRecord,
                                                                                iWillPrompte, iWillHost, iHostedInPast, assignedTo, roleName, 0);
                        if (listProspects != null)
                        {
                            objProspects = listProspects.ToArray();
                        }
                    }
                }
                else
                {
                    string shellId       = IoC.Resolve <ISessionContext>().UserSession.CurrentOrganizationRole.OrganizationId.ToString();
                    var    listProspects = objFranchisorDal.GetProspectsDetail(strProspectName, strStartDate, strEndDate, Convert.ToInt64(shellId), istatusId, itypeId, 1, strZipCode, Convert.ToInt32(strDistance), 0, isAssigned, iSalesPersonId, territoryId, strSortColomn, strSortOrder, iPageSize, iPageIndex, out iTotalRecord, iWillPrompte, iWillHost, iHostedInPast, assignedTo, roleName, 0);
                    if (listProspects != null)
                    {
                        objProspects = listProspects.ToArray();
                    }
                }
            }

            if (objProspects.Length == 1 && Request.QueryString["QuickSearch"] != null && Request.QueryString["QuickSearch"].Equals("True"))
            {
                Response.Write("/App/Franchisee/SalesRep/SalesRepProspectDetails.aspx?Type=Prospect&QuickSearch=True&ProspectID=" + objProspects[0].ProspectID);
            }
            else
            {
                var dtProspect = new DataTable();

                //Create template for data table

                dtProspect.Columns.Add("ProspectId", typeof(Int32));
                dtProspect.Columns.Add("ProspectName");
                dtProspect.Columns.Add("ProspectCreatedDate");
                dtProspect.Columns.Add("PhoneOffice");
                dtProspect.Columns.Add("ProspectStatus");
                dtProspect.Columns.Add("AssignedStatus");
                dtProspect.Columns.Add("NoOFCalls");
                dtProspect.Columns.Add("NoOFMeeting");

                dtProspect.Columns.Add("NoOfContacts");
                dtProspect.Columns.Add("SalesPersonFirstName");
                dtProspect.Columns.Add("SalesPersonLastName");
                dtProspect.Columns.Add("FranchiseeName");
                dtProspect.Columns.Add("ProspectAddress1");
                dtProspect.Columns.Add("ProspectAddress2");
                dtProspect.Columns.Add("ProspectCity");
                dtProspect.Columns.Add("ProspectState");

                dtProspect.Columns.Add("ProspectZip");
                dtProspect.Columns.Add("ProspectCountry");
                dtProspect.Columns.Add("ProspectCompleteAddress");

                dtProspect.Columns.Add("ContactFirstName");
                dtProspect.Columns.Add("ContactLastName");
                dtProspect.Columns.Add("ContactPhone");
                dtProspect.Columns.Add("ContactEmail");

                dtProspect.Columns.Add("ContactCallDate");
                dtProspect.Columns.Add("ContactCallStatus");

                dtProspect.Columns.Add("LnkContactViewAll");
                dtProspect.Columns.Add("LnkContactAddCall");
                dtProspect.Columns.Add("LnkContactAddMeeting");
                dtProspect.Columns.Add("LnkactivityNotes");
                dtProspect.Columns.Add("LnkViewDetails");
                dtProspect.Columns.Add("LnkAddContact");
                dtProspect.Columns.Add("LnkConvertToHost");
                dtProspect.Columns.Add("NotesToolTip");
                dtProspect.Columns.Add("ProspectStatusImage");

                //Add all the fetched data to data table
                if (objProspects != null && objProspects.Length > 0)
                {
                    foreach (var objProspect in objProspects)
                    {
                        DataRow drProspect = dtProspect.NewRow();
                        drProspect["ProspectId"]          = objProspect.ProspectID;
                        drProspect["ProspectName"]        = string.IsNullOrEmpty(objProspect.OrganizationName) ? "N/A" : objProspect.OrganizationName;
                        drProspect["ProspectCreatedDate"] = string.IsNullOrEmpty(objProspect.ProspectDate) ? "N/A" :
                                                            Convert.ToDateTime(objProspect.ProspectDate).ToShortDateString();

                        drProspect["PhoneOffice"] = !string.IsNullOrEmpty(objProspect.PhoneOffice) ? objCommonCode.FormatPhoneNumberGet(objProspect.PhoneOffice) : "N/A";

                        drProspect["AssignedStatus"] = objProspect.AssignedStatus.ToString();

                        if (string.IsNullOrEmpty(objProspect.Status))
                        {
                            drProspect["ProspectStatus"] = "N/A";
                        }
                        else
                        {
                            string status;
                            //Set the status according to status id
                            switch (objProspect.Status)
                            {
                            case "1":
                                status = "Hot";
                                drProspect["ProspectStatusImage"] = "<img src='/App/Images/hot-icon.gif' alt='Hot' />";
                                break;

                            case "2":
                                status = "Cold";
                                drProspect["ProspectStatusImage"] = "<img src='/App/Images/cold-icon.gif' alt='Cold' />";
                                break;

                            case "3":
                                status = "Warm";
                                drProspect["ProspectStatusImage"] = "<img src='/App/Images/warm-icon.gif' alt='Warm' />";
                                break;

                            default:
                                status = "none";
                                drProspect["ProspectStatusImage"] = "";
                                break;
                            }
                            drProspect["ProspectStatus"] = status;
                        }

                        drProspect["NoOFCalls"]    = objProspect.NoOfCalls;
                        drProspect["NoOFMeeting"]  = objProspect.NoOfMeetings;
                        drProspect["NoOfContacts"] = objProspect.NoOfContacts;

                        if (string.IsNullOrEmpty(objProspect.FirstName) && string.IsNullOrEmpty(objProspect.LastName))
                        {
                            drProspect["SalesPersonFirstName"] = "N/A";
                            drProspect["SalesPersonLastName"]  = "";
                        }
                        else
                        {
                            drProspect["SalesPersonFirstName"] = objProspect.FirstName;
                            drProspect["SalesPersonLastName"]  = objProspect.LastName;
                        }
                        if (string.IsNullOrEmpty(objProspect.FranchiseeName))
                        {
                            drProspect["FranchiseeName"] = "N/A";
                        }
                        else
                        {
                            drProspect["FranchiseeName"] = objProspect.FranchiseeName;
                        }

                        //EAddress objAddress = objProspect.Address;
                        var objAddress = objProspect.Address;

                        // Set Initially the new line in address
                        string strProspectCompleteAddress;

                        drProspect["ProspectAddress1"] = string.IsNullOrEmpty(objAddress.Address1) ? "" : objAddress.Address1;
                        drProspect["ProspectAddress2"] = string.IsNullOrEmpty(objAddress.Address2) ? "" : objAddress.Address2;
                        drProspect["ProspectCity"]     = string.IsNullOrEmpty(objAddress.City) ? "N/A" : objAddress.City;
                        drProspect["ProspectState"]    = string.IsNullOrEmpty(objAddress.State) ? "N/A" : objAddress.State;

                        if (string.IsNullOrEmpty(objAddress.Zip) || (objAddress.Zip == "0"))
                        {
                            drProspect["ProspectZip"] = "N/A";
                        }
                        else
                        {
                            drProspect["ProspectZip"] = objAddress.Zip;
                        }
                        // Format Address
                        strProspectCompleteAddress            = CommonCode.AddressMultiLine(objAddress.Address1, objAddress.Address2, objAddress.City, objAddress.State, objAddress.Zip);
                        drProspect["ProspectCompleteAddress"] = strProspectCompleteAddress;

                        var listContact = objProspect.Contact;
                        Falcon.Entity.Other.EContact[] objContact;
                        objContact = listContact.ToArray();
                        if (string.IsNullOrEmpty(objContact[0].FirstName))
                        {
                            if (string.IsNullOrEmpty(objContact[0].LastName))
                            {
                                drProspect["ContactFirstName"] = "N/A";
                                drProspect["ContactLastName"]  = "";
                            }
                            else
                            {
                                drProspect["ContactFirstName"] = objContact[0].FirstName;
                                drProspect["ContactLastName"]  = objContact[0].LastName;
                            }
                        }
                        else
                        {
                            drProspect["ContactFirstName"] = objContact[0].FirstName;
                            drProspect["ContactLastName"]  = objContact[0].LastName;
                        }

                        if (string.IsNullOrEmpty(objContact[0].PhoneHome))
                        {
                            drProspect["ContactPhone"] = "N/A";
                        }
                        else if (objContact[0].PhoneHome.Trim().Equals("(___)-___-____"))
                        {
                            drProspect["ContactPhone"] = "N/A";
                        }
                        else
                        {
                            drProspect["ContactPhone"] = objCommonCode.FormatPhoneNumberGet(objContact[0].PhoneHome);
                        }

                        drProspect["ContactEmail"] = string.IsNullOrEmpty(objContact[0].EMail) ? "N/A" : objContact[0].EMail;

                        var objContactCall = objProspect.ContactCall;
                        drProspect["ContactCallDate"] = string.IsNullOrEmpty(objContactCall.StartDate) ? "N/A" : objContactCall.StartDate;

                        var objCallStatus = objContactCall.CallStatus;
                        if (string.IsNullOrEmpty(objCallStatus.Status))
                        {
                            drProspect["ContactCallStatus"] = "N/A";
                        }
                        else
                        {
                            drProspect["ContactCallStatus"] = objCallStatus.Status;
                        }

                        // Prepare Notes ToolTips
                        bool blnNotes = false;
                        strNotesToolTip = strNotesToolTip + "<table cellpadding='3' cellspacing='0' border='0' width='100%'>";
                        //Date and Time
                        if (!string.IsNullOrEmpty(objContactCall.StartDate))
                        {
                            string[] strDateTime = objContactCall.StartDate.Split(' ');
                            if (strDateTime.Length >= 2)
                            {
                                strNotesToolTip = strNotesToolTip + "<tr><td>Date: " + strDateTime[0] + "</td><td>Time: " + strDateTime[1] + "</td></tr>";
                                blnNotes        = true;
                            }
                        }
                        // Duration
                        if (!string.IsNullOrEmpty(objCallStatus.Duration))
                        {
                            strNotesToolTip = strNotesToolTip + "<tr><td colspan=2>Duration: " + objCallStatus.Duration + " mins.</td></tr>";
                            blnNotes        = true;
                        }
                        // Status
                        if (!string.IsNullOrEmpty(objCallStatus.Status))
                        {
                            strNotesToolTip = strNotesToolTip + "<tr><td colspan=2>Status: " + objCallStatus.Status + "</td></tr>";
                            blnNotes        = true;
                        }
                        // Notes
                        if (!string.IsNullOrEmpty(objCallStatus.Notes))
                        {
                            strNotesToolTip = strNotesToolTip + "<tr><td colspan=2>Notes: </td></tr><tr><td colspan=2>" + objCallStatus.Notes + "</td></tr>";
                            blnNotes        = true;
                        }
                        strNotesToolTip = strNotesToolTip + "</table>";

                        drProspect["NotesToolTip"] = blnNotes ? strNotesToolTip : "<table cellpadding='3' cellspacing='0' border='0' width='100%'><tr><td> Details Not Available </td></tr></table>";
                        strNotesToolTip            = string.Empty;
                        dtProspect.Rows.Add(drProspect);
                    }
                }

                // Bind data with grid if rowcount is greate than 0 else shows No record found message
                if (dtProspect.Rows.Count > 0)
                {
                    grdProspect.DataSource = dtProspect;
                    grdProspect.DataBind();

                    if (dtProspect.Rows.Count == 1)
                    {
                        //spCount.InnerHtml = iTotalRecord.ToString() + " Result Found";
                    }
                    string pagingstring = ImplementPaging(iPageIndex, iPageSize, iTotalRecord);

                    HtmlForm newForm = Page.Form;
                    newForm.Controls.Clear();
                    newForm.Controls.Add(grdProspect);

                    var sb       = new System.Text.StringBuilder();
                    var htWriter = new HtmlTextWriter(new System.IO.StringWriter(sb));

                    newForm.RenderControl(htWriter);

                    string strRenderedHTML = sb.ToString();
                    string strTottalRecord;
                    int    startindex = strRenderedHTML.IndexOf("<table");
                    int    endindex   = strRenderedHTML.LastIndexOf("</table>");
                    int    length     = (endindex - startindex) + 8;
                    strRenderedHTML = strRenderedHTML.Substring(startindex, length);
                    strTottalRecord = "<span id=spnTotalRecordAsync>" + iTotalRecord.ToString() + "</span>";
                    strRenderedHTML = "<div style='float: left; width: 746px'>" + strRenderedHTML + "</div>";

                    Response.Write(strRenderedHTML + pagingstring + "<p class=\"blueboxbotbg_cl\"><img src=\"/App/Images/specer.gif\" width=\"746\" height=\"5\" /></p>" + strTottalRecord);
                }
                else
                {
                    string noRecordFound = "<div style='float:left; width:746px; border:solid 1px #E7F0F5; padding:10px 0px 10px 0px; display:block;' id='dvNoProspectFound' runat='server'>";
                    noRecordFound = noRecordFound + "<div class='divnoitemfound_custdbrd' style='margin-top:0px;'><p class='divnoitemtxt_custdbrd'><span class='orngbold18_default'>No Records Found</span></p></div></div>";
                    Response.Write(noRecordFound);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Method to search prospects based on search criteria
        /// </summary>
        private void SearchProspects()
        {
            // format phone no.
            CommonCode objCommonCode = new CommonCode();

            //saving search parameter
            var    parameterString = new string[18];
            bool   blnReset        = false;
            string roleName        = string.Empty;

            // reset flag
            if (Request["isreset"] != null && Request["isreset"] == "true")
            {
                blnReset = true;
                Session["ParameterStringHost"] = null;
            }

            if (Session["ParameterStringHost"] != null && blnReset == false)
            {
                parameterString = (string[])Session["ParameterStringHost"];
            }

            if (Request["prospectname"] != null)
            {
                parameterString[0] = Request["prospectname"];
            }
            if (Request["startdate"] != null)
            {
                parameterString[1] = Request["startdate"];
            }
            if (Request["enddate"] != null)
            {
                parameterString[2] = Request["enddate"];
            }
            if (Request["salesrepid"] != null)
            {
                parameterString[3] = Request["salesrepid"];
            }
            if (Request["distance"] != null)
            {
                parameterString[4] = Request["distance"];
            }
            if (Request["zipcode"] != null)
            {
                parameterString[5] = Request["zipcode"];
            }
            if (Request["status"] != null)
            {
                parameterString[6] = Request["status"];
            }
            if (Request["hasevent"] != null)
            {
                parameterString[7] = Request["hasevent"];
            }
            if (Request["territory"] != null)
            {
                parameterString[8] = Request["territory"];
            }
            if (Request["pagenumber"] != null)
            {
                parameterString[9] = Request["pagenumber"];
            }
            if (Request["pagesize"] != null)
            {
                parameterString[10] = Request["pagesize"];
            }
            // Assigned To
            if (Request["assignedTo"] != null)
            {
                parameterString[16] = Request["assignedTo"];
            }
            // login role
            if (Request["role"] != null)
            {
                roleName = Request["role"];
            }
            // prospectTypeId
            if (Request["hostType"] != null)
            {
                parameterString[17] = Request["hostType"];
            }

            Session["ParameterStringHost"] = parameterString;

            long   franchiseeid    = 0;
            int    territoryid     = 0;
            string strProspectName = string.Empty;
            string strStartDate    = string.Empty;
            string strEndDate      = string.Empty;
            long   iSalesPersonId  = 0;
            long   prospectTypeId  = 0;
            int    istatusId       = 0;
            int    itypeId         = 0;

            string    strUserId       = string.Empty;
            string    strZipCode      = string.Empty;
            string    strDistance     = "0";
            string    strNotesToolTip = string.Empty;
            const int isFeeder        = 4;

            string strSortColomn = string.Empty;
            string strSortOrder  = string.Empty;
            int    iPageSize     = 5;
            int    iPageIndex    = 1;
            long   iTotalRecord;
            long   assignedTo = 0;

            var objFranchisorDal = new FranchisorDAL();

            EProspect[] objProspects = null;

            // Prospect Name
            if (!string.IsNullOrEmpty(parameterString[0]))
            {
                strProspectName = parameterString[0];
            }
            // Start Name
            if (!string.IsNullOrEmpty(parameterString[1]))
            {
                strStartDate = parameterString[1];
            }
            // End Name
            if (!string.IsNullOrEmpty(parameterString[2]))
            {
                strEndDate = parameterString[2];
            }
            // SalesPersonId
            if (!string.IsNullOrEmpty(parameterString[3]))
            {
                iSalesPersonId = Convert.ToInt64(parameterString[3]);
            }

            if (!string.IsNullOrEmpty(parameterString[4]) && (!string.IsNullOrEmpty(parameterString[5])))
            {
                strDistance = parameterString[4];
                strZipCode  = parameterString[5];
            }

            //StatusID
            if (!string.IsNullOrEmpty(parameterString[6]))
            {
                istatusId = Convert.ToInt32(parameterString[6]);
            }
            //event status
            if (!string.IsNullOrEmpty(parameterString[7]))
            {
                itypeId = Convert.ToInt32(parameterString[7]);
            }
            // Territory id
            if (!string.IsNullOrEmpty(parameterString[8]))
            {
                territoryid = Convert.ToInt32(parameterString[8]);
            }

            // Get Page Number
            if (!string.IsNullOrEmpty(parameterString[9]))
            {
                iPageIndex = Convert.ToInt32(parameterString[9]);
            }

            // Get Page Size
            if (!string.IsNullOrEmpty(parameterString[10]))
            {
                iPageSize = Convert.ToInt32(parameterString[10]);
            }

            // Franchisee id
            if (!string.IsNullOrEmpty(Request["franchiseeid"]))
            {
                franchiseeid = Convert.ToInt64(Request["franchiseeid"]);
            }

            // AssignedTo (FranchiFranchiseesUserId)
            if (!string.IsNullOrEmpty(parameterString[16]))
            {
                assignedTo = Convert.ToInt64(parameterString[16]);
            }
            // ProspectTypeId
            if (!string.IsNullOrEmpty(parameterString[17]))
            {
                prospectTypeId = Convert.ToInt64(parameterString[17]);
            }

            // Get Sort Column
            if (!string.IsNullOrEmpty(Request["sortcolumn"]))
            {
                strSortColomn = Request["sortcolumn"];
            }
            // Get Sort Order
            if (!string.IsNullOrEmpty(Request["sortorder"]))
            {
                strSortOrder = Request["sortorder"];
            }
            if (strSortOrder.Equals("Ascending"))
            {
                strSortOrder = " Asc ";
            }
            if (strSortOrder.Equals("Descending"))
            {
                strSortOrder = " Desc ";
            }

            //Get data for salesperson selected in dropdown id true else call all data
            if (FranchiseeView)
            {
                if (strUserId == "" && strZipCode == "" && (strDistance == "" || strDistance == "0"))
                {
                    var listProspects = objFranchisorDal.GetProspectsDetail(strProspectName, strStartDate, strEndDate,
                                                                            franchiseeid, istatusId, itypeId, 2, "", 0, 1, isFeeder, iSalesPersonId,
                                                                            territoryid, strSortColomn, strSortOrder, iPageSize, iPageIndex, out iTotalRecord, 2, 2, 2, assignedTo, roleName, prospectTypeId);
                    if (listProspects != null)
                    {
                        objProspects = listProspects.ToArray();
                    }
                }
                else if (strUserId != "" && strZipCode != "" && strDistance != "" && strDistance != "0")
                {
                    var listProspects = objFranchisorDal.GetProspectsDetail(strProspectName, strStartDate, strEndDate,
                                                                            franchiseeid, istatusId, itypeId, 2, strZipCode, Convert.ToInt32(strDistance), 1, isFeeder,
                                                                            iSalesPersonId, territoryid, strSortColomn, strSortOrder, iPageSize, iPageIndex, out iTotalRecord, 2, 2, 2, assignedTo, roleName, prospectTypeId);
                    if (listProspects != null)
                    {
                        objProspects = listProspects.ToArray();
                    }
                }
                else
                {
                    var listProspects = objFranchisorDal.GetProspectsDetail(strProspectName, strStartDate, strEndDate,
                                                                            franchiseeid, istatusId, itypeId, 2, strZipCode, Convert.ToInt32(strDistance), 1, isFeeder,
                                                                            Convert.ToInt64(iSalesPersonId), territoryid, strSortColomn, strSortOrder, iPageSize, iPageIndex, out iTotalRecord, 2, 2, 2, assignedTo, roleName, prospectTypeId);
                    if (listProspects != null)
                    {
                        objProspects = listProspects.ToArray();
                    }
                }
            }
            else
            {
                string shellId       = IoC.Resolve <ISessionContext>().UserSession.CurrentOrganizationRole.OrganizationId.ToString();
                var    listProspects = objFranchisorDal.GetProspectsDetail(strProspectName, strStartDate, strEndDate,
                                                                           long.Parse(shellId), istatusId, itypeId, 2, strZipCode, int.Parse(strDistance), 1, isFeeder,
                                                                           iSalesPersonId, territoryid, strSortColomn, strSortOrder, iPageSize, iPageIndex, out iTotalRecord, 2, 2, 2, assignedTo, roleName, prospectTypeId);
                if (listProspects != null)
                {
                    objProspects = listProspects.ToArray();
                }
            }

            if (objProspects != null)
            {
                if (objProspects.Length == 1 && Request.QueryString["QuickSearch"] != null &&
                    Request.QueryString["QuickSearch"].Equals("True"))
                {
                    Response.Write("/App/Franchisee/SalesRep/SalesRepProspectDetails.aspx?Type=Host&QuickSearch=True&ProspectID=" +
                                   objProspects[0].ProspectID);
                }
                else
                {
                    var dtProspect = new DataTable();

                    //Create template for data table
                    dtProspect.Columns.Add("ProspectId", typeof(Int32));
                    dtProspect.Columns.Add("ProspectName");
                    dtProspect.Columns.Add("ProspectCreatedDate");
                    dtProspect.Columns.Add("PhoneOffice");
                    dtProspect.Columns.Add("ProspectStatus");
                    dtProspect.Columns.Add("NoOFCalls");
                    dtProspect.Columns.Add("NoOFMeeting");

                    dtProspect.Columns.Add("NoOfContacts");
                    dtProspect.Columns.Add("SalesPersonFirstName");
                    dtProspect.Columns.Add("SalesPersonLastName");
                    dtProspect.Columns.Add("FranchiseeName");
                    dtProspect.Columns.Add("ProspectAddressId");
                    dtProspect.Columns.Add("ProspectAddress1");
                    dtProspect.Columns.Add("ProspectAddress2");
                    dtProspect.Columns.Add("ProspectCity");
                    dtProspect.Columns.Add("ProspectState");

                    dtProspect.Columns.Add("ProspectZip");
                    dtProspect.Columns.Add("ProspectCountry");
                    dtProspect.Columns.Add("ProspectCompleteAddress");

                    dtProspect.Columns.Add("ContactFirstName");
                    dtProspect.Columns.Add("ContactLastName");
                    dtProspect.Columns.Add("ContactPhone");
                    dtProspect.Columns.Add("ContactEmail");

                    dtProspect.Columns.Add("ContactCallDate");
                    dtProspect.Columns.Add("ContactCallStatus");

                    dtProspect.Columns.Add("LnkContactViewAll");
                    dtProspect.Columns.Add("LnkContactAddCall");
                    dtProspect.Columns.Add("LnkContactAddMeeting");
                    dtProspect.Columns.Add("LnkactivityNotes");
                    dtProspect.Columns.Add("LnkViewDetails");
                    dtProspect.Columns.Add("LnkAddContact");
                    dtProspect.Columns.Add("LnkConvertToHost");
                    dtProspect.Columns.Add("NotesToolTip");


                    //Add all the fetched data tto data table
                    if (objProspects.Length > 0)
                    {
                        //// Case SalesRep
                        //if (usershellmodulerole.RoleName == Roles.SalesRep.ToString())
                        //{
                        //    //TODO: This filter is only for SaleRep and need to do for Franchisee also

                        //    // Sales Reps with territory assignments should only see hosts applicable to them.
                        //    long salesRepId = usershellmodulerole.RoleShellID;
                        //    ITerritoryRepository territoryRepository = new TerritoryRepository();
                        //    IHostRepository hostRepository = new HostRepository();
                        //    List<SalesRepTerritory> salesRepTerritories = territoryRepository.GetTerritoriesForSalesRep(salesRepId);
                        //    if (!salesRepTerritories.IsEmpty())
                        //    {
                        //        IEnumerable<string> acceptableZipCodes = salesRepTerritories.
                        //            SelectMany(srt => srt.ZipCodes).Distinct().Select(z => z.Zip);

                        //        // Filter out hosts not located in zip codes of this sales rep's territories.
                        //        objProspects = objProspects.Where(p => acceptableZipCodes.Contains(p.Address.Zip)).ToArray();

                        //        // Filter out hosts that do not host events of the type that the sales rep can see.
                        //        var prospectsToRemove = new List<EProspect>();
                        //        foreach (EProspect prospect in objProspects)
                        //        {
                        //            string hostingZipCode = prospect.Address.Zip;
                        //            SalesRepTerritory territoryEventIsHostedIn = salesRepTerritories.Single(srt => srt.ZipCodes.Select(z => z.Zip).
                        //                Contains(hostingZipCode));
                        //            EventType salesRepPermission = territoryEventIsHostedIn.SalesRepTerritoryAssignments.
                        //                Single(srta => srta.SalesRep.SalesRepresentativeId == salesRepId).EventTypeSetupPermission;

                        //            var acceptableEventTypes = hostRepository.GetEventTypesForHost(prospect.ProspectID);
                        //            if (salesRepPermission != EventType.Both && !acceptableEventTypes.Contains(salesRepPermission))
                        //            {
                        //                prospectsToRemove.Add(prospect);
                        //            }
                        //        }
                        //        objProspects = objProspects.Except(prospectsToRemove).ToArray();
                        //        iTotalRecord = objProspects.Count();
                        //    }
                        //}

                        foreach (var objProspect in objProspects)
                        {
                            DataRow drProspect = dtProspect.NewRow();
                            drProspect["ProspectId"]          = objProspect.ProspectID;
                            drProspect["ProspectName"]        = string.IsNullOrEmpty(objProspect.OrganizationName) ? "N/A" : objProspect.OrganizationName;
                            drProspect["ProspectCreatedDate"] = string.IsNullOrEmpty(objProspect.ProspectDate) ? "N/A" :
                                                                Convert.ToDateTime(objProspect.ProspectDate).ToShortDateString();
                            drProspect["PhoneOffice"] = !string.IsNullOrEmpty(objProspect.PhoneOffice) ? objCommonCode.FormatPhoneNumberGet(objProspect.PhoneOffice) : "N/A";

                            if (string.IsNullOrEmpty(objProspect.Status))
                            {
                                drProspect["ProspectStatus"] = "N/A";
                            }
                            else
                            {
                                string status;
                                switch (objProspect.Status)
                                {
                                case "1":
                                    status = "Hot";
                                    break;

                                case "2":
                                    status = "Cold";
                                    break;

                                case "3":
                                    status = "Dead";
                                    break;

                                case "4":
                                    status = "Call Back";
                                    break;

                                default:
                                    status = "none";
                                    break;
                                }
                                drProspect["ProspectStatus"] = status;
                            }

                            drProspect["NoOFCalls"]    = objProspect.NoOfCalls;
                            drProspect["NoOFMeeting"]  = objProspect.NoOfMeetings;
                            drProspect["NoOfContacts"] = objProspect.NoOfContacts;

                            if (string.IsNullOrEmpty(objProspect.FirstName) && string.IsNullOrEmpty(objProspect.LastName))
                            {
                                drProspect["SalesPersonFirstName"] = "N/A";
                                drProspect["SalesPersonLastName"]  = "";
                            }
                            else
                            {
                                drProspect["SalesPersonFirstName"] = objProspect.FirstName;
                                drProspect["SalesPersonLastName"]  = objProspect.LastName;
                            }
                            if (string.IsNullOrEmpty(objProspect.FranchiseeName))
                            {
                                drProspect["FranchiseeName"] = "N/A";
                            }
                            else
                            {
                                drProspect["FranchiseeName"] = objProspect.FranchiseeName;
                            }


                            var objAddress = objProspect.Address;

                            // Set Initially the new line in address
                            drProspect["ProspectAddressId"] = objAddress.AddressID.ToString();
                            drProspect["ProspectAddress1"]  = string.IsNullOrEmpty(objAddress.Address1) ? "" : objAddress.Address1;
                            drProspect["ProspectAddress2"]  = string.IsNullOrEmpty(objAddress.Address2) ? "" : objAddress.Address2;
                            drProspect["ProspectCity"]      = string.IsNullOrEmpty(objAddress.City) ? "N/A" : objAddress.City;
                            drProspect["ProspectState"]     = string.IsNullOrEmpty(objAddress.State) ? "N/A" : objAddress.State;

                            if (string.IsNullOrEmpty(objAddress.Zip) || (objAddress.Zip == "0"))
                            {
                                drProspect["ProspectZip"] = "N/A";
                            }
                            else
                            {
                                drProspect["ProspectZip"] = objAddress.Zip;
                            }

                            // Format Address
                            string prospectCompleteAddress = CommonCode.AddressMultiLine(objAddress.Address1,
                                                                                         objAddress.Address2, objAddress.City, objAddress.State, objAddress.Zip);
                            drProspect["ProspectCompleteAddress"] = prospectCompleteAddress;

                            var objContact = objProspect.Contact.ToArray();
                            if (string.IsNullOrEmpty(objContact[0].FirstName))
                            {
                                if (string.IsNullOrEmpty(objContact[0].LastName))
                                {
                                    drProspect["ContactFirstName"] = "N/A";
                                    drProspect["ContactLastName"]  = "";
                                }
                                else
                                {
                                    drProspect["ContactFirstName"] = objContact[0].FirstName;
                                    drProspect["ContactLastName"]  = objContact[0].LastName;
                                }
                            }
                            else
                            {
                                drProspect["ContactFirstName"] = objContact[0].FirstName;
                                drProspect["ContactLastName"]  = objContact[0].LastName;
                            }

                            if (string.IsNullOrEmpty(objContact[0].PhoneHome))
                            {
                                drProspect["ContactPhone"] = "N/A";
                            }
                            else if (objContact[0].PhoneHome.Trim().Equals("(___)-___-____"))
                            {
                                drProspect["ContactPhone"] = "N/A";
                            }
                            else
                            {
                                drProspect["ContactPhone"] = objCommonCode.FormatPhoneNumberGet(objContact[0].PhoneHome);
                            }

                            drProspect["ContactEmail"] = string.IsNullOrEmpty(objContact[0].EMail) ? "N/A" : objContact[0].EMail;

                            var objContactCall = objProspect.ContactCall;
                            drProspect["ContactCallDate"] = string.IsNullOrEmpty(objContactCall.StartDate) ? "N/A" : objContactCall.StartDate;


                            var objCallStatus = objContactCall.CallStatus;
                            drProspect["ContactCallStatus"] = string.IsNullOrEmpty(objCallStatus.Status) ? "N/A" : objCallStatus.Status;

                            // Prepare Notes ToolTips
                            bool blnNotes = false;
                            strNotesToolTip = strNotesToolTip + "<table cellpadding='3' cellspacing='0' border='0' width='100%'>";
                            // Date and Time
                            if (!string.IsNullOrEmpty(objContactCall.StartDate))
                            {
                                string[] strDateTime = objContactCall.StartDate.Split(' ');
                                if (strDateTime.Length >= 2)
                                {
                                    strNotesToolTip = strNotesToolTip + "<tr><td>Date: " + strDateTime[0] +
                                                      "</td><td>Time: " + strDateTime[1] + "</td></tr>";
                                    blnNotes = true;
                                }
                            }
                            // Duration
                            if (!string.IsNullOrEmpty(objCallStatus.Duration) && (objCallStatus.Duration != "0.00"))
                            {
                                strNotesToolTip = strNotesToolTip + "<tr><td colspan=2>Duration: " +
                                                  objCallStatus.Duration + " mins.</td></tr>";
                                blnNotes = true;
                            }
                            // Status
                            if (!string.IsNullOrEmpty(objCallStatus.Status))
                            {
                                strNotesToolTip = strNotesToolTip + "<tr><td colspan=2>Status: " + objCallStatus.Status +
                                                  "</td></tr>";
                                blnNotes = true;
                            }
                            // Notes
                            if (!string.IsNullOrEmpty(objCallStatus.Notes))
                            {
                                strNotesToolTip = strNotesToolTip + "<tr><td colspan=2>Notes: </td></tr><tr><td colspan=2>" +
                                                  objCallStatus.Notes + "</td></tr>";
                                blnNotes = true;
                            }
                            strNotesToolTip = strNotesToolTip + "</table>";

                            drProspect["NotesToolTip"] = blnNotes ? strNotesToolTip
                                : "<table cellpadding='3' cellspacing='0' border='0' width='100%'><tr><td> Details Not Available </td></tr></table>";
                            strNotesToolTip = string.Empty;
                            dtProspect.Rows.Add(drProspect);
                        }
                    }

                    if (dtProspect.Rows.Count > 0)
                    {
                        grdProspect.DataSource = dtProspect;
                        grdProspect.DataBind();
                        string pagingstring = ImplementPaging(iPageIndex, iPageSize, iTotalRecord);

                        HtmlForm formNew = Page.Form;
                        formNew.Controls.Clear();
                        formNew.Controls.Add(grdProspect);

                        var sb       = new System.Text.StringBuilder();
                        var htWriter = new HtmlTextWriter(new System.IO.StringWriter(sb));

                        formNew.RenderControl(htWriter);

                        string strRenderedHTML = sb.ToString();
                        int    startindex      = strRenderedHTML.IndexOf("<table");
                        int    endindex        = strRenderedHTML.LastIndexOf("</table>");
                        int    length          = (endindex - startindex) + 8;
                        strRenderedHTML = strRenderedHTML.Substring(startindex, length);
                        string totalRecord = "<span id=spnTotalRecordAsync>" + iTotalRecord + "</span>";
                        strRenderedHTML = "<div style='float: left; width: 746px'>" + strRenderedHTML + "</div>";

                        Response.Write(strRenderedHTML + pagingstring +
                                       "<p class=\"blueboxbotbg_cl\"><img src=\"/App/Images/specer.gif\" width=\"746\" height=\"5\" /></p>" + totalRecord);
                    }
                    else
                    {
                        string noRecordFound =
                            "<div style='float:left; width:746px; border:solid 1px #E7F0F5; padding:10px 0px 10px 0px; display:block;' id='dvNoProspectFound' runat='server'>";
                        noRecordFound = noRecordFound +
                                        "<div class='divnoitemfound_custdbrd' style='margin-top:0px;'><p class='divnoitemtxt_custdbrd'><span class='orngbold18_default'>No Records Found</span></p></div></div>";
                        Response.Write(noRecordFound);
                    }
                }
            }
        }