private void ChartZhu()
{
try
{
string beginTime, endTime, townCode;
int count = 0, degree = -1, state = 0;
bool isDegree = true;
if (radioGroup1.SelectedIndex==0)
isDegree = true;
else
isDegree = false;
//初始化参数
degree = InitParamS(degree, out beginTime, out endTime, out townCode);
//省级视图
if (lookUpEdit5.EditValue != null &&
(lookUpEdit6.EditValue == null || lookUpEdit6.EditValue.ToString() == "-1") &&
(lookUpEdit8.EditValue == null || lookUpEdit8.EditValue.ToString() == "-1") &&
(lookUpEdit7.EditValue == null || lookUpEdit7.EditValue.ToString() == "-1"))
{
DataTable dt = GetLocalProvinceDetails(beginTime, endTime, townCode, degree, state, out count);
InitDetailsView(dt);
return;
}
//市级视图
if (lookUpEdit5.EditValue != null &&
lookUpEdit6.EditValue != null &&
(lookUpEdit8.EditValue == null || lookUpEdit8.EditValue.ToString() == "-1") &&
(lookUpEdit7.EditValue == null || lookUpEdit7.EditValue.ToString() == "-1"))
{
DataTable dt = GetLocalCityDetails(beginTime, endTime, townCode, degree, state, out count);
InitDetailsView(dt);
return;
}
//县级视图
if (lookUpEdit5.EditValue != null &&
lookUpEdit6.EditValue != null &&
lookUpEdit8.EditValue != null &&
(lookUpEdit7.EditValue == null || lookUpEdit7.EditValue.ToString() == "-1"))
{
DataTable dt = GetLocalCountyDetails(beginTime, endTime, townCode, degree, state, out count);
InitDetailsView(dt);
return;
}
//乡级视图
if (lookUpEdit5.EditValue != null && lookUpEdit6.EditValue != null && lookUpEdit8.EditValue != null && lookUpEdit7.EditValue != null)
{
DataTable dt = bllh.GetChartData1(beginTime, endTime, townCode, isDegree);
InitDetailsView(dt);
return;
}
}
catch (Exception ex)
{
XtraMessageBox.Show("显示视图失败:" ex.Message, "友情提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
/// <summary>
/// 初始化参数
/// </summary>
/// <param name="degree"></param>
/// <param name="beginTime"></param>
/// <param name="endTime"></param>
/// <param name="townCode"></param>
/// <returns></returns>
private int InitParamS(int degree, out string beginTime, out string endTime, out string townCode)
{
Initparams(out beginTime, out endTime, out townCode);
if (ischeck)
degree = InitDegree(degree);
ischeck = radioGroup3.Enabled;
return degree;
}
/// <summary>
/// 初始化参数
/// </summary>
/// <param name="beginTime"></param>
/// <param name="endTime"></param>
/// <param name="townCode"></param>
private void Initparams(out string beginTime, out string endTime, out string townCode)
{
beginTime = this.dateEdit4.DateTime.ToString("yyyy-MM-dd") " 00:00:00";
endTime = this.dateEdit3.DateTime.AddDays(1).ToString("yyyy-MM-dd") " 00:00:00";
townCode = string.Empty;
if (lookUpEdit5.EditValue != null && lookUpEdit5.EditValue.ToString() != "-1")
townCode = lookUpEdit5.EditValue.ToString();
if (lookUpEdit6.EditValue != null && lookUpEdit6.EditValue.ToString() != "-1")
townCode = lookUpEdit6.EditValue.ToString();
if (lookUpEdit8.EditValue != null && lookUpEdit8.EditValue.ToString() != "-1")
townCode = lookUpEdit8.EditValue.ToString();
if (lookUpEdit7.EditValue != null && lookUpEdit7.EditValue.ToString() != "-1")
townCode = lookUpEdit7.EditValue.ToString();
}
/// <summary>
/// 给degree赋值
/// </summary>
/// <param name="degree"></param>
/// <returns></returns>
private int InitDegree(int degree)
{
if (radioGroup3.Properties.Items.Count == 3)
{
if (radioGroup3.SelectedIndex == 0)
degree = 0;
if (radioGroup3.SelectedIndex == 1)
degree = 1;
if (radioGroup3.SelectedIndex == 2)
degree = 2;
}
if (radioGroup3.Properties.Items.Count == 5)
{
if (radioGroup3.SelectedIndex == 2)
degree = 4;
if (radioGroup3.SelectedIndex == 1)
degree = 3;
if (radioGroup3.SelectedIndex == 0)
degree = 1;
if (radioGroup3.SelectedIndex == 3)
degree = 2;
if (radioGroup3.SelectedIndex == 4)
degree = 5;
}
return degree;
}
/// <summary>
/// 初始化柱状图
/// </summary>
/// <param name="dt"></param>
private void InitDetailsView(DataTable dt)
{
StringBuilder frist = new StringBuilder();
StringBuilder strXml = new StringBuilder();
strXml.Append("<categories>");
frist.Append("<dataset seriesname=''>");
for (int i = 0; i < dt.Rows.Count; i )
{
strXml.Append("<category name='" dt.Rows[i]["Corp_Town_Name"].ToString() "'/>");
frist.AppendFormat("<set value='{0}' />", dt.Rows[i]["Count"].ToString());
}
strXml.Append("</categories>");
frist.Append("</dataset>");
strXml.Append(frist);
string data = string.Format("<script type='text/javascript' src='javascript/jquery-1.4.2.min.js'></script><script type='text/javascript' src='javascript/lib.js'></script><script type='text/javascript' src='javascript/FusionCharts.js'></script><object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\" width=\"680\" height=\"440\" name=\"我来试试\"><param name=\"allowScriptAccess\" value=\"always\" /><param name=\"movie\" value=\"swf/MSColumn3D.swf\"/><param name=\"FlashVars\" value=\"&chartWidth=680&chartHeight=440&debugMode=0&dataXML=<chart caption='隐患数量柱形图示' decimalPrecision='0' chartLeftMargin='0' outCnvBaseFontSize='12'baseFontSize='12' yAxisName='隐患数量' numberPrefix='' ecimalPrecision='1' >{0}</chart>\" /><param name=\"quality\" value=\"high\" /><embed src=\"swf/MSColumn3D.swf\" FlashVars=\"&chartWidth=680&chartHeight=440&debugMode=0&dataXML=<chart caption='隐患数量柱形图示' decimalPrecision='0'chartLeftMargin='0 outCnvBaseFontSize='12'baseFontSize='12' yAxisName='隐患数量' numberPrefix='' decimalPrecision='1'>{1}</chart>\" quality=\"high\" width=\"680\" height=\"440\" name=\"我来试试\" allowScriptAccess=\"always\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" /></object>", strXml, strXml);
WriteData(data);
SetContext(webBrowser1);
}
/// <summary>
/// 获取一个乡的详细情况
/// </summary>
/// <param name="beginTime"></param>
/// <param name="endTime"></param>
/// <param name="townCode">乡代码(xxxxxx-xxx)</param>
/// <param name="degree"></param>
/// <param name="state"></param>
/// <param name="count">已废弃参数,返回常量"0"</param>
/// <returns>一个县的每个乡的详细情况</returns>
private DataTable GetLocalCountyDetails(string beginTime, string endTime, string townCode, int degree, int state, out int count)
{
DataTable Xianji = new DataTable();//初始化县列表
Xianji.TableName = townCode;
Xianji.Columns.AddRange(new DataColumn[]{
new DataColumn("Corp_Town_Name"),
new DataColumn("Count")
});
//向县列表中添加每个乡的信息
DataTable temp = bllh.GetChartDataByQY1(beginTime, endTime, townCode, degree, state, out count);
if (temp != null && temp.Rows.Count > 0)
{
for (int i = 0; i < temp.Rows.Count; i )
{
Xianji.Rows.Add(new object[] { temp.Rows[i]["Corp_Town_Name"].ToString(), temp.Rows[i]["Count"].ToString() });
}
}
return Xianji;
}
/// <summary>
/// 获取一个市的详细信息
/// </summary>
/// <param name="beginTime"></param>
/// <param name="endTime"></param>
/// <param name="cityCode">市代码(xxxx)</param>
/// <param name="degree"></param>
/// <param name="state"></param>
/// <param name="count">已废弃参数,返回常量"0"</param>
/// <returns>一个市的每一个县详细情况</returns>
public DataTable GetLocalCityDetails(string beginTime, string endTime, string cityCode, int degree, int state, out int count)
{
count = 0;
DataTable ShiJi = new DataTable();//初始化市级列表
ShiJi.Columns.AddRange(new DataColumn[] {
new DataColumn("Corp_Town_Name"),
new DataColumn("Count")});
//获取隶属于本市的所有县级代码
DataTable Countys = rbll.GetCounty1(cityCode, null);
//初始化临时县级表
DataTable[] Towns = new DataTable[Countys.Rows.Count];
//在临时县级表里添加数据
for (int i = 0; i < Countys.Rows.Count; i )
{
string code = Countys.Rows[i]["Corp_Town_Code"].ToString();
Towns[i] = new DataTable();
Towns[i] = GetLocalCountyDetails(beginTime, endTime, code, degree, state, out count);
}
string CountyValuename = ""; //初始化一个县的名称
int CountyValueNum = 0; //初始化一个县的总统计数值
for (int j = 0; j < Countys.Rows.Count; j )
{
CountyValuename = Countys.Rows[j]["Corp_Town_Name"].ToString();//获取这个县的名称
for (int k = 0; k < Towns[j].Rows.Count; k )
{
CountyValueNum = int.Parse(Towns[j].Rows[k]["Count"].ToString());//获取这个县的总值
}
ShiJi.Rows.Add(new object[] { CountyValuename, CountyValueNum });
}
return ShiJi;
}
/// <summary>
/// 获取一个省的详细信息
/// </summary>
/// <param name="beginTime"></param>
/// <param name="endTime"></param>
/// <param name="ProvinceCode">省代码(xx)</param>
/// <param name="degree"></param>
/// <param name="state"></param>
/// <param name="count">已废弃参数,返回常量"0"</param>
/// <returns>一个省的每一个市详细情况</returns>
public DataTable GetLocalProvinceDetails(string beginTime, string endTime, string ProvinceCode, int degree, int state, out int count)
{
count = 0;
DataTable Shengji = new DataTable();//初始化省级列表
Shengji.Columns.AddRange(new DataColumn[]{
new DataColumn("Corp_Town_Name"),
new DataColumn("Count")});
//获取隶属于本省的所有市级代码
DataTable Citys = rbll.GetCity1(ProvinceCode);
//初始化临时市级表
DataTable[] Countys = new DataTable[Citys.Rows.Count];
//在临时市级表里添加数据
for (int i = 0; i < Citys.Rows.Count; i )
{
string code = Citys.Rows[i]["Corp_Town_Code"].ToString();
Countys[i] = new DataTable();
Countys[i] = GetLocalCityDetails(beginTime, endTime, code, degree, state, out count);
}
string CityValuename = ""; //初始化一个市的名称
int CityValueNum = 0; //初始化一个市的总统计数值
for (int j = 0; j < Citys.Rows.Count; j )
{
CityValuename = Citys.Rows[j]["Corp_Town_Name"].ToString();//获取这个市的名称
for (int k = 0; k < Countys[j].Rows.Count; k )
{
CityValueNum = int.Parse(Countys[j].Rows[k]["Count"].ToString());////获取这个市的总值
}
Shengji.Rows.Add(new object[] { CityValuename, CityValueNum });
}
return Shengji;
}