KiXforms Forum Index KiXforms
The Forum for the KiXforms Community
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 Quick Links 
Site News
Downloads
Documentation
Donations
Script Archive
Tracking Systems

Field chooser

 
Post new topic   Reply to topic    KiXforms Forum Index -> Script Archive
View previous topic :: View next topic  
Author Message
It Took My Prozac
KiXforms Supporter
KiXforms Supporter


Joined: 15 Feb 2005
Posts: 65

PostPosted: Fri May 19, 2006 4:35 am    Post subject: Field chooser Reply with quote

Thanks to Shawn, Jochen and Benny,
I've written a field chooser that enables users to select columns for listviews, reports etc. You can move the fields up and down and toggle selection with a click. Hope you like it...
Cheers,
Richard

Code:
Break On

$=SetOption("NoVarsInStrings","On")
$aQueryColumns="MachineName","SerialNumber","Status","OS","Manufacturer","Model","LastUserName"
$aFields="uniqueid","SerialNumber","MachineName","UpdateTime","FirstAdded","Discovered","Laptop",
"DeliveryDate","ReturnDate","LeasePeriod","PurchaseOrderNumber","LeaseContractNumber","VendorQuoteNumber",
"VendorInvoiceNumber","TotalValue","Status","FinancialStatus","Division","Classification","Role","BST",
"Site","Location","Custodian","AssetNumber","Comment","Manufacturer","Model","BIOS","OSFamily","OS",
"ServicePack","WinDomain","DNSDomain","LastUserID","LastUserName","CpuName","CpuArchitecture","CpuSpeed",
"NumberOfCpus","CoresPerCpu","ThreadsPerCore","Memory","OU","AltNames","Dependencies","MaintContract",
"MaintEndDate","MaintLevel","MaintProvider"

$DarkColour = 80,115,165

AddDictionaries

$System=CreateObject("Kixtart.System")

$Form = $System.Form
$Form.Width = 1000
$Form.Height = 500
$Form.Center

$ToolBar = $Form.Controls.GroupBox
$ToolBar.Height = 26
$ToolBar.Dock = 1
$ToolBar.DockPadding = 2,2,2,2

$Button = $ToolBar.Controls.ToolButton
$Button.Width = 120
$Button.Dock = 3
$Button.Icon = 72
$Button.Text = "Select Columns"
$Button.OnClick = "$aQueryColumns=SelectFields($aQueryColumns,$aFields,1) UpdateListView"

$ListView = $Form.ListView
$ListView.Dock = 5

$YesNoBox = $Form.Dialogs.MessageBox
$YesNoBox.Title = "Are you sure..."
$YesNoBox.Style = 36

UpdateListview

$Form.Show

While $Form.Visible
   $=Execute($System.DoEvents)
Loop

Function UpdateListView

   Dim $i
   $ListView.Beginupdate
   $ListView.Columns.Clear
   For $i = 0 to Ubound($aQueryColumns)
      $=$ListView.Columns.Add($dRColumn.Item($aQueryColumns[$i]),100)
   Next
   $ListView.Endupdate

EndFunction

