示例#1
0
        int BuildSlices(out string strError)
        {
            strError = "";

            this.m_timeSlices = new List<TimeSlice>();
            if (this.comboBox_slice.Text == "<不切片>")
            {
                // 只有一片
                TimeSlice slice = new TimeSlice();
                slice.Start = this.StartTime;
                slice.Length = this.EndTime - this.StartTime;
                slice.Caption = DateTimeUtil.ToDateString(slice.Start) + "-" + DateTimeUtil.ToDateString(slice.Start + slice.Length);
                this.m_timeSlices.Add(slice);
                return 0;
            }

            if (this.comboBox_slice.Text == "日")
            {
                DateTime start = this.StartTime;
                DateTime end = this.EndTime;
                for (; ; )
                {
                    if (start >= end)
                        break;
                    TimeSlice slice = new TimeSlice();
                    slice.Start = start;
                    slice.Length = new TimeSpan(1, 0, 0, 0);
                    slice.Caption = DateTimeUtil.ToDateString(slice.Start);
                    if (start.Day == 1)
                        slice.Style = "dark";   // 每月第一日加重背景显示
                    this.m_timeSlices.Add(slice);

                    start += new TimeSpan(1, 0, 0, 0);
                }

                return 0;
            }

            if (this.comboBox_slice.Text == "月")
            {
                DateTime start = this.StartTime;
                // 校正为整月第一天
                start = new DateTime(start.Year, start.Month, 1);
                DateTime end = this.EndTime;
                for (; ; )
                {
                    if (start >= end)
                        break;
                    DateTime end_month;
                    if (start.Month == 12)
                        end_month = new DateTime(start.Year+1, 1, 1);
                    else
                        end_month = new DateTime(start.Year, start.Month+1, 1);

                    TimeSlice slice = new TimeSlice();
                    slice.Start = start;
                    slice.Length = end_month - start;
                    slice.Caption = DateTimeUtil.ToMonthString(slice.Start);
                    if (start.Month == 1)
                        slice.Style = "dark";   // 每年第一个月加重背景显示
                    this.m_timeSlices.Add(slice);

                    start = end_month;
                }

                return 0;
            }

            if (this.comboBox_slice.Text == "年")
            {
                DateTime start = this.StartTime;
                // 校正为整年第一天
                start = new DateTime(start.Year, 1, 1);
                DateTime end = this.EndTime;
                for (; ; )
                {
                    if (start >= end)
                        break;
                    DateTime end_year = new DateTime(start.Year + 1, 1, 1);

                    TimeSlice slice = new TimeSlice();
                    slice.Start = start;
                    slice.Length = end_year - start;
                    slice.Caption = DateTimeUtil.ToYearString(slice.Start);
                    this.m_timeSlices.Add(slice);

                    start = end_year;
                }

                return 0;
            }

            strError = "无法识别的时间间隔 '" + this.comboBox_slice.Text + "'";
            return -1;
        }
示例#2
0
        int BuildSlices(out string strError)
        {
            strError = "";

            this.m_timeSlices = new List <TimeSlice>();
            if (this.comboBox_slice.Text == "<不切片>")
            {
                // 只有一片
                TimeSlice slice = new TimeSlice();
                slice.Start   = this.StartTime;
                slice.Length  = this.EndTime - this.StartTime;
                slice.Caption = DateTimeUtil.ToDateString(slice.Start) + "-" + DateTimeUtil.ToDateString(slice.Start + slice.Length);
                this.m_timeSlices.Add(slice);
                return(0);
            }

            if (this.comboBox_slice.Text == "日")
            {
                DateTime start = this.StartTime;
                DateTime end   = this.EndTime;
                for (; ;)
                {
                    if (start >= end)
                    {
                        break;
                    }
                    TimeSlice slice = new TimeSlice();
                    slice.Start   = start;
                    slice.Length  = new TimeSpan(1, 0, 0, 0);
                    slice.Caption = DateTimeUtil.ToDateString(slice.Start);
                    if (start.Day == 1)
                    {
                        slice.Style = "dark";   // 每月第一日加重背景显示
                    }
                    this.m_timeSlices.Add(slice);

                    start += new TimeSpan(1, 0, 0, 0);
                }

                return(0);
            }

            if (this.comboBox_slice.Text == "月")
            {
                DateTime start = this.StartTime;
                // 校正为整月第一天
                start = new DateTime(start.Year, start.Month, 1);
                DateTime end = this.EndTime;
                for (; ;)
                {
                    if (start >= end)
                    {
                        break;
                    }
                    DateTime end_month;
                    if (start.Month == 12)
                    {
                        end_month = new DateTime(start.Year + 1, 1, 1);
                    }
                    else
                    {
                        end_month = new DateTime(start.Year, start.Month + 1, 1);
                    }

                    TimeSlice slice = new TimeSlice();
                    slice.Start   = start;
                    slice.Length  = end_month - start;
                    slice.Caption = DateTimeUtil.ToMonthString(slice.Start);
                    if (start.Month == 1)
                    {
                        slice.Style = "dark";   // 每年第一个月加重背景显示
                    }
                    this.m_timeSlices.Add(slice);

                    start = end_month;
                }

                return(0);
            }

            if (this.comboBox_slice.Text == "年")
            {
                DateTime start = this.StartTime;
                // 校正为整年第一天
                start = new DateTime(start.Year, 1, 1);
                DateTime end = this.EndTime;
                for (; ;)
                {
                    if (start >= end)
                    {
                        break;
                    }
                    DateTime end_year = new DateTime(start.Year + 1, 1, 1);

                    TimeSlice slice = new TimeSlice();
                    slice.Start   = start;
                    slice.Length  = end_year - start;
                    slice.Caption = DateTimeUtil.ToYearString(slice.Start);
                    this.m_timeSlices.Add(slice);

                    start = end_year;
                }

                return(0);
            }

            strError = "无法识别的时间间隔 '" + this.comboBox_slice.Text + "'";
            return(-1);
        }