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;

public partial class Business_GENERATE_GATEWAY : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            btnGenReport.Enabled = true;
            btnPostAll.Enabled = false;
        }
    }
    protected void btnGenReport_Click(object sender, EventArgs e)
    {
        btnPostAll.Enabled = true;
        string p1 = DateTime.Now.ToString("yyMMdd");
        string p2 = "0";
        string UrlString1 = "rpt=515&p1=" + p1 + "&p2=" + p2;
        ScriptManager.RegisterClientScriptBlock(this, typeof(string), "new window",
                "window.open('../Reports/Default.aspx?" + UrlString1 + "','Report')", true);
    }
    protected void btnPostAll_Click(object sender, EventArgs e)
    {
        string error = "";
        bool saved = PostAll(ref error);
        if (saved)
        {
            lblError.Text = "Post Successful";
        }
        else
        {
            lblError.Text = error;
        }
    }
    private bool PostAll(ref string error)
    {
        string DBConnection = Helper.dbConnection();
        OracleConnection oracon = new OracleConnection(DBConnection);
        oracon.Open();

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

        oracom.CommandType = CommandType.StoredProcedure;
        oracom.CommandText = "GENERATE_GL_FILE.GW56_pos_files";
        oracom.Parameters.Add("p_file_dir", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_current_uid", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_pos_settl_cnt", OracleType.Number).Direction = ParameterDirection.Output;
        oracom.Parameters.Add("p_pos_settl_amt", OracleType.Number).Direction = ParameterDirection.Output;                
        oracom.Parameters.Add("p_file_name", OracleType.VarChar, 250).Direction = ParameterDirection.Output;
        oracom.Parameters.Add("v_res", OracleType.VarChar, 250).Direction = ParameterDirection.Output;

        oracom.Parameters["p_current_uid"].Value = Session["uid"].ToString();
        oracom.Parameters["p_file_dir"].Value = "OUTPUT";
        oracom.ExecuteNonQuery();
        oracon.Close();
        string a = oracom.Parameters["v_res"].Value.ToString();
        //error = oracom.Parameters["p_res_msg"].Value.ToString();
        if (a == "Successful")
        {
            lblFileName.Text = oracom.Parameters["p_file_name"].Value.ToString();
            lblPOSSettlementAmount.Text = oracom.Parameters["p_pos_settl_amt"].Value.ToString();
            lblPOSSettlementCount.Text = oracom.Parameters["p_pos_settl_cnt"].Value.ToString();            
            return true;
        }
        else
        {
            return false;
        }


    }
}