📄 createstudents.ascx.cs
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using TeachHelper.BusinessLogicLayer;
using TeachHelper.Comm;
public partial class TeachHelper_Controls_CreateStudents : System.Web.UI.UserControl
{
#region 事件处理
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindYears();
BindClasses();
DataSet ds = Department.GetCollect();
this.DropDownListDepartment.DataSource = ds;
this.DropDownListDepartment.DataTextField = "Name";
this.DropDownListDepartment.DataValueField = "Id";
this.DropDownListDepartment.DataBind();
DropDownListDepartment_SelectedIndexChanged(DropDownListDepartment, null);
}
}
protected void DropDownListDepartment_SelectedIndexChanged(object sender, EventArgs e)
{
int departmentId = Convert.ToInt32(((DropDownList)(sender)).SelectedValue);
DataSet ds = Major.GetCollectByDepartmentId(departmentId);
this.DropDownListMajor.DataSource = ds;
this.DropDownListMajor.DataTextField = "Name";
this.DropDownListMajor.DataValueField = "Id";
this.DropDownListMajor.DataBind();
}
protected void ButtonMakeStudentId_Click(object sender, EventArgs e)
{
string year = this.DropDownListYears.SelectedValue;
string department = Convert.ToInt32(this.DropDownListDepartment.SelectedValue).ToString("000");
string major = Convert.ToInt32(this.DropDownListMajor.SelectedValue).ToString("000");
string classes = Convert.ToInt32(this.DropDownListClass.SelectedValue).ToString("000");
string studentId = string.Format("{0}{1}{2}{3}{4}", year, department, major, classes, "***");
this.LabelStudentId.Text = studentId;
this.ButtonFinish.Enabled = true;
}
protected void ButtonFinish_Click(object sender, EventArgs e)
{
this.LabelCreateStatus.Text = string.Empty;
CreateStudentUser();
}
#endregion
#region 私有 & 保护方法
private void CreateStudentUser()
{
int beginSeat = Convert.ToInt32(this.TextBoxBeginSeat.Text.Trim());
int endSeat = Convert.ToInt32(this.TextBoxEndSeat.Text.Trim());
string year = this.DropDownListYears.SelectedValue;
string department = Convert.ToInt32(this.DropDownListDepartment.SelectedValue).ToString("000");
string major = Convert.ToInt32(this.DropDownListMajor.SelectedValue).ToString("000");
string classes = Convert.ToInt32(this.DropDownListClass.SelectedValue).ToString("000");
string studentId = string.Format("{0}{1}{2}{3}", year, department, major, classes);
string seat = String.Empty;
string username = String.Empty;
string password = this.TextBoxPassword.Text;
string email = String.Empty;
string passwordQuestion = this.TextBoxPasswordQuestion.Text;
string passwordAnswer = this.TextBoxPasswordAnswer.Text;
MembershipCreateStatus status = new MembershipCreateStatus();
for (int i = beginSeat; i <= endSeat; i++)
{
seat = i.ToString("000");
username = studentId + seat;
email = username + @"@gdqy.edu.cn";
try
{
Membership.CreateUser(username, password, email, passwordQuestion, passwordAnswer, true, out status);
this.LabelCreateStatus.Text = "创建成功!";
Roles.AddUserToRole(username, "学生");
}
catch (Exception ex)
{
this.LabelCreateStatus.Text = "创建失败!";
}
}
}
private void BindYears()
{
List<int> listYears = OtherData.Years();
this.DropDownListYears.DataSource = listYears;
this.DropDownListYears.DataBind();
}
private void BindClasses()
{
List<int> listClasses = OtherData.Classes();
this.DropDownListClass.DataSource = listClasses;
this.DropDownListClass.DataBind();
}
#endregion
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -