Passing multiple variables to parameter - arrays

Syntax:
New-VirtualSwitch [-VMHost] [-Name] [[-NumPorts] ] [[-Nic] String[]]
I am using the above cmdlet to add a new vSwitch in vSphere, where my knowledge lacks is how to use four checkbox that represent four NICs and when checked are passed to the -Nic parameter.
For instance the below wouldn't work
New-VirtualSwitch -VMHost $comboBox611.SelectedItem.toString() -Name $textBox611.Text -NumPorts 200 **-Nic $nic0,$nic1,$nic2,$nic3** -Mtu $textBox612.Text -Confirm
How do I pass the variables of each checkbox to a string array as the syntax shows it can be done?
$handler_linkLabel601_LinkClicked=
{
if ($networkdataGridView.CurrentRow.Cells['VM Host'].Value.toString() -gt " ")
{
Add-Type -AssemblyName System.Windows.Forms
$form601 = New-Object Windows.Forms.Form
$form601.Size = New-Object Drawing.Size (250,270)
$form601.StartPosition = "CenterScreen"
$label611.Size = New-Object Drawing.Size (70,40)
$label611.Location = New-Object System.Drawing.Size (10,15)
$label611.Text = "vSwitch Name:"
$textBox611.Size = New-Object Drawing.Size (100,30)
$textBox611.Location = New-Object System.Drawing.Size (90,15)
$textBox611.Name = "vSwitch Name"
$label612.Size = New-Object Drawing.Size (50,20)
$label612.Location = New-Object System.Drawing.Size (10,55)
$label612.Text = "Host:"
$vmhostlist = Get-VMHost
foreach ($vmhost in $vmhostlist)
{
$comboBox611.Items.add($vmhost.name.toString())
}
$comboBox611.Size = New-Object Drawing.Size (100,20)
$comboBox611.Location = New-Object System.Drawing.Size (90,50)
$checkBox611.Size = New-Object Drawing.Size (20,20)
$checkBox611.Location = New-Object System.Drawing.Size (100,80)
# Add Click-Event
$checkBox611.Add_CheckStateChanged({
If ($checkBox611.Checked) {
$global:nic0 = "vmnic0"
} Else {
$global:nic0 = ""
}
})
$checkBox612.Size = New-Object Drawing.Size (20,20)
$checkBox612.Location = New-Object System.Drawing.Size (170,80)
$checkBox611.Add_CheckStateChanged({
If ($checkBox611.Checked) {
$global:nic1 = "vmnic1"
} Else {
$global:nic1 = ""
}
})
$checkBox613.Size = New-Object Drawing.Size (20,20)
$checkBox613.Location = New-Object System.Drawing.Size (100,100)
$checkBox611.Add_CheckStateChanged({
If ($checkBox611.Checked) {
$global:nic2 = "vmnic2"
} Else {
$global:nic2 = ""
}
})
$checkBox614.Size = New-Object Drawing.Size (20,20)
$checkBox614.Location = New-Object System.Drawing.Size (170,100)
$checkBox611.Add_CheckStateChanged({
If ($checkBox611.Checked) {
$global:nic3 = "vmnic3"
} Else {
$global:nic3 = ""
}
})
$label613.Size = New-Object Drawing.Size (80,20)
$label613.Location = New-Object System.Drawing.Size (10,140)
$label613.Text = "MTU Size:"
$textBox612.Size = New-Object Drawing.Size (100,20)
$textBox612.Location = New-Object System.Drawing.Size (90,140)
$textBox612.Name = "MTU"
$button = New-Object System.Windows.Forms.Button
$button.Size = New-Object Drawing.Size (90,30)
$button.Location = New-Object System.Drawing.Size (70,200)
$selectedvmhost = ($comboBox611.SelectedItem.toString())
$button.add_click({test})
$button.Text = "Add New vSwitch"
$form601.Controls.Add($button)
$form601.Controls.Add($textBox611)
$form601.Controls.Add($textBox612)
$form601.Controls.Add($label611)
$form601.Controls.Add($label612)
$form601.Controls.Add($label613)
$form601.Controls.Add($comboBox611)
$form601.Controls.Add($checkBox611)
$form601.Controls.Add($checkBox612)
$form601.Controls.Add($checkBox613)
$form601.Controls.Add($checkBox614)
$form601.ShowDialog()
}
ELSE
{}
}
function test
{
$nic = #($global:nic0,$global:nic1,$global:nic2,$global:nic3 | ? {-not [string]::IsNullOrEmpty($_)})
if ( $nic.count )
{
New-VirtualSwitch -VMHost $comboBox611.SelectedItem.toString() -Name $textBox611.Text -NumPorts 200 -Nic $nic -Mtu $textBox612.Text -Confirm
}
}

just as C.B. said replace $nic0 with $global:nic0, and $nic1 with $global:nic1 etc.
then test is
function test
{
$nic = #($global:nic0,$global:nic1,$global:nic2,$global:nic3 | ? {-not [string]::IsNullOrEmpty($_)})
if ( $nic.count )
{
New-VirtualSwitch -VMHost $comboBox611.SelectedItem.toString() -Name $textBox611.Text -NumPorts 200 -Nic $nic -Mtu $textBox612.Text -Confirm
}
}

Related

When changing templates on custom block the content gets deleted from the DB

I have a custom block for Concrete5 I built which uses multiple template files associated with it. If I apply the template to the block when I am initially adding the block to the page everything works fine. However if I then try to change templates after the block has already been set I run into issues. When saving changes with the new template, all my content gets deleted from the DB; so everything in that current row equals null except the block id "bID", the bID will change to the next increment.
I do not know why this happens!! I feel like I ran into a similar a long time ago but don't remember how it was resolved. Any advice would be great!
My template files are just standard html in a php file with the <?php defined('C5_EXECUTE') or die("Access Denied."); ?> at the top of the file.
My controller (which is my suspect for the issue right now) look like this:
<?php
namespace Concrete\Package\ThemeCaboodle\Block\GridBlock;
use Concrete\Core\Block\BlockController;
use Database;
use Page;
use Concrete\Core\Editor\LinkAbstractor;
use Core;
use File;
use View;
use BlockType;
class Controller extends BlockController
{
public $defaultBlockClassList = '';
public $defaultEntriesClassList = 'unit-md-4';
protected $btTable = 'btGrid';
protected $btExportTables = array('btGrid', 'btGridEntries');
protected $btInterfaceWidth = "600";
protected $btWrapperClass = 'ccm-ui';
protected $btInterfaceHeight = "550";
protected $btCacheBlockRecord = true;
protected $btExportFileColumns = array('thumbnailFID');
protected $btCacheBlockOutput = true;
protected $btCacheBlockOutputOnPost = true;
protected $btCacheBlockOutputForRegisteredUsers = false;
protected $btIgnorePageThemeGridFrameworkContainer = true;
public function getBlockTypeDescription()
{
return t("Easily add a grid with prebuilt templates to your site using the grid block");
}
public function getBlockTypeName()
{
return t("Grid");
}
public function getFileObject($fID) {
return File::getByID($fID);
}
public function getSearchableContent()
{
$db = Database::get();
$rows = $db->Execute('SELECT * FROM btGridEntries WHERE bID = ?', array($this->bID));
$content = '';
foreach ($rows as $row) {
$content .= $row['title'].' ';
$content .= $row['description'].' ';
}
return $content;
}
public function view()
{
$this->set('entries', $this->getEntries());
$this->set('block', $this->getBlockData());
$this->addHeaderItem('<link rel="stylesheet" type="text/css" href="//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"/>');
}
public function add()
{
$this->requireAsset('core/file-manager');
$this->requireAsset('core/sitemap');
$this->requireAsset('redactor');
}
public function edit()
{
$this->requireAsset('core/file-manager');
$this->requireAsset('core/sitemap');
$this->requireAsset('redactor');
$this->set('entries', $this->getEntries());
$this->set('block', $this->getBlockData());
}
public function composer()
{
$this->edit();
}
public function registerViewAssets($outputContent = '')
{
$al = \Concrete\Core\Asset\AssetList::getInstance();
$this->requireAsset('javascript', 'jquery');
}
public function duplicate($newBID)
{
parent::duplicate($newBID);
$db = Database::get();
$rows = $db->Execute('SELECT * FROM btGridEntries WHERE bID = ?', array($this->bID));
while ($row = $rows->FetchRow()) {
$db->execute('INSERT INTO btGridEntries (bID, thumbnailFID, fallbackFID, title, description, classList, buttonText, sortOrder, externalLinkURL, internalLinkCID, fileFID) values(?,?,?,?,?,?,?,?,?,?,?)',
array(
$newBID,
$row['ENTRY_thumbnailFID'],
$row['ENTRY_fallbackFID'],
$row['ENTRY_title'],
$row['ENTRY_description'],
$row['ENTRY_classList'],
$row['ENTRY_buttonText'],
$row['ENTRY_sortOrder'],
$row['ENTRY_externalLinkURL'],
$row['ENTRY_internalLinkCID'],
$row['ENTRY_fileFID']
)
);
}
}
public function delete()
{
$db = Database::get();
$db->delete('btGridEntries', array('bID' => $this->bID));
parent::delete();
}
public function save($args)
{
$db = Database::get();
$db->execute('DELETE from btGridEntries WHERE bID = ?', array($this->bID));
parent::save($args);
if (isset($args['ENTRY_sortOrder'])) {
$count = count($args['ENTRY_sortOrder']);
$i = 0;
while ($i < $count) {
$externalLinkURL = $args['ENTRY_externalLinkURL'][$i];
$internalLinkCID = $args['ENTRY_internalLinkCID'][$i];
$fileFID = $args['ENTRY_fileFID'][$i];
switch (intval($args['ENTRY_linkType'][$i])) {
case 1:
$externalLinkURL = '';
$fileFID = 0;
break;
case 2:
$internalLinkCID = 0;
$fileFID = 0;
break;
case 3:
$externalLinkURL = '';
$internalLinkCID = 0;
break;
default:
$externalLinkURL = '';
$internalLinkCID = 0;
$fileFID = 0;
break;
}
if (isset($args['ENTRY_description'][$i])) {
$args['ENTRY_description'][$i] = LinkAbstractor::translateTo($args['ENTRY_description'][$i]);
}
$db->execute('INSERT INTO btGridEntries (bID, thumbnailFID, fallbackFID, title, description, classList, buttonText, sortOrder, externalLinkURL, internalLinkCID, fileFID) values(?,?,?,?,?,?,?,?,?,?,?)',
array(
$this->bID,
intval($args['ENTRY_thumbnailFID'][$i]),
intval($args['ENTRY_fallbackFID'][$i]),
$args['ENTRY_title'][$i],
$args['ENTRY_description'][$i],
$args['ENTRY_classList'][$i],
$args['ENTRY_buttonText'][$i],
$args['ENTRY_sortOrder'][$i],
$externalLinkURL,
$internalLinkCID,
$fileFID
)
);
++$i;
}
}
}
public function getBlockAssetPath() {
$bt = BlockType::getByHandle('buckets_block');
return Core::make('helper/concrete/urls')->getBlockTypeAssetsURL($bt);
}
public function getBlockData()
{
$db = Database::get();
$row = $db->GetRow('SELECT * FROM btGrid WHERE bID = ?', array($this->bID));
if ($row['bgFID']) {
$row['BG'] = \File::getByID($row['bgFID'])->getVersion()->getRelativePath();
}
return $row;
}
public function getEntries()
{
$v = View::getInstance();
$db = Database::get();
$rows = $db->GetAll('SELECT * FROM btGridEntries WHERE bID = ? ORDER BY sortOrder', array($this->bID));
// in view mode, linkURL takes us to where we need to go whether it's on our site or elsewhere
$entries = array();
foreach ($rows as $row) {
// Generate the URL based on what the linkType is
if ($row['externalLinkURL'] =='' && !$row['fileFID'] && $row['internalLinkCID']) {
$c = Page::getByID($row['internalLinkCID'], 'ACTIVE');
$row['linkURL'] = $c->getCollectionLink();
} elseif ($row['externalLinkURL'] =='' && !$row['internalLinkCID'] && $row['fileFID']) {
$f = File::getByID($row['fileFID']);
$row['linkURL'] = $f ? $f->getVersion()->getRelativePath() : '';
} elseif ($row['externalLinkURL']!='') {
$row['linkURL'] = $row['externalLinkURL'];
} else {
$row['linkURL'] = '';
}
// Thumbnail
$thumbnail = $row['thumbnailFID'] ? File::getByID($row['thumbnailFID'])->getVersion()->getRelativePath() : $v->getThemePath().'/no-image.jpg';
$row['thumbnail'] = $thumbnail;
$fallback = $row['fallbackFID'] ? File::getByID($row['fallbackFID'])->getVersion()->getRelativePath() : $v->getThemePath().'/no-image.jpg';
$row['fallback'] = $fallback;
$row['description'] = LinkAbstractor::translateFrom($row['description']);
$entries[] = $row;
}
return $entries;
}
public function getClassList($string) {
$array = explode(',',$string);
if (count($array) > 0) {
return implode(' ',$array);
}
}
}
I apologize for the pretty long file in advance ;) i just want to make sure you can see all possible issues
I think your problem is that in the duplicate function, once you got your results back from your select you put an ENTRY_ prefix everywhere like in $row['ENTRY_thumbnailFID'] when it should really be $row['thumbnailFID'] according to your screenshot

