[flash=500,400]http://s1.knowsky.com/20160211/ww5xeweh1xd15.gif[/flash][flash=500,400]http://s1.knowsky.com/20160211/m13nnet54gm15.gif[/flash]1usingSystem;2usingSystem.Collections.Generic;3usingSystem.Linq;4usingSystem.Web;5usingSystem.Web.UI;6usingSystem.Web.UI.WebControls;7usingSystem.Data.SqlClient;8usingSystem.Text;9usingSystem.Data;10usingSystem.IO;1112publicpartialclassScoreManage : System.Web.UI.Page13{14PRotectedstaticPagedDataSource pds =newPagedDataSource();//创建一个分页数据源的对象且一定要声明为静态15accessacc =newAccess();16publicstaticclassuid17{18publicstaticstringname ="";19publicstaticstringName20{21get{returnname; }22}23publicstaticstringstrsysdatetime ="";24publicstaticstringStrsysdatetime25{26get{returnstrsysdatetime; }27}28publicstaticintlist2 = -1;29publicstaticintList230{31get{returnlist2; }32}33publicstaticDataSet tempst =newDataSet();34publicstaticDataSet Tempst35{36get{returntempst; }37}38}39protectedvoidPage_Load(objectsender, EventArgs e)40{41if(!Page.IsPostBack)42{43if(session["userid"] ==null)44{45Response.Redirect("Default.aspx");46}47else48{49bing();5051}52}53}54privatevoidbing()55{56uid.name = Session["userid"].ToString();57subjectlist.Items.Clear();58SqlCommand cm1 =newSqlCommand("select REPLACE(t.positionname+a.subjectname,'老师','--') as sunname,a.ID as subid from P_Position t,S_SubjectRel a,UP_UserPosRel b where a.teacherid = t.id and b.pos_id = t.id and b.user_id ="+ uid.Name +"", acc.conn);59acc.conn.Open();60SqlDataReader dr1 =cm1.ExecuteReader();61this.subjectlist.DataSource =dr1;62this.subjectlist.DataTextField ="sunname";63this.subjectlist.DataValueField ="subid";64this.subjectlist.DataBind();65dr1.Close();66acc.conn.Close();67ListItem it =newListItem("-----------请选择-----------","0000");//6869DropDownList1.Items.Insert(0, it);70DropDownList1.Items.Clear();71SqlCommand cm11 =newSqlCommand("select b.id as classid,b.classname as classname from UC_UserClassRel a ,C_Class b where a.class_id = b.id and a.user_id ="+ uid.Name +"", acc.conn);72acc.conn.Open();73SqlDataReader dr11 =cm11.ExecuteReader();74this.DropDownList1.DataSource =dr11;75this.DropDownList1.DataTextField ="classname";76this.DropDownList1.DataValueField ="classid";77this.DropDownList1.DataBind();78dr11.Close();79acc.conn.Close();80DropDownList1.Items.Insert(0, it);81subjectlist.Items.Insert(0, it);82}83privatevoidBindDataList(intcurrentpage)84{85pds.AllowPaging =true;//允许分页86//pds.PageSize = 3;//每页显示3条数据87pds.CurrentPageIndex = currentpage;//当前页为传入的一个int型值88pds.DataSource = uid.Tempst.Tables[0].DefaultView;//把数据集中的数据放入分页数据源中89DataList1.DataSource = pds;//绑定Datalist90DataList1.DataBind();91}9293protectedvoidDataList1_ItemCommand(objectsource, DataListCommandEventArgs e)94{95switch(e.CommandName)96{97//以下5个为 捕获用户点击 上一页 下一页等时发生的事件98case"first"://第一页99pds.CurrentPageIndex =0;100BindDataList(pds.CurrentPageIndex);101
break;102case"pre"://上一页103pds.CurrentPageIndex = pds.CurrentPageIndex -1;104BindDataList(pds.CurrentPageIndex);105
break;106case"next"://下一页107pds.CurrentPageIndex = pds.CurrentPageIndex +1;108BindDataList(pds.CurrentPageIndex);109
break;110case"last"://最后一页111pds.CurrentPageIndex = pds.PageCount -1;112BindDataList(pds.CurrentPageIndex);113
break;114case"search"://页面跳转页115if(e.Item.ItemType ==ListItemType.Footer)116{117intPageCount =int.Parse(pds.PageCount.ToString());118TextBox txtPage = e.Item.FindControl("txtPage")asTextBox;119intMyPageNum =0;120if(!txtPage.Text.Equals(""))121MyPageNum =Convert.ToInt32(txtPage.Text.ToString());122if(MyPageNum <=0|| MyPageNum >PageCount)123{124Label3.Text ="请输入页数并确定没有超出总页数!";125txtPage.Text ="";126}127else128{129130BindDataList(MyPageNum -1);131}132}133
break;134case"size"://显示条数135if(e.Item.ItemType ==ListItemType.Footer)136{137intPageSize =int.Parse(pds.PageSize.ToString());138TextBox txtSize = e.Item.FindControl("txtSize")asTextBox;139intMySizeNum =0;140if(!txtSize.Text.Equals(""))141MySizeNum =Convert.ToInt32(txtSize.Text.ToString());142if(MySizeNum <=0|| MySizeNum >500)143{144Label3.Text ="请输入正确的显示条数最大值为500!";145txtSize.Text ="";146}147else148{149pds.PageSize =MySizeNum;150BindDataList(0);151}152153}154
break;155}156}157protectedvoidDataList1_ItemDataBound(objectsender, DataListItemEventArgs e)158{159if(e.Item.ItemType ==ListItemType.Footer)160{161//以下六个为得到脚模板中的控件,并创建变量.162Label CurrentPage = e.Item.FindControl("labCurrentPage")asLabel;163Label PageCount = e.Item.FindControl("labPageCount")asLabel;164LinkButton FirstPage = e.Item.FindControl("lnkbtnFirst")asLinkButton;165LinkButton PrePage = e.Item.FindControl("lnkbtnFront")asLinkButton;166LinkButton NextPage = e.Item.FindControl("lnkbtnNext")asLinkButton;167LinkButton LastPage = e.Item.FindControl("lnkbtnLast")asLinkButton;168CurrentPage.Text = (pds.CurrentPageIndex +1).ToString();//绑定显示当前页169PageCount.Text = pds.PageCount.ToString();//绑定显示总页数170if(pds.IsFirstPage)//如果是第一页,首页和上一页不能用171{172FirstPage.Enabled =false;173PrePage.Enabled =false;174}175if(pds.IsLastPage)//如果是最后一页"下一页"和"尾页"按钮不能用176{177NextPage.Enabled =false;178LastPage.Enabled =false;179}180}181}182publicDataSet txtinsql(stringstr)183{184stringinsertCmd =string.Empty;185acc.conn.Open();186StreamReader sr =newStreamReader(newFileStream(str, FileMode.Open, FileAccess.Read), System.Text.Encoding.Default);187insertCmd ="insert into [I_ImportRecords](studentcode,score,importsign) values (@studentcode,@score,@importsign)";188chardelimChar =',';189string[] split =null;190stringstrTemp =sr.ReadLine();191while(strTemp !=null)192{193split =strTemp.Split(delimChar);194SqlCommand cmd =newSqlCommand(insertCmd, acc.conn);195cmd.Parameters.Add("@studentcode", SqlDbType.NChar).Value = split[0];196cmd.Parameters.Add("@score", SqlDbType.Float).Value = split[1];197cmd.Parameters.Add("@importsign", SqlDbType.NChar).Value =uid.Strsysdatetime;198cmd.ExecuteNonQuery();199strTemp =sr.ReadLine();200}201insertCmd ="select s.ID as studentid,s.Student_Code as studentcode,s.Student_Name as studentname,c.classname as classname,tt.score as score from [I_ImportRecords] tt, S_Student s,C_Class c,SC_StudentClassRel sc where s.ID = sc.student_id and sc.class_id = c.id and tt.studentcode = s.Student_Code and importsign = '"+ uid.Strsysdatetime +"'";202SqlDataAdapter sda =newSqlDataAdapter(insertCmd, acc.conn);203DataSet ds =newDataSet();204sda.Fill(ds);205acc.conn.Close();206sr.Close();207sda.Dispose();208returnds;209}210protectedvoidButton1_Click(objectsender, EventArgs e)211{212if(subjectlist.SelectedValue =="0000"|| DropDownList1.SelectedValue =="0000"|| FileUpload1.HasFile ==false)213{214Label3.Text ="科目,班级列表或者文件还未选择.";215}216else217{218uid.strsysdatetime = DateTime.Now.ToFileTime().ToString() +uid.Name;219FileUpload1.SaveAs(System.AppDomain.CurrentDomain.BaseDirectory +@"file\"+ uid.Strsysdatetime +".txt");220uid.tempst = txtinsql(System.AppDomain.CurrentDomain.BaseDirectory +@"file\"+ uid.Strsysdatetime +".txt");221pds.PageSize =3;222BindDataList(0);223Button2.Enabled =true;224}225}226}
ScoreManage.aspx
[flash=500,400]http://s1.knowsky.com/20160211/ww5xeweh1xd15.gif[/flash][flash=500,400]http://s1.knowsky.com/20160211/m13nnet54gm15.gif[/flash]1<%@ Page Language="C#"AutoEventWireup="true"CodeFile="ScoreManage.aspx.cs"Inherits="ScoreManage"%>23<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">45<htmlxmlns="http://www.w3.org/1999/xhtml">6<headrunat="server">7<title></title>8<linkrel="stylesheet"type="text/CSS"href="StyleSheet.css"/>9</head>10<body>11<formid="form2"runat="server">12<divclass="ifarmdiv">13<asp:PanelID="Panel1"runat="server"GroupingText="成绩录入"ForeColor="#0076C8"style="COLOR: #0076C8; BACKGROUND-COLOR: #F4FAFF;"Font-Size="12pt">14<tablewidth= "790px"border="0"cellpadding="3"style="background-color: #b9d8f3; text-align:center;">15<trstyle="text-align: center; COLOR: #0076C8; BACKGROUND-COLOR: #F4FAFF; font-weight: bold"><tdstyle="width:395px"><asp:labelID="Label1"runat="server"text="科目:"Font-Size="12pt"></asp:label>16<asp:DropDownListID="subjectlist"runat="server"></asp:DropDownList></td>17<tdstyle="width:395px"><asp:labelID="Label2"runat="server"text="班级:"Font-Size="12pt"></asp:label>18<asp:DropDownListID="DropDownList1"runat="server">19<asp:ListItemValue="3">33</asp:ListItem>20<asp:ListItem>12</asp:ListItem>21<asp:ListItem>33</asp:ListItem>22<asp:ListItemValue="33"></asp:ListItem>23</asp:DropDownList></td></tr>24<trstyle="text-align: center; COLOR: #0076C8; BACKGROUND-COLOR: #F4FAFF; font-weight: bold"><tdstyle="width:395px"><asp:FileUploadID="FileUpload1"runat="server"25/><asp:ButtonID="Button1"runat="server"Text="预览"26onclick="Button1_Click"/></td><tdstyle="width:395px"><asp:ButtonID="Button2"27runat="server"Text="确认导入"Enabled="False"/>28</td></tr>29</table>30<tableborder="0"cellpadding="0"31style="width:790px">32<tr>33<tdstyle="text-align:center">34<asp:DataListID="DataList1"runat="server"35Width="785px"onitemcommand="DataList1_ItemCommand"36onitemdatabound="DataList1_ItemDataBound"BackColor="LightGoldenrodYellow"37BorderColor="Tan"BorderWidth="1px"CellPadding="2"ForeColor="Black"Font-Size="12pt">38<HeaderTemplate>39<table>40<tr>41<tdstyle=" width:100px">学生ID</td>42<tdstyle=" width:185px">学号</td>43<tdstyle=" width:210px">班级</td>44<tdstyle=" width:210px">姓名</td>45<tdstyle=" width:80px">成绩</td>46</tr>47</table>48</HeaderTemplate>49<HeaderStyleBackColor="Tan"Font-Bold="True"/>50<ItemTemplate>51<table>52<tronmouSEOver="backcolor=this.style.backgroundColor;this.style.backgroundColor='#6699ff'"onmouseout="this.style.backgroundColor=backcolor">53<tdstyle=" width:100px"><%#Eval("studentid")%></td>54<tdstyle=" width:185px"><%#Eval("studentcode")%></td>55<tdstyle=" width:210px"><%#Eval("classname")%></td>56<tdstyle=" width:210px"><%#Eval("studentname")%></td>57<tdstyle=" width:80px"><%#Eval("score")%></td>58</tr>59</table>60</ItemTemplate>6162<AlternatingItemStyleBackColor="PaleGoldenrod"/>63<FooterStyleBackColor="Tan"/>6465<FooterTemplate>66<divstyle="text-align:center">67<tableid="Page"cellpadding="0"68style="font-size: 12px; width:780px">69<tr>70<td>71<asp:LabelID="labCurrentPage"runat="server"></asp:Label>/72<asp:LabelID="labPageCount"runat="server"></asp:Label>73<asp:LinkButtonID="lnkbtnFirst"runat="server"CommandName="first"Font-Underline="False"74ForeColor="Black">首页</asp:LinkButton>75<asp:LinkButtonID="lnkbtnFront"runat="server"CommandName="pre"Font-Underline="False"76ForeColor="Black">上一页</asp:LinkButton>77<asp:LinkButtonID="lnkbtnNext"runat="server"CommandName="next"Font-Underline="False"78ForeColor="Black">下一页</asp:LinkButton>79<asp:LinkButtonID="lnkbtnLast"runat="server"CommandName="last"Font-Underline="False"80ForeColor="Black">尾页</asp:LinkButton>81 跳转至:<asp:TextBoxID="txtPage"runat="server"Width="35px"Height="21px"></asp:TextBox>82<asp:ButtonID="Button1"runat="server"CommandName="search"Text="GO"83Height="19px"/>84 每页显示条数:<asp:TextBoxID="txtSize"runat="server"Width="35px"Height="21px"></asp:TextBox>85<asp:ButtonID="Button3"runat="server"CommandName="size"Text="GO"86Height="19px"/>87</td>88</tr>89</table>90</div>91</FooterTemplate>9293<SelectedItemStyleBackColor="DarkSlateBlue"ForeColor="GhostWhite"/>9495</asp:DataList>96</td>97</tr>98<tr><td><asp:LabelID="Label3"runat="server"ForeColor="Red"></asp:Label>99</td></tr>100</table>101102</asp:Panel>103</div>104</form>105</body>106</html>
ScoreManage.aspx