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_MonthlySAMA : System.Web.UI.Page
{
    static int intCount = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            loadSAMAAccountType();
            ExceptionUtility.LogException(0, "", "84", "Page_Load", "");
        }
    }
    private void loadSAMAAccountType()
    {
        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_sama_monthly_gl";

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

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

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

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

            ddlSAMAType.Items.Insert(0, "------ All ------");
            
            oracon.Close();
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "LOOKUP_GETTER.p_sama_monthly", "", "loadSAMAAccountType", "");
            //Response.Redirect("../ErrorPages/ErrorPage.aspx");
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        pnlResult.Visible = true;
        pnlControls.Visible = false;
        pnlResult.Enabled = true;
        ExceptionUtility.LogException(0, "", "84.492", "Button1_Click", "");
        loadResult();
       
    }
    private void loadResult()
    {
        string parameters = "";
        try
        {
            string currentMethod = "";
            StackTrace stackTrace = new StackTrace();
            currentMethod = stackTrace.GetFrame(1).GetMethod().Name;
            string DBConnection = Helper.dbConnection();

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

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

            oracom.CommandType = CommandType.StoredProcedure;
            oracom.CommandText = "SAMA_MONTHLY_ACCT_EDITOR.get_SAMA_monthly_GL";


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

            if(ddlSAMAType .SelectedIndex >0)
                oracom.Parameters["p_sama_type"].Value = ddlSAMAType.SelectedValue; 
            else
                oracom.Parameters["p_sama_type"].Value = OracleNumber .Null ; 
            oracom.Parameters["p_lang"].Value = "EN";
            oracom.Parameters["p_current_uid"].Value = Session["uid"].ToString();

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

            oracon.Close();

            GridView1.DataSource = ds;
            GridView1.DataBind();
            
            if (currentMethod.Contains("Button1_Click"))
                ExceptionUtility.LogException(0, "SAMA_MONTHLY_ACCT_EDITOR.get_SAMA_monthly_GL", "492.1", "loadResult", parameters);
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "SAMA_MONTHLY_ACCT_EDITOR.get_SAMA_monthly_GL", "492.1", "loadResult", parameters);
            GridView1.DataSource = null;
            GridView1.DataBind();
            //Response.Redirect("../ErrorPages/ErrorPage.aspx");
        }
    }
    private DataSet  loadMonthlySAMAbyType(string  type)
    {
       
        try
        {
            string currentMethod = "";
            StackTrace stackTrace = new StackTrace();
            currentMethod = stackTrace.GetFrame(1).GetMethod().Name;
            string DBConnection = Helper.dbConnection();

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

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

            oracom.CommandType = CommandType.StoredProcedure;
            oracom.CommandText = "SAMA_MONTHLY_ACCT_EDITOR.get_SAMA_monthly_GL";


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

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

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

            oracon.Close();
            ExceptionUtility.LogException(0, "SAMA_MONTHLY_ACCT_EDITOR.get_SAMA_monthly_GL", "494.1", "loadMonthlySAMAbyType", "type-" + type);
            return ds;

            //if (currentMethod.Contains("Button1_Click"))
           
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "SAMA_MONTHLY_ACCT_EDITOR.get_SAMA_monthly_GL", "494.1", "loadMonthlySAMAbyType", "type-" + type);
            GridView1.DataSource = null;
            GridView1.DataBind();
            return null;
            //Response.Redirect("../ErrorPages/ErrorPage.aspx");
        }
    }
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        intCount = 0;
        pnlControls.Visible = true;
        pnlResult.Enabled = false;
        ViewState["mode"] = "a";
        ddlSAMAType1.Enabled = true;
        clear();
        ExceptionUtility.LogException(0, "", "84.495", "btnAdd_Click", "");
    }
    protected void btnCancel_Click(object sender, EventArgs e)
    {
        clear();
        pnlControls.Visible = false;
        pnlResult.Enabled = true;
        ExceptionUtility.LogException(0, "", "", "btnCancel_Click", "");
    }
    private void clear()
    {
        ddlSAMAType1.SelectedIndex = 0;
        TxtCredit.Text = "";
        txtDebit.Text = "";
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (intCount < 1)
            intCount++;
        else
        {
            pnlControls.Visible = false;
            lblError.Text = "Your request has been sent to Checker user for Approval";
            return;
        }
        try
        {
            string mode = ViewState["mode"].ToString();
            string error = "";

           
            if (mode.Equals("a"))
            {
                
                ExceptionUtility.LogException(0, "", "84.496", "btnSave_Click", "");
                if (Can_Insert())
                {
                    int chgId = loadChgID();

                    bool saved = false;
                    //adding records for the primary table (gl_accnt_table)
                    saved = UpdateMakerChecker(chgId, ddlSAMAType1.SelectedValue, "SMTA_CODE", "", ddlSAMAType1.SelectedItem.Text, "", ddlSAMAType1.SelectedValue, 0, ref error);
                    if (saved == false)
                    {
                        if (Helper.OracleError(error))
                        {
                            lblError.Text = "An Error Occured!";
                            ExceptionUtility.LogException(9, "", "84.496", "btnSave_Click", error);
                        }
                        else
                            lblError.Text = error;
                        return;
                    }
                    saved = UpdateMakerChecker(chgId, ddlSAMAType1.SelectedValue, "DEBIT_ACCOUNT", "", txtDebit.Text, "", "", 0, ref error);
                    if (saved == false)
                    {
                        if (Helper.OracleError(error))
                        {
                            lblError.Text = "An Error Occured!";
                            ExceptionUtility.LogException(9, "", "84.496", "btnSave_Click", error);
                        }
                        else
                            lblError.Text = error;
                        return;
                    }
                    saved = UpdateMakerChecker(chgId, ddlSAMAType1.SelectedValue,  "CREDIT_ACCOUNT", "", TxtCredit .Text, "", "", 0, ref error);
                    if (saved == false)
                    {
                        if (Helper.OracleError(error))
                        {
                            lblError.Text = "An Error Occured!";
                            ExceptionUtility.LogException(9, "", "84.496", "btnSave_Click", error);
                        }
                        else
                            lblError.Text = error;
                        return;
                    }
                    saved = UpdateMakerChecker(chgId, ddlSAMAType1.SelectedValue, "RECORD_DATE", "", "", "", "", 0, ref error);
                    if (saved == false)
                    {
                        if (Helper.OracleError(error))
                        {
                            lblError.Text = "An Error Occured!";
                            ExceptionUtility.LogException(9, "", "84.496", "btnSave_Click", error);
                        }
                        else
                            lblError.Text = error;
                        return;
                    }
                    saved = UpdateMakerChecker(chgId, ddlSAMAType1.SelectedValue, "CREATED_BY", "", Session["uid"].ToString(), "", "", 0, ref error);
                    if (saved == false)
                    {
                        if (Helper.OracleError(error))
                        {
                            lblError.Text = "An Error Occured!";
                            ExceptionUtility.LogException(9, "", "84.496", "btnSave_Click", error);
                        }
                        else
                            lblError.Text = error;
                        return;
                    }
                    saved = UpdateMakerChecker(chgId, ddlSAMAType1.SelectedValue,  "MODIFIED_BY", "", Session["uid"].ToString(), "", "", 0, ref error);
                    if (saved == false)
                    {
                        if (Helper.OracleError(error))
                        {
                            lblError.Text = "An Error Occured!";
                            ExceptionUtility.LogException(9, "", "84.496", "btnSave_Click", error);
                        }
                        else
                            lblError.Text = error;
                        return;
                    }


                    lblError.Text = "Your request has been sent to Checker user for Approval";
                }
                else
                {
                    lblError.Text = "This record is already existing";
                }

            }
            else if (mode.Equals("u"))
            {
                string  Uid = ViewState["rowid"].ToString ();
                int chgId = loadChgID();
                bool compare = false;
                DataSet ds = loadMonthlySAMAbyType(Uid);
                ExceptionUtility.LogException(0, "", "84.496", "btnSave_Click", "");
                //bool saved = updateGL(Uid, ref error);
                if (ds.Tables[0].Rows.Count > 0)
                {
                    
                    if (ds.Tables[0].Rows[0]["SMTA_CODE"].ToString() == ddlSAMAType1.SelectedValue && ds.Tables[0].Rows[0]["DEBIT_ACCOUNT"].ToString() == txtDebit .Text  &&
                        ds.Tables[0].Rows[0]["CREDIT_ACCOUNT"].ToString() == TxtCredit .Text)
                        compare = true;
                    if (compare == false)
                    {
                        bool update = false;
                       
                        if (ds.Tables[0].Rows[0]["SMTA_CODE"].ToString() != ddlSAMAType1.SelectedValue)
                        {
                            update = UpdateMakerChecker(chgId, Uid, "SMTA_CODE", ds.Tables[0].Rows[0]["SMTA_CODE_DESC"].ToString(), ddlSAMAType1.SelectedItem.Text, ds.Tables[0].Rows[0]["SMTA_CODE"].ToString(), ddlSAMAType1.SelectedValue, 1, ref error);//SMTA_CODE
                            if (update == false)
                            {
                                if (Helper.OracleError(error))
                                {
                                    lblError.Text = "An Error Occured!";
                                    ExceptionUtility.LogException(9, "", "84.496", "btnSave_Click", error);
                                }
                                else
                                    lblError.Text = error;
                                return;
                            }
                        }
                        if (ds.Tables[0].Rows[0]["DEBIT_ACCOUNT"].ToString() != txtDebit.Text)
                        {
                            update = UpdateMakerChecker(chgId, Uid, "DEBIT_ACCOUNT", ds.Tables[0].Rows[0]["DEBIT_ACCOUNT"].ToString(), txtDebit.Text, "", "", 1, ref error);//DEBIT_ACCOUNT
                            if (update == false)
                            {
                                if (Helper.OracleError(error))
                                {
                                    lblError.Text = "An Error Occured!";
                                    ExceptionUtility.LogException(9, "", "84.496", "btnSave_Click", error);
                                }
                                else
                                    lblError.Text = error;
                                return;
                            }
                        }
                        if (ds.Tables[0].Rows[0]["CREDIT_ACCOUNT"].ToString() != TxtCredit .Text)
                        {
                            update = UpdateMakerChecker(chgId, Uid, "CREDIT_ACCOUNT", ds.Tables[0].Rows[0]["CREDIT_ACCOUNT"].ToString(), TxtCredit.Text, "", "", 1, ref error);//CREDIT_ACCOUNT
                            if (update == false)
                            {
                                if (Helper.OracleError(error))
                                {
                                    lblError.Text = "An Error Occured!";
                                    ExceptionUtility.LogException(9, "", "84.496", "btnSave_Click", error);
                                }
                                else
                                    lblError.Text = error;
                                return;
                            }
                        }
                        if (ds.Tables[0].Rows[0]["MODIFIED_BY"].ToString() != Session["uid"].ToString())
                        {
                            update = UpdateMakerChecker(chgId, Uid, "MODIFIED_BY", ds.Tables[0].Rows[0]["MODIFIED_BY"].ToString(), Session["uid"].ToString(), "", "", 1, ref error);//MODIFIED_BY
                            if (update == false)
                            {
                                if (Helper.OracleError(error))
                                {
                                    lblError.Text = "An Error Occured!";
                                    ExceptionUtility.LogException(9, "", "84.496", "btnSave_Click", error);
                                }
                                else
                                    lblError.Text = error;
                                return;
                            }
                        }
                        lblError.Text = "Your request has been sent to Checker user for Approval";

                    }
                }
            }
            loadResult() ;
            ViewState["mode"] = null;
            ViewState["rowid"] = null;
            pnlControls.Visible = false;
            pnlResult.Enabled = true;            
            ExceptionUtility.LogException(0, "", "", "btnSave_Click", "");
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "", "", "btnSave_Click", "");
            //Response.Redirect("../ErrorPages/ErrorPage.aspx");
        }
    }
    private bool Can_Insert()
    {
        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_SAMA_Account";

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


            oracom.Parameters["P_sama_type"].Value = int.Parse (ddlSAMAType1 .SelectedValue) ;


            oracom.ExecuteNonQuery();
            oracon.Close();
            string a = oracom.Parameters["p_res_code"].Value.ToString();
            if (a == "0")
            {
                ExceptionUtility.LogException(0, "maker_checker_editor.can_insert_SAMA_Account", "496.1", "Can_Insert", "");
                return true;
            }
            else
            {
                ExceptionUtility.LogException(9, "maker_checker_editor.can_can_insert_SAMA_Accountinsert_ATM", "496.1", "Can_Insert", "");
                return false;
            }
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "maker_checker_editor.can_insert_SAMA_Account", "496.1", "Can_Insert", "");
            //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();
            return nop;
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "maker_checker_editor.get_chg_id", "", "loadChgID", "");
            //Response.Redirect("../ErrorPages/ErrorPage.aspx");
            return 0;
        }
    }
    private bool UpdateMakerChecker(int chgId, string pkey, string columnName, string oldValue, string newValue, string oldValueNo, string NewValueNo, int chgType, ref string error)
    {
        try
        {
            string DBConnection = Helper.dbConnection();

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

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

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

            oracom.Parameters.Add("p_current_uid", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_chg_id", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_chg_type", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_page_id", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_table_name", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_column_name", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_old_value", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_new_value", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_maker_id", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_made_on_date", OracleType.DateTime).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_checker_id", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_checked_on_date", OracleType.DateTime).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_changed_rec_id", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_chg_status", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_checker_notes", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_old_number", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_new_number", OracleType.Number).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_lang", OracleType.VarChar).Direction = ParameterDirection.Input;
            oracom.Parameters.Add("p_res_code", OracleType.Number).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_res_type", OracleType.VarChar, 250).Direction = ParameterDirection.Output;
            oracom.Parameters.Add("p_res_msg", OracleType.VarChar, 250).Direction = ParameterDirection.Output;

            oracom.Parameters["p_current_uid"].Value = Session["uid"].ToString();
            oracom.Parameters["p_page_id"].Value = 84;
            oracom.Parameters["p_table_name"].Value = "SAMA_MONTHLY_TOT_ACCT";
            oracom.Parameters["p_chg_id"].Value = chgId;
            oracom.Parameters["p_chg_type"].Value = chgType;
            oracom.Parameters["p_column_name"].Value = columnName;
            oracom.Parameters["p_new_value"].Value = newValue;
            oracom.Parameters["p_old_value"].Value = oldValue;
            oracom.Parameters["p_maker_id"].Value = Session["uid"].ToString();
            oracom.Parameters["p_made_on_date"].Value = OracleDateTime.Null;
            oracom.Parameters["p_checker_id"].Value = OracleNumber.Null;
            oracom.Parameters["p_checked_on_date"].Value = OracleDateTime.Null;
            oracom.Parameters["p_changed_rec_id"].Value = pkey;
            oracom.Parameters["p_chg_status"].Value = 0;
            oracom.Parameters["p_checker_notes"].Value = OracleString.Null;

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

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

            oracom.ExecuteNonQuery();
            oracon.Close();
            string a = oracom.Parameters["p_res_code"].Value.ToString();
            error = oracom.Parameters["p_res_msg"].Value.ToString();
            if (a == "0")
            {
                ExceptionUtility.LogException(0, "MAKER_CHECKER_EDITOR.Add_Maker_Checker", "", "UpdateMakerChecker", "chgId: " + chgId + ", pkey: " + pkey + ", columnName: " + columnName + ", oldValue: " + oldValue + " , newValue: " + newValue + " , oldValueNo: " + oldValueNo + ", NewValueNo: " + NewValueNo + " ,chgType: " + chgType);
                return true;
            }
            else
            {
                ExceptionUtility.LogException(9, "MAKER_CHECKER_EDITOR.Add_Maker_Checker", "", "UpdateMakerChecker", "chgId: " + chgId + ", pkey: " + pkey + ", columnName: " + columnName + ", oldValue: " + oldValue + " , newValue: " + newValue + " , oldValueNo: " + oldValueNo + ", NewValueNo: " + NewValueNo + " ,chgType: " + chgType);
                return false;
            }
        }
        catch (Exception ex)
        {
            ExceptionUtility.LogException(ex, "MAKER_CHECKER_EDITOR.Add_Maker_Checker", "", "UpdateMakerChecker", "chgId: " + chgId + ", pkey: " + pkey + ", columnName: " + columnName + ", oldValue: " + oldValue + " , newValue: " + newValue + " , oldValueNo: " + oldValueNo + ", NewValueNo: " + NewValueNo + " ,chgType: " + chgType);
            //Response.Redirect("../ErrorPages/ErrorPage.aspx");
            return false;
        }
    }
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
       
       
        if (e.CommandName.Equals("e"))
        {
            intCount = 0;
            pnlControls.Visible = true;
            pnlResult.Enabled = false;
            ExceptionUtility.LogException(0, "", "84.494", "GridView1_RowCommand.Edit", "");
            int index = int.Parse(e.CommandArgument.ToString());
            string rowID = GridView1.DataKeys[index].Value.ToString();
            string debitAccount = GridView1.Rows[index].Cells[2].Text.ToString();
            string creditAccount = GridView1.Rows[index].Cells[3].Text.ToString();

            if (!debitAccount.Equals("&nbsp;"))
                txtDebit.Text = debitAccount;
            if (!creditAccount.Equals("&nbsp;"))
                TxtCredit.Text = creditAccount;
            ddlSAMAType1.SelectedValue = rowID;
            ddlSAMAType1.Enabled = false;

          

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

          
        }
       
        else if (e.CommandName.Equals("vm"))
        {
            ExceptionUtility.LogException(0, "", "84.494", "GridView1_RowCommand.ViewModification", "");
            pnlControls.Visible = false;
            int index = int.Parse(e.CommandArgument.ToString());
            string rowID = GridView1.DataKeys[index].Value.ToString();
            int chgId = loadMaxChgID(rowID);
            Response.Redirect("Checker.aspx?chgId=" + chgId);

        }

        loadResult ();
    }
    private int loadMaxChgID(string atm_number)
    {
        try
        {
            string DBConnection = Helper.dbConnection();

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

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

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

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

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

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

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



    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.Header || e.Row.RowType == DataControlRowType.DataRow)
        {

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

            if (app_status == 0)
            {
                e.Row.Cells[9].Visible = true;
                e.Row.Cells[10].Visible = false;
               
            }
            else
            {
                e.Row.Cells[9].Visible = false;
                e.Row.Cells[10].Visible = true;
               
            }
            
        }
    }
    protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.Header || e.Row.RowType == DataControlRowType.DataRow)
        {
            
            e.Row.Cells[7].Visible = false;
          
        }
    }
}