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

public partial class Business_ATM_Jard : System.Web.UI.Page
{
    //private int jardID;
    
    protected void Page_Load(object sender, EventArgs e)
    {
        
        
        if (!IsPostBack)
        {
            this.pnl_result.Visible = false;
            this.pnl_jardDetails.Visible = false;
            this.pnl_capturedCardsGridPnl.Visible = false;
            this.pnl_addNew.Visible = false;
            this.pnl_jardDetailsDenos.Visible = false;

            //this.ddl_capturedCard_cardType.Enabled = false;
            //this.txt_capturedCard_cardNo.Enabled = false;
            //this.txt_capturedCard_issuerBank.Enabled = false;
            //this.txt_capturedCard_holderName.Enabled = false;
            //this.btn_addCard.Enabled = false;

            this.loadCardsTypes();
            ExceptionUtility.LogException(0, "", "73", "Page_Load", "");
        }

        lbl_error.Text = "";
    }

    protected void btn_search_Click(object sender, EventArgs e)
    {
        string atmNumber = this.txt_atmNumberFilter.Text;
        string rplCurrency = (this.ddl_rplCurrency_filter.SelectedIndex != 0)? this.ddl_rplCurrency_filter.SelectedValue : "";
        string rplDate = (this.dtp_rplDate.date.Length != 0) ? this.dtp_rplDate.date.Replace("-", "") : "";
        int searchResCode;

        this.pnl_result.Visible = true;
        this.pnl_jardDetails.Visible = false;
        this.pnl_capturedCardsGridPnl.Visible = false;
        this.pnl_addNew.Visible = false;
        this.pnl_jardDetailsDenos.Visible = false;
        this.clearAllControls();
        ExceptionUtility.LogException(0, "", "73.396", "btn_search_Click", "");
        searchResCode = this.searchJards(atmNumber, rplCurrency, rplDate);

        this.pnl_addNew.Visible = true;

        if (searchResCode == 124)
        {
            this.lbl_error.Text = "ERROR: The ATM not defined";
        }
        
    }

    private int searchJards(string atmNumber, string rplCurrency, string rplDate)
    {
        try
        {
            string currentMethod = "";
            StackTrace stackTrace = new StackTrace();
            currentMethod = stackTrace.GetFrame(1).GetMethod().Name ;
            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 = "ATM_JARD_OPERATIONS.SEARCH_JARDS";

            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_atm_Number", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_rpl_currency", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_rpl_date", OracleType.VarChar).Direction = ParameterDirection.Input;

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

            oracom.Parameters["p_current_uid"].Value = Session["uid"].ToString(); ;
            oracom.Parameters["p_lang"].Value = "EN";
            oracom.Parameters["p_atm_Number"].Value = atmNumber;
            oracom.Parameters["p_rpl_currency"].Value = rplCurrency;
            oracom.Parameters["p_rpl_date"].Value = rplDate;

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

            oracon.Close();

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

            if (resCode != 124)
            {
                this.grd_jardResult.DataSource = ds;
                this.grd_jardResult.DataBind();
            }
            if (currentMethod.Contains("btn_search_Click"))
                ExceptionUtility.LogException(0, "", "396.1", "searchJards", "atmNumber: " + atmNumber + ", rplCurrency: " + rplCurrency + ", rplDate: " + rplDate);
            return resCode;
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "", "396.1", "searchJards", "atmNumber: " + atmNumber + ", rplCurrency: " + rplCurrency + ", rplDate: " + rplDate);
            return 0;
        }
    }
    
    protected void btn_addNew_Click(object sender, EventArgs e)
    {
        this.pnl_addNew.Visible = false;
        this.pnl_jardDetails.Visible = true;
        this.btn_addJard.Visible = true;
        this.btn_cancel_basicDetails.Visible = true;
        this.txt_atmNumber.Text = this.txt_atmNumberFilter.Text;

        DateTime currentDate = DateTime.Now;
        this.lbl_currentReplDate.Text = String.Format("{0:dd-MM-yyyy}", currentDate);
        ExceptionUtility.LogException(0, "", "73.397", "btn_addNew_Click", "");
        this.enableJardBasicDetailsControls();
        
        
        this.lbl_lastReplDate.Text = this.getLastRplDate(this.txt_atmNumber.Text);
        this.ddl_rplCurrency.SelectedIndex = 0;
        this.txt_replTime.Text = "";
        
    }
    
    protected void btn_addJard_Click(object sender, EventArgs e)
    {
        string atmNumber = this.txt_atmNumber.Text;
        string lastRplDate = this.lbl_lastReplDate.Text;
        string rplTime = this.txt_replTime.Text;
        int firstTranNumber = (this.txt_firstTranNo.Text.Length != 0) ? int.Parse(this.txt_firstTranNo.Text) : 0;
        int lastTranNumber = (this.txt_lastTranNo.Text.Length != 0) ? int.Parse(this.txt_lastTranNo.Text) : 0;
        int retractAmount = (this.txt_retractAmount.Text.Length != 0) ? (int.Parse(this.txt_retractAmount.Text)) : 0;
        string rplCurrency = this.ddl_rplCurrency.SelectedValue.ToString();


        string errorMsg = "";
        ExceptionUtility.LogException(0, "", "73.404", "btn_addJard_Click", "");
        bool isAdded = this.addNewJard(atmNumber, rplCurrency, lastRplDate, rplTime, firstTranNumber, lastTranNumber, retractAmount, ref errorMsg);

        if (isAdded)
        {
            lbl_error.Text = "New Jard Added Successfully, please fill the other details...";

            pnl_jardDetailsDenos.Visible = true;

            this.disbleJardBasicDetailsControls();

            if (rplCurrency == "SAR")
            {
                this.disableUSDControls();
            }
            else if (rplCurrency == "USD")
            {
                this.disableSARControls();
            }

        } else 
        {
            lbl_error.Text = errorMsg;
            this.clearAllControls();
            this.btn_addNew.Visible = true;
            this.pnl_jardDetails.Visible = false;
        }
    }

    private bool addNewJard(string atmNumber, string rplCurrency, string lastRplDate, string rplTime, int firstTranNumber, int lastTranNumber, int retractAmount ,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 = "ATM_JARD_OPERATIONS.ADD_NEW_JARD";

            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_atm_number", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_last_rpl_date", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_rpl_time", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_first_tran_no", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_last_tran_no", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_retract_amount", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_jard_curreny", OracleType.VarChar).Direction = ParameterDirection.Input;

            oracom.Parameters.Add("p_jard_id", 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_atm_number"].Value = atmNumber;
            oracom.Parameters["p_last_rpl_date"].Value = (lastRplDate.Length != 0 && lastRplDate != "------") ? Helper.formatDate_ToDBFormat(lastRplDate) : "------";
            oracom.Parameters["p_rpl_time"].Value = Helper.formatTime_toDBFormat(rplTime);
            oracom.Parameters["p_first_tran_no"].Value = firstTranNumber;
            oracom.Parameters["p_last_tran_no"].Value = lastTranNumber;
            oracom.Parameters["p_retract_amount"].Value = retractAmount;
            oracom.Parameters["p_jard_curreny"].Value = rplCurrency;

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

            this.jardID.Value = oracom.Parameters["p_jard_id"].Value.ToString();

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

            if (resCode == "0")
            {
                this.arrangeAtmCassettes(atmNumber);
                ExceptionUtility.LogException(0, "", "", "404.1", "atmNumber- " + atmNumber + ": lastReplDate- " + lastRplDate + ": rplTime- " + rplTime + ": firstTranNumber- " + firstTranNumber + ": lastTranNumber- " + lastTranNumber + ":retractAmount- " + retractAmount + ": rplCurrency- " + rplCurrency);
                return true;
            }
            else
            {
                ExceptionUtility.LogException(0, "", "", "404.1", "atmNumber- " + atmNumber + ": lastReplDate- " + lastRplDate + ": rplTime- " + rplTime + ": firstTranNumber- " + firstTranNumber + ": lastTranNumber: " + lastTranNumber + ":retractAmount- " + retractAmount + ": rplCurrency- " + rplCurrency);
                return false;
            }
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "", "", "404.1", "atmNumber- " + atmNumber + ": lastReplDate- " + lastRplDate + ": rplTime: " + rplTime + ": firstTranNumber- " + firstTranNumber + ": lastTranNumber- " + lastTranNumber + ":retractAmount- " + retractAmount + ": rplCurrency- " + rplCurrency);
            return false;
        }
    }

    private ArrayList getAtmCassettes(string atmNumber)
    {
        try
        {
            ArrayList cassettes = new ArrayList();
            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 = "ATM_JARD_OPERATIONS.GET_ATM_CASSETTES_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_atm_Number", OracleType.VarChar).Direction = ParameterDirection.Input;

            oracom.Parameters.Add("p_GID", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_CASS1_CURR", OracleType.VarChar, 3).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_CASS1_VALUE", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_CASS2_CURR", OracleType.VarChar, 3).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_CASS2_VALUE", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_CASS3_CURR", OracleType.VarChar, 3).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_CASS3_VALUE", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_CASS4_CURR", OracleType.VarChar, 3).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_CASS4_VALUE", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_CASS5_CURR", OracleType.VarChar, 3).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_CASS5_VALUE", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_CASS6_CURR", OracleType.VarChar, 3).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_CASS6_VALUE", 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_atm_Number"].Value = atmNumber;

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

            oracon.Close();

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


            if (resCode == 9)
            {
                return null;
            }
            else
            {
                ATMCassette tempAtmCassette;

                if (oracom.Parameters["p_CASS1_VALUE"].Value.ToString().Length != null && oracom.Parameters["p_CASS1_VALUE"].Value.ToString().Length != 0)
                {
                    tempAtmCassette = new ATMCassette();

                    tempAtmCassette.setValue(int.Parse(oracom.Parameters["p_CASS1_VALUE"].Value.ToString()));
                    tempAtmCassette.setCurreny(oracom.Parameters["p_CASS1_CURR"].Value.ToString().Trim());

                    cassettes.Add(tempAtmCassette);
                }
                if (oracom.Parameters["p_CASS2_VALUE"].Value.ToString().Length != null && oracom.Parameters["p_CASS1_VALUE"].Value.ToString().Length != 0)
                {
                    tempAtmCassette = new ATMCassette();

                    tempAtmCassette.setValue(int.Parse(oracom.Parameters["p_CASS2_VALUE"].Value.ToString()));
                    tempAtmCassette.setCurreny(oracom.Parameters["p_CASS2_CURR"].Value.ToString().Trim());

                    cassettes.Add(tempAtmCassette);
                }
                if (oracom.Parameters["p_CASS3_VALUE"].Value.ToString().Length != null && oracom.Parameters["p_CASS1_VALUE"].Value.ToString().Length != 0)
                {
                    tempAtmCassette = new ATMCassette();

                    tempAtmCassette.setValue(int.Parse(oracom.Parameters["p_CASS3_VALUE"].Value.ToString()));
                    tempAtmCassette.setCurreny(oracom.Parameters["p_CASS3_CURR"].Value.ToString().Trim());

                    cassettes.Add(tempAtmCassette);
                }
                if (oracom.Parameters["p_CASS4_VALUE"].Value.ToString().Length != null && oracom.Parameters["p_CASS1_VALUE"].Value.ToString().Length != 0)
                {
                    tempAtmCassette = new ATMCassette();

                    tempAtmCassette.setValue(int.Parse(oracom.Parameters["p_CASS4_VALUE"].Value.ToString()));
                    tempAtmCassette.setCurreny(oracom.Parameters["p_CASS4_CURR"].Value.ToString().Trim());

                    cassettes.Add(tempAtmCassette);
                }
                if (oracom.Parameters["p_CASS5_VALUE"].Value.ToString().Length != null && oracom.Parameters["p_CASS1_VALUE"].Value.ToString().Length != 0)
                {
                    tempAtmCassette = new ATMCassette();

                    tempAtmCassette.setValue(int.Parse(oracom.Parameters["p_CASS5_VALUE"].Value.ToString()));
                    tempAtmCassette.setCurreny(oracom.Parameters["p_CASS5_CURR"].Value.ToString().Trim());

                    cassettes.Add(tempAtmCassette);
                }
                if (oracom.Parameters["p_CASS6_VALUE"].Value.ToString().Length != null && oracom.Parameters["p_CASS1_VALUE"].Value.ToString().Length != 0)
                {
                    tempAtmCassette = new ATMCassette();

                    tempAtmCassette.setValue(int.Parse(oracom.Parameters["p_CASS6_VALUE"].Value.ToString()));
                    tempAtmCassette.setCurreny(oracom.Parameters["p_CASS6_CURR"].Value.ToString().Trim());

                    cassettes.Add(tempAtmCassette);
                }
            }


            ExceptionUtility.LogException(9, "ATM_JARD_OPERATIONS.GET_ATM_CASSETTES_DETAILS","", "getAtmCassettes", "atmNumber: " + atmNumber);
            return cassettes;
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "ATM_JARD_OPERATIONS.GET_ATM_CASSETTES_DETAILS","", "getAtmCassettes", "atmNumber: " + atmNumber);
            return null;
        }
    }

    private void arrangeAtmCassettes(string atmNumber)
    {
        try
        {
            ArrayList atmCassettes = this.getAtmCassettes(atmNumber);

            if (atmCassettes.Count == 0)
            {
                this.enableAllCassettes();
            }
            else
            {
                this.disableAllCassettes();
                this.makeSARCassettesAsGray();
                this.makeUSDCassettesAsGray();

                foreach (ATMCassette atmCassette in atmCassettes)
                {

                    if (atmCassette.getValue() == 10 && atmCassette.getCurrency() == "SAR")
                    {
                        this.txt_cashDispensed_10SR.Enabled = true;
                        this.txt_closeCashATMSlip_10SR.Enabled = true;
                        this.txt_closePhyCashCount_10SR.Enabled = true;
                        this.txt_opnCashEJ_10SR.Enabled = true;
                        this.txt_opnPhyCash_10SR.Enabled = true;

                        this.txt_cashDispensed_10SR.BackColor = Color.White;
                        this.txt_closeCashATMSlip_10SR.BackColor = Color.White;
                        this.txt_closePhyCashCount_10SR.BackColor = Color.White;
                        this.txt_opnCashEJ_10SR.BackColor = Color.White;
                        this.txt_opnPhyCash_10SR.BackColor = Color.White;
                    }

                    else if (atmCassette.getValue() == 20 && atmCassette.getCurrency() == "SAR")
                    {
                        this.txt_cashDispensed_20SR.Enabled = true;
                        this.txt_closeCashATMSlip_20SR.Enabled = true;
                        this.txt_closePhyCashCount_20SR.Enabled = true;
                        this.txt_opnCashEJ_20SR.Enabled = true;
                        this.txt_opnPhyCash_20SR.Enabled = true;

                        this.txt_cashDispensed_20SR.BackColor = Color.White;
                        this.txt_closeCashATMSlip_20SR.BackColor = Color.White;
                        this.txt_closePhyCashCount_20SR.BackColor = Color.White;
                        this.txt_opnCashEJ_20SR.BackColor = Color.White;
                        this.txt_opnPhyCash_20SR.BackColor = Color.White;
                    }

                    else if (atmCassette.getValue() == 50 && atmCassette.getCurrency() == "SAR")
                    {
                        this.txt_cashDispensed_50SR.Enabled = true;
                        this.txt_closeCashATMSlip_50SR.Enabled = true;
                        this.txt_closePhyCashCount_50SR.Enabled = true;
                        this.txt_opnCashEJ_50SR.Enabled = true;
                        this.txt_opnPhyCash_50SR.Enabled = true;

                        this.txt_cashDispensed_50SR.BackColor = Color.White;
                        this.txt_closeCashATMSlip_50SR.BackColor = Color.White;
                        this.txt_closePhyCashCount_50SR.BackColor = Color.White;
                        this.txt_opnCashEJ_50SR.BackColor = Color.White;
                        this.txt_opnPhyCash_50SR.BackColor = Color.White;
                    }

                    else if (atmCassette.getValue() == 100 && atmCassette.getCurrency() == "SAR")
                    {
                        this.txt_cashDispensed_100SR.Enabled = true;
                        this.txt_closeCashATMSlip_100SR.Enabled = true;
                        this.txt_closePhyCashCount_100SR.Enabled = true;
                        this.txt_opnCashEJ_100SR.Enabled = true;
                        this.txt_opnPhyCash_100SR.Enabled = true;

                        this.txt_cashDispensed_100SR.BackColor = Color.White;
                        this.txt_closeCashATMSlip_100SR.BackColor = Color.White;
                        this.txt_closePhyCashCount_100SR.BackColor = Color.White;
                        this.txt_opnCashEJ_100SR.BackColor = Color.White;
                        this.txt_opnPhyCash_100SR.BackColor = Color.White;
                    }

                    else if (atmCassette.getValue() == 500 && atmCassette.getCurrency() == "SAR")
                    {
                        this.txt_cashDispensed_500SR.Enabled = true;
                        this.txt_closeCashATMSlip_500SR.Enabled = true;
                        this.txt_closePhyCashCount_500SR.Enabled = true;
                        this.txt_opnCashEJ_500SR.Enabled = true;
                        this.txt_opnPhyCash_500SR.Enabled = true;

                        this.txt_cashDispensed_500SR.BackColor = Color.White;
                        this.txt_closeCashATMSlip_500SR.BackColor = Color.White;
                        this.txt_closePhyCashCount_500SR.BackColor = Color.White;
                        this.txt_opnCashEJ_500SR.BackColor = Color.White;
                        this.txt_opnPhyCash_500SR.BackColor = Color.White;
                    }

                    else if (atmCassette.getValue() == 100 && atmCassette.getCurrency() == "USD")
                    {
                        this.txt_cashDispensed_100USD.Enabled = true;
                        this.txt_closeCashATMSlip_100USD.Enabled = true;
                        this.txt_closePhyCashCount_100USD.Enabled = true;
                        this.txt_opnCashEJ_100USD.Enabled = true;
                        this.txt_opnPhyCash_100USD.Enabled = true;

                        this.txt_cashDispensed_100USD.BackColor = Color.White;
                        this.txt_closeCashATMSlip_100USD.BackColor = Color.White;
                        this.txt_closePhyCashCount_100USD.BackColor = Color.White;
                        this.txt_opnCashEJ_100USD.BackColor = Color.White;
                        this.txt_opnPhyCash_100USD.BackColor = Color.White;
                    }
                }
            }
            ExceptionUtility.LogException(0, "", "arrangeAtmCassettes", "", "atmNumber- " + atmNumber);
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "", "arrangeAtmCassettes","", "atmNumber- "+atmNumber );
        }
    }

    private void enableAllCassettes()
    {
        this.txt_cashDispensed_10SR.Enabled = true;
        this.txt_closeCashATMSlip_10SR.Enabled = true;
        this.txt_closePhyCashCount_10SR.Enabled = true;
        this.txt_opnCashEJ_10SR.Enabled = true;
        this.txt_opnPhyCash_10SR.Enabled = true;

        this.txt_cashDispensed_20SR.Enabled = true;
        this.txt_closeCashATMSlip_20SR.Enabled = true;
        this.txt_closePhyCashCount_20SR.Enabled = true;
        this.txt_opnCashEJ_20SR.Enabled = true;
        this.txt_opnPhyCash_20SR.Enabled = true;

        this.txt_cashDispensed_50SR.Enabled = true;
        this.txt_closeCashATMSlip_50SR.Enabled = true;
        this.txt_closePhyCashCount_50SR.Enabled = true;
        this.txt_opnCashEJ_50SR.Enabled = true;
        this.txt_opnPhyCash_50SR.Enabled = true;

        this.txt_cashDispensed_100SR.Enabled = true;
        this.txt_closeCashATMSlip_100SR.Enabled = true;
        this.txt_closePhyCashCount_100SR.Enabled = true;
        this.txt_opnCashEJ_100SR.Enabled = true;
        this.txt_opnPhyCash_100SR.Enabled = true;

        this.txt_cashDispensed_500SR.Enabled = true;
        this.txt_closeCashATMSlip_500SR.Enabled = true;
        this.txt_closePhyCashCount_500SR.Enabled = true;
        this.txt_opnCashEJ_500SR.Enabled = true;
        this.txt_opnPhyCash_500SR.Enabled = true;

        this.txt_cashDispensed_100USD.Enabled = true;
        this.txt_closeCashATMSlip_100USD.Enabled = true;
        this.txt_closePhyCashCount_100USD.Enabled = true;
        this.txt_opnCashEJ_100USD.Enabled = true;
        this.txt_opnPhyCash_100USD.Enabled = true;
    }

    private void disableAllCassettes()
    {
        this.txt_cashDispensed_10SR.Enabled = false;
        this.txt_closeCashATMSlip_10SR.Enabled = false;
        this.txt_closePhyCashCount_10SR.Enabled = false;
        this.txt_opnCashEJ_10SR.Enabled = false;
        this.txt_opnPhyCash_10SR.Enabled = false;

        this.txt_cashDispensed_20SR.Enabled = false;
        this.txt_closeCashATMSlip_20SR.Enabled = false;
        this.txt_closePhyCashCount_20SR.Enabled = false;
        this.txt_opnCashEJ_20SR.Enabled = false;
        this.txt_opnPhyCash_20SR.Enabled = false;

        this.txt_cashDispensed_50SR.Enabled = false;
        this.txt_closeCashATMSlip_50SR.Enabled = false;
        this.txt_closePhyCashCount_50SR.Enabled = false;
        this.txt_opnCashEJ_50SR.Enabled = false;
        this.txt_opnPhyCash_50SR.Enabled = false;

        this.txt_cashDispensed_100SR.Enabled = false;
        this.txt_closeCashATMSlip_100SR.Enabled = false;
        this.txt_closePhyCashCount_100SR.Enabled = false;
        this.txt_opnCashEJ_100SR.Enabled = false;
        this.txt_opnPhyCash_100SR.Enabled = false;

        this.txt_cashDispensed_500SR.Enabled = false;
        this.txt_closeCashATMSlip_500SR.Enabled = false;
        this.txt_closePhyCashCount_500SR.Enabled = false;
        this.txt_opnCashEJ_500SR.Enabled = false;
        this.txt_opnPhyCash_500SR.Enabled = false;

        this.txt_cashDispensed_100USD.Enabled = false;
        this.txt_closeCashATMSlip_100USD.Enabled = false;
        this.txt_closePhyCashCount_100USD.Enabled = false;
        this.txt_opnCashEJ_100USD.Enabled = false;
        this.txt_opnPhyCash_100USD.Enabled = false;
    }

    private void disableSARControls()
    {
        this.txt_cashDispensed_10SR.Enabled = false;
        this.txt_closeCashATMSlip_10SR.Enabled = false;
        this.txt_closePhyCashCount_10SR.Enabled = false;
        this.txt_opnCashEJ_10SR.Enabled = false;
        this.txt_opnPhyCash_10SR.Enabled = false;

        this.txt_cashDispensed_20SR.Enabled = false;
        this.txt_closeCashATMSlip_20SR.Enabled = false;
        this.txt_closePhyCashCount_20SR.Enabled = false;
        this.txt_opnCashEJ_20SR.Enabled = false;
        this.txt_opnPhyCash_20SR.Enabled = false;

        this.txt_cashDispensed_50SR.Enabled = false;
        this.txt_closeCashATMSlip_50SR.Enabled = false;
        this.txt_closePhyCashCount_50SR.Enabled = false;
        this.txt_opnCashEJ_50SR.Enabled = false;
        this.txt_opnPhyCash_50SR.Enabled = false;

        this.txt_cashDispensed_100SR.Enabled = false;
        this.txt_closeCashATMSlip_100SR.Enabled = false;
        this.txt_closePhyCashCount_100SR.Enabled = false;
        this.txt_opnCashEJ_100SR.Enabled = false;
        this.txt_opnPhyCash_100SR.Enabled = false;

        this.txt_cashDispensed_500SR.Enabled = false;
        this.txt_closeCashATMSlip_500SR.Enabled = false;
        this.txt_closePhyCashCount_500SR.Enabled = false;
        this.txt_opnCashEJ_500SR.Enabled = false;
        this.txt_opnPhyCash_500SR.Enabled = false;
    }

    private void disableUSDControls()
    {
        this.txt_cashDispensed_100USD.Enabled = false;
        this.txt_closeCashATMSlip_100USD.Enabled = false;
        this.txt_closePhyCashCount_100USD.Enabled = false;
        this.txt_opnCashEJ_100USD.Enabled = false;
        this.txt_opnPhyCash_100USD.Enabled = false;
    }

    private string getLastRplDate(string atmNumber)
    {
        try
        {
            int resCode;
            string lastRplDate = "";

            string DBConnection = Helper.dbConnection();

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

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

            oracom.CommandType = CommandType.StoredProcedure;
            oracom.CommandText = "ATM_JARD_OPERATIONS.GET_LAST_RPL_DATE";

            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_atm_Number", OracleType.VarChar).Direction = ParameterDirection.Input;

            oracom.Parameters.Add("p_last_rpl_date", OracleType.VarChar, 10).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_atm_Number"].Value = atmNumber;

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

            oracon.Close();

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

            if (resCode == 0)
            {
                lastRplDate = oracom.Parameters["p_last_rpl_date"].Value.ToString();
            }
            else if (resCode == 9)
            {
                lastRplDate = "------";
            }

            ExceptionUtility.LogException(0, "ATM_JARD_OPERATIONS.GET_LAST_RPL_DATE","", "getLastRplDate", "atmNumber: " + atmNumber);
            return lastRplDate;
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "ATM_JARD_OPERATIONS.GET_LAST_RPL_DATE","", "getLastRplDate", "atmNumber: " + atmNumber);
            return null;
        }
    }

    private void loadCardsTypes()
    {
        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_SERVICES";

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

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

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

            ddl_capturedCard_cardType.Items.Insert(0, "------ Types ------");

            oracon.Close();
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "LOOKUP_GETTER.GET_SERVICES","", "loadCardsTypes", "");
        }
    }

    private int addCapturedCard(int jardID, string cardNumber, int cardType, string issuerBank, string holderName, 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 = "ATM_JARD_OPERATIONS.ADD_CAPTURED_CARD";

            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_AJT", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("P_CARD_NUMBER", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("P_CARD_TYPE", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("P_ISSUER", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("P_CARDHOLDER_NAME", 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_lang"].Value = "EN";
            oracom.Parameters["P_AJT"].Value = jardID;
            oracom.Parameters["P_CARD_NUMBER"].Value = cardNumber;
            oracom.Parameters["P_CARD_TYPE"].Value = cardType;
            oracom.Parameters["P_ISSUER"].Value = issuerBank;
            oracom.Parameters["P_CARDHOLDER_NAME"].Value = holderName;

            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, "ATM_JARD_OPERATIONS.ADD_CAPTURED_CARD", "addCapturedCard", "400.1", "jardID- " + jardID + ": cardNumber- " + cardNumber + ": cardType- " + cardType + ": issuerbank- " + issuerBank + ": holderName- " + holderName);
            return resCode;
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "ATM_JARD_OPERATIONS.ADD_CAPTURED_CARD", "addCapturedCard","400.1", "jardID- " + jardID + ": cardNumber- " + cardNumber + ": cardType- " + cardType + ": issuerbank- " + issuerBank + ": holderName- " + holderName);
            return 0;
        }
    }

    private int loadCapturedCards(int jardID)
    {
        try
        {
            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 = "ATM_JARD_OPERATIONS.GET_CAPTURED_CARDS";

            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_jard_id", 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.Add("p_output", OracleType.Cursor).Direction = ParameterDirection.Output;


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

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

            oracon.Close();

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

            this.grd_capturedCards.DataSource = ds;
            this.grd_capturedCards.DataBind();
            ExceptionUtility.LogException(0, "ATM_JARD_OPERATIONS.GET_CAPTURED_CARDS", "400.2", "loadCapturedCards", "jardID- " + jardID);
            return resCode;
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "ATM_JARD_OPERATIONS.GET_CAPTURED_CARDS","400.2", "loadCapturedCards", "jardID- " + jardID);
            return 0;
        }
    }
        
    protected void btn_addCard_Click(object sender, EventArgs e)
    {
        string errorMsg = "";
        int addingCapturedCardResCode;
        int enteredCapturedCardsNumber;
        
        string cardNumber = this.txt_capturedCard_cardNo.Text; 
        int cardType = int.Parse(this.ddl_capturedCard_cardType.SelectedValue); 
        string issuerBank = this.txt_capturedCard_issuerBank.Text;
        string holderName = this.txt_capturedCard_holderName.Text;

        enteredCapturedCardsNumber = this.grd_capturedCards.Rows.Count;

        if (enteredCapturedCardsNumber < int.Parse(this.txt_capturedCardsNo.Text))
        {
            ExceptionUtility.LogException(0, "", "73.400", "btn_addCard_Click", "");
            addingCapturedCardResCode = this.addCapturedCard(int.Parse(this.jardID.Value), cardNumber, cardType, issuerBank, holderName, ref errorMsg);

            if (addingCapturedCardResCode == 0)
            {
                this.pnl_capturedCardsGridPnl.Visible = true;
                this.loadCapturedCards(int.Parse(this.jardID.Value));
                this.clearCapturedCardsControls();
            }
            else if (addingCapturedCardResCode == 128)
            {
                this.lbl_capturedCardsError.Text = "Sorry, the entered Card is duplicated!";
            }
        }
        else
        {
            this.lbl_capturedCardsError.Text = "Sorry, you can't enter more cards!";
        }

        
    }

    private void clearCapturedCardsControls()
    {
        this.txt_capturedCard_cardNo.Text = "";
        this.txt_capturedCard_holderName.Text = "";
        this.txt_capturedCard_issuerBank.Text = "";
        this.ddl_capturedCard_cardType.SelectedIndex = 0;
    }
    
    protected void grd_jardResult_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        int selectedIndex = int.Parse(e.CommandArgument.ToString());
        int selectedJardID = int.Parse(this.grd_jardResult.DataKeys[selectedIndex].Value.ToString());
        string selectedJardCurrency = this.grd_jardResult.Rows[selectedIndex].Cells[1].Text.ToString();
        string selectedJardStatus = this.grd_jardResult.Rows[selectedIndex].Cells[5].Text.ToString();

        if (e.CommandName == "u")
        {
            ExceptionUtility.LogException(0, "", "73.399", "grd_jardResult_RowCommand.update", "");
            if (selectedJardStatus.Equals("Closed"))
            {
                this.lbl_error.Text = "Sorry, you cant update a closed JARD form.";
            }
            else
            {
                this.btn_addJard.Visible = true;
                this.btn_close.Visible = true;
                this.btn_save.Visible = true;
                this.btn_cancel_basicDetails.Visible = false;
                this.pnl_jardDetails.Visible = true;
                this.pnl_jardDetailsDenos.Visible = true;
                this.pnl_capturedCardsGridPnl.Visible = true;
                //this.loadCapturedCards(selectedJardID);
                this.jardID.Value = selectedJardID.ToString();

                this.clearAllControls();
                this.loadJardDetails(selectedJardID);
                this.btn_addJard.Visible = false;

                this.disbleJardBasicDetailsControls();
                this.enableCapturedCardsControls();



                if (selectedJardCurrency == "SAR")
                {
                    this.disableUSDControls();
                    this.makeUSDCassettesAsGray();
                    this.pnl_capturedCards.Visible = true;
                }
                else if (selectedJardCurrency == "USD")
                {
                    this.disableSARControls();
                    this.makeSARCassettesAsGray();
                    this.pnl_capturedCards.Visible = false;
                }
            }

        }

        if (e.CommandName == "v")
        {
            ExceptionUtility.LogException(0, "", "73.398", "grd_jardResult_RowCommand.View", "");
            this.clearAllControls();
            this.loadJardDetails(selectedJardID);
            
            this.pnl_jardDetails.Visible = true;
            this.pnl_jardDetailsDenos.Visible = true;

            this.btn_cancel_basicDetails.Visible = false;

            this.disableAllCassettes();
            this.disbleJardBasicDetailsControls();
            this.disableCapturedCardsControls();

            this.btn_addJard.Visible = false;
            this.btn_close.Visible = false;
            this.btn_save.Visible = false;

            if (selectedJardCurrency == "SAR")
            {
                this.makeUSDCassettesAsGray();
                this.pnl_capturedCards.Visible = true;
            }
            else if (selectedJardCurrency == "USD")
            {
                this.makeSARCassettesAsGray();
                this.pnl_capturedCards.Visible = false;
            }
        }

        if (e.CommandName == "d")
        {
            ExceptionUtility.LogException(0, "", "73.403", "grd_jardResult_RowCommand.Delete", "");
            int deleteStatus = this.deleteJard(selectedJardID);

            if (deleteStatus == 0)
            {
                this.btn_search_Click(sender, e);
                this.lbl_capturedCardsError.Text = "The Selected JARD Form Deleted Successfully...";
            }
            else
            {
                this.lbl_capturedCardsError.Text = "An Error occured while trying to delete the selected JARD Form...";
            }
        }
    }

    private void disbleJardDetailsControls()
    {
        this.txt_atmNumber.Enabled = false;
        this.ddl_rplCurrency.Enabled = false;
        this.txt_replTime.Enabled = false;
        this.txt_firstTranNo.Enabled = false;
        this.txt_retractAmount.Enabled = false;
        this.txt_lastTranNo.Enabled = false;
    }
    
    private void disbleJardBasicDetailsControls()
    {
        this.txt_atmNumber.Enabled = false;
        this.ddl_rplCurrency.Enabled = false;
        this.txt_replTime.Enabled = false;
    }

    private void enableJardBasicDetailsControls()
    {
        this.txt_atmNumber.Enabled = true;
        this.ddl_rplCurrency.Enabled = true;
        this.txt_replTime.Enabled = true;
    }

    private int loadJardDetails(int jardID)
    {
        try
        {
            int resCode;

            string atmNumber;


            string open_cash_10, open_cash_20, open_cash_50, open_cash_100, open_cash_500,
                    open_cash_100_usd, open_cash_tot, closing_phy_10, closing_phy_20, closing_phy_50,
                    closing_phy_100, closing_phy_500, closing_phy_100_usd, closing_phy_tot, cash_desp_ej_10,
                    cash_desp_ej_20, cash_desp_ej_50, cash_desp_ej_100, cash_desp_ej_500, cash_desp_ej_100_usd,
                    cash_desp_ej_tot, open_ej_cash_10, open_ej_cash_20, open_ej_cash_50, open_ej_cash_100,
                    open_ej_cash_500, open_ej_cash_100_usd, open_ej_cash_tot, closing_ej_10, closing_ej_20,
                    closing_ej_50, closing_ej_100, closing_ej_500, closing_ej_100_usd, closing_ej_tot, difference,
                    sequence_frst_txn, sequence_last_txn, no_of_captured_crd, retract_amount, jard_status,
                    last_repl_date, curr_repl_date, repl_time, repl_curr;

            string DBConnection = Helper.dbConnection();
            OracleConnection oracon = new OracleConnection(DBConnection);
            oracon.Open();

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

            oracom.CommandType = CommandType.StoredProcedure;
            oracom.CommandText = "ATM_JARD_OPERATIONS.GET_JARD_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_jard_id", OracleType.Number).Direction = ParameterDirection.Input;

            oracom.Parameters.Add("p_ajt", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_atm_no", OracleType.VarChar, 4).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_last_repl_date", OracleType.VarChar, 10).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_curr_repl_date", OracleType.VarChar, 10).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_open_cash_10", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_open_cash_20", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_open_cash_50", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_open_cash_100", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_open_cash_500", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_open_cash_100_usd", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_open_cash_tot", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_repl_curr", OracleType.VarChar, 3).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_open_ej_cash_10", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_open_ej_cash_20", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_open_ej_cash_50", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_open_ej_cash_100", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_open_ej_cash_500", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_open_ej_cash_100_usd", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_open_ej_cash_tot", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_cash_desp_ej_10", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_cash_desp_ej_20", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_cash_desp_ej_50", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_cash_desp_ej_100", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_cash_desp_ej_500", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_cash_desp_ej_100_usd", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_cash_desp_ej_tot", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_closing_ej_10", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_closing_ej_20", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_closing_ej_50", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_closing_ej_100", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_closing_ej_500", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_closing_ej_100_usd", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_closing_ej_tot", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_closing_phy_10", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_clsoing_phy_20", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_closing_phy_50", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_closing_phy_100", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_closing_phy_500", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_closing_phy_100_usd", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_closing_phy_tot", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_difference", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_sequence_frst_txn", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_sequence_last_txn", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_no_of_captured_crd", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_retract_amount", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_jard_status", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_repl_time", OracleType.VarChar, 10).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_jard_id"].Value = jardID;

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

            oracon.Close();

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

            atmNumber = oracom.Parameters["p_atm_no"].Value.ToString();
            last_repl_date = oracom.Parameters["p_last_repl_date"].Value.ToString();
            curr_repl_date = oracom.Parameters["p_curr_repl_date"].Value.ToString();
            open_cash_10 = oracom.Parameters["p_open_cash_10"].Value.ToString();
            open_cash_20 = oracom.Parameters["p_open_cash_20"].Value.ToString();
            open_cash_50 = oracom.Parameters["p_open_cash_50"].Value.ToString();
            open_cash_100 = oracom.Parameters["p_open_cash_100"].Value.ToString();
            open_cash_500 = oracom.Parameters["p_open_cash_500"].Value.ToString();
            open_cash_100_usd = oracom.Parameters["p_open_cash_100_usd"].Value.ToString();
            open_cash_tot = oracom.Parameters["p_open_cash_tot"].Value.ToString();
            closing_phy_10 = oracom.Parameters["p_closing_phy_10"].Value.ToString();
            closing_phy_20 = oracom.Parameters["p_clsoing_phy_20"].Value.ToString();
            closing_phy_50 = oracom.Parameters["p_closing_phy_50"].Value.ToString();
            closing_phy_100 = oracom.Parameters["p_closing_phy_100"].Value.ToString();
            closing_phy_500 = oracom.Parameters["p_closing_phy_500"].Value.ToString();
            closing_phy_100_usd = oracom.Parameters["p_closing_phy_100_usd"].Value.ToString();
            closing_phy_tot = oracom.Parameters["p_closing_phy_tot"].Value.ToString();
            cash_desp_ej_10 = oracom.Parameters["p_cash_desp_ej_10"].Value.ToString();
            cash_desp_ej_20 = oracom.Parameters["p_cash_desp_ej_20"].Value.ToString();
            cash_desp_ej_50 = oracom.Parameters["p_cash_desp_ej_50"].Value.ToString();
            cash_desp_ej_100 = oracom.Parameters["p_cash_desp_ej_100"].Value.ToString();
            cash_desp_ej_500 = oracom.Parameters["p_cash_desp_ej_500"].Value.ToString();
            cash_desp_ej_100_usd = oracom.Parameters["p_cash_desp_ej_100_usd"].Value.ToString();
            cash_desp_ej_tot = oracom.Parameters["p_cash_desp_ej_tot"].Value.ToString();
            open_ej_cash_10 = oracom.Parameters["p_open_ej_cash_10"].Value.ToString();
            open_ej_cash_20 = oracom.Parameters["p_open_ej_cash_20"].Value.ToString();
            open_ej_cash_50 = oracom.Parameters["p_open_ej_cash_50"].Value.ToString();
            open_ej_cash_100 = oracom.Parameters["p_open_ej_cash_100"].Value.ToString();
            open_ej_cash_500 = oracom.Parameters["p_open_ej_cash_500"].Value.ToString();
            open_ej_cash_100_usd = oracom.Parameters["p_open_ej_cash_100_usd"].Value.ToString();
            open_ej_cash_tot = oracom.Parameters["p_open_ej_cash_tot"].Value.ToString();
            closing_ej_10 = oracom.Parameters["p_closing_ej_10"].Value.ToString();
            closing_ej_20 = oracom.Parameters["p_closing_ej_20"].Value.ToString();
            closing_ej_50 = oracom.Parameters["p_closing_ej_50"].Value.ToString();
            closing_ej_100 = oracom.Parameters["p_closing_ej_100"].Value.ToString();
            closing_ej_500 = oracom.Parameters["p_closing_ej_500"].Value.ToString();
            closing_ej_100_usd = oracom.Parameters["p_closing_ej_100_usd"].Value.ToString();
            closing_ej_tot = oracom.Parameters["p_closing_ej_tot"].Value.ToString();
            difference = oracom.Parameters["p_difference"].Value.ToString();
            sequence_frst_txn = oracom.Parameters["p_sequence_frst_txn"].Value.ToString();
            sequence_last_txn = oracom.Parameters["p_sequence_last_txn"].Value.ToString();
            no_of_captured_crd = oracom.Parameters["p_no_of_captured_crd"].Value.ToString();
            retract_amount = oracom.Parameters["p_retract_amount"].Value.ToString();
            jard_status = oracom.Parameters["p_jard_status"].Value.ToString();
            repl_time = oracom.Parameters["p_repl_time"].Value.ToString();
            repl_curr = oracom.Parameters["p_repl_curr"].Value.ToString();

            if (resCode == 0)
            {
                this.txt_atmNumber.Text = atmNumber.ToString();
                this.lbl_lastReplDate.Text = last_repl_date;
                this.lbl_currentReplDate.Text = curr_repl_date;
                this.txt_replTime.Text = repl_time;
                this.txt_firstTranNo.Text = sequence_frst_txn.ToString();
                this.txt_lastTranNo.Text = sequence_last_txn.ToString();
                this.txt_retractAmount.Text = retract_amount.ToString();

                this.txt_cashDispensed_10SR.Text = cash_desp_ej_10.ToString();
                this.txt_closeCashATMSlip_10SR.Text = closing_ej_10.ToString();
                this.txt_closePhyCashCount_10SR.Text = closing_phy_10.ToString();
                this.txt_opnCashEJ_10SR.Text = open_ej_cash_10.ToString();
                this.txt_opnPhyCash_10SR.Text = open_cash_10.ToString();

                this.txt_cashDispensed_20SR.Text = cash_desp_ej_20.ToString();
                this.txt_closeCashATMSlip_20SR.Text = closing_ej_20.ToString();
                this.txt_closePhyCashCount_20SR.Text = closing_phy_20.ToString();
                this.txt_opnCashEJ_20SR.Text = open_ej_cash_20.ToString();
                this.txt_opnPhyCash_20SR.Text = open_cash_20.ToString();

                this.txt_cashDispensed_50SR.Text = cash_desp_ej_50.ToString();
                this.txt_closeCashATMSlip_50SR.Text = closing_ej_50.ToString();
                this.txt_closePhyCashCount_50SR.Text = closing_phy_50.ToString();
                this.txt_opnCashEJ_50SR.Text = open_ej_cash_50.ToString();
                this.txt_opnPhyCash_50SR.Text = open_cash_50.ToString();

                this.txt_cashDispensed_100SR.Text = cash_desp_ej_100.ToString();
                this.txt_closeCashATMSlip_100SR.Text = closing_ej_100.ToString();
                this.txt_closePhyCashCount_100SR.Text = closing_phy_100.ToString();
                this.txt_opnCashEJ_100SR.Text = open_ej_cash_100.ToString();
                this.txt_opnPhyCash_100SR.Text = open_cash_100.ToString();

                this.txt_cashDispensed_500SR.Text = cash_desp_ej_500.ToString();
                this.txt_closeCashATMSlip_500SR.Text = closing_ej_500.ToString();
                this.txt_closePhyCashCount_500SR.Text = closing_phy_500.ToString();
                this.txt_opnCashEJ_500SR.Text = open_ej_cash_500.ToString();
                this.txt_opnPhyCash_500SR.Text = open_cash_500.ToString();

                this.txt_cashDispensed_100USD.Text = cash_desp_ej_100_usd.ToString();
                this.txt_closeCashATMSlip_100USD.Text = closing_ej_100_usd.ToString();
                this.txt_closePhyCashCount_100USD.Text = closing_phy_100_usd.ToString();
                this.txt_opnCashEJ_100USD.Text = open_ej_cash_100_usd.ToString();
                this.txt_opnPhyCash_100USD.Text = open_cash_100_usd.ToString();

                this.lbl_openEJCashTotal.Text = open_ej_cash_tot.ToString();

                this.lbl_openPhyCashTotal.Text = open_cash_tot.ToString();

                this.lbl_dispCashTotal.Text = cash_desp_ej_tot.ToString();

                this.lbl_closeCashTotal.Text = closing_ej_tot.ToString();

                this.lbl_closePhyCashTotal.Text = closing_phy_tot.ToString();

                this.lbl_difference.Text = difference.ToString();

                this.txt_capturedCardsNo.Text = no_of_captured_crd;

                this.ddl_rplCurrency.SelectedValue = repl_curr;

                this.arrangeAtmCassettes(atmNumber);
                this.loadCapturedCards(jardID);

                if (repl_curr == "SAR")
                {
                    this.disableUSDControls();
                }
                else if (repl_curr == "USD")
                {
                    this.disableSARControls();
                }
            }

            ExceptionUtility.LogException(0, "ATM_JARD_OPERATIONS.GET_JARD_DETAILS", "391.1", "loadJardDetails", "jardID: " + jardID);
            return resCode;
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "ATM_JARD_OPERATIONS.GET_JARD_DETAILS","391.1","loadJardDetails", "jardID: " + jardID);
            return 0;
        }
    }
        
    protected void btn_save_Click(object sender, EventArgs e)
    {
        int updateStatus;
        string errorMsg = "";
        updateStatus = this.updateJardDetails(ref errorMsg);

        if (updateStatus == 0) 
        {
            this.lbl_error.Text = "Jard Details Updated Successfully...";
            this.clearAllControls();
            this.loadJardDetails(int.Parse(this.jardID.Value));
        }
        else
        {
            this.lbl_error.Text = "Sorry, an Error occured !";
        }
    }

    private int updateJardDetails(ref string errorMsg)
    {
        try
        {
            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 = "ATM_JARD_OPERATIONS.UPDATE_JARD_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_jard_id", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_open_cash_10", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_open_cash_20", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_open_cash_50", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_open_cash_100", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_open_cash_500", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_open_cash_100_usd", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_open_ej_cash_10", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_open_ej_cash_20", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_open_ej_cash_50", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_open_ej_cash_100", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_open_ej_cash_500", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_open_ej_cash_100_usd", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_cash_desp_ej_10", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_cash_desp_ej_20", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_cash_desp_ej_50", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_cash_desp_ej_100", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_cash_desp_ej_500", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_cash_desp_ej_100_usd", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_closing_ej_10", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_closing_ej_20", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_closing_ej_50", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_closing_ej_100", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_closing_ej_500", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_closing_ej_100_usd", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_closing_phy_10", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_closing_phy_20", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_closing_phy_50", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_closing_phy_100", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_closing_phy_500", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_closing_phy_100_usd", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_sequence_frst_txn", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_sequence_last_txn", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_no_of_captured_crd", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_retract_amount", 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_lang"].Value = "EN";

            oracom.Parameters["p_jard_id"].Value = this.jardID.Value;
            oracom.Parameters["p_open_cash_10"].Value = this.txt_opnPhyCash_10SR.Text;
            oracom.Parameters["p_open_cash_20"].Value = this.txt_opnPhyCash_20SR.Text;
            oracom.Parameters["p_open_cash_50"].Value = this.txt_opnPhyCash_50SR.Text;
            oracom.Parameters["p_open_cash_100"].Value = this.txt_opnPhyCash_100SR.Text;
            oracom.Parameters["p_open_cash_500"].Value = this.txt_opnPhyCash_500SR.Text;
            oracom.Parameters["p_open_cash_100_usd"].Value = this.txt_opnPhyCash_100USD.Text;
            oracom.Parameters["p_open_ej_cash_10"].Value = this.txt_opnCashEJ_10SR.Text;
            oracom.Parameters["p_open_ej_cash_20"].Value = this.txt_opnCashEJ_20SR.Text;
            oracom.Parameters["p_open_ej_cash_50"].Value = this.txt_opnCashEJ_50SR.Text;
            oracom.Parameters["p_open_ej_cash_100"].Value = this.txt_opnCashEJ_100SR.Text;
            oracom.Parameters["p_open_ej_cash_500"].Value = this.txt_opnCashEJ_500SR.Text;
            oracom.Parameters["p_open_ej_cash_100_usd"].Value = this.txt_opnCashEJ_100USD.Text;
            oracom.Parameters["p_cash_desp_ej_10"].Value = this.txt_cashDispensed_10SR.Text;
            oracom.Parameters["p_cash_desp_ej_20"].Value = this.txt_cashDispensed_20SR.Text;
            oracom.Parameters["p_cash_desp_ej_50"].Value = this.txt_cashDispensed_50SR.Text;
            oracom.Parameters["p_cash_desp_ej_100"].Value = this.txt_cashDispensed_100SR.Text;
            oracom.Parameters["p_cash_desp_ej_500"].Value = this.txt_cashDispensed_500SR.Text;
            oracom.Parameters["p_cash_desp_ej_100_usd"].Value = this.txt_cashDispensed_100USD.Text;
            oracom.Parameters["p_closing_ej_10"].Value = this.txt_closeCashATMSlip_10SR.Text;
            oracom.Parameters["p_closing_ej_20"].Value = this.txt_closeCashATMSlip_20SR.Text;
            oracom.Parameters["p_closing_ej_50"].Value = this.txt_closeCashATMSlip_50SR.Text;
            oracom.Parameters["p_closing_ej_100"].Value = this.txt_closeCashATMSlip_100SR.Text;
            oracom.Parameters["p_closing_ej_500"].Value = this.txt_closeCashATMSlip_500SR.Text;
            oracom.Parameters["p_closing_ej_100_usd"].Value = this.txt_closeCashATMSlip_100USD.Text;
            oracom.Parameters["p_closing_phy_10"].Value = this.txt_closePhyCashCount_10SR.Text;
            oracom.Parameters["p_closing_phy_20"].Value = this.txt_closePhyCashCount_20SR.Text;
            oracom.Parameters["p_closing_phy_50"].Value = this.txt_closePhyCashCount_50SR.Text;
            oracom.Parameters["p_closing_phy_100"].Value = this.txt_closePhyCashCount_100SR.Text;
            oracom.Parameters["p_closing_phy_500"].Value = this.txt_closePhyCashCount_500SR.Text;
            oracom.Parameters["p_closing_phy_100_usd"].Value = this.txt_closePhyCashCount_100USD.Text;
            oracom.Parameters["p_sequence_frst_txn"].Value = this.txt_firstTranNo.Text;
            oracom.Parameters["p_sequence_last_txn"].Value = this.txt_lastTranNo.Text;
            oracom.Parameters["p_no_of_captured_crd"].Value = this.txt_capturedCardsNo.Text; ;
            oracom.Parameters["p_retract_amount"].Value = this.txt_retractAmount.Text;

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

            resCode = int.Parse(oracom.Parameters["p_res_code"].Value.ToString());
            errorMsg = oracom.Parameters["p_res_msg"].Value.ToString();
            ExceptionUtility.LogException(0, "ATM_JARD_OPERATIONS.UPDATE_JARD_Details", "", "updateJardDetails", "");
            return resCode;
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "ATM_JARD_OPERATIONS.UPDATE_JARD_Details","", "updateJardDetails", "");
            return 0;
        }
    }
    
    protected void grd_capturedCards_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        string selectedCardNumber;
        int selectedIndex;
        
        if (e.CommandName == "d") 
        {
            selectedIndex = int.Parse(e.CommandArgument.ToString());
            selectedCardNumber = this.grd_capturedCards.DataKeys[selectedIndex].Value.ToString();

            int deleteStatus = this.deleteCapturedCard(int.Parse(this.jardID.Value), selectedCardNumber);

            if (deleteStatus == 0)
            {
                this.loadCapturedCards(int.Parse(this.jardID.Value.ToString()));
                this.lbl_capturedCardsError.Text = "The Selected Card Deleted Successfully...";
            }
            else
            {
                this.lbl_capturedCardsError.Text = "An Error occured while trying to delete the selected Card...";
            }
        }
    }

    private int deleteCapturedCard(int jardID, string cardNumber)
    {
        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 = "ATM_JARD_OPERATIONS.DELETE_CAPTURED_CARD";

            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_AJT", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("P_CARD_NUMBER", 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_lang"].Value = "EN";
            oracom.Parameters["P_AJT"].Value = jardID;
            oracom.Parameters["P_CARD_NUMBER"].Value = cardNumber;

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

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

            return resCode;
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "ATM_JARD_OPERATIONS.DELETE_CAPTURED_CARD","", "deleteCapturedCard", "jardID: " + jardID + ", cardNumber: " + cardNumber);
            return 0;
        }
    }

    protected void txt_opnPhyCash_TextChanged(object sender, EventArgs e)
    {
        if (this.ddl_rplCurrency.SelectedValue == "SAR")
        {
            this.lbl_openPhyCashTotal.Text = ((int.Parse(this.txt_opnPhyCash_10SR.Text) * 10) +
                                            (int.Parse(this.txt_opnPhyCash_20SR.Text) * 20) +
                                            (int.Parse(this.txt_opnPhyCash_50SR.Text) * 50) +
                                            (int.Parse(this.txt_opnPhyCash_100SR.Text) * 100) +
                                            (int.Parse(this.txt_opnPhyCash_500SR.Text) * 500)).ToString();
        }
        else if (this.ddl_rplCurrency.SelectedValue == "USD")
        {
            this.lbl_openPhyCashTotal.Text = "USD";
        }
        else
        {
            this.lbl_openPhyCashTotal.Text = "ELSE";
        }
    }

    private void clearDemosControls()
    {
        this.txt_cashDispensed_10SR.Text = "";
        this.txt_closeCashATMSlip_10SR.Text = "";
        this.txt_closePhyCashCount_10SR.Text = "";
        this.txt_opnCashEJ_10SR.Text = "";
        this.txt_opnPhyCash_10SR.Text = "";

        this.txt_cashDispensed_20SR.Text = "";
        this.txt_closeCashATMSlip_20SR.Text = "";
        this.txt_closePhyCashCount_20SR.Text = "";
        this.txt_opnCashEJ_20SR.Text = "";
        this.txt_opnPhyCash_20SR.Text = "";

        this.txt_cashDispensed_50SR.Text = "";
        this.txt_closeCashATMSlip_50SR.Text = "";
        this.txt_closePhyCashCount_50SR.Text = "";
        this.txt_opnCashEJ_50SR.Text = "";
        this.txt_opnPhyCash_50SR.Text = "";

        this.txt_cashDispensed_100SR.Text = "";
        this.txt_closeCashATMSlip_100SR.Text = "";
        this.txt_closePhyCashCount_100SR.Text = "";
        this.txt_opnCashEJ_100SR.Text = "";
        this.txt_opnPhyCash_100SR.Text = "";

        this.txt_cashDispensed_500SR.Text = "";
        this.txt_closeCashATMSlip_500SR.Text = "";
        this.txt_closePhyCashCount_500SR.Text = "";
        this.txt_opnCashEJ_500SR.Text = "";
        this.txt_opnPhyCash_500SR.Text = "";

        this.txt_cashDispensed_100USD.Text = "";
        this.txt_closeCashATMSlip_100USD.Text = "";
        this.txt_closePhyCashCount_100USD.Text = "";
        this.txt_opnCashEJ_100USD.Text = "";
        this.txt_opnPhyCash_100USD.Text = "";

        this.lbl_dispCashTotal.Text = "";
        this.lbl_closeCashTotal.Text = "";
        this.lbl_closePhyCashTotal.Text = "";
        this.lbl_openEJCashTotal.Text = "";
        this.lbl_openPhyCashTotal.Text = "";
    }
    
    private void clearAllControls()
    {
        this.clearDemosControls();
        this.clearCapturedCardsControls();

        this.clearBasicDetailsControls();
    }

    private void clearBasicDetailsControls()
    {
        this.txt_atmNumber.Text = "";
        this.ddl_rplCurrency.SelectedIndex = 0;
        this.txt_replTime.Text = "";
        this.lbl_lastReplDate.Text = "";
        this.lbl_currentReplDate.Text = "";
        this.txt_firstTranNo.Text = "";
        this.txt_lastTranNo.Text = "";
        this.txt_retractAmount.Text = "";
    }

    private int closeJard(int jardID, 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 = "ATM_JARD_OPERATIONS.CLOSE_JARD";

            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_AJT", 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_AJT"].Value = int.Parse(this.jardID.Value);

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

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

            return resCode;
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "ATM_JARD_OPERATIONS.CLOSE_JARD","", "closeJard", "jardID: " + jardID);
            return 0;
        }
    }
    
    protected void btn_close_Click(object sender, EventArgs e)
    {
        int closeStatus;
        string closeErrorMsg = "";

        if (this.canCloseJard())
        {

            closeStatus = this.closeJard(int.Parse(this.jardID.Value), ref closeErrorMsg);

            if (closeStatus == 0)
            {
                this.lbl_error.Text = "Jard Closed Successfully";

                //this.clearAllControls();
                this.disableAllCassettes();
                this.disbleJardBasicDetailsControls();
                this.btn_addCard.Enabled = false;
                this.btn_save.Enabled = false;
                this.btn_cancel.Enabled = false;

            }
            else
            {
                this.lbl_error.Text = closeErrorMsg;
            }
        }


    }

    private bool canCloseJard()
    {
        bool canBeClosed = false;
        
        if (this.txt_cashDispensed_10SR.Enabled) {
            if ( this.txt_cashDispensed_10SR.Text.Length != 0 &&
                 this.txt_closeCashATMSlip_10SR.Text.Length != 0 &&
                 this.txt_closePhyCashCount_10SR.Text.Length != 0 &&
                 this.txt_opnCashEJ_10SR.Text.Length != 0 &&
                 this.txt_opnPhyCash_10SR.Text.Length != 0)
            {
                canBeClosed = true;
            }
            else
            {
                canBeClosed = false;
                this.lbl_error.Text = "You can't close this JARD from, please enter fill the available Cassettes Details for this ATM.";
            }

        }

        if (this.txt_cashDispensed_20SR.Enabled)
        {
            if (this.txt_cashDispensed_20SR.Text.Length != 0 &&
                 this.txt_closeCashATMSlip_20SR.Text.Length != 0 &&
                 this.txt_closePhyCashCount_20SR.Text.Length != 0 &&
                 this.txt_opnCashEJ_20SR.Text.Length != 0 &&
                 this.txt_opnPhyCash_20SR.Text.Length != 0)
            {
                canBeClosed = true;
            }
            else
            {
                canBeClosed = false;
                this.lbl_error.Text = "You can't close this JARD from, please enter fill the available Cassettes Details for this ATM.";
            }
        }

        if (this.txt_cashDispensed_50SR.Enabled)
        {
            if (this.txt_cashDispensed_50SR.Text.Length != 0 &&
                 this.txt_closeCashATMSlip_50SR.Text.Length != 0 &&
                 this.txt_closePhyCashCount_50SR.Text.Length != 0 &&
                 this.txt_opnCashEJ_50SR.Text.Length != 0 &&
                 this.txt_opnPhyCash_50SR.Text.Length != 0)
            {
                canBeClosed = true;
            }
            else
            {
                canBeClosed = false;
                this.lbl_error.Text = "You can't close this JARD from, please enter fill the available Cassettes Details for this ATM.";
            }
        }

        if (this.txt_cashDispensed_100SR.Enabled)
        {
            if (this.txt_cashDispensed_100SR.Text.Length != 0 &&
            this.txt_closeCashATMSlip_100SR.Text.Length != 0 &&
            this.txt_closePhyCashCount_100SR.Text.Length != 0 &&
            this.txt_opnCashEJ_100SR.Text.Length != 0 &&
            this.txt_opnPhyCash_100SR.Text.Length != 0)
            {
                canBeClosed = true;
            }
            else
            {
                canBeClosed = false;
                this.lbl_error.Text = "You can't close this JARD from, please enter fill the available Cassettes Details for this ATM.";
            }
        }

        if (this.txt_cashDispensed_500SR.Enabled)
        {
            if (this.txt_cashDispensed_500SR.Text.Length != 0 &&
            this.txt_closeCashATMSlip_500SR.Text.Length != 0 &&
            this.txt_closePhyCashCount_500SR.Text.Length != 0 &&
            this.txt_opnCashEJ_500SR.Text.Length != 0 &&
            this.txt_opnPhyCash_500SR.Text.Length != 0)
            {
                canBeClosed = true;
            }
            else
            {
                canBeClosed = false;
                this.lbl_error.Text = "You can't close this JARD from, please enter fill the available Cassettes Details for this ATM.";
            }
        }
        
        if (this.txt_cashDispensed_100USD.Enabled)
        {
            if (this.txt_cashDispensed_100USD.Text.Length != 0 &&
            this.txt_closeCashATMSlip_100USD.Text.Length != 0 &&
            this.txt_closePhyCashCount_100USD.Text.Length != 0 &&
            this.txt_opnCashEJ_100USD.Text.Length != 0 &&
            this.txt_opnPhyCash_100USD.Text.Length != 0)
            {
                canBeClosed = true;
            }
            else
            {
                canBeClosed = false;
                this.lbl_error.Text = "You can't close this JARD from, please enter fill the available Cassettes Details for this ATM.";
            }
        }

        if (this.txt_capturedCardsNo.Text.Length > 0)
        {
            if (this.grd_capturedCards.Rows.Count == int.Parse(this.txt_capturedCardsNo.Text))
            {
                canBeClosed = true;
            }
            else
            {
                canBeClosed = false;
                this.lbl_error.Text = "You can't close this JARD from, please add the currect Captured Cards Number.";
            }
        }

       
        return canBeClosed;
    }

    private void disableCapturedCardsControls()
    {
        this.txt_capturedCardsNo.Enabled = false;
        this.txt_capturedCard_cardNo.Enabled = false;
        this.txt_capturedCard_holderName.Enabled = false;
        this.txt_capturedCard_issuerBank.Enabled = false;
        this.ddl_capturedCard_cardType.Enabled = false;

    }

    private void enableCapturedCardsControls()
    {
        this.txt_capturedCardsNo.Enabled = true;
        this.txt_capturedCard_cardNo.Enabled = true;
        this.txt_capturedCard_holderName.Enabled = true;
        this.txt_capturedCard_issuerBank.Enabled = true;
        this.ddl_capturedCard_cardType.Enabled = true;

    }

    protected void btn_cancel_Click(object sender, EventArgs e)
    {
        this.clearAllControls();
        this.pnl_jardDetails.Visible = false;
        this.pnl_jardDetailsDenos.Visible = false;
        this.btn_addNew.Visible = true;
    }
        
    protected void btn_cancel_basicDetails_Click(object sender, EventArgs e)
    {
        this.clearBasicDetailsControls();
        this.pnl_jardDetails.Visible = false;

        this.pnl_addNew.Visible = true;
    }

    private void makeUSDCassettesAsGray()
    {
        this.txt_cashDispensed_100USD.BackColor = Color.LightGray;
        this.txt_closeCashATMSlip_100USD.BackColor = Color.LightGray;
        this.txt_closePhyCashCount_100USD.BackColor = Color.LightGray;
        this.txt_opnCashEJ_100USD.BackColor = Color.LightGray;
        this.txt_opnPhyCash_100USD.BackColor = Color.LightGray;
    }

    private void makeSARCassettesAsGray()
    {
        this.txt_cashDispensed_10SR.BackColor = Color.LightGray;
        this.txt_closeCashATMSlip_10SR.BackColor = Color.LightGray;
        this.txt_closePhyCashCount_10SR.BackColor = Color.LightGray;
        this.txt_opnCashEJ_10SR.BackColor = Color.LightGray;
        this.txt_opnPhyCash_10SR.BackColor = Color.LightGray;
        this.txt_cashDispensed_20SR.BackColor = Color.LightGray;
        this.txt_closeCashATMSlip_20SR.BackColor = Color.LightGray;
        this.txt_closePhyCashCount_20SR.BackColor = Color.LightGray;
        this.txt_opnCashEJ_20SR.BackColor = Color.LightGray;
        this.txt_opnPhyCash_20SR.BackColor = Color.LightGray;
        this.txt_cashDispensed_50SR.BackColor = Color.LightGray;
        this.txt_closeCashATMSlip_50SR.BackColor = Color.LightGray;
        this.txt_closePhyCashCount_50SR.BackColor = Color.LightGray;
        this.txt_opnCashEJ_50SR.BackColor = Color.LightGray;
        this.txt_opnPhyCash_50SR.BackColor = Color.LightGray;
        this.txt_cashDispensed_100SR.BackColor = Color.LightGray;
        this.txt_closeCashATMSlip_100SR.BackColor = Color.LightGray;
        this.txt_closePhyCashCount_100SR.BackColor = Color.LightGray;
        this.txt_opnCashEJ_100SR.BackColor = Color.LightGray;
        this.txt_opnPhyCash_100SR.BackColor = Color.LightGray;
        this.txt_cashDispensed_500SR.BackColor = Color.LightGray;
        this.txt_closeCashATMSlip_500SR.BackColor = Color.LightGray;
        this.txt_closePhyCashCount_500SR.BackColor = Color.LightGray;
        this.txt_opnCashEJ_500SR.BackColor = Color.LightGray;
        this.txt_opnPhyCash_500SR.BackColor = Color.LightGray;
    }
    
    protected void grd_jardResult_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        ExceptionUtility.LogException(0, "", "", "grd_jardResult_PageIndexChanging", "");
        grd_jardResult.PageIndex = e.NewPageIndex;

        string atmNumber = this.txt_atmNumberFilter.Text;
        string rplCurrency = (this.ddl_rplCurrency_filter.SelectedIndex != 0) ? this.ddl_rplCurrency_filter.SelectedValue : "";
        string rplDate = (this.dtp_rplDate.date.Length != 0) ? this.dtp_rplDate.date.Replace("-", "") : "";

        this.searchJards(atmNumber, rplCurrency, rplDate);
    }

    protected void btn_print_Click(object sender, EventArgs e)
    {
        ExceptionUtility.LogException(0, "", "", "btn_print_Click", "");
        ScriptManager.RegisterClientScriptBlock(this, typeof(string), "new window",
            "window.open('../Reports/Default.aspx?rpt=223&p1=" + this.jardID.Value + "&p2=" + Session["uid"].ToString() + "','Report')", true);

    }


    private int deleteJard(int jardId)
    {
        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 = "ATM_JARD_OPERATIONS.DELETE_JARD";

            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_JARD_ID", 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_JARD_ID"].Value = jardId;

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

            int resCode = int.Parse(oracom.Parameters["p_res_code"].Value.ToString());
            ExceptionUtility.LogException(0, "ATM_JARD_OPERATIONS.DELETE_JARD", "403.1", "deleteJard", "jardID: " + jardID);
            return resCode;
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "ATM_JARD_OPERATIONS.DELETE_JARD","403.1", "deleteJard", "jardID: " + jardID);
            return 0;
        }
    }
}