/// <summary> /// Add new ch_professions record /// </summary> /// <param name="pro1">ch_professions row you want to add </param> /// <returns>string of an error or a string.Empty if the action is completed</returns> public static string AddPro(ch_professions pro1) { string strSql1 = "SELECT COUNT(pro_id) FROM ch_professions WHERE pro_name = '" + pro1.pro_Name + "'"; int num = Convert.ToInt32(Connect.MathAction(strSql1, "ch_professions")); if (num > 0) { return("המקצוע כבר קיים"); } string strSql = "INSERT INTO ch_professions(pro_name) VALUES('" + pro1.pro_Name + "')"; Connect.DoAction(strSql, "ch_professions"); return(""); }
/// <summary> /// Update ch_profession record from database using profession id /// </summary> /// <param name="id">profession id of the profession you want to update</param> /// <param name="newPro1">the new profession you want to update</param> public static string UpdateProById(int id, ch_professions newPro1) { string strSql1 = "SELECT COUNT(pro_id) FROM ch_professions WHERE pro_name = '" + newPro1.pro_Name + "' AND pro_id <>" + id; int num = Convert.ToInt32(Connect.MathAction(strSql1, "ch_professions")); if (num > 0) { return("המקצוע כבר קיים"); } string strSql = "UPDATE ch_professions SET pro_name='" + newPro1.pro_Name + "' WHERE pro_id=" + id; Connect.DoAction(strSql, "ch_professions"); return(""); }
protected void btn_update_pro_Click(object sender, ImageClickEventArgs e) { ImageButton btn = (ImageButton)sender; GridViewRow gvr = (GridViewRow)btn.NamingContainer; int pro_id = Convert.ToInt32(GVProfessions.DataKeys[gvr.RowIndex].Value.ToString()); TextBox txt_edit_pro_name = (TextBox)gvr.FindControl("txt_edit_pro_name"); if (txt_edit_pro_name.Text.Trim() != "") { if (Regex.IsMatch(txt_edit_pro_name.Text.Trim(), @"^[א-תa-zA-Z''-'\s]{2,35}$")) { //all vars to one object ch_professions pro1 = new ch_professions(); pro1.pro_Name = txt_edit_pro_name.Text.Trim(); string err = ch_professionsSvc.UpdateProById(pro_id, pro1); if (err == "")//אם העדכון התבצע { lblErrGV.Text = string.Empty; GVProfessions.EditIndex = -1; //Bind data to GridView DataSet dsProfessions = ch_professionsSvc.GetProfessions(); GridViewSvc.GVBind(dsProfessions, GVProfessions); } else { lblErrGV.Text = err; //Bind data to GridView DataSet dsProfessions = ch_professionsSvc.GetProfessions(); GridViewSvc.GVBind(dsProfessions, GVProfessions); } } else { lblErrGV.Text = "הכנס אותיות בין 2 ל 35 תווים"; } } else { lblErrGV.Text = "הכנס מקצוע"; } }
protected void btn_insert_pro_Click(object sender, ImageClickEventArgs e) { ImageButton btn = (ImageButton)sender; GridViewRow gvr = (GridViewRow)btn.NamingContainer; TextBox txt_insert_pro_name = (TextBox)gvr.FindControl("txt_insert_pro_name"); if (txt_insert_pro_name.Text.Trim() != "") { if (Regex.IsMatch(txt_insert_pro_name.Text.Trim(), @"^[א-תa-zA-Z''-'\s]{2,35}$")) { //all vars to one object ch_professions pro1 = new ch_professions(); pro1.pro_Name = txt_insert_pro_name.Text.Trim(); string err = ch_professionsSvc.AddPro(pro1); if (err == "")//אם ההכנסה התבצע { lblErrGV.Text = ""; GVProfessions.ShowFooter = false; btnInsert.Enabled = true; //Bind data to GridView DataSet dsProfessions = ch_professionsSvc.GetProfessions(); GridViewSvc.GVBind(dsProfessions, GVProfessions); } else { lblErrGV.Text = err; txt_insert_pro_name.Text = ""; //Bind data to GridView DataSet dsProfessions = ch_professionsSvc.GetProfessions(); GridViewSvc.GVBind(dsProfessions, GVProfessions); } } else { lblErrGV.Text = "הכנס אותיות בין 2 ל 35 תווים"; } } else { lblErrGV.Text = "הכנס מקצוע"; } }