5 assurer la sécurité la qualité et intégrer des logs #9

Merged
winkaeter merged 3 commits from 5-assurer-la-sécurité-la-qualité-et-intégrer-des-logs into master 2026-03-30 13:31:57 +00:00
10 changed files with 183 additions and 68 deletions
Showing only changes of commit 8a75e165b8 - Show all commits

View file

@ -4,7 +4,8 @@
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" /> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup> </startup>
<appSettings> <appSettings>
<add key="ApiAuthentication" value="admin:adminpwd"/> <add key="ApiAuthentication" value="admin:adminpwd" />
<add key="ApiUri" value="http://localhost/rest_mediatekdocuments/" />
</appSettings> </appSettings>
<runtime> <runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
@ -12,6 +13,22 @@
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" /> <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-13.0.0.0" newVersion="13.0.0.0" /> <bindingRedirect oldVersion="0.0.0.0-13.0.0.0" newVersion="13.0.0.0" />
</dependentAssembly> </dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.1.2" newVersion="4.0.1.2" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Google.Protobuf" publicKeyToken="a7d26565bac4d604" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.34.1.0" newVersion="3.34.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="K4os.Compression.LZ4.Streams" publicKeyToken="2186fa9121ef231d" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.3.8.0" newVersion="1.3.8.0" />
</dependentAssembly>
</assemblyBinding> </assemblyBinding>
</runtime> </runtime>
</configuration> </configuration>

View file

@ -12,6 +12,8 @@
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic> <Deterministic>true</Deterministic>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget> <PlatformTarget>AnyCPU</PlatformTarget>
@ -33,20 +35,63 @@
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="BouncyCastle.Crypto, Version=1.8.5.0, Culture=neutral, PublicKeyToken=0e99375e54769942" /> <Reference Include="BouncyCastle.Crypto, Version=1.8.5.0, Culture=neutral, PublicKeyToken=0e99375e54769942">
<Reference Include="Google.Protobuf, Version=3.19.4.0, Culture=neutral, PublicKeyToken=a7d26565bac4d604" /> <HintPath>..\packages\BouncyCastle.1.8.5\lib\BouncyCastle.Crypto.dll</HintPath>
<Reference Include="K4os.Compression.LZ4.Streams, Version=1.2.6.0, Culture=neutral, PublicKeyToken=2186fa9121ef231d" /> </Reference>
<Reference Include="MySql.Data, Version=8.0.29.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d, processorArchitecture=MSIL" /> <Reference Include="BouncyCastle.Cryptography, Version=2.0.0.0, Culture=neutral, PublicKeyToken=072edcf4a5328938, processorArchitecture=MSIL">
<HintPath>..\packages\BouncyCastle.Cryptography.2.6.2\lib\net461\BouncyCastle.Cryptography.dll</HintPath>
</Reference>
<Reference Include="Google.Protobuf, Version=3.34.1.0, Culture=neutral, PublicKeyToken=a7d26565bac4d604, processorArchitecture=MSIL">
<HintPath>..\packages\Google.Protobuf.3.34.1\lib\net45\Google.Protobuf.dll</HintPath>
</Reference>
<Reference Include="K4os.Compression.LZ4, Version=1.3.8.0, Culture=neutral, PublicKeyToken=2186fa9121ef231d, processorArchitecture=MSIL">
<HintPath>..\packages\K4os.Compression.LZ4.1.3.8\lib\net462\K4os.Compression.LZ4.dll</HintPath>
</Reference>
<Reference Include="K4os.Compression.LZ4.Streams, Version=1.3.8.0, Culture=neutral, PublicKeyToken=2186fa9121ef231d, processorArchitecture=MSIL">
<HintPath>..\packages\K4os.Compression.LZ4.Streams.1.3.8\lib\net462\K4os.Compression.LZ4.Streams.dll</HintPath>
</Reference>
<Reference Include="K4os.Hash.xxHash, Version=1.0.8.0, Culture=neutral, PublicKeyToken=32cd54395057cec3, processorArchitecture=MSIL">
<HintPath>..\packages\K4os.Hash.xxHash.1.0.8\lib\net462\K4os.Hash.xxHash.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Bcl.AsyncInterfaces, Version=5.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Bcl.AsyncInterfaces.5.0.0\lib\net461\Microsoft.Bcl.AsyncInterfaces.dll</HintPath>
</Reference>
<Reference Include="MySql.Data, Version=8.0.29.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d, processorArchitecture=MSIL">
<HintPath>..\packages\MySql.Data.8.0.29\lib\net452\MySql.Data.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> <Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath> <HintPath>..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference> </Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll</HintPath>
</Reference>
<Reference Include="System.ComponentModel" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Configuration" /> <Reference Include="System.Configuration" />
<Reference Include="System.Configuration.ConfigurationManager, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Configuration.ConfigurationManager.8.0.0\lib\net462\System.Configuration.ConfigurationManager.dll</HintPath>
</Reference>
<Reference Include="System.Configuration.Install" /> <Reference Include="System.Configuration.Install" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.IO.Pipelines, Version=5.0.0.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.IO.Pipelines.5.0.2\lib\net461\System.IO.Pipelines.dll</HintPath>
</Reference>
<Reference Include="System.Management" /> <Reference Include="System.Management" />
<Reference Include="System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" /> <Reference Include="System.Memory, Version=4.0.1.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Memory.4.5.5\lib\net461\System.Memory.dll</HintPath>
</Reference>
<Reference Include="System.Net.Http.Formatting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" /> <Reference Include="System.Net.Http.Formatting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
<Reference Include="System.Numerics" />
<Reference Include="System.Numerics.Vectors, Version=4.1.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll</HintPath>
</Reference>
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.6.0.0\lib\net461\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
</Reference>
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll</HintPath>
</Reference>
<Reference Include="System.Transactions" /> <Reference Include="System.Transactions" />
<Reference Include="System.Xml.Linq" /> <Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" /> <Reference Include="System.Data.DataSetExtensions" />
@ -57,8 +102,15 @@
<Reference Include="System.Net.Http" /> <Reference Include="System.Net.Http" />
<Reference Include="System.Windows.Forms" /> <Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
<Reference Include="Ubiety.Dns.Core, Version=2.2.1.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" /> <Reference Include="Ubiety.Dns.Core, Version=2.2.1.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d, processorArchitecture=MSIL">
<Reference Include="ZstdNet, Version=1.4.5.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" /> <HintPath>..\packages\MySql.Data.8.0.29\lib\net452\Ubiety.Dns.Core.dll</HintPath>
</Reference>
<Reference Include="ZstdNet, Version=1.4.5.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d, processorArchitecture=MSIL">
<HintPath>..\packages\MySql.Data.8.0.29\lib\net452\ZstdNet.dll</HintPath>
</Reference>
<Reference Include="ZstdSharp, Version=0.8.6.0, Culture=neutral, PublicKeyToken=8d151af33a4ad5cf, processorArchitecture=MSIL">
<HintPath>..\packages\ZstdSharp.Port.0.8.6\lib\net462\ZstdSharp.dll</HintPath>
</Reference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="controller\FrmAuthController.cs" /> <Compile Include="controller\FrmAuthController.cs" />
@ -124,4 +176,11 @@
</ItemGroup> </ItemGroup>
<ItemGroup /> <ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\ZstdNet.1.4.5\build\ZstdNet.targets" Condition="Exists('..\packages\ZstdNet.1.4.5\build\ZstdNet.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>Ce projet fait référence à des packages NuGet qui sont manquants sur cet ordinateur. Utilisez l'option de restauration des packages NuGet pour les télécharger. Pour plus d'informations, consultez http://go.microsoft.com/fwlink/?LinkID=322105. Le fichier manquant est : {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\ZstdNet.1.4.5\build\ZstdNet.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\ZstdNet.1.4.5\build\ZstdNet.targets'))" />
</Target>
</Project> </Project>

View file

@ -15,7 +15,6 @@ namespace MediaTekDocuments
Application.EnableVisualStyles(); Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false); Application.SetCompatibleTextRenderingDefault(false);
//Application.Run(new FrmAuth());
FrmAuth auth = new FrmAuth(); FrmAuth auth = new FrmAuth();
if (auth.ShowDialog() == DialogResult.OK) if (auth.ShowDialog() == DialogResult.OK)

View file

