public static void GetDateRangeByType(DateRanges rangeType, out DateTime startDate, out DateTime endDate) { switch (rangeType) { case DateRanges.Last30Days: startDate = DateTime.UtcNow.Date.AddDays(-30); endDate = DateTime.UtcNow.Date; break; case DateRanges.Last60Days: startDate = DateTime.UtcNow.Date.AddDays(-60); endDate = DateTime.UtcNow.Date; break; case DateRanges.Last90Days: startDate = DateTime.UtcNow.Date.AddDays(-90); endDate = DateTime.UtcNow.Date; break; case DateRanges.Last6Months: startDate = DateTime.UtcNow.Date.AddMonths(-6); endDate = DateTime.UtcNow.Date; break; case DateRanges.Custom: throw new ApplicationException("Method cannot determine time range when using a custom range"); default: throw new ApplicationException("Unknown enumeration value for date range"); } }
public void SetData(string from, string to, DateRanges range = DateRanges.Custom) { fromDateString = from; fromDate = BusinessDomain.GetDateValue(from); if (fromDate.Value != DateTime.MinValue) { fromDate = fromDate.Value.Date; } else { fromDate = null; } toDateString = to; toDate = BusinessDomain.GetDateValue(to); if (toDate.Value != DateTime.MinValue) { toDate = toDate.Value.Date; } else { toDate = null; } timeRange = range; }
public override void SetDataFilter(DataFilter dataFilter) { timeRange = DateRanges.Custom; if (dataFilter.Values.Length > 2) { timeRange = (DateRanges)Enum.ToObject(typeof(DateRanges), dataFilter.Values [2]); SetDateRange(timeRange); } if (timeRange != DateRanges.Custom || dataFilter.Values.Length < 1) { return; } fromDateString = GetFieldText(dataFilter.Values [0]); fromDate = (DateTime?)dataFilter.Values [0]; if (dataFilter.Values.Length < 2) { return; } toDateString = GetFieldText(dataFilter.Values [1]); toDate = (DateTime?)dataFilter.Values [1]; base.SetDataFilter(dataFilter); }
public DateRangeAttribute(DateRanges maximum) { if (maximum == DateRanges.today) { _maximum = DateTime.Now.ToString("MM/dd/yyyy"); } }
public IActionResult OnPostClear() { ProviderODSCode = null; ConsumerODSCode = null; SelectedDateRange = DateRanges.First().Value; ModelState.Clear(); return(Page()); }
public static EventDateRange ToEventDateRange(this DateRanges dateRange) { var eventDateRange = new EventDateRange { Description = dateRange.ToString() }; return(eventDateRange); }
public override void Clear() { base.Clear(); fromDate = null; fromDateString = string.Empty; toDate = null; toDateString = string.Empty; timeRange = DateRanges.Custom; }
/// <summary> /// Gets the time range that is currently selected in the control. /// </summary> /// <param name="startDate"> /// The <see cref="DateTime" /> of the start of the selected range. /// </param> /// <param name="endDate"> /// The <see cref="DateTime" /> of the end of the selected range. /// </param> /// <param name="rangeType"> /// The <see cref="DateRanges" /> value that defines the type of /// range being returned. It can either be a predefined range, or /// a custom range. /// </param> public void GetTimeRange(out DateTime startDate, out DateTime endDate, out DateRanges rangeType) { rangeType = (DateRanges)int.Parse(_ddlDateRange.Text); //If it's custom, we need to read the user input if (rangeType == DateRanges.Custom) { startDate = _startCalendar.SelectedDate.Date; endDate = _endCalendar.SelectedDate.Date; return; } GetDateRangeByType(rangeType, out startDate, out endDate); }
public static int tinhThamNienTaiTruong(HRMDB0Entities db, NhanVien nv) { var tongThoiGian = new DateRanges(); foreach (var ct in db.nvQTLamViec.Where(ct => ct.NV_id == nv.id)) { tongThoiGian.Add(ct.ThoiGianBatDau, ct.ThoiGianKetThuc); } foreach (var lv in db.nvQTNghiNganHan.Where(lv => lv.CongTac.NV_id == nv.id)) { tongThoiGian.Sub(lv.NgayBatDau, lv.NgayKetThuc); } return(tongThoiGian.ToMonths()); }
public static int tinhThamNienGiangDay(HRMDB0Entities db, NhanVien nv) { var tongThoiGian = new DateRanges(); foreach (var ct in db.nvQTLamViec.Where(ct => ct.NV_id == nv.id) .Where(ct => ct.ChucDanhChucVu_id.HasValue && ct.ChucDanhChuyenMon.laDayHoc)) { /*if (ct.ChucDanhChuyenMon.tenChucDanhChuyenMon.ToLower().Contains("giảng") || ct.ChucDanhChuyenMon.tenChucDanhChuyenMon.ToLower().Contains("giáo"))*/ tongThoiGian.Add(ct.ThoiGianBatDau, ct.ThoiGianKetThuc); } return(tongThoiGian.ToMonths() + db.NhanViens.All.Find(nv.id).nvTTMoRongs.Single().ThamNienGiangDay_Truoc); }
public void SetData(DateTime from, DateTime to, DateRanges range = DateRanges.Custom) { fromDateString = BusinessDomain.GetFormattedDate(from); fromTimeString = BusinessDomain.GetFormattedTime(from); fromDate = from.Date; fromTime = from.TimeOfDay; toDateString = BusinessDomain.GetFormattedDate(to); toTimeString = BusinessDomain.GetFormattedTime(to); toDate = to.Date; toTime = to.TimeOfDay; timeRange = range; }
public static string GetPath(this DateRanges dateRange, DateTime?dateTime = null) { var source = dateTime.GetValueOrDefault(DateTime.Now); var path = string.Empty; foreach (DateRanges item in Enum.GetValues(typeof(DateRanges))) { var section = item.GetValue(source); path = Path.Combine(path, section); if (item == dateRange) { break; } } return(path); }
public void SetTimeRange(DateTime startDate, DateTime endDate, DateRanges rangeType) { ListItem rangeMatch; //Determine which list item matches the range type rangeMatch = _ddlDateRange.Items.FindByValue(((int)rangeType).ToString()); _ddlDateRange.SelectedIndex = _ddlDateRange.Items.IndexOf(rangeMatch); //If it's not a custom range, calculate the dates if (rangeType != DateRanges.Custom) { GetDateRangeByType(rangeType, out startDate, out endDate); } _startCalendar.SelectedDate = startDate; _endCalendar.SelectedDate = endDate; }
public static string GetValue(this DateRanges dateRange, DateTime dateTime) => dateRange switch {
public void SetDateRange(DateRanges dateRange) { DateTime today = BusinessDomain.Today; DayOfWeek dow = today.DayOfWeek; int dayOfWeek = dow == DayOfWeek.Sunday ? 7 : (int)dow; DateTime?from = null; DateTime?to = null; switch (dateRange) { case DateRanges.Today: from = today; to = today; break; case DateRanges.Yesterday: from = today.AddDays(-1); to = today.AddDays(-1); break; case DateRanges.ThisWeek: from = today.AddDays(1 - dayOfWeek); to = today.AddDays(7 - dayOfWeek); break; case DateRanges.PastWeek: from = today.AddDays(-7); to = today; break; case DateRanges.LastWeek: from = today.AddDays(1 - 7 - dayOfWeek); to = today.AddDays(7 - 7 - dayOfWeek); break; case DateRanges.ThisMonth: from = new DateTime(today.Year, today.Month, 1); to = new DateTime(today.Year, today.Month, DateTime.DaysInMonth(today.Year, today.Month)); break; case DateRanges.PastMonth: from = today.AddMonths(-1); to = today; break; case DateRanges.LastMonth: today = today.AddMonths(-1); from = new DateTime(today.Year, today.Month, 1); to = new DateTime(today.Year, today.Month, DateTime.DaysInMonth(today.Year, today.Month)); break; case DateRanges.ThisYear: from = new DateTime(today.Year, 1, 1); to = new DateTime(today.Year, 12, DateTime.DaysInMonth(today.Year, 12)); break; case DateRanges.PastYear: from = today.AddYears(-1); to = today; break; case DateRanges.LastYear: today = today.AddYears(-1); from = new DateTime(today.Year, 1, 1); to = new DateTime(today.Year, 12, DateTime.DaysInMonth(today.Year, 12)); break; } if (from.HasValue) { fromDateString = BusinessDomain.GetFormattedDate(from.Value); fromDate = from; } if (to.HasValue) { toDateString = BusinessDomain.GetFormattedDate(to.Value); toDate = to; } }