Function SelectFields($a1,$a2,Optional $Resolve)

   If Ubound($a2)=0
      $SelectFields=$a2
      Exit
   EndIf
   $Form.BeginUpdate
   ;Hack! Can't reliably get back to sbSelectFields through control name
   If IsDeclared($sbSelectFields)
      $sbSelectFields=""
   Else
      Global $sbSelectFields
   EndIf      
   Dim $frmSelectFields,$agbTopTickBar[4],$gbTick,$agbBottomTickBar[4],$btnSelectAll,$btnDeselectAll,$gbSelectFields,$Col,$i,$j,$aButton[Ubound($a2)],$aOrder[Ubound($a2)],$Y,$a3,$Text
   $frmSelectFields = ""
   $frmSelectFields = $System.Form($Form)
   $frmSelectFields.Width = 194
   $frmSelectFields.ClientHeight = 30+(Ubound($a2)+1)*20
   $frmSelectFields.icon = 72
   $frmSelectFields.Text = "Select Columns"
   $frmSelectFields.OnResize = "ResizeSelectFieldsForm("+(Ubound($a2)+1)+")"
   $frmSelectFields.Name = "frmSelectFields"
   $frmSelectFields.MinimizeBox = 0
   $frmSelectFields.MaximizeBox = 0
   $frmSelectFields.MouseMoved = 0
   $frmSelectFields.MinimumSize = 194, 0
   $frmSelectFields.Center
   
   If $frmSelectFields.ClientHeight > 680
      $frmSelectFields.ClientHeight = 680
   EndIf
   
   For $i = 4 to 0 Step -1
      $agbTopTickBar[$i] = $frmSelectFields.Controls.GroupBox
      $agbTopTickBar[$i].BackColor = $DarkColour[0]+(($i+1)*35),$DarkColour[1]+(($i+1)*28),$DarkColour[2]+(($i+1)*18)
      $agbTopTickBar[$i].BorderStyle = 0
      $agbTopTickBar[$i].Height = 1
      $agbTopTickBar[$i].Dock = 1
   Next

   $gbTick = $frmSelectFields.Controls.GroupBox
   $gbTick.Borderstyle = 0
   $gbTick.ForeColor = $DarkBlue
   $gbTick.BackColor = $DarkColour
   $gbTick.Height = 20
   $gbTick.Dock = 1

   $btnSelectAll = $gbTick.Controls.ToolButton("Select All")
   $btnSelectAll.Width = 97
   $btnSelectAll.Icon = 64
   $btnSelectAll.FlatStyle = 1
   $btnSelectAll.Dock = 3
   $btnSelectAll.OnClick = "TickFields("+Ubound($a2)+",0)"
   
   $btnDeselectAll = $gbTick.Controls.ToolButton("Deselect All")
   $btnDeselectAll.Dock = 5
   $btnDeselectAll.Icon = 65
   $btnDeselectAll.FlatStyle = 1
   $btnDeselectAll.OnClick = "TickFields("+Ubound($a2)+",1)"
   
   For $i = 0 to 4
      $agbBottomTickBar[$i] = $frmSelectFields.Controls.GroupBox
      $agbBottomTickBar[$i].BackColor = $DarkColour[0]-(($i+1)*11),$DarkColour[1]-(($i+1)*13),$DarkColour[2]-(($i+1)*16)
      $agbBottomTickBar[$i].BorderStyle = 0
      $agbBottomTickBar[$i].Height = 1
      $agbBottomTickBar[$i].Dock = 1
   Next

   $gbSelectFields = $frmSelectFields.Controls.GroupBox
   $gbSelectFields.name = "gbSelectFields"
   $gbSelectFields.Borderstyle = 0
   $gbSelectFields.Dock = 5

   $sbSelectFields = $gbSelectFields.Controls.ScrollBar()
   $sbSelectFields.Width = 16
   $sbSelectFields.Height = $gbSelectFields.ClientHeight
   $sbSelectFields.Left = $gbSelectFields.ClientWidth - 16
   $sbSelectFields.Minimum = 0
   $sbSelectFields.Maximum = Ubound($a2)-($gbSelectFields.ClientHeight/20)+1
   $sbSelectFields.Step = 1
   $sbSelectFields.OnScroll = "ScrollSelectFields"
   $sbSelectFields.Orientation = 1

   For $i = 0 to Ubound($a1)
      $aOrder[$i] = $i
      $aButton[$i] = $gbSelectFields.ToolButton()
      $aButton[$i].Cursor = 16
      $aButton[$i].Size = 170, 20
      $aButton[$i].Alignment = 0
      $aButton[$i].Top = $i*$aButton[$i].Height
      $aButton[$i].OnMouseDown = "$aButton["+$i+"].BringToFront $frmSelectFields.Y = $aButton["+$i+"].MouseY"
      $aButton[$i].OnMouseMove = "MouseMove("+$i+")"
      $aButton[$i].OnMouseUp = "ReOrder("+$i+",$frmSelectFields.MouseMoved) $frmSelectFields.MouseMoved=0"
      $aButton[$i].Text = IIf($dRColumn.Item($a1[$i]) And $Resolve,$dRColumn.Item($a1[$i]),$a1[$i])
      $aButton[$i].Name = "b"+$i
      $aButton[$i].Icon = 64
      $aButton[$i].Tag = 64
   Next
   $j = Ubound($a1)
   For $i = 0 to Ubound($a2)
      If AScan($a1,$a2[$i])=-1
         $j=$j+1
         $aOrder[$j] = $j
         $aButton[$j] = $gbSelectFields.ToolButton()
         $aButton[$j].Cursor = 16
         $aButton[$j].Size = 170, 20
         $aButton[$j].Alignment = 0
         $aButton[$j].Top = $j*$aButton[$j].Height
         $aButton[$j].OnMouseDown = "$aButton["+$j+"].BringToFront $frmSelectFields.Y = $aButton["+$j+"].MouseY"
         $aButton[$j].OnMouseMove = "MouseMove("+$j+")"
         $aButton[$j].OnMouseUp = "ReOrder("+$j+",$frmSelectFields.MouseMoved) $frmSelectFields.MouseMoved=0"
         $aButton[$j].Text = IIf($dRColumn.Item($a2[$i]) And $Resolve,$dRColumn.Item($a2[$i]),$a2[$i])
         $aButton[$j].Name = "b"+$j
         $aButton[$j].Icon = 65
         $aButton[$j].Tag = 65
      EndIf
   Next
   $frmSelectFields.aButton = $aButton
   $frmSelectFields.aOrder = $aOrder
   $Form.EndUpdate
   $frmSelectFields.Center
   $frmSelectFields.Show

   While $frmSelectFields.Visible And $Form.Visible
      $=Execute($System.DoEvents)
   Loop
   $aOrder = $frmSelectFields.aOrder
   
   $j = 0
   For $i = 0 to Ubound($aOrder)
      If $frmSelectFields.Controls("b"+$aOrder[$i]).Tag = 64
         ReDim Preserve $a3[$j]
         $a3[$j]=IIf($dQColumn.Item($frmSelectFields.Controls("b"+$aOrder[$i]).Text) And $Resolve,$dQColumn.Item($frmSelectFields.Controls("b"+$aOrder[$i]).Text),$frmSelectFields.Controls("b"+$aOrder[$i]).Text)
         $j=$j+1
      EndIf
   Next
   If DifferentArrays($a1,$a3)
      If $YesNoBox.Show("Do you wish to accept the new field changes?","Fields Changed")=6
         $SelectFields=$a3
      Else
         $SelectFields=$a1
      EndIf
   Else
      $SelectFields=$a1
   EndIf
   
EndFunction

Function ScrollSelectFields

   Dim $i, $frmSelectFields, $aOrder
   $frmSelectFields = $System.ActiveForm
   If $frmSelectFields.Name = "frmSelectFields"
      $aOrder = $frmSelectFields.aOrder
      $frmSelectFields.BeginUpdate
      For $i = 0 to Ubound($aOrder)
         $frmSelectFields.Controls("b"+$aOrder[$i]).Top = ($i-$sbSelectFields.value) * 20
      Next
      $sbSelectFields.Top = 0
      $frmSelectFields.EndUpdate
   EndIf

EndFunction

