Powerbuilder : How to Get the RowNumber of specific data on datawindow - powerbuilder

Good Day!,
Can anyone here give me a hint or idea on how to get the rownumber of specific value in datawindow.
i have 2 objects, treeview and datawindow with same Value. Treeview data are sorted but in datawindow is not. when i click an item in Treeview it will show the rownumber in datawindow correspond to value clicked in treeview. How can i do that?
Best regards,
Newnbie
P.S Sorry for my English

I would use dw.Find(*). Code example:
long ll_row
string ls_keyValue, ls_dwSearch
// Read value from TreeView
ls_keyValue = '...'
// "MyKey" :: Column in DataWindow containing the key read from tree view
ls_dwSearch = "MyKey = '" + ls_keyValue + "'"
ll_row = dw_data.Find(ls_dwSearch, 1, dw_data.RowCount( ))
if ll_row > 0 then
// Key value found => Make row current and visible
dw_data.ScrollToRow(ll_row)
end if

Related

how to Auto fill fields in powerbuilder

i'm new to PowerBuilder 10.5 i'm trying to create a cost application , i want to autocomplete the row when i pick a enter image description herematerial from a DDDW i want to auto fill the price & unit. there are 2 tables 1Material - Unit - Price 2- Itemname DDDW - Quantity - Unit - Price
i did it on MSaccess but i don't know how to code it on PowerBuilder
on access the code was
Private Sub ItemName_AfterUpdate()
Unit = ItemName. Column(2)
Price = ItemName. Column(3)
End Sub
how can i do it in PowerBuilder
Code the following in the ƌtemChanged event of your detail datawindow (of course the code must be adapted to your specific situation):
decimal ld_qty, ld_unitprice
if Upper(dwo.name) <> 'ITEM' then
return
end if
select qty, unit_price into :ld_qty, :ld_unitprice from your_table where your_table.key = data;
dw2.SetItem(row, 'your_dw_col_qty', ld_qty)
dw2.SetItem(row, 'your_dw_unit_price', ld_unitprice)
If you have included the quantity and price with the data retrieved as part of the datawindow object you are using for the DDDW you can access it without another database call. Something like this (in itemchanged event):
datawindowchild dwc
string ls_name
long ll_row
IF Upper(dwo.Name) = "ITEM" THEN
GetChild("item", dwc)
ls_name = data
dwc.SetFilter("name = '" + ls_name +"'" )
dwc.Filter( ) // filter to specific row in dddw
ll_row = dwc.RowCount( ) // How many? Use the last one.
if ll_row > 0 then
SetItem(row, "cost", GetItemDecimal('cost', ll_row))
SetItem(row, "amount", GetItemDecimal('amount', ll_row))
end if
end if

How to recursively query for many to many relationships in SQL Server 2012

I have a table in SQL 2012 that has a many to many relationship with itself through a junction table. It's laid out as follows
The many to many relationship I'm referring to is Currency_Dependency.
What I would like to do is make a recursive query that displays all dependencies in a tree fashion, so that each relationship is denoted with a number that shows how many steps away from the primary currency item being selected, as well as a number identifying which branch it's on. I would want, if possible, this query to go both ways, showing all of the currency items it depends on (Parent currency items), as well as all of the currency items that depend on it (child currency items). I have a query that shows only the first level both ways.
SELECT curr.Model AS 'Root Currency Item', cur2.Model AS 'Child Currency Item', cur3.Model AS 'Parent Currency Item'
FROM dbo.Currency curr
FULL JOIN dbo.Currency_Dependency cdep
ON curr.CurrencyId = cdep.CurrencyId
FULL JOIN dbo.Currency cur2
ON cdep.DependencyId = cur2.CurrencyId
FULL JOIN dbo.Currency_Dependency cdep2
ON curr.CurrencyId = cdep2.DependencyId
FULL JOIN dbo.Currency cur3
ON cdep2.CurrencyId = cur3.CurrencyId
WHERE curr.Status = 1 AND NOT(cur2.Model IS null AND cur3.Model IS null)
Which produces these results
So I would like additional columns for parent and child dependencies with that number denoting how many steps from the root currency item it is. I hope that makes sense.
Is such a query possible? I'm aware that a common table expression is something that is used for recursive queries but everything I've read on it so far has been pretty Greek (I'm a 2nd year Computer programming student)
Please let me know if you can help! Thanks so much!
Without example data I can't be sure, but I think this is what you are after:
;with cte as (
-- anchor elements: where curr.Status = 1 and not a dependent
select
CurrencyId
, Model
, ParentId = null
, ParentModel = convert(varchar(128),'')
, Root = curr.Model
, [Level] = convert(int,0)
, [Path] = convert(varchar(512),Model)
from dbo.Currency as curr
where curr.Status = 1
/* anchors do not depend on any other currency */
and not exists (
select 1
from dbo.Currency_Dependency i
where curr.CurrencyId = i.DependencyId
)
-- recursion begins here
union all
select
CurrencyId = c.CurrencyId
, Model = c.Model
, ParentId = p.CurrencyId
, ParentModel = convert(varchar(128),p.Model)
, Root = p.Root
, [Level] = p.[Level] + 1
, [Path] = convert(varchar(512),p.[Path] + ' > ' + c.Model)
from dbo.Currency as c
inner join dbo.Currency_Dependency as dep
on c.CurrencyId = dep.DependencyId
inner join cte as p
on dep.CurrencyId = p.CurrencyId
)
select * from cte

In Handsontable How do you save records with specific ids each row?

I have this set of records object-array like for example..
[{firstname:'John',lastname:'Smith'},{firstname:'Jimmy',lastname:'Morre'}]
What I want to do is to enable Saving feature of Handsontable. My problem is I can't update it where column name is "firstname" or "lastname" .. or at least row id (where can I put rowID by the way?) because the getData() function returns only values of the cell not the with the properties of the original data-set such as like 'firstname ' and 'lastname'.
Anyone from here who are more familiar with Handsontable? thank you..
I am not sure to understand what you want.
But in this JSFiddle you can see how to get the property of your data ;)
var datas = hot.getData()
$.each(datas, function(rowIndex, row) {
console.log('The row id is ' + rowIndex);
$.each(row, function(colIndex, value) {
console.log('The column id is ' + colIndex + ' and the property is ' + Object.keys(hot.getSchema())[colIndex]);
console.log(value);
});
console.log("----------------------------");
});
I hope it helps you.

