public void SetBind() { DataTable dt = new DataTable(); DataTable rt = new AdminsManage().QueryAdmins(); dt.Columns.Add("AdminID", typeof(Int32)); dt.Columns.Add("AdminName", typeof(string)); dt.Columns.Add("Level", typeof(bool)); dt.Columns.Add("IsDeleted", typeof(bool)); dt.Columns.Add("Deletable", typeof(bool)); for (int i = 0; i < rt.Rows.Count; i++) { dt.Rows.Add(); dt.Rows[i]["AdminID"] = rt.Rows[i]["AdminID"].ToString(); dt.Rows[i]["AdminName"] = rt.Rows[i]["AdminName"].ToString(); dt.Rows[i]["Level"] = rt.Rows[i]["Level"].ToString(); dt.Rows[i]["IsDeleted"] = rt.Rows[i]["IsDeleted"].ToString(); if (rt.Rows[i]["AdminName"].ToString() == username || rt.Rows[i]["IsDeleted"].ToString() == "True") dt.Rows[i]["Deletable"] = false; else { dt.Rows[i]["Deletable"] = Int32.Parse(rt.Rows[i]["AdminID"].ToString()) == 1 ? false : true; } } AdminsRepeater.DataSource = dt; AdminsRepeater.DataBind(); }
protected void Delete_Command(object sender, CommandEventArgs e) { string aid = e.CommandArgument.ToString(); bool i = new AdminsManage().DeleteAdmin(aid); if (i == true) Response.Write("<script language=javascript>alert('删除成功!')</script>"); else Response.Write("<script language=javascript>alert('删除失败!')</script>"); SetBind(); }
protected void Confirm_Click(object sender, EventArgs e) { string newName = Name.Text.Trim(); string newPwd = Pwd.Text.Trim(); newPwd = new GetMD5().GetValue(newPwd); bool i = new AdminsManage().CreateAdmin(newName, newPwd); if (i == true) Response.Write("<script language=javascript>alert('成功!')</script>"); else Response.Write("<script language=javascript>alert('失败!')</script>"); }
protected void LoginClick_Click(object sender, EventArgs e) { string name = Name.Text.Trim(); string pwd = Pwd.Text.Trim(); bool i = new AdminsManage().LoginCheck(name, pwd); if (i == false) { Response.Write("<script language=javascript>alert('登录失败,请检查后重试!')</script>"); } else { Page.Session["admin"] = name; Response.Redirect("Manage.aspx"); } }
protected void Page_Load(object sender, EventArgs e) { try { string username = Session["admin"].ToString(); bool i = new AdminsManage().CheckLevel(username); if (i != false) Manage0.Attributes.Add("style", "display:none;"); else Manage0.Visible = true; } catch { Response.Redirect("Login.aspx"); } }
protected void Page_Load(object sender, EventArgs e) { try { string username = Session["admin"].ToString(); bool i = new AdminsManage().CheckLevel(username); if (i != false) form1.Visible = false; else form1.Visible = true; } catch { Response.Redirect("Login.aspx"); } SetBind(); }
void EntityDataSource() { AdminsManage am = new AdminsManage(); var dt = am.SelectAll();// 获取数据库中所有数据 // 清除数据源 DataSource.Rows.Clear(); for (int i = 0; i < dt.Rows.Count; i++) { DataRow row = DataSource.NewRow(); row["编号"] = dt.Rows[i]["adminId"]; row["名称"] = dt.Rows[i]["name"]; row["编号"] = dt.Rows[i]["cellphone"]; DataSource.Rows.Add(row); } gvwRoleBind(); }
protected void Button1_Click(object sender, EventArgs e) { #region 验证文件 if (string.IsNullOrEmpty(fudExcel.FileName)) { Response.Write("请选择上传文件!"); return; } string extension = fudExcel.FileName.Substring(fudExcel.FileName.LastIndexOf('.')); if (extension == ".xlsx") { Response.Write("目前模板只支持Excel2003版文件,请转换后再导入!"); return; } if (extension != ".xls") { Response.Write("上传文件扩展必须是(xls/xlsx)文件!"); return; } #endregion string filepath = string.Empty; // 上传到服务器临时目录下 string tempdir = Server.MapPath("upload/"); string filename = Guid.NewGuid() + extension; filepath = tempdir + filename; // 保存 fudExcel.SaveAs(filepath); bool existsSheetname = false; // 读取到DataTable var data = ExcelDataSource(filepath, ref existsSheetname); if (!existsSheetname) { Response.Write("没有找到《模板工作表》工作表!"); return; } // 删除临时文件 System.IO.File.Delete(filepath); if (data == null) { Response.Write("解析Excel失败,请检查Excel是否符合模板要求!"); return; } foreach (DataRow row in data.Rows) { string id = row["编号"].ToString(); var arrRow = DataSource.Select("编号='" + id + "'"); if (arrRow != null && arrRow.Length > 0) { } else { DataRow newrow = DataSource.NewRow(); newrow["编号"] = row["编号"]; newrow["名称"] = row["名称"]; newrow["备注"] = row["备注"]; AdminsManage am = new AdminsManage(); admins n = new admins(); n.AdminId = newrow["编号"].ToString(); n.Name = newrow["名称"].ToString(); n.Cellphone = newrow["备注"].ToString(); n.Creater = "120"; n.Email = "fefefe"; n.Pwd = "111"; am.Insert(n); DataSource.Rows.Add(newrow); } } gvwRoleBind(); }
protected void ImageButton1_Click(object sender, ImageClickEventArgs e) { if (DropDownList1.SelectedValue == "admin") { AdminsManage am = new AdminsManage(); bool n = am.Login(txtName.Text.Trim(), txtPwd.Text.Trim()); int tmp = String.Compare(Request.Cookies["CheckCode"].Value, TextBox1.Text.Trim(), true); if (n && tmp == 0) { Session["adminId"] = txtName.Text.Trim(); Response.Redirect("admin/adminDefault.aspx"); } else if (tmp != 0) { Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('登陆失败,验证码错误!');</script>"); } else { Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('登陆失败,用户名或者密码错误!');</script>"); } } if (DropDownList1.SelectedValue == "teacher") { TeachersManage tm = new TeachersManage(); bool n = tm.Login(txtName.Text.Trim(), txtPwd.Text.Trim()); int tmp = String.Compare(Request.Cookies["CheckCode"].Value, TextBox1.Text.Trim(), true); if (n && tmp == 0) { Session["teacherId"] = txtName.Text.Trim(); Response.Redirect("teacher/teaDefault.aspx"); } else if (tmp != 0) { Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('登陆失败,验证码错误!');</script>"); } else { Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('登陆失败,用户名或者密码错误!');</script>"); } } if (DropDownList1.SelectedValue == "student") { StudentsManage sm = new StudentsManage(); bool n = sm.Login(txtName.Text.Trim(), txtPwd.Text.Trim()); int tmp = String.Compare(Request.Cookies["CheckCode"].Value, TextBox1.Text.Trim(), true); if (n && tmp == 0) { Session["studentId"] = txtName.Text.Trim(); Response.Redirect("student/stuDefault.aspx"); } else if (tmp != 0) { Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('登陆失败,验证码错误!');</script>"); } else { Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('登陆失败,用户名或者密码错误!');</script>"); } } this.txtName.Text = ""; this.TextBox1.Text = ""; }