Devexpress自定义字段不保存回db

时间:2016-06-12 14:49:24

标签: c# asp.net webforms devexpress

我正在使用devexpress ASPxScheduler并创建自定义表单字段。在大多数情况下,这是有效的,并按照屏幕截图添加表单中的字段。但我遇到的问题是表单没有保存我的自定义值。

我正在使用实体数据源来提供数据,但我认为它仍然可以使用此方法

调度程序的主要代码:

 <dxwschs:ASPxScheduler     OptionsBehavior-ShowViewNavigator="false" Views-DayView-ShowWorkTimeOnly="true" Views-FullWeekView-ShowWorkTimeOnly="true" Views-WorkWeekView-ShowWorkTimeOnly="true" ID="apertureAppointments" Width="100%" runat="server" AppointmentDataSourceID="entyAppointments" ClientIDMode="AutoID" ResourceDataSourceID="entyResource" Start="2016-06-10" Theme="SoftOrange" OnAppointmentRowInserted="apertureAppointments_AppointmentRowInserted" ViewStateMode="Disabled" OnAppointmentFormShowing="apertureAppointments_AppointmentFormShowing" OnAppointmentInserting="apertureAppointments_AppointmentInserting">
                            <Storage>
                                <Appointments AutoRetrieveId="True">

                                    <Mappings AppointmentId="UniqueID" Description="Description" End="EndDate" Label="Label" Location="Location" RecurrenceInfo="RecurrenceInfo" ReminderInfo="ReminderInfo" ResourceId="ResourceID" Start="StartDate" Status="Status" Subject="Subject" Type="Type" />
                                    <CustomFieldMappings>
                                        <dxwschs:ASPxAppointmentCustomFieldMapping Member="AllDay" Name="AllDay" />
                                        <dxwschs:ASPxAppointmentCustomFieldMapping Member="CustomField1" Name="CustomField1" />
                                        <dxwschs:ASPxAppointmentCustomFieldMapping Member="ResourceIDs" Name="ResourceIDs" />
                                        <dxwschs:ASPxAppointmentCustomFieldMapping Member="Address1" Name="Address1" />
                                        <dxwschs:ASPxAppointmentCustomFieldMapping Member="Address2" Name="Address2" />
                                        <dxwschs:ASPxAppointmentCustomFieldMapping Member="County" Name="County" />
                                        <dxwschs:ASPxAppointmentCustomFieldMapping Member="CustomerFirstName" Name="CustomerFirstName" />
                                        <dxwschs:ASPxAppointmentCustomFieldMapping Member="attachment" Name="Attachment" />
                                        <dxwschs:ASPxAppointmentCustomFieldMapping Member="CustomerLastName" Name="CustomerLastName" />
                                        <dxwschs:ASPxAppointmentCustomFieldMapping Member="emailAddress" Name="EmailAddress" />
                                        <dxwschs:ASPxAppointmentCustomFieldMapping Member="mobileNumber" Name="MobileNumber" />
                                        <dxwschs:ASPxAppointmentCustomFieldMapping Member="notes" Name="Notes" />
                                        <dxwschs:ASPxAppointmentCustomFieldMapping Member="PostCode" Name="PostCode" />
                                        <dxwschs:ASPxAppointmentCustomFieldMapping Member="preferedContactNumber" Name="PreferedContactNumber" />
                                    </CustomFieldMappings>
                                </Appointments>
                                <Resources>
                                    <Mappings Caption="ResourceName" Color="Color" Image="Image" ResourceId="ResourceID" />
                                    <CustomFieldMappings>
                                        <dxwschs:ASPxResourceCustomFieldMapping Member="CustomField1" Name="CustomField1" />
                                        <dxwschs:ASPxResourceCustomFieldMapping Member="UniqueID" Name="UniqueID" />
                                    </CustomFieldMappings>
                                </Resources>


                            </Storage>
                            <Views>
                                <DayView>
                                    <AppointmentDisplayOptions ShowRecurrence="true" />
                                    <TimeRulers>
                                        <cc1:TimeRuler />
                                    </TimeRulers>
                                    <WorkTime Start="08:00" End="20:00" />
                                </DayView>
                                <WorkWeekView>
                                    <AppointmentDisplayOptions ShowRecurrence="true" />
                                    <TimeRulers>
                                        <cc1:TimeRuler />
                                    </TimeRulers>
                                    <WorkTime Start="08:00" End="20:00" />
                                </WorkWeekView>
                                <WeekView Enabled="false"></WeekView>
                                <FullWeekView Enabled="true">
                                    <AppointmentDisplayOptions ShowRecurrence="true" />
                                    <TimeRulers>
                                        <cc1:TimeRuler />
                                    </TimeRulers>
                                    <WorkTime Start="08:00" End="20:00" />
                                </FullWeekView>
                            </Views>

                            <OptionsBehavior ShowViewNavigator="False" />

                            <OptionsForms   AppointmentFormTemplateUrl="~/MyForms/UserAppointmentForm.ascx" AppointmentInplaceEditorFormTemplateUrl="~/DevExpress/ASPxSchedulerForms/InplaceEditor.ascx" GotoDateFormTemplateUrl="~/DevExpress/ASPxSchedulerForms/GotoDateForm.ascx" RecurrentAppointmentDeleteFormTemplateUrl="~/DevExpress/ASPxSchedulerForms/RecurrentAppointmentDeleteForm.ascx" RecurrentAppointmentEditFormTemplateUrl="~/DevExpress/ASPxSchedulerForms/RecurrentAppointmentEditForm.ascx" RemindersFormTemplateUrl="~/DevExpress/ASPxSchedulerForms/ReminderForm.ascx" />
                            <OptionsToolTips AppointmentDragToolTipUrl="~/DevExpress/ASPxSchedulerForms/AppointmentDragToolTip.ascx" AppointmentToolTipUrl="~/DevExpress/ASPxSchedulerForms/AppointmentToolTip.ascx" SelectionToolTipUrl="~/DevExpress/ASPxSchedulerForms/SelectionToolTip.ascx" />
                        </dxwschs:ASPxScheduler>

