gridview中的一列具有相同的结果

时间:2018-01-04 20:12:40

标签: c# datagridview exchangewebservices

我正在工作以在gridview上显示结果,并且该列上的结果之一具有相同的值,但在控制台上它显示了所有结果,这里是我的代码

    private bool DisplayErrorEmails(ExchangeService service)
    {
        try
        {


            FindItemsResults<Item> findResults;
            DateTime TwoDays = DateTime.Today.AddDays(-2);

            //Search for the Undelivered Email
            SearchFilter.SearchFilterCollection compoundFilter = new SearchFilter.SearchFilterCollection(LogicalOperator.Or);
compoundFilter.Add(new SearchFilter.ContainsSubstring(ItemSchema.ItemClass, "REPORT.IPM.Note.NDR"));
            compoundFilter.Add(new SearchFilter.ContainsSubstring(ItemSchema.ItemClass, "REPORT.IPM.Note.DR"));
            compoundFilter.Add(new SearchFilter.ContainsSubstring(ItemSchema.ItemClass, "REPORT.IPM.Note.DELAYED"));
            compoundFilter.Add(new SearchFilter.ContainsSubstring(ItemSchema.ItemClass, "REPORT.IPM.Note.IPNRN"));
            compoundFilter.Add(new SearchFilter.ContainsSubstring(ItemSchema.ItemClass, "REPORT.IPM.Note.IPNNRN"));
            compoundFilter.Add(new SearchFilter.ContainsSubstring(ItemSchema.ItemClass, "REPORT.IPM.SMIME.NDR"));
            compoundFilter.Add(new SearchFilter.ContainsSubstring(ItemSchema.ItemClass, "REPORT.IPM.SMIME.DR"));
            compoundFilter.Add(new SearchFilter.ContainsSubstring(ItemSchema.ItemClass, "REPORT.IPM.NoteSMIME.MULTIPARTSIGNED.NDR"));
            compoundFilter.Add(new SearchFilter.ContainsSubstring(ItemSchema.ItemClass, "REPORT.IPM.Note.SMIME.MULTIPARTSIGNED.DR"));



            //Displays the result
            ItemView view = new ItemView(100);

            do
            {
                findResults = service.FindItems(WellKnownFolderName.Inbox, compoundFilter, view);
                foreach (Item item in findResults.Items)
                {

                    if (findResults.ToString() != "")
                    {
                        EmailList.Add(item);
                        item.Load();

                        string Sender = item.DisplayTo;
                        string Subject = item.Subject;
                        string DateCreated = item.DateTimeCreated.ToString();

                        //Display the EmailBody
                        PropertySet itemProperty = new PropertySet();
                        itemProperty.RequestedBodyType = BodyType.Text;
                        itemProperty.Add(ItemSchema.Body);
                        PropertySet FindItemPropertySet = new PropertySet(BasePropertySet.IdOnly);
                        view.PropertySet = FindItemPropertySet;
                        PropertySet GetItemsPropertySet = new PropertySet(BasePropertySet.FirstClassProperties);
                        GetItemsPropertySet.RequestedBodyType = BodyType.Text;
                        if (findResults.Items.Count > 0)
                        {
                            service.LoadPropertiesForItems(findResults.Items, GetItemsPropertySet);
                            foreach (Item Item in findResults.Items)
                            {
                                var EmailBody = Item.Body.Text;
                                var pattern = new[] { "Remote Server returned '554 5.4.4 SMTPSEND.DNS.NonExistentDomain; nonexistent domain",
                    "Either there are no alternate hosts, or delivery failed to all alternate hosts",
                    "Remote Server returned '550 No Such User Here",
                    "5.2.3 smtp;550 5.2.3 RESOLVER.RST.SendSizeLimit.Org; message too large for this organization",
                    "5.1.10 smtp;550 5.1.10 RESOLVER.ADR.RecipientNotFound; Recipient user@contoso.com not found by SMTP address lookup",
                    "Remote Server returned '550 4.4.7 QUEUE.Expired; message expired'",
                    "Remote host said: 550-5.1.1 The email account that you tried to reach does not exist",};


                                string matchingMessage = String.Empty;
                                var found = pattern.Any(m => { var match = EmailBody.Contains(m);
                                    if (match) matchingMessage = m;
                                    return match;

                                });
                                matchingMessagePublic = matchingMessage;
                                Console.WriteLine("Subject" + item.Subject);
                              Console.WriteLine("Error::::" + matchingMessage);

                            }

                        }
                    }
                }
                if (findResults.NextPageOffset != null)
                {
                    view.Offset = (int)findResults.NextPageOffset;
                }

            }
            while (findResults.MoreAvailable);

            Status = "list of undelivered email.";
            return true;
        }
        catch (Exception ex)
        {
            Status = "Error: " + ex.Message;
            return false;
        }
    }

这是我在gridview上显示结果的代码

public void LoadResult()
    {

        EmailMethods email = new EmailMethods();

        email.EmailServer = "https://SampleExchange.asmx";
        email.AccountName = ConfigurationManager.AppSettings["Account"];
        email.Password = ConfigurationManager.AppSettings["Secret"];
        email.Domain = ConfigurationManager.AppSettings["Domain"];
        email.GetEmails();
        DataTable dt = new DataTable();

        dt.Columns.Add("Subject", typeof(string));
        dt.Columns.Add("Sender", typeof(string));
        dt.Columns.Add("DateCreated", typeof(string));
        dt.Columns.Add("EmailHeader", typeof(string));
        dt.Columns.Add("ErrorTwo", typeof(string));

        foreach (Item item in email.EmailList)
        {
            dt.Rows.Add(item.Subject, item.DisplayTo, item.DateTimeCreated, item.Body, email.matchingMessagePublic);

            GridView1.DataSource = dt;
            GridView1.DataBind();

        }

    }
在作为列的email.matchMakingPublic上的

具有相同的结果。我可以在项目上添加配对吗?或者在microsoft.exchange.webservices.data.item上,以便它在gridview上显示正确的结果,因为我尝试在email.matchmakingpublic上调试循环,就像旋转相同的结果一样。任何人都可以帮我解决我的代码谢谢。

0 个答案:

没有答案