コード例 #1
0
        protected void DropDownList_Group_SelectedIndexChanged(object sender, EventArgs e)
        {
            string SelectGroup = DropDownList_Group.SelectedValue;

            //SELECT [StudentID], [Name], [Class], [Groups] FROM [PersonalInformation] ORDER BY [StudentID] DESC
            SqlDataSource_stust.SelectCommand = "SELECT StudentID,Name,Class,Groups FROM PersonalInformation  WHERE (Purview = 'Student')AND(Groups='" + SelectGroup.Trim() + "') ORDER BY StudentID DESC";
            SqlDataSource_stust.DataBind();
        }
コード例 #2
0
        protected void Button_fix_Click(object sender, EventArgs e)
        {
            SqlConnection AllData_Connection = null;

            AllData_Connection = new SqlConnection(ConfigurationManager.ConnectionStrings["DataBaseConnection"].ConnectionString);                                                  //宣告一個資料庫連結
            AllData_Connection.Open();                                                                                                                                              //開啟AllData資料庫
            string DataBase_Language = "UPDATE TestTimeData set TestContent=@Range,begin_time=@BeginTime,end_time=@EndTime,RandCount=@Count,TeacherID=@TeacherID WHERE TestID=@ID"; //資料庫語法

            cmd = new SqlCommand(DataBase_Language, AllData_Connection);                                                                                                            //使用SQL
            cmd.Parameters.Add("BeginTime", SqlDbType.DateTime).Value = BeginTime;
            cmd.Parameters.Add("EndTime", SqlDbType.DateTime).Value   = EndTime;
            cmd.Parameters.Add("Range", SqlDbType.NVarChar).Value     = TextBox_Range.Text.ToString();
            cmd.Parameters.Add("ID", SqlDbType.Char).Value            = DropDownList2.SelectedValue;
            cmd.Parameters.Add("Count", SqlDbType.Int).Value          = Int32.Parse(TextBox_RandCount.Text);
            cmd.Parameters.Add("TeacherID", SqlDbType.NVarChar).Value = StudentID;
            /*Class*/

            /* string classStr = "";
             * for (int tempClass = 0; tempClass < CheckBoxList_class.Items.Count; tempClass++)
             * {
             *   if (CheckBoxList_class.Items[tempClass].Selected == true)
             *       classStr += CheckBoxList_class.Items[tempClass].Value + ",";
             * }
             * cmd.Parameters.Add("Class", SqlDbType.NVarChar).Value = classStr.Trim();
             */
            cmd.Connection = AllData_Connection;
            cmd.ExecuteNonQuery();
            AllData_Connection.Close();
            AllData_Connection.Open();                                         //開啟AllData資料庫
            DataBase_Language = "DELETE FROM ExamsList where TestID=@TestID";; //資料庫語法
            cmd = new SqlCommand(DataBase_Language, AllData_Connection);       //使用SQL
            cmd.Parameters.Add("TestID", SqlDbType.Char).Value = DropDownList2.SelectedValue;
            cmd.ExecuteNonQuery();
            AllData_Connection.Close();
            for (int i = 0; i < GridView_Stust.Rows.Count; i++)
            {
                if (((CheckBox)GridView_Stust.Rows[i].FindControl("CheckBox1")).Checked == true)
                {
                    AllData_Connection.Open();                                                                                                                                                     //開啟AllData資料庫
                    DataBase_Language = "INSERT INTO ExamsList(TestID,StudentID,TestContent,Score,StudentName,CreateTime)VALUES(@TestID,@StudentID,@TestContent,@Score,@StudentName,@CreateTime)"; //資料庫語法
                    cmd = new SqlCommand(DataBase_Language, AllData_Connection);                                                                                                                   //使用SQL
                    cmd.Parameters.Add("StudentID", SqlDbType.Char).Value       = GridView_Stust.Rows[i].Cells[1].Text;
                    cmd.Parameters.Add("TestID", SqlDbType.Char).Value          = DropDownList2.SelectedValue;
                    cmd.Parameters.Add("StudentName", SqlDbType.Char).Value     = GridView_Stust.Rows[i].Cells[2].Text;
                    cmd.Parameters.Add("CreateTime", SqlDbType.Char).Value      = DateTime.Now;
                    cmd.Parameters.Add("TestContent", SqlDbType.NVarChar).Value = TextBox_Range.Text.ToString();
                    cmd.Parameters.Add("Score", SqlDbType.Int).Value            = -1;
                    cmd.ExecuteNonQuery();
                    AllData_Connection.Close();
                }
            }
            GridView1.DataSourceID = "SqlDataSource1";
            GridView2.DataSourceID = "SqlDataSource_Doing";
            //
            SqlDataSource_Doing.SelectCommand = "SELECT TestID,StudentID FROM ExamsList WHERE (TestID='" + DropDownList2.SelectedValue + "')";
            SqlDataSource_stust.DataBind();
        }
