Using the daily program in WinForm Development Xtrascheduler (2)--deep understanding of data storage

Source: Internet
Author: User

In the previous essay, "WinForm development in the use of daily program Xtrascheduler" introduced in DevExpress Xtrascheduler Day program of the various use of knowledge points, for us, the day program is not unfamiliar, such as Outlook has a calendar module , but this day program is really a very complex control, need to fully grasp may take a lot of time to understand, because it is a technical research, I always hope that it is commonly used in the function of the more thorough analysis, the previous essay also introduced its storage function, based on the way the entity class stored in the database, But the introduction is not enough, this article continues the above content, the data storage aspects of the introduction.

After looking at a lot of data, and one or two days of dive research, I finally got a clearer understanding of its data storage and related familiarity.

1. Review of data binding and loading processing

In the last essay, I introduced the data binding of this control, and how the data is stored in the database, and the steps to bind to DevExpress's Xtrascheduler day program are to set the mapping relationship (Mappings) First, then bind the data source.

The operation code is shown below.

        /// <summary>        ///set field mappings for a day program/// </summary>        /// <param name= "Control" >Day Program Control parts</param>        Private voidsetmappings (Schedulercontrol control) {Appointmentmappinginfo appoint=control.            Storage.Appointments.Mappings; Appoint. AllDay="AllDay"; Appoint. Description="Description"; Appoint. End="EndDate"; Appoint. Label="Applabel"; Appoint. Location=" Location"; Appoint. Recurrenceinfo="Recurrenceinfo"; Appoint. Reminderinfo="Reminderinfo"; Appoint. ResourceId="ResourceId"; Appoint. Start="StartDate"; Appoint. Status="Status"; Appoint. Subject="Subject"; Appoint. Type="EventType"; Resourcemappinginfo Res=control.            Storage.Resources.Mappings; Res. Caption="resourcename"; Res. Color="Color"; Res. Id="ResourceId"; Res. Image="Image"; }

Then it is bound appointment and resource to the corresponding data source inside the interface.

            // Load Schedule Information            from a database list<appresourceinfo> resoucelist = bllfactory<appresource>. Instance.getall ();             this. SchedulerStorage1.Resources.DataSource = resoucelist;            List<UserAppointmentInfo> eventlist = bllfactory<userappointment>. Instance.getall ();             this. SchedulerStorage1.Appointments.DataSource = EventList;

2, the Schedule data deletion and modification processing

However, the above-mentioned storage is actually relatively small, that is, we tend to add or copy records on the interface, modify records, or delete records and so on, so we need to further utilize the perfect interface of the daily program to handle these operations.

We can see some important events about storage in the corresponding control properties of VS, that is, the change and deletion of the schedule, as shown below.

Above these events is corresponding to the control of the day in the right-click menu corresponding additions and deletions to change the operation.

In addition, the daily program can also support drag modification, drag copy, delete key delete operation, these will continue to invoke the above additions and deletions to change the operation of the event, so we will be perfect for them, our focus is to deal with ING type of events, such as the inserting event, before writing to the date of the program assembly processing.

            // Write back events            for database operations Control. Storage.appointmentinserting + = storage_appointmentinserting            ; + = storage_appointmentchanging            ; + = storage_appointmentdeleting;

For the processing before the data is modified, we have to let it have a smooth write to the database, decide whether to update the storage collection of the Schedule object or discard the modification record, as shown below.

        void Storage_appointmentchanging (object  sender, Persistentobjectcanceleventargs e)        {            as  appointment;             = Converttoappoint (APT);             bool success = Bllfactory<userappointment>. Instance.update (info, Apt. ID);            = !  success;        }

Notice the above E. Cancel =true or False indicates whether to give up, the above code logic is if we successfully write to the database, then we can successfully update to the daily control of the storage collection, and you can see the latest results in the interface.

With the above understanding, we can further refine the code before and after the insertion is processed.

For the action before the delete, we can use the following code as shown below.

        voidStorage_appointmentdeleting (Objectsender, Persistentobjectcanceleventargs e) {Appointment apt= E.object asappointment; if(Apt! =NULL&& Apt. Id! =NULL)            {                if(messagedxutil.showyesnoandwarning("Are you sure you want to delete this record? ") ==dialogresult.yes) {BOOLSuccess = Bllfactory<userappointment>. Instance.delete (Apt.                    ID); E.cancel= !success; }            }        }

We use the code messagedxutil.showyesnoandwarning to determine whether to proceed, as shown in the following interface.

For the inserted records, we need to pay more attention to the need to write to the database, the local storage records of the update, so as to reasonably display, otherwise prone to replication, the creation of record location is always wrong, offset to other places.

        void Storage_appointmentinserting (object  sender, Persistentobjectcanceleventargs e)        {            as  appointment;             = Converttoappoint (APT);             bool success = Bllfactory<userappointment>. Instance.insert (info);             = ! success;             if (Success)            {                loaddata ();            }        }

LoadData is that we load the schedule information from the database, and bound to the storage object of the day program, which needs to be noted is the need to use the RefreshData method, so that the daily program storage objects refreshed, so that we can successfully display the records we added.

            // Load Schedule Information            from a database list<appresourceinfo> resoucelist = bllfactory<appresource>. Instance.getall ();             this. SchedulerStorage1.Resources.DataSource = resoucelist;            List<UserAppointmentInfo> eventlist = bllfactory<userappointment>. Instance.getall ();             this. SchedulerStorage1.Appointments.DataSource = EventList;
            this. Schedulercontrol1.refreshdata (); // must refresh the data source for each modification, otherwise the interface needs to be refreshed again

3, the processing of multi-person resources

In the Japanese program, support the processing of multi-human resources, the default is that resources can only choose one, need more people, then you need to set the following properties to display the declaration using multi-person resources, as shown below.

true;

With a multi-person resource, you can check the resource, and its mapping record is resourceids, so when we set the mapping property, we need to judge the ResourceSharing property.

            if (Control. resourcesharing)            {                "resourceids";            }             Else             {                "ResourceId";            }

Where the content format for ResourceID is as follows

<ResourceIds>  <resourceid type="system.string" value="1  " /><resourceid type="system.string" value="2  " />  </ResourceIds>

Unlike ResourceID, the value here is an XML content, which, like the storage format for reminders, is based on XML content. Some of the XML information that is involved in a Japanese program is shown below.

            //information on multi-person resources            if(Apt. Resourceids! =NULL) {appointmentresourceidcollectioncontextelement Item=Newappointmentresourceidcollectioncontextelement (Apt.                Resourceids); Info. Resourceids=item.                Valuetostring (); //The second Kind//Appointmentresourceidcollectionxmlpersistencehelper helper = new Appointmentresourceidcollectionxmlpersistencehelper (Apt.                Resourceids); //info. Resourceids = Helper. TOXML ();            }            //Schedule Recurrence Information            if(Apt. Recurrenceinfo! =NULL) {info. Recurrenceinfo=Apt.            Recurrenceinfo.toxml (); }            //Reminder Information            if(Apt. Reminder! =NULL) {info. Reminderinfo=remindercollectionxmlpersistencehelper.createsaveinstance (APT).            TOXML (); }

The above is our regular use of the schedule control of the content, we hope to help.

Using the daily program in WinForm Development Xtrascheduler (2)--deep understanding of data storage

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.