protected void btnAddLost_Click(object sender, EventArgs e) { int roleID = Convert.ToInt32(ddlUserRole.SelectedItem.Value.Trim()); string roleName = ddlUserRole.SelectedItem.Text.Trim(); string source = this.FileUpload1.PostedFile.FileName; string getExtension = System.IO.Path.GetExtension(source); if (source == String.Empty || getExtension != ".xls") { this.Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('请选择Excel文件!');</script>"); return; } else { if (roleName == "管理员") { int num = adminManage.AddAdmins(source, roleID); if (num > 0) { this.Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('添加成功!');</script>"); } else { this.Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('添加失败!原因可能为:您添加的用户已存在');</script>"); } } else if (roleName == "学生") { int num = studentManage.AddStudents(source, roleID); if (num > 0) { this.Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('添加成功!');</script>"); } else { this.Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('添加失败!原因可能为:您添加的用户已存在');</script>"); } } else if (roleName == "教师") { int num = teacherManage.AddTeachers(source, roleID); if (num > 0) { this.Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('添加成功!');</script>"); } else { this.Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('添加失败!原因可能为:您添加的用户已存在');</script>"); } } } }