PDA

View Full Version : [CLOSED] how to call direct method



tactime10
Oct 03, 2012, 9:29 AM
Hi,

I try to call the direct method for ItemMouseUp event on the chart, but it doesn't work in my page. How can do it?
My code is below:


<%@ Page Language = "C#"%>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

<script runat="server">
public class MonitorViewer
{
private double yieldValue;
private int pnFirstOk;
private int pnFirstKo;
private int pnTotalPass;
private string period;

public MonitorViewer() {}

public double YieldValue {
get { return yieldValue; }
set { yieldValue = value; }
}

public int PnFirstOk {
get { return pnFirstOk; }
set { pnFirstOk = value; }
}

public int PnFirstKo {
get { return pnFirstKo; }
set { pnFirstKo = value; }
}

public int PnTotalPass {
get { return pnTotalPass; }
set { pnTotalPass = value; }
}

public string Period {
get { return period; }
set { period = value; }
}
}

public object[] DataValue () {
IList<MonitorViewer> listItems = new List<MonitorViewer>();
MonitorViewer monitorViewer1 = new MonitorViewer();
monitorViewer1.YieldValue = Double.Parse("95,97");
monitorViewer1.Period= "30/03/12 - 20/04/12";
monitorViewer1.PnFirstOk = 7507;
monitorViewer1.PnFirstKo = 315;
monitorViewer1.PnTotalPass = 7994;

MonitorViewer monitorViewer2 = new MonitorViewer();
monitorViewer2.YieldValue = Double.Parse("96,68");
monitorViewer2.Period= "20/04/12 - 12/05/12";
monitorViewer2.PnFirstOk = 5995;
monitorViewer2.PnFirstKo = 206;
monitorViewer2.PnTotalPass = 6504;

MonitorViewer monitorViewer3 = new MonitorViewer();
monitorViewer3.YieldValue = Double.Parse("95,91");
monitorViewer3.Period= "12/05/12 - 03/06/12";
monitorViewer3.PnFirstOk = 9732;
monitorViewer3.PnFirstKo = 415;
monitorViewer3.PnTotalPass = 10209;

MonitorViewer monitorViewer4 = new MonitorViewer();
monitorViewer4.YieldValue = Double.Parse("96,09");
monitorViewer4.Period= "03/06/12 - 24/06/12";
monitorViewer4.PnFirstOk = 6710;
monitorViewer4.PnFirstKo = 273;
monitorViewer4.PnTotalPass = 7309;

MonitorViewer monitorViewer5 = new MonitorViewer();
monitorViewer5.YieldValue = Double.Parse("96,29");
monitorViewer5.Period= "24/06/12 - 16/07/12";
monitorViewer5.PnFirstOk = 1922;
monitorViewer5.PnFirstKo = 74;
monitorViewer5.PnTotalPass = 2021;

MonitorViewer monitorViewer6 = new MonitorViewer();
monitorViewer6.YieldValue = Double.Parse("0,0");
monitorViewer6.Period= "16/07/12 - 07/08/12";
monitorViewer6.PnFirstOk = 0;
monitorViewer6.PnFirstKo = 0;
monitorViewer6.PnTotalPass = 0;

MonitorViewer monitorViewer7 = new MonitorViewer();
monitorViewer7.YieldValue = Double.Parse("0,0");
monitorViewer7.Period= "07/08/12 - 28/08/12";
monitorViewer7.PnFirstOk = 0;
monitorViewer7.PnFirstKo = 0;
monitorViewer7.PnTotalPass = 0;

listItems.Add(monitorViewer1);
listItems.Add(monitorViewer2);
listItems.Add(monitorViewer3);
listItems.Add(monitorViewer4);
listItems.Add(monitorViewer5);
listItems.Add(monitorViewer6);
listItems.Add(monitorViewer7);

object[] periodArray = new object
[listItems.Count];
for (int i = 0;i < listItems.Count;i++) {
MonitorViewer monitorViewer = listItems[i];
object[] itemArray = new object[]{monitorViewer.YieldValue,monitorViewer.Period,mon itorViewer.PnFirstOk,monitorViewer.PnFirstKo,monit orViewer.PnTotalPass};

periodArray[i] = itemArray;
}
return periodArray;
}

