DevExpress Scheduler 使用详解

使用详解


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Data.OracleClient;
using DevExpress.XtraScheduler;

namespace SchedulerSQLRuntime {
    public partial class Form1 : Form {
        public Form1() {
            InitializeComponent();

            // Subscribe to Storage events required for updating the data source. 
            this.schedulerStorage1.AppointmentsInserted += OnApptChangedInsertedDeleted;
            this.schedulerStorage1.AppointmentsChanged += OnApptChangedInsertedDeleted;
            this.schedulerStorage1.AppointmentsDeleted += OnApptChangedInsertedDeleted;

            //// Uncomment the code below to demonstrate how to store and retrieve data in the appointment custom field.
            //// 取消对以下代码的注释,以演示如何在约会自定义字段中存储和检索数据。
            //// Do not forget to uncomment event handlers.
            //// 不要忘记取消对事件处理程序的注释。
            //this.schedulerControl1.InitAppointmentDisplayText += schedulerControl1_InitAppointmentDisplayText;
            //this.schedulerControl1.InitNewAppointment += schedulerControl1_InitNewAppointment;


        }

        // Modify this string if required to connect to your database.
        const string SchedulerDBConnection = "Data Source=(LocalDB)\\v11.0;AttachDbFilename=|DataDirectory|Data\\DXDBScheduler.mdf;Integrated Security=True;Connect Timeout=30";
        
        DataSet DXSchedulerDataset;        
        SqlDataAdapter AppointmentDataAdapter;
        SqlDataAdapter ResourceDataAdapter;
        SqlConnection DXSchedulerConn;

        private void Form1_Load(object sender, EventArgs e) {

            this.schedulerStorage1.Appointments.ResourceSharing= true;
            this.schedulerControl1.GroupType = SchedulerGroupType.Resource;
            this.schedulerControl1.Start = DateTime.Today;
            
            DXSchedulerDataset = new DataSet();
            string selectAppointments = "SELECT * FROM Appointments";
            string selectResources = "SELECT * FROM resources";

            DXSchedulerConn = new SqlConnection(SchedulerDBConnection);
            DXSchedulerConn.Open();

            AppointmentDataAdapter = new SqlDataAdapter(selectAppointments, DXSchedulerConn);
            // Subscribe to RowUpdated event to retrieve identity value for an inserted row.
            AppointmentDataAdapter.RowUpdated += new SqlRowUpdatedEventHandler(AppointmentDataAdapter_RowUpdated);
            AppointmentDataAdapter.Fill(DXSchedulerDataset, "Appointments");

            ResourceDataAdapter = new SqlDataAdapter(selectResources, DXSchedulerConn);
            ResourceDataAdapter.Fill(DXSchedulerDataset, "Resources");

            // Specify mappings.
            MapAppointmentData();
            MapResourceData();

            // Generate commands using CommandBuilder.  
            SqlCommandBuilder cmdBuilder = new SqlCommandBuilder(AppointmentDataAdapter);
            AppointmentDataAdapter.InsertCommand = cmdBuilder.GetInsertCommand();
            AppointmentDataAdapter.DeleteCommand = cmdBuilder.GetDeleteCommand();
            AppointmentDataAdapter.UpdateCommand = cmdBuilder.GetUpdateCommand();

            DXSchedulerConn.Close();

            this.schedulerStorage1.Appointments.DataSource = DXSchedulerDataset;
            this.schedulerStorage1.Appointments.DataMember = "Appointments";
            this.schedulerStorage1.Resources.DataSource = DXSchedulerDataset;
            this.schedulerStorage1.Resources.DataMember = "Resources";

        }

        private void MapAppointmentData()
        {
            this.schedulerStorage1.Appointments.Mappings.AllDay = "AllDay";
            this.schedulerStorage1.Appointments.Mappings.Description = "Description";
            // Required mapping.
            this.schedulerStorage1.Appointments.Mappings.End = "EndDate";
            this.schedulerStorage1.Appointments.Mappings.Label = "Label";
            this.schedulerStorage1.Appointments.Mappings.Location = "Location";
            this.schedulerStorage1.Appointments.Mappings.RecurrenceInfo = "RecurrenceInfo";
            this.schedulerStorage1.Appointments.Mappings.ReminderInfo = "ReminderInfo";
            // Required mapping.
            this.schedulerStorage1.Appointments.Mappings.Start = "StartDate";
            this.schedulerStorage1.Appointments.Mappings.Status = "Status";
            this.schedulerStorage1.Appointments.Mappings.Subject = "Subject";
            this.schedulerStorage1.Appointments.Mappings.Type = "Type";
            this.schedulerStorage1.Appointments.Mappings.ResourceId = "ResourceIDs";
            this.schedulerStorage1.Appointments.CustomFieldMappings.Add(new AppointmentCustomFieldMapping("MyNote", "CustomField1")); 
        }