Function MouseMove($i)

   Dim $frmSelectFields,$aButton,$Y
   $frmSelectFields=$System.ActiveForm
   If $frmSelectFields.name = "frmSelectFields"
      $aButton = $frmSelectFields.aButton
      If $aButton[$i].MouseButton = 1
         If $frmSelectFields.Controls("gbSelectFields").MouseY > $frmSelectFields.Controls("gbSelectFields").Height Or $frmSelectFields.Controls("gbSelectFields").MouseY < 0
            $sbSelectFields.Value = $sbSelectFields.Value + ($frmSelectFields.Controls("gbSelectFields").MouseY - IIf($frmSelectFields.Controls("gbSelectFields").MouseY < 0,0,$frmSelectFields.Controls("gbSelectFields").ClientHeight)) / 20
            ScrollSelectFields
         EndIf
         $Y = $aButton[$i].Top - $frmSelectFields.Controls("gbSelectFields").MouseY + $frmSelectFields.Y
         If Abs($Y) => 20
            $frmSelectFields.BeginUpdate
            $aButton[$i].Top  = $aButton[$i].Top - ($Y/20)*20
            $frmSelectFields.EndUpdate
            $frmSelectFields.MouseMoved=1
            ReOrder($i)
            ScrollSelectFields
         EndIf
      EndIf
   EndIf

EndFunction

Function ReOrder($i,Optional $MouseMoved)

   Dim $frmSelectFields,$aButton,$aOrder,$OldPos,$NewPos,$Step,$h,$j
   $frmSelectFields = $System.ActiveForm
   $frmSelectFields.Controls("b"+$aOrder[$i]).Top = ($i-1-$sbSelectFields.value) * 20
   $aButton = $frmSelectFields.aButton
   $aOrder = $frmSelectFields.aOrder
   $OldPos=AScan($aOrder,Cint(Right($aButton[$i].Name,-1)))
   $NewPos=($aButton[$i].Top/20)+$sbSelectFields.value
   If $NewPos < 0 $NewPos = 0 EndIf
   If $NewPos > Ubound($aOrder) $NewPos = Ubound($aOrder) EndIf
   $Step=IIf($NewPos-$OldPos > 0,1,-1)
   If $NewPos=$OldPos
      If $MouseMoved = 0
      ; Hack! Have to use tag property as I can't query the Icon property.
         If $aButton[$i].Tag=65
            $aButton[$i].Icon = 64
            $aButton[$i].Tag = 64
         Else
            $aButton[$i].Icon = 65
            $aButton[$i].Tag = 65
         EndIf
      EndIf
   Else
      $frmSelectFields.BeginUpdate
      For $j = $OldPos to $NewPos-$Step Step $Step
         $aOrder[$j] = $aOrder[$j+$Step]
         $h = $aOrder[$j]
         $aButton[$h].Top = ($j-$sbSelectFields.value) * 20
      Next
      $aOrder[$NewPos]=$i
      $aButton[$i].Top = ($NewPos-$sbSelectFields.value) * 20
      $frmSelectFields.EndUpdate
   EndIf
   $frmSelectFields.aButton=$aButton
   $frmSelectFields.aOrder=$aOrder

EndFunction

Function ResizeSelectFieldsForm($i)

   Dim $frmSelectFields,$gbSelectFields
   $frmSelectFields = $System.ActiveForm
   If $frmSelectFields.Name = "frmSelectFields"
      $gbSelectFields = $frmSelectFields.Controls("gbSelectFields")
      $frmSelectFields.Width = 194
      If $frmSelectFields.ClientHeight > 30+$i*20
         $frmSelectFields.ClientHeight = 30+$i*20
      Else
         $frmSelectFields.ClientHeight = 30+20*($gbSelectFields.ClientHeight/20)
         $sbSelectFields.Maximum = $i-($gbSelectFields.ClientHeight/20)
      EndIf
      $sbSelectFields.Height = $gbSelectFields.ClientHeight
      $frmSelectFields.Refresh
   EndIf

EndFunction

Function TickFields($i,$Untick)

   Dim $frmSelectFields,$j
   $frmSelectfields = $System.ActiveForm
   For $j = $Untick to $i
      $frmSelectFields.Controls("gbSelectFields").Controls("b"+$j).Icon = 64 + $Untick
      $frmSelectFields.Controls("gbSelectFields").Controls("b"+$j).Tag = 64 + $Untick
   Next

EndFunction

Function DifferentArrays($a1,$a2)

   If Ubound($a1) <> Ubound($a2)
      $DifferentArrays = 1
      Exit
   EndIf
   Dim $i
   For $i = 0 to Ubound($a1)
      If $a1[$i] <> $a2[$i]
         $DifferentArrays = 1
         Exit
      EndIf
   Next       

EndFunction

