在文本框中写消息,并在 try catch on if
Write message in text box with try catch on if
我希望在文本框中显示一条消息。选中的框表示 文件夹复制到另一个目录。我希望在文本框中显示一条消息,具体取决于复制的文件夹是成功还是失败(错误示例:如果文件夹不存在)。那时,我已经尝试使用 TRY CATCH,但是,我无法弄清楚将我的东西放在哪里,所以它不会删除以前的消息或重复的消息。请注意,您最多可以选中 6 个复选框。所以最后我应该有 6 条消息。
查看底部的 Tab1BTNcreation。谢谢!
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass
Add-Type -AssemblyName PresentationCore, PresentationFramework
[xml]$xaml = @"
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Programme de tests QA" Height="515" Width="828" ResizeMode="NoResize">
<Grid>
<TabControl HorizontalAlignment="Left" Height="500" VerticalAlignment="Top" Width="825">
<TabControl.Resources>
<Style TargetType="TabItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="TabItem">
<Border Name="Border" BorderThickness="0,0,0,0" CornerRadius="5,5,0,0" Margin="2,0">
<ContentPresenter x:Name="Tab1"
VerticalAlignment="Center"
HorizontalAlignment="Center"
ContentSource="Header"
Margin="10,2"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter TargetName="Border" Property="Background" Value="#292929" />
</Trigger>
<Trigger Property="IsSelected" Value="False">
<Setter TargetName="Border" Property="Background" Value="#FF23BBB8" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</TabControl.Resources>
<TabItem x:Name="tab1" Header="CR`ÉATION" Height="40" Width="273" Background="#292929" FontFamily="Segoe UI Semibold" Foreground="white" IsSelected="True">
<Grid Background="#292929" Width="840" Height="455" Margin="-7,1,-14,-4">
<Label x:Name="titre1" Content="cr`éation d'une nouvelle serie" FontFamily="Segoe UI" FontSize="20" Foreground="#797979" HorizontalAlignment="Left" Height="47" Margin="49,47,0,0" VerticalAlignment="Top" Width="723"/>
<Line X1="55" X2="440" Y1="99" Y2="99" Stroke="#5f5f5f" StrokeThickness="1"></Line>
<Line X1="55" X2="440" Y1="200" Y2="200" Stroke="#5f5f5f" StrokeThickness="1"></Line>
<Line X1="480" X2="770" Y1="99" Y2="99" Stroke="#5f5f5f" StrokeThickness="1"></Line>
<Line X1="480" X2="770" Y1="200" Y2="200" Stroke="#5f5f5f" StrokeThickness="1"></Line>
<TextBlock HorizontalAlignment="Left" Height="21" Margin="60,121,0,0" TextWrapping="Wrap" Text="de" VerticalAlignment="Top" Width="36" Foreground="#797979"/>
<TextBlock HorizontalAlignment="Left" Height="21" Margin="60,161,0,0" TextWrapping="Wrap" Text="vers" VerticalAlignment="Top" Width="36" Foreground="#797979"/>
<ComboBox x:Name="CBBdeRep1" HorizontalAlignment="Left" Height="20" Margin="107,120,0,0" VerticalAlignment="Top" Width="103" BorderBrush="#FF23BBB8" BorderThickness="0" FontSize="10" Foreground="#797979"/>
<ComboBox x:Name="CBBdeSerie1" HorizontalAlignment="Left" Height="20" Margin="227,120,0,0" VerticalAlignment="Top" Width="211" BorderBrush="#FF23BBB8" BorderThickness="0" FontSize="10" Foreground="#797979"/>
<ComboBox x:Name="CBBversRep1" HorizontalAlignment="Left" Height="20" Margin="107,159,0,0" VerticalAlignment="Top" Width="103" BorderBrush="#FF23BBB8" BorderThickness="0" FontSize="10" Foreground="#797979"/>
<TextBox x:Name="TBversSerie1" HorizontalAlignment="Left" Height="20" Margin="227,159,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="211" Padding="2" MaxLength="33" FontSize="10" Foreground="#797979" />
<Grid x:Name="CheckBoxGroup1">
<CheckBox x:Name="CBbin1" Content=" bin" HorizontalAlignment="Left" Height="19" Margin="480,118,0,0" VerticalAlignment="Top" Width="92" Foreground="#797979"/>
<CheckBox x:Name="CBexport1" Content=" export" HorizontalAlignment="Left" Height="19" Margin="480,142,0,0" VerticalAlignment="Top" Width="92" Foreground="#797979"/>
<CheckBox x:Name="CBparam1" Content=" param" HorizontalAlignment="Left" Height="19" Margin="480,166,0,0" VerticalAlignment="Top" Width="92" Foreground="#797979"/>
<CheckBox x:Name="CBlist1" Content=" list" HorizontalAlignment="Left" Height="19" Margin="600,118,0,0" VerticalAlignment="Top" Width="92" Foreground="#797979"/>
<CheckBox x:Name="CBscript1" Content=" script" HorizontalAlignment="Left" Height="19" Margin="600,142,0,0" VerticalAlignment="Top" Width="92" Foreground="#797979"/>
<CheckBox x:Name="CBtemplate1" Content=" template" HorizontalAlignment="Left" Height="19" Margin="600,166,0,0" VerticalAlignment="Top" Width="92" Foreground="#797979"/>
</Grid>
<Button x:Name="BTNcreation" Content="cr`éer la s`érie et synchroniser" FontSize="15" HorizontalAlignment="Left" Height="48" Margin="480,335,0,0" VerticalAlignment="Top" Foreground="white" Background="#FF23BBB8" Width="290"/>
<TextBox x:Name="TBmessages1" HorizontalAlignment="Left" Height="145" Margin="55,238,0,0" TextWrapping="Wrap" VerticalScrollBarVisibility="Visible" Text="Affichage des messages d'erreurs." Foreground="#797979" Padding="6" FontSize="10" VerticalAlignment="Top" Width="383"/>
</Grid>
</TabItem>
<TabItem x:Name="tab2" Header="SYNCHRONISATION" Background="#FF00565F" Height="40" Width="273" BorderBrush="#FF00565F" FontSize="12" Foreground="White" FontFamily="Segoe UI Semibold">
<Grid Background="#292929" Width="840" Height="455" Margin="-7,1,-14,-4">
<Label Content="synchronisation d'une s`érie" FontFamily="Segoe UI" FontSize="20" Foreground="#797979" HorizontalAlignment="Left" Height="47" Margin="49,47,0,0" VerticalAlignment="Top" Width="723"/>
<Line X1="55" X2="440" Y1="200" Y2="200" Stroke="#5f5f5f" StrokeThickness="1"></Line>
<Line X1="55" X2="440" Y1="99" Y2="99" Stroke="#5f5f5f" StrokeThickness="1"></Line>
<Line X1="480" X2="770" Y1="99" Y2="99" Stroke="#5f5f5f" StrokeThickness="1"></Line>
<Line X1="480" X2="770" Y1="200" Y2="200" Stroke="#5f5f5f" StrokeThickness="1"></Line>
<TextBlock HorizontalAlignment="Left" Height="21" Margin="60,121,0,0" TextWrapping="Wrap" Text="de" VerticalAlignment="Top" Width="36" Foreground="#797979"/>
<TextBlock HorizontalAlignment="Left" Height="21" Margin="60,161,0,0" TextWrapping="Wrap" Text="vers" VerticalAlignment="Top" Width="36" Foreground="#797979"/>
<ComboBox x:Name="CBBdeRep2" HorizontalAlignment="Left" Height="20" Margin="107,120,0,0" VerticalAlignment="Top" Width="103" FontSize="10" Foreground="#797979" />
<ComboBox x:Name="CBBdeSerie2" HorizontalAlignment="Left" Height="20" Margin="227,120,0,0" VerticalAlignment="Top" Width="211" FontSize="10" Foreground="#797979"/>
<ComboBox x:Name="CBBversRep2" HorizontalAlignment="Left" Height="20" Margin="107,159,0,0" VerticalAlignment="Top" Width="103" FontSize="10" Foreground="#797979" />
<ComboBox x:Name="CBBversSerie2" HorizontalAlignment="Left" Height="20" Margin="227,159,0,0" VerticalAlignment="Top" Width="211" FontSize="10" Foreground="#797979" />
<CheckBox x:Name="CBbin2" Content=" bin" HorizontalAlignment="Left" Height="19" Margin="480,118,0,0" VerticalAlignment="Top" Width="92" Foreground="#797979"/>
<CheckBox x:Name="CBexport2" Content=" export" HorizontalAlignment="Left" Height="19" Margin="480,142,0,0" VerticalAlignment="Top" Width="92" Foreground="#797979"/>
<CheckBox x:Name="CBparam2" Content=" param" HorizontalAlignment="Left" Height="19" Margin="480,166,0,0" VerticalAlignment="Top" Width="92" Foreground="#797979"/>
<CheckBox x:Name="CBlist2" Content=" list" HorizontalAlignment="Left" Height="19" Margin="600,118,0,0" VerticalAlignment="Top" Width="92" Foreground="#797979"/>
<CheckBox x:Name="CBscript2" Content=" script" HorizontalAlignment="Left" Height="19" Margin="600,142,0,0" VerticalAlignment="Top" Width="92" Foreground="#797979"/>
<CheckBox x:Name="CBtemplate2" Content=" template" HorizontalAlignment="Left" Height="19" Margin="600,166,0,0" VerticalAlignment="Top" Width="92" Foreground="#797979"/>
<TextBox x:Name="TBmessages2" HorizontalAlignment="Left" Height="145" Margin="55,238,0,0" TextWrapping="Wrap" VerticalScrollBarVisibility="Visible" Text="Affichage des messages d'erreurs." Foreground="#797979" Padding="6" FontSize="10" VerticalAlignment="Top" Width="383"/>
<Button x:Name="BTNsynchro" Content="synchroniser la s`érie" FontSize="15" HorizontalAlignment="Left" Height="48" Margin="480,335,0,0" VerticalAlignment="Top" Foreground="white" Background="#FF23BBB8" Width="290"/>
</Grid>
</TabItem>
<TabItem x:Name="tab3" Header="EX`ÉCUTION" Background="#FF00565F" Height="40" Width="273" BorderBrush="#FF00565F" FontSize="12" Foreground="white" FontFamily="Segoe UI Semibold">
<Grid Background="#292929" Width="840" Height="455" Margin="-7,1,-14,-4" >
<Label x:Name="titre3" Content="ex`écution des tests QA" FontFamily="Segoe UI" FontSize="20" Foreground="#797979" HorizontalAlignment="Left" Height="47" Margin="49,47,0,0" VerticalAlignment="Top" Width="723"/>
<Line X1="55" X2="335" Y1="99" Y2="99" Stroke="#5f5f5f" StrokeThickness="1"></Line>
<Line X1="55" X2="335" Y1="160" Y2="160" Stroke="#5f5f5f" StrokeThickness="1"></Line>
<Line X1="480" X2="770" Y1="99" Y2="99" Stroke="#5f5f5f" StrokeThickness="1"></Line>
<Line X1="480" X2="770" Y1="250" Y2="250" Stroke="#5f5f5f" StrokeThickness="1"></Line>
<Line X1="480" X2="770" Y1="200" Y2="200" Stroke="#5f5f5f" StrokeThickness="1"></Line>
<TextBlock HorizontalAlignment="Left" Height="21" Margin="54,121,0,0" TextWrapping="Wrap" Text="version" VerticalAlignment="Top" Width="55" Foreground="#797979"/>
<TextBlock HorizontalAlignment="Left" Height="21" Margin="482,121,0,0" TextWrapping="Wrap" Text="`équipe" VerticalAlignment="Top" Width="55" Foreground="#797979"/>
<TextBlock HorizontalAlignment="Left" Height="21" Margin="482,161,0,0" TextWrapping="Wrap" Text="liste" VerticalAlignment="Top" Width="36" Foreground="#797979"/>
<ComboBox x:Name="CBBversion3" HorizontalAlignment="Left" Height="20" Margin="113,120,0,0" VerticalAlignment="Top" Width="70" FontSize="10" Foreground="#797979" />
<TextBox x:Name="TBbuild3" HorizontalAlignment="Left" Height="20" Margin="201,120,0,0" TextWrapping="Wrap" Text="Build" VerticalAlignment="Top" Width="77" Padding="2" MaxLength="4" FontSize="10" Foreground="#797979" />
<TextBox x:Name="TBrevision3" HorizontalAlignment="Left" Height="20" Margin="297,120,0,0" TextWrapping="Wrap" Text="R`év." VerticalAlignment="Top" Width="36" Padding="2" MaxLength="3" FontSize="10" Foreground="#797979" />
<ComboBox x:Name="CBBequipe3" HorizontalAlignment="Left" Height="20" Margin="542,120,0,0" VerticalAlignment="Top" Width="150" BorderBrush="#FF23BBB8" BorderThickness="0" FontSize="10" Foreground="#797979"/>
<ComboBox x:Name="CBBliste3" HorizontalAlignment="Left" Height="20" Margin="542,159,0,0" VerticalAlignment="Top" Width="150" BorderBrush="#FF23BBB8" BorderThickness="0" FontSize="10" Foreground="#797979"/>
<CheckBox x:Name="CBrtf3" Content=" produire les fichiers en format .rtf" HorizontalAlignment="Left" Height="19" Margin="480,217,0,0" VerticalAlignment="Top" Width="230" Foreground="#797979"/>
<TextBox x:Name="TBmessages3" HorizontalAlignment="Left" Height="190" Margin="55,193,0,0" VerticalScrollBarVisibility="Visible" TextWrapping="Wrap" Text="Affichage des messages d'erreurs." Foreground="#797979" Padding="6" FontSize="10" VerticalAlignment="Top" Width="383"/>
<Button x:Name="BTNexecution" Content="lancer les tests" FontSize="15" HorizontalAlignment="Left" Height="48" Margin="480,335,0,0" VerticalAlignment="Top" Foreground="white" Background="#FF23BBB8" Width="290"/>
</Grid>
</TabItem>
</TabControl>
</Grid>
</Window>
"@
#Read XAML (Parse it)
$reader=(New-Object System.Xml.XmlNodeReader $XAML)
$Window=[Windows.Markup.XamlReader]::Load( $reader )
#region ----- xaml objects to variables -----
#Connect to Controls TAB2
$Tab1CBB1 = $Window.FindName('CBBdeRep1')
$Tab1CBB2 = $Window.FindName('CBBdeSerie1')
$Tab1CBB3 = $Window.FindName('CBBversRep1')
$Tab1TB4 = $Window.FindName('TBversSerie1')
$Tab1CBbin = $Window.FindName('CBbin1')
$Tab1CBexport = $Window.FindName('CBexport1')
$Tab1CBparam = $Window.FindName('CBparam1')
$Tab1CBlist = $Window.FindName('CBlist1')
$Tab1CBscript = $Window.FindName('CBscript1')
$Tab1CBtemplate = $Window.FindName('CBtemplate1')
$Tab1TBmessages = $Window.findName("TBmessages1")
$Tab1BTNcreation = $Window.findName("BTNcreation")
$Tab1CBGroup = $Window.findName("CheckBoxGroup1")
#Connect to Controls TAB2
$Tab2CBB1 = $Window.FindName('CBBdeRep2')
$Tab2CBB2 = $Window.FindName('CBBdeSerie2')
$Tab2CBB3 = $Window.FindName('CBBversRep2')
$Tab2CBB4 = $Window.FindName('CBBversSerie2')
$Tab2CBbin = $Window.FindName('CBbin2')
$Tab2CBexport = $Window.FindName('CBbin2')
$Tab2CBparam = $Window.FindName('CBparam2')
$Tab2CBlist = $Window.FindName('CBlist2')
$Tab2CBscript = $Window.FindName('CBscript2')
$Tab2CBtemplate = $Window.FindName('CBtemplate2')
$Tab2TBmessages = $Window.findName("TBmessages2")
$Tab2BTNsynchro = $Window.findName("BTNsyncro")
#Connect to Controls TAB2
$Tab3CBBversion = $Window.findName("CBBversion3")
$Tab3TBbuild = $Window.findName("TBbuild3")
$Tab3TBrev = $Window.findName("TBrevision3")
$Tab3CBBequipe = $Window.findName("CBBequipe3")
$Tab3CBBliste = $Window.findName("CBBliste3")
$Tab3CBrtf = $Window.findName("CBrtf3")
$Tab3TBmessages = $Window.findName("TBmessages3")
$Tab3BTNexecution = $Window.findName("BTNexecution")
#endregion
#region ---- Path variables -----
$pathDE='E:\Scripts\BibliothequePowershell\Melanie\GUI-ProgTestQA\Simulation\DE\'
$pathVERS='E:\Scripts\BibliothequePowershell\Melanie\GUI-ProgTestQA\Simulation\VERS\'
$pathDBQcust01='E:\Scripts\BibliothequePowershell\Melanie\GUI-ProgTestQA\Simulation\DE\DBQcust01\Sets\'
$pathQA14='E:\Scripts\BibliothequePowershell\Melanie\GUI-ProgTestQA\Simulation\DE\QA14\Sets\'
$pathQA15='E:\Scripts\BibliothequePowershell\Melanie\GUI-ProgTestQA\Simulation\DE\QA15\Sets\'
$pathSERIE = 'E:\Scripts\BibliothequePowershell\Melanie\GUI-ProgTestQA\Simulation\DE\QA14\Sets' #simulation
$pathSIMULATION = 'E:\Scripts\BibliothequePowershell\Melanie\GUI-ProgTestQA\Simulation'
#endregion ----
#region ---- lists of series ----
$listQA14 = Get-ChildItem $pathQA14 -Directory -Name
$listQA15 = Get-ChildItem $pathQA15 -Directory -Name
$listDBQcust01 = Get-ChildItem $pathDBQcust01 -Directory -Name
$FolderLists = Get-ChildItem $pathSIMULATION\Listes -Include *.txt -Name
#endregion
#------------- TAB1 ------------------
#region /// ComboBox 1 : DE folder
$FoldersCBB1 = @('--- choisir ---','DBQcust01','QA14','QA15')
$Tab1CBB1.SelectedItem = '--- choisir ---'
foreach ($Folder in $FoldersCBB1) {
$Tab1CBB1.Items.Add($Folder)
}
#endregion
#region /// ComboBox 2 : DE SERIE (éventuellement changer pour SWITCH)
$Tab1CBB1.add_SelectionChanged({
$Selection = ($Tab1CBB1.SelectedItem.ToString())
if ($Selection -eq 'QA14')
{
$Tab1CBB2.Items.Clear()
$Tab1CBB2.Items.Add('--- choisir une série sous QA14 ---')
$Tab1CBB2.SelectedItem = '--- choisir une série sous QA14 ---'
foreach ($Serie in $listQA14) {
$Tab1CBB2.Items.Add($Serie)
}
}
elseif ($Selection -eq 'QA15')
{
$Tab1CBB2.Items.Clear()
$Tab1CBB2.Items.Add('--- choisir une série sous QA15 ---')
$Tab1CBB2.SelectedItem = '--- choisir une série sous QA15 ---'
foreach ($Serie in $listQA15) {
$Tab1CBB2.Items.Add($Serie)
}
}
elseif ($Selection -eq 'DBQcust01')
{
$Tab1CBB2.Items.Clear()
$Tab1CBB2.Items.Add('--- choisir une série sous DBQcust01 ---')
$Tab1CBB2.SelectedItem = '--- choisir une série sous DBQcust01 ---'
foreach ($Serie in $listDBQcust01) {
$Tab1CBB2.Items.Add($Serie)
}
}
})
#endregion
#region /// ComboBox 3 : VERS folder
$FoldersCBB3 = @('SPMT','OTHER')
$Tab1CBB3.Items.Add('--- choisir ---')
$Tab1CBB3.SelectedItem = '--- choisir ---'
foreach ($Folder in $FoldersCBB3) {
$Tab1CBB3.Items.Add($Folder)
}
#endregion
#region /// TextBox 4 : VERS Série
#à venir (essayer de mettre le contenu des sélections des cbb automatiquement dans le textbox)
$Tab1TB4.text = "SÉRIE+ÉQUIPE"
#endregion
#region /// Bouton Creation
$Tab1BTNcreation.Add_Click({
$SelectionCBB1 = ($Tab1CBB1.SelectedValue)
$SelectionCBB2 = ($Tab1CBB2.SelectedValue)
$SelectionCBB3 = ($Tab1CBB3.SelectedValue)
$SelectionTB4 = ($Tab1TB4.Text)
$Tab1TBmessages.Clear()
New-item -ItemType Directory -Path "$pathVERS$SelectionCBB3" -Name "$SelectionTB4"
$ErrorActionPreference = "stop"
If ($Tab1CBbin.IsChecked -eq $true) {
try {copy-item -Path "$pathDE$SelectionCBB1\sets$SelectionCBB2\Bin2" -Recurse -Destination "$pathVERS$SelectionCBB3$SelectionTB4",$Tab1TBmessages.AddText("Dossier Bin : Copié `r`n")}
catch {$Tab1TBmessages.AddText("Dossier Bin : Non copié `r`n")}
}
If ($Tab1CBexport.IsChecked -eq $true) {
try {copy-item -Path "$pathDE$SelectionCBB1\sets$SelectionCBB2\Export" -Recurse -Destination "$pathVERS$SelectionCBB3$SelectionTB4", $Tab1TBmessages.AddText("Dossier Export : Copié `r`n") }
catch {$Tab1TBmessages.AddText("Dossier Export : Non copié `r`n")}
}
If ($Tab1CBlist.IsChecked -eq $true) { copy-item -Path "$pathDE$SelectionCBB1\sets$SelectionCBB2\List" -Recurse -Destination "$pathVERS$SelectionCBB3$SelectionTB4" }
If ($Tab1CBparam.IsChecked -eq $true) { copy-item -Path "$pathDE$SelectionCBB1\sets$SelectionCBB2\Param" -Recurse -Destination "$pathVERS$SelectionCBB3$SelectionTB4" }
If ($Tab1CBscript.IsChecked -eq $true) { copy-item -Path "$pathDE$SelectionCBB1\sets$SelectionCBB2\QA\Script" -Recurse -Destination "$pathVERS$SelectionCBB3$SelectionTB4\QA\Script" }
If ($Tab1CBtemplate.IsChecked -eq $true) { copy-item -Path "$pathDE$SelectionCBB1\sets$SelectionCBB2\Template" -Recurse -Destination "$pathVERS$SelectionCBB3$SelectionTB4" }
else{
}
})
#endregion
#------------- TAB2 ------------------
#------------- TAB3 ------------------
$Window.ShowDialog() | out-null
实际上,我在我的按钮中执行了此操作(并将继续用于我的所有 IF)。我刚刚复制了代码的末尾。
$Tab1BTNcreation.Add_Click({
$SelectionCBB1 = ($Tab1CBB1.SelectedValue)
$SelectionCBB2 = ($Tab1CBB2.SelectedValue)
$SelectionCBB3 = ($Tab1CBB3.SelectedValue)
$SelectionTB4 = ($Tab1TB4.Text)
$Tab1TBmessages.Clear()
$SelectedPathBin = "$pathDE$SelectionCBB1\sets$SelectionCBB2\Bin2"
$SelectedPathVers = "$pathVERS$SelectionCBB3$SelectionTB4"
New-item -ItemType Directory -Path "$pathVERS$SelectionCBB3" -Name "$SelectionTB4"
If ($Tab1CBbin.IsChecked -eq $true) {
$TestPath1 = Test-Path $SelectedPathBin
$TestPath2 = Test-Path $SelectedPathVers
If ($TestPath1 -eq $True -and $TestPath2 -eq $True) {
copy-item -Path $SelectedPathBin -Recurse -Destination $SelectedPathVers
$Tab1TBmessages.AddText("Dossier Bin : Copié`r`n")
}
else {$Tab1TBmessages.AddText("Dossier Bin : Non copié `r`n")
}
} (......)
我希望在文本框中显示一条消息。选中的框表示 文件夹复制到另一个目录。我希望在文本框中显示一条消息,具体取决于复制的文件夹是成功还是失败(错误示例:如果文件夹不存在)。那时,我已经尝试使用 TRY CATCH,但是,我无法弄清楚将我的东西放在哪里,所以它不会删除以前的消息或重复的消息。请注意,您最多可以选中 6 个复选框。所以最后我应该有 6 条消息。
查看底部的 Tab1BTNcreation。谢谢!
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass
Add-Type -AssemblyName PresentationCore, PresentationFramework
[xml]$xaml = @"
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Programme de tests QA" Height="515" Width="828" ResizeMode="NoResize">
<Grid>
<TabControl HorizontalAlignment="Left" Height="500" VerticalAlignment="Top" Width="825">
<TabControl.Resources>
<Style TargetType="TabItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="TabItem">
<Border Name="Border" BorderThickness="0,0,0,0" CornerRadius="5,5,0,0" Margin="2,0">
<ContentPresenter x:Name="Tab1"
VerticalAlignment="Center"
HorizontalAlignment="Center"
ContentSource="Header"
Margin="10,2"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter TargetName="Border" Property="Background" Value="#292929" />
</Trigger>
<Trigger Property="IsSelected" Value="False">
<Setter TargetName="Border" Property="Background" Value="#FF23BBB8" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</TabControl.Resources>
<TabItem x:Name="tab1" Header="CR`ÉATION" Height="40" Width="273" Background="#292929" FontFamily="Segoe UI Semibold" Foreground="white" IsSelected="True">
<Grid Background="#292929" Width="840" Height="455" Margin="-7,1,-14,-4">
<Label x:Name="titre1" Content="cr`éation d'une nouvelle serie" FontFamily="Segoe UI" FontSize="20" Foreground="#797979" HorizontalAlignment="Left" Height="47" Margin="49,47,0,0" VerticalAlignment="Top" Width="723"/>
<Line X1="55" X2="440" Y1="99" Y2="99" Stroke="#5f5f5f" StrokeThickness="1"></Line>
<Line X1="55" X2="440" Y1="200" Y2="200" Stroke="#5f5f5f" StrokeThickness="1"></Line>
<Line X1="480" X2="770" Y1="99" Y2="99" Stroke="#5f5f5f" StrokeThickness="1"></Line>
<Line X1="480" X2="770" Y1="200" Y2="200" Stroke="#5f5f5f" StrokeThickness="1"></Line>
<TextBlock HorizontalAlignment="Left" Height="21" Margin="60,121,0,0" TextWrapping="Wrap" Text="de" VerticalAlignment="Top" Width="36" Foreground="#797979"/>
<TextBlock HorizontalAlignment="Left" Height="21" Margin="60,161,0,0" TextWrapping="Wrap" Text="vers" VerticalAlignment="Top" Width="36" Foreground="#797979"/>
<ComboBox x:Name="CBBdeRep1" HorizontalAlignment="Left" Height="20" Margin="107,120,0,0" VerticalAlignment="Top" Width="103" BorderBrush="#FF23BBB8" BorderThickness="0" FontSize="10" Foreground="#797979"/>
<ComboBox x:Name="CBBdeSerie1" HorizontalAlignment="Left" Height="20" Margin="227,120,0,0" VerticalAlignment="Top" Width="211" BorderBrush="#FF23BBB8" BorderThickness="0" FontSize="10" Foreground="#797979"/>
<ComboBox x:Name="CBBversRep1" HorizontalAlignment="Left" Height="20" Margin="107,159,0,0" VerticalAlignment="Top" Width="103" BorderBrush="#FF23BBB8" BorderThickness="0" FontSize="10" Foreground="#797979"/>
<TextBox x:Name="TBversSerie1" HorizontalAlignment="Left" Height="20" Margin="227,159,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="211" Padding="2" MaxLength="33" FontSize="10" Foreground="#797979" />
<Grid x:Name="CheckBoxGroup1">
<CheckBox x:Name="CBbin1" Content=" bin" HorizontalAlignment="Left" Height="19" Margin="480,118,0,0" VerticalAlignment="Top" Width="92" Foreground="#797979"/>
<CheckBox x:Name="CBexport1" Content=" export" HorizontalAlignment="Left" Height="19" Margin="480,142,0,0" VerticalAlignment="Top" Width="92" Foreground="#797979"/>
<CheckBox x:Name="CBparam1" Content=" param" HorizontalAlignment="Left" Height="19" Margin="480,166,0,0" VerticalAlignment="Top" Width="92" Foreground="#797979"/>
<CheckBox x:Name="CBlist1" Content=" list" HorizontalAlignment="Left" Height="19" Margin="600,118,0,0" VerticalAlignment="Top" Width="92" Foreground="#797979"/>
<CheckBox x:Name="CBscript1" Content=" script" HorizontalAlignment="Left" Height="19" Margin="600,142,0,0" VerticalAlignment="Top" Width="92" Foreground="#797979"/>
<CheckBox x:Name="CBtemplate1" Content=" template" HorizontalAlignment="Left" Height="19" Margin="600,166,0,0" VerticalAlignment="Top" Width="92" Foreground="#797979"/>
</Grid>
<Button x:Name="BTNcreation" Content="cr`éer la s`érie et synchroniser" FontSize="15" HorizontalAlignment="Left" Height="48" Margin="480,335,0,0" VerticalAlignment="Top" Foreground="white" Background="#FF23BBB8" Width="290"/>
<TextBox x:Name="TBmessages1" HorizontalAlignment="Left" Height="145" Margin="55,238,0,0" TextWrapping="Wrap" VerticalScrollBarVisibility="Visible" Text="Affichage des messages d'erreurs." Foreground="#797979" Padding="6" FontSize="10" VerticalAlignment="Top" Width="383"/>
</Grid>
</TabItem>
<TabItem x:Name="tab2" Header="SYNCHRONISATION" Background="#FF00565F" Height="40" Width="273" BorderBrush="#FF00565F" FontSize="12" Foreground="White" FontFamily="Segoe UI Semibold">
<Grid Background="#292929" Width="840" Height="455" Margin="-7,1,-14,-4">
<Label Content="synchronisation d'une s`érie" FontFamily="Segoe UI" FontSize="20" Foreground="#797979" HorizontalAlignment="Left" Height="47" Margin="49,47,0,0" VerticalAlignment="Top" Width="723"/>
<Line X1="55" X2="440" Y1="200" Y2="200" Stroke="#5f5f5f" StrokeThickness="1"></Line>
<Line X1="55" X2="440" Y1="99" Y2="99" Stroke="#5f5f5f" StrokeThickness="1"></Line>
<Line X1="480" X2="770" Y1="99" Y2="99" Stroke="#5f5f5f" StrokeThickness="1"></Line>
<Line X1="480" X2="770" Y1="200" Y2="200" Stroke="#5f5f5f" StrokeThickness="1"></Line>
<TextBlock HorizontalAlignment="Left" Height="21" Margin="60,121,0,0" TextWrapping="Wrap" Text="de" VerticalAlignment="Top" Width="36" Foreground="#797979"/>
<TextBlock HorizontalAlignment="Left" Height="21" Margin="60,161,0,0" TextWrapping="Wrap" Text="vers" VerticalAlignment="Top" Width="36" Foreground="#797979"/>
<ComboBox x:Name="CBBdeRep2" HorizontalAlignment="Left" Height="20" Margin="107,120,0,0" VerticalAlignment="Top" Width="103" FontSize="10" Foreground="#797979" />
<ComboBox x:Name="CBBdeSerie2" HorizontalAlignment="Left" Height="20" Margin="227,120,0,0" VerticalAlignment="Top" Width="211" FontSize="10" Foreground="#797979"/>
<ComboBox x:Name="CBBversRep2" HorizontalAlignment="Left" Height="20" Margin="107,159,0,0" VerticalAlignment="Top" Width="103" FontSize="10" Foreground="#797979" />
<ComboBox x:Name="CBBversSerie2" HorizontalAlignment="Left" Height="20" Margin="227,159,0,0" VerticalAlignment="Top" Width="211" FontSize="10" Foreground="#797979" />
<CheckBox x:Name="CBbin2" Content=" bin" HorizontalAlignment="Left" Height="19" Margin="480,118,0,0" VerticalAlignment="Top" Width="92" Foreground="#797979"/>
<CheckBox x:Name="CBexport2" Content=" export" HorizontalAlignment="Left" Height="19" Margin="480,142,0,0" VerticalAlignment="Top" Width="92" Foreground="#797979"/>
<CheckBox x:Name="CBparam2" Content=" param" HorizontalAlignment="Left" Height="19" Margin="480,166,0,0" VerticalAlignment="Top" Width="92" Foreground="#797979"/>
<CheckBox x:Name="CBlist2" Content=" list" HorizontalAlignment="Left" Height="19" Margin="600,118,0,0" VerticalAlignment="Top" Width="92" Foreground="#797979"/>
<CheckBox x:Name="CBscript2" Content=" script" HorizontalAlignment="Left" Height="19" Margin="600,142,0,0" VerticalAlignment="Top" Width="92" Foreground="#797979"/>
<CheckBox x:Name="CBtemplate2" Content=" template" HorizontalAlignment="Left" Height="19" Margin="600,166,0,0" VerticalAlignment="Top" Width="92" Foreground="#797979"/>
<TextBox x:Name="TBmessages2" HorizontalAlignment="Left" Height="145" Margin="55,238,0,0" TextWrapping="Wrap" VerticalScrollBarVisibility="Visible" Text="Affichage des messages d'erreurs." Foreground="#797979" Padding="6" FontSize="10" VerticalAlignment="Top" Width="383"/>
<Button x:Name="BTNsynchro" Content="synchroniser la s`érie" FontSize="15" HorizontalAlignment="Left" Height="48" Margin="480,335,0,0" VerticalAlignment="Top" Foreground="white" Background="#FF23BBB8" Width="290"/>
</Grid>
</TabItem>
<TabItem x:Name="tab3" Header="EX`ÉCUTION" Background="#FF00565F" Height="40" Width="273" BorderBrush="#FF00565F" FontSize="12" Foreground="white" FontFamily="Segoe UI Semibold">
<Grid Background="#292929" Width="840" Height="455" Margin="-7,1,-14,-4" >
<Label x:Name="titre3" Content="ex`écution des tests QA" FontFamily="Segoe UI" FontSize="20" Foreground="#797979" HorizontalAlignment="Left" Height="47" Margin="49,47,0,0" VerticalAlignment="Top" Width="723"/>
<Line X1="55" X2="335" Y1="99" Y2="99" Stroke="#5f5f5f" StrokeThickness="1"></Line>
<Line X1="55" X2="335" Y1="160" Y2="160" Stroke="#5f5f5f" StrokeThickness="1"></Line>
<Line X1="480" X2="770" Y1="99" Y2="99" Stroke="#5f5f5f" StrokeThickness="1"></Line>
<Line X1="480" X2="770" Y1="250" Y2="250" Stroke="#5f5f5f" StrokeThickness="1"></Line>
<Line X1="480" X2="770" Y1="200" Y2="200" Stroke="#5f5f5f" StrokeThickness="1"></Line>
<TextBlock HorizontalAlignment="Left" Height="21" Margin="54,121,0,0" TextWrapping="Wrap" Text="version" VerticalAlignment="Top" Width="55" Foreground="#797979"/>
<TextBlock HorizontalAlignment="Left" Height="21" Margin="482,121,0,0" TextWrapping="Wrap" Text="`équipe" VerticalAlignment="Top" Width="55" Foreground="#797979"/>
<TextBlock HorizontalAlignment="Left" Height="21" Margin="482,161,0,0" TextWrapping="Wrap" Text="liste" VerticalAlignment="Top" Width="36" Foreground="#797979"/>
<ComboBox x:Name="CBBversion3" HorizontalAlignment="Left" Height="20" Margin="113,120,0,0" VerticalAlignment="Top" Width="70" FontSize="10" Foreground="#797979" />
<TextBox x:Name="TBbuild3" HorizontalAlignment="Left" Height="20" Margin="201,120,0,0" TextWrapping="Wrap" Text="Build" VerticalAlignment="Top" Width="77" Padding="2" MaxLength="4" FontSize="10" Foreground="#797979" />
<TextBox x:Name="TBrevision3" HorizontalAlignment="Left" Height="20" Margin="297,120,0,0" TextWrapping="Wrap" Text="R`év." VerticalAlignment="Top" Width="36" Padding="2" MaxLength="3" FontSize="10" Foreground="#797979" />
<ComboBox x:Name="CBBequipe3" HorizontalAlignment="Left" Height="20" Margin="542,120,0,0" VerticalAlignment="Top" Width="150" BorderBrush="#FF23BBB8" BorderThickness="0" FontSize="10" Foreground="#797979"/>
<ComboBox x:Name="CBBliste3" HorizontalAlignment="Left" Height="20" Margin="542,159,0,0" VerticalAlignment="Top" Width="150" BorderBrush="#FF23BBB8" BorderThickness="0" FontSize="10" Foreground="#797979"/>
<CheckBox x:Name="CBrtf3" Content=" produire les fichiers en format .rtf" HorizontalAlignment="Left" Height="19" Margin="480,217,0,0" VerticalAlignment="Top" Width="230" Foreground="#797979"/>
<TextBox x:Name="TBmessages3" HorizontalAlignment="Left" Height="190" Margin="55,193,0,0" VerticalScrollBarVisibility="Visible" TextWrapping="Wrap" Text="Affichage des messages d'erreurs." Foreground="#797979" Padding="6" FontSize="10" VerticalAlignment="Top" Width="383"/>
<Button x:Name="BTNexecution" Content="lancer les tests" FontSize="15" HorizontalAlignment="Left" Height="48" Margin="480,335,0,0" VerticalAlignment="Top" Foreground="white" Background="#FF23BBB8" Width="290"/>
</Grid>
</TabItem>
</TabControl>
</Grid>
</Window>
"@
#Read XAML (Parse it)
$reader=(New-Object System.Xml.XmlNodeReader $XAML)
$Window=[Windows.Markup.XamlReader]::Load( $reader )
#region ----- xaml objects to variables -----
#Connect to Controls TAB2
$Tab1CBB1 = $Window.FindName('CBBdeRep1')
$Tab1CBB2 = $Window.FindName('CBBdeSerie1')
$Tab1CBB3 = $Window.FindName('CBBversRep1')
$Tab1TB4 = $Window.FindName('TBversSerie1')
$Tab1CBbin = $Window.FindName('CBbin1')
$Tab1CBexport = $Window.FindName('CBexport1')
$Tab1CBparam = $Window.FindName('CBparam1')
$Tab1CBlist = $Window.FindName('CBlist1')
$Tab1CBscript = $Window.FindName('CBscript1')
$Tab1CBtemplate = $Window.FindName('CBtemplate1')
$Tab1TBmessages = $Window.findName("TBmessages1")
$Tab1BTNcreation = $Window.findName("BTNcreation")
$Tab1CBGroup = $Window.findName("CheckBoxGroup1")
#Connect to Controls TAB2
$Tab2CBB1 = $Window.FindName('CBBdeRep2')
$Tab2CBB2 = $Window.FindName('CBBdeSerie2')
$Tab2CBB3 = $Window.FindName('CBBversRep2')
$Tab2CBB4 = $Window.FindName('CBBversSerie2')
$Tab2CBbin = $Window.FindName('CBbin2')
$Tab2CBexport = $Window.FindName('CBbin2')
$Tab2CBparam = $Window.FindName('CBparam2')
$Tab2CBlist = $Window.FindName('CBlist2')
$Tab2CBscript = $Window.FindName('CBscript2')
$Tab2CBtemplate = $Window.FindName('CBtemplate2')
$Tab2TBmessages = $Window.findName("TBmessages2")
$Tab2BTNsynchro = $Window.findName("BTNsyncro")
#Connect to Controls TAB2
$Tab3CBBversion = $Window.findName("CBBversion3")
$Tab3TBbuild = $Window.findName("TBbuild3")
$Tab3TBrev = $Window.findName("TBrevision3")
$Tab3CBBequipe = $Window.findName("CBBequipe3")
$Tab3CBBliste = $Window.findName("CBBliste3")
$Tab3CBrtf = $Window.findName("CBrtf3")
$Tab3TBmessages = $Window.findName("TBmessages3")
$Tab3BTNexecution = $Window.findName("BTNexecution")
#endregion
#region ---- Path variables -----
$pathDE='E:\Scripts\BibliothequePowershell\Melanie\GUI-ProgTestQA\Simulation\DE\'
$pathVERS='E:\Scripts\BibliothequePowershell\Melanie\GUI-ProgTestQA\Simulation\VERS\'
$pathDBQcust01='E:\Scripts\BibliothequePowershell\Melanie\GUI-ProgTestQA\Simulation\DE\DBQcust01\Sets\'
$pathQA14='E:\Scripts\BibliothequePowershell\Melanie\GUI-ProgTestQA\Simulation\DE\QA14\Sets\'
$pathQA15='E:\Scripts\BibliothequePowershell\Melanie\GUI-ProgTestQA\Simulation\DE\QA15\Sets\'
$pathSERIE = 'E:\Scripts\BibliothequePowershell\Melanie\GUI-ProgTestQA\Simulation\DE\QA14\Sets' #simulation
$pathSIMULATION = 'E:\Scripts\BibliothequePowershell\Melanie\GUI-ProgTestQA\Simulation'
#endregion ----
#region ---- lists of series ----
$listQA14 = Get-ChildItem $pathQA14 -Directory -Name
$listQA15 = Get-ChildItem $pathQA15 -Directory -Name
$listDBQcust01 = Get-ChildItem $pathDBQcust01 -Directory -Name
$FolderLists = Get-ChildItem $pathSIMULATION\Listes -Include *.txt -Name
#endregion
#------------- TAB1 ------------------
#region /// ComboBox 1 : DE folder
$FoldersCBB1 = @('--- choisir ---','DBQcust01','QA14','QA15')
$Tab1CBB1.SelectedItem = '--- choisir ---'
foreach ($Folder in $FoldersCBB1) {
$Tab1CBB1.Items.Add($Folder)
}
#endregion
#region /// ComboBox 2 : DE SERIE (éventuellement changer pour SWITCH)
$Tab1CBB1.add_SelectionChanged({
$Selection = ($Tab1CBB1.SelectedItem.ToString())
if ($Selection -eq 'QA14')
{
$Tab1CBB2.Items.Clear()
$Tab1CBB2.Items.Add('--- choisir une série sous QA14 ---')
$Tab1CBB2.SelectedItem = '--- choisir une série sous QA14 ---'
foreach ($Serie in $listQA14) {
$Tab1CBB2.Items.Add($Serie)
}
}
elseif ($Selection -eq 'QA15')
{
$Tab1CBB2.Items.Clear()
$Tab1CBB2.Items.Add('--- choisir une série sous QA15 ---')
$Tab1CBB2.SelectedItem = '--- choisir une série sous QA15 ---'
foreach ($Serie in $listQA15) {
$Tab1CBB2.Items.Add($Serie)
}
}
elseif ($Selection -eq 'DBQcust01')
{
$Tab1CBB2.Items.Clear()
$Tab1CBB2.Items.Add('--- choisir une série sous DBQcust01 ---')
$Tab1CBB2.SelectedItem = '--- choisir une série sous DBQcust01 ---'
foreach ($Serie in $listDBQcust01) {
$Tab1CBB2.Items.Add($Serie)
}
}
})
#endregion
#region /// ComboBox 3 : VERS folder
$FoldersCBB3 = @('SPMT','OTHER')
$Tab1CBB3.Items.Add('--- choisir ---')
$Tab1CBB3.SelectedItem = '--- choisir ---'
foreach ($Folder in $FoldersCBB3) {
$Tab1CBB3.Items.Add($Folder)
}
#endregion
#region /// TextBox 4 : VERS Série
#à venir (essayer de mettre le contenu des sélections des cbb automatiquement dans le textbox)
$Tab1TB4.text = "SÉRIE+ÉQUIPE"
#endregion
#region /// Bouton Creation
$Tab1BTNcreation.Add_Click({
$SelectionCBB1 = ($Tab1CBB1.SelectedValue)
$SelectionCBB2 = ($Tab1CBB2.SelectedValue)
$SelectionCBB3 = ($Tab1CBB3.SelectedValue)
$SelectionTB4 = ($Tab1TB4.Text)
$Tab1TBmessages.Clear()
New-item -ItemType Directory -Path "$pathVERS$SelectionCBB3" -Name "$SelectionTB4"
$ErrorActionPreference = "stop"
If ($Tab1CBbin.IsChecked -eq $true) {
try {copy-item -Path "$pathDE$SelectionCBB1\sets$SelectionCBB2\Bin2" -Recurse -Destination "$pathVERS$SelectionCBB3$SelectionTB4",$Tab1TBmessages.AddText("Dossier Bin : Copié `r`n")}
catch {$Tab1TBmessages.AddText("Dossier Bin : Non copié `r`n")}
}
If ($Tab1CBexport.IsChecked -eq $true) {
try {copy-item -Path "$pathDE$SelectionCBB1\sets$SelectionCBB2\Export" -Recurse -Destination "$pathVERS$SelectionCBB3$SelectionTB4", $Tab1TBmessages.AddText("Dossier Export : Copié `r`n") }
catch {$Tab1TBmessages.AddText("Dossier Export : Non copié `r`n")}
}
If ($Tab1CBlist.IsChecked -eq $true) { copy-item -Path "$pathDE$SelectionCBB1\sets$SelectionCBB2\List" -Recurse -Destination "$pathVERS$SelectionCBB3$SelectionTB4" }
If ($Tab1CBparam.IsChecked -eq $true) { copy-item -Path "$pathDE$SelectionCBB1\sets$SelectionCBB2\Param" -Recurse -Destination "$pathVERS$SelectionCBB3$SelectionTB4" }
If ($Tab1CBscript.IsChecked -eq $true) { copy-item -Path "$pathDE$SelectionCBB1\sets$SelectionCBB2\QA\Script" -Recurse -Destination "$pathVERS$SelectionCBB3$SelectionTB4\QA\Script" }
If ($Tab1CBtemplate.IsChecked -eq $true) { copy-item -Path "$pathDE$SelectionCBB1\sets$SelectionCBB2\Template" -Recurse -Destination "$pathVERS$SelectionCBB3$SelectionTB4" }
else{
}
})
#endregion
#------------- TAB2 ------------------
#------------- TAB3 ------------------
$Window.ShowDialog() | out-null
实际上,我在我的按钮中执行了此操作(并将继续用于我的所有 IF)。我刚刚复制了代码的末尾。
$Tab1BTNcreation.Add_Click({
$SelectionCBB1 = ($Tab1CBB1.SelectedValue)
$SelectionCBB2 = ($Tab1CBB2.SelectedValue)
$SelectionCBB3 = ($Tab1CBB3.SelectedValue)
$SelectionTB4 = ($Tab1TB4.Text)
$Tab1TBmessages.Clear()
$SelectedPathBin = "$pathDE$SelectionCBB1\sets$SelectionCBB2\Bin2"
$SelectedPathVers = "$pathVERS$SelectionCBB3$SelectionTB4"
New-item -ItemType Directory -Path "$pathVERS$SelectionCBB3" -Name "$SelectionTB4"
If ($Tab1CBbin.IsChecked -eq $true) {
$TestPath1 = Test-Path $SelectedPathBin
$TestPath2 = Test-Path $SelectedPathVers
If ($TestPath1 -eq $True -and $TestPath2 -eq $True) {
copy-item -Path $SelectedPathBin -Recurse -Destination $SelectedPathVers
$Tab1TBmessages.AddText("Dossier Bin : Copié`r`n")
}
else {$Tab1TBmessages.AddText("Dossier Bin : Non copié `r`n")
}
} (......)