using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
namespace DSWeb.WebSearchEngine
{
public partial class SearchEngineAdapter : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
WebClient webClient = new WebClient();
Byte[] pageHtmlBtyes;
string strUrl = "http://www.qingdaoport.net/ywzx/qqct/dpcx/hgfx.jsp?val=COSU6066673580";
//http://www.qingdaoport.net/ywzx/qqct/dpcx/ydbg.jsp?tdh=COSU6066673580
/*
sldata[10]:=twsou('
',' | ',sl[i]);
if not aQuery2.Locate('箱号',trim(sldata[5]),[]) then begin
aQuery2.Insert;
aQuery2.fieldbyname('编号').AsString:=bsno;
aQuery2.FieldByName('船名').AsString:=sldata[1];
aQuery2.FieldByName('航次').AsString:=sldata[2];
aQuery2.FieldByName('主单号').AsString:=sldata[3];
aQuery2.FieldByName('分单号').AsString:=sldata[4];
aQuery2.FieldByName('箱号').AsString:=sldata[5];
aQuery2.FieldByName('进港时间').AsString:=sldata[6];
aQuery2.FieldByName('发送时间').AsString:=sldata[7];
aQuery2.FieldByName('回执时间').AsString:=sldata[8];
aQuery2.FieldByName('回执状态').AsString:=sldata[9];
aQuery2.FieldByName('回执信息').AsString:=sldata[10];
aQuery2.FieldByName('类型').AsString:='QQCT';
*/
//http://www.qingdaoport.net/ywzx/qqct/dpcx/hgfx.jsp?val=COSU6066673580
/*
if not aQuery2.Locate('报关单号',trim(sldata[1]),[]) then begin
aQuery2.Insert;
aQuery2.fieldbyname('编号').AsString:=bsno;
aQuery2.FieldByName('报关单号').AsString:=sldata[1];
aQuery2.FieldByName('放行时间').AsString:=sldata[2];
aQuery2.FieldByName('放行件数').Asinteger:=strtointdef(sldata[3],0);
aQuery2.FieldByName('船名').AsString:=sldata[4];
aQuery2.FieldByName('航次').AsString:=sldata[5];
aQuery2.FieldByName('提单号').AsString:=sldata[6];
aQuery2.FieldByName('净重').Asfloat:=strtofloatdef(sldata[7],0);
aQuery2.FieldByName('毛重').Asfloat:=strtofloatdef(sldata[8],0);
aQuery2.FieldByName('海关状态').AsString:=sldata[9];
aQuery2.FieldByName('导入时间').AsString:=sldata[10];
aQuery2.FieldByName('类型').AsString:='QQCT';*/
//http://www.qingdaoport.net/ywzx/qqctu/customs_arrschema.jsp?tdh=APLU063457596
/* if not aQuery2.Locate('箱号',trim(sldata[5]),[]) then begin
aQuery2.Insert;
aQuery2.fieldbyname('编号').AsString:=bsno;
aQuery2.FieldByName('船名').AsString:=sldata[1];
aQuery2.FieldByName('航次').AsString:=sldata[2];
aQuery2.FieldByName('主单号').AsString:=sldata[3];
aQuery2.FieldByName('分单号').AsString:=sldata[4];
aQuery2.FieldByName('箱号').AsString:=sldata[5];
aQuery2.FieldByName('进港时间').AsString:=sldata[6];
aQuery2.FieldByName('发送时间').AsString:=sldata[7];
aQuery2.FieldByName('回执时间').AsString:=sldata[8];
aQuery2.FieldByName('回执状态').AsString:=sldata[9];
aQuery2.FieldByName('回执信息').AsString:=sldata[10];
aQuery2.FieldByName('类型').AsString:='QQCTU';*/
//http://www.qingdaoport.net/ywzx/qqctu/customs_release.jsp?val=APLU063457596
/* if not aQuery2.Locate('报关单号',trim(sldata[1]),[]) then begin
aQuery2.Insert;
aQuery2.fieldbyname('编号').AsString:=bsno;
aQuery2.FieldByName('报关单号').AsString:=sldata[1];
aQuery2.FieldByName('放行时间').AsString:=sldata[2];
aQuery2.FieldByName('放行件数').Asinteger:=strtointdef(sldata[3],0);
aQuery2.FieldByName('船名').AsString:=sldata[4];
aQuery2.FieldByName('航次').AsString:=sldata[5];
aQuery2.FieldByName('提单号').AsString:=sldata[6];
aQuery2.FieldByName('净重').Asfloat:=strtofloatdef(sldata[7],0);
aQuery2.FieldByName('毛重').Asfloat:=strtofloatdef(sldata[8],0);
aQuery2.FieldByName('海关状态').AsString:=sldata[9];
aQuery2.FieldByName('导入时间').AsString:=sldata[10];
aQuery2.FieldByName('类型').AsString:='QQCTU';*/
pageHtmlBtyes = webClient.DownloadData(strUrl);
//UTF8Encoding utf8Encoding = new UTF8Encoding();
Encoding gbEncoding = Encoding.GetEncoding("gb2312");
this.txt_val.Value = gbEncoding.GetString(pageHtmlBtyes);
//
ArrayList alist = new ArrayList();
string[] txtval = gbEncoding.GetString(pageHtmlBtyes).Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
string ls = "";
for (int i = 0; i < txtval.Length; i++)
{
ls = txtval[i].ToString().Trim().Replace("\t", "");
int sss = ls.IndexOf(">")+1;
int ttt = 0;
if (sss > 0)
{
if (ls.Substring(0, sss).Equals(""))
{
ls = ls.Substring(sss);
ttt=ls.IndexOf("<");
if (ttt > 0)
{
ls = ls.Substring(0, ttt);
}
else
{
ls = "";
}
alist.Add(ls);
}
else if (ls.Substring(0, sss).Equals(" | "))
{
ls = ls.Substring(sss);
ttt = ls.IndexOf("<");
if (ttt > 0)
{
ls = ls.Substring(0, ttt);
}
else
{
ls = "";
}
alist.Add(ls);
}
else if (ls.Substring(0, sss).Equals(" | "))
{
ls = ls.Substring(sss);
ttt = ls.IndexOf("<");
if (ttt > 0)
{
ls = ls.Substring(0, ttt);
}
else
{
ls = "";
}
alist.Add(ls);
}
else if (ls.Substring(0, sss).Equals(" | "))
{
ls = ls.Substring(sss);
ttt = ls.IndexOf("<");
if (ttt > 0)
{
ls = ls.Substring(0, ttt);
}
else
{
ls = "";
}
alist.Add(ls);
}
}
}
//-------
this.txt_val.Value = "";
for (int i = 0; i < alist.Count; i++)
{
this.txt_val.Value += alist[i].ToString().Trim() + "\r\n";
}
}
#region Unicode-GB Code转换
///
/// Unicode-GB Code转换
///
/// 将Unicode编码字符转换成GB编码字符
/// GB Code字符串
public string UnicodeToGB(string text)
{
UnicodeEncoding unicode = new UnicodeEncoding();
text = unicode.GetString(unicode.GetBytes(Regex.Unescape(text.Trim())));
return text;
}
///
/// Unicode-GB Code转换
///
/// 将Unicode编码字符转换成GB编码字符
/// GB Code字符串
public string UnicodeToGB_Old(string text)
{
MatchCollection mc = Regex.Matches(text, "([\\w]+)|(\\\\u([\\w]{4}))");
if (mc != null && mc.Count > 0)
{
StringBuilder sb = new StringBuilder();
foreach (Match m2 in mc)
{
string v = m2.Value;
if (v.IndexOf("\\") >= 0)
{
string word = v.Substring(2);
byte[] codes = new byte[2];
int code = Convert.ToInt32(word.Substring(0, 2), 16);
int code2 = Convert.ToInt32(word.Substring(2), 16);
codes[0] = (byte)code2;
codes[1] = (byte)code;
sb.Append(Encoding.Unicode.GetString(codes));
}
else
{
sb.Append(v);
}
}
return sb.ToString();
}
else
{
return text;
}
}
#endregion
}
}
|