1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Web; 5 using System.Web.UI; 6 using System.Web.UI.We ...
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Web; 5 using System.Web.UI; 6 using System.Web.UI.WebControls; 7 using System.Data.SqlClient; 8 using System.Text; 9 using System.Data; 10 using System.IO; 11 12 public partial class ScoreManage : System.Web.UI.Page 13 { 14 protected static PagedDataSource pds = new PagedDataSource();//创建一个分页数据源的对象且一定要声明为静态 15 Access acc = new Access(); 16 public static class uid 17 { 18 public static get='_blank'>string name = ""; 19 public static string Name 20 { 21 get { return name; } 22 } 23 public static string strsysdatetime = ""; 24 public static string Strsysdatetime 25 { 26 get { return strsysdatetime; } 27 } 28 public static int list2 = -1; 29 public static int List2 30 { 31 get { return list2; } 32 } 33 public static DataSet tempst = new DataSet(); 34 public static DataSet Tempst 35 { 36 get { return tempst; } 37 } 38 } 39 protected void Page_Load(object sender, EventArgs e) 40 { 41 if (!Page.IsPostBack) 42 { 43 if (Session["userid"] == null) 44 { 45 Response.Redirect("Default.aspx"); 46 } 47 else 48 { 49 bing(); 50 51 } 52 } 53 } 54 private void bing() 55 { 56 uid.name = Session["userid"].ToString(); 57 subjectlist.Items.Clear(); 58 SqlCommand cm1 = new SqlCommand("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); 59 acc.conn.Open(); 60 SqlDataReader dr1 = cm1.ExecuteReader(); 61 this.subjectlist.DataSource = dr1; 62 this.subjectlist.DataTextField = "sunname"; 63 this.subjectlist.DataValueField = "subid"; 64 this.subjectlist.DataBind(); 65 dr1.Close(); 66 acc.conn.Close(); 67 ListItem it = new ListItem("-----------请选择-----------", "0000"); // 68 69 DropDownList1.Items.Insert(0, it); 70 DropDownList1.Items.Clear(); 71 SqlCommand cm11 = new SqlCommand("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); 72 acc.conn.Open(); 73 SqlDataReader dr11 = cm11.ExecuteReader(); 74 this.DropDownList1.DataSource = dr11; 75 this.DropDownList1.DataTextField = "classname"; 76 this.DropDownList1.DataValueField = "classid"; 77 this.DropDownList1.DataBind(); 78 dr11.Close(); 79 acc.conn.Close(); 80 DropDownList1.Items.Insert(0, it); 81 subjectlist.Items.Insert(0, it); 82 } 83 private void BindDataList(int currentpage) 84 { 85 pds.AllowPaging = true;//允许分页 86 //pds.PageSize = 3;//每页显示3条数据 87 pds.CurrentPageIndex = currentpage;//当前页为传入的一个int型值 88 pds.DataSource = uid.Tempst.Tables[0].DefaultView;//把数据集中的数据放入分页数据源中 89 DataList1.DataSource = pds;//绑定Datalist 90 DataList1.DataBind(); 91 } 92 93 protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e) 94 { 95 switch (e.CommandName) 96 { 97 //以下5个为 捕获用户点击 上一页 下一页等时发生的事件 98 case "first"://第一页 99 pds.CurrentPageIndex = 0;100 BindDataList(pds.CurrentPageIndex);101 break;102 case "pre"://上一页103 pds.CurrentPageIndex = pds.CurrentPageIndex - 1;104 BindDataList(pds.CurrentPageIndex);105 break;106 case "next"://下一页107 pds.CurrentPageIndex = pds.CurrentPageIndex + 1;108 BindDataList(pds.CurrentPageIndex);109 break;110 case "last"://最后一页111 pds.CurrentPageIndex = pds.PageCount - 1;112 BindDataList(pds.CurrentPageIndex);113 break;114 case "search"://页面跳转页115 if (e.Item.ItemType == ListItemType.Footer)116 {117 int PageCount = int.Parse(pds.PageCount.ToString());118 TextBox txtPage = e.Item.FindControl("txtPage") as TextBox;119 int MyPageNum = 0;120 if (!txtPage.Text.Equals(""))121 MyPageNum = Convert.ToInt32(txtPage.Text.ToString());122 if (MyPageNum <= 0 || MyPageNum > PageCount)123 {124 Label3.Text = "请输入页数并确定没有超出总页数!";125 txtPage.Text = "";126 }127 else128 {129 130 BindDataList(MyPageNum - 1);131 }132 }133 break;134 case "size"://显示条数135 if (e.Item.ItemType == ListItemType.Footer)136 {137 int PageSize = int.Parse(pds.PageSize.ToString());138 TextBox txtSize = e.Item.FindControl("txtSize") as TextBox;139 int MySizeNum = 0;140 if (!txtSize.Text.Equals(""))141 MySizeNum = Convert.ToInt32(txtSize.Text.ToString());142 if (MySizeNum <= 0 || MySizeNum > 500)143 {144 Label3.Text = "请输入正确的显示条数最大值为500!";145 txtSize.Text = "";146 }147 else148 {149 pds.PageSize = MySizeNum;150 BindDataList(0);151 }152 153 }154 break;155 }156 }157 protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)158 {159 if (e.Item.ItemType == ListItemType.Footer)160 {161 //以下六个为得到脚模板中的控件,并创建变量.162 Label CurrentPage = e.Item.FindControl("labCurrentPage") as Label;163 Label PageCount = e.Item.FindControl("labPageCount") as Label;164 LinkButton FirstPage = e.Item.FindControl("lnkbtnFirst") as LinkButton;165 LinkButton PrePage = e.Item.FindControl("lnkbtnFront") as LinkButton;166 LinkButton NextPage = e.Item.FindControl("lnkbtnNext") as LinkButton;167 LinkButton LastPage = e.Item.FindControl("lnkbtnLast") as LinkButton;168 CurrentPage.Text = (pds.CurrentPageIndex + 1).ToString();//绑定显示当前页169 PageCount.Text = pds.PageCount.ToString();//绑定显示总页数170 if (pds.IsFirstPage)//如果是第一页,首页和上一页不能用171 {172 FirstPage.Enabled = false;173 PrePage.Enabled = false;174 }175 if (pds.IsLastPage)//如果是最后一页"下一页"和"尾页"按钮不能用176 {177 NextPage.Enabled = false;178 LastPage.Enabled = false;179 }180 }181 }182 public DataSet txtinsql(string str)183 {184 string insertCmd = string.Empty;185 acc.conn.Open();186 StreamReader sr = new StreamReader(new FileStream(str, FileMode.Open, FileAccess.Read), System.Text.Encoding.Default);187 insertCmd = "insert into [I_ImportRecords](studentcode,score,importsign) values (@studentcode,@score,@importsign)";188 char delimChar = ',';189 string[] split = null;190 string strTemp = sr.ReadLine();191 while (strTemp != null)192 {193 split = strTemp.Split(delimChar);194 SqlCommand cmd = new SqlCommand(insertCmd, acc.conn);195 cmd.Parameters.Add("@studentcode", SqlDbType.NChar).Value = split[0];196 cmd.Parameters.Add("@score", SqlDbType.Float).Value = split[1];197 cmd.Parameters.Add("@importsign", SqlDbType.NChar).Value = uid.Strsysdatetime;198 cmd.ExecuteNonQuery();199 strTemp = sr.ReadLine();200 }201 insertCmd = "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 + "'";202 SqlDataAdapter sda = new SqlDataAdapter(insertCmd, acc.conn);203 DataSet ds = new DataSet();204 sda.Fill(ds);205 acc.conn.Close();206 sr.Close();207 sda.Dispose();208 return ds;209 }210 protected void Button1_Click(object sender, EventArgs e)211 {212 if (subjectlist.SelectedValue == "0000" || DropDownList1.SelectedValue == "0000" || FileUpload1.HasFile == false)213 {214 Label3.Text = "科目,班级列表或者文件还未选择.";215 }216 else217 {218 uid.strsysdatetime = DateTime.Now.ToFileTime().ToString() + uid.Name;219 FileUpload1.SaveAs(System.AppDomain.CurrentDomain.BaseDirectory + @"file\" + uid.Strsysdatetime + ".txt");220 uid.tempst = txtinsql(System.AppDomain.CurrentDomain.BaseDirectory + @"file\" + uid.Strsysdatetime + ".txt");221 pds.PageSize = 3;222 BindDataList(0);223 Button2.Enabled = true;224 }225 }226 }
海外公司注册、海外银行开户、跨境平台代入驻、VAT、EPR等知识和在线办理:https://www.xlkjsw.com
原标题:自己代码备份
关键词:
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们:
admin#shaoqun.com
(#换成@)。