public void AdvancedNormalizationWorks1()
        {
            DateTime now = DateTime.Now;

            PeriodCollection col = new PeriodCollection();

            col.Add(new Period(now.AddHours(31), now.AddHours(34)));
            col.Add(new Period(now.AddHours(16), now.AddHours(18)));
            col.Add(new Period(now.AddHours(2), now.AddHours(5)));
            col.Add(new Period(now.AddHours(27), now.AddHours(28)));
            col.Add(new Period(now, now.AddHours(1)));
            col.Add(new Period(now.AddHours(4), now.AddHours(7)));
            col.Add(new Period(now.AddHours(3), now.AddHours(4)));
            col.Add(new Period(now.AddHours(9), now.AddHours(11)));
            col.Add(new Period(now.AddHours(24), now.AddHours(26)));
            col.Add(new Period(now.AddHours(2), now.AddHours(5)));
            col.Add(new Period(now.AddHours(11), now.AddHours(13)));
            col.Add(new Period(now.AddHours(25), now.AddHours(32)));

            col.Normalize();

            Assert.AreEqual(5, col.Count);
            Assert.AreEqual(new Period(now, now.AddHours(1)), col[0]);
            Assert.AreEqual(new Period(now.AddHours(2), now.AddHours(7)), col[1]);
            Assert.AreEqual(new Period(now.AddHours(9), now.AddHours(13)), col[2]);
            Assert.AreEqual(new Period(now.AddHours(16), now.AddHours(18)), col[3]);
            Assert.AreEqual(new Period(now.AddHours(24), now.AddHours(34)), col[4]);
        }
示例#2
0
 public static DateTime DefaultDueDate(PeriodCollection periodCalendar)
 {
     if (periodCalendar.NextPeriod != null)
     {
         return periodCalendar.NextPeriod.LastDate;
     }
     return periodCalendar.Tomorrow;
 }
 public void InsertionWorks()
 {
     PeriodCollection col = new PeriodCollection();
     DateTime now = DateTime.Now;
     col.Add(new Period(now, now.AddHours(1)));
     col.Add(new Period(now.AddHours(2), now.AddHours(3)));
     Assert.AreEqual(2, col.Count);
     Assert.AreEqual(new Period(now, now.AddHours(1)), col[0]);
     Assert.AreEqual(new Period(now.AddHours(2), now.AddHours(3)), col[1]);
 }
 protected void btn_Cancel_Click(object sender, EventArgs e)
 {
     PeriodServiceClient _pclient = new PeriodServiceClient();
     Period _period = new PeriodCollection(_pclient.GetCurrentPeriod())[0];
     mp1.Hide();
     GetData(_period);
     //gv_Transaction.BackColor = System.Drawing.ColorTranslator.FromHtml("#FFFFFF");
     up_Edit.Update();
     if (Session["Rowindex"] != null)
         gv_Transaction.Rows[Convert.ToInt32(Session["Rowindex"])].BackColor = System.Drawing.ColorTranslator.FromHtml("#023e91");
 }
        public void NormalizationWorks()
        {
            DateTime now = DateTime.Now;

            PeriodCollection col = new PeriodCollection();

            col.Add(new Period(now.AddHours(2), now.AddHours(5)));
            col.Add(new Period(now, now.AddHours(1)));
            col.Add(new Period(now.AddHours(4), now.AddHours(7)));

            col.Normalize();

            Assert.AreEqual(2, col.Count);
            Assert.AreEqual(new Period(now, now.AddHours(1)), col[0]);
            Assert.AreEqual(new Period(now.AddHours(2), now.AddHours(7)), col[1]);
        }
