DevExpress the custom filter for Scheduler control

Source: Internet
Author: User
Tags documentation

In recent days, learning DevExpress Scheduler control

It is indeed more complicated.

Let's start by listing where we can get the resources to learn:

https://documentation.devexpress.com/#WindowsForms/customdocument2278 Lesson 5-bind a Scheduler to MS SQL Database At Design time

This paragraph is a more important resource.

From the documentation we see that can be customized with Lesson 7-create a custom appointment Edit Form Lesson 8-implement a custom Inplace Edito R

However, these two, frankly speaking, are not the crux of the real problem.

The core of the whole scheduler system is appointment.

Because, as a manager, the need to face all the staff's task, in this case, filter is the key,

The image above is the two examples in the devexpress example that are related to filter.

The first example, about the TV station, has two dimensions in the interface: Channels and sports.

Although there are only two dimensions, there is a preliminary demonstration of the complexity of the real world: television channels, and sports, have a complex space-time relationship.

But if we are faced with more complex needs.

For example, we need to add another one-dimensional filter.

For example, I like to watch the NBA, or, I just like an athlete, such as the recent world championships more famous Couzens, then how to add one dimension.

For example, television channels are exclusive resources, however, in the real world, many resources are not independent, such as 8-lane highways, such as a job, may serve a limited number of objects.

This situation, and how.

So, there are only two dimensions, which is obviously not enough.

Let's first analyze the example of appointment filtering, which has the following over-the-line code:

        private void Schedulerstorage_filterappointment (object sender, Persistentobjectcanceleventargs e) {
            int sportid = Convert.ToInt32 (this.imcbSports.EditValue);
            if (Sportid < 0)
                return;

            Appointment apt = (appointment) E.object;
            E.cancel = Apt. Labelid! = Sportid;
        }


Look at this sentence:

E.cancel = Apt. Labelid! = Sportid;

Here's a problem, the APT object is an instance of the appointment class.

The appointment class, however, is a class of the Devexpress.xtrascheduler library.

In other words, this class is in the class library, and we cannot change it unless we recompile the original code of DevExpress.

The source code is initially read, and we cannot inherit this class. Because, DevExpress does not seem to provide a place to register a factory class.

Frankly speaking, in the face of this situation, really should, really connected to the class library code to change the easy. But for now, let's look at other examples.

Thought, here's another example

In this example, a new dimension is added.

After the break, we analyze:

That is to say, overwrite the Appointmentform class

protected override Appointmentformcontroller Createcontroller (Schedulercontrol control, appointment apt) {
return new Userdefinedfilterappointmentformcontroller (control, APT);
}

The example adds a custom controller to the dialog box that fills in the custom appointment. An instance of Userdefinedfilterappointmentformcontroller.

The purpose of the controller is to extend the appointment class so that the custom fields in this class can also be used.

	public class Userdefinedfilterappointmentformcontroller:appointmentformcontroller {public
		Userdefinedfilterappointmentformcontroller (Schedulercontrol control, appointment apt)
			: Base (Control, APT) {
		}

		Public Decimal Price {
			get {
				Object value = editedappointmentcopy.customfields["Customfieldprice"];
				try {
					return Convert.todecimal (value);
				}
				Catch {
					return 0;
				}
			}
			set {editedappointmentcopy.customfields["customfieldprice"] = value;}
		}

		protected override void Applycustomfieldsvalues () {
			base. Applycustomfieldsvalues ();
			sourceappointment.customfields["Customfieldprice"] = Price;
		}
	}


The image above is the call stack.

Below, we analyze the implementation of the filter in Userdefinedfiltermodule:

The key is a sentence:

		private void Onbtnapplyclick (object sender, EventArgs e) {
			SchedulerControl.Storage.Appointments.Filter = filtercontrolforappointments.filterstring;
		}


The analysis is almost there.

In addition, for example, the mapping of custom fields,

		private void Addcustomfieldsmapping () {
			appointmentcustomfieldmapping custompricemapping = new Appointmentcustomfieldmapping ("Customfieldprice", "Price", fieldvaluetype.decimal);
			SCHEDULERSTORAGE1.APPOINTMENTS.CUSTOMFIELDMAPPINGS.ADD (custompricemapping);
		}


In fact, for me, it's more customary to use a visual editor to define custom mappings.

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.