creating DropdownList - asp.net

Consider the following XML file:
<?xml version="1.0" encoding="utf-8"?>
<warehouse>
<cat id="computer">
<item>
<SN>1</SN>
<name>Toshiba</name>
<quantity>12</quantity>
<description>CPU: CORE I5 RAM: 3 GB HD: 512 GB</description>
<price>400 USD</price>
</item>
<item>
<SN>2</SN>
<name>Dell</name>
<quantity>14</quantity>
<description>CPU: CORE I5 RAM: 3 GB HD: 512 GB</description>
<price>300 USD</price>
</item>
<item>
<SN>3</SN>
<name>Dell</name>
<quantity>14</quantity>
<description>CPU: CORE I5 RAM: 3 GB HD: 512 GB</description>
<price>300 USD</price>
</item>
<item>
<SN>5</SN>
<name>Dell</name>
<quantity>14</quantity>
<description>CPU: CORE I5 RAM: 3 GB HD: 512 GB</description>
<price>300 USD</price>
</item>
<item>
<SN>6</SN>
<name>Dell</name>
<quantity>14</quantity>
<description>CPU: CORE I5 RAM: 3 GB HD: 512 GB</description>
<price>300 USD</price>
</item>
<item>
<SN>8</SN>
<name>Toshiba</name>
<quantity>13</quantity>
<description>CPU: CORE I5 RAM: 5 GB HD: 512 GB3</description>
<price>400 USD</price>
</item>
<item>
<SN>9</SN>
<name>Toshiba</name>
<quantity>13</quantity>
<description>CPU: CORE I5 RAM: 5 GB HD: 512 GB3</description>
<price>400 USD</price>
</item>
<item>
<SN>dsfdSF</SN>
<name>fsdfsD</name>
<quantity>dsfdSFS</quantity>
<description>FSDFS</description>
<price>FSDFSD</price>
</item>
<item>
<SN>dsfdSF</SN>
<name>fsdfsD</name>
<quantity>dsfdSFS</quantity>
<description>FSDFS</description>
<price>FSDFSD</price>
</item>
<item>
<SN>alia</SN>
<name>alia</name>
<quantity>alia</quantity>
<description>alia</description>
<price>alia</price>
</item>
</cat>
<cat id="Stationery">
<item>
<SN> 1 </SN>
<name>note books</name>
<quantity>250</quantity>
<description>Caterpiller</description>
<price>5 USD</price>
</item>
<item>
<SN> 2 </SN>
<name> pencils </name>
<quantity> 300 </quantity>
<description> Caterpiller </description>
<price> 2 USD </price>
</item>
<item>
<SN> 3 </SN>
<name> note books </name>
<quantity> 250 </quantity>
<description> Caterpiller </description>
<price> 5 USD </price>
</item>
<item>
<SN>4</SN>
<name>pencils</name>
<quantity>45</quantity>
<description>Pilot</description>
<price>4 USD</price>
</item>
<item>
<SN>5</SN>
<name>pencils</name>
<quantity>45</quantity>
<description>Pilot</description>
<price>4 USD</price>
</item>
<item>
<SN>6</SN>
<name>pencils</name>
<quantity>45</quantity>
<description>Pilot</description>
<price>4 USD</price>
</item>
<item>
<SN>7</SN>
<name>sdfsdfsdfsdfsd</name>
<quantity>sdfsdf</quantity>
<description>dsfsdfs</description>
<price>sdfsdf</price>
</item>
<item>
<SN>8</SN>
<name>pencils</name>
<quantity>45</quantity>
<description>Pilot</description>
<price>4 USD</price>
</item>
<item>
<SN>9</SN>
<name>books</name>
<quantity>250</quantity>
<description>chinses</description>
<price>3 USD</price>
</item>
<item>
<SN>alia</SN>
<name>alia</name>
<quantity>alia</quantity>
<description>alia</description>
<price>alia</price>
</item>
</cat>
<cat id="Furniture">
<item>
<SN> 1 </SN>
<name>dasd</name>
<quantity>asdasd</quantity>
<description>das</description>
<price>dasd</price>
</item>
<item>
<SN> 2 </SN>
<name> chairs </name>
<quantity> 18 </quantity>
<description> European Type</description>
<price> 150 USD </price>
</item>
<item>
<SN>3</SN>
<name>Tabels</name>
<quantity>12</quantity>
<description>European Type</description>
<price>50 USD</price>
</item>
<item>
<SN>4</SN>
<name>Tabels</name>
<quantity>12</quantity>
<description>European Type</description>
<price>50 USD</price>
</item>
<item>
<SN>5</SN>
<name>Tabels</name>
<quantity>12</quantity>
<description>European Type</description>
<price>50 USD</price>
</item>
<item>
<SN>6</SN>
<name>Tabels</name>
<quantity>12</quantity>
<description>European Type</description>
<price>50 USD</price>
</item>
<item>
<SN>7</SN>
<name>Tabels</name>
<quantity>12</quantity>
<description>European Type</description>
<price>50 USD</price>
</item>
<item>
<SN>8</SN>
<name>Tabels</name>
<quantity>12</quantity>
<description>European Type</description>
<price>50 USD</price>
</item>
<item>
<SN>alia</SN>
<name>alia</name>
<quantity>alia</quantity>
<description>alia</description>
<price>alia</price>
</item>
</cat>
</warehouse>
I need to create a drop down list. The drop down list has to display all the values of <SN> where <cat id="computer"> only.
How can this be done using LINQ or DataView or Xpath?

