This is a migrated thread and some comments may be shown as answers.

CUstomer Data provider and resources

2 Answers 155 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Bruce St.Clair
Top achievements
Rank 2
Bruce St.Clair asked on 31 Jul 2008, 07:01 PM
Using your sample I built a custom data provider.  Everythig works except when I try to use resources.

  In your sample you make a trip to the database to fetch the Classes.  Then you make another trip to get the resources. Then you make another trip to align the resources and classes. 

  I use a stored procedure that when I fetch my appointments ( your classes) I also have the resource ID for each appointment in said dataset.  I call LoadResources like the sample. 

  What I am having a problem with is how to align my 2 datasets using 

//Resource site = apt.Owner.Resources.GetResource("Site", ????);

 Here is my code if anybody can help I could move n with my 2 day hang up.

Default.aspx.cs

protected void Page_Load(object sender, EventArgs e)
{
RadScheduler1.GroupBy = "Site";
}

Provived Code

      public override IEnumerable<Appointment> GetAppointments(RadScheduler owner)
        {
            List<Appointment> appointments = new List<Appointment>();

   //Code removed for security, This is how I get my dataset

            DB.m_da = das;

            DataSet ds = new DataSet("Patients");
            DB.m_da.SetRead("[pWebApptsDay]", 0);

            SqlParameter pday = new SqlParameter("@day", System.Data.SqlDbType.VarChar);
            pday.Value = DateTime.Today;
            DateTime dt = DateTime.Today;
            DB.m_da.AddParam(pday);
            DB.m_da.Run(ref ds);

            System.Data.DataRow[] rows = ds.Tables[0].Select(null, null, System.Data.DataViewRowState.CurrentRows);

            foreach (DataRow row in rows)
            {
                Appointment apt = new Appointment();
                apt.Owner = owner;
                DateTime st = new DateTime();
                DateTime et = new DateTime();
                st = (DateTime)(row.ItemArray.GetValue(2));
                et = st.AddMinutes((int)row.ItemArray.GetValue(3));
                System.Drawing.Color color = ColorTranslator.FromWin32((int)row.ItemArray.GetValue(4));

                //trap for bad data IE Nulls
                if (String.IsNullOrEmpty(row.ItemArray.GetValue(5).ToString()))
                    apt.Subject = "Bad Appointment Data Contact Tims Support Appointment id =" + row.ItemArray.GetValue(0).ToString();
                else
                    apt.ID = row.ItemArray.GetValue(0).ToString();
                apt.Subject = (String)row.ItemArray.GetValue(5);
                apt.Start = Convert.ToDateTime(((DateTime)row.ItemArray.GetValue(2)).ToShortDateString() +
                    " " + ((DateTime)row.ItemArray.GetValue(2)).ToShortTimeString());
                apt.End = (apt.Start.AddMinutes((int)row.ItemArray.GetValue(3)));
                apt.BorderColor = color;

                LoadResources(apt);
                //Resource site = apt.Owner.Resources.GetResource("Site", ????);
                apt.Resources.Add(site);

                appointments.Add(apt);
               

            }
            return appointments;

       }
        public override void Insert(RadScheduler owner, Appointment appointmentToInsert)
        {
        }

        public override void Update(RadScheduler owner, Appointment appointmentToUpdate)
        {
        }

        public override void Delete(RadScheduler owner, Appointment appointmentToDelete)
        {
        }

        public override IEnumerable<ResourceType> GetResourceTypes(RadScheduler owner)
        {
            ResourceType[] resourceTypes = new ResourceType[3];
            resourceTypes[0] = new ResourceType("Site", true);
            resourceTypes[1] = new ResourceType("Provider", true);
            resourceTypes[2] = new ResourceType("Resource", true);

            return resourceTypes;
        }

        public override IEnumerable<Resource> GetResourcesByType(RadScheduler owner, string resourceType)
        {
            switch (resourceType)
            {
                case "Site":
                    return GetSite();

                case "Provider":
                    return GetProvider();

                case "Resource":
                    return GetResource();

                default:
                    throw new InvalidOperationException("Unknown resource type: " + resourceType);
            }

        }

        private IEnumerable<Resource> GetSite()
        {
            List<Resource> resources = new List<Resource>();

  //Code removed for security, This is how I get my dataset

            DB.m_da = das;

            DataSet ds = new DataSet("Resources");
            DB.m_da.SetRead("[pWebApptResourceFetch]", 0);

            SqlParameter type = new SqlParameter("@ResourceType", System.Data.SqlDbType.VarChar);
            type.Value = "Site";
            DB.m_da.AddParam(type);
            DB.m_da.Run(ref ds);

            System.Data.DataRow[] rows = ds.Tables[0].Select(null, null, System.Data.DataViewRowState.CurrentRows);

            foreach (DataRow row in rows)
            {
                Resource res = new Resource();
                res.Type = "Site";
                res.Key = row.ItemArray.GetValue(0).ToString();
                res.Text = row.ItemArray.GetValue(1).ToString(); ;
                //res.Attributes["Phone"] = Convert.ToString(reader["Phone"]);
                resources.Add(res);
            }

            return resources;
        }