public void Page_Load() {
//var store = this.yieldChart.GetStore();
//store.DataSource = DataValue();
//store.DataBind();
}

protected void ExtractData(object sender, DirectEventArgs e) {
this.panel1.Hidden = false;
var store = this.yieldChart.GetStore();
store.DataSource = DataValue();
store.DataBind();
}

[DirectMethod]
public void OnItemMouseUp(string item, int index) {
X.Msg.Alert("Message","index: " + index + " item: " + item).Show();
}
</script>
<script type="text/javascript">
var onMouseUp = function (item) {
var series = App.yieldChart.series.get(0),
index = Ext.Array.indexOf(series.items, item);

App.direct.OnItemMouseUp(item,index);
};
</script>

<body>
<form Method=post Runat="server">
<ext:ResourceManager Id="resourceManager" runat="server" />
<br/>
<h3>Example</h3>
<br/>
<ext:Panel id="panelFilter" runat="server" MarginSpec="0 5 5 0" Border="false"
AutoHeight="false" Header="false" Collapsible="false" CollapseMode="Mini" BodyPadding="5" >
<Items>
<ext:FieldSet Id="fieldSetFilterLeadtime" runat="server" Title="Filter" Collapsible="true" Layout="AnchorLayout"
ButtonAlign="Right" BodyPadding="5">
<Items>
<ext:Panel runat="server" Layout="HBoxLayout" Border="false" AutoHeight="true" Header="false">
<Defaults>
<ext:Parameter Name="margins" Value="5 0 0 0" Mode="Value" />
</Defaults>
<LayoutConfig>
<ext:HBoxLayoutConfig Align="Middle" />
</LayoutConfig>
<Items>
<ext:Button ID="btnSearch" Text="Search" runat="server" Hidden="false" Icon="Magnifier" >
<DirectEvents>
<Click OnEvent="ExtractData">
<EventMask ShowMask="true" MinDelay="100"/>
</Click>
</DirectEvents>
</ext:Button>
</Items>
</ext:Panel>
</Items>
</ext:FieldSet>
</Items>
</ext:Panel>
<br/>
<ext:ChartTheme
ID="CustomThemeID"
runat="server"
ThemeName="CustomTheme"
Colors="url(#blueColor),url(#greenColor),url(#redColor),ur l(#orangeColor)">
</ext:ChartTheme>

<ext:FormPanel ID="panel1" runat="server" Title="Items found" MarginSpec="0 5 5 5"
Frame="true" BodyPadding="5" Hidden="true" Icon="ApplicationFormMagnify" >
<LayoutConfig>
<ext:VBoxLayoutConfig Align="Stretch" />
</LayoutConfig>
<Bin>
<ext:Store ID="yieldStore" runat="server" >
<Reader>
<ext:ArrayReader />
</Reader>
<Model>
<ext:Model runat="server">
<Fields>
<ext:ModelField Name="yield"/>
<ext:ModelField Name="period"/>
<ext:ModelField Name="pnFirstOk"/>
<ext:ModelField Name="pnFirstKo"/>
<ext:ModelField Name="pnTotalPass"/>
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Bin>
<Items>
<ext:FormPanel runat="server" Border="false" Height="600" >
<LayoutConfig>
<ext:HBoxLayoutConfig Align="Stretch" />
</LayoutConfig>
<Items>
<ext:Panel runat="server" Border="true" Layout="FitLayout" Flex="1" Title="Monitor">
<Items>
<ext:Chart
ID="yieldChart"
runat="server"
Flex="1"
Theme="CustomTheme"
Shadow="true"
Animate="true"
StoreID="yieldStore">

