using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.OracleClient;

public partial class GroupPermissions : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            pnlControls.Visible = false;
            pnl_pageFunctions.Visible = false;
            LiteralGroupName.Text = Request.QueryString["GName"];
            getGroupPages();
            getPages();
        }
        lblError.Text = "";
    }

    private void getPages()
    {
        string DBConnection = Helper.dbConnection();

        OracleConnection oracon = new OracleConnection(DBConnection);
        oracon.Open();

        OracleCommand oracom = new OracleCommand();
        oracom.Connection = oracon;

        oracom.CommandType = CommandType.StoredProcedure;
        oracom.CommandText = "sec_group_maintain.get_group_unassigned_pages";

        oracom.Parameters.Add("p_gid", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_lang", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_pages", OracleType.Cursor).Direction = ParameterDirection.Output;


        oracom.Parameters["p_gid"].Value = Request.QueryString["gid"];
        oracom.Parameters["p_lang"].Value = "EN";

        OracleDataAdapter da = new OracleDataAdapter(oracom);
        DataSet ds = new DataSet();
        da.Fill(ds);

        oracon.Close();

        ddlPages.DataSource = ds;
        ddlPages.DataBind();
    }

    private void getGroupPages()
    {
        string DBConnection = Helper.dbConnection();

        OracleConnection oracon = new OracleConnection(DBConnection);
        oracon.Open();

        OracleCommand oracom = new OracleCommand();
        oracom.Connection = oracon;

        oracom.CommandType = CommandType.StoredProcedure;
        oracom.CommandText = "SEC_GROUP_MAINTAIN.get_group_pages";

        oracom.Parameters.Add("p_gid", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_lang", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_grp_pages", OracleType.Cursor).Direction = ParameterDirection.Output;


        oracom.Parameters["p_lang"].Value = "EN";
        oracom.Parameters["p_gid"].Value = Request.QueryString["gid"];

        OracleDataAdapter da = new OracleDataAdapter(oracom);
        DataSet ds = new DataSet();
        da.Fill(ds);

        oracon.Close();

        GridView1.DataSource = ds;
        GridView1.DataBind();
    }

    private bool deletePage(string pageID, ref string error)
    {
        string DBConnection = Helper.dbConnection();

        OracleConnection oracon = new OracleConnection(DBConnection);
        oracon.Open();

        OracleCommand oracom = new OracleCommand();
        oracom.Connection = oracon;

        oracom.CommandType = CommandType.StoredProcedure;
        oracom.CommandText = "SEC_GROUP_MAINTAIN.assign_group_pages";

        oracom.Parameters.Add("p_current_uid", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_gid", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_pid", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_action", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_add_fn_list", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_del_fn_list", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_lang", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_res_code", OracleType.Number).Direction = ParameterDirection.Output;
        oracom.Parameters.Add("p_res_type", OracleType.VarChar, 250).Direction = ParameterDirection.Output;
        oracom.Parameters.Add("p_res_msg", OracleType.VarChar, 250).Direction = ParameterDirection.Output;

        oracom.Parameters["p_gid"].Value = Request.QueryString["gid"];
        oracom.Parameters["p_pid"].Value = pageID;
        oracom.Parameters["p_action"].Value = "D";
        oracom.Parameters["p_add_fn_list"].Value = OracleString.Null;
        oracom.Parameters["p_del_fn_list"].Value = OracleString.Null;
        oracom.Parameters["p_lang"].Value = "EN";
        oracom.Parameters["p_current_uid"].Value = Session["uid"].ToString();

        oracom.ExecuteNonQuery();
        oracon.Close();
        string a = oracom.Parameters["p_res_code"].Value.ToString();
        error = oracom.Parameters["p_res_msg"].Value.ToString();
        if (a == "0")
            return true;
        else
            return false;
    }

    private bool addPage(string pageID, ref string error)
    {
        string DBConnection = Helper.dbConnection();

        OracleConnection oracon = new OracleConnection(DBConnection);
        oracon.Open();

        OracleCommand oracom = new OracleCommand();
        oracom.Connection = oracon;

        oracom.CommandType = CommandType.StoredProcedure;
        oracom.CommandText = "SEC_GROUP_MAINTAIN.assign_group_pages";

        oracom.Parameters.Add("p_current_uid", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_gid", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_pid", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_action", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_add_fn_list", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_del_fn_list", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_lang", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_res_code", OracleType.Number).Direction = ParameterDirection.Output;
        oracom.Parameters.Add("p_res_type", OracleType.VarChar, 250).Direction = ParameterDirection.Output;
        oracom.Parameters.Add("p_res_msg", OracleType.VarChar, 250).Direction = ParameterDirection.Output;

        oracom.Parameters["p_gid"].Value = Request.QueryString["gid"];
        oracom.Parameters["p_pid"].Value = pageID;
        oracom.Parameters["p_action"].Value = "A";
        oracom.Parameters["p_add_fn_list"].Value = OracleString.Null;
        oracom.Parameters["p_del_fn_list"].Value = OracleString.Null;
        oracom.Parameters["p_lang"].Value = "EN";
        oracom.Parameters["p_current_uid"].Value = Session["uid"].ToString();

        oracom.ExecuteNonQuery();
        oracon.Close();
        string a = oracom.Parameters["p_res_code"].Value.ToString();
        error = oracom.Parameters["p_res_msg"].Value.ToString();
        if (a == "0")
            return true;
        else
            return false;
    }


    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.Equals("d"))
        {
            int index = int.Parse(e.CommandArgument.ToString());
            string Uid = GridView1.DataKeys[index].Value.ToString();
            string error = "";
            bool temp = deletePage(Uid, ref error);
            if(temp)
                lblError.Text = "Page Permission Deleted";
            else
                lblError.Text = error;
            getGroupPages();
        }
        else if (e.CommandName.Equals("v"))
        {
            int index = int.Parse(e.CommandArgument.ToString());
            string Pid = GridView1.DataKeys[index].Value.ToString();
            string pageName = GridView1.Rows[index].Cells[0].Text;
            pnl_pageFunctions.Visible = true;
            getPageFunctions(Pid);
            getGroupPageFunctions(Pid);
            ViewState["pid"] = Pid;

            lblLegend.Text = pageName;
        }
        else if (e.CommandName.Equals("approve"))
        {
            int index = int.Parse(e.CommandArgument.ToString());
            string Uid = GridView1.DataKeys[index].Value.ToString();
            string error = "";
            bool temp = approvePage(Uid, ref error);
            if (temp)
                lblError.Text = "Page status updated";
            else
                lblError.Text = error;
            getGroupPages();
        }
        else if (e.CommandName.Equals("decline"))
        {
            int index = int.Parse(e.CommandArgument.ToString());
            string Uid = GridView1.DataKeys[index].Value.ToString();
            string error = "";
            bool temp = declinePage(Uid, ref error);
            if (temp)
                lblError.Text = "Page status updated";
            else
                lblError.Text = error;
            getGroupPages();
        }
    }

    protected void btnAdd_Click(object sender, EventArgs e)
    {
        pnlControls.Visible = true;
        pnlGrid.Enabled = false;
    }

    protected void btnCancel_Click(object sender, EventArgs e)
    {
        pnlControls.Visible = false;
        pnlGrid.Enabled = true;
    }

    protected void btnSave_Click(object sender, EventArgs e)
    {
        string error = "";
        bool saved = addPage(ddlPages.SelectedValue, ref error);
        if (saved)
        {
            lblError.Text = "Page Added";
        }
        else
        {
            lblError.Text = error;
        }
        getGroupPages();
        getPages();
        pnlControls.Visible = false;
        pnlGrid.Enabled = true;
    }

    protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
    {
        //if (e.Row.RowType == DataControlRowType.DataRow)
        //{
        //    e.Row.Cells[2].Text = "Approved";
        //}
    }
    
    private void getPageFunctions(string PID)
    {
        string DBConnection = Helper.dbConnection();

        OracleConnection oracon = new OracleConnection(DBConnection);
        oracon.Open();

        OracleCommand oracom = new OracleCommand();
        oracom.Connection = oracon;

        oracom.CommandType = CommandType.StoredProcedure;
        oracom.CommandText = "sec_module_core.get_page_functions";

        oracom.Parameters.Add("p_pid", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_page_fns", OracleType.Cursor).Direction = ParameterDirection.Output;


        oracom.Parameters["p_pid"].Value = PID;

        OracleDataAdapter da = new OracleDataAdapter(oracom);
        DataSet ds = new DataSet();
        da.Fill(ds);

        oracon.Close();

        ddl_pageFunctions.DataSource = ds;
        ddl_pageFunctions.DataBind();
    }

    private void getGroupPageFunctions(string PID)
    {
        string DBConnection = Helper.dbConnection();

        OracleConnection oracon = new OracleConnection(DBConnection);
        oracon.Open();

        OracleCommand oracom = new OracleCommand();
        oracom.Connection = oracon;

        oracom.CommandType = CommandType.StoredProcedure;
        oracom.CommandText = "sec_group_maintain.get_all_group_page_functions";

        oracom.Parameters.Add("p_gid", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_pid", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_functions", OracleType.Cursor).Direction = ParameterDirection.Output;


        oracom.Parameters["p_pid"].Value = PID;
        oracom.Parameters["p_gid"].Value = Request.QueryString["gid"];

        OracleDataAdapter da = new OracleDataAdapter(oracom);
        DataSet ds = new DataSet();
        da.Fill(ds);

        oracon.Close();

        grd_pageFunctions.DataSource = ds;
        grd_pageFunctions.DataBind();

        //GridView2.Visible = true;

        //for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
        //{
        //    string fid = ds.Tables[0].Rows[i][0].ToString();
        //    CheckBoxList1.Items.FindByValue(fid).Selected = true;
        //    CheckBoxList2.Items.FindByValue(fid).Selected = true;
        //}
    }

    //private bool addDeleteFunctions(string pageID, ref string error)
    //{
    //    //format the add and delete arrays
    //    string addList = "", delList = "";
    //    for (int i = 0; i < CheckBoxList1.Items.Count; i++)
    //    {
    //        if (CheckBoxList1.Items[i].Selected && !CheckBoxList2.Items[i].Selected)
    //            addList += CheckBoxList1.Items[i].Value + ";";
    //        if (!CheckBoxList1.Items[i].Selected && CheckBoxList2.Items[i].Selected)
    //            delList += CheckBoxList1.Items[i].Value + ";";
    //    }
    //    delList = delList.TrimEnd(';');
    //    addList = addList.TrimEnd(';');

    //    //call the sotred procedure
    //    string DBConnection = Helper.dbConnection();

    //    OracleConnection oracon = new OracleConnection(DBConnection);
    //    oracon.Open();

    //    OracleCommand oracom = new OracleCommand();
    //    oracom.Connection = oracon;

    //    oracom.CommandType = CommandType.StoredProcedure;
    //    oracom.CommandText = "SEC_GROUP_MAINTAIN.assign_group_pages";

    //    oracom.Parameters.Add("p_current_uid", OracleType.Number).Direction = ParameterDirection.Input;
    //    oracom.Parameters.Add("p_gid", OracleType.Number).Direction = ParameterDirection.Input;
    //    oracom.Parameters.Add("p_pid", OracleType.Number).Direction = ParameterDirection.Input;
    //    oracom.Parameters.Add("p_action", OracleType.VarChar).Direction = ParameterDirection.Input;
    //    oracom.Parameters.Add("p_add_fn_list", OracleType.VarChar).Direction = ParameterDirection.Input;
    //    oracom.Parameters.Add("p_del_fn_list", OracleType.VarChar).Direction = ParameterDirection.Input;
    //    oracom.Parameters.Add("p_lang", OracleType.VarChar).Direction = ParameterDirection.Input;
    //    oracom.Parameters.Add("p_res_code", OracleType.Number).Direction = ParameterDirection.Output;
    //    oracom.Parameters.Add("p_res_type", OracleType.VarChar, 250).Direction = ParameterDirection.Output;
    //    oracom.Parameters.Add("p_res_msg", OracleType.VarChar, 250).Direction = ParameterDirection.Output;

    //    oracom.Parameters["p_gid"].Value = Request.QueryString["gid"];
    //    oracom.Parameters["p_pid"].Value = pageID;
    //    oracom.Parameters["p_action"].Value = "U";
    //    oracom.Parameters["p_add_fn_list"].Value = addList;
    //    oracom.Parameters["p_del_fn_list"].Value = delList;
    //    oracom.Parameters["p_lang"].Value = "EN";
    //    oracom.Parameters["p_current_uid"].Value = Session["uid"].ToString();

    //    oracom.ExecuteNonQuery();
    //    oracon.Close();
    //    string a = oracom.Parameters["p_res_code"].Value.ToString();
    //    error = oracom.Parameters["p_res_msg"].Value.ToString();
    //    if (a == "0")
    //        return true;
    //    else
    //        return false;
    //}
    
    //protected void BtnSaveFUn_Click(object sender, EventArgs e)
    //{
    //    string Pid = ViewState["pid"].ToString();
    //    string error = "";
    //    bool saved = addDeleteFunctions(Pid, ref error);
    //    if (saved)
    //    {
    //        lblError.Text = "Functions Updated";
    //    }
    //    else
    //    {
    //        lblError.Text = error;
    //    }
    //    getGroupPages();
    //    pnlFun.Visible = false;
    //    pnlGrid.Enabled = true;
        
    //}

    private bool approvePage(string pageID, ref string error)
    {
        string DBConnection = Helper.dbConnection();

        OracleConnection oracon = new OracleConnection(DBConnection);
        oracon.Open();

        OracleCommand oracom = new OracleCommand();
        oracom.Connection = oracon;

        oracom.CommandType = CommandType.StoredProcedure;
        oracom.CommandText = "SEC_GROUP_MAINTAIN.approve_sec_page";

        oracom.Parameters.Add("p_current_uid", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_gid", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_pid", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_lang", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_res_code", OracleType.Number).Direction = ParameterDirection.Output;
        oracom.Parameters.Add("p_res_type", OracleType.VarChar, 250).Direction = ParameterDirection.Output;
        oracom.Parameters.Add("p_res_msg", OracleType.VarChar, 250).Direction = ParameterDirection.Output;

        oracom.Parameters["p_gid"].Value = Request.QueryString["gid"];
        oracom.Parameters["p_pid"].Value = pageID;
        oracom.Parameters["p_lang"].Value = "EN";
        oracom.Parameters["p_current_uid"].Value = Session["uid"].ToString();

        oracom.ExecuteNonQuery();
        oracon.Close();
        string a = oracom.Parameters["p_res_code"].Value.ToString();
        error = oracom.Parameters["p_res_msg"].Value.ToString();
        if (a == "0")
            return true;
        else
            return false;
    }

    private bool declinePage(string pageID, ref string error)
    {
        string DBConnection = Helper.dbConnection();

        OracleConnection oracon = new OracleConnection(DBConnection);
        oracon.Open();

        OracleCommand oracom = new OracleCommand();
        oracom.Connection = oracon;

        oracom.CommandType = CommandType.StoredProcedure;
        oracom.CommandText = "SEC_GROUP_MAINTAIN.decline_sec_page";

        oracom.Parameters.Add("p_current_uid", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_gid", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_pid", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_lang", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_res_code", OracleType.Number).Direction = ParameterDirection.Output;
        oracom.Parameters.Add("p_res_type", OracleType.VarChar, 250).Direction = ParameterDirection.Output;
        oracom.Parameters.Add("p_res_msg", OracleType.VarChar, 250).Direction = ParameterDirection.Output;

        oracom.Parameters["p_gid"].Value = Request.QueryString["gid"];
        oracom.Parameters["p_pid"].Value = pageID;
        oracom.Parameters["p_lang"].Value = "EN";
        oracom.Parameters["p_current_uid"].Value = Session["uid"].ToString();

        oracom.ExecuteNonQuery();
        oracon.Close();
        string a = oracom.Parameters["p_res_code"].Value.ToString();
        error = oracom.Parameters["p_res_msg"].Value.ToString();
        if (a == "0")
            return true;
        else
            return false;
    }
    
    private int addFunction(string groupId, string pageId, string functionId, ref string erroMsg)
    {
        string DBConnection = Helper.dbConnection();

        OracleConnection oracon = new OracleConnection(DBConnection);
        oracon.Open();

        OracleCommand oracom = new OracleCommand();
        oracom.Connection = oracon;

        oracom.CommandType = CommandType.StoredProcedure;
        oracom.CommandText = "SEC_GROUP_MAINTAIN.add_group_page_function";

        oracom.Parameters.Add("p_current_uid", OracleType.Number).Direction = ParameterDirection.Input;
        
        oracom.Parameters.Add("p_gid", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_pid", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_fid", OracleType.Number).Direction = ParameterDirection.Input;

        oracom.Parameters.Add("p_lang", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_res_code", OracleType.Number).Direction = ParameterDirection.Output;
        oracom.Parameters.Add("p_res_type", OracleType.VarChar, 250).Direction = ParameterDirection.Output;
        oracom.Parameters.Add("p_res_msg", OracleType.VarChar, 250).Direction = ParameterDirection.Output;

        oracom.Parameters["p_gid"].Value = groupId;
        oracom.Parameters["p_pid"].Value = pageId;
        oracom.Parameters["p_fid"].Value = functionId;
        
        oracom.Parameters["p_lang"].Value = "EN";
        oracom.Parameters["p_current_uid"].Value = Session["uid"].ToString();

        oracom.ExecuteNonQuery();
        oracon.Close();
        string errorCode = oracom.Parameters["p_res_code"].Value.ToString();
        erroMsg = oracom.Parameters["p_res_msg"].Value.ToString();

        return int.Parse(errorCode);
    }
   
    protected void btn_AddFnction_Click(object sender, EventArgs e)
    {
        string groupId = this.Request.QueryString["gid"];
        string pageId = this.ViewState["pid"].ToString();
        string functionId = this.ddl_pageFunctions.SelectedValue.ToString();
        string erroMsg = "";

        int resCode = this.addFunction(groupId, pageId, functionId, ref erroMsg);

        if (resCode == 0)
        {
            this.lblError.Text = "The Function added successfully";

            this.getGroupPageFunctions(this.ViewState["pid"].ToString());
        }
        else
        {
            this.lblError.Text = erroMsg;
        }
    }

    protected void grd_pageFunctions_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        string commandName = e.CommandName;

        int selectedFunctionIndex = int.Parse(e.CommandArgument.ToString());
        string selectedFunctionId = grd_pageFunctions.DataKeys[selectedFunctionIndex].Value.ToString();
        string groupId = this.Request.QueryString["gid"];
        string pageId = this.ViewState["pid"].ToString();

        string errorMsg = "";
        int resCode;

        if (commandName.Equals("del"))
        {
            resCode = this.deleteFunction(groupId, pageId, selectedFunctionId, ref errorMsg);

            if (resCode != 0)
            {
                this.lblError.Text = errorMsg;
            }
        }
        else if (commandName.Equals("approve"))
        {
            resCode = this.approveFunction(groupId, pageId, selectedFunctionId, ref errorMsg);

            if (resCode != 0)
            {
                this.lblError.Text = errorMsg;
            }
        }
        else if (commandName.Equals("decline"))
        {
            resCode = this.declineFunction(groupId, pageId, selectedFunctionId, ref errorMsg);

            if (resCode != 0)
            {
                this.lblError.Text = errorMsg;
            }
        }

        this.getGroupPageFunctions(pageId);

    }

    private int deleteFunction(string groupId, string pageId, string functionId, ref string errorMsg)
    {
        string DBConnection = Helper.dbConnection();

        OracleConnection oracon = new OracleConnection(DBConnection);
        oracon.Open();

        OracleCommand oracom = new OracleCommand();
        oracom.Connection = oracon;

        oracom.CommandType = CommandType.StoredProcedure;
        oracom.CommandText = "SEC_GROUP_MAINTAIN.delete_function";

        oracom.Parameters.Add("p_current_uid", OracleType.Number).Direction = ParameterDirection.Input;

        oracom.Parameters.Add("p_gid", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_pid", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_fid", OracleType.Number).Direction = ParameterDirection.Input;

        oracom.Parameters.Add("p_lang", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_res_code", OracleType.Number).Direction = ParameterDirection.Output;
        oracom.Parameters.Add("p_res_type", OracleType.VarChar, 250).Direction = ParameterDirection.Output;
        oracom.Parameters.Add("p_res_msg", OracleType.VarChar, 250).Direction = ParameterDirection.Output;

        oracom.Parameters["p_gid"].Value = groupId;
        oracom.Parameters["p_pid"].Value = pageId;
        oracom.Parameters["p_fid"].Value = functionId;

        oracom.Parameters["p_lang"].Value = "EN";
        oracom.Parameters["p_current_uid"].Value = Session["uid"].ToString();

        oracom.ExecuteNonQuery();
        oracon.Close();
        string errorCode = oracom.Parameters["p_res_code"].Value.ToString();
        errorMsg = oracom.Parameters["p_res_msg"].Value.ToString();

        return int.Parse(errorCode);
    }

    private int declineFunction(string groupId, string pageId, string functionId, ref string errorMsg)
    {
        string DBConnection = Helper.dbConnection();

        OracleConnection oracon = new OracleConnection(DBConnection);
        oracon.Open();

        OracleCommand oracom = new OracleCommand();
        oracom.Connection = oracon;

        oracom.CommandType = CommandType.StoredProcedure;
        oracom.CommandText = "SEC_GROUP_MAINTAIN.decline_sec_function";

        oracom.Parameters.Add("p_current_uid", OracleType.Number).Direction = ParameterDirection.Input;

        oracom.Parameters.Add("p_gid", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_pid", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_fid", OracleType.Number).Direction = ParameterDirection.Input;

        oracom.Parameters.Add("p_lang", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_res_code", OracleType.Number).Direction = ParameterDirection.Output;
        oracom.Parameters.Add("p_res_type", OracleType.VarChar, 250).Direction = ParameterDirection.Output;
        oracom.Parameters.Add("p_res_msg", OracleType.VarChar, 250).Direction = ParameterDirection.Output;

        oracom.Parameters["p_gid"].Value = groupId;
        oracom.Parameters["p_pid"].Value = pageId;
        oracom.Parameters["p_fid"].Value = functionId;

        oracom.Parameters["p_lang"].Value = "EN";
        oracom.Parameters["p_current_uid"].Value = Session["uid"].ToString();

        oracom.ExecuteNonQuery();
        oracon.Close();
        string errorCode = oracom.Parameters["p_res_code"].Value.ToString();
        errorMsg = oracom.Parameters["p_res_msg"].Value.ToString();

        return int.Parse(errorCode);
    }

    private int approveFunction (string groupId, string pageId, string functionId, ref string errorMsg)
    {
        string DBConnection = Helper.dbConnection();

        OracleConnection oracon = new OracleConnection(DBConnection);
        oracon.Open();

        OracleCommand oracom = new OracleCommand();
        oracom.Connection = oracon;

        oracom.CommandType = CommandType.StoredProcedure;
        oracom.CommandText = "SEC_GROUP_MAINTAIN.approve_sec_function";

        oracom.Parameters.Add("p_current_uid", OracleType.Number).Direction = ParameterDirection.Input;

        oracom.Parameters.Add("p_gid", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_pid", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_fid", OracleType.Number).Direction = ParameterDirection.Input;

        oracom.Parameters.Add("p_lang", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_res_code", OracleType.Number).Direction = ParameterDirection.Output;
        oracom.Parameters.Add("p_res_type", OracleType.VarChar, 250).Direction = ParameterDirection.Output;
        oracom.Parameters.Add("p_res_msg", OracleType.VarChar, 250).Direction = ParameterDirection.Output;

        oracom.Parameters["p_gid"].Value = groupId;
        oracom.Parameters["p_pid"].Value = pageId;
        oracom.Parameters["p_fid"].Value = functionId;

        oracom.Parameters["p_lang"].Value = "EN";
        oracom.Parameters["p_current_uid"].Value = Session["uid"].ToString();

        oracom.ExecuteNonQuery();
        oracon.Close();
        string errorCode = oracom.Parameters["p_res_code"].Value.ToString();
        errorMsg = oracom.Parameters["p_res_msg"].Value.ToString();

        return int.Parse(errorCode);
    }
   
}
