Calculateur Salaire
Add-Type -AssemblyName System.Windows.Forms
# Fonction pour calculer les salaires
function Calculate-Salaries {
$annualSalary = [double]$txtAnnualSalary.Text
$hoursPerWeek = [double]$txtHoursPerWeek.Text
$percentage = [double]$txtPercentage.Text / 100
$salaryDivision = [double]$cboSalaryDivision.SelectedItem
if ($hoursPerWeek -eq 0) {
[System.Windows.Forms.MessageBox]::Show("Le nombre d'heures par semaine ne peut pas être zéro.", "Erreur", [System.Windows.Forms.MessageBoxButtons]::OK, [System.Windows.Forms.MessageBoxIcon]::Error)
return
}
if ($percentage -lt 0 -or $percentage -gt 1) {
[System.Windows.Forms.MessageBox]::Show("Le pourcentage doit être entre 0 et 100.", "Erreur", [System.Windows.Forms.MessageBoxButtons]::OK, [System.Windows.Forms.MessageBoxIcon]::Error)
return
}
$adjustedAnnualSalary = $annualSalary * $percentage
$hourlyRate = $adjustedAnnualSalary / (52 * $hoursPerWeek)
$dailyRate = $hourlyRate * ($hoursPerWeek / 5) # Supposition de 5 jours de travail par semaine
$weeklyRate = $hourlyRate * $hoursPerWeek
$monthlyRate = $adjustedAnnualSalary / $salaryDivision
$lblHourlyRate.Text = "Salaire Horaire : CHF " + [math]::Round($hourlyRate, 2)
$lblDailyRate.Text = "Salaire Journalier : CHF " + [math]::Round($dailyRate, 2)
$lblWeeklyRate.Text = "Salaire Hebdomadaire : CHF " + [math]::Round($weeklyRate, 2)
$lblMonthlyRate.Text = "Salaire Mensuel : CHF " + [math]::Round($monthlyRate, 2)
}
# Créer la fenêtre
$form = New-Object System.Windows.Forms.Form
$form.Text = "Calculateur de Salaire"
$form.Size = New-Object System.Drawing.Size(320,380)
$form.StartPosition = "CenterScreen"
# Label et textbox pour le salaire annuel
$lblAnnualSalary = New-Object System.Windows.Forms.Label
$lblAnnualSalary.Text = "Salaire Annuel (CHF):"
$lblAnnualSalary.AutoSize = $true
$lblAnnualSalary.Location = New-Object System.Drawing.Point(10,20)
$txtAnnualSalary = New-Object System.Windows.Forms.TextBox
$txtAnnualSalary.Location = New-Object System.Drawing.Point(160,17)
$txtAnnualSalary.Width = 120
# Label et textbox pour le nombre d'heures par semaine
$lblHoursPerWeek = New-Object System.Windows.Forms.Label
$lblHoursPerWeek.Text = "Heures par Semaine:"
$lblHoursPerWeek.AutoSize = $true
$lblHoursPerWeek.Location = New-Object System.Drawing.Point(10,60)
$txtHoursPerWeek = New-Object System.Windows.Forms.TextBox
$txtHoursPerWeek.Location = New-Object System.Drawing.Point(160,57)
$txtHoursPerWeek.Width = 120
# Label et textbox pour le pourcentage
$lblPercentage = New-Object System.Windows.Forms.Label
$lblPercentage.Text = "Pourcentage de Travail (%):"
$lblPercentage.AutoSize = $true
$lblPercentage.Location = New-Object System.Drawing.Point(10,100)
$txtPercentage = New-Object System.Windows.Forms.TextBox
$txtPercentage.Location = New-Object System.Drawing.Point(160,97)
$txtPercentage.Width = 120
# Combobox pour choisir 12 ou 13 salaires
$lblSalaryDivision = New-Object System.Windows.Forms.Label
$lblSalaryDivision.Text = "Divisions Annuelles :"
$lblSalaryDivision.AutoSize = $true
$lblSalaryDivision.Location = New-Object System.Drawing.Point(10,140)
$cboSalaryDivision = New-Object System.Windows.Forms.ComboBox
$cboSalaryDivision.Items.AddRange(@(12, 13))
$cboSalaryDivision.SelectedIndex = 0 # Par défaut 12
$cboSalaryDivision.Location = New-Object System.Drawing.Point(160,137)
$cboSalaryDivision.Width = 120
# Bouton pour calculer
$btnCalculate = New-Object System.Windows.Forms.Button
$btnCalculate.Text = "Calculer"
$btnCalculate.Location = New-Object System.Drawing.Point(100,180)
$btnCalculate.Add_Click({Calculate-Salaries})
# Labels pour afficher les résultats
$lblHourlyRate = New-Object System.Windows.Forms.Label
$lblHourlyRate.AutoSize = $true
$lblHourlyRate.Location = New-Object System.Drawing.Point(10,220)
$lblDailyRate = New-Object System.Windows.Forms.Label
$lblDailyRate.AutoSize = $true
$lblDailyRate.Location = New-Object System.Drawing.Point(10,250)
$lblWeeklyRate = New-Object System.Windows.Forms.Label
$lblWeeklyRate.AutoSize = $true
$lblWeeklyRate.Location = New-Object System.Drawing.Point(10,280)
$lblMonthlyRate = New-Object System.Windows.Forms.Label
$lblMonthlyRate.AutoSize = $true
$lblMonthlyRate.Location = New-Object System.Drawing.Point(10,310)
# Ajouter tous les contrôles à la fenêtre
$form.Controls.Add($lblAnnualSalary)
$form.Controls.Add($txtAnnualSalary)
$form.Controls.Add($lblHoursPerWeek)
$form.Controls.Add($txtHoursPerWeek)
$form.Controls.Add($lblPercentage)
$form.Controls.Add($txtPercentage)
$form.Controls.Add($lblSalaryDivision)
$form.Controls.Add($cboSalaryDivision)
$form.Controls.Add($btnCalculate)
$form.Controls.Add($lblHourlyRate)
$form.Controls.Add($lblDailyRate)
$form.Controls.Add($lblWeeklyRate)
$form.Controls.Add($lblMonthlyRate)
# Afficher la fenêtre
$form.Add_Shown({$form.Activate()})
[void]$form.ShowDialog()
No comments to display
No comments to display