How about this?
XmlDocument doc = new XmlDocument();
doc.Load(#"~/XML/XML.xml");
var nodes = doc.SelectNodes("warehouse/cat[#id='computer']/item/SN");
myDropDown.DataTextField = "InnerText";
myDropDown.DataValueField = "InnerText";
//now bind the dropdownlist to the dataview
myDropDown.DataSource = nodes;
myDropDown.DataBind();

Load the xml into an XElement:
var xml = XElement.Load("test.xml");
Execute XPath to select the SN elements in the cats with id computer: (+ put them in a list)
var snValues = xml.XPathSelectElements("//cat[#id='computer']/item/SN")
.Select(x => x.Value).ToList();
Required usings:
using System.Linq;
using System.Xml.Linq;
using System.Xml.XPath;

Related

How can I edit the grid position of a QtElement in the QtDesigner without manipulating the .ui file manually?

How can I change the grid position of the labels "Bottom left" and "bottom right" within the QTDesigner?
In this case, I would like edit the column number of "Bottom left" (from 1 to 0) and "bottom right" (from 0 to 1) without changing the XML manually, as shown in the snippet from the *.ui file.
If I'm using drag and drop, I'am facing some issues with additional columns or rows and in the end, I have to change the *.ui file manually again.
<widget class="QWidget" name="centralwidget">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="top_left">
<property name="text">
<string>Top left</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="top_right">
<property name="text">
<string>Top right</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="bottom_right">
<property name="text">
<string>bottom right</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="bottom_left">
<property name="text">
<string>bottom left</string>
</property>
</widget>
</item>
</layout>
</widget>

Pyqt not displaying QT Application correctly

I am designing a simple GUI to do something and at a very early stage I find that QT is not behaving as I am expecting it to. I designed the ui file in QT Design and it looks like this:
However when I execute the python code and call the application, the object positions are all changed. I have tried converting the ui file to python file and the importing the ui file directly as well. But this has not changed the behavior.
Here is the code:
from __future__ import (
unicode_literals,
print_function,
division,
absolute_import
)
from PyQt4 import QtGui, QtCore, uic
from PyQt4.QtCore import QTime
from PyQt4.QtGui import QApplication
import main_gui
# class MyGUI(QtGui.QMainWindow, main_gui.Ui_MainWindow):
class MyGUI(QtGui.QMainWindow):
"""
The main class to execute the application
"""
def __init__(self, parent=None):
super(MyGUI, self).__init__(parent)
uic.loadUi('main_gui.ui', self)
# self.setupUi(self)
# self.showMaximized()
def main():
"""
But first we'll need to initialize that class on our code startup,
we'll handle the class instance creation and other stuff in our main()
function:
:return: Nothing
"""
app = QtGui.QApplication([])
form = MyGUI()
form.show()
app.exec()
if __name__ == '__main__':
main()
The output looks like this:
Here is a screen shot of my designer:
What am I doing wrong?
EDIT:
Upon request, I am attaching main.ui file. Here it is:
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>1143</width>
<height>865</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="Line" name="line_10">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="title">
<property name="minimumSize">
<size>
<width>200</width>
<height>40</height>
</size>
</property>
<property name="font">
<font>
<pointsize>20</pointsize>
</font>
</property>
<property name="mouseTracking">
<bool>false</bool>
</property>
<property name="text">
<string>Title</string>
</property>
<property name="alignment">
<set>Qt::AlignBottom|Qt::AlignHCenter</set>
</property>
</widget>
</item>
<item>
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item alignment="Qt::AlignLeft|Qt::AlignVCenter">
<widget class="QLabel" name="label_2">
<property name="font">
<font>
<pointsize>24</pointsize>
</font>
</property>
<property name="text">
<string>SN</string>
</property>
</widget>
</item>
<item>
<widget class="Line" name="line_6">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item alignment="Qt::AlignRight|Qt::AlignVCenter">
<widget class="QLabel" name="sn">
<property name="font">
<font>
<pointsize>18</pointsize>
</font>
</property>
<property name="text">
<string>PPPPPPPPPPPPPPGSDB1YYDDDHHMMSS</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item alignment="Qt::AlignLeft|Qt::AlignVCenter">
<widget class="QLabel" name="label_4">
<property name="font">
<font>
<pointsize>18</pointsize>
</font>
</property>
<property name="text">
<string>Part Status</string>
</property>
</widget>
</item>
<item>
<widget class="Line" name="line_7">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item alignment="Qt::AlignRight|Qt::AlignVCenter">
<widget class="QLabel" name="part_status">
<property name="font">
<font>
<pointsize>26</pointsize>
</font>
</property>
<property name="text">
<string>NA</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item alignment="Qt::AlignLeft|Qt::AlignVCenter">
<widget class="QLabel" name="label_7">
<property name="font">
<font>
<pointsize>18</pointsize>
</font>
</property>
<property name="text">
<string>Tester Status</string>
</property>
</widget>
</item>
<item>
<widget class="Line" name="line_8">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item alignment="Qt::AlignRight|Qt::AlignVCenter">
<widget class="QLabel" name="tester_status">
<property name="font">
<font>
<pointsize>28</pointsize>
</font>
</property>
<property name="text">
<string>DOWN</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item alignment="Qt::AlignLeft|Qt::AlignVCenter">
<widget class="QLabel" name="label_9">
<property name="font">
<font>
<pointsize>18</pointsize>
</font>
</property>
<property name="text">
<string>IP Address</string>
</property>
</widget>
</item>
<item>
<widget class="Line" name="line_9">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item alignment="Qt::AlignRight|Qt::AlignVCenter">
<widget class="QLabel" name="ip_address">
<property name="font">
<font>
<pointsize>24</pointsize>
</font>
</property>
<property name="text">
<string>NA</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line_5">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item>
<widget class="QTextBrowser" name="test_box"/>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>1143</width>
<height>26</height>
</rect>
</property>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
<connections/>
</ui>

Access the children from the QScrollArea

I have added a QScrollArea widget in QDialog form.
In the scrollarea, I have added 16 chcekboxes.
I want to loop inside the scrollarea and check for which of the checkboxes are checked.
Can anyone please help me with this. Thanks in advance!
The code for ScrollArea and Checkbox is like this:
<widget class="QScrollArea" name="scrollArea">
<property name="geometry">
<rect>
<x>20</x>
<y>320</y>
<width>271</width>
<height>206</height>
</rect>
</property>
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>252</width>
<height>420</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="0">
<widget class="QCheckBox" name="checkBox1">
<property name="text">
<string>1</string>
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="QCheckBox" name="checkBox7">
<property name="text">
<string>2</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QCheckBox" name="checkBox5">
<property name="text">
<string>3</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="checkBox2">
<property name="text">
<string>4</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QCheckBox" name="checkBox0">
<property name="text">
<string>5</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QCheckBox" name="checkBox3">
<property name="text">
<string>6</string>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QCheckBox" name="checkBox6">
<property name="text">
<string>7</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QCheckBox" name="checkBox4">
<property name="text">
<string>8</string>
</property>
</widget>
</item>
<item row="12" column="0">
<widget class="QCheckBox" name="checkBox12">
<property name="text">
<string>9</string>
</property>
</widget>
</item>
<item row="10" column="0">
<widget class="QCheckBox" name="checkBox10">
<property name="text">
<string>10</string>
</property>
</widget>
</item>
<item row="11" column="0">
<widget class="QCheckBox" name="checkBox11">
<property name="text">
<string>11</string>
</property>
</widget>
</item>
<item row="9" column="0">
<widget class="QCheckBox" name="checkBox9">
<property name="text">
<string>Signal Mask</string>
</property>
</widget>
</item>
<item row="8" column="0">
<widget class="QCheckBox" name="checkBox8">
<property name="text">
<string>12</string>
</property>
</widget>
</item>
<item row="15" column="0">
<widget class="QCheckBox" name="checkBox15">
<property name="text">
<string>13</string>
</property>
</widget>
</item>
<item row="14" column="0">
<widget class="QCheckBox" name="checkBox14">
<property name="text">
<string>14</string>
</property>
</widget>
</item>
<item row="13" column="0">
<widget class="QCheckBox" name="checkBox13">
<property name="text">
<string>15</string>
</property>
</widget>
</item>
<item row="16" column="0">
<widget class="QCheckBox" name="checkBox16">
<property name="text">
<string>16</string>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
This can be accomplished with the QObject::findChildren method.
An example code in your .cpp file that belongs to the .ui file would look like this:
QList<QCheckBox *> allCheckBoxes = this->findChildren<QCheckBox *>();
for (QCheckBox *checkBox: allCheckBoxes) {
if (checkBox->isChecked()) {
qDebug() << "CheckBox with object name " << checkBox->objectName() << " is checked";
}
}

Nested structures with QRadioButtons

I would like to achieve something similar to this picture:
except that the top level ("Adress bar", "forms" and "User names...") should be radio buttons.
The idea is that the sublevels should get enabled or disabled depending on the state of the radiobuttons. And the sublevels should be shifted to the right as on the picture.
Can that be done Qt in an elegant way?
I would say a simple QVBoxLayout for the top level and each "sublevel" has a QHBoxLayout with a fixed sized spacer item as the first child and a QVBoxLayout containing the sub options.
Disabling all sub options can then simply be done by disabling the "sublevel" widget.
Just put those sub-items (like "Browsing history", "Favorites", ...) into a separated QWidget and connect that widget's QWidget::setEnabled() slot with the "Adress bar" radio-button's QAbstractButton::toggled() signal.
This is a Qt Designer's .ui file (with working signal-slot connection, try Ctrl+R in Designer) that demonstrates the idea:
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Form</class>
<widget class="QWidget" name="Form">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>170</width>
<height>178</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QRadioButton" name="radioButton">
<property name="text">
<string>RadioButton</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QWidget" name="widget" native="true">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QCheckBox" name="checkBox">
<property name="text">
<string>CheckBox</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_2">
<property name="text">
<string>CheckBox</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_3">
<property name="text">
<string>CheckBox</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioButton_2">
<property name="text">
<string>RadioButton</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioButton_3">
<property name="text">
<string>RadioButton</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>radioButton</sender>
<signal>toggled(bool)</signal>
<receiver>widget</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>84</x>
<y>17</y>
</hint>
<hint type="destinationlabel">
<x>84</x>
<y>77</y>
</hint>
</hints>
</connection>
</connections>
</ui>

Mapping with BizTalk + Multiple nodes to a single one

I'm trying to make a mapping with this xml:
<rootxml>
<documents>
<document>
<iddoc>1</iddoc>
<total_price>1000</total_price>
</document>
</documents>
<items>
<item>
<iddoc>1</iddoc>
<iditem>1</iditem>
<quantity>1</quantity>
<price>800</price>
</item>
<item>
<iddoc>1</iddoc>
<iditem>2</iditem>
<quantity>1</quantity>
<price>200</price>
</item>
</items>
<taxes>
<tax>
<iddoc>1</iddoc>
<iditem>1</iditem>
<idtax>1000</idtax>
<value>123.90</value>
<tax>
<tax>
<iddoc>1</iddoc>
<iditem>2</iditem>
<idtax>1000</idtax>
<value>34.13</value>
<tax>
</taxes>
</rootxml>
to this one:
<resultxml>
<documento>
<iddoc>1</iddoc>
<total_price>1000</total_price>
<items>
<item>
<iddoc>1</iddoc>
<iditem>1</iditem>
<quantity>1</quantity>
<price>800</price>
<taxes>
<idtax>1000</idtax>
<value>123.90</value>
</taxes>
</item>
<item>
<iddoc>1</iddoc>
<iditem>2</iditem>
<quantity>1</quantity>
<price>200</price>
<taxes>
<tax>
<idtax>1000</idtax>
<value>34.13</value>
<tax>
</taxes>
</item>
</items>
</documento>
</resultxml>
I can't find out how to solve this. Although the original xml document can have several documents it will always have one, so I have to merge the items into it and taxes into its respective item.
Thank you
I think you'll have to write a chunk of custom-XSLT. Loop through items/item and then build an xpath to taxes/tax[where iditem=$itemId]. The trick is to get the first itemId into the variable.
Sorry, I have limited time right now, cannot create a full working demo for you.
Here's the related issue I had a while back:
http://www.stylusstudio.com/ssdn/default.asp?action=9&fid=48&read=7896
Neal Walters

Resources