Function AddDictionaries

   Global $dQColumn,$dRColumn
   $dQColumn = CreateObject("Scripting.Dictionary")
   $dQColumn.CompareMode=1
   $dQColumn.Add("Machine Name","MachineName")
   $dQColumn.Add("Serial Number","SerialNumber")
   $dQColumn.Add("Asset Number","AssetNumber")
   $dQColumn.Add("BST","BST")
   $dQColumn.Add("Classification","Classification")
   $dQColumn.Add("Comment","Comment")
   $dQColumn.Add("Date Updated","UpdateTime")
   $dQColumn.Add("Division","Division")
   $dQColumn.Add("Financial Status","FinancialStatus")
   $dQColumn.Add("Lease Contract Number","LeaseContractNumber")
   $dQColumn.Add("Location","Location")
   $dQColumn.Add("Purchase Order Number","PurchaseOrderNumber")
   $dQColumn.Add("Role","Role")
   $dQColumn.Add("Site","Site")
   $dQColumn.Add("Status","Status")
   $dQColumn.Add("Total Value","TotalValue")
   $dQColumn.Add("Vendor Invoice Number","VendorInvoiceNumber")
   $dQColumn.Add("Vendor Quote Number","VendorQuoteNumber")
   $dQColumn.Add("Dependencies","Dependencies")
   $dQColumn.Add("DNS Domain","DNSDomain")
   $dQColumn.Add("Manufacturer","Manufacturer")
   $dQColumn.Add("Model","Model")
   $dQColumn.Add("OS Family","OSFamily")
   $dQColumn.Add("Service Pack","ServicePack")
   $dQColumn.Add("Unique ID","UniqueID")
   $dQColumn.Add("Laptop (0/1)","Laptop")
   $dQColumn.Add("Date First Added","FirstAdded")
   $dQColumn.Add("Date Updated","UpdateTime")
   $dQColumn.Add("Date of Delivery","DeliveryDate")
   $dQColumn.Add("Date of Return","ReturnDate")
   $dQColumn.Add("Discovered (0/1)","Discovered")
   $dQColumn.Add("Lease Period (years)","LeasePeriod")
   $dQColumn.Add("Operating System","OS")
   $dQColumn.Add("Organisational Unit","OU")
   $dQColumn.Add("Domain","WinDomain")
   $dQColumn.Add("BIOS Version","BIOS")
   $dQColumn.Add("Last User (User ID)","LastUserID")
   $dQColumn.Add("Last User (Full Name)","LastUserName")
   $dQColumn.Add("Last Logged On User",)
   $dQColumn.Add("CPU Architecture","CpuArchitecture")
   $dQColumn.Add("CPU Name","CpuName")
   $dQColumn.Add("CPU Speed (MHz)","CpuSpeed")
   $dQColumn.Add("CPU (Number of CPU's)","NumberOfCpus")
   $dQColumn.Add("CPU (Cores/CPU)","CoresPerCPU")
   $dQColumn.Add("CPU (Threads/Core)","ThreadsPerCore")
   $dQColumn.Add("Memory Size (MB)","Memory")
   $dQColumn.Add("Memory Speed (MHz)","Speed")
   
   $dRColumn = CreateObject("Scripting.Dictionary")
   $dRColumn.CompareMode=1
   Dim $Key
   For Each $Key in $dQColumn
      $dRColumn.Add($dQColumn.Item($Key),$Key)
   Next

EndFunction


Last edited by It Took My Prozac on Thu Jun 01, 2006 12:50 am; edited 5 times in total
Back to top
View user's profile Send private message
Jochen
KiXforms Devotee
KiXforms Devotee


Joined: 05 Mar 2003
Posts: 1204
Location: Stuttgart, Germany

PostPosted: Fri May 19, 2006 9:11 am    Post subject: Reply with quote

Very cool script there Richard, and I am partly proud of it too Smile
I will keep that very nice sample in mind for later use!



One comment on it though: Please add a break on at the beginning of the code for well known reasons (One who runs don't wan't to be logged off if he is in need of terminating the process)

_________________
Jochen

Tell me, and I will forget.
Show me, and I may remember.
Involve me, and I will understand.
Back to top
View user's profile Send private message MSN Messenger
It Took My Prozac
KiXforms Supporter
KiXforms Supporter


Joined: 15 Feb 2005
Posts: 65

PostPosted: Mon May 22, 2006 12:28 am    Post subject: Reply with quote

Thanks Jochen, Very Happy
Silly me for not including "Break On". As you can imagine, I cut this out of a much larger script and I forgot to include it. I hate when I log myself off accidentally. Stupid Anyway I've updated the code with another form and a ListView to show the control in action.
Cheers,
Richard
Back to top
View user's profile Send private message
It Took My Prozac
KiXforms Supporter
KiXforms Supporter


Joined: 15 Feb 2005
Posts: 65

PostPosted: Thu Jun 01, 2006 12:43 am    Post subject: Reply with quote

Hi All,
I've changed this script to make it a lot nicer. The scrolling is much smoother now and the buttons now scroll when the mouse is above or below the client height of the groupbox they're a member of. I've also add the ability to check/uncheck all the buttons. Wink
Cheers,
Richard
Back to top
View user's profile Send private message
Jochen
KiXforms Devotee
KiXforms Devotee


Joined: 05 Mar 2003
Posts: 1204
Location: Stuttgart, Germany

PostPosted: Thu Jun 01, 2006 11:09 am    Post subject: Reply with quote

Richard,

you're an artist!
I like this(these) groupbox(es) to select/deselect all. Nice 3d effect.


Hmm, will have to ask Shawn someday what happened to the GradientColor properties stuff Wink

_________________
Jochen

Tell me, and I will forget.
Show me, and I may remember.
Involve me, and I will understand.
Back to top
View user's profile Send private message MSN Messenger
benny69
KiXforms Advocate
KiXforms Advocate


Joined: 30 Oct 2003
Posts: 567
Location: Lincoln, Ne

PostPosted: Thu Jun 01, 2006 11:44 am    Post subject: Reply with quote

Richard,
Very Nice!, I like how you are creating your ToolButtons.
Curious, why do you choose to use ToolButtons and not CheckBoxs?

_________________
Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta)
Back to top
View user's profile Send private message Send e-mail
Jochen
KiXforms Devotee
KiXforms Devotee


Joined: 05 Mar 2003
Posts: 1204
Location: Stuttgart, Germany

PostPosted: Thu Jun 01, 2006 12:31 pm    Post subject: Reply with quote

That's because of the dragability of the controls to change the order of columns ... it probably just doesn't look that nice with checkboxes, idk
_________________
Jochen

Tell me, and I will forget.
Show me, and I may remember.
Involve me, and I will understand.
Back to top
View user's profile Send private message MSN Messenger
benny69
KiXforms Advocate
KiXforms Advocate


Joined: 30 Oct 2003
Posts: 567
Location: Lincoln, Ne

PostPosted: Thu Jun 01, 2006 1:30 pm    Post subject: Reply with quote

Oh, ya I didnít think about that.
I like to see creative KiXforms, well done Richard

_________________
Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta)
Back to top
View user's profile Send private message Send e-mail
It Took My Prozac
KiXforms Supporter
KiXforms Supporter


Joined: 15 Feb 2005
Posts: 65

PostPosted: Thu Jun 01, 2006 11:32 pm    Post subject: Reply with quote

