#Define tvwFirst 0
#Define tvwLast 1
#Define tvwNext 2
#Define tvwPrevious 3
#Define tvwChild 4
Public oForm
oForm = Createobject('lvForm')
oForm.Show()
Define Class lvForm As Form
DataSession = 2
Height = 400
Width = 800
Add Object tv As OleControl With ;
Left = 0,Height = 400,Width = 200, OleClass = 'MSComCtlLib.TreeCtrl'
Add Object lv As OleControl With ;
Left = 200,Height = 400,Width = 600, OleClass = 'MSComCtlLib.ListviewCtrl.2'
Procedure Init
Thisform.tvSetUp()
Thisform.lvSetUp('All')
Endproc
Procedure tv.NodeClick
Lparameters Node
Node.ensurevisible
Thisform.lvSetUp(Node.Key)
Endproc
Procedure lv.ItemClick
Lparameters Item
Thisform.lvSetUp(Item.Key)
Endproc
Procedure lvSetUp(tcKey)
If !(m.tcKey == 'All' Or ;
m.tcKey = 'Cntry_' Or ;
m.tcKey = 'Cust_' Or ;
m.tcKey = 'Ord_')
Return
Endif
With Thisform.tv
.SelectedItem = .Nodes( m.tcKey )
.SelectedItem.ensurevisible
Endwith
With Thisform.lv
.ListItems.Clear()
.ColumnHeaders.Clear()
Do Case
Case m.tcKey = 'All'
.View = 2
.ColumnHeaders.Add( , , "Country", 200)
.ColumnHeaders.Add( , , "Customer Count", 50)
Select country, Cnt(*) As CustomerCount ;
From (_samples+"data\customer") ;
Where !Empty(country) ;
GROUP By country ;
Into Cursor grpByCountry
Scan
itmX = .ListItems.Add(Recno(), 'Cntry_'+Trim(grpByCountry.country))
itmX.Text = Trim(grpByCountry.country)
itmX.SubItems(1) = Transform(grpByCountry.CustomerCount)
Endscan
Use In 'grpByCountry'
Case m.tcKey = 'Cntry_'
.View = 3
.ColumnHeaders.Add( , , "Title", 150)
.ColumnHeaders.Add( , , "Contact", 150)
.ColumnHeaders.Add( , , "Company", 200)
.ColumnHeaders.Add( , , "Country", 100)
Select * From (_samples+"data\customer") ;
Where country == Substr(m.tcKey,Len('Cntry_')+1) ;
Into Cursor crsDetail
Scan
itmX = .ListItems.Add(,'Cust_'+crsDetail.cust_id)
itmX.Text = crsDetail.Title
itmX.SubItems(1) =crsDetail.contact
itmX.SubItems(2) =crsDetail.Company
itmX.SubItems(3) =crsDetail.country
Endscan
Use In 'crsDetail'
Case m.tcKey = 'Cust_'
.View = 3
.ColumnHeaders.Add( , , "Order No", 50)
.ColumnHeaders.Add( , , "Salesman", 200)
.ColumnHeaders.Add( , , "Date Ordered",200)
.ColumnHeaders.Add( , , "Ship Date", 200)
Select * ;
From (_samples+"data\orders") ord ;
INNER Join (_samples+"data\employee") emp ;
ON ord.emp_id == emp.emp_id ;
Where cust_id == Substr(m.tcKey,Len('Cust_')+1) ;
Into Cursor crsDetail
Scan
itmX = .ListItems.Add(,'Ord_'+Padl(Int(Val(crsDetail.order_id)),6,'0') )
itmX.Text = Padl(Int(Val(crsDetail.order_id)),6,'0')
itmX.SubItems(1) = Trim(crsDetail.First_Name - (' '+crsDetail.Last_Name))
itmX.SubItems(2) = Transform(crsDetail.Order_date,'@YL')
itmX.SubItems(3) = Transform(crsDetail.Shipped_on,'@YL')
Endscan
Use In 'crsDetail'
Case m.tcKey = 'Ord_'
.View = 3
.ColumnHeaders.Add( , , "Line No", 50)
.ColumnHeaders.Add( , , "Product Name", 250)
.ColumnHeaders.Add( , , "Quantity", 50, 1)
.ColumnHeaders.Add( , , "Price", 120,1)
.ColumnHeaders.Add( , , "Ext.Price", 120,1)
Select oi.*, prd.Prod_Name ;
From (_samples+"data\orditems") oi ;
INNER Join (_samples+"data\products") prd ;
ON oi.product_id == prd.product_id ;
Where Val(order_id) = Val(Substr(m.tcKey,Len('Ord_')+1)) ;
ORDER By line_no ;
Into Cursor crsDetail
Scan
itmX = .ListItems.Add(,;
'Oi_'+Padl(Int(Val(crsDetail.order_id)),6,'0')+;
Padl(crsDetail.line_no,6,'0') )
itmX.Text = Transform(crsDetail.line_no)
itmX.SubItems(1) = crsDetail.Prod_Name
itmX.SubItems(2) = Transform(crsDetail.Quantity)
itmX.SubItems(3) = Transform(crsDetail.Unit_Price,'@($')
itmX.SubItems(4) = Transform(crsDetail.Unit_Price*crsDetail.Quantity,'@($')
Endscan
Use In 'crsDetail'
Endcase
Endwith
Endproc
Procedure tvSetUp(tcKey)
Local oNode
Local Array oNodes[1]
With Thisform.tv
Do Case
Case Empty(m.tcKey)
.linestyle = 1
.Font.Name = 'Times New Roman'
.Font.Size = 10
.indentation = 5
.LabelEdit = 1
.HideSelection = .F.
oNode = .Nodes.Add(,tvwFirst,'All','Ihracat Yaptigimiz Ulkeler:=)')
Thisform.tvSetUp(oNode.Key)
Case m.tcKey = 'All'
Select country, Cnt(*) As CustomerCount ;
From (_samples+"data\customer") ;
Where !Empty(country) ;
GROUP By country ;
Into Cursor grpByCountry
Dimension oNodes[_Tally]
oNodes = .Null.
Scan
oNodes[RECNO()] = .Nodes.Add(m.tcKey,tvwChild,;
'Cntry_'+Trim(grpByCountry.country),;
Trim(grpByCountry.country))
Endscan
Use In 'grpByCountry'
For Each oNode In oNodes
Thisform.tvSetUp( oNode.Key )
Endfor
Case m.tcKey = 'Cntry_'
Select * From (_samples+"data\customer") ;
Where country == Substr(m.tcKey,Len('Cntry_')+1) ;
Into Cursor crsDetail
Dimension oNodes[_Tally]
oNodes = .Null.
Scan
oNodes[RECNO()] = .Nodes.Add(m.tcKey,tvwChild, ;
'Cust_'+crsDetail.cust_id, crsDetail.Company)
Endscan
Use In 'crsDetail'
For Each oNode In oNodes
Thisform.tvSetUp( oNode.Key )
Endfor
Case m.tcKey = 'Cust_'
Select * ;
From (_samples+"data\orders") ord ;
INNER Join (_samples+"data\employee") emp ;
ON ord.emp_id == emp.emp_id ;
Where cust_id == Substr(m.tcKey,Len('Cust_')+1) ;
Into Cursor crsDetail
Scan
.Nodes.Add(m.tcKey,tvwChild,;
'Ord_'+Padl(Int(Val(crsDetail.order_id)),6,'0'),;
'Order#:'+Padl(Int(Val(crsDetail.order_id)),6,'0'))
Endscan
Use In 'crsDetail'
Endcase
Endwith
Endproc
Enddefine