-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
45 lines (39 loc) · 1.54 KB
/
Program.cs
File metadata and controls
45 lines (39 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
using System;
using System.Windows.Forms;
using Microsoft.Extensions.Configuration;
using RapportCVVentes.Data; // ton SqlDb
namespace CVReport
{
// Ancre non statique pour UserSecrets
internal sealed class SecretsAnchor { }
internal static class Program
{
[STAThread]
static void Main()
{
ApplicationConfiguration.Initialize();
var configuration = new ConfigurationBuilder()
.SetBasePath(AppContext.BaseDirectory)
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile("appsettings.Development.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables()
.Build();
// On lit le nom de la connexion active, puis on résout la vraie chaîne
var activeName = configuration["ActiveConnectionString"]; // ex: "ReportDb_ByAttach"
var connString = string.IsNullOrWhiteSpace(activeName)
? null
: configuration.GetConnectionString(activeName);
if (string.IsNullOrWhiteSpace(connString))
{
MessageBox.Show(
"La chaîne de connexion est vide.\n" +
"Vérifie 'ActiveConnectionString' et l'entrée correspondante dans ConnectionStrings.",
"Configuration manquante",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
using var db = new SqlDb(connString);
Application.Run(new MainForm(db));
}
}
}