Devexpress Scheduler 使用详解

1.数据库创建

2.实体类

(1)Appointment 实体类

#region #customappointment
    public class CustomAppointment {
        public DateTime StartTime { get; set; }
        public DateTime EndTime { get; set; }
        public string Subject { get; set; }
        public int Status { get; set; }
        public string Description { get; set; }
        public int Label { get; set; }
        public string Location { get; set; }
        public bool AllDay { get; set; }
        public int EventType { get; set; }
        public string RecurrenceInfo { get; set; }
        public string ReminderInfo { get; set; }
        public object OwnerId { get; set; }

        public byte[] Icon1 { get; set; }
        public byte[] Icon2 { get; set; }

        public string AdditionalInfo { get; set; }
    }
    #endregion  #customappointment

(2)Resource 实体类

#region #customresource
    public class CustomResource {
        public string Name { get; set; }
        public int ResID { get; set; }
        public System.Drawing.Color ResColor { get; set; }
        // To display resources using the specified color set the SchedulerStorage.Resources.ColorSaving property to ColorSavingType.Color.
    }
    #endregion #customresource

3.数据绑定

(1)Appointment 绑定

        #region #initappointments
        private void InitAppointments() {
            AppointmentMappingInfo mappings = this.schedulerStorage1.Appointments.Mappings;
            mappings.Start = "StartTime";
            mappings.End = "EndTime";
            mappings.Subject = "Subject";
            mappings.AllDay = "AllDay";
            mappings.Description = "Description";
            mappings.Label = "Label";
            mappings.Location = "Location";
            mappings.RecurrenceInfo = "RecurrenceInfo";
            mappings.ReminderInfo = "ReminderInfo";
            mappings.ResourceId = "OwnerId";
            mappings.Status = "Status";
            mappings.Type = "EventType";            

            schedulerStorage1.Appointments.CustomFieldMappings.Add(new AppointmentCustomFieldMapping("ApptImage1", "Icon1", FieldValueType.Object));
            schedulerStorage1.Appointments.CustomFieldMappings.Add(new AppointmentCustomFieldMapping("ApptImage2", "Icon2", FieldValueType.Object));
            schedulerStorage1.Appointments.CustomFieldMappings.Add(new AppointmentCustomFieldMapping("ApptAddInfo", "AdditionalInfo", FieldValueType.String));

            GenerateEvents(CustomEventList, 3);
        }
        #endregion #initappointments

private void GenerateEvents(List<CustomAppointment> eventList, int count) {

            for(int i = 0; i < count; i++) {
                CustomResource c_Resource = CustomResourceCollection[i];
                string subjPrefix = c_Resource.Name + "'s ";
                Assembly currentAssembly = System.Reflection.Assembly.GetExecutingAssembly();

                eventList.Add(CreateEvent(subjPrefix + "meeting", "The meeting will be held in the Conference Room", c_Resource.ResID, 2, 5, 14, currentAssembly.GetManifestResourceStream("CustomAppointmentImageAndText.Images.BOCustomer_16x16.png"), currentAssembly.GetManifestResourceStream("CustomAppointmentImageAndText.Images.Project_32x32.png")));
                eventList.Add(CreateEvent(subjPrefix + "travel", "Book a hotel in advance", c_Resource.ResID, 3, 6, 10, currentAssembly.GetManifestResourceStream("CustomAppointmentImageAndText.Images.Country_16x16.png"), currentAssembly.GetManifestResourceStream("CustomAppointmentImageAndText.Images.BOChangeHistory_32x32.png")));
                eventList.Add(CreateEvent(subjPrefix + "phone call", "Important phone call", c_Resource.ResID, 0, 4, 16, currentAssembly.GetManifestResourceStream("CustomAppointmentImageAndText.Images.BOContact_16x16.png"), currentAssembly.GetManifestResourceStream("CustomAppointmentImageAndText.Images.EditTask_32x32.png")));
            }
        }

(2)Resource 绑定

private void InitResources() {
            ResourceMappingInfo mappings = this.schedulerStorage1.Resources.Mappings;
            mappings.Id = "ResID";
            mappings.Caption = "Name";
            mappings.Color = "ResColor";

            CustomResourceCollection.Add(CreateCustomResource(1, "Max Fowler", Color.PowderBlue));
            CustomResourceCollection.Add(CreateCustomResource(2, "Nancy Drewmore", Color.PaleVioletRed));
            CustomResourceCollection.Add(CreateCustomResource(3, "Pak Jang", Color.PeachPuff));
        }

        private CustomResource CreateCustomResource(int res_id, string caption, Color resColor) {
            CustomResource cr = new CustomResource();
            cr.ResID = res_id;
            cr.Name = caption;
            cr.ResColor = resColor;
            return cr;
        }

private CustomAppointment CreateEvent(string subject, string additionalInfo, object resourceId, int status, int label, int sHour, Stream icon1, Stream icon2) {
            CustomAppointment apt = new CustomAppointment();
            apt.Subject = subject;
            apt.OwnerId = resourceId;
            Random rnd = RandomInstance;

            apt.StartTime = DateTime.Today.AddHours(sHour);
            apt.EndTime = apt.StartTime.AddHours(1);
            apt.Status = status;
            apt.Label = label;

            using(MemoryStream ms = new MemoryStream()) {
                icon1.CopyTo(ms);
                apt.Icon1 = ms.ToArray();
            }
            using(MemoryStream ms = new MemoryStream()) {
                icon2.CopyTo(ms);
                apt.Icon2 = ms.ToArray();
            }

            apt.AdditionalInfo = additionalInfo;
            return apt;
        }

自定义文本显示及图像的显示

private void schedulerControl1_InitAppointmentImages(object sender, AppointmentImagesEventArgs e) {
            if (e.Appointment.CustomFields["ApptImage1"] != null) {
                byte[] imageBytes = (byte[])e.Appointment.CustomFields["ApptImage1"];
                if (imageBytes != null) {
                    AppointmentImageInfo info = new AppointmentImageInfo();
                    using (MemoryStream ms = new MemoryStream(imageBytes)) {
                        info.Image = Image.FromStream(ms);
                        e.ImageInfoList.Add(info);
                    }
                }
            }

            if (e.Appointment.CustomFields["ApptImage2"] != null) {
                byte[] imageBytes = (byte[])e.Appointment.CustomFields["ApptImage2"];
                if (imageBytes != null) {
                    AppointmentImageInfo info = new AppointmentImageInfo();
                    using (MemoryStream ms = new MemoryStream(imageBytes)) {
                        info.Image = Image.FromStream(ms);
                        e.ImageInfoList.Add(info);
                    }
                }
            }
        }
        #endregion #initappointmentimages

        #region #initappointmentdisplaytext

private void schedulerControl1_InitAppointmentDisplayText(object sender, AppointmentDisplayTextEventArgs e) {
            // Display custom text in Day and WorkWeek views only (VerticalAppointmentViewInfo).
            if (e.ViewInfo is VerticalAppointmentViewInfo && e.Appointment.CustomFields["ApptAddInfo"] != null) {
                e.Text = e.Appointment.Subject + "\r\n";
                e.Text += "------\r\n";
                e.Text += e.Appointment.CustomFields["ApptAddInfo"].ToString();
            }
        }
        #endregion #initappointmentdisplaytext
赞(0)
未经允许不得转载:TaKaSa » Devexpress Scheduler 使用详解