Thanks guys! Very Happy As for the nice 3d effect toolbar, I can solely thank Benny for giving me the idea. I so liked the nice toolbars in KFD .net I just had to do some myself!
Back to top
View user's profile Send private message
It Took My Prozac
KiXforms Supporter
KiXforms Supporter


Joined: 15 Feb 2005
Posts: 65

PostPosted: Mon Jun 05, 2006 7:14 am    Post subject: Reply with quote

Here's a version that uses checkboxes. It also accepts keyboard input for moving the checkboxes up and down.

Code:
Break On

$=SetOption("NoVarsInStrings","On")
$aQueryColumns="MachineName","SerialNumber","Status","OS","Manufacturer","Model","LastUserName"
$aFields="uniqueid","SerialNumber","MachineName","UpdateTime","FirstAdded","Discovered","Laptop",
"DeliveryDate","ReturnDate","LeasePeriod","PurchaseOrderNumber","LeaseContractNumber","VendorQuoteNumber",
"VendorInvoiceNumber","TotalValue","Status","FinancialStatus","Division","Classification","Role","BST",
"Site","Location","Custodian","AssetNumber","Comment","Manufacturer","Model","BIOS","OSFamily","OS",
"ServicePack","WinDomain","DNSDomain","LastUserID","LastUserName","CpuName","CpuArchitecture","CpuSpeed",
"NumberOfCpus","CoresPerCpu","ThreadsPerCore","Memory","OU","AltNames","Dependencies","MaintContract",
"MaintEndDate","MaintLevel","MaintProvider"

$LightBlue = 240,248,255
$MediumBlue = 115,147,193
$DarkBlue = 80,115,165
$ReadOnlyColour = 225,233,240
$DarkBlueText = 5,5,70

AddDictionaries

$System=CreateObject("Kixtart.System")

$Form = $System.Form
$Form.Width = 700
$Form.Height = 500
$Form.Center

$ToolBar = $Form.Controls.GroupBox
$ToolBar.Height = 26
$ToolBar.Dock = 1
$ToolBar.DockPadding = 2,2,2,2

$Button = $ToolBar.Controls.ToolButton
$Button.Width = 120
$Button.Dock = 3
$Button.Icon = 72
$Button.Text = "Select Columns"
$Button.OnClick = "$aQueryColumns=SelectFields($aQueryColumns,$aFields,1) UpdateListView"

$ListView = $Form.ListView
$ListView.Dock = 5

$YesNoBox = $Form.Dialogs.MessageBox
$YesNoBox.Title = "Are you sure..."
$YesNoBox.Style = 36

UpdateListview

$Form.Show

While $Form.Visible
   $=Execute($System.DoEvents)
Loop

Function UpdateListView

   Dim $i
$ListView.Beginupdate
$ListView.Columns.Clear
For $i = 0 to Ubound($aQueryColumns)
   $=$ListView.Columns.Add($dRColumn.Item($aQueryColumns[$i]),100)
Next
$ListView.Endupdate

EndFunction

