当前位置:编程学习 > C#/ASP.NET >>

ASP.NET开发员工业绩评测中心(3)

答案:     (以下源代码不排版)
  
    源代码编译环境:安装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控件中显示来自两个表的信息
  
  
  

上一个:ASP.NET开发员工业绩评测中心(2)
下一个:如何控制DataGrid里的内容换行与不换行?

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,