@ -15,10 +15,6 @@ namespace MediaTekDocuments.dal
/// </summary> /// </summary>
public class Access public class Access
{ {
/// <summary>
/// adresse de l'API
/// </summary>
private static readonly string uriApi = "http://localhost/rest_mediatekdocuments/";
/// <summary> /// <summary>
/// instance unique de la classe /// instance unique de la classe
/// </summary> /// </summary>
@ -48,12 +44,18 @@ namespace MediaTekDocuments.dal
/// Méthode privée pour créer un singleton /// Méthode privée pour créer un singleton
/// initialise l'accès à l'API /// initialise l'accès à l'API
/// </summary> /// </summary>
// Le constructeur redevient sans paramètre pour le Singleton
private Access() private Access()
{ {
String authenticationString; string authenticationString;
string uriApi; // Devient une variable locale au constructeur
try try
{ {
// Lecture directe depuis le fichier de configuration
uriApi = ConfigurationManager.AppSettings["ApiUri"];
authenticationString = ConfigurationManager.AppSettings["ApiAuthentication"]; authenticationString = ConfigurationManager.AppSettings["ApiAuthentication"];
// On passe la variable locale à l'API Rest
api = ApiRest.GetInstance(uriApi, authenticationString); api = ApiRest.GetInstance(uriApi, authenticationString);
} }
catch (Exception e) catch (Exception e)
@ -63,14 +65,11 @@ namespace MediaTekDocuments.dal
} }
} }
/// <summary>
/// Création et retour de l'instance unique de la classe
/// </summary>
/// <returns>instance unique de la classe</returns>
public static Access GetInstance() public static Access GetInstance()
{ {
if(instance == null) if (instance == null)
{ {
// On appelle le constructeur sans argument
instance = new Access(); instance = new Access();
} }
return instance; return instance;
@ -303,12 +302,18 @@ namespace MediaTekDocuments.dal
public string GetNextCommandeId() public string GetNextCommandeId()
{ {
List<dynamic> result = TraitementRecup<dynamic>(GET, "maxcommande", null); List<dynamic> result = TraitementRecup<dynamic>(GET, "maxcommande", null);
if (result != null && result.Count > 0)
if (result != null && result.Count > 0 && result[0].maxId != null)
{ {
string lastId = result[0].maxId.ToString(); var firstResult = result[0];
int nextIdVal = int.Parse(lastId.Substring(1)) + 1; if (firstResult != null && firstResult.maxId != null)
return "" + nextIdVal.ToString("D4"); {
string lastId = firstResult.maxId.ToString();
if (lastId.Length > 1)
{
int nextIdVal = int.Parse(lastId.Substring(1)) + 1;
return nextIdVal.ToString("D4");
}
}
} }
return "0001"; return "0001";
} }

View file

@ -1,4 +1,21 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<packages> <packages>
<package id="BouncyCastle" version="1.8.5" targetFramework="net472" />
<package id="BouncyCastle.Cryptography" version="2.6.2" targetFramework="net472" />
<package id="Google.Protobuf" version="3.34.1" targetFramework="net472" />
<package id="K4os.Compression.LZ4" version="1.3.8" targetFramework="net472" />
<package id="K4os.Compression.LZ4.Streams" version="1.3.8" targetFramework="net472" />
<package id="K4os.Hash.xxHash" version="1.0.8" targetFramework="net472" />
<package id="Microsoft.Bcl.AsyncInterfaces" version="5.0.0" targetFramework="net472" />
<package id="MySql.Data" version="8.0.29" targetFramework="net472" />
<package id="Newtonsoft.Json" version="13.0.1" targetFramework="net472" /> <package id="Newtonsoft.Json" version="13.0.1" targetFramework="net472" />
<package id="System.Buffers" version="4.5.1" targetFramework="net472" />
<package id="System.Configuration.ConfigurationManager" version="8.0.0" targetFramework="net472" />
<package id="System.IO.Pipelines" version="5.0.2" targetFramework="net472" />
<package id="System.Memory" version="4.5.5" targetFramework="net472" />
<package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net472" />
<package id="System.Runtime.CompilerServices.Unsafe" version="6.0.0" targetFramework="net472" />
<package id="System.Threading.Tasks.Extensions" version="4.5.4" targetFramework="net472" />
<package id="ZstdNet" version="1.4.5" targetFramework="net472" />
<package id="ZstdSharp.Port" version="0.8.6" targetFramework="net472" />
</packages> </packages>

View file

@ -23,7 +23,8 @@ namespace MediaTekDocuments.view
private void FrmAuth_Load(object sender, EventArgs e) private void FrmAuth_Load(object sender, EventArgs e)
{ {
// // Méthode laissée vide intentionnellement.
// Aucun traitement spécifique n'est requis au chargement du formulaire d'authentification.
} }
private void btnLogin_Click(object sender, EventArgs e) private void btnLogin_Click(object sender, EventArgs e)
@ -31,9 +32,9 @@ namespace MediaTekDocuments.view
string identifiant = txtIdentifiant.Text; string identifiant = txtIdentifiant.Text;
string password = txtPassword.Text; string password = txtPassword.Text;
Utilisateur user = controller.GetConnection(identifiant, password); Utilisateur utilisateur = controller.GetConnection(identifiant, password);
if(user == null) if(utilisateur == null)
{ {
txtIdentifiant.Text = ""; txtIdentifiant.Text = "";
txtPassword.Text = ""; txtPassword.Text = "";
@ -41,7 +42,7 @@ namespace MediaTekDocuments.view
return; return;
} }
if(user.LibelleService == "Culture") if(utilisateur.LibelleService == "Culture")
{ {
MessageBox.Show("Vous n'êtes pas autorisé à accéder à cette application !", "Accès refusé", MessageBoxButtons.OK, MessageBoxIcon.Warning); MessageBox.Show("Vous n'êtes pas autorisé à accéder à cette application !", "Accès refusé", MessageBoxButtons.OK, MessageBoxIcon.Warning);
this.DialogResult = DialogResult.Abort; this.DialogResult = DialogResult.Abort;
@ -49,7 +50,7 @@ namespace MediaTekDocuments.view
return; return;
} }
this.user = user; this.user = utilisateur;
this.DialogResult = DialogResult.OK; this.DialogResult = DialogResult.OK;
this.Close(); this.Close();
} }