Function SelectFields($a1,$a2,Optional $Resolve)

   If Ubound($a2)=0
      $SelectFields=$a2
      Exit
   EndIf
   $Form.BeginUpdate
   ;Hack! Can't reliably get back to sbSelectFields through control name
   If IsDeclared($sbSelectFields)
      $sbSelectFields=""
   Else
      Global $sbSelectFields
   EndIf      
   Dim $frmSelectFields,$agbTopTickBar[4],$gbTick,$agbBottomTickBar[4],$btnSelectAll,$btnDeselectAll,$gbSelectFields,$Col,$i,$j,$aCheckBox[Ubound($a2)],$aOrder[Ubound($a2)],$Y,$a3,$Text
   $frmSelectFields = ""
   $frmSelectFields = $System.Form($Form)
   $frmSelectFields.Width = 194
   $frmSelectFields.ClientHeight = 52+(Ubound($a2)+1)*20
   $frmSelectFields.Icon = 72
   $frmSelectFields.Text = "Select Columns"
   $frmSelectFields.OnResize = "ResizeSelectFieldsForm("+(Ubound($a2)+1)+")"
   $frmSelectFields.Name = "frmSelectFields"
   $frmSelectFields.MinimizeBox = 0
   $frmSelectFields.MaximizeBox = 0
   $frmSelectFields.MouseMoved = 0
   $frmSelectFields.MinimumSize = 194, 0
   $frmSelectFields.Center
   
   If $frmSelectFields.ClientHeight > 680
      $frmSelectFields.ClientHeight = 680
   EndIf
   
   For $i = 4 to 0 Step -1
      $agbTopTickBar[$i] = $frmSelectFields.Controls.GroupBox
      $agbTopTickBar[$i].BackColor = $DarkBlue[0]+(($i+1)*35),$DarkBlue[1]+(($i+1)*28),$DarkBlue[2]+(($i+1)*18)
      $agbTopTickBar[$i].BorderStyle = 0
      $agbTopTickBar[$i].Height = 1
      $agbTopTickBar[$i].Dock = 1
   Next

   $gbTick = $frmSelectFields.Controls.GroupBox
   $gbTick.Borderstyle = 0
   $gbTick.ForeColor = $DarkBlueText
   $gbTick.BackColor = $DarkBlue
   $gbTick.Height = 20
   $gbTick.Dock = 1

   $btnSelectAll = $gbTick.Controls.ToolButton("Select All")
   $btnSelectAll.HotForeColor = "Blue"
   $btnSelectAll.HotBackColor = $MediumBlue
   $btnSelectAll.Width = 97
   $btnSelectAll.Icon = 64
   $btnSelectAll.Alignment = 1
   $btnSelectAll.FlatStyle = 1
   $btnSelectAll.Dock = 3
   $btnSelectAll.OnClick = "TickFields("+Ubound($a2)+",0)"
   
   $btnDeselectAll = $gbTick.Controls.ToolButton("Deselect All")
   $btnDeselectAll.HotForeColor = "Blue"
   $btnDeselectAll.HotBackColor = $MediumBlue
   $btnDeselectAll.Dock = 5
   $btnDeselectAll.Icon = 65
   $btnDeselectAll.Alignment = 1
   $btnDeselectAll.FlatStyle = 1
   $btnDeselectAll.OnClick = "TickFields("+Ubound($a2)+",1)"
   
   For $i = 0 to 4
      $agbBottomTickBar[$i] = $frmSelectFields.Controls.GroupBox
      $agbBottomTickBar[$i].BackColor = $DarkBlue[0]-(($i+1)*11),$DarkBlue[1]-(($i+1)*13),$DarkBlue[2]-(($i+1)*16)
      $agbBottomTickBar[$i].BorderStyle = 0
      $agbBottomTickBar[$i].Height = 1
      $agbBottomTickBar[$i].Dock = 1
   Next

   $gbSelectFieldsLabel = $frmSelectFields.Controls.GroupBox
   $gbSelectFieldsLabel.Height = 22
   $gbSelectFieldsLabel.DockPadding = 1,2,1,2
   $gbSelectFieldsLabel.Dock = 1
   
   $lblSelectFields = $gbSelectFieldsLabel.Controls.Label("Drag columns up and down to reorder")
   $lblSelectFields.BackColor = $LightBlue
   $lblSelectFields.ForeColor = $DarkBlueText
   $lblSelectFields.BorderStyle = 2
   $lblSelectFields.TextAlign = 32
   $lblSelectFields.Height = 22
   $lblSelectFields.Dock = 5

   $gbSelectFields = $frmSelectFields.Controls.GroupBox
   $gbSelectFields.name = "gbSelectFields"
   $gbSelectFields.Borderstyle = 0
   $gbSelectFields.Dock = 5

   $sbSelectFields = $gbSelectFields.Controls.ScrollBar()
   $sbSelectFields.Width = 16
   $sbSelectFields.Height = $gbSelectFields.ClientHeight
   $sbSelectFields.Dock = 4
   $sbSelectFields.Minimum = 0
   $sbSelectFields.Maximum = Ubound($a2)-($sbSelectFields.ClientHeight/20)+1
   $sbSelectFields.Step = 1
   $sbSelectFields.OnScroll = "ScrollSelectFields"
   $sbSelectFields.Orientation = 1

   For $i = 0 to Ubound($a1)
      $aOrder[$i] = $i
      $aCheckBox[$i] = $gbSelectFields.CheckBox
      $aCheckBox[$i].Checked = -1
      $aCheckBox[$i].Cursor = 16
      $aCheckBox[$i].TextAlign = 16
      $aCheckBox[$i].Size = 170, 20
      $aCheckBox[$i].Top = $i*20
      $aCheckBox[$i].OnKeyDown = "KeyPressed("+$i+",$aCheckBox["+$i+"].KeyCode)"
      $aCheckBox[$i].OnMouseDown = "$frmSelectFields.Y = $aCheckBox["+$i+"].MouseY"
      $aCheckBox[$i].OnMouseMove = "MouseMove("+$i+")"
      $aCheckBox[$i].OnMouseUp = "ReOrder("+$i+",$frmSelectFields.MouseMoved) $frmSelectFields.MouseMoved=0"
      $aCheckBox[$i].Text = IIf($dRColumn.Item($a1[$i]) And $Resolve,$dRColumn.Item($a1[$i]),$a1[$i])
      $aCheckBox[$i].Name = "c"+$i
   Next
   $j = Ubound($a1)
   For $i = 0 to Ubound($a2)
      If AScan($a1,$a2[$i])=-1
         $j=$j+1
         $aOrder[$j] = $j
         $aCheckBox[$j] = $gbSelectFields.CheckBox
         $aCheckBox[$j].Cursor = 16
         $aCheckBox[$j].TextAlign = 16
         $aCheckBox[$j].Size = 170, 20
         $aCheckBox[$j].Top = $j*$aCheckBox[$j].Height
         $aCheckBox[$j].OnKeyDown = "KeyPressed("+$j+",$aCheckBox["+$j+"].KeyCode)"
         $aCheckBox[$j].OnMouseDown = "$frmSelectFields.Y = $aCheckBox["+$j+"].MouseY"
         $aCheckBox[$j].OnMouseMove = "MouseMove("+$j+")"
         $aCheckBox[$j].OnMouseUp = "ReOrder("+$j+",$frmSelectFields.MouseMoved) $frmSelectFields.MouseMoved=0"
         $aCheckBox[$j].Text = IIf($dRColumn.Item($a2[$i]) And $Resolve,$dRColumn.Item($a2[$i]),$a2[$i])
         $aCheckBox[$j].Name = "c"+$j
      EndIf
   Next
   $frmSelectFields.aCheckBox = $aCheckBox
   $frmSelectFields.aOrder = $aOrder
   $Form.EndUpdate
   $frmSelectFields.Center
   $frmSelectFields.Show

   While $frmSelectFields.Visible And $Form.Visible
      $=Execute($System.DoEvents)
   Loop
   $aOrder = $frmSelectFields.aOrder
   
   $j = 0
   For $i = 0 to Ubound($aOrder)
      If $frmSelectFields.Controls("c"+$aOrder[$i]).Checked=0
         ReDim Preserve $a3[$j]
         $a3[$j]=IIf($dQColumn.Item($frmSelectFields.Controls("c"+$aOrder[$i]).Text) And $Resolve,$dQColumn.Item($frmSelectFields.Controls("c"+$aOrder[$i]).Text),$frmSelectFields.Controls("c"+$aOrder[$i]).Text)
         $j=$j+1
      EndIf
   Next
   If DifferentArrays($a1,$a3)
      If $YesNoBox.Show("Do you wish to accept the new field changes?","Fields Changed")=6
         $SelectFields=$a3
      Else
         $SelectFields=$a1
      EndIf
   Else
      $SelectFields=$a1
   EndIf
   