<Gradients>
<ext:Gradient GradientID="redColor" Angle="0">
<Stops>
<ext:GradientStop Offset="0" Color="#e21413" />
<ext:GradientStop Offset="100" Color="#d82931" />
</Stops>
</ext:Gradient>

<ext:Gradient GradientID="orangeColor" Angle="0">
<Stops>
<ext:GradientStop Offset="0" Color="#ecbe38" />
<ext:GradientStop Offset="100" Color="#dc9614" />
</Stops>
</ext:Gradient>

<ext:Gradient GradientID="greenColor" Angle="0">
<Stops>
<ext:GradientStop Offset="0" Color="#3ed730" />
<ext:GradientStop Offset="100" Color="#3ea830" />
</Stops>
</ext:Gradient>

<ext:Gradient GradientID="blueColor" Angle="0">
<Stops>
<ext:GradientStop Offset="0" Color="#4868e7" />
<ext:GradientStop Offset="100" Color="#3c56bf" />
</Stops>
</ext:Gradient>
</Gradients>

<Axes>
<ext:NumericAxis Position="Left" Fields="yield" Minimum="0" />
<ext:NumericAxis Position="Right" Minimum="0" Fields="pnFirstOk,pnFirstKo,pnTotalPass" Hidden="true">
</ext:NumericAxis>
<ext:CategoryAxis Position="Bottom" Fields="period">
<Label Font="10px Arial">
<Rotate Degrees="270" />
<Renderer Handler="return Ext.String.ellipsis(value, 15, false);" />
</Label>
</ext:CategoryAxis>
</Axes>

<Series>
<ext:ColumnSeries Axis="Left" Highlight="true" XField="period" YField="yield">
<Style Fill="#38B8BF" StrokeWidth="3" />
<Label Contrast="true" Display="Under" Field="yield" Color="#000" TextAnchor="middle" />
<Listeners>
<ItemMouseUp Fn="onMouseUp" />
</Listeners>
</ext:ColumnSeries>
<ext:LineSeries Highlight="true" Axis="Right" Smooth="3" XField="period" YField="pnFirstOk" >
<MarkerConfig Type="Circle" Size="4" Radius="4" StrokeWidth="0" />

<Label Contrast="false" Display="InsideEnd" Field="pnFirstOk" Color="#319915" TextAnchor="Middle" />
</ext:LineSeries>
<ext:LineSeries Highlight="true" Axis="Right" Smooth="3" XField="period" YField="pnFirstKo" >
<MarkerConfig Type="Circle" Size="4" Radius="4" StrokeWidth="0" />

<Label Contrast="false" Display="InsideEnd" Field="pnFirstKo" Color="#CC1700" TextAnchor="Middle" />
</ext:LineSeries>
<ext:LineSeries Highlight="true" Axis="Right" Smooth="3" XField="period" YField="pnTotalPass" >
<MarkerConfig Type="Circle" Size="4" Radius="4" StrokeWidth="0" />

<Label Contrast="false" Display="InsideEnd" Field="pnTotalPass" Color="#C97C00" TextAnchor="Middle" />
</ext:LineSeries>
</Series>
</ext:Chart>
</Items>
</ext:Panel>
</Items>
</ext:FormPanel>
</Items>
</ext:FormPanel>
</form>
</Body>
</Html>


Can you help me?
Thank you so much.

Daniil
Oct 03, 2012, 12:59 PM
Hi @tactime10,

The problem is here:

App.direct.OnItemMouseUp(item,index);

The "item" is a too complex object to be passed as a DirectMethod parameters. It cannot be serialized, because there are recursion links in this object.

Please retrieve a required info only from the "item" to pass on server.

tactime10
Oct 04, 2012, 8:38 AM
Hi,

Ok thanks

I change parameters with a simple object.