        private void MapResourceData()
        {
            this.schedulerStorage1.Resources.Mappings.Id = "ResourceID";
            this.schedulerStorage1.Resources.Mappings.Caption = "ResourceName";
        }

        // Retrieve identity value for an inserted appointment.
        void AppointmentDataAdapter_RowUpdated(object sender, SqlRowUpdatedEventArgs e)
        {
            if (e.Status == UpdateStatus.Continue && e.StatementType == StatementType.Insert) {
                int id = 0;
                using (SqlCommand cmd = new SqlCommand("SELECT IDENT_CURRENT('Appointments')", DXSchedulerConn))
                {
                    id = Convert.ToInt32(cmd.ExecuteScalar());
                }
                e.Row["UniqueID"] = id;
            }
        }

        // Store modified data in the database
        private void OnApptChangedInsertedDeleted(object sender, PersistentObjectsEventArgs e) {
            AppointmentDataAdapter.Update(DXSchedulerDataset.Tables["Appointments"]);
            DXSchedulerDataset.AcceptChanges();
        }

        //// Uncomment the code below to demonstrate how to store and retrieve data in the appointment custom field.
        //// 取消对以下代码的注释,以演示如何在约会自定义字段中存储和检索数据
        //// Do not forget to uncomment event subscription code in the form constructor.
        //// 不要忘记在窗体构造函数中取消对事件订阅代码的注释

        //// Store a custom value in the newly created appointment.
        //// 在新创建的约会中存储自定义值

        //private void schedulerControl1_InitNewAppointment(object sender, AppointmentEventArgs e)
        //{
        //    e.Appointment.CustomFields["MyNote"] = String.Format("Created on {0:d} at {0:t} \n", DateTime.Now);
        //}

        //// Modify default appointment text to display a custom value.
        //// 修改默认约会文本以显示自定义值。
        //private void schedulerControl1_InitAppointmentDisplayText(object sender, AppointmentDisplayTextEventArgs e)
        //{
        //    e.Text = (e.Appointment.CustomFields["MyNote"] is DBNull) ? String.Empty : (string)e.Appointment.CustomFields["MyNote"];
        //}

    }
}

日程自定义修改界面

//自定义日程添加修改界面
namespace CustomRecurrenceFormDescendantSample
{
    public partial class Form1 : Form
    {	
        public Form1()
        {
            InitializeComponent();

            this.schedulerControl1.EditAppointmentFormShowing += schedulerControl1_EditAppointmentFormShowing;
           this.Shown += Form1_Shown;
        }

        void schedulerControl1_EditAppointmentFormShowing(object sender, DevExpress.XtraScheduler.AppointmentFormEventArgs e)
        {
            // Recurrence form allows editing only daily recurring appointments. 
            MyAppointmentEditForm myForm = new MyAppointmentEditForm(schedulerControl1,
                e.Appointment, e.OpenRecurrenceForm, DevExpress.XtraScheduler.RecurrenceType.Daily);
            myForm.ShowDialog();
            e.Handled = true;

        }

        void Form1_Shown(object sender, EventArgs e)
        {
            this.schedulerControl1.CreateAppointment(false, true);
            this.schedulerControl1.Start = DateTime.Today;
        }
    }
}

DevExpress Scheduler源码分析

 //
    // 摘要:
    //     Lists the types of recurrent appointments.
    //重复类型
    public enum RecurrenceType
    {
        //
        // 摘要:
        //     The recurring appointment reoccurs on a daily base.定期约会每天发生

        Daily = 0,
        //
        // 摘要:
        //     The recurring appointment reoccurs on a weekly base.
        Weekly = 1,
        //
        // 摘要:
        //     The recurring appointment reoccurs on a monthly base.
        Monthly = 2,
        //
        // 摘要:
        //     The recurring appointment reoccurs on an yearly base.
        Yearly = 3,
        //
        // 摘要:
        //     The recurring appointment reoccurs on a minute base.
        Minutely = 4,
        //
        // 摘要:
        //     The recurring appointment reoccurs on an hourly base.
        Hourly = 5
    }


 //
    // 摘要:
    //     Lists the types of recurrence range.
    //重复范围
    public enum RecurrenceRange
    {
        //
        // 摘要:
        //     A recurring appointment will not have an end date.
        NoEndDate = 0,
        //
        // 摘要:
        //     A recurring appointment will end after its recurrence count exceeds the value
        //     specified by the DevExpress.XtraScheduler.RecurrenceInfo.OccurrenceCount property.
        OccurrenceCount = 1,
        //
        // 摘要:
        //     A recurring appointment will end after the date specified by the DevExpress.XtraScheduler.RecurrenceInfo.End
        //     property.
        EndByDate = 2
    }