コード例 #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Label_END.Text   = EndTime.ToLongDateString() + EndTime.ToLongTimeString();
            Label_BEGIN.Text = BeginTime.ToLongDateString() + BeginTime.ToLongTimeString();
            #region Use是否上線
            SqlConnection AllData_Connection = new SqlConnection(ConfigurationManager.ConnectionStrings["DataBaseConnection"].ConnectionString); //宣告一個資料庫連結
            AllData_Connection.Open();                                                                                                           //開啟AllData資料庫
            string DataBase_Language = "Select * from PersonalInformation Where Account=@Account and Passsword=@Passsword";                      //資料庫語法
            string MD5_A             = "";
            string MD5_P             = "";
            try
            {
                MD5_A = Server.HtmlEncode(Request.Cookies["CCMATH"]["UserID"].ToString());
                MD5_P = Server.HtmlEncode(Request.Cookies["CCMATH"]["Password"].ToString());
            }
            catch
            {
                Server.Transfer("~/Account/Login.aspx");
            }
            //  Session["CCMATHUserID"] = MD5_A;
            // Session["CCMATHPassword"] = MD5_P;
            cmd = new SqlCommand(DataBase_Language, AllData_Connection);//使用SQL
            cmd.Parameters.Add("Account", SqlDbType.Char).Value   = MD5_A;
            cmd.Parameters.Add("Passsword", SqlDbType.Char).Value = MD5_P;
            DataBase_Reader = cmd.ExecuteReader();
            Boolean check = false;
            while (DataBase_Reader.Read())
            {
                check     = true;
                StudentID = (string)DataBase_Reader["StudentID"];
                group     = (string)DataBase_Reader["Groups"];
                Session["CCMATHGroups"] = group;
            }
            AllData_Connection.Close();//開啟AllData資料庫
            if (!check)
            {
                Server.Transfer("~/Account/Login.aspx");
            }
            #endregion

            if (!IsPostBack)
            {
                string SelectGroup = DropDownList_Group.SelectedValue;
                SqlDataSource_stust.SelectCommand = "SELECT StudentID,Groups FROM PersonalInformation WHERE (Purview = 'Student')AND(Groups='" + SelectGroup.Trim() + "')";
                SqlDataSource_stust.DataBind();
                SqlDataSource1.DataBind();
            }
            GridView2.DataBind();
            Label_say.Text = "考試人數:" + GridView2.Rows.Count + "人";
        }
コード例 #4
0
        protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            string SelectGroup = group;
            int    count       = 0;

            count = 0;
            string str = "";

            foreach (ListItem li in CheckBoxList1.Items)
            {
                if (li.Selected)
                {
                    if (count == 0)
                    {
                        str = "('" + li.Value + "'";
                        count++;
                    }
                    else
                    {
                        str += ",'" + li.Value + "'";
                    }
                }
            }
            if (count != 0)
            {
                str = str + ")";
                string sr = "SELECT StudentID,Name,Class,Groups FROM PersonalInformation  WHERE (Purview = 'Student')AND(Groups='" + SelectGroup.Trim() + "') AND ClassID IN" + str + "  ORDER BY StudentID DESC";
                SqlDataSource_stust.SelectCommand = sr;
            }
            else
            {
                SqlDataSource_stust.SelectCommand = "SELECT StudentID,Name,Class,Groups FROM PersonalInformation  WHERE (Purview = 'Student')AND(Groups='" + SelectGroup.Trim() + "') ORDER BY StudentID DESC";
            }


            SqlDataSource_stust.DataBind();
        }