示例#6
0
        /// <summary>
        /// This method is used to return all recurring instances between the two specified date/times based on
        /// the current settings.
        /// </summary>
        /// <param name="fromDate">The minimum date/time on or after which instances should occur.  This will
        /// include an instance if it starts before the date/time but overlaps it when its duration is added to
        /// its start time.</param>
        /// <param name="toDate">The maximum date/time on or before which instances should occur.  This will
        /// include an instance if it starts on or before the specified date/time regardless of its duration.</param>
        /// <param name="inLocalTime">If true, the date/time parameters are assumed to be in local time and the
        /// returned date/times are expressed in local time.  If false, the date/time parameters are assumed to
        /// be in the time zone of the object and the returned date/times are expressed in the time zone of the
        /// object as specified by the <see cref="TimeZoneId"/> property.  If no time zone ID has been specified
        /// or it cannot be found, local time is used.</param>
        /// <returns>Returns a <see cref="DateTimeInstanceCollection"/> containing <see cref="DateTimeInstance" />
        /// objects that represent all instances found between the two specified date/times.  Instances may have
        /// a different duration if created from an <c>RDATE</c> property.</returns>
        /// <exception cref="ArgumentException">This is thrown if a start date has not been specified (it equals
        /// <c>DateTime.MinValue</c>) or the duration is negative.</exception>
        /// <seealso cref="AllInstances"/>
        /// <seealso cref="OccursOn"/>
        public DateTimeInstanceCollection InstancesBetween(DateTime fromDate, DateTime toDate, bool inLocalTime)
        {
            DateTimeCollection recurDates;
            Period p;
            DateTime endDate, tempDate1 = DateTime.MaxValue, tempDate2;
            int idx, count;
            string timeZoneID = this.TimeZoneId;

            PeriodCollection periods = new PeriodCollection();
            DateTime startDate = this.StartDateTime.TimeZoneDateTime;
            Duration dur = this.InstanceDuration;

            if(startDate == DateTime.MinValue)
                throw new ArgumentException(LR.GetString("ExNoComponentStartDate"));

            if(dur.Ticks < 0)
                throw new ArgumentException(LR.GetString("ExRONegativeDuration"));

            // Convert fromDate and toDate to time zone time if inLocalTime is true.  Recurrences are always
            // resolved in the time of the object.
            if(inLocalTime && timeZoneID != null)
            {
                fromDate = VCalendar.LocalTimeToTimeZoneTime(fromDate, timeZoneID).StartDateTime;
                toDate = VCalendar.LocalTimeToTimeZoneTime(toDate, timeZoneID).StartDateTime;
            }

            // There might be instances that overlap the requested range so we'll adjust the From date/time by
            // the duration to catch them.
            if(dur.Ticks > 1)
                fromDate = fromDate.Add(new TimeSpan(0 - dur.Ticks + 1));

            // As per the spec, the start date/time is always included in the set but only if it (or it's
            // duration) is within the requested range.  However, if it is recurring and the custom Exclude Start
            // property is set to true, it is not added.
            p = new Period(startDate, dur);

            if(((p.StartDateTime >= fromDate && p.StartDateTime <= toDate) || (p.EndDateTime >= fromDate &&
              p.EndDateTime <= toDate)) && (!this.IsRecurring || !excludeStart))
            {
                periods.Add(p);
            }

            // If it isn't recurring or starts after the requested end date, just return the collection as it is
            if(this.IsRecurring && startDate <= toDate)
            {
                // Expand each recurrence rule
                foreach(RRuleProperty rr in this.RecurrenceRules)
                {
                    // If used, RecurUntil is stored in Universal Time which is converted to local time.  If a
                    // time zone ID is specified, convert it to that time zone temporarily to make sure things
                    // are calculated correctly.
                    if(rr.Recurrence.MaximumOccurrences == 0 && timeZoneID != null)
                    {
                        tempDate1 = rr.Recurrence.RecurUntil;
                        rr.Recurrence.RecurUntil = VCalendar.LocalTimeToTimeZoneTime(tempDate1, timeZoneID).StartDateTime;
                    }

                    rr.Recurrence.StartDateTime = startDate;
                    recurDates = rr.Recurrence.InstancesBetween(fromDate, toDate);

                    if(rr.Recurrence.MaximumOccurrences == 0 && timeZoneID != null)
                        rr.Recurrence.RecurUntil = tempDate1;

                    foreach(DateTime dt in recurDates)
                        periods.Add(new Period(dt, dur));
                }

                // Add on recurrence dates within the range
                foreach(RDateProperty rd in this.RecurDates)
                    if(rd.ValueLocation != ValLocValue.Period)
                    {
                        // If it's not a period, use the component's duration.  If it's only a date, assume it's
                        // the whole day.  The spec is not clear on this so I'm making a best guess.
                        if(rd.ValueLocation == ValLocValue.DateTime)
                            endDate = rd.TimeZoneDateTime.Add(dur.TimeSpan);
                        else
                            endDate = rd.TimeZoneDateTime.Add(new TimeSpan(TimeSpan.TicksPerDay));

                        if((rd.TimeZoneDateTime >= fromDate && rd.TimeZoneDateTime <= toDate) ||
                          (endDate >= fromDate && endDate <= toDate))
                        {
                            periods.Add(new Period(rd.TimeZoneDateTime, endDate));
                        }
                    }
                    else
                    {
                        // As with Recurrence.RecurUntil, the period values are in Universal Time so convert them
                        // to the time zone time for proper comparison.
                        tempDate1 = rd.PeriodValue.StartDateTime;
                        tempDate2 = rd.PeriodValue.EndDateTime;

                        if(timeZoneID != null)
                            tempDate1 = VCalendar.LocalTimeToTimeZoneTime(tempDate1, timeZoneID).StartDateTime;

                        if(timeZoneID != null)
                            tempDate2 = VCalendar.LocalTimeToTimeZoneTime(tempDate2, timeZoneID).StartDateTime;

                        if((tempDate1 >= fromDate && tempDate1 <= toDate) ||
                          (tempDate2 >= fromDate && tempDate2 <= toDate))
                        {
                            periods.Add(new Period(tempDate1, tempDate2));
                        }
                    }

                // Expand exception rules and filter out those instances
                count = periods.Count;

                foreach(RRuleProperty er in this.ExceptionRules)
                {
                    // Same as above
                    if(er.Recurrence.MaximumOccurrences == 0 && timeZoneID != null)
                    {
                        tempDate1 = er.Recurrence.RecurUntil;
                        er.Recurrence.RecurUntil = VCalendar.LocalTimeToTimeZoneTime(tempDate1, timeZoneID).StartDateTime;
                    }

                    er.Recurrence.StartDateTime = startDate;
                    recurDates = er.Recurrence.InstancesBetween(fromDate, toDate);

                    if(er.Recurrence.MaximumOccurrences == 0 && timeZoneID != null)
                        er.Recurrence.RecurUntil = tempDate1;

                    foreach(DateTime dt in recurDates)
                        for(idx = 0; idx < count; idx++)
                            if(periods[idx].StartDateTime == dt)
                            {
                                periods.RemoveAt(idx);
                                idx--;
                                count--;
                            }
                }

                // Filter out any exception dates
                foreach(ExDateProperty ed in this.ExceptionDates)
                {
                    DateTime dt = ed.TimeZoneDateTime;

                    // If it's only a date, assume it's the whole day and remove all instances on that day
                    // regardless of the time.  The spec is not clear on this so I'm making a best guess.
                    if(ed.ValueLocation == ValLocValue.DateTime)
                    {
                        if(dt >= fromDate && dt <= toDate)
                            for(idx = 0; idx < count; idx++)
                                if(periods[idx].StartDateTime == dt)
                                {
                                    periods.RemoveAt(idx);
                                    idx--;
                                    count--;
                                }
                    }
                    else
                        if(dt >= fromDate.Date && dt <= toDate.Date)
                            for(idx = 0; idx < count; idx++)
                                if(periods[idx].StartDateTime.Date == dt)
                                {
                                    periods.RemoveAt(idx);
                                    idx--;
                                    count--;
                                }
                }

                // Sort the periods and remove duplicates
                periods.Sort(true);

                for(idx = 1; idx < count; idx++)
                    if(periods[idx] == periods[idx - 1])
                    {
                        periods.RemoveAt(idx);
                        idx--;
                        count--;
                    }
            }

            // Now convert the periods to DateTimeInstances that include the necessary time zone information
            DateTimeInstanceCollection dtic = new DateTimeInstanceCollection();
            DateTimeInstance dti, dtiEnd;

            // Always in local time if there is no time zone ID
            if(timeZoneID == null)
                inLocalTime = true;

            foreach(Period pd in periods)
            {
                if(inLocalTime)
                {
                    dti = VCalendar.TimeZoneTimeToLocalTime(pd.StartDateTime, timeZoneID);
                    dtiEnd = VCalendar.TimeZoneTimeToLocalTime(pd.EndDateTime, timeZoneID);
                }
                else
                {
                    dti = VCalendar.TimeZoneTimeInfo(pd.StartDateTime, timeZoneID);
                    dtiEnd = VCalendar.TimeZoneTimeInfo(pd.EndDateTime, timeZoneID);
                }

                dti.Duration = pd.Duration;
                dti.EndDateTime = dtiEnd.EndDateTime;
                dti.EndIsDaylightSavingTime = dtiEnd.EndIsDaylightSavingTime;
                dti.EndTimeZoneName = dtiEnd.EndTimeZoneName;

                // If it already contains the entry and it is in DST, bump it forward an hour to account for the
                // time adjustment.  This will happen on hourly, minutely, and secondly recurrence patterns.  By
                // moving duplicates forward an hour, we retain the expected number of occurrences.
                if(!dtic.Contains(dti))
                    dtic.Add(dti);
                else
                    if(dti.StartIsDaylightSavingTime)
                    {
                        dti.StartDateTime = dti.StartDateTime.AddHours(1);
                        dti.EndDateTime = dti.EndDateTime.AddHours(1);
                        dtic.Add(dti);
                    }
            }

            return dtic;     // And finally, we are done
        }
        public void ANDSimple()
        {
            DateTime now = DateTime.Now;

            PeriodCollection left = new PeriodCollection();
            left.Add(new Period(now.AddHours(1), now.AddHours(3)));
            left.Add(new Period(now.AddHours(4), now.AddHours(7)));

            PeriodCollection right = new PeriodCollection();
            right.Add(new Period(now.AddHours(2), now.AddHours(3)));
            right.Add(new Period(now.AddHours(5), now.AddHours(8)));

            PeriodCollection res = PeriodCollection.AND(left, right);
            Assert.AreEqual(2, res.Count);
            Assert.AreEqual(new Period(now.AddHours(2), now.AddHours(3)), res[0]);
            Assert.AreEqual(new Period(now.AddHours(5), now.AddHours(7)), res[1]);
        }
        protected void gv_Transaction_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            GridViewRow row = (GridViewRow)((Control)e.CommandSource).NamingContainer;
            int id = Convert.ToInt32(gv_Transaction.DataKeys[row.RowIndex].Values[0]);
            string _FromEntityID =gv_Transaction.DataKeys[row.RowIndex].Values[1].ToString();
            string _ToEntityID = gv_Transaction.DataKeys[row.RowIndex].Values[2].ToString();

            using (DataEntryServiceClient _client = new DataEntryServiceClient())
            {
                PeriodServiceClient _pclient = new PeriodServiceClient();
                Period _period = new PeriodCollection(_pclient.GetCurrentPeriod())[0];
                if (e.CommandName.Equals("Btn_Notice"))
                {
                    _client.SetNotices(id, Convert.ToInt32(Session["Userid"]));
                    GetData(_period);

                }
                else if (e.CommandName.Equals("Btn_Confirm"))
                {
                    Transaction _tran = new TransactionCollection(_client.LoadTransactionByID(id))[0];
                    _tran.Updater.UserID = Convert.ToInt32(Session["Userid"]);
                    _tran.Period = _period;
                    _client.SetConfirm(_tran);
                    GetData(_period);

                }
                else if (e.CommandName.Equals("Btn_Edit"))
                {
                    Session["IsAdd"] = false;
                    tx_FromEntity.Text = gv_Transaction.Rows[row.RowIndex].Cells[0].Text ;
                    tx_ToEntity.Text = gv_Transaction.Rows[row.RowIndex].Cells[2].Text;
                    tx_Amount.Text = gv_Transaction.Rows[row.RowIndex].Cells[5].Text;
                    lb_FromEntityID.Text = _FromEntityID;
                    lb_ToEntityID.Text = _ToEntityID;
                    lb_FromCurrency.Text = gv_Transaction.Rows[row.RowIndex].Cells[1].Text;
                    lb_ToCurrency.Text = gv_Transaction.Rows[row.RowIndex].Cells[3].Text;
                    tx_ExchangeRate.Text = gv_Transaction.Rows[row.RowIndex].Cells[4].Text;
                    btn_Confirm.Text = "";
                    lb_ID.Text = id.ToString();
                    up_Edit.Update();
                    Session["Rowindex"] = row.RowIndex;
                    mp1.Show();

                }
                gv_Transaction.Rows[row.RowIndex].BackColor = System.Drawing.ColorTranslator.FromHtml("#023e91");
            }
        }