View file

@ -1,4 +1,5 @@
using System; using System;
using System.Text;
using System.Windows.Forms; using System.Windows.Forms;
using MediaTekDocuments.model; using MediaTekDocuments.model;
using MediaTekDocuments.controller; using MediaTekDocuments.controller;
@ -33,7 +34,7 @@ namespace MediaTekDocuments.view
InitializeComponent(); InitializeComponent();
this.controller = new FrmMediatekController(); this.controller = new FrmMediatekController();
this.user = user; this.user = user;
this.Text += " - " + user.Prenom + " " + user.Nom; this.Text += " - " + this.user.Prenom + " " + user.Nom;
RemplirComboSuivi(controller.GetAllSuivis(), bdgSuivis, cboSuivi); RemplirComboSuivi(controller.GetAllSuivis(), bdgSuivis, cboSuivi);
RemplirComboSuivi(controller.GetAllSuivis(), bdgSuivis, cboSuiviDvd); RemplirComboSuivi(controller.GetAllSuivis(), bdgSuivis, cboSuiviDvd);
@ -115,7 +116,7 @@ namespace MediaTekDocuments.view
if (tabOngletsApplication.TabPages.Contains(tabCommandeLivres)) if (tabOngletsApplication.TabPages.Contains(tabCommandeLivres))
{ {
dgvListeLivre2.DataSource = null; dgvListeLivre2.DataSource = null;
dgvListeLivre2.DataSource = bdgLivresListe; dgvListeLivre2.DataSource = livres;
if (dgvListeLivre2.Columns.Count > 0 && dgvListeLivre2.Columns.Contains("isbn")) if (dgvListeLivre2.Columns.Count > 0 && dgvListeLivre2.Columns.Contains("isbn"))
{ {
@ -454,7 +455,7 @@ namespace MediaTekDocuments.view
if (tabOngletsApplication.TabPages.Contains(tabCommandeDvd)) if (tabOngletsApplication.TabPages.Contains(tabCommandeDvd))
{ {
dgvDvd.DataSource = null; dgvDvd.DataSource = null;
dgvDvd.DataSource = bdgDvdListe; dgvDvd.DataSource = dvds;
if (dgvDvd.Columns.Count > 0 && dgvDvd.Columns.Contains("idRayon")) if (dgvDvd.Columns.Count > 0 && dgvDvd.Columns.Contains("idRayon"))
{ {
@ -1398,11 +1399,14 @@ namespace MediaTekDocuments.view
dgvCommandes.DataSource = null; dgvCommandes.DataSource = null;
dgvCommandes.Columns.Clear(); dgvCommandes.Columns.Clear();
dgvCommandes.DataSource = lesCommandes; dgvCommandes.DataSource = lesCommandes;
string[] toHide = { "id", "idLivreDvd", "idSuivi" };
foreach (string col in toHide)
if (dgvCommandes.Columns.Contains(col)) dgvCommandes.Columns[col].Visible = false;
dgvCommandes.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
string[] toHide = { "id", "idLivreDvd", "idSuivi" };
dgvCommandes.Columns.Cast<DataGridViewColumn>()
.Where(col => toHide.Contains(col.Name))
.ToList()
.ForEach(col => col.Visible = false);
dgvCommandes.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
dgvCommandes.ClearSelection(); dgvCommandes.ClearSelection();
dgvCommandes.CurrentCell = null; dgvCommandes.CurrentCell = null;
ViderZonesSaisieCommande(); ViderZonesSaisieCommande();
@ -1441,10 +1445,10 @@ namespace MediaTekDocuments.view
if (dgvCommandes.CurrentRow.Cells["Montant"].Value != null) if (dgvCommandes.CurrentRow.Cells["Montant"].Value != null)
{ {
CommandeDocument commandeDocument = (CommandeDocument)dgvCommandes.CurrentRow.DataBoundItem;
updownMontant.Value = Convert.ToDecimal(dgvCommandes.CurrentRow.Cells["Montant"].Value); updownMontant.Value = Convert.ToDecimal(dgvCommandes.CurrentRow.Cells["Montant"].Value);
updownNbExemplaire.Value = Convert.ToDecimal(dgvCommandes.CurrentRow.Cells["NbExemplaire"].Value); updownNbExemplaire.Value = Convert.ToDecimal(dgvCommandes.CurrentRow.Cells["NbExemplaire"].Value);
string etape = commandeDocument.LibelleSuivi;
string etape = commande.LibelleSuivi;
cboSuivi.SelectedIndex = cboSuivi.FindStringExact(etape); cboSuivi.SelectedIndex = cboSuivi.FindStringExact(etape);
grpNewCommande.Text = "Modifier commande"; grpNewCommande.Text = "Modifier commande";
@ -1452,8 +1456,6 @@ namespace MediaTekDocuments.view
dateTimeCommande.Enabled = false; dateTimeCommande.Enabled = false;
updownMontant.Enabled = false; updownMontant.Enabled = false;
updownNbExemplaire.Enabled = false; updownNbExemplaire.Enabled = false;
} }
} }
else else
@ -1466,8 +1468,6 @@ namespace MediaTekDocuments.view
{ {
if (dgvListeLivre2.CurrentCell != null && dgvCommandes.CurrentCell != null) if (dgvListeLivre2.CurrentCell != null && dgvCommandes.CurrentCell != null)
{ {
string id = dgvListeLivre2.CurrentRow.Cells["Id"].Value.ToString();
string commandeId = dgvCommandes.CurrentRow.Cells["id"].Value.ToString();
CommandeDocument commande = (CommandeDocument)dgvCommandes.CurrentRow.DataBoundItem; CommandeDocument commande = (CommandeDocument)dgvCommandes.CurrentRow.DataBoundItem;
btnDeleteCommande.Enabled = false; btnDeleteCommande.Enabled = false;
@ -1647,9 +1647,12 @@ namespace MediaTekDocuments.view
{ {
dgvCommandesDvd.DataSource = null; dgvCommandesDvd.DataSource = null;
dgvCommandesDvd.DataSource = lesCommandes; dgvCommandesDvd.DataSource = lesCommandes;
string[] toHide = { "id", "idLivreDvd", "idSuivi" }; string[] toHide = { "id", "idLivreDvd", "idSuivi" };
foreach (string col in toHide) dgvCommandesDvd.Columns.Cast<DataGridViewColumn>()
if (dgvCommandesDvd.Columns.Contains(col)) dgvCommandesDvd.Columns[col].Visible = false; .Where(col => toHide.Contains(col.Name))
.ToList()
.ForEach(col => col.Visible = false);
dgvCommandesDvd.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells; dgvCommandesDvd.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
} }
@ -1768,10 +1771,8 @@ namespace MediaTekDocuments.view
private void btnDeleteCommandeDvd_Click(object sender, EventArgs e) private void btnDeleteCommandeDvd_Click(object sender, EventArgs e)
{ {
if (dgvCommandesDvd.CurrentCell != null && dgvCommandesDvd.CurrentCell != null) if (dgvCommandesDvd.CurrentCell != null)
{ {
string id = dgvCommandesDvd.CurrentRow.Cells["Id"].Value.ToString();
string commandeId = dgvCommandesDvd.CurrentRow.Cells["id"].Value.ToString();
CommandeDocument commande = (CommandeDocument)dgvCommandesDvd.CurrentRow.DataBoundItem; CommandeDocument commande = (CommandeDocument)dgvCommandesDvd.CurrentRow.DataBoundItem;
btnDeleteCommandeDvd.Enabled = false; btnDeleteCommandeDvd.Enabled = false;
@ -1816,40 +1817,31 @@ namespace MediaTekDocuments.view
private void AlerteAbonnementsExpirants() private void AlerteAbonnementsExpirants()
{ {
List<Revue> toutesLesRevues = controller.GetAllRevues(); List<Revue> toutesLesRevues = controller.GetAllRevues();
string message = "Abonnements se terminant sous 30 jours :\n"; StringBuilder stp = new StringBuilder("Abonnements se terminant sous 30 jours :\n");
bool alerte = false; bool alerte = false;
foreach (Revue revue in toutesLesRevues) foreach (Revue revue in toutesLesRevues)
{ {
List<Abonnement> abos = controller.GetAbonnements(revue.Id); List<Abonnement> abos = controller.GetAbonnements(revue.Id);
// On prend le dernier abonnement (le plus récent)
Abonnement dernierAbo = abos.OrderByDescending(a => a.DateFinAbonnement).FirstOrDefault(); Abonnement dernierAbo = abos.OrderByDescending(a => a.DateFinAbonnement).FirstOrDefault();
if (dernierAbo != null && (dernierAbo.DateFinAbonnement - DateTime.Now).TotalDays <= 30 if (dernierAbo != null && (dernierAbo.DateFinAbonnement - DateTime.Now).TotalDays <= 30
&& (dernierAbo.DateFinAbonnement - DateTime.Now).TotalDays > 0) && (dernierAbo.DateFinAbonnement - DateTime.Now).TotalDays > 0)
{ {
message += $"- {revue.Titre} : finit le {dernierAbo.DateFinAbonnement:dd/MM/yyyy}\n"; stp.Append($"- {revue.Titre} : finit le {dernierAbo.DateFinAbonnement:dd/MM/yyyy}\n");
alerte = true; alerte = true;
} }
} }
if (alerte) if (alerte)
{ {
MessageBox.Show(message, "Alerte Abonnements", MessageBoxButtons.OK, MessageBoxIcon.Warning); MessageBox.Show(stp.ToString(), "Alerte Abonnements", MessageBoxButtons.OK, MessageBoxIcon.Warning);
} }
} }
private bool PeutSupprimerAbonnement(Abonnement abonnement) private bool PeutSupprimerAbonnement(Abonnement abonnement)
{ {
List<Exemplaire> exemplaires = controller.GetExemplairesRevue(abonnement.IdRevue); List<Exemplaire> exemplaires = controller.GetExemplairesRevue(abonnement.IdRevue);
foreach (Exemplaire ex in exemplaires) return !exemplaires.Exists(ex => ParutionDansAbonnement(abonnement.DateCommande,abonnement.DateFinAbonnement, ex.DateAchat));
{
if (ParutionDansAbonnement(abonnement.DateCommande, abonnement.DateFinAbonnement, ex.DateAchat))
{
return false;
}
}
return true;
} }
public bool ParutionDansAbonnement(DateTime dateCommande, DateTime dateFinAbonnement, DateTime dateParution) public bool ParutionDansAbonnement(DateTime dateCommande, DateTime dateFinAbonnement, DateTime dateParution)
@ -1920,7 +1912,7 @@ namespace MediaTekDocuments.view
private void btnAbonnementAjouter_Click(object sender, EventArgs e) private void btnAbonnementAjouter_Click(object sender, EventArgs e)
{ {
string idRevue = txbRevuesCommandesNumRecherche.Text; string idRevue = txbRevuesCommandesNumRecherche.Text;
if (idRevue.Equals("")) if (string.IsNullOrEmpty(idRevue))
{ {
MessageBox.Show("Veuillez d'abord sélectionner une revue.", "Information"); MessageBox.Show("Veuillez d'abord sélectionner une revue.", "Information");
return; return;

View file

@ -54,6 +54,7 @@
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="app.config" />
<None Include="packages.config" /> <None Include="packages.config" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View file

@ -14,22 +14,23 @@ namespace Mediatek.Tests
Utilisateur user = new Utilisateur("1", "admin", "philippe", "erwann", 1, "administration"); Utilisateur user = new Utilisateur("1", "admin", "philippe", "erwann", 1, "administration");
FrmMediatek frm = new FrmMediatek(user); FrmMediatek frm = new FrmMediatek(user);
DateTime debut = new DateTime(2024, 01, 01); // Ajout de DateTimeKind.Local à chaque création d'objet DateTime
DateTime fin = new DateTime(2024, 12, 31); DateTime debut = new DateTime(2024, 01, 01, 0, 0, 0, DateTimeKind.Local);
DateTime fin = new DateTime(2024, 12, 31, 0, 0, 0, DateTimeKind.Local);
DateTime parutionDebut = new DateTime(2024, 01, 01); DateTime parutionDebut = new DateTime(2024, 01, 01, 0, 0, 0, DateTimeKind.Local);
Assert.IsTrue(frm.ParutionDansAbonnement(debut, fin, parutionDebut), "La date de début devrait être incluse."); Assert.IsTrue(frm.ParutionDansAbonnement(debut, fin, parutionDebut), "La date de début devrait être incluse.");
DateTime parutionFin = new DateTime(2024, 12, 31); DateTime parutionFin = new DateTime(2024, 12, 31, 0, 0, 0, DateTimeKind.Local);
Assert.IsTrue(frm.ParutionDansAbonnement(debut, fin, parutionFin), "La date de fin devrait être incluse."); Assert.IsTrue(frm.ParutionDansAbonnement(debut, fin, parutionFin), "La date de fin devrait être incluse.");
DateTime parutionMilieu = new DateTime(2024, 06, 15); DateTime parutionMilieu = new DateTime(2024, 06, 15, 0, 0, 0, DateTimeKind.Local);
Assert.IsTrue(frm.ParutionDansAbonnement(debut, fin, parutionMilieu), "Une date en milieu d'abonnement doit être vraie."); Assert.IsTrue(frm.ParutionDansAbonnement(debut, fin, parutionMilieu), "Une date en milieu d'abonnement doit être vraie.");
DateTime parutionAvant = new DateTime(2023, 12, 31); DateTime parutionAvant = new DateTime(2023, 12, 31, 0, 0, 0, DateTimeKind.Local);
Assert.IsFalse(frm.ParutionDansAbonnement(debut, fin, parutionAvant), "Une date avant le début doit être fausse."); Assert.IsFalse(frm.ParutionDansAbonnement(debut, fin, parutionAvant), "Une date avant le début doit être fausse.");
DateTime parutionApres = new DateTime(2025, 01, 01); DateTime parutionApres = new DateTime(2025, 01, 01, 0, 0, 0, DateTimeKind.Local);
Assert.IsFalse(frm.ParutionDansAbonnement(debut, fin, parutionApres), "Une date après la fin doit être fausse."); Assert.IsFalse(frm.ParutionDansAbonnement(debut, fin, parutionApres), "Une date après la fin doit être fausse.");
} }
} }

23
Mediatek.Tests/app.config Normal file
View file

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.1.2" newVersion="4.0.1.2" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Google.Protobuf" publicKeyToken="a7d26565bac4d604" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.34.1.0" newVersion="3.34.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="K4os.Compression.LZ4.Streams" publicKeyToken="2186fa9121ef231d" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.3.8.0" newVersion="1.3.8.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>