예제 #1
0
        public IActionResult Get(string date)
        {
            string[] dateArr = date.Split(' ');
            string   year    = dateArr.Length > 1 ? dateArr[1] : "";

            if (year.Length == 0)
            {
                return(new BadRequestResult());
            }

            DateTime dateTime = Convert.ToDateTime(date);

            while (DateSystem.IsPublicHoliday(dateTime, CountryCode.CZ) || DateSystem.IsWeekend(dateTime, CountryCode.CZ))
            {
                dateTime = dateTime.AddDays(-1);
            }

            List <Currency> result = database.GetCollection <Currency>(dateTime.Year.ToString()).Find(a => true).ToList();

            if (result.Count > 0)
            {
                return(new OkObjectResult(result));
            }
            else
            {
                return(new NotFoundResult());
            }
        }
예제 #2
0
        public List <DateTime> WorkDayList()
        {
            int year, month;

            year  = Convert.ToInt32(textBox_Year.Text);
            month = Convert.ToInt32(textBox_Month.Text);
            var ignoreDays = listBox_IgnoreDays.Items.Cast <string>().ToArray();

            var result  = new List <DateTime>();
            var lastDay = DateTime.DaysInMonth(year, month);

            for (int day = 1; day < lastDay; day++)
            {
                var date = new DateTime(year, month, day);
                if (checkBox_publicHoliday.Checked)
                {
                    if (DateSystem.IsPublicHoliday(date, CountryCode.KR))
                    {
                        continue;
                    }
                }
                if (DateSystem.IsWeekend(date, CountryCode.KR))
                {
                    continue;
                }
                else if (ignoreDays.Contains(day + ""))
                {
                    continue;
                }
                result.Add(date);
            }
            return(result);
        }
예제 #3
0
        public void Statistics()
        {
            var jsonIssue = new JsonJiraIssue
            {
                Id     = "1",
                Key    = "JIRA-1",
                Fields = new JsonJiraIssueFields
                {
                    Created = "2020-01-01T12:00:00.000-0500",
                    // 1, 2, 3, 6, 7, 8, 9, 10, 13, 14, 15, 16, 17, 20
                    ResolutionDate = "2020-01-15T12:00:01.746-0500",
                    Creator        = John,
                    Status         = Done,
                    FixVersions    = new List <JsonJiraFixVersion>
                    {
                        Release1
                    },
                    Components = new List <JsonJiraComponent>(),
                    Sprint     = new JsonJiraSprint[0],
                    IssueType  = new JsonJiraIssueType
                    {
                        Id   = "1",
                        Name = "Story"
                    }
                },
                Changelog = new List <JsonJiraIssueChangelogEvent>
                {
                    MakeIssueChange(John, "2020-01-02T12:00:00.000-0500", Open, Todo),
                    MakeIssueChange(John, "2020-01-03T12:00:00.000-0500", Todo, Work),
                    MakeIssueChange(Mike, "2020-01-07T12:00:00.000-0500", false, true), // john +
                    MakeIssueChange(Jane, "2020-01-08T12:00:00.000-0500", true, false),
                    MakeIssueChange(Mike, "2020-01-10T12:00:00.000-0500", Work, Rejected),
                    MakeIssueChange(Mike, "2020-01-13T12:00:00.000-0500", Rejected, Todo),
                    MakeIssueChange(John, "2020-01-14T12:00:00.000-0500", Todo, Work),
                    MakeIssueChange(John, "2020-01-15T12:00:00.000-0500", Work, Done),
                }
            };

            var opts = new JiraOptions
            {
                IsWorkDayPredicate = date => false == DateSystem.IsWeekend(date, CountryCode.CA)
            };

            var issue = JiraIssueAssembler.Assemble(opts, jsonIssue, AllStatuses, AllFixVersions);

            Assert.Equal(ParseDateTime("2020-01-01T12:00:00.000-0500"), issue.Created);
            Assert.Equal(ParseDateTime("2020-01-15T12:00:00.000-0500"), issue.Finished);

            Assert.Equal(14, issue.CycleTime);

            var statistics = issue.Statistics;

            Assert.Equal(TimeSpan.FromDays(3), statistics.CategoryDurations[JiraStatusCategory.New]);
            Assert.Equal(TimeSpan.FromDays(5), statistics.CategoryDurations[JiraStatusCategory.InProgress]);
            Assert.Equal(TimeSpan.FromDays(1), statistics.CategoryDurations[JiraStatusCategory.OnHold]);
            Assert.True(statistics.CategoryDurations[JiraStatusCategory.Done] > TimeSpan.Zero);

            Assert.Equal(TimeSpan.FromDays(3), statistics.PersonDurations[John.EmailAddress]);
            Assert.Equal(TimeSpan.FromDays(2), statistics.PersonDurations[Jane.EmailAddress]);
        }
예제 #4
0
        public IActionResult Get(string date)
        {
            string[] dateArr = date.Split(' ');
            string   year    = dateArr.Length > 1 ? dateArr[1] : "";

            if (year.Length == 0)
            {
                return(new BadRequestResult());
            }

            DateTime dateTime = Convert.ToDateTime(date);

            while (DateSystem.IsPublicHoliday(dateTime, CountryCode.CZ) || DateSystem.IsWeekend(dateTime, CountryCode.CZ))
            {
                dateTime = dateTime.AddDays(-1);
            }
            date = dateTime.ToString("dd.MMM yyyy"); //Convert back for comparison
            List <ExchangeRate> result = database.GetCollection <ExchangeRate>(dateTime.Year.ToString()).Find(a => a.date == date).ToList();

            if (result.Count > 0)
            {
                return(new OkObjectResult(result[0]));
            }
            else
            {
                return(new NotFoundResult());
            }
        }
        public static bool CheckOnHoliday(DateTime dateTime,
                                          CountryCode countryCode,
                                          string countyCode = null)
        {
            var isHolidayOrWeekend = DateSystem.IsWeekend(dateTime, CountryCode.RU) ||
                                     DateSystem.IsPublicHoliday(dateTime, CountryCode.RU) ||
                                     countyCode != null && DateSystem.IsOfficialPublicHolidayByCounty(dateTime, countryCode, countyCode);

            return(isHolidayOrWeekend);
        }
        public bool IsHolidayEntry(IEntry entry)
        {
            bool adamHoliday = entry.Application.Equals("admin", StringComparison.InvariantCultureIgnoreCase);

            if (adamHoliday)
            {
                return(true);
            }

            DateTime date = DateTime.Parse(entry.Date, new CultureInfo("en-US"));

            return(DateSystem.IsPublicHoliday(date, CountryCode.US) || DateSystem.IsWeekend(date, CountryCode.US));
        }
        public void TestNagerDateLibrary()
        {
            var xmas    = new DateTime(2020, 12, 25);
            var weekday = new DateTime(2020, 12, 11);
            var weekend = new DateTime(2020, 12, 12);

            Assert.True(DateSystem.IsPublicHoliday(xmas, CountryCode.US));
            Assert.False(DateSystem.IsPublicHoliday(weekday, CountryCode.US));
            Assert.True(DateSystem.IsWeekend(weekend, CountryCode.US));

            Assert.False(DateSystem.IsPublicHoliday(weekend, CountryCode.US)); // a public holiday is NOT a weekend
            Assert.False(DateSystem.IsWeekend(xmas, CountryCode.US));          // a weekend is NOT a public holiday
        }
        public static WorkDayType ToWorkDayType(this DateTime date)
        {
            if (DateSystem.IsPublicHoliday(date, CountryCode.DE, "DE-SN"))
            {
                return(WorkDayType.BankHoliday);
            }

            if (DateSystem.IsWeekend(date, CountryCode.DE))
            {
                return(WorkDayType.Weekend);
            }

            return(WorkDayType.Workday);
        }
예제 #9
0
        /// <summary>
        /// Change date when is set at holiday or weekend day
        /// </summary>
        /// <param name="value">Date to check if is holiday and change it</param>
        /// <returns>Date that is not holiday date</returns>
        public DateTime ReturnDateBeforeDayOff(DateTime value)
        {
            while (true)
            {
                if (!DateSystem.IsPublicHoliday(value, CountryCode.PL) && !DateSystem.IsWeekend(value, CountryCode.PL))
                {
                    break;
                }

                value = value.AddDays(-1);
            }

            return(value);
        }
예제 #10
0
        public static List <int> CalcolaGiorniFestivi(int mese, int anno)
        {
            List <int> giorniFestivi = new List <int>();

            for (int i = 1; i <= DateTime.DaysInMonth(anno, mese); i++)
            {
                var date = new DateTime(anno, mese, i);
                if (DateSystem.IsWeekend(date, CountryCode.IT) || DateSystem.IsPublicHoliday(date, CountryCode.IT))
                {
                    giorniFestivi.Add(i);
                }
            }
            return(giorniFestivi);
        }
