public class AppointmentFormControllerBase : INotifyPropertyChanged { InnerSchedulerControl innerControl; Appointment sourceApt; public AppointmentFormControllerBase(InnerSchedulerControl innerControl, Appointment apt) { this.innerControl = innerControl; this.sourceApt = apt; //... } protected internal Appointment SourceAppointment { get { return sourceApt; } } //... }
public AppointmentFormControllerBase(InnerSchedulerControl innerControl, Appointment apt) { //... CreateAppointmentCopies(); } public Appointment EditedAppointmentCopy { get { return editedAptCopy; } } protected internal virtual void CreateAppointmentCopies() { editedAptCopy = sourceApt.Copy(); //... }
public virtual void ApplyChanges() { // … sourceApt.BeginUpdate(); try { ApplyChangesCore(); } finally { sourceApt.EndUpdate(); } } protected internal virtual void ApplyChangesCore() { AppointmentFormAppointmentCopyHelper helper = new AppointmentFormAppointmentCopyHelper(this); helper.AssignSimpleProperties(editedAptCopy, sourceApt); helper.AssignCollectionProperties(editedAptCopy, sourceApt); }
public string Subject { get { return editedAptCopy.Subject; } set { editedAptCopy.Subject = value; NotifyPropertyChanged("Subject"); } }
public DateTime Start { get { return InnerControl.TimeZoneHelper.ToClientTime(editedAptCopy.Start); } set { editedAptCopy.Start = InnerControl.TimeZoneHelper.FromClientTime(value); } }
public DateTime StartDate { get { return editedAptCopy.Start.Date; } set { editedAptCopy.Start = value.Date + editedAptCopy.Start.TimeOfDay; NotifyPropertyChanged("StartDate"); } } public TimeSpan StartTime { get { return editedAptCopy.Start.TimeOfDay; } set { editedAptCopy.Start = editedAptCopy.Start.Date + value; NotifyPropertyChanged("StartTime"); } }
public virtual bool IsNewAppointment { get { … } } public bool CanDeleteAppointment { get { … } }
protected internal virtual void edtStartDate_Validated(object sender, EventArgs e) { controller.DisplayStart = edtStartDate.DateTime.Date + edtStartTime.Time.TimeOfDay; UpdateIntervalControls(); } protected internal virtual void UpdateIntervalControls() { UnsubscribeControlsEvents(); try { UpdateIntervalControlsCore(); } finally { SubscribeControlsEvents(); } } protected virtual void UpdateIntervalControlsCore() { edtEndDate.EditValue = controller.DisplayEnd.Date; edtEndTime.EditValue = new DateTime(controller.DisplayEnd.TimeOfDay.Ticks); //... bool enableTime = !controller.AllDay; edtEndTime.Visible = enableTime; edtEndTime.Enabled = enableTime; }
public partial class AppointmentForm : DevExpress.XtraEditors.XtraForm { readonly AppointmentFormController controller; public AppointmentForm(SchedulerControl control, Appointment apt, bool openRecurrenceForm) { // … this.controller = CreateController(control, apt); UpdateForm(); } protected internal AppointmentFormController Controller { get { return controller; } } protected virtual AppointmentFormController CreateController(SchedulerControl control, Appointment apt) { return new AppointmentFormController(control, apt); } protected virtual void UpdateForm () { tbSubject.Text = controller.Subject; edtShowTimeAs.Status = controller.GetStatus(); bool resourceSharing = controller.ResourceSharing; edtResource.Visible = !resourceSharing; bool canEditResource = controller.CanEditResource; edtResource.Enabled = canEditResource; //… } protected internal virtual void tbSubject_EditValueChanged(object sender, EventArgs e) { controller.Subject = tbSubject.Text; } protected internal virtual void OnOkButton() { if (controller.IsConflictResolved()) { controller.ApplyChanges(); } //… }
<%@ Control Language="C#" AutoEventWireup="true" Inherits="AppointmentForm" CodeFile="AppointmentForm.ascx.cs" %> <%@ Register Assembly="DevExpress.Web.ASPxEditors.v10.2, … Namespace="DevExpress.Web.ASPxEditors" TagPrefix="dxe" %> <table class="dxscAppointmentForm"> </table> <tr> //… <td> <dxe:ASPxDateEdit ID="edtStartDate" runat="server" Date='<%# ((AppointmentFormTemplateContainer)Container).Start %>' EditFormat="DateTime" /> </td> <td> <dxe:ASPxComboBox ID="edtResource" runat="server" DataSource='<%# ResourceDataSource %>' Enabled='<%# ((AppointmentFormTemplateContainer)Container).CanEditResource %>' /> </td> //… </tr> </table> <dxsc:AppointmentRecurrenceForm ID="AppointmentRecurrenceForm1" runat="server" Start='<%# ((AppointmentFormTemplateContainer)Container).RecurrenceStart %>' > </dxsc:AppointmentRecurrenceForm> //… <dxe:ASPxButton runat="server" ID="btnOk" Text="OK" UseSubmitBehavior="false" />
using System.Web.UI; public partial class AppointmentForm : UserControl { public override void DataBind() { base.DataBind(); AppointmentFormTemplateContainer container = (AppointmentFormTemplateContainer)Parent; AppointmentRecurrenceForm1.Visible = container.ShouldShowRecurrence; //… btnOk.ClientSideEvents.Click = container.SaveHandler; } public class AppointmentFormTemplateContainer : Control, IDataItemContainer, INamingContainer { AppointmentFormController controller; public AppointmentFormTemplateContainer(ASPxScheduler control) { this.controller = CreateController(control, Appointment); // … } public DateTime Start { get { return TimeZoneHelper.ToClientTime(Controller.EditedAppointmentCopy.Start); } } public bool CanEditResource { get { return Controller.CanEditResource; } } public bool ShouldShowRecurrence { get { return Controller.SourceAppointment.IsOccurrence && Controller.ShouldShowRecurrenceButton; } } public DateTime RecurrenceStart { get { return TimeZoneHelper.ToClientTime(Controller.EditedPattern != null ? Controller.EditedPattern.RecurrenceInfo.Start : DateTime.Now); } } public string SaveHandler { get { return String.Format("function() {{ aspxAppointmentSave(\"{0}\"); }}", ControlClientId); } } // … }
<UserControl x:Class="DevExpress.Xpf.Scheduler.UI.AppointmentForm" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors" xmlns:dxsch="clr-namespace:DevExpress.Xpf.Scheduler" x:Name="AptForm" MinWidth="600" > // … <Grid> // … <dxe:TextEdit Text="{Binding Controller.Subject, UpdateSourceTrigger=PropertyChanged}" /> <dxe:DateEdit Name="edtStartDate" EditValue ="{Binding Controller.DisplayStartDate}" /> <!--Resources--> <TextBlock IsEnabled="{Binding Controller.CanEditResource}"/> <ContentControl Content="{Binding ElementName=AptForm, Path=Controller}" ContentTemplateSelector="{StaticResource ResTemplateSelector}" IsEnabled="{Binding Controller.CanEditResource}"> </ContentControl> <Button Click="OnDeleteButtonClick" Visibility="{Binding Controller.CanDeleteAppointment, Converter={local:BoolToVisibilityConverter}}" /> // … </Grid> </UserControl>
Source: https://habr.com/ru/post/107359/