(以下源代码不排版)
源代码编译环境:安装visual studio.net 7.0,sqlserver2000
源代码1(前台评测主页面):
//建立数据库连接,取出bigrules表数据放入ds中
sqlconnection conn = new sqlconnection(“server=localhost;uid=sa;pwd=;database=ygpc”;
sqlcommand comm. = new sqlcommand(“select * from bigrules”,conn);
sqldataadapter da = new sqldataadapter(comm);
dataset ds;
da.fill(ds,”bigrules”);
int ntotalbig = ds.tables[“bigrules”].rows.count;
int k = convert.toint32(ds.tables["bigrules"].rows[0]["bigid"].tostring());
for(int ibig=0;k<=convert.toint32(ds.tables["bigrules"].rows[ntotalbig-1]["bigid"].tostring());k=convert.toint32(ds.tables["bigrules"].rows[ibig]["id"].tostring()))
//ibig代表bigrules表中行值,k代表ibig行对应的id值
{
string commtext = "select * from smallrules where bigid="+k+"order by id";
sqlcommand commsmall = new sqlcommand(commtext,conn);
sqldataadapter dasmall = new sqldataadapter(commsmall);
if(ds1!=null) ds1.clear();
ds1 = new dataset();//每次循环都需要更新ds1中记录的细则数据
dasmall.fill(ds1,"smallrules");
int ntotalrows = ds1.tables["smallrules"].rows.count;
int i=convert.toint32(ds1.tables["smallrules"].rows[0]["id"].tostring());
string str = "select * from score where
_testpersonid="+testid+"and testedpersonid="+testedid+"and month="+curmon+" and smallid="+i;
//判断当前被测员工当月是否已有过成绩,即检查score表中是否有与testedid, testid,curmon相符
//的记录,判断结果为true或false存入hidtested隐藏控件中,
// 在显示”黄框”以往成绩时起到作用,略
for(int z=0;i<=convert.toint32(ds1.tables["smallrules"]
_.rows[ntotalrows-1][“id”].tostring());
i=convert.toint32(ds1.tables[“smallrules”].rows[z][“id”].tostring()))
//z代表smallrules中的行值,i代表z行的id值,需要找出i值对应的score表的"成绩"值
{
htmltablerow tr = new htmltablerow();
array.setvalue(indexpagerow++,i);
//array为静态数组,记录每个i值在页面上的对应行,
// 因为各项评测smallrules经过后台不断的增,删,改,其id值与页面上的行并不对应
for(int j=0;j<ds1.tables["smallrules"].columns.count;j++)
{
htmltablecell tc = new htmltablecell();
if(j==0)//当前范围的零行零列
{
if(i == convert.toint32(ds1.tables["smallrules"].rows[0]["id"].tostring()))
{
//最左的细则分类列,注意从bigrules表中取数据
tc.innerhtml = s.tables["bigrules"].rows[ibig][j+1].tostring()+
_ds.tables["bigrules"].rows[ibig]["totalscore"].tostring()+"分";
}
tr.cells.add(tc);
}
else //不是最左列
{
if(j!=ds1.tables["smallrules"].columns.count-1)//判断是否最右列
{
tc.innerhtml = ds1.tables["smallrules"].rows[z][j].tostring();
}
else
{
//最右的成绩分值列
if(hidtested.value==”true”)
//最后一个cell列含两个textbox列,显示上次评测的成绩
{
textbox box1= new textbox();
box1.width = 30;
//找出i值对应的score表中的成绩放入ds2
box1.text = ds2.tables["score"].rows[0]["score"].tostring();
box1.readonly = true;
box1.backcolor = system.drawing.color.beige;
tc.controls.add(box1);
}
textbox box = new textbox();
if(hidtested.value == "false")
box.width = 60;
else
box.width = 30;
box.attributes["onblur"]="javascript:onchange("+ds1.tables[
"smallrules"].rows[z][j-1].tostring()+",this)";
//javascript控制用户评测分数在该项分值之内,
//ds1.tables["smallrules"].rows[z][j-1].tostring()
//传给onchange函数该项评测细则分值
}
tr.cells.add(tc);//将htmltablecell对象存入htmltablerow对象中
}
}
t.rows.add(tr);//一行数据完成,加入到htmltable的rows集合中
z++;
}//一个细则分类的所有评测细则完成
ibig++;
}//下一个细则分类,如由”遵守制度”到”专业技能”
其中嵌入的javascript语句的onchange()函数在html页面中head部分实现如下:
<script language=”javascript”>
function onchange(maxvalue,obj)
{
//maxvalue为该项细则的分值,obj为该项得分,是object型
parseint(obj.value,10); parseint(maxvalue,10);
if(!isnan(obj.value)) //判断是否自然数
if(obj.value>maxvalue) //值超过范围
{
alert('值超过范围') obj.focus();}
else {}
else //值非法
{
alert('值非法') obj.focus();}
</script>
源代码2(评测结果页面,以一个datagrid为例):
datatable table1 = ds.tables.add("score");//ds,ds1为两个dataset型数据集
table1.columns.add("smallid",typeof(int));//细则id列
table1.columns.add("realname", typeof(string));//测评人姓名
table1.columns.add("score", typeof(int));//该项细则得分
string commtext = "select smallid,realname,score from score, employee where score.testpersonid="+testid+"and score.testedpersonid="+testedid+"and score.month="+curmon+"order by score.smallid";
//其中testid,testedid为页面进入时从前一页面记录的测评人id和被评人id值
sqlconnection conn = new sqlconnection(“server=localhost;uid=sa;pwd=;database=ygpc”;
conn.open();
sqlcommand comm= new sqlcommand(commtext,conn);
sqldatareader reader = com1.executereader();
int ncolcount= table1.columns.count;
while(reader.read())
{
system.data.datarow row = table1.newrow();
for(int i=0;i<ncolcount;i++)
{
row[i]=reader[i];
}
table1.rows.add(row);
}
datagrid1.datasource=ds.tables["score"].defaultview;
datagrid1.datamember =ds.tables["employee"].tablename;
datagrid1.databind();
//使用datasource和datamember就能在一个datagrid控件中显示来自两个表的信息
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器