DotNetBar Schedule 加载数据库数据

运行结果展示
数据库结构及数据
using DBUtility;
using DevComponents.DotNetBar.Schedule;
using DevComponents.Schedule.Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TestDotNetBarSchedule
{
    public partial class Form1 : Form
    {
        public CalendarModel model = new CalendarModel();
        public Form1()
        {
            InitializeComponent();
            //calendarView1.CalendarModel.AppointmentAdded += new AppointmentEventHandler(ModelAppointmentAdded);
            //calendarView1.CalendarModel.AppointmentRemoved += new AppointmentEventHandler(ModelAppointmentRemoved);
            //calendarView1.AppointmentViewChanged += new EventHandler<AppointmentViewChangedEventArgs>(AppointmentViewChanged);
           // calendarView1.CalendarModel = new CalendarModel(); 
        }

        #region Handled events

        /// <summary>
        /// Event sent when an appointment is added to the Model
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void ModelAppointmentAdded(object sender, AppointmentEventArgs e)
        {
            Console.WriteLine(@"{0} New Appointment Added. Appointment Subject: {1}",
                DateTime.Now, e.Appointment.Subject);
        }

        /// <summary>
        /// Event sent when an appointment is removed from the Model
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void ModelAppointmentRemoved(object sender, AppointmentEventArgs e)
        {
            Console.WriteLine(@"{0} Appointment Removed. Appointment Subject: {1}",
                DateTime.Now, e.Appointment.Subject);
        }

        /// <summary>
        /// Event sent when an appointment is either moved or resized
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void AppointmentViewChanged(object sender, AppointmentViewChangedEventArgs e)
        {
            AppointmentView view = e.CalendarItem as AppointmentView;

            if (view != null)
            {
                string sOperation = (e.eViewOperation == eViewOperation.AppointmentMove)
                    ? "Moved" : "Resized";

                Console.WriteLine(@"{0} Appointment {1}. Appointment Subject: {2}",
                    DateTime.Now, sOperation, view.Appointment.Subject);
            }
        }
        #endregion

        private void Form1_Load(object sender, EventArgs e)
        {
            calendarView1.DisplayedOwners.Add("TrueBeam");
            ////CalendarModel model = new CalendarModel();

            ////calendarView1.CalendarModel = model;
            ListAppointment();
           // AddSampleAppointments();

        }

        private void calendarView1_SelectedViewChanged(object sender, DevComponents.DotNetBar.Schedule.SelectedViewEventArgs e)
        {
            switch (e.NewValue)
            {
                case eCalendarView.Day:
                    btnDay.Checked = true;
                    break;

                case eCalendarView.Week:
                    btnWeek.Checked = true;
                    break;

                case eCalendarView.Month:
                    btnMonth.Checked = true;
                    break;

                   
            }
        }

        private void btnDay_Click(object sender, EventArgs e)
        {
            calendarView1.SelectedView = eCalendarView.Day;
        }

        private void btnWeek_Click(object sender, EventArgs e)
        {
            calendarView1.SelectedView = eCalendarView.Week;
        }

        private void btnMonth_Click(object sender, EventArgs e)
        {
            calendarView1.SelectedView = eCalendarView.Month;
        }
//加载数据库数据
        private void ListAppointment()
        {
            calendarView1.CalendarModel.Appointments.Clear();
            string sql = "select subject, starttime, endtime, categorycolor,ownerkey,timemarkedas,occurrences from appointment";
            SqlDataReader dr = SQLHelper.GetReader(sql);
            Appointment item;
            while (dr.Read())
            {
                item = new Appointment
                {
                    Subject = dr["subject"].ToString(),
                    StartTime = Convert.ToDateTime(dr["starttime"].ToString()),
                    EndTime = Convert.ToDateTime(dr["endtime"].ToString()),
                    CategoryColor = dr["categorycolor"].ToString(),
                    OwnerKey = dr["ownerkey"].ToString(),
                    TimeMarkedAs = dr["timemarkedas"].ToString()
                };
                item.Recurrence = new AppointmentRecurrence();
                item.Recurrence.RecurrenceType = eRecurrencePatternType.Daily;
                item.Recurrence.Daily.RepeatOnDaysOfWeek = eDailyRecurrenceRepeat.WeekDays;
                item.Recurrence.Daily.RepeatInterval = 1;
                item.Recurrence.RangeLimitType = eRecurrenceRangeLimitType.RangeNumberOfOccurrences;
                item.Recurrence.RangeNumberOfOccurrences = Convert.ToInt32(dr["occurrences"]);
  
                item.DisplayTemplate = item.StartTime.ToString("t") + "-" + item.EndTime.ToString("t") + " | " + item.Subject;//个性化显示文本
                calendarView1.CalendarModel.Appointments.Add(item);
               
            }
            
        }

        //private void AddSampleAppointments()
        //{
        //    // Recurring appointment

        //    Appointment appointment = new Appointment();
        //    appointment.Subject = "Recurring Appointment every 3rd week day";
        //    appointment.Description = "Custom description for this appointment";
        //    appointment.Tooltip = "This is a Custom tooltip for this appointment";
        //    appointment.CategoryColor = Appointment.CategoryOrange;
        //    appointment.StartTime = DateTime.Today.AddHours(8.00);
        //    appointment.EndTime = appointment.StartTime.AddMinutes(10);
        //    appointment.OwnerKey = "TrueBeam";
        //    // Set recurrence type to Daily
        //    appointment.Recurrence = new AppointmentRecurrence();
        //    appointment.Recurrence.RecurrenceType = eRecurrencePatternType.Daily;
        //    appointment.Recurrence.Daily.RepeatOnDaysOfWeek = eDailyRecurrenceRepeat.WeekDays;
        //    appointment.Recurrence.Daily.RepeatInterval = 1;
        //    //appointment.Recurrence.RangeLimitType = eRecurrenceRangeLimitType.RangeEndDate;
        //    appointment.Recurrence.RangeLimitType = eRecurrenceRangeLimitType.RangeNumberOfOccurrences;
        //    //appointment.Recurrence.RangeEndDate = DateTime.Today.AddDays(3);
        //    appointment.Recurrence.RangeNumberOfOccurrences = 25;
        //    // Add appointment to the model
        //    calendarView1.CalendarModel.Appointments.Add(appointment);
           

        //}
    }
}
赞(0) 打赏
未经允许不得转载:TaKaSa » DotNetBar Schedule 加载数据库数据

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
  • Q Q(选填)

赞助下

支付宝扫一扫打赏

微信扫一扫打赏