protected void btnAddBhv_Click(object sender, EventArgs e) { if (!ValidatePage()) { return; } for (int i = 0; i < gvBhv.Rows.Count; i++) { for (int j = 2; j < gvBhv.Rows[i].Cells.Count; j++) { CheckBox ckCurrent = (CheckBox)gvBhv.Rows[i].FindControl("ckStuBhv_" + j); if (ckCurrent.Checked) { ch_students_behaviors stu_bhvCurrent = new ch_students_behaviors(); stu_bhvCurrent.bhv_id = ch_behaviorsSvc.GetIdByBhvName(gvBhv.HeaderRow.Cells[j].Text); stu_bhvCurrent.stu_id = Convert.ToInt32(gvBhv.Rows[i].Cells[0].Text); stu_bhvCurrent.les_id = Convert.ToInt32(ddlLessons.SelectedValue); stu_bhvCurrent.stu_bhv_date = DateTime.ParseExact(txtLesDate.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture); stu_bhvCurrent.hr_id = Convert.ToInt32(ddlHours.SelectedValue); ch_students_behaviorsSvc.AddStuBehavior(stu_bhvCurrent); } } } Response.Redirect("Behaviors.aspx"); }
/// <summary> /// Add a new ch_students_behaviors record to the database /// </summary> /// <param name="stubhv1">a new student behavior you want to add</param> /// <returns>string of an error or a string.Empty if the action is completed</returns> public static string AddStuBehavior(ch_students_behaviors stubhv1) { if (IsStuBehaviorExist(stubhv1) > 0) return "לא יכולה להירשם התנהגות כפולה באותו יום ושעה לאותו תלמיד"; string strSql = "INSERT INTO ch_students_behaviors(bhv_id, stu_id, les_id, stu_bhv_date, hr_id) VALUES(" + stubhv1.bhv_id + "," + stubhv1.stu_id + "," + stubhv1.les_id + ",'" + stubhv1.stu_bhv_date.ToString("yyyy/MM/dd") + "'," + stubhv1.hr_id + ")"; Connect.DoAction(strSql, "ch_students_behaviors"); return ""; }
/// <summary> /// Update an old stu_bhv by a new one. /// </summary> /// <param name="old_stubhv1">the old stu_bhv to change</param> /// <param name="new_stubhv1">the new stu_bhv</param> /// <returns>string of an error or a string.Empty if the action is completed</returns> public static string UpdateStuBehavior(ch_students_behaviors old_stubhv1, ch_students_behaviors new_stubhv1) { string strSql1 = "SELECT COUNT(bhv_id) FROM ch_students_behaviors WHERE bhv_id = " + new_stubhv1.bhv_id + " AND stu_id = " + new_stubhv1.stu_id + " AND les_id = " + new_stubhv1.les_id + " AND Format(stu_bhv_date, 'yyyy/MM/dd') = #" + new_stubhv1.stu_bhv_date.ToString("yyyy/MM/dd") + "# AND hr_id = " + new_stubhv1.hr_id; int num = Convert.ToInt32(Connect.MathAction(strSql1, "ch_students_behaviors")); if (num > 0) return "לא יכולה להירשם התנהגות כפולה באותו יום ושעה לאותו תלמיד"; string strSql = "UPDATE ch_students_behaviors SET bhv_id = " + new_stubhv1.bhv_id + " AND stu_id = " + new_stubhv1.stu_id + " AND les_id = " + new_stubhv1.les_id + " AND Format(stu_bhv_date, 'yyyy/MM/dd') = #" + new_stubhv1.stu_bhv_date.ToString("yyyy/MM/dd") + "# AND hr_id = " + new_stubhv1.hr_id + " WHERE bhv_id = " + old_stubhv1.bhv_id + " AND stu_id = " + old_stubhv1.stu_id + " AND les_id = " + old_stubhv1.les_id + " AND Format(stu_bhv_date, 'yyyy/MM/dd') = #" + old_stubhv1.stu_bhv_date.ToString("yyyy/MM/dd") + "# AND hr_id = " + old_stubhv1.hr_id; Connect.DoAction(strSql, "ch_students_behaviors"); return ""; }
public bool IsEqual(ch_students_behaviors stu_bhv) { if (this.stu_id != stu_bhv.stu_id) { return(false); } if (this.bhv_id != stu_bhv.bhv_id) { return(false); } return(true); }
protected void btn_delete_bhv_Click(object sender, ImageClickEventArgs e) { ImageButton btn = (ImageButton)sender; GridViewRow gvr = (GridViewRow)btn.NamingContainer; //Delete selected row Label lblBhvDate = (Label)gvr.FindControl("lblBhvDate"); Label lblBhvName = (Label)gvr.FindControl("lblBhvName"); Label lblLesName = (Label)gvr.FindControl("lblLesName"); Label lblHrName = (Label)gvr.FindControl("lblHrName"); ch_students_behaviors stu_bhv = new ch_students_behaviors(); stu_bhv.stu_bhv_date = Convert.ToDateTime(lblBhvDate.Text); stu_bhv.bhv_id = ch_behaviorsSvc.GetIdByBhvName(lblBhvName.Text); stu_bhv.les_id = ch_lessonsSvc.GetIdByLesName(lblLesName.Text); stu_bhv.stu_id = Convert.ToInt32(lbStudents.SelectedValue); int sc_id = Convert.ToInt32(Session["lvl_id"]) < 4 ? Convert.ToInt32(Session["sc_id"]) : Convert.ToInt32(ddlSchools.SelectedValue); stu_bhv.hr_id = ch_hoursSvc.GetId(sc_id, lblHrName.Text); //Response.Write("stu_bhv_date=" + stu_bhv.stu_bhv_date + "&bhv_id=" + stu_bhv.bhv_id + "&les_id=" + stu_bhv.les_id + "&stu_id=" + stu_bhv.stu_id + "&hr_id=" + stu_bhv.hr_id); ch_students_behaviorsSvc.DeleteStuBehavior(stu_bhv); if (Convert.ToInt32(Session["lvl_id"]) == 1) // אם מורה //Bind data to GridView { pnlBhv.Visible = true; int stu_id = Convert.ToInt32(lbStudents.SelectedValue); int tch_id = Convert.ToInt32(Session["usr_id"]); DataSet dsBhv = ch_students_behaviorsSvc.GetStuBehaviors(stu_id); lblSumPoints.Text = "סה\"כ נקודות החודש(" + GetMonth() + "): " + ch_students_behaviorsSvc.GetStuBehaviorsPointsByMonth(stu_id); //bind GridViewSvc.GVBind(dsBhv, gvBhv); } else if (Convert.ToInt32(Session["lvl_id"]) >= 3) //אם עורך בית ספר ומעלה //Bind data to GridView { pnlBhv.Visible = true; int stu_id = Convert.ToInt32(lbStudents.SelectedValue); DataSet dsBhv = ch_students_behaviorsSvc.GetStuBehaviors(stu_id); lblSumPoints.Text = "סה\"כ נקודות החודש(" + GetMonth() + "): " + ch_students_behaviorsSvc.GetStuBehaviorsPointsByMonth(stu_id); //bind GridViewSvc.GVBind(dsBhv, gvBhv); } }
/// <returns>DataRow of a specific student behavior</returns> public static DataRow GetStuBehavior(ch_students_behaviors stubhv1) { string strSql = "SELECT * FROM ch_students_behaviors WHERE bhv_id = " + stubhv1.bhv_id + " AND stu_id = " + stubhv1.stu_id + " AND les_id = " + stubhv1.les_id + " AND Format(stu_bhv_date, 'yyyy/MM/dd') = #" + stubhv1.stu_bhv_date.ToString("yyyy/MM/dd") + "# AND hr_id = " + stubhv1.hr_id; return Connect.GetData(strSql, "ch_students_behaviors").Tables[0].Rows[0]; }
/// <param name="stubhv1">the object to check if exist in database</param> /// <returns>the number of instances of stubhv1 existing in database</returns> public static int IsStuBehaviorExist(ch_students_behaviors stubhv1) { string strSql1 = "SELECT COUNT(bhv_id) FROM ch_students_behaviors WHERE bhv_id = " + stubhv1.bhv_id + " AND stu_id = " + stubhv1.stu_id + " AND les_id = " + stubhv1.les_id + " AND Format(stu_bhv_date, 'yyyy/MM/dd') = #" + stubhv1.stu_bhv_date.ToString("yyyy/MM/dd") + "# AND hr_id = " + stubhv1.hr_id; return Convert.ToInt32(Connect.MathAction(strSql1, "ch_students_behaviors")); }
/// <summary> /// Delete a student behavior /// </summary> /// <param name="stubhv1">student behavior to delete</param> public static void DeleteStuBehavior(ch_students_behaviors stubhv1) { string strSql = "DELETE * FROM ch_students_behaviors WHERE bhv_id = " + stubhv1.bhv_id + " AND stu_id = " + stubhv1.stu_id + " AND les_id = " + stubhv1.les_id + " AND Format(stu_bhv_date, 'yyyy/MM/dd') = '" + stubhv1.stu_bhv_date.ToString("yyyy/MM/dd") + "' AND hr_id = " + stubhv1.hr_id; Connect.DoAction(strSql, "ch_students_behaviors"); }