Thanks for any help :)

2 Answers, 1 is accepted

Sort by
0
Accepted
Simon
Telerik team
answered on 04 Aug 2008, 11:19 AM
Hello Bruce St.Clair,

The RadScheduler.Resources.GetResource(string, object) method returns the Resource of the specified Type and with the specified Key (ID). So, to get the Site Resource of the current Appointment you need to specify its ID as the second argument.

Since you load the Resources of the current Appointment in the LoadResources(Appointment) method you should RadSchduler.Resources.GetResource() in there to load the Site resource.

In other words, since you get the ID of the Resource when loading the Appointment data, you can use this ID in the GetResource method to load the Resource object and add it to the Appointment's Resources.

Please examine the MyDbSchedulerProvider class used in the Live Demos Web Site (Live Demos/App_Code/Scheduler/MyDbSchedulerProvider.cs) for more details on the correct approach.

Regards,
Simon
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Bruce St.Clair
Top achievements
Rank 2
answered on 04 Aug 2008, 08:01 PM
Thanks for the info.  Here is the working code for anybody else that runs into this problem


DayProviderCustom.cs

DB.m_da = das;

DataSet ds = new DataSet("Patients");

DB.m_da.SetRead("[pWebApptsDay]", 0);

SqlParameter pday = new SqlParameter("@day", System.Data.SqlDbType.VarChar);

pday.Value =

DateTime.Today;

DateTime dt = DateTime.Today;

DB.m_da.AddParam(pday);

DB.m_da.Run(ref ds);

System.Data.

DataRow[] rows = ds.Tables[0].Select(null, null, System.Data.DataViewRowState.CurrentRows);

foreach (DataRow row in rows)

{

Appointment apt = new Appointment();

apt.Owner = owner;

DateTime st = new DateTime();

DateTime et = new DateTime();

st = (

DateTime)(row.ItemArray.GetValue(2));

et = st.AddMinutes((

int)row.ItemArray.GetValue(3));

System.Drawing.

Color color = ColorTranslator.FromWin32((int)row.ItemArray.GetValue(4));

//trap for bad data IE Nulls

if (String.IsNullOrEmpty(row.ItemArray.GetValue(5).ToString()))

apt.Subject =

"Bad Appointment Data Contact Tims Support Appointment id =" + row.ItemArray.GetValue(0).ToString();

else

apt.ID = row.ItemArray.GetValue(0).ToString();

apt.Subject = (

String)row.ItemArray.GetValue(5);

apt.Start =

Convert.ToDateTime(((DateTime)row.ItemArray.GetValue(2)).ToShortDateString() +

" " + ((DateTime)row.ItemArray.GetValue(2)).ToShortTimeString());

apt.End = (apt.Start.AddMinutes((

int)row.ItemArray.GetValue(3)));

apt.BorderColor = color;

 

//LoadResources(apt);

Resource site = apt.Owner.Resources.GetResource("Site", row.ItemArray.GetValue(6).ToString());

//trap any bad data

if (site != null)

{

apt.Resources.Add(site);

}

appointments.Add(apt);

Tags
Scheduler
Asked by
Bruce St.Clair
Top achievements
Rank 2
Answers by
Simon
Telerik team
Bruce St.Clair
Top achievements
Rank 2
Share this question
or