예제 #1
0
    private void GetCompanyGridDataSource(GridSortCommandEventArgs sortEventArgs)
    {
        int pageNumber = CompanyGrid.CurrentPageIndex + 1;
        string sortExpress = string.Empty;
        string sortExpressInvert = string.Empty;
        foreach (GridSortExpression item in CompanyGrid.MasterTableView.SortExpressions)
        {
            GridSortOrder newSortOrder = item.SortOrder;
            if (sortEventArgs != null && item.FieldName == sortEventArgs.SortExpression)
            {
                newSortOrder = sortEventArgs.NewSortOrder;
            }

            if (!string.IsNullOrEmpty(sortExpress) && newSortOrder != GridSortOrder.None)
            {
                sortExpress += ", ";
                sortExpressInvert += ", ";
            }
            if (newSortOrder == GridSortOrder.Ascending)
            {
                sortExpress += item.FieldName + " ASC";
                sortExpressInvert += item.FieldName + " DESC";
            }
            else if (newSortOrder == GridSortOrder.Descending)
            {
                sortExpress += item.FieldName + " DESC";
                sortExpressInvert += item.FieldName + " ASC";
            }
        }

        if (sortEventArgs != null && !sortExpress.Contains(sortEventArgs.SortExpression))
        {
            if (!string.IsNullOrEmpty(sortExpress) && sortEventArgs.NewSortOrder != GridSortOrder.None)
            {
                sortExpress += ", ";
                sortExpressInvert += ", ";
            }
            if (sortEventArgs.NewSortOrder == GridSortOrder.Ascending)
            {
                sortExpress += sortEventArgs.SortExpression + " ASC";
                sortExpressInvert += sortEventArgs.SortExpression + " DESC";
            }
            else if (sortEventArgs.NewSortOrder == GridSortOrder.Descending)
            {
                sortExpress += sortEventArgs.SortExpression + " DESC";
                sortExpressInvert += sortEventArgs.SortExpression + " ASC";
            }
        }

        if (!string.IsNullOrEmpty(sortExpress))
        {
            if (sortExpress.Contains("CompanyName"))
            {
                sortExpress = sortExpress.Replace("CompanyName", "SocNom");
                sortExpressInvert = sortExpressInvert.Replace("CompanyName", "SocNom");
            }
            if (sortExpress.Contains("City"))
            {
                sortExpress = sortExpress.Replace("City", "Commune");
                sortExpressInvert = sortExpressInvert.Replace("City", "Commune");
            }
            if (sortExpress.Contains("StatusLabel"))
            {
                sortExpress = sortExpress.Replace("StatusLabel", "StatusLabel");
                sortExpressInvert = sortExpressInvert.Replace("StatusLabel", "StatusLabel");
            }
            if (sortExpress.Contains("Responsible"))
            {
                sortExpress = sortExpress.Replace("Responsible", "Responsable");
                sortExpressInvert = sortExpressInvert.Replace("Responsible", "Responsable");
            }
            if (sortExpress.Contains("CreatedDate"))
            {
                sortExpress = sortExpress.Replace("CreatedDate", "DateCreation");
                sortExpressInvert = sortExpressInvert.Replace("CreatedDate", "DateCreation");
            }
        }
        else
        {
            sortExpress = "SocNom ASC";
            sortExpressInvert = "SocNom DESC";
        }

        CompanyRepository companyRepo = new CompanyRepository();
        List<Company> companyList = new List<Company>();
        /*if (!string.IsNullOrEmpty(Request.QueryString["type"])) //search by type
        {
            switch (Request.QueryString["type"])
            {
                case "all":
                    CompanyGrid.VirtualItemCount = companyRepo.CountAllCompanies();
                    companyList = companyRepo.GetAllCompanies(pageSize, pageNumber, sortExpress, sortExpressInvert);
                    break;
                case "client":
                    CompanyGrid.VirtualItemCount = companyRepo.CountCustomerCompanies();
                    companyList = companyRepo.GetCustomerCompanies(pageSize, pageNumber, sortExpress, sortExpressInvert);
                    break;
                case "prospect":
                    CompanyGrid.VirtualItemCount = companyRepo.CountPropectCompanies();
                    companyList = companyRepo.GetPropectCompanies(pageSize, pageNumber, sortExpress, sortExpressInvert);
                    break;
                case "inactive":
                    CompanyGrid.VirtualItemCount = companyRepo.CountInactiveCompanies();
                    companyList = companyRepo.GetInactiveCompanies(pageSize, pageNumber, sortExpress, sortExpressInvert);
                    break;
                default:
                    CompanyGrid.VirtualItemCount = companyRepo.CountAllCompanies();
                    companyList = companyRepo.GetAllCompanies(pageSize, pageNumber, sortExpress, sortExpressInvert);
                    break;
            }
        }
        else*/

        //if ((!string.IsNullOrEmpty(Request.QueryString["cname"]))) // search by name
        //{
            if (!string.IsNullOrEmpty(Request.QueryString["ctype"]))
            {
                switch(Request.QueryString["ctype"])
                {
                    case "all":
                        CompanyGrid.VirtualItemCount = companyRepo.CountSearchCompaniesByName(Request.QueryString["cname"]);
                        companyList = companyRepo.FindByName(Request.QueryString["cname"], pageSize, pageNumber, sortExpress, sortExpressInvert);
                        break;
                    case "client":
                        CompanyGrid.VirtualItemCount = companyRepo.CountSearchCompaniesByNameAndType(Request.QueryString["cname"], "1");
                        companyList = companyRepo.FindByNameAndType(Request.QueryString["cname"],"1", pageSize, pageNumber, sortExpress, sortExpressInvert);
                        break;
                    case "prospect":
                        CompanyGrid.VirtualItemCount = companyRepo.CountSearchCompaniesByNameAndType(Request.QueryString["cname"], "2");
                        companyList = companyRepo.FindByNameAndType(Request.QueryString["cname"], "2", pageSize, pageNumber, sortExpress, sortExpressInvert);
                        break;
                    case "inactive":
                        CompanyGrid.VirtualItemCount = companyRepo.CountSearchCompaniesByNameAndType(Request.QueryString["cname"], "0");
                        companyList = companyRepo.FindByNameAndType(Request.QueryString["cname"], "0", pageSize, pageNumber, sortExpress, sortExpressInvert);
                        break;
                }
            }
            else
            {
                //CompanyGrid.VirtualItemCount = companyRepo.CountSearchCompaniesByName(Request.QueryString["cname"]);
                //companyList = companyRepo.FindByName(Request.QueryString["cname"], pageSize, pageNumber, sortExpress, sortExpressInvert);
                companyList = companyRepo.GetTopCompany(pageSize);
            }
        //}
        //else //view a number of recent company
        //{
        //    companyList = companyRepo.GetTopCompany(pageSize);
        //}
        CompanyGrid.DataSource = companyList;
    }