Screen Shot 1

自定义字段的类     我想用两个字段来测试这个,这就是我刚刚编写customerfirstname和customerlastname以进行测试的原因。

using DevExpress.Web;
using DevExpress.Web.ASPxScheduler;
using DevExpress.Web.ASPxScheduler.Internal;
using DevExpress.XtraScheduler;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

#region #userappointmentformtemplatecontainer
public class UserAppointmentFormTemplateContainer : AppointmentFormTemplateContainer
{
    public UserAppointmentFormTemplateContainer(ASPxScheduler control)
        : base(control)
    {
    }
    public string Field1 { get { return Convert.ToString(Appointment.CustomFields["CustomerFirstName"]); } }
    public string Field2 { get { return Convert.ToString(Appointment.CustomFields["CustomerLastName"]); } }
}
#endregion #userappointmentformtemplatecontainer
#region #userappointmentformcontroller
public class UserAppointmentFormController : AppointmentFormController
{
    public UserAppointmentFormController(ASPxScheduler control, Appointment apt)
        : base(control, apt)
    {
    }
    public string Field1
    {
        get { return (string)EditedAppointmentCopy.CustomFields["CustomerFirstName"]; }
        set { EditedAppointmentCopy.CustomFields["CustomerFirstName"] = value; }
    }
    public string Field2
    {
        get { return (string)EditedAppointmentCopy.CustomFields["CustomerLastName"]; }
        set { EditedAppointmentCopy.CustomFields["CustomerLastName"] = value; }
    }


    public string SourceCustomerFirstName
    {
        get { return (string)SourceAppointment.CustomFields["CustomerFirstName"]; }
        set { SourceAppointment.CustomFields["CustomerFirstName"] = value; }
    }
    public string SourceCustomerLastName
    {
        get { return (string)SourceAppointment.CustomFields["CustomerLastName"]; }
        set { SourceAppointment.CustomFields["CustomerLastName"] = value; }
    }

    public override bool IsAppointmentChanged()
    {
        if (base.IsAppointmentChanged())
            return true;
        return SourceCustomerFirstName != Field1 || SourceCustomerLastName!=Field2;

    }
    protected override void ApplyCustomFieldsValues()
    {
        SourceCustomerFirstName = Field1;
        SourceCustomerLastName = Field2;

    }
    #endregion #userappointmentformcontroller
    #region #userappointmentsavecallbackcommand
    public class UserAppointmentSaveCallbackCommand : AppointmentFormSaveCallbackCommand
    {
        public UserAppointmentSaveCallbackCommand(ASPxScheduler control)
            : base(control)
        {
        }
        protected internal new UserAppointmentFormController Controller
        {
            get { return (UserAppointmentFormController)base.Controller; }
        }

        protected override void AssignControllerValues()
        {
            ASPxTextBox tbCustomerFirstName = (ASPxTextBox)FindControlByID("tbCustomerFirstName");
            ASPxTextBox tbCustomerLastName = (ASPxTextBox)FindControlByID("tbCustomerLastName");

            Controller.SourceCustomerFirstName = tbCustomerFirstName.Text;
            Controller.SourceCustomerLastName = tbCustomerLastName.Text;
            ASPxComboBox cbLocation = (ASPxComboBox)FindControlByID("cbLocation");
            ASPxTextBox tbLocation = (ASPxTextBox)FindControlByID("tbLocation");



            if (cbLocation.Value == null)
                tbLocation.Text = string.Empty;
            else
                tbLocation.Text = cbLocation.Text;

            base.AssignControllerValues();
        }
        protected override AppointmentFormController CreateAppointmentFormController
            (Appointment apt)
        {
            return new UserAppointmentFormController(Control, apt);
        }
    }
}

