PDA

View Full Version : [CLOSED] Store refresh issue



bossun
Aug 31, 2012, 9:50 AM
Hi

I have two pages which are used to insert values trough a gridpanel. One works perfectely the second one shows the following error :

4708

It's shown on inserting and on deleting.

Here is my code :


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ConvocationPeriods.aspx.cs" Inherits="Web_ConvocationPeriods" %>

<!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">
<ext:XScript ID="XScript1" runat="server">
<script type="text/javascript">
var addNewConvocationPeriod = function () {
var grid = #{ConvocationPeriondGridPanel};
var store = grid.getStore();
grid.editingPlugin.cancelEdit();


store.insert(0, {
SEASONID: #{ddlSeasons}.getValue(),
STARTDATE: new Date(),
ENDDATE: new Date(),
CALENDARDEADLINE: new Date(),
CONVOCATIONDEADLINE: new Date()
});

grid.editingPlugin.startEdit(0, 0);

}

</script>
</ext:XScript>
</head>
<body>
<form id="form1" runat="server">
<div>
<ext:ResourceManager ID="ResourceManager1" runat="server" />


<asp:ObjectDataSource ID="ConvPeriodDataSource" runat="server" SelectMethod="ConvocationPeriodSelectBySeason"
TypeName="Sigmasport.Code.BusinessLayer.SigmaSportConvocatio nPeriod"
onselecting="ConvPeriodDataSource_Selecting"
>
<SelectParameters>
<asp:Parameter Name="SEASONID" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>

<asp:ObjectDataSource ID="SeasonsDataSource" runat="server"
SelectMethod="SeasonSelect"
TypeName="Sigmasport.Code.BusinessLayer.SigmaSportSeason"
>
</asp:ObjectDataSource>

<ext:Store runat="server" ID="SeasonsStoreID"
DataSourceID="SeasonsDataSource"
>
<Model>
<ext:Model runat="server" IDProperty="ID">
<Fields>
<ext:ModelField Name="ID" Type="Int" />
<ext:ModelField Name="COMMENT" Type="String" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
<ext:Store
ID="ConvocationPeriodStoreID"
runat="server"
DataSourceID="ConvPeriodDataSource"
onbeforestorechanged="ConvocationPeriodStoreID_BeforeStoreChanged"
onreaddata="ConvocationPeriodStoreID_ReadData"
>
<Model>
<ext:Model runat="server" IDProperty="ID">
<Fields>
<ext:ModelField Name="ID" Type="Int" />
<ext:ModelField Name="SEASONID" Type="Int" />
<ext:ModelField Name="STARTDATE" Type="Date" />
<ext:ModelField Name="ENDDATE" Type="Date" />
<ext:ModelField Name="CALENDARDEADLINE" Type="Date" />
<ext:ModelField Name="CONVOCATIONDEADLINE" Type="Date" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
<ext:Viewport ID="Viewport1" runat="server" Layout="border" Padding="5">
<Items>
<ext:GridPanel ID="ConvocationPeriondGridPanel"
runat="server"
StoreID="ConvocationPeriodStoreID"
Frame="true"
Padding="5"
Title="<%$ Resources:Resource,ConvocationPeriod %>"
Icon="ApplicationViewColumns"
Region="Center"
>
<ColumnModel ID="ColumnModel1" runat="server">
<Columns>
<ext:Column runat="server" Text="<%$ Resources:Resource,ID %>" DataIndex="ID" Hidden="true" />
<ext:DateColumn runat="server" Text="<%$ Resources:Resource,StartDate %>" DataIndex="STARTDATE" Format="dd MMM yyyy" Flex="1">
<Editor>
<ext:DateField ID="DFstartdate" runat="server" DataIndex="STARTDATE" EndDateField="DFenddate" Vtype="daterange" AllowBlank="false" Format="dd MMM yyyy"></ext:DateField>
</Editor>
</ext:DateColumn>
<ext:DateColumn runat="server" Text="<%$ Resources:Resource,EndDate %>" DataIndex="ENDDATE" Format="dd MMM yyyy" Flex="1">
<Editor>
<ext:DateField ID="DFenddate" runat="server" DataIndex="ENDDATE" StartDateField="DFstartdate" Vtype="daterange" AllowBlank="false" Format="dd MMM yyyy"></ext:DateField>
</Editor>
</ext:DateColumn>
<ext:DateColumn runat="server" Text="<%$ Resources:Resource,CalendarDeadLine %>" DataIndex="CALENDARDEADLINE" Format="dd MMM yyyy" Flex="1">
<Editor>
<ext:DateField runat="server" DataIndex="CALENDARDEADLINE" AllowBlank="false" Format="dd MMM yyyy"></ext:DateField>
</Editor>
</ext:DateColumn>
<ext:DateColumn runat="server" Text="<%$ Resources:Resource,ConvocationDeadLine %>" DataIndex="CONVOCATIONDEADLINE" Format="dd MMM yyyy" Flex="1">
<Editor>
<ext:DateField runat="server" DataIndex="CONVOCATIONDEADLINE" AllowBlank="false" Format="dd MMM yyyy"></ext:DateField>
</Editor>
</ext:DateColumn>
</Columns>
</ColumnModel>
<Plugins>
<ext:RowEditing ID="RowEditor1" runat="server" SaveBtnText="<%$ Resources:Resource,Save %>" CancelBtnText="<%$ Resources:Resource,Cancel %>" >
<Listeners>
<Edit Handler="#{ConvocationPeriodStoreID}.sync();" />
<CancelEdit Handler="#{ConvocationPeriodStoreID}.reload();" />
</Listeners>
</ext:RowEditing>
</Plugins>
<SelectionModel>
<ext:RowSelectionModel runat="server" ID="RowSelectModel1" SingleSelect="true"/>
</SelectionModel>
<TopBar>
<ext:Toolbar runat="server" Padding="5">
<Items>
<ext:ComboBox runat="server" ID="ddlSeasons"
StoreID="SeasonsStoreID" AutoWidth="true"
Width="230"
FieldLabel="<%$ Resources:Resource,Season %>"
DisplayField="COMMENT" ValueField="ID">
<SelectedItems>
<ext:ListItem Index="-1" />
</SelectedItems>
<Listeners>
<Select Handler="#{ConvocationPeriodStoreID}.reload()" />
</Listeners>
</ext:ComboBox>
<ext:ToolbarSeparator runat="server" />
<ext:Button ID="btnNew" runat="server" Icon="Add" Text="<%$ Resources:Resource,AddNew %>">
<Listeners>
<Click Fn="addNewConvocationPeriod" />
</Listeners>
</ext:Button>
<ext:ToolbarSeparator runat="server" />
<ext:Button ID="btnDelete" runat="server" Icon="Delete" Text="<%$ Resources:Resource,Delete %>">
<Listeners>
<Click Handler="#{ConvocationPeriondGridPanel}.deleteSelected();
#{ConvocationPeriodStoreID}.sync(); " />
</Listeners>
</ext:Button>
<ext:ToolbarSeparator runat="server" />
<ext:FileUploadField runat="server" ID="btnUpload" Icon="TableSave" ButtonOnly="true" ButtonText="<%$ Resources:Resource, ImportFromFile %>" Enabled="false"></ext:FileUploadField>
</Items>
</ext:Toolbar>
</TopBar>
</ext:GridPanel>
</Items>
</ext:Viewport>
</div>
</form>
</body>
</html>




