c#写的学生管理系统的心得1

来源:互联网 发布:linux如何压缩文件 编辑:程序博客网 时间:2024/05/17 18:28

1.html文件中引入另一个html文件,用 #parse("../include/header.htm"),最好不要用<iframe  scrolling="no" marginwidth="0" marginheight="0" width="100%" height="50" src="/include/header.htm" frameborder="0"></iframe>这种形式的

2.需要连接数据库和导入sqlhelper(数据库里边的一些方法)和引用Nvelocity(渲染html页面)

连接数据库需要在web.config中配置:

<connectionStrings>
    <add name="connstr" connectionString="Data Source=.;Initial Catalog=stuentsystem;User Id=sa;Password=136156a;"/>        --stuentsystem数据库名称
  </connectionStrings>

3.可以往Data存多个数据:

                    DataTable dt = SqlHelper.ExecuteDataTable("select * from class where CLASS_ID=@CLASS_ID", new SqlParameter("@CLASS_ID", id));
                    DataTable dts = SqlHelper.ExecuteDataTable("select * from teacher");
                    var Data = new { team = dt.Rows[0], teachers=dts.Rows};
                    string html = CommonHelper.RenderHtml("editteam.html", Data);
                    context.Response.Write(html);

相应的前台可以通过$Data.team和$Data.teachers调用

4.比如班级(班级表中)里边得到所有的班主任老师名称(在另一个数据表teacher中)  添加页面

相当于遍历老师表:

前台:<td>
                <select name="teacher">    
                <option>请选择</option>
                   #foreach($p in $Data.teachers)                 
                  <option value="$p.TEACHER_ID">$p.NAME</option>     
                  #end                        
                </select>
              </td>

后台(需要得到teachers):

              DataTable dt = SqlHelper.ExecuteDataTable("select * from teacher");
                var Data = new { teachers = dt.Rows };
                string html = CommonHelper.RenderHtml("addteam.html", Data);
                context.Response.Write(html);

5.编辑页面    显示已经选择的老师名称,并且遍历

前台:

           <tr>
              <td>班主任老师</td>
              <td>
                <select name="teacher">
                 #foreach($p in $Data.teachers)
                        #if($Data.team.TEACHER_ID == $p.TEACHER_ID)        --班级里的老师ID和教师表里的id一致的时候,显示老师名称;否则显示所有的老师名称
                        <option value="$p.TEACHER_ID" selected="selected">$p.NAME</option>
                        #else
                        <option value="$p.TEACHER_ID">$p.NAME</option>
                        #end
                 #end            
                </select>
              </td>
            </tr>

后台:需要得到当前编辑的班级和教师列表

                  DataTable dt = SqlHelper.ExecuteDataTable("select * from class where CLASS_ID=@CLASS_ID", new SqlParameter("@CLASS_ID", id));
                    DataTable dts = SqlHelper.ExecuteDataTable("select * from teacher");
                    var Data = new { team = dt.Rows[0], teachers=dts.Rows};
                    string html = CommonHelper.RenderHtml("editteam.html", Data);
                    context.Response.Write(html);

6.模糊查询:

 DataTable dt = SqlHelper.ExecuteDataTable("select * from class_teacher where C_NAMElike @C_NAME", new SqlParameter("@C_NAME", "%" + searchText + "%"));                                                                                                                                                                                                     --searchText为输入框的name


好了,现在就这么多吧,别的问题暂时还没怎么遇到呢

0 0