基本信息
源码名称:C# 全国车辆违章查询 实例源码下载
源码大小:5.90M
文件格式:.rar
开发语言:C#
更新时间:2017-01-19
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 4 元×
微信扫码支付:4 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using 全国违章车辆查询.ToosClass;
using 全国违章车辆查询.EntiyClass;
using System.Threading;
using System.Net;
using System.IO;
namespace 全国违章车辆查询
{
public partial class Form1 : Form
{
public Form1()
{
CheckForIllegalCrossThreadCalls = false;
InitializeComponent();
}
DateTime startTime;
long timeStamp;
HttpHelper httphelper = null;
HttpItem item1 = null;
HttpItem item2 = null;
HttpItem item3 = null;
bool isFist = true;
private void Form1_Load(object sender, EventArgs e)
{
#region 绑定省市
List<ProvinceInfo> prinfo = new List<ProvinceInfo>()
{
new ProvinceInfo {cityName="北京市",cityValue="bj" },new ProvinceInfo {cityName="天津市",cityValue="tj" },
new ProvinceInfo {cityName="重庆市",cityValue="cq" },new ProvinceInfo {cityName="上海市",cityValue="sh" },
new ProvinceInfo {cityName="河北省",cityValue="he" },new ProvinceInfo {cityName="海南省",cityValue="hi" },
new ProvinceInfo {cityName="山西省",cityValue="sx" },new ProvinceInfo {cityName="四川省",cityValue="sc" },
new ProvinceInfo {cityName="辽宁省",cityValue="ln" },new ProvinceInfo {cityName="贵州省",cityValue="gz" },
new ProvinceInfo {cityName="吉林省",cityValue="jl" },new ProvinceInfo {cityName="云南省",cityValue="yn" },
new ProvinceInfo {cityName="黑龙江省",cityValue="hl"},new ProvinceInfo {cityName="陕西省",cityValue="sn" },
new ProvinceInfo {cityName="江苏省",cityValue="" },new ProvinceInfo {cityName="甘肃省",cityValue="gs" },
new ProvinceInfo {cityName="浙江省",cityValue="" },new ProvinceInfo {cityName="青海省",cityValue="qh" },
new ProvinceInfo {cityName="安徽省",cityValue="ah" },new ProvinceInfo {cityName="台湾省",cityValue="" },
new ProvinceInfo {cityName="福建省",cityValue="fj" },new ProvinceInfo {cityName="内蒙古自治区",cityValue="nm" },
new ProvinceInfo {cityName="江西省",cityValue="jx" },new ProvinceInfo {cityName="广西壮族自治区",cityValue="gx" },
new ProvinceInfo {cityName="山东省",cityValue="sd" },new ProvinceInfo {cityName="宁夏回族自治区",cityValue="nx" },
new ProvinceInfo {cityName="河南省",cityValue="ha"},new ProvinceInfo {cityName="新疆维吾尔自治区",cityValue="xj" },
new ProvinceInfo {cityName="湖北省",cityValue="hb" },new ProvinceInfo {cityName="西藏自治区",cityValue="xz" },
new ProvinceInfo {cityName="湖南省",cityValue="hn" },new ProvinceInfo {cityName="香港特别行政区",cityValue="" },
new ProvinceInfo {cityName="广东省",cityValue="gd" },new ProvinceInfo {cityName="澳门特别行政区",cityValue="" },
};
cboProvice.DataSource = prinfo;
cboProvice.DisplayMember = "cityname";
cboProvice.ValueMember = "cityValue";
#endregion
#region 绑定车辆类型
List<PlateType> plate = new List<PlateType>()
{
new PlateType {PlateName="大型汽车",PlateValue="01"},new PlateType {PlateName="小型汽车",PlateValue="02" },
new PlateType {PlateName="使馆汽车",PlateValue="03"},new PlateType {PlateName="领馆汽车",PlateValue="04" },
new PlateType {PlateName="境外汽车",PlateValue="05"},new PlateType {PlateName="外籍汽车",PlateValue="06" },
new PlateType {PlateName="普通摩托车",PlateValue="07"},new PlateType {PlateName="轻便摩托车",PlateValue="08" },
new PlateType {PlateName="使馆摩托车",PlateValue="09"},new PlateType {PlateName="领馆摩托车",PlateValue="10" },
new PlateType {PlateName="境外摩托车",PlateValue="11"},new PlateType {PlateName="外籍摩托车",PlateValue="12" },
new PlateType {PlateName="低速车",PlateValue="13"},new PlateType {PlateName="拖拉机",PlateValue="14" },
new PlateType {PlateName="挂车",PlateValue="15"},new PlateType {PlateName="教练汽车",PlateValue="16" },
new PlateType {PlateName="教练摩托车",PlateValue="17"},new PlateType {PlateName="实验汽车",PlateValue="18" },
new PlateType {PlateName="实验摩托车",PlateValue="19"},new PlateType {PlateName="临时入境汽车",PlateValue="20" },
new PlateType {PlateName="临时入境摩托车",PlateValue="21"},new PlateType {PlateName="临时行驶车",PlateValue="22" },
new PlateType {PlateName="警用汽车",PlateValue="23"},new PlateType {PlateName="警用摩托",PlateValue="24" },
new PlateType {PlateName="原农机号码",PlateValue="25"},new PlateType {PlateName="香港入境车",PlateValue="26" },
new PlateType {PlateName="澳门入境车",PlateValue="27"}
};
cboType.DataSource = plate;
cboType.DisplayMember = "PlateName";
cboType.ValueMember = "PlateValue";
richTextBox1.AppendText("绑定数据完成..." "\r\n");
#endregion
richTextBox1.AppendText("窗口加载完成..." "\r\n");
richTextBox1.AppendText("等待用户输入数据..." "\r\n");
}
private void txtCaptcha_Enter(object sender, EventArgs e)
{
if (!txtCarnum.Text.Equals("")&&!txtFadongji.Text.Equals(""))
{
if (isFist)
{
richTextBox1.AppendText("正在抓取网页验证码....." "\r\n");
GetVerificationCode();
isFist = false;
}
}
else
{
MessageBox.Show("请查看数据是否填写完整!");
}
}
/// <summary>
/// 获取网页验证码
/// </summary>
private void GetVerificationCode()
{
startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1)); // 当地时区
timeStamp = (long)(DateTime.Now - startTime).TotalMilliseconds; // 相差毫秒数
if (cboProvice.Text.Equals("浙江省") || cboProvice.Text.Equals("江苏省"))
{
#region 根据浙江,江苏的城市获取验证码
try
{
httphelper = new HttpHelper();
item1 = new HttpItem()
{
URL = "http://" cboCity.SelectedValue ".122.gov.cn/views/inquiry.html",
Method = "get",
};
HttpResult res = httphelper.GetHtml(item1);
string cookie = res.Cookie;
item2 = new HttpItem()
{
URL = "http://" cboCity.SelectedValue ".122.gov.cn/captcha?nocache=" timeStamp,
Cookie = cookie,
Method = "get",
ResultType = ResultType.Byte
};
}
catch (Exception)
{
MessageBox.Show("打开网页失败,请查看网络连接");
}
HttpResult res1 = httphelper.GetHtml(item1);
HttpResult res2 = httphelper.GetHtml(item2);
MemoryStream ms = new MemoryStream(res2.ResultByte);//获取验证码图片
Image image = Image.FromStream(ms);
this.pictureBox1.Image = image;
ms.Close();
richTextBox1.AppendText("抓取验证码成功....." "\r\n");
#endregion
}
else
{
#region 根据省份获取验证码
try
{
httphelper = new HttpHelper();
item1 = new HttpItem()
{
URL = "http://" cboProvice.SelectedValue ".122.gov.cn/views/inquiry.html",
Method = "get",
};
HttpResult res = httphelper.GetHtml(item1);
string cookie = res.Cookie;
item2 = new HttpItem()
{
URL = "http://" cboProvice.SelectedValue ".122.gov.cn/captcha?nocache=" timeStamp,
Cookie = cookie,
Method = "get",
ResultType = ResultType.Byte
};
}
catch (Exception)
{
MessageBox.Show("打开网页失败,请查看网络连接");
}
HttpResult res1 = httphelper.GetHtml(item1);
HttpResult res2 = httphelper.GetHtml(item2);
MemoryStream ms = new MemoryStream(res2.ResultByte);//获取验证码图片
Image image = Image.FromStream(ms);
this.pictureBox1.Image = image;
ms.Close();
richTextBox1.AppendText("抓取验证码成功....." "\r\n");
#endregion
}
}
/// <summary>
/// 查询
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnSeach_Click(object sender, EventArgs e)
{
richTextBox1.AppendText("正在准备提交参数..." "\r\n");
string carIdnum = txtCarnum.Text.Trim();//车牌号码
string hpzl = cboType.SelectedValue.ToString();//号牌类型
string carid = cboCarnum.Text carIdnum;//详细车牌号
string caridStr = TransferEncoding(Encoding.UTF8, Encoding.Default, carid);
string fdjh = txtFadongji.Text.Trim();//发动机号
string captcar = txtCaptcha.Text.Trim();//验证码
richTextBox1.AppendText("正在查询..." "\r\n");
if (CheckIsNull())
{
try
{
#region 浙江和江苏按照城市查询的
if (cboProvice.Text.Equals("浙江省") || cboProvice.Text.Equals("江苏省"))
{
httphelper = new HttpHelper();
item3 = new HttpItem()
{
URL = "http://" cboCity.SelectedValue ".122.gov.cn/m/publicquery/vio",
Method = "post",
UserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0",
Accept = "application/json, text/javascript, */*; q=0.01",
Host = "ha.122.gov.cn",
Cookie = item2.Cookie,
Referer = "http://" cboCity.SelectedValue ".122.gov.cn/views/inquiry.html",
ContentType = "application/x-www-form-urlencoded; charset=UTF-8",
Postdata = "hpzl=" hpzl "&hphm1b=" carIdnum "&hphm=" caridStr "&fdjh=" fdjh "&captcha=" captcar "&qm=wf&page=1"
};
HttpResult res3 = httphelper.GetHtml(item3);
string resultStr1 = res3.Html;
var submitinfo1 = JsonHelper.JsonDeserialize<SubmitInfo>(resultStr1);
rtbInfo.BodyInnerHTML = submitinfo1.message "<br/><br/>";
richTextBox1.AppendText("查询完成..." "\r\n");
}
#endregion
#region 按照省份查的
else
{
item3 = new HttpItem()
{
URL = "http://" cboProvice.SelectedValue ".122.gov.cn/m/publicquery/vio",
Method = "post",
UserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0",
Accept = "application/json, text/javascript, */*; q=0.01",
Host = "ha.122.gov.cn",
Cookie = item2.Cookie,
Referer = "http://" cboProvice.SelectedValue ".122.gov.cn/views/inquiry.html",
ContentType = "application/x-www-form-urlencoded; charset=UTF-8",
Postdata = "hpzl=" hpzl "&hphm1b=" carIdnum "&hphm=" caridStr "&fdjh=" fdjh "&captcha=" captcar "&qm=wf&page=1"
};
HttpResult res3 = httphelper.GetHtml(item3);
string resultStr = res3.Html;
var submitinfo = JsonHelper.JsonDeserialize<SubmitInfo>(resultStr);
rtbInfo.BodyInnerHTML = submitinfo.message;
richTextBox1.AppendText("查询完成..." "\r\n");
}
#endregion
}
catch (Exception)
{
MessageBox.Show("网络连接错误,请查看网络连接!");
}
}
}
private void cboProvice_SelectedIndexChanged(object sender, EventArgs e)
{
if (cboProvice.Text.Equals("台湾省") || cboProvice.Text.Equals("香港特别行政区") || cboProvice.Text.Equals("澳门特别行政区"))
{
MessageBox.Show("该省份还没有开通该服务!");
}
#region 绑定省对应的城市
else if (cboProvice.Text == "江苏省")
{
List<CityInfo> cityinfo = new List<CityInfo>() {
new CityInfo {CityName="徐州市",CityValue="xuz" },new CityInfo {CityName="连云港市",CityValue="lyg"},
new CityInfo {CityName="宿迁市",CityValue="suq" },new CityInfo {CityName="淮安市",CityValue="has" },
new CityInfo {CityName="盐城市",CityValue="ynz"},new CityInfo {CityName="扬州市",CityValue="yzo"},
new CityInfo {CityName="泰州市",CityValue="tzs" },new CityInfo {CityName="南京市",CityValue="nkg" },
new CityInfo {CityName="镇江市",CityValue="zhe" },new CityInfo {CityName="南通市",CityValue="ntg" },
new CityInfo {CityName="常州市",CityValue="czx" },new CityInfo {CityName="无锡市",CityValue="wux"},
new CityInfo {CityName="苏州市",CityValue="szv" },
};
cboCity.DataSource = cityinfo;
cboCity.DisplayMember = "CityName";
cboCity.ValueMember = "CityValue";
}
else if (cboProvice.Text == "浙江省")
{
List<CityInfo> cityinfo = new List<CityInfo>() {
new CityInfo {CityName="湖州市",CityValue="hzh" },new CityInfo {CityValue="jix",CityName="嘉兴市"},
new CityInfo {CityName="舟山市",CityValue="zos" },new CityInfo {CityName="绍兴市",CityValue="sxg" },
new CityInfo {CityName="宁波市",CityValue="ngb"},new CityInfo {CityName="衢州市",CityValue="quz"},
new CityInfo {CityName="金华市",CityValue="jha" },new CityInfo {CityName="台州市",CityValue="tzz" },
new CityInfo {CityName="丽水市",CityValue="lss" },new CityInfo {CityName="温州市",CityValue="wnz" },
new CityInfo {CityName="杭州市",CityValue="hgh" },
};
cboCity.DataSource = cityinfo;
cboCity.DisplayMember = "CityName";
cboCity.ValueMember = "CityValue";
}
#endregion
#region 根据省份绑定简称
switch (cboProvice.Text)
{
case "北京市":
cboCarnum.Text = "京";
break;
case "上海市":
cboCarnum.Text = "沪";
break;
case "广东省":
cboCarnum.Text = "粤";
break;
case "山东省":
cboCarnum.Text = "鲁";
break;
case "山西省":
cboCarnum.Text = "晋";
break;
case "河北省":
cboCarnum.Text = "冀";
break;
case "河南省":
cboCarnum.Text = "豫";
break;
case "四川省":
cboCarnum.Text = "川";
break;
case "重庆市":
cboCarnum.Text = "渝";
break;
case "辽宁省":
cboCarnum.Text = "辽";
break;
case "吉林省":
cboCarnum.Text = "吉";
break;
case "黑龙江省":
cboCarnum.Text = "黑";
break;
case "湖北省":
cboCarnum.Text = "鄂";
break;
case "湖南省":
cboCarnum.Text = "湘";
break;
case "江西省":
cboCarnum.Text = "赣";
break;
case "福建省":
cboCarnum.Text = "闽";
break;
case "陕西省":
cboCarnum.Text = "陕";
break;
case "甘肃省":
cboCarnum.Text = "甘";
break;
case "宁夏回族自治区":
cboCarnum.Text = "宁";
break;
case "内蒙古自治区":
cboCarnum.Text = "蒙";
break;
case "天津市":
cboCarnum.Text = "津";
break;
case "贵州省":
cboCarnum.Text = "贵";
break;
case "云南省":
cboCarnum.Text = "云";
break;
case "广西壮族自治区":
cboCarnum.Text = "桂";
break;
case "海南省":
cboCarnum.Text = "琼";
break;
case "青海省":
cboCarnum.Text = "青";
break;
case "新疆维吾尔自治区":
cboCarnum.Text = "新";
break;
case "西藏自治区":
cboCarnum.Text = "藏";
break;
case "江苏省":
cboCarnum.Text = "苏";
break;
case "浙江省":
cboCarnum.Text = "浙";
break;
default:
break;
}
#endregion
}
//utf8 编码
static string TransferEncoding(Encoding srcEncoding, Encoding dstEncoding, string srcStr)
{
byte[] srcBytes = srcEncoding.GetBytes(srcStr);
byte[] bytes = Encoding.Convert(srcEncoding, dstEncoding, srcBytes);
return dstEncoding.GetString(bytes);
}
/// <summary>
/// 非空验证
/// </summary>
/// <returns></returns>
private bool CheckIsNull()
{
if (string.IsNullOrEmpty(txtCarnum.Text))
{
MessageBox.Show("请输入车牌号");
txtCarnum.Focus();
return false;
}
else
{
if (string.IsNullOrEmpty(txtFadongji.Text))
{
MessageBox.Show("请输入发动机号");
txtFadongji.Focus();
return false;
}
else if (string.IsNullOrEmpty(txtCaptcha.Text))
{
MessageBox.Show("请填写验证码");
txtCaptcha.Focus();
return false;
}
return true;
}
}
private void timer1_Tick(object sender, EventArgs e)
{
tsl2.Text = DateTime.Now.ToLongDateString() DateTime.Now.ToLongTimeString();
}
/// <summary>
/// 刷新验证码
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnUpdate_Click(object sender, EventArgs e)
{
GetVerificationCode();
}
private void txtCarnum_KeyPress(object sender, KeyPressEventArgs e)
{
txtCarnum.CharacterCasing = CharacterCasing.Upper;
}
private void btnHelper_Click(object sender, EventArgs e)
{
Help help = new Help();
help.Show();
}
}
}