예제 #11
0
 public bool IsWorkday(DateTime date)
 {
     if (DateSystem.IsWeekend(date, CountryCode.DE))
     {
         return(false);
     }
     foreach (Holiday f in Holidays())
     {
         if (f.Date == date)
         {
             return(false);
         }
     }
     return(true);
 }
예제 #12
0
        public void CheckIsWeekend()
        {
            var isPublicHoliday = DateSystem.IsWeekend(new DateTime(2021, 10, 20), CountryCode.AT);

            Assert.IsFalse(isPublicHoliday);

            isPublicHoliday = DateSystem.IsWeekend(new DateTime(2021, 10, 20), "AT");
            Assert.IsFalse(isPublicHoliday);

            isPublicHoliday = DateSystem.IsWeekend(new DateTime(2021, 10, 24), CountryCode.AT);
            Assert.IsTrue(isPublicHoliday);

            isPublicHoliday = DateSystem.IsWeekend(new DateTime(2021, 10, 24), "AT");
            Assert.IsTrue(isPublicHoliday);
        }
예제 #13
0
        public static double BusinessDaysUntil(this DateTime fromDate, DateTime toDate)
        {
            var businessDays = new List <DateTime>();

            for (var date = fromDate; date <= toDate; date = date.AddDays(1))
            {
                if (DateSystem.IsPublicHoliday(date, CountryCode.DK) || DateSystem.IsWeekend(date, CountryCode.DK))
                {
                    continue;
                }

                businessDays.Add(date);
            }

            return(businessDays.Count);
        }
        private DateTime GetClosestValidDate()
        {
            var date        = DateTime.Today;
            var countryCode = CountryCode.SE;

            //Traverse 14 days backwards to find valid non-weekend/holiday date
            for (int i = 0; i < 14; i++)
            {
                if (DateSystem.IsPublicHoliday(date, countryCode) || DateSystem.IsWeekend(date, countryCode))
                {
                    date = date.AddDays(-1);
                }
                else
                {
                    return(date);
                }
            }

            return(DateTime.MinValue);
        }
예제 #15
0
        /// <summary>
        /// Refreshes the calendar-header with all holidays from date: <paramref name="startDate"/>
        /// </summary>
        public static void UpdateHolidays(DateTime startDate, DataGridView header, Dictionary <Point, string> cellToolTips)
        {
            if (lastDate == null || lastDate.Year != startDate.Year)
            {
                AddHolidays(startDate.Year);
            }

            lastDate = startDate;

            for (int col = 0; col < header.ColumnCount; col++)
            {
                if (DateSystem.IsWeekend(startDate.AddDays(col), CountryCode.SE))
                {
                    header[col, 1].Style.BackColor = Color.LightGray;
                }
                else
                {
                    header[col, 1].Style.BackColor = Color.White;
                }
            }

            DisplayHolidays(startDate, header, cellToolTips);
        }
예제 #16
0
      /// <summary>
      /// Valida la si elcampo es de tipo fecha
      /// </summary>
      /// <param name="campo">Contenido y información del campo..</param>
      /// <returns>Mensaje de error.</returns>
      static public string ValidarFecha(Campo campo)
      {
          string   mensaje = string.Empty;
          DateTime fecha   = default(DateTime);
          bool     isFecha = DateTime.TryParse(campo.Contenido.ToString(), out fecha);

          mensaje += (!isFecha) ? $"El campo solo debe ser de tipo fecha {Environment.NewLine}" : string.Empty;

          mensaje += (isFecha && (DateSystem.IsPublicHoliday(fecha, CountryCode.CO) || DateSystem.IsWeekend(fecha, CountryCode.CO)) && campo.IsHabil) ? $"La {campo.Nombre} que ingresó no es un día hábil. {Environment.NewLine} " : string.Empty;
          return(mensaje);
      }
예제 #17
0
 public static bool IsBusinessDay(this DateTime date)
 {
     return(DateSystem.IsPublicHoliday(date, CountryCode.DK) == false && DateSystem.IsWeekend(date, CountryCode.DK) == false);
 }
