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_AjaxRemainingNoOfLeaves : Base.BasePage
{
    LeaveApplicationEventData objLeaveApplicationEventData = new LeaveApplicationEventData();
    //Cls_Connect cl = new Cls_Connect();
    DataSet dsRemainingNoOfleaves = new DataSet();
    DataSet dsRequiredPeriod = new DataSet();
    cls_Common objclsCommon = new cls_Common();
    int intYearSettingsId = 0;
    protected override void Page_Load(object sender, EventArgs e)
    {
        // session checking and reset date format
        base.Page_Load(sender, e);
        if (Request.QueryString["EmpId"].ToString() == "" || Request.QueryString["leaveTypeId"].ToString() == "" || Request.QueryString["leaveTypeId"].ToString() == "-Select-")
        {
            Response.Write("Fail");
        }
        else
        {
            int EmpId = Convert.ToInt32(Request.QueryString["EmpId"]);
            int leaveTypeId = Convert.ToInt32(Request.QueryString["leaveTypeId"]);
            string LeaveFromDate = Request.QueryString["LeaveFromDate"].ToString();
            string LeaveToDate = Request.QueryString["LeaveToDate"].ToString();
            LeaveFromDate = objclsCommon.DateConvertion(Session["MDateFormat"].ToString(), LeaveFromDate);
            LeaveToDate = objclsCommon.DateConvertion(Session["MDateFormat"].ToString(), LeaveToDate);
            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
                //dsRequiredPeriod = cl.fillDs_SP("Proc_TA_GetEmployeeRequiredPeriod ", pParams);
                dsRequiredPeriod = objLeaveApplicationEventData.GetEmployeeRequiredPeriod(EmpId, leaveTypeId, Convert.ToDateTime(LeaveFromDate).ToShortDateString().ToString(), Convert.ToDateTime(LeaveToDate).ToShortDateString().ToString());
                if (dsRequiredPeriod.Tables.Count > 0)
                {
                    dsRequiredPeriod.Tables[0].TableName = "Details";
                    if (dsRequiredPeriod.Tables[0].Rows[0]["RemainingNoOfLeaves"].ToString() == "N" || dsRequiredPeriod.Tables[0].Rows[0]["RemainingNoOfLeaves"].ToString() == "Y")
                    {
                        //SqlParameter pEmpIdRemain = new SqlParameter("@Employee_Id", EmpId);
                        //SqlParameter pleaveTypeIdRemain = new SqlParameter("@LeaveType_Id", leaveTypeId);
                        //SqlParameter[] pParamsRemain ={ pEmpIdRemain, pleaveTypeIdRemain };
                        //dsRemainingNoOfleaves = cl.fillDs_SP("Proc_TA_GetRemainingNumberOfLeaves", pParamsRemain);
                        if (Request.QueryString["ApplicationYear"] != string.Empty && Request.QueryString["ApplicationYear"] != null)
                        {
                            intYearSettingsId = Convert.ToInt32(Request.QueryString["ApplicationYear"].ToString());
                        }
                        dsRemainingNoOfleaves = objLeaveApplicationEventData.GetRemainingNumberOfLeavesForLeaveApplication(EmpId, leaveTypeId, intYearSettingsId);
                        if (dsRemainingNoOfleaves.Tables.Count > 0)
                        {
                            if (dsRemainingNoOfleaves.Tables[0].Rows.Count > 0)
                            {
                                dsRemainingNoOfleaves.Tables[0].TableName = "Details";
                                if (dsRemainingNoOfleaves.Tables["Details"].Rows.Count > 0)
                                {
                                    if (dsRemainingNoOfleaves.Tables["Details"].Rows[0]["RemainingNoOfLeaves"].ToString() == "0.00" || dsRemainingNoOfleaves.Tables["Details"].Rows[0]["RemainingNoOfLeaves"].ToString() == "0.0")
                                    {
                                        //Check Policy for Borrow enabled or not
                                        DataSet dsBorrow = new DataSet();
                                        dsBorrow = objLeaveApplicationEventData.CheckBorrowExists(EmpId, leaveTypeId);
                                        if (dsBorrow.Tables[0].Rows[0]["Borrow"].ToString() == "True")
                                        {
                                            Response.Clear();
                                            Response.ContentType = "text/xml";
                                            Response.Write("BorrowExist");
                                            dsBorrow.Dispose();
                                        }
                                        else
                                        {
                                            Response.Clear();
                                            Response.ContentType = "text/xml";
                                            Response.Write("BorrowNotExist");
                                            dsBorrow.Dispose();
                                        }
                                    }
                                    else
                                    {
                                        Response.Clear();
                                        Response.ContentType = "text/xml";
                                        Response.Write(dsRemainingNoOfleaves.GetXml());
                                        dsRemainingNoOfleaves.Dispose();
                                    }
                                }
                            }
                        }
                        else
                        {
                            Response.Clear();
                            Response.ContentType = "text/xml";
                            Response.Write("Fail");
                        }
                    }
                    else
                    {
                        if (dsRequiredPeriod.Tables["Details"].Rows.Count > 0)
                        {
                            Response.Clear();
                            Response.ContentType = "text/xml";
                            Response.Write(dsRequiredPeriod.GetXml());
                            dsRequiredPeriod.Dispose();
                        }
                        else
                        {
                            Response.Clear();
                            Response.ContentType = "text/xml";
                            Response.Write("Fail");
                        }
                    }
                }
                else
                {
                    Response.Clear();
                    Response.ContentType = "text/xml";
                    Response.Write("Fail");
                }
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }
        }
        Response.End();
    }
}