示例#9
0
    // sets up the statistics control
    private void CreateStatistics(Variable var, Station st, DateTime start, DateTime end, DataManager manager)
    {
        //TODO: eliminate double loading of periodCollection!!!
        PeriodCollection periods = new PeriodCollection(manager);
        periods.Load(var.Id, st.StationId);
        bool hasObservations = periods.HasObservations(new TimeInterval(start, end));

        if (hasObservations)
        {
            MeasuredTimeSeries ts = TimeSeriesFactory.CreateTimeSeries(new Sensor(st, var, start, end));
            ts.LoadObservations(manager);
            Statistics stats = new Statistics(ts);

            controls_statistics_window statControl = (controls_statistics_window) LoadControl("~/controls/statistics_window.ascx");
            statControl.Statistics = stats;
            statControl.Variable = var;
            statControl.Update();
            placeholder_statistics.Controls.Add(statControl);
        }
    }
示例#10
0
        private void CreateOneActivityLabel(DateTime idxDate, int dayNo, PeriodCollection col, Activity idxActivity, bool isActive)
        {
            Period curDayPeriod = new Period(idxDate, idxDate.AddHours(23).AddMinutes(59));
            Period curActivityPeriod = new Period(idxActivity.Start, idxActivity.End);
            if (Period.Intersects(curDayPeriod, curActivityPeriod))
            {
                Label actLbl = new Label
                {
                    ID = "act" + idxActivity.ID + "x" + idxDate.DayOfYear,
                    Xtra = idxActivity.ID.ToString()
                };
                actLbl.Style[Styles.opacity] = "0.7";
                actLbl.CssClass = "activity";
                if (curActivityPeriod.End.Date != idxDate.Date)
                    actLbl.CssClass += " actOpenBottom";
                if (curActivityPeriod.Start.Date != idxDate.Date)
                    actLbl.CssClass += " actOpenTop";
                curActivityPeriod = CalculatePositionOfActivity(dayNo, col, idxActivity, curActivityPeriod, actLbl, curDayPeriod);

                // Checking to see if this actuvity is "selected"...
                if (!string.IsNullOrEmpty(CurrentActivityLabel) && 
                    actLbl.ID.IndexOf(CurrentActivityLabel.Substring(0, CurrentActivityLabel.IndexOf("x") + 1)) == 0)
                {
                    actLbl.Style[Styles.width] = "80px";
                    actLbl.Style[Styles.opacity] = "1.0";
                    actLbl.CssClass = actLbl.CssClass.Replace("activity", "activitySelected");
                    actLbl.Style[Styles.zIndex] = (int.Parse(actLbl.Style[Styles.zIndex]) + 10).ToString();
                }

                SetTextAndTooltipOfActivity(idxActivity, actLbl);

                // Trapping Click event to "bring to front"...
                actLbl.Click += acctLbl_Click;

                actWrp.Controls.Add(actLbl);

                if (isActive)
                    BringActivityToFront(new List<Label>(new Label[] {actLbl}),
                                         actLbl.ID.Substring(0, actLbl.ID.IndexOf("x") + 1).Replace("act", "").Replace(
                                             "x", ""));
            }
            col.Add(curActivityPeriod);
        }
        public void ANDTwoLongLists()
        {
            DateTime now = DateTime.Now.Date;

            PeriodCollection left = new PeriodCollection();
            left.Add(new Period(now.AddHours(1), now.AddHours(3)));
            left.Add(new Period(now.AddHours(4), now.AddHours(7)));
            left.Add(new Period(now.AddHours(1), now.AddHours(3)));
            left.Add(new Period(now.AddHours(5), now.AddHours(6)));
            left.Add(new Period(now.AddHours(7), now.AddHours(8)));
            left.Add(new Period(now.AddHours(11), now.AddHours(13)));
            left.Add(new Period(now.AddHours(11), now.AddHours(12)));
            left.Add(new Period(now.AddHours(15), now.AddHours(16)));
            left.Add(new Period(now.AddHours(16), now.AddHours(17)));
            left.Add(new Period(now.AddHours(17), now.AddHours(20)));

            PeriodCollection right = new PeriodCollection();
            right.Add(new Period(now.AddHours(1), now.AddHours(3)));
            right.Add(new Period(now.AddHours(5), now.AddHours(6)));
            right.Add(new Period(now.AddHours(7), now.AddHours(10)));
            right.Add(new Period(now.AddHours(12), now.AddHours(15)));
            right.Add(new Period(now.AddHours(17), now.AddHours(25)));

            PeriodCollection res = PeriodCollection.AND(left, right);
            Assert.AreEqual(5, res.Count);
            Assert.AreEqual(new Period(now.AddHours(1), now.AddHours(3)), res[0]);
            Assert.AreEqual(new Period(now.AddHours(5), now.AddHours(6)), res[1]);
            Assert.AreEqual(new Period(now.AddHours(7), now.AddHours(8)), res[2]);
            Assert.AreEqual(new Period(now.AddHours(12), now.AddHours(13)), res[3]);
            Assert.AreEqual(new Period(now.AddHours(17), now.AddHours(20)), res[4]);
        }
        public void ANDTwoNonOverlappingLists()
        {
            DateTime now = DateTime.Now;

            PeriodCollection left = new PeriodCollection();
            left.Add(new Period(now.AddHours(1), now.AddHours(3)));
            left.Add(new Period(now.AddHours(4), now.AddHours(7)));

            PeriodCollection right = new PeriodCollection();
            right.Add(new Period(now.AddHours(9), now.AddHours(11)));
            right.Add(new Period(now.AddHours(12), now.AddHours(13)));

            PeriodCollection res = PeriodCollection.AND(left, right);
            Assert.AreEqual(0, res.Count);
        }
