protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (Session["DoctorGUID"] == null) { Util.ShowMessage("用户登录超时,请重新登录!", "Login.aspx"); Response.End(); } else { using (SqlConnection conn = new DB().GetConnection()) { string sql = "Select * from Department order by ID asc"; SqlCommand cmd = new SqlCommand(sql, conn); conn.Open(); SqlDataReader rd = cmd.ExecuteReader(); DepartmentDDL.DataSource = rd; DepartmentDDL.DataTextField = "Department"; DepartmentDDL.DataValueField = "GUID"; DepartmentDDL.DataBind(); rd.Close(); DepartmentDDL.Items.Insert(0, new ListItem(" ", "-1")); } } } }
protected void Page_Init(object sender, EventArgs e) { using (WebhostEntities db = new WebhostEntities()) { int id = ((BasePage)Page).user.ID; Faculty faculty = db.Faculties.Where(fac => fac.ID == id).Single(); List <int> depts = faculty.Departments.Select(d => d.id).ToList(); DepartmentDDL.DataSource = DepartmentListItem.GetDataSource(depts); DepartmentDDL.DataTextField = "Text"; DepartmentDDL.DataValueField = "ID"; DepartmentDDL.DataBind(); } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (Session["DoctorGUID"] == null) { Util.ShowMessage("用户登录超时,请重新登录!", "Login.aspx"); Response.End(); } else { DoctorGUID.Text = Convert.ToString(Session["DoctorGUID"]); if (Request.QueryString["GUID"] != null) { DoctorGUID.Text = Request.QueryString["GUID"].ToString(); } using (SqlConnection conn = new DB().GetConnection()) { string sql = "Select * from Department order by ID asc"; SqlCommand cmd = new SqlCommand(sql, conn); conn.Open(); SqlDataReader rd = cmd.ExecuteReader(); DepartmentDDL.DataSource = rd; DepartmentDDL.DataTextField = "Department"; DepartmentDDL.DataValueField = "GUID"; DepartmentDDL.DataBind(); rd.Close(); cmd.CommandText = "select * from Doctor where GUID=@DoctorGUID"; cmd.Parameters.AddWithValue("@DoctorGUID", DoctorGUID.Text); rd = cmd.ExecuteReader(); string IsAdmin = ""; if (rd.Read()) { DoctorName.Text = rd["DoctorName"].ToString(); IDCard.Text = Util.AESDecrypt(rd["IDCard"].ToString()); IsAdmin = Util.AESDecrypt(rd["IsAdmin"].ToString()); if (IDCard.Text.Length > 3) { IDC.Text = IDCard.Text.Substring(0, 3) + "**********"; } else { IDC.Text = "**********"; } if (IsAdmin == "True") { UpdateBtn.Visible = true; RolePanel.Visible = true; Role2.Checked = true; } else { UpdateBtn.Visible = false; RolePanel.Visible = false; Role1.Checked = true; } Phone.Text = rd["Phone"].ToString(); EmployeeNum.Text = rd["EmployeeNum"].ToString(); string DepartmentGUID = rd["DepartmentGUID"].ToString(); if (DepartmentDDL.Items.FindByValue(DepartmentGUID) != null) { DepartmentDDL.ClearSelection(); DepartmentDDL.Items.FindByValue(DepartmentGUID).Selected = true; } } rd.Close(); conn.Close(); } } } }