bool iscjlist = false;
bool iscjinfo = false;
int cjnum = 0;
int jlcount = 0;
List<string> ltlist = new List<string>();
List<string> ltbh = new List<string>();
List<string> listsql = new List<string>();
Thread thrxx;
Common.MtoStr mnc = new MtoStr();
int PageNum = 0;
string spage = "";
string f_bh = "";
private void Form1_Load(object sender, EventArgs e)
{
//string BH = DbHelperSQL.GETCZBH();
object obj = DbHelperSQL.GetSingle("select top 1 jxh from bank_log order by id desc");
if (obj != null)
{
f_bh = obj.ToString();
}
webBrowser1.Navigate("https://mybank.icbc.com.cn/icbc/perbank/index.jsp");
// webBrowser1.CanGoBack = true;
}
private void button1_Click(object sender, EventArgs e)
{
// mshtml.HTMLDocument doc = (mshtml.HTMLDocument)webBrowser1.Document.DomDocument;
// //HtmlDocument
// //foreach(HtmlDocument aa in doc.documentElement.children.)
// //{
// //}
// object index = 0;
// mshtml.IHTMLWindow2 frame = (mshtml.IHTMLWindow2)doc.frames.item(ref index);
// doc = (mshtml.HTMLDocument)frame.document;
int al = webBrowser1.Document.GetElementById("indexFrame").Children.Count;
// MessageBox.Show(doc.ToString());
//HtmlElementCollection selects = webBrowser1.Document.Window.Frames["indexFrame"].Document.Window.Frames["downFrame"].Document.Window.Frames["mainFrame"].Document.GetElementsByTagName("SELECT");
//selects[2].SetAttribute("value", "1");
webBrowser1.Document.Window.Frames["indexFrame"].Document.Window.Frames["downFrame"].Document.Window.Frames["mainFrame"].Document.InvokeScript("changepage", new object[] { "20", "1" });
}
private void button2_Click(object sender, EventArgs e)
{
// MessageBox.Show(webBrowser1.Document.GetElementById("indexFrame").Document.Body.InnerText.ToString());
//webBrowser1.Document.Window.Frames["indexFrame"].Document
//webBrowser1.Document.Window.Frames["indexFrame"].Document.Window.Frames["downFrame"].Document.Body.InnerHtml
string aa = webBrowser1.Document.Window.Frames["indexFrame"].Document.Window.Frames["downFrame"].Document.Window.Frames["mainFrame"].Document.Body.InnerHtml;
Clipboard.SetDataObject(aa);
MessageBox.Show(aa);
}
private void button3_Click(object sender, EventArgs e)
{
jlcount = 0;
iscjlist = false;
spage = "";
HtmlDocument main = webBrowser1.Document.Window.Frames["indexFrame"].Document.Window.Frames["downFrame"].Document.Window.Frames["mainFrame"].Document;
HtmlElementCollection selects = main.GetElementsByTagName("SELECT");
selects[3].SetAttribute("value", "1");//Trantypechange
main.InvokeScript("Trantypechange");
selects[4].SetAttribute("value", "1");//Tranflagchange
main.InvokeScript("Tranflagchange");
main.InvokeScript("formsubmit");
timer5.Start();
}
private void button4_Click(object sender, EventArgs e)
{
webBrowser1.Document.Window.Frames["indexFrame"].Document.Window.Frames["downFrame"].Document.Window.Frames["mainFrame"].Document.InvokeScript("changepage", new object[] { "10", "1" });
}
private void timer1_Tick(object sender, EventArgs e)
{
if (!iscjlist)
{
try
{
HtmlDocument main = webBrowser1.Document.Window.Frames["indexFrame"].Document.Window.Frames["downFrame"].Document.Window.Frames["mainFrame"].Document;
string mainhtml = main.Body.InnerHtml;
if (mainhtml.IndexOf("on_sub") >= 0)
{
HtmlElementCollection aas = main.GetElementsByTagName("A");
HtmlElementCollection tables = main.GetElementsByTagName("TABLE");
HtmlElementCollection trs = tables[15].GetElementsByTagName("TR");
for (int i = 0; i < aas.Count; i++)
{
string anr = aas[i].GetAttribute("href");
if (anr.IndexOf("on_sub") >= 0)
{
if (anr.IndexOf(this.f_bh) > 0)
{
if (jlcount == 0)
{
timer1.Stop();
webBrowser1.GoBack();
timer4.Start();
}
break;
}
else
{
string bh = anr.Replace("javascript:on_sub('thisform','currserialNo','", "").Replace("')", "");
if (textBox3.Text.ToString().IndexOf(bh) <= 0)
{
HtmlElementCollection tds = trs[jlcount + 2].GetElementsByTagName("TD");
jlcount = jlcount + 1;
this.f_bh = bh;
iscjinfo = false;
string sj = tds[0].InnerHtml.Replace("年", "-").Replace("月", "-").Replace("日", "");//时间
string xm = tds[1].InnerHtml;//姓名
string je = tds[2].InnerHtml;//金额
string sxf = tds[4].InnerHtml;//手续费
ltlist.Add(xm + "用户ID," + "金额," + je + "时间," + sj + "手续费," + sxf + "交易号," + bh);
ltbh.Add(bh);
}
}
}
}
iscjlist = true;
}
}
catch { }
textBox2.Text = jlcount.ToString();
cjnum = jlcount;
}
else if(jlcount>0)
{
if (cjnum > 0)
{
cjnum = cjnum - 1;
string bh = ltbh[cjnum ];
HtmlDocument main = webBrowser1.Document.Window.Frames["indexFrame"].Document.Window.Frames["downFrame"].Document.Window.Frames["mainFrame"].Document;
main.InvokeScript("on_sub", new object[] { "thisform", "currserialNo", bh });
timer1.Stop();
timer2.Start();
if (cjnum == 0)
{
timer1.Stop();
}
}
else
{
timer1.Stop();
webBrowser1.GoBack();
ltlist.Clear();
timer4.Start();
}
}
}
private void timer2_Tick(object sender, EventArgs e)
{
try
{
HtmlDocument main = webBrowser1.Document.Window.Frames["indexFrame"].Document.Window.Frames["downFrame"].Document.Window.Frames["mainFrame"].Document;
string xx = main.Body.InnerHtml;
int n = xx.IndexOf("附言");
if (n >= 0)
{
HtmlElementCollection tables = main.GetElementsByTagName("TABLE");
HtmlElementCollection trs = tables[15].GetElementsByTagName("TR");
HtmlElementCollection tds1 = trs[0].GetElementsByTagName("TD");
HtmlElementCollection tds2 = trs[1].GetElementsByTagName("TD");
HtmlElementCollection tds3 = trs[6].GetElementsByTagName("TD");
string skr = tds1[3].InnerHtml;
string fkr = tds1[1].InnerHtml;
string skzh = tds2[3].InnerHtml;
string fkzh = tds2[1].InnerHtml;
string id=tds3[3].InnerHtml;
string yhid = "用户ID," +id ;
string[] xxarray = ltlist[cjnum].Split(',');
string je = xxarray[2].Replace("人民币时间","");
listsql.Clear();
SqlDataReader dr = DbHelperSQL.ExecuteReader("select id,back_money2,ft003 from bank_back where state=0 and (ft005-ft003)/12="+id.Substring(0,4)+"");
if (dr.Read())
{
if(mnc.Dec(dr[1].ToString(),dr[2].ToString())==je)
{
listsql.Add("update bank_back set state=1 where id="+dr[0].ToString()+"");
}
}
dr.Dispose();
dr.Close();
string sxf = xxarray[4].Replace("交易号", "").Replace("元", "");
string jysj=xxarray[3].Replace("手续费","");
listsql.Add("insert into bank_log (userid,yhname,je,sxf,fksj,cjsj,jxh,skr,fkr,skzh,fkzh) values(" + id + ",'" + xxarray[0].Replace("用户ID", "") + "'," + je + "," + sxf + ",'" + jysj + "','" + DateTime.Now.ToString() + "','" + xxarray[5] + "','"+skr+"','"+fkr+"','"+skzh+"','"+fkzh+"')");
int i = DbHelperSQL.ExecuteSqlTran(listsql);
textBox3.Text = textBox3.Text +"---"+ltlist[cjnum].Replace("用户ID,",yhid)+"/r/n" ;
this.f_bh = xxarray[5];
timer2.Stop();
timer3.Start();
webBrowser1.GoBack();
}
}
catch(Exception ex)
{
}
}
private void timer3_Tick(object sender, EventArgs e)
{
try
{
HtmlDocument main = webBrowser1.Document.Window.Frames["indexFrame"].Document.Window.Frames["downFrame"].Document.Window.Frames["mainFrame"].Document;
string xx = main.Body.InnerHtml;
int n = xx.IndexOf("手续费");
if (n >= 0)
{
iscjinfo = true;
timer3.Stop();
timer1.Start();
}
}
catch(Exception ex)
{
}
}
private void button6_Click(object sender, EventArgs e)
{
HtmlDocument main = webBrowser1.Document.Window.Frames["indexFrame"].Document.Window.Frames["downFrame"].Document.Window.Frames["mainFrame"].Document;
Clipboard.SetDataObject(main.Body.InnerHtml);
}
private void timer4_Tick(object sender, EventArgs e)
{
try
{
HtmlDocument main = webBrowser1.Document.Window.Frames["indexFrame"].Document.Window.Frames["downFrame"].Document.Window.Frames["mainFrame"].Document;
string xx = main.Body.InnerHtml;
int n = xx.IndexOf("Trantypechange");
if (n >= 0)
{
jlcount = 0;
iscjlist = false;
HtmlElementCollection selects = main.GetElementsByTagName("SELECT");
selects[3].SetAttribute("value", "1");//Trantypechange
main.InvokeScript("Trantypechange");
selects[4].SetAttribute("value", "1");//Tranflagchange
main.InvokeScript("Tranflagchange");
main.InvokeScript("formsubmit");
timer1.Start();
timer4.Stop();
}
else if(xx.IndexOf("上一页")>=0||xx.IndexOf("下一页")>=0)
{
jlcount = 0;
iscjlist = false;
timer1.Start();
timer4.Stop();
}
}
catch (Exception ex)
{
}
}
private void timer5_Tick(object sender, EventArgs e)
{
try
{
HtmlDocument main = webBrowser1.Document.Window.Frames["indexFrame"].Document.Window.Frames["downFrame"].Document.Window.Frames["mainFrame"].Document;
string mainhtml = main.Body.InnerHtml;
int bz3 = mainhtml.IndexOf(spage);
if (mainhtml.IndexOf("下一页") >= 0 && (mainhtml.IndexOf(f_bh) <= 0) && (bz3 > 0 || spage == ""))
{
PageNum = PageNum + 1;
spage = "changepage('" + Convert.ToString((PageNum - 1) * 10) + "','0')";
string pages = Convert.ToString(PageNum * 10);
main.InvokeScript("changepage", new object[] { pages, "1" });
}
else if (mainhtml.IndexOf(f_bh) > 0 || (bz3 > 0 && mainhtml.IndexOf("下一页")<0))
{
timer1.Start();
timer5.Stop();
}
}
catch(Exception ex)
{}
}
}
}