Esempio n. 1
0
    /// <summary>
    /// Check if level is exist
    /// </summary>
    /// <param name="lvl1">level you want to check</param>
    /// <returns>true if exist, false if not</returns>
    public static bool IsLevelExist(ch_levels lvl1)//use while insert
    {
        string strSql = "SELECT COUNT(lvl_id) FROM ch_levels WHERE lvl_id = " + lvl1.lvl_Id + " OR lvl_name = '" + lvl1.lvl_Name + "' OR lvl_desc = '" + lvl1.lvl_Desc + "'";
        int    num    = Convert.ToInt32(Connect.MathAction(strSql, "ch_levels"));

        if (num > 0)
        {
            return(true);
        }
        return(false);
    }
Esempio n. 2
0
    /// <summary>
    /// Add new record of ch_levels in Database
    /// </summary>
    /// <param name="lvl1">the level you want to add</param>
    /// <returns>string of an error or a string.Empty if the action is completed</returns>
    public static string AddLevel(ch_levels lvl1)
    {
        if (IsLevelExist(lvl1))
        {
            return("הדרגה כבר קיימת");
        }

        string strSql = "INSERT INTO ch_levels(lvl_id, lvl_name, lvl_desc)  VALUES(" + lvl1.lvl_Id + ",'" + lvl1.lvl_Name + "','" + lvl1.lvl_Desc + "')";

        Connect.DoAction(strSql, "ch_levels");
        return("");
    }
Esempio n. 3
0
    /// <summary>
    /// Update lvl using its id
    /// </summary>
    /// <param name="id">lvl_id statement</param>
    /// <param name="newLevel1">ch_levels object</param>
    public static string UpdateLevelById(int id, string name, ch_levels newLevel1)
    {
        if (IsLevelExist(newLevel1, id, name))
        {
            return("הדרגה כבר קיימת");
        }

        string strSql = "UPDATE ch_levels SET lvl_id = " + newLevel1.lvl_Id + ", lvl_name = '" + newLevel1.lvl_Name + "', lvl_desc = '" + newLevel1.lvl_Desc + "' WHERE lvl_id=" + id;

        Connect.DoAction(strSql, "ch_levels");

        return("");
    }
    protected void btn_update_lvl_Click(object sender, ImageClickEventArgs e)
    {
        ImageButton btn = (ImageButton)sender;
        GridViewRow gvr = (GridViewRow)btn.NamingContainer;

        int     lvl_id            = Convert.ToInt32(gvLevels.DataKeys[gvr.RowIndex].Values["lvl_id"].ToString());
        string  lvl_name          = gvLevels.DataKeys[gvr.RowIndex].Values["lvl_name"].ToString();
        TextBox txt_edit_lvl_id   = (TextBox)gvr.FindControl("txt_edit_lvl_id");
        TextBox txt_edit_lvl_name = (TextBox)gvr.FindControl("txt_edit_lvl_name");
        TextBox txt_edit_lvl_desc = (TextBox)gvr.FindControl("txt_edit_lvl_desc");

        if (lvl_id.ToString() != txt_edit_lvl_id.Text)
        {
        }
        if (txt_edit_lvl_id.Text.Trim() != "" && txt_edit_lvl_name.Text.Trim() != "")
        {
            //all vars to one object
            ch_levels lvl1 = new ch_levels();
            lvl1.lvl_Id   = Convert.ToInt32(txt_edit_lvl_id.Text.Trim());
            lvl1.lvl_Name = txt_edit_lvl_name.Text.Trim();
            lvl1.lvl_Desc = txt_edit_lvl_desc.Text.Trim();

            string err = ch_levelsSvc.UpdateLevelById(lvl_id, lvl_name, lvl1);
            if (err == "")//אם העדכון התבצע
            {
                lblErrGV.Text      = string.Empty;
                gvLevels.EditIndex = -1;

                //Bind data to GridView
                DataSet dsLevels = ch_levelsSvc.GetLevels();
                GridViewSvc.GVBind(dsLevels, gvLevels);
            }
            else
            {
                lblErrGV.Text = err;

                //Bind data to GridView
                DataSet dsLevels = ch_levelsSvc.GetLevels();
                GridViewSvc.GVBind(dsLevels, gvLevels);
            }
        }
        else
        {
            lblErrGV.Text = "הכנס דרגה";
        }
    }
    protected void btn_insert_lvl_Click(object sender, ImageClickEventArgs e)
    {
        ImageButton btn = (ImageButton)sender;
        GridViewRow gvr = (GridViewRow)btn.NamingContainer;

        TextBox txt_insert_lvl_id   = (TextBox)gvr.FindControl("txt_insert_lvl_id");
        TextBox txt_insert_lvl_name = (TextBox)gvr.FindControl("txt_insert_lvl_name");
        TextBox txt_insert_lvl_desc = (TextBox)gvr.FindControl("txt_insert_lvl_desc");

        if (txt_insert_lvl_id.Text.Trim() != "" && txt_insert_lvl_name.Text.Trim() != "")
        {
            //all vars to one object
            ch_levels lvl1 = new ch_levels();
            lvl1.lvl_Id   = Convert.ToInt32(txt_insert_lvl_id.Text.Trim());
            lvl1.lvl_Name = txt_insert_lvl_name.Text.Trim();
            lvl1.lvl_Desc = txt_insert_lvl_desc.Text.Trim();

            string err = ch_levelsSvc.AddLevel(lvl1);

            if (err == "")//אם ההכנסה התבצע
            {
                lblErrGV.Text       = "";
                gvLevels.ShowFooter = false;
                btnInsert.Enabled   = true;

                //Bind data to GridView
                DataSet dsLevels = ch_levelsSvc.GetLevels();
                GridViewSvc.GVBind(dsLevels, gvLevels);
            }
            else
            {
                lblErrGV.Text            = err;
                txt_insert_lvl_id.Text   = "";
                txt_insert_lvl_name.Text = "";
                txt_insert_lvl_desc.Text = "";
                //Bind data to GridView
                DataSet dsLevels = ch_levelsSvc.GetLevels();
                GridViewSvc.GVBind(dsLevels, gvLevels);
            }
        }
        else
        {
            lblErrGV.Text = "הכנס דרגה";
        }
    }