Get minimum value in an array and then get index

I want to get the minimum value in an array and then get the index of that item, in one step without writing my own loop (if I have to please let me know).
I know I can just do the
$b = ($a | Measure -Minimum).Minimum
But then I have to do
[array]::IndexOf($a, $b)
And while that is normally okay, I'm looking for a way to do it once because I'm running this MANY MANY times in a loop.
Thanks!
EDIT: One step meaning without looping through the array twice
Personally, I might consider a different data structure. Maybe something sorted to begin with...
This code may work for your needs:
$myArray = 5,66,4,33,2,9,9,12
$index = 0
$minIndex = 0
$minValue = [int]::MaxValue
$myArray | % { if ($minValue -gt $_) {$minValue = $_; $minIndex = $index}; $index++ }
"MinIndex $minIndex = MinValue $minValue"
its a problem of type, try like this:
$myArray = [int[]]5,66,4,33,2,9,9,12
$minvalue=[int]($myArray | measure -Minimum).Minimum
$myArray.IndexOf($minvalue)
Here are 6 different options for you...
cls
$myArray = #(5,66,4,33,2,9,9,12)
$iterations = 50000
$t = (measure-command{
foreach ($i in 1..$iterations) {
$minValue = [int]($myArray | Measure-Object -Minimum).Minimum
$minIndex = $myArray.IndexOf($minValue)
}
}).TotalSeconds
"measure-object with indexOf: $t"
$t = (measure-command{
foreach ($i in 1..$iterations) {
$index = 0
$minIndex = 0
$minValue = [int]::MaxValue
$myArray | % { if ($minValue -gt $_) {$minValue = $_; $minIndex = $index}; $index++ }
}
}).TotalSeconds
"pipeline with compare: $t"
$t = (measure-command{
foreach ($i in 1..$iterations) {
$minIndex = 0
$minValue = [int]::MaxValue
foreach ($index in 0..($myArray.count-1)) {
if ($myArray[$index] -lt $minValue) {
$minValue = $myArray[$index]
$minIndex = $index
}
}
}
}).TotalSeconds
"foreach-loop with compare: $t"
$t = (measure-command{
foreach ($i in 1..$iterations) {
$h = [System.Collections.ArrayList]::new()
foreach ($index in 0..($myArray.count-1)) {
$null = $h.add([tuple]::Create($myArray[$index], $index))
}
$h.Sort()
$minIndex = $h[0].Item2
}
}).TotalSeconds
"quicksort of a list of tuples: $t"
Add-Type -TypeDefinition #"
using System;
using System.Linq;
public static class My {
public static int indexOfMin(int[] arr){
int min = arr.Min();
return Array.IndexOf(arr, min);
}
}
"#
$t = (measure-command{
foreach ($i in 1..$iterations) {
$minIndex = [my]::indexOfMin($myArray)
}
}).TotalSeconds
"custom type and IndexOf: $t"
Add-Type #"
public static int[] indexOfMin(int[] arr){
int min = int.MaxValue;
int minIndex = 0;
for (int i = 0; i < arr.Length; i++) {
if (arr[i]<min) {
min = arr[i];
minIndex = i;
}
}
return new int[] {min, minIndex};
}
"# -name My2 -Namespace System
$t = (measure-command{
foreach ($i in 1..$iterations) {
$minValue, $minIndex = [my2]::indexOfMin($myArray)
}
}).TotalSeconds
"custom type and looping: $t"

