/// <summary> /// Adds a new record of hour to the database. /// </summary> /// <param name="hr1">the hour to add</param> /// <returns>string of an error or a string.Empty if the action is completed</returns> public static string AddHour(ch_hours hr1) { if (IsHourExist(hr1) > 0) { return("החדר כבר קיים"); } string strSql = "INSERT INTO ch_hours(hr_name, hr_start_time, hr_end_time, sc_id) VALUES('" + hr1.hr_Name + "', #" + hr1.hr_Start_Time + "#, #" + hr1.hr_End_Time + "#, " + hr1.sc_Id + ")"; Connect.DoAction(strSql, "ch_hours"); return(""); }
protected void btn_update_hr_Click(object sender, ImageClickEventArgs e) { ImageButton btn = (ImageButton)sender; GridViewRow gvr = (GridViewRow)btn.NamingContainer; int hr_id = Convert.ToInt32(gvHours.DataKeys[gvr.RowIndex].Value.ToString()); TextBox txt_edit_hr_name = (TextBox)gvr.FindControl("txt_edit_hr_name"); TextBox txt_edit_hr_start_time = (TextBox)gvr.FindControl("txt_edit_hr_start_time"); TextBox txt_edit_hr_end_time = (TextBox)gvr.FindControl("txt_edit_hr_end_time"); if (!ValidateEditPage(gvr)) { return; } //all vars to one object ch_hours hr1 = new ch_hours(); hr1.hr_Name = txt_edit_hr_name.Text.Trim(); hr1.hr_Start_Time = txt_edit_hr_start_time.Text.Trim(); hr1.hr_End_Time = txt_edit_hr_end_time.Text.Trim(); if (Convert.ToInt32(Session["lvl_id"]) < 4) { hr1.sc_Id = Convert.ToInt32(Session["sc_id"]); } else { hr1.sc_Id = Convert.ToInt32(ddlSchools.SelectedValue); } string err = ch_hoursSvc.UpdateHourById(hr_id, hr1); if (err == "")//אם העדכון התבצע { lblErrGV.Text = string.Empty; gvHours.EditIndex = -1; //Bind data to GridView int sc_id = Convert.ToInt32(Session["lvl_id"]) < 4 ? Convert.ToInt32(Session["sc_id"]) : Convert.ToInt32(ddlSchools.SelectedValue); DataSet dsHours = ch_hoursSvc.GetHours(sc_id); GridViewSvc.GVBind(dsHours, gvHours); } else { lblErrGV.Text = err; //Bind data to GridView int sc_id = Convert.ToInt32(Session["lvl_id"]) < 4 ? Convert.ToInt32(Session["sc_id"]) : Convert.ToInt32(ddlSchools.SelectedValue); DataSet dsHours = ch_hoursSvc.GetHours(sc_id); GridViewSvc.GVBind(dsHours, gvHours); } }
/// <summary> /// Update hour using its id /// </summary> /// <param name="id">hr_id statement</param> /// <param name="newHour1">ch_hours object</param> public static string UpdateHourById(int id, ch_hours newHour1) { if (IsHourExist(newHour1) > 1) { return("החדר כבר קיים"); } string strSql = "UPDATE ch_hours SET hr_name='" + newHour1.hr_Name + "', hr_start_time=#" + newHour1.hr_Start_Time + "#, hr_end_time=#" + newHour1.hr_End_Time + "# WHERE hr_id=" + id; Connect.DoAction(strSql, "ch_hours"); return(""); }
protected void btn_insert_hr_Click(object sender, ImageClickEventArgs e) { ImageButton btn = (ImageButton)sender; GridViewRow gvr = (GridViewRow)btn.NamingContainer; TextBox txt_insert_hr_name = (TextBox)gvr.FindControl("txt_insert_hr_name"); TextBox txt_insert_hr_start_time = (TextBox)gvr.FindControl("txt_insert_hr_start_time"); TextBox txt_insert_hr_end_time = (TextBox)gvr.FindControl("txt_insert_hr_end_time"); if (!ValidateInsertPage(gvr)) { return; } //all vars to one object ch_hours hr1 = new ch_hours(); hr1.hr_Name = txt_insert_hr_name.Text.Trim(); hr1.hr_Start_Time = txt_insert_hr_start_time.Text.Trim(); hr1.hr_End_Time = txt_insert_hr_end_time.Text.Trim(); hr1.sc_Id = Convert.ToInt32(Session["lvl_id"]) < 4 ? Convert.ToInt32(Session["sc_id"]) : Convert.ToInt32(ddlSchools.SelectedValue); string err = ch_hoursSvc.AddHour(hr1); if (err == "")//אם ההכנסה התבצעה { lblErrGV.Text = ""; gvHours.ShowFooter = false; btnInsert.Enabled = true; //Bind data to GridView int sc_id = Convert.ToInt32(Session["lvl_id"]) < 4 ? Convert.ToInt32(Session["sc_id"]) : Convert.ToInt32(ddlSchools.SelectedValue); DataSet dsHours = ch_hoursSvc.GetHours(sc_id); GridViewSvc.GVBind(dsHours, gvHours); } else { lblErrGV.Text = err; txt_insert_hr_name.Text = ""; //Bind data to GridView int sc_id = Convert.ToInt32(Session["lvl_id"]) < 4 ? Convert.ToInt32(Session["sc_id"]) : Convert.ToInt32(ddlSchools.SelectedValue); DataSet dsHours = ch_hoursSvc.GetHours(sc_id); GridViewSvc.GVBind(dsHours, gvHours); } }
/// <summary> /// Check if hr1 is exist in homework /// </summary> /// <param name="hr1">homework identity</param> /// <returns>num of existing hr1 in DataSet</returns> public static int IsHourExist(ch_hours hr1) { string strSql = "SELECT COUNT(hr_id) FROM ch_hours WHERE sc_id = " + hr1.sc_Id + " AND (hr_start_time = #" + hr1.hr_Start_Time + "# OR hr_end_time = #" + hr1.hr_End_Time + "#)"; return(Convert.ToInt32(Connect.MathAction(strSql, "ch_hours"))); }