using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.OracleClient;
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.Diagnostics;

public partial class Business_GLS1 : System.Web.UI.Page
{
    public int page_id = 0;
    public string table_name = "";
    string url = "";
    static int intCount = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        table_name = "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();
            loadTables();
            ExceptionUtility.LogException(0, "", "5", "Page_Load", "");
        }
    }
    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 loadTables()
    {
        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_Bus_Rules_Tables";

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

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

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

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

            oracon.Close();
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "LOOKUP_GETTER.Get_Bus_Rules_Tables","", "loadTables", "");
            //Response.Redirect("../ErrorPages/ErrorPage.aspx");
        }
    }

    private void loadFileNames()
    {
        string parameters = "";

        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_Master_File_Names";

            oracom.Parameters.Add("p_master_table", OracleType.VarChar, 250).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_files", OracleType.Cursor).Direction = ParameterDirection.Output;

            oracom.Parameters["p_master_table"].Value = ddlMaster.SelectedValue;
            if (ddlMaster.SelectedIndex > 0)
                parameters = "p_master_table-" + ddlMaster.SelectedItem.Text;
            OracleDataAdapter da = new OracleDataAdapter(oracom);
            DataSet ds = new DataSet();
            da.Fill(ds);

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

            oracon.Close();
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "LOOKUP_GETTER.Get_Master_File_Names","", "loadFileNames", "");
            //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();

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

            ddlChannels.Items.Insert(0, "------ Channels ------");

            //To Remove The Finacle Channle
            ddlChannels.Items.RemoveAt(1);
            oracon.Close();

            string dgn = ConfigurationSettings.AppSettings["DGN"];
            ddlChannels.Items.Remove(ddlChannels.Items.FindByValue(dgn));
            ddlChannels0.Items.Remove(ddlChannels0.Items.FindByValue(dgn));
        }
        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();

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

            ddlEvents.Items.Insert(0, "------ Events ------");
            oracon.Close();

            string dgn = ConfigurationSettings.AppSettings["DGN"];
            if (!dgn.Equals("0"))
            {
                ddlEvents.Items.Remove(ddlEvents.Items.FindByValue("41"));
                ddlEvents.Items.Remove(ddlEvents.Items.FindByValue("42"));
                ddlEvents.Items.Remove(ddlEvents.Items.FindByValue("43"));

                ddlEvents0.Items.Remove(ddlEvents.Items.FindByValue("41"));
                ddlEvents0.Items.Remove(ddlEvents.Items.FindByValue("42"));
                ddlEvents0.Items.Remove(ddlEvents.Items.FindByValue("43"));
            }
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "LOOKUP_GETTER.Get_Recon_Events","", "loadEvents", "");
            //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 = "BUSINESS_RULES_EDITOR.Get_Business_Rules";

            oracom.Parameters.Add("p_current_uid", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_rc_code", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_re_code", 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 (channelID.Length != 0)
            {
                parameters = "p_rc_code-" + channelID;
                oracom.Parameters["p_rc_code"].Value = channelID;
            }
            else
                oracom.Parameters["p_rc_code"].Value = OracleNumber.Null;
            if (eventID.Length != 0)
            {
                parameters = parameters + "p_re_code-" + eventID;
                oracom.Parameters["p_re_code"].Value = eventID;
            }
            else
                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("Button1_Click"))
                ExceptionUtility.LogException(0, "BUSINESS_RULES_EDITOR.Get_Business_Rules","132.1", "loadResult", parameters );
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "BUSINESS_RULES_EDITOR.Get_Business_Rules","132.1", "loadResult", parameters );
            //Response.Redirect("../ErrorPages/ErrorPage.aspx");
        }
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        string channelID = "", EventID = "";
        if (ddlChannels.SelectedIndex > 0)
            channelID = ddlChannels.SelectedValue;
        if (ddlEvents.SelectedIndex > 0)
            EventID = ddlEvents.SelectedValue;
        pnlResult.Visible = true;
        pnlBR.Visible = false;
        ExceptionUtility.LogException(0, "", "5.132", "Button1_Click", "");//channelID: " + channelID + ", eventID: " + eventID + ", pageSize: " + pageSize + ", pageNumber: " + pageNumber);

        loadResult(channelID, EventID, Helper.gridSize(), 1);
    }

    protected void ddlPages_SelectedIndexChanged(object sender, EventArgs e)
    {
        string channelID = "", EventID = "";
        if (ddlChannels.SelectedIndex > 0)
            channelID = ddlChannels.SelectedValue;
        if (ddlEvents.SelectedIndex > 0)
            EventID = ddlEvents.SelectedValue;
        pnlBR.Visible = false;
        ExceptionUtility.LogException(0, "", "", "ddlPages_SelectedIndexChanged", "");
        loadResult(channelID, EventID, Helper.gridSize(), int.Parse(ddlPages.SelectedValue));
    }

    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.Equals("e"))
        {
            intCount = 0;
            ExceptionUtility.LogException(0, "", "5.8", "GridView1_RowCommand.Edit", "");
            int index = int.Parse(e.CommandArgument.ToString());
            string rowID = GridView1.DataKeys[index].Value.ToString();
            pnlBR.Visible = true;
            pnlBR.Enabled = true;
            loadBR(rowID);
            ViewState["rowid"] = rowID;
            ViewState["mode"] = "u";
            addrow.Visible = false;
        }
        else if (e.CommandName.Equals("v"))
        {
            ExceptionUtility.LogException(0, "", "5.7", "GridView1_RowCommand.View", "");
            int index = int.Parse(e.CommandArgument.ToString());
            string rowID = GridView1.DataKeys[index].Value.ToString();
            pnlBR.Visible = true;
            pnlBR.Enabled = false;
            loadBR(rowID);
            addrow.Visible = false;
        }
        else if(e.CommandName.Equals ("vm"))
        {
            ExceptionUtility.LogException(0, "", "5.478", "GridView1_RowCommand.ViewModification", "");
            pnlBR.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);

        }
    }
    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 void loadBR(string rowID)
    {
        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 = "BUSINESS_RULES_EDITOR.Get_Rule_Details";

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

            oracom.Parameters["p_br_code"].Value = rowID;

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

            lblRecordDate.Text = ds.Tables[0].Rows[0]["record_date"].ToString();

            txtcos.Text = ds.Tables[0].Rows[0]["cut_off_start"].ToString();
            txtcoe.Text = ds.Tables[0].Rows[0]["cut_off_end"].ToString();

            int intChecked = int.Parse(ds.Tables[0].Rows[0]["cut_off_rule"].ToString());
            if (intChecked == 1)
                CheckBox1.Checked = true;

            intChecked = int.Parse(ds.Tables[0].Rows[0]["tran_date"].ToString());
            if (intChecked == 1)
                CheckBox2.Checked = true;

            intChecked = int.Parse(ds.Tables[0].Rows[0]["tran_time"].ToString());
            if (intChecked == 1)
                CheckBox3.Checked = true;

            intChecked = int.Parse(ds.Tables[0].Rows[0]["card_number"].ToString());
            if (intChecked == 1)
                CheckBox4.Checked = true;

            intChecked = int.Parse(ds.Tables[0].Rows[0]["rrn"].ToString());
            if (intChecked == 1)
                CheckBox5.Checked = true;

            intChecked = int.Parse(ds.Tables[0].Rows[0]["trace_id"].ToString());
            if (intChecked == 1)
                CheckBox6.Checked = true;

            intChecked = int.Parse(ds.Tables[0].Rows[0]["local_date"].ToString());
            if (intChecked == 1)
                CheckBox7.Checked = true;

            intChecked = int.Parse(ds.Tables[0].Rows[0]["local_time"].ToString());
            if (intChecked == 1)
                CheckBox8.Checked = true;

            intChecked = int.Parse(ds.Tables[0].Rows[0]["currency"].ToString());
            if (intChecked == 1)
                CheckBox9.Checked = true;

            intChecked = int.Parse(ds.Tables[0].Rows[0]["tran_amount"].ToString());
            if (intChecked == 1)
                CheckBox10.Checked = true;

            intChecked = int.Parse(ds.Tables[0].Rows[0]["settlement_amount"].ToString());
            if (intChecked == 1)
                CheckBox11.Checked = true;

            intChecked = int.Parse(ds.Tables[0].Rows[0]["fee_amount"].ToString());
            if (intChecked == 1)
                CheckBox12.Checked = true;

            intChecked = int.Parse(ds.Tables[0].Rows[0]["auth_code"].ToString());
            if (intChecked == 1)
                CheckBox13.Checked = true;

            intChecked = int.Parse(ds.Tables[0].Rows[0]["message_type"].ToString());
            if (intChecked == 1)
                CheckBox14.Checked = true;

            intChecked = int.Parse(ds.Tables[0].Rows[0]["tran_source"].ToString());
            if (intChecked == 1)
                CheckBox15.Checked = true;

            intChecked = int.Parse(ds.Tables[0].Rows[0]["tran_destination"].ToString());
            if (intChecked == 1)
                CheckBox16.Checked = true;

            intChecked = int.Parse(ds.Tables[0].Rows[0]["term_id"].ToString());
            if (intChecked == 1)
                CheckBox17.Checked = true;

            intChecked = int.Parse(ds.Tables[0].Rows[0]["acct_number"].ToString());
            if (intChecked == 1)
                CheckBox19.Checked = true;

            ddlMaster.SelectedValue = ds.Tables[0].Rows[0]["master_table"].ToString();
            ddlSlave.SelectedValue = ds.Tables[0].Rows[0]["slave_table"].ToString();

            txtBefore.Text = ds.Tables[0].Rows[0]["days_before"].ToString();
            txtAfter.Text = ds.Tables[0].Rows[0]["days_after"].ToString();

            loadFileNames();
            ddlFileName.SelectedValue = ds.Tables[0].Rows[0]["FILE_NAME"].ToString();

            intChecked = int.Parse(ds.Tables[0].Rows[0]["active"].ToString());
            if (intChecked == 1)
                CheckBox18.Checked = true;
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "BUSINESS_RULES_EDITOR.Get_Rule_Details","", "loadBR", "rowID: " + rowID);
            //Response.Redirect("../ErrorPages/ErrorPage.aspx");
        }
    }

    private DataSet loadBRDetails(string rowID)
    {
        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 = "BUSINESS_RULES_EDITOR.Get_Rule_Details";

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

            oracom.Parameters["p_br_code"].Value = rowID;

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

            return ds;
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "BUSINESS_RULES_EDITOR.Get_Rule_Details", "", "loadBRDetails", "p_br_code- " + rowID);
            //Response.Redirect("../ErrorPages/ErrorPage.aspx");
            return null;
        }
    }

    
    protected void btnCancel_Click(object sender, EventArgs e)
    {
        pnlBR.Visible = false;
        pnlResult.Enabled = true;
        ExceptionUtility.LogException(0, "", "", "btnCancel_Click", "");//rowID: " + rowID);
    }

    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","408.1", "loadChgID", "");
            //Response.Redirect("../ErrorPages/ErrorPage.aspx");
            return 0;
        }
    }

    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (intCount < 1)
            intCount++;
        else
        {
            pnlBR.Visible = false;
            lblError.Text = "Your request has been sent to Checker user for Approval";
            return;
        }
        ExceptionUtility.LogException(0, "", "5.408", "btnSave_Click", "");
        string mode = ViewState["mode"].ToString();
        string error = "";
        string RE_CODE_NEW = ddlEvents0.SelectedValue;
        string re_code_desc_new = ddlEvents0.SelectedItem.Text;
        string RC_CODE_NEW = ddlChannels0.SelectedValue;
        string rc_code_desc_new = ddlChannels0.SelectedItem.Text;
        string CUT_OFF_START_NEW = txtcos.Text.Replace(":", "");
        string CUT_OFF_END_NEW = txtcoe.Text.Replace(":", "");
        string CUT_OFF_RULE_NEW = CheckBox1.Checked ? "1" : "0";
        string TRAN_DATE_NEW = CheckBox2.Checked ? "1" : "0";
        string TRAN_TIME_NEW = CheckBox3.Checked ? "1" : "0";
        string CARD_NUMBER_NEW = CheckBox4.Checked ? "1" : "0";
        string RRN_NEW = CheckBox5.Checked ? "1" : "0";
        string TRACE_ID_NEW = CheckBox6.Checked ? "1" : "0";
        string LOCAL_DATE_NEW = CheckBox7.Checked ? "1" : "0";
        string LOCAL_TIME_NEW = CheckBox8.Checked ? "1" : "0";
        string CURRENCY_NEW = CheckBox9.Checked ? "1" : "0";
        string TRAN_AMOUNT_NEW = CheckBox10.Checked ? "1" : "0";
        string SETTLEMENT_AMOUNT_NEW = CheckBox11.Checked ? "1" : "0";
        string FEE_AMOUNT_NEW = CheckBox12.Checked ? "1" : "0";
        string AUTH_CODE_NEW = CheckBox13.Checked ? "1" : "0";
        string MESSAGE_TYPE_NEW = CheckBox14.Checked ? "1" : "0";
        string TRAN_SOURCE_NEW = CheckBox15.Checked ? "1" : "0";
        string TRAN_DESTINATION_NEW = CheckBox16.Checked ? "1" : "0";
        string MASTER_TABLE_NEW = ddlMaster.SelectedValue;
        string SLAVE_TABLE_NEW = ddlSlave.SelectedValue;
        string TERM_ID_NEW = CheckBox17.Checked ? "1" : "0";
        string ACCT_NUMBER_NEW = CheckBox19.Checked ? "1" : "0";
        string DAYS_BEFORE_NEW = txtBefore.Text.Trim();
        string DAYS_AFTER_NEW = txtAfter.Text.Trim();
        string FILE_NAME_NEW = ddlFileName.SelectedValue;
        string ACTIVE_NEW = CheckBox18.Checked ? "1" : "0";
        if (mode.Equals("a"))
        {
            int chgId = loadChgID();
            bool saved = false;
            

            //bool saved = addBR(ref error);
            saved = UpdateMakerChecker(chgId, "", "RECON_EVENT", "", re_code_desc_new, "", RE_CODE_NEW, 0, ref error);
            if (saved == false)
            {
                if (Helper.OracleError(error))
                {
                    lblError.Text = "An error occured!";
                    ExceptionUtility.LogException(0, "", "5.408", "btnSave_Click", error);
                }
                else
                    lblError.Text = error;
                return;
            }
            saved = UpdateMakerChecker(chgId, "", "CHANNEL_RECON", "", rc_code_desc_new, "", RC_CODE_NEW, 0, ref error);
            if (saved == false)
            {
                if (Helper.OracleError(error))
                {
                    lblError.Text = "An error occured!";
                    ExceptionUtility.LogException(0, "", "5.408", "btnSave_Click", error);
                }
                else
                    lblError.Text = error;
                return;
            }
            saved = UpdateMakerChecker(chgId, "", "CUT_OFF_START", "", CUT_OFF_START_NEW, "", "", 0, ref error);
            if (saved == false)
            {
                if (Helper.OracleError(error))
                {
                    lblError.Text = "An error occured!";
                    ExceptionUtility.LogException(0, "", "5.408", "btnSave_Click", error);
                }
                else
                    lblError.Text = error;
                return;
            }
            saved = UpdateMakerChecker(chgId, "", "CUT_OFF_END", "", CUT_OFF_END_NEW, "", "", 0, ref error);
            if (saved == false)
            {
                if (Helper.OracleError(error))
                {
                    lblError.Text = "An error occured!";
                    ExceptionUtility.LogException(0, "", "5.408", "btnSave_Click", error);
                }
                else
                    lblError.Text = error;
                return;
            }
            saved = UpdateMakerChecker(chgId, "", "CUT_OFF_RULE", "", CUT_OFF_RULE_NEW, "", "", 0, ref error);
            if (saved == false)
            {
                if (Helper.OracleError(error))
                {
                    lblError.Text = "An error occured!";
                    ExceptionUtility.LogException(0, "", "5.408", "btnSave_Click", error);
                }
                else
                    lblError.Text = error;
                return;
            }
            saved = UpdateMakerChecker(chgId, "", "TRAN_DATE", "", TRAN_DATE_NEW, "", "", 0, ref error);
            if (saved == false)
            {
                if (Helper.OracleError(error))
                {
                    lblError.Text = "An error occured!";
                    ExceptionUtility.LogException(0, "", "5.408", "btnSave_Click", error);
                }
                else
                    lblError.Text = error;
                return;
            }
            saved = UpdateMakerChecker(chgId, "", "TRAN_TIME", "", TRAN_TIME_NEW, "", "", 0, ref error);
            if (saved == false)
            {
                if (Helper.OracleError(error))
                {
                    lblError.Text = "An error occured!";
                    ExceptionUtility.LogException(0, "", "5.408", "btnSave_Click", error);
                }
                else
                    lblError.Text = error;
                return;
            }
            saved = UpdateMakerChecker(chgId, "", "CARD_NUMBER", "", CARD_NUMBER_NEW, "", "", 0, ref error);
            if (saved == false)
            {
                if (Helper.OracleError(error))
                {
                    lblError.Text = "An error occured!";
                    ExceptionUtility.LogException(0, "", "5.408", "btnSave_Click", error);
                }
                else
                    lblError.Text = error;
                return;
            }
            saved = UpdateMakerChecker(chgId, "", "RRN", "", RRN_NEW, "", "", 0, ref error);
            if (saved == false)
            {
                if (Helper.OracleError(error))
                {
                    lblError.Text = "An error occured!";
                    ExceptionUtility.LogException(0, "", "5.408", "btnSave_Click", error);
                }
                else
                    lblError.Text = error;
                return;
            }
            saved = UpdateMakerChecker(chgId, "", "TRACE_ID", "", TRACE_ID_NEW, "", "", 0, ref error);
            if (saved == false)
            {
                if (Helper.OracleError(error))
                {
                    lblError.Text = "An error occured!";
                    ExceptionUtility.LogException(0, "", "5.408", "btnSave_Click", error);
                }
                else
                    lblError.Text = error;
                return;
            }
            saved = UpdateMakerChecker(chgId, "", "LOCAL_DATE", "", LOCAL_DATE_NEW, "", "", 0, ref error);
            if (saved == false)
            {
                if (Helper.OracleError(error))
                {
                    lblError.Text = "An error occured!";
                    ExceptionUtility.LogException(0, "", "5.408", "btnSave_Click", error);
                }
                else
                    lblError.Text = error;
                return;
            }
            saved = UpdateMakerChecker(chgId, "", "LOCAL_TIME", "", LOCAL_TIME_NEW, "", "", 0, ref error);
            if (saved == false)
            {
                if (Helper.OracleError(error))
                {
                    lblError.Text = "An error occured!";
                    ExceptionUtility.LogException(0, "", "5.408", "btnSave_Click", error);
                }
                else
                    lblError.Text = error;
                return;
            }
            saved = UpdateMakerChecker(chgId, "", "CURRENCY", "", CURRENCY_NEW, "", "", 0, ref error);
            if (saved == false)
            {
                if (Helper.OracleError(error))
                {
                    lblError.Text = "An error occured!";
                    ExceptionUtility.LogException(0, "", "5.408", "btnSave_Click", error);
                }
                else
                    lblError.Text = error;
                return;
            }
            saved = UpdateMakerChecker(chgId, "", "TRAN_AMOUNT", "", TRAN_AMOUNT_NEW, "", "", 0, ref error);
            if (saved == false)
            {
                if (Helper.OracleError(error))
                {
                    lblError.Text = "An error occured!";
                    ExceptionUtility.LogException(0, "", "5.408", "btnSave_Click", error);
                }
                else
                    lblError.Text = error;
                return;
            }
            saved = UpdateMakerChecker(chgId, "", "SETTLEMENT_AMOUNT", "", SETTLEMENT_AMOUNT_NEW, "", "", 0, ref error);
            if (saved == false)
            {
                if (Helper.OracleError(error))
                {
                    lblError.Text = "An error occured!";
                    ExceptionUtility.LogException(0, "", "5.408", "btnSave_Click", error);
                }
                else
                    lblError.Text = error;
                return;
            }
            saved = UpdateMakerChecker(chgId, "", "FEE_AMOUNT", "", FEE_AMOUNT_NEW, "", "", 0, ref error);
            if (saved == false)
            {
                if (Helper.OracleError(error))
                {
                    lblError.Text = "An error occured!";
                    ExceptionUtility.LogException(0, "", "5.408", "btnSave_Click", error);
                }
                else
                    lblError.Text = error;
                return;
            }
            saved = UpdateMakerChecker(chgId, "", "AUTH_CODE", "", AUTH_CODE_NEW, "", "", 0, ref error);
            if (saved == false)
            {
                if (Helper.OracleError(error))
                {
                    lblError.Text = "An error occured!";
                    ExceptionUtility.LogException(0, "", "5.408", "btnSave_Click", error);
                }
                else
                    lblError.Text = error;
                return;
            }
            saved = UpdateMakerChecker(chgId, "", "MESSAGE_TYPE", "", MESSAGE_TYPE_NEW, "", "", 0, ref error);
            if (saved == false)
            {
                if (Helper.OracleError(error))
                {
                    lblError.Text = "An error occured!";
                    ExceptionUtility.LogException(0, "", "5.408", "btnSave_Click", error);
                }
                else
                    lblError.Text = error;
                return;
            }
            saved = UpdateMakerChecker(chgId, "", "TRAN_SOURCE", "", TRAN_SOURCE_NEW, "", "", 0, ref error);
            if (saved == false)
            {
                if (Helper.OracleError(error))
                {
                    lblError.Text = "An error occured!";
                    ExceptionUtility.LogException(0, "", "5.408", "btnSave_Click", error);
                }
                else
                    lblError.Text = error;
                return;
            }
            saved = UpdateMakerChecker(chgId, "", "TRAN_DESTINATION", "", TRAN_DESTINATION_NEW, "", "", 0, ref error);
            if (saved == false)
            {
                if (Helper.OracleError(error))
                {
                    lblError.Text = "An error occured!";
                    ExceptionUtility.LogException(0, "", "5.408", "btnSave_Click", error);
                }
                else
                    lblError.Text = error;
                return;
            }
            saved = UpdateMakerChecker(chgId, "", "MASTER_TABLE", "", MASTER_TABLE_NEW, "", "", 0, ref error);
            if (saved == false)
            {
                if (Helper.OracleError(error))
                {
                    lblError.Text = "An error occured!";
                    ExceptionUtility.LogException(0, "", "5.408", "btnSave_Click", error);
                }
                else
                    lblError.Text = error;
                return;
            }
            saved = UpdateMakerChecker(chgId, "", "SLAVE_TABLE", "", SLAVE_TABLE_NEW, "", "", 0, ref error);
            if (saved == false)
            {
                if (Helper.OracleError(error))
                {
                    lblError.Text = "An error occured!";
                    ExceptionUtility.LogException(0, "", "5.408", "btnSave_Click", error);
                }
                else
                    lblError.Text = error;
                return;
            }
            saved = UpdateMakerChecker(chgId, "", "TERM_ID", "", TERM_ID_NEW, "", "", 0, ref error);
            if (saved == false)
            {
                if (Helper.OracleError(error))
                {
                    lblError.Text = "An error occured!";
                    ExceptionUtility.LogException(0, "", "5.408", "btnSave_Click", error);
                }
                else
                    lblError.Text = error;
                return;
            }
            saved = UpdateMakerChecker(chgId, "", "ACCT_NUMBER", "", ACCT_NUMBER_NEW, "", "", 0, ref error);
            if (saved == false)
            {
                if (Helper.OracleError(error))
                {
                    lblError.Text = "An error occured!";
                    ExceptionUtility.LogException(0, "", "5.408", "btnSave_Click", error);
                }
                else
                    lblError.Text = error;
                return;
            }
            saved = UpdateMakerChecker(chgId, "", "DAYS_BEFORE", "", DAYS_BEFORE_NEW, "", "", 0, ref error);
            if (saved == false)
            {
                if (Helper.OracleError(error))
                {
                    lblError.Text = "An error occured!";
                    ExceptionUtility.LogException(0, "", "5.408", "btnSave_Click", error);
                }
                else
                    lblError.Text = error;
                return;
            }
            saved = UpdateMakerChecker(chgId, "", "DAYS_AFTER", "", DAYS_AFTER_NEW, "", "", 0, ref error);
            if (saved == false)
            {
                if (Helper.OracleError(error))
                {
                    lblError.Text = "An error occured!";
                    ExceptionUtility.LogException(0, "", "5.408", "btnSave_Click", error);
                }
                else
                    lblError.Text = error;
                return;
            }
            saved = UpdateMakerChecker(chgId, "", "FILE_NAME", "", FILE_NAME_NEW, "", "", 0, ref error);
            if (saved == false)
            {
                if (Helper.OracleError(error))
                {
                    lblError.Text = "An error occured!";
                    ExceptionUtility.LogException(0, "", "5.408", "btnSave_Click", error);
                }
                else
                    lblError.Text = error;
                return;
            }
            saved = UpdateMakerChecker(chgId, "", "ACTIVE", "", ACTIVE_NEW, "", "", 0, ref error);
            if (saved == false)
            {
                if (Helper.OracleError(error))
                {
                    lblError.Text = "An error occured!";
                    ExceptionUtility.LogException(0, "", "5.408", "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 rowID = ViewState["rowid"].ToString();
            int chgId = loadChgID();
            bool compare = false;
            DataSet ds = loadBRDetails(rowID);
            if (ds.Tables[0].Rows.Count > 0)
            {
               // string RE_CODE_OLD = ds.Tables[0].Rows[0]["re_code"].ToString();
                //string re_code_desc_OLD = ds.Tables[0].Rows[0]["event_name"].ToString();
               // string RC_CODE_OLD = ds.Tables[0].Rows[0]["rc_code"].ToString();
               // string rc_code_desc_OLD = ds.Tables[0].Rows[0]["channel_name"].ToString();
                string CUT_OFF_START_OLD = ds.Tables[0].Rows[0]["cut_off_start"].ToString().Replace(":", "");
                string CUT_OFF_END_OLD = ds.Tables[0].Rows[0]["cut_off_end"].ToString().Replace(":", "");
                string CUT_OFF_RULE_OLD = ds.Tables[0].Rows[0]["cut_off_rule"].ToString();
                string TRAN_DATE_OLD = ds.Tables[0].Rows[0]["tran_date"].ToString();
                string TRAN_TIME_OLD = ds.Tables[0].Rows[0]["tran_time"].ToString();
                string CARD_NUMBER_OLD = ds.Tables[0].Rows[0]["card_number"].ToString();
                string RRN_OLD = ds.Tables[0].Rows[0]["rrn"].ToString();
                string TRACE_ID_OLD = ds.Tables[0].Rows[0]["trace_id"].ToString();
                string LOCAL_DATE_OLD = ds.Tables[0].Rows[0]["local_date"].ToString();
                string LOCAL_TIME_OLD = ds.Tables[0].Rows[0]["local_time"].ToString();
                string CURRENCY_OLD = ds.Tables[0].Rows[0]["currency"].ToString();
                string TRAN_AMOUNT_OLD = ds.Tables[0].Rows[0]["tran_amount"].ToString();
                string SETTLEMENT_AMOUNT_OLD = ds.Tables[0].Rows[0]["settlement_amount"].ToString();
                string FEE_AMOUNT_OLD = ds.Tables[0].Rows[0]["fee_amount"].ToString();
                string AUTH_CODE_OLD = ds.Tables[0].Rows[0]["auth_code"].ToString();
                string MESSAGE_TYPE_OLD = ds.Tables[0].Rows[0]["message_type"].ToString();
                string TRAN_SOURCE_OLD = ds.Tables[0].Rows[0]["tran_source"].ToString();
                string TRAN_DESTINATION_OLD = ds.Tables[0].Rows[0]["tran_destination"].ToString();
                string MASTER_TABLE_OLD = ds.Tables[0].Rows[0]["master_table"].ToString();
                string SLAVE_TABLE_OLD = ds.Tables[0].Rows[0]["slave_table"].ToString();
                string TERM_ID_OLD = ds.Tables[0].Rows[0]["term_id"].ToString();
                string ACCT_NUMBER_OLD = ds.Tables[0].Rows[0]["acct_number"].ToString();
                string DAYS_BEFORE_OLD = ds.Tables[0].Rows[0]["days_before"].ToString();
                string DAYS_AFTER_OLD = ds.Tables[0].Rows[0]["days_after"].ToString();
                string FILE_NAME_OLD = ds.Tables[0].Rows[0]["file_name"].ToString();               
                string ACTIVE_OLD = ds.Tables[0].Rows[0]["active"].ToString();

                 if (CUT_OFF_START_NEW ==CUT_OFF_START_OLD  && CUT_OFF_END_NEW ==CUT_OFF_END_OLD  &&
                    CUT_OFF_RULE_NEW==CUT_OFF_RULE_OLD && TRAN_DATE_NEW==TRAN_DATE_OLD &&
                    TRAN_TIME_NEW==TRAN_TIME_OLD  && CARD_NUMBER_NEW==CARD_NUMBER_OLD &&
                    RRN_NEW==RRN_OLD && TRACE_ID_NEW==TRACE_ID_OLD &&
                    LOCAL_DATE_NEW==LOCAL_DATE_OLD && LOCAL_TIME_NEW==LOCAL_TIME_OLD &&
                    CURRENCY_NEW==CURRENCY_OLD && TRAN_AMOUNT_NEW==TRAN_AMOUNT_OLD &&
                    SETTLEMENT_AMOUNT_NEW==SETTLEMENT_AMOUNT_OLD && FEE_AMOUNT_NEW==FEE_AMOUNT_OLD &&
                    AUTH_CODE_NEW==AUTH_CODE_OLD && MESSAGE_TYPE_NEW==MESSAGE_TYPE_OLD &&
                    TRAN_SOURCE_NEW==TRAN_SOURCE_OLD && TRAN_DESTINATION_NEW==TRAN_DESTINATION_OLD &&
                    TERM_ID_NEW==TERM_ID_OLD && ACCT_NUMBER_NEW==ACCT_NUMBER_OLD &&
                    MASTER_TABLE_NEW==MASTER_TABLE_OLD && SLAVE_TABLE_NEW==SLAVE_TABLE_OLD &&
                    DAYS_BEFORE_NEW==DAYS_BEFORE_OLD && DAYS_AFTER_NEW==DAYS_AFTER_OLD &&
                    FILE_NAME_NEW==FILE_NAME_OLD  && ACTIVE_NEW==ACTIVE_OLD)
                compare = true;

                 if (compare == false)
                 {
                     bool update = false;

                     //if (RC_CODE_NEW != RC_CODE_OLD)
                     //    update=UpdateMakerChecker(chgId, rowID, "rc_code", rc_code_desc_OLD, rc_code_desc_new, RC_CODE_OLD, RC_CODE_NEW, 1, ref error);
                     //if(RE_CODE_NEW != RE_CODE_OLD)
                     //    update=UpdateMakerChecker(chgId, rowID, "re_code", re_code_desc_OLD, re_code_desc_new, RE_CODE_OLD, RE_CODE_NEW, 1, ref error);
                     if (CUT_OFF_START_NEW != CUT_OFF_START_OLD)
                     {
                         update = UpdateMakerChecker(chgId, rowID, "CUT_OFF_START", CUT_OFF_START_OLD, CUT_OFF_START_NEW, "", "", 1, ref error);
                         if (update == false)
                         {
                             if (Helper.OracleError(error))
                             {
                                 lblError.Text = "An error occured!";
                                 ExceptionUtility.LogException(0, "", "5.408", "btnSave_Click", error);
                             }
                             else
                                 lblError.Text = error;
                             return;
                         }
                     }
                     if (CUT_OFF_END_NEW != CUT_OFF_END_OLD)
                     {
                         update = UpdateMakerChecker(chgId, rowID, "CUT_OFF_END", CUT_OFF_END_OLD, CUT_OFF_END_NEW, "", "", 1, ref error);
                         if (update == false)
                         {
                             if (Helper.OracleError(error))
                             {
                                 lblError.Text = "An error occured!";
                                 ExceptionUtility.LogException(0, "", "5.408", "btnSave_Click", error);
                             }
                             else
                                 lblError.Text = error;
                             return;
                         }
                     }
                     if (CUT_OFF_RULE_NEW != CUT_OFF_RULE_OLD)
                     {
                         update = UpdateMakerChecker(chgId, rowID, "CUT_OFF_RULE", CUT_OFF_RULE_OLD, CUT_OFF_RULE_NEW, "", "", 1, ref error);
                         if (update == false)
                         {
                             if (Helper.OracleError(error))
                             {
                                 lblError.Text = "An error occured!";
                                 ExceptionUtility.LogException(0, "", "5.408", "btnSave_Click", error);
                             }
                             else
                                 lblError.Text = error;
                             return;
                         }
                     }
                     if (TRAN_DATE_NEW != TRAN_DATE_OLD)
                     {
                         update = UpdateMakerChecker(chgId, rowID, "TRAN_DATE", TRAN_DATE_OLD, TRAN_DATE_NEW, "", "", 1, ref error);
                         if (update == false)
                         {
                             if (Helper.OracleError(error))
                             {
                                 lblError.Text = "An error occured!";
                                 ExceptionUtility.LogException(0, "", "5.408", "btnSave_Click", error);
                             }
                             else
                                 lblError.Text = error;
                             return;
                         }
                     }

                     if (TRAN_TIME_NEW != TRAN_TIME_OLD)
                     {
                         update = UpdateMakerChecker(chgId, rowID, "TRAN_TIME", TRAN_TIME_OLD, TRAN_TIME_NEW, "", "", 1, ref error);
                         if (update == false)
                         {
                             if (Helper.OracleError(error))
                             {
                                 lblError.Text = "An error occured!";
                                 ExceptionUtility.LogException(0, "", "5.408", "btnSave_Click", error);
                             }
                             else
                                 lblError.Text = error;
                             return;
                         }
                     }
                     if (CARD_NUMBER_NEW != CARD_NUMBER_OLD)
                     {
                         update = UpdateMakerChecker(chgId, rowID, "CARD_NUMBER", CARD_NUMBER_OLD, CARD_NUMBER_NEW, "", "", 1, ref error);
                         if (update == false)
                         {
                             if (Helper.OracleError(error))
                             {
                                 lblError.Text = "An error occured!";
                                 ExceptionUtility.LogException(0, "", "5.408", "btnSave_Click", error);
                             }
                             else
                                 lblError.Text = error;
                             return;
                         }
                     }
                     if (RRN_NEW != RRN_OLD)
                     {
                         update = UpdateMakerChecker(chgId, rowID, "RRN", RRN_OLD, RRN_NEW, "", "", 1, ref error);
                         if (update == false)
                         {
                             if (Helper.OracleError(error))
                             {
                                 lblError.Text = "An error occured!";
                                 ExceptionUtility.LogException(0, "", "5.408", "btnSave_Click", error);
                             }
                             else
                                 lblError.Text = error;
                             return;
                         }
                     }
                     if (TRACE_ID_NEW != TRACE_ID_OLD)
                     {
                         update = UpdateMakerChecker(chgId, rowID, "TRACE_ID", TRACE_ID_OLD, TRACE_ID_NEW, "", "", 1, ref error);
                         if (update == false)
                         {
                             if (Helper.OracleError(error))
                             {
                                 lblError.Text = "An error occured!";
                                 ExceptionUtility.LogException(0, "", "5.408", "btnSave_Click", error);
                             }
                             else
                                 lblError.Text = error;
                             return;
                         }
                     }
                     if (LOCAL_DATE_OLD != LOCAL_TIME_NEW)
                     {
                         update = UpdateMakerChecker(chgId, rowID, "LOCAL_DATE", LOCAL_DATE_OLD, LOCAL_TIME_NEW, "", "", 1, ref error);
                         if (update == false)
                         {
                             if (Helper.OracleError(error))
                             {
                                 lblError.Text = "An error occured!";
                                 ExceptionUtility.LogException(0, "", "5.408", "btnSave_Click", error);
                             }
                             else
                                 lblError.Text = error;
                             return;
                         }
                     }
                     if (LOCAL_TIME_OLD != LOCAL_TIME_NEW)
                     {
                         update = UpdateMakerChecker(chgId, rowID, "LOCAL_TIME", LOCAL_TIME_OLD, LOCAL_TIME_NEW, "", "", 1, ref error);
                         if (update == false)
                         {
                             if (Helper.OracleError(error))
                             {
                                 lblError.Text = "An error occured!";
                                 ExceptionUtility.LogException(0, "", "5.408", "btnSave_Click", error);
                             }
                             else
                                 lblError.Text = error;
                             return;
                         }
                     }
                     if (CURRENCY_NEW != CURRENCY_OLD)
                     {
                         update = UpdateMakerChecker(chgId, rowID, "CURRENCY", CURRENCY_OLD, CURRENCY_NEW, "", "", 1, ref error);
                         if (update == false)
                         {
                             if (Helper.OracleError(error))
                             {
                                 lblError.Text = "An error occured!";
                                 ExceptionUtility.LogException(0, "", "5.408", "btnSave_Click", error);
                             }
                             else
                                 lblError.Text = error;
                             return;
                         }
                     }
                     if (TRAN_AMOUNT_NEW != TRAN_AMOUNT_OLD)
                     {
                         update = UpdateMakerChecker(chgId, rowID, "TRAN_AMOUNT", TRAN_AMOUNT_OLD, TRAN_AMOUNT_NEW, "", "", 1, ref error);
                         if (update == false)
                         {
                             if (Helper.OracleError(error))
                             {
                                 lblError.Text = "An error occured!";
                                 ExceptionUtility.LogException(0, "", "5.408", "btnSave_Click", error);
                             }
                             else
                                 lblError.Text = error;
                             return;
                         }
                     }
                     if (SETTLEMENT_AMOUNT_NEW != SETTLEMENT_AMOUNT_OLD)
                     {
                         update = UpdateMakerChecker(chgId, rowID, "SETTLEMENT_AMOUNT", SETTLEMENT_AMOUNT_OLD, SETTLEMENT_AMOUNT_NEW, "", "", 1, ref error);
                         if (update == false)
                         {
                             if (Helper.OracleError(error))
                             {
                                 lblError.Text = "An error occured!";
                                 ExceptionUtility.LogException(0, "", "5.408", "btnSave_Click", error);
                             }
                             else
                                 lblError.Text = error;
                             return;
                         }
                     }
                     if (FEE_AMOUNT_NEW != FEE_AMOUNT_OLD)
                     {
                         update = UpdateMakerChecker(chgId, rowID, "FEE_AMOUNT", FEE_AMOUNT_OLD, FEE_AMOUNT_NEW, "", "", 1, ref error);
                         if (update == false)
                         {
                             if (Helper.OracleError(error))
                             {
                                 lblError.Text = "An error occured!";
                                 ExceptionUtility.LogException(0, "", "5.408", "btnSave_Click", error);
                             }
                             else
                                 lblError.Text = error;
                             return;
                         }
                     }
                     if (AUTH_CODE_NEW != AUTH_CODE_OLD)
                     {
                         update = UpdateMakerChecker(chgId, rowID, "AUTH_CODE", AUTH_CODE_OLD, AUTH_CODE_NEW, "", "", 1, ref error);
                         if (update == false)
                         {
                             if (Helper.OracleError(error))
                             {
                                 lblError.Text = "An error occured!";
                                 ExceptionUtility.LogException(0, "", "5.408", "btnSave_Click", error);
                             }
                             else
                                 lblError.Text = error;
                             return;
                         }
                     }
                     if (MESSAGE_TYPE_NEW != MESSAGE_TYPE_OLD)
                     {
                         update = UpdateMakerChecker(chgId, rowID, "MESSAGE_TYPE", MESSAGE_TYPE_OLD, MESSAGE_TYPE_NEW, "", "", 1, ref error);
                         if (update == false)
                         {
                             if (Helper.OracleError(error))
                             {
                                 lblError.Text = "An error occured!";
                                 ExceptionUtility.LogException(0, "", "5.408", "btnSave_Click", error);
                             }
                             else
                                 lblError.Text = error;
                             return;
                         }
                     }
                     if (TRAN_SOURCE_NEW != TRAN_SOURCE_OLD)
                     {
                         update = UpdateMakerChecker(chgId, rowID, "TRAN_SOURCE", TRAN_SOURCE_OLD, TRAN_SOURCE_NEW, "", "", 1, ref error);
                         if (update == false)
                         {
                             if (Helper.OracleError(error))
                             {
                                 lblError.Text = "An error occured!";
                                 ExceptionUtility.LogException(0, "", "5.408", "btnSave_Click", error);
                             }
                             else
                                 lblError.Text = error;
                             return;
                         }
                     }
                     if (TRAN_DESTINATION_NEW != TRAN_DESTINATION_OLD)
                     {
                         update = UpdateMakerChecker(chgId, rowID, "TRAN_DESTINATION", TRAN_DESTINATION_OLD, TRAN_DESTINATION_NEW, "", "", 1, ref error);
                         if (update == false)
                         {
                             if (Helper.OracleError(error))
                             {
                                 lblError.Text = "An error occured!";
                                 ExceptionUtility.LogException(0, "", "5.408", "btnSave_Click", error);
                             }
                             else
                                 lblError.Text = error;
                             return;
                         }
                     }
                     if (TERM_ID_NEW != TERM_ID_OLD)
                     {
                         update = UpdateMakerChecker(chgId, rowID, "TERM_ID", TERM_ID_OLD, TERM_ID_NEW, "", "", 1, ref error);
                         if (update == false)
                         {
                             if (Helper.OracleError(error))
                             {
                                 lblError.Text = "An error occured!";
                                 ExceptionUtility.LogException(0, "", "5.408", "btnSave_Click", error);
                             }
                             else
                                 lblError.Text = error;
                             return;
                         }
                     }
                     if (ACCT_NUMBER_OLD != ACCT_NUMBER_NEW)
                     {
                         update = UpdateMakerChecker(chgId, rowID, "ACCT_NUMBER", ACCT_NUMBER_OLD, ACCT_NUMBER_NEW, "", "", 1, ref error);
                         if (update == false)
                         {
                             if (Helper.OracleError(error))
                             {
                                 lblError.Text = "An error occured!";
                                 ExceptionUtility.LogException(0, "", "5.408", "btnSave_Click", error);
                             }
                             else
                                 lblError.Text = error;
                             return;
                         }
                     }
                     if (MASTER_TABLE_NEW != MASTER_TABLE_OLD)
                     {
                         update = UpdateMakerChecker(chgId, rowID, "MASTER_TABLE", MASTER_TABLE_OLD, MASTER_TABLE_NEW, "", "", 1, ref error);
                         if (update == false)
                         {
                             if (Helper.OracleError(error))
                             {
                                 lblError.Text = "An error occured!";
                                 ExceptionUtility.LogException(0, "", "5.408", "btnSave_Click", error);
                             }
                             else
                                 lblError.Text = error;
                             return;
                         }
                     }
                     if (SLAVE_TABLE_NEW != SLAVE_TABLE_OLD)
                     {
                         update = UpdateMakerChecker(chgId, rowID, "SLAVE_TABLE", SLAVE_TABLE_OLD, SLAVE_TABLE_NEW, "", "", 1, ref error);
                         if (update == false)
                         {
                             if (Helper.OracleError(error))
                             {
                                 lblError.Text = "An error occured!";
                                 ExceptionUtility.LogException(0, "", "5.408", "btnSave_Click", error);
                             }
                             else
                                 lblError.Text = error;
                             return;
                         }
                     }
                     if (DAYS_BEFORE_NEW != DAYS_BEFORE_OLD)
                     {
                         update = UpdateMakerChecker(chgId, rowID, "DAYS_BEFORE", DAYS_BEFORE_OLD, DAYS_BEFORE_NEW, "", "", 1, ref error);
                         if (update == false)
                         {
                             if (Helper.OracleError(error))
                             {
                                 lblError.Text = "An error occured!";
                                 ExceptionUtility.LogException(0, "", "5.408", "btnSave_Click", error);
                             }
                             else
                                 lblError.Text = error;
                             return;
                         }
                     }
                     if (DAYS_AFTER_NEW != DAYS_AFTER_OLD)
                     {
                         update = UpdateMakerChecker(chgId, rowID, "DAYS_AFTER", DAYS_AFTER_OLD, DAYS_AFTER_NEW, "", "", 1, ref error);
                         if (update == false)
                         {
                             if (Helper.OracleError(error))
                             {
                                 lblError.Text = "An error occured!";
                                 ExceptionUtility.LogException(0, "", "5.408", "btnSave_Click", error);
                             }
                             else
                                 lblError.Text = error;
                             return;
                         }
                     }
                     if (FILE_NAME_NEW != FILE_NAME_OLD)
                     {
                         update = UpdateMakerChecker(chgId, rowID, "FILE_NAME", FILE_NAME_OLD, FILE_NAME_NEW, "", "", 1, ref error);
                         if (update == false)
                         {
                             if (Helper.OracleError(error))
                             {
                                 lblError.Text = "An error occured!";
                                 ExceptionUtility.LogException(0, "", "5.408", "btnSave_Click", error);
                             }
                             else
                                 lblError.Text = error;
                             return;
                         }
                     }
                     if (ACTIVE_NEW != ACTIVE_OLD)
                     {
                         update = UpdateMakerChecker(chgId, rowID, "ACTIVE", ACTIVE_OLD, ACTIVE_NEW, "", "", 1, ref error);
                         if (update == false)
                         {
                             if (Helper.OracleError(error))
                             {
                                 lblError.Text = "An error occured!";
                                 ExceptionUtility.LogException(0, "", "5.408", "btnSave_Click", error);
                             }
                             else
                                 lblError.Text = error;
                             return;
                         }
                     }


                     lblError.Text = "Your request has been sent to Checker user for Approval";
                    
                 }
                 
            }
            
           
        }

        //loading the grid again
        string channelID = "", EventID = "";
        if (ddlChannels.SelectedIndex > 0)
            channelID = ddlChannels.SelectedValue;
        if (ddlEvents.SelectedIndex > 0)
            EventID = ddlEvents.SelectedValue;
        pnlResult.Visible = true;
        pnlResult.Enabled = true;
        pnlBR.Visible = false;
        loadResult(channelID, EventID, Helper.gridSize(), 1);


    }

   

    protected void btnAdd_Click(object sender, EventArgs e)
    {
        intCount = 0;
        pnlBR.Visible = true;
        pnlResult.Enabled = false;
        ViewState["mode"] = "a";

        lblRecordDate.Text = "";

        txtcos.Text = "";
        txtcoe.Text = "";

        CheckBox1.Checked = false;

        CheckBox2.Checked = false;

        CheckBox3.Checked = false;

        CheckBox4.Checked = false;

        CheckBox5.Checked = false;

        CheckBox6.Checked = false;

        CheckBox7.Checked = false;

        CheckBox8.Checked = false;

        CheckBox9.Checked = false;

        CheckBox10.Checked = false;

        CheckBox11.Checked = false;

        CheckBox12.Checked = false;

        CheckBox13.Checked = false;

        CheckBox14.Checked = false;

        CheckBox15.Checked = false;

        CheckBox16.Checked = false;

        CheckBox17.Checked = false;

        ddlMaster.SelectedIndex = 0;
        ddlSlave.SelectedIndex = 0;

        if (ddlChannels.SelectedIndex > 0)
            ddlChannels0.SelectedValue = ddlChannels.SelectedValue;

        if (ddlEvents.SelectedIndex > 0)
            ddlEvents0.SelectedValue = ddlEvents.SelectedValue;

        loadFileNames();
        txtBefore.Text = "";
        txtAfter.Text = "";

        loadFileNames();
        ddlFileName.SelectedIndex = 0;

        CheckBox18.Checked = false;

        addrow.Visible = true;
        ExceptionUtility.LogException(0, "", "5.408", "btnAdd_Click", "");
    }

    protected void ddlMaster_SelectedIndexChanged(object sender, EventArgs e)
    {
        ExceptionUtility.LogException(0, "", "408.2", "ddlMaster_SelectedIndexChanged", "");//chgId: " + chgId + ", pkey: " + pkey + ", columnName: " + columnName + ", oldValue: " + oldValue + " , newValue: " + newValue + " , oldValueNo: " + oldValueNo + ", NewValueNo: " + NewValueNo + " ,chgType: " + chgType);
        loadFileNames();
    }

    private bool UpdateMakerChecker(int chgId,string pkey, 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 = table_name;
            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", "408.2", "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", "408.2", "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","408.2", "UpdateMakerChecker", "chgId: " + chgId + ", pkey: " + pkey + ", columnName: " + columnName + ", oldValue: " + oldValue + " , newValue: " + newValue + " , oldValueNo: " + oldValueNo + ", NewValueNo: " + NewValueNo + " ,chgType: " + chgType);
            //Response.Redirect("../ErrorPages/ErrorPage.aspx");
            return false;
        }
    }


   
    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[10].Visible = true;
                e.Row.Cells[11].Visible = false;
            }
            else
            {
                e.Row.Cells[10].Visible = false;
                e.Row.Cells[11].Visible = true;
            }
            e.Row.Cells[8].Visible = false;
        }
    }
    protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
    {
        
    }
}