============================
#region 程序集 DevExpress.XtraScheduler.v18.1, Version=18.1.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a
// C:\Program Files (x86)\DevExpress 18.1\Components\Bin\Framework\DevExpress.XtraScheduler.v18.1.dll
#endregion

using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using DevExpress.Utils.Menu;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Controls;

namespace DevExpress.XtraScheduler.UI
{
    //
    // 摘要:
    //     Default recurrence editing form.
    [ComVisible(false)]
    public class AppointmentRecurrenceForm : XtraForm
    {
        protected SimpleButton btnOk;
        protected CheckEdit chkEndAfterNumberOfOccurrences;
        protected CheckEdit chkYearly;
        protected CheckEdit chkMonthly;
        protected CheckEdit chkWeekly;
        protected CheckEdit chkDaily;
        protected CheckEdit chkEndByDate;
        protected CheckEdit chkNoEndDate;
        protected DurationEdit cbDuration;
        protected LabelControl lblDuration;
        protected MonthlyRecurrenceControl monthlyRecurrenceControl1;
        protected WeeklyRecurrenceControl weeklyRecurrenceControl1;
        protected DailyRecurrenceControl dailyRecurrenceControl1;
        protected SpinEdit spinRangeOccurrencesCount;
        protected YearlyRecurrenceControl yearlyRecurrenceControl1;
        protected LabelControl lblEnd;
        protected SimpleButton btnCancel;
        protected TimeEdit edtEndTime;
        protected GroupControl grpAptTime;
        protected GroupControl grpRecurrencePattern;
        protected GroupControl grpRecurrenceRange;
        protected LabelControl lblRangeStart;
        protected SimpleButton btnRemoveRecurrence;
        protected LabelControl lblRangeOccurrencesCount;
        protected DateEdit edtRangeEnd;
        protected TimeEdit edtStartTime;
        protected LabelControl lblStart;
        protected DateEdit edtRangeStart;

        //
        // 摘要:
        //     Initializes a new instance of the AppointmentRecurrenceForm class with default
        //     settings.
        [EditorBrowsable(EditorBrowsableState.Never)]
        public AppointmentRecurrenceForm();
        //
        // 摘要:
        //     Initializes a new instance of the AppointmentRecurrenceForm class and loads the
        //     specified appointment pattern.
        //
        // 参数:
        //   pattern:
        //     An DevExpress.XtraScheduler.Appointment instance specifying the recurrence pattern.
        //
        //   firstDayOfWeek:
        //     A DevExpress.XtraScheduler.FirstDayOfWeek enumeration member specifying the day
        //     of week from which the week starts.
        [Obsolete("Please use the AppointmentRecurrenceForm(Appointment pattern, FirstDayOfWeek firstDayOfWeek, AppointmentFormController controller) instead.")]
        public AppointmentRecurrenceForm(Appointment pattern, FirstDayOfWeek firstDayOfWeek);
        //
        // 摘要:
        //     Initializes a new instance of the AppointmentRecurrenceForm class bound to the
        //     specified form controller and loads the specified appointment pattern.
        //
        // 参数:
        //   pattern:
        //     An DevExpress.XtraScheduler.Appointment instance specifying the recurrence pattern.
        //
        //   firstDayOfWeek:
        //     A DevExpress.XtraScheduler.FirstDayOfWeek enumeration member specifying the starting
        //     day of the week.
        //
        //   controller:
        //     A DevExpress.XtraScheduler.UI.AppointmentFormControllerBase instance that is
        //     the controller of the parent appointment form.
        public AppointmentRecurrenceForm(Appointment pattern, FirstDayOfWeek firstDayOfWeek, AppointmentFormControllerBase controller);

        //
        // 摘要:
        //     Gets or sets whether to show a warning when the user clicks the OK button.
        [DefaultValue(false)]
        [DevExpressXtraSchedulerLocalizedDescriptionAttribute("AppointmentRecurrenceFormShowExceptionsRemoveMsgBox")]
        [DXCategory("Behavior")]
        public bool ShowExceptionsRemoveMsgBox { get; set; }
        protected internal RecurrenceRange RecurrenceRange { get; set; }
        protected internal RecurrenceType RecurrenceType { get; set; }
        protected internal RecurrenceControlBase CurrentRecurrenceControl { get; set; }
        protected internal IRecurrenceInfo RecurrenceInfo { get; }
        protected internal Appointment Pattern { get; }
        protected internal SchedulerRecurrenceValidator Validator { get; }
        protected internal AppointmentFormControllerBase Controller { get; }

