using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
/****************************************************************************************************************************
* Project Name    : TimeCheck                    Started Date  : 18-July-2007
* Module          : Leave Application            Last Modified : 29-Aug-2007
* Programmer      : Prabakaran.P
* Current Storage : \\Angler56\Projects\Inprogress\SCREEN1206\code\Time_AttendanceApp
* BackUp          :
****************************************************************************************************************************/
public partial class Transactions_AjaxRemainingNoOfHolidays : Base.BasePage
{
    //Cls_Connect cl = new Cls_Connect();
    DataSet dsRemainingNoOfHolidays= new DataSet();
    LeaveApplicationEventData objLeaveApplicationEventData = new LeaveApplicationEventData();
    DataSet dsMaximumHolidays = new DataSet();
    string FromDate, ToDate;
    int intYearSettingsId = 0;
    protected override void Page_Load(object sender, EventArgs e)
    {
        // session checking and reset date format
        base.Page_Load(sender, e);    
        //Session.LCID = 1033;
        if (!IsPostBack)
        {
            if (Request.QueryString["EmpId"].ToString() == "" || Request.QueryString["leaveTypeId"].ToString() == "")
            {
                Response.Write("Fail");
            }
            else
            {
                int EmpId = Convert.ToInt32(Request.QueryString["EmpId"]);
                int leaveTypeId = Convert.ToInt32(Request.QueryString["leaveTypeId"]);
                if (Request.QueryString["ApplicationYear"] != string.Empty && Request.QueryString["ApplicationYear"] != null)
                {
                    intYearSettingsId = Convert.ToInt32(Request.QueryString["ApplicationYear"].ToString());
                }
                try
                {
                    //SqlParameter pEmpId = new SqlParameter("@Employee_Id", EmpId);
                    //SqlParameter pleaveTypeId = new SqlParameter("@LeaveType_Id", leaveTypeId);
                    // SqlParameter[] pParams ={ pEmpId, pleaveTypeId };
                    //To check the Required period completed per leave type
                    //dsMaximumHolidays = cl.StoredProcedure_NoParams_DS("Proc_TA_SelectMaximumNoOfHolidays");
                    dsMaximumHolidays = objLeaveApplicationEventData.GetMaximumNoOfHolidays(intYearSettingsId);
                    dsMaximumHolidays.Tables[0].TableName = "Details";
                    if (dsMaximumHolidays.Tables[0].Rows[0]["RetrictedHolidays"].ToString() != null)
                    {
                        //SqlParameter pEmpIdRemain = new SqlParameter("@Employee_Id", EmpId);
                        //SqlParameter pleaveTypeIdRemain = new SqlParameter("@LeaveType_Id", leaveTypeId);
                        //SqlParameter[] pParamsRemain ={ pEmpIdRemain, pleaveTypeIdRemain };
                        decimal TotalNumberOfHolidays;
                        decimal HolidaysTaken = 0;
                        //dsRemainingNoOfHolidays = cl.fillDs_SP("Proc_TA_GetNumberOfHolidaysTaken", pParamsRemain);
                        dsRemainingNoOfHolidays = objLeaveApplicationEventData.GetNumberOfHolidaysTaken(EmpId, leaveTypeId, intYearSettingsId);
                        if (dsRemainingNoOfHolidays.Tables[0].Rows.Count > 0)
                        {
                            foreach (DataRow dRow in dsRemainingNoOfHolidays.Tables[0].Rows)
                            {
                                HolidaysTaken = HolidaysTaken + Convert.ToDecimal(dRow["HolidaysTaken"]);
                                if (Convert.ToInt32(dRow["holiday_Id"]) == leaveTypeId)
                                {
                                    FromDate = dRow["Holiday_FromDate"].ToString();
                                    ToDate = dRow["Holiday_ToDate"].ToString();
                                }
                            }
                            TotalNumberOfHolidays = Convert.ToInt32(dsMaximumHolidays.Tables[0].Rows[0]["RetrictedHolidays"]) - HolidaysTaken;
                            Response.Clear();
                            Response.ContentType = "text/xml";
                            Response.Write(Convert.ToString(TotalNumberOfHolidays) + "," + DateTime.Parse(FromDate).ToString(Session["MDateFormat"].ToString()) + "," + DateTime.Parse(ToDate).ToString(Session["MDateFormat"].ToString()));
                        }
                        else
                        {
                            Response.Clear();
                            Response.ContentType = "text/xml";
                            Response.Write("Fail");
                        }
                    }
                    else
                    {
                        if (dsMaximumHolidays.Tables["Details"].Rows.Count > 0)
                        {
                            Response.Clear();
                            Response.ContentType = "text/xml";
                            Response.Write(dsMaximumHolidays.GetXml());
                            dsMaximumHolidays.Dispose();
                        }
                        else
                        {
                            Response.Clear();
                            Response.ContentType = "text/xml";
                            Response.Write("Fail");
                        }
                    }
                }
                catch (Exception ex)
                {
                    Response.Write(ex.Message);
                }
            }
            Response.End();
        }
    }
}
