Bonjour,
J'ai une application (Scheduler Drag-And-Drop) ou le SELECT fonctionne, l'UPDATE et le DELETE aussi, mais rien a faire quant au INSERT, il ne veut pas fonctionner
Aurais-je oublier quelque chose ?
J'attends vos aides si possible,
Merci
Voici les codes :
DefaultCS.aspx.
DefaultCS.aspx.cs
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="DefaultCS.aspx.cs" Inherits="Telerik.Web.Examples.Scheduler.DragAndDropIntegration.DefaultCS" %> <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <link rel="stylesheet" href="styles.css" type="text/css" /> </head> <body class="BODY"> <form id="form1" runat="server"> <telerik:RadScriptManager ID="ScriptManager" runat="server" /> <telerik:RadScriptBlock ID="RadScriptBlock1" runat="server"> <script type="text/javascript"> function rowDropping(sender, eventArgs) { // Fired when the user drops a grid row var htmlElement = eventArgs.get_destinationHtmlElement(); var scheduler = $find('<%= RadScheduler1.ClientID %>'); if (isPartOfSchedulerAppointmentArea(htmlElement)) { // The row was dropped over the scheduler appointment area // Find the exact time slot and save its unique index in the hidden field var timeSlot = scheduler._activeModel.getTimeSlotFromDomElement(htmlElement); $get("TargetSlotHiddenField").value = timeSlot.get_index(); // The HTML needs to be set in order for the postback to execute normally eventArgs.set_destinationHtmlElement("TargetSlotHiddenField"); } else { // The node was dropped elsewhere on the document eventArgs.set_cancel(true); } } function isPartOfSchedulerAppointmentArea(htmlElement) { // Determines if an html element is part of the scheduler appointment area // This can be either the rsContent or the rsAllDay div (in day and week view) return $telerik.$(htmlElement).parents().is("div.rsAllDay") || $telerik.$(htmlElement).parents().is("div.rsContent") } function onRowDoubleClick(sender, args) { sender.get_masterTableView().editItem(args.get_itemIndexHierarchical()); } </script> </telerik:RadScriptBlock> <input type="hidden" runat="server" id="TargetSlotHiddenField" /> <telerik:RadAjaxManager runat="server" ID="RadAjaxManager1"> <AjaxSettings> <telerik:AjaxSetting AjaxControlID="RadScheduler1"> <UpdatedControls> <telerik:AjaxUpdatedControl ControlID="RadScheduler1" /> </UpdatedControls> </telerik:AjaxSetting> <telerik:AjaxSetting AjaxControlID="RadGrid1"> <UpdatedControls> <telerik:AjaxUpdatedControl ControlID="RadGrid1" /> </UpdatedControls> </telerik:AjaxSetting> </AjaxSettings> </telerik:RadAjaxManager> <telerik:RadSplitter runat="server" ID="RadSplitter1" Height="100%" Width="100%" Skin="WebBlue" LiveResize="True"> <telerik:RadPane runat="server" ID="BottomPane" Width="30%"> <div style="border: none;"> <telerik:RadGrid runat="server" ID="RadGrid1" DataSourceID="GridDataSource" GridLines="None" AutoGenerateColumns="False" OnRowDrop="RadGrid1_RowDrop" Skin="WebBlue" Style="border: none; outline: 0" Height="100%" AllowAutomaticInserts="True" AllowAutomaticUpdates="true" ShowFooter="true" OnItemCreated="RadGrid1_ItemCreated" OnItemCommand="RadGrid1_ItemCommand" AllowSorting="true" > <ClientSettings AllowRowsDragDrop="True"> <Selecting AllowRowSelect="True" /> <ClientEvents OnRowDropping="rowDropping" OnRowDblClick="onRowDoubleClick" /> </ClientSettings> <MasterTableView DataKeyNames="AppointmentID" InsertItemDisplay="Bottom" EditMode="InPlace"> <SortExpressions> <telerik:GridSortExpression FieldName="Due" SortOrder="Ascending" /> </SortExpressions> <Columns> <telerik:GridTemplateColumn DataField="Subject" HeaderText="Task"> <ItemTemplate> <asp:Label runat="server" ID="Label1" Text='<%# Bind("Subject") %>'></asp:Label> </ItemTemplate> <FooterTemplate> <asp:LinkButton Text="New task" CommandName="<%# RadGrid.InitInsertCommandName %>" runat="server" ID="LinkButton1"></asp:LinkButton> </FooterTemplate> <EditItemTemplate> <asp:TextBox runat="Server" ID="TextBox1" Text='<%# Bind("Subject") %>' Width="100%"></asp:TextBox> </EditItemTemplate> </telerik:GridTemplateColumn> <telerik:GridDateTimeColumn DataField="Due" HeaderText="Due Date" DataFormatString="{0:d}" HeaderStyle-Width="200px"> <HeaderStyle Width="200px" /> </telerik:GridDateTimeColumn> <telerik:GridTemplateColumn DataField="Priority" HeaderText="Priority" HeaderStyle-Width="200px"> <ItemTemplate> <asp:Label runat="Server" ID="Label2" Text='<%#Bind("Priority") %>'></asp:Label> </ItemTemplate> <EditItemTemplate> <telerik:RadComboBox runat="server" ID="priorityComboBox" SelectedValue='<%#Bind("Priority") %>' Skin="Office2007" Width="80px"> <Items> <telerik:RadComboBoxItem Text="High" Value="High" /> <telerik:RadComboBoxItem Text="Medium" Value="Medium" /> <telerik:RadComboBoxItem Text="Low" Value="Low" /> </Items> </telerik:RadComboBox> <br /> <asp:LinkButton ID="btnUpdate" Text="Save" runat="server" CommandName='<%# (Container is GridDataInsertItem) ? RadGrid.PerformInsertCommandName : RadGrid.UpdateCommandName %>'></asp:LinkButton> <asp:LinkButton ID="btnCancel" Text="Cancel" runat="server" CommandName='<%# RadGrid.CancelCommandName %>'></asp:LinkButton> </EditItemTemplate> <HeaderStyle Width="200px" /> </telerik:GridTemplateColumn> </Columns> </MasterTableView> </telerik:RadGrid> </div> </telerik:RadPane> <telerik:RadSplitBar runat="Server" ID="RadSplitBar1" /> <telerik:RadPane runat="server" ID="TopPane" Scrolling="None" Width="70%"> <telerik:RadScheduler ID="RadScheduler1" runat="server" Width="100%" DataSourceID="SchedulerDataSource" DataKeyField="AppointmentID" DataStartField="Start" DataEndField="End" DataSubjectField="Subject" OnAppointmentCommand="RadScheduler1_AppointmentCommand" Skin="WebBlue" Height="100%" ShowFooter="false" RowHeaderWidth="52" CustomAttributeNames="Due, Priority" OverflowBehavior="Scroll" Culture="French (France)" DayEndTime="20:00:00" FirstDayOfWeek="Monday" SelectedView="MonthView" WorkDayEndTime="18:00:00"> <AppointmentTemplate> <%# Eval("Subject") %> <asp:Button runat="server" ID="UnscheduleAppointment" CssClass="simpleButton" CommandName="Unschedule" Text="Unschedule" ToolTip="Unschedule this appointment" /> </AppointmentTemplate> </telerik:RadScheduler> </telerik:RadPane> </telerik:RadSplitter> <asp:SqlDataSource ID="SchedulerDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:TelerikConnectionString %>" SelectCommand="SELECT [AppointmentID], [Start], [End], [Subject], [Due], [Priority] FROM [Appointments_DragAndDrop] WHERE ([Start] IS NOT NULL) AND ([End] IS NOT NULL)" InsertCommand="INSERT INTO [Appointments_DragAndDrop] ([Subject], [Start], [End]) VALUES (@Subject, @Start, @End)" UpdateCommand="UPDATE [Appointments_DragAndDrop] SET [Start] = @Start, [End] = @End, [Subject] = @Subject WHERE AppointmentID = @AppointmentID" DeleteCommand="DELETE FROM [Appointments_DragAndDrop] WHERE [AppointmentID] = @AppointmentID"> <InsertParameters> <asp:Parameter Name="Subject" Type="String" /> <asp:Parameter Name="Start" Type="DateTime" /> <asp:Parameter Name="End" Type="DateTime" /> </InsertParameters> <UpdateParameters> <asp:Parameter Name="Subject" Type="String" /> <asp:Parameter Name="Start" Type="DateTime" /> <asp:Parameter Name="End" Type="DateTime" /> <asp:Parameter Name="AppointmentID" Type="Int32" /> </UpdateParameters> <DeleteParameters> <asp:Parameter Name="AppointmentID" Type="Int32" /> </DeleteParameters> </asp:SqlDataSource> <asp:SqlDataSource ID="GridDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:TelerikConnectionString %>" SelectCommand="SELECT [AppointmentID], [Start], [End], [Subject], [Due], [Priority] FROM [Appointments_DragAndDrop] WHERE ([Start] IS NULL) AND ([End] IS NULL)" UpdateCommand="UPDATE [Appointments_DragAndDrop] SET [Start] = @Start, [End] = @End, [Subject] = @Subject, [Due] = @Due, [Priority] = @Priority WHERE AppointmentID = @AppointmentID" InsertCommand="INSERT INTO [Appointments_DragAndDrop] ([Subject], [Due], [Priority]) VALUES (@Subject, @Due, @Priority)"> <UpdateParameters> <asp:Parameter Name="Subject" Type="String" /> <asp:Parameter Name="Start" Type="DateTime" /> <asp:Parameter Name="End" Type="DateTime" /> <asp:Parameter Name="Due" Type="DateTime" /> <asp:Parameter Name="Priority" Type="String" /> <asp:Parameter Name="AppointmentID" Type="Int32" /> </UpdateParameters> <InsertParameters> <asp:Parameter Name="Subject" Type="String" /> <asp:Parameter Name="Due" Type="DateTime" /> <asp:Parameter Name="Priority" Type="String" /> </InsertParameters> </asp:SqlDataSource> </form> </body> </html>
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143 using System; using System.Collections; using System.Collections.Specialized; using System.Web.UI; using Telerik.Web.UI; using Telerik.Web.UI.Scheduler.Views; namespace Telerik.Web.Examples.Scheduler.DragAndDropIntegration { public partial class DefaultCS : Page { protected void Page_Load(object sender, EventArgs e) { } protected void RadGrid1_RowDrop(object sender, GridDragDropEventArgs e) { GridDataItem dataItem = e.DraggedItems[0]; Hashtable values = new Hashtable(); dataItem.ExtractValues(values); int id = (int)dataItem.GetDataKeyValue("AppointmentID"); string subject = (string)values["Subject"]; string targetSlotIndex = TargetSlotHiddenField.Value; if (targetSlotIndex != string.Empty) { HandleSchedulerDrop(id, subject, targetSlotIndex); TargetSlotHiddenField.Value = string.Empty; } RadScheduler1.Rebind(); RadGrid1.Rebind(); RadAjaxManager1.AjaxSettings.AddAjaxSetting(RadGrid1, RadScheduler1); } private void HandleSchedulerDrop(int id, string subject, string targetSlotIndex) { RadScheduler1.Rebind(); ISchedulerTimeSlot slot = RadScheduler1.GetTimeSlotFromIndex(targetSlotIndex); TimeSpan duration = TimeSpan.FromHours(1); if (slot.Duration == TimeSpan.FromDays(1)) { duration = slot.Duration; } ScheduleAppointment(id, subject, slot.Start, slot.Start.Add(duration)); } protected void RadScheduler1_AppointmentCommand(object sender, AppointmentCommandEventArgs e) { if (e.CommandName == "Unschedule") { int id = (int)e.Container.Appointment.ID; DateTime dueDate = DateTime.Now; if (!string.IsNullOrEmpty(e.Container.Appointment.Attributes["Due"])) dueDate = Convert.ToDateTime(e.Container.Appointment.Attributes["Due"]); string priority = "Medium"; if (!string.IsNullOrEmpty(e.Container.Appointment.Attributes["Priority"])) priority = e.Container.Appointment.Attributes["Priority"]; UnscheduleAppointment(id, dueDate, priority); RadScheduler1.Rebind(); RadGrid1.Rebind(); RadAjaxManager1.AjaxSettings.AddAjaxSetting(RadScheduler1, RadGrid1); } } private void UnscheduleAppointment(int id, DateTime dueDate, string priority) { IDataSource dataSource = GridDataSource; DataSourceView view = dataSource.GetView("DefaultView"); IOrderedDictionary data = new OrderedDictionary(); data.Add("Start", null); data.Add("End", null); data.Add("Due", dueDate); data.Add("Priority", priority); IDictionary keys = new OrderedDictionary(); keys.Add("AppointmentID", id); view.Update(keys, data, new OrderedDictionary(), OnDataSourceOperationComplete); } private void ScheduleAppointment(int id, string subject, DateTime start, DateTime end) { IDataSource dataSource = SchedulerDataSource; DataSourceView view = dataSource.GetView("DefaultView"); IOrderedDictionary data = new OrderedDictionary(); data.Add("Subject", subject); data.Add("Start", start); data.Add("End", end); IDictionary keys = new OrderedDictionary(); keys.Add("AppointmentID", id); view.Update(keys, data, new OrderedDictionary(), OnDataSourceOperationComplete); } private static bool OnDataSourceOperationComplete(int count, Exception e) { if (e != null) { throw e; } return true; } protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e) { if (e.Item is GridFooterItem && RadGrid1.MasterTableView.IsItemInserted) { e.Item.Visible = false; } } protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e) { if (e.CommandName == RadGrid.InitInsertCommandName) { e.Canceled = true; //Prepare an IDictionary with the predefined values ListDictionary newValues = new ListDictionary(); newValues["Priority"] = "Medium"; newValues["Due"] = DateTime.Now; newValues["Subject"] = "Nouvelle tâche"; //Insert the item and rebind e.Item.OwnerTableView.InsertItem(newValues); } } } }
Partager