How do I populate table fields with combobox selections in Access

I have a Combobox with 2 columns and I'm trying to get it to populate 2 fields in a table AfterUpdate. The code I have right now is:
Private Sub ProductSelect_AfterUpdate()
Product = ProductSelect.Column(0)
Product2 = ProductSelect.Column(1)
End Sub
But it only populates the "Product" field, not the "Product2" field. From everything I've read this should work. What am I missing?
The correct code, I've found, is this:
Private Sub ProductSelect_AfterUpdate()
Me!Product = Me!ProductSelect.Column(0)
Me!Product2 = Me!ProductSelect.Column(1)
End Sub

QRelationalTable category with relation

I have small problem in Qt. I have two tables, one with products, one with categories. I want to display list of products in QTableView. No big deal. It's also not big deal to assign relation and display name of category instead of id in one column.
But, in categories I have an internal relation, so I can make subcategories. It's done very simple by creating additional column with parentId.
And here is the problem... How can I display that relation in QTableView? I mean instead of displaying only name of category that products belong to, it will display all parent categories also, for example that way:
Have 3 categories:
Food (with no parent)
Fruits (with parent Food)
Citrus(with parent Fruits)
Product:
Orange assigned to category Citrus.
In TableView in column Category it should be:
Food/Fruits/Citrus
or
Food->Fruits->Citrus
or something like that...
How to do it? Subclass QRelationalTableModel and make additional relation? Or make Delegate for that column? Or maybe both?
Arleady did it...
What I've done:
For table categories
CREATE TABLE categories (id INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR(100), parent NUMERIC)
created table categories_closure (all SQL statements are for SQLite) :
CREATE TABLE categories_closure (parent NUMERIC, child NUMERIC, depth NUMERIC)
next, created some triggers to automate my closure table
CREATE TRIGGER categories_delete AFTER DELETE ON categories
BEGIN
DELETE FROM categories_closure WHERE child=OLD.id;
UPDATE categories SET parent=OLD.parent WHERE parent=OLD.id;
END;
CREATE TRIGGER categories_insert AFTER INSERT ON categories
BEGIN
INSERT INTO categories_closure (parent, child, depth) VALUES (NEW.id, NEW.id, 0);
INSERT INTO categories_closure (parent, child, depth)
SELECT p.parent, c.child, p.depth+c.depth+1
FROM categories_closure p, categories_closure c
WHERE p.child=NEW.parent AND c.parent=NEW.id;
END;
CREATE TRIGGER categories_update AFTER UPDATE OF id,parent ON categories
BEGIN
DELETE FROM categories_closure WHERE child=OLD.id;
INSERT INTO categories_closure (parent, child, depth) VALUES (NEW.id, NEW.id, 0);
INSERT INTO categories_closure (parent, child, depth)
SELECT p.parent, c.child, p.depth+c.depth+1
FROM categories_closure p, categories_closure c
WHERE p.child=NEW.parent AND c.parent=NEW.id;
UPDATE categories SET parent=NEW.id WHERE parent=OLD.id;
END;
Now I can get string of all parent categories with simple query, co I created an View
CREATE VIEW categories_resolved AS
SELECT
id,
group_concat(name, ' ') AS fullname,
group_concat(parent) AS branch
FROM (
SELECT
c.id,
cc.parent,
c2.name
FROM categories c
LEFT JOIN categories_closure cc ON c.id=cc.child
LEFT JOIN categories c2 ON c2.id=cc.parent
ORDER BY cc.depth DESC
)
GROUP BY id
ORDER BY id ASC
And finally I used this View on relation in QSqlRelationalTableModel instead of categories table. Simple, and no need for creating model, view, proxy, delegate or modify code of Qt classes.

Resources