SignatureGenerator.ps1

#-------------------------------------------------------------#
#----Initial Declarations-------------------------------------#
#-------------------------------------------------------------#

Add-Type -AssemblyName PresentationCore, PresentationFramework, System.Windows.Forms

$Xaml= @"
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" Width="900" Height="500">
  <Grid>
    <Grid.ColumnDefinitions>
    <ColumnDefinition Width="110"/>
    <ColumnDefinition Width="676*"/>
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
      <RowDefinition Height="180"/>
      <RowDefinition Height="263*"/>
    </Grid.RowDefinitions>
    <Border BorderBrush="Black" BorderThickness="1" Grid.Row="0" Grid.Column="0">
      <StackPanel>
        <Label HorizontalAlignment="Left" VerticalAlignment="Top" Content="Full Name" Margin="0,0,0,0"/>
        <Label HorizontalAlignment="Left" VerticalAlignment="Top" Content="Title" Margin="0,0,0,0"/>
        <Label HorizontalAlignment="Left" VerticalAlignment="Top" Content="Office Number" Margin="0,0,0,0"/>
        <Label HorizontalAlignment="Left" VerticalAlignment="Top" Content="Cell Number" Margin="0,0,0,0"/>
        <Label HorizontalAlignment="Left" VerticalAlignment="Top" Content="Email Address" Margin="0,0,0,0"/>
        <Label HorizontalAlignment="Left" VerticalAlignment="Top" Content="Street Address" Margin="0,0,0,0"/>
      </StackPanel>
    </Border>
    <Border BorderBrush="Black" BorderThickness="1" Grid.Row="1" Grid.Column="1" Name="WebBorder">
    <WebBrowser Name="WebBrowser" ></WebBrowser>
    </Border>
    <Border BorderBrush="Black" BorderThickness="1" Grid.Row="1" Grid.Column="0">
      <StackPanel>
      <Button Content="Import Template" HorizontalAlignment="Left" VerticalAlignment="Top" Width="95" Margin="5,5,0,0" Name="l6kw1fboq5l4q"/>
      <Button Content="Preview" HorizontalAlignment="Left" VerticalAlignment="Top" Width="95" Margin="5,5,0,0" Name="l6kw1fboo4u5b"/>
      <Button Content="Save" HorizontalAlignment="Left" VerticalAlignment="Top" Width="95" Margin="5,5,0,0" Name="l6kw1fbormfj6"/>
      </StackPanel>
    </Border>
    <Grid Grid.Row="0" Grid.Column="1">
      <Grid.ColumnDefinitions>
        <ColumnDefinition Width="144*"/>
        <ColumnDefinition Width="566*"/>
      </Grid.ColumnDefinitions>
      <Border BorderBrush="Black" BorderThickness="1" Grid.Row="0" Grid.Column="0">
        <StackPanel>
        <TextBox HorizontalAlignment="Left" VerticalAlignment="Top" Height="17" Width="140" TextWrapping="Wrap" Margin="5,5,0,0" Text="{Binding Name}" Name="l6kw1fboyydhr"/>
        <TextBox HorizontalAlignment="Left" VerticalAlignment="Top" Height="17" Width="140" TextWrapping="Wrap" Margin="5,10,0,0" Text="{Binding Title}" Name="l6kw1fboi72h2"/>
        <TextBox HorizontalAlignment="Left" VerticalAlignment="Top" Height="17" Width="140" TextWrapping="Wrap" Margin="5,10,0,0" Text="{Binding OfficePhone}" Name="l6kw1fbosfusy"/>
        <TextBox HorizontalAlignment="Left" VerticalAlignment="Top" Height="17" Width="140" TextWrapping="Wrap" Margin="5,10,0,0" Text="{Binding Email}" Name="l6kw1fbo1o7t9"/>
        <TextBox HorizontalAlignment="Left" VerticalAlignment="Top" Height="17" Width="140" TextWrapping="Wrap" Margin="5,10,0,0" Text="{Binding CellPhone}" Name="CellPhone"/>
      <ComboBox HorizontalAlignment="Left" VerticalAlignment="Top" Width="120" Margin="5,10,0,0" Name="l6kw1fbok04cl" ItemsSource="{Binding Locations}"/>
        </StackPanel>
      </Border>
      <Border BorderBrush="Black" BorderThickness="1" Grid.Row="0" Grid.Column="1" Name="ATBorder">
        <StackPanel />
      </Border>
    </Grid>
  </Grid>
</Window>
"@


#-------------------------------------------------------------#
#----Control Event Handlers-----------------------------------#
#-------------------------------------------------------------#


