Combobox item (i.e. some username) should map to (i.e. should return) ID on clicking Add button - winforms

Right now the text written in combobox (i.e.ID) onclick adds the same text as
$b = New-Object System.Windows.Forms.ComboBox
$b.DropDownStyle = [System.Windows.Forms.ComboBoxStyle]::Simple
$a = New-Object System.Windows.Forms.Button
$a.add_click({
if(-not $b.Items.contains($b.Text)) {
$b.Items.Add($b.Text)
}
$b.Text = ''
$b.Focus()
})
I'm using .NET binding to populate the data i.e. .dll file.
If I write username in the combobox, it should map to the ID and on add_click button the ID should be returned.
Please let me know if you need more information on this or to know what all things I tried.

Related

Powershell Register WPF events

I'm trying to build a WPF gui where i have two radiobutton listboxes.
A button loads the radio buttons:
function mybuttonclick {
$List = get-content "list.txt"
foreach ($item in $list) {
$tmpradio = New-Object System.Windows.Controls.RadioButton
$tmpradio.content = "$item"
$tmpradio.groupname = "MyList"
Register-ObjectEvent -InputObject $tmpradio -EventName Checked -Action { write-host "test"}
$MyListbox.AddChild($tmpradio)
}
}
However i'm getting nothing back, is it a scope issue where the object gets deleted after exiting from the function?
Is there a solution to make so i can pick an action or another wheter the groupname is "MyList" or for example "MyOtherList"
Looks like i will once more answer my own question..
It honestly is as simple as i tought it would...
Jim Moyle explained it, i adapted to my situation..
function mybuttonclick {
$List = get-content "list.txt"
foreach ($item in $list) {
$tmpradio = New-Object System.Windows.Controls.RadioButton
$tmpradio.content = "$item"
$tmpradio.groupname = "MyList"
[System.Windows.RoutedEventHandler]$checkhandler = {write-host 'Test'}
$tmpradio.AddHandler([System.Windows.Controls.RadioButton]::CheckedEvent, $checkhandler)
$MyListbox.AddChild($tmpradio)
}
}
To make it simple i just create my radio button as usual,
then i create a handler scriptblock, which is just code executed on x event triggered.
At last i add that handler to my radiobutton on the CheckedEvent.
I could find the event name by opening up a debugger, type down this:
[System.Windows.Controls.RadioButton]::
and then start tabbing for autocompletion
Source: https://www.youtube.com/watch?v=s6A9KuEM324

Modx Resource List as checkbox for users

Please help, I am stuck with Modx Revo tv input type options.
What I want to achieve is have a checkbox type tv, that displays the resources of a particular parent as checkbox items. So when user checks an item or two, they will be outputted as comma separated values.
Than I will put my tv in a getresources call on the template and it will output some information form the checked resources.
So how do I convert resource list into checkbox options?
The documentation on this is very ambiguous.
Accomplishing this requires some work, but it is not very difficult.
First, create a new Template Variable. Name it whatever you want, for example list_children. Then go to Input Options tab and set Input Type to Checkbox and under Input Option Values enter the following:
#eval return $modx->runSnippet('list_children');
Go to the Output Options tab and select Delimiter in the Output Type dropdown. In the Delimiter textbox write a single comma ,. Apply the Template Variable to your Template of choice and save.
New, create a new Snippet. Name this list_children, or whatever you changed the eval expression to call.
In this snippet, fill in the following:
<?php
$c = $modx->newQuery('modResource');
$c->where(array(
'parent' => 2, // Id to fetch children from
'published' => 1, // Remove this line if you also want to include unpublished resources
'deleted' => 0 // Remove this line if you also want resources that are marked for deletion
));
$c->sortby('menuindex', 'ASC');
$collection = $modx->getCollection('modResource', $c);
$output = array();
foreach ($collection as $v) {
$output[] = $v->get('pagetitle') . '==' . $v->get('id');
}
return implode('||', $output);
I found an alternative way.
Make TV with Input Type Checkbox.
Put #SELECT pagetitle, id FROM modx_site_content WHERE parent=123
!Attn. pay attention on modx_site_content, it needs to reflect MySQL db prefix, which in this case is modx, change 123 to respective parent id.
Change TV output type to Delimiter and coma (,) as delimiter.
Set TV access to respective templates.
Now you can select any or many children of a parent resource which will output their ids as TV output. E.g. let's say our parent 123 had children 33, 34 and 35. In Template variable sections of the resource using the template with access to tv, you will find a checkbox list with children titles. Selecting one or more, e.g. 33 and 35 will output "33,35" in the tv used in chunk.
I found the solution in Modx forums. Lost the link unfortunately.

