search envelope-o feed check
Home Unanswered Active Tags New Question
user comment-o

How to add resources and their events from datatable (o different datasource) in DayPilotScheduler

Asked by Elisa Bisello <e.bisello@libero.it>
16 years ago.
Hello,
I don't find information how to view events in DayPilotScheduler.
I want that every resources I can view its appointments.
My code in function Load:
SqlConnection cnn = new SqlConnection();
cnn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["ConnAttiva"].ConnectionString;
cnn.Open();

StrSql = "select ClCodice, rtrim(ClNome) + ' ' + rtrim(ClCognome) as 'nomerisorsa' " +
"from " + CodApplicazione + "UtenteLogin inner join " + CodApplicazione + "UtenteAgenzia on UlCodice = UaCodice " +
"and UaAgenziaFiliale = '" + CodAgenzia + "' and UaAgenziaContatto = '" + CodAgenzia + "' " +
"and UaCodiceFiliale = '" + Session["CodFilialeUtente"].ToString() + "' and UlCodiceCpuser <> '20' " +
"inner join " + CodApplicazione + "Contatto on ClAgenzia = UaAgenziaContatto and ClCodice = UaCodiceContatto";


SqlCommand cmd = new SqlCommand(StrSql, cnn);
SqlDataReader sdr = cmd.ExecuteReader();

DayPilotScheduler1.Resources.Clear();

while (sdr.Read())
{
DayPilotScheduler1.Resources.Add(new Resource(Convert.ToString(sdr["nomerisorsa"]), Convert.ToString(sdr["ClCodice"])));
}

sdr.Close();
cnn.Close();

My code for datatable:

protected DataTable getData
{
get
{
SqlConnection cnn = new SqlConnection();
cnn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["ConnAttiva"].ConnectionString;
cnn.Open();

//leggere gli appuntamenti e salvare in un dataset
string StrSql = "Select ClCodice, rtrim(ClNome) + ' ' + rtrim(ClCognome) as 'nomerisorsa', plagenzia + '/' + plcodice as 'key', rtrim(TpDescrizione) as tag, rtrim(TpDescrizione) + ' - ' + rtrim(PlLuogo) as subject," +
"dateadd(minute ,cast(right(PlOraInizio,2) as int),dateadd(Hour, cast(left(PlOraInizio,2) as int), PlData)) as start, " +
"dateadd(minute ,cast(right(PlOraFine,2) as int),dateadd(Hour, cast(left(PlOraFine,2) as int), PlData)) as 'end', PlNote as nota, rtrim(PlLuogo) as luogo From vst_" + CodApplicazione + "_Planner Where " +
"PlAgenzia = '" + CodAgenzia + "' And PlFiliale = '" + Session["CodFilialeUtente"].ToString() + "'";

// query
SqlDataAdapter query = new SqlDataAdapter(StrSql, cnn);

// creo il dataset
DataSet querydataset = new DataSet();
query.Fill(querydataset);

cnn.Close();

//resistuisco la tabella con i dati
return querydataset.Tables[0];
}

}

in the page aspx:

<DayPilot:DayPilotScheduler ID="DayPilotScheduler1" runat="server" TimeFormat="Clock24Hours"
DataValueField="key" DataTextField="subject" DataEndField="end" DataTagFields="tag" DataStartField="start" DataSource="<%# getData %>" DataResourceField="nomerisorsa" CellDuration="15" DurationBarColor="#666666" CellGroupBy="Hour">

</DayPilot:DayPilotScheduler>

I see the resorces, but I don't see their appointment.
what I mistake?
Thanks
Comment posted by Dan Letecky
16 years ago.
If you are matching the resources and the events using "nomerisorsa" field you should probably switch the parameters of new Resourse():

DayPilotScheduler1.Resources.Add(new Resource(Convert.ToString(sdr["ClCodice"]), Convert.ToString(sdr["nomerisorsa"])));

The first Resource constructor parameter is the resource name, the second is the value.
Comment posted by Elisa Bisello &lt;e.bisello@libero.it&gt;
16 years ago.
Yes, this is clear, but my problem is that I show only resources and not their appointments.
I create the resourses in the event Load, I add items in this way:

DayPilotScheduler1.Resources.Add(new Resource(Convert.ToString(sdr["nomerisorsa"]), Convert.ToString(sdr["ClCodice"])));

But when I create the DataTable getData for DayPilotScheduler appointment I select in the query name and text of resources, but I don't understand how to associate resorses to their appointments.
There are fields in the DayPilotScheduler for matching the resources?
I use:
DataValueField= key appointment
DataTextField=text appointment
DataEndField=date/time end appointment
DataTagFields=tipology appointment
DataStartField=date/time start appointment
DataSource=getData (DataTable)
DataResourceField=id resources
but it is wrong...
Sorry, my inglish is orrible, but I'm Italian.

Regards
Comment posted by Dan Letecky
16 years ago.
> DataValueField= key appointment
> DataTextField=text appointment
> DataEndField=date/time end appointment
> DataTagFields=tipology appointment
> DataStartField=date/time start appointment
> DataSource=getData (DataTable)
> DataResourceField=id resources

Yes, this is correct.

And when you are adding the resources, you use:

DayPilotScheduler1.Resources.Add(new Resource(resourceName, resourceId));

Where:
  • resourceName is what will be visible in the header on the left side
  • resourceId is what will be used to find the appropriate events
E.g.

1. Add a resource:

DayPilotScheduler1.Resources.Add(new Resource("First resource", "123"));

2. When having the following table:

nameidstartendresourceEvent 112007-01-01 08:002007-01-01 09:00123Event 222007-01-01 09:002007-01-01 10:00123
Use the following mapping:

DataValueField="id"
DataTextField="name"
DataEndField="end"
DataStartField="start"
DataResourceField="resource"

3. Using rendering, the value of "resource" column is compared with the resource id from the Resources collection (here "123"). If these values match, the event is rendered in that row.
Comment posted by Dan Letecky
16 years ago.
The table should look like this (it got destroyed by the editor):

name id start end resource
Event 1 1 2007-01-01 08:00 2007-01-01 09:00 123
Event 2 2 2007-01-01 09:00 2007-01-01 10:00 123
Comment posted by Dan Letecky
16 years ago.
OK, another try (I guess I need to fix the forum a little bit):

Row #1 from the DB
name: Event 1
id: 1
start: 2007-01-01 08:00
end: 2007-01-01 09:00
resource: 123

Row #2 from the DB
name: Event 2
id: 2
start: 2007-01-01 09:00
end: 2007-01-01 10:00
resource: 123
Comment posted by Elisa Bisello &lt;e.bisello@libero.it&gt;
16 years ago.
Perfect!
it works now! :)
I didn't launch theDayPilotScheduler1 DataBind!!
Thank you very much! :)

Compliments for your object, it works divinely!
This question is more than 1 months old and has been closed. Please create a new question if you have anything to add.