Example #1
0
    /// <summary>
    /// Adds a new record of behavior to the database.
    /// </summary>
    /// <param name="bhv1">The behavior to add</param>
    /// <returns>string of an error or a string.Empty if the action is completed</returns>
    public static string AddBehavior(ch_behaviors bhv1)
    {
        if (NumBhvExist(bhv1) > 0)
        {
            return("שם ההתנהגות כבר קיים במערכת");
        }

        string strSql = "INSERT INTO ch_behaviors(bhv_name, bhv_value)  VALUES('" + bhv1.bhv_name + "'," + bhv1.bhv_value + ")";

        Connect.DoAction(strSql, "ch_behaviors");
        return("");
    }
Example #2
0
    /// <summary>
    /// Update a behavior record in the database by bhv_id
    /// </summary>
    /// <param name="id">behavior id</param>
    /// <param name="newBhv1">new behavior to update</param>
    /// <returns>string of an error or a string.Empty if the action is completed</returns>
    public static string UpdateBehaviorById(int id, ch_behaviors newBhv1)
    {
        string strSql1 = "SELECT COUNT(bhv_id) FROM ch_behaviors WHERE bhv_name = '" + newBhv1.bhv_name + "' AND bhv_id <>" + id;
        int    num     = Convert.ToInt32(Connect.MathAction(strSql1, "ch_behaviors"));

        if (num > 0)
        {
            return("שם ההתנהגות כבר קיים במערכת");
        }

        string strSql = "UPDATE ch_behaviors SET bhv_name='" + newBhv1.bhv_name + "', bhv_value=" + newBhv1.bhv_value + " WHERE bhv_id=" + id;

        Connect.DoAction(strSql, "ch_behaviors");

        return("");
    }
Example #3
0
    protected void btn_insert_bhv_Click(object sender, ImageClickEventArgs e)
    {
        ImageButton btn = (ImageButton)sender;
        GridViewRow gvr = (GridViewRow)btn.NamingContainer;

        TextBox txt_insert_bhv_name  = (TextBox)gvr.FindControl("txt_insert_bhv_name");
        TextBox txt_insert_bhv_value = (TextBox)gvr.FindControl("txt_insert_bhv_value");

        if (!ValidateInsertPage(gvr))
        {
            return;
        }

        //all vars to one object
        ch_behaviors bhv1 = new ch_behaviors();

        bhv1.bhv_name  = txt_insert_bhv_name.Text.Trim();
        bhv1.bhv_value = Convert.ToInt32(txt_insert_bhv_value.Text.Trim());

        string err = ch_behaviorsSvc.AddBehavior(bhv1);

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

            //Bind data to GridView
            DataSet dsBehaviors = ch_behaviorsSvc.GetBehaviors();
            GridViewSvc.GVBind(dsBehaviors, gvBehaviorsTypes);
        }
        else
        {
            lblErr.Text = err;
            txt_insert_bhv_name.Text = "";

            //Bind data to GridView
            DataSet dsBehaviors = ch_behaviorsSvc.GetBehaviors();
            GridViewSvc.GVBind(dsBehaviors, gvBehaviorsTypes);
        }
    }
Example #4
0
    protected void btn_update_bhv_Click(object sender, ImageClickEventArgs e)
    {
        ImageButton btn = (ImageButton)sender;
        GridViewRow gvr = (GridViewRow)btn.NamingContainer;

        int     bhv_id             = Convert.ToInt32(gvBehaviorsTypes.DataKeys[gvr.RowIndex].Value.ToString());
        TextBox txt_edit_bhv_name  = (TextBox)gvr.FindControl("txt_edit_bhv_name");
        TextBox txt_edit_bhv_value = (TextBox)gvr.FindControl("txt_edit_bhv_value");

        if (!ValidateEditPage(gvr))
        {
            return;
        }

        //all vars to one object
        ch_behaviors bhv1 = new ch_behaviors();

        bhv1.bhv_name  = txt_edit_bhv_name.Text.Trim();
        bhv1.bhv_value = Convert.ToInt32(txt_edit_bhv_value.Text.Trim());

        string err = ch_behaviorsSvc.UpdateBehaviorById(bhv_id, bhv1);

        if (err == "")//אם העדכון התבצע
        {
            lblErr.Text = string.Empty;
            gvBehaviorsTypes.EditIndex = -1;

            //Bind data to GridView
            DataSet dsBehaviors = ch_behaviorsSvc.GetBehaviors();
            GridViewSvc.GVBind(dsBehaviors, gvBehaviorsTypes);
        }
        else
        {
            lblErr.Text = err;

            //Bind data to GridView
            DataSet dsBehaviors = ch_behaviorsSvc.GetBehaviors();
            GridViewSvc.GVBind(dsBehaviors, gvBehaviorsTypes);
        }
    }
Example #5
0
    /// <summary>
    /// Check if the behavior that the function get is already exist in database.
    /// </summary>
    /// <param name="bhv1">The behavior to check if it's equal to record in the Database</param>
    /// <returns>Integer number of behaviors in database that are equal to bhv1.</returns>
    public static int NumBhvExist(ch_behaviors bhv1)
    {
        string strSql1 = "SELECT COUNT(bhv_id) FROM ch_behaviors WHERE bhv_name = '" + bhv1.bhv_name + "'";

        return(Convert.ToInt32(Connect.MathAction(strSql1, "ch_behaviors")));
    }