How to get the text from webpage using coded ui

I am new for coded ui and I have got stuck for processing message display on webpage. As we used to get text from web page in selenium using method getText(), is such kind of possibility are available in coded ui.?
I would appreciate your help!!!!
Thanks,
Dani
updated - 5/14/2014
script code:
public void FPInternetExplorer()
{
#region Variable Declarations
HtmlEdit uIUserNameEdit = this.UIFundingPilotPortalWiWindow.UIFundingPilotPortalDocument.UIUserNameEdit;
HtmlEdit uIPasswordEdit = this.UIFundingPilotPortalWiWindow.UIFundingPilotPortalDocument.UIPasswordEdit;
HtmlInputButton uILoginButton = this.UIFundingPilotPortalWiWindow.UIFundingPilotPortalDocument.UILoginButton;
HtmlEdit uISecurityQuestionAnswEdit = this.UIFundingPilotPortalWiWindow.UIFundingPilotPortalDocument.UISecurityQuestionAnswEdit;
HtmlInputButton uIValidateButton = this.UIFundingPilotPortalWiWindow.UIFundingPilotPortalDocument.UIValidateButton;
#endregion
this.UIInternetExplorerEnhaWindow6.LaunchUrl(new System.Uri(this.FPInternetExplorerParams.UIInternetExplorerEnhaWindow6Url));
// Type 'test#test.test' in 'User Name' text box
uIUserNameEdit.Text = this.FPInternetExplorerParams.UIUserNameEditText;
// Type '{Tab}' in 'User Name' text box
Keyboard.SendKeys(uIUserNameEdit, this.FPInternetExplorerParams.UIUserNameEditSendKeys, ModifierKeys.None);
// Type '********' in 'Password' text box
uIPasswordEdit.Password = this.FPInternetExplorerParams.UIPasswordEditPassword;
// Click 'Login' button
Mouse.Click(uILoginButton, new Point(62, 19));
//Code to get the text from div tag. This is the code I have added
HtmlDiv testLabel = new HtmlDiv();
testLabel.SearchProperties[HtmlDiv.PropertyNames.Id] = "SecurityQuestion_AnswerText";
string myText = testLabel.InnerText;
Console.Write("myText " + myText);
// Type 'Computer' in 'SecurityQuestion.AnswerText' text box
uISecurityQuestionAnswEdit.Text = this.FPInternetExplorerParams.UISecurityQuestionAnswEditText;
// Type '{Tab}' in 'SecurityQuestion.AnswerText' text box
Keyboard.SendKeys(uISecurityQuestionAnswEdit, this.FPInternetExplorerParams.UISecurityQuestionAnswEditSendKeys, ModifierKeys.None);
// Click 'Validate' button
Mouse.Click(uIValidateButton, new Point(81, 25));
}
// When run this code using coded UI, system gives exception: Message - 'To test Windows Store apps, use the Coded UI Test project template for Windows Store apps under the Windows Store node.' Is something missing in this code? Would appreciate if you could provide link to configure missing component
The property you're looking for is "InnerText". So, for example, on a hyperlink like:
HtmlHyperlink target = new HtmlHyperlink();
target.SearchProperties[<search property>] = <value>;
string myText = target.InnerText;
You can extrapolate this to just read all of the text on the page by selecting the outer container of the page and getting the InnerText of it, then parse through the string for what you want, but I've found it a lot simpler if you work in the most focused object.

Zend Form: Get array element in view script

