Пример #1
0
 protected void Page_Load(object sender, EventArgs e)
 {
     MyiTestDataDataContext db = new MyiTestDataDataContext();
     int iduser = (int)(Session["idlogin"]);
     st_GetUserInfoResult user = db.st_GetUserInfo(iduser).FirstOrDefault();
     if (user != null)
     {
         txtUsername.Text = user.iUserName;
     }
 }
Пример #2
0
 protected void btnlogin_Click(object sender, EventArgs e)
 {
     MyiTestDataDataContext db = new MyiTestDataDataContext();
     int id = db.st_Login(txtUsername.Text.Trim(), FormsAuthentication.HashPasswordForStoringInConfigFile(txtPass.Text.Trim(), "MD5"));
     if (id > 0)
     {
         Session["idlogin"] = id;
         Response.Redirect("Default.aspx");
     }
     else
     {
         Response.Write("<script>alert('Đăng nhập thất bạn. Vui lòng Nhập lại');</script>");
     }
 }
Пример #3
0
 protected void btnChangePass_Click(object sender, EventArgs e)
 {
     if (txtNewPass.Text.Trim() != txtReEnterNewPass.Text.Trim())
     {
         Response.Write("<script>alert('Xác nhận mật khẩu mới không chính xác');</script>");
         txtOldPass.Focus();
     }
     else
         if (txtNewPass.Text == "")
         {
             Response.Write("<script>alert('Chưa nhập mật khẩu mới');</script>");
             txtOldPass.Focus();
         }
         else
         {
             MyiTestDataDataContext db = new MyiTestDataDataContext();
             int iduser = Convert.ToInt32(Session["idlogin"]);
             int result = db.st_ChangePassword(iduser, FormsAuthentication.HashPasswordForStoringInConfigFile(txtOldPass.Text.Trim(), "MD5"), FormsAuthentication.HashPasswordForStoringInConfigFile(txtNewPass.Text.Trim(), "MD5"));
             if (result == -1)
             {
                 Response.Write("<script>alert('Mật khẩu cũ không đúng');</script>");
                 txtOldPass.Focus();
                 return;
             }
             if (result == 0)
             {
                 Response.Write("<script>alert('Không thể thay đổi mật khẩu, vui lòng thử lại');</script>");
                 txtOldPass.Focus();
                 return;
             }
             else
             {
                 Response.Write("<script>alert('Đổi mật khẩu thành công !');</script>");
                 txtOldPass.Text = string.Empty;
                 txtNewPass.Text = string.Empty;
                 txtReEnterNewPass.Text = string.Empty;
                 return;
             }
         }
 }
Пример #4
0
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            MyiTestDataDataContext db = new MyiTestDataDataContext();
            iChapter ch = new iChapter();

            if (ddlSubject.SelectedValue != "-1" && txtName.Text.Trim().Length > 0)
            {
                int subid = db.st_LoadSubjectID(ddlSubject.Text.Trim());
                //int chapindex = db.st_CheckChapIndex(txtIndex.Text.Trim(), subid);
                int chapname = db.st_CheckChapName(txtName.Text.Trim(), subid);

                if (chapname == 0)
                {
                    lbName.Text = "";
                    lbName.Text = "Tên chương đã tồn tại !";
                    txtName.Text = string.Empty;
                    //btnSignUp.Enabled = false;
                }
                else
                {
                    ch.iSubjectID = subid;
                    ch.iChapterName = txtName.Text.ToString();

                    db.iChapters.InsertOnSubmit(ch);
                    db.SubmitChanges();

                    Response.Write("<script>alert('Thêm chương mới thành công !')</script>");
                    txtName.Text = string.Empty;

                    lbName.Text = "";
                    txtName.Focus();
                }
            }
            else if (ddlSubject.SelectedValue == "-1" | txtName.Text.Trim().Length <= 0)
            {
                Response.Write("<script>alert('Vui lòng nhập đầy đủ thông tin')</script>");
            }
        }
Пример #5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            MyiTestDataDataContext db = new MyiTestDataDataContext();

            //if (Session["UserName"] != null)
            {
                gdv_User.DataSource = db.st_GetUserInfo(Convert.ToInt32(Session["idlogin"]));
                gdv_User.DataBind();

                lblUserName.Text = gdv_User.Rows[0].Cells[1].Text;
                lblCreatedDate.Text = gdv_User.Rows[0].Cells[6].Text;
                lblEmail.Text = gdv_User.Rows[0].Cells[3].Text;
                lblSumBuonus.Text = db.st_GetBonus(Convert.ToInt32(Session["idlogin"])).ToString();

                float sumtest = (float)db.st_GetSumTest(Convert.ToInt32(Session["idlogin"]));
                float summark = (float)db.st_GetMark(Convert.ToInt32(Session["idlogin"]));

                lblSumMark.Text = summark.ToString();
                lblSumTest.Text = sumtest.ToString();

                double avg = Math.Round((double)(summark/sumtest),2);
                lblAvgMark.Text = avg.ToString();
            }
        }
Пример #6
0
        /* public int RandomNumber(int min, int max)
         {
             Random random = new Random();
             return random.Next(min, max);
         }*/
        protected void ddlSubject_SelectedIndexChanged(object sender, EventArgs e)
        {
            while (ddlChap.Items.Count >= 2)
            {
                ddlChap.Items.RemoveAt(1); //index 0 cant remove because it's title of Dropdownlist
            }

            //----- select sub index when user choice -----------------------------------------------------------
            MyiTestDataDataContext db = new MyiTestDataDataContext();
            int subid = db.st_LoadSubjectID(ddlSubject.Text.Trim());
            //----------------------------------------------------------------

            var query = from c in data.iChapters
                        where c.iSubjectID == subid
                        select new { c.iChapID, c.iChapterName };
            ddlChap.DataSource = query;
            ddlChap.DataTextField = "iChapterName";
            ddlChap.DataValueField = "iChapID";
            ddlChap.DataBind();
        }
Пример #7
0
        protected void btnSignUp_Click(object sender, EventArgs e)
        {
            MyiTestDataDataContext db = new MyiTestDataDataContext();
            iUser ius = new iUser();

            if (txtUsername.Text.Length > 0 && txtUsername.Text.Length < 12 && txtPass.Text.Length > 0 && txtPass.Text.Length < 20
                && txtReEnterPass.Text.Length > 0 && txtEmail.Text.Length > 0)
            {
                int user = db.st_CheckAvailableUser(txtUsername.Text.Trim());
                int email = db.st_CheckAvailableEmail(txtEmail.Text.Trim());

                if (user == 0)
                {
                    labUser.Text = "";
                    labRePass.Text = "";
                    labEmail.Text = "";

                    labUser.Text = "This name is exist ! Please enter other name";
                    txtUsername.Text = string.Empty;
                    //btnSignUp.Enabled = false;
                }
                else if (email == 0)
                {
                    labUser.Text = "";
                    labRePass.Text = "";
                    labEmail.Text = "";

                    labEmail.Text = "This email is exist ! Please enter other email address";
                    txtEmail.Text = string.Empty;
                    //btnSignUp.Enabled = false;
                }
                else if (txtReEnterPass.Text.Trim() != txtPass.Text.Trim())
                {
                    labUser.Text = "";
                    labRePass.Text = "";
                    labEmail.Text = "";

                    labRePass.Text = "Incorrect Password ! Please enter again";
                    txtReEnterPass.Text = string.Empty;
                }
                else
                {

                    ius.iUserName = txtUsername.Text.ToString();
                    ius.iPass = FormsAuthentication.HashPasswordForStoringInConfigFile(txtPass.Text.Trim(), "MD5");
                    ius.iEmailUser = txtEmail.Text.ToString();

                    db.iUsers.InsertOnSubmit(ius);
                    db.SubmitChanges();

                    string strScript = "<script>";
                    strScript += "alert('Created New Account');";
                    strScript += "window.location='Login.aspx';";
                    strScript += "</script>";
                    Page.RegisterClientScriptBlock("strScript", strScript);

                    //Response.Redirect("RedirectHomePage.aspx");

                }
            }
            else
            {
                Response.Write("<script>alert('Please enter all infomation')</script>");

            }
        }
Пример #8
0
        /** edit by lightmoon7 - 20/10/2011 */
        protected void ddlSubName_SelectedIndexChanged(object sender, EventArgs e)
        {
            //------ refresh all data in controls: ddlChapNum and TextBox1
            while (ddlChapNum.Items.Count >= 2)
            {
                ddlChapNum.Items.RemoveAt(1); //index 0 cant remove because it's title of Dropdownlist
            }
            //TextBox1.Text = "";
            //----- select sub index when user choice -----------------------------------------------------------
            MyiTestDataDataContext db = new MyiTestDataDataContext();
            int subid = db.st_LoadSubjectID(ddlSubName.Text.Trim());
            //----------------------------------------------------------------

            var query = from c in data.iChapters
                        where c.iSubjectID == subid
                        select new { c.iChapID, c.iChapterName };
            ddlChapNum.DataSource = query;
            ddlChapNum.DataTextField = "iChapterName";
            ddlChapNum.DataValueField = "iChapID";
            ddlChapNum.DataBind();

            //ddlChapNum.SelectedIndex = 1; //if checking index after binding
        }
Пример #9
0
        MyiTestDataDataContext data = new MyiTestDataDataContext(); /** edit by lightmoon7 - 20/10/2011 */

        #endregion Fields

        #region Methods

        protected void btnAddQuest_Click(object sender, EventArgs e)
        {
            MyiTestDataDataContext db = new MyiTestDataDataContext();
            iQuestion qs = new iQuestion();
            //if (DropDownList1.SelectedValue == "2")
            { /*

                if (ddlSubName.SelectedValue != null && ddlChapNum.SelectedValue != null
                    && txtnoidung.Value.Length > 0
                    && FileUploadAns1.HasFile==true)
                {
                    iAnswer ans1 = new iAnswer();
                    iAnswer ans2 = new iAnswer();
                    iAnswer ans3 = new iAnswer();
                    iAnswer ans4 = new iAnswer();

                    /////up image
                    //Check Folder exists or not
                    DirectoryInfo dInfo = new DirectoryInfo(Server.MapPath("~/UploadFiles"));
                    if (!dInfo.Exists)
                    {
                        dInfo.Create();
                    }

                    //check question file browsed or not
                    if (FileUploadQuest.HasFile)
                    {
                        FileUploadQuest.PostedFile.SaveAs(Server.MapPath("~/UploadFiles/" + FileUploadQuest.FileName));
                    }

                    // image ans1
                    if (FileUploadAns1.HasFile)
                    {
                        FileUploadAns1.PostedFile.SaveAs(Server.MapPath("~/UploadFiles/" + FileUploadAns1.FileName));

                    }

                    // add question and answers into database

                    int subid = db.st_LoadSubjectID(ddlSubName.Text.Trim());
                    int chapid = data.st_LoadChapID(TextBox1.Text.Trim(), subid);

                    qs.iChapID = chapid;//db.st_LoadChapID(ddlChapNum.Text.Trim(), subid);
                    qs.iType = "1"; // 0 = binh thuong. 1= hinh anh
                    qs.iLevel = ddlLevel.SelectedValue;
                    //**************Level***********
                    //   0 = chua xac dinh         /
                    //   1 = dễ                    /
                    //   2 = binh thuong           /
                    //   3 = kho                   /
                    //   4= thong minh (rat kho)   /
                    //******************************
                    qs.iBodyQuest = txtnoidung.Value.ToString();
                    if (!FileUploadQuest.HasFile)
                        qs.iImageQName = null;
                    else
                        qs.iImageQName = FileUploadQuest.FileName.ToString();

                    db.iQuestions.InsertOnSubmit(qs);
                    db.SubmitChanges();

                    //////ans1
                    int qsid = qs.iQuestID;

                    ans1.iQuestID = qsid;
                    ans1.iBodyAns = " ";
                    if (!FileUploadAns1.HasFile)
                        ans1.iImageAName = null;
                    else
                        ans1.iImageAName = FileUploadAns1.FileName.ToString();

                    //////ans2
                    ans2.iQuestID = qsid;
                    ans2.iBodyAns = txtAns2.Text.ToString();
                    if (!FileUploadAns2.HasFile)
                        ans2.iImageAName = null;
                    else
                        ans2.iImageAName = FileUploadAns2.FileName.ToString();

                    /////ans3
                    ans3.iQuestID = qsid;
                    ans3.iBodyAns = txtAns3.Text.ToString();
                    if (!FileUploadAns3.HasFile)
                        ans3.iImageAName = null;
                    else
                        ans3.iImageAName = FileUploadAns3.FileName.ToString();

                    /////ans4
                    ans4.iQuestID = qsid;
                    ans4.iBodyAns = txtAns4.Text.ToString();
                    if (!FileUploadAns4.HasFile)
                        ans4.iImageAName = null;
                    else
                        ans4.iImageAName = FileUploadAns4.FileName.ToString();

                    ans1.iProperty = '1';
                    ans2.iProperty = '0';
                    ans3.iProperty = '0';
                    ans4.iProperty = '0';
                    if (cb1.Checked == true)
                    {
                        ans1.iProperty = '1';
                    }
                    else ans1.iProperty = '0';

                    if (cb2.Checked == true)
                    {
                        ans2.iProperty = '1';
                    }
                    else ans2.iProperty = '0';

                    if (cb3.Checked == true)
                    {
                        ans3.iProperty = '1';
                    }
                    else ans3.iProperty = '0';

                    if (cb4.Checked == true)
                    {
                        ans4.iProperty = '1';
                    }
                    else ans4.iProperty = '0';

                    db.iAnswers.InsertOnSubmit(ans1);
                    db.SubmitChanges();
                    db.iAnswers.InsertOnSubmit(ans2);
                    db.SubmitChanges();
                    db.iAnswers.InsertOnSubmit(ans3);
                    db.SubmitChanges();
                    db.iAnswers.InsertOnSubmit(ans4);
                    db.SubmitChanges();

                    Response.Write("<script>alert('This question was added');</script>");

                    txtnoidung.Value = string.Empty;
                    txtAns1.Text = string.Empty;
                    txtAns2.Text = string.Empty;
                    txtAns3.Text = string.Empty;
                    txtAns4.Text = string.Empty;

                    cb1.Checked = true;
                    cb2.Checked = false;
                    cb3.Checked = false;
                    cb4.Checked = false;

                    txtnoidung.Focus();
                    DropDownList1.SelectedValue = "-1";*/

                //}
                //else if (DropDownList1.SelectedValue == "1")
                //{
                if (ddlSubName.SelectedValue != "-1" && ddlChapNum.SelectedValue != "0"
            && /*edtQuest.Content.Length > 0*/ areaQuest.Value.Length > 0
            && areaAns1.Value.Length > 0 && areaAns2.Value.Length > 0
            && areaAns3.Value.Length > 0 && areaAns4.Value.Length > 0)
                {
                    iAnswer ans5 = new iAnswer();
                    iAnswer ans6 = new iAnswer();
                    iAnswer ans7 = new iAnswer();
                    iAnswer ans8 = new iAnswer();

                    /////up image
                    //Check Folder exists or not
                    DirectoryInfo dInfo = new DirectoryInfo(Server.MapPath("~/UploadFiles"));
                    if (!dInfo.Exists)
                    {
                        dInfo.Create();
                    }

                    // add question and answers into database

                    int subid = db.st_LoadSubjectID(ddlSubName.Text.Trim());
                    int chapid = int.Parse(ddlChapNum.SelectedValue);

                    qs.iChapID = chapid;//db.st_LoadChapID(ddlChapNum.Text.Trim(), subid);
                    //qs.iType = Convert.ToInt32(ddlLevel.SelectedValue);
                    qs.iLevel = Convert.ToInt32(ddlLevel.SelectedValue);
                    qs.iBodyQuest = areaQuest.Value;
                    if (!FileUploadQuest.HasFile)
                        qs.iImageQName = null;
                    else
                        qs.iImageQName = FileUploadQuest.FileName.ToString();

                    // trang thai
                    qs.iStatus = 0;
                    if (rdOK.Checked == true)
                        qs.iStatus = 1;
                    else
                        qs.iStatus = 0;
                    //user add
                    qs.iUserID = (int)Session["idlogin"];
                    // date add
                    qs.iLastModified = DateTime.Now;
                    //submit
                    db.iQuestions.InsertOnSubmit(qs);
                    db.SubmitChanges();

                    //////ans1
                    int qsid = qs.iQuestID;

                    //kiem tra xem fileupload co file hay ko, neu co thi add, + them id cau hoi phia truoc
                    if (FileUploadQuest.HasFile)
                    {
                        FileUploadQuest.PostedFile.SaveAs(Server.MapPath("~/UploadFiles/" + qsid + FileUploadQuest.FileName));
                    }
                    ans5.iQuestID = qsid;
                    ans5.iBodyAns = areaAns1.Value;

                    //////ans2
                    ans6.iQuestID = qsid;
                    ans6.iBodyAns = areaAns2.Value;

                    /////ans3
                    ans7.iQuestID = qsid;
                    ans7.iBodyAns = areaAns3.Value;

                    /////ans4
                    ans8.iQuestID = qsid;
                    ans8.iBodyAns = areaAns4.Value;

                    /// xet default dap an dung
                    ans5.iProperty = '1';
                    ans6.iProperty = '0';
                    ans7.iProperty = '0';
                    ans8.iProperty = '0';

                    /// xet dap an dung theo tuy chon cua nguoi nhap
                    if (rbA.Checked == true)
                    {
                        ans5.iProperty = '1';
                    }
                    else ans5.iProperty = '0';

                    if (rbB.Checked == true)
                    {
                        ans6.iProperty = '1';
                    }
                    else ans6.iProperty = '0';

                    if (rbC.Checked == true)
                    {
                        ans7.iProperty = '1';
                    }
                    else ans7.iProperty = '0';

                    if (rbD.Checked == true)
                    {
                        ans8.iProperty = '1';
                    }
                    else ans8.iProperty = '0';

                    // insert vao database
                    db.iAnswers.InsertOnSubmit(ans5);
                    db.SubmitChanges();
                    db.iAnswers.InsertOnSubmit(ans6);
                    db.SubmitChanges();
                    db.iAnswers.InsertOnSubmit(ans7);
                    db.SubmitChanges();
                    db.iAnswers.InsertOnSubmit(ans8);
                    db.SubmitChanges();

                    // Thong bao thanh cong
                    Response.Write("<script>alert('Thêm câu  hỏi thành công');</script>");

                    // Tra form ve gia tri mac dinh
                    areaQuest.Value="";
                    //edtQuest.Content = string.Empty;
                    areaAns1.Value="";
                    areaAns2.Value="";
                    areaAns3.Value="";
                    areaAns4.Value="";

                    rbA.Checked = true;
                    rbB.Checked = false;
                    rbC.Checked = false;
                    rbD.Checked = false;

                    areaQuest.Focus();
                    //DropDownList1.SelectedValue = "-1";
                }
                //}
                else // Chua nhap du thong tin
                {
                    Response.Write("<script>alert('Vui lòng nhập thông tin đầy đủ');</script>");
                }
            }
            /*
            protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
            {

                if (DropDownList1.SelectedValue == "1")
                {
                    Panel_OneChoice.Visible = true;
                    Panel_MutiChoices.Visible = false;
                    return;
                }
                else if (DropDownList1.SelectedValue == "2")
                {
                    Panel_MutiChoices.Visible = true;
                    Panel_OneChoice.Visible = false;
                    return;
                }
                else
                {
                    Panel_MutiChoices.Visible = false;
                    Panel_OneChoice.Visible = false;
                    return;
                }
            }*/
        }
