Xquery select values where value exists in node - xquery

I have the following XML:
<ELEMENTS>
<TOL_Article>
<fields>
<ArtDesc />
<ArtNr>481214</ArtNr>
<Qty>4.0000000000</Qty>
<Sort />
<Type>Circulatie_en_warmtestab</Type>
<Unit>st</Unit>
</fields>
</TOL_Article>
<TOL_Article>
<fields>
<ArtDesc>Kokerdelen TT- 4</ArtDesc>
<ArtNr>4100040</ArtNr>
<Qty>18.0000000000</Qty>
<Sort />
<Type>Kanalen</Type>
<Unit>st</Unit>
</fields>
</TOL_Article>
<TOL_Article>
<fields>
<ArtDesc>Kokerdelen TT- 5</ArtDesc>
<ArtNr>4100050</ArtNr>
<Qty>18.0000000000</Qty>
<Sort />
<Type>Kanalen</Type>
<Unit>st</Unit>
</fields>
</TOL_Article>
<TOL_Article>
<fields>
<ArtDesc>] RV.Opn.0-100% 4-20mA buiten</ArtDesc>
<ArtNr>3518000410</ArtNr>
<BaseQuantity>1.0000000000</BaseQuantity>
<Qty>1.0000000000</Qty>
<Sort>451050</Sort>
<Type>Sensoren</Type>
<Unit>st</Unit>
</fields>
</TOL_Article>
<TOL_Article>
<fields>
<ArtDesc>] Inst. Weerhuisje</ArtDesc>
<ArtNr>3518010010</ArtNr>
<BaseQuantity>1.0000000000</BaseQuantity>
<Qty>1.0000000000</Qty>
<Sort>451050</Sort>
<Type>Sensoren</Type>
<Unit>st</Unit>
</fields>
</TOL_Article>
<TOL_Article>
<fields>
<ArtDesc>] Inst. 5x1,0 in goot</ArtDesc>
<ArtNr>3518261250</ArtNr>
<BaseQuantity>1.0000000000</BaseQuantity>
<Qty>10.0000000000</Qty>
<Sort>451050</Sort>
<Type>Sensoren</Type>
<Unit>m</Unit>
</fields>
</TOL_Article>
</ELEMENTS>
Now I want to select all the ArtNr values where the node Type has the value "Sensoren".
I tried the following
select *
from XMLTABLE as z
where xml.exist('/LIST/ELEMENTS/TOL_Article/fields/Type[#value="Sensoren]')=1
But here I get the following error:
Msg 2274, Level 16, State 1, Line 21
XQuery [z.infohdrXML_A.exist()]: Unterminated string constant (started on line 1)
Does anyone have an idea how I can get these values from the xml?
Thank you in advance
Arjan

Related

Chancing ASPxGridView data

I would like to change my gridview data. My data type are integer, but I want to divide this data with 100 For example;
They must be;
200,00
100,00
50,00
I tried do this with OnCustomColumnDisplayText event but when I added this event it was working more than one. When open the page, many times was worked again and again. So many times I divided with 100. Can you help me, please? My codes below;
<dx:ASPxGridView ID="MainDataList" ClientInstanceName="mainDataDl" runat="server" CssClass="mainDataList"
AutoGenerateColumns="False" EnableRowsCache="false" OnDataBinding="MainDataList_DataBinding" Width="100%"
OnRowUpdating="MainDataList_RowUpdating" OnCustomColumnDisplayText="MainDataList_CustomColumnDisplayText" >
<ClientSideEvents Init="grid_Init" />
<SettingsAdaptivity AdaptivityMode="HideDataCells" HideDataCellsAtWindowInnerWidth="600"
AllowOnlyOneAdaptiveDetailExpanded="true" AllowHideDataCellsByColumnMinWidth="true" />
<EditFormLayoutProperties>
<SettingsAdaptivity AdaptivityMode="SingleColumnWindowLimit" SwitchToSingleColumnAtWindowInnerWidth="680" />
</EditFormLayoutProperties>
<SettingsEditing Mode="EditFormAndDisplayRow" EditFormColumnCount="2"/>
<Styles>
<Header ForeColor="White" BackColor="#969696" Font-Size="12px" />
<Cell Font-Size="12px" Wrap="False" />
<EditForm CssClass="editForm" />
</Styles>
<Settings ShowFilterRow="True" AutoFilterCondition="Contains" />
<Columns>
<dx:GridViewCommandColumn ShowClearFilterButton="True" VisibleIndex="0" Name="TempColumn" >
</dx:GridViewCommandColumn>
</Columns>
<SettingsPager PageSize="10" NumericButtonCount="4" Mode="ShowPager" />
<TotalSummary />
<SettingsDataSecurity AllowDelete="False" AllowEdit="True" AllowInsert="False" />
<SettingsSearchPanel Visible="false" CustomEditorID="MainDataListSearchTextBox" />
<SettingsLoadingPanel Mode="Disabled" />
<SettingsBehavior AllowFocusedRow="True" ProcessFocusedRowChangedOnServer="true" />
<SettingsCommandButton>
<ShowAdaptiveDetailButton ButtonType="Image">
</ShowAdaptiveDetailButton>
<HideAdaptiveDetailButton ButtonType="Image">
</HideAdaptiveDetailButton>
</SettingsCommandButton>
</dx:ASPxGridView>
protected void MainDataList_CustomColumnDisplayText(object sender, ASPxGridViewColumnDisplayTextEventArgs e)
{
foreach (MimasPortal.TableFieldData_1_0 tf in userSession.DetailStruct.Fields)
{
if (tf.FieldType == "MONEY")
{
DataRowView rowData = (DataRowView)MainDataList.GetRow(e.VisibleIndex);
if (rowData != null)
{
if (rowData.Row[tf.FieldName].ToString().Length > 2 && rowData.Row[tf.FieldName].ToString().IndexOf('.') < 1 && rowData.Row[tf.FieldName].ToString().IndexOf(',') < 1)
{
decimal newValue = (Convert.ToDecimal(e.GetFieldValue(tf.FieldName))) / 100;
rowData.Row[tf.FieldName] = newValue;
}
else
{
rowData.Row[tf.FieldName] = e.GetFieldValue(tf.FieldName).ToString();
}
}
}
}
}

