コード例 #1
0
        private DateTime GetDateTimeNotFixedDateRule(TimeZoneInfo.TransitionTime transitionTime, int year)
        {
            System.Globalization.Calendar calendar = _userConnection.CurrentUser.Culture.Calendar;
            DateTime firstDateOfMonth    = new DateTime(year, transitionTime.Month, 1);
            int      firstDayOfMounth    = (int)calendar.GetDayOfWeek(firstDateOfMonth);
            int      startDayOfWeek      = (transitionTime.Week * 7) - 6;
            int      transitionDayOfWeek = (int)transitionTime.DayOfWeek;
            int      transitionDay;

            if (firstDayOfMounth <= transitionDayOfWeek)
            {
                transitionDay = startDayOfWeek + (transitionDayOfWeek - firstDayOfMounth);
            }
            else
            {
                transitionDay = startDayOfWeek + (7 - firstDayOfMounth + transitionDayOfWeek);
            }
            if (transitionDay > calendar.GetDaysInMonth(year, transitionTime.Month))
            {
                transitionDay -= 7;
            }
            return(new DateTime(
                       year,
                       transitionTime.Month,
                       transitionDay,
                       transitionTime.TimeOfDay.Hour,
                       transitionTime.TimeOfDay.Minute,
                       transitionTime.TimeOfDay.Second,
                       DateTimeKind.Utc));
        }
コード例 #2
0
        public UninvoiceWork GetAllUninvoicedWork(int identityID)
        {
            Facade.IOrganisation facOrg  = new Facade.Organisation();
            DateTime             endDate = DateTime.Today.AddMonths(-1);

            // this has been amended to look up to the end of the previous month
            System.Globalization.Calendar cal = System.Globalization.CultureInfo.CurrentCulture.Calendar;
            endDate = new DateTime(endDate.Year, endDate.Month, cal.GetDaysInMonth(endDate.Year, endDate.Month));

            DataSet ds = facOrg.GetAllUninvoicedWorkForOrganisation(identityID, DateTime.Today.AddYears(-1), endDate, true, true, true);

            try
            {
                int     orderCount = 0;
                decimal orderValue = 0;
                foreach (DataRow row in ds.Tables[1].Rows)
                {
                    orderCount += (int)row["CountOfJobs"];
                    orderValue += (decimal)row["Total Charge Amount"];
                }

                UninvoiceWork retVal = new UninvoiceWork()
                {
                    NumberOfOrders = orderCount, ValueOfOrders = orderValue
                };
                return(retVal);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #3
0
        /// <summary>
        /// Returns number of days in a month
        /// </summary>
        /// <param name="value">Th date</param>
        /// <returns>Number of days in a month</returns>
        public static Int32 GetCountDaysOfMonth(this DateTime value)
        {
            System.Globalization.DateTimeFormatInfo dfi      = System.Globalization.DateTimeFormatInfo.CurrentInfo;
            System.Globalization.Calendar           calendar = dfi.Calendar;

            return(calendar.GetDaysInMonth(value.Year, value.Month));
        }
コード例 #4
0
        protected void OnRadioCurMonthClicked(object sender, EventArgs e)
        {
            if ((sender as RadioButton).Active == false)
            {
                return;
            }
            IsRadioChange = true;
            int Year  = DateTime.Today.Year;
            int Month = DateTime.Today.Month;

            System.Globalization.Calendar cal = System.Globalization.CultureInfo.CurrentCulture.Calendar;
            int LastDay = cal.GetDaysInMonth(Year, Month);

            StartDate.Date = new DateTime(Year, Month, 1);
            EndDate.Date   = new DateTime(Year, Month, LastDay);
            EndRadioChange();
        }
コード例 #5
0
        /// <summary>
        /// Deterines if the input date is valid in the target calendar type.
        /// </summary>
        /// <param name="calendar1">Target calendar to check input date in that calendar.</param>
        /// <param name="year">Year of input date to check.</param>
        /// <param name="month">Month of input date to check.</param>
        /// <param name="day">Day of input date to check.</param>
        /// <returns>True if valid, false if not valid.</returns>
        public static bool IsValidDate(DateTimeSscCalendars calendar1, int year, int month, int day)   //check if the date time is invalid
        {
            System.Globalization.Calendar c1 = GetCalendar(calendar1);
            bool r = false;
            int  temp1;

            if (year <= c1.MaxSupportedDateTime.Year && year >= c1.MinSupportedDateTime.Year)
            {
                temp1 = c1.GetMonthsInYear(year);
                if (month >= 1 && month <= temp1)
                {
                    temp1 = c1.GetDaysInMonth(year, month);
                    if (day >= 1 && day <= temp1)
                    {
                        r = true;
                    }
                }
            }
            return(r);
        }
コード例 #6
0
ファイル: CalendarDriver.cs プロジェクト: GNOME/nemo
            public State(View current_view, DateTime current_selected)
            {
                calendar = new System.Globalization.GregorianCalendar();

                view = current_view;

                // FIXME: perhaps, let end time be current_selected

                if (view == View.Year)
                {
                    start_time = new System.DateTime(current_selected.Year, 1, 1);
                    end_time = new System.DateTime(current_selected.Year, 12, calendar.GetDaysInMonth(current_selected.Year, 12));
                }
                else if (view == View.Month)
                {
                    start_time = new System.DateTime(current_selected.Year, current_selected.Month, 1);
                    // always start a week on a monday
                    start_time -= new System.TimeSpan(days_from_monday(calendar.GetDayOfWeek(start_time)), 0, 0, 0);

                    end_time = new System.DateTime(current_selected.Year, current_selected.Month, calendar.GetDaysInMonth(current_selected.Year, current_selected.Month));
                    // always end a week on a sunday
                    end_time += new System.TimeSpan(days_til_monday(calendar.GetDayOfWeek(end_time)), 0, 0, 0);

                    //System.Console.WriteLine("setting start: {0} - {1}, end: {2} - {3}",
                    //start_time, calendar.GetDayOfWeek(start_time), end_time, calendar.GetDayOfWeek(end_time));
                }
                else if (view == View.Week)
                {
                    start_time = current_selected;
                    // always start a week on a monday
                    start_time -= new System.TimeSpan(days_from_monday(calendar.GetDayOfWeek(start_time)), 0, 0, 0);
                    start_time = new DateTime(start_time.Year, start_time.Month, start_time.Day); // set time to 12am

                    end_time = current_selected;
                    // always end a week on a sunday

                    end_time += new System.TimeSpan(days_til_monday(calendar.GetDayOfWeek(end_time)), 0, 0, 0);
                    end_time = new DateTime(end_time.Year, end_time.Month, end_time.Day); // set time to 12am
                }
                else if (view == View.Day)
                {
                    start_time = new DateTime(current_selected.Year, current_selected.Month, current_selected.Day); // set time to 12am

                    end_time = current_selected;
                    end_time += new System.TimeSpan(1, 0, 0, 0);
                    end_time = new DateTime(end_time.Year, end_time.Month, end_time.Day); // set time to 12am
                }
                else
                {
                    Debug.Assert(false);
                    // should never happen
                    start_time = current_selected;
                    end_time = current_selected;
                }

                Debug.Assert(start_time != end_time);
            }
コード例 #7
0
        protected override void Render(HtmlTextWriter writer)
        {
            try
            {
                DateTime tmpDate;
                try
                {
                    tmpDate = this.SelectedDate == "" ? DateTime.Now : Convert.ToDateTime(SelectedDate);
                }
                catch (Exception ex)
                {
                    tmpDate = DateTime.Now;
                }


                string temp = CssClass;
                CssClass = "";
                if (temp == "")
                {
                    temp = "ampicker";
                }
                writer.AddAttribute(HtmlTextWriterAttribute.Cellpadding, "0");
                writer.AddAttribute(HtmlTextWriterAttribute.Cellspacing, "0");
                writer.AddAttribute(HtmlTextWriterAttribute.Width, Width.ToString());
                writer.RenderBeginTag(HtmlTextWriterTag.Table);
                writer.RenderBeginTag(HtmlTextWriterTag.Tr);
                if (Text != "")
                {
                    writer.AddAttribute(HtmlTextWriterAttribute.Style, "white-space:nowrap");
                    writer.RenderBeginTag(HtmlTextWriterTag.Td);
                    writer.Write(Text);
                    writer.RenderEndTag();
                }
                writer.AddAttribute(HtmlTextWriterAttribute.Width, Width.ToString());
                writer.RenderBeginTag(HtmlTextWriterTag.Td);
                writer.AddAttribute("class", temp);
                writer.AddAttribute("id", ClientID);
                writer.AddAttribute("name", ClientID);
                writer.AddAttribute("onblur", "return window." + ClientID + ".onblur(this);");
                writer.AddAttribute("onkeypress", "return window." + ClientID + ".onlyDateChars(event);");
                //writer.AddAttribute("onkeydown", "return window." & Me.ClientID & ".KeyPress(event);")
                //writer.AddAttribute("onclick", "return window." & Me.ClientID & ".Click(event);showalert();")
                if (Enabled == false)
                {
                    writer.AddAttribute("disabled", "disabled");
                }
                if (ShowDateBox)
                {
                    writer.RenderBeginTag(HtmlTextWriterTag.Input);
                    writer.RenderEndTag();
                }
                dtFI = Thread.CurrentThread.CurrentCulture.DateTimeFormat;
                if (!(string.IsNullOrEmpty(SelectedDate)))
                {
                    DateTime dte = DateTime.Parse(SelectedDate);
                    SelectedDate = dte.ToString(dtFI.ShortDatePattern + " " + dtFI.ShortTimePattern);
                }
                writer.AddAttribute("type", "hidden");
                writer.AddAttribute("id", "hid_" + ClientID);
                writer.AddAttribute("name", "hid_" + ClientID);
                writer.AddAttribute("value", SelectedDate);
                writer.RenderBeginTag(HtmlTextWriterTag.Input);
                writer.RenderEndTag();
                writer.AddAttribute("id", "cal_" + ClientID);
                writer.AddAttribute("style", "display:none;position:absolute;");
                writer.RenderBeginTag(HtmlTextWriterTag.Div);
                writer.RenderEndTag();
                writer.RenderEndTag();
                writer.RenderBeginTag(HtmlTextWriterTag.Td);
                if (ImageUrl == string.Empty)
                {
                    ImageUrl = Page.ClientScript.GetWebResourceUrl(GetType(), "DotNetNuke.Modules.ActiveForums.CustomControls.Resources.calendar.gif");
                }
                if (Enabled)
                {
                    writer.AddAttribute("src", ImageUrl);
                    writer.AddAttribute("onclick", "window." + ClientID + ".Toggle(event);");
                    writer.AddAttribute("id", "img_" + ClientID);
                    writer.RenderBeginTag(HtmlTextWriterTag.Img);
                    writer.RenderEndTag();
                }
                writer.RenderEndTag();
                writer.RenderEndTag();
                writer.RenderEndTag();
                var str = new StringBuilder();
                str.Append("<script type=\"text/javascript\">");

                cal = new System.Globalization.GregorianCalendar();
                if (Thread.CurrentThread.CurrentCulture != null)
                {
                    cal = Thread.CurrentThread.CurrentCulture.Calendar;
                }
                DateFormat = dtFI.ShortDatePattern;
                TimeFormat = dtFI.ShortTimePattern;
                str.Append("window." + ClientID + "=new asDatePicker('" + ClientID + "');");
                str.Append("window." + ClientID + ".Locale='" + Context.Request.UserLanguages[0].Substring(0, 2).ToUpper() + "';");
                str.Append("window." + ClientID + ".SelectedDate='" + SelectedDate + "';");
                str.Append("window." + ClientID + ".Width='" + CalendarWidth + "';");
                str.Append("window." + ClientID + ".Height='" + CalendarHeight + "';");
                str.Append("window." + ClientID + ".DateFormat='" + dtFI.ShortDatePattern + "';");
                str.Append("window." + ClientID + ".TimeFormat='" + dtFI.ShortTimePattern + "';");
                str.Append("window." + ClientID + ".Year=" + tmpDate.Year + ";");
                str.Append("window." + ClientID + ".Month=" + (tmpDate.Month - 1) + ";");
                str.Append("window." + ClientID + ".Day=" + tmpDate.Day + ";");
                str.Append("window." + ClientID + ".SelectedYear=" + tmpDate.Year + ";");
                str.Append("window." + ClientID + ".SelectedMonth=" + (tmpDate.Month - 1) + ";");
                str.Append("window." + ClientID + ".SelectedDay=" + tmpDate.Day + ";");
                str.Append("window." + ClientID + ".ShowTime=" + ShowTime.ToString().ToLower() + ";");
                str.Append("window." + ClientID + ".DefaultTime='" + DefaultTime + "';");
                str.Append("window." + ClientID + ".CallbackFlag='" + CallbackFlag + "';");
                if (!(string.IsNullOrEmpty(RelatedControl)))
                {
                    Control ctl = Parent.FindControl(RelatedControl);
                    if (ctl == null)
                    {
                        ctl = Page.FindControl(RelatedControl);
                    }
                    if (ctl == null)
                    {
                        RelatedControl = string.Empty;
                    }
                    else
                    {
                        RelatedControl = ctl.ClientID;
                    }
                }
                str.Append("window." + ClientID + ".linkedControl='" + RelatedControl + "';");
                if (IsEndDate)
                {
                    str.Append("window." + ClientID + ".isEndDate=true;");
                }
                else
                {
                    str.Append("window." + ClientID + ".isEndDate=false;");
                }

                string sTime = string.Empty;
                SelectedTime = tmpDate.ToString(TimeFormat);
                if (ShowTime)
                {
                    if (SelectedTime != "12:00 AM")
                    {
                        sTime = SelectedTime;
                    }
                    if (TimeRequired)
                    {
                        str.Append("window." + ClientID + ".RequireTime=true;");
                    }
                    else
                    {
                        str.Append("window." + ClientID + ".RequireTime=false;");
                    }
                }
                else
                {
                    str.Append("window." + ClientID + ".RequireTime=false;");
                }

                str.Append("window." + ClientID + ".SelectedTime='" + sTime + "';");
                if (string.IsNullOrEmpty(ImgNext))
                {
                    str.Append("window." + ClientID + ".ImgNext='" + Page.ClientScript.GetWebResourceUrl(GetType(), "DotNetNuke.Modules.ActiveForums.CustomControls.Resources.cal_nextMonth.gif") + "';");
                }
                else
                {
                    str.Append("window." + ClientID + ".ImgNext='" + Page.ResolveUrl(ImgNext) + "';");
                }
                if (string.IsNullOrEmpty(ImgPrev))
                {
                    str.Append("window." + ClientID + ".ImgPrev='" + Page.ClientScript.GetWebResourceUrl(GetType(), "DotNetNuke.Modules.ActiveForums.CustomControls.Resources.cal_prevMonth.gif") + "';");
                }
                else
                {
                    str.Append("window." + ClientID + ".ImgPrev='" + Page.ResolveUrl(ImgPrev) + "';");
                }
                if (SelectedDate != "")
                {
                    try
                    {
                        if (ShowTime == false && sTime == string.Empty)
                        {
                            str.Append("window." + ClientID + ".textbox.value=new Date(" + tmpDate.Year + "," + (tmpDate.Month - 1) + "," + tmpDate.Day + ").formatDP('" + DateFormat + "','" + ClientID + "');");
                            str.Append("window." + ClientID + ".dateSel = new Date(" + tmpDate.Year + "," + (tmpDate.Month - 1) + "," + tmpDate.Day + ",0,0,0,0);");
                        }
                        else
                        {
                            str.Append("window." + ClientID + ".textbox.value=new Date(" + tmpDate.Year + "," + (tmpDate.Month - 1) + "," + tmpDate.Day + "," + tmpDate.Hour + "," + tmpDate.Minute + ",0).formatDP('" + DateFormat + " " + TimeFormat + "','" + ClientID + "');");
                            str.Append("window." + ClientID + ".dateSel = new Date(" + tmpDate.Year + "," + (tmpDate.Month - 1) + "," + tmpDate.Day + "," + tmpDate.Hour + "," + tmpDate.Minute + ",0);");
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                }
                int xMonths   = cal.GetMonthsInYear(cal.GetYear(tmpDate), cal.GetEra(tmpDate));
                int currMonth = cal.GetMonth(tmpDate);
                int currYear  = cal.GetYear(tmpDate);
                int currDay   = cal.GetDayOfMonth(tmpDate);

                str.Append("window." + ClientID + ".MonthDays = new Array(");
                for (int i = 0; i < xMonths; i++)
                {
                    str.Append(cal.GetDaysInMonth(currYear, i + 1));
                    if (i < (xMonths - 1))
                    {
                        str.Append(",");
                    }
                }
                str.Append(");");
                str.AppendLine();

                string[] mNames = dtFI.MonthNames;
                str.Append("window." + ClientID + ".MonthNames = new Array(");
                for (int i = 0; i < xMonths; i++)
                {
                    str.Append("'" + mNames[i] + "'");
                    if (i < (xMonths - 1))
                    {
                        str.Append(",");
                    }
                }
                str.Append(");");
                str.AppendLine();
                str.Append("window." + ClientID + ".ShortMonthNames = new Array(");
                string[] mAbbr = dtFI.AbbreviatedMonthNames;
                for (int i = 0; i < xMonths; i++)
                {
                    str.Append("'" + mAbbr[i] + "'");
                    if (i < (xMonths - 1))
                    {
                        str.Append(",");
                    }
                }
                str.Append(");");
                str.AppendLine();
                str.Append("window." + ClientID + ".ShortDayNames = new Array(");
                string[] dAbbr = dtFI.AbbreviatedDayNames;
                for (int i = 0; i <= 6; i++)
                {
                    str.Append("'" + dAbbr[i] + "'");
                    if (i < 6)
                    {
                        str.Append(",");
                    }
                }
                str.Append(");");
                str.AppendLine();

                str.Append("window." + ClientID + ".Class={");
                str.Append("CssCalendarStyle:'" + CssCalendarStyle + "',");
                str.Append("CssMonthStyle:'" + CssMonthStyle + "',");
                str.Append("CssWeekendStyle:'" + CssWeekendStyle + "',");
                str.Append("CssWeekdayStyle:'" + CssWeekdayStyle + "',");
                str.Append("CssSelectedDayStyle:'" + CssSelectedDayStyle + "',");
                str.Append("CssCurrentMonthDayStyle:'" + CssCurrentMonthDayStyle + "',");
                str.Append("CssOtherMonthDayStyle:'" + CssOtherMonthDayStyle + "',");
                str.Append("CssDayHeaderStyle:'" + CssDayHeaderStyle + "',");
                str.Append("CssCurrentDayStyle:'" + CssCurrentDayStyle + "'};");
                str.Append("window." + ClientID + ".selectedDate=window." + ClientID + ".textbox.value;");
                str.Append("window." + ClientID + ".timeLabel='[RESX:Time]';");



                str.Append("</script>");
                writer.Write(str);
            }
            catch (Exception ex)
            {
            }
        }