protected void Page_Load(object sender, EventArgs e)
    {
        //获取所有老师
        SqlConnection  sqlConnection   = SqlTools.Connection();
        SqlDataAdapter sqlDataAdapter1 = new SqlDataAdapter("select * from teacher", sqlConnection);
        DataSet        dataSet1        = new DataSet();

        sqlDataAdapter1.Fill(dataSet1);

        //所有老师绑定到系别下拉框
        DropDownListTeacher.DataSource    = dataSet1;
        DropDownListTeacher.DataTextField = "name";
        DropDownListTeacher.DataBind();


        //获取所有教室
        SqlDataAdapter sqlDataAdapter2 = new SqlDataAdapter("select * from classroom", sqlConnection);
        DataSet        dataSet2        = new DataSet();

        sqlDataAdapter2.Fill(dataSet2);
        //所有教室绑定到系别下拉框
        DropDownListPlace.DataSource    = dataSet2;
        DropDownListPlace.DataTextField = "id";
        DropDownListPlace.DataBind();
    }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DropDownListTeacher.Items.Clear();
                DropDownListTeacher.Items.Add(new ListItem("--Select Teacher--", ""));

                DropDownListTeacher.AppendDataBoundItems = true;
                String        strConnString = ConfigurationManager.ConnectionStrings["dbconnection"].ConnectionString;
                String        strQuery      = "select TID, TName from tbl_Teacher";
                SqlConnection con           = new SqlConnection(strConnString);
                SqlCommand    cmd           = new SqlCommand();
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = strQuery;
                cmd.Connection  = con;
                try
                {
                    con.Open();
                    DropDownListTeacher.DataSource     = cmd.ExecuteReader();
                    DropDownListTeacher.DataTextField  = "TName";
                    DropDownListTeacher.DataValueField = "TID";
                    DropDownListTeacher.DataBind();
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    con.Close();
                    con.Dispose();
                }
            }

            //if (!IsPostBack)
            //{
            //    DropDownListDepartment.DataSource= getData("spGetDept", null);
            //    DropDownListDepartment.DataBind();

            //    ListItem listDept = new ListItem("Select Dept", "-1");
            //    DropDownListDepartment.Items.Insert(0, listDept);

            //    ListItem listTeacher = new ListItem("Select Teacher", "-1");
            //    DropDownListTeacher.Items.Insert(0, listTeacher);

            //    //DropDownListTeacher.Enabled = false;
            //}
        }
Esempio n. 3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserID"] != null)
            {
                userID = Int32.Parse(Session["UserID"].ToString());

                eRegisterData.DAL DAL  = new eRegisterData.DAL();
                SqlConnection     conn = DAL.getSubject();
                SqlCommand        comm = new SqlCommand();

                try
                {
                    conn.Open();
                    comm.Connection  = conn;
                    comm.CommandText = @" SELECT ActorID
                                      FROM Actors
                                      WHERE UserID='" + userID + "'";

                    studentID = Int32.Parse(comm.ExecuteScalar().ToString());
                    conn.Close();
                }
                catch (Exception ex)
                {
                    lblError.Text = ex.Message;
                }
                System.Data.DataTable teacherNameInfo = new System.Data.DataTable();
                eRegisterData.DAL     oDal            = new eRegisterData.DAL();
                if (!IsPostBack)
                {
                    teacherNameInfo = oDal.GetTeacherList(studentID);
                    DropDownListTeacher.DataSource     = teacherNameInfo.DefaultView;
                    DropDownListTeacher.DataTextField  = teacherNameInfo.Columns["TeacherName"].ColumnName.ToString();
                    DropDownListTeacher.DataValueField = teacherNameInfo.Columns["TeacherID"].ColumnName.ToString();
                    DropDownListTeacher.DataBind();
                    DropDownListTeacher.Items.Add(new ListItem("Моля изберете", "-1"));
                    DropDownListTeacher.SelectedIndex = DropDownListTeacher.Items.Count - 1;
                }
                messageID = Request.QueryString["messageID"];
                if (messageID != string.Empty)
                {
                    StatusID = oDal.MessageStatusID(messageID);
                    if (StatusID == 1)
                    {
                        System.Data.DataTable dt = oDal.MessageDraft(messageID);

                        DropDownListTeacher.ClearSelection();

                        ListItem selectedListItem = DropDownListTeacher.Items.FindByValue(dt.Rows[0][0].ToString());
                        if (selectedListItem != null)
                        {
                            selectedListItem.Selected = true;
                        }
                        txtMessage.Text = dt.Rows[0][1].ToString();
                    }
                    else
                    {
                        try
                        {
                            messageFrom = oDal.MessageReply(messageID);
                        }
                        catch (Exception ex)
                        {
                            lblError.Text = "No link to the Data Server!";
                        }
                        DropDownListTeacher.ClearSelection();
                        ListItem selectedListItem = DropDownListTeacher.Items.FindByValue(messageFrom.ToString());
                        if (selectedListItem != null)
                        {
                            selectedListItem.Selected   = true;
                            DropDownListTeacher.Enabled = false;
                        }
                        else
                        {
                        }
                    }
                }
            }
            else
            {
                Response.Redirect("~/eRegister.aspx");
            }
        }
Esempio n. 4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserID"] != null)
            {
                userID = Int32.Parse(Session["UserID"].ToString());

                eRegisterData.DAL DAL  = new eRegisterData.DAL();
                SqlConnection     conn = DAL.getSubject();
                SqlCommand        comm = new SqlCommand();

                try
                {
                    conn.Open();
                    comm.Connection  = conn;
                    comm.CommandText = @" SELECT ActorID
                                      FROM Actors
                                      WHERE UserID='" + userID + "'";

                    studentID = Int32.Parse(comm.ExecuteScalar().ToString());
                    conn.Close();
                }
                catch (Exception ex)
                {
                    lblError.Text = ex.Message;
                }

                if (!IsPostBack)
                {
                    System.Data.DataTable teacherName = new System.Data.DataTable();
                    eRegisterData.DAL     oDal        = new eRegisterData.DAL();
                    teacherName = oDal.GetActors(2);
                    DropDownListTeacher.DataSource     = teacherName.DefaultView;
                    DropDownListTeacher.DataTextField  = teacherName.Columns["Name"].ColumnName.ToString();
                    DropDownListTeacher.DataValueField = teacherName.Columns["ActorID"].ColumnName.ToString();
                    DropDownListTeacher.DataBind();
                    DropDownListTeacher.Items.Add(new ListItem("Моля изберете", "-1"));
                    DropDownListTeacher.SelectedIndex = DropDownListTeacher.Items.Count - 1;

                    System.Data.DataTable parentName = new System.Data.DataTable();
                    eRegisterData.DAL     oDal1      = new eRegisterData.DAL();
                    parentName = oDal1.GetActors(3);
                    DropDownListParent.DataSource     = parentName.DefaultView;
                    DropDownListParent.DataTextField  = parentName.Columns["Name"].ColumnName.ToString();
                    DropDownListParent.DataValueField = parentName.Columns["ActorID"].ColumnName.ToString();
                    DropDownListParent.DataBind();
                    DropDownListParent.Items.Add(new ListItem("Моля изберете", "-1"));
                    DropDownListParent.SelectedIndex = DropDownListParent.Items.Count - 1;

                    System.Data.DataTable studentName = new System.Data.DataTable();
                    eRegisterData.DAL     oDal2       = new eRegisterData.DAL();
                    studentName = oDal2.GetActors(4);
                    DropDownListStudent.DataSource     = studentName.DefaultView;
                    DropDownListStudent.DataTextField  = studentName.Columns["Name"].ColumnName.ToString();
                    DropDownListStudent.DataValueField = studentName.Columns["ActorID"].ColumnName.ToString();
                    DropDownListStudent.DataBind();
                    DropDownListStudent.Items.Add(new ListItem("Моля изберете", "-1"));
                    DropDownListStudent.SelectedIndex = DropDownListStudent.Items.Count - 1;

                    System.Data.DataTable messageTypeInfo = new System.Data.DataTable();
                    eRegisterData.DAL     oDal3           = new eRegisterData.DAL();
                    messageTypeInfo = oDal3.getMessageType();
                    DropDownListMessageType.DataSource     = messageTypeInfo.DefaultView;
                    DropDownListMessageType.DataTextField  = messageTypeInfo.Columns["Type"].ColumnName.ToString();
                    DropDownListMessageType.DataValueField = messageTypeInfo.Columns["MessageTypeID"].ColumnName.ToString();
                    DropDownListMessageType.DataBind();
                    DropDownListMessageType.Items.Add(new ListItem("Моля изберете", "-1"));
                    DropDownListMessageType.SelectedIndex = DropDownListMessageType.Items.Count - 1;
                }
            }
            else
            {
                Response.Redirect("~/eRegister.aspx");
            }
        }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //获取要编辑课程
            string id = Request.QueryString["id"];
            Course c  = (Course)dao.getBody(id, 4);

            TextBoxID.Text    = c.ID;
            TextBoxName.Text  = c.Name;
            TextBoxScore.Text = c.Score;
            TextBoxDate.Text  = c.Date;



            //获取所有老师
            SqlConnection  sqlConnection   = SqlTools.Connection();
            SqlDataAdapter sqlDataAdapter1 = new SqlDataAdapter("select * from teacher", sqlConnection);
            DataSet        dataSet1        = new DataSet();
            sqlDataAdapter1.Fill(dataSet1);

            //所有老师绑定到系别下拉框
            DropDownListTeacher.DataSource    = dataSet1;
            DropDownListTeacher.DataTextField = "name";
            DropDownListTeacher.DataBind();
            //下拉框选中该课程老师
            //1.查询老师编号对应的老师姓名
            string      teacherName = "";
            string      sql1        = string.Format("select name from teacher where id='{0}'", c.Teacher);
            IDataReader idr         = SqlTools.Read(sql1);
            if (idr.Read())
            {
                teacherName = idr.GetString(0);
            }
            //2.选中
            DropDownListTeacher.SelectedValue = teacherName;


            //绑定上课时间
            string[] dayAndNode = c.Time.Split(',');
            for (int i = 0; i < dayAndNode.Length; i++)
            {
                //第一个字符为1说明是星期一
                if (dayAndNode[i].Substring(0, 1).Equals("1"))
                {
                    RadioButtonMonday.Checked        = true;
                    DropDownListMonday.SelectedValue = dayAndNode[i].Substring(2, 1);
                }
                else if (dayAndNode[i].Substring(0, 1).Equals("2"))
                {
                    RadioButtonTuesday.Checked        = true;
                    DropDownListTuesday.SelectedValue = dayAndNode[i].Substring(2, 1);
                }
                else if (dayAndNode[i].Substring(0, 1).Equals("3"))
                {
                    RadioButtonWed.Checked = true;
                    DropDownListWednesday.SelectedValue = dayAndNode[i].Substring(2, 1);
                }
                else if (dayAndNode[i].Substring(0, 1).Equals("4"))
                {
                    RadioButtonThur.Checked            = true;
                    DropDownListThursday.SelectedValue = dayAndNode[i].Substring(2, 1);
                }
                else if (dayAndNode[i].Substring(0, 1).Equals("5"))
                {
                    RadioButtonFri.Checked           = true;
                    DropDownListFriday.SelectedValue = dayAndNode[i].Substring(2, 1);
                }
            }

            //绑定课程周次
            string[] startAndEnd = c.Week.Split('-');
            DropDownListStart.SelectedValue = startAndEnd[0];
            DropDownListEnd.SelectedValue   = startAndEnd[1];


            //获取所有教室
            SqlDataAdapter sqlDataAdapter2 = new SqlDataAdapter("select * from classroom", sqlConnection);
            DataSet        dataSet2        = new DataSet();
            sqlDataAdapter2.Fill(dataSet2);
            //所有教室绑定到系别下拉框
            DropDownListPlace.DataSource    = dataSet2;
            DropDownListPlace.DataTextField = "id";
            DropDownListPlace.DataBind();
            //选中上课地点
            DropDownListTeacher.SelectedValue = c.Place;


            sqlConnection.Close();
        }

        //不能改课程号
        TextBoxID.Enabled = false;
    }