예제 #18
0
        protected void BindData()
        {
            try
            {
                Employee        loggedEmployee = (Employee)Session["MY_INFORMATION"];
                string          acp            = (string)Session["CONSULTED_ACPMANAGEMENT"];
                List <Workload> workloads      = new List <Workload>();
                String          init           = dateinit.Text;
                String          end            = dateend.Text;
                if (acp != null)
                {
                    if ((!init.Equals("")) && (!end.Equals("")))
                    {
                        DateTime initDate = Convert.ToDateTime(init);
                        DateTime endDate  = Convert.ToDateTime(end);
                        if (ValidateDateRange(initDate, endDate))
                        {
                            GetAllWorkloadsByACPCommand cmd = new GetAllWorkloadsByACPCommand(acp, initDate, endDate);
                            cmd.Execute();
                            workloads = cmd.GetResults();
                            repCostCenter.DataSource = workloads;
                            repCostCenter.DataBind();
                            DateTime movableDate = initDate;
                            int      dayCounter  = 1;
                            header16.Visible = true;
                            header15.Visible = true;
                            header14.Visible = true;
                            footer16.Visible = true;
                            footer15.Visible = true;
                            footer14.Visible = true;
                            List <Int32> totalsPerDay = new List <int>();
                            totalsPerDay.Add(0);
                            totalsPerDay.Add(0);
                            totalsPerDay.Add(0);
                            totalsPerDay.Add(0);
                            totalsPerDay.Add(0);
                            totalsPerDay.Add(0);
                            totalsPerDay.Add(0);
                            totalsPerDay.Add(0);
                            totalsPerDay.Add(0);
                            totalsPerDay.Add(0);
                            totalsPerDay.Add(0);
                            totalsPerDay.Add(0);
                            totalsPerDay.Add(0);
                            totalsPerDay.Add(0);
                            totalsPerDay.Add(0);
                            totalsPerDay.Add(0);
                            foreach (Workload workload in workloads)
                            {
                                totalsPerDay[0]  += workload.day1;
                                totalsPerDay[1]  += workload.day2;
                                totalsPerDay[2]  += workload.day3;
                                totalsPerDay[3]  += workload.day4;
                                totalsPerDay[4]  += workload.day5;
                                totalsPerDay[5]  += workload.day6;
                                totalsPerDay[6]  += workload.day7;
                                totalsPerDay[7]  += workload.day8;
                                totalsPerDay[8]  += workload.day9;
                                totalsPerDay[9]  += workload.day10;
                                totalsPerDay[10] += workload.day11;
                                totalsPerDay[11] += workload.day12;
                                totalsPerDay[12] += workload.day13;
                                totalsPerDay[13] += workload.day14;
                                totalsPerDay[14] += workload.day15;
                                totalsPerDay[15] += workload.day16;
                            }
                            Holiday        holidayManagement = new Holiday();
                            List <Holiday> holidays          = holidayManagement.getHolidaysNameVenezuela();
                            while (DateTime.Compare(movableDate, endDate) != 1)
                            {
                                switch (dayCounter)
                                {
                                case 1:
                                    header1.InnerText = movableDate.ToString("dd/MM/yyyy");
                                    footer1.InnerText = totalsPerDay[dayCounter - 1].ToString();
                                    break;

                                case 2:
                                    header2.InnerText = movableDate.ToString("dd/MM/yyyy");
                                    footer2.InnerText = totalsPerDay[dayCounter - 1].ToString();
                                    break;

                                case 3:
                                    header3.InnerText = movableDate.ToString("dd/MM/yyyy");
                                    footer3.InnerText = totalsPerDay[dayCounter - 1].ToString();
                                    break;

                                case 4:
                                    header4.InnerText = movableDate.ToString("dd/MM/yyyy");
                                    footer4.InnerText = totalsPerDay[dayCounter - 1].ToString();
                                    break;

                                case 5:
                                    header5.InnerText = movableDate.ToString("dd/MM/yyyy");
                                    footer5.InnerText = totalsPerDay[dayCounter - 1].ToString();
                                    break;

                                case 6:
                                    header6.InnerText = movableDate.ToString("dd/MM/yyyy");
                                    footer6.InnerText = totalsPerDay[dayCounter - 1].ToString();
                                    break;

                                case 7:
                                    header7.InnerText = movableDate.ToString("dd/MM/yyyy");
                                    footer7.InnerText = totalsPerDay[dayCounter - 1].ToString();
                                    break;

                                case 8:
                                    header8.InnerText = movableDate.ToString("dd/MM/yyyy");
                                    footer8.InnerText = totalsPerDay[dayCounter - 1].ToString();
                                    break;

                                case 9:
                                    header9.InnerText = movableDate.ToString("dd/MM/yyyy");
                                    footer9.InnerText = totalsPerDay[dayCounter - 1].ToString();
                                    break;

                                case 10:
                                    header10.InnerText = movableDate.ToString("dd/MM/yyyy");
                                    footer10.InnerText = totalsPerDay[dayCounter - 1].ToString();
                                    break;

                                case 11:
                                    header11.InnerText = movableDate.ToString("dd/MM/yyyy");
                                    footer11.InnerText = totalsPerDay[dayCounter - 1].ToString();
                                    break;

                                case 12:
                                    header12.InnerText = movableDate.ToString("dd/MM/yyyy");
                                    footer12.InnerText = totalsPerDay[dayCounter - 1].ToString();
                                    break;

                                case 13:
                                    header13.InnerText = movableDate.ToString("dd/MM/yyyy");
                                    footer13.InnerText = totalsPerDay[dayCounter - 1].ToString();
                                    break;

                                case 14:
                                    header14.InnerText = movableDate.ToString("dd/MM/yyyy");
                                    footer14.InnerText = totalsPerDay[dayCounter - 1].ToString();
                                    break;

                                case 15:
                                    header15.InnerText = movableDate.ToString("dd/MM/yyyy");
                                    footer15.InnerText = totalsPerDay[dayCounter - 1].ToString();
                                    break;

                                case 16:
                                    header16.InnerText = movableDate.ToString("dd/MM/yyyy");
                                    footer16.InnerText = totalsPerDay[dayCounter - 1].ToString();
                                    break;
                                }
                                int total = totalsPerDay[0] + totalsPerDay[1] + totalsPerDay[2] + totalsPerDay[3] + totalsPerDay[4] +
                                            totalsPerDay[5] + totalsPerDay[6] + totalsPerDay[7] + totalsPerDay[8] + totalsPerDay[9] +
                                            totalsPerDay[10] + totalsPerDay[11] + totalsPerDay[12] + totalsPerDay[13] + totalsPerDay[14] +
                                            totalsPerDay[15];
                                footerTotal.InnerText = total.ToString();
                                bool holidayWeekend = DateSystem.IsWeekend(movableDate, CountryCode.VE);
                                foreach (Holiday holiday in holidays)
                                {
                                    int sameDate = DateTime.Compare(movableDate, holiday.date);
                                    if (sameDate == 0)
                                    {
                                        holidayWeekend = true;
                                    }
                                }
                                if (holidayWeekend)
                                {
                                    int row = 0;
                                    foreach (RepeaterItem item in repCostCenter.Items)
                                    {
                                        int           realDay = dayCounter;
                                        string        freeDay = "day" + realDay;
                                        HtmlTableCell day     = ((HtmlTableCell)repCostCenter.Items[row].FindControl(freeDay));
                                        day.BgColor = "#D3D3D3";
                                        row++;
                                    }
                                }
                                movableDate = movableDate.AddDays(1);
                                dayCounter++;
                            }
                            int counter = 0;
                            foreach (RepeaterItem item in repCostCenter.Items)
                            {
                                HtmlTableCell day14 = ((HtmlTableCell)repCostCenter.Items[counter].FindControl("day14"));
                                HtmlTableCell day15 = ((HtmlTableCell)repCostCenter.Items[counter].FindControl("day15"));
                                HtmlTableCell day16 = ((HtmlTableCell)repCostCenter.Items[counter].FindControl("day16"));
                                if (endDate.Day == 30)
                                {
                                    day16.Visible    = false;
                                    header16.Visible = false;
                                    footer16.Visible = false;
                                }
                                else if (endDate.Day == 29)
                                {
                                    day16.Visible    = false;
                                    day15.Visible    = false;
                                    header16.Visible = false;
                                    header15.Visible = false;
                                    footer16.Visible = false;
                                    footer15.Visible = false;
                                }
                                else if (endDate.Day == 15)
                                {
                                    day16.Visible    = false;
                                    header16.Visible = false;
                                    footer16.Visible = false;
                                }
                                else if (endDate.Day == 28)
                                {
                                    day16.Visible    = false;
                                    day15.Visible    = false;
                                    day14.Visible    = false;
                                    header16.Visible = false;
                                    header15.Visible = false;
                                    header14.Visible = false;
                                    footer16.Visible = false;
                                    footer15.Visible = false;
                                    footer14.Visible = false;
                                }
                                counter++;
                            }
                        }
                        else
                        {
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "randomText", "errorSweetAlert('Debe seleccionar un rango de fechas válido', 'error')", true);
                        }
                    }
                    else
                    {
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "randomText", "errorSweetAlert('Debe seleccionar la fecha de inicio y de fin', 'error')", true);
                    }
                }
                else
                {
                    Session.Remove("CONSULTED_ACP");
                    Response.Redirect("~/site/employees/acpmanagement/myacps.aspx", false);
                }
            }
            catch (Exception ex)
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "randomText", "errorSweetAlert('Ha ocurrido un error al cargar la información', 'error')", true);
            }
        }