I want to display a title and a content field for each language. So, in the form, I have:
foreach ($languages as $language)
{
// Add the title element
$title = new Zend_Form_Element_Text($language);
$title->setLabel($translate->_('News Title'))
->setBelongsTo('title');
$this->addElement($title);
// Add the content element
$content = new Zend_Form_Element_Textarea($language);
$content->setLabel($translate->_('News Content'))
->setBelongsTo('content');
$this->addElement($content);
}
If I render the form in the usual way it works perfectly:
echo $this->form;
However, I want to render each field separately to include some HTML in the middle and other jQuery stuff. My problem is that I cannot manage to access those elements. I tried
foreach ($languages as $language)
{
$this->form->getElement($language);
}
but it only renders 'content' element. Am I overriding 'title' element?
Thanks
Yes, you're overriding the Title element. The parameter you pass to new Zend_Form_Element_Text($language); ($language in your case) should be unique. Infact you can use it to identify and retrieve the element when you need.
To setup the param you can do something like this:
foreach ($languages as $language)
{
// Add the title element
$title = new Zend_Form_Element_Text('title-' . $language);
...
}

LDAP group membership (including Domain Users)

How can I get a list of users within an LDAP group, even if that group happens to be the primary group for some users?
For example, suppose "Domain Users" is "Domain Leute" in German. I want all members of "CN=Domain Leute,DC=mycompany,DC=com". How would I know that is the well-known "Domain Users" group?
Or what if some users' primary group was changed to "CN=rebels,DC=mycompany,DC=com", and I wanted to get members of THAT group? Users don't have a memberOf property for their primary group, and the primary group won't have a member property listing them.
This is what I see when viewed via LDAP (ie, no MS extensions):
To get the the primaryGroupToken from any given group extract it from the objectSid so for example Domain Users objectSid = S-1-5-21-704657944-2065781323-617630493-513 then the primaryGroupToken is the last digits after the "-" so in the case of the "Domain Users" its 513
You need to find out primaryGroupToken from the Group object first. If you are using ADSIEdit, you need to make sure you have "Constructed" filter on to see this calculated attribute. For Domain Users, the primaryGroupToken should be 513.
Then, you neeed to find all the users with primaryGroupID set to this value. Here is the ldap query you should write to find out all users with Domain Users set as the primary group.
(&(objectCategory=person)(objectClass=user)(primaryGroupID=513))
EDIT
Here is the steps to show primaryGroupToken in LDAP Browser. I am using LDAP browser 2.6 build 650. Right click your profile and click properties
Go to LDAP Settings tab and click Advanced button.
Add an extra operational attribute primaryGroupToken
Click Apply button and close the properties page. Now, you should see the primaryGroupToken in your group object.
This is a PS script that I made to do exactly that:
[void][System.Reflection.Assembly]::LoadWithPartialName("System.DirectoryServices");
$groupName = "Grupo Domain";
$directoryEntry = New-Object System.DirectoryServices.DirectoryEntry;
$directorySearcher = New-Object System.DirectoryServices.DirectorySearcher($directoryEntry, "(&(objectClass=group)(CN=$groupName))");
[void]$directorySearcher.PropertiesToLoad.Add("objectSid");
[void]$directorySearcher.PropertiesToLoad.Add("member");
$result = $directorySearcher.FindOne();
if ($result -eq $null) { return; }
# Try get the group members through the "member" property.
if ($result.Properties["member"].Count -gt 0) {
foreach ($member in $result.Properties["member"]) {
$memberSearcher = New-Object System.DirectoryServices.DirectorySearcher($directoryEntry, "(&(objectClass=*)(distinguishedName=$member))");
[void]$memberSearcher.PropertiesToLoad.Add("msDS-PrincipalName");
$memberResult = $memberSearcher.FindOne();
if ($memberResult -eq $null) { continue; }
Write-Output $memberResult.Properties["msDS-PrincipalName"];
}
return;
}
if ($result.Properties["objectSid"].Count -gt 0) {
# The group might be an AD primary group. Try get the members by the PrimaryGroupID.
$groupSid = New-Object System.Security.Principal.SecurityIdentifier($result.Properties["objectSid"][0], 0);
# Hacky way to get only the last RID.
$primaryGroupSid = $groupSid.Value.Replace($groupSid.AccountDomainSid.ToString(), [String]::Empty).TrimStart('-');
$memberSearcher = New-Object System.DirectoryServices.DirectorySearcher($directoryEntry, "(&(objectClass=*)(primaryGroupId=$primaryGroupSid))");
[void]$memberSearcher.PropertiesToLoad.Add("msDS-PrincipalName");
$memberResult = $memberSearcher.FindAll();
if ($memberResult -eq $null) { continue; }
foreach ($member in $memberResult) {
Write-Output $member.Properties["msDS-PrincipalName"];
}
}

Resources