コード例 #1
0
    protected DataSet ContactGrid_OnDataReload(string completeWhere, string currentOrder, int currentTopN, string columns, int currentOffset, int currentPageSize, ref int totalRecords)
    {
        try
        {
            ICredentialProvider credentialProvider = new UserCredentialProvider(MembershipContext.AuthenticatedUser);

            DataComClient        client   = DataComHelper.CreateClient();
            IContactProvider     provider = DataComHelper.CreateContactProvider(client, credentialProvider.GetCredential());
            ContactSearchResults response = provider.SearchContacts(CurrentContactFilter, currentOffset / currentPageSize, currentPageSize);
            DataTable            table    = new DataTable("Contacts");
            table.Columns.Add("ContactId", typeof(long));
            table.Columns.Add("FirstName", typeof(string));
            table.Columns.Add("LastName", typeof(string));
            table.Columns.Add("CompanyName", typeof(string));
            foreach (Contact contact in response.Contacts)
            {
                DataRow row = table.NewRow();
                row["ContactId"]   = contact.ContactId;
                row["FirstName"]   = contact.FirstName;
                row["LastName"]    = contact.LastName;
                row["CompanyName"] = contact.CompanyName;
                table.Rows.Add(row);
                if (contact.ContactId == CurrentContactId)
                {
                    CurrentContact = contact;
                }
            }
            DataSet dataSet = new DataSet();
            dataSet.Tables.Add(table);
            int maxHitCount = currentPageSize * MAX_PAGE_COUNT;
            int hitCount    = (int)response.TotalHits;
            if (hitCount > maxHitCount)
            {
                hitCount = maxHitCount;
                ShowWarning(GetString("datacom.toomanycontacts"), null, null);
            }
            totalRecords = hitCount;
            return(dataSet);
        }
        catch (Exception exception)
        {
            HandleException(exception);
        }
        totalRecords = 0;

        return(null);
    }