예제 #19
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                try
                {
                    Employee loggedEmployee = (Employee)Session["MY_INFORMATION"];
                    if (loggedEmployee != null)
                    {
                        string timesheetString = (string)Session["CONSULTED_TIMESHEET_HRM"];
                        if (timesheetString != null)
                        {
                            Timesheet timesheet = new Timesheet(Int64.Parse(timesheetString));
                            GetAllWorkloadsByTimesheetCommand cmd = new GetAllWorkloadsByTimesheetCommand(timesheet);
                            cmd.Execute();
                            timesheet         = cmd.GetResults();
                            timesheetLbl.Text = timesheet.id.ToString() + " - Estatus: " + timesheet.status;
                            commentLbl.Text   = "Comentario: " + timesheet.comment;
                            bool allApproved = true;
                            foreach (Workload workload in timesheet.workloads)
                            {
                                total.day1  += workload.day1;
                                total.day2  += workload.day2;
                                total.day3  += workload.day3;
                                total.day4  += workload.day4;
                                total.day5  += workload.day5;
                                total.day6  += workload.day6;
                                total.day7  += workload.day7;
                                total.day8  += workload.day8;
                                total.day9  += workload.day9;
                                total.day10 += workload.day10;
                                total.day11 += workload.day11;
                                total.day12 += workload.day12;
                                total.day13 += workload.day13;
                                total.day14 += workload.day14;
                                total.day15 += workload.day15;
                                total.day16 += workload.day16;
                                if (!workload.status.Equals("APROBADA"))
                                {
                                    allApproved        = false;
                                    approveBtn.Enabled = false;
                                }
                            }
                            repWorkloads.DataSource = timesheet.workloads;
                            repWorkloads.DataBind();
                            day1Lbl.Text  = total.day1.ToString();
                            day2Lbl.Text  = total.day2.ToString();
                            day3Lbl.Text  = total.day3.ToString();
                            day4Lbl.Text  = total.day4.ToString();
                            day5Lbl.Text  = total.day5.ToString();
                            day6Lbl.Text  = total.day6.ToString();
                            day7Lbl.Text  = total.day7.ToString();
                            day8Lbl.Text  = total.day8.ToString();
                            day9Lbl.Text  = total.day9.ToString();
                            day10Lbl.Text = total.day10.ToString();
                            day11Lbl.Text = total.day11.ToString();
                            day12Lbl.Text = total.day12.ToString();
                            day13Lbl.Text = total.day13.ToString();
                            day14Lbl.Text = total.day14.ToString();
                            day15Lbl.Text = total.day15.ToString();
                            day16Lbl.Text = total.day16.ToString();
                            totalLbl.Text = total.TotalHoursPerACP().ToString();
                            DateTime       movableDate       = timesheet.initDate;
                            int            dayCounter        = 1;
                            Holiday        holidayManagement = new Holiday();
                            List <Holiday> holidays          = holidayManagement.getHolidaysNameVenezuela();
                            while (DateTime.Compare(movableDate, timesheet.endDate) != 1)
                            {
                                switch (dayCounter)
                                {
                                case 1:
                                    header1.Text = movableDate.ToString("dd/MM/yyyy");
                                    break;

                                case 2:
                                    header2.Text = movableDate.ToString("dd/MM/yyyy");
                                    break;

                                case 3:
                                    header3.Text = movableDate.ToString("dd/MM/yyyy");
                                    break;

                                case 4:
                                    header4.Text = movableDate.ToString("dd/MM/yyyy");
                                    break;

                                case 5:
                                    header5.Text = movableDate.ToString("dd/MM/yyyy");
                                    break;

                                case 6:
                                    header6.Text = movableDate.ToString("dd/MM/yyyy");
                                    break;

                                case 7:
                                    header7.Text = movableDate.ToString("dd/MM/yyyy");
                                    break;

                                case 8:
                                    header8.Text = movableDate.ToString("dd/MM/yyyy");
                                    break;

                                case 9:
                                    header9.Text = movableDate.ToString("dd/MM/yyyy");
                                    break;

                                case 10:
                                    header10.Text = movableDate.ToString("dd/MM/yyyy");
                                    break;

                                case 11:
                                    header11.Text = movableDate.ToString("dd/MM/yyyy");
                                    break;

                                case 12:
                                    header12.Text = movableDate.ToString("dd/MM/yyyy");
                                    break;

                                case 13:
                                    header13.Text = movableDate.ToString("dd/MM/yyyy");
                                    break;

                                case 14:
                                    _header14.Text = movableDate.ToString("dd/MM/yyyy");
                                    break;

                                case 15:
                                    _header15.Text = movableDate.ToString("dd/MM/yyyy");
                                    break;

                                case 16:
                                    _header16.Text = movableDate.ToString("dd/MM/yyyy");
                                    break;
                                }
                                bool holidayWeekend = DateSystem.IsWeekend(movableDate, CountryCode.VE);
                                foreach (Holiday holiday in holidays)
                                {
                                    int sameDate = DateTime.Compare(movableDate, holiday.date);
                                    if (sameDate == 0)
                                    {
                                        holidayWeekend = true;
                                    }
                                }
                                if (holidayWeekend)
                                {
                                    int row = 0;
                                    foreach (RepeaterItem item in repWorkloads.Items)
                                    {
                                        int           realDay = dayCounter;
                                        string        freeDay = "day" + realDay;
                                        HtmlTableCell day     = ((HtmlTableCell)repWorkloads.Items[row].FindControl(freeDay));
                                        day.BgColor = "#D3D3D3";
                                        row++;
                                    }
                                }
                                movableDate = movableDate.AddDays(1);
                                dayCounter++;
                            }
                        }
                        else
                        {
                            Session.Remove("CONSULTED_TIMESHEET_HRM");
                            Response.Redirect("~/site/employees/overseer/unittimesheets.aspx", false);
                        }
                    }
                    else
                    {
                        Session.RemoveAll();
                        Response.Redirect("~/site/usermanagement/login.aspx", false);
                    }
                }
                catch (Exception ex)
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "randomText", "errorSweetAlert('Ha ocurrido un error al cargar la información', 'error')", true);
                }
            }
        }
