每年的时间轴视图(DeveExpress控件)

时间:2019-01-17 16:27:21

标签: c# winforms devexpress scheduler

我正在尝试将时间轴控件用作screenshot。 我使用此代码,但实际上我不知道问题出在哪里,导致它起作用。

public CollectionView()
    {
        InitializeComponent();

        schedulerControl1.Start = new DateTime(2009, 1, 1);
        schedulerControl1.TimelineView.Scales.Clear();
        schedulerControl1.TimelineView.Scales.Add(new TimeScaleYear());

        BindingList<ModelResource> resourceList = new BindingList<ModelResource> {
            new ModelResource() { Id = Guid.NewGuid(), Name = "One" },
            new ModelResource() { Id = Guid.NewGuid(), Name = "Two" },
            new ModelResource() { Id = Guid.NewGuid(), Name = "Three" },
        };

        BindingList<ModelAppointment> appointmentList = new BindingList<ModelAppointment> {
            new ModelAppointment() { StartTime = new DateTime(2010, 01, 01), EndTime = new DateTime(2011, 07, 01), Subject = "PL: TT.MM.JJ SL: TT.MM.JJ", ResourceId = resourceList[0].Id },
            new ModelAppointment() { StartTime = new DateTime(2011, 06, 01), EndTime = new DateTime(2012, 11, 01), Subject = "PL: TT.MM.JJ SL: TT.MM.JJ", ResourceId = resourceList[1].Id },
            new ModelAppointment() { StartTime = new DateTime(2012, 10, 01), EndTime = new DateTime(2014, 02, 01), Subject = "PL: TT.MM.JJ SL: TT.MM.JJ", ResourceId = resourceList[2].Id },
        };

        //SchedulerControl.Storage.ResourceStorage.DataSource = resourceList;
        //SchedulerControl.Storage.AppointmentStorage.DataSource = appointmentList;
        schedulerControl1.DataStorage.Resources.DataSource = resourceList;
        schedulerControl1.DataStorage.Appointments.DataSource = appointmentList;
        //schedulerStorage1
    }

模型是:

public class ModelAppointment
{
    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 long Label { get; set; }
    public string Location { get; set; }
    public bool AllDay { get; set; }
    public int EventType { get; set; }
    public object ResourceId { get; set; }

    public ModelAppointment()
    {
    }
}

public class ModelResource
{
    public object Id { get; set; }
    public string Name { get; set; }

    public ModelResource()
    {
    }
}

看起来应该是屏幕截图,但schedulerControl中没有任何显示,为空数据。 如您所见,result

编辑: 正如Svetlana提到的Mapping: 这是代码:

public LifeCycleCollectionView()
    {
        InitializeComponent();
    }

    private BindingList<LifecycleResource> CustomResourceCollection = new BindingList<LifecycleResource>();
    private BindingList<LifecycleAppointment> CustomEventList = new BindingList<LifecycleAppointment>();


    private void LifeCycleCollectionView_Load(object sender, EventArgs e)
    {
        InitResources();
        InitAppointments();

        CreateTimeScales();
    }

    private void CreateTimeScales()
    {
        schedulerControl1.Views.TimelineView.Scales.Clear();
        schedulerControl1.Views.TimelineView.Scales.Add(new TimeScaleYear());
        //schedulerControl1.Views.TimelineView.Scales.Add(new TimeScaleMonth());
        //schedulerControl1.Views.TimelineView.Scales.Add(new TimeScaleDay());
        //schedulerControl1.Views.TimelineView.Scales.Add(new TimeScaleFixedInterval(TimeSpan.FromHours(3)));
    }

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

        CustomResourceCollection.Add(CreateCustomResource(1, "Project Pre-Study", Color.PowderBlue));
        CustomResourceCollection.Add(CreateCustomResource(2, "Project Execution", Color.PaleVioletRed));
        CustomResourceCollection.Add(CreateCustomResource(3, "Project Closure", Color.PeachPuff));
        this.schedulerStorage1.Resources.DataSource = CustomResourceCollection;
    }

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

    private void InitAppointments()
    {
        AppointmentMappingInfo mappings = this.schedulerStorage1.Appointments.Mappings;
        mappings.Start = "CycleBegin";
        mappings.End = "CycleEnd";
        mappings.Subject = "Comment";
        mappings.ResourceId = "OwnerId";
        mappings.AppointmentId = "IDLifeCycle";
        mappings.Description = "GoLiveDate";

        GenerateEvents(CustomEventList);
        this.schedulerStorage1.Appointments.DataSource = CustomEventList;
    }

    private void GenerateEvents(BindingList<LifecycleAppointment> eventList)
    {
        eventList.Add(CreateEvent(schedulerStorage1.Resources[1].Caption + " comment 1", schedulerStorage1.Resources[1].Id, 0, 10, false));
        //int count = schedulerStorage1.Resources.Count;

        //for (int i = 0; i < count; i++)
        //{
        //    Resource resource = schedulerStorage1.Resources[i];
        //    string subjPrefix = resource.Caption + "'s ";
        //    eventList.Add(CreateEvent(subjPrefix + "Phase 1", resource.Id, 2, 5, false));
        //    eventList.Add(CreateEvent(subjPrefix + "Phase 2", resource.Id, 3, 6, true));
        //    eventList.Add(CreateEvent(subjPrefix + "Phase 3", resource.Id, 0, 10, false));
        //}
    }

    private LifecycleAppointment CreateEvent(string subject, object resourceId, int status, int label, bool allDay)
    {
        LifecycleAppointment apt = new LifecycleAppointment();
        apt.Comment = subject;
        apt.OwnerId = resourceId;
        //Random rnd = RandomInstance;
        //int rangeInMinutes = 60 * 24;
        if (allDay)
        {
            apt.CycleBegin = DateTime.Today;
            //apt.AllDay = true;
        }
        else
        {
            apt.CycleBegin = new DateTime(2019, 01, 01);
            apt.CycleEnd = new DateTime(2020, 01, 01);
        }
        //apt.Status = status;
        //apt.Label = label;
        return apt;
    }

但是我不知道问题出在哪里,请参见上面的picture代码结果

2 个答案:

答案 0 :(得分:1)

确保已按照Mappings帮助主题中的说明为约会和资源创建了所有必要的映射。

答案 1 :(得分:1)

尝试设置SchedulerControl.GroupType = SchedulerGroupType.Resource;