We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Reading and Writing schedule data from/to SQL

Thread ID:

Created:

Updated:

Platform:

Replies:

144190 Apr 24,2019 07:27 AM UTC Apr 25,2019 11:38 AM UTC WinForms 1
loading
Tags: ScheduleControl
Anton
Asked On April 24, 2019 07:27 AM UTC

Hi,

I'm trying to build an app that manages a schedule on a desktop application. This application should be able to read and write to/from SQL database so that I can pull the data to a mobile application later on.

Are there any simple samples available that implements CRUD with the ScheduleControl on WinForms?



Jagadeesan Pichaimuthu [Syncfusion]
Replied On April 25, 2019 11:38 AM UTC

Hi Marco,  

Thanks for using Syncfusion products.  

By default, Schedule control does not have the direct support to bind the data from DB. If you want to generate the appointment based on the DB data, you can create the appointment based on the DB data using StartTime, EndTime and Subject property in SimpleSheduleDataProvider. Please refer to the below code example,   
  
VB  
SimpleScheduleDataProvider dataProvider = new SimpleScheduleDataProvider(); 
dataProvider.MasterList = SimpleScheduleDataProvider.InitializeRandomData(); 
scheduleControl1.DataSource = dataProvider; 
public class SimpleScheduleDataProvider : ScheduleDataProvider 
{ 
 
    DataSet dset = new DataSet(); 
        static DataTable dt = new DataTable(); 
                /// <summary> 
                /// Default constructor. 
                /// </summary> 
                public SimpleScheduleDataProvider() 
                                : base() 
                { 
          dset.ReadXml(@"..\..\default.xml"); 
          dt = dset.Tables["MasterList"]; 
                } 
 
                 
 
                private SimpleScheduleAppointmentList masterList; 
 
                /// <summary> 
                /// Get or sets an IScheduleAppointmentList collection that holds the IScheduleAppointments.  
                /// </summary> 
                public SimpleScheduleAppointmentList MasterList 
                { 
                                get{return masterList;} 
                                set{masterList = value;} 
                } 
 
                #region random data 
 
    public static SimpleScheduleAppointmentList InitializeRandomData() 
    { 
        Random r = new Random(tc); 
 
        // set the number of sample items you want in this list. 
        int count = dt.Rows.Count;  
        SimpleScheduleAppointmentList masterList = new SimpleScheduleAppointmentList(); 
        for (int i = 0; i < count; ++i) 
        { 
            ScheduleAppointment item = masterList.NewScheduleAppointment() as ScheduleAppointment; 
            int dayOffSet = 30 - r.Next(60); 
            int hourOffSet = 24 - r.Next(48); 
            int len = 30 * (r.Next(4) + 1); 
            item.StartTime = DateTime.Now.AddDays(i);  
            item.EndTime = DateTime.Now.AddDays(i);            item.Subject = dt.Rows[i]["Subject"].ToString(); 
            item.Content = dt.Rows[i]["Content"].ToString(); 
            item.LabelValue = Convert.ToInt16(dt.Rows[i]["LabelValue"]); 
            item.LocationValue = dt.Rows[i]["LocationValue"].ToString(); 
            item.MarkerValue = (Convert.ToInt16(dt.Rows[i]["MarkerValue"])); 
            item.UniqueId = i; 
           item.Dirty = false; 
            masterList.Add(item); 
        } 
        masterList.SortStartTime(); 
        return masterList; 
} 
  
To perform the CRUD operation in ScheduleControl to your binding source, you could perform the operation using ItemChanged event. Please refer the following code example. 
 
Edit 
this.scheduleControl1.ItemChanged += ScheduleControl1_ItemChanged; 
private void ScheduleControl1_ItemChanged(object sender, ScheduleAppointmentEventArgs e) 
{ 
    if (e.Action == ItemAction.Edit) 
    { 
        int id = e.CurrentItem.UniqueID; 
        var dr = SimpleScheduleDataProvider.dt.Rows.Cast<DataRow>().First(x => x[10].Equals(e.CurrentItem.UniqueID.ToString())); 
        int index = SimpleScheduleDataProvider.dt.Rows.IndexOf(dr as DataRow); 
        if (index > -1) 
        { 
            dr[0] = e.CurrentItem.StartTime; 
            dr[1] = e.CurrentItem.EndTime; 
            dr[2] = e.CurrentItem.Subject; 
            dr[3] = e.CurrentItem.AllDay; 
            dr[4] = e.CurrentItem.Content; 
            dr[5] = e.CurrentItem.LabelValue; 
            dr[6] = e.CurrentItem.MarkerValue; 
            dr[7] = e.CurrentItem.Reminder; 
            dr[8] = e.CurrentItem.ReminderValue; 
            dr[9] = e.CurrentItem.LocationValue; 
            dr[10] = e.CurrentItem.UniqueID; 
        } 
    } 
} 
 
Add 
//In SimpleScheduleDataProvider class 
public override void AddItem(IScheduleAppointment item) 
{ 
    DataRow dr = dt.NewRow(); 
    dr[0] = item.StartTime; 
    dr[1] = item.EndTime; 
    dr[2] = item.Subject; 
    dr[3] = item.AllDay; 
    dr[4] = item.Content; 
    dr[5] = item.LabelValue; 
    dr[6] = item.MarkerValue; 
    dr[7] = item.Reminder; 
    dr[8] = item.ReminderValue; 
    dr[9] = item.LocationValue; 
    dr[10] = item.UniqueID; 
    dt.Rows.Add(dr); 
                this.MasterList.Add(item); 
} 
 
Delete 
//In SimpleScheduleDataProvider class 
public override void RemoveItem(IScheduleAppointment item) 
{ 
    var row = dt.Rows.Cast<DataRow>().First(x => x[10].Equals(item.UniqueID.ToString())); 
    int index = dt.Rows.IndexOf(row as DataRow); 
    if (index>-1) 
    { 
        dt.Rows.RemoveAt(index); 
    } 
                this.MasterList.Remove(item); 
} 
 
  
Please get back to us if you need any further assistance on this.  
  
Regards, 
Jagadeesan

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon