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;
using System.Diagnostics;

public partial class Business_GLSetup : System.Web.UI.Page
{
    public int page_id = 0;
    public string table_name = "";
    public string table_name2="";
    string url = "";
    static int intCount = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        table_name = "GL_ACCT_TABLE"; //gl_acct_table
        table_name2 = "GL_BUSINESS_RULES"; //gl_business_rules
        url = HttpContext.Current.Request.Url.AbsolutePath;
        string[] urlArr = url.Split('/');
        url = urlArr[2] + "/" + urlArr[3];
        page_id = loadPageIDs(url);
        if (!IsPostBack)
        {
            SecurityAgent.AuthenticateArchive();
            loadChannels();
            loadEvents();
            loadChannelTypes();
            loadMatchResult();
            channelsRow.Visible = false;
            channelsRow1.Visible = false;
            ExceptionUtility.LogException(0, "", "14", "Page_Load", "");
        }
        lblError.Text = "";
      
        txtAccount.MaxLength = int.Parse (getParamByID ("300"));
    }

    private int loadPageIDs(string URL)
    {
        try
        {
            string DBConnection = Helper.dbConnection();

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

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

            oracom.CommandType = CommandType.StoredProcedure;
            oracom.CommandText = "lookup_getter.get_pages";

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


            oracom.Parameters["p_url"].Value = URL;

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

            oracon.Close();
            return int.Parse(ds.Tables[0].Rows[0]["pid"].ToString());
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "lookup_getter.get_pages","", "loadPageIDs", "URL: " + URL );
            //Response.Redirect("../ErrorPages/ErrorPage.aspx");
            return 0;
        }
    }

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

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

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

            oracom.CommandType = CommandType.StoredProcedure;
            oracom.CommandText = "LOOKUP_GETTER.Get_Match_Result";

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

            oracom.Parameters["p_ch_type"].Value = ddlType2.SelectedValue;

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

            ddlMatchResult.DataSource = ds;
            ddlMatchResult.DataBind();
            oracon.Close();
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "LOOKUP_GETTER.Get_Match_Result","", "loadMatchResult", "");
            //Response.Redirect("../ErrorPages/ErrorPage.aspx");
        }
    }

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

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

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

            oracom.CommandType = CommandType.StoredProcedure;
            oracom.CommandText = "LOOKUP_GETTER.Get_Recon_Channels";

            oracom.Parameters.Add("p_recon_channels", OracleType.Cursor).Direction = ParameterDirection.Output;

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

            ddlChannels.DataSource = ds;
            ddlChannels.DataBind();
            DropDownList2.DataSource = ds;
            DropDownList2.DataBind();


            ddlChannels.Items.Insert(0, "------ Channels ------");
            DropDownList2.Items.Insert(0, "------ Channels ------");
            oracon.Close();
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "LOOKUP_GETTER.Get_Recon_Channels","", "loadChannels", "");
            //Response.Redirect("../ErrorPages/ErrorPage.aspx");
        }
    }

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

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

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

            oracom.CommandType = CommandType.StoredProcedure;
            oracom.CommandText = "LOOKUP_GETTER.Get_Recon_Events";

            oracom.Parameters.Add("p_recon_events", OracleType.Cursor).Direction = ParameterDirection.Output;

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

            ddlEvents.DataSource = ds;
            ddlEvents.DataBind();
            DropDownList1.DataSource = ds;
            DropDownList1.DataBind();

            ddlEvents.Items.Insert(0, "------ Events ------");
            DropDownList1.Items.Insert(0, "------ Events ------");
            oracon.Close();
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "LOOKUP_GETTER.Get_Recon_Events","", "loadEvents", "");
            //Response.Redirect("../ErrorPages/ErrorPage.aspx");
        }
    }

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

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

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

            oracom.CommandType = CommandType.StoredProcedure;
            oracom.CommandText = "LOOKUP_GETTER.get_gsetup_channel_types";

            oracom.Parameters.Add("p_ch_types", OracleType.Cursor).Direction = ParameterDirection.Output;

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

            ddlType.DataSource = ds;
            ddlType.DataBind();
            ddlType2.DataSource = ds;
            ddlType2.DataBind();
            oracon.Close();
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "LOOKUP_GETTER.get_gsetup_channel_types","", "loadChannelTypes", "");
            //Response.Redirect("../ErrorPages/ErrorPage.aspx");
        }
    }

    private void loadResult(string ChannelID, string EventID, int pageSize, int pageNumber)
    {
        string parameters = "";
        try
        {
            string currentMethod = "";
            StackTrace stackTrace = new StackTrace();
            currentMethod = stackTrace.GetFrame(1).GetMethod().Name;
            string DBConnection = Helper.dbConnection();

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

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

            oracom.CommandType = CommandType.StoredProcedure;
            oracom.CommandText = "GL_SETUP_EDITOR.Get_GL_Setup_Info";


            oracom.Parameters.Add("p_current_uid", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_re_code", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_rc_code", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_ch_type", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_page_size", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_page_num", 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.Add("p_output", OracleType.Cursor).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_total_pages", OracleType.Number).Direction = ParameterDirection.Output;

            if (rdChannel.Checked)
            {
                oracom.Parameters["p_rc_code"].Value = ChannelID;
                oracom.Parameters["p_ch_type"].Value = "3";
                oracom.Parameters["p_re_code"].Value = OracleNumber.Null;
                parameters = "p_rc_code-" + ChannelID + ":p_ch_type-3:";
            }

            if (rdEvent.Checked)
            {
                oracom.Parameters["p_re_code"].Value = EventID;
                oracom.Parameters["p_ch_type"].Value = ddlType.SelectedValue;
                oracom.Parameters["p_rc_code"].Value = OracleNumber.Null;
                parameters = parameters + "p_re_code-" + EventID + ":p_ch_type-" + ddlType.SelectedItem.Text;
            }

            if (rdPOS1.Checked)
            {
                oracom.Parameters["p_rc_code"].Value = ChannelID;
                oracom.Parameters["p_ch_type"].Value = "6";
                oracom.Parameters["p_re_code"].Value = OracleNumber.Null;
                parameters = parameters + "p_rc_code-" + ChannelID + ":p_ch_type-6";
            }

            //if (rdPOS2.Checked)
            //{
            //    oracom.Parameters["p_rc_code"].Value = OracleNumber.Null;
            //    oracom.Parameters["p_ch_type"].Value = "7";
            //    oracom.Parameters["p_re_code"].Value = OracleNumber.Null;
            //}


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

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

            int nop = int.Parse(oracom.Parameters["p_total_pages"].Value.ToString());
            oracon.Close();

            GridView1.DataSource = ds;
            GridView1.DataBind();
            if (pageNumber == 1)
            {
                ddlPages.Items.Clear();
                for (int i = 1; i <= nop; i++)
                {
                    ddlPages.Items.Add(i.ToString());
                }
            }
            if (currentMethod.Contains("getSetup"))
                ExceptionUtility.LogException(0, "GL_SETUP_EDITOR.Get_GL_Setup_Info", "27.1.1", "loadResult", parameters);
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "GL_SETUP_EDITOR.Get_GL_Setup_Info","27.1.1", "loadResult",parameters );
            GridView1.DataSource = null ;
            GridView1.DataBind();
            //Response.Redirect("../ErrorPages/ErrorPage.aspx");
        }
    }

    private DataSet loadGL(string gaCode)
    {
        try
        {
            string DBConnection = Helper.dbConnection();

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

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

            oracom.CommandType = CommandType.StoredProcedure;
            oracom.CommandText = "GL_SETUP_EDITOR.Get_GL_Setup_details";


            oracom.Parameters.Add("p_current_uid", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_ga_code", 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.Add("p_output", OracleType.Cursor).Direction = ParameterDirection.Output;



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

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

            oracon.Close();
            ExceptionUtility.LogException(0, "GL_SETUP_EDITOR.Get_GL_Setup_details", "", "loadGL", "gaCode: " + gaCode);
            return ds;
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "GL_SETUP_EDITOR.Get_GL_Setup_details","", "loadGL", "gaCode: " + gaCode );
            //Response.Redirect("../ErrorPages/ErrorPage.aspx");
            return null;

        }
    }


    protected void Button1_Click(object sender, EventArgs e)
    {
        if (ddlChannels.SelectedIndex == 0 && rdChannel.Checked)
        {
            ExceptionUtility.LogException(0, "", "14.27", "Button1_Click", "");
            lblError.Text = "You must choose a Channel";
        }
        else if (ddlEvents.SelectedIndex == 0 && rdEvent.Checked)
        {
            ExceptionUtility.LogException(0, "", "14.27", "Button1_Click", "");
            lblError.Text = "You must choose an Event";
        }
        else if (ddlChannels.SelectedIndex == 0 && rdPOS1.Checked)
        {
            ExceptionUtility.LogException(0, "", "14.27", "Button1_Click", "");
            lblError.Text = "You must choose an Channel";
        }
        else
        {
            ExceptionUtility.LogException(0, "", "14.27", "Button1_Click", "");
            getSetup();
        }
    }

    private void getSetup()
    {
        try
        {
            string currentMethod = "";
            StackTrace stackTrace = new StackTrace();
            currentMethod = stackTrace.GetFrame(1).GetMethod().Name;
            string channelID = "", EventID = "";
            if (rdChannel.Checked || rdPOS1.Checked)
                channelID = ddlChannels.SelectedValue;
            else
                EventID = ddlEvents.SelectedValue;
            pnlResult.Visible = true;
            pnlControls.Visible = false;
            pnlResult.Enabled = true;
            if(currentMethod .Contains ("Button1_Click"))
                ExceptionUtility.LogException(0, "", "27.1", "getSetup", "");
            loadResult(channelID, EventID, Helper.gridSize(), 1);
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "", "27.1", "getSetup()", "");
        }
    }

    protected void ddlPages_SelectedIndexChanged(object sender, EventArgs e)
    {
        string channelID = "", EventID = "";
        if (rdChannel.Checked)
            channelID = ddlChannels.SelectedValue;
        else
            EventID = ddlEvents.SelectedValue;
        pnlResult.Visible = true;
        pnlControls.Visible = false;
        pnlResult.Enabled = true;
        ExceptionUtility.LogException(0, "", "", "ddlPages_SelectedIndexChanged", "");
        loadResult(channelID, EventID, Helper.gridSize(), int.Parse(ddlPages.SelectedValue));
    }

    protected void btnAdd_Click(object sender, EventArgs e)
    {
        intCount = 0;
        txtAccount.Enabled = true;

        pnlControls.Visible = true;
        pnlResult.Enabled = false;
        ViewState["mode"] = "a";

        row1.Visible = false;
        rdChannels1.Checked = rdChannel.Checked;
        rdEvents1.Checked = rdEvent.Checked;
        rdPOS11.Checked = rdPOS1.Checked;
        //rdPOS22.Checked = rdPOS2.Checked;

        DropDownList1.SelectedIndex = ddlEvents.SelectedIndex;
        DropDownList2.SelectedIndex = ddlChannels.SelectedIndex;
        ddlType2.SelectedIndex = ddlType.SelectedIndex;
        loadMatchResult();
        if (rdChannels1.Checked || rdPOS11.Checked)
        {
            eventsRow1.Visible = false;
            channelsRow1.Visible = true;
        }
        else if (rdEvents1.Checked)
        {
            eventsRow1.Visible = true;
            channelsRow1.Visible = false;
        }
        else
        {
            eventsRow1.Visible = false;
            channelsRow1.Visible = false;
        }
        ExceptionUtility.LogException(0, "", "14.28", "btnAdd_Click", "");
    }

    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.Equals("a"))
        {
            int index = int.Parse(e.CommandArgument.ToString());
            string error = "";
            ExceptionUtility.LogException(0, "", "14.29", "GridView1_RowCommand.PostingRequired", "");
            bool saved = GLPostingRequired("1", index, ref error);
            if (saved)
            {
                lblError.Text = "Record Updated";
            }
            else
            {
                if (Helper.OracleError(error))
                {
                    lblError.Text = "An Error Occured!";
                    ExceptionUtility.LogException(9, "", "14.29", "GridView1_RowCommand.PostingRequired", error);
                }
                else
                    lblError.Text = error;
            }
        }
        else if (e.CommandName.Equals("r"))
        {
            int index = int.Parse(e.CommandArgument.ToString());
            string error = "";
            ExceptionUtility.LogException(0, "", "14.30", "GridView1_RowCommand.PostingNotRequired", "");
            bool saved = GLPostingRequired("0", index, ref error);
            if (saved)
            {
                lblError.Text = "Record Updated";
            }
            else
            {
                if (Helper.OracleError(error))
                {
                    lblError.Text = "An Error Occured!";
                    ExceptionUtility.LogException(9, "", "14.29", "GridView1_RowCommand.PostingRequired", error);
                }
                else
                    lblError.Text = error;
            }
        }
        else if (e.CommandName.Equals("e"))
        {
            intCount = 0;
            pnlControls.Visible = true;
            pnlResult.Enabled = false;
            ExceptionUtility.LogException(0, "", "14.31", "GridView1_RowCommand.Edit", "");
            int index = int.Parse(e.CommandArgument.ToString());
            string rowID = GridView1.DataKeys[index].Value.ToString();
            string eventID = GridView1.Rows[index].Cells[1].Text.ToString();
            string channelID = GridView1.Rows[index].Cells[0].Text.ToString();
            string account = GridView1.Rows[index].Cells[6].Text.ToString();
            string match = GridView1.Rows[index].Cells[7].Text.ToString();
            string AccName = GridView1.Rows[index].Cells[3].Text.ToString();
            string chType = GridView1.Rows[index].Cells[18].Text.ToString();

            if(!eventID.Equals("&nbsp;"))
                DropDownList1.SelectedValue = eventID;
            if (!channelID.Equals("&nbsp;"))
            DropDownList2.SelectedValue = channelID;

            if (rdEvent.Checked)
            {
                if (!chType.Equals("&nbsp;"))
                    ddlType2.SelectedValue = chType;
                loadMatchResult();
                ddlMatchResult.SelectedValue = match;
            }
            txtAccount.Text = account;
            //txtAccount.Enabled = false;
            
            txtAccountName.Text = AccName;

            ViewState["mode"] = "u";
            ViewState["rowid"] = rowID;

            row1.Visible = false;
            eventsRow1.Visible = false;
            channelsRow1.Visible = false;
            return;
        }
        else if (e.CommandName.Equals("d"))
        {
            int index = int.Parse(e.CommandArgument.ToString());
            string rowID = GridView1.DataKeys[index].Value.ToString();
            string error = "";
            int chgId = loadChgID();
            ExceptionUtility.LogException(0, "", "14.154", "GridView1_RowCommand.Delete", "");
            bool temp = UpdateMakerChecker(chgId, rowID,table_name, "GA_CODE", rowID, "", "", "", 2, ref error);//ga_code
            //bool saved = deleteGL(rowID, ref error);

            if (temp)
            {
                lblError.Text = "Your request has been sent to Checker user for Approval";
            }
            else
            {
                if (Helper.OracleError(error))
                {
                    lblError.Text = "An Error Occured!";
                    ExceptionUtility.LogException(9, "", "14.154", "GridView1_RowCommand.Delete", error);
                }
                else
                    lblError.Text = error;
            }
        }
        else if (e.CommandName.Equals("vm"))
        {
            pnlControls .Visible = false;
            int index = int.Parse(e.CommandArgument.ToString());
            string rowID = GridView1.DataKeys[index].Value.ToString();
            int chgId = loadMaxChgID(rowID);
            Response.Redirect("Checker.aspx?chgId=" + chgId);

        }

        getSetup();
    }

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

    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (intCount < 1)
            intCount++;
        else
        {
            pnlControls.Visible = false;
            lblError.Text = "Your request has been sent to Checker user for Approval";
            return;
        }
        try
        {
                string mode = ViewState["mode"].ToString();
                string error = "";
                string RE_CODE_NEW="", RE_CODE_DESC_NEW="", GL_CHANNEL_TYPE_NEW="", GL_CHANNEL_TYPE_DESC_NEW="", RE_MATCH_RESULT_NEW="", RE_MATCH_RESULT_DESC_NEW="", RC_CODE_NEW="", RC_CODE_DESC_NEW="", ACCT_NUMBER_NEW="", ACCT_NAME_NEW="",GL_TYPE_NEW="",ACCT_TYPE_NEW="";
                string RE_CODE_OLD="", RE_CODE_DESC_OLD="", GL_CHANNEL_TYPE_OLD="", GL_CHANNEL_TYPE_DESC_OLD="", RE_MATCH_RESULT_OLD="", RE_MATCH_RESULT_DESC_OLD="", RC_CODE_OLD="", RC_CODE_DESC_OLD="", ACCT_NUMBER_OLD="", ACCT_NAME_OLD="";
                
                if (rdEvents1.Checked)
                {
                    RE_CODE_NEW = DropDownList1.SelectedValue;
                    RE_CODE_DESC_NEW = DropDownList1.SelectedItem.Text;
                    GL_CHANNEL_TYPE_NEW = ddlType2.SelectedValue;
                    GL_CHANNEL_TYPE_DESC_NEW = ddlType2.SelectedItem.Text;
                    RE_MATCH_RESULT_NEW = ddlMatchResult.SelectedValue;
                    RE_MATCH_RESULT_DESC_NEW = ddlMatchResult.SelectedItem.Text;
                    RC_CODE_NEW = "";
                    RC_CODE_DESC_NEW = "";
                }
                if (rdChannels1.Checked)
                {
                    RE_CODE_NEW = "";
                    RE_CODE_DESC_NEW ="";
                    GL_CHANNEL_TYPE_NEW = "3";
                    GL_CHANNEL_TYPE_DESC_NEW = "channel Gl";
                    RE_MATCH_RESULT_NEW = "";
                    RE_MATCH_RESULT_DESC_NEW = "";
                    RC_CODE_NEW = DropDownList2.SelectedValue;
                    RC_CODE_DESC_NEW = DropDownList2.SelectedItem.Text;

                }
                if (rdPOS11.Checked)
                {

                    RE_CODE_NEW = "";
                    RE_CODE_DESC_NEW = "";
                    GL_CHANNEL_TYPE_NEW = "6";
                    GL_CHANNEL_TYPE_DESC_NEW = "POS Settlement GL";
                    RE_MATCH_RESULT_NEW = "";
                    RE_MATCH_RESULT_DESC_NEW = "";
                    RC_CODE_NEW = DropDownList2.SelectedValue;
                    RC_CODE_DESC_NEW = DropDownList2.SelectedItem.Text;

                }
                if (rdPOS22.Checked)
                {
                    RE_CODE_NEW = "";
                    RE_CODE_DESC_NEW = "";
                    GL_CHANNEL_TYPE_NEW = "7";
                    GL_CHANNEL_TYPE_DESC_NEW = "POS Rental Fees";
                    RE_MATCH_RESULT_NEW = "";
                    RE_MATCH_RESULT_DESC_NEW = "";
                    RC_CODE_NEW = "";
                    RC_CODE_DESC_NEW = "";

                }
                ACCT_NUMBER_NEW = txtAccount.Text.Trim();
                ACCT_NAME_NEW = txtAccountName.Text.Trim();
                //if (GL_CHANNEL_TYPE_NEW == "1" || GL_CHANNEL_TYPE_NEW == "2" || GL_CHANNEL_TYPE_NEW == "4")
                //{
                //    GL_TYPE_NEW = "1";
                //    ACCT_TYPE_NEW = "1";
                //}
                //else if (GL_CHANNEL_TYPE_NEW == "8")
                //{
                //    GL_TYPE_NEW = "3";
                //    ACCT_TYPE_NEW = "3";
                //}
                //else if (GL_CHANNEL_TYPE_NEW == "3")
                //{
                //    GL_TYPE_NEW = "2";
                //    ACCT_TYPE_NEW = "2";
                //}
                //else
                //{
                //    GL_TYPE_NEW = "4";
                //    ACCT_TYPE_NEW = "4";
                //}
                if (mode.Equals("a"))
                {
                    int chgId = loadChgID();
                    string pkey = loadGLId();
                    string pkey2 = loadGBRId();
                    bool saved = false;
                    //adding records for the primary table (gl_accnt_table)
                    saved = UpdateMakerChecker(chgId, pkey, table_name, "RE_CODE", "", RE_CODE_DESC_NEW, "", RE_CODE_NEW, 0, ref error);
                    if (saved == false)
                    {
                        if (Helper.OracleError(error))
                        {
                            lblError.Text = "An Error Occured!";
                            ExceptionUtility.LogException(9, "", "", "btnSave_Click", error);
                        }
                        else
                            lblError.Text = error;
                        return;
                    }
                    saved = UpdateMakerChecker(chgId, pkey, table_name, "GL_CHANNEL_TYPE", "", GL_CHANNEL_TYPE_DESC_NEW, "", GL_CHANNEL_TYPE_NEW, 0, ref error);
                    if (saved == false)
                    {
                        if (Helper.OracleError(error))
                        {
                            lblError.Text = "An Error Occured!";
                            ExceptionUtility.LogException(9, "", "", "btnSave_Click", error);
                        }
                        else
                            lblError.Text = error;
                        return;
                    }
                    saved = UpdateMakerChecker(chgId, pkey, table_name, "RE_MATCH_RESULT", "", RE_MATCH_RESULT_DESC_NEW, "", RE_MATCH_RESULT_NEW, 0, ref error);
                    if (saved == false)
                    {
                        if (Helper.OracleError(error))
                        {
                            lblError.Text = "An Error Occured!";
                            ExceptionUtility.LogException(9, "", "", "btnSave_Click", error);
                        }
                        else
                            lblError.Text = error;
                        return;
                    }
                    saved = UpdateMakerChecker(chgId, pkey, table_name, "RC_CODE", "", RC_CODE_DESC_NEW, "", RC_CODE_NEW, 0, ref error);
                    if (saved == false)
                    {
                        if (Helper.OracleError(error))
                        {
                            lblError.Text = "An Error Occured!";
                            ExceptionUtility.LogException(9, "", "", "btnSave_Click", error);
                        }
                        else
                            lblError.Text = error;
                        return;
                    }
                    saved = UpdateMakerChecker(chgId, pkey, table_name, "ACCT_NUMBER", "", ACCT_NUMBER_NEW, "", "", 0, ref error);
                    if (saved == false)
                    {
                        if (Helper.OracleError(error))
                        {
                            lblError.Text = "An Error Occured!";
                            ExceptionUtility.LogException(9, "", "", "btnSave_Click", error);
                        }
                        else
                            lblError.Text = error;
                        return;
                    }
                    saved = UpdateMakerChecker(chgId, pkey, table_name, "ACCT_NAME", "", ACCT_NAME_NEW, "", "", 0, ref error);
                    if (saved == false)
                    {
                        if (Helper.OracleError(error))
                        {
                            lblError.Text = "An Error Occured!";
                            ExceptionUtility.LogException(9, "", "", "btnSave_Click", error);
                        }
                        else
                            lblError.Text = error;
                        return;
                    }
                    saved = UpdateMakerChecker(chgId, pkey, table_name, "ACCT_TYPE", "", ACCT_TYPE_NEW, "", "", 0, ref error);
                    if (saved == false)
                    {
                        if (Helper.OracleError(error))
                        {
                            lblError.Text = "An Error Occured!";
                            ExceptionUtility.LogException(9, "", "", "btnSave_Click", error);
                        }
                        else
                            lblError.Text = error;
                        return;
                    }
                    saved = UpdateMakerChecker(chgId, pkey, table_name, "STATUS", "", "1", "", "", 0, ref error);
                    if (saved == false)
                    {
                        if (Helper.OracleError(error))
                        {
                            lblError.Text = "An Error Occured!";
                            ExceptionUtility.LogException(9, "", "", "btnSave_Click", error);
                        }
                        else
                            lblError.Text = error;
                        return;
                    }
                    saved = UpdateMakerChecker(chgId, pkey, table_name, "CREATED_BY", "", Session["uid"].ToString(), "", "", 0, ref error);
                    if (saved == false)
                    {
                        if (Helper.OracleError(error))
                        {
                            lblError.Text = "An Error Occured!";
                            ExceptionUtility.LogException(9, "", "", "btnSave_Click", error);
                        }
                        else
                            lblError.Text = error;
                        return;
                    }
                    saved = UpdateMakerChecker(chgId, pkey, table_name, "MODIFIED_BY", "", Session["uid"].ToString(), "", "", 0, ref error);
                    if (saved == false)
                    {
                        if (Helper.OracleError(error))
                        {
                            lblError.Text = "An Error Occured!";
                            ExceptionUtility.LogException(9, "", "", "btnSave_Click", error);
                        }
                        else
                            lblError.Text = error;
                        return;
                    }
                    //bool saved = addGL(ref error);
                    //Adding records for the secondary table (gl_business_rule)
                    saved = UpdateMakerChecker(chgId, pkey2, table_name2, "RE_CODE", "", RE_CODE_DESC_NEW, "", RE_CODE_NEW, 0, ref error);
                    if (saved == false)
                    {
                        if (Helper.OracleError(error))
                        {
                            lblError.Text = "An Error Occured!";
                            ExceptionUtility.LogException(9, "", "", "btnSave_Click", error);
                        }
                        else
                            lblError.Text = error;
                        return;
                    }
                    saved = UpdateMakerChecker(chgId, pkey2, table_name2, "GL_CHANNEL_TYPE", "", GL_CHANNEL_TYPE_DESC_NEW, "", GL_CHANNEL_TYPE_NEW, 0, ref error);
                    if (saved == false)
                    {
                        if (Helper.OracleError(error))
                        {
                            lblError.Text = "An Error Occured!";
                            ExceptionUtility.LogException(9, "", "", "btnSave_Click", error);
                        }
                        else
                            lblError.Text = error;
                        return;
                    }
                    saved = UpdateMakerChecker(chgId, pkey2, table_name2, "RE_MATCH_RESULT", "", RE_MATCH_RESULT_DESC_NEW, "", RE_MATCH_RESULT_NEW, 0, ref error);
                    if (saved == false)
                    {
                        if (Helper.OracleError(error))
                        {
                            lblError.Text = "An Error Occured!";
                            ExceptionUtility.LogException(9, "", "", "btnSave_Click", error);
                        }
                        else
                            lblError.Text = error;
                        return;
                    }
                    saved = UpdateMakerChecker(chgId, pkey2, table_name2, "RC_CODE", "", RC_CODE_DESC_NEW, "", RC_CODE_NEW, 0, ref error);
                    if (saved == false)
                    {
                        if (Helper.OracleError(error))
                        {
                            lblError.Text = "An Error Occured!";
                            ExceptionUtility.LogException(9, "", "", "btnSave_Click", error);
                        }
                        else
                            lblError.Text = error;
                        return;
                    }
                    saved = UpdateMakerChecker(chgId, pkey2, table_name2, "CREATED_BY", "", Session["uid"].ToString(), "", "", 0, ref error);
                    if (saved == false)
                    {
                        if (Helper.OracleError(error))
                        {
                            lblError.Text = "An Error Occured!";
                            ExceptionUtility.LogException(9, "", "", "btnSave_Click", error);
                        }
                        else
                            lblError.Text = error;
                        return;
                    }
                    saved = UpdateMakerChecker(chgId, pkey2, table_name2, "MODIFIED_BY", "", Session["uid"].ToString(), "", "", 0, ref error);
                    if (saved == false)
                    {
                        if (Helper.OracleError(error))
                        {
                            lblError.Text = "An Error Occured!";
                            ExceptionUtility.LogException(9, "", "", "btnSave_Click", error);
                        }
                        else
                            lblError.Text = error;
                        return;
                    }

                    lblError.Text = "Your request has been sent to Checker user for Approval";
                  
                }
                else if (mode.Equals("u"))
                {
                    string Uid = ViewState["rowid"].ToString();
                    int chgId = loadChgID();
                    bool compare = false;
                    DataSet ds = loadGL(Uid);
                    //bool saved = updateGL(Uid, ref error);
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        RE_CODE_OLD = ds.Tables[0].Rows[0]["re_code"].ToString();
                        RE_CODE_DESC_OLD = ds.Tables[0].Rows[0]["event"].ToString();
                        GL_CHANNEL_TYPE_OLD = ds.Tables[0].Rows[0]["gl_channel_type"].ToString();
                        GL_CHANNEL_TYPE_DESC_OLD = ds.Tables[0].Rows[0]["channel_type"].ToString();
                        RE_MATCH_RESULT_OLD = ds.Tables[0].Rows[0]["re_match_result"].ToString();
                        RE_MATCH_RESULT_DESC_OLD = ds.Tables[0].Rows[0]["match_result"].ToString();
                        RC_CODE_OLD = ds.Tables[0].Rows[0]["rc_code"].ToString();
                        RC_CODE_DESC_OLD = ds.Tables[0].Rows[0]["channel"].ToString();
                        ACCT_NAME_OLD = ds.Tables[0].Rows[0]["acct_name"].ToString();
                        ACCT_NUMBER_OLD = ds.Tables[0].Rows[0]["acct_number"].ToString();
                        if (RE_CODE_OLD == RE_CODE_NEW && GL_CHANNEL_TYPE_OLD == GL_CHANNEL_TYPE_NEW &&
                            RE_MATCH_RESULT_OLD == RE_MATCH_RESULT_NEW && RC_CODE_OLD == RC_CODE_NEW &&
                            ACCT_NUMBER_NEW == ACCT_NUMBER_OLD && ACCT_NAME_NEW == ACCT_NAME_OLD)
                            compare = true;
                        if (compare == false)
                        {
                            bool update = false;
                            //if (RE_CODE_OLD != RE_CODE_NEW)
                            //    update = UpdateMakerChecker(chgId, Uid ,table_name, "re_code", RE_CODE_DESC_OLD, RE_CODE_DESC_NEW, RE_CODE_OLD, RE_CODE_NEW, 1, ref error);
                            //if(GL_CHANNEL_TYPE_OLD!=GL_CHANNEL_TYPE_NEW )
                            //    update = UpdateMakerChecker(chgId, Uid, table_name, "gl_channel_type", GL_CHANNEL_TYPE_DESC_OLD, GL_CHANNEL_TYPE_DESC_NEW, GL_CHANNEL_TYPE_OLD, GL_CHANNEL_TYPE_NEW, 1, ref error);
                            //if(RE_MATCH_RESULT_OLD!=RE_MATCH_RESULT_DESC_NEW)
                            //    update = UpdateMakerChecker(chgId, Uid,table_name, "re_match_result", RE_MATCH_RESULT_DESC_OLD, RE_MATCH_RESULT_DESC_NEW, RE_MATCH_RESULT_OLD, RE_MATCH_RESULT_NEW, 1, ref error);
                            //if(RC_CODE_OLD!=RC_CODE_NEW)
                            //    update = UpdateMakerChecker(chgId, Uid,table_name, "rc_code", RC_CODE_DESC_OLD, RC_CODE_DESC_NEW, RC_CODE_OLD, RC_CODE_NEW, 1, ref error);
                            if (ACCT_NUMBER_OLD != ACCT_NUMBER_NEW)
                            {
                                update = UpdateMakerChecker(chgId, Uid, table_name, "ACCT_NUMBER", ACCT_NUMBER_OLD, ACCT_NUMBER_NEW, "", "", 1, ref error);//acct_number
                                if (update == false)
                                {
                                    if (Helper.OracleError(error))
                                    {
                                        lblError.Text = "An Error Occured!";
                                        ExceptionUtility.LogException(9, "", "", "btnSave_Click", error);
                                    }
                                    else
                                        lblError.Text = error;
                                    return;
                                }
                            }
                            if (ACCT_NAME_OLD != ACCT_NAME_NEW)
                            {
                                update = UpdateMakerChecker(chgId, Uid, table_name, "ACCT_NAME", ACCT_NAME_OLD, ACCT_NAME_NEW, "", "", 1, ref error);//acct_name
                                if (update == false)
                                {
                                    if (Helper.OracleError(error))
                                    {
                                        lblError.Text = "An Error Occured!";
                                        ExceptionUtility.LogException(9, "", "", "btnSave_Click", error);
                                    }
                                    else
                                        lblError.Text = error;
                                    return;
                                }
                            }

                            lblError.Text = "Your request has been sent to Checker user for Approval";
                           
                        }
                    }
                }
                getSetup();
                ViewState["mode"] = null;
                ViewState["rowid"] = null;
                pnlControls.Visible = false;
                pnlResult.Enabled = true;
                ExceptionUtility.LogException(0, "", "", "btnSave_Click", "");
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "", "", "btnSave_Click", "");
            //Response.Redirect("../ErrorPages/ErrorPage.aspx");
        }
    }
    private string loadGLId()
    {
        try
        {
            string DBConnection = Helper.dbConnection();

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

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

            oracom.CommandType = CommandType.StoredProcedure;
            oracom.CommandText = "gl_setup_editor.get_gl_id";

            oracom.Parameters.Add("v_gl_id", OracleType.Number).Direction = ParameterDirection.ReturnValue;

            oracom.ExecuteNonQuery();
            oracon.Close();

            string paramId = oracom.Parameters["v_gl_id"].Value.ToString();
            oracon.Close();
            ExceptionUtility.LogException(0, "gl_setup_editor.get_gl_id", "", "loadGLId", "");
            return paramId;
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "gl_setup_editor.get_gl_id","", "loadGLId", "");
            //Response.Redirect("../ErrorPages/ErrorPage.aspx");
            return null;
        }
    }
    private string loadGBRId()
    {
        try
        {
            string DBConnection = Helper.dbConnection();

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

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

            oracom.CommandType = CommandType.StoredProcedure;
            oracom.CommandText = "gl_setup_editor.get_gbr_id";

            oracom.Parameters.Add("v_gbr_id", OracleType.Number).Direction = ParameterDirection.ReturnValue;

            oracom.ExecuteNonQuery();
            oracon.Close();

            string paramId = oracom.Parameters["v_gbr_id"].Value.ToString();
            oracon.Close();
            return paramId;
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "gl_setup_editor.get_gbr_id","", "loadGBRId", "");
            //Response.Redirect("../ErrorPages/ErrorPage.aspx");
            return null;
        }
    }
    protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.Header || e.Row.RowType == DataControlRowType.DataRow)
        {
            for (int i = 0; i <= 2; i++)
                e.Row.Cells[i].Visible = false;
            e.Row.Cells[4].Visible = false;
            e.Row.Cells[5].Visible = false;
            e.Row.Cells[7].Visible = false;
            e.Row.Cells[18].Visible = false;
        }
        
    }

    private bool GLPostingRequired(string postingRequired,int index, ref string error)
    {

        try
        {
            
            string DBConnection = Helper.dbConnection();

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

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

            oracom.CommandType = CommandType.StoredProcedure;
            oracom.CommandText = "GL_SETUP_EDITOR.Update_GL_Posting";

            oracom.Parameters.Add("p_current_uid", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_re_code", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_rc_code", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_match_res", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_gl_posting_req", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_ch_type", 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;

            if (GridView1.Rows[index].Cells[1].Text != "&nbsp;")
                oracom.Parameters["p_re_code"].Value = GridView1.Rows[index].Cells[1].Text;
            else
                oracom.Parameters["p_re_code"].Value = OracleString.Null;

            if (GridView1.Rows[index].Cells[0].Text != "&nbsp;")
                oracom.Parameters["p_rc_code"].Value = GridView1.Rows[index].Cells[0].Text;
            else
                oracom.Parameters["p_rc_code"].Value = OracleString.Null;

            oracom.Parameters["p_match_res"].Value = GridView1.Rows[index].Cells[7].Text;
            oracom.Parameters["p_gl_posting_req"].Value = postingRequired;
            oracom.Parameters["p_ch_type"].Value = GridView1.Rows[index].Cells[15].Text;

            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")
            {
                ExceptionUtility.LogException(0, "GL_SETUP_EDITOR.Update_GL_Posting", "29.1", "GLPostingRequired", "postingRequired: " + postingRequired + ", index: " + index);
                return true;
            }
            else
            {
                ExceptionUtility.LogException(9, "GL_SETUP_EDITOR.Update_GL_Posting", "29.1", "GLPostingRequired", "postingRequired: " + postingRequired + ", index: " + index);
                return false;
            }
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "GL_SETUP_EDITOR.Update_GL_Posting","29.1", "GLPostingRequired", "postingRequired: "+postingRequired +", index: "+index );
            //Response.Redirect("../ErrorPages/ErrorPage.aspx");
            return false ;
        }
    }

    private bool updateGL(string rowID, ref string error)
    {
        try
        {
            string DBConnection = Helper.dbConnection();

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

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

            oracom.CommandType = CommandType.StoredProcedure;
            oracom.CommandText = "GL_SETUP_EDITOR.Edit_GL_Setup_Info";

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

            oracom.Parameters.Add("p_account_number", 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_ga_code"].Value = rowID;

            oracom.Parameters["p_acct_name"].Value = txtAccountName.Text;
            oracom.Parameters["p_account_number"].Value = txtAccount.Text;

            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")
            {
                ExceptionUtility.LogException(0, "GL_SETUP_EDITOR.Edit_GL_Setup_Info", "31.1", "updateGL", "rowID: " + rowID);
                return true;
            }
            else
            {
                ExceptionUtility.LogException(9, "GL_SETUP_EDITOR.Edit_GL_Setup_Info", "31.1", "updateGL", "rowID: " + rowID);
                return false;
            }
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "GL_SETUP_EDITOR.Edit_GL_Setup_Info","31.1", "updateGL", "rowID: " + rowID );
            //Response.Redirect("../ErrorPages/ErrorPage.aspx");
            return false;
        }
    }

    

    protected void rdEvent_CheckedChanged(object sender, EventArgs e)
    {
        eventsRow.Visible = true;
        channelsRow.Visible = false;
    }

    protected void rdChannel_CheckedChanged(object sender, EventArgs e)
    {
        eventsRow.Visible = false;
        channelsRow.Visible = true;
    }

    protected void rdPOS1_CheckedChanged(object sender, EventArgs e)
    {
        eventsRow.Visible = false;
        channelsRow.Visible = true;
    }

    protected void rdPOS2_CheckedChanged(object sender, EventArgs e)
    {
        eventsRow.Visible = false;
        channelsRow.Visible = false;
    }

    protected void rdEvents1_CheckedChanged(object sender, EventArgs e)
    {
        eventsRow1.Visible = true;
        channelsRow1.Visible = false;
    }

    protected void rdChannels1_CheckedChanged(object sender, EventArgs e)
    {
        eventsRow1.Visible = false;
        channelsRow1.Visible = true;
    }

    protected void rdPOS11_CheckedChanged(object sender, EventArgs e)
    {
        eventsRow1.Visible = false;
        channelsRow1.Visible = true;
    }

    protected void rdPOS22_CheckedChanged(object sender, EventArgs e)
    {
        eventsRow1.Visible = false;
        channelsRow1.Visible = false;
    }

    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {

    }

    protected void ddlType2_SelectedIndexChanged(object sender, EventArgs e)
    {
        ExceptionUtility.LogException(0, "", "31.1", "ddlType2_SelectedIndexChanged", "");//rowID: " + rowID);
        loadMatchResult();
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.Header || e.Row.RowType == DataControlRowType.DataRow)
        {

            int app_status = Convert.ToInt16(DataBinder.Eval(e.Row.DataItem, "app_status"));

            if (app_status == 0)
            {
                e.Row.Cells[13].Visible = true;
                e.Row.Cells[16].Visible = false;
                e.Row.Cells[17].Visible = false;
            }
            else
            {
                e.Row.Cells[13].Visible = false;
                e.Row.Cells[16].Visible = true;
                e.Row.Cells[17].Visible = true;
            }
            e.Row.Cells[11].Visible = false;
        }
    }
    private int loadChgID()
    {
        try
        {
            string DBConnection = Helper.dbConnection();

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

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

            oracom.CommandType = CommandType.StoredProcedure;
            oracom.CommandText = "maker_checker_editor.get_chg_id";


            oracom.Parameters.Add("p_chg_id", OracleType.Number).Direction = ParameterDirection.Output;

            oracom.ExecuteNonQuery();
            oracon.Close();

            int nop = int.Parse(oracom.Parameters["p_chg_id"].Value.ToString());
            oracon.Close();
            return nop;
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "maker_checker_editor.get_chg_id","", "loadChgID", "");
            //Response.Redirect("../ErrorPages/ErrorPage.aspx");
            return 0;
        }
    }
    private int loadMaxChgID(string atm_number)
    {
        try
        {
            string DBConnection = Helper.dbConnection();

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

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

            oracom.CommandType = CommandType.StoredProcedure;
            oracom.CommandText = "maker_checker_editor.get_max_chg_id";

            oracom.Parameters.Add("p_changed_rec_id", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_chg_id", OracleType.Number).Direction = ParameterDirection.Output;

            oracom.Parameters["p_changed_rec_id"].Value = atm_number;

            oracom.ExecuteNonQuery();
            oracon.Close();

            int nop = int.Parse(oracom.Parameters["p_chg_id"].Value.ToString());
            oracon.Close();
            return nop;
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "maker_checker_editor.get_max_chg_id","", "loadMaxChgID", "atm_number: "+atm_number );
            //Response.Redirect("../ErrorPages/ErrorPage.aspx");
            return 0;
        }
    }

    private bool UpdateMakerChecker(int chgId, string pkey, string tableName,string columnName, string oldValue, string newValue, string oldValueNo, string NewValueNo, int chgType, ref string error)
    {
        try
        {
            string DBConnection = Helper.dbConnection();

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

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

            oracom.CommandType = CommandType.StoredProcedure;
            oracom.CommandText = "MAKER_CHECKER_EDITOR.Add_Maker_Checker";

            oracom.Parameters.Add("p_current_uid", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_chg_id", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_chg_type", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_page_id", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_table_name", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_column_name", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_old_value", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_new_value", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_maker_id", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_made_on_date", OracleType.DateTime).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_checker_id", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_checked_on_date", OracleType.DateTime).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_changed_rec_id", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_chg_status", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_checker_notes", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_old_number", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_new_number", 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_current_uid"].Value = Session["uid"].ToString();
            oracom.Parameters["p_page_id"].Value = page_id;
            oracom.Parameters["p_table_name"].Value = tableName;
            oracom.Parameters["p_chg_id"].Value = chgId;
            oracom.Parameters["p_chg_type"].Value = chgType;
            oracom.Parameters["p_column_name"].Value = columnName;
            oracom.Parameters["p_new_value"].Value = newValue;
            oracom.Parameters["p_old_value"].Value = oldValue;
            oracom.Parameters["p_maker_id"].Value = Session["uid"].ToString();
            oracom.Parameters["p_made_on_date"].Value = OracleDateTime.Null;
            oracom.Parameters["p_checker_id"].Value = OracleNumber.Null;
            oracom.Parameters["p_checked_on_date"].Value = OracleDateTime.Null;
            oracom.Parameters["p_changed_rec_id"].Value = pkey;
            oracom.Parameters["p_chg_status"].Value = 0;
            oracom.Parameters["p_checker_notes"].Value = OracleString.Null;

            if (oldValueNo.Trim() == "")
                oracom.Parameters["p_old_number"].Value = OracleNumber.Null;
            else
                oracom.Parameters["p_old_number"].Value = oldValueNo;
            if (NewValueNo.Trim() == "")
                oracom.Parameters["p_new_number"].Value = OracleNumber.Null;
            else
                oracom.Parameters["p_new_number"].Value = NewValueNo;

            oracom.Parameters["p_lang"].Value = "EN";

            oracom.ExecuteNonQuery();
            oracon.Close();
            string a = oracom.Parameters["p_res_code"].Value.ToString();
            error = oracom.Parameters["p_res_msg"].Value.ToString();
            if (a == "0")
            {
                ExceptionUtility.LogException(0, "MAKER_CHECKER_EDITOR.Add_Maker_Checker", "154.1", "UpdateMakerChecker", "chgId: " + chgId + ", pkey: " + pkey + ", columnName: " + columnName + ", oldValue: " + oldValue + " , newValue: " + newValue + " , oldValueNo: " + oldValueNo + ", NewValueNo: " + NewValueNo + " ,chgType: " + chgType);
                return true;
            }
            else
            {
                ExceptionUtility.LogException(9, "MAKER_CHECKER_EDITOR.Add_Maker_Checker", "154.1", "UpdateMakerChecker", "chgId: " + chgId + ", pkey: " + pkey + ", columnName: " + columnName + ", oldValue: " + oldValue + " , newValue: " + newValue + " , oldValueNo: " + oldValueNo + ", NewValueNo: " + NewValueNo + " ,chgType: " + chgType);
                return false;
            }
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "MAKER_CHECKER_EDITOR.Add_Maker_Checker","154.1", "UpdateMakerChecker", "chgId: " + chgId + ", pkey: " + pkey + ", columnName: " + columnName + ", oldValue: " + oldValue + " , newValue: " + newValue + " , oldValueNo: " + oldValueNo + ", NewValueNo: " + NewValueNo + " ,chgType: " + chgType);
            //Response.Redirect("../ErrorPages/ErrorPage.aspx");
            return false;
        }
    }
    private string getParamByID(string ID)
    {
        try
        {
            string DBConnection = Helper.dbConnectionLive();

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

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

            oracom.CommandType = CommandType.StoredProcedure;
            oracom.CommandText = "SYSTEM_PARAM_EDITOR.get_parameter_by_id";

            oracom.Parameters.Add("p_current_uid", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_param_id", 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.Add("p_output", OracleType.Cursor).Direction = ParameterDirection.Output;

            oracom.Parameters["p_param_id"].Value = ID;
            oracom.Parameters["p_lang"].Value = "EN";
            oracom.Parameters["p_current_uid"].Value = "1";

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

            string temp = ds.Tables[0].Rows[0][2].ToString();
            oracon.Close();
            //ExceptionUtility.LogException(0, "SYSTEM_PARAM_EDITOR.get_parameter_by_id", "", "getParamByID", "ID :" + ID + "");
            return temp;
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(9, "SYSTEM_PARAM_EDITOR.get_parameter_by_id","", "getParamByID", "ID :" + ID + "");
            //Response.Redirect("../ErrorPages/ErrorPage.aspx");
            return null;
        }
    }
}