using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Sigmasport.Code.Shared;
using Sigmasport.Code.BusinessLayer;
using Ext.Net;
using Resources;

public partial class Web_ConvocationPeriods : SigmaSportPage
{
protected void Page_Load(object sender, EventArgs e)
{
if (!X.IsAjaxRequest)
{

}
}

protected void ConvocationPeriodStoreID_BeforeStoreChanged(object sender, BeforeStoreChangedEventArgs e)
{
try
{
List<Dictionary<string, object>> record = e.DataHandler.ObjectData<Dictionary<string, object>>();

foreach (Dictionary<string, object> r in record)
{
if (e.Action == StoreAction.Create)
{
ExecuteMethod(r, typeof(SigmaSportConvocationPeriod), "ConvocationPeriodInsert");
ShowNotification(Resource.M_Notif_ItemCreated);
}
if (e.Action == StoreAction.Update)
{
ExecuteMethod(r, typeof(SigmaSportConvocationPeriod), "ConvocationPeriodUpdate");
ShowNotification(Resource.M_Notif_ItemUpdated);
}
if (e.Action == StoreAction.Destroy)
{
ExecuteMethod(r, typeof(SigmaSportConvocationPeriod), "ConvocationPeriodDelete");
ShowNotification(Resource.M_Notif_ItemDeleted);
}

e.ResponseRecords.Add(r);
}

}
catch (Exception ex)
{
ExceptionBox(ex.InnerException.Message);
}

ConvocationPeriodStoreID.Reload();
e.Cancel = true;

}


protected void ConvocationPeriodStoreID_ReadData(object sender, StoreReadDataEventArgs e)
{
ConvocationPeriodStoreID.DataBind();
}
protected void ConvPeriodDataSource_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
{
e.InputParameters["SEASONID"] = ddlSeasons.SelectedItem.Value;
}
}

The ConvocationPeriodStoreID_ReadData function is not called when inserting. When deleting, it's called but I still get the error box. All DB operations are correctly proceeded. It seems to be a refresh issue.

The second page has the same structure, same parameters are set and works perfectly.

Daniil
Aug 31, 2012, 12:01 PM
Hi,

Please clarify why do you need this?

ConvocationPeriodStoreID.Reload();

bossun
Aug 31, 2012, 12:13 PM
Hi,

Please clarify why do you need this?

ConvocationPeriodStoreID.Reload();


I would like to get the inserted record ID which is given by the Database.

bossun
Aug 31, 2012, 1:10 PM
Hi Daniil,

I found the issue,

I removed the FileUploadField and it works...

Thank you for your Help.

Daniil
Aug 31, 2012, 1:23 PM
I would like to get the inserted record ID which is given by the Database.

I don't think you should reload the Store.

All record values including ids must be returned from a BeforeStoreChanged handler. It is required.

Lets consider this example.
http://examples2.ext.net/#/GridPanel/Saving_Variations/StoreCustomLogic/

When a user inserts a record and click the Save button, the new record values are submitted to the server and executing the Store1_BeforeChange handler.

After this code:


db.Suppliers.InsertOnSubmit(supplier);
...
db.SubmitChanges();


All inserted records get new ids from a database.

And these ids and all rest values go to a response here:


foreach (Supplier supplier in data) {
e.ResponseRecords.Add(supplier);
}

So, no need to reload the Store.