using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OracleClient;
using System.Data;
using System.Diagnostics;

public partial class Business_DailySettlement : System.Web.UI.Page
{
    public int pageId = 0;
    string url = "";
    public static int intCount = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        url = HttpContext.Current.Request.Url.AbsolutePath;
        string[] urlArr = url.Split('/');
        url = urlArr[2] + "/" + urlArr[3];
        pageId = loadPageIDs(url);
        if (!this.IsPostBack)
        {
            this.pnl_result.Visible = false;
            ExceptionUtility.LogException(0, "", "72", "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 Dictionary<string, double> searchSamaFiles(string settlementDate, ref string errorMsg)
    {

        try
        {
            string currentMethod = "";
            StackTrace stackTrace = new StackTrace();
            currentMethod = stackTrace.GetFrame(1).GetMethod().Name;
            Dictionary<string, double> resultParams = new Dictionary<string, double>();
            int resCode;

            string DBConnection = Helper.dbConnection();

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

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

            oracom.CommandType = CommandType.StoredProcedure;
            oracom.CommandText = "SAMA_SETTL_OPERATIONS.GET_SAMA_SETTL_FILES_AMOUNTS";

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

            oracom.Parameters.Add("p_settl_date", OracleType.VarChar).Direction = ParameterDirection.Input;

            oracom.Parameters.Add("p_sama_atm_credit", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_sama_atm_debit", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_sama_pos_credit", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_sama_pos_debit", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_sama_ecom_credit", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_sama_ecom_debit", OracleType.Number).Direction = ParameterDirection.Output;

            oracom.Parameters.Add("p_sama_gcc_atm_credit", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_sama_gcc_atm_debit", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_sama_gcc_atm_credit_FEES", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_sama_gcc_atm_debit_FEES", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_gcc_atm_credit", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_gcc_atm_debit", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_gcc_atm_credit_FEES", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_gcc_atm_debit_FEES", OracleType.Number).Direction = ParameterDirection.Output;

            oracom.Parameters.Add("p_sama_gcc_POS_credit", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_sama_gcc_POS_debit", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_sama_gcc_POS_credit_FEES", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_sama_gcc_POS_debit_FEES", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_gcc_POS_credit", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_gcc_POS_debit", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_gcc_POS_credit_FEES", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_gcc_POS_debit_FEES", OracleType.Number).Direction = ParameterDirection.Output;

            oracom.Parameters.Add("p_atm_credit", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_atm_debit", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_pos_credit", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_pos_debit", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_ecom_credit", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_ecom_debit", OracleType.Number).Direction = ParameterDirection.Output;


            oracom.Parameters.Add("p_atm_credit_diff", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_atm_debit_diff", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_pos_credit_diff", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_pos_debit_diff", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_ecom_credit_diff", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_ecom_debit_diff", OracleType.Number).Direction = ParameterDirection.Output;

            oracom.Parameters.Add("p_gcc_atm_credit_diff", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_gcc_atm_debit_diff", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_gcc_atm_credit_diff_FEES", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_gcc_atm_debit_diff_FEES", OracleType.Number).Direction = ParameterDirection.Output;

            oracom.Parameters.Add("p_gcc_POS_credit_diff", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_gcc_POS_debit_diff", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_gcc_POS_credit_diff_FEES", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_gcc_POS_debit_diff_FEES", OracleType.Number).Direction = ParameterDirection.Output;

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

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

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

            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_lang"].Value = "EN";
            oracom.Parameters["p_settl_date"].Value = settlementDate;

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

            oracon.Close();

            ViewState["mode"] = oracom.Parameters["p_status"].Value.ToString();
            /*
                0 - New
                1 - Posted
            */

            errorMsg = oracom.Parameters["p_res_msg"].Value.ToString();
            resCode = int.Parse(oracom.Parameters["p_res_code"].Value.ToString());

            resultParams.Add("p_res_code", resCode);

            if (resCode == 0)
            {
                resultParams.Add("p_sama_atm_credit", double.Parse(oracom.Parameters["p_sama_atm_credit"].Value.ToString()));
                resultParams.Add("p_sama_atm_debit", double.Parse(oracom.Parameters["p_sama_atm_debit"].Value.ToString()));
                resultParams.Add("p_sama_pos_credit", double.Parse(oracom.Parameters["p_sama_pos_credit"].Value.ToString()));
                resultParams.Add("p_sama_pos_debit", double.Parse(oracom.Parameters["p_sama_pos_debit"].Value.ToString()));
                resultParams.Add("p_sama_ecom_credit", double.Parse(oracom.Parameters["p_sama_ecom_credit"].Value.ToString()));
                resultParams.Add("p_sama_ecom_debit", double.Parse(oracom.Parameters["p_sama_ecom_debit"].Value.ToString()));

                resultParams.Add("p_sama_gcc_atm_credit", double.Parse(oracom.Parameters["p_sama_gcc_atm_credit"].Value.ToString()));
                resultParams.Add("p_sama_gcc_atm_debit", double.Parse(oracom.Parameters["p_sama_gcc_atm_debit"].Value.ToString()));
                resultParams.Add("p_sama_gcc_atm_credit_FEES", double.Parse(oracom.Parameters["p_sama_gcc_atm_credit_FEES"].Value.ToString()));
                resultParams.Add("p_sama_gcc_atm_debit_FEES", double.Parse(oracom.Parameters["p_sama_gcc_atm_debit_FEES"].Value.ToString()));

                resultParams.Add("p_sama_gcc_POS_credit", double.Parse(oracom.Parameters["p_sama_gcc_POS_credit"].Value.ToString()));
                resultParams.Add("p_sama_gcc_POS_debit", double.Parse(oracom.Parameters["p_sama_gcc_POS_debit"].Value.ToString()));
                resultParams.Add("p_sama_gcc_POS_credit_FEES", double.Parse(oracom.Parameters["p_sama_gcc_POS_credit_FEES"].Value.ToString()));
                resultParams.Add("p_sama_gcc_POS_debit_FEES", double.Parse(oracom.Parameters["p_sama_gcc_POS_debit_FEES"].Value.ToString()));

                if (ViewState["mode"].ToString().Equals("1"))
                {
                    resultParams.Add("p_app_status", int.Parse(oracom.Parameters["p_app_status"].Value.ToString()));
                    resultParams.Add("p_atm_credit", double.Parse(oracom.Parameters["p_atm_credit"].Value.ToString()));
                    resultParams.Add("p_atm_debit", double.Parse(oracom.Parameters["p_atm_debit"].Value.ToString()));
                    resultParams.Add("p_pos_credit", double.Parse(oracom.Parameters["p_pos_credit"].Value.ToString()));
                    resultParams.Add("p_pos_debit", double.Parse(oracom.Parameters["p_pos_debit"].Value.ToString()));
                    resultParams.Add("p_ecom_credit", double.Parse(oracom.Parameters["p_ecom_credit"].Value.ToString()));
                    resultParams.Add("p_ecom_debit", double.Parse(oracom.Parameters["p_ecom_debit"].Value.ToString()));
                    resultParams.Add("p_gcc_atm_credit", double.Parse(oracom.Parameters["p_gcc_atm_credit"].Value.ToString()));
                    resultParams.Add("p_gcc_atm_debit", double.Parse(oracom.Parameters["p_gcc_atm_debit"].Value.ToString()));
                    if (oracom.Parameters["p_gcc_atm_credit_FEES"].Value.ToString() == "")
                        oracom.Parameters["p_gcc_atm_credit_FEES"].Value = "0";
                    if (oracom.Parameters["p_gcc_atm_debit_FEES"].Value.ToString() == "")
                        oracom.Parameters["p_gcc_atm_debit_FEES"].Value = "0";
                    resultParams.Add("p_gcc_atm_credit_FEES", double.Parse(oracom.Parameters["p_gcc_atm_credit_FEES"].Value.ToString()));
                    resultParams.Add("p_gcc_atm_debit_FEES", double.Parse(oracom.Parameters["p_gcc_atm_debit_FEES"].Value.ToString()));

                    resultParams.Add("p_gcc_POS_credit", double.Parse(oracom.Parameters["p_gcc_POS_credit"].Value.ToString()));
                    resultParams.Add("p_gcc_POS_debit", double.Parse(oracom.Parameters["p_gcc_POS_debit"].Value.ToString()));
                    if (oracom.Parameters["p_gcc_POS_credit_FEES"].Value.ToString() == "")
                        oracom.Parameters["p_gcc_POS_credit_FEES"].Value = "0";
                    if (oracom.Parameters["p_gcc_POS_debit_FEES"].Value.ToString() == "")
                        oracom.Parameters["p_gcc_POS_debit_FEES"].Value = "0";
                    resultParams.Add("p_gcc_POS_credit_FEES", double.Parse(oracom.Parameters["p_gcc_POS_credit_FEES"].Value.ToString()));
                    resultParams.Add("p_gcc_POS_debit_FEES", double.Parse(oracom.Parameters["p_gcc_POS_debit_FEES"].Value.ToString()));

                    resultParams.Add("p_atm_credit_diff", double.Parse(oracom.Parameters["p_atm_credit_diff"].Value.ToString()));
                    resultParams.Add("p_atm_debit_diff", double.Parse(oracom.Parameters["p_atm_debit_diff"].Value.ToString()));
                    resultParams.Add("p_pos_credit_diff", double.Parse(oracom.Parameters["p_pos_credit_diff"].Value.ToString()));
                    resultParams.Add("p_pos_debit_diff", double.Parse(oracom.Parameters["p_pos_debit_diff"].Value.ToString()));
                    resultParams.Add("p_ecom_credit_diff", double.Parse(oracom.Parameters["p_ecom_credit_diff"].Value.ToString()));
                    resultParams.Add("p_ecom_debit_diff", double.Parse(oracom.Parameters["p_ecom_debit_diff"].Value.ToString()));
                    resultParams.Add("p_gcc_atm_credit_diff", double.Parse(oracom.Parameters["p_gcc_atm_credit_diff"].Value.ToString()));
                    resultParams.Add("p_gcc_atm_debit_diff", double.Parse(oracom.Parameters["p_gcc_atm_debit_diff"].Value.ToString()));
                    if (oracom.Parameters["p_gcc_atm_credit_diff_FEES"].Value.ToString() == "")
                        oracom.Parameters["p_gcc_atm_credit_diff_FEES"].Value = "0";
                    if (oracom.Parameters["p_gcc_atm_debit_diff_FEES"].Value.ToString() == "")
                        oracom.Parameters["p_gcc_atm_debit_diff_FEES"].Value = "0";
                    resultParams.Add("p_gcc_atm_credit_diff_FEES", double.Parse(oracom.Parameters["p_gcc_atm_credit_diff_FEES"].Value.ToString()));
                    resultParams.Add("p_gcc_atm_debit_diff_FEES", double.Parse(oracom.Parameters["p_gcc_atm_debit_diff_FEES"].Value.ToString()));

                    resultParams.Add("p_gcc_POS_credit_diff", double.Parse(oracom.Parameters["p_gcc_POS_credit_diff"].Value.ToString()));
                    resultParams.Add("p_gcc_POS_debit_diff", double.Parse(oracom.Parameters["p_gcc_POS_debit_diff"].Value.ToString()));
                    if (oracom.Parameters["p_gcc_POS_credit_diff_FEES"].Value.ToString() == "")
                        oracom.Parameters["p_gcc_POS_credit_diff_FEES"].Value = "0";
                    if (oracom.Parameters["p_gcc_POS_debit_diff_FEES"].Value.ToString() == "")
                        oracom.Parameters["p_gcc_POS_debit_diff_FEES"].Value = "0";
                    resultParams.Add("p_gcc_POS_credit_diff_FEES", double.Parse(oracom.Parameters["p_gcc_POS_credit_diff_FEES"].Value.ToString()));
                    resultParams.Add("p_gcc_POS_debit_diff_FEES", double.Parse(oracom.Parameters["p_gcc_POS_debit_diff_FEES"].Value.ToString()));

                    resultParams.Add("p_is_span_amounts_updatable", double.Parse(oracom.Parameters["p_is_span_amounts_updatable"].Value.ToString()));
                    resultParams.Add("p_is_gcc_amounts_updatable", double.Parse(oracom.Parameters["p_is_gcc_amounts_updatable"].Value.ToString()));
                }
            }
            if (currentMethod.Contains("btn_search_Click"))
                ExceptionUtility.LogException(0, "SAMA_SETTL_OPERATIONS.GET_SAMA_SETTL_FILES_AMOUNTS", "392.1", "searchSamaFiles", "SettlementDate: " + settlementDate);
            return resultParams;
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "SAMA_SETTL_OPERATIONS.GET_SAMA_SETTL_FILES_AMOUNTS", "392.1", "searchSamaFiles", "SettlementDate: " + settlementDate);
            //Response.Redirect("../ErrorPages/ErrorPage.aspx");
            return null;
        }
    }

    private DataSet searchSamaFileDataset(string settlementDate, ref string errorMsg)
    {
        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 = "SAMA_SETTL_OPERATIONS.GET_SAMA_SETTL_FILES_AMOUNTS";

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

            oracom.Parameters.Add("p_settl_date", OracleType.VarChar).Direction = ParameterDirection.Input;

            oracom.Parameters.Add("p_sama_atm_credit", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_sama_atm_debit", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_sama_pos_credit", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_sama_pos_debit", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_sama_gcc_atm_credit", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_sama_gcc_atm_debit", OracleType.Number).Direction = ParameterDirection.Output;

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

            oracom.Parameters.Add("p_atm_credit", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_atm_debit", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_pos_credit", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_pos_debit", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_ecom_credit", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_ecom_debit", OracleType.Number).Direction = ParameterDirection.Output;
            

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

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

            oracom.Parameters.Add("p_atm_credit_diff", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_atm_debit_diff", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_pos_credit_diff", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_pos_debit_diff", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_gcc_atm_credit_diff", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_gcc_atm_debit_diff", OracleType.Number).Direction = ParameterDirection.Output;

            oracom.Parameters.Add("p_gcc_atm_credit_diff_FEES", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_gcc_atm_debit_diff_FEES", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_app_status", OracleType.Number).Direction = ParameterDirection.Output;

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

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

            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_lang"].Value = "EN";
            oracom.Parameters["p_settl_date"].Value = settlementDate;

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

            oracon.Close();
            return ds;
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "SAMA_SETTL_OPERATIONS.GET_SAMA_SETTL_FILES_AMOUNTS", "", "searchSamaFiles", "SettlementDate: " + settlementDate);
            //Response.Redirect("../ErrorPages/ErrorPage.aspx");
            return null;
        }
    }

    protected void btn_search_Click(object sender, EventArgs e)
    {
        intCount = 0;
        this.lbl_error.Text = "";

        string settmelentDate = this.dtp_filter_sttlDate.date;
        string errorMsg = "";

        double resCode = -1;
        ExceptionUtility.LogException(0, "", "72.392", "btn_search_Click", "");
        Dictionary<string, double> results = this.searchSamaFiles(settmelentDate, ref errorMsg);

        resCode = results["p_res_code"];

        if (resCode == 0)
        {
            this.pnl_result.Visible = true;
            //this.pnl_searchCriteria.Enabled = false;
            this.enableResultControls();
            this.btn_save.Enabled = true;

            if (ViewState["mode"].ToString().Equals("0"))
            {

                this.txt_creditATM_amount.Text = "";
                this.txt_debitATM_amount.Text = "";
                this.txt_creditPOS_amount.Text = "";
                this.txt_debitPOS_amount.Text = "";
                this.txt_creditECOM_amount.Text = "";
                this.txt_debitECOM_amount.Text = "";
                this.txt_creditATM_GCC_amount.Text = "";
                this.txt_debitATM_GCC_amount.Text = "";
                this.txt_creditATM_GCC_amount_Fees.Text = "";
                this.txt_debitATM_GCC_amount_Fees.Text = "";

                this.txt_creditPOS_GCC_amount.Text = "";
                this.txt_debitPOS_GCC_amount.Text = "";
                this.txt_creditPOS_GCC_amount_Fees.Text = "";
                this.txt_debitPOS_GCC_amount_Fees.Text = "";

                this.lbl_creditATM_difference.Text = "";
                this.lbl_creditATM_GCC_difference.Text = "";
                this.lbl_creditPOS_GCC_difference.Text = "";
                this.lbl_creditPOS_difference.Text = "";
                this.lbl_creditECOM_difference.Text = "";
                this.lbl_debitATM_difference.Text = "";
                this.lbl_debitATM_GCC_difference.Text = "";
                this.lbl_debitPOS_GCC_difference.Text = "";
                this.lbl_debitPOS_difference.Text = "";
                this.lbl_debitECOM_difference.Text = "";

                this.lbl_creditATM_GCC_difference_Fees.Text = "";
                this.lbl_debitATM_GCC_difference_Fees.Text = "";
                this.lbl_creditPOS_GCC_difference_Fees.Text = "";
                this.lbl_debitPOS_GCC_difference_Fees.Text = "";

                this.btn_save.Text = "   Add   ";

                this.btn_print.Enabled = false;

                this.clearManualControls();

                this.enableResultControls();
            }
            else if (ViewState["mode"].ToString().Equals("1"))
            {
                if (results["p_app_status"] == 0)
                {
                    this.btn_save.Enabled = false;
                }
                this.btn_save.Text = "  Update  ";

                this.btn_print.Enabled = true;

                this.txt_creditATM_amount.Text = results["p_atm_credit"].ToString();
                this.txt_debitATM_amount.Text = results["p_atm_debit"].ToString();
                this.txt_creditPOS_amount.Text = results["p_pos_credit"].ToString();
                this.txt_debitPOS_amount.Text = results["p_pos_debit"].ToString();
                this.txt_creditECOM_amount.Text = results["p_ecom_credit"].ToString();
                this.txt_debitECOM_amount.Text = results["p_ecom_debit"].ToString();
                this.txt_creditATM_GCC_amount.Text = results["p_gcc_atm_credit"].ToString();
                this.txt_debitATM_GCC_amount.Text = results["p_gcc_atm_debit"].ToString();
                this.txt_creditPOS_GCC_amount.Text = results["p_gcc_POS_credit"].ToString();
                this.txt_debitPOS_GCC_amount.Text = results["p_gcc_POS_debit"].ToString();
                this.txt_creditATM_GCC_amount_Fees.Text = results["p_gcc_atm_credit_FEES"].ToString();
                this.txt_debitATM_GCC_amount_Fees.Text = results["p_gcc_atm_debit_FEES"].ToString();
                this.txt_creditPOS_GCC_amount_Fees.Text = results["p_gcc_POS_credit_FEES"].ToString();
                this.txt_debitPOS_GCC_amount_Fees.Text = results["p_gcc_POS_debit_FEES"].ToString();

                this.lbl_creditATM_difference.Text = results["p_atm_credit_diff"].ToString();
                this.lbl_creditATM_GCC_difference.Text = results["p_gcc_atm_credit_diff"].ToString();
                this.lbl_creditPOS_GCC_difference.Text = results["p_gcc_POS_credit_diff"].ToString();
                this.lbl_creditPOS_difference.Text = results["p_pos_credit_diff"].ToString();
                this.lbl_creditECOM_difference.Text = results["p_ecom_credit_diff"].ToString();
                this.lbl_debitATM_difference.Text = results["p_atm_debit_diff"].ToString();
                this.lbl_debitATM_GCC_difference.Text = results["p_gcc_atm_debit_diff"].ToString();
                this.lbl_debitPOS_GCC_difference.Text = results["p_gcc_POS_debit_diff"].ToString();
                this.lbl_debitPOS_difference.Text = results["p_pos_debit_diff"].ToString();
                this.lbl_debitECOM_difference.Text = results["p_ecom_debit_diff"].ToString();
                this.lbl_creditATM_GCC_difference_Fees.Text = results["p_gcc_atm_credit_diff_FEES"].ToString();
                this.lbl_debitATM_GCC_difference_Fees.Text = results["p_gcc_atm_debit_diff_FEES"].ToString();
                this.lbl_creditPOS_GCC_difference_Fees.Text = results["p_gcc_POS_credit_diff_FEES"].ToString();
                this.lbl_debitPOS_GCC_difference_Fees.Text = results["p_gcc_POS_debit_diff_FEES"].ToString();

                if (int.Parse(results["p_is_span_amounts_updatable"].ToString()) == 0)
                {
                    this.txt_creditATM_amount.Enabled = false;
                    this.txt_debitATM_amount.Enabled = false;
                    this.txt_creditPOS_amount.Enabled = false;
                    this.txt_debitPOS_amount.Enabled = false;
                    this.txt_creditECOM_amount.Enabled = false;
                    this.txt_debitECOM_amount.Enabled = false;
                }
                else
                {
                    this.txt_creditATM_amount.Enabled = true;
                    this.txt_debitATM_amount.Enabled = true;
                    this.txt_creditPOS_amount.Enabled = true;
                    this.txt_debitPOS_amount.Enabled = true;
                    this.txt_creditECOM_amount.Enabled = true;
                    this.txt_debitECOM_amount.Enabled = true;
                }

                if (int.Parse(results["p_is_gcc_amounts_updatable"].ToString()) == 0)
                {
                    this.txt_creditATM_GCC_amount.Enabled = false;
                    this.txt_debitATM_GCC_amount.Enabled = false;
                    this.txt_creditATM_GCC_amount_Fees.Enabled = false;
                    this.txt_debitATM_GCC_amount_Fees.Enabled = false;
                    this.txt_creditPOS_GCC_amount.Enabled = false;
                    this.txt_debitPOS_GCC_amount.Enabled = false;
                    this.txt_creditPOS_GCC_amount_Fees.Enabled = false;
                    this.txt_debitPOS_GCC_amount_Fees.Enabled = false;
                }
                else
                {
                    this.txt_creditATM_GCC_amount.Enabled = true;
                    this.txt_debitATM_GCC_amount.Enabled = true;
                    this.txt_creditATM_GCC_amount_Fees.Enabled = true;
                    this.txt_debitATM_GCC_amount_Fees.Enabled = true;
                    this.txt_creditPOS_GCC_amount.Enabled = true;
                    this.txt_debitPOS_GCC_amount.Enabled = true;
                    this.txt_creditPOS_GCC_amount_Fees.Enabled = true;
                    this.txt_debitPOS_GCC_amount_Fees.Enabled = true;
                }
            }

            this.lbl_creditATM_SamaAmount.Text = results["p_sama_atm_credit"].ToString();
            this.lbl_debitATM_SamaAmount.Text = results["p_sama_atm_debit"].ToString();
            this.lbl_creditPOS_SamaAmount.Text = results["p_sama_pos_credit"].ToString();
            this.lbl_debitPOS_SamaAmount.Text = results["p_sama_pos_debit"].ToString();
            this.lbl_creditECOM_SamaAmount.Text = results["p_sama_ecom_credit"].ToString();
            this.lbl_debitECOM_SamaAmount.Text = results["p_sama_ecom_debit"].ToString();
            this.lbl_creditATM_GCC_SamaAmount.Text = results["p_sama_gcc_atm_credit"].ToString();
            this.lbl_debitATM_GCC_SamaAmount.Text = results["p_sama_gcc_atm_debit"].ToString();
            this.lbl_creditATM_GCC_SamaAmount_Fees.Text = results["p_sama_gcc_atm_credit_FEES"].ToString();
            this.lbl_debitATM_GCC_SamaAmount_Fees.Text = results["p_sama_gcc_atm_debit_FEES"].ToString();

            this.lbl_creditPOS_GCC_SamaAmount.Text = results["p_sama_gcc_POS_credit"].ToString();
            this.lbl_debitPOS_GCC_SamaAmount.Text = results["p_sama_gcc_POS_debit"].ToString();
            this.lbl_creditPOS_GCC_SamaAmount_Fees.Text = results["p_sama_gcc_POS_credit_FEES"].ToString();
            this.lbl_debitPOS_GCC_SamaAmount_Fees.Text = results["p_sama_gcc_POS_debit_FEES"].ToString();
        }
        else if (resCode == 9)
        {
            ExceptionUtility.LogException(9, "SAMA_SETTL_OPERATIONS.GET_SAMA_SETTL_FILES_AMOUNTS", "", "btn_search_Click", "");
            this.lbl_error.Text = "No Data Found";

            this.pnl_result.Visible = false;
        }
        else if (resCode == 132)
        {
            ExceptionUtility.LogException(9, "SAMA_SETTL_OPERATIONS.GET_SAMA_SETTL_FILES_AMOUNTS", "", "btn_search_Click", "");
            this.lbl_error.Text = errorMsg;
            this.pnl_result.Visible = false;
        }
    }

    private int addSettlementDetails(string settlementDate, double samaAtmCreditAmount, double samaAtmDebitAmount,
                                      double samaPosCreditAmount, double samaPosDebitAmount,
                                      double samaGccAtmCreditAmount, double samaGccAtmDebitAmount, double samaGccAtmCreditFees, double samaGccAtmDebitFees,
                                      double samaGccPOSCreditAmount, double samaGccPOSDebitAmount, double samaGccPOSCreditFees, double samaGccPOSDebitFees,
                                      double atmCreditAmount, double atmDebitAmount,
                                      double posCreditAmount, double posDebitAmount,
                                     // double ecomCreditAmount, double ecomDebitAmount,  
                                      double gccAtmCreditAmount, double gccAtmDebitAmount, double gccAtmCreditFees, double gccAtmDebitFees,
                                      double gccPOSCreditAmount, double gccPOSDebitAmount, double gccPOSCreditFees, double gccPOSDebitFees,
                                      ref string errorMsg)
    {
        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 = "SAMA_SETTL_OPERATIONS.ADD_SETTLEMENT_DETAILS";

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

            oracom.Parameters.Add("p_settl_date", OracleType.VarChar).Direction = ParameterDirection.Input;

            oracom.Parameters.Add("p_atm_sama_credit", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_atm_sama_debit", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_pos_sama_credit", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_pos_sama_debit", OracleType.Number).Direction = ParameterDirection.Input;

            oracom.Parameters.Add("p_atm_credit", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_atm_debit", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_pos_credit", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_pos_debit", OracleType.Number).Direction = ParameterDirection.Input;

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

            oracom.Parameters.Add("p_gcc_atm_credit", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_gcc_atm_debit", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_gcc_atm_credit_fees", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_gcc_atm_debit_fees", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_gcc_sama_atm_credit", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_gcc_sama_atm_debit", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_gcc_sama_atm_credit_fees", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_gcc_sama_atm_debit_fees", OracleType.Number).Direction = ParameterDirection.Input;

            oracom.Parameters.Add("p_gcc_pos_credit", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_gcc_pos_debit", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_gcc_pos_credit_fees", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_gcc_pos_debit_fees", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_gcc_sama_pos_credit", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_gcc_sama_pos_debit", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_gcc_sama_pos_credit_fees", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_gcc_sama_pos_debit_fees", OracleType.Number).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_lang"].Value = "EN";

            oracom.Parameters["p_settl_date"].Value = settlementDate;

            oracom.Parameters["p_atm_sama_credit"].Value = samaAtmCreditAmount;
            oracom.Parameters["p_atm_sama_debit"].Value = samaAtmDebitAmount;
            oracom.Parameters["p_pos_sama_credit"].Value = samaPosCreditAmount;
            oracom.Parameters["p_pos_sama_debit"].Value = samaPosDebitAmount;

            oracom.Parameters["p_atm_credit"].Value = atmCreditAmount;
            oracom.Parameters["p_atm_debit"].Value = atmDebitAmount;
            oracom.Parameters["p_pos_credit"].Value = posCreditAmount;
            oracom.Parameters["p_pos_debit"].Value = posDebitAmount;

          //  oracom.Parameters["p_ecom_credit"].Value = ecomCreditAmount;
          //  oracom.Parameters["p_ecom_debit"].Value = ecomDebitAmount;

            oracom.Parameters["p_gcc_pos_credit"].Value = gccPOSCreditAmount;
            oracom.Parameters["p_gcc_pos_debit"].Value = gccPOSDebitAmount;
            oracom.Parameters["p_gcc_pos_credit_fees"].Value = gccPOSCreditFees;
            oracom.Parameters["p_gcc_pos_debit_fees"].Value = gccPOSDebitFees;
            oracom.Parameters["p_gcc_sama_pos_credit"].Value = samaGccPOSCreditAmount;
            oracom.Parameters["p_gcc_sama_pos_debit"].Value = samaGccPOSDebitAmount;
            oracom.Parameters["p_gcc_sama_pos_credit_fees"].Value = samaGccPOSCreditFees;
            oracom.Parameters["p_gcc_sama_pos_debit_fees"].Value = samaGccPOSDebitFees;

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

            int resCode = int.Parse(oracom.Parameters["p_res_code"].Value.ToString());
            errorMsg = oracom.Parameters["p_res_msg"].Value.ToString();
            ExceptionUtility.LogException(0, "SAMA_SETTL_OPERATIONS.ADD_SETTLEMENT_DETAILS", "", "addSettlementDetails", "settlementDate: " + settlementDate + ", samaAtmCreditAmount: " + samaAtmCreditAmount + ", samaAtmDebitAmount :" + samaAtmDebitAmount + ", samaPosCreditAmount: " + samaPosCreditAmount + ", samaPosDebitAmount: " + samaPosDebitAmount + ", samaGCCAtmCreditAmount: " + samaGccAtmCreditAmount + ", samaGccAtmDebitAmount: " + samaGccAtmDebitAmount + ", samaGccAtmDebitFees: " + samaGccAtmDebitFees + ", samaGccAtmCreditFees: " + samaGccAtmCreditFees + ", atmCreditAmount: " + atmCreditAmount + ", atmDebitAmount: " + atmDebitAmount + ", PosCreditAmount: " + posCreditAmount + ", posDebitAMount: " + posDebitAmount + ", gccAtmCreditAmount: " + gccAtmCreditAmount + ", gccAtmDebitAMount: " + gccAtmDebitAmount + ", gccAtmCreditFees :" + gccAtmCreditFees + ", gccAtmDebitFees : " + gccAtmDebitFees);
            return resCode;
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "SAMA_SETTL_OPERATIONS.ADD_SETTLEMENT_DETAILS", "", "addSettlementDetails", "settlementDate: " + settlementDate + ", samaAtmCreditAmount: " + samaAtmCreditAmount + ", samaAtmDebitAmount :" + samaAtmDebitAmount + ", samaPosCreditAmount: " + samaPosCreditAmount + ", samaPosDebitAmount: " + samaPosDebitAmount + ", samaGCCAtmCreditAmount: " + samaGccAtmCreditAmount + ", samaGccAtmDebitAmount: " + samaGccAtmDebitAmount + ", samaGccAtmDebitFees: " + samaGccAtmDebitFees + ", samaGccAtmCreditFees: " + samaGccAtmCreditFees + ", atmCreditAmount: " + atmCreditAmount + ", atmDebitAmount: " + atmDebitAmount + ", PosCreditAmount: " + posCreditAmount + ", posDebitAMount: " + posDebitAmount + ", gccAtmCreditAmount: " + gccAtmCreditAmount + ", gccAtmDebitAMount: " + gccAtmDebitAmount + ", gccAtmCreditFees :" + gccAtmCreditFees + ", gccAtmDebitFees : " + gccAtmDebitFees);
            //Response.Redirect("../ErrorPages/ErrorPage.aspx");
            return 0;
        }
    }

    private bool UpdateMakerChecker(int chgId, string tableName, string columnName, string oldValue, string newValue, 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 = pageId;
            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 = this.dtp_filter_sttlDate.date;
            oracom.Parameters["p_chg_status"].Value = 0;
            oracom.Parameters["p_checker_notes"].Value = OracleString.Null;


            oracom.Parameters["p_old_number"].Value = OracleNumber.Null;


            oracom.Parameters["p_new_number"].Value = OracleNumber.Null;


            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", "393.3", "UpdateMakerChecker", "chgId- " + chgId + ": columnName- " + columnName + ": oldValue- " + oldValue + " : newValue- " + newValue + ":chgType- " + chgType);
                return true;
            }
            else
            {
                ExceptionUtility.LogException(9, "MAKER_CHECKER_EDITOR.Add_Maker_Checker", "393.3", "UpdateMakerChecker", "chgId- " + chgId + ": columnName- " + columnName + ": oldValue- " + oldValue + " : newValue- " + newValue + ":chgType- " + chgType);
                return false;
            }
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "MAKER_CHECKER_EDITOR.Add_Maker_Checker", "393.3", "UpdateMakerChecker", "chgId- " + chgId + ": columnName- " + columnName + ": oldValue- " + oldValue + " : newValue- " + newValue + ":chgType- " + chgType);
            //Response.Redirect("../ErrorPages/ErrorPage.aspx");
            return 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();
            ExceptionUtility.LogException(0, "maker_checker_editor.get_chg_id", "393.2", "loadChgID", "");
            return nop;
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "maker_checker_editor.get_chg_id", "393.2", "loadChgID", "");
            //Response.Redirect("../ErrorPages/ErrorPage.aspx");
            return 0;
        }
    }
    private bool Can_Insert()
    {
        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 = "maker_checker_editor.can_insert_dailysamasettlement";

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


            oracom.Parameters["p_settl_date"].Value = this.dtp_filter_sttlDate.date;
            if (dtp_filter_sttlDate.date.Length > 0)
                parameters = "p_settl_date-" + this.dtp_filter_sttlDate.date;
            oracom.ExecuteNonQuery();
            oracon.Close();
            string a = oracom.Parameters["p_res_code"].Value.ToString();
            if (a == "0")
            {
                ExceptionUtility.LogException(0, "maker_checker_editor.can_insert_dailysamasettlement", "393.1", "Can_Insert", parameters);
                return true;
            }
            else
            {
                ExceptionUtility.LogException(9, "maker_checker_editor.can_insert_dailysamasettlement", "393.1", "Can_Insert", parameters);
                return false;
            }
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "maker_checker_editor.can_insert_dailysamasettlement", "393.1", "Can_Insert", parameters);
            //Response.Redirect("../ErrorPages/ErrorPage.aspx");
            return false;
        }
    }
    protected void btn_save_Click(object sender, EventArgs e)
    {
        if (intCount < 1)
            intCount++;
        else
        {
            pnl_result.Visible = false;
            lbl_error.Text = "Your request has been sent to Checker user for Approval";
            return;
        }
        ExceptionUtility.LogException(0, "", "72.393", "btn_save_Click", "");//chgId: " + chgId + ", columnName: " + columnName + ", oldValue: " + oldValue + " , newValue: " + newValue + ",chgType: " + chgType);
        string settlementDate;
        double samaAtmCreditAmount, samaAtmDebitAmount,
                samaPosCreditAmount, samaPosDebitAmount,
                samaECOMCreditAmount, samaECOMDebitAmount,
                atmCreditAmount, atmDebitAmount,
                posCreditAmount, posDebitAmount,
                ECOMCreditAmount, ECOMDebitAmount,

                samaGccAtmCreditAmount, samaGccAtmDebitAmount,
                gccAtmCreditAmount, gccAtmDebitAmount,
                samaGccAtmCreditFees, samaGccAtmDebitFees,
                gccAtmCreditFees, gccAtmDebitFees,
                gccAtmCreditAmountold = 0, gccAtmDebitAmountold = 0,
                gccAtmCreditFeesold = 0, gccAtmDebitFeesold = 0,
                diffDebitATMGCCold = 0, diffDebitATMGCCFeeold = 0,
                diffCreditATMGCCold = 0, diffCreditATMGCCFeeold = 0,

                samaGccPOSCreditAmount, samaGccPOSDebitAmount,
                gccPOSCreditAmount, gccPOSDebitAmount,
                samaGccPOSCreditFees, samaGccPOSDebitFees,
                gccPOSCreditFees, gccPOSDebitFees,
                gccPOSCreditAmountold = 0, gccPOSDebitAmountold = 0,
                gccPOSCreditFeesold = 0, gccPOSDebitFeesold = 0,
                diffDebitPOSGCCold = 0, diffDebitPOSGCCFeeold = 0,
                diffCreditPOSGCCold = 0, diffCreditPOSGCCFeeold = 0,
                diffDebitPOSGCC, diffDebitPOSGCCFee,
                diffCreditPOSGCC, diffCreditPOSGCCFee,

                diffDebitPos, diffCreditPos,
                diffDebitECOM, diffCreditECOM,
                diffDebitATM, diffCreditATM,

                diffDebitATMGCC, diffDebitATMGCCFee,
                diffCreditATMGCC, diffCreditATMGCCFee,

                 atmCreditAmountold = 0, atmDebitAmountold = 0,
                 posCreditAmountold = 0, posDebitAmountold = 0,
                 ECOMCreditAmountold = 0, ECOMDebitAmountold = 0,

                 diffDebitPosold = 0, diffCreditPosold = 0,
                 diffDebitECOMold = 0, diffCreditECOMold = 0,
                 diffDebitATMold = 0, diffCreditATMold = 0;


        string errorMsg = "";


        settlementDate = this.dtp_filter_sttlDate.date;
        samaAtmCreditAmount = double.Parse(this.lbl_creditATM_SamaAmount.Text);
        samaAtmDebitAmount = double.Parse(this.lbl_debitATM_SamaAmount.Text);
        samaPosCreditAmount = double.Parse(this.lbl_creditPOS_SamaAmount.Text);
        samaPosDebitAmount = double.Parse(this.lbl_debitPOS_SamaAmount.Text);
        samaECOMCreditAmount = double.Parse(this.lbl_creditECOM_SamaAmount.Text);
        samaECOMDebitAmount = double.Parse(this.lbl_debitECOM_SamaAmount.Text);


        samaGccAtmCreditAmount = double.Parse(this.lbl_creditATM_GCC_SamaAmount.Text);
        samaGccAtmDebitAmount = double.Parse(this.lbl_debitATM_GCC_SamaAmount.Text);
        samaGccAtmCreditFees = double.Parse(this.lbl_creditATM_GCC_SamaAmount_Fees.Text);
        samaGccAtmDebitFees = double.Parse(this.lbl_debitATM_GCC_SamaAmount_Fees.Text);
        gccAtmCreditAmount = double.Parse(this.txt_creditATM_GCC_amount.Text);
        gccAtmDebitAmount = double.Parse(this.txt_debitATM_GCC_amount.Text);
        gccAtmCreditFees = double.Parse(this.txt_creditATM_GCC_amount_Fees.Text);
        gccAtmDebitFees = double.Parse(this.txt_debitATM_GCC_amount_Fees.Text);
        diffDebitATMGCC = samaGccAtmDebitAmount - gccAtmDebitAmount;
        diffCreditATMGCC = samaGccAtmCreditAmount - gccAtmCreditAmount;
        diffCreditATMGCCFee = samaGccAtmCreditFees - gccAtmCreditFees;
        diffDebitATMGCCFee = samaGccAtmDebitFees - gccAtmDebitFees;

        samaGccPOSCreditAmount = double.Parse(this.lbl_creditPOS_GCC_SamaAmount.Text);
        samaGccPOSDebitAmount = double.Parse(this.lbl_debitPOS_GCC_SamaAmount.Text);
        samaGccPOSCreditFees = double.Parse(this.lbl_creditPOS_GCC_SamaAmount_Fees.Text);
        samaGccPOSDebitFees = double.Parse(this.lbl_debitPOS_GCC_SamaAmount_Fees.Text);
        gccPOSCreditAmount = double.Parse(this.txt_creditPOS_GCC_amount.Text);
        gccPOSDebitAmount = double.Parse(this.txt_debitPOS_GCC_amount.Text);
        gccPOSCreditFees = double.Parse(this.txt_creditPOS_GCC_amount_Fees.Text);
        gccPOSDebitFees = double.Parse(this.txt_debitPOS_GCC_amount_Fees.Text);
        diffDebitPOSGCC = samaGccPOSDebitAmount - gccPOSDebitAmount;
        diffCreditPOSGCC = samaGccPOSCreditAmount - gccPOSCreditAmount;
        diffCreditPOSGCCFee = samaGccPOSCreditFees - gccPOSCreditFees;
        diffDebitPOSGCCFee = samaGccPOSDebitFees - gccPOSDebitFees;

        atmCreditAmount = double.Parse(this.txt_creditATM_amount.Text);
        atmDebitAmount = double.Parse(this.txt_debitATM_amount.Text);
        posCreditAmount = double.Parse(this.txt_creditPOS_amount.Text);
        posDebitAmount = double.Parse(this.txt_debitPOS_amount.Text);
        ECOMCreditAmount = double.Parse(this.txt_creditECOM_amount.Text);
        ECOMDebitAmount = double.Parse(this.txt_debitECOM_amount.Text);


        diffDebitPos = samaPosDebitAmount - posDebitAmount;
        diffCreditPos = samaPosCreditAmount - posCreditAmount;
        diffDebitECOM = samaECOMDebitAmount - ECOMDebitAmount;
        diffCreditECOM = samaECOMCreditAmount - ECOMCreditAmount;
        diffDebitATM = samaAtmDebitAmount - atmDebitAmount;
        diffCreditATM = samaAtmCreditAmount - atmCreditAmount;





        if (ViewState["mode"].ToString() == "0")
        {
            //if (Can_Insert())
            //{
            int chgId = loadChgID();

            bool saved = false;

            saved = UpdateMakerChecker(chgId, "SAMA_SETTL_TOTAL", "SETTL_DATE", "", settlementDate, 0, ref errorMsg);
            if (saved == false)
            {

                if (Helper.OracleError(errorMsg))
                {
                    lbl_error.Text = "An Error Occured!";
                    ExceptionUtility.LogException(9, "", "72.393", "btn_save_Click", errorMsg);
                }
                else
                    lbl_error.Text = errorMsg;
                return;
            }

            saved = UpdateMakerChecker(chgId, "SAMA_SETTL_TOTAL", "AUTO_CR_ATM_ACQ_AMT", "", samaAtmCreditAmount.ToString(), int.Parse(ViewState["mode"].ToString()), ref errorMsg);
            if (saved == false)
            {
                if (Helper.OracleError(errorMsg))
                {
                    lbl_error.Text = "An Error Occured!";
                    ExceptionUtility.LogException(9, "", "72.393", "btn_save_Click", errorMsg);
                }
                else
                    lbl_error.Text = errorMsg;
                return;
            }
            saved = UpdateMakerChecker(chgId, "SAMA_SETTL_TOTAL", "AUTO_DR_ATM_ISS_AMT", "", samaAtmDebitAmount.ToString(), int.Parse(ViewState["mode"].ToString()), ref errorMsg);
            if (saved == false)
            {
                if (Helper.OracleError(errorMsg))
                {
                    lbl_error.Text = "An Error Occured!";
                    ExceptionUtility.LogException(9, "", "72.393", "btn_save_Click", errorMsg);
                }
                else
                    lbl_error.Text = errorMsg;
                return;
            }
            saved = UpdateMakerChecker(chgId, "SAMA_SETTL_TOTAL", "AUTO_CR_POS_ACQ_AMT", "", samaPosCreditAmount.ToString(), int.Parse(ViewState["mode"].ToString()), ref errorMsg);
            if (saved == false)
            {
                if (Helper.OracleError(errorMsg))
                {
                    lbl_error.Text = "An Error Occured!";
                    ExceptionUtility.LogException(9, "", "72.393", "btn_save_Click", errorMsg);
                }
                else
                    lbl_error.Text = errorMsg;
                return;
            }
            saved = UpdateMakerChecker(chgId, "SAMA_SETTL_TOTAL", "AUTO_DR_POS_ACQ_AMT", "", samaPosDebitAmount.ToString(), int.Parse(ViewState["mode"].ToString()), ref errorMsg);
            if (saved == false)
            {
                if (Helper.OracleError(errorMsg))
                {
                    lbl_error.Text = "An Error Occured!";
                    ExceptionUtility.LogException(9, "", "72.393", "btn_save_Click", errorMsg);
                }
                else
                    lbl_error.Text = errorMsg;
                return;
            }
            /**/
            saved = UpdateMakerChecker(chgId, "SAMA_SETTL_TOTAL", "AUTO_CR_ECOM_ACQ_AMT", "", samaECOMCreditAmount.ToString(), int.Parse(ViewState["mode"].ToString()), ref errorMsg);
            if (saved == false)
            {
                if (Helper.OracleError(errorMsg))
                {
                    lbl_error.Text = "An Error Occured!";
                    ExceptionUtility.LogException(9, "", "72.393", "btn_save_Click", errorMsg);
                }
                else
                    lbl_error.Text = errorMsg;
                return;
            }
            saved = UpdateMakerChecker(chgId, "SAMA_SETTL_TOTAL", "AUTO_DR_ECOM_ACQ_AMT", "", samaECOMDebitAmount.ToString(), int.Parse(ViewState["mode"].ToString()), ref errorMsg);
            if (saved == false)
            {
                if (Helper.OracleError(errorMsg))
                {
                    lbl_error.Text = "An Error Occured!";
                    ExceptionUtility.LogException(9, "", "72.393", "btn_save_Click", errorMsg);
                }
                else
                    lbl_error.Text = errorMsg;
                return;
            }
            /**/
            saved = UpdateMakerChecker(chgId, "SAMA_SETTL_TOTAL", "AUTO_CR_ATM_ACQ_AMT_GCC", "", samaGccAtmCreditAmount.ToString(), int.Parse(ViewState["mode"].ToString()), ref errorMsg);
            if (saved == false)
            {
                if (Helper.OracleError(errorMsg))
                {
                    lbl_error.Text = "An Error Occured!";
                    ExceptionUtility.LogException(9, "", "72.393", "btn_save_Click", errorMsg);
                }
                else
                    lbl_error.Text = errorMsg;
                return;
            }
            saved = UpdateMakerChecker(chgId, "SAMA_SETTL_TOTAL", "AUTO_DR_ATM_ISS_AMT_GCC", "", samaGccAtmDebitAmount.ToString(), int.Parse(ViewState["mode"].ToString()), ref errorMsg);
            if (saved == false)
            {
                if (Helper.OracleError(errorMsg))
                {
                    lbl_error.Text = "An Error Occured!";
                    ExceptionUtility.LogException(9, "", "72.393", "btn_save_Click", errorMsg);
                }
                else
                    lbl_error.Text = errorMsg;
                return;
            }
            saved = UpdateMakerChecker(chgId, "SAMA_SETTL_TOTAL", "AUTO_CR_ATM_ACQ_AMT_GCC_FEES", "", samaGccAtmCreditFees.ToString(), int.Parse(ViewState["mode"].ToString()), ref errorMsg);
            if (saved == false)
            {
                if (Helper.OracleError(errorMsg))
                {
                    lbl_error.Text = "An Error Occured!";
                    ExceptionUtility.LogException(9, "", "72.393", "btn_save_Click", errorMsg);
                }
                else
                    lbl_error.Text = errorMsg;
                return;
            }
            saved = UpdateMakerChecker(chgId, "SAMA_SETTL_TOTAL", "AUTO_DR_ATM_ISS_AMT_GCC_FEES", "", samaGccAtmDebitFees.ToString(), int.Parse(ViewState["mode"].ToString()), ref errorMsg);
            if (saved == false)
            {
                if (Helper.OracleError(errorMsg))
                {
                    lbl_error.Text = "An Error Occured!";
                    ExceptionUtility.LogException(9, "", "72.393", "btn_save_Click", errorMsg);
                }
                else
                    lbl_error.Text = errorMsg;
                return;
            }
            saved = UpdateMakerChecker(chgId, "SAMA_SETTL_TOTAL", "MANUEL_CR_ATM_ACQ_AMT", samaAtmCreditAmount.ToString(), atmCreditAmount.ToString(), int.Parse(ViewState["mode"].ToString()), ref errorMsg);
            if (saved == false)
            {
                if (Helper.OracleError(errorMsg))
                {
                    lbl_error.Text = "An Error Occured!";
                    ExceptionUtility.LogException(9, "", "72.393", "btn_save_Click", errorMsg);
                }
                else
                    lbl_error.Text = errorMsg;
                return;
            }
            saved = UpdateMakerChecker(chgId, "SAMA_SETTL_TOTAL", "MANUEL_DR_ATM_ISS_AMT", samaAtmDebitAmount.ToString(), atmDebitAmount.ToString(), int.Parse(ViewState["mode"].ToString()), ref errorMsg);
            if (saved == false)
            {
                if (Helper.OracleError(errorMsg))
                {
                    lbl_error.Text = "An Error Occured!";
                    ExceptionUtility.LogException(9, "", "72.393", "btn_save_Click", errorMsg);
                }
                else
                    lbl_error.Text = errorMsg;
                return;
            }
            saved = UpdateMakerChecker(chgId, "SAMA_SETTL_TOTAL", "MANUEL_CR_POS_ACQ_AMT", samaPosCreditAmount.ToString(), posCreditAmount.ToString(), int.Parse(ViewState["mode"].ToString()), ref errorMsg);
            if (saved == false)
            {
                if (Helper.OracleError(errorMsg))
                {
                    lbl_error.Text = "An Error Occured!";
                    ExceptionUtility.LogException(9, "", "72.393", "btn_save_Click", errorMsg);
                }
                else
                    lbl_error.Text = errorMsg;
                return;
            }
            saved = UpdateMakerChecker(chgId, "SAMA_SETTL_TOTAL", "MANUEL_DR_POS_ACQ_AMT", samaPosDebitAmount.ToString(), posDebitAmount.ToString(), int.Parse(ViewState["mode"].ToString()), ref errorMsg);
            if (saved == false)
            {
                if (Helper.OracleError(errorMsg))
                {
                    lbl_error.Text = "An Error Occured!";
                    ExceptionUtility.LogException(9, "", "72.393", "btn_save_Click", errorMsg);
                }
                else
                    lbl_error.Text = errorMsg;
                return;
            }
            /**/
            saved = UpdateMakerChecker(chgId, "SAMA_SETTL_TOTAL", "MANUEL_CR_ECOM_ACQ_AMT", samaECOMCreditAmount.ToString(), ECOMCreditAmount.ToString(), int.Parse(ViewState["mode"].ToString()), ref errorMsg);
            if (saved == false)
            {
                if (Helper.OracleError(errorMsg))
                {
                    lbl_error.Text = "An Error Occured!";
                    ExceptionUtility.LogException(9, "", "72.393", "btn_save_Click", errorMsg);
                }
                else
                    lbl_error.Text = errorMsg;
                return;
            }
            saved = UpdateMakerChecker(chgId, "SAMA_SETTL_TOTAL", "MANUEL_DR_ECOM_ACQ_AMT", samaECOMDebitAmount.ToString(), ECOMDebitAmount.ToString(), int.Parse(ViewState["mode"].ToString()), ref errorMsg);
            if (saved == false)
            {
                if (Helper.OracleError(errorMsg))
                {
                    lbl_error.Text = "An Error Occured!";
                    ExceptionUtility.LogException(9, "", "72.393", "btn_save_Click", errorMsg);
                }
                else
                    lbl_error.Text = errorMsg;
                return;
            }
            /**/
            saved = UpdateMakerChecker(chgId, "SAMA_SETTL_TOTAL", "MANUEL_CR_ATM_ACQ_AMT_GCC", samaGccAtmCreditAmount.ToString(), gccAtmCreditAmount.ToString(), int.Parse(ViewState["mode"].ToString()), ref errorMsg);
            if (saved == false)
            {
                if (Helper.OracleError(errorMsg))
                {
                    lbl_error.Text = "An Error Occured!";
                    ExceptionUtility.LogException(9, "", "72.393", "btn_save_Click", errorMsg);
                }
                else
                    lbl_error.Text = errorMsg;
                return;
            }
            saved = UpdateMakerChecker(chgId, "SAMA_SETTL_TOTAL", "MANUEL_DR_ATM_ISS_AMT_GCC", samaGccAtmDebitAmount.ToString(), gccAtmDebitAmount.ToString(), int.Parse(ViewState["mode"].ToString()), ref errorMsg);
            if (saved == false)
            {
                if (Helper.OracleError(errorMsg))
                {
                    lbl_error.Text = "An Error Occured!";
                    ExceptionUtility.LogException(9, "", "72.393", "btn_save_Click", errorMsg);
                }
                else
                    lbl_error.Text = errorMsg;
                return;
            }
            saved = UpdateMakerChecker(chgId, "SAMA_SETTL_TOTAL", "MANUEL_CR_ATM_ACQ_AMT_GCC_FEES", samaGccAtmCreditFees.ToString(), gccAtmCreditFees.ToString(), int.Parse(ViewState["mode"].ToString()), ref errorMsg);
            if (saved == false)
            {
                if (Helper.OracleError(errorMsg))
                {
                    lbl_error.Text = "An Error Occured!";
                    ExceptionUtility.LogException(9, "", "72.393", "btn_save_Click", errorMsg);
                }
                else
                    lbl_error.Text = errorMsg;
                return;
            }
            saved = UpdateMakerChecker(chgId, "SAMA_SETTL_TOTAL", "MANUEL_DR_ATM_ISS_AMT_GCC_FEES", samaGccAtmDebitFees.ToString(), gccAtmDebitFees.ToString(), int.Parse(ViewState["mode"].ToString()), ref errorMsg);
            if (saved == false)
            {
                if (Helper.OracleError(errorMsg))
                {
                    lbl_error.Text = "An Error Occured!";
                    ExceptionUtility.LogException(9, "", "72.393", "btn_save_Click", errorMsg);
                }
                else
                    lbl_error.Text = errorMsg;
                return;
            }
            saved = UpdateMakerChecker(chgId, "SAMA_SETTL_TOTAL", "DIFF_DR_ATM_ISS_AMT", "", diffDebitATM.ToString(), int.Parse(ViewState["mode"].ToString()), ref errorMsg);
            if (saved == false)
            {
                if (Helper.OracleError(errorMsg))
                {
                    lbl_error.Text = "An Error Occured!";
                    ExceptionUtility.LogException(9, "", "72.393", "btn_save_Click", errorMsg);
                }
                else
                    lbl_error.Text = errorMsg;
                return;
            }
            saved = UpdateMakerChecker(chgId, "SAMA_SETTL_TOTAL", "DIFF_CR_ATM_ACQ_AMT", "", diffCreditATM.ToString(), int.Parse(ViewState["mode"].ToString()), ref errorMsg);
            if (saved == false)
            {
                if (Helper.OracleError(errorMsg))
                {
                    lbl_error.Text = "An Error Occured!";
                    ExceptionUtility.LogException(9, "", "72.393", "btn_save_Click", errorMsg);
                }
                else
                    lbl_error.Text = errorMsg;
                return;
            }
            saved = UpdateMakerChecker(chgId, "SAMA_SETTL_TOTAL", "DIFF_DR_POS_ACQ_AMT", "", diffDebitPos.ToString(), int.Parse(ViewState["mode"].ToString()), ref errorMsg);
            if (saved == false)
            {
                if (Helper.OracleError(errorMsg))
                {
                    lbl_error.Text = "An Error Occured!";
                    ExceptionUtility.LogException(9, "", "72.393", "btn_save_Click", errorMsg);
                }
                else
                    lbl_error.Text = errorMsg;
                return;
            }
            saved = UpdateMakerChecker(chgId, "SAMA_SETTL_TOTAL", "DIFF_CR_POS_ACQ_AMT", "", diffCreditPos.ToString(), int.Parse(ViewState["mode"].ToString()), ref errorMsg);
            if (saved == false)
            {
                if (Helper.OracleError(errorMsg))
                {
                    lbl_error.Text = "An Error Occured!";
                    ExceptionUtility.LogException(9, "", "72.393", "btn_save_Click", errorMsg);
                }
                else
                    lbl_error.Text = errorMsg;
                return;
            }
            /**/
            saved = UpdateMakerChecker(chgId, "SAMA_SETTL_TOTAL", "DIFF_DR_ECOM_ACQ_AMT", "", diffDebitECOM.ToString(), int.Parse(ViewState["mode"].ToString()), ref errorMsg);
            if (saved == false)
            {
                if (Helper.OracleError(errorMsg))
                {
                    lbl_error.Text = "An Error Occured!";
                    ExceptionUtility.LogException(9, "", "72.393", "btn_save_Click", errorMsg);
                }
                else
                    lbl_error.Text = errorMsg;
                return;
            }
            saved = UpdateMakerChecker(chgId, "SAMA_SETTL_TOTAL", "DIFF_CR_ECOM_ISS_AMT", "", diffCreditECOM.ToString(), int.Parse(ViewState["mode"].ToString()), ref errorMsg);
            if (saved == false)
            {
                if (Helper.OracleError(errorMsg))
                {
                    lbl_error.Text = "An Error Occured!";
                    ExceptionUtility.LogException(9, "", "72.393", "btn_save_Click", errorMsg);
                }
                else
                    lbl_error.Text = errorMsg;
                return;
            }
            /**/
            saved = UpdateMakerChecker(chgId, "SAMA_SETTL_TOTAL", "DIFF_DR_ATM_ISS_AMT_GCC", "", diffDebitATMGCC.ToString(), int.Parse(ViewState["mode"].ToString()), ref errorMsg);
            if (saved == false)
            {
                if (Helper.OracleError(errorMsg))
                {
                    lbl_error.Text = "An Error Occured!";
                    ExceptionUtility.LogException(9, "", "72.393", "btn_save_Click", errorMsg);
                }
                else
                    lbl_error.Text = errorMsg;
                return;
            }
            saved = UpdateMakerChecker(chgId, "SAMA_SETTL_TOTAL", "DIFF_CR_ATM_ACQ_AMT_GCC", "", diffCreditATMGCC.ToString(), int.Parse(ViewState["mode"].ToString()), ref errorMsg);
            if (saved == false)
            {
                if (Helper.OracleError(errorMsg))
                {
                    lbl_error.Text = "An Error Occured!";
                    ExceptionUtility.LogException(9, "", "72.393", "btn_save_Click", errorMsg);
                }
                else
                    lbl_error.Text = errorMsg;
                return;
            }
            saved = UpdateMakerChecker(chgId, "SAMA_SETTL_TOTAL", "DIFF_DR_ATM_ISS_AMT_GCC_FEES", "", diffDebitATMGCCFee.ToString(), int.Parse(ViewState["mode"].ToString()), ref errorMsg);
            if (saved == false)
            {
                if (Helper.OracleError(errorMsg))
                {
                    lbl_error.Text = "An Error Occured!";
                    ExceptionUtility.LogException(9, "", "72.393", "btn_save_Click", errorMsg);
                }
                else
                    lbl_error.Text = errorMsg;
                return;
            }
            saved = UpdateMakerChecker(chgId, "SAMA_SETTL_TOTAL", "DIFF_CR_ATM_ACQ_AMT_GCC_FEES", "", diffCreditATMGCCFee.ToString(), int.Parse(ViewState["mode"].ToString()), ref errorMsg);
            if (saved == false)
            {
                if (Helper.OracleError(errorMsg))
                {
                    lbl_error.Text = "An Error Occured!";
                    ExceptionUtility.LogException(9, "", "72.393", "btn_save_Click", errorMsg);
                }
                else
                    lbl_error.Text = errorMsg;
                return;
            }

            /*----------------------------POS GCC -----------------------------------------------------*/
            saved = UpdateMakerChecker(chgId, "SAMA_SETTL_TOTAL", "AUTO_CR_POS_ACQ_AMT_GCC", "", samaGccPOSCreditAmount.ToString(), int.Parse(ViewState["mode"].ToString()), ref errorMsg);
            if (saved == false)
            {
                if (Helper.OracleError(errorMsg))
                {
                    lbl_error.Text = "An Error Occured!";
                    ExceptionUtility.LogException(9, "", "72.393", "btn_save_Click", errorMsg);
                }
                else
                    lbl_error.Text = errorMsg;
                return;
            }
            saved = UpdateMakerChecker(chgId, "SAMA_SETTL_TOTAL", "AUTO_DR_POS_ISS_AMT_GCC", "", samaGccPOSDebitAmount.ToString(), int.Parse(ViewState["mode"].ToString()), ref errorMsg);
            if (saved == false)
            {
                if (Helper.OracleError(errorMsg))
                {
                    lbl_error.Text = "An Error Occured!";
                    ExceptionUtility.LogException(9, "", "72.393", "btn_save_Click", errorMsg);
                }
                else
                    lbl_error.Text = errorMsg;
                return;
            }
            saved = UpdateMakerChecker(chgId, "SAMA_SETTL_TOTAL", "AUTO_CR_POS_ACQ_AMT_GCC_FEES", "", samaGccPOSCreditFees.ToString(), int.Parse(ViewState["mode"].ToString()), ref errorMsg);
            if (saved == false)
            {
                if (Helper.OracleError(errorMsg))
                {
                    lbl_error.Text = "An Error Occured!";
                    ExceptionUtility.LogException(9, "", "72.393", "btn_save_Click", errorMsg);
                }
                else
                    lbl_error.Text = errorMsg;
                return;
            }
            saved = UpdateMakerChecker(chgId, "SAMA_SETTL_TOTAL", "AUTO_DR_POS_ISS_AMT_GCC_FEES", "", samaGccPOSDebitFees.ToString(), int.Parse(ViewState["mode"].ToString()), ref errorMsg);
            if (saved == false)
            {
                if (Helper.OracleError(errorMsg))
                {
                    lbl_error.Text = "An Error Occured!";
                    ExceptionUtility.LogException(9, "", "72.393", "btn_save_Click", errorMsg);
                }
                else
                    lbl_error.Text = errorMsg;
                return;
            }
            /**/
            saved = UpdateMakerChecker(chgId, "SAMA_SETTL_TOTAL", "MANUEL_CR_POS_ACQ_AMT_GCC", samaGccPOSCreditAmount.ToString(), gccPOSCreditAmount.ToString(), int.Parse(ViewState["mode"].ToString()), ref errorMsg);
            if (saved == false)
            {
                if (Helper.OracleError(errorMsg))
                {
                    lbl_error.Text = "An Error Occured!";
                    ExceptionUtility.LogException(9, "", "72.393", "btn_save_Click", errorMsg);
                }
                else
                    lbl_error.Text = errorMsg;
                return;
            }
            saved = UpdateMakerChecker(chgId, "SAMA_SETTL_TOTAL", "MANUEL_DR_POS_ISS_AMT_GCC", samaGccPOSDebitAmount.ToString(), gccPOSDebitAmount.ToString(), int.Parse(ViewState["mode"].ToString()), ref errorMsg);
            if (saved == false)
            {
                if (Helper.OracleError(errorMsg))
                {
                    lbl_error.Text = "An Error Occured!";
                    ExceptionUtility.LogException(9, "", "72.393", "btn_save_Click", errorMsg);
                }
                else
                    lbl_error.Text = errorMsg;
                return;
            }
            saved = UpdateMakerChecker(chgId, "SAMA_SETTL_TOTAL", "MANUEL_CR_POS_ACQ_AMT_GCC_FEES", samaGccPOSCreditFees.ToString(), gccPOSCreditFees.ToString(), int.Parse(ViewState["mode"].ToString()), ref errorMsg);
            if (saved == false)
            {
                if (Helper.OracleError(errorMsg))
                {
                    lbl_error.Text = "An Error Occured!";
                    ExceptionUtility.LogException(9, "", "72.393", "btn_save_Click", errorMsg);
                }
                else
                    lbl_error.Text = errorMsg;
                return;
            }
            saved = UpdateMakerChecker(chgId, "SAMA_SETTL_TOTAL", "MANUEL_DR_POS_ISS_AMT_GCC_FEES", samaGccPOSDebitFees.ToString(), gccPOSDebitFees.ToString(), int.Parse(ViewState["mode"].ToString()), ref errorMsg);
            if (saved == false)
            {
                if (Helper.OracleError(errorMsg))
                {
                    lbl_error.Text = "An Error Occured!";
                    ExceptionUtility.LogException(9, "", "72.393", "btn_save_Click", errorMsg);
                }
                else
                    lbl_error.Text = errorMsg;
                return;
            }
            saved = UpdateMakerChecker(chgId, "SAMA_SETTL_TOTAL", "DIFF_CR_POS_ACQ_AMT_GCC", "", diffCreditPOSGCC.ToString(), int.Parse(ViewState["mode"].ToString()), ref errorMsg);
            if (saved == false)
            {
                if (Helper.OracleError(errorMsg))
                {
                    lbl_error.Text = "An Error Occured!";
                    ExceptionUtility.LogException(9, "", "72.393", "btn_save_Click", errorMsg);
                }
                else
                    lbl_error.Text = errorMsg;
                return;
            }
            saved = UpdateMakerChecker(chgId, "SAMA_SETTL_TOTAL", "DIFF_DR_POS_ISS_AMT_GCC_FEES", "", diffDebitPOSGCCFee.ToString(), int.Parse(ViewState["mode"].ToString()), ref errorMsg);
            if (saved == false)
            {
                if (Helper.OracleError(errorMsg))
                {
                    lbl_error.Text = "An Error Occured!";
                    ExceptionUtility.LogException(9, "", "72.393", "btn_save_Click", errorMsg);
                }
                else
                    lbl_error.Text = errorMsg;
                return;
            }
            saved = UpdateMakerChecker(chgId, "SAMA_SETTL_TOTAL", "DIFF_CR_POS_ACQ_AMT_GCC_FEES", "", diffCreditPOSGCCFee.ToString(), int.Parse(ViewState["mode"].ToString()), ref errorMsg);
            if (saved == false)
            {
                if (Helper.OracleError(errorMsg))
                {
                    lbl_error.Text = "An Error Occured!";
                    ExceptionUtility.LogException(9, "", "72.393", "btn_save_Click", errorMsg);
                }
                else
                    lbl_error.Text = errorMsg;
                return;
            }
            //resCode = this.addSettlementDetails(settlementDate, samaAtmCreditAmount, samaAtmDebitAmount,
            //                          samaPosCreditAmount, samaPosDebitAmount, samaGccAtmCreditAmount,
            //                          samaGccAtmDebitAmount, samaGccAtmCreditFees,
            //                          samaGccAtmDebitFees, atmCreditAmount, atmDebitAmount,
            //                          posCreditAmount, posDebitAmount, gccAtmCreditAmount,
            //                          gccAtmDebitAmount, gccAtmCreditFees, gccAtmDebitFees, ref errorMsg);

            //if (resCode == 0)
            //{
            this.lbl_error.Text = "Your request has been sent to Checker user for Approval";

            //this.disableResultControls();
            this.clearResultControls();
            this.pnl_result.Visible = false;

            this.btn_save.Enabled = false;
            this.pnl_searchCriteria.Enabled = true;

            //}
            //else if (resCode == 131)
            //{
            //    this.lbl_error.Text = errorMsg;
            //}
            //else
            //{
            //    this.lbl_error.Text = errorMsg;
            //}
            //}
            //else
            //{
            //    lbl_error.Text = "Request is already sent for the selected settlement date";
            //}
        }
        else if (ViewState["mode"].ToString() == "1")
        {
            //resCode = this.updateSettlementDetails( settlementDate, samaAtmCreditAmount, samaAtmDebitAmount,
            //                                        samaPosCreditAmount, samaPosDebitAmount, samaGccAtmCreditAmount,
            //                                        samaGccAtmDebitAmount, samaGccAtmCreditFees, samaGccAtmDebitFees,
            //                                        atmCreditAmount, atmDebitAmount,
            //                                        posCreditAmount, posDebitAmount, gccAtmCreditAmount,
            //                                        gccAtmDebitAmount, gccAtmCreditFees, gccAtmDebitFees, ref errorMsg);

            //if (resCode == 0)
            //{
            string settmelentDate = this.dtp_filter_sttlDate.date;

            double resCode = -1;

            Dictionary<string, double> results = this.searchSamaFiles(settmelentDate, ref errorMsg);

            resCode = results["p_res_code"];

            atmCreditAmountold = results["p_atm_credit"];
            atmDebitAmountold = results["p_atm_debit"];
            posCreditAmountold = results["p_pos_credit"];
            posDebitAmountold = results["p_pos_debit"];
            ECOMCreditAmountold = results["p_ecom_credit"];
            ECOMDebitAmountold = results["p_ecom_debit"];

            gccAtmCreditAmountold = results["p_gcc_atm_credit"];
            gccAtmDebitAmountold = results["p_gcc_atm_debit"];
            gccAtmCreditFeesold = results["p_gcc_atm_credit_FEES"];
            gccAtmDebitFeesold = results["p_gcc_atm_debit_FEES"];

            gccPOSCreditAmountold = results["p_gcc_POS_credit"];
            gccPOSDebitAmountold = results["p_gcc_POS_debit"];
            gccPOSCreditFeesold = results["p_gcc_POS_credit_FEES"];
            gccPOSDebitFeesold = results["p_gcc_POS_debit_FEES"];


            diffCreditATMold = results["p_atm_credit_diff"];
            diffCreditPosold = results["p_pos_credit_diff"];
            diffDebitPosold = results["p_atm_debit_diff"];
           // diffCreditECOMold = results["p_ecom_credit_diff"];
           // diffDebitECOMold = results["p_ecom_debit_diff"];
            diffDebitATMold = results["p_gcc_atm_credit_diff"];

            diffDebitATMGCCold = results["p_pos_debit_diff"];
            diffCreditATMGCCold = results["p_gcc_atm_debit_diff"];
            diffCreditATMGCCFeeold = results["p_gcc_atm_credit_diff_FEES"];
            diffDebitATMGCCFeeold = results["p_gcc_atm_debit_diff_FEES"];

            diffDebitPOSGCCold = results["p_pos_debit_diff"];
            diffCreditPOSGCCold = results["p_gcc_POS_debit_diff"];
            diffCreditPOSGCCFeeold = results["p_gcc_POS_credit_diff_FEES"];
            diffDebitPOSGCCFeeold = results["p_gcc_POS_debit_diff_FEES"];



            int chgId = loadChgID();

            bool saved = false;

            //saved = UpdateMakerChecker(chgId, "SAMA_SETTL_TOTAL", "SETTL_DATE", "", settlementDate,1, ref errorMsg);
            //if (saved == false)
            //{
            //    lbl_error.Text = errorMsg;
            //    return;
            //}

            if (atmCreditAmount != atmCreditAmountold)
            {
                saved = UpdateMakerChecker(chgId, "SAMA_SETTL_TOTAL", "MANUEL_CR_ATM_ACQ_AMT", atmCreditAmountold.ToString(), atmCreditAmount.ToString(), int.Parse(ViewState["mode"].ToString()), ref errorMsg);
                if (saved == false)
                {
                    if (Helper.OracleError(errorMsg))
                    {
                        lbl_error.Text = "An Error Occured!";
                        ExceptionUtility.LogException(9, "", "72.393", "btn_save_Click", errorMsg);
                    }
                    else
                        lbl_error.Text = errorMsg;
                    return;
                }
                saved = UpdateMakerChecker(chgId, "SAMA_SETTL_TOTAL", "DIFF_CR_ATM_ACQ_AMT", diffCreditATMold.ToString(), diffCreditATM.ToString(), int.Parse(ViewState["mode"].ToString()), ref errorMsg);
                if (saved == false)
                {
                    if (Helper.OracleError(errorMsg))
                    {
                        lbl_error.Text = "An Error Occured!";
                        ExceptionUtility.LogException(9, "", "72.393", "btn_save_Click", errorMsg);
                    }
                    else
                        lbl_error.Text = errorMsg;
                    return;
                }
            }
            if (atmDebitAmount != atmDebitAmountold)
            {
                saved = UpdateMakerChecker(chgId, "SAMA_SETTL_TOTAL", "MANUEL_DR_ATM_ISS_AMT", atmDebitAmountold.ToString(), atmDebitAmount.ToString(), int.Parse(ViewState["mode"].ToString()), ref errorMsg);
                if (saved == false)
                {
                    if (Helper.OracleError(errorMsg))
                    {
                        lbl_error.Text = "An Error Occured!";
                        ExceptionUtility.LogException(9, "", "72.393", "btn_save_Click", errorMsg);
                    }
                    else
                        lbl_error.Text = errorMsg;
                    return;
                }
                saved = UpdateMakerChecker(chgId, "SAMA_SETTL_TOTAL", "DIFF_DR_ATM_ISS_AMT", diffDebitATMold.ToString(), diffDebitATM.ToString(), int.Parse(ViewState["mode"].ToString()), ref errorMsg);
                if (saved == false)
                {
                    if (Helper.OracleError(errorMsg))
                    {
                        lbl_error.Text = "An Error Occured!";
                        ExceptionUtility.LogException(9, "", "72.393", "btn_save_Click", errorMsg);
                    }
                    else
                        lbl_error.Text = errorMsg;
                    return;
                }
            }
            if (posCreditAmount != posCreditAmountold)
            {
                saved = UpdateMakerChecker(chgId, "SAMA_SETTL_TOTAL", "MANUEL_CR_POS_ACQ_AMT", posCreditAmountold.ToString(), posCreditAmount.ToString(), int.Parse(ViewState["mode"].ToString()), ref errorMsg);
                if (saved == false)
                {
                    if (Helper.OracleError(errorMsg))
                    {
                        lbl_error.Text = "An Error Occured!";
                        ExceptionUtility.LogException(9, "", "72.393", "btn_save_Click", errorMsg);
                    }
                    else
                        lbl_error.Text = errorMsg;
                    return;
                }
                saved = UpdateMakerChecker(chgId, "SAMA_SETTL_TOTAL", "DIFF_CR_POS_ACQ_AMT", diffCreditPosold.ToString(), diffCreditPos.ToString(), int.Parse(ViewState["mode"].ToString()), ref errorMsg);
                if (saved == false)
                {
                    if (Helper.OracleError(errorMsg))
                    {
                        lbl_error.Text = "An Error Occured!";
                        ExceptionUtility.LogException(9, "", "72.393", "btn_save_Click", errorMsg);
                    }
                    else
                        lbl_error.Text = errorMsg;
                    return;
                }
            }
            if (posDebitAmount != posDebitAmountold)
            {
                saved = UpdateMakerChecker(chgId, "SAMA_SETTL_TOTAL", "MANUEL_DR_POS_ACQ_AMT", posDebitAmountold.ToString(), posDebitAmount.ToString(), int.Parse(ViewState["mode"].ToString()), ref errorMsg);
                if (saved == false)
                {
                    if (Helper.OracleError(errorMsg))
                    {
                        lbl_error.Text = "An Error Occured!";
                        ExceptionUtility.LogException(9, "", "72.393", "btn_save_Click", errorMsg);
                    }
                    else
                        lbl_error.Text = errorMsg;
                    return;
                }
                saved = UpdateMakerChecker(chgId, "SAMA_SETTL_TOTAL", "DIFF_DR_POS_ACQ_AMT", diffDebitPosold.ToString(), diffDebitPos.ToString(), int.Parse(ViewState["mode"].ToString()), ref errorMsg);
                if (saved == false)
                {
                    if (Helper.OracleError(errorMsg))
                    {
                        lbl_error.Text = "An Error Occured!";
                        ExceptionUtility.LogException(9, "", "72.393", "btn_save_Click", errorMsg);
                    }
                    else
                        lbl_error.Text = errorMsg;
                    return;
                }
            }
            /****************************/
            if (ECOMCreditAmount != ECOMCreditAmountold)
            {
                saved = UpdateMakerChecker(chgId, "SAMA_SETTL_TOTAL", "MANUEL_CR_ECOM_ACQ_AMT", ECOMCreditAmountold.ToString(), ECOMCreditAmount.ToString(), int.Parse(ViewState["mode"].ToString()), ref errorMsg);
                if (saved == false)
                {
                    if (Helper.OracleError(errorMsg))
                    {
                        lbl_error.Text = "An Error Occured!";
                        ExceptionUtility.LogException(9, "", "72.393", "btn_save_Click", errorMsg);
                    }
                    else
                        lbl_error.Text = errorMsg;
                    return;
                }
                saved = UpdateMakerChecker(chgId, "SAMA_SETTL_TOTAL", "DIFF_CR_ECOM_ACQ_AMT", diffCreditECOMold.ToString(), diffCreditECOM.ToString(), int.Parse(ViewState["mode"].ToString()), ref errorMsg);
                if (saved == false)
                {
                    if (Helper.OracleError(errorMsg))
                    {
                        lbl_error.Text = "An Error Occured!";
                        ExceptionUtility.LogException(9, "", "72.393", "btn_save_Click", errorMsg);
                    }
                    else
                        lbl_error.Text = errorMsg;
                    return;
                }
            }
            if (ECOMDebitAmount != ECOMDebitAmountold)
            {
                saved = UpdateMakerChecker(chgId, "SAMA_SETTL_TOTAL", "MANUEL_DR_ECOM_ACQ_AMT", ECOMDebitAmountold.ToString(), ECOMDebitAmount.ToString(), int.Parse(ViewState["mode"].ToString()), ref errorMsg);
                if (saved == false)
                {
                    if (Helper.OracleError(errorMsg))
                    {
                        lbl_error.Text = "An Error Occured!";
                        ExceptionUtility.LogException(9, "", "72.393", "btn_save_Click", errorMsg);
                    }
                    else
                        lbl_error.Text = errorMsg;
                    return;
                }
                saved = UpdateMakerChecker(chgId, "SAMA_SETTL_TOTAL", "DIFF_DR_ECOM_ACQ_AMT", diffDebitECOMold.ToString(), diffDebitECOM.ToString(), int.Parse(ViewState["mode"].ToString()), ref errorMsg);
                if (saved == false)
                {
                    if (Helper.OracleError(errorMsg))
                    {
                        lbl_error.Text = "An Error Occured!";
                        ExceptionUtility.LogException(9, "", "72.393", "btn_save_Click", errorMsg);
                    }
                    else
                        lbl_error.Text = errorMsg;
                    return;
                }
            }
            /****************************/
            if (gccAtmCreditAmount != gccAtmCreditAmountold)
            {
                saved = UpdateMakerChecker(chgId, "SAMA_SETTL_TOTAL", "MANUEL_CR_ATM_ACQ_AMT_GCC", gccAtmCreditAmountold.ToString(), gccAtmCreditAmount.ToString(), int.Parse(ViewState["mode"].ToString()), ref errorMsg);
                if (saved == false)
                {
                    if (Helper.OracleError(errorMsg))
                    {
                        lbl_error.Text = "An Error Occured!";
                        ExceptionUtility.LogException(9, "", "72.393", "btn_save_Click", errorMsg);
                    }
                    else
                        lbl_error.Text = errorMsg;
                    return;
                }
                saved = UpdateMakerChecker(chgId, "SAMA_SETTL_TOTAL", "DIFF_CR_ATM_ACQ_AMT_GCC", diffCreditATMGCCold.ToString(), diffCreditATMGCC.ToString(), int.Parse(ViewState["mode"].ToString()), ref errorMsg);
                if (saved == false)
                {
                    if (Helper.OracleError(errorMsg))
                    {
                        lbl_error.Text = "An Error Occured!";
                        ExceptionUtility.LogException(9, "", "72.393", "btn_save_Click", errorMsg);
                    }
                    else
                        lbl_error.Text = errorMsg;
                    return;
                }
            }
            if (gccAtmDebitAmount != gccAtmDebitAmountold)
            {
                saved = UpdateMakerChecker(chgId, "SAMA_SETTL_TOTAL", "MANUEL_DR_ATM_ISS_AMT_GCC", gccAtmDebitAmountold.ToString(), gccAtmDebitAmount.ToString(), int.Parse(ViewState["mode"].ToString()), ref errorMsg);
                if (saved == false)
                {
                    if (Helper.OracleError(errorMsg))
                    {
                        lbl_error.Text = "An Error Occured!";
                        ExceptionUtility.LogException(9, "", "72.393", "btn_save_Click", errorMsg);
                    }
                    else
                        lbl_error.Text = errorMsg;
                    return;
                }
                saved = UpdateMakerChecker(chgId, "SAMA_SETTL_TOTAL", "DIFF_DR_ATM_ISS_AMT_GCC", diffDebitATMGCC.ToString(), diffDebitATMGCC.ToString(), int.Parse(ViewState["mode"].ToString()), ref errorMsg);
                if (saved == false)
                {
                    if (Helper.OracleError(errorMsg))
                    {
                        lbl_error.Text = "An Error Occured!";
                        ExceptionUtility.LogException(9, "", "72.393", "btn_save_Click", errorMsg);
                    }
                    else
                        lbl_error.Text = errorMsg;
                    return;
                }
            }
            if (gccAtmCreditFees != gccAtmCreditFeesold)
            {
                saved = UpdateMakerChecker(chgId, "SAMA_SETTL_TOTAL", "MANUEL_CR_ATM_ACQ_AMT_GCC_FEES", gccAtmCreditFeesold.ToString(), gccAtmCreditFees.ToString(), int.Parse(ViewState["mode"].ToString()), ref errorMsg);
                if (saved == false)
                {
                    if (Helper.OracleError(errorMsg))
                    {
                        lbl_error.Text = "An Error Occured!";
                        ExceptionUtility.LogException(9, "", "72.393", "btn_save_Click", errorMsg);
                    }
                    else
                        lbl_error.Text = errorMsg;
                    return;
                }
                saved = UpdateMakerChecker(chgId, "SAMA_SETTL_TOTAL", "DIFF_CR_ATM_ACQ_AMT_GCC_FEES", diffCreditATMGCCFeeold.ToString(), diffCreditATMGCCFee.ToString(), int.Parse(ViewState["mode"].ToString()), ref errorMsg);
                if (saved == false)
                {
                    if (Helper.OracleError(errorMsg))
                    {
                        lbl_error.Text = "An Error Occured!";
                        ExceptionUtility.LogException(9, "", "72.393", "btn_save_Click", errorMsg);
                    }
                    else
                        lbl_error.Text = errorMsg;
                    return;
                }
            }
            if (gccAtmDebitFees != gccAtmDebitFeesold)
            {
                saved = UpdateMakerChecker(chgId, "SAMA_SETTL_TOTAL", "MANUEL_DR_ATM_ISS_AMT_GCC_FEES", gccAtmDebitFeesold.ToString(), gccAtmDebitFees.ToString(), int.Parse(ViewState["mode"].ToString()), ref errorMsg);
                if (saved == false)
                {
                    if (Helper.OracleError(errorMsg))
                    {
                        lbl_error.Text = "An Error Occured!";
                        ExceptionUtility.LogException(9, "", "72.393", "btn_save_Click", errorMsg);
                    }
                    else
                        lbl_error.Text = errorMsg;
                    return;
                }
                saved = UpdateMakerChecker(chgId, "SAMA_SETTL_TOTAL", "DIFF_DR_ATM_ISS_AMT_GCC_FEES", diffDebitATMGCCFeeold.ToString(), diffDebitATMGCCFee.ToString(), int.Parse(ViewState["mode"].ToString()), ref errorMsg);
                if (saved == false)
                {
                    if (Helper.OracleError(errorMsg))
                    {
                        lbl_error.Text = "An Error Occured!";
                        ExceptionUtility.LogException(9, "", "72.393", "btn_save_Click", errorMsg);
                    }
                    else
                        lbl_error.Text = errorMsg;
                    return;
                }
            }
            /****************************/
            if (gccPOSCreditAmount != gccPOSCreditAmountold)
            {
                saved = UpdateMakerChecker(chgId, "SAMA_SETTL_TOTAL", "MANUEL_CR_POS_ACQ_AMT_GCC", gccPOSCreditAmountold.ToString(), gccPOSCreditAmount.ToString(), int.Parse(ViewState["mode"].ToString()), ref errorMsg);
                if (saved == false)
                {
                    if (Helper.OracleError(errorMsg))
                    {
                        lbl_error.Text = "An Error Occured!";
                        ExceptionUtility.LogException(9, "", "72.393", "btn_save_Click", errorMsg);
                    }
                    else
                        lbl_error.Text = errorMsg;
                    return;
                }
                saved = UpdateMakerChecker(chgId, "SAMA_SETTL_TOTAL", "DIFF_CR_POS_ACQ_AMT_GCC", diffCreditPOSGCCold.ToString(), diffCreditPOSGCC.ToString(), int.Parse(ViewState["mode"].ToString()), ref errorMsg);
                if (saved == false)
                {
                    if (Helper.OracleError(errorMsg))
                    {
                        lbl_error.Text = "An Error Occured!";
                        ExceptionUtility.LogException(9, "", "72.393", "btn_save_Click", errorMsg);
                    }
                    else
                        lbl_error.Text = errorMsg;
                    return;
                }
            }
            if (gccPOSDebitAmount != gccPOSDebitAmountold)
            {
                saved = UpdateMakerChecker(chgId, "SAMA_SETTL_TOTAL", "MANUEL_DR_POS_ISS_AMT_GCC", gccPOSDebitAmountold.ToString(), gccPOSDebitAmount.ToString(), int.Parse(ViewState["mode"].ToString()), ref errorMsg);
                if (saved == false)
                {
                    if (Helper.OracleError(errorMsg))
                    {
                        lbl_error.Text = "An Error Occured!";
                        ExceptionUtility.LogException(9, "", "72.393", "btn_save_Click", errorMsg);
                    }
                    else
                        lbl_error.Text = errorMsg;
                    return;
                }
                saved = UpdateMakerChecker(chgId, "SAMA_SETTL_TOTAL", "DIFF_DR_POS_ISS_AMT_GCC", diffDebitPOSGCC.ToString(), diffDebitPOSGCC.ToString(), int.Parse(ViewState["mode"].ToString()), ref errorMsg);
                if (saved == false)
                {
                    if (Helper.OracleError(errorMsg))
                    {
                        lbl_error.Text = "An Error Occured!";
                        ExceptionUtility.LogException(9, "", "72.393", "btn_save_Click", errorMsg);
                    }
                    else
                        lbl_error.Text = errorMsg;
                    return;
                }
            }
            if (gccPOSCreditFees != gccPOSCreditFeesold)
            {
                saved = UpdateMakerChecker(chgId, "SAMA_SETTL_TOTAL", "MANUEL_CR_POS_ACQ_AMT_GCC_FEES", gccPOSCreditFeesold.ToString(), gccPOSCreditFees.ToString(), int.Parse(ViewState["mode"].ToString()), ref errorMsg);
                if (saved == false)
                {
                    if (Helper.OracleError(errorMsg))
                    {
                        lbl_error.Text = "An Error Occured!";
                        ExceptionUtility.LogException(9, "", "72.393", "btn_save_Click", errorMsg);
                    }
                    else
                        lbl_error.Text = errorMsg;
                    return;
                }
                saved = UpdateMakerChecker(chgId, "SAMA_SETTL_TOTAL", "DIFF_CR_POS_ACQ_AMT_GCC_FEES", diffCreditPOSGCCFeeold.ToString(), diffCreditPOSGCCFee.ToString(), int.Parse(ViewState["mode"].ToString()), ref errorMsg);
                if (saved == false)
                {
                    if (Helper.OracleError(errorMsg))
                    {
                        lbl_error.Text = "An Error Occured!";
                        ExceptionUtility.LogException(9, "", "72.393", "btn_save_Click", errorMsg);
                    }
                    else
                        lbl_error.Text = errorMsg;
                    return;
                }
            }
            if (gccPOSDebitFees != gccPOSDebitFeesold)
            {
                saved = UpdateMakerChecker(chgId, "SAMA_SETTL_TOTAL", "MANUEL_DR_POS_ISS_AMT_GCC_FEES", gccPOSDebitFeesold.ToString(), gccPOSDebitFees.ToString(), int.Parse(ViewState["mode"].ToString()), ref errorMsg);
                if (saved == false)
                {
                    if (Helper.OracleError(errorMsg))
                    {
                        lbl_error.Text = "An Error Occured!";
                        ExceptionUtility.LogException(9, "", "72.393", "btn_save_Click", errorMsg);
                    }
                    else
                        lbl_error.Text = errorMsg;
                    return;
                }
                saved = UpdateMakerChecker(chgId, "SAMA_SETTL_TOTAL", "DIFF_DR_POS_ISS_AMT_GCC_FEES", diffDebitPOSGCCFeeold.ToString(), diffDebitPOSGCCFee.ToString(), int.Parse(ViewState["mode"].ToString()), ref errorMsg);
                if (saved == false)
                {
                    if (Helper.OracleError(errorMsg))
                    {
                        lbl_error.Text = "An Error Occured!";
                        ExceptionUtility.LogException(9, "", "72.393", "btn_save_Click", errorMsg);
                    }
                    else
                        lbl_error.Text = errorMsg;
                    return;
                }
            }
            if (saved == true)
                this.lbl_error.Text = "Your request has been sent to Checker user for Approval.";

            //this.disableResultControls();
            this.clearResultControls();
            this.pnl_result.Visible = false;

            this.btn_save.Enabled = false;
            this.pnl_searchCriteria.Enabled = true;

            //}
            //else if (resCode == 10)
            //{
            //    this.lbl_error.Text = errorMsg;
            //}
            //else
            //{
            //    this.lbl_error.Text = errorMsg;
            //}
        }
    }

    protected void btn_clear_Click(object sender, EventArgs e)
    {
        this.clearResultControls();
        this.dtp_filter_sttlDate.date = "";
        this.pnl_result.Visible = false;
        this.pnl_searchCriteria.Enabled = true;
        ExceptionUtility.LogException(0, "", "393.1", "btn_clear_Click", "");
    }

    private void clearResultControls()
    {
        this.txt_creditATM_amount.Text = "";
        this.txt_debitATM_amount.Text = "";
        this.txt_creditPOS_amount.Text = "";
        this.txt_debitPOS_amount.Text = "";
        this.txt_creditECOM_amount.Text = "";
        this.txt_debitECOM_amount.Text = "";
        this.txt_creditATM_GCC_amount.Text = "";
        this.txt_debitATM_GCC_amount.Text = "";
        this.txt_creditPOS_GCC_amount.Text = "";
        this.txt_debitPOS_GCC_amount.Text = "";

        this.lbl_creditATM_difference.Text = "";
        this.lbl_creditATM_GCC_difference.Text = "";
        this.lbl_creditATM_GCC_SamaAmount.Text = "";
        this.lbl_creditPOS_GCC_difference.Text = "";
        this.lbl_creditPOS_GCC_SamaAmount.Text = "";
        this.lbl_creditATM_SamaAmount.Text = "";
        this.lbl_creditPOS_difference.Text = "";
        this.lbl_creditPOS_SamaAmount.Text = "";
        this.lbl_creditECOM_difference.Text = "";
        this.lbl_creditECOM_SamaAmount.Text = "";
        this.lbl_debitATM_difference.Text = "";
        this.lbl_debitATM_GCC_difference.Text = "";
        this.lbl_debitATM_GCC_SamaAmount.Text = "";
        this.lbl_debitPOS_GCC_difference.Text = "";
        this.lbl_debitPOS_GCC_SamaAmount.Text = "";
        this.lbl_debitATM_SamaAmount.Text = "";
        this.lbl_debitPOS_difference.Text = "";
        this.lbl_debitPOS_SamaAmount.Text = "";
        this.lbl_debitECOM_difference.Text = "";
        this.lbl_debitECOM_SamaAmount.Text = "";
    }

    private void clearManualControls()
    {
        this.txt_creditATM_amount.Text = "";
        this.txt_debitATM_amount.Text = "";
        this.txt_creditPOS_amount.Text = "";
        this.txt_debitPOS_amount.Text = "";
        this.txt_creditECOM_amount.Text = "";
        this.txt_debitECOM_amount.Text = "";
        this.txt_creditATM_GCC_amount.Text = "";
        this.txt_debitATM_GCC_amount.Text = "";
        this.txt_creditPOS_GCC_amount.Text = "";
        this.txt_debitPOS_GCC_amount.Text = "";
    }

    private void disableResultControls()
    {
        this.txt_creditATM_amount.Enabled = false;
        this.txt_debitATM_amount.Enabled = false;
        this.txt_creditPOS_amount.Enabled = false;
        this.txt_debitPOS_amount.Enabled = false;
        this.txt_creditECOM_amount.Enabled = false;
        this.txt_debitECOM_amount.Enabled = false;
        this.txt_creditATM_GCC_amount.Enabled = false;
        this.txt_debitATM_GCC_amount.Enabled = false;
        this.txt_creditPOS_GCC_amount.Enabled = false;
        this.txt_debitPOS_GCC_amount_Fees.Enabled = false;
    }

    private void enableResultControls()
    {
        this.txt_creditATM_amount.Enabled = true;
        this.txt_debitATM_amount.Enabled = true;
        this.txt_creditPOS_amount.Enabled = true;
        this.txt_debitPOS_amount.Enabled = true;
        this.txt_creditECOM_amount.Enabled = true;
        this.txt_debitECOM_amount.Enabled = true;
        this.txt_creditATM_GCC_amount.Enabled = true;
        this.txt_debitATM_GCC_amount.Enabled = true;
        this.txt_creditPOS_GCC_amount.Enabled = true;
        this.txt_debitPOS_GCC_amount_Fees.Enabled = true;
    }

    private int updateSettlementDetails(string settlementDate, double samaAtmCreditAmount, double samaAtmDebitAmount,
                                          double samaPosCreditAmount, double samaPosDebitAmount,
                                          double samaGccAtmCreditAmount, double samaGccAtmDebitAmount, double samaGccAtmCreditFees, double samaGccAtmDebitFees,
                                          double samaGccPOSCreditAmount, double samaGccPOSDebitAmount, double samaGccPOSCreditFees, double samaGccPOSDebitFees,
                                          double atmCreditAmount, double atmDebitAmount,
                                          double posCreditAmount, double posDebitAmount,
                                          double gccAtmCreditAmount, double gccAtmDebitAmount, double gccAtmCreditFees, double gccAtmDebitFees,
                                          double gccPOSCreditAmount, double gccPOSDebitAmount, double gccPOSCreditFees, double gccPOSDebitFees,
                                          ref string errorMsg)
    {
        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 = "SAMA_SETTL_OPERATIONS.UPDATE_SETTLEMENT_DETAILS";

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

            oracom.Parameters.Add("p_settl_date", OracleType.VarChar).Direction = ParameterDirection.Input;

            oracom.Parameters.Add("p_atm_sama_credit", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_atm_sama_debit", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_pos_sama_credit", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_pos_sama_debit", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_atm_credit", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_atm_debit", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_pos_credit", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_pos_debit", OracleType.Number).Direction = ParameterDirection.Input;

         //   oracom.Parameters.Add("p_ecom_credit", OracleType.Number).Direction = ParameterDirection.Input;
         //   oracom.Parameters.Add("p_ecom_debit", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_gcc_sama_atm_credit", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_gcc_sama_atm_debit", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_gcc_sama_atm_credit_fees", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_gcc_sama_atm_debit_fees", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_gcc_atm_credit", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_gcc_atm_debit", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_gcc_atm_credit_fees", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_gcc_atm_debit_fees", OracleType.Number).Direction = ParameterDirection.Input;

            oracom.Parameters.Add("p_gcc_sama_pos_credit", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_gcc_sama_pos_debit", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_gcc_sama_pos_credit_fees", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_gcc_sama_pos_debit_fees", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_gcc_pos_credit", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_gcc_pos_debit", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_gcc_pos_credit_fees", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_gcc_pos_debit_fees", OracleType.Number).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_lang"].Value = "EN";

            oracom.Parameters["p_settl_date"].Value = settlementDate;

            oracom.Parameters["p_atm_sama_credit"].Value = samaAtmCreditAmount;
            oracom.Parameters["p_atm_sama_debit"].Value = samaAtmDebitAmount;
            oracom.Parameters["p_pos_sama_credit"].Value = samaPosCreditAmount;
            oracom.Parameters["p_pos_sama_debit"].Value = samaPosDebitAmount;
            oracom.Parameters["p_atm_credit"].Value = atmCreditAmount;
            oracom.Parameters["p_atm_debit"].Value = atmDebitAmount;
            oracom.Parameters["p_pos_credit"].Value = posCreditAmount;
            oracom.Parameters["p_pos_debit"].Value = posDebitAmount;

          //  oracom.Parameters["p_ECOM_credit"].Value = ECOMCreditAmount;
          //  oracom.Parameters["p_ECOM_debit"].Value = ECOMDebitAmount;

            oracom.Parameters["p_gcc_sama_atm_credit"].Value = samaGccAtmCreditAmount;
            oracom.Parameters["p_gcc_sama_atm_debit"].Value = samaGccAtmDebitAmount;
            oracom.Parameters["p_gcc_sama_atm_credit_fees"].Value = samaGccAtmCreditFees;
            oracom.Parameters["p_gcc_sama_atm_debit_fees"].Value = samaGccAtmDebitFees;
            oracom.Parameters["p_gcc_atm_credit"].Value = gccAtmCreditAmount;
            oracom.Parameters["p_gcc_atm_debit"].Value = gccAtmDebitAmount;
            oracom.Parameters["p_gcc_atm_credit_fees"].Value = gccAtmCreditFees;
            oracom.Parameters["p_gcc_atm_debit_fees"].Value = gccAtmDebitFees;

            oracom.Parameters["p_gcc_sama_pos_credit"].Value = samaGccPOSCreditAmount;
            oracom.Parameters["p_gcc_sama_pos_debit"].Value = samaGccPOSDebitAmount;
            oracom.Parameters["p_gcc_sama_pos_credit_fees"].Value = samaGccPOSCreditFees;
            oracom.Parameters["p_gcc_sama_pos_debit_fees"].Value = samaGccPOSDebitFees;
            oracom.Parameters["p_gcc_pos_credit"].Value = gccPOSCreditAmount;
            oracom.Parameters["p_gcc_pos_debit"].Value = gccPOSDebitAmount;
            oracom.Parameters["p_gcc_pos_credit_fees"].Value = gccPOSCreditFees;
            oracom.Parameters["p_gcc_pos_debit_fees"].Value = gccPOSDebitFees;




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

            int resCode = int.Parse(oracom.Parameters["p_res_code"].Value.ToString());
            errorMsg = oracom.Parameters["p_res_msg"].Value.ToString();
            ExceptionUtility.LogException(0, "SAMA_SETTL_OPERATIONS.UPDATE_SETTLEMENT_DETAILS", "", "updateSettlementDetails", "settlementDate: " + settlementDate + ", samaAtmCreditAmount: " + samaAtmCreditAmount + ", samaAtmDebitAmount :" + samaAtmDebitAmount + ", samaPosCreditAmount: " + samaPosCreditAmount + ", samaPosDebitAmount: " + samaPosDebitAmount + ", samaGCCAtmCreditAmount: " + samaGccAtmCreditAmount + ", samaGccAtmDebitAmount: " + samaGccAtmDebitAmount + ", samaGccAtmDebitFees: " + samaGccAtmDebitFees + ", samaGccAtmCreditFees: " + samaGccAtmCreditFees + ", atmCreditAmount: " + atmCreditAmount + ", atmDebitAmount: " + atmDebitAmount + ", PosCreditAmount: " + posCreditAmount + ", posDebitAMount: " + posDebitAmount + ", gccAtmCreditAmount: " + gccAtmCreditAmount + ", gccAtmDebitAMount: " + gccAtmDebitAmount + ", gccAtmCreditFees :" + gccAtmCreditFees + ", gccAtmDebitFees : " + gccAtmDebitFees);
            return resCode;
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "SAMA_SETTL_OPERATIONS.UPDATE_SETTLEMENT_DETAILS", "", "updateSettlementDetails", "settlementDate: " + settlementDate + ", samaAtmCreditAmount: " + samaAtmCreditAmount + ", samaAtmDebitAmount :" + samaAtmDebitAmount + ", samaPosCreditAmount: " + samaPosCreditAmount + ", samaPosDebitAmount: " + samaPosDebitAmount + ", samaGCCAtmCreditAmount: " + samaGccAtmCreditAmount + ", samaGccAtmDebitAmount: " + samaGccAtmDebitAmount + ", samaGccAtmDebitFees: " + samaGccAtmDebitFees + ", samaGccAtmCreditFees: " + samaGccAtmCreditFees + ", atmCreditAmount: " + atmCreditAmount + ", atmDebitAmount: " + atmDebitAmount + ", PosCreditAmount: " + posCreditAmount + ", posDebitAMount: " + posDebitAmount + ", gccAtmCreditAmount: " + gccAtmCreditAmount + ", gccAtmDebitAMount: " + gccAtmDebitAmount + ", gccAtmCreditFees :" + gccAtmCreditFees + ", gccAtmDebitFees : " + gccAtmDebitFees);
            //Response.Redirect("../ErrorPages/ErrorPage.aspx");
            return 0;
        }
    }

    protected void btn_print_Click(object sender, EventArgs e)
    {
        ExceptionUtility.LogException(0, "", "", "btn_print_Click", "");//btn_print_Click: " + settlementDate + ", samaAtmCreditAmount: " + samaAtmCreditAmount + ", samaAtmDebitAmount :" + samaAtmDebitAmount + ", samaPosCreditAmount: " + samaPosCreditAmount + ", samaPosDebitAmount: " + samaPosDebitAmount + ", samaGCCAtmCreditAmount: " + samaGccAtmCreditAmount + ", samaGccAtmDebitAmount: " + samaGccAtmDebitAmount + ", samaGccAtmDebitFees: " + samaGccAtmDebitFees + ", samaGccAtmCreditFees: " + samaGccAtmCreditFees + ", atmCreditAmount: " + atmCreditAmount + ", atmDebitAmount: " + atmDebitAmount + ", PosCreditAmount: " + posCreditAmount + ", posDebitAMount: " + posDebitAmount + ", gccAtmCreditAmount: " + gccAtmCreditAmount + ", gccAtmDebitAMount: " + gccAtmDebitAmount + ", gccAtmCreditFees :" + gccAtmCreditFees + ", gccAtmDebitFees : " + gccAtmDebitFees);

        ScriptManager.RegisterClientScriptBlock(this, typeof(string), "new window",
            "window.open('../Reports/Default.aspx?rpt=222&p1=" + this.dtp_filter_sttlDate.date + "&p2=" + Session["uid"].ToString() + "','Report')", true);

    }
}