RadGrid make field invisible on Edit

<telerik:RadGrid runat="server" ID="rdReport" AutoGenerateColumns="false" AllowPaging="true" Skin="Metro" OnItemCommand="ItemCommand" OnItemDataBound="rdReport_ItemDataBound" OnPreRender="rdReport_PreRender" DataSourceID="FountainSource" AllowAutomaticUpdates="true" AllowAutomaticDeletes="true">
<MasterTableView DataKeyNames="ID" CommandItemDisplay="None">
<Columns>
<telerik:GridEditCommandColumn ButtonType="ImageButton" />
<telerik:GridBoundColumn DataField="LocName" HeaderText="Location" ReadOnly="true" />
<
<telerik:GridBoundColumn DataField="Field1Value" HeaderText="Custom Field1" />
<telerik:GridBoundColumn DataField="Field2Value" HeaderText="Custom Field2" />
<telerik:GridBoundColumn DataField="Field3Value" HeaderText="Custom Field3" />
<telerik:GridButtonColumn ConfirmText="Delete?" ConfirmDialogType="RadWindow"
ConfirmTitle="Delete" ButtonType="ImageButton" CommandName="Delete" />
</Columns>
<EditFormSettings>
<EditColumn ButtonType="ImageButton" />
</EditFormSettings>
</MasterTableView>
<PagerStyle Mode="NextPrevAndNumeric" />
</telerik:RadGrid>
On Edit, I like to make a field invisible.
I am using the following code which works but want to check to see if it is best practice:
protected void rdReport_ItemDataBound(object sender, GridItemEventArgs e)
{
// Edit Mode
if ((e.Item is GridEditFormItem) && (e.Item.IsInEditMode))
{
GridEditFormItem fndColumn = (GridEditFormItem)e.Item;
fnColumn["Field1Value"].Parent.Visible = false;
}
}
The solution which was provided by you is perfect but it would be nice if you will also add UniqueName property in each column. If we will not assign the UniqueName than it is consider DataField value as UniqueName.
ASPX
<telerik:GridButtonColumn DataField="Field1Value" HeaderText="Custom Field1" UniqueName="Field1Value" />
ASPX.CS
protected void rdReport_ItemDataBound(object sender, GridItemEventArgs e)
{
// Edit Mode
if ((e.Item is GridEditFormItem) && (e.Item.IsInEditMode))
{
GridEditFormItem fndColumn = (GridEditFormItem)e.Item;
fnColumn["Field1Value"].Parent.Visible = false; // "Field1Value" is column uniquename
}
}
Let me know if you required more information.
This is just a suggested alternative. I've worked with telerik a few times, and it is a pain to say the least. What you could do is also add a tertiary condition to the parent container. If in edit mode, then show a class, such as 'edit', or 'current'. If not in edit mode, don't show the class. Then, in your CSS you can select for whatever element you want to hide.
<div>
<input type="text" id="whateverisgenerated" class="uniqueclass" />
</div>
Then, when in edit mode, you will have
<div class="edit">
<input type="text" id="whateverisgenerated" class="uniqueclass" />
</div>
With your CSS:
div.edit input.uniqueclass { display: none; }
As for your telerik control (I just grabbed something from your code), you can do the following to add your class:
<telerik:GridButtonColumn ConfirmText="Delete?" ConfirmDialogType="RadWindow" ConfirmTitle="Delete" ButtonType="ImageButton" CommandName="Delete" CssClass="uniqueclass" />
I added CssClass="uniqueclass" in the control above.
What I provided is just an example. I hope you find a use for it. Thanks

How to get the value of selected valueField in Combobox?

I'm trying to assign a value ext:Hidden. I want to set the selected value of the field "HiddenSmo". How to get the value of selected valueField in Combobox?
<DirectEvents>
<Select OnEvent="ValueSelected" After="var ind = #{ComboBoxSmo}.getValue();
#{HiddenSmo}.setValue(#{ComboBoxSmo}.store.getAt(ind).get('code'));" />
</DirectEvents>
but after selection HiddenSmo="". Please help me. thanks in advance. Full code:
<ext:ComboBox
ID="ComboBoxSmo"
runat="server"
DisplayField="name"
ValueField="IdSmo"
TypeAhead="false"
TriggerAction="Query"
QueryMode="Remote"
ForceSelection="true"
SelectOnFocus="true"
Disabled="false"
Name="IDSmo">
<Store>
<ext:Store
runat="server">
<Proxy>
<ext:AjaxProxy
Url="~/Controls/DataService.asmx/GetSMOsD" >
<ActionMethods
Read="POST" />
<Reader>
<ext:XmlReader
Root="ArrayOfSMOResponse"
Record="SMOResponse"
/>
</Reader>
</ext:AjaxProxy>
</Proxy>
<Model>
<ext:Model
runat="server"
IDProperty="IdSmo">
<Fields>
<ext:ModelField Name="code" Type="Int" />
<ext:ModelField Name="IdSmo" Type="Int" />
<ext:ModelField Name="name" Type="String" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
<DirectEvents>
<Select OnEvent="ValueSelected" After="var ind = #{ComboBoxSmo}.getValue();
#{HiddenSmo}.setValue(#{ComboBoxSmo}.store.getAt(ind).get('code'));" />
</DirectEvents>
Although I don't know the "wrapper language" you use, combo, as any other form fields, has setter and getter of its value:
var val = combo.getValue(); // to get the current combo value
combo.setValue(val); // to set value of the combo to val
try to use this one
App.ComboBoxSmo.getValue()
instead of this #{ComboBoxSmo}.getValue()
I don't understand why you would use a HiddenField to store the value of the combobox selection when the combobox selection already stores it's own value. My guess is that you are trying to workaround what you see as strange behavior within the combobox. So here are some quick pointers I've learned while fighting with combobox's.
If you use a store, you need to shape the object in "setValue([object])" just like the way the store model is shaped.
Use "SelectedItems.Add(...)" and "UpdateSelectedItems()". When just using Ext.Net.ListItems and adding to the Items collection on comboboxes this may not be necessary but when you use a store this seems to be required to get the combobox to play nice with the store on directevents.
<Model>
<ext:Model
runat="server"
IDProperty="IdSmo">
<Fields>
<ext:ModelField Name="code" Type="Int" />
<ext:ModelField Name="IdSmo" Type="Int" />
<ext:ModelField Name="name" Type="String" />
</Fields>
</ext:Model>
</Model>
Server Side:
protected void updateComboBoxSelection(object sender, DirectEventArgs e)
{
if (X.IsAjaxRequest)
{
this.ComboBoxSmo.SelectedItems.Add(new { IdSmo=101, name="foobar", code=15 });
this.ComboBoxDateTime.UpdateSelectedItems();
}
}

Ext.net 2.0 ComboBox Store

I have a ComboBox Control:
<ext:ComboBox id="comboDatabase"></ext:ComboBox>
In my code I populate the ComboBox Store by:
comboDatabase.Store.Primary.DataSource = dbList
comboDatabase.Store.Primary.DataBind()
However, in my javascript, when I do comboDatabase.getStore().data.items, it returns nothing.
Any idea why? Thanks in advance.
Just define the store:
<ext:ComboBox ID="PACKING" runat="server" FieldLabel="PACKING"
ValueField="id" DisplayField="pk" QueryMode="Local">
<Store>
<ext:Store ID="PackingStore" runat="server" Data='<%# packings %>'>
<Model>
<ext:Model runat="server">
<Fields>
<ext:ModelField Name="id" />
<ext:ModelField Name="pk" />
</Fields>
</ext:Model>
</Model>
<Reader>
<ext:ArrayReader IDProperty="id" />
</Reader>
</ext:Store>
</Store>
</ext:ComboBox>
c#:
protected object packings
{
get { return ctx.Packings.Select(p => new object[] { p.id, p.PackingName }).ToArray<object>();
}
Is Easy, the same code of ext.net 1.x
EXT.NET CODE
<ext:Store ID="Store1" runat="server" >
<Model>
<ext:Model runat="server" IDProperty="code">
<Fields>
<ext:ModelField Name="code_item" />
<ext:ModelField Name="description_item" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
...
<ext:combobox id="combo" runat="server" storeid="Store1" displayfield="description_item" valuefield="code_item" />
C# CODE
private void LoadStore(Store store, string query)
{
OdbcConnection Odbc = new OdbcConnection();
try
{
Odbc.ConnectionString = mntClass.HelperDB.strConn(); //mntClass is my particular dll
Odbc.Open();
DataSet objDataset1 = new DataSet();
objDataset1 = mntClass.HelperDB.ExecuteSelectQuery(Odbc, query);
store.DataSource = objDataset1;
store.DataBind();
}
catch (OdbcException)
{
}
finally
{
Odbc.Close();
}
}

Nullable Datetime field not getting rendered in Store (Ext.Net)

<ext:Store ID="StoreSample" runat="server" RemotePaging="true" RemoteSort="true" AutoLoad="true"
ShowWarningOnFailure="false" >
<Proxy>
<ext:HttpProxy Url="~/Samples/OpenEdit/GetSampleList" Json="true">
</ext:HttpProxy>
</Proxy>
<Reader>
<ext:JsonReader IDProperty="Id" Root="data">
<Fields>
<ext:RecordField Name="Id" Type="Int">
</ext:RecordField>
<ext:RecordField Name="SampleDescription" Mapping="Description">
</ext:RecordField>
<ext:RecordField Name="SampleStartDate" Mapping="StartDate" Type="Date">
</ext:RecordField>
<ext:RecordField Name="SampleEndDate" Mapping="EndDate" Type="Date" >
</ext:RecordField>
</Fields>
</ext:JsonReader>
</ext:Store>
In this store the fields SampleStartDate and SampleEndDate are of type Nullabe Datetime (Datetime?) in the model. In controller i am getting value for every field and i am converting this to StoreResult in the function GetSampleList. But in store i am always getting the value as 'undefined' in these two fields. But if i change the datatype from Datetime? to DateTime the in model i am getting all the values in store.
Can any one help me to get the nullable datetime value in store?
i am using this store in GridPanel
<Sample:GridPanel ID="GridPanelSample" runat="server" StoreID="StoreSample" Header="false"
AnchorHorizontal="right" AnchorVertical="96%" StandardPager="true" MonitorResize="true" TabIndex="15">
<TopBar>
</TopBar>
<ColumnModel>
<Columns>
<ext:Column runat="server" ColumnID="SampleDescription" Header="Description"
DataIndex="SampleDescription">
</ext:Column>
<ext:DateColumn runat="server" ColumnID="SampleStartDate" Header="StartDate"
DataIndex="SampleStartDate" Format="d MMM Y">
</ext:DateColumn>
<ext:DateColumn runat="server" ColumnID="SampleEndDate" Header="EndDate"
DataIndex="SampleEndDate" Format="d MMM Y">
</ext:DateColumn>
</Columns>
</ColumnModel>
<SelectionModel>
<ext:RowSelectionModel ID="RowSelectionModel1" runat="server" SingleSelect="true"
MoveEditorOnEnter="true">
</ext:RowSelectionModel>
</SelectionModel>
<View>
<ext:LockingGridView runat="server" ID="gridview1" />
</View>
<Listeners>
<ViewReady Handler="openEdit.setOpenEditGridColumnWidths();"></ViewReady>
</Listeners>
</Sample:GridPanel>
But SampleStartDate and SampleEndDate column is always empty
I think you need to configure the .DateFormat property of the <ext:RecordField>.
Example
<ext:RecordField Name="lastChange" Type="Date" DateFormat="M$" />
Setting .DateFormat="M$" will automatically parse the "/Date(123...)/" value into a JavaScript Date object.
Hope this helps.
Finally i found the solution.
It was because i didn't covert the date type. It was always returning Microsoft AJAX serialized dates (Eg "/Date(1313467512730+0530)/"). This date i need to convert like "2011-08- 15T00:00:00:000". For this i used convert handler.
Code is like
<ext:RecordField Name="SampleStartDate" Mapping="StartDate" Type="Date">
<Convert Handler="return new Date(parseInt(value.substr(6)))" />
</ext:RecordField>
Then i am getting the nullable datetime field values in store.
Hope it will help you also
Thanks

Resources