Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Saving WPF Scheduler data into SQL Database (Read 4012 times)
Garry
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 2
Joined: Apr 7th, 2016
Saving WPF Scheduler data into SQL Database
Apr 7th, 2016 at 5:14am
Print Post  
Hi Meppy, Cool

I am using the latest WPF scheduler control 4.0 from 2016 build. I can see from documentation that there are options to export data into XML, XSLX & PDF.

However i am looking for an option to save data into SQL database. Please let me know how is it possible? Undecided

Regards
Garry
  
Back to top
 
IP Logged
 
Slavcho
God Member
*****
Online


tech.support

Posts: 3147
Joined: Oct 19th, 2005
Re: Saving WPF Scheduler data into SQL Database
Reply #1 - Apr 7th, 2016 at 4:55pm
Print Post  
Hi Garry,

Meppy is on a leave so you'll have to do with me for now Roll Eyes There's no built-in SQL export. You could save to a database by iterating over the schedule items and creating corresponding table rows or Entity Framework objects. E.g. this example works with EF -

Code
Select All
public Window1()
{
    InitializeComponent();
    Closing += new System.ComponentModel.CancelEventHandler(Window1_Closing);
    calendar.BeginInit();
    calendar.TimetableSettings.Dates.Clear();

    for (int i = 0; i < 5; i++)
    {
        calendar.TimetableSettings.Dates.Add(
            DateTime.Today + new TimeSpan(i, 0, 0, 0));
    }

    calendar.EndInit();

    foreach (var dbApp in db.Appointments)
    {
        calendar.Schedule.Items.Add(
            new MindFusion.Scheduling.Appointment
            {
                Tag = dbApp,
                Subject = dbApp.Title,
                DescriptionText = dbApp.Description,
                StartTime = dbApp.Start,
                EndTime = dbApp.End
            });
    }
}

void Window1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
    int autoId = db.Appointments.Any() ?
        db.Appointments.Select(a => a.Id).Max() + 1 : 0;
    foreach (MindFusion.Scheduling.Appointment app in calendar.Schedule.Items)
    {
        var dbApp = (Appointment)app.Tag;
        if (dbApp == null)
        {
            dbApp = db.Appointments.CreateObject();
            dbApp.Id = autoId++;
            db.Appointments.AddObject(dbApp);
        }
        dbApp.Title = app.Subject;
        dbApp.Description = app.DescriptionText;
        dbApp.Start = app.StartTime;
        dbApp.End = app.EndTime;
    }
    db.SaveChanges();
}

ScheduleEntities db = new ScheduleEntities(); 



If using full SqlServer you can skip the Id assignment part (I've tested that with Compact edition and it does not support auto-identifiers). Also if you don't care about creating separate records but only saving the full schedule, you could use a MemoryStream and schedule's SaveTo/LoadFrom methods, storing the stream's bytes in a BLOB or TEXT field.

Regards,
Slavcho
Mindfusion
  

Tutorial1_SqlServer.zip ( 16 KB | 157 Downloads )
Back to top
 
IP Logged
 
Garry
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 2
Joined: Apr 7th, 2016
Re: Saving WPF Scheduler data into SQL Database
Reply #2 - Apr 19th, 2016 at 5:09am
Print Post  
Sorry for late response.

I have tested your solution but its giving me a run time exception. Please see the attached screenshot.

  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint