RE: Insert Record Form Panel
Code:
<Buttons>
<ext:Button ID="ButtonUpdate" runat="server" Text="Save Record Store" Icon="Disk">
<Listeners>
<Click Handler="#{Store1}.insertRecord(0);#{FormPanel1}.getForm().updateRecord(#{Store1}.getAt(0));#{Store1}.save();" />
</Listeners>
</ext:Button>
</Buttons>
However I get this error.
{serviceResponse:{Data:{confirm:[{s:false,oldId:"1001",newId:"1001"}]},Success:true}}
And the record does not commit itself to the DB.
RE: Insert Record Form Panel
This was also covered in this thread
http://forums.ext.net/showthread.php?5016
However I cant seem to put the pieces together or I'm missing something. Here is the entire page. Any advice or help would be appriciated. Thanks
Code:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TestForm.aspx.cs" Inherits="TestForm" %>
<%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script runat="server">
private bool cancel;
private string message;
protected void Store1_AfterRecordInserted(object sender, AfterRecordInsertedEventArgs e)
{
//The deleted and updated records confirms automatic (depending AffectedRows field)
//But you can override this in AfterRecordUpdated and AfterRecordDeleted event
//For insert we should set new id for refresh on client
//If we don't set new id then old id will be used
if (e.Confirmation.Confirm && !string.IsNullOrEmpty(insertedValue))
{
e.Confirmation.ConfirmRecord(insertedValue);
insertedValue = "";
}
}
private string insertedValue;
protected void SqlDataSource1_Inserted(object sender, SqlDataSourceStatusEventArgs e)
{
//use e.AffectedRows for ensure success action. The store read this value and set predefined Confirm depend on e.AffectedRows
//The Confirm can be granted or denied in OnRecord....ed event
insertedValue = e.Command.Parameters["@newId"].Value != null
? e.Command.Parameters["@newId"].Value.ToString()
: "";
}
protected void Store1_AfterAjaxEvent(object sender, AfterAjaxEventArgs e)
{
if (e.Response.Success)
{
// set to .Success to false if we want to return a failure
e.Response.Success = !cancel;
e.Response.Msg = message;
}
}
protected void Store1_BeforeAjaxEvent(object sender, BeforeAjaxEventArgs e)
{
string emulError = e.Parameters["EmulateError"];
if (emulError == "1")
{
throw new Exception("Emulating error");
}
}
protected void Store1_RefershData(object sender, StoreRefreshDataEventArgs e)
{
this.Store1.DataBind();
}
</script>
</head>
<body>
<form id="form1" runat="server">
<ext:ScriptManager runat="server" />
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:CMMS_Connection %>"
InsertCommand="INSERT INTO Test
(TestValue)
VALUES
(@TestValue);
SELECT @TestID = @@Identity;"
OnInserted="SqlDataSource1_Inserted">
<InsertParameters>
<asp:Parameter Name="TestValue" Type="String" />
<asp:Parameter Direction="Output" Name="newId" Type="Int32" />
</InsertParameters>
</asp:SqlDataSource>
<ext:Store ID="Store1" runat="server"
DataSourceID="SqlDataSource1"
OnAfterAjaxEvent="Store1_AfterAjaxEvent"
OnBeforeAjaxEvent="Store1_BeforeAjaxEvent"
UseIdConfirmation="true"
OnAfterRecordInserted="Store1_AfterRecordInserted"
OnRefreshData="Store1_RefershData">
<Reader>
<ext:JsonReader ReaderID="TestID">
<Fields>
<ext:RecordField Name="TestValue" />
</Fields>
</ext:JsonReader>
</Reader>
<SortInfo Field="TestValue" Direction="ASC" />
<Listeners>
<LoadException Handler="Ext.Msg.alert('Status - Load failed', e.message || e )" />
<CommitFailed Handler="Ext.Msg.alert('Status - Commit failed', 'Reason: ' + msg)" />
<SaveException Handler="Ext.Msg.alert('Status - Save failed', e.message || e)" />
<CommitDone Handler="Ext.Msg.alert('Status - Commit', 'The data successfully saved');" />
</Listeners>
</ext:Store>
<Center>
<ext:FormPanel ID="FormPanel1" runat="server" Title="Form Panel" BodyStyle="padding:5px;" ButtonAlign="Right">
<Body>
<ext:FormLayout ID="FormLayout1" runat="server">
<ext:Anchor Horizontal="95%">
<ext:TextField ID="TestValue" DataIndex="TestValue" runat="server" FieldLabel="Test" />
</ext:Anchor>
</ext:FormLayout>
</Body>
<Buttons>
<ext:Button ID="ButtonUpdate" runat="server" Text="Save Record Store" Icon="Disk">
<Listeners>
<Click Handler="#{Store1}.insertRecord(0);#{FormPanel1}.getForm().updateRecord(#{Store1}.getAt(0));#{Store1}.save();" />
</Listeners>
</ext:Button>
</Buttons>
</ext:FormPanel>
</Center>
</form>
</body>
</html>
RE: Insert Record Form Panel
I still can't seem to get this to work.
Any thoughts?
RE: Insert Record Form Panel
This is what worked for me.
Also I had an incorrect newid value for the SELECT @newId = @@Identity; in my SqlDataSource
Code:
<ext:Button ID="ButtonUpdate" runat="server" Text="Add New" Icon="Disk">
<Listeners>
<Click Handler="#{GridPanel1}.insertRecord(0, {});#{FormPanel1}.getForm().updateRecord(#{Store1}.getAt(0, {}));#{Store1}.save()" />
<%--<Click Handler="#{Store1}.insertRecord(0);#{FormPanel1}.getForm().loadRecord(#{Store1}.getAt(0));#{Store1}.save()" />--%>
</Listeners>
</ext:Button>
RE: Insert Record Form Panel
Hi... Im having the same problem.. can you please post your entire page code because im confused as you used gridpanel1 in your last post but you dont have gridpanel on your page code.
Im a newbie and I would really appreciate your help.
Thanks in advance.
RE: Insert Record Form Panel
Here is the entire page.
Code:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Inventory.aspx.cs" Inherits="Inventory" %>
<%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>FormPanel - Coolite Toolkit Examples</title>
<script runat="server">
private bool cancel;
private string message;
protected void Store1_AfterRecordInserted(object sender, AfterRecordInsertedEventArgs e)
{
//The deleted and updated records confirms automatic (depending AffectedRows field)
//But you can override this in AfterRecordUpdated and AfterRecordDeleted event
//For insert we should set new id for refresh on client
//If we don't set new id then old id will be used
if (e.Confirmation.Confirm && !string.IsNullOrEmpty(insertedValue))
{
e.Confirmation.ConfirmRecord(insertedValue);
insertedValue = "";
}
}
private string insertedValue;
protected void SqlDataSource1_Inserted(object sender, SqlDataSourceStatusEventArgs e)
{
//use e.AffectedRows for ensure success action. The store read this value and set predefined Confirm depend on e.AffectedRows
//The Confirm can be granted or denied in OnRecord....ed event
insertedValue = e.Command.Parameters["@newId"].Value != null
? e.Command.Parameters["@newId"].Value.ToString()
: "";
}
protected void Store1_AfterAjaxEvent(object sender, AfterAjaxEventArgs e)
{
if (e.Response.Success)
{
// set to .Success to false if we want to return a failure
e.Response.Success = !cancel;
e.Response.Msg = message;
}
}
protected void Store1_BeforeAjaxEvent(object sender, BeforeAjaxEventArgs e)
{
string emulError = e.Parameters["EmulateError"];
if (emulError == "1")
{
throw new Exception("Emulating error");
}
}
protected void Store1_RefershData(object sender, StoreRefreshDataEventArgs e)
{
this.Store1.DataBind();
}
</script>
</head>
<body>
<form id="form1" runat="server">
<ext:ScriptManager ID="ScriptManager1" runat="server" ScriptMode="Debug" />
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:CMMS_Connection %>"
DeleteCommand="DELETE FROM TblInventoryMaster WHERE (ItemID = @ItemID)"
InsertCommand="INSERT INTO TblInventoryMaster
(PropertyClassID
,ItemName
,Nomenclature
,SerialNumber
,Model
,PartNumber
,StockNumber
,UnitofMeasure
,Manufacturer
,LocationBldg
,LocationRoom
,LocationOther
,Warranty
,SoftwareLicenseExpireDate
,PurchaseOrderNumber
,ItemCost
,PurchaseOrderDate
,ExpectedReceiveDate
,RecieveDate
,DisposalDate
,ShelfLifeCide
,PurchaseOrderStatusID
,WSS_DocumentRepository)
VALUES
(@PropertyClassID
,@ItemName
,@Nomenclature
,@SerialNumber
,@Model
,@PartNumber
,@StockNumber
,@UnitofMeasure
,@Manufacturer
,@LocationBldg
,@LocationRoom
,@LocationOther
,@Warranty
,@SoftwareLicenseExpireDate
,@PurchaseOrderNumber
,@ItemCost
,@PurchaseOrderDate
,@ExpectedReceiveDate
,@RecieveDate
,@DisposalDate
,@ShelfLifeCide
,@PurchaseOrderStatusID
,@WSS_DocumentRepository);
SELECT @newId = @@Identity;"
SelectCommand="SELECT
ItemID,
PropertyClassID
,ItemName
,Nomenclature
,SerialNumber
,Model
,PartNumber
,StockNumber
,UnitofMeasure
,Manufacturer
,LocationBldg
,LocationRoom
,LocationOther
,Warranty
,SoftwareLicenseExpireDate
,PurchaseOrderNumber
,ItemCost
,PurchaseOrderDate
,ExpectedReceiveDate
,RecieveDate
,DisposalDate
,ShelfLifeCide
,PurchaseOrderStatusID
,WSS_DocumentRepository
FROM TblInventoryMaster"
UpdateCommand="UPDATE TblInventoryMaster
SET PropertyClassID = @PropertyClassID
,ItemName = @ItemName
,Nomenclature = @Nomenclature
,SerialNumber = @SerialNumber
,Model = @Model
,PartNumber = @PartNumber
,StockNumber = @StockNumber
,UnitofMeasure = @UnitofMeasure
,Manufacturer = @Manufacturer
,LocationBldg = @LocationBldg
,LocationRoom = @LocationRoom
,LocationOther = @LocationOther
,Warranty = @Warranty
,SoftwareLicenseExpireDate = @SoftwareLicenseExpireDate
,PurchaseOrderNumber = @PurchaseOrderNumber
,ItemCost = @ItemCost
,PurchaseOrderDate = @PurchaseOrderDate
,ExpectedReceiveDate = @ExpectedReceiveDate
,RecieveDate = @RecieveDate
,DisposalDate = @DisposalDate
,ShelfLifeCide = @ShelfLifeCide
,PurchaseOrderStatusID = @PurchaseOrderStatusID
,WSS_DocumentRepository = @WSS_DocumentRepository
WHERE (ItemID = @ItemID)"
OnInserted="SqlDataSource1_Inserted">
<DeleteParameters>
<asp:Parameter Name="ItemID" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="PropertyClassID" Type="Int32" />
<asp:Parameter Name="ItemName" Type="String" />
<asp:Parameter Name="Nomenclature" Type="String" />
<asp:Parameter Name="SerialNumber" Type="String" />
<asp:Parameter Name="Model" Type="String" />
<asp:Parameter Name="PartNumber" Type="String" />
<asp:Parameter Name="StockNumber" Type="String" />
<asp:Parameter Name="UnitofMeasure" Type="String" />
<asp:Parameter Name="Manufacturer" Type="String" />
<asp:Parameter Name="LocationBldg" Type="String" />
<asp:Parameter Name="LocationRoom" Type="String" />
<asp:Parameter Name="LocationOther" Type="String" />
<asp:Parameter Name="Warranty" Type="String" />
<asp:Parameter Name="SoftwareLicenseExpireDate" Type="String" />
<asp:Parameter Name="PurchaseOrderNumber" Type="String" />
<asp:Parameter Name="ItemCost" Type="String" />
<asp:Parameter Name="PurchaseOrderDate" Type="String" />
<asp:Parameter Name="ExpectedReceiveDate" Type="String" />
<asp:Parameter Name="RecieveDate" Type="String" />
<asp:Parameter Name="DisposalDate" Type="String" />
<asp:Parameter Name="ShelfLifeCide" Type="String" />
<asp:Parameter Name="PurchaseOrderStatusID" Type="Int32" />
<asp:Parameter Name="WSS_DocumentRepository" Type="String" />
<asp:Parameter Name="ItemID" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="PropertyClassID" Type="Int32" />
<asp:Parameter Name="ItemName" Type="String" />
<asp:Parameter Name="Nomenclature" Type="String" />
<asp:Parameter Name="SerialNumber" Type="String" />
<asp:Parameter Name="Model" Type="String" />
<asp:Parameter Name="PartNumber" Type="String" />
<asp:Parameter Name="StockNumber" Type="String" />
<asp:Parameter Name="UnitofMeasure" Type="String" />
<asp:Parameter Name="Manufacturer" Type="String" />
<asp:Parameter Name="LocationBldg" Type="String" />
<asp:Parameter Name="LocationRoom" Type="String" />
<asp:Parameter Name="LocationOther" Type="String" />
<asp:Parameter Name="Warranty" Type="String" />
<asp:Parameter Name="SoftwareLicenseExpireDate" Type="String" />
<asp:Parameter Name="PurchaseOrderNumber" Type="String" />
<asp:Parameter Name="ItemCost" Type="String" />
<asp:Parameter Name="PurchaseOrderDate" Type="String" />
<asp:Parameter Name="ExpectedReceiveDate" Type="String" />
<asp:Parameter Name="RecieveDate" Type="String" />
<asp:Parameter Name="DisposalDate" Type="String" />
<asp:Parameter Name="ShelfLifeCide" Type="String" />
<asp:Parameter Name="PurchaseOrderStatusID" Type="Int32" />
<asp:Parameter Name="WSS_DocumentRepository" Type="String" />
<asp:Parameter Direction="Output" Name="newId" Type="Int32" />
</InsertParameters>
</asp:SqlDataSource>
<ext:Store ID="Store1" runat="server"
DataSourceID="SqlDataSource1"
OnAfterAjaxEvent="Store1_AfterAjaxEvent"
OnBeforeAjaxEvent="Store1_BeforeAjaxEvent"
UseIdConfirmation="true"
OnAfterRecordInserted="Store1_AfterRecordInserted"
OnRefreshData="Store1_RefershData">
<Reader>
<ext:JsonReader ReaderID="ItemID">
<Fields>
<ext:RecordField Name="PropertyClassID" />
<ext:RecordField Name="ItemName" />
<ext:RecordField Name="Nomenclature" />
<ext:RecordField Name="SerialNumber" />
<ext:RecordField Name="Model" />
<ext:RecordField Name="PartNumber" />
<ext:RecordField Name="StockNumber" />
<ext:RecordField Name="UnitofMeasure" />
<ext:RecordField Name="Manufacturer" />
<ext:RecordField Name="LocationBldg" />
<ext:RecordField Name="LocationRoom" />
<ext:RecordField Name="LocationOther" />
<ext:RecordField Name="Warranty" />
<ext:RecordField Name="SoftwareLicenseExpireDate" Type="Date" />
<ext:RecordField Name="PurchaseOrderNumber" />
<ext:RecordField Name="ItemCost" />
<ext:RecordField Name="PurchaseOrderDate" Type="Date" />
<ext:RecordField Name="ExpectedReceiveDate" Type="Date" />
<ext:RecordField Name="RecieveDate" Type="Date" />
<ext:RecordField Name="DisposalDate" Type="Date" />
<ext:RecordField Name="ShelfLifeCide" />
<ext:RecordField Name="PurchaseOrderStatusID" />
<ext:RecordField Name="WSS_DocumentRepository" />
</Fields>
</ext:JsonReader>
</Reader>
<SortInfo Field="ItemName" Direction="ASC" />
<Listeners>
<LoadException Handler="Ext.Msg.alert('Status - Load failed', e.message || e )" />
<CommitFailed Handler="Ext.Msg.alert('Status - Commit failed', 'Reason: ' + msg)" />
<SaveException Handler="Ext.Msg.alert('Status - Save failed', e.message || e)" />
<CommitDone Handler="Ext.Msg.alert('Status - Commit', 'The data successfully saved');" />
</Listeners>
</ext:Store>
<ext:Panel ID="Panel1" runat="server" Width="800" Height="800">
<Body>
<ext:BorderLayout ID="BorderLayout1" runat="server">
<West>
<ext:GridPanel
ID="GridPanel1"
runat="server"
StoreID="Store1"
StripeRows="true"
Title="Grid"
TrackMouseOver="true"
Width="500"
AutoExpandColumn="ItemName">
<ColumnModel ID="ColumnModel1" runat="server">
<Columns>
<ext:Column ColumnID="ItemName" Header="Item Name" Width="160" Sortable="true" DataIndex="ItemName" />
<ext:Column Header="Nomenclature" Width="75" Sortable="true" DataIndex="Nomenclature" /> </Columns>
</ColumnModel>
<SelectionModel>
<ext:RowSelectionModel ID="RowSelectionModel1" runat="server" SingleSelect="true">
<Listeners>
<RowSelect Handler="#{FormPanel1}.getForm().loadRecord(record);" />
</Listeners>
</ext:RowSelectionModel>
</SelectionModel>
</ext:GridPanel>
</West>
<Center>
<ext:FormPanel ID="FormPanel1" runat="server" Title="Form Panel" StoreID="Store1" BodyStyle="padding:5px;" ButtonAlign="Right">
<Body>
<ext:FormLayout ID="FormLayout1" runat="server">
<ext:Anchor Horizontal="95%">
<ext:TextField ID="PropertyClassID" DataIndex="PropertyClassID" runat="server" FieldLabel="Property Class" />
</ext:Anchor>
<ext:Anchor Horizontal="95%">
<ext:TextField ID="ItemName" DataIndex="ItemName" runat="server" FieldLabel="Item Name" />
</ext:Anchor>
<ext:Anchor Horizontal="95%">
<ext:TextField ID="Nomenclature" DataIndex="Nomenclature" runat="server" FieldLabel="Nomenclature" />
</ext:Anchor>
<ext:Anchor Horizontal="95%">
<ext:TextField ID="SerialNumber" DataIndex="SerialNumber" runat="server" FieldLabel="Serial Number" />
</ext:Anchor>
<ext:Anchor Horizontal="95%">
<ext:TextField ID="Model" DataIndex="Model" runat="server" FieldLabel="Model" />
</ext:Anchor>
<ext:Anchor Horizontal="95%">
<ext:TextField ID="PartNumber" DataIndex="PartNumber" runat="server" FieldLabel="Part Number" />
</ext:Anchor>
<ext:Anchor Horizontal="95%">
<ext:TextField ID="StockNumber" DataIndex="StockNumber" runat="server" FieldLabel="Stock Number" />
</ext:Anchor>
<ext:Anchor Horizontal="95%">
<ext:TextField ID="UnitofMeasure" DataIndex="UnitofMeasure" runat="server" FieldLabel="Unit of Measure " />
</ext:Anchor>
<ext:Anchor Horizontal="95%">
<ext:TextField ID="Manufacturer" DataIndex="Manufacturer" runat="server" FieldLabel="Manufacturer" />
</ext:Anchor>
<ext:Anchor Horizontal="95%">
<ext:TextField ID="LocationBldg" DataIndex="LocationBldg" runat="server" FieldLabel="Location Bldg" />
</ext:Anchor>
<ext:Anchor Horizontal="95%">
<ext:TextField ID="LocationRoom" DataIndex="LocationRoom" runat="server" FieldLabel="Location Room" />
</ext:Anchor>
<ext:Anchor Horizontal="95%">
<ext:TextField ID="LocationOther" DataIndex="LocationOther" runat="server" FieldLabel="Location Other" />
</ext:Anchor>
<ext:Anchor Horizontal="95%">
<ext:DateField ID="Warranty" DataIndex="Warranty" runat="server" FieldLabel="Warranty" />
</ext:Anchor>
<ext:Anchor Horizontal="95%">
<ext:DateField ID="SoftwareLicenseExpireDate" DataIndex="SoftwareLicenseExpireDate" runat="server" FieldLabel="Software License Expire Date" />
</ext:Anchor>
<ext:Anchor Horizontal="95%">
<ext:TextField ID="PurchaseOrderNumber" DataIndex="PurchaseOrderNumber" runat="server" FieldLabel="Purchase Order Number" />
</ext:Anchor>
<ext:Anchor Horizontal="95%">
<ext:TextField ID="ItemCost" DataIndex="ItemCost" runat="server" FieldLabel="Item Cost" />
</ext:Anchor>
<ext:Anchor Horizontal="95%">
<ext:DateField ID="PurchaseOrderDate" DataIndex="PurchaseOrderDate" runat="server" FieldLabel="Purchase Order Date" />
</ext:Anchor>
<ext:Anchor Horizontal="95%">
<ext:DateField ID="ExpectedReceiveDate" DataIndex="ExpectedReceiveDate" runat="server" FieldLabel="Expected Receive Date" />
</ext:Anchor>
<ext:Anchor Horizontal="95%">
<ext:DateField ID="RecieveDate" DataIndex="RecieveDate" runat="server" FieldLabel="Recieve Date" />
</ext:Anchor>
<ext:Anchor Horizontal="95%">
<ext:DateField ID="DisposalDate" DataIndex="DisposalDate" runat="server" FieldLabel="Disposal Date" />
</ext:Anchor>
<ext:Anchor Horizontal="95%">
<ext:TextField ID="ShelfLifeCide" DataIndex="ShelfLifeCide" runat="server" FieldLabel="Shelf Life Cide" />
</ext:Anchor>
<ext:Anchor Horizontal="95%">
<ext:TextField ID="PurchaseOrderStatusID" DataIndex="PurchaseOrderStatusID" runat="server" FieldLabel="Purchase Order Status" />
</ext:Anchor>
<ext:Anchor Horizontal="95%">
<ext:TextField ID="WSS_DocumentRepository" DataIndex="WSS_DocumentRepository" runat="server" FieldLabel="Test" />
</ext:Anchor>
</ext:FormLayout>
</Body>
<Buttons>
<ext:Button ID="ButtonUpdate" runat="server" Text="Add New" Icon="Disk">
<Listeners>
<Click Handler="#{GridPanel1}.insertRecord(0, {});#{FormPanel1}.getForm().updateRecord(#{Store1}.getAt(0, {}));#{Store1}.save()" />
</Listeners>
</ext:Button>
<ext:Button ID="ButtonReset" runat="server" Text="Reset Fields">
<Listeners>
<Click Handler="#{GridPanel1}.save();" />
</Listeners>
</ext:Button>
<ext:Button ID="btnInsert" runat="server" Text="Save" Icon="Add">
<Listeners>
<Click Handler="#{FormPanel1}.getForm().updateRecord(#{GridPanel1}.getSelectionModel().getSelected());#{GridPanel1}.save();" />
</Listeners>
</ext:Button>
</Buttons>
</ext:FormPanel>
</Center>
</ext:BorderLayout>
</Body>
</ext:Panel>
</form>
</body>
</html>
Still need to change my reset button back to clear the form fields (its in the original example) and add some code that will disable the buttons appropriately, because if you click the save button while there is no record it will cause a JavaScript error.
I need to add validation and a few combo boxes. I'll post that later as well.
RE: Insert Record Form Panel
Code:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Inventory.aspx.cs" Inherits="Inventory" %>
<%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>FormPanel - Coolite Toolkit Examples</title>
<script runat="server">
private bool cancel;
private string message;
protected void Store1_AfterRecordInserted(object sender, AfterRecordInsertedEventArgs e)
{
//The deleted and updated records confirms automatic (depending AffectedRows field)
//But you can override this in AfterRecordUpdated and AfterRecordDeleted event
//For insert we should set new id for refresh on client
//If we don't set new id then old id will be used
if (e.Confirmation.Confirm && !string.IsNullOrEmpty(insertedValue))
{
e.Confirmation.ConfirmRecord(insertedValue);
insertedValue = "";
}
}
private string insertedValue;
protected void SqlDataSource1_Inserted(object sender, SqlDataSourceStatusEventArgs e)
{
//use e.AffectedRows for ensure success action. The store read this value and set predefined Confirm depend on e.AffectedRows
//The Confirm can be granted or denied in OnRecord....ed event
insertedValue = e.Command.Parameters["@newId"].Value != null
? e.Command.Parameters["@newId"].Value.ToString()
: "";
}
protected void Store1_AfterAjaxEvent(object sender, AfterAjaxEventArgs e)
{
if (e.Response.Success)
{
// set to .Success to false if we want to return a failure
e.Response.Success = !cancel;
e.Response.Msg = message;
}
}
protected void Store1_BeforeAjaxEvent(object sender, BeforeAjaxEventArgs e)
{
string emulError = e.Parameters["EmulateError"];
if (emulError == "1")
{
throw new Exception("Emulating error");
}
}
protected void Store1_RefershData(object sender, StoreRefreshDataEventArgs e)
{
this.Store1.DataBind();
}
</script>
</head>
<body>
<form id="form1" runat="server">
<ext:ScriptManager ID="ScriptManager1" runat="server" ScriptMode="Debug" />
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:CMMS_Connection %>"
SelectCommand="SELECT
PropertyClassID,
PropertyClassTitle
FROM TblPropertyClassMaster">
</asp:SqlDataSource>
<ext:Store ID="Store2" runat="server" AutoLoad="true" DataSourceID="SqlDataSource2">
<Reader>
<ext:JsonReader ReaderID="PropertyClassID">
<Fields>
<ext:RecordField Name="PropertyClassID" />
<ext:RecordField Name="PropertyClassTitle" />
</Fields>
</ext:JsonReader>
</Reader>
</ext:Store>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:CMMS_Connection %>"
DeleteCommand="DELETE FROM TblInventoryMaster WHERE (ItemID = @ItemID)"
InsertCommand="INSERT INTO TblInventoryMaster
(PropertyClassID
,ItemName
,Nomenclature
,SerialNumber
,Model
,PartNumber
,StockNumber
,UnitofMeasure
,Manufacturer
,LocationBldg
,LocationRoom
,LocationOther
,Warranty
,SoftwareLicenseExpireDate
,PurchaseOrderNumber
,ItemCost
,PurchaseOrderDate
,ExpectedReceiveDate
,RecieveDate
,DisposalDate
,ShelfLifeCide
,PurchaseOrderStatusID
,WSS_DocumentRepository)
VALUES
(@PropertyClassID
,@ItemName
,@Nomenclature
,@SerialNumber
,@Model
,@PartNumber
,@StockNumber
,@UnitofMeasure
,@Manufacturer
,@LocationBldg
,@LocationRoom
,@LocationOther
,@Warranty
,@SoftwareLicenseExpireDate
,@PurchaseOrderNumber
,@ItemCost
,@PurchaseOrderDate
,@ExpectedReceiveDate
,@RecieveDate
,@DisposalDate
,@ShelfLifeCide
,@PurchaseOrderStatusID
,@WSS_DocumentRepository);
SELECT @newId = @@Identity;"
SelectCommand="SELECT
ItemID,
PropertyClassID
,RTRIM(ItemName) as ItemName
,RTRIM(Nomenclature) as Nomenclature
,RTRIM(SerialNumber) as SerialNumber
,RTRIM(Model) as Model
,RTRIM(PartNumber) as PartNumber
,RTRIM(StockNumber) as StockNumber
,RTRIM(UnitofMeasure) as UnitofMeasure
,RTRIM(Manufacturer) as Manufacturer
,RTRIM(LocationBldg) as LocationBldg
,RTRIM(LocationRoom) as LocationRoom
,RTRIM(LocationOther) as LocationOther
,Warranty
,SoftwareLicenseExpireDate
,RTRIM(PurchaseOrderNumber) as ItemName
,RTRIM(ItemCost) as ItemName
,PurchaseOrderDate
,ExpectedReceiveDate
,RecieveDate
,DisposalDate
,RTRIM(ShelfLifeCide) as ShelfLifeCide
,PurchaseOrderStatusID
,RTRIM(WSS_DocumentRepository) as WSS_DocumentRepository
FROM TblInventoryMaster"
UpdateCommand="UPDATE TblInventoryMaster
SET PropertyClassID = @PropertyClassID
,ItemName = @ItemName
,Nomenclature = @Nomenclature
,SerialNumber = @SerialNumber
,Model = @Model
,PartNumber = @PartNumber
,StockNumber = @StockNumber
,UnitofMeasure = @UnitofMeasure
,Manufacturer = @Manufacturer
,LocationBldg = @LocationBldg
,LocationRoom = @LocationRoom
,LocationOther = @LocationOther
,Warranty = @Warranty
,SoftwareLicenseExpireDate = @SoftwareLicenseExpireDate
,PurchaseOrderNumber = @PurchaseOrderNumber
,ItemCost = @ItemCost
,PurchaseOrderDate = @PurchaseOrderDate
,ExpectedReceiveDate = @ExpectedReceiveDate
,RecieveDate = @RecieveDate
,DisposalDate = @DisposalDate
,ShelfLifeCide = @ShelfLifeCide
,PurchaseOrderStatusID = @PurchaseOrderStatusID
,WSS_DocumentRepository = @WSS_DocumentRepository
WHERE (ItemID = @ItemID)"
OnInserted="SqlDataSource1_Inserted">
<DeleteParameters>
<asp:Parameter Name="ItemID" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="PropertyClassID" Type="Int32" />
<asp:Parameter Name="ItemName" Type="String" />
<asp:Parameter Name="Nomenclature" Type="String" />
<asp:Parameter Name="SerialNumber" Type="String" />
<asp:Parameter Name="Model" Type="String" />
<asp:Parameter Name="PartNumber" Type="String" />
<asp:Parameter Name="StockNumber" Type="String" />
<asp:Parameter Name="UnitofMeasure" Type="String" />
<asp:Parameter Name="Manufacturer" Type="String" />
<asp:Parameter Name="LocationBldg" Type="String" />
<asp:Parameter Name="LocationRoom" Type="String" />
<asp:Parameter Name="LocationOther" Type="String" />
<asp:Parameter Name="Warranty" Type="String" />
<asp:Parameter Name="SoftwareLicenseExpireDate" Type="String" />
<asp:Parameter Name="PurchaseOrderNumber" Type="String" />
<asp:Parameter Name="ItemCost" Type="String" />
<asp:Parameter Name="PurchaseOrderDate" Type="String" />
<asp:Parameter Name="ExpectedReceiveDate" Type="String" />
<asp:Parameter Name="RecieveDate" Type="String" />
<asp:Parameter Name="DisposalDate" Type="String" />
<asp:Parameter Name="ShelfLifeCide" Type="String" />
<asp:Parameter Name="PurchaseOrderStatusID" Type="Int32" />
<asp:Parameter Name="WSS_DocumentRepository" Type="String" />
<asp:Parameter Name="ItemID" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="PropertyClassID" Type="Int32" />
<asp:Parameter Name="ItemName" Type="String" />
<asp:Parameter Name="Nomenclature" Type="String" />
<asp:Parameter Name="SerialNumber" Type="String" />
<asp:Parameter Name="Model" Type="String" />
<asp:Parameter Name="PartNumber" Type="String" />
<asp:Parameter Name="StockNumber" Type="String" />
<asp:Parameter Name="UnitofMeasure" Type="String" />
<asp:Parameter Name="Manufacturer" Type="String" />
<asp:Parameter Name="LocationBldg" Type="String" />
<asp:Parameter Name="LocationRoom" Type="String" />
<asp:Parameter Name="LocationOther" Type="String" />
<asp:Parameter Name="Warranty" Type="String" />
<asp:Parameter Name="SoftwareLicenseExpireDate" Type="String" />
<asp:Parameter Name="PurchaseOrderNumber" Type="String" />
<asp:Parameter Name="ItemCost" Type="String" />
<asp:Parameter Name="PurchaseOrderDate" Type="String" />
<asp:Parameter Name="ExpectedReceiveDate" Type="String" />
<asp:Parameter Name="RecieveDate" Type="String" />
<asp:Parameter Name="DisposalDate" Type="String" />
<asp:Parameter Name="ShelfLifeCide" Type="String" />
<asp:Parameter Name="PurchaseOrderStatusID" Type="Int32" />
<asp:Parameter Name="WSS_DocumentRepository" Type="String" />
<asp:Parameter Direction="Output" Name="newId" Type="Int32" />
</InsertParameters>
</asp:SqlDataSource>
<ext:Store ID="Store1" runat="server"
DataSourceID="SqlDataSource1"
OnAfterAjaxEvent="Store1_AfterAjaxEvent"
OnBeforeAjaxEvent="Store1_BeforeAjaxEvent"
UseIdConfirmation="true"
OnAfterRecordInserted="Store1_AfterRecordInserted"
OnRefreshData="Store1_RefershData">
<Reader>
<ext:JsonReader ReaderID="ItemID">
<Fields>
<ext:RecordField Name="PropertyClassID" />
<ext:RecordField Name="ItemName" />
<ext:RecordField Name="Nomenclature" />
<ext:RecordField Name="SerialNumber" />
<ext:RecordField Name="Model" />
<ext:RecordField Name="PartNumber" />
<ext:RecordField Name="StockNumber" />
<ext:RecordField Name="UnitofMeasure" />
<ext:RecordField Name="Manufacturer" />
<ext:RecordField Name="LocationBldg" />
<ext:RecordField Name="LocationRoom" />
<ext:RecordField Name="LocationOther" />
<ext:RecordField Name="Warranty" />
<ext:RecordField Name="SoftwareLicenseExpireDate" Type="Date" />
<ext:RecordField Name="PurchaseOrderNumber" />
<ext:RecordField Name="ItemCost" />
<ext:RecordField Name="PurchaseOrderDate" Type="Date" />
<ext:RecordField Name="ExpectedReceiveDate" Type="Date" />
<ext:RecordField Name="RecieveDate" Type="Date" />
<ext:RecordField Name="DisposalDate" Type="Date" />
<ext:RecordField Name="ShelfLifeCide" />
<ext:RecordField Name="PurchaseOrderStatusID" />
<ext:RecordField Name="WSS_DocumentRepository" />
</Fields>
</ext:JsonReader>
</Reader>
<SortInfo Field="ItemName" Direction="ASC" />
<Listeners>
<LoadException Handler="Ext.Msg.alert('Status - Load failed', e.message || e )" />
<CommitFailed Handler="Ext.Msg.alert('Status - Commit failed', 'Reason: ' + msg)" />
<SaveException Handler="Ext.Msg.alert('Status - Save failed', e.message || e)" />
<CommitDone Handler="Ext.Msg.alert('Status - Commit', 'The data successfully saved');" />
</Listeners>
</ext:Store>
<ext:Panel ID="Test" runat="server" ActiveTabIndex="0" Title="Administration | Inventory" Height="900">
<Body>
<ext:BorderLayout ID="BorderLayout_Description" runat="server">
<North MarginsSummary="5 5 5 5">
<ext:Panel ID="PanelDesc" runat="server" Title="Description" Height="100" BodyStyle="padding: 5px;"
Frame="true" Icon="Information">
<Body>
Inventory.
</Body>
</ext:Panel>
</North>
<Center MarginsSummary="0 5 0 5">
<ext:Panel ID="Panel1" runat="server" Height="800">
<Body>
<ext:BorderLayout ID="BorderLayout1" runat="server">
<West>
<ext:GridPanel
ID="GridPanel1"
runat="server"
StoreID="Store1"
StripeRows="true"
Title="Inventory List"
TrackMouseOver="true"
Width="500"
AutoExpandColumn="Nomenclature">
<ColumnModel ID="ColumnModel1" runat="server">
<Columns>
<ext:Column ColumnID="ItemName" Header="Item Name" Width="200" Sortable="true" DataIndex="ItemName" />
<ext:Column ColumnID="Nomenclature" Header="Nomenclature" Sortable="true" DataIndex="Nomenclature" /> </Columns>
</ColumnModel>
<SelectionModel>
<ext:RowSelectionModel ID="RowSelectionModel1" runat="server" SingleSelect="true">
<Listeners>
<RowSelect Handler="#{ButtonUpdate}.disable();#{btnInsert}.enable();#{FormPanel1}.getForm().loadRecord(record);" />
<RowDeselect Handler="if (!#{GridPanel1}.hasSelection()) {#{btnInsert}.disable();}" />
</Listeners>
</ext:RowSelectionModel>
</SelectionModel>
</ext:GridPanel>
</West>
<Center>
<ext:FormPanel ID="FormPanel1" runat="server" Title="Inventory Detail" StoreID="Store1" BodyStyle="padding:5px;" ButtonAlign="Right">
<Body>
<ext:FormLayout ID="FormLayout1" runat="server">
<%--<ext:Anchor Horizontal="95%">
<ext:TextField ID="PropertyClassID" DataIndex="PropertyClassID" runat="server" FieldLabel="Property Class ID" />
</ext:Anchor>--%>
<ext:Anchor Horizontal="95%">
<ext:ComboBox
ID="PropertyClassID"
FieldLabel="Property Class"
DataIndex="PropertyClassID"
runat="server"
StoreID="Store2"
Width="250"
Editable="false"
DisplayField="PropertyClassTitle"
ValueField="PropertyClassID"
TypeAhead="true"
Mode="Local"
ForceSelection="true"
TriggerAction="All"
EmptyText="Select a Property Class..."
Selectonfocus="true">
</ext:ComboBox>
</ext:Anchor>
<ext:Anchor Horizontal="95%">
<ext:TextField ID="ItemName" DataIndex="ItemName" runat="server" FieldLabel="Item Name" MaxLength="40" />
</ext:Anchor>
<ext:Anchor Horizontal="95%">
<ext:TextField ID="Nomenclature" DataIndex="Nomenclature" runat="server" FieldLabel="Nomenclature" MaxLength="40" />
</ext:Anchor>
<ext:Anchor Horizontal="95%">
<ext:TextField ID="SerialNumber" DataIndex="SerialNumber" runat="server" FieldLabel="Serial Number" MaxLength="40" />
</ext:Anchor>
<ext:Anchor Horizontal="95%">
<ext:TextField ID="Model" DataIndex="Model" runat="server" FieldLabel="Model" MaxLength="40" />
</ext:Anchor>
<ext:Anchor Horizontal="95%">
<ext:TextField ID="PartNumber" DataIndex="PartNumber" runat="server" FieldLabel="Part Number" MaxLength="40" />
</ext:Anchor>
<ext:Anchor Horizontal="95%">
<ext:TextField ID="StockNumber" DataIndex="StockNumber" runat="server" FieldLabel="Stock Number" MaxLength="40" />
</ext:Anchor>
<ext:Anchor Horizontal="95%">
<ext:TextField ID="UnitofMeasure" DataIndex="UnitofMeasure" runat="server" FieldLabel="Unit of Measure " MaxLength="40" />
</ext:Anchor>
<ext:Anchor Horizontal="95%">
<ext:TextField ID="Manufacturer" DataIndex="Manufacturer" runat="server" FieldLabel="Manufacturer" MaxLength="40" />
</ext:Anchor>
<ext:Anchor Horizontal="95%">
<ext:TextField ID="LocationBldg" DataIndex="LocationBldg" runat="server" FieldLabel="Location Bldg" MaxLength="40" />
</ext:Anchor>
<ext:Anchor Horizontal="95%">
<ext:TextField ID="LocationRoom" DataIndex="LocationRoom" runat="server" FieldLabel="Location Room" MaxLength="40" />
</ext:Anchor>
<ext:Anchor Horizontal="95%">
<ext:TextField ID="LocationOther" DataIndex="LocationOther" runat="server" FieldLabel="Location Other" MaxLength="40" />
</ext:Anchor>
<ext:Anchor Horizontal="95%">
<ext:DateField ID="Warranty" DataIndex="Warranty" runat="server" FieldLabel="Warranty" />
</ext:Anchor>
<ext:Anchor Horizontal="95%">
<ext:DateField ID="SoftwareLicenseExpireDate" DataIndex="SoftwareLicenseExpireDate" runat="server" FieldLabel="Software License Expire Date" />
</ext:Anchor>
<ext:Anchor Horizontal="95%">
<ext:TextField ID="PurchaseOrderNumber" DataIndex="PurchaseOrderNumber" runat="server" FieldLabel="Purchase Order Number" MaxLength="40" />
</ext:Anchor>
<ext:Anchor Horizontal="95%">
<ext:TextField ID="ItemCost" DataIndex="ItemCost" runat="server" FieldLabel="Item Cost" MaxLength="10" />
</ext:Anchor>
<ext:Anchor Horizontal="95%">
<ext:DateField ID="PurchaseOrderDate" DataIndex="PurchaseOrderDate" runat="server" FieldLabel="Purchase Order Date" />
</ext:Anchor>
<ext:Anchor Horizontal="95%">
<ext:DateField ID="ExpectedReceiveDate" DataIndex="ExpectedReceiveDate" runat="server" FieldLabel="Expected Receive Date" />
</ext:Anchor>
<ext:Anchor Horizontal="95%">
<ext:DateField ID="RecieveDate" DataIndex="RecieveDate" runat="server" FieldLabel="Recieve Date" />
</ext:Anchor>
<ext:Anchor Horizontal="95%">
<ext:DateField ID="DisposalDate" DataIndex="DisposalDate" runat="server" FieldLabel="Disposal Date" />
</ext:Anchor>
<ext:Anchor Horizontal="95%">
<ext:TextField ID="ShelfLifeCide" DataIndex="ShelfLifeCide" runat="server" FieldLabel="Shelf Life Cide" MaxLength="20" />
</ext:Anchor>
<ext:Anchor Horizontal="95%">
<ext:TextField ID="PurchaseOrderStatusID" DataIndex="PurchaseOrderStatusID" runat="server" FieldLabel="Purchase Order Status" />
</ext:Anchor>
<ext:Anchor Horizontal="95%">
<ext:TextField ID="WSS_DocumentRepository" DataIndex="WSS_DocumentRepository" runat="server" FieldLabel="SharePoint Folder" MaxLength="100" />
</ext:Anchor>
</ext:FormLayout>
</Body>
<Buttons>
<ext:Button ID="ButtonUpdate" runat="server" Text="Add New" Icon="Disk" Disabled="false">
<Listeners>
<Click Handler="#{GridPanel1}.insertRecord(0, {});#{FormPanel1}.getForm().updateRecord(#{Store1}.getAt(0, {}));#{Store1}.save()" />
</Listeners>
</ext:Button>
<ext:Button ID="ButtonReset" runat="server" Text="Reset Fields">
<Listeners>
<Click Handler="#{FormPanel1}.getForm().reset();#{btnInsert}.disable();#{ButtonUpdate}.enable();" />
</Listeners>
</ext:Button>
<ext:Button ID="btnInsert" runat="server" Text="Save" Icon="Add" Disabled="true">
<Listeners>
<Click Handler="#{FormPanel1}.getForm().updateRecord(#{GridPanel1}.getSelectionModel().getSelected());#{GridPanel1}.save();if (!#{GridPanel1}.hasSelection()) {#{btnInsert}.disable();}" />
</Listeners>
</ext:Button>
</Buttons>
</ext:FormPanel>
</Center>
</ext:BorderLayout>
</Body>
</ext:Panel>
</Center>
</ext:BorderLayout>
</Body>
</ext:Panel>
</form>
</body>
</html>
I did not change much.
Added
Buttons are disabled based on function of what the page is doing (edit or new).
Combo box added
minor-minor validation
i don't want to use a grid panel!!!
I just want to use a formpanel, tie it to a SQLDataSource, and update that SqlDataSource....i DON'T want to use a GridPanel, and i guess i could do without a store as well....any luck doing this?