最近要做的一个界面,由于数据太多且涉及到多个主子关联的表,朋友说用四个DataGrid绑定数据并实现与查询条件的联动,太麻烦而且界面肯定不好看,我用mshtml改造成这样了。
未加载数据的窗体
加载数据后的窗体
步骤:1)用Macromedia Dreamweaver生成一个名为fsallcondition.htm的html文件,源码如下:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>废水排放情况统计</title>
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
<style type="text/css">
<!--
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
body {
}{
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
-->
</style>
<script language="JavaScript" src="../includes/js/common.js"></script>
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
<script language="javascript">
function printsetup()
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
// 打印页面设置
wb.execwb(8,1);
}
function printpreview()
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
// 打印页面预览
wb.execwb(7,1);
}
function printit()
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if (confirm('您确定要打印本文档吗?'))
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
wb.execwb(6,6);
}
}
</script>
<link href="../includes/css/main.css" rel="stylesheet" type="text/css">
</head>
<body>
<OBJECT classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2" height=0 id=wb name=wb width=0></OBJECT>
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="center" valign="top"><table width="80%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="56%"><br>
<br><table width="806px" border="0" cellpadding="0" cellspacing="0" class="tableborder">
<tr>
<td width="83" class="tdrbborder"> 排污口编号</td>
<td id="pwkbh" width="107" class="tdrbborder"> </td>
<td width="85" class="tdrbborder"> 排污口名称</td>
<td id="pwkmc" width="120" class="tdrbborder"> </td>
<td width="77" class="tdrbborder"> 排污口位置</td>
<td id="pwkwz" width="136" class="tdrbborder"> </td>
<td width="77" class="tdrbborder"> 排放去向</td>
<td id="pfqx" width="120" class="tdbborder"> </td>
</tr>
<tr class="font9">
<td class="tdrbborder"> 接纳水体类别</td>
<td id="jnstlb" class="tdrbborder"> </td>
<td colspan="2" class="tdrbborder"> 新建项目名称及建设日期</td>
<td id="xjxmmcjjsrq" colspan="4" class="tdbborder"> </td>
</tr>
<tr class="font9">
<td class="tdrbborder"> 监控仪器</td>
<td id="jkyq" colspan="7" class="tdbborder"> </td>
</tr>
<tr class="font9">
<td class="tdrbborder"> 执行标准</td>
<td id="zxbz" colspan="7" class="tdbborder"> </td>
</tr>
<tr class="tdbborder">
<td id="pwkzxbz" colspan="8" class="tdbborder"> <strong>排污口执行标准:</strong><br><br>
</td>
</tr>
<tr class="font9">
<td colspan="8"><br>
<strong>允许排放量: </strong>
<div id="pwxkzbh" style="width:200px; line-height:18pt; font:9pt"> [排污许可证编号——]</div></td>
</tr>
<tr class="font9">
<td colspan="8" class="tdbborder"><table id="tblYXPFL" width="90%" border="0" align="center" cellpadding="0" cellspacing="0" class="tabletbborder">
<tr>
<td width="20%" class="tdrbborder"> 污水允许排放量</td>
<td width="27%" class="tdrbborder"> 污染物</td>
<td width="26%" class="tdrbborder"> 许可浓度</td>
<td width="27%" class="tdbborder"> 许可排放量</td>
</tr>
</table>
<br></td>
</tr>
<tr class="font9">
<td colspan="5" valign="top"><br>
<strong>污水排放情况:</strong>
<div id="pfzl" style="width:200px; line-height:18pt; font:9pt"> [排放总量——]</div></td>
<td colspan="3" valign="top"><br>
<strong>指标监测情况:</strong></td>
</tr>
<tr class="font9">
<td colspan="5" valign="top"><table width="95%" border="0" align="center" cellpadding="0" cellspacing="0" class="tabletbborder">
<tr>
<td width="28%" class="tdrbborder"> 污染物</td>
<td width="16%" class="tdrbborder"> 实际浓度</td>
<td width="17%" class="tdrbborder"> 达标排放量</td>
<td width="17%" class="tdrbborder"> 超标排放量</td>
<td width="22%" class="tdbborder"> 合计</td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
<br></td>
<td colspan="3" valign="top"><table width="95%" border="0" align="center" cellpadding="0" cellspacing="0" class="tabletbborder">
<tr>
<td width="48%" class="tdrbborder"> 污染物</td>
<td width="22%" class="tdrbborder"> 检测浓度</td>
<td width="30%" class="tdbborder"> 检测标准浓度</td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table><br></td>
</tr>
</table></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td> </td>
</tr>
</table></td>
</tr>
</table>
</body>
</html>
关键是:为每个数据区域(Td和Div)定义一个ID,以便在程序中进行引用。
2)建立WinForm窗体,引用Microsoft.mshtml,使用Microsoft Web浏览器加载html文件,"查询"按钮用于调用向html文件中写数据的过程,"页面设置"、"打印预览"及"打印"按钮用以调用html文件中的javascript完成相应的功能。源码如下:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
namespace HC.WinForm
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
{
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// frm_废水所有信息 的摘要说明。
/// </summary>
public class frm_废水所有信息 : System.Windows.Forms.Form
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.ComboBox cmbPWK;
private System.Windows.Forms.DateTimePicker dateTimePicker1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.RadioButton radYear;
private System.Windows.Forms.RadioButton radMonth;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Button btnQuery;
private System.Windows.Forms.Button btnExit;
private AxSHDocVw.AxWebBrowser awbMain;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.Button btnPS;
private System.Windows.Forms.Button btnPP;
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
[STAThread]
static void Main()
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
Application.Run(new frm_废水所有信息());
}
//单位编号
private string strunit = "";
//计数器,记录页面加载的次数
private int intLoadTimes = 0;
public string strUnit
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
get
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return this.strunit;
}
set
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
this.strunit = value;
}
}
private mshtml.IHTMLDocument2 doc = null;
private System.Runtime.InteropServices.Expando.IExpando ex;
private mshtml.IHTMLWindow2 win = null;
public frm_废水所有信息()
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if( disposing )
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if(components != null)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
Windows 窗体设计器生成的代码#region Windows 窗体设计器生成的代码
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(frm_废水所有信息));
this.panel1 = new System.Windows.Forms.Panel();
this.button3 = new System.Windows.Forms.Button();
this.btnPP = new System.Windows.Forms.Button();
this.btnPS = new System.Windows.Forms.Button();
this.btnExit = new System.Windows.Forms.Button();
this.btnQuery = new System.Windows.Forms.Button();
this.label4 = new System.Windows.Forms.Label();
this.radMonth = new System.Windows.Forms.RadioButton();
this.radYear = new System.Windows.Forms.RadioButton();
this.label3 = new System.Windows.Forms.Label();
this.dateTimePicker1 = new System.Windows.Forms.DateTimePicker();
this.cmbPWK = new System.Windows.Forms.ComboBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.awbMain = new AxSHDocVw.AxWebBrowser();
this.panel1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.awbMain)).BeginInit();
this.SuspendLayout();
//
// panel1
//
this.panel1.BackColor = System.Drawing.Color.White;
this.panel1.Controls.Add(this.button3);
this.panel1.Controls.Add(this.btnPP);
this.panel1.Controls.Add(this.btnPS);
this.panel1.Controls.Add(this.btnExit);
this.panel1.Controls.Add(this.btnQuery);
this.panel1.Controls.Add(this.label4);
this.panel1.Controls.Add(this.radMonth);
this.panel1.Controls.Add(this.radYear);
this.panel1.Controls.Add(this.label3);
this.panel1.Controls.Add(this.dateTimePicker1);
this.panel1.Controls.Add(this.cmbPWK);
this.panel1.Controls.Add(this.label1);
this.panel1.Controls.Add(this.label2);
this.panel1.Dock = System.Windows.Forms.DockStyle.Top;
this.panel1.Location = new System.Drawing.Point(0, 0);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(850, 48);
this.panel1.TabIndex = 0;
//
// button3
//
this.button3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.button3.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
this.button3.Location = new System.Drawing.Point(712, 13);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(56, 23);
this.button3.TabIndex = 5;
this.button3.Text = "打印(&P)";
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// btnPP
//
this.btnPP.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.btnPP.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
this.btnPP.Location = new System.Drawing.Point(640, 13);
this.btnPP.Name = "btnPP";
this.btnPP.Size = new System.Drawing.Size(64, 23);
this.btnPP.TabIndex = 4;
this.btnPP.Text = "打印预览";
this.btnPP.Click += new System.EventHandler(this.btnPP_Click);
//
// btnPS
//
this.btnPS.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.btnPS.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
this.btnPS.Location = new System.Drawing.Point(568, 13);
this.btnPS.Name = "btnPS";
this.btnPS.Size = new System.Drawing.Size(64, 23);
this.btnPS.TabIndex = 3;
this.btnPS.Text = "页面设置";
this.btnPS.Click += new System.EventHandler(this.btnPS_Click);
//
// btnExit
//
this.btnExit.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.btnExit.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
this.btnExit.Location = new System.Drawing.Point(776, 13);
this.btnExit.Name = "btnExit";
this.btnExit.Size = new System.Drawing.Size(56, 23);
this.btnExit.TabIndex = 6;
this.btnExit.Text = "退出(&X)";
this.btnExit.Click += new System.EventHandler(this.btnExit_Click);
//
// btnQuery
//
this.btnQuery.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.btnQuery.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
this.btnQuery.Location = new System.Drawing.Point(504, 13);
this.btnQuery.Name = "btnQuery";
this.btnQuery.Size = new System.Drawing.Size(56, 23);
this.btnQuery.TabIndex = 2;
this.btnQuery.Text = "查询(&Q)";
this.btnQuery.Click += new System.EventHandler(this.btnQuery_Click);
//
// label4
//
this.label4.Location = new System.Drawing.Point(448, 16);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(32, 16);
this.label4.TabIndex = 7;
this.label4.Text = "查询";
//
// radMonth
//
this.radMonth.Checked = true;
this.radMonth.Location = new System.Drawing.Point(416, 12);
this.radMonth.Name = "radMonth";
this.radMonth.Size = new System.Drawing.Size(32, 24);
this.radMonth.TabIndex = 6;
this.radMonth.TabStop = true;
this.radMonth.Text = "月";
//
// radYear
//
this.radYear.Location = new System.Drawing.Point(384, 12);
this.radYear.Name = "radYear";
this.radYear.Size = new System.Drawing.Size(32, 24);
this.radYear.TabIndex = 5;
this.radYear.Text = "年";
//
// label3
//
this.label3.Location = new System.Drawing.Point(368, 16);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(16, 16);
this.label3.TabIndex = 4;
this.label3.Text = "按";
//
// dateTimePicker1
//
this.dateTimePicker1.Location = new System.Drawing.Point(232, 14);
this.dateTimePicker1.Name = "dateTimePicker1";
this.dateTimePicker1.Size = new System.Drawing.Size(120, 21);
this.dateTimePicker1.TabIndex = 1;
//
// cmbPWK
//
this.cmbPWK.Location = new System.Drawing.Point(64, 14);
this.cmbPWK.Name = "cmbPWK";
this.cmbPWK.Size = new System.Drawing.Size(121, 20);
this.cmbPWK.TabIndex = 0;
this.cmbPWK.Text = "comboBox1";
//
// label1
//
this.label1.Location = new System.Drawing.Point(16, 16);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(64, 16);
this.label1.TabIndex = 0;
this.label1.Text = "排污口";
//
// label2
//
this.label2.Location = new System.Drawing.Point(200, 16);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(64, 16);
this.label2.TabIndex = 3;
this.label2.Text = "年月";
//
// awbMain
//
this.awbMain.Dock = System.Windows.Forms.DockStyle.Fill;
this.awbMain.Enabled = true;
this.awbMain.Location = new System.Drawing.Point(0, 48);
this.awbMain.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("awbMain.OcxState")));
this.awbMain.Size = new System.Drawing.Size(850, 408);
this.awbMain.TabIndex = 1;
this.awbMain.DocumentComplete += new AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEventHandler(this.awbMain_DocumentComplete);
//
// frm_废水所有信息
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(850, 456);
this.Controls.Add(this.awbMain);
this.Controls.Add(this.panel1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
this.Name = "frm_废水所有信息";
this.Text = "废水所有信息统计";
this.Load += new System.EventHandler(this.frm_废水所有信息_Load);
this.panel1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.awbMain)).EndInit();
this.ResumeLayout(false);
}
#endregion
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 为cmbPWK绑定数据
/// </summary>
private void SetUnitCombo()
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
string strSQL = "SELECT 排污口编号, 排污口名称 FROM [PW_废水排污口] WHERE (所属单位 = '" + this.strUnit + "') ORDER BY 排污口编号";
System.Data.DataSet dsUnit = HEWin.Sys.sysDb.GetDataSetBySql(strSQL, "废水排污口");
this.cmbPWK.DataSource = dsUnit.Tables["废水排污口"];
this.cmbPWK.DisplayMember = "排污口名称";
this.cmbPWK.ValueMember = "排污口编号";
dsUnit.Dispose();
}
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 排污口基本情况,最多只有一行数据
/// </summary>
private string SetBasicInfo()
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
string strRet = "";
string strSQL = "SELECT 排污口编号, 排污口名称, 排污口位置, 排放去向, 排放标准, 接纳水体功能类别 AS 接纳水体类别, 最近建设项目名称及建设日期 AS 新建项目名称及建设日期, 监控仪器, 执行标准 FROM [CX_排污口基本情况] WHERE (排污口编号 = '" + this.cmbPWK.SelectedValue.ToString() + "')";
System.Data.DataSet dsBasicInfo = HEWin.Sys.sysDb.GetDataSetBySql(strSQL, "排污口基本情况");
if (dsBasicInfo.Tables["排污口基本情况"].Rows.Count == 0)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
this.win.execScript("showMD(\"环境检测管理系统\", \"errnounit.htm\", true, false, false)", "javascript");
return strRet;
}
strRet = dsBasicInfo.Tables["排污口基本情况"].Rows[0]["排放标准"].ToString();
mshtml.IHTMLElement2 eleTd = (mshtml.IHTMLElement2)doc.all.item("pwkbh", null);
((mshtml.HTMLTableCellClass)eleTd).innerHTML = " <font color='blue'>" + dsBasicInfo.Tables["排污口基本情况"].Rows[0]["排污口编号"].ToString() + "</font>";
eleTd = (mshtml.IHTMLElement2)doc.all.item("pwkmc", null);
((mshtml.HTMLTableCellClass)eleTd).innerHTML = " <font color='blue'>" + dsBasicInfo.Tables["排污口基本情况"].Rows[0]["排污口名称"].ToString() + "</font>";
eleTd = (mshtml.IHTMLElement2)doc.all.item("pwkwz", null);
((mshtml.HTMLTableCellClass)eleTd).innerHTML = " <font color='blue'>" + dsBasicInfo.Tables["排污口基本情况"].Rows[0]["排污口位置"].ToString() + "</font>";
eleTd = (mshtml.IHTMLElement2)doc.all.item("pfqx", null);
((mshtml.HTMLTableCellClass)eleTd).innerHTML = " <font color='blue'>" + dsBasicInfo.Tables["排污口基本情况"].Rows[0]["排放去向"].ToString() + "</font>";
eleTd = (mshtml.IHTMLElement2)doc.all.item("jnstlb", null);
((mshtml.HTMLTableCellClass)eleTd).innerHTML = " <font color='blue'>" + dsBasicInfo.Tables["排污口基本情况"].Rows[0]["接纳水体类别"].ToString() + "</font>";
eleTd = (mshtml.IHTMLElement2)doc.all.item("xjxmmcjjsrq", null);
((mshtml.HTMLTableCellClass)eleTd).innerHTML = " <font color='blue'>" + dsBasicInfo.Tables["排污口基本情况"].Rows[0]["新建项目名称及建设日期"].ToString() + "</font>";
eleTd = (mshtml.IHTMLElement2)doc.all.item("jkyq", null);
((mshtml.HTMLTableCellClass)eleTd).innerHTML = " <font color='blue'>" + dsBasicInfo.Tables["排污口基本情况"].Rows[0]["监控仪器"].ToString() + "</font>";
eleTd = (mshtml.IHTMLElement2)doc.all.item("zxbz", null);
((mshtml.HTMLTableCellClass)eleTd).innerHTML = " <font color='blue'>" + dsBasicInfo.Tables["排污口基本情况"].Rows[0]["执行标准"].ToString() + "</font>";
dsBasicInfo.Dispose();
eleTd = null;
return strRet;
}
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 执行标准
/// </summary>
/// <param name="执行标准"></param>
private void SetExecStandard(string 执行标准)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if (执行标准 == "")
return;
string strSQL = "SELECT 执行标准编号, 执行标准 FROM [CX_废水执行标准] WHERE (执行标准编号 = '" + 执行标准 + "')";
string strIH = " <strong>排污口执行标准:</strong><br><center><font color='blue'>";
System.Data.DataSet dsES = HEWin.Sys.sysDb.GetDataSetBySql(strSQL, "废水执行标准");
if (dsES.Tables["废水执行标准"].Rows.Count == 0)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
strIH += "无执行标准";
}
else
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
for(int i = 0; i < dsES.Tables["废水执行标准"].Rows.Count; i ++)
strIH += dsES.Tables["废水执行标准"].Rows[i]["执行标准"].ToString().Replace(" ", " ") + "<br>";
}
strIH += "</font></center>";
mshtml.IHTMLElement2 eleTd = (mshtml.IHTMLElement2)doc.all.item("pwkzxbz", null);
((mshtml.HTMLTableCellClass)eleTd).innerHTML = strIH;
}
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 允许排放量
/// </summary>
private void SetYXPFL()
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
string strSQL = "SELECT 许可证编号, 污水允许排放量, 污染物, 许可浓度, 许可排放量 FROM [CX_废水允许排放量] WHERE (排污口编号 = '" + this.cmbPWK.SelectedValue.ToString() + "') ORDER BY 污染物";
System.Data.DataSet dsYXPFL = HEWin.Sys.sysDb.GetDataSetBySql(strSQL, "允许排放量");
string strScript = "";
mshtml.IHTMLElement2 eleDiv = (mshtml.IHTMLElement2)doc.all.item("pwxkzbh", null);
if (dsYXPFL.Tables["允许排放量"].Rows.Count == 0)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
//没有污水允许排放量时的处理
strScript = "var rowNew = tblYXPFL.insertRow();";
//污水允许排放量
strScript += "var tdWSYXPFL = rowNew.insertCell();";
//设置单元格的ColSpan为4
strScript += "tdWSYXPFL.colSpan = 4;";
strScript += "tdWSYXPFL.innerHTML = '<center><font color=blue>——————————————</font></center>';";
this.win.execScript(strScript, "javascript");
((mshtml.HTMLDivElementClass)eleDiv).innerHTML = " [排污许可证编号——<font color='red'>无</font>]";
}
else
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
((mshtml.HTMLDivElementClass)eleDiv).innerHTML = " [排污许可证编号——<font color='red'>" + dsYXPFL.Tables["允许排放量"].Rows[0]["许可证编号"].ToString() + "</font>]";
if (dsYXPFL.Tables["允许排放量"].Rows.Count > 1)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//* 执行Script为表添加数据行、单元格及单元格格式与数据
* 由于受单元格样式不同的影响,此处只添加表行数-1行数据
* 此循环后的代码添加最后一行数据
* 如果只有一行数据,不执行下面的循环
*/
for (int i = 0; i < dsYXPFL.Tables["允许排放量"].Rows.Count - 1; i++)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
strScript = "var rowNew = tblYXPFL.insertRow();";
//污水允许排放量
strScript += "var tdWSYXPFL = rowNew.insertCell();";
strScript += "tdWSYXPFL.className = 'tdrbborder';";
strScript += "tdWSYXPFL.innerHTML = ' <font color=blue>" + dsYXPFL.Tables["允许排放量"].Rows[i]["污水允许排放量"].ToString() + "</font>';";
//污染物
strScript += "var tdWRW = rowNew.insertCell();";
strScript += "tdWRW.className = 'tdrbborder';";
strScript += "tdWRW.innerHTML = ' <font color=blue>" + dsYXPFL.Tables["允许排放量"].Rows[i]["污染物"].ToString() + "</font>';";
//许可浓度
strScript += "var tdXKND = rowNew.insertCell();";
strScript += "tdXKND.className = 'tdrbborder';";
strScript += "tdXKND.innerHTML = ' <font color=blue>" + dsYXPFL.Tables["允许排放量"].Rows[i]["许可浓度"].ToString() + "</font>';";
//许可排放量
strScript += "var tdXKPFL = rowNew.insertCell();";
strScript += "tdXKPFL.className = 'tdbborder';";
strScript += "tdXKPFL.innerHTML = ' <font color=blue>" + dsYXPFL.Tables["允许排放量"].Rows[i]["许可排放量"].ToString() + "</font>';";
//执行上面的SCRIPT
this.win.execScript(strScript, "javascript");
}
}
strScript = "var rowNew = tblYXPFL.insertRow();";
//污水允许排放量
strScript += "var tdWSYXPFL = rowNew.insertCell();";
strScript += "tdWSYXPFL.className = 'tdrborder';";
strScript += "tdWSYXPFL.innerHTML = ' <font color=blue>" + dsYXPFL.Tables["允许排放量"].Rows[dsYXPFL.Tables["允许排放量"].Rows.Count - 1]["污水允许排放量"].ToString() + "</font>';";
//污染物
strScript += "var tdWRW = rowNew.insertCell();";
strScript += "tdWRW.className = 'tdrborder';";
strScript += "tdWRW.innerHTML = ' <font color=blue>" + dsYXPFL.Tables["允许排放量"].Rows[dsYXPFL.Tables["允许排放量"].Rows.Count - 1]["污染物"].ToString() + "</font>';";
//许可浓度
strScript += "var tdXKND = rowNew.insertCell();";
strScript += "tdXKND.className = 'tdrborder';";
strScript += "tdXKND.innerHTML = ' <font color=blue>" + dsYXPFL.Tables["允许排放量"].Rows[dsYXPFL.Tables["允许排放量"].Rows.Count - 1]["许可浓度"].ToString() + "</font>';";
//许可排放量
strScript += "var tdXKPFL = rowNew.insertCell();";
strScript += "tdXKPFL.innerHTML = ' <font color=blue>" + dsYXPFL.Tables["允许排放量"].Rows[dsYXPFL.Tables["允许排放量"].Rows.Count - 1]["许可排放量"].ToString() + "</font>';";
//执行上面的SCRIPT
this.win.execScript(strScript, "javascript");
}
eleDiv = null;
dsYXPFL.Dispose();
}
private void frm_废水所有信息_Load(object sender, System.EventArgs e)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
this.strUnit = "001";
this.SetUnitCombo();
object url = System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), @"html\html\fsallcondition.htm");
object r = System.Reflection.Missing.Value;
//装载没有数据的页面
this.awbMain.Navigate2(ref url,ref r,ref r,ref r,ref r);
}
private void btnExit_Click(object sender, System.EventArgs e)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
this.Dispose();
}
private void btnQuery_Click(object sender, System.EventArgs e)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//*
* 每次查询前清空数据,重新加载一遍没有数据的页面即可
* 此事件中代码不负责具体的查询数据的工作
*/
object url = System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), @"html\html\fsallcondition.htm");
object r = System.Reflection.Missing.Value;
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//* 装载没有数据的页面
* Navigate2方法会引发awbMain_DocumentComplete事件
* 在awbMain_DocumentComplete事件中进行数据的查询
*/
this.awbMain.Navigate2(ref url,ref r,ref r,ref r,ref r);
}
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 浏览器加载完毕时的处理事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void awbMain_DocumentComplete(object sender, AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent e)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if (this.intLoadTimes == 0)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
//第一次加载页面时执行该段代码,减少执行次数(只执行一次)
this.doc = (mshtml.IHTMLDocument2)this.awbMain.Document;
ex = (System.Runtime.InteropServices.Expando.IExpando)doc;
System.Reflection.PropertyInfo piform = ex.AddProperty("MainForm");
piform.SetValue(doc, this, null);
this.win = this.doc.parentWindow;
}
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//* 在页面中加入了
* <OBJECT classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2" height=0 id=wb name=wb width=0></OBJECT>
* 组件后引发了两次awbMain_DocumentComplete事件
*
*/
else if (this.intLoadTimes > 2)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
//不是第一次加载页面时查询数据
string strESBH = this.SetBasicInfo();
this.SetExecStandard(strESBH);
this.SetYXPFL();
}
this.intLoadTimes ++;
}
//调用HTML文件中的Javascript进行页面设置
private void btnPS_Click(object sender, System.EventArgs e)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
this.win.execScript("printsetup();", "javascript");
}
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//* 调用HTML文件中的Javascript进行打印预览
* 调出打印预览的窗口是不能最大化的,大小取决于本窗体的大小。
*
*/
private void btnPP_Click(object sender, System.EventArgs e)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
this.win.execScript("printpreview();", "javascript");
}
private void button3_Click(object sender, System.EventArgs e)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
this.win.execScript("printit();", "javascript");
}
}
}
这个过程中发现的两个问题:
1)在页面中加入了<OBJECT classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2" height=0 id=wb name=wb width=0></OBJECT>组件后引发了两次awbMain_DocumentComplete事件;
2)调用HTML文件中的Javascript进行打印预览,调出打印预览的窗口是不能最大化的,大小取决于本窗体的大小。