protected void ddlWorkingLocation_SelectedIndexChanged(object sender, EventArgs e)
        {
            int companyId = Int32.Parse(hdfCompanyId.Value);
            VacationsNonWorkingDaysInformationGateway vacationsNonWorkingDaysInformationGateway = new VacationsNonWorkingDaysInformationGateway(vacationsNonWorkingDaysInformationTDS);
            vacationsNonWorkingDaysInformationGateway.LoadByCompanyLevelId(Int32.Parse(ddlWorkingLocation.SelectedValue), companyId);

            Session["vacationsNonWorkingDaysInformationTDS"] = vacationsNonWorkingDaysInformationTDS;
            Session["nonWorkingDaysInformation"] = vacationsNonWorkingDaysInformationTDS.NonWorkingDaysInformation;

            odsNonWorkingDaysGrid.DataBind();
            tkrsNonWorkingDays.DataBind();
        }
        /// <summary>
        /// Save all NonWorking Days (direct)
        /// </summary>
        public void Save()
        {
            VacationsNonWorkingDaysInformationTDS nonWorkingDaysInformationChanges = (VacationsNonWorkingDaysInformationTDS)Data.GetChanges();

            if (nonWorkingDaysInformationChanges != null)
            {
                if (nonWorkingDaysInformationChanges.NonWorkingDaysInformation.Rows.Count > 0)
                {
                    VacationsNonWorkingDaysInformationGateway vacationsNonWorkingDaysInformationGateway = new VacationsNonWorkingDaysInformationGateway(nonWorkingDaysInformationChanges);

                    foreach (VacationsNonWorkingDaysInformationTDS.NonWorkingDaysInformationRow row in (VacationsNonWorkingDaysInformationTDS.NonWorkingDaysInformationDataTable)nonWorkingDaysInformationChanges.NonWorkingDaysInformation)
                    {
                        // Insert new NonWorking Day
                        if ((!row.Deleted) && (!row.InDatabase))
                        {
                            VacationsNonWorkingDays vacationsNonWorkingDays = new VacationsNonWorkingDays(null);
                            vacationsNonWorkingDays.InsertDirect(row.StartDate, row.CompanyLevelID, row.Description, row.Deleted, row.COMPANY_ID);
                        }

                        // Update NonWorking Day
                        if ((!row.Deleted) && (row.InDatabase))
                        {
                            int originalNonWorkingDayId = row.NonWorkingDayID;
                            DateTime originalDate = row.StartDate;
                            int originalCompanyLevelId = row.CompanyLevelID;
                            bool originalDeleted = false;
                            int originalCompanyId = row.COMPANY_ID;

                            // Original values
                            string originalDescription = vacationsNonWorkingDaysInformationGateway.GetDescriptionOriginal(originalNonWorkingDayId);

                            // New values
                            string newDescription = vacationsNonWorkingDaysInformationGateway.GetDescription(originalNonWorkingDayId);

                            VacationsNonWorkingDays vacationsNonWorkingDays = new VacationsNonWorkingDays(null);
                            vacationsNonWorkingDays.UpdateDirect(originalNonWorkingDayId, originalDate, originalCompanyLevelId, originalDescription, originalDeleted, originalCompanyId, originalDate, originalCompanyLevelId, newDescription, originalDeleted, originalCompanyId);
                        }

                        // Delete NonWorking Day
                        if ((row.Deleted) && (row.InDatabase))
                        {
                            int originalNonWorkingDayId = row.NonWorkingDayID;

                            VacationsNonWorkingDays vacationsNonWorkingDays = new VacationsNonWorkingDays(null);
                            vacationsNonWorkingDays.DeleteDirect(originalNonWorkingDayId, row.COMPANY_ID);
                        }
                    }
                }
            }
        }
 // ////////////////////////////////////////////////////////////////////////
 // PUBLIC METHODS
 //
 /// <summary>
 /// LoadByCompanyLevelId
 /// </summary>
 /// <param name="companyLevelId">companyLevelId</param>              
 /// <param name="companyId">companyId</param>
 public void LoadByCompanyLevelId(int companyLevelId, int companyId)
 {
     VacationsNonWorkingDaysInformationGateway vacationsNonWorkingDaysInformationGateway = new VacationsNonWorkingDaysInformationGateway(Data);
     vacationsNonWorkingDaysInformationGateway.LoadByCompanyLevelId(companyLevelId, companyId);
 }
Ejemplo n.º 4
0
        /// <summary>
        /// ValidateExistPayPeriod
        /// </summary>
        /// <param name="date">date</param>
        public static bool ValidateIfNonWorkingDay(DateTime date, int employeeId, int companyId)
        {
            int companyLevelId = 2;//Default for Canada

            EmployeeGateway employeeGateway = new EmployeeGateway();
            employeeGateway.LoadByEmployeeId(employeeId);

            if (employeeGateway.GetType(employeeId).Contains("US"))
            {
                companyLevelId = 3;
            }

            VacationsNonWorkingDaysInformationGateway vacationsNonWorkingDaysInformationGateway = new VacationsNonWorkingDaysInformationGateway();
            if (vacationsNonWorkingDaysInformationGateway.IsNonWorkingDay(date, companyLevelId, companyId))
            {
                return false;
            }
            else
            {
                return true;
            }
        }
        // ////////////////////////////////////////////////////////////////////////
        // 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_HOLIDAY_FULL_EDITING"])))
                {
                    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) && ((string)Request.QueryString["date_to_show"] == null))
                {
                    Response.Redirect("./../../error_page.aspx?error=" + "Invalid query string in vacations_non_working_days_definition.aspx");
                }

                // Tag page
                // ... 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";
                }

                // Tag page
                ViewState["date_to_show"] = (string)Request.QueryString["date_to_show"];
                ViewState["level"] = "-1";
                int companyId = Int32.Parse(Session["companyID"].ToString());
                hdfCompanyId.Value = companyId.ToString();

                // Prepare initial data
                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();
                ddlVacationsFor.SelectedValue = Session["ddlVacationsForSelectedValue"].ToString();

                // ... For ddl working location
                companyLevels = new CompanyLevelsTDS();
                CompanyLevel companyLevel = new CompanyLevel(companyLevels);
                companyLevel.LoadNodes(companyId);
                GetNodeForCompanyLevel(1);
                int companyLevelId = 0;
                if (employeeTypeNow.Contains("CA"))
                {
                    ddlWorkingLocation.SelectedValue = "2";//Canada
                    companyLevelId = 2;
                }
                else
                {
                    ddlWorkingLocation.SelectedValue = "3";//Canada
                    companyLevelId = 3;
                }

                // ... Load non working days
                vacationsNonWorkingDaysInformationTDS = new VacationsNonWorkingDaysInformationTDS();
                nonWorkingDaysInformation = new VacationsNonWorkingDaysInformationTDS.NonWorkingDaysInformationDataTable();

                VacationsNonWorkingDaysInformationGateway vacationsNonWorkingDaysInformationGateway = new VacationsNonWorkingDaysInformationGateway(vacationsNonWorkingDaysInformationTDS);
                vacationsNonWorkingDaysInformationGateway.LoadByCompanyLevelId(companyLevelId, companyId);

                Session["vacationsNonWorkingDaysInformationTDS"] = vacationsNonWorkingDaysInformationTDS;
                Session["nonWorkingDaysInformation"] = vacationsNonWorkingDaysInformationTDS.NonWorkingDaysInformation;

                tkrsNonWorkingDays.SelectedDate = DateTime.Parse(ViewState["date_to_show"].ToString());

                // Databind
                Page.DataBind();
            }
            else
            {
                vacationsNonWorkingDaysInformationTDS = (VacationsNonWorkingDaysInformationTDS)Session["vacationsNonWorkingDaysInformationTDS"];
                nonWorkingDaysInformation = (VacationsNonWorkingDaysInformationTDS.NonWorkingDaysInformationDataTable)Session["nonWorkingDaysInformation"];
            }
        }