// ////////////////////////////////////////////////////////////////////////
        // AUXILIAR EVENTS
        //
        protected void ddlWorkingLocation_SelectedIndexChanged(object sender, EventArgs e)
        {
            VacationsInformationGateway vacationsInformationGateway = new VacationsInformationGateway(vacationsInformationTDS);

            if (hdfIsVacationManager.Value == "False")
            {
                vacationsInformationGateway.LoadByEmployeeIdEmployeeType(Int32.Parse(ViewState["employee_id"].ToString()), ddlWorkingLocation.SelectedValue, Int32.Parse(hdfCompanyId.Value));
            }
            else
            {
                DropDownList ddlVacationsFor = (DropDownList)tkrpbLeftMenuAllVacations.FindItemByValue("nbVacationsForDDL").FindControl("ddlVacationsFor");

                if (ddlVacationsFor.SelectedIndex > 0)
                {
                    vacationsInformationGateway.LoadByEmployeeIdEmployeeType(Int32.Parse(ddlVacationsFor.SelectedValue), ddlWorkingLocation.SelectedValue, Int32.Parse(hdfCompanyId.Value));
                }
                else
                {
                    vacationsInformationGateway.LoadByEmployeeType(ddlWorkingLocation.SelectedValue, Int32.Parse(hdfCompanyId.Value));
                }
            }

            Session["vacationsInformationTDS"] = vacationsInformationTDS;
            Session["vacationsInformation"] = vacationsInformationTDS.VacationsInformation;

            tkrsVacations.DataBind();
        }
        protected void tkrsVacations_AppointmentInsert(object sender, SchedulerCancelEventArgs e)
        {
            Page.Validate();

            if (Page.IsValid)
            {
                string filterExpression = string.Format("Deleted = 0 AND StartDate = '{0}'", e.Appointment.Start);
                 DataRow[] drarray = vacationsInformationTDS.DaysInformation.Select(filterExpression, "StartDate ASC", DataViewRowState.CurrentRows);
                 bool isValidVacation = true;

                 switch (e.Appointment.Subject)
                 {
                     case "Half Vacation Day":
                         if (drarray.Length > 0)
                         {
                             if ((drarray[0]["PaymentType"].ToString() != "Half Vacation Day") && (drarray[0]["PaymentType"].ToString() != "Unpaid Leave Half Day"))
                             {
                                 isValidVacation = false;
                             }
                             else
                             {
                                 if (drarray.Length > 1)
                                 {
                                     isValidVacation = false;
                                 }
                             }
                         }
                         break;

                     case "Full Vacation Day":
                         if (drarray.Length > 0)
                         {
                             isValidVacation = false;
                         }
                         break;

                     case "Unpaid Leave Full Day":
                         if (drarray.Length > 0)
                         {
                             isValidVacation = false;
                         }
                         break;

                     case "Unpaid Leave Half Day":
                         if (drarray.Length > 0)
                         {
                             if ((drarray[0]["PaymentType"].ToString() != "Unpaid Leave Half Day") && (drarray[0]["PaymentType"].ToString() != "Half Vacation Day"))
                             {
                                 isValidVacation = false;
                             }
                             else
                             {
                                 if (drarray.Length > 1)
                                 {
                                     isValidVacation = false;
                                 }
                             }
                         }
                         break;
                 }

                 // Verify non working days
                 if (isValidVacation)
                 {
                     isValidVacation = LiquiForce.LFSLive.BL.LabourHours.ProjectTime.ProjectTime.ValidateIfNonWorkingDay(e.Appointment.Start, Int32.Parse(hdfEmployeeId.Value), Int32.Parse(hdfCompanyId.Value));

                     if (!isValidVacation)
                     {
                         e.Cancel = true;
                         ScriptManager.RegisterStartupScript(Page, GetType(), "alert", "alert('You can not take vacations on this day, this is a non working day. Please verify your data.');", true);
                     }
                     else
                     {
                         // Verify existent vacations
                         isValidVacation = LiquiForce.LFSLive.BL.LabourHours.ProjectTime.ProjectTime.ValidateIfExistsAVacation(e.Appointment.Start, Int32.Parse(hdfEmployeeId.Value), Int32.Parse(hdfCompanyId.Value));

                         if (!isValidVacation)
                         {
                             e.Cancel = true;
                             ScriptManager.RegisterStartupScript(Page, GetType(), "alert", "alert('You have a vacation planned for this day. Please verify your data.');", true);
                         }
                         else
                         {
                             VacationsInformationGateway vacationsInformationGateway = new VacationsInformationGateway();
                             int amountHalfDays = vacationsInformationGateway.IsHalfVacationDay(e.Appointment.Start, Int32.Parse(hdfEmployeeId.Value), Int32.Parse(hdfCompanyId.Value));

                             if (amountHalfDays > 0)
                             {
                                 if ((e.Appointment.Subject == "Unpaid Leave Full Day") || (e.Appointment.Subject == "Full Vacation Day"))
                                 {
                                     isValidVacation = false;
                                     e.Cancel = true;
                                     ScriptManager.RegisterStartupScript(Page, GetType(), "alert", "alert('You have a half vacation day planned for this day. Please verify your data.');", true);
                                 }
                             }
                         }
                     }
                 }
                 else
                 {
                     e.Cancel = true;
                     ScriptManager.RegisterStartupScript(Page, GetType(), "alert", "alert('You already have a vacation request for this day please verify your data.');", true);
                 }

                 if (isValidVacation)
                 {
                     double takenDay = 0;
                     switch (e.Appointment.Subject)
                     {
                         case "Half Vacation Day":
                             takenDay = 0.5;
                             break;

                         case "Full Vacation Day":
                             takenDay = 1;
                             break;
                     }

                     VacationsInformationDaysInformation vacationsInformationDaysInformation = new VacationsInformationDaysInformation(vacationsInformationTDS);
                     vacationsInformationDaysInformation.Insert(Int32.Parse(hdfRequestId.Value), e.Appointment.Start, e.Appointment.Start, e.Appointment.Subject, e.Appointment.Subject, false, Int32.Parse(hdfCompanyId.Value));

                     // Store dataset
                     Session["vacationsInformationTDS"] = vacationsInformationTDS;
                     Session["vacationDaysInformation"] = vacationsInformationTDS.DaysInformation;

                     tkrsVacations.DataBind();

                     double newRemainingVacationDays = double.Parse(tbxRemaining.Text) - takenDay;
                     tbxRemaining.Text = newRemainingVacationDays.ToString();

                     if (double.Parse(tbxRemaining.Text) < 0)
                     {
                         ScriptManager.RegisterStartupScript(Page, GetType(), "alert", "alert('You are requesting more vacation than the entitlement. If you continue this days will be discounted from next years total.');", true);
                     }
                 }
            }
            else
            {
                e.Cancel = true;
            }
        }
 // ////////////////////////////////////////////////////////////////////////
 // PUBLIC METHODS
 //
 /// <summary>
 /// LoadByEmployeeType
 /// </summary>
 /// <param name="employeeType">employeeType</param>              
 /// <param name="companyId">companyId</param>
 public void LoadByEmployeeType(string employeeType, int companyId)
 {
     VacationsInformationGateway vacationsInformationGateway = new VacationsInformationGateway(Data);
     vacationsInformationGateway.LoadByEmployeeType(employeeType, companyId);
 }
        // ////////////////////////////////////////////////////////////////////////
        // EVENTS
        //
        protected void Page_Load(object sender, EventArgs e)
        {
            // Register client scripts
            this.RegisterClientScripts();

            if (!IsPostBack)
            {
                // Security check
                if (!(Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_VACATIONS_VIEW"])))
                {
                    Response.Redirect("./../../error_page.aspx?error=" + "You are not authorized to view this page. Contact your system administrator.");
                }

                // Validate query string
                if (((string)Request.QueryString["source_page"] == null))
                {
                    Response.Redirect("./../../error_page.aspx?error=" + "Invalid query string in vacations_all.aspx");
                }

                // Tag page
                int companyId = Int32.Parse(Session["companyID"].ToString());
                hdfCompanyId.Value = companyId.ToString();

                // ... For non vacation managers
                EmployeeGateway employeeGatewayManager = new EmployeeGateway();

                int employeeIdNow = employeeGatewayManager.GetEmployeIdByLoginId(Convert.ToInt32(Session["loginID"]));

                employeeGatewayManager.LoadByEmployeeId(employeeIdNow);

                if (employeeGatewayManager.GetIsVacationsManager(employeeIdNow))
                {
                    hdfIsVacationManager.Value = "True";
                }
                else
                {
                    hdfIsVacationManager.Value = "False";
                }

                // Initialize values
                DropDownList ddlVacationsFor = (DropDownList)tkrpbLeftMenuAllVacations.FindItemByValue("nbVacationsForDDL").FindControl("ddlVacationsFor");
                EmployeeList employeeList = new EmployeeList();

                string employeeTypeNow = employeeGatewayManager.GetType(employeeIdNow);

                if (employeeTypeNow.Contains("CA"))
                {
                    employeeList.LoadBySalariedEmployeeTypeAndAddItem(1, "CA", -1, "(All)");
                }
                else
                {
                    employeeList.LoadBySalariedEmployeeTypeAndAddItem(1, "US", -1, "(All)");
                }
                ddlVacationsFor.DataSource = employeeList.Table;
                ddlVacationsFor.DataValueField = "EmployeeID";
                ddlVacationsFor.DataTextField = "FullName";
                ddlVacationsFor.DataBind();

                //... date_to_show
                if ((string)Request.QueryString["date_to_show"] == null)
                {
                    ViewState["date_to_show"] = DateTime.Now.ToString();
                }
                else
                {
                    ViewState["date_to_show"] = (string)Request.QueryString["date_to_show"];
                }

                // Load vacations
                vacationsInformationTDS = new VacationsInformationTDS();
                vacationsInformation = new VacationsInformationTDS.VacationsInformationDataTable();

                VacationsInformationGateway vacationsInformationGateway = new VacationsInformationGateway(vacationsInformationTDS);

                if (hdfIsVacationManager.Value == "False")
                {
                    EmployeeGateway employeeGateway1 = new EmployeeGateway();
                    ViewState["employee_id"] = employeeGateway1.GetEmployeIdByLoginId(Convert.ToInt32(Session["loginID"]));

                    EmployeeInformationBasicInformationGateway employeeInformationBasicInformationGateway = new EmployeeInformationBasicInformationGateway();
                    employeeInformationBasicInformationGateway.LoadByEmployeeId(Int32.Parse(ViewState["employee_id"].ToString()));

                    string employeeType = employeeInformationBasicInformationGateway.GetType(Int32.Parse(ViewState["employee_id"].ToString()));

                    if (employeeType.Contains("CA"))
                    {
                        ddlWorkingLocation.SelectedValue = "CA";

                    }
                    else
                    {
                        ddlWorkingLocation.SelectedValue = "US";
                    }

                    vacationsInformationGateway.LoadByEmployeeIdEmployeeType(Int32.Parse(ViewState["employee_id"].ToString()), employeeType, companyId);
                }
                else
                {
                    if ((string)Request.QueryString["employee_id"] == null)
                    {
                        ViewState["employee_id"] = "-1";

                        if (employeeTypeNow.Contains("CA"))
                        {
                            ddlWorkingLocation.SelectedValue = "CA";
                        }
                        else
                        {
                            ddlWorkingLocation.SelectedValue = "US";
                        }

                        vacationsInformationGateway.LoadByEmployeeType(employeeTypeNow, companyId);
                    }
                    else
                    {
                        ViewState["employee_id"] = (string)Request.QueryString["employee_id"];

                        EmployeeInformationBasicInformationGateway employeeInformationBasicInformationGateway = new EmployeeInformationBasicInformationGateway();
                        employeeInformationBasicInformationGateway.LoadByEmployeeId(Int32.Parse(ViewState["employee_id"].ToString()));

                        string employeeType = employeeInformationBasicInformationGateway.GetType(Int32.Parse(ViewState["employee_id"].ToString()));

                        if (employeeTypeNow.Contains("CA"))
                        {
                            ddlWorkingLocation.SelectedValue = "CA";
                        }
                        else
                        {
                            ddlWorkingLocation.SelectedValue = "US";
                        }

                        vacationsInformationGateway.LoadByEmployeeIdEmployeeType(Int32.Parse(ViewState["employee_id"].ToString()), employeeType, companyId);

                        ddlVacationsFor.SelectedValue = ViewState["employee_id"].ToString();
                    }
                }

                Session["vacationsInformationTDS"] = vacationsInformationTDS;
                Session["vacationsInformation"] = vacationsInformationTDS.VacationsInformation;

                tkrsVacations.SelectedDate = DateTime.Parse(ViewState["date_to_show"].ToString());
                lblTitle.Text = "Vacations Calendar for " + tkrsVacations.SelectedDate.ToString("MMMM") + " " + tkrsVacations.SelectedDate.Year.ToString();

                // Databind
                Page.DataBind();

                // For Open Vacation event
                if ((Request.Params["__EVENTTARGET"]) == "openVacation")
                {
                    int vacationId = Int32.Parse(Request.Params.Get("__EVENTARGUMENT").ToString()) ;
                    VacationsInformationDaysInformationGateway vacationsInformationDaysInformationGateway = new VacationsInformationDaysInformationGateway();
                    vacationsInformationDaysInformationGateway.LoadByVacationId(vacationId, companyId);
                    int requestId = vacationsInformationDaysInformationGateway.GetRequestID(vacationId);

                    Session["ddlVacationsForSelectedValue"] = ddlVacationsFor.SelectedValue;

                    Response.Redirect("./vacations_summary.aspx?source_page=vacations_all.aspx&vacation_id=" + vacationId.ToString() + "&request_id=" + requestId.ToString() + "&date_to_show=" + ViewState["date_to_show"]);
                }
            }
            else
            {
                vacationsInformationTDS = (VacationsInformationTDS)Session["vacationsInformationTDS"];
                vacationsInformation = (VacationsInformationTDS.VacationsInformationDataTable)Session["vacationsInformation"];

                // For Open Vacation event
                if ((Request.Params["__EVENTTARGET"]) == "openVacation")
                {
                    int vacationId = Int32.Parse(Request.Params.Get("__EVENTARGUMENT").ToString());
                    VacationsInformationDaysInformationGateway vacationsInformationDaysInformationGateway = new VacationsInformationDaysInformationGateway();
                    vacationsInformationDaysInformationGateway.LoadByVacationId(vacationId, Int32.Parse(hdfCompanyId.Value));
                    int requestId = vacationsInformationDaysInformationGateway.GetRequestID(vacationId);

                    DropDownList ddlVacationsFor = (DropDownList)tkrpbLeftMenuAllVacations.FindItemByValue("nbVacationsForDDL").FindControl("ddlVacationsFor");
                    Session["ddlVacationsForSelectedValue"] = ddlVacationsFor.SelectedValue;

                    Response.Redirect("./vacations_summary.aspx?source_page=vacations_all.aspx&vacation_id=" + vacationId.ToString() + "&request_id=" + requestId.ToString() + "&date_to_show=" + ViewState["date_to_show"]);
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// ValidateIfExistsAVacation
        /// </summary>
        /// <param name="date">date</param>
        /// <param name="employeeId">employeeId</param>
        /// <param name="companyId">companyId</param>
        public static bool ValidateIfExistsAVacation(DateTime date, int employeeId, int companyId)
        {
            bool valid = true;

            VacationsInformationGateway vacationsInformationGateway = new VacationsInformationGateway();
            if (vacationsInformationGateway.IsFullVacationDay(date, employeeId, companyId))
            {
                valid = false;
            }
            else
            {
                int amountHalfDays = vacationsInformationGateway.IsHalfVacationDay(date, employeeId, companyId);
                if (amountHalfDays == 2)
                {
                    valid = false;
                }
                else
                {
                    if ((amountHalfDays == 0) || (amountHalfDays == 1))
                    {
                        valid = true;
                    }
                }
            }

            return valid;
        }