#endregion #userappointmentsavecallbackcommand

用户表单背后的代码:

using System;
using System.Web.UI;
using DevExpress.XtraScheduler;

using DevExpress.Web.ASPxScheduler;
using DevExpress.Web.ASPxScheduler.Internal;
using System.Data;
using DevExpress.Web;

public partial class AppointmentForm : SchedulerFormControl {
    public bool CanShowReminders {
        get {
            return ((AppointmentFormTemplateContainer)Parent).Control.Storage.EnableReminders;
        }
    }

    protected void Page_Load(object sender, EventArgs e) {
        PrepareChildControls();
        tbSubject.Focus();
    }
    public override void DataBind() {
        base.DataBind();

        AppointmentFormTemplateContainer container = (AppointmentFormTemplateContainer)Parent;
        Appointment apt = container.Appointment;
        edtLabel.SelectedIndex = apt.LabelId;
        edtStatus.SelectedIndex = apt.StatusId;
        if (!Object.Equals(apt.ResourceId, ResourceEmpty.Id))
            edtResource.Value = apt.ResourceId.ToString();
        else
            edtResource.Value = DevExpress.XtraScheduler.EmptyResourceId.Id;


        AppointmentRecurrenceForm1.Visible = container.ShouldShowRecurrence;

        if (container.Appointment.HasReminder) {
            cbReminder.Value = container.Appointment.Reminder.TimeBeforeStart.ToString();
            chkReminder.Checked = true;
        }
        else {
            cbReminder.ClientEnabled = false;
        }

        btnOk.ClientSideEvents.Click = container.SaveHandler;
        btnCancel.ClientSideEvents.Click = container.CancelHandler;
        btnDelete.ClientSideEvents.Click = container.DeleteHandler;
        //btnDelete.Enabled = !container.IsNewAppointment;
    }

    protected override void PrepareChildControls() {
        AppointmentFormTemplateContainer container = (AppointmentFormTemplateContainer)Parent;
        ASPxScheduler control = container.Control;

        AppointmentRecurrenceForm1.EditorsInfo = new EditorsInfo(control, control.Styles.FormEditors, control.Images.FormEditors, control.Styles.Buttons);
        base.PrepareChildControls();
    }
    protected override ASPxEditBase[] GetChildEditors() {
        ASPxEditBase[] edits = new ASPxEditBase[] {
            lblSubject, tbSubject,
            lblLocation, cbLocation,
            lblCustomerFirstName,tbCustomerFirstName,
              lblCustomterLastName,tbCustomerLastName,
            lblLabel, edtLabel,
            lblStartDate, edtStartDate,
            lblEndDate, edtEndDate,
            lblStatus, edtStatus,
            lblAllDay, chkAllDay,
            lblResource, edtResource,
            tbDescription, cbReminder,
        };
        return edits;
    }
    protected override ASPxButton[] GetChildButtons() {
        ASPxButton[] buttons = new ASPxButton[] {
            btnOk, btnCancel, btnDelete
        };
        return buttons;
    }


    protected void edtField1_Init(object sender, EventArgs e) {
        DataTable dataTable = PrepareComboData();

        cbLocation.DataSource = dataTable;
        cbLocation.SelectedIndex = 0;

        for (int i = 0; i < dataTable.Rows.Count; i++) {
            string nextValue = dataTable.Rows[i][cbLocation.ValueField].ToString();

            if (!string.IsNullOrEmpty(nextValue) && nextValue == ((AppointmentFormTemplateContainer)this.Parent).Appointment.Location) {
                cbLocation.SelectedIndex = i;
                break;
            }
        }

        cbLocation.DataBind();
    }

    protected DataTable PrepareComboData() {
        DataTable dataTable = new DataTable("dataTable");

        dataTable.Columns.Add("Code", typeof(string));
        dataTable.Columns.Add("Description", typeof(string));

        dataTable.Rows.Add(new object[] { "", "[Select Location]" });
        dataTable.Rows.Add(new object[] { "Home", "Home" });
        dataTable.Rows.Add(new object[] { "Workplace", "Workplace" });
        dataTable.Rows.Add(new object[] { "External", "External" });

        return dataTable;
    }


}

0 个答案:

没有答案