Exemple #1
0
 protected void txtLeaveName_OnTextChanged(object sender, EventArgs e)
 {
     if (editid.Value == "")
     {
         DataTable dt = objLeave.GetLeaveMasterByLeaveName(Session["CompId"].ToString().ToString(), txtLeaveName.Text.Trim());
         if (dt.Rows.Count > 0)
         {
             txtLeaveName.Text = "";
             DisplayMessage("Leave Type Name Already Exists");
             System.Web.UI.ScriptManager.GetCurrent(this).SetFocus(txtLeaveName);
             return;
         }
         DataTable dt1 = objLeave.GetLeaveMasterInactive(Session["CompId"].ToString().ToString());
         dt1 = new DataView(dt1, "Leave_Name='" + txtLeaveName.Text + "'", "", DataViewRowState.CurrentRows).ToTable();
         if (dt1.Rows.Count > 0)
         {
             txtLeaveName.Text = "";
             DisplayMessage("Leave Type Name Already Exists - Go to Bin Tab");
             System.Web.UI.ScriptManager.GetCurrent(this).SetFocus(txtLeaveName);
             return;
         }
         txtLeaveNameL.Focus();
     }
     else
     {
         DataTable dtTemp = objLeave.GetLeaveMasterById(Session["CompId"].ToString().ToString(), editid.Value);
         if (dtTemp.Rows.Count > 0)
         {
             if (dtTemp.Rows[0]["Leave_Name"].ToString() != txtLeaveName.Text)
             {
                 DataTable dt = objLeave.GetLeaveMaster(Session["CompId"].ToString().ToString());
                 dt = new DataView(dt, "Leave_Name='" + txtLeaveName.Text + "'", "", DataViewRowState.CurrentRows).ToTable();
                 if (dt.Rows.Count > 0)
                 {
                     txtLeaveName.Text = "";
                     DisplayMessage("Leave Type Name Already Exists");
                     System.Web.UI.ScriptManager.GetCurrent(this).SetFocus(txtLeaveName);
                     return;
                 }
                 DataTable dt1 = objLeave.GetLeaveMaster(Session["CompId"].ToString().ToString());
                 dt1 = new DataView(dt1, "Leave_Name='" + txtLeaveName.Text + "'", "", DataViewRowState.CurrentRows).ToTable();
                 if (dt1.Rows.Count > 0)
                 {
                     txtLeaveName.Text = "";
                     DisplayMessage("Leave Type Name Already Exists - Go to Bin Tab");
                     System.Web.UI.ScriptManager.GetCurrent(this).SetFocus(txtLeaveName);
                     return;
                 }
             }
         }
         txtLeaveNameL.Focus();
     }
 }
    protected void rbtnMonthlyYearly(object sender, EventArgs e)
    {
        if (txtFromDate.Text == "")
        {
            DisplayMessage("Enter From Date");
            rbtnMonthly.Checked = false;
            rbtnYearly.Checked  = false;
            txtFromDate.Focus();
            return;
        }
        else
        {
            try
            {
                Convert.ToDateTime(txtFromDate.Text);
            }
            catch
            {
                DisplayMessage("Enter Correct From Date Format dd-MMM-yyyy");
                txtFromDate.Focus();
                rbtnMonthly.Checked = false;
                rbtnYearly.Checked  = false;
                return;
            }
        }

        if (txtToDate.Text == "")
        {
            DisplayMessage("Enter To Date");
            txtToDate.Focus();
            rbtnMonthly.Checked = false;
            rbtnYearly.Checked  = false;
            return;
        }
        else
        {
            try
            {
                Convert.ToDateTime(txtToDate.Text);
            }
            catch
            {
                DisplayMessage("Enter Correct To Date Format dd-MMM-yyyy");
                txtToDate.Focus();
                rbtnMonthly.Checked = false;
                rbtnYearly.Checked  = false;
                return;
            }
        }
        if (Convert.ToDateTime(txtFromDate.Text) > Convert.ToDateTime(txtToDate.Text))
        {
            DisplayMessage("From Date cannot be greater than To Date");
            txtFromDate.Text = "";
            txtToDate.Text   = "";
            txtFromDate.Focus();
            rbtnMonthly.Checked = false;
            rbtnYearly.Checked  = false;
            return;
        }



        if (rbtnMonthly.Checked)
        {
            DataTable dtLeaveSummary = objEmpleave.GetEmployeeLeaveTransactionDataByEmpId(hdnEmpId.Value);

            string   months   = string.Empty;
            string   year     = string.Empty;
            DateTime FromDate = Convert.ToDateTime(txtFromDate.Text);
            DateTime ToDate   = Convert.ToDateTime(txtToDate.Text);
            while (FromDate <= ToDate)
            {
                months  += FromDate.Month.ToString() + ",";
                FromDate = FromDate.AddMonths(1);
                string year1 = FromDate.Year.ToString();
                if (!year.Split(',').Contains(year1))
                {
                    year += year1 + ",";
                }
            }


            string   months4   = string.Empty;
            string   year4     = string.Empty;
            DateTime FromDate1 = DateTime.Now;
            DateTime ToDate1   = DateTime.Now.AddMonths(2);
            while (FromDate <= ToDate)
            {
                months4 += FromDate1.Month.ToString() + ",";
                FromDate = FromDate1.AddMonths(1);
                string year5 = FromDate1.Year.ToString();
                if (!year4.Split(',').Contains(year5))
                {
                    year4 += year5 + ",";
                }
            }

            DataTable dt = objAppParam.GetApplicationParameterByParamName("FinancialYearStartMonth", Session["CompId"].ToString());
            int       FinancialYearMonth = 0;

            if (dt.Rows.Count > 0)
            {
                FinancialYearMonth = int.Parse(dt.Rows[0]["Param_Value"].ToString());
            }

            DateTime FinancialYearStartDate = new DateTime();
            DateTime FinancialYearEndDate   = new DateTime();
            if (DateTime.Now.Month < FinancialYearMonth)
            {
                FinancialYearStartDate = new DateTime(DateTime.Now.Year - 1, FinancialYearMonth, 1);

                FinancialYearEndDate = FinancialYearStartDate.AddYears(1).AddDays(-1);
            }
            else
            {
                FinancialYearStartDate = new DateTime(DateTime.Now.Year, FinancialYearMonth, 1);
                FinancialYearEndDate   = FinancialYearStartDate.AddYears(1).AddDays(-1);
            }
            year = string.Empty;

            if (FinancialYearStartDate.Year == FinancialYearEndDate.Year)
            {
                year4 = FinancialYearStartDate.Year.ToString();
            }
            else
            {
                year4 += FinancialYearStartDate.Year.ToString() + ",";

                year4 += FinancialYearEndDate.Year.ToString() + ",";
            }

            DateTime DateFrm = Convert.ToDateTime(txtFromDate.Text);

            if (!months4.Split(',').Contains(DateFrm.Month.ToString()) && !year4.Split(',').Contains(DateFrm.Year.ToString()))
            {
                DisplayMessage("You cannot request leave for this month");
                txtFromDate.Text = "";
                txtToDate.Text   = "";
                txtFromDate.Focus();
                rbtnMonthly.Checked = false;
                rbtnYearly.Checked  = false;
                lblDays.Text        = "";
                return;
            }



            dtLeaveSummary = new DataView(dtLeaveSummary, "month in(" + months + ") and year in (" + year4 + ") ", "", DataViewRowState.CurrentRows).ToTable();
            dtLeaveSummary = dtLeaveSummary.DefaultView.ToTable(true, "Leave_Type_Id");
            DataTable dtleave = new DataTable();
            for (int i = 0; i < dtLeaveSummary.Rows.Count; i++)
            {
                dtleave = objleave.GetLeaveMasterById(Session["CompId"].ToString(), dtLeaveSummary.Rows[i]["Leave_Type_Id"].ToString());
            }
            if (dtleave.Rows.Count > 0)
            {
                ddlLeaveType.DataSource     = dtleave;
                ddlLeaveType.DataTextField  = "Leave_Name";
                ddlLeaveType.DataValueField = "Leave_Id";

                ddlLeaveType.DataBind();
                ddlLeaveType.Visible = true;
            }
            else
            {
                ddlLeaveType.Items.Clear();
                ddlLeaveType.DataSource = null;
                ddlLeaveType.DataBind();
                ddlLeaveType.Visible = false;
            }
        }
        else if (rbtnYearly.Checked)
        {
            DataTable dtLeaveSummary = objEmpleave.GetEmployeeLeaveTransactionDataByEmpId(hdnEmpId.Value);

            string   months   = string.Empty;
            string   year     = string.Empty;
            DateTime FromDate = DateTime.Now;


            string year4 = string.Empty;


            DataTable dt = objAppParam.GetApplicationParameterByParamName("FinancialYearStartMonth", Session["CompId"].ToString());
            int       FinancialYearMonth = 0;

            if (dt.Rows.Count > 0)
            {
                FinancialYearMonth = int.Parse(dt.Rows[0]["Param_Value"].ToString());
            }

            DateTime FinancialYearStartDate = new DateTime();
            DateTime FinancialYearEndDate   = new DateTime();
            if (DateTime.Now.Month < FinancialYearMonth)
            {
                FinancialYearStartDate = new DateTime(DateTime.Now.Year - 1, FinancialYearMonth, 1);

                FinancialYearEndDate = FinancialYearStartDate.AddYears(1).AddDays(-1);
            }
            else
            {
                FinancialYearStartDate = new DateTime(DateTime.Now.Year, FinancialYearMonth, 1);
                FinancialYearEndDate   = FinancialYearStartDate.AddYears(1).AddDays(-1);
            }
            year = string.Empty;

            if (FinancialYearStartDate.Year == FinancialYearEndDate.Year)
            {
                year4 = FinancialYearStartDate.Year.ToString();
            }
            else
            {
                year4 += FinancialYearStartDate.Year.ToString() + ",";
            }

            dtLeaveSummary = new DataView(dtLeaveSummary, "month='0'and year in (" + year4.ToString() + ") ", "", DataViewRowState.CurrentRows).ToTable();

            if (dtLeaveSummary.Rows.Count > 0)
            {
                ddlLeaveType.DataSource = dtLeaveSummary;

                ddlLeaveType.DataTextField  = "Leave_Name";
                ddlLeaveType.DataValueField = "Leave_Type_Id";


                ddlLeaveType.DataBind();
                ddlLeaveType.Visible = true;
            }
            else
            {
                ddlLeaveType.Items.Clear();
                ddlLeaveType.DataSource = null;
                ddlLeaveType.DataBind();
                ddlLeaveType.Visible = false;
            }
        }
        else if (rbtnMonthly.Checked == false && rbtnYearly.Checked == false)
        {
            ddlLeaveType.Items.Clear();
            ddlLeaveType.DataSource = null;
            ddlLeaveType.DataBind();
            ddlLeaveType.Visible = false;
        }
    }