Calendar demo
Source of:
AddItems.aspx
<%@ Import Namespace="System.Collections.Generic" %>
<script runat="server">
void addItems() {
//
// Add new 'SchedulerItem' objects to a 'Items' collection in appropriate 'ResourceRow' object.
//
string id = DateTime.Now.ToString();
DateTime dt = DateTime.Today;
SchedulerItem it = new SchedulerItem("First new", dt.AddHours(3), dt.AddHours(18));
it.ItemID = id+"1";
it.Style.BackColor = System.Drawing.Color.Aqua;
it.LinkToIDs = new string[] { id+"2" };
Sch.Rows[0].ChildRows[3].Items.Add(it);
it = new SchedulerItem("Second new", dt.AddHours(24), dt.AddHours(30));
it.ItemID = id+"2";
it.Style.BackColor = System.Drawing.Color.Aqua;
Sch.Rows[0].ChildRows[3].Items.Add(it);
}
void removeItem(string id) {
//
// Get a SchedulerItem object with specified ID.
//
SchedulerItem it = Sch.Items.GetValue(id, false);
if (it!=null) {
//
// Move all link IDs of the children items from the current (removing) item into its parents.
//
foreach (SchedulerItem parent in Sch.Items) {
if (parent.LinkToIDs!=null) {
for (int i = 0; i<parent.LinkToIDs.Length; i++) {
if (parent.LinkToIDs[i]==it.ItemID) {
List<string> list = new List<string>(parent.LinkToIDs);
list.RemoveAt(i);
list.AddRange(it.LinkToIDs);
parent.LinkToIDs = list.ToArray();
break;
}
}
}
}
//
// Remove SchedulerItem from a ResourceRow.Items collection.
//
it.Row.Items.Remove(it);
}
}
protected void Sch_Action(object sender, ComponentGo.Web.ActionEventArgs e) {
//
// A server event executed after appropriate method in a client object below is called.
//
switch (e.Name) {
case "additems":
addItems();
break;
case "removeitem":
removeItem(e.Argument);
break;
}
}
protected void Sch_PreRender(object sender, EventArgs e) {
if (SmallBoxCheck.Checked)
Sch.ItemStyle = SchedulerItemStyle.SmallBox;
}
</script>
<script language="javascript">
function AddButton_onclick() {
//
// A method called after in a browser a button calling a server event adding new
// SchedulerItem objects is pressed.
// A server event is called using a callback.
//
SchObj.DoAction("additems");
}
function RemoveButton_onclick() {
//
// A method called after in a browser a button calling a server event removing
// SchedulerItem objects is pressed.
// A server event is called using a callback.
//
var it = SchObj.get_ClickedItem();
if (it==null)
alert("First you have to click an appropriate item.");
else
SchObj.DoAction("removeitem", it.get_ItemID());
}
</script>
<table width="100%">
<tr>
<td valign="top" width="1" style="height: 351px">
<gos:Scheduler ID="Sch" ObjectID="SchObj" runat="server" Height="293px" Width="601px"
BackColor="Lavender" Caption="Add new scheduler items" Font-Names="Verdana" Font-Size="Small"
FreeDateColor="LightCoral" FreeTimeColor="LightSteelBlue" HorizontalHeaderLine="1px Black Solid"
HorizontalLine="1px SlateBlue Solid" VerticalLine0="2px SlateBlue Solid" VerticalLine1="1px SlateBlue Solid"
VerticalResourceLine="1px SlateBlue Solid" ForeColor="Navy" SplitterColor="0, 0, 192"
VerticalLine2="1px LightSteelBlue Dotted" OnAction="Sch_Action" LinkLine="1px RoyalBlue Solid"
OnPreRender="Sch_PreRender" BehaviorOptions="AllowOverlapItems, Default">
<Columns>
<gos:ResourceColumn Text="Caption">
</gos:ResourceColumn>
</Columns>
<BodyStyle BackColor="Lavender">
</BodyStyle>
<TimeLineStyle Font-Size="X-Small" ResourceImage="Blue">
</TimeLineStyle>
<CaptionStyle HorizontalAlign="Center" ResourceImage="Blue" Font-Bold="True" Font-Size="X-Small" Border="1px Navy Solid">
</CaptionStyle>
<ResourceListStyle BackColor="AliceBlue">
</ResourceListStyle>
<ResourceHeaderStyle BackColor="AliceBlue">
</ResourceHeaderStyle>
<DefaultItemStyle>
<EventClick ClientScript="var e = document.getElementById("RemoveButton");
e.value = "Remove "+SchObj.get_ClickedItem().get_Text();" />
</DefaultItemStyle>
</gos:Scheduler>
</td>
<td valign="top" style="height: 351px">
An example demostrates how to add two linked SchedulerItem objects.
<br />
Objects will be added to a <em>Project 1 | Bathrooms</em> resource.<br />
Adding is performed by server code called using a <strong>callback</strong>.
<br />
<br />
<input id="AddButton" type="button" value="Add new items" language="javascript" onclick="return AddButton_onclick()" /><br />
<br />
You can use a <strong>callback</strong> to removing items too. First, you need click
appropriate item.
<br />
<br />
<input id="RemoveButton" type="button" value="Remove <click item first>" language="javascript"
onclick="return RemoveButton_onclick()" /><br />
<br />
You can set appearance of the items' rectangles:<br />
<asp:CheckBox ID="SmallBoxCheck" runat="server" AutoPostBack="True" Text="Small items' rectangles" /></td>
</tr>
</table>
<span style="font-size: 8pt">Adding is performed by server code, but it is initiated
by pressing a button on a HTML page in a browser. After a button is pressed a client
JavaScript <em>AddButton_onclick()</em> is called. Using a <em>GoControl.DoAction()</em>
method it calls a server event.
<br />
A <em>GoControl.Action</em> event is called. A way it works can be controlled using
<em>GoControl.EventAction</em> property settings. A call uses <strong>callback</strong>
so whole operation is performed in a background without a browser reading a whole
page again.<br />
A server <em>addItems()</em> method called by a method handling a <em>Sch_Action()</em>
event adds two new <em>SchedulerItem</em> objects to a collection. It is important
that they are added to a <em>ResourceRow.Items</em> collection, not to <em>Scheduler.Items</em>.
This means that before adding these objects, appropriate <em>ResourceRow</em> object
items will be added to should be read.<br />
The last operation after adding (changing) is to call a <em>Scheduler.RefreshClientControl()</em>
method. It informs a server scheduler control that it should prepare data refreshing
contents of a client scheduler control in a browser. Without a call to this method,
changes made by server code would not affect HTML page. Refreshing is required only
when <strong>callback</strong> events are handled. </span>