Пример #10
0
        protected void btnSignUp_Click(object sender, EventArgs e)
        {
            MyiTestDataDataContext db = new MyiTestDataDataContext();
            iUser ius = new iUser();

            if (chk_DongY.Checked == true)
            {
                if (txtUsername.Text.Length > 0 && txtUsername.Text.Length <= 12
                    && txtPass.Text.Length > 0 && txtPass.Text.Length <= 20
                    && txtReEnterPass.Text.Length > 0 && txtEmail.Text.Length > 0 && txtAnswer.Text.Length > 0
                    && dropCauHoiBiMat.SelectedValue != "-1")
                {
                    int user = db.st_CheckAvailableUser(txtUsername.Text.Trim());
                    int email = db.st_CheckAvailableEmail(txtEmail.Text.Trim());

                    if (user == 0)
                    {
                        labUser.Text = "";
                        labRePass.Text = "";
                        labEmail.Text = "";

                        labUser.Text = "Tên đăng nhập đã tồn tại!";
                        txtUsername.Text = string.Empty;

                    }
                    else if (email == 0)
                    {
                        labUser.Text = "";
                        labRePass.Text = "";
                        labEmail.Text = "";

                        labEmail.Text = "Email đã được sử dụng!";
                        txtEmail.Text = string.Empty;
                        //btnSignUp.Enabled = false;
                    }
                    else if (txtReEnterPass.Text.Trim() != txtPass.Text.Trim())
                    {
                        labUser.Text = "";
                        labRePass.Text = "";
                        labEmail.Text = "";

                        labRePass.Text = "Xác nhận mật khẩu không chính xác!";
                        txtReEnterPass.Text = string.Empty;
                    }
                    else
                    {

                        ius.iUserName = txtUsername.Text.ToString();
                        ius.iPass = FormsAuthentication.HashPasswordForStoringInConfigFile(txtPass.Text.Trim(), "MD5");
                        ius.iEmailUser = txtEmail.Text.ToString();
                        ius.iBirthday =Convert.ToDateTime(ddlNgay.SelectedValue + "-" + ddlThang.SelectedValue + "-" + ddlNam.SelectedValue);
                        ius.iSID = Convert.ToInt32(dropCauHoiBiMat.SelectedItem.Value);
                        ius.iSAns = txtAnswer.Text;
                        ius.iCreatedDate = DateTime.Now;

                        db.iUsers.InsertOnSubmit(ius);
                        db.SubmitChanges();

                        string strScript = "<script>";
                        strScript += "alert('Chào mừng bạn đến với iTest');";
                        strScript += "window.location='Default.aspx';";
                        strScript += "</script>";
                        Page.RegisterClientScriptBlock("strScript", strScript);
                    }
                }
                else
                {
                    Response.Write("<script>alert('Vui lòng điền đầy đủ thông tin ! ')</script>");
                }
            }
            else
            {
                Response.Write("<script>alert('Bạn phải đánh dấu vào ô chấp nhận các điều khoản của iTest.')</script>");
            }
        }