示例#13
0
        /// <summary>
        /// This method is used to return all recurring instances between the two specified date/times based on
        /// the current settings.
        /// </summary>
        /// <param name="fromDate">The minimum date/time on or after which instances should occur.  This will
        /// include an instance if it starts before the date/time but overlaps it when its duration is added to
        /// its start time.</param>
        /// <param name="toDate">The maximum date/time on or before which instances should occur.  This will
        /// include an instance if it starts on or before the specified date/time regardless of its duration.</param>
        /// <param name="inLocalTime">If true, the date/time parameters are assumed to be in local time and the
        /// returned date/times are expressed in local time.  If false, the date/time parameters are assumed to
        /// be in the time zone of the object and the returned date/times are expressed in the time zone of the
        /// object as specified by the <see cref="TimeZoneId"/> property.  If no time zone ID has been specified
        /// or it cannot be found, local time is used.</param>
        /// <returns>Returns a <see cref="DateTimeInstanceCollection"/> containing <see cref="DateTimeInstance" />
        /// objects that represent all instances found between the two specified date/times.  Instances may have
        /// a different duration if created from an <c>RDATE</c> property.</returns>
        /// <exception cref="ArgumentException">This is thrown if a start date has not been specified (it equals
        /// <c>DateTime.MinValue</c>) or the duration is negative.</exception>
        /// <seealso cref="AllInstances"/>
        /// <seealso cref="OccursOn"/>
        public DateTimeInstanceCollection InstancesBetween(DateTime fromDate, DateTime toDate, bool inLocalTime)
        {
            DateTimeCollection recurDates;
            Period             p;
            DateTime           endDate, tempDate1 = DateTime.MaxValue, tempDate2;
            int    idx, count;
            string timeZoneID = this.TimeZoneId;

            PeriodCollection periods   = new PeriodCollection();
            DateTime         startDate = this.StartDateTime.TimeZoneDateTime;
            Duration         dur       = this.InstanceDuration;

            if (startDate == DateTime.MinValue)
            {
                throw new ArgumentException(LR.GetString("ExNoComponentStartDate"));
            }

            if (dur.Ticks < 0)
            {
                throw new ArgumentException(LR.GetString("ExRONegativeDuration"));
            }

            // Convert fromDate and toDate to time zone time if inLocalTime is true.  Recurrences are always
            // resolved in the time of the object.
            if (inLocalTime && timeZoneID != null)
            {
                fromDate = VCalendar.LocalTimeToTimeZoneTime(fromDate, timeZoneID).StartDateTime;
                toDate   = VCalendar.LocalTimeToTimeZoneTime(toDate, timeZoneID).StartDateTime;
            }

            // There might be instances that overlap the requested range so we'll adjust the From date/time by
            // the duration to catch them.
            if (dur.Ticks > 1)
            {
                fromDate = fromDate.Add(new TimeSpan(0 - dur.Ticks + 1));
            }

            // As per the spec, the start date/time is always included in the set but only if it (or it's
            // duration) is within the requested range.  However, if it is recurring and the custom Exclude Start
            // property is set to true, it is not added.
            p = new Period(startDate, dur);

            if (((p.StartDateTime >= fromDate && p.StartDateTime <= toDate) || (p.EndDateTime >= fromDate &&
                                                                                p.EndDateTime <= toDate)) && (!this.IsRecurring || !this.ExcludeStartDateTime))
            {
                periods.Add(p);
            }

            // If it isn't recurring or starts after the requested end date, just return the collection as it is
            if (this.IsRecurring && startDate <= toDate)
            {
                // Expand each recurrence rule
                foreach (RRuleProperty rr in this.RecurrenceRules)
                {
                    // If used, RecurUntil is stored in Universal Time which is converted to local time.  If a
                    // time zone ID is specified, convert it to that time zone temporarily to make sure things
                    // are calculated correctly.
                    if (rr.Recurrence.MaximumOccurrences == 0 && timeZoneID != null)
                    {
                        tempDate1 = rr.Recurrence.RecurUntil;
                        rr.Recurrence.RecurUntil = VCalendar.LocalTimeToTimeZoneTime(tempDate1, timeZoneID).StartDateTime;
                    }

                    rr.Recurrence.StartDateTime = startDate;
                    recurDates = rr.Recurrence.InstancesBetween(fromDate, toDate);

                    if (rr.Recurrence.MaximumOccurrences == 0 && timeZoneID != null)
                    {
                        rr.Recurrence.RecurUntil = tempDate1;
                    }

                    foreach (DateTime dt in recurDates)
                    {
                        periods.Add(new Period(dt, dur));
                    }
                }

                // Add on recurrence dates within the range
                foreach (RDateProperty rd in this.RecurDates)
                {
                    if (rd.ValueLocation != ValLocValue.Period)
                    {
                        // If it's not a period, use the component's duration.  If it's only a date, assume it's
                        // the whole day.  The spec is not clear on this so I'm making a best guess.
                        if (rd.ValueLocation == ValLocValue.DateTime)
                        {
                            endDate = rd.TimeZoneDateTime.Add(dur.TimeSpan);
                        }
                        else
                        {
                            endDate = rd.TimeZoneDateTime.Add(new TimeSpan(TimeSpan.TicksPerDay));
                        }

                        if ((rd.TimeZoneDateTime >= fromDate && rd.TimeZoneDateTime <= toDate) ||
                            (endDate >= fromDate && endDate <= toDate))
                        {
                            periods.Add(new Period(rd.TimeZoneDateTime, endDate));
                        }
                    }
                    else
                    {
                        // As with Recurrence.RecurUntil, the period values are in Universal Time so convert them
                        // to the time zone time for proper comparison.
                        tempDate1 = rd.PeriodValue.StartDateTime;
                        tempDate2 = rd.PeriodValue.EndDateTime;

                        if (timeZoneID != null)
                        {
                            tempDate1 = VCalendar.LocalTimeToTimeZoneTime(tempDate1, timeZoneID).StartDateTime;
                        }

                        if (timeZoneID != null)
                        {
                            tempDate2 = VCalendar.LocalTimeToTimeZoneTime(tempDate2, timeZoneID).StartDateTime;
                        }

                        if ((tempDate1 >= fromDate && tempDate1 <= toDate) ||
                            (tempDate2 >= fromDate && tempDate2 <= toDate))
                        {
                            periods.Add(new Period(tempDate1, tempDate2));
                        }
                    }
                }

                // Expand exception rules and filter out those instances
                count = periods.Count;

                foreach (RRuleProperty er in this.ExceptionRules)
                {
                    // Same as above
                    if (er.Recurrence.MaximumOccurrences == 0 && timeZoneID != null)
                    {
                        tempDate1 = er.Recurrence.RecurUntil;
                        er.Recurrence.RecurUntil = VCalendar.LocalTimeToTimeZoneTime(tempDate1, timeZoneID).StartDateTime;
                    }

                    er.Recurrence.StartDateTime = startDate;
                    recurDates = er.Recurrence.InstancesBetween(fromDate, toDate);

                    if (er.Recurrence.MaximumOccurrences == 0 && timeZoneID != null)
                    {
                        er.Recurrence.RecurUntil = tempDate1;
                    }

                    foreach (DateTime dt in recurDates)
                    {
                        for (idx = 0; idx < count; idx++)
                        {
                            if (periods[idx].StartDateTime == dt)
                            {
                                periods.RemoveAt(idx);
                                idx--;
                                count--;
                            }
                        }
                    }
                }

                // Filter out any exception dates
                foreach (ExDateProperty ed in this.ExceptionDates)
                {
                    DateTime dt = ed.TimeZoneDateTime;

                    // If it's only a date, assume it's the whole day and remove all instances on that day
                    // regardless of the time.  The spec is not clear on this so I'm making a best guess.
                    if (ed.ValueLocation == ValLocValue.DateTime)
                    {
                        if (dt >= fromDate && dt <= toDate)
                        {
                            for (idx = 0; idx < count; idx++)
                            {
                                if (periods[idx].StartDateTime == dt)
                                {
                                    periods.RemoveAt(idx);
                                    idx--;
                                    count--;
                                }
                            }
                        }
                    }
                    else
                    if (dt >= fromDate.Date && dt <= toDate.Date)
                    {
                        for (idx = 0; idx < count; idx++)
                        {
                            if (periods[idx].StartDateTime.Date == dt)
                            {
                                periods.RemoveAt(idx);
                                idx--;
                                count--;
                            }
                        }
                    }
                }

                // Sort the periods and remove duplicates
                periods.Sort(true);

                for (idx = 1; idx < count; idx++)
                {
                    if (periods[idx] == periods[idx - 1])
                    {
                        periods.RemoveAt(idx);
                        idx--;
                        count--;
                    }
                }
            }

            // Now convert the periods to DateTimeInstances that include the necessary time zone information
            DateTimeInstanceCollection dtic = new DateTimeInstanceCollection();
            DateTimeInstance           dti, dtiEnd;

            // Always in local time if there is no time zone ID
            if (timeZoneID == null)
            {
                inLocalTime = true;
            }

            foreach (Period pd in periods)
            {
                if (inLocalTime)
                {
                    dti    = VCalendar.TimeZoneTimeToLocalTime(pd.StartDateTime, timeZoneID);
                    dtiEnd = VCalendar.TimeZoneTimeToLocalTime(pd.EndDateTime, timeZoneID);
                }
                else
                {
                    dti    = VCalendar.TimeZoneTimeInfo(pd.StartDateTime, timeZoneID);
                    dtiEnd = VCalendar.TimeZoneTimeInfo(pd.EndDateTime, timeZoneID);
                }

                dti.Duration                = pd.Duration;
                dti.EndDateTime             = dtiEnd.EndDateTime;
                dti.EndIsDaylightSavingTime = dtiEnd.EndIsDaylightSavingTime;
                dti.EndTimeZoneName         = dtiEnd.EndTimeZoneName;

                // If it already contains the entry and it is in DST, bump it forward an hour to account for the
                // time adjustment.  This will happen on hourly, minutely, and secondly recurrence patterns.  By
                // moving duplicates forward an hour, we retain the expected number of occurrences.
                if (!dtic.Contains(dti))
                {
                    dtic.Add(dti);
                }
                else
                if (dti.StartIsDaylightSavingTime)
                {
                    dti.StartDateTime = dti.StartDateTime.AddHours(1);
                    dti.EndDateTime   = dti.EndDateTime.AddHours(1);
                    dtic.Add(dti);
                }
            }

            return(dtic);     // And finally, we are done
        }
        protected void btn_Confirm_Click(object sender, EventArgs e)
        {
            CheckExchange();
            if (tx_FromEntity.Text.Equals("") || tx_ToEntity.Text.Equals(""))
            {
                Alert(" You have to select [ From cloumn ] or [ To Entity ] . ");
                return;
            }
            if (tx_Amount.Text.Equals(""))
            {
                Alert(" You have to key in To Amount . ");
                return;
            }
            if (tx_FromAmount.Text.Equals(""))
            {
                Alert(" You have to key in From Amount . ");
                return;
            }
            string regex = "^[0-9]{0,5}$|^[0-9]{0,5}\\.[0-9]{0,2}$ ";
            System.Text.RegularExpressions.RegexOptions options = ((System.Text.RegularExpressions.RegexOptions.IgnorePatternWhitespace | System.Text.RegularExpressions.RegexOptions.Multiline)
            | System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex(regex, options);
            if (!reg.IsMatch(tx_Amount.Text))
            {
                Alert(" Please check Amount column . ");
                return;
            }
            using (DataEntryServiceClient _client = new DataEntryServiceClient())
            {
                PeriodServiceClient _pclient = new PeriodServiceClient();
                Period _period = new PeriodCollection(_pclient.GetCurrentPeriod())[0];

                int _FromEntityID = Convert.ToInt32(lb_FromEntityID.Text);
                int _ToEntityID = Convert.ToInt32(lb_ToEntityID.Text);
                decimal _Amount = Convert.ToDecimal(tx_Amount.Text);
                decimal _FromAmount = Convert.ToDecimal(tx_FromAmount.Text);
                if ((bool)Session["IsAdd"])
                {
                    Transaction _tran = new Transaction();
                    _tran.Period.ID = _period.ID;
                    _tran.IsPay = IsPay.N;
                    _tran.Creator.UserID = Convert.ToInt32(Session["Userid"]);
                    _tran.Amount = _FromAmount;
                    _tran.FromEntity.EntityID = _FromEntityID;
                    _tran.ToEntity.EntityID = _ToEntityID;
                    _tran.FromCurrency = lb_FromCurrency.Text;
                    _tran.ToCurrency = lb_ToCurrency.Text;
                    _tran.ExchangeRate = Convert.ToDecimal(tx_ExchangeRate.Text);
                    _tran.To_Amount = _Amount;
                    _client.InsertTransaction(_tran);
                    mp1.Hide();
                    GetData(_period);
                }
                else
                {
                    Transaction _tran = new TransactionCollection(_client.LoadTransactionByID(Convert.ToInt32(lb_ID.Text)))[0];
                    _tran.FromEntity.EntityID = _FromEntityID;
                    _tran.ToEntity.EntityID = _ToEntityID;
                    _tran.Amount = _FromAmount;
                    _tran.To_Amount = _Amount;
                    _tran.FromCurrency = lb_FromCurrency.Text;
                    _tran.ToCurrency = lb_ToCurrency.Text;
                    _tran.ExchangeRate = Convert.ToDecimal(tx_ExchangeRate.Text);
                    _client.Updatetransaction(_tran);
                    mp1.Hide();
                    GetData(_period);

                }
            }
            if(Session["Rowindex"]!=null)
                gv_Transaction.Rows[Convert.ToInt32(Session["Rowindex"])].BackColor = System.Drawing.ColorTranslator.FromHtml("#023e91");
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            //ToDo
            CheckLimit.CheckPage(Request["menuid"]);
            tx_FromEntity.Attributes.Add("readonly","true");
            tx_ToEntity.Attributes.Add("readonly", "true");
            tx_Amount.Attributes.Add("OnKeyPress", "txtKeyNumber();");
            if (!IsPostBack)
            {
                Session["IsAdd"] = false;
                Session["Rowindex"] = null;
                //tree
                BindTree();
                PeriodServiceClient _pclient = new PeriodServiceClient();
                Period _period = new PeriodCollection(_pclient.GetCurrentPeriod())[0];
                GetData(_period);

            }
        }
        public void ANDOneBigSpanAndLargeList()
        {
            DateTime now = DateTime.Now.Date;

            PeriodCollection left = new PeriodCollection();
            left.Add(new Period(now.AddHours(22), now.AddHours(27)));
            left.Add(new Period(now.AddHours(1), now.AddHours(3)));
            left.Add(new Period(now.AddHours(4), now.AddHours(7)));
            left.Add(new Period(now.AddHours(11), now.AddHours(13)));
            left.Add(new Period(now.AddHours(11), now.AddHours(12)));
            left.Add(new Period(now.AddHours(17), now.AddHours(20)));
            left.Add(new Period(now.AddHours(21), now.AddHours(23)));
            left.Add(new Period(now.AddHours(22), now.AddHours(23)));
            left.Add(new Period(now.AddHours(15), now.AddHours(16)));
            left.Add(new Period(now.AddHours(16), now.AddHours(17)));
            left.Add(new Period(now.AddHours(1), now.AddHours(3)));
            left.Add(new Period(now.AddHours(5), now.AddHours(6)));
            left.Add(new Period(now.AddHours(7), now.AddHours(8)));
            left.Add(new Period(now.AddHours(16), now.AddHours(17)));
            PeriodCollection expected = new PeriodCollection(left);
            expected.Normalize();

            PeriodCollection right = new PeriodCollection();
            right.Add(new Period(now.AddHours(1), now.AddHours(30)));

            PeriodCollection res = PeriodCollection.AND(right, left);
            Assert.AreEqual(expected.Count, res.Count);
            for (int idx = 0; idx < expected.Count; idx++)
            {
                Assert.AreEqual(expected[idx], res[idx]);
            }
        }
示例#17
0
        private void PopulateCalendarWithActivities(int activeID)
        {
            // Retrieving activites from Database...
            _activities = FillActivities();

            // Creating start, end and index values
            DateTime start = FirstDate;
            DateTime idxDate = start;
            DateTime endDate = start.AddDays(7);
            int dayNo = 0;

            // Looping through all the days we want to display
            while (idxDate < endDate)
            {
                PeriodCollection col = new PeriodCollection();
                foreach (Activity idxActivity in _activities)
                {
                    CreateOneActivityLabel(idxDate, dayNo, col, idxActivity, idxActivity.ID == activeID);
                }
                idxDate = idxDate.AddDays(1);
                dayNo += 1;
            }
        }
        public void NOTTest()
        {
            DateTime now = DateTime.Now.Date;

            PeriodCollection left = new PeriodCollection();
            left.Add(new Period(now.AddHours(22), now.AddHours(27)));
            left.Add(new Period(now.AddHours(1), now.AddHours(3)));
            left.Add(new Period(now.AddHours(4), now.AddHours(7)));
            left.Add(new Period(now.AddHours(11), now.AddHours(13)));
            left.Add(new Period(now.AddHours(11), now.AddHours(12)));
            left.Add(new Period(now.AddHours(17), now.AddHours(20)));
            left.Add(new Period(now.AddHours(21), now.AddHours(23)));
            left.Add(new Period(now.AddHours(22), now.AddHours(23)));
            left.Add(new Period(now.AddHours(15), now.AddHours(16)));
            left.Add(new Period(now.AddHours(16), now.AddHours(17)));
            left.Add(new Period(now.AddHours(1), now.AddHours(3)));
            left.Add(new Period(now.AddHours(5), now.AddHours(6)));
            left.Add(new Period(now.AddHours(7), now.AddHours(8)));
            left.Add(new Period(now.AddHours(16), now.AddHours(17)));
            PeriodCollection expected = new PeriodCollection(left);
            expected.Normalize();

            PeriodCollection res = left.NOT();

            Assert.AreEqual(expected.Count + 1, res.Count);

            PeriodCollection res2 = res.NOT();
            Assert.AreEqual(expected.Count, res2.Count);
            for (int idx = 0; idx < res2.Count; idx++)
            {
                Assert.AreEqual(expected[idx], res2[idx]);
            }
        }
示例#19
0
 private bool CheckHourlyPrecipAvailable(Variable var, Station st, DateTime start, DateTime end, DataManager manager)
 {
     Variable tmpVar = new Variable(VariableEnum.PrecipHour);
     PeriodCollection periods = new PeriodCollection(manager);
     TimeInterval interval = new TimeInterval(start, end);
     periods.Load(st.StationId, tmpVar.Id, interval);
     if ( periods.Count > 0 )
     {
         return periods.HasObservations(interval);
     }
     else
     {
         return false;
     }
 }
        public void XORTest()
        {
            DateTime now = DateTime.Now.Date;

            PeriodCollection left = new PeriodCollection();
            left.Add(new Period(now.AddHours(1), now.AddHours(5)));
            left.Add(new Period(now.AddHours(7), now.AddHours(9)));
            left.Add(new Period(now.AddHours(11), now.AddHours(20)));

            PeriodCollection right = new PeriodCollection();
            right.Add(new Period(now.AddHours(0), now.AddHours(2)));
            right.Add(new Period(now.AddHours(4), now.AddHours(6)));
            right.Add(new Period(now.AddHours(8), now.AddHours(9)));
            right.Add(new Period(now.AddHours(13), now.AddHours(14)));
            right.Add(new Period(now.AddHours(17), now.AddHours(20)));

            PeriodCollection XOR = PeriodCollection.XOR(left, right);
            Assert.AreEqual(6, XOR.Count);
            Assert.AreEqual(new Period(now.AddHours(0), now.AddHours(1)), XOR[0]);
            Assert.AreEqual(new Period(now.AddHours(2), now.AddHours(4)), XOR[1]);
            Assert.AreEqual(new Period(now.AddHours(5), now.AddHours(6)), XOR[2]);
            Assert.AreEqual(new Period(now.AddHours(7), now.AddHours(8)), XOR[3]);
            Assert.AreEqual(new Period(now.AddHours(11), now.AddHours(13)), XOR[4]);
            Assert.AreEqual(new Period(now.AddHours(14), now.AddHours(17)), XOR[5]);
        }
        public WeeklySummaryCollection QuerybyPeriod(int periodID)
        {
            WeeklySummaryCollection collection = new WeeklySummaryCollection();
            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                SqlCommand command = new SqlCommand();
                command.Connection = connection;
                command.CommandText = "SP_SEL_Table";
                SqlParameter _param = command.Parameters.Add("@value1", System.Data.SqlDbType.VarChar);
                _param.Value = "Weekly_Summary";
                SqlParameter _param2 = command.Parameters.Add("@value2", System.Data.SqlDbType.VarChar);
                _param2.Value = "1";
                SqlParameter _param3 = command.Parameters.Add("@value3", System.Data.SqlDbType.VarChar);
                _param3.Value = periodID;
                SqlParameter _param4 = command.Parameters.Add("@order_by1", System.Data.SqlDbType.VarChar);
                _param4.Value = "1";
                SqlParameter _param5 = command.Parameters.Add("@order_by2", System.Data.SqlDbType.TinyInt);
                _param5.Value = 0;
                command.CommandType = System.Data.CommandType.StoredProcedure;
                connection.Open();
                SqlDataReader reader = command.ExecuteReader();
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        WeeklySummary _week = new WeeklySummary();
                        PeriodCollection _periodc = new PeriodCollection();
                        PeriodAccess _perioda = new PeriodAccess();
                        _periodc = _perioda.Query(Convert.ToInt32(reader["Period_ID"]));
                        _week.Period = _periodc[0];

                        EntityCollection _entityc = new EntityCollection();
                        EntityAccess _entity = new EntityAccess();
                        _entityc = _entity.Query(Convert.ToInt32(reader["Entity_Id"]));
                        _week.Entity = _entityc[0];

                        _week.BaseCurrency = reader["Base_Currency"].ToString();
                        _week.ExchangeRate = Convert.ToDecimal(reader["Exchange_Rate"].ToString());
                        _week.BasePrevBalance = Convert.ToDecimal(reader["Base_Prev_Balance"].ToString());
                        _week.SGDPrevBalance = Convert.ToDecimal(reader["SGD_Prev_Balance"].ToString());
                        _week.BaseWinAndLoss = Convert.ToDecimal(reader["Base_Win_Lose"].ToString());
                        _week.SGDWinAndLoss = Convert.ToDecimal(reader["SGD_Win_Lose"].ToString());
                        _week.BaseTransfer = Convert.ToDecimal(reader["Base_Transfer"].ToString());
                        _week.SGDTransfer = Convert.ToDecimal(reader["SGD_Transfer"].ToString());
                        _week.BaseTransaction = Convert.ToDecimal(reader["Base_Transaction"].ToString());
                        _week.SGDTransaction = Convert.ToDecimal(reader["SGD_Transaction"].ToString());
                        _week.BaseBalance = Convert.ToDecimal(reader["Base_Balance"].ToString());
                        _week.SGDBalance = Convert.ToDecimal(reader["SGD_Balance"].ToString());
                        _week.Status = (WeeklySummaryStatus)Convert.ToInt32(reader["Status"].ToString());
                        try
                        {
                            UserAccess usera = new UserAccess();
                            _week.ConfirmUser = new UserCollection(usera.Query(Convert.ToInt32(reader["Confirm_User"])))[0];
                        }
                        catch
                        {
                            _week.ConfirmUser = new User();
                        }
                        collection.Add(_week);
                    }
                }
                reader.Close();
                return collection;
            }
        }
        protected void btn_Search_Click(object sender, EventArgs e)
        {
            Period _period = new Period();
            if(tx_Period.Text.Equals(""))
                GetData(_period);
            else
            {
                PeriodServiceClient _pclient = new PeriodServiceClient();
                try
                {
                    _period = new PeriodCollection(_pclient.DateOfPeriod(tx_Period.Text))[0];
                    GetData(_period);
                }
                catch (Exception)
                {
                    throw;
                }

            }
        }