EndFunction

Function KeyPressed($i,$KeyCode)

   Dim $frmSelectFields,$gbSelectFields,$aCheckBox,$Reorder,$Scroll
   $frmSelectFields=$System.ActiveForm
   If $frmSelectFields.name = "frmSelectFields"
      $frmSelectFields.BeginUpdate
      $gbSelectFields = $frmSelectFields.Controls("gbSelectFields")
      $aCheckBox = $frmSelectFields.aCheckBox
      If $KeyCode = 40
         If $i < Ubound($aCheckBox)
            $aCheckBox[$i].Top = $aCheckBox[$i].Top + 10
            $Reorder = 1
         EndIf
      Else
         If $KeyCode = 38 And $i
            $aCheckBox[$i].Top = $aCheckBox[$i].Top - 10
            $Reorder = 1
         EndIf
      EndIf
      If $Reorder
         If $aCheckBox[$i].Top < 0
            $sbSelectFields.Value = $sbSelectFields.Value -1 + $aCheckBox[$i].Top / 20
            $aCheckBox[$i].Top = 0
            $Scroll = 1
         Else
            If $aCheckBox[$i].Top > $gbSelectFields.Height - 20
               $sbSelectFields.Value = $sbSelectFields.Value + 1 + ($aCheckBox[$i].Top - $gbSelectFields.ClientHeight) / 20
               $aCheckBox[$i].Top = $gbSelectFields.Height - 20
               $Scroll = 1
            EndIf
         EndIf
         Reorder($i,1)
         If $Scroll
            ScrollSelectFields
         EndIf
      EndIf
      $frmSelectFields.EndUpdate
   EndIf

EndFunction

Function ScrollSelectFields

   Dim $i, $frmSelectFields, $aOrder
   $frmSelectFields = $System.ActiveForm
   If $frmSelectFields.Name = "frmSelectFields"
      $aOrder = $frmSelectFields.aOrder
      $frmSelectFields.BeginUpdate
      For $i = 0 to Ubound($aOrder)
         $frmSelectFields.Controls("c"+$aOrder[$i]).Top = ($i-$sbSelectFields.value) * 20
      Next
      $sbSelectFields.Top = 0
      $frmSelectFields.EndUpdate
   EndIf

EndFunction

Function MouseMove($i)

   Dim $frmSelectFields,$gbSelectFields,$aCheckBox,$Y,$Scroll
   $frmSelectFields=$System.ActiveForm
   $gbSelectFields=$frmSelectFields.Controls("gbSelectFields")
   If $frmSelectFields.name = "frmSelectFields"
      $aCheckBox = $frmSelectFields.aCheckBox
      If $aCheckBox[$i].MouseButton = 1
         If $gbSelectFields.MouseY < 0
            $sbSelectFields.Value = $sbSelectFields.Value -1 + $gbSelectFields.MouseY / 20
            $Scroll = 1
         Else
            If $gbSelectFields.MouseY > $gbSelectFields.Height
               $sbSelectFields.Value = $sbSelectFields.Value + 1 + ($gbSelectFields.MouseY - $gbSelectFields.ClientHeight) / 20
               $Scroll = 1
            EndIf
         EndIf
         $Y = $aCheckBox[$i].Top - $gbSelectFields.MouseY + $frmSelectFields.Y
         If Abs($Y) => 20
            $frmSelectFields.BeginUpdate
            $aCheckBox[$i].Top  = $aCheckBox[$i].Top - ($Y/20)*20
            If $aCheckBox[$i].Top < 0
               $aCheckBox[$i].Top = 0
            Else
               If $aCheckBox[$i].Top > $gbSelectFields.Height - 20
                  $aCheckBox[$i].Top = $gbSelectFields.Height - 20
               EndIf
            EndIf
            $frmSelectFields.EndUpdate
            $frmSelectFields.MouseMoved=1
            ReOrder($i)
            $Scroll = 1
         EndIf
         If $Scroll ScrollSelectFields EndIf
      EndIf
   EndIf

EndFunction

Function ReOrder($i,Optional $Moved)

   Dim $frmSelectFields,$aCheckBox,$aOrder,$OldPos,$NewPos,$Step,$h,$j
   $frmSelectFields = $System.ActiveForm
   $frmSelectFields.Controls("c"+$aOrder[$i]).Top = ($i-1-$sbSelectFields.value) * 20
   $aCheckBox = $frmSelectFields.aCheckBox
   $aOrder = $frmSelectFields.aOrder
   $OldPos=AScan($aOrder,Cint(Right($aCheckBox[$i].Name,-1)))
   $NewPos=($aCheckBox[$i].Top/20)+$sbSelectFields.value
   If $NewPos < 0 $NewPos = 0 EndIf
   If $NewPos > Ubound($aOrder) $NewPos = Ubound($aOrder) EndIf
   $Step=IIf($NewPos-$OldPos > 0,1,-1)
   $frmSelectFields.BeginUpdate
   If $NewPos<>$OldPos
      For $j = $OldPos to $NewPos-$Step Step $Step
         $aOrder[$j] = $aOrder[$j+$Step]
         $h = $aOrder[$j]
         $aCheckBox[$h].Top = ($j-$sbSelectFields.value) * 20
      Next
      $aOrder[$NewPos]=$i
   EndIf
   If $Moved = 1
      $aCheckBox[$i].Checked = 0
      If $NewPos
         $h = $aOrder[$NewPos-1]
         If $aCheckBox[$h].Checked
            $aCheckBox[$i].Checked = -1
         EndIf
      EndIf
      If    $NewPos < Ubound($aCheckBox)
         $h = $aOrder[$NewPos+1]
         If $aCheckBox[$h].Checked
            $aCheckBox[$i].Checked = -1
         EndIf
      EndIf
   EndIf
   $frmSelectFields.EndUpdate
   $frmSelectFields.aCheckBox=$aCheckBox
   $frmSelectFields.aOrder=$aOrder