Powershell refresh CheckBox array from ComboBox

With Powershell, I have a form with several tabs.
In the third tab, I make an array of numbers picked from Windows registry that I'll put in a ComboBox.
Then I make automatically several CheckBox by registry value names depending the ComboBox.
My problem is that I can't refresh/update the CheckBox when I change the text of the ComboBox. I tried ".Refresh()" like below and other things, but it doesn't work.
Here are my registry keys:
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\SOFTWARE\MySoftware]
[HKEY_CURRENT_USER\SOFTWARE\MySoftware\Folder]
[HKEY_CURRENT_USER\SOFTWARE\MySoftware\Folder\SubFolder]
"ValueName1"=""
"ValueName2"=""
"ValueName4"=""
"ValueName5"=""
"ValueName6"=""
"ValueName8"=""
"ValueName9"=""
"ValueName10"=""
"ValueName11"=""
[HKEY_CURRENT_USER\SOFTWARE\MySoftware\Folder1]
[HKEY_CURRENT_USER\SOFTWARE\MySoftware\Folder1\SubFolder]
"ValueName1"=""
"ValueName2"=""
"ValueName6"=""
"ValueName7"=""
"ValueName8"=""
"ValueName9"=""
"ValueName11"=""
[HKEY_CURRENT_USER\SOFTWARE\MySoftware\Folder10]
[HKEY_CURRENT_USER\SOFTWARE\MySoftware\Folder10\SubFolder]
"ValueName1"=""
"ValueName2"=""
"ValueName6"=""
"ValueName7"=""
"ValueName8"=""
"ValueName9"=""
"ValueName10"=""
"ValueName11"=""
[HKEY_CURRENT_USER\SOFTWARE\MySoftware\Folder2]
[HKEY_CURRENT_USER\SOFTWARE\MySoftware\Folder2\SubFolder]
[HKEY_CURRENT_USER\SOFTWARE\MySoftware\Folder3]
[HKEY_CURRENT_USER\SOFTWARE\MySoftware\Folder3\SubFolder]
"ValueName1"=""
"ValueName2"=""
"ValueName3"=""
"ValueName5"=""
"ValueName6"=""
"ValueName7"=""
"ValueName9"=""
"ValueName10"=""
[HKEY_CURRENT_USER\SOFTWARE\MySoftware\Folder4]
[HKEY_CURRENT_USER\SOFTWARE\MySoftware\Folder4\SubFolder]
"ValueName1"=""
"ValueName2"=""
"ValueName4"=""
"ValueName5"=""
"ValueName6"=""
"ValueName7"=""
"ValueName10"=""
"ValueName11"=""
[HKEY_CURRENT_USER\SOFTWARE\MySoftware\Folder5]
[HKEY_CURRENT_USER\SOFTWARE\MySoftware\Folder5\SubFolder]
"ValueName1"=""
"ValueName4"=""
"ValueName5"=""
"ValueName6"=""
"ValueName8"=""
"ValueName9"=""
"ValueName10"=""
[HKEY_CURRENT_USER\SOFTWARE\MySoftware\Folder6]
[HKEY_CURRENT_USER\SOFTWARE\MySoftware\Folder6\SubFolder]
"ValueName1"=""
"ValueName2"=""
"ValueName5"=""
"ValueName6"=""
"ValueName7"=""
"ValueName9"=""
"ValueName11"=""
[HKEY_CURRENT_USER\SOFTWARE\MySoftware\Folder7]
[HKEY_CURRENT_USER\SOFTWARE\MySoftware\Folder7\SubFolder]
"ValueName1"=""
"ValueName2"=""
"ValueName5"=""
"ValueName6"=""
"ValueName7"=""
"ValueName10"=""
"ValueName11"=""
[HKEY_CURRENT_USER\SOFTWARE\MySoftware\Folder8]
[HKEY_CURRENT_USER\SOFTWARE\MySoftware\Folder8\SubFolder]
"ValueName1"=""
"ValueName2"=""
"ValueName3"=""
"ValueName4"=""
"ValueName7"=""
"ValueName8"=""
"ValueName9"=""
"ValueName11"=""
[HKEY_CURRENT_USER\SOFTWARE\MySoftware\Folder9]
[HKEY_CURRENT_USER\SOFTWARE\MySoftware\Folder9\SubFolder]
"ValueName1"=""
"ValueName5"=""
"ValueName6"=""
"ValueName10"=""
"ValueName11"=""
And here is my script:
function GenerateForm {
[reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null
[reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null
$form1 = New-Object System.Windows.Forms.Form
$tabControl = New-Object System.Windows.Forms.tabControl
$ToolTip = New-Object System.Windows.Forms.ToolTip
$ToolTip.BackColor = [System.Drawing.Color]::LightGoldenrodYellow
$ToolTip.IsBalloon = $true
$Tab1 = New-Object System.Windows.Forms.TabPage
$Tab2 = New-Object System.Windows.Forms.TabPage
$tabTab3 = New-Object System.Windows.Forms.TabPage
$labelDossierTab3 = New-Object System.Windows.Forms.Label
$ComboTab3 = New-Object System.Windows.Forms.ComboBox
$checkBoxAllTab3 = New-Object System.Windows.Forms.Button
$checkBoxNothingTab3 = New-Object System.Windows.Forms.Button
$ActiveTab3 = New-Object System.Windows.Forms.CheckBox
$GenerateButtonTab3 = New-Object System.Windows.Forms.Button
$CloseButton = New-Object System.Windows.Forms.Button
$fontDialog1 = New-Object System.Windows.Forms.FontDialog
$InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
$CloseButton_OnClick=
{
$form1.Close()
}
$OnLoadForm_StateCorrection=
{
$form1.WindowState = $InitialFormWindowState
}
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 464
$System_Drawing_Size.Width = 704
$form1.ClientSize = $System_Drawing_Size
$form1.DataBindings.DefaultDataSourceUpdateMode = 0
$form1.Name = "form1"
$form1.Text = "Task generator"
$form1.StartPosition = "CenterScreen"
$form1.CancelButton = $CloseButton
$tabControl.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 136
$System_Drawing_Point.Y = 83
$tabControl.Location = $System_Drawing_Point
$tabControl.Name = "tabControl"
$tabControl.SelectedIndex = 0
$tabControl.ShowToolTips = $True
$tabControl.Multiline = $True
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 320
$System_Drawing_Size.Width = 453
$tabControl.Size = $System_Drawing_Size
$tabControl.TabIndex = 4
$form1.Controls.Add($tabControl)
$Tab1.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 4
$System_Drawing_Point.Y = 22
$Tab1.Location = $System_Drawing_Point
$Tab1.Name = "Tab1"
$System_Windows_Forms_Padding = New-Object System.Windows.Forms.Padding
$System_Windows_Forms_Padding.All = 3
$System_Windows_Forms_Padding.Bottom = 3
$System_Windows_Forms_Padding.Left = 3
$System_Windows_Forms_Padding.Right = 3
$System_Windows_Forms_Padding.Top = 3
$Tab1.Padding = $System_Windows_Forms_Padding
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 274
$System_Drawing_Size.Width = 445
$Tab1.Size = $System_Drawing_Size
$Tab1.TabIndex = 0
$Tab1.Text = "Tab1"
$Tab1.UseVisualStyleBackColor = $True
$tabControl.Controls.Add($Tab1)
$Tab2.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 4
$System_Drawing_Point.Y = 22
$Tab2.Location = $System_Drawing_Point
$Tab2.Name = "Tab2"
$System_Windows_Forms_Padding = New-Object System.Windows.Forms.Padding
$System_Windows_Forms_Padding.All = 3
$System_Windows_Forms_Padding.Bottom = 3
$System_Windows_Forms_Padding.Left = 3
$System_Windows_Forms_Padding.Right = 3
$System_Windows_Forms_Padding.Top = 3
$Tab2.Padding = $System_Windows_Forms_Padding
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 274
$System_Drawing_Size.Width = 445
$Tab2.Size = $System_Drawing_Size
$Tab2.TabIndex = 4
$Tab2.Text = "Tab2"
$Tab2.UseVisualStyleBackColor = $True
$tabControl.Controls.Add($Tab2)
$tabTab3.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 4
$System_Drawing_Point.Y = 22
$tabTab3.Location = $System_Drawing_Point
$tabTab3.Name = "tabTab3"
$System_Windows_Forms_Padding = New-Object System.Windows.Forms.Padding
$System_Windows_Forms_Padding.All = 3
$System_Windows_Forms_Padding.Bottom = 3
$System_Windows_Forms_Padding.Left = 3
$System_Windows_Forms_Padding.Right = 3
$System_Windows_Forms_Padding.Top = 3
$tabTab3.Padding = $System_Windows_Forms_Padding
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 274
$System_Drawing_Size.Width = 445
$tabTab3.Size = $System_Drawing_Size
$tabTab3.TabIndex = 4
$tabTab3.Text = "Tab3"
$tabTab3.UseVisualStyleBackColor = $True
$tabControl.Controls.Add($tabTab3)
$labelDossierTab3.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 340
$System_Drawing_Point.Y = 6
$labelDossierTab3.Location = $System_Drawing_Point
$labelDossierTab3.Name = "labeTab3"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 40
$System_Drawing_Size.Width = 50
$labelDossierTab3.Size = $System_Drawing_Size
$labelDossierTab3.TabIndex = 2
$labelDossierTab3.Text = "Option :"
$tabTab3.Controls.Add($labelDossierTab3)
$ComboTab3.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 390
$System_Drawing_Point.Y = 3
$ComboTab3.Location = $System_Drawing_Point
$ComboTab3.Name = "labeTab3"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 40
$System_Drawing_Size.Width = 45
$ComboTab3.Size = $System_Drawing_Size
$ComboTab3.TabIndex = 3
$ComboTab3.BeginUpdate()
$Dossierslist = Get-ChildItem "HKCU:\Software\MySoftware\" | Where-Object {$_ -match "Folder."} | Foreach-object {$_ -replace 'HKEY_CURRENT_USER\\Software\\MySoftware\\Folder', ''}
foreach($Dossier in $Dossierslist){$ComboTab3.Items.Add($Dossier) | sort}
$ComboTab3.EndUpdate()
$ComboTab3.SelectedIndex = 0
$ComboTab3.add_TextChanged({
$tabTab3.Refresh()
})
$tabTab3.Controls.Add($ComboTab3)
$CleDossier = "HKCU:\Software\MySoftware\Folder"+($ComboTab3.text)+"\"
$Baseslist = #()
$Baseslist += Get-ChildItem $CleDossier | Where-Object {$_.Name -match "SubFolder"}
$Baseslist += Get-ChildItem "HKCU:\Software\MySoftware\Folder\" | Where-Object {$_.Name -match "SubFolder"}
$CheckBoxLabelsC = $Baseslist.Property -match "'ValueName1'|ValueName3|ValueName5|ValueName7|ValueName9|ValueName11" | sort | Select -Unique
$CheckBoxCounterC = 1
$CheckBoxesC = foreach($LabelC in $CheckBoxLabelsC) {
$CheckBoxC = New-Object System.Windows.Forms.CheckBox
$CheckBoxC.DataBindings.DefaultDataSourceUpdateMode = 0
$CheckBoxC.UseVisualStyleBackColor = $True
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 130
$System_Drawing_Size.Height = 20
$CheckBoxC.Size = $System_Drawing_Size
$CheckBoxC.TabIndex = 2
$CheckBoxC.Text = $LabelC
$System_Drawing_Point = New-Object System.Drawing.Point
if($CheckBoxCounterC -lt 7){
$System_Drawing_Point.X = 130}
elseif($CheckBoxCounterC -ge 7){
$System_Drawing_Point.X = 300}
if($CheckBoxCounterC -lt 7){
$System_Drawing_Point.Y = 75 + (($CheckBoxCounterC - 1) * 20)}
elseif(($CheckBoxCounterC -ge 7) -AND ($CheckBoxCounterC -lt 17)){
$System_Drawing_Point.Y = - 45 + (($CheckBoxCounterC - 1) * 20)}
$CheckBoxC.Location = $System_Drawing_Point
$CheckBoxC.Name = "CheckBoxC$CheckBoxCounterC"
$CheckBoxC.Add_CheckStateChanged({
foreach($CheckBoxC in $CheckBoxesC | Where-Object {$_.checked -eq $false}) {
$GenerateButtonTab3.Enabled = $false}
})
$CheckBoxC.Add_CheckStateChanged({
foreach($CheckBoxC in $CheckBoxesC | Where-Object {$_.checked -eq $true}) {
$GenerateButtonTab3.Enabled = $true}
})
$tabTab3.Controls.Add($CheckBoxC)
$CheckBoxC
$CheckBoxCounterC++
}
$checkBoxAllTab3.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 17
$System_Drawing_Point.Y = 55
$checkBoxAllTab3.Location = $System_Drawing_Point
$checkBoxAllTab3.Name = "checkBoxAllTab3"
$checkBoxAllTab3.Text = "All"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 20
$System_Drawing_Size.Width = 60
$checkBoxAllTab3.Size = $System_Drawing_Size
$checkBoxAllTab3.TabIndex = 0
$checkBoxAllTab3.Add_Click({
foreach($CheckBoxC in $CheckBoxesC) {
$CheckBoxC.Checked = $true}
})
$tabTab3.Controls.Add($checkBoxAllTab3)
$checkBoxNothingTab3.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 17
$System_Drawing_Point.Y = 85
$checkBoxNothingTab3.Location = $System_Drawing_Point
$checkBoxNothingTab3.Name = "checkBoxNothingTab3"
$checkBoxNothingTab3.Text = "Nothing"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 20
$System_Drawing_Size.Width = 60
$checkBoxNothingTab3.Size = $System_Drawing_Size
$checkBoxNothingTab3.TabIndex = 0
$checkBoxNothingTab3.Add_Click({
foreach($CheckBoxC in $CheckBoxesC) {
$CheckBoxC.Checked = $false}
})
$tabTab3.Controls.Add($checkBoxNothingTab3)
$ActiveTab3.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 320
$System_Drawing_Point.Y = 240
$ActiveTab3.Location = $System_Drawing_Point
$ActiveTab3.Name = "ActiveTab3"
$ActiveTab3.Text = "Desactivate"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 30
$System_Drawing_Size.Width = 123
$ActiveTab3.Size = $System_Drawing_Size
$ActiveTab3.TabIndex = 12
$ToolTip.SetToolTip($ActiveTab3, "The task will be desactivated. You'll have to activate it by yourself")
$tabTab3.Controls.Add($ActiveTab3)
$handler_GenerateButtonTab3_Click=
{
}
$GenerateButtonTab3.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 147
$System_Drawing_Point.Y = 244
$GenerateButtonTab3.Location = $System_Drawing_Point
$GenerateButtonTab3.Name = "GenerateButtonTab3"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 23
$System_Drawing_Size.Width = 150
$GenerateButtonTab3.Size = $System_Drawing_Size
$GenerateButtonTab3.TabIndex = 0
$GenerateButtonTab3.Text = "Generate"
$GenerateButtonTab3.Enabled = $false
$GenerateButtonTab3.UseVisualStyleBackColor = $True
$GenerateButtonTab3.add_Click($handler_GenerateButtonTab3_Click)
$tabTab3.Controls.Add($GenerateButtonTab3)
$CloseButton.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 475
$System_Drawing_Point.Y = 420
$CloseButton.Location = $System_Drawing_Point
$CloseButton.Name = "CloseButton"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 23
$System_Drawing_Size.Width = 75
$CloseButton.Size = $System_Drawing_Size
$CloseButton.TabIndex = 6
$CloseButton.Text = "Close"
$CloseButton.UseVisualStyleBackColor = $True
$CloseButton.add_Click($CloseButton_OnClick)
$form1.Controls.Add($CloseButton)
$fontDialog1.ShowHelp = $True
$InitialFormWindowState = $form1.WindowState
$form1.add_Load($OnLoadForm_StateCorrection)
$form1.ShowDialog()| Out-Null
}
GenerateForm
Thanks for your help!
I don't think you're subscribing to the right event.
Have you looked at SelectedIndexChanged?
This will fire when a selection has changed and then you can look at the ComboBox's Index property to figure out which item changed. An index of negative one means no item in the combobox is selected.
The click event has nothing to do with selected items in a combobox.

Multiple database- access data from the 3rd database using codeigniter

I am using codeigniter.I want to use 3 database in my project.I set the database.php file us,
$active_group = 'default';
$active_record = TRUE;
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'marketer_fp';
$db['default']['password'] = 'xxxxx';
$db['default']['database'] = 'marketer_fpr';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
$db['wpdb']['hostname'] = "localhost";
$db['wpdb']['username'] = "marketer_fprr";
$db['wpdb']['password'] = "yyyy";
$db['wpdb']['database'] = "marketer_mark";
$db['wpdb']['dbdriver'] = "mysql";
$db['wpdb']['dbprefix'] = "";
$db['wpdb']['pconnect'] = FALSE;
$db['wpdb']['db_debug'] = TRUE;
$db['wpdb']['cache_on'] = FALSE;
$db['wpdb']['cachedir'] = "";
$db['wpdb']['char_set'] = "utf8";
$db['wpdb']['dbcollat'] = "utf8_general_ci";
$db['wpfashn']['hostname'] = "localhost";
$db['wpfashn']['username'] = "marketer_fprr";
$db['wpfashn']['password'] = "yyyy";
$db['wpfashn']['database'] = "marketer_fah";
$db['wpfashn']['dbdriver'] = "mysql";
$db['wpfashn']['dbprefix'] = "";
$db['wpfashn']['pconnect'] = FALSE;
$db['wpfashn']['db_debug'] = TRUE;
$db['wpfashn']['cache_on'] = FALSE;
$db['wpfashn']['cachedir'] = "";
$db['wpfashn']['char_set'] = "utf8";
$db['wpfashn']['dbcollat'] = "utf8_general_ci";
The second and third database have same username and password.
In the controller ,inside construct function these 3 database are called.
$this->db3 =$this->load->database('wpfashn', TRUE);
$this->db2 =$this->load->database('wpdb', TRUE);
$this->db =$this->load->database('default', TRUE);
Inside another function a query is written,which should be executed by using the database 3.
$check=$this->db3->query("select * from mm_use_dat where wp_user_id='2'");
print_r($check->result());
this query return an empty array even if value present in the database.What should be the problem?Please help me to find a solution!

How can I display the max value array, edited in a class

I need to find the worker with highest salary in PHP and display only him (his name, position and salary). Made several tries in the IF statement but none of them lead to what i needed.
class Workers {
public $name;
public $position;
public $salary;
private function Workers($name, $position, $salary){
$this->name = $name;
$this->position = $position;
$this->salary = $salary;
}
public function newWorker($name, $position, $salary){
// if ( ) {
return new Workers($name, $position, $salary);
// }
// else return NULL;
}
}
$arr = array();
$arr[] = Workers::newWorker("Peter", "work1", 600);
$arr[] = Workers::newWorker("John", "work2", 700);
$arr[] = Workers::newWorker("Hans", "work3", 550);
$arr[] = Workers::newWorker("Maria", "work4", 900);
$arr[] = Workers::newWorker("Jim", "work5", 1000);
print_r($arr);
This is my code and like that it will display all workers i have created but i need to output only the one with highest salary (worker 5 - Jim with 1000 salary)
You can use this snippet:
$max = null;
foreach ($arr as $worker) {
$max = $max === null ? $worker : ($worker->salary > $max->salary ? $worker : $max);
}
Or this, as more clarity:
$max = null;
foreach ($arr as $worker) {
if (!$max) {
$max = $worker;
} elseif ($worker->salary > $max->salary) {
$max = $worker;
}
}
$max now contains a worker with maximum salary.

Resources