Scheduler.Net with DHTMLXConnector


#1

I downloaded the template (sample ) of the Scheduler.Net with the DHTMLXConnector. After some finangling, I was able to get it to work with the sample database (I believe). However, I want to tie it in to our production database where it pulls records of our scheduled service calls and displays them on a READ-ONLY calendar. I have created a View to match the requirements of the DB structure. I have tried multiple methods of connecting, but it constantly comes up with a blank calendar. I have tried both my live server (separate machine) and accessing MSSQL Express on my local machine with the same data. I am not receiving any errors or warnings during a build.

I have been up and down the different guides, docs, forum posts and have tried multiple suggestions. I have to say that I am a beginner->novice at .Net programming, and even less experience with C#. (VB6 was the flavor I learned on).

I have tried different options for my connector string:
First, I tried the SQL string querying both a table and a view. I have also tried the same thing with a stored procedure.

     var connector = new dhtmlxSchedulerConnector(
            String.Format("SELECT StartDate, EndDate, Name, Details, DepartmentId FROM SMCalendar")
            , "EventID"
            , dhtmlxDatabaseAdapterType.SqlServer2005
            , ConfigurationManager.ConnectionStrings["Viewpoint"].ConnectionString,
            "StartDate", "EndDate",
            "Name as text,Details,DepartmentId");

I tried the option of just listing the Table/View.

          var connector = new dhtmlxSchedulerConnector(
             "Viewpoint.dbo.SMCalendar"
            , "EventID"
            , dhtmlxDatabaseAdapterType.SqlServer2005
            , ConfigurationManager.ConnectionStrings["Viewpoint"].ConnectionString,
            "StartDate", "EndDate",
            "Name as text,Details,DepartmentId");

I also have the following line in my web.config file.

    <add name="Viewpoint" connectionString="server=localhost\SQLExpress;database=Viewpoint;uid=user;password=password;"/>

Any guidance would be greatly appreciated. Let me know if any more information would be necessary to be of assistance.


#2

Hello,

I’d suggest you ditch dhtmlxConnector, since at this stage it just adds more unknowns to your app, plus we’re no longer actively develop it.

If you need a read-only calendar, you should be able to implement data loading by hand. It will have more steps to be code manually, but at the same time, all of them will be easier to understand and debug.

What you need to do is:

  1. read events from the database
  2. convert them to JSON according to scheduler formats
  3. write serialized data to the response

This may sound like a lot, but these things are fairly standard and you should be able to find many working code samples and tutorials.

For the first step, the usual approach is EntityFramework
You can generate classes from your database tables as shown here:
https://docs.microsoft.com/en-us/ef/ef6/modeling/code-first/workflows/existing-database#3-reverse-engineer-model

If you follow step 3, you should have a database context class with a data set that can read from your SMCalendar table.

And when you’re able to read the data, you’ll need to convert it to the structure scheduler will accept.

The whole code (excluding EF classes definitions), might look like this:


public class Data : IHttpHandler
{

    public void ProcessRequest(HttpContext context)
    {
        var db = new YourContext();

        // select events and convert them to the format scheduler can understand
        var schedulerEvents = db.Events.ToList().Select(e => new {
            id = e.EventID,
            start_date = e.StartDate.ToString("yyyy-MM-dd HH:mm"),
            end_date = e.StartDate.ToString("yyyy-MM-dd HH:mm"),
            text = e.Name,
            details = e.Details,
            departmentId = e.DepartmentId
        });

        // note I've specified date format for start_date/end_date fields
        // be sure to set Scheduler.Config.xml_date = "%Y-%m-%d %H:%i";


        var serializer = new System.Web.Script.Serialization.JavaScriptSerializer();

        context.Response.ContentType = "text/json";
        context.Response.Write(serializer.Serialize(schedulerEvents));
    }
}

you’ll only have a different class for YourContext and YourContext.Events collection, other than that, the code shouldn’t differ much.

If there won’t be any errors but also no events in the calendar - you can check the server output in browser dev tools, it may also contain an error message.
Here is an article on how to do it https://docs.dhtmlx.com/scheduler/troubleshooting.html

And here is a quick demo, seems working locally:
https://files.dhtmlx.com/30d/523c01f2b393d81a9f0a0812759a58ab/SchedulerReadOnlyLoading.zip
I’ve used javascript initialization of dhtmlxScheudler and a database file located in AppData as a data source.