using System;
using System.Collections.Generic;
using System.Linq;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.Services;
using System.Web.UI.WebControls.WebParts;
using System.Data.OracleClient;
using System.Xml;
using System.Diagnostics;
using MscllnsFundXferMsgGenerator;
using EjadaMQProcessor;



public partial class Business_T24Setttl : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["uid"] == null)
            Response.Redirect("../Security/LoginPage.aspx");


        string[] temp;
        string response = "", message = "";
        temp = Request.Url.ToString().Split('/');

        string path = temp[temp.Length - 2] + "/" + temp[temp.Length - 1];
        if (path.Contains("?"))
        {
            path = path.Substring(0, path.IndexOf('?'));
        }
        string userID = Session["uid"].ToString();
        DataSet ds = new DataSet();
        ds = SecurityAgent.authenticateUserPage(userID, path, ref response, ref message);

        if (!response.Equals("0"))
        {
            Response.Redirect("../Business/default.aspx?err=1");
        }



        if (!IsPostBack)
        {
            loadEvents(); // This page function

            Label2.Text = DateTime.Now.Date.ToString("dd-MM-yyyy");
            Label3.Text = DateTime.Now.TimeOfDay.ToString().Split('.')[0];
            Label1.Text = Session["username"].ToString();
        }
      
    }

    private void loadEvents()
    {
        string DBConnection = Helper.dbConnection();

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

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

        oracom.CommandType = CommandType.StoredProcedure;
        oracom.CommandText = "LOOKUP_GETTER.Get_Recon_Events";

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

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

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

        //ddlEvents.Items.Insert(0, "------ All Events ------");
        ddlEvents.Items.Insert(0, new ListItem("------ All Events ------", ""));
        oracon.Close();
    }


    [WebMethod(EnableSession = true)]
    public static object ListDataAll(string Settle_Date, string DEBIT_ACCOUNT, string CREDIT_ACCOUNT, string RE_CODE, int jtStartIndex, int jtPageSize, string jtSorting)
    {

        try
        {
            int FilterListCount = 0;
            if (Settle_Date.Length < 10)
                return new { Result = "ERROR", Message = "Please, Enter Valid Date" };
            else
                Settle_Date = Settle_Date.Substring(6, 4) + Settle_Date.Substring(0, 2) + Settle_Date.Substring(3, 2);

            var DataList = T24SettlementCls.load_T24_Settlement_Enties(Settle_Date, DEBIT_ACCOUNT, CREDIT_ACCOUNT, RE_CODE, jtStartIndex, jtPageSize, jtSorting, out FilterListCount);

            if (FilterListCount == 0)
                System.Threading.Thread.Sleep(1000);

            return new { Result = "OK", Records = DataList, TotalRecordCount = FilterListCount };
        }
        catch (Exception ex)
        {
            return new { Result = "ERROR", Message = ex.Message };
        }
    }

    protected void btnSearch_Click(object sender, EventArgs e)
    {
        Response.Redirect("../Business/default.aspx");
    }
}