        //
        // 摘要:
        //     Sets the object that controls the look and feel of the popup menus for all controls
        //     in the form.
        //
        // 参数:
        //   menuManager:
        //     An object with the DevExpress.Utils.Menu.IDXMenuManager interface that controls
        //     the look and feel of the popup menus.
        public virtual void SetMenuManager(IDXMenuManager menuManager);
        protected virtual SchedulerRecurrenceValidator CreateRecurrenceValidator();
        protected override void Dispose(bool disposing);
        protected virtual void FocusInvalidControl(Control control);
        protected virtual void SubscribeRecurrencePatternControlEvents();
        protected virtual void UnsubscribeRecurrencePatternControlEvents();
        protected virtual void UpdateIcon();
        protected internal virtual void btnOk_Click(object sender, EventArgs e);
        protected internal virtual void cbDuration_InvalidValue(object sender, InvalidValueExceptionEventArgs e);
        protected internal virtual void cbDuration_Validated(object sender, EventArgs e);
        protected internal virtual void cbDuration_Validating(object sender, CancelEventArgs e);
        protected internal virtual void ChangeCurrentRecurrenceControl();
        protected internal virtual void chkEndTypeChanged(object sender, EventArgs e);
        protected internal virtual void chkRecurrenceTypeChanged(object sender, EventArgs e);
        protected internal virtual void edtEndTime_Validated(object sender, EventArgs e);
        protected internal virtual void edtRangeEnd_EditValueChanged(object sender, EventArgs e);
        protected internal virtual void edtRangeEnd_InvalidValue(object sender, InvalidValueExceptionEventArgs e);
        protected internal virtual void edtRangeEnd_Validated(object sender, EventArgs e);
        protected internal virtual void edtRangeEnd_Validating(object sender, CancelEventArgs e);
        protected internal virtual void edtRangeStart_InvalidValue(object sender, InvalidValueExceptionEventArgs e);
        protected internal virtual void edtRangeStart_Validated(object sender, EventArgs e);
        protected internal virtual void edtRangeStart_Validating(object sender, CancelEventArgs e);
        protected internal virtual void edtStartTime_InvalidValue(object sender, InvalidValueExceptionEventArgs e);
        protected internal virtual void edtStartTime_Validated(object sender, EventArgs e);
        protected internal virtual void edtStartTime_Validating(object sender, CancelEventArgs e);
        protected internal virtual DateTime FromClientTime(DateTime date);
        protected internal virtual RecurrenceRange GetRangeType();
        protected internal virtual RecurrenceType GetRecurrenceType();
        protected internal virtual void InitializeControls(FirstDayOfWeek firstDayOfWeek);
        protected internal virtual void InitRecurrenceControls(FirstDayOfWeek firstDayOfWeek);
        protected internal virtual void OnOkButton();
        protected internal virtual void OnRecurrenceInfoChanged(object sender, EventArgs e);
        protected internal virtual void OnRecurrenceTypeEditValueChanged();
        protected internal virtual void OnStartModified();
        protected internal virtual void ResetRecurrenceInfo();
        protected internal virtual void SetRangeType(RecurrenceRange range);
        protected internal virtual void SetRecurrenceType(RecurrenceType type);
        protected internal virtual DialogResult ShowMessageBox(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon);
        protected internal virtual void spinRangeOccurrencesCount_EditValueChanged(object sender, EventArgs e);
        protected internal virtual void spinRangeOccurrencesCount_InvalidValue(object sender, InvalidValueExceptionEventArgs e);
        protected internal virtual void spinRangeOccurrencesCount_Validated(object sender, EventArgs e);
        protected internal virtual void spinRangeOccurrencesCount_Validating(object sender, CancelEventArgs e);
        protected internal virtual void SubscribeAppointmentTimeControlsEvents();
        protected internal virtual void SubscribeRecurrenceRangeControlsEvents();
        protected internal virtual void SubscribeRecurrenceTypeControlsEvents();
        protected internal virtual DateTime ToClientTime(DateTime date);
        protected internal virtual void UnsubscribeAppointmentTimeControlsEvents();
        protected internal virtual void UnsubscribeRecurrenceRangeControlsEvents();
        protected internal virtual void UnsubscribeRecurrenceTypeControlsEvents();
        protected internal virtual void UpdateRecurrenceInfoRange(DateTime start, DateTime end, RecurrenceRange rangeType, int occurrencesCount);
        protected internal virtual void UpdateRecurrenceRangeControls();
        protected internal virtual void UpdateRecurrenceRangeControlsCore();
        protected internal virtual void ValidateRecurrenceRange(ValidationArgs args);
        protected internal virtual void ValidateTimeAndDuration(ValidationArgs args);
        protected internal virtual void ValidateValues(ValidationArgs args);
    }
}

赞(1)
未经允许不得转载:TaKaSa » DevExpress Scheduler 使用详解