From 2e362003d7551f350ef43e3c3649fe1981be8963 Mon Sep 17 00:00:00 2001 From: Erwann PHILIPPE Date: Thu, 26 Mar 2026 15:42:48 +0100 Subject: [PATCH] Mission 2 finie. Gestion d'abonnement mise en place et fonctionnelle --- MediaTekDocuments.sln | 6 + MediaTekDocuments/MediaTekDocuments.csproj | 1 + .../controller/FrmMediatekController.cs | 15 + MediaTekDocuments/dal/Access.cs | 33 ++ MediaTekDocuments/model/Abonnement.cs | 22 ++ .../view/FrmMediatek.Designer.cs | 334 ++++++++++++++++++ MediaTekDocuments/view/FrmMediatek.cs | 191 +++++++++- MediaTekDocuments/view/FrmMediatek.resx | 3 + Mediatek.Tests/Mediatek.Tests.csproj | 75 ++++ Mediatek.Tests/Properties/AssemblyInfo.cs | 20 ++ Mediatek.Tests/UnitTest1.cs | 35 ++ Mediatek.Tests/packages.config | 5 + MediatekTests/MediatekTests.csproj | 68 ++++ MediatekTests/Properties/AssemblyInfo.cs | 20 ++ MediatekTests/UnitTest1.cs | 14 + MediatekTests/packages.config | 5 + 16 files changed, 846 insertions(+), 1 deletion(-) create mode 100644 MediaTekDocuments/model/Abonnement.cs create mode 100644 Mediatek.Tests/Mediatek.Tests.csproj create mode 100644 Mediatek.Tests/Properties/AssemblyInfo.cs create mode 100644 Mediatek.Tests/UnitTest1.cs create mode 100644 Mediatek.Tests/packages.config create mode 100644 MediatekTests/MediatekTests.csproj create mode 100644 MediatekTests/Properties/AssemblyInfo.cs create mode 100644 MediatekTests/UnitTest1.cs create mode 100644 MediatekTests/packages.config diff --git a/MediaTekDocuments.sln b/MediaTekDocuments.sln index 0f7c4c5..da4671b 100644 --- a/MediaTekDocuments.sln +++ b/MediaTekDocuments.sln @@ -5,6 +5,8 @@ VisualStudioVersion = 16.0.32413.511 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MediaTekDocuments", "MediaTekDocuments\MediaTekDocuments.csproj", "{75DE903D-6147-4E14-BBE0-FA20CD1F9840}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mediatek.Tests", "Mediatek.Tests\Mediatek.Tests.csproj", "{C5F4A786-C844-424C-BB13-F45C6C4CBB93}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -15,6 +17,10 @@ Global {75DE903D-6147-4E14-BBE0-FA20CD1F9840}.Debug|Any CPU.Build.0 = Debug|Any CPU {75DE903D-6147-4E14-BBE0-FA20CD1F9840}.Release|Any CPU.ActiveCfg = Release|Any CPU {75DE903D-6147-4E14-BBE0-FA20CD1F9840}.Release|Any CPU.Build.0 = Release|Any CPU + {C5F4A786-C844-424C-BB13-F45C6C4CBB93}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C5F4A786-C844-424C-BB13-F45C6C4CBB93}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C5F4A786-C844-424C-BB13-F45C6C4CBB93}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C5F4A786-C844-424C-BB13-F45C6C4CBB93}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/MediaTekDocuments/MediaTekDocuments.csproj b/MediaTekDocuments/MediaTekDocuments.csproj index 69098d9..7feb7dc 100644 --- a/MediaTekDocuments/MediaTekDocuments.csproj +++ b/MediaTekDocuments/MediaTekDocuments.csproj @@ -64,6 +64,7 @@ + Form diff --git a/MediaTekDocuments/controller/FrmMediatekController.cs b/MediaTekDocuments/controller/FrmMediatekController.cs index 9f62c81..403c129 100644 --- a/MediaTekDocuments/controller/FrmMediatekController.cs +++ b/MediaTekDocuments/controller/FrmMediatekController.cs @@ -127,5 +127,20 @@ namespace MediaTekDocuments.controller { return access.UpdateSuiviCommande(idCommande, idSuivi); } + + public List GetAbonnements(string idRevue) + { + return access.GetAbonnements(idRevue); + } + + public bool CreerAbonnement(Abonnement abonnement) + { + return access.CreerAbonnement(abonnement); + } + + public bool SupprimerAbonnement(Abonnement abonnement) + { + return access.SupprimerAbonnement(abonnement.Id); + } } } diff --git a/MediaTekDocuments/dal/Access.cs b/MediaTekDocuments/dal/Access.cs index c412ca8..a6d165e 100644 --- a/MediaTekDocuments/dal/Access.cs +++ b/MediaTekDocuments/dal/Access.cs @@ -327,5 +327,38 @@ namespace MediaTekDocuments.dal return false; } } + + public List GetAbonnements(string idRevue) + { + string jsonIdRevue = convertToJson("id", idRevue); + return TraitementRecup(GET, "commanderevue/" + jsonIdRevue, null); + } + + public bool CreerAbonnement(Abonnement abonnement) + { + string jsonAbonnement = JsonConvert.SerializeObject(abonnement, new CustomDateTimeConverter()); + try + { + JObject retour = api.RecupDistant(POST, "abonnement", "champs=" + jsonAbonnement); + + return retour["code"].ToString().Equals("200"); + } + catch (Exception ex) + { + Console.WriteLine("Erreur lors de l'accès à l'API : " + ex.Message); + return false; + } + } + + public bool SupprimerAbonnement(string idAbonnement) + { + string jsonId = convertToJson("id", idAbonnement); + try + { + JObject retour = api.RecupDistant(DELETE, "abonnement/" + jsonId, null); + return retour["code"].ToString().Equals("200"); + } + catch { return false; } + } } } diff --git a/MediaTekDocuments/model/Abonnement.cs b/MediaTekDocuments/model/Abonnement.cs new file mode 100644 index 0000000..5fd6ee4 --- /dev/null +++ b/MediaTekDocuments/model/Abonnement.cs @@ -0,0 +1,22 @@ +using System; + +namespace MediaTekDocuments.model +{ + public class Abonnement + { + public string Id { get; set; } + public DateTime DateCommande { get; set; } + public double Montant { get; set; } + public DateTime DateFinAbonnement { get; set; } + public string IdRevue { get; set; } + + public Abonnement(string id, DateTime dateCommande, double montant, DateTime dateFinAbonnement, string idRevue) + { + this.Id = id; + this.DateCommande = dateCommande; + this.Montant = montant; + this.DateFinAbonnement = dateFinAbonnement; + this.IdRevue = idRevue; + } + } +} \ No newline at end of file diff --git a/MediaTekDocuments/view/FrmMediatek.Designer.cs b/MediaTekDocuments/view/FrmMediatek.Designer.cs index bdf534b..18fcb4b 100644 --- a/MediaTekDocuments/view/FrmMediatek.Designer.cs +++ b/MediaTekDocuments/view/FrmMediatek.Designer.cs @@ -256,6 +256,33 @@ namespace MediaTekDocuments.view this.dgvDvd = new System.Windows.Forms.DataGridView(); this.txtRechercheDvd = new System.Windows.Forms.TextBox(); this.label78 = new System.Windows.Forms.Label(); + this.tabCommandesRevues = new System.Windows.Forms.TabPage(); + this.grpAbonnementSaisie = new System.Windows.Forms.GroupBox(); + this.btnAbonnementSupprimer = new System.Windows.Forms.Button(); + this.btnAbonnementAjouter = new System.Windows.Forms.Button(); + this.dtpAbonnementDateFin = new System.Windows.Forms.DateTimePicker(); + this.label101 = new System.Windows.Forms.Label(); + this.nudAbonnementMontant = new System.Windows.Forms.NumericUpDown(); + this.label100 = new System.Windows.Forms.Label(); + this.dtpAbonnementDateCommande = new System.Windows.Forms.DateTimePicker(); + this.label99 = new System.Windows.Forms.Label(); + this.grpAbonnementsInfos = new System.Windows.Forms.GroupBox(); + this.dgvAbonnements = new System.Windows.Forms.DataGridView(); + this.label98 = new System.Windows.Forms.Label(); + this.pictureBox1 = new System.Windows.Forms.PictureBox(); + this.label97 = new System.Windows.Forms.Label(); + this.txbRevuesCommandesRayon = new System.Windows.Forms.TextBox(); + this.label96 = new System.Windows.Forms.Label(); + this.txbRevuesCommandesPublic = new System.Windows.Forms.TextBox(); + this.txbRevuesCommandesGenre = new System.Windows.Forms.TextBox(); + this.label95 = new System.Windows.Forms.Label(); + this.txbRevuesCommandesPeriodicite = new System.Windows.Forms.TextBox(); + this.label94 = new System.Windows.Forms.Label(); + this.txbRevuesCommandesTitre = new System.Windows.Forms.TextBox(); + this.label93 = new System.Windows.Forms.Label(); + this.btnRevuesCommandesRechercher = new System.Windows.Forms.Button(); + this.txbRevuesCommandesNumRecherche = new System.Windows.Forms.TextBox(); + this.label92 = new System.Windows.Forms.Label(); this.tabOngletsApplication.SuspendLayout(); this.tabLivres.SuspendLayout(); this.grpLivresInfos.SuspendLayout(); @@ -295,6 +322,12 @@ namespace MediaTekDocuments.view this.grpDvdCommande.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dgvCommandesDvd)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.dgvDvd)).BeginInit(); + this.tabCommandesRevues.SuspendLayout(); + this.grpAbonnementSaisie.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.nudAbonnementMontant)).BeginInit(); + this.grpAbonnementsInfos.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dgvAbonnements)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); this.SuspendLayout(); // // tabOngletsApplication @@ -305,6 +338,7 @@ namespace MediaTekDocuments.view this.tabOngletsApplication.Controls.Add(this.tabReceptionRevue); this.tabOngletsApplication.Controls.Add(this.tabCommandeLivres); this.tabOngletsApplication.Controls.Add(this.tabCommandeDvd); + this.tabOngletsApplication.Controls.Add(this.tabCommandesRevues); this.tabOngletsApplication.Dock = System.Windows.Forms.DockStyle.Fill; this.tabOngletsApplication.ItemSize = new System.Drawing.Size(49, 18); this.tabOngletsApplication.Location = new System.Drawing.Point(0, 0); @@ -2689,6 +2723,271 @@ namespace MediaTekDocuments.view this.label78.TabIndex = 0; this.label78.Text = "Numéro de document :"; // + // tabCommandesRevues + // + this.tabCommandesRevues.Controls.Add(this.grpAbonnementSaisie); + this.tabCommandesRevues.Controls.Add(this.grpAbonnementsInfos); + this.tabCommandesRevues.Location = new System.Drawing.Point(4, 22); + this.tabCommandesRevues.Name = "tabCommandesRevues"; + this.tabCommandesRevues.Padding = new System.Windows.Forms.Padding(3); + this.tabCommandesRevues.Size = new System.Drawing.Size(875, 633); + this.tabCommandesRevues.TabIndex = 7; + this.tabCommandesRevues.Text = "Commandes Revues"; + this.tabCommandesRevues.UseVisualStyleBackColor = true; + this.tabCommandesRevues.Enter += new System.EventHandler(this.tabCommandeRevues_Enter); + // + // grpAbonnementSaisie + // + this.grpAbonnementSaisie.Controls.Add(this.btnAbonnementSupprimer); + this.grpAbonnementSaisie.Controls.Add(this.btnAbonnementAjouter); + this.grpAbonnementSaisie.Controls.Add(this.dtpAbonnementDateFin); + this.grpAbonnementSaisie.Controls.Add(this.label101); + this.grpAbonnementSaisie.Controls.Add(this.nudAbonnementMontant); + this.grpAbonnementSaisie.Controls.Add(this.label100); + this.grpAbonnementSaisie.Controls.Add(this.dtpAbonnementDateCommande); + this.grpAbonnementSaisie.Controls.Add(this.label99); + this.grpAbonnementSaisie.Enabled = false; + this.grpAbonnementSaisie.Location = new System.Drawing.Point(9, 410); + this.grpAbonnementSaisie.Name = "grpAbonnementSaisie"; + this.grpAbonnementSaisie.Size = new System.Drawing.Size(858, 215); + this.grpAbonnementSaisie.TabIndex = 1; + this.grpAbonnementSaisie.TabStop = false; + this.grpAbonnementSaisie.Text = "Nouvelle commande / renouvellement"; + // + // btnAbonnementSupprimer + // + this.btnAbonnementSupprimer.Location = new System.Drawing.Point(103, 103); + this.btnAbonnementSupprimer.Name = "btnAbonnementSupprimer"; + this.btnAbonnementSupprimer.Size = new System.Drawing.Size(75, 23); + this.btnAbonnementSupprimer.TabIndex = 7; + this.btnAbonnementSupprimer.Text = "Supprimer"; + this.btnAbonnementSupprimer.UseVisualStyleBackColor = true; + this.btnAbonnementSupprimer.Click += new System.EventHandler(this.btnAbonnementSupprimer_Click); + // + // btnAbonnementAjouter + // + this.btnAbonnementAjouter.Location = new System.Drawing.Point(10, 103); + this.btnAbonnementAjouter.Name = "btnAbonnementAjouter"; + this.btnAbonnementAjouter.Size = new System.Drawing.Size(75, 23); + this.btnAbonnementAjouter.TabIndex = 6; + this.btnAbonnementAjouter.Text = "Ajouter"; + this.btnAbonnementAjouter.UseVisualStyleBackColor = true; + this.btnAbonnementAjouter.Click += new System.EventHandler(this.btnAbonnementAjouter_Click); + // + // dtpAbonnementDateFin + // + this.dtpAbonnementDateFin.Location = new System.Drawing.Point(142, 71); + this.dtpAbonnementDateFin.Name = "dtpAbonnementDateFin"; + this.dtpAbonnementDateFin.Size = new System.Drawing.Size(200, 20); + this.dtpAbonnementDateFin.TabIndex = 5; + // + // label101 + // + this.label101.AutoSize = true; + this.label101.Location = new System.Drawing.Point(7, 77); + this.label101.Name = "label101"; + this.label101.Size = new System.Drawing.Size(129, 13); + this.label101.TabIndex = 4; + this.label101.Text = "Date de fin d\'abonnement"; + // + // nudAbonnementMontant + // + this.nudAbonnementMontant.Location = new System.Drawing.Point(58, 45); + this.nudAbonnementMontant.Name = "nudAbonnementMontant"; + this.nudAbonnementMontant.Size = new System.Drawing.Size(120, 20); + this.nudAbonnementMontant.TabIndex = 3; + // + // label100 + // + this.label100.AutoSize = true; + this.label100.Location = new System.Drawing.Point(6, 51); + this.label100.Name = "label100"; + this.label100.Size = new System.Drawing.Size(46, 13); + this.label100.TabIndex = 2; + this.label100.Text = "Montant"; + // + // dtpAbonnementDateCommande + // + this.dtpAbonnementDateCommande.Location = new System.Drawing.Point(113, 19); + this.dtpAbonnementDateCommande.Name = "dtpAbonnementDateCommande"; + this.dtpAbonnementDateCommande.Size = new System.Drawing.Size(200, 20); + this.dtpAbonnementDateCommande.TabIndex = 1; + // + // label99 + // + this.label99.AutoSize = true; + this.label99.Location = new System.Drawing.Point(7, 25); + this.label99.Name = "label99"; + this.label99.Size = new System.Drawing.Size(100, 13); + this.label99.TabIndex = 0; + this.label99.Text = "Date de commande"; + // + // grpAbonnementsInfos + // + this.grpAbonnementsInfos.Controls.Add(this.dgvAbonnements); + this.grpAbonnementsInfos.Controls.Add(this.label98); + this.grpAbonnementsInfos.Controls.Add(this.pictureBox1); + this.grpAbonnementsInfos.Controls.Add(this.label97); + this.grpAbonnementsInfos.Controls.Add(this.txbRevuesCommandesRayon); + this.grpAbonnementsInfos.Controls.Add(this.label96); + this.grpAbonnementsInfos.Controls.Add(this.txbRevuesCommandesPublic); + this.grpAbonnementsInfos.Controls.Add(this.txbRevuesCommandesGenre); + this.grpAbonnementsInfos.Controls.Add(this.label95); + this.grpAbonnementsInfos.Controls.Add(this.txbRevuesCommandesPeriodicite); + this.grpAbonnementsInfos.Controls.Add(this.label94); + this.grpAbonnementsInfos.Controls.Add(this.txbRevuesCommandesTitre); + this.grpAbonnementsInfos.Controls.Add(this.label93); + this.grpAbonnementsInfos.Controls.Add(this.btnRevuesCommandesRechercher); + this.grpAbonnementsInfos.Controls.Add(this.txbRevuesCommandesNumRecherche); + this.grpAbonnementsInfos.Controls.Add(this.label92); + this.grpAbonnementsInfos.Location = new System.Drawing.Point(9, 7); + this.grpAbonnementsInfos.Name = "grpAbonnementsInfos"; + this.grpAbonnementsInfos.Size = new System.Drawing.Size(858, 396); + this.grpAbonnementsInfos.TabIndex = 0; + this.grpAbonnementsInfos.TabStop = false; + this.grpAbonnementsInfos.Text = "Infos"; + // + // dgvAbonnements + // + this.dgvAbonnements.AllowUserToAddRows = false; + this.dgvAbonnements.AllowUserToDeleteRows = false; + this.dgvAbonnements.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dgvAbonnements.Location = new System.Drawing.Point(10, 149); + this.dgvAbonnements.Name = "dgvAbonnements"; + this.dgvAbonnements.ReadOnly = true; + this.dgvAbonnements.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; + this.dgvAbonnements.Size = new System.Drawing.Size(842, 241); + this.dgvAbonnements.TabIndex = 1; + this.dgvAbonnements.ColumnHeaderMouseClick += new System.Windows.Forms.DataGridViewCellMouseEventHandler(this.dgvAbonnements_ColumnHeaderMouseClick); + // + // label98 + // + this.label98.AutoSize = true; + this.label98.Location = new System.Drawing.Point(573, 50); + this.label98.Name = "label98"; + this.label98.Size = new System.Drawing.Size(36, 13); + this.label98.TabIndex = 14; + this.label98.Text = "Image"; + // + // pictureBox1 + // + this.pictureBox1.Location = new System.Drawing.Point(615, 47); + this.pictureBox1.Name = "pictureBox1"; + this.pictureBox1.Size = new System.Drawing.Size(100, 87); + this.pictureBox1.TabIndex = 13; + this.pictureBox1.TabStop = false; + // + // label97 + // + this.label97.AutoSize = true; + this.label97.Location = new System.Drawing.Point(386, 50); + this.label97.Name = "label97"; + this.label97.Size = new System.Drawing.Size(38, 13); + this.label97.TabIndex = 12; + this.label97.Text = "Rayon"; + // + // txbRevuesCommandesRayon + // + this.txbRevuesCommandesRayon.Location = new System.Drawing.Point(430, 47); + this.txbRevuesCommandesRayon.Name = "txbRevuesCommandesRayon"; + this.txbRevuesCommandesRayon.ReadOnly = true; + this.txbRevuesCommandesRayon.Size = new System.Drawing.Size(100, 20); + this.txbRevuesCommandesRayon.TabIndex = 11; + // + // label96 + // + this.label96.AutoSize = true; + this.label96.Location = new System.Drawing.Point(200, 81); + this.label96.Name = "label96"; + this.label96.Size = new System.Drawing.Size(36, 13); + this.label96.TabIndex = 10; + this.label96.Text = "Public"; + // + // txbRevuesCommandesPublic + // + this.txbRevuesCommandesPublic.Location = new System.Drawing.Point(242, 78); + this.txbRevuesCommandesPublic.Name = "txbRevuesCommandesPublic"; + this.txbRevuesCommandesPublic.ReadOnly = true; + this.txbRevuesCommandesPublic.Size = new System.Drawing.Size(100, 20); + this.txbRevuesCommandesPublic.TabIndex = 9; + // + // txbRevuesCommandesGenre + // + this.txbRevuesCommandesGenre.Location = new System.Drawing.Point(242, 47); + this.txbRevuesCommandesGenre.Name = "txbRevuesCommandesGenre"; + this.txbRevuesCommandesGenre.ReadOnly = true; + this.txbRevuesCommandesGenre.Size = new System.Drawing.Size(100, 20); + this.txbRevuesCommandesGenre.TabIndex = 8; + // + // label95 + // + this.label95.AutoSize = true; + this.label95.Location = new System.Drawing.Point(200, 50); + this.label95.Name = "label95"; + this.label95.Size = new System.Drawing.Size(36, 13); + this.label95.TabIndex = 7; + this.label95.Text = "Genre"; + // + // txbRevuesCommandesPeriodicite + // + this.txbRevuesCommandesPeriodicite.Location = new System.Drawing.Point(68, 74); + this.txbRevuesCommandesPeriodicite.Name = "txbRevuesCommandesPeriodicite"; + this.txbRevuesCommandesPeriodicite.ReadOnly = true; + this.txbRevuesCommandesPeriodicite.Size = new System.Drawing.Size(100, 20); + this.txbRevuesCommandesPeriodicite.TabIndex = 6; + // + // label94 + // + this.label94.AutoSize = true; + this.label94.Location = new System.Drawing.Point(6, 77); + this.label94.Name = "label94"; + this.label94.Size = new System.Drawing.Size(56, 13); + this.label94.TabIndex = 5; + this.label94.Text = "Periodicite"; + // + // txbRevuesCommandesTitre + // + this.txbRevuesCommandesTitre.Location = new System.Drawing.Point(40, 47); + this.txbRevuesCommandesTitre.Name = "txbRevuesCommandesTitre"; + this.txbRevuesCommandesTitre.ReadOnly = true; + this.txbRevuesCommandesTitre.Size = new System.Drawing.Size(100, 20); + this.txbRevuesCommandesTitre.TabIndex = 4; + // + // label93 + // + this.label93.AutoSize = true; + this.label93.Location = new System.Drawing.Point(6, 50); + this.label93.Name = "label93"; + this.label93.Size = new System.Drawing.Size(28, 13); + this.label93.TabIndex = 3; + this.label93.Text = "Titre"; + // + // btnRevuesCommandesRechercher + // + this.btnRevuesCommandesRechercher.Location = new System.Drawing.Point(214, 15); + this.btnRevuesCommandesRechercher.Name = "btnRevuesCommandesRechercher"; + this.btnRevuesCommandesRechercher.Size = new System.Drawing.Size(75, 23); + this.btnRevuesCommandesRechercher.TabIndex = 2; + this.btnRevuesCommandesRechercher.Text = "Rechercher"; + this.btnRevuesCommandesRechercher.UseVisualStyleBackColor = true; + this.btnRevuesCommandesRechercher.Click += new System.EventHandler(this.btnRevuesCommandesRechercher_Click); + // + // txbRevuesCommandesNumRecherche + // + this.txbRevuesCommandesNumRecherche.Location = new System.Drawing.Point(108, 17); + this.txbRevuesCommandesNumRecherche.Name = "txbRevuesCommandesNumRecherche"; + this.txbRevuesCommandesNumRecherche.Size = new System.Drawing.Size(100, 20); + this.txbRevuesCommandesNumRecherche.TabIndex = 1; + // + // label92 + // + this.label92.AutoSize = true; + this.label92.Location = new System.Drawing.Point(7, 20); + this.label92.Name = "label92"; + this.label92.Size = new System.Drawing.Size(95, 13); + this.label92.TabIndex = 0; + this.label92.Text = "Numéro de revue :"; + // // FrmMediatek // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -2750,6 +3049,14 @@ namespace MediaTekDocuments.view this.grpDvdCommande.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.dgvCommandesDvd)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.dgvDvd)).EndInit(); + this.tabCommandesRevues.ResumeLayout(false); + this.grpAbonnementSaisie.ResumeLayout(false); + this.grpAbonnementSaisie.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.nudAbonnementMontant)).EndInit(); + this.grpAbonnementsInfos.ResumeLayout(false); + this.grpAbonnementsInfos.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dgvAbonnements)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); this.ResumeLayout(false); } @@ -2983,6 +3290,33 @@ namespace MediaTekDocuments.view private System.Windows.Forms.Label label90; private System.Windows.Forms.DateTimePicker dateTimeCommandeDvd; private System.Windows.Forms.Label label91; + private System.Windows.Forms.TabPage tabCommandesRevues; + private System.Windows.Forms.GroupBox grpAbonnementsInfos; + private System.Windows.Forms.Label label93; + private System.Windows.Forms.Button btnRevuesCommandesRechercher; + private System.Windows.Forms.TextBox txbRevuesCommandesNumRecherche; + private System.Windows.Forms.Label label92; + private System.Windows.Forms.Label label94; + private System.Windows.Forms.TextBox txbRevuesCommandesTitre; + private System.Windows.Forms.Label label97; + private System.Windows.Forms.TextBox txbRevuesCommandesRayon; + private System.Windows.Forms.Label label96; + private System.Windows.Forms.TextBox txbRevuesCommandesPublic; + private System.Windows.Forms.TextBox txbRevuesCommandesGenre; + private System.Windows.Forms.Label label95; + private System.Windows.Forms.TextBox txbRevuesCommandesPeriodicite; + private System.Windows.Forms.Label label98; + private System.Windows.Forms.PictureBox pictureBox1; + private System.Windows.Forms.DataGridView dgvAbonnements; + private System.Windows.Forms.GroupBox grpAbonnementSaisie; + private System.Windows.Forms.Button btnAbonnementSupprimer; + private System.Windows.Forms.Button btnAbonnementAjouter; + private System.Windows.Forms.DateTimePicker dtpAbonnementDateFin; + private System.Windows.Forms.Label label101; + private System.Windows.Forms.NumericUpDown nudAbonnementMontant; + private System.Windows.Forms.Label label100; + private System.Windows.Forms.DateTimePicker dtpAbonnementDateCommande; + private System.Windows.Forms.Label label99; } } diff --git a/MediaTekDocuments/view/FrmMediatek.cs b/MediaTekDocuments/view/FrmMediatek.cs index 4f7944e..7ee6f73 100644 --- a/MediaTekDocuments/view/FrmMediatek.cs +++ b/MediaTekDocuments/view/FrmMediatek.cs @@ -21,11 +21,13 @@ namespace MediaTekDocuments.view private readonly BindingSource bdgPublics = new BindingSource(); private readonly BindingSource bdgRayons = new BindingSource(); private readonly BindingSource bdgSuivis = new BindingSource(); + private readonly BindingSource bdgAbonnements = new BindingSource(); + private List lesAbonnements = new List(); /// /// Constructeur : création du contrôleur lié à ce formulaire /// - internal FrmMediatek() + public FrmMediatek() { InitializeComponent(); this.controller = new FrmMediatekController(); @@ -36,6 +38,7 @@ namespace MediaTekDocuments.view cboSuivi.SelectedIndex = 0; cboSuiviDvd.SelectedIndex = 0; + AlerteAbonnementsExpirants(); } /// @@ -1772,5 +1775,191 @@ namespace MediaTekDocuments.view } } } + + private void AlerteAbonnementsExpirants() + { + List toutesLesRevues = controller.GetAllRevues(); + string message = "Abonnements se terminant sous 30 jours :\n"; + bool alerte = false; + + foreach (Revue revue in toutesLesRevues) + { + List abos = controller.GetAbonnements(revue.Id); + // On prend le dernier abonnement (le plus récent) + Abonnement dernierAbo = abos.OrderByDescending(a => a.DateFinAbonnement).FirstOrDefault(); + + if (dernierAbo != null && (dernierAbo.DateFinAbonnement - DateTime.Now).TotalDays <= 30 + && (dernierAbo.DateFinAbonnement - DateTime.Now).TotalDays > 0) + { + message += $"- {revue.Titre} : finit le {dernierAbo.DateFinAbonnement:dd/MM/yyyy}\n"; + alerte = true; + } + } + + if (alerte) + { + MessageBox.Show(message, "Alerte Abonnements", MessageBoxButtons.OK, MessageBoxIcon.Warning); + } + } + + private bool PeutSupprimerAbonnement(Abonnement abonnement) + { + List exemplaires = controller.GetExemplairesRevue(abonnement.IdRevue); + foreach (Exemplaire ex in exemplaires) + { + if (ParutionDansAbonnement(abonnement.DateCommande, abonnement.DateFinAbonnement, ex.DateAchat)) + { + return false; + } + } + return true; + } + + public bool ParutionDansAbonnement(DateTime dateCommande, DateTime dateFinAbonnement, DateTime dateParution) + { + return (dateParution >= dateCommande && dateParution <= dateFinAbonnement); + } + + private void btnRevuesCommandesRechercher_Click(object sender, EventArgs e) + { + if (!txbRevuesCommandesNumRecherche.Text.Equals("")) + { + Revue revue = lesRevues.Find(x => x.Id.Equals(txbRevuesCommandesNumRecherche.Text)); + if (revue != null) + { + AfficheRevueInfosCommande(revue); + } + else + { + MessageBox.Show("Numéro de revue introuvable"); + } + } + } + + private void AfficheRevueInfosCommande(Revue revue) + { + txbRevuesCommandesTitre.Text = revue.Titre; + txbRevuesCommandesGenre.Text = revue.Genre; + txbRevuesCommandesPublic.Text = revue.Public; + txbRevuesCommandesRayon.Text = revue.Rayon; + txbRevuesCommandesPeriodicite.Text = revue.Periodicite; + + lesAbonnements = controller.GetAbonnements(revue.Id) + .OrderByDescending(a => a.DateCommande) + .ToList(); + RemplirAbonnementsListe(lesAbonnements); + grpAbonnementSaisie.Enabled = true; + } + + private void RemplirAbonnementsListe(List abonnements) + { + bdgAbonnements.DataSource = abonnements; + dgvAbonnements.DataSource = bdgAbonnements; + dgvAbonnements.Columns["id"].Visible = false; + dgvAbonnements.Columns["idRevue"].Visible = false; + dgvAbonnements.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + } + + private void tabCommandeRevues_Enter(object sender, EventArgs e) + { + // On charge la liste des revues pour permettre la recherche par numéro + lesRevues = controller.GetAllRevues(); + // On vide les champs par sécurité au cas où une recherche précédente resterait + ViderAbonnementChamps(); + } + + private void ViderAbonnementChamps() + { + txbRevuesCommandesNumRecherche.Text = ""; + txbRevuesCommandesTitre.Text = ""; + txbRevuesCommandesGenre.Text = ""; + txbRevuesCommandesPublic.Text = ""; + txbRevuesCommandesRayon.Text = ""; + txbRevuesCommandesPeriodicite.Text = ""; + RemplirAbonnementsListe(new List()); + grpAbonnementSaisie.Enabled = false; + } + + private void btnAbonnementAjouter_Click(object sender, EventArgs e) + { + string idRevue = txbRevuesCommandesNumRecherche.Text; + if (idRevue.Equals("")) + { + MessageBox.Show("Veuillez d'abord sélectionner une revue.", "Information"); + return; + } + DateTime dateCommande = dtpAbonnementDateCommande.Value; + DateTime dateFin = dtpAbonnementDateFin.Value; + double montant = (double)nudAbonnementMontant.Value; + if (dateFin <= dateCommande) + { + MessageBox.Show("La date de fin d'abonnement doit être supérieure à la date de commande.", "Erreur de saisie"); + return; + } + string nextId = controller.GetNextCommandeId(); + Abonnement nouvelAbo = new Abonnement(nextId, dateCommande, montant, dateFin, idRevue); + + if (controller.CreerAbonnement(nouvelAbo)) + { + MessageBox.Show("Abonnement enregistré avec succès.", "Succès"); + AfficheRevueInfosCommande(lesRevues.Find(r => r.Id == idRevue)); + } + else + { + MessageBox.Show("Erreur lors de l'enregistrement de l'abonnement.", "Erreur"); + } + } + + private void btnAbonnementSupprimer_Click(object sender, EventArgs e) + { + if (dgvAbonnements.CurrentRow == null) + { + MessageBox.Show("Veuillez sélectionner un abonnement dans la liste.", "Information"); + return; + } + Abonnement aboSelectionne = (Abonnement)bdgAbonnements.List[bdgAbonnements.Position]; + if (PeutSupprimerAbonnement(aboSelectionne)) + { + if (MessageBox.Show($"Voulez-vous vraiment supprimer l'abonnement n°{aboSelectionne.Id} ?", + "Confirmation de suppression", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + if (controller.SupprimerAbonnement(aboSelectionne)) + { + MessageBox.Show("Abonnement supprimé avec succès."); + AfficheRevueInfosCommande(lesRevues.Find(r => r.Id == aboSelectionne.IdRevue)); + } + else + { + MessageBox.Show("Une erreur est survenue lors de la suppression sur le serveur."); + } + } + } + else + { + MessageBox.Show("Suppression impossible : un ou plusieurs exemplaires ont été reçus pendant la période de cet abonnement.", "Règle de gestion"); + } + } + + private void dgvAbonnements_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e) + { + string titreColonne = dgvAbonnements.Columns[e.ColumnIndex].DataPropertyName; + List sortedList; + + switch (titreColonne) + { + case "DateCommande": + sortedList = lesAbonnements.OrderBy(o => o.DateCommande).ToList(); + break; + case "Montant": + sortedList = lesAbonnements.OrderBy(o => o.Montant).ToList(); + break; + case "DateFinAbonnement": + sortedList = lesAbonnements.OrderBy(o => o.DateFinAbonnement).ToList(); + break; + default: + return; + } + bdgAbonnements.DataSource = sortedList; + } } } diff --git a/MediaTekDocuments/view/FrmMediatek.resx b/MediaTekDocuments/view/FrmMediatek.resx index 9c70bc2..70ff217 100644 --- a/MediaTekDocuments/view/FrmMediatek.resx +++ b/MediaTekDocuments/view/FrmMediatek.resx @@ -120,4 +120,7 @@ True + + True + \ No newline at end of file diff --git a/Mediatek.Tests/Mediatek.Tests.csproj b/Mediatek.Tests/Mediatek.Tests.csproj new file mode 100644 index 0000000..3ac5e17 --- /dev/null +++ b/Mediatek.Tests/Mediatek.Tests.csproj @@ -0,0 +1,75 @@ + + + + + + Debug + AnyCPU + {C5F4A786-C844-424C-BB13-F45C6C4CBB93} + Library + Properties + Mediatek.Tests + Mediatek.Tests + v4.7.2 + 512 + {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 15.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages + False + UnitTest + + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\MSTest.TestFramework.2.1.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll + + + ..\packages\MSTest.TestFramework.2.1.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll + + + + + + + + + + + + + + + {75de903d-6147-4e14-bbe0-fa20cd1f9840} + MediaTekDocuments + + + + + + + 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}. + + + + + + \ No newline at end of file diff --git a/Mediatek.Tests/Properties/AssemblyInfo.cs b/Mediatek.Tests/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..8eba767 --- /dev/null +++ b/Mediatek.Tests/Properties/AssemblyInfo.cs @@ -0,0 +1,20 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +[assembly: AssemblyTitle("Mediatek.Tests")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Mediatek.Tests")] +[assembly: AssemblyCopyright("Copyright © 2026")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +[assembly: ComVisible(false)] + +[assembly: Guid("c5f4a786-c844-424c-bb13-f45c6c4cbb93")] + +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Mediatek.Tests/UnitTest1.cs b/Mediatek.Tests/UnitTest1.cs new file mode 100644 index 0000000..d6e1cdd --- /dev/null +++ b/Mediatek.Tests/UnitTest1.cs @@ -0,0 +1,35 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using MediaTekDocuments.model; +using MediaTekDocuments.view; // Nécessaire car la méthode à tester est dans FrmMediatek + +namespace Mediatek.Tests +{ + [TestClass] + public class CommandeTests + { + [TestMethod] + public void TestParutionDansAbonnement_ValidationDates() + { + FrmMediatek frm = new FrmMediatek(); + + DateTime debut = new DateTime(2024, 01, 01); + DateTime fin = new DateTime(2024, 12, 31); + + DateTime parutionDebut = new DateTime(2024, 01, 01); + Assert.IsTrue(frm.ParutionDansAbonnement(debut, fin, parutionDebut), "La date de début devrait être incluse."); + + DateTime parutionFin = new DateTime(2024, 12, 31); + Assert.IsTrue(frm.ParutionDansAbonnement(debut, fin, parutionFin), "La date de fin devrait être incluse."); + + DateTime parutionMilieu = new DateTime(2024, 06, 15); + Assert.IsTrue(frm.ParutionDansAbonnement(debut, fin, parutionMilieu), "Une date en milieu d'abonnement doit être vraie."); + + DateTime parutionAvant = new DateTime(2023, 12, 31); + Assert.IsFalse(frm.ParutionDansAbonnement(debut, fin, parutionAvant), "Une date avant le début doit être fausse."); + + DateTime parutionApres = new DateTime(2025, 01, 01); + Assert.IsFalse(frm.ParutionDansAbonnement(debut, fin, parutionApres), "Une date après la fin doit être fausse."); + } + } +} \ No newline at end of file diff --git a/Mediatek.Tests/packages.config b/Mediatek.Tests/packages.config new file mode 100644 index 0000000..f84cb10 --- /dev/null +++ b/Mediatek.Tests/packages.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/MediatekTests/MediatekTests.csproj b/MediatekTests/MediatekTests.csproj new file mode 100644 index 0000000..5f20618 --- /dev/null +++ b/MediatekTests/MediatekTests.csproj @@ -0,0 +1,68 @@ + + + + + + Debug + AnyCPU + {AFBF991E-F823-46DF-A9B5-07E920AD7061} + Library + Properties + MediatekTests + MediatekTests + v4.7.2 + 512 + {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 15.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages + False + UnitTest + + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\MSTest.TestFramework.2.1.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll + + + ..\packages\MSTest.TestFramework.2.1.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll + + + + + + + + + + + + + + + + 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}. + + + + + + \ No newline at end of file diff --git a/MediatekTests/Properties/AssemblyInfo.cs b/MediatekTests/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..fc65b42 --- /dev/null +++ b/MediatekTests/Properties/AssemblyInfo.cs @@ -0,0 +1,20 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +[assembly: AssemblyTitle("MediatekTests")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("MediatekTests")] +[assembly: AssemblyCopyright("Copyright © 2026")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +[assembly: ComVisible(false)] + +[assembly: Guid("afbf991e-f823-46df-a9b5-07e920ad7061")] + +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/MediatekTests/UnitTest1.cs b/MediatekTests/UnitTest1.cs new file mode 100644 index 0000000..6a7069c --- /dev/null +++ b/MediatekTests/UnitTest1.cs @@ -0,0 +1,14 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; + +namespace MediatekTests +{ + [TestClass] + public class UnitTest1 + { + [TestMethod] + public void TestMethod1() + { + } + } +} diff --git a/MediatekTests/packages.config b/MediatekTests/packages.config new file mode 100644 index 0000000..f84cb10 --- /dev/null +++ b/MediatekTests/packages.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file