HTML代码
后台代码
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>gerenmingxi</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
<style type="text/css">BODY { BACKGROUND-COLOR: #def3ff }
</style>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<FONT face="宋体">
<asp:Label id="Label1" style="Z-INDEX: 101; LEFT: 40px; POSITION: absolute; TOP: 48px" runat="server"
Font-Size="Smaller" ForeColor="#004000">起始日期:</asp:Label>
<asp:Label id="Label6" style="Z-INDEX: 114; LEFT: 40px; POSITION: absolute; TOP: 80px" runat="server"
Font-Size="Smaller">注意:时间使用统一格式,年月日,比如050901</asp:Label>
<asp:TextBox id="TextBox1" style="Z-INDEX: 102; LEFT: 104px; POSITION: absolute; TOP: 40px" runat="server"
Width="104px" BorderStyle="Groove" tabIndex="2"></asp:TextBox>
<asp:Label id="Label2" style="Z-INDEX: 103; LEFT: 224px; POSITION: absolute; TOP: 48px" runat="server"
Font-Size="Smaller" ForeColor="#004000">截止日期:</asp:Label>
<asp:TextBox id="TextBox2" style="Z-INDEX: 104; LEFT: 288px; POSITION: absolute; TOP: 40px" runat="server"
Width="104px" BorderStyle="Groove" tabIndex="3"></asp:TextBox>
<asp:Button id="Button1" style="Z-INDEX: 105; LEFT: 416px; POSITION: absolute; TOP: 40px" runat="server"
Text="查 询" ForeColor="#004000" BorderStyle="Groove" tabIndex="4"></asp:Button>
<asp:Label id="Label3" style="Z-INDEX: 106; LEFT: 40px; POSITION: absolute; TOP: 16px" runat="server"
Font-Size="Smaller" ForeColor="#004000">职工名称:</asp:Label>
<asp:TextBox id="TextBox3" style="Z-INDEX: 107; LEFT: 104px; POSITION: absolute; TOP: 8px" runat="server"
Width="104px" BorderStyle="Groove" tabIndex="1"></asp:TextBox>
<asp:Table id="Table1" style="Z-INDEX: 108; LEFT: 40px; POSITION: absolute; TOP: 104px" runat="server"
ForeColor="DarkSlateBlue" GridLines="Both" BorderColor="#C000C0"></asp:Table>
<asp:RequiredFieldValidator id="RequiredFieldValidator1" style="Z-INDEX: 109; LEFT: 224px; POSITION: absolute; TOP: 16px"
runat="server" Font-Size="Smaller" ErrorMessage="请输入职工名,注意两个字的名字请在中间输入两个空格" ControlToValidate="TextBox3"></asp:RequiredFieldValidator></FONT>
</form>
</body>
</HTML>
<HTML>
<HEAD>
<title>gerenmingxi</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
<style type="text/css">BODY { BACKGROUND-COLOR: #def3ff }
</style>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<FONT face="宋体">
<asp:Label id="Label1" style="Z-INDEX: 101; LEFT: 40px; POSITION: absolute; TOP: 48px" runat="server"
Font-Size="Smaller" ForeColor="#004000">起始日期:</asp:Label>
<asp:Label id="Label6" style="Z-INDEX: 114; LEFT: 40px; POSITION: absolute; TOP: 80px" runat="server"
Font-Size="Smaller">注意:时间使用统一格式,年月日,比如050901</asp:Label>
<asp:TextBox id="TextBox1" style="Z-INDEX: 102; LEFT: 104px; POSITION: absolute; TOP: 40px" runat="server"
Width="104px" BorderStyle="Groove" tabIndex="2"></asp:TextBox>
<asp:Label id="Label2" style="Z-INDEX: 103; LEFT: 224px; POSITION: absolute; TOP: 48px" runat="server"
Font-Size="Smaller" ForeColor="#004000">截止日期:</asp:Label>
<asp:TextBox id="TextBox2" style="Z-INDEX: 104; LEFT: 288px; POSITION: absolute; TOP: 40px" runat="server"
Width="104px" BorderStyle="Groove" tabIndex="3"></asp:TextBox>
<asp:Button id="Button1" style="Z-INDEX: 105; LEFT: 416px; POSITION: absolute; TOP: 40px" runat="server"
Text="查 询" ForeColor="#004000" BorderStyle="Groove" tabIndex="4"></asp:Button>
<asp:Label id="Label3" style="Z-INDEX: 106; LEFT: 40px; POSITION: absolute; TOP: 16px" runat="server"
Font-Size="Smaller" ForeColor="#004000">职工名称:</asp:Label>
<asp:TextBox id="TextBox3" style="Z-INDEX: 107; LEFT: 104px; POSITION: absolute; TOP: 8px" runat="server"
Width="104px" BorderStyle="Groove" tabIndex="1"></asp:TextBox>
<asp:Table id="Table1" style="Z-INDEX: 108; LEFT: 40px; POSITION: absolute; TOP: 104px" runat="server"
ForeColor="DarkSlateBlue" GridLines="Both" BorderColor="#C000C0"></asp:Table>
<asp:RequiredFieldValidator id="RequiredFieldValidator1" style="Z-INDEX: 109; LEFT: 224px; POSITION: absolute; TOP: 16px"
runat="server" Font-Size="Smaller" ErrorMessage="请输入职工名,注意两个字的名字请在中间输入两个空格" ControlToValidate="TextBox3"></asp:RequiredFieldValidator></FONT>
</form>
</body>
</HTML>
后台代码
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
namespace lanchuxitong
{
/// <summary>
/// gerenmingxi 的摘要说明。
/// </summary>
public class gerenmingxi : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.TextBox TextBox2;
protected System.Data.SqlClient.SqlConnection sqlConnection1;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.TextBox TextBox3;
protected System.Web.UI.WebControls.Table Table1;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
protected System.Web.UI.WebControls.Label Label6;
protected System.Web.UI.WebControls.Button Button1;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
}
Web 窗体设计器生成的代码
private void Button1_Click(object sender, System.EventArgs e)
{
WriteTableHead();
sqlConnection1.Open();
SqlCommand cmd1 = new SqlCommand("select zgm,ssbm,chzh,lanchujine,lclx,dkh,curq from lcdj where zgm='"+ TextBox3.Text +"' and (crrq >= '"+ TextBox1.Text +"') and (crrq <= '"+ TextBox2.Text +"')", sqlConnection1);
SqlDataReader reader1 = cmd1.ExecuteReader();
int rowid = 0;
while(reader1.Read())
{
TableRow r = new TableRow();
// Set bgcolor on alternating rows.
if (rowid%2 == 1)
r.BackColor=System.Drawing.Color.Gainsboro;
for (int i=0; i<7; i++)
{
TableCell c = new TableCell();
switch(i)
{
case 0:
case 1:
case 2:
case 4:
case 5:
case 6:
c.Controls.Add(new LiteralControl(reader1.GetString(i)));
break;
case 3:
c.Controls.Add(new LiteralControl(reader1.GetDecimal(i).ToString()));
break;
/*case 2:
c.Controls.Add(new LiteralControl(reader1.GetDecimal(i).ToString()));
break;
case 3:
c.Controls.Add(new LiteralControl(reader1.GetInt32(i).ToString()));
break;
case 0:
c.Controls.Add(new LiteralControl(reader1.GetDateTime(i).ToString("yyyy-MM-dd")));
break;
case 1:
c.Controls.Add(new LiteralControl(reader1.GetDateTime(i).ToString("HH:mm")));
break;*/
default:
break;
}
r.Cells.Add(c);
}
Table1.Rows.Add(r);
rowid++;
}
}
private void WriteTableHead()
{
TableRow r = new TableRow();
r.BackColor=System.Drawing.Color.BlueViolet;
r.ForeColor=System.Drawing.Color.GreenYellow;
// Set bgcolor on alternating rows.
//if (row%2 == 1)
// r.BackColor=System.Drawing.Color.Gainsboro;
TableCell c1 = new TableCell();
c1.Controls.Add(new LiteralControl("列名"));
r.Cells.Add(c1);
TableCell c2 = new TableCell();
c2.Controls.Add(new LiteralControl("列名"));
r.Cells.Add(c2);
TableCell c3 = new TableCell();
c3.Controls.Add(new LiteralControl("列名"));
r.Cells.Add(c3);
TableCell c4 = new TableCell();
c4.Controls.Add(new LiteralControl("列名"));
r.Cells.Add(c4);
TableCell c5 = new TableCell();
c5.Controls.Add(new LiteralControl("列名"));
r.Cells.Add(c5);
TableCell c6 = new TableCell();
c6.Controls.Add(new LiteralControl("列名"));
r.Cells.Add(c6);
TableCell c7 = new TableCell();
c7.Controls.Add(new LiteralControl("列名"));
r.Cells.Add(c7);
Table1.Rows.Add(r);
}
}
}
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
namespace lanchuxitong
{
/// <summary>
/// gerenmingxi 的摘要说明。
/// </summary>
public class gerenmingxi : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.TextBox TextBox2;
protected System.Data.SqlClient.SqlConnection sqlConnection1;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.TextBox TextBox3;
protected System.Web.UI.WebControls.Table Table1;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
protected System.Web.UI.WebControls.Label Label6;
protected System.Web.UI.WebControls.Button Button1;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
}
Web 窗体设计器生成的代码
private void Button1_Click(object sender, System.EventArgs e)
{
WriteTableHead();
sqlConnection1.Open();
SqlCommand cmd1 = new SqlCommand("select zgm,ssbm,chzh,lanchujine,lclx,dkh,curq from lcdj where zgm='"+ TextBox3.Text +"' and (crrq >= '"+ TextBox1.Text +"') and (crrq <= '"+ TextBox2.Text +"')", sqlConnection1);
SqlDataReader reader1 = cmd1.ExecuteReader();
int rowid = 0;
while(reader1.Read())
{
TableRow r = new TableRow();
// Set bgcolor on alternating rows.
if (rowid%2 == 1)
r.BackColor=System.Drawing.Color.Gainsboro;
for (int i=0; i<7; i++)
{
TableCell c = new TableCell();
switch(i)
{
case 0:
case 1:
case 2:
case 4:
case 5:
case 6:
c.Controls.Add(new LiteralControl(reader1.GetString(i)));
break;
case 3:
c.Controls.Add(new LiteralControl(reader1.GetDecimal(i).ToString()));
break;
/*case 2:
c.Controls.Add(new LiteralControl(reader1.GetDecimal(i).ToString()));
break;
case 3:
c.Controls.Add(new LiteralControl(reader1.GetInt32(i).ToString()));
break;
case 0:
c.Controls.Add(new LiteralControl(reader1.GetDateTime(i).ToString("yyyy-MM-dd")));
break;
case 1:
c.Controls.Add(new LiteralControl(reader1.GetDateTime(i).ToString("HH:mm")));
break;*/
default:
break;
}
r.Cells.Add(c);
}
Table1.Rows.Add(r);
rowid++;
}
}
private void WriteTableHead()
{
TableRow r = new TableRow();
r.BackColor=System.Drawing.Color.BlueViolet;
r.ForeColor=System.Drawing.Color.GreenYellow;
// Set bgcolor on alternating rows.
//if (row%2 == 1)
// r.BackColor=System.Drawing.Color.Gainsboro;
TableCell c1 = new TableCell();
c1.Controls.Add(new LiteralControl("列名"));
r.Cells.Add(c1);
TableCell c2 = new TableCell();
c2.Controls.Add(new LiteralControl("列名"));
r.Cells.Add(c2);
TableCell c3 = new TableCell();
c3.Controls.Add(new LiteralControl("列名"));
r.Cells.Add(c3);
TableCell c4 = new TableCell();
c4.Controls.Add(new LiteralControl("列名"));
r.Cells.Add(c4);
TableCell c5 = new TableCell();
c5.Controls.Add(new LiteralControl("列名"));
r.Cells.Add(c5);
TableCell c6 = new TableCell();
c6.Controls.Add(new LiteralControl("列名"));
r.Cells.Add(c6);
TableCell c7 = new TableCell();
c7.Controls.Add(new LiteralControl("列名"));
r.Cells.Add(c7);
Table1.Rows.Add(r);
}
}
}