PDA

View Full Version : SQLDataSource Examples



preussmd
Nov 04, 2010, 12:19 AM
Hello,
Just wanted to say congratulations on the 1.0 release. Is there any way that you might be able to update the examples explorer with several more SQLDataSource examples? Specifically around forms. I am having issues figuring out how to add/update/delete using a SQLDataSource to an Oracle server. If the below examples could have equivalent SQLDataSource examples, that would be great.

http://examples1.ext.net/#/GridPanel/Data_with_Details/Form_Details/
http://examples1.ext.net/#/GridPanel/Miscellaneous/Details_Window_Remote/
http://examples1.ext.net/#/GridPanel/Update/AutoSave/
http://examples1.ext.net/#/Form/Miscellaneous/Edit_Form_View/

thanks,
Mike

grosenbrock
Nov 04, 2010, 8:17 PM
They basically work the same for the sqldatasource/ext:store part as the crude example below where ID_Person in the table is tied to your sequence in oracle and the logic on the buttons will trigger your insert and delete while the autosave will update your records (if it is set to true - one button disables it and another enables it).

Since there is no validation in the example it will not win gold at the olympics but it should give you an idea to how the elements play together. Feel free to use this example in any way you or others want.



<ext:ResourceManager ID="ResourceManager1" runat="server">
</ext:ResourceManager>

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:HSA_ApplicationConnectionString %>"
InsertCommand="
INSERT INTO [HSA_Person]
(NM_First,NM_last)
VALUES
(@NM_First,@NM_Last)"
SelectCommand="
SELECT
ID_Person,
NM_First,
NM_Last
FROM
[HSA_Person]"
UpdateCommand="
UPDATE
[HSA_Person]
SET
[NM_First] = @NM_First,
[NM_Last] = @NM_Last
WHERE
[ID_Person] = @ID_Person"
DeleteCommand="
DELETE FROM
[HSA_Person]
WHERE
[ID_Person] = @ID_Person">
<InsertParameters>
<asp:Parameter Name="NM_First" Type="String" />
<asp:Parameter Name="NM_Last" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="ID_Person" Type="Int32" />
<asp:Parameter Name="NM_First" Type="String" />
<asp:Parameter Name="NM_Last" Type="String" />
</UpdateParameters>
<DeleteParameters>
<asp:Parameter Name="ID_Person" Type="Int32" />
</DeleteParameters>
</asp:SqlDataSource>

<ext:GridPanel ID="View1" Title="Listing" runat="server" Frame="true" Border="true" ColumnLines="True" height= 510" AutoWidth="true"
TrackMouseOver="True" StripeRows="True" AutoScroll="True">
<Store>
<ext:Store ID="Store1" runat="server" DataSourceID="SqlDataSource1" AutoSave="True">
<Reader>
<ext:JsonReader IDProperty="ID_Person">
<Fields>
<ext:RecordField Name="ID_Person" SortType="AsInt" />
<ext:RecordField Name="NM_First" SortType="AsText" />
<ext:RecordField Name="NM_Last" SortType="AsText" />
</Fields>
</ext:JsonReader>
</Reader>
</ext:Store>
</Store>
<ColumnModel ID="ColumnModel1" runat="server">
<Columns>
<ext:Column DataIndex="ID_Person" Header="ID" Width="50" Editable="False">
</ext:Column>
<ext:Column DataIndex="NM_First" Header="First Name" Tooltip="First Name" Width="100">
<Editor>
<ext:TextField ID="TextField1" runat="server" MaxLength="50">
</ext:TextField>
</Editor>
</ext:Column>
<ext:Column DataIndex="NM_Last" Header="Last Name" Tooltip="Last Name" Width="100">
<Editor>
<ext:TextField ID="TextField2" runat="server" MaxLength="100">
</ext:TextField>
</Editor>
</ext:Column>
</Columns>
</ColumnModel>
<SelectionModel>
<ext:RowSelectionModel ID="RowSelectionModel1" runat="server" />
</SelectionModel>
<TopBar>
<ext:Toolbar ID="Toolbar1" runat="server">
<Items>
<ext:Button ID="btnPersonAdd" runat="server" Text="Add new record" Icon="Add" Disabled="false"
ToolTip="Add a new record">
<Listeners>
<Click Handler="#{Store1}.autoSave=false;#{View1}.insertRecord(0, {});#{View1}.startEditing(0,1);#{btnPersonAdd}.set Disabled(true);#{btnPersonSave}.setDisabled(false) ;" />
</Listeners>
</ext:Button>
<ext:Button ID="btnPersonSave" runat="server" Text="Save record" Icon="DatabaseSave" ToolTip="Save your changes"
Disabled="true">
<Listeners>
<Click Handler="#{View1}.save();#{Store1}.autoSave=true;#{btnPerso nAdd}.setDisabled(false);#{btnPersonSave}.setDisab led(true);" />
</Listeners>
</ext:Button>
<ext:ToolbarSeparator />
<ext:Button ID="btnPersonDelete" runat="server" Text="Delete selected records" Icon="Delete"
ToolTip="Delete the records that you have selected">
<Listeners>
<Click Handler="#{View1}.deleteSelected();#{View1}.store.load(#{Vi ew1}.store.lastOptions);" />
</Listeners>
</ext:Button>
</Items>
</ext:Toolbar>
</TopBar>
</ext:GridPanel>

preussmd
Nov 07, 2010, 8:29 PM
Thank you for providing the example grosenbrock. Would you mind updating the example to work fully? I tried dropping the code into the examples explorer but could not get it to work.

thanks.