예제 #1
0
        public DataPage <ClientBaseInfo> Client_Find(
            ClientSearchCriteria criteria,
            List <SortCriteria <ClientSortField> > sortCriteria,
            PageRequest pageRequest)
        {
            List <SqlParameter> parameters = new List <SqlParameter>();

            parameters.AddInputParameter("@Firstname", SqlDbType.NVarChar, criteria.Firstname);
            parameters.AddInputParameter("@Secondname", SqlDbType.NVarChar, criteria.Secondname);
            parameters.AddInputParameter("@Lastname", SqlDbType.NVarChar, criteria.Lastname);

            parameters.AddInputParameter("@Birthday", SqlDbType.Date, criteria.Birthday);
            parameters.AddInputParameter("@TemporaryPolicyDateFrom", SqlDbType.Date, criteria.TemporaryPolicyDateFrom);
            parameters.AddInputParameter("@TemporaryPolicyDateTo", SqlDbType.Date, criteria.TemporaryPolicyDateTo);
            parameters.AddInputParameter("@TemporaryPolicyNumber", SqlDbType.NVarChar, criteria.TemporaryPolicyNumber);
            parameters.AddInputParameter("@PolicySeries", SqlDbType.NVarChar, criteria.PolicySeries);
            parameters.AddInputParameter("@PolicyNumber", SqlDbType.NVarChar, criteria.PolicyNumber);
            parameters.AddInputParameter("@PolicyDateFrom", SqlDbType.Date, criteria.PolicyDateFrom);
            parameters.AddInputParameter("@PolicyDateTo", SqlDbType.Date, criteria.PolicyDateTo);
            parameters.AddInputParameter("@UnifiedPolicyNumber", SqlDbType.NVarChar, criteria.UnifiedPolicyNumber);

            SqlParameter totalCountParameter = parameters.AddOutputParameter("@total_count", SqlDbType.Int);

            parameters.AddInputParameter("@sort_criteria", SqlDbType.Structured, DaoHelper.GetSortFieldsTable(sortCriteria));

            parameters.AddInputParameter("@Page_size", SqlDbType.Int, pageRequest.PageSize);
            parameters.AddInputParameter("@Page_number", SqlDbType.Int, pageRequest.PageNumber);

            List <ClientBaseInfo> clients = Execute_GetList(ClientBaseInfoMaterializer.Instance, "Client_Find", parameters);

            return(DaoHelper.GetDataPage(clients, totalCountParameter, pageRequest));
        }
예제 #2
0
    public string GetClientsByName(string name, string userid)
    {
        // Used in activity entry screen.
        IClientService service = null;

        try
        {
            // Create search criteria.
            ClientSearchCriteria criteria = new ClientSearchCriteria();
            criteria.Name = name;

            // Create the service.
            service = AppService.Create <IClientService>();
            // TODO: Need to change.
            UserAuthentication authentication = new UserAuthentication();
            service.AppManager = authentication.AppManager;

            // Call service method.
            List <Client> clients    = service.Search(criteria, Convert.ToInt32(userid));
            string        clientJson = "[]";
            if (clients != null)
            {
                var resultList = from item in clients
                                 where item.IsActive = true
                                                       select new
                {
                    Id          = item.Id,
                    Name        = item.Name,
                    Description = item.Description
                };

                // Serialize.
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                clientJson = serializer.Serialize(resultList);
            }

            // Return the value.
            return(clientJson);
        }
        catch { throw; }
        finally
        {
            // Dispose.
            if (service != null)
            {
                service.Dispose();
            }
        }
    }
예제 #3
0
 public ClientSearchCriteriaModel(ClientSearchCriteria criteria)
 {
     this.Firstname               = criteria.Firstname;
     this.Secondname              = criteria.Secondname;
     this.Lastname                = criteria.Lastname;
     this.Birthday                = criteria.Birthday;
     this.TemporaryPolicyNumber   = criteria.TemporaryPolicyNumber;
     this.PolicySeries            = criteria.PolicySeries;
     this.PolicyNumber            = criteria.PolicyNumber;
     this.PolicyDateFrom          = criteria.PolicyDateFrom;
     this.PolicyDateTo            = criteria.PolicyDateTo;
     this.TemporaryPolicyDateTo   = criteria.TemporaryPolicyDateTo;
     this.TemporaryPolicyDateFrom = criteria.TemporaryPolicyDateFrom;
     this.PolicyNumber            = criteria.PolicyNumber;
     this.UnifiedPolicyNumber     = criteria.UnifiedPolicyNumber;
 }
예제 #4
0
        public IList <ClientDTO> SearchClients(ClientSearchCriteria sc)
        {
            try
            {
                using (var dbModel = InitiateDbContext())
                {
                    IList <Client> clients;

                    if (string.IsNullOrEmpty(sc.FirstName) &&
                        string.IsNullOrEmpty(sc.LastName) &&
                        string.IsNullOrEmpty(sc.MedicalRecordNumber) &&
                        sc.DateOfBirth == null)
                    {
                        clients = dbModel.Clients.Include(x => x.GenderLookup)
                                  .Include(x => x.RaceLookup)
                                  .ToList();
                    }
                    else
                    {
                        clients = dbModel.Clients.Where(x => sc.FirstName == null || (x.FirstName + "").ToLower().StartsWith((sc.FirstName + "").ToLower()))
                                  .Where(x => sc.LastName == null || (x.LastName + "").ToLower().StartsWith((sc.LastName + "").ToLower()))
                                  .Where(x => sc.MedicalRecordNumber == null || (x.MedicalRecordNumber + "").ToLower().StartsWith((sc.MedicalRecordNumber + "").ToLower()))
                                  .Where(x => sc.DateOfBirth == null || DateTime.Equals(x.DateOfBirth, sc.DateOfBirth))
                                  .Include(x => x.GenderLookup)
                                  .Include(x => x.RaceLookup)
                                  .AsNoTracking().ToList();
                    }
                    return((from C in clients
                            orderby C.Id descending
                            select new ClientDTO
                    {
                        Id = C.Id,
                        Name = C.DisplayName,
                        DateOfBirth = C.DateOfBirth,
                        Gender = C.GenderLookup.Description,
                        Race = C.RaceLookup.Description,
                        MedicalRecordNumber = C.MedicalRecordNumber,
                    }).ToList());
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString());
                throw;
            }
        }
 /// <summary>
 /// Get a list of clients that match the search criteria
 /// </summary>
 /// <param name="oHostSecurityToken">HostSecurityToken obtained when security provider of IWS is called</param>
 /// <param name="collectionRequest">Information about the collection being requested</param>
 /// <param name="criteria">Client search criteria</param>
 /// <returns></returns>
 public ClientSearchReturnValue ClientSearch(HostSecurityToken oHostSecurityToken, CollectionRequest collectionRequest,
     ClientSearchCriteria criteria)
 {
     ClientSearchReturnValue returnValue = null;
     if (Functions.ValidateIWSToken(oHostSecurityToken))
     {
         oClientService = new ClientService();
         returnValue = oClientService.ClientSearch(Functions.GetLogonIdFromToken(oHostSecurityToken), collectionRequest, criteria);
     }
     else
     {
         returnValue = new ClientSearchReturnValue();
         returnValue.Success = false;
         returnValue.Message = "Invalid Token";
     }
     return returnValue;
 }
        /// <summary>
        /// Gets the client details.
        /// </summary>
        private void GetClientDetails(string matterReference)
        {
            ClientServiceClient clientService = null;

            try
            {
                CollectionRequest collectionRequest = new CollectionRequest();
                collectionRequest.ForceRefresh = true;

                ClientSearchCriteria criteria = new ClientSearchCriteria();
                criteria.ClientReference = matterReference.Substring(0, 6);

                clientService = new ClientServiceClient();
                ClientSearchReturnValue returnValue = clientService.ClientSearch(_logonSettings.LogonId,
                                                                                 collectionRequest, criteria);

                if (returnValue.Success)
                {
                    if (returnValue.Clients != null)
                    {
                        Session[SessionName.MemberId]       = returnValue.Clients.Rows[0].MemberId;
                        Session[SessionName.OrganisationId] = returnValue.Clients.Rows[0].OrganisationId;
                        Session[SessionName.ClientRef]      = returnValue.Clients.Rows[0].ClientReference;
                        Session[SessionName.ClientName]     = returnValue.Clients.Rows[0].Name;
                    }
                }
                else
                {
                    throw new Exception(returnValue.Message);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (clientService != null)
                {
                    if (clientService.State != System.ServiceModel.CommunicationState.Faulted)
                    {
                        clientService.Close();
                    }
                }
            }
        }
예제 #7
0
        /// <summary>
        /// Get a list of clients that match the search criteria
        /// </summary>
        /// <param name="oHostSecurityToken">HostSecurityToken obtained when security provider of IWS is called</param>
        /// <param name="collectionRequest">Information about the collection being requested</param>
        /// <param name="criteria">Client search criteria</param>
        /// <returns></returns>
        public ClientSearchReturnValue ClientSearch(HostSecurityToken oHostSecurityToken, CollectionRequest collectionRequest,
                                                    ClientSearchCriteria criteria)
        {
            ClientSearchReturnValue returnValue = null;

            if (Functions.ValidateIWSToken(oHostSecurityToken))
            {
                oClientService = new ClientService();
                returnValue    = oClientService.ClientSearch(Functions.GetLogonIdFromToken(oHostSecurityToken), collectionRequest, criteria);
            }
            else
            {
                returnValue         = new ClientSearchReturnValue();
                returnValue.Success = false;
                returnValue.Message = "Invalid Token";
            }
            return(returnValue);
        }
예제 #8
0
        public ClientSearchCriteria GetClientSearchCriteria()
        {
            ClientSearchCriteria criteria = new ClientSearchCriteria()
            {
                Birthday                = this.Birthday,
                Firstname               = this.Firstname,
                Lastname                = this.Lastname,
                PolicySeries            = this.PolicySeries,
                PolicyNumber            = this.PolicyNumber,
                PolicyDateFrom          = this.PolicyDateFrom,
                PolicyDateTo            = this.PolicyDateTo,
                Secondname              = this.Secondname,
                TemporaryPolicyDateTo   = this.TemporaryPolicyDateTo,
                TemporaryPolicyDateFrom = this.TemporaryPolicyDateFrom,
                TemporaryPolicyNumber   = this.TemporaryPolicyNumber,
                UnifiedPolicyNumber     = this.UnifiedPolicyNumber
            };

            return(criteria);
        }
예제 #9
0
        /// <summary>
        /// Returns sorted list of ClientBaseInfo by specified criteria
        /// </summary>
        /// <param name="criteria">Specified criteria</param>
        /// <param name="sortCriteria">Sort criteria</param>
        /// <param name="pageRequest">Page size and number</param>
        /// <returns>List of ClientBaseInfo</returns>
        public DataPage <ClientBaseInfo> Client_Find(
            ClientSearchCriteria criteria,
            List <SortCriteria <ClientSortField> > sortCriteria,
            PageRequest pageRequest)
        {
            if (criteria == null)
            {
                throw new ArgumentNullException("criteria can't be null");
            }

            if (sortCriteria == null)
            {
                throw new ArgumentNullException("sortCriteria can't be null");
            }

            if (pageRequest == null)
            {
                throw new ArgumentNullException("pageRequest can't be null");
            }

            return(ClientDao.Instance.Client_Find(criteria, sortCriteria, pageRequest));
        }
        public Task <PaginationResult <DbClient> > GetClientsAsync(
            ClientSearchCriteria criteria, CancellationToken cancellationToken)
        {
            var policy = _policyRegistry["SqlConnection"] as AsyncPolicy;

            // ReSharper disable once PossibleNullReferenceException
            return(policy.ExecuteAsync(
                       async() =>
            {
                IQueryable <DbClient> query = _context
                                              .Clients
                                              .Include(c => c.Claims);

                if (!string.IsNullOrEmpty(criteria.ClientId))
                {
                    query = query.Where(c => c.ClientId == criteria.ClientId);
                }

                if (!string.IsNullOrEmpty(criteria.TenantId))
                {
                    query = query.Where(c => c.Claims.Any(
                                            cl => cl.Type == "Tenant" && cl.Value == criteria.TenantId));
                }

                var totalCount = await query.CountAsync(cancellationToken);
                var subItems = await query
                               .Skip(criteria.PageIndex * criteria.PageSize)
                               .Take(criteria.PageSize)
                               .ToArrayAsync(cancellationToken);
                return new PaginationResult <DbClient>
                {
                    PageIndex = criteria.PageIndex,
                    PageSize = criteria.PageSize,
                    TotalCount = totalCount,
                    Items = subItems
                };
            }));
        }
예제 #11
0
        public ActionResult Index(ClientListModel clientListModel)
        {
            ClientSearchCriteria      criteria = clientListModel.SearchCriteriaModel.GetClientSearchCriteria();
            DataPage <ClientBaseInfo> clients  = clientBusinessLogic.Client_Find(
                criteria,
                new List <SortCriteria <ClientSortField> >(),
                new PageRequest()
            {
                PageNumber = clientListModel.PageNumber, PageSize = clientListModel.PageSize
            });
            ClientListModel model = new ClientListModel()
            {
                Items = clients.Data
                        .Select(item => new ClientBaseInfoModel(item)),
                SearchCriteriaModel = new ClientSearchCriteriaModel(
                    criteria),
                PageNumber = clientListModel.PageNumber,
                PageSize   = clientListModel.PageSize,
                TotalCount = clients.TotalCount
            };

            return(View(model));
        }
예제 #12
0
        /// <summary>
        /// Searches for clients that match the search criteria.
        /// </summary>
        public ClientSearchItem[] SearchClient(int startRow, int pageSize, string sortBy, string name, string NINo, string partner,
                                               string DOB, string postcode, string town, bool forceRefresh)
        {
            ClientServiceClient clientService = null;

            ClientSearchItem[] clients = null;
            try
            {
                if (HttpContext.Current.Session[SessionName.LogonSettings] != null)
                {
                    if (name == null || name.Trim() == string.Empty)
                    {
                        if (NINo == null || NINo == string.Empty)
                        {
                            if (partner == null || partner.Trim() == string.Empty)
                            {
                                if (DOB == null || DOB.Trim() == string.Empty)
                                {
                                    if (postcode == null || postcode.Trim() == string.Empty)
                                    {
                                        if (town == null || town.Trim() == string.Empty)
                                        {
                                            throw new Exception("Please enter search criteria");
                                        }
                                    }
                                }
                            }
                        }
                    }


                    if (!IsReset)
                    {
                        // LSC - Insert Wildcards - 28/08/2010
                        if (!string.IsNullOrWhiteSpace(name) && !name.Contains('%'))
                        {
                            name = "%" + name.Trim() + "%";
                        }

                        Guid _logonId = ((LogonReturnValue)HttpContext.Current.Session[SessionName.LogonSettings]).LogonId;
                        CollectionRequest collectionRequest = new CollectionRequest();
                        collectionRequest.ForceRefresh = forceRefresh;
                        collectionRequest.StartRow     = startRow;
                        collectionRequest.RowCount     = pageSize;


                        ClientSearchCriteria criteria = new ClientSearchCriteria();
                        criteria.Name = name != null?name.Replace("'", "''")  : name;

                        criteria.NINumber = NINo != null?NINo.Replace("'", "''")  : NINo;

                        criteria.OrganisationId = DataConstants.DummyGuid;
                        criteria.MemberId       = DataConstants.DummyGuid;
                        criteria.OrderBy        = sortBy;
                        Guid partnerId = DataConstants.DummyGuid;

                        if (partner != null && partner != string.Empty)
                        {
                            partnerId = new Guid(partner);
                        }
                        criteria.Partner = partnerId;

                        if (DOB != null && DOB.Length > 0)
                        {
                            criteria.DateOfBirthFrom = Convert.ToDateTime(DOB.Trim());
                            criteria.DateOfBirthTo   = Convert.ToDateTime(DOB.Trim());
                        }
                        else
                        {
                            criteria.DateOfBirthFrom = null;
                            criteria.DateOfBirthTo   = null;
                        }

                        criteria.PostCode = postcode != null?postcode.Replace("'", "''")  : postcode;

                        criteria.Town = town != null?town.Replace("'", "''")  : town;

                        clientService = new ClientServiceClient();
                        ClientSearchReturnValue returnValue = clientService.ClientSearch(_logonId,
                                                                                         collectionRequest, criteria);

                        if (returnValue.Success)
                        {
                            _clientRowCount = returnValue.Clients.TotalRowCount;
                            clients         = returnValue.Clients.Rows;
                        }
                        else
                        {
                            if (returnValue.Message == "SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.")
                            {
                                throw new Exception("Date is invalid");
                            }
                            else
                            {
                                throw new Exception(returnValue.Message);
                            }
                        }
                    }
                }
                return(clients);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (clientService != null)
                {
                    if (clientService.State != System.ServiceModel.CommunicationState.Faulted)
                    {
                        clientService.Close();
                    }
                }
            }
        }
        /// <summary>
        /// Searches for clients that match the search criteria.
        /// </summary>
        public ClientSearchItem[] SearchClient(int startRow, int pageSize, string sortBy,  string name, string NINo, string partner,
                                    string DOB, string postcode, string town, bool forceRefresh)
        {
            ClientServiceClient clientService = null;
            ClientSearchItem[] clients = null;
            try
            {
                if (HttpContext.Current.Session[SessionName.LogonSettings] != null)
                {
                    if (name == null || name.Trim() == string.Empty)
                        if (NINo == null || NINo == string.Empty)
                            if (partner == null || partner.Trim() == string.Empty)
                                if (DOB == null || DOB.Trim() == string.Empty)
                                    if (postcode == null || postcode.Trim() == string.Empty)
                                        if (town == null || town.Trim() == string.Empty)
                                                throw new Exception("Please enter search criteria");

                    if (!IsReset)
                    {
                        // LSC - Insert Wildcards - 28/08/2010
                        if (!string.IsNullOrWhiteSpace(name) && !name.Contains('%'))
                        {
                            name = "%" + name.Trim() + "%";
                        }

                        Guid _logonId = ((LogonReturnValue)HttpContext.Current.Session[SessionName.LogonSettings]).LogonId;
                        CollectionRequest collectionRequest = new CollectionRequest();
                        collectionRequest.ForceRefresh = forceRefresh;
                        collectionRequest.StartRow = startRow;
                        collectionRequest.RowCount = pageSize;

                        ClientSearchCriteria criteria = new ClientSearchCriteria();
                        criteria.Name = name != null ? name.Replace("'", "''")  : name;
                        criteria.NINumber = NINo != null ? NINo.Replace("'", "''")  : NINo;
                        criteria.OrganisationId = DataConstants.DummyGuid;
                        criteria.MemberId = DataConstants.DummyGuid;
                        criteria.OrderBy = sortBy;
                        Guid partnerId = DataConstants.DummyGuid;

                        if (partner != null && partner != string.Empty)
                        {
                            partnerId = new Guid(partner);
                        }
                        criteria.Partner = partnerId;

                        if (DOB != null && DOB.Length > 0)
                        {
                            criteria.DateOfBirthFrom = Convert.ToDateTime(DOB.Trim());
                            criteria.DateOfBirthTo = Convert.ToDateTime(DOB.Trim());
                        }
                        else
                        {
                            criteria.DateOfBirthFrom = null;
                            criteria.DateOfBirthTo = null;
                        }

                        criteria.PostCode = postcode != null ? postcode.Replace("'", "''")  : postcode;
                        criteria.Town = town != null ? town.Replace("'", "''")  : town;

                        clientService = new ClientServiceClient();
                        ClientSearchReturnValue returnValue = clientService.ClientSearch(_logonId,
                                                    collectionRequest, criteria);

                        if (returnValue.Success)
                        {
                            _clientRowCount = returnValue.Clients.TotalRowCount;
                            clients = returnValue.Clients.Rows;
                        }
                        else
                        {
                            if (returnValue.Message == "SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.")
                                throw new Exception("Date is invalid");
                            else
                                throw new Exception(returnValue.Message);

                        }
                    }
                }
                return clients;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (clientService != null)
                {
                    if (clientService.State != System.ServiceModel.CommunicationState.Faulted)
                        clientService.Close();
                }
            }
        }
        /// <summary>
        /// Gets the client details.
        /// </summary>
        private void GetClientDetails(string matterReference)
        {
            ClientServiceClient clientService = null;
            try
            {
                CollectionRequest collectionRequest = new CollectionRequest();
                collectionRequest.ForceRefresh = true;

                ClientSearchCriteria criteria = new ClientSearchCriteria();
                criteria.ClientReference = matterReference.Substring(0, 6);

                clientService = new ClientServiceClient();
                ClientSearchReturnValue returnValue = clientService.ClientSearch(_logonSettings.LogonId,
                                            collectionRequest, criteria);

                if (returnValue.Success)
                {
                    if (returnValue.Clients != null)
                    {
                        Session[SessionName.MemberId] = returnValue.Clients.Rows[0].MemberId;
                        Session[SessionName.OrganisationId] = returnValue.Clients.Rows[0].OrganisationId;
                        Session[SessionName.ClientRef] = returnValue.Clients.Rows[0].ClientReference;
                        Session[SessionName.ClientName] = returnValue.Clients.Rows[0].Name;
                    }
                }
                else
                {
                    throw new Exception(returnValue.Message);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (clientService != null)
                {
                    if (clientService.State != System.ServiceModel.CommunicationState.Faulted)
                        clientService.Close();
                }
            }
        }
        protected void _imgBtnSearch_Click(object sender, ImageClickEventArgs e)
        {
            if (_txtSearch.Text.Trim() == string.Empty)
            {
                _txtSearch.Text = AllClients;
            }

            ClientServiceClient clientService = null;
            try
            {
                CollectionRequest collectionRequest = new CollectionRequest();
                collectionRequest.ForceRefresh = true;

                ClientSearchCriteria criteria = new ClientSearchCriteria();
                if (_txtSearch.Text.Trim() == string.Empty || _txtSearch.Text.Trim() == AllClients)
                {
                    criteria.Name = string.Empty;
                }
                else
                {
                    criteria.Name = _txtSearch.Text.Trim();
                }

                if (_ddlFeeEarner.SelectedIndex > 0)
                {
                    criteria.Partner = new Guid(_ddlFeeEarner.SelectedValue);
                }

                clientService = new ClientServiceClient();
                ClientSearchReturnValue returnValue = clientService.ClientSearch(_logonId,
                                            collectionRequest, criteria);

                _ddlClients.Items.Clear();
                _ddlClientMatters.Items.Clear();

                if (returnValue.Success)
                {
                    if (returnValue.Clients.Rows.Length > 0)
                    {
                        foreach (ClientSearchItem client in returnValue.Clients.Rows)
                        {
                            ListItem item = new ListItem();
                            item.Text = client.ClientReference.Trim() + " - " + client.Name;
                            item.Value = client.MemberId.ToString() + "$" + client.OrganisationId.ToString();
                            _ddlClients.Items.Add(item);
                        }
                    }
                    else
                    {
                        SuccessEventArgs success = new SuccessEventArgs();
                        success.Message = "Search is complete. There are no results to display.";
                        OnSearchSuccessful(success);
                    }

                    if (_ddlClients.Items.Count > 0)
                    {
                        _clientRowCount = _ddlClients.Items.Count;

                        Guid memberId = new Guid(GetValueOnIndexFromArray(_ddlClients.SelectedValue, 0));
                        Guid organisationId = new Guid(GetValueOnIndexFromArray(_ddlClients.SelectedValue, 1));
                        GetClientMatters(memberId, organisationId);
                        SelectLastMatter();
                    }

                }
                else
                {
                    ErrorEventArgs error = new ErrorEventArgs();
                    error.Message = returnValue.Message.Replace("WebClientSearch requires some parameters", "Please select a Fee Earner or use the client search.");
                    OnError(error);
                }
            }
            catch (Exception ex)
            {
                ErrorEventArgs error = new ErrorEventArgs();
                error.Message = ex.Message;
                OnError(error);
            }
            finally
            {
                if (clientService != null)
                {
                    if (clientService.State != System.ServiceModel.CommunicationState.Faulted)
                        clientService.Close();
                }
            }
        }
        protected void _imgBtnSearch_Click(object sender, ImageClickEventArgs e)
        {
            if (_txtSearch.Text.Trim() == string.Empty)
            {
                _txtSearch.Text = AllClients;
            }

            ClientServiceClient clientService = null;

            try
            {
                CollectionRequest collectionRequest = new CollectionRequest();
                collectionRequest.ForceRefresh = true;

                ClientSearchCriteria criteria = new ClientSearchCriteria();
                if (_txtSearch.Text.Trim() == string.Empty || _txtSearch.Text.Trim() == AllClients)
                {
                    criteria.Name = string.Empty;
                }
                else
                {
                    criteria.Name = _txtSearch.Text.Trim();
                }

                if (_ddlFeeEarner.SelectedIndex > 0)
                {
                    criteria.Partner = new Guid(_ddlFeeEarner.SelectedValue);
                }

                clientService = new ClientServiceClient();
                ClientSearchReturnValue returnValue = clientService.ClientSearch(_logonId,
                                                                                 collectionRequest, criteria);

                _ddlClients.Items.Clear();
                _ddlClientMatters.Items.Clear();

                if (returnValue.Success)
                {
                    if (returnValue.Clients.Rows.Length > 0)
                    {
                        foreach (ClientSearchItem client in returnValue.Clients.Rows)
                        {
                            ListItem item = new ListItem();
                            item.Text  = client.ClientReference.Trim() + " - " + client.Name;
                            item.Value = client.MemberId.ToString() + "$" + client.OrganisationId.ToString();
                            _ddlClients.Items.Add(item);
                        }
                    }
                    else
                    {
                        SuccessEventArgs success = new SuccessEventArgs();
                        success.Message = "Search is complete. There are no results to display.";
                        OnSearchSuccessful(success);
                    }

                    if (_ddlClients.Items.Count > 0)
                    {
                        _clientRowCount = _ddlClients.Items.Count;

                        Guid memberId       = new Guid(GetValueOnIndexFromArray(_ddlClients.SelectedValue, 0));
                        Guid organisationId = new Guid(GetValueOnIndexFromArray(_ddlClients.SelectedValue, 1));
                        GetClientMatters(memberId, organisationId);
                        SelectLastMatter();
                    }
                }
                else
                {
                    ErrorEventArgs error = new ErrorEventArgs();
                    error.Message = returnValue.Message.Replace("WebClientSearch requires some parameters", "Please select a Fee Earner or use the client search.");
                    OnError(error);
                }
            }
            catch (Exception ex)
            {
                ErrorEventArgs error = new ErrorEventArgs();
                error.Message = ex.Message;
                OnError(error);
            }
            finally
            {
                if (clientService != null)
                {
                    if (clientService.State != System.ServiceModel.CommunicationState.Faulted)
                    {
                        clientService.Close();
                    }
                }
            }
        }
    private void SearchClient()
    {
        IClientService service = null;

        try
        {
            // Get the values.
            string name   = txtSearchName.Value;
            string status = ddlStatus.Items[ddlStatus.SelectedIndex].Value;

            // Validate.
            this.ValidateSearchEntity();


            // Create the service.
            service            = AppService.Create <IClientService>();
            service.AppManager = this.mAppManager;

            // Build search criteria.
            ClientSearchCriteria criteria = new ClientSearchCriteria();
            criteria.Name   = name;
            criteria.Status = status;

            // Invoke service method.
            mclientlist = service.Search(criteria, 0);

            // Display the list.
            this.DisplayList(mclientlist);


            if (gvwEntityList.Rows.Count == 0)
            {
                dvinitalvalue.Visible = true;
                divEmptyRow.Visible   = true;
                this.ShowHideValidationMessage(true);
                this.HideIntialView(true);
                //this.divEmptyRow.InnerHtml = "<b>No Record Found </b>";
                this.hdrGridHeader.InnerText = string.Empty;
                dvinitalvalue.Visible        = true;
            }
            else
            {
                dvinitalvalue.Visible = false;
                //gvwEntityList.Columns[0].wid = 200;
//                System.Windows.Forms.DataGridViewTextBoxColumn col = new DataGridViewTextBoxColumn();

                //   gvwEntityList.Columns[1].Width = 108;
                divEmptyRow.Visible = false;
                this.ShowHideValidationMessage(false);
                //this.HideIntialView(false);
                // this.hdrGridHeader.InnerText = "Clients List: (" + mclientlist.Count + " found)";
                this.hdrGridHeader.InnerText = cntlist + " (" + mclientlist.Count + " " + cntFound + ")";

                List <LblLanguage> lblLanguagelst = null;

                ILblLanguage mLanguageService = null;
                lblLanguagelst              = new List <LblLanguage>();
                mLanguageService            = AppService.Create <ILblLanguage>();
                mLanguageService.AppManager = ((IAppManager)Session["APP_MANAGER"]);
                // retrieve
                lblLanguagelst = mLanguageService.RetrieveLabel(((IAppManager)Session["APP_MANAGER"]).LoginUser.Id, "CLIENT");

                Utility _objUtil = new Utility();
                _objUtil.LoadGridLabels(lblLanguagelst, gvwEntityList);
                dvinitalvalue.Visible = false;
            }


            this.divSuccessMessage.InnerHtml = string.Empty;
            this.DisableRefershControl();
        }
        catch (ValidationException ex)
        {
            //Display the validation  errors.
            StringBuilder ErrorMessage = new StringBuilder();
            ErrorMessage.Append(string.Format("<table><tr><td>{0}</td></tr>", ex.Message));
            foreach (string s in ex.Data.Values)
            {
                ErrorMessage.Append(string.Format("<tr><td>{0}</td></tr></table>", s.ToString()));
            }
            //Hide the Error message
            this.divSuccessMessage.InnerHtml = ErrorMessage.ToString();
            this.HideIntialView(true);
            //Hide List Found.
            this.hdrGridHeader.InnerText = string.Empty;
            //Disable the Refersh control
            this.lnkrefresh.Enabled = false;
        }

        catch { throw; }
        finally
        {
            if (service != null)
            {
                service.Dispose();
            }
        }
    }
        /// <summary>
        /// Get a list of clients that match the search criteria
        /// </summary>
        /// <param name="logonId">Logon id obtained when logging on to the logon service</param>
        /// <param name="collectionRequest">Information about the collection being requested</param>
        /// <param name="criteria">Client search criteria</param>
        /// <returns></returns>
        public ClientSearchReturnValue ClientSearch(Guid logonId, CollectionRequest collectionRequest,
            ClientSearchCriteria criteria)
        {
            ClientSearchReturnValue returnValue = new ClientSearchReturnValue();

            try
            {
                // Get the logged on user from the current logons and add their
                // ApplicationSettings the list of concurrent sessions.
                Host.LoadLoggedOnUser(logonId);

                try
                {
                    switch (UserInformation.Instance.UserType)
                    {
                        // Can do everything
                        case DataConstants.UserType.Staff:
                        case DataConstants.UserType.ThirdParty:
                            // The query will return only clients that the third party is allowed to see
                            break;
                        case DataConstants.UserType.Client:
                            throw new Exception("Access denied");
                        default:
                            throw new Exception("Access denied");
                    }

                    // Create a data list creator for a list of matters
                    DataListCreator<ClientSearchItem> dataListCreator = new DataListCreator<ClientSearchItem>();

                    // Declare an inline event (annonymous delegate) to read the
                    // dataset if it is required
                    dataListCreator.ReadDataSet += delegate(object Sender, ReadDataSetEventArgs e)
                    {
                        e.DataSet = SrvClientCommon.WebClientSearch(criteria.OrganisationId,
                                                                    criteria.MemberId,
                                                                    criteria.Name,
                                                                    criteria.BusinessSource,
                                                                    criteria.ClientReference,
                                                                    criteria.DateOfBirthFrom,
                                                                    criteria.DateOfBirthTo,
                                                                    criteria.PostCode,
                                                                    criteria.Partner,
                                                                    criteria.Branch,
                                                                    criteria.NINumber,
                                                                    criteria.ClientGroup,
                                                                    criteria.Town);

                        if (criteria.OrderBy != string.Empty)
                        {
                            DataTable dt = Functions.SortDataTable(e.DataSet.Tables[0], criteria.OrderBy);
                            e.DataSet.Tables.Remove("Table");
                            e.DataSet.Tables.Add(dt);
                        }

                    };

                    // Create the data list
                    DataList<ClientSearchItem> clientList = dataListCreator.Create(logonId,
                        // Give the query a name so it can be cached
                        "ClientSearch",
                        // Tell it the query criteria used so if the cache is accessed
                        // again it knows if it is the same query
                        criteria.ToString(),
                        collectionRequest,
                        // Import mappings to map the dataset row fields to the data
                        // list entity properties
                        new ImportMapping[] {
                            new ImportMapping("MemberId", "memId"),
                            new ImportMapping("OrganisationId", "orgId"),
                            new ImportMapping("ClientReference", "cliRef"),
                            new ImportMapping("Name", "Name"),
                            new ImportMapping("Address","Address"),
                            new ImportMapping("PartnerName", "Partner"),
                            new ImportMapping("Partner","cliPartner"),
                            new ImportMapping("DateOfBirth","DateofBirth"),
                            new ImportMapping("NationalInsuranceNo","personNHINo"),
                            new ImportMapping("DateOfDeath","PersonDOD")
                            }
                        );

                    clientList.Rows.ForEach(delegate(ClientSearchItem item)
                    {
                        if (item.MemberId != DataConstants.DummyGuid)
                        {
                            if (SrvClientCommon.IsClientArchived(item.MemberId))
                            {
                                item.IsArchived = true;
                            }
                            else
                            {
                                item.IsArchived = false;
                            }
                        }

                        if (item.OrganisationId != DataConstants.DummyGuid)
                        {
                            if (SrvClientCommon.IsClientArchived(item.OrganisationId))
                            {
                                item.IsArchived = true;
                            }
                            else
                            {
                                item.IsArchived = false;
                            }
                        }

                    });

                    returnValue.Clients = clientList;
                }
                finally
                {
                    // Remove the logged on user's ApplicationSettings from the
                    // list of concurrent sessions
                    Host.UnloadLoggedOnUser();
                }
            }
            catch (System.Data.SqlClient.SqlException)
            {
                returnValue.Success = false;
                returnValue.Message = Functions.SQLErrorMessage;
            }
            catch (Exception ex)
            {
                returnValue.Success = false;
                returnValue.Message = ex.Message;
            }

            return returnValue;
        }