如何返回并从一种方法重新检查到另一种方法 [英] how to go back and recheck from one method to another method

查看:93
本文介绍了如何返回并从一种方法重新检查到另一种方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





从下面的代码中,我从电子表格中获取帐号,并使用c#代码将其放在另一个网站上,有时它将抛出错误消息(找不到匹配项)并将错误消息存储到数据表中。我的问题是,每当错误消息(找不到匹配)来自网站时,如何返回到btnExecute_Click方法,我又需要再次检查同一个帐户?你能帮助我吗?



  private   void  btnExecute_Click( object  sender,EventArgs e)
{
if (webBrowser1.Document == null
{
.LoadPageInBrowser();
}
datattablecolbinding();

ClaimSearch();
importexcel();
Readexceldata();

if (theDS.Tables.Count > 0
{
label6.Text = 总计记录: + theDS.Tables [ 0 ]。Rows.Count;
foreach (DataRow drval in theDS.Tables [ 0 ]。行)
{
while (webBrowser1.ReadyState!= WebBrowserReadyState.Complete)
{
Application.DoEvents();
}

accountnumber = drval [ account#]的ToString();
if (accountnumber.Length > 9
{
accountnumber = accountnumber.Substring( 0 9 );
}
}
}
ClaimInfo();
}

private void ClaimInfo()
{
string vsb = webBrowser1.Document.Body.InnerHtml;
HtmlAgilityPack.HtmlDocument htmlDoc = new HtmlAgilityPack.HtmlDocument();
htmlDoc.OptionFixNestedTags = true ;
htmlDoc.LoadHtml(vsb);

if (htmlDoc.DocumentNode!= null
{
HtmlAgilityPack.HtmlNodeCollection ClmError = htmlDoc.DocumentNode.SelectNodes( .// table [@ class ='cancelText ] // TR);

if (ClmError!= null
{
for int introws = 0 ; introws < ClmError.Count; introws ++)
{
HtmlAgilityPack.HtmlNodeCollection link = ClmError [introws] .SelectNodes( .// td);
for int j = 0 ; j < link.Count; j ++)
{
value = link [j] .InnerText;
}
}
}
}
}

解决方案

最佳解决方案是更改ClaimInfo以返回bool:true表示all ok,false表示No Matches Found。

Click处理程序然后可以使用该结果并再次检查是否需要。

Hi,

From the below code, I'm getting the account no from the spread sheet and put it on a another website using c# code, sometimes it will throw a error message ("No Matches found") and I stored the error message in to the data table. My question is, whenever the error msg ("No Matches found") is coming from the website, how to go back to the btnExecute_Click method, again I need to recheck the same account one more time?. Can you please anyone help me on that?

private void btnExecute_Click(object sender, EventArgs e)
 {
     if (webBrowser1.Document == null)
     {
         this.LoadPageInBrowser();
     }
     datattablecolbinding();

     ClaimSearch();
     importexcel();
     Readexceldata();

     if (theDS.Tables.Count > 0)
     {
         label6.Text = "Total Records :" + theDS.Tables[0].Rows.Count;
         foreach (DataRow drval in theDS.Tables[0].Rows)
         {
             while (webBrowser1.ReadyState != WebBrowserReadyState.Complete)
             {
                 Application.DoEvents();
             }

             accountnumber = drval["account #"].ToString();
             if (accountnumber.Length > 9)
             {
                 accountnumber = accountnumber.Substring(0, 9);
             }
         }
     }
     ClaimInfo();
}

private void ClaimInfo()
{
    string vsb = webBrowser1.Document.Body.InnerHtml;
    HtmlAgilityPack.HtmlDocument htmlDoc = new HtmlAgilityPack.HtmlDocument();
    htmlDoc.OptionFixNestedTags = true;
    htmlDoc.LoadHtml(vsb);
            
    if (htmlDoc.DocumentNode != null)
    {
      HtmlAgilityPack.HtmlNodeCollection ClmError = htmlDoc.DocumentNode.SelectNodes(".//table[@class='cancelText']//tr");
    
        if (ClmError != null)
        {
    for (int introws = 0; introws < ClmError.Count; introws++)
         {
      HtmlAgilityPack.HtmlNodeCollection link = ClmError[introws].SelectNodes(".//td");
          for (int j = 0; j < link.Count; j++)
          {
           value = link[j].InnerText;
          }
         }
        }
    }
}

解决方案

Best solution is to change ClaimInfo to return a bool: true for "all ok" and false for "No Matches Found".
The Click handler can then use that result and check again if it wants to.


这篇关于如何返回并从一种方法重新检查到另一种方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