-création d'un point .bat (ajt.bat) pour lancer le script PS1 (si bloqué par la Policy)

-pour qu'une opération soit prise en compte, il faut les champs: operation, rptx, cp, zep
-création d'un compteur pour le tel: 1ere opé -> tel 0000000000, 2eme opé -> tel 0000000001
-préparation pour la gestion du train encadrant / dernière zep parcourrue
-amélioration des messages affichés et des commentaires du source
This commit is contained in:
2020-06-05 09:26:10 +02:00
parent fa4d0d5c01
commit 6b77eed770
2 changed files with 80 additions and 14 deletions

9
ajt_creator/ajt.bat Normal file
View File

@@ -0,0 +1,9 @@
@echo off
REM start powershell -command "& '.\MyPowershellScript.ps1' -MyArguments blah"
REM start powershell -command "& '.\ajt_creator2.ps1'"
powershell.exe -noprofile -executionpolicy bypass -file .\ajt_creator2.ps1
REM powershell -ExecutionPolicy Bypass -File ajt_creator2.ps1

View File

@@ -1,4 +1,11 @@
# Pour avoir les accents, choisir l'encodage UTF-8-BOM
#############################
# #
# MGPT Ajt Créateur #
# #
#############################
# Pour avoir les accents, choisir l'encodage UTF-8-BOM pour le fichier du script PS
# Ouvrir ajt_creator en passant le fichier .xlsx en paramètre.
# .\ajt_creator "C:\Users\bruno\Desktop\xls\essai ve 15-05.xlsx"
@@ -91,7 +98,7 @@ If(ps excel){kill -name excel}
# On efface / backup tous les fichiers MGPT*.dat existants
Write-host "On efface / backup tous les fichiers MGPT*.dat existants..."
Write-host "On efface / backup tous les fichiers MGPT*.dat existants dans le dossier MGPT_Ajt_Archives ..."
$fileToCheck = "$env:USERPROFILE\Desktop\MGPT*.dat"
$archivePath = "$env:USERPROFILE\Desktop\MGPT_Ajt_Archives"
@@ -115,24 +122,40 @@ $A = import-csv -Path $CSVFileName -Delimiter ";" -Header $header
# On sélectionne uniquement les lignes commençant par AK ou BF
#$planches = $A | Where-Object planche -Match "^AK*|^BF*"
# On sélectionne uniquement les lignes dont le champ Voie/Catenaire est "V"
$planches = $A | Where-Object VC -eq "V"
$long = $planches.length
Write-host "$long planches trouvées ..."
if (![string]::IsNullOrWhitespace($planches)) {
Write-host "Aucune planche S9 MGPTable"
}
Write-host "On supprime les planches incomplètes..."
Write-host "Création du .dat avec les opérations suivantes:"
$i = 0
$filename = ""
# Pour chaque opération
ForEach ($operation in $planches){
# Operation
#$ope = $($operation.planche).Split(" ")[1]
$ope = $($operation.planche)
# Operation# BF 123456
$ope = $($operation.planche).Split(" ")[1]
# - si 123456
#$ope = $($operation.planche)
#$ope
# ZEP/Groupement
# ZEP 305 / GROUPEMENT 8704
#CCTT 8948 "ZEP DJ20948" (702+712+714+720+722+724+726+728)
$zep = $($operation.zep).Split(" ")[1]
#$zep
# Debut
# 15/05/2020 / 8:50
$dd = $($operation.d_deb)
$y = $($dd.Split("/")[2])
$m = $($dd.Split("/")[1])
@@ -142,7 +165,17 @@ $hd = $($operation.h_deb).Replace(":", "")
$debut = "$($dd)$($hd)"
#$debut
# Nom du fichier .dat à créer
# MGPT_BF_0000131428_20200511_1504_U.dat
if ([string]::IsNullOrWhitespace($filename)) {
$a = Get-Date -Format "HHmm"
$filename = "MGPT_BF_0000131428_$($dd)_$($a)_U.dat"
#$filename
$dat_file = "$env:USERPROFILE\Desktop\$($filename).dat"
}
# Fin
# 15/05/2020 / 8:50
$df = $($operation.d_fin)
$y = $($df.Split("/")[2])
$m = $($df.Split("/")[1])
@@ -155,33 +188,51 @@ $fin = "$($df)$($hf)"
# Voie
$voie = ""
# Encadrant
# Train:7899 / Début:220
$encadrant = $($operation.encadrant).Split(":")[1]
$encadrant
# Dernière ZEP
if (![string]::IsNullOrWhitespace($encadrant)) {
$derniere_zep = $($zep).Split("+")[1]
$derniere_zep
}
# Rptx
# RPTx:VILPOUX
$rptx = $($operation.rptx).Split(":")[1]
#$rptx
# N° CP
# 7607869Y
$cp = $($operation.ncp)
#$cp
# Tel
$tel = "0000000000"
$tel = "000000000$i"
#$tel
# Terminaison
# Terminaison (26 barres)
$term = "||||||||||||||||||||||||||"
# Construction de la ligne
$ligne = "$($ope)|1|$($zep)|$($voie)|$($debut)|$($fin)|$($rptx)|$($cp)|$($tel)$term"
#$dat_file = "$env:USERPROFILE\Desktop\$($filename).dat"
# On supprime les lignes dont 1 des champs est nul: rptx, cp, ope
if (![string]::IsNullOrWhitespace($rptx) -And ![string]::IsNullOrWhitespace($cp) -And ![string]::IsNullOrWhitespace($ope)) {
Write-host $ligne
# Chaque opération est écrite dans le fichier MGPT_<date-du-jour>.dat
#echo $ligne >> $env:USERPROFILE/Desktop/MGPT_$dd.dat
$dat_file = "$env:USERPROFILE\Desktop\MGPT_$dd.dat"
Add-Content $dat_file $ligne
}
Write-host "Le fichier ajt $dat_file a été crée."
$i++
}
Write-host "Le fichier ajt $dat_file a été crée sur le bureau."
@@ -190,10 +241,13 @@ IF ($Export -eq "o") {
Write-host "Insérer une clé USB..."
# Routine attente clé à faire
# On choisit la destination
$d = Get-Item $dat_file
$dat = $d.Basename
$dest_dat_file = Save-FileName -initialDirectory "%USERDATA%\desktop\" -name $dat
$dest_dat_file
<#
$e = Get-Item $dest_dat_file
$e.Basename
@@ -205,6 +259,9 @@ IF ($Export -eq "o") {
Copy-Item -Path $dat_file -Destination $destination
#>
Write-host "Copie du fichier ajt sur la destination..."
Write-host " => $dat_file vers $dest_dat_file"
Copy-Item -Path $dat_file -Destination $dest_dat_file
Write-host "Pensez à copier le fichier ajt sur le transit et à le récupérer sur le PC Ajt."
}