protected void btnUpdateGrades_Click(object sender, EventArgs e)
    {
        if (ValidatePage())
        {
            string gradeName = txtGradeName.Text;
            string gradeDate = DateTime.ParseExact(txtGradeDate.Text, "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture).ToString("yyyy/MM/dd");


            int     grd_id = Convert.ToInt32(Request.QueryString["grd_id"]);
            DataRow drTest = ch_gradesSvc.GetTest(grd_id);
            int     les_id = Convert.ToInt32(drTest["les_id"].ToString());

            ch_grades newGrades = new ch_grades(les_id, gradeName, gradeDate);
            lblErr.Text = ch_gradesSvc.UpdateGrade(grd_id, newGrades);

            ch_users_gradesSvc.DeleteUsersGradesByTest(grd_id);

            foreach (GridViewRow gvr in gvStudents.Rows)
            {
                int usr_id  = Convert.ToInt32(((Label)gvr.FindControl("lbl_usr_id")).Text);
                int grd_num = Convert.ToInt32(((TextBox)gvr.FindControl("txtGrade")).Text);

                ch_users_grades usr_grd = new ch_users_grades(usr_id, grd_id, grd_num);
                ch_users_gradesSvc.AddUsrGrade(usr_grd);
            }
            if (lblErr.Text == "")
            {
                Response.Redirect("Grades.aspx");
            }
        }
    }
Exemple #2
0
    protected void btnAddGrades_Click(object sender, EventArgs e)
    {
        if (ValidatePage())
        {
            string gradeName = txtGradeName.Text;
            string gradeDate = DateTime.ParseExact(txtGradeDate.Text, "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture).ToString("yyyy/MM/dd");

            int les_id = Convert.ToInt32(ddlLessons.SelectedValue);

            ch_grades newGrades = new ch_grades(les_id, gradeName, gradeDate);
            lblErr.Text = ch_gradesSvc.AddGrade(newGrades);

            int last_grd_id = ch_gradesSvc.GetMaxId();

            foreach (GridViewRow gvr in gvStudents.Rows)
            {
                int usr_id  = Convert.ToInt32(((Label)gvr.FindControl("lbl_usr_id")).Text);
                int grd_num = Convert.ToInt32(((TextBox)gvr.FindControl("txtGrade")).Text);

                ch_users_grades usr_grd = new ch_users_grades(usr_id, last_grd_id, grd_num);
                ch_users_gradesSvc.AddUsrGrade(usr_grd);
            }
            if (lblErr.Text == "")
            {
                Response.Redirect("Grades.aspx");
            }
        }
    }
    /// <summary>
    /// Add a grade to a user
    /// </summary>
    /// <param name="newUsrGrade">the user grade</param>
    /// <returns>string of an error or a string.Empty if the action is completed</returns>
    public static string AddUsrGrade(ch_users_grades newUsrGrade)
    {
        string queryIsExist = "SELECT COUNT(grd_id) FROM ch_users_grades ";

        queryIsExist += "WHERE usr_id = " + newUsrGrade.usr_Id + " AND grd_id = " + newUsrGrade.grd_Id;
        int num = Convert.ToInt32(Connect.MathAction(queryIsExist, "ch_users_grades"));

        if (num > 0)
        {
            return("לתלמיד כבר יש ציון במערכת");
        }

        string queryInsert = "INSERT INTO ch_users_grades";

        queryInsert += "(usr_id, grd_id, grd_num) ";
        queryInsert += "VALUES(" + newUsrGrade.usr_Id + ", " + newUsrGrade.grd_Id + ", " + newUsrGrade.grd_Num + ")";

        Connect.DoAction(queryInsert, "ch_users_grades");
        return("");
    }
    /// <summary>
    /// Delete a user grade
    /// </summary>
    /// <param name="usrGrade">the user grade to delete</param>
    public static void DeleteUserGrade(ch_users_grades usrGrade)
    {
        string queryDeleteUserGrade = "DELETE * FROM ch_users_grades WHERE usr_id = " + usrGrade.usr_Id + " AND grd_id = " + usrGrade.grd_Id;

        Connect.DoAction(queryDeleteUserGrade, "ch_users_grades");
    }
    /// <param name="usrGrade">the user grade to get</param>
    /// <returns>DataRow of a user grade</returns>
    public static DataRow GetUserGrade(ch_users_grades usrGrade)
    {
        string queryGetUserGrade = "SELECT * FROM ch_users_grades WHERE usr_id = " + usrGrade.usr_Id + " AND grd_id = " + usrGrade.grd_Id;

        return(Connect.GetData(queryGetUserGrade, "ch_users_grades").Tables[0].Rows[0]);
    }