diff --git a/MediaTekDocuments/MediaTekDocuments.csproj b/MediaTekDocuments/MediaTekDocuments.csproj index 7feb7dc..c2d4120 100644 --- a/MediaTekDocuments/MediaTekDocuments.csproj +++ b/MediaTekDocuments/MediaTekDocuments.csproj @@ -61,11 +61,19 @@ + + + + Form + + + FrmAuth.cs + Form @@ -94,6 +102,9 @@ True Resources.resx + + FrmAuth.cs + FrmMediatek.cs diff --git a/MediaTekDocuments/Program.cs b/MediaTekDocuments/Program.cs index 8a7d02f..975e4a1 100644 --- a/MediaTekDocuments/Program.cs +++ b/MediaTekDocuments/Program.cs @@ -14,7 +14,15 @@ namespace MediaTekDocuments { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); - Application.Run(new FrmMediatek()); + + //Application.Run(new FrmAuth()); + FrmAuth auth = new FrmAuth(); + + if (auth.ShowDialog() == DialogResult.OK) + { + Utilisateur user = auth.user; + Application.Run(new FrmMediatek(user)); + } } } } diff --git a/MediaTekDocuments/controller/FrmAuthController.cs b/MediaTekDocuments/controller/FrmAuthController.cs new file mode 100644 index 0000000..e98af7d --- /dev/null +++ b/MediaTekDocuments/controller/FrmAuthController.cs @@ -0,0 +1,22 @@ +using System.Collections.Generic; +using MediaTekDocuments.model; +using MediaTekDocuments.dal; +using System; + +namespace MediaTekDocuments.controller +{ + class FrmAuthController + { + private readonly Access access; + + public FrmAuthController() + { + access = Access.GetInstance(); + } + + public Utilisateur GetConnection(string login, string pwd) + { + return access.GetConnection(login, pwd); + } + } +} diff --git a/MediaTekDocuments/dal/Access.cs b/MediaTekDocuments/dal/Access.cs index a6d165e..db35f21 100644 --- a/MediaTekDocuments/dal/Access.cs +++ b/MediaTekDocuments/dal/Access.cs @@ -360,5 +360,23 @@ namespace MediaTekDocuments.dal } catch { return false; } } + + public Utilisateur GetConnection(string login, string pwd) + { + Dictionary loginInfo = new Dictionary + { + { "identifiant", login }, + { "motDePasse", pwd } + }; + + string jsonLogin = JsonConvert.SerializeObject(loginInfo); + List lesUtilisateurs = TraitementRecup(GET, "utilisateur/" + jsonLogin, null); + + if (lesUtilisateurs != null && lesUtilisateurs.Count > 0) + { + return lesUtilisateurs[0]; + } + return null; + } } } diff --git a/MediaTekDocuments/model/Utilisateur.cs b/MediaTekDocuments/model/Utilisateur.cs new file mode 100644 index 0000000..5e9e356 --- /dev/null +++ b/MediaTekDocuments/model/Utilisateur.cs @@ -0,0 +1,19 @@ +public class Utilisateur +{ + public string Id { get; set; } + public string Identifiant { get; set; } + public string Nom { get; set; } + public string Prenom { get; set; } + public int IdService { get; set; } + public string LibelleService { get; set; } + + public Utilisateur(string id, string identifiant, string nom, string prenom, int idService, string libelleService) + { + this.Id = id; + this.Identifiant = identifiant; + this.Nom = nom; + this.Prenom = prenom; + this.IdService = idService; + this.LibelleService = libelleService; + } +} \ No newline at end of file diff --git a/MediaTekDocuments/view/FrmAuth.Designer.cs b/MediaTekDocuments/view/FrmAuth.Designer.cs new file mode 100644 index 0000000..30221b7 --- /dev/null +++ b/MediaTekDocuments/view/FrmAuth.Designer.cs @@ -0,0 +1,136 @@ + +namespace MediaTekDocuments.view +{ + partial class FrmAuth + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.grpAuthInfos = new System.Windows.Forms.GroupBox(); + this.btnLogin = new System.Windows.Forms.Button(); + this.txtPassword = new System.Windows.Forms.TextBox(); + this.label2 = new System.Windows.Forms.Label(); + this.txtIdentifiant = new System.Windows.Forms.TextBox(); + this.label1 = new System.Windows.Forms.Label(); + this.lblErreur = new System.Windows.Forms.Label(); + this.grpAuthInfos.SuspendLayout(); + this.SuspendLayout(); + // + // grpAuthInfos + // + this.grpAuthInfos.Controls.Add(this.lblErreur); + this.grpAuthInfos.Controls.Add(this.btnLogin); + this.grpAuthInfos.Controls.Add(this.txtPassword); + this.grpAuthInfos.Controls.Add(this.label2); + this.grpAuthInfos.Controls.Add(this.txtIdentifiant); + this.grpAuthInfos.Controls.Add(this.label1); + this.grpAuthInfos.Location = new System.Drawing.Point(13, 13); + this.grpAuthInfos.Name = "grpAuthInfos"; + this.grpAuthInfos.Size = new System.Drawing.Size(200, 118); + this.grpAuthInfos.TabIndex = 0; + this.grpAuthInfos.TabStop = false; + this.grpAuthInfos.Text = "Se connecter"; + // + // btnLogin + // + this.btnLogin.Location = new System.Drawing.Point(6, 89); + this.btnLogin.Name = "btnLogin"; + this.btnLogin.Size = new System.Drawing.Size(75, 23); + this.btnLogin.TabIndex = 4; + this.btnLogin.Text = "Connexion"; + this.btnLogin.UseVisualStyleBackColor = true; + this.btnLogin.Click += new System.EventHandler(this.btnLogin_Click); + // + // txtPassword + // + this.txtPassword.Location = new System.Drawing.Point(95, 43); + this.txtPassword.Name = "txtPassword"; + this.txtPassword.PasswordChar = '*'; + this.txtPassword.Size = new System.Drawing.Size(100, 20); + this.txtPassword.TabIndex = 3; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.label2.Location = new System.Drawing.Point(7, 46); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(82, 13); + this.label2.TabIndex = 2; + this.label2.Text = "mot de passe"; + // + // txtIdentifiant + // + this.txtIdentifiant.Location = new System.Drawing.Point(76, 17); + this.txtIdentifiant.Name = "txtIdentifiant"; + this.txtIdentifiant.Size = new System.Drawing.Size(100, 20); + this.txtIdentifiant.TabIndex = 1; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.label1.Location = new System.Drawing.Point(7, 20); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(63, 13); + this.label1.TabIndex = 0; + this.label1.Text = "identifiant"; + // + // lblErreur + // + this.lblErreur.AutoSize = true; + this.lblErreur.Location = new System.Drawing.Point(7, 73); + this.lblErreur.Name = "lblErreur"; + this.lblErreur.Size = new System.Drawing.Size(0, 13); + this.lblErreur.TabIndex = 5; + // + // FrmAuth + // + this.AcceptButton = this.btnLogin; + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(227, 143); + this.Controls.Add(this.grpAuthInfos); + this.Name = "FrmAuth"; + this.Text = "Connexion"; + this.Load += new System.EventHandler(this.FrmAuth_Load); + this.grpAuthInfos.ResumeLayout(false); + this.grpAuthInfos.PerformLayout(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.GroupBox grpAuthInfos; + private System.Windows.Forms.TextBox txtIdentifiant; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.TextBox txtPassword; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Button btnLogin; + private System.Windows.Forms.Label lblErreur; + } +} \ No newline at end of file diff --git a/MediaTekDocuments/view/FrmAuth.cs b/MediaTekDocuments/view/FrmAuth.cs new file mode 100644 index 0000000..9b90465 --- /dev/null +++ b/MediaTekDocuments/view/FrmAuth.cs @@ -0,0 +1,58 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System; +using System.Windows.Forms; +using MediaTekDocuments.model; +using MediaTekDocuments.controller; +using System.Collections.Generic; +using System.Linq; +using System.Drawing; +using System.IO; + +namespace MediaTekDocuments.view +{ + public partial class FrmAuth : Form + { + private readonly FrmAuthController controller; + public Utilisateur user { get; private set; } + + public FrmAuth() + { + InitializeComponent(); + this.controller = new FrmAuthController(); + } + + private void FrmAuth_Load(object sender, EventArgs e) + { + // + } + + private void btnLogin_Click(object sender, EventArgs e) + { + string identifiant = txtIdentifiant.Text; + string password = txtPassword.Text; + + Utilisateur user = controller.GetConnection(identifiant, password); + + if(user == null) + { + txtIdentifiant.Text = ""; + txtPassword.Text = ""; + lblErreur.Text = "Identifiant ou mot de passe invalide."; + return; + } + + if(user.LibelleService == "Culture") + { + MessageBox.Show("Vous n'êtes pas autorisé à accéder à cette application !", "Accès refusé", MessageBoxButtons.OK, MessageBoxIcon.Warning); + this.DialogResult = DialogResult.Abort; + this.Close(); + } + + this.user = user; + this.DialogResult = DialogResult.OK; + this.Close(); + } + } +} diff --git a/MediaTekDocuments/view/FrmAuth.resx b/MediaTekDocuments/view/FrmAuth.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/MediaTekDocuments/view/FrmAuth.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/MediaTekDocuments/view/FrmMediatek.cs b/MediaTekDocuments/view/FrmMediatek.cs index 7ee6f73..9ec3b17 100644 --- a/MediaTekDocuments/view/FrmMediatek.cs +++ b/MediaTekDocuments/view/FrmMediatek.cs @@ -17,6 +17,7 @@ namespace MediaTekDocuments.view { #region Commun private readonly FrmMediatekController controller; + private readonly Utilisateur user; private readonly BindingSource bdgGenres = new BindingSource(); private readonly BindingSource bdgPublics = new BindingSource(); private readonly BindingSource bdgRayons = new BindingSource(); @@ -27,18 +28,30 @@ namespace MediaTekDocuments.view /// /// Constructeur : création du contrôleur lié à ce formulaire /// - public FrmMediatek() + public FrmMediatek(Utilisateur user) { InitializeComponent(); this.controller = new FrmMediatekController(); - this.controller = new FrmMediatekController(); + this.user = user; + this.Text += " - " + user.Prenom + " " + user.Nom; RemplirComboSuivi(controller.GetAllSuivis(), bdgSuivis, cboSuivi); RemplirComboSuivi(controller.GetAllSuivis(), bdgSuivis, cboSuiviDvd); cboSuivi.SelectedIndex = 0; cboSuiviDvd.SelectedIndex = 0; - AlerteAbonnementsExpirants(); + + if(user.LibelleService == "Prêts") + { + AlerteAbonnementsExpirants(); + } + + if(user.LibelleService == "Administratif") + { + tabOngletsApplication.TabPages.Remove(tabCommandesRevues); + tabOngletsApplication.TabPages.Remove(tabCommandeLivres); + tabOngletsApplication.TabPages.Remove(tabCommandeDvd); + } } /// @@ -94,16 +107,28 @@ namespace MediaTekDocuments.view dgvLivresListe.Columns["id"].DisplayIndex = 0; dgvLivresListe.Columns["titre"].DisplayIndex = 1; - dgvListeLivre2.DataSource = livres; - dgvListeLivre2.DataSource = bdgLivresListe; - dgvListeLivre2.Columns["isbn"].Visible = false; - dgvListeLivre2.Columns["idRayon"].Visible = false; - dgvListeLivre2.Columns["idGenre"].Visible = false; - dgvListeLivre2.Columns["idPublic"].Visible = false; - dgvListeLivre2.Columns["image"].Visible = false; - dgvListeLivre2.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells; - dgvListeLivre2.Columns["id"].DisplayIndex = 0; - dgvListeLivre2.Columns["titre"].DisplayIndex = 1; + RemplirDgvListeLivre2(livres); + } + + private void RemplirDgvListeLivre2(List livres) + { + if (tabOngletsApplication.TabPages.Contains(tabCommandeLivres)) + { + dgvListeLivre2.DataSource = null; + dgvListeLivre2.DataSource = bdgLivresListe; + + if (dgvListeLivre2.Columns.Count > 0 && dgvListeLivre2.Columns.Contains("isbn")) + { + dgvListeLivre2.Columns["isbn"].Visible = false; + dgvListeLivre2.Columns["idRayon"].Visible = false; + dgvListeLivre2.Columns["idGenre"].Visible = false; + dgvListeLivre2.Columns["idPublic"].Visible = false; + dgvListeLivre2.Columns["image"].Visible = false; + dgvListeLivre2.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells; + dgvListeLivre2.Columns["id"].DisplayIndex = 0; + dgvListeLivre2.Columns["titre"].DisplayIndex = 1; + } + } } /// @@ -421,16 +446,28 @@ namespace MediaTekDocuments.view dgvDvdListe.Columns["id"].DisplayIndex = 0; dgvDvdListe.Columns["titre"].DisplayIndex = 1; - dgvDvd.DataSource = Dvds; - dgvDvd.DataSource = bdgDvdListe; - dgvDvd.Columns["idRayon"].Visible = false; - dgvDvd.Columns["idGenre"].Visible = false; - dgvDvd.Columns["idPublic"].Visible = false; - dgvDvd.Columns["image"].Visible = false; - dgvDvd.Columns["synopsis"].Visible = false; - dgvDvd.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells; - dgvDvd.Columns["id"].DisplayIndex = 0; - dgvDvd.Columns["titre"].DisplayIndex = 1; + RemplirDgvDvd(Dvds); + } + + private void RemplirDgvDvd(List dvds) + { + if (tabOngletsApplication.TabPages.Contains(tabCommandeDvd)) + { + dgvDvd.DataSource = null; + dgvDvd.DataSource = bdgDvdListe; + + if (dgvDvd.Columns.Count > 0 && dgvDvd.Columns.Contains("idRayon")) + { + dgvDvd.Columns["idRayon"].Visible = false; + dgvDvd.Columns["idGenre"].Visible = false; + dgvDvd.Columns["idPublic"].Visible = false; + dgvDvd.Columns["image"].Visible = false; + dgvDvd.Columns["synopsis"].Visible = false; + dgvDvd.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells; + dgvDvd.Columns["id"].DisplayIndex = 0; + dgvDvd.Columns["titre"].DisplayIndex = 1; + } + } } /// diff --git a/MediaTekDocuments/view/FrmMediatek.resx b/MediaTekDocuments/view/FrmMediatek.resx index 70ff217..9c70bc2 100644 --- a/MediaTekDocuments/view/FrmMediatek.resx +++ b/MediaTekDocuments/view/FrmMediatek.resx @@ -120,7 +120,4 @@ True - - True - \ No newline at end of file