예제 #20
0
        public string ReturnTotalTollFeeForToday(string typedRegistrationNumber)
        {
            DateTime vehiclePassedAt = DateTime.Now;

            //Try to get vehicle from database
            Vehicle vehicle = new Vehicle();

            vehicle = GetVehicle(typedRegistrationNumber.ToUpper());

            if (vehicle != null)
            {
                //In case the vehicle is a toll free vehicle, return a message saying so.
                //(And the only vehicle that is not a toll free vehicle is the type is the: CAR.)
                if (vehicle.VehicleType != "Car")
                {
                    return("The vehicle with registration number " + vehicle.RegistrationNumber +
                           " is a " + vehicle.VehicleType + " vehicle and it is a toll free vehicle.");
                }


                //Is it weekend or a holiday today? If yes, Yay! NO TOLL FEE!!
                if (DateSystem.IsWeekend(vehiclePassedAt, CountryCode.SE) | DateSystem.IsPublicHoliday(vehiclePassedAt, CountryCode.SE))
                {
                    return("It's weekend or holiday today. So " + vehicle.RegistrationNumber + " does not have to pay any toll fee today!");
                }


                //Has the CAR passed at least once in the last 60 min period?
                //Then the passage with the highest price is the only one that counts.
                List <DriveBy> lastHoursDriveBys = new List <DriveBy>();
                lastHoursDriveBys = GetDriveBys1HourBack(vehicle.Id, vehiclePassedAt);

                //Get current Toll fee
                int tollFeeForCurrentDriveBy = GetTollFee(vehiclePassedAt);

                //Mapp driveBy
                DriveBy curentDriveBy = new DriveBy();
                curentDriveBy.PassageCost = tollFeeForCurrentDriveBy;
                curentDriveBy.PassedAt    = vehiclePassedAt;
                curentDriveBy.VehicleId   = vehicle.Id;

                if (lastHoursDriveBys != null)
                {
                    //Check if the latest passage is the more expensive than the other ones.
                    bool       currentTollFeeIsMoreExpensive = false;
                    List <int> tollFeeCostsTheLastHour       = new List <int>();
                    for (int i = 0; i < lastHoursDriveBys.Count(); i++)
                    {
                        tollFeeCostsTheLastHour.Add(lastHoursDriveBys[i].PassageCost);
                    }
                    if (tollFeeForCurrentDriveBy > tollFeeCostsTheLastHour.Max())
                    {
                        currentTollFeeIsMoreExpensive = true;
                    }

                    if (currentTollFeeIsMoreExpensive)
                    {
                        //If yes, okay, get the diffrence and add that difference to the CostPerDay to update the total toll fee for the day.
                        int costDiff = tollFeeForCurrentDriveBy - tollFeeCostsTheLastHour.Max();

                        //Add current passing to DriveBys table
                        bool driveByAdded = false;
                        curentDriveBy.PassageCost = costDiff;
                        driveByAdded = AddDriveBy(curentDriveBy);

                        //Update the CostPerDays table with the diff
                        bool costPerDayWasAddedOrUpdated = false;
                        costPerDayWasAddedOrUpdated = UpdateOrAddCostPerDay(curentDriveBy);

                        if (driveByAdded && costPerDayWasAddedOrUpdated)
                        {
                            CostPerDay cost = new CostPerDay();
                            cost = GetTodaysTotalCost(vehicle.Id, curentDriveBy.PassedAt);
                            if (cost == null)
                            {
                                return("Could not get the total cost for today but the current toll fee replaced the previous highest toll fee for the past hour for " + vehicle.RegistrationNumber + ".");
                            }
                            else
                            {
                                return("Current Toll fee (" + tollFeeForCurrentDriveBy.ToString() + " kr) replaced the previous highest toll fee for the past hour for " + vehicle.RegistrationNumber + ".  Now the total cost for " + cost.Date.ToShortDateString() + " is " + cost.CostThisDay + " kr.");
                            }
                        }
                        else
                        {
                            return("Could not Add the current driveby and/or could not Add/Update the total cost for today with the current toll fee for: " + vehicle.RegistrationNumber + ".");
                        }
                    }
                    else
                    {
                        //If NO, good. No need to add anything to the CostPerDays table. Only add to the DriveBys table.

                        //Add current passaing to DriveBys table
                        bool driveByAdded = false;
                        driveByAdded = AddDriveBy(curentDriveBy);

                        if (driveByAdded)
                        {
                            CostPerDay cost = new CostPerDay();
                            cost = GetTodaysTotalCost(vehicle.Id, curentDriveBy.PassedAt);
                            if (cost == null)
                            {
                                return("Could not get the total cost for today. Current toll fee did not need to be added to the DB for: " + vehicle.RegistrationNumber + ".");
                            }
                            else
                            {
                                return("Toll fee (" + curentDriveBy.PassageCost.ToString() + " kr) did not need to be added for " + vehicle.RegistrationNumber + ". Total cost for " + cost.Date.ToShortDateString() + " is " + cost.CostThisDay + " kr.");
                            }
                        }
                        else
                        {
                            return("Someting went wrong when adding DriveBy to the DB when one or more already exist in the table for " + vehicle.RegistrationNumber + ".");
                        }
                    }
                }
                else
                {
                    // No Drivebys the last hour for this car. Just add the latest passage to the  CostPerDay & DriveBys  tables.
                    bool driveByAdded = false;
                    driveByAdded = AddDriveBy(curentDriveBy);

                    if (driveByAdded)
                    {
                        //Update or add total cost for the day.
                        bool costPerDayWasAddedOrUpdated = false;
                        costPerDayWasAddedOrUpdated = UpdateOrAddCostPerDay(curentDriveBy);

                        if (costPerDayWasAddedOrUpdated)
                        {
                            CostPerDay cost = new CostPerDay();
                            cost = GetTodaysTotalCost(vehicle.Id, curentDriveBy.PassedAt);
                            if (cost == null)
                            {
                                return("Could not get the total cost for today but the current toll fee was added for " + vehicle.RegistrationNumber + ".");
                            }
                            else
                            {
                                return("Toll fee (" + curentDriveBy.PassageCost.ToString() + " kr) was added for " + vehicle.RegistrationNumber + ". Total cost for " + cost.Date.ToShortDateString() + " is " + cost.CostThisDay + " kr.");
                            }
                        }
                        else
                        {
                            return("Could not Add or Update the total cost for the day with the current toll fee for: " + vehicle.RegistrationNumber + ".");
                        }
                    }
                    else
                    {
                        //Something went wrong
                        return("Something went wrong when trying to add the passage to the DB for " + vehicle.RegistrationNumber + ".");
                    }
                }
            }

            //Vehicle not found.
            return("Vehicle not found. Try a different registration number.");
        }