#region Logic
$Locations = @()
$Locations += [PSCustomObject]@{
    Name = "Melbourne HQ"
    Address = "7607 Coral Drive"
    City = "West Melbourne, FL 32904 USA"
}
$Locations += [PSCustomObject]@{
    Name = "Melbourne Accounting"
    Address = "1990 West New Haven Avenue"
    City = "Melbourne Financial Center, Suite 304 <BR> Melbourne, Florida 32904, United States"
}
$Locations += [PSCustomObject]@{
    Name = "Orlando"
    Address = "5025 S. Orange Avenue"
    City = "Orlando, Florida 32809, United States"
}
$LocIndex = $Locations | Group-Object Name -AsHashTable -AsString
#endregion
#region Template
function Get-Template {
  if ($State.CellPhone.Length -le 1){
    $State.Template = $Null
    $State.Template = (Invoke-WebRequest -Uri "https://raw.githubusercontent.com/MEConstruction/Signature/main/Kimberly.htm" -UseBasicParsing).Content
  }
  if ($State.CellPhone.Length -gt 1){
    $State.Template = $Null
    $State.Template = (Invoke-WebRequest -Uri "https://raw.githubusercontent.com/MEConstruction/Signature/main/MECSignature.htm" -UseBasicParsing).Content
  }
}
function PreviewChanges {
    SetLocation
    if ($State.CellPhone.length -le 1){
    $State.Changes = $null
    $State.Changes = $State.Template.replace("Replace Name",$State.Name).replace("Replace Title",$State.Title).replace("Replace Office Phone",$State.OfficePhone).replace("Replace Email",$State.Email).replace("Replace Street",$State.Street).replace("Replace City",$State.City).replace("KimberlyB@MECFlorida.com",$State.Email)
    }
    if ($State.CellPhone -gt 1){
      $State.Changes = $null
      $State.Changes = $State.Template.replace("Replace Name",$State.Name).replace("Replace Title",$State.Title).replace("Replace Office Phone",$State.OfficePhone).replace("Replace Email",$State.Email).replace("Replace Street",$State.Street).replace("Replace City",$State.City).replace("KimberlyB@MECFlorida.com",$State.Email).replace("Replace Cell",$State.CellPhone)
    }
    $WebBrowser.NavigateToString($State.Changes)
    
}
function SaveChanges {
    SetLocation
    $State.Changes = $State.Template.replace("Replace Name",$State.Name).replace("Replace Title",$State.Title).replace("Replace Office Phone",$State.OfficePhone).replace("Replace Email",$State.Email).replace("Replace Street",$State.Street).replace("Replace City",$State.City).replace("KimberlyB@MECFlorida.com",$State.Email)
    $FileBrowser = [System.Windows.Forms.SaveFileDialog]::new()
    $FileBrowser.InitialDirectory = [Environment]::GetFolderPath('Desktop')
    $FileBrowser.FileName = "MECSignature.htm"
    $FileBrowser.Filter = "HTM Files (*.htm)|*.htm"
    $FileBrowser.ShowDialog()
    $State.Changes > $FileBrowser.FileName
}
function SetLocation {
    $State.Street = ($LocIndex[$l6kw1fbok04cl.SelectedItem]).Address
    $State.City = ($LocIndex[$l6kw1fbok04cl.SelectedItem]).city
}

#endregion


#-------------------------------------------------------------#
#----Script Execution-----------------------------------------#
#-------------------------------------------------------------#

$Window = [Windows.Markup.XamlReader]::Parse($Xaml)

[xml]$xml = $Xaml

$xml.SelectNodes("//*[@Name]") | ForEach-Object { Set-Variable -Name $_.Name -Value $Window.FindName($_.Name) }



$l6kw1fbok04cl.Add_SelectionChanged({SetLocation $this $_})
$l6kw1fboq5l4q.Add_Click({Get-Template $this $_})
$l6kw1fboo4u5b.Add_Click({PreviewChanges $this $_})
$l6kw1fbormfj6.Add_Click({SaveChanges $this $_})

$State = [PSCustomObject]@{}


Function Set-Binding {
    Param($Target,$Property,$Index,$Name,$UpdateSourceTrigger)
 
    $Binding = New-Object System.Windows.Data.Binding
    $Binding.Path = "["+$Index+"]"
    $Binding.Mode = [System.Windows.Data.BindingMode]::TwoWay
    if($UpdateSourceTrigger -ne $null){$Binding.UpdateSourceTrigger = $UpdateSourceTrigger}


    [void]$Target.SetBinding($Property,$Binding)
}

function FillDataContext($props){

    For ($i=0; $i -lt $props.Length; $i++) {
   
   $prop = $props[$i]
   $DataContext.Add($DataObject."$prop")
   
    $getter = [scriptblock]::Create("Write-Output `$DataContext['$i'] -noenumerate")
    $setter = [scriptblock]::Create("param(`$val) return `$DataContext['$i']=`$val")
    $State | Add-Member -Name $prop -MemberType ScriptProperty -Value  $getter -SecondValue $setter
               
       }
   }



$DataObject =  ConvertFrom-Json @"
 
{
    "Template" : "$Template",
    "Name" : "",
    "Title" : "",
    "OfficePhone" : "",
    "CellPhone" : "",
    "Email" : "",
    "Street" : "",
    "City" : "",
    "Changes": "",
    "Locations": ["Melbourne HQ","Melbourne Accounting","Orlando"]
}
 
"@


$DataContext = New-Object System.Collections.ObjectModel.ObservableCollection[Object]
FillDataContext @("Template","Name","Title","OfficePhone","CellPhone","Email","Street","City","Changes","Locations") 

$Window.DataContext = $DataContext
Set-Binding -Target $l6kw1fboyydhr -Property $([System.Windows.Controls.TextBox]::TextProperty) -Index 1 -Name "Name"  
Set-Binding -Target $l6kw1fboi72h2 -Property $([System.Windows.Controls.TextBox]::TextProperty) -Index 2 -Name "Title"  
Set-Binding -Target $l6kw1fbosfusy -Property $([System.Windows.Controls.TextBox]::TextProperty) -Index 3 -Name "OfficePhone" 
Set-Binding -Target $CellPhone     -Property $([System.Windows.Controls.TextBox]::TextProperty) -Index 5 -Name "CellPhone"
Set-Binding -Target $l6kw1fbo1o7t9 -Property $([System.Windows.Controls.TextBox]::TextProperty) -Index 4 -Name "Email"  
Set-Binding -Target $l6kw1fbok04cl -Property $([System.Windows.Controls.ComboBox]::ItemsSourceProperty) -Index 9 -Name "Locations"  

$Window.ShowDialog()