EndFunction

Function ResizeSelectFieldsForm($i)

   Dim $frmSelectFields,$gbSelectFields
   $frmSelectFields = $System.ActiveForm
   If $frmSelectFields.Name = "frmSelectFields"
      $gbSelectFields = $frmSelectFields.Controls("gbSelectFields")
      $frmSelectFields.Width = 194
      If $frmSelectFields.ClientHeight > 52+$i*20
         $frmSelectFields.ClientHeight = 52+$i*20
      Else
         $frmSelectFields.ClientHeight = 52+20*($gbSelectFields.ClientHeight/20)
         $sbSelectFields.Maximum = $i-($gbSelectFields.ClientHeight/20)
      EndIf
      $sbSelectFields.Height = $gbSelectFields.ClientHeight
      $frmSelectFields.Refresh
   EndIf

EndFunction

Function TickFields($i,$Untick)

   Dim $frmSelectFields,$j
   $frmSelectfields = $System.ActiveForm
   For $j = $Untick to $i
      $frmSelectFields.Controls("gbSelectFields").Controls("c"+$j).Checked = $Untick -1
   Next

EndFunction

Function DifferentArrays($a1,$a2)

   If Ubound($a1) <> Ubound($a2)
      $DifferentArrays = 1
      Exit
   EndIf
   Dim $i
   For $i = 0 to Ubound($a1)
      If $a1[$i] <> $a2[$i]
         $DifferentArrays = 1
         Exit
      EndIf
   Next       

EndFunction

Function AddDictionaries

   Global $dQColumn,$dRColumn
   $dQColumn = CreateObject("Scripting.Dictionary")
   $dQColumn.CompareMode=1
   $dQColumn.Add("Machine Name","MachineName")
   $dQColumn.Add("Serial Number","SerialNumber")
   $dQColumn.Add("Asset Number","AssetNumber")
   $dQColumn.Add("BST","BST")
   $dQColumn.Add("Classification","Classification")
   $dQColumn.Add("Comment","Comment")
   $dQColumn.Add("Date Updated","UpdateTime")
   $dQColumn.Add("Division","Division")
   $dQColumn.Add("Financial Status","FinancialStatus")
   $dQColumn.Add("Lease Contract Number","LeaseContractNumber")
   $dQColumn.Add("Location","Location")
   $dQColumn.Add("Purchase Order Number","PurchaseOrderNumber")
   $dQColumn.Add("Role","Role")
   $dQColumn.Add("Site","Site")
   $dQColumn.Add("Status","Status")
   $dQColumn.Add("Total Value","TotalValue")
   $dQColumn.Add("Vendor Invoice Number","VendorInvoiceNumber")
   $dQColumn.Add("Vendor Quote Number","VendorQuoteNumber")
   $dQColumn.Add("Dependencies","Dependencies")
   $dQColumn.Add("DNS Domain","DNSDomain")
   $dQColumn.Add("Manufacturer","Manufacturer")
   $dQColumn.Add("Model","Model")
   $dQColumn.Add("OS Family","OSFamily")
   $dQColumn.Add("Service Pack","ServicePack")
   $dQColumn.Add("Unique ID","UniqueID")
   $dQColumn.Add("Laptop (0/1)","Laptop")
   $dQColumn.Add("Date First Added","FirstAdded")
   $dQColumn.Add("Date Updated","UpdateTime")
   $dQColumn.Add("Date of Delivery","DeliveryDate")
   $dQColumn.Add("Date of Return","ReturnDate")
   $dQColumn.Add("Discovered (0/1)","Discovered")
   $dQColumn.Add("Lease Period (years)","LeasePeriod")
   $dQColumn.Add("Operating System","OS")
   $dQColumn.Add("Organisational Unit","OU")
   $dQColumn.Add("Domain","WinDomain")
   $dQColumn.Add("BIOS Version","BIOS")
   $dQColumn.Add("Last User (User ID)","LastUserID")
   $dQColumn.Add("Last User (Full Name)","LastUserName")
   $dQColumn.Add("Last Logged On User",)
   $dQColumn.Add("CPU Architecture","CpuArchitecture")
   $dQColumn.Add("CPU Name","CpuName")
   $dQColumn.Add("CPU Speed (MHz)","CpuSpeed")
   $dQColumn.Add("CPU (Number of CPU's)","NumberOfCpus")
   $dQColumn.Add("CPU (Cores/CPU)","CoresPerCPU")
   $dQColumn.Add("CPU (Threads/Core)","ThreadsPerCore")
   $dQColumn.Add("Memory Size (MB)","Memory")
   $dQColumn.Add("Memory Speed (MHz)","Speed")
   $dRColumn = CreateObject("Scripting.Dictionary")
   $dRColumn.CompareMode=1
   Dim $Key
   For Each $Key in $dQColumn
      $dRColumn.Add($dQColumn.Item($Key),$Key)
   Next

EndFunction
Back to top
View user's profile Send private message
benny69
KiXforms Advocate
KiXforms Advocate


Joined: 30 Oct 2003
Posts: 567
Location: Lincoln, Ne

PostPosted: Mon Jun 05, 2006 11:53 am    Post subject: Reply with quote

Oh, Very Nice, I like the control Drag-N-Drop your MouseMove() function is nicely done.

thanks for sharing.

_________________
Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta)
Back to top
View user's profile Send private message Send e-mail
It Took My Prozac
KiXforms Supporter
KiXforms Supporter


Joined: 15 Feb 2005
Posts: 65

PostPosted: Mon Jun 05, 2006 11:15 pm    Post subject: Reply with quote

Thanks, I really can't explain why it didn't occur to me to use checkboxes instead of toolbuttons; thanks for pointing me in the right direction. Nod
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    KiXforms Forum Index -> Script Archive All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group