From 1c3d6ab0e503dad8f3bc1c1c0be8b992268f3e9e Mon Sep 17 00:00:00 2001 From: gamondue Date: Sat, 20 Mar 2021 09:25:55 +0100 Subject: [PATCH 1/2] Creation of form frmUsersManagement, temporary non compiling version to sycnronize with developers. --- BusinessLayer/BusinessLayer.cs | 4 ++ DataLayer/DataLayer.cs | 9 ++- DbClasses/User.cs | 4 +- SchoolGrades/frmLogin.cs | 26 ++++----- SchoolGrades/frmUsersManagement.Designer.cs | 62 +++++++++++++++++++++ SchoolGrades/frmUsersManagement.cs | 32 +++++++++++ SchoolGrades/frmUsersManagement.resx | 60 ++++++++++++++++++++ 7 files changed, 182 insertions(+), 15 deletions(-) create mode 100644 SchoolGrades/frmUsersManagement.Designer.cs create mode 100644 SchoolGrades/frmUsersManagement.cs create mode 100644 SchoolGrades/frmUsersManagement.resx diff --git a/BusinessLayer/BusinessLayer.cs b/BusinessLayer/BusinessLayer.cs index 83d871b..3cc18cf 100644 --- a/BusinessLayer/BusinessLayer.cs +++ b/BusinessLayer/BusinessLayer.cs @@ -21,6 +21,10 @@ internal User GetUser(string Username) { return dl.GetUser(Username); } + internal List GetAllUsers() + { + return dl.GetAllUsers(); + } internal bool UserHasLoginPermission(string Username, string Password) { User uFromDb = GetUser(Username); diff --git a/DataLayer/DataLayer.cs b/DataLayer/DataLayer.cs index 17b9087..5be76c8 100644 --- a/DataLayer/DataLayer.cs +++ b/DataLayer/DataLayer.cs @@ -1,5 +1,6 @@ using SchoolGrades.DbClasses; using System; +using System.Collections.Generic; using System.Data.Common; using System.Data.SQLite; @@ -24,6 +25,12 @@ public DataLayer() } dbName = Commons.PathAndFileDatabase; } + + internal List GetAllUsers() + { + throw new NotImplementedException(); + } + public DataLayer(string PathAndFile) { if (!System.IO.File.Exists(PathAndFile)) @@ -85,7 +92,7 @@ internal User GetUser(string Username) } return t; } - internal User GetUserFromRow(DbDataReader dRead) + private User GetUserFromRow(DbDataReader dRead) { User u = null; if (dRead.HasRows) diff --git a/DbClasses/User.cs b/DbClasses/User.cs index dfbaf95..7b9ccd6 100644 --- a/DbClasses/User.cs +++ b/DbClasses/User.cs @@ -18,9 +18,10 @@ class User public string Username { get => username; set => username = value; } public string LastName { get => lastName; set => lastName = value; } + public string FirstName { get => firstName; set => firstName = value; } public string Password { get => password; set => password = value; } public string Description { get => description; set => description = value; } - public string FirstName { get => firstName; set => firstName = value; } + private int idUserType; public string Email { get => email; set => email = value; } public DateTime? CreationTime { get => create_time; set => create_time = value; } public DateTime? LastChange { get; internal set; } @@ -28,6 +29,7 @@ class User public string Salt { get => salt; set => salt = value; } public int? IdUserCategory { get => idUserCategory; set => idUserCategory = value; } public bool? IsEnabled { get; internal set; } + public int IdUserType { get => idUserType; set => idUserType = value; } public User(string Username, string Password) { diff --git a/SchoolGrades/frmLogin.cs b/SchoolGrades/frmLogin.cs index 82a6433..bcc483b 100644 --- a/SchoolGrades/frmLogin.cs +++ b/SchoolGrades/frmLogin.cs @@ -19,21 +19,21 @@ private void frmLogin_Load(object sender, EventArgs e) bl = new BusinessLayer.BusinessLayer(); //// test examples - //User u; - //u = new User("pippo", "pluto"); - ////u = new User("pina", "pluto"); - //////u = new User("ugo", "pina"); - ////bl.CreateUser(u); - //u.Password = "mariangela"; - //bl.ChangePassword(u); + User u; + u = new User("pippo", "pluto"); + //u = new User("pina", "pluto"); + ////u = new User("ugo", "pina"); + //bl.CreateUser(u); + u.Password = "mariangela"; + bl.ChangePassword(u); - //u.FirstName = "Ugo"; - //u.LastName = "Fantozzi"; - //u.Email = "u.fantozzi@megaditta.com"; - //u.Description = "Inferiore Rag. Ugo Fantozzi"; - //bl.UpdateUser(u); + u.FirstName = "Ugo"; + u.LastName = "Fantozzi"; + u.Email = "u.fantozzi@megaditta.com"; + u.Description = "Inferiore Rag. Ugo Fantozzi"; + bl.UpdateUser(u); - //User u1 = bl.GetUser("ugo"); + User u1 = bl.GetUser("ugo"); } private void btnOk_Click(object sender, EventArgs e) { diff --git a/SchoolGrades/frmUsersManagement.Designer.cs b/SchoolGrades/frmUsersManagement.Designer.cs new file mode 100644 index 0000000..1f1054e --- /dev/null +++ b/SchoolGrades/frmUsersManagement.Designer.cs @@ -0,0 +1,62 @@ + +namespace SchoolGrades +{ + partial class frmUsersManagement + { + /// + /// 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.listBox1 = new System.Windows.Forms.ListBox(); + this.SuspendLayout(); + // + // listBox1 + // + this.listBox1.FormattingEnabled = true; + this.listBox1.ItemHeight = 20; + this.listBox1.Location = new System.Drawing.Point(29, 33); + this.listBox1.Name = "listBox1"; + this.listBox1.Size = new System.Drawing.Size(150, 484); + this.listBox1.TabIndex = 0; + this.listBox1.SelectedIndexChanged += new System.EventHandler(this.listBox1_SelectedIndexChanged); + // + // frmUsersManagement + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(980, 551); + this.Controls.Add(this.listBox1); + this.Name = "frmUsersManagement"; + this.Text = "frmUsersManagement"; + this.Load += new System.EventHandler(this.frmUsersManagement_Load); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.ListBox listBox1; + } +} \ No newline at end of file diff --git a/SchoolGrades/frmUsersManagement.cs b/SchoolGrades/frmUsersManagement.cs new file mode 100644 index 0000000..2a0c5ae --- /dev/null +++ b/SchoolGrades/frmUsersManagement.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Text; +using System.Windows.Forms; +using SchoolGrades.BusinessLayer; +using SchoolGrades.DbClasses; + +namespace SchoolGrades +{ + public partial class frmUsersManagement : Form + { + BusinessLayer.BusinessLayer bl = new BusinessLayer.BusinessLayer(); + + public frmUsersManagement() + { + InitializeComponent(); + } + + private void frmUsersManagement_Load(object sender, EventArgs e) + { + listBox1.DataSource = bl.GetAllUsers(); + } + + private void listBox1_SelectedIndexChanged(object sender, EventArgs e) + { + UserControl currentUser = (User)listBox1[listBox1.SelectedIndex]; + } + } +} diff --git a/SchoolGrades/frmUsersManagement.resx b/SchoolGrades/frmUsersManagement.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/SchoolGrades/frmUsersManagement.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 From ff98d409415aa380246c289f3b13ca1613eeaf42 Mon Sep 17 00:00:00 2001 From: Gabriele MONTI Date: Sat, 20 Mar 2021 20:27:23 +0100 Subject: [PATCH 2/2] Added code of the method GetAllUsers to DataLayer, working. Added ToString() to Class User. Added call to frmClassesManagement to frmSetup. --- DataLayer/DataLayer.cs | 27 ++++++++++++++++----- DbClasses/User.cs | 5 ++++ SchoolGrades/frmLogin.cs | 2 +- SchoolGrades/frmQuestionChoose.Designer.cs | 12 ++++----- SchoolGrades/frmSetup.Designer.cs | 3 +-- SchoolGrades/frmSetup.cs | 4 ++- SchoolGrades/frmUsersManagement.Designer.cs | 20 +++++++-------- SchoolGrades/frmUsersManagement.cs | 16 ++++++------ 8 files changed, 54 insertions(+), 35 deletions(-) diff --git a/DataLayer/DataLayer.cs b/DataLayer/DataLayer.cs index 5be76c8..359ea09 100644 --- a/DataLayer/DataLayer.cs +++ b/DataLayer/DataLayer.cs @@ -25,12 +25,6 @@ public DataLayer() } dbName = Commons.PathAndFileDatabase; } - - internal List GetAllUsers() - { - throw new NotImplementedException(); - } - public DataLayer(string PathAndFile) { if (!System.IO.File.Exists(PathAndFile)) @@ -92,6 +86,27 @@ internal User GetUser(string Username) } return t; } + internal List GetAllUsers() + { + List l = new List(); + using (DbConnection conn = Connect()) + { + DbCommand cmd = conn.CreateCommand(); + string query = "SELECT *" + + " FROM Users"; + cmd = new SQLiteCommand(query); + cmd.Connection = conn; + DbDataReader dRead = cmd.ExecuteReader(); + while (dRead.Read()) + { + User u = GetUserFromRow(dRead); + l.Add(u); + } + dRead.Dispose(); + cmd.Dispose(); + } + return l; + } private User GetUserFromRow(DbDataReader dRead) { User u = null; diff --git a/DbClasses/User.cs b/DbClasses/User.cs index 7b9ccd6..6590cfe 100644 --- a/DbClasses/User.cs +++ b/DbClasses/User.cs @@ -36,5 +36,10 @@ public User(string Username, string Password) this.username = Username; this.password = Password; } + + public override string ToString() + { + return Username + ": "+ Description; + } } } diff --git a/SchoolGrades/frmLogin.cs b/SchoolGrades/frmLogin.cs index bcc483b..8ac3324 100644 --- a/SchoolGrades/frmLogin.cs +++ b/SchoolGrades/frmLogin.cs @@ -18,7 +18,7 @@ private void frmLogin_Load(object sender, EventArgs e) db = new DbAndBusiness(); bl = new BusinessLayer.BusinessLayer(); - //// test examples + // test examples User u; u = new User("pippo", "pluto"); //u = new User("pina", "pluto"); diff --git a/SchoolGrades/frmQuestionChoose.Designer.cs b/SchoolGrades/frmQuestionChoose.Designer.cs index 14a67c0..dfe0bac 100644 --- a/SchoolGrades/frmQuestionChoose.Designer.cs +++ b/SchoolGrades/frmQuestionChoose.Designer.cs @@ -178,7 +178,7 @@ private void InitializeComponent() this.txtTopic.Location = new System.Drawing.Point(102, 27); this.txtTopic.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.txtTopic.Name = "txtTopic"; - this.txtTopic.Size = new System.Drawing.Size(694, 24); + this.txtTopic.Size = new System.Drawing.Size(705, 24); this.txtTopic.TabIndex = 0; // // grpQuestions @@ -450,7 +450,7 @@ private void InitializeComponent() this.cmbQuestionTypes.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.cmbQuestionTypes.Font = new System.Drawing.Font("Microsoft Sans Serif", 11F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); this.cmbQuestionTypes.FormattingEnabled = true; - this.cmbQuestionTypes.Location = new System.Drawing.Point(253, 27); + this.cmbQuestionTypes.Location = new System.Drawing.Point(246, 27); this.cmbQuestionTypes.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.cmbQuestionTypes.Name = "cmbQuestionTypes"; this.cmbQuestionTypes.Size = new System.Drawing.Size(233, 26); @@ -479,7 +479,7 @@ private void InitializeComponent() // lblQuestionType // this.lblQuestionType.AutoSize = true; - this.lblQuestionType.Location = new System.Drawing.Point(250, 6); + this.lblQuestionType.Location = new System.Drawing.Point(243, 6); this.lblQuestionType.Name = "lblQuestionType"; this.lblQuestionType.Size = new System.Drawing.Size(103, 18); this.lblQuestionType.TabIndex = 7; @@ -538,17 +538,17 @@ private void InitializeComponent() // this.txtSearchText.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); - this.txtSearchText.Location = new System.Drawing.Point(509, 28); + this.txtSearchText.Location = new System.Drawing.Point(485, 28); this.txtSearchText.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.txtSearchText.Name = "txtSearchText"; - this.txtSearchText.Size = new System.Drawing.Size(349, 24); + this.txtSearchText.Size = new System.Drawing.Size(337, 24); this.txtSearchText.TabIndex = 7; this.txtSearchText.TextChanged += new System.EventHandler(this.txtSearchText_TextChanged); // // lblSearchText // this.lblSearchText.AutoSize = true; - this.lblSearchText.Location = new System.Drawing.Point(506, 6); + this.lblSearchText.Location = new System.Drawing.Point(482, 5); this.lblSearchText.Name = "lblSearchText"; this.lblSearchText.Size = new System.Drawing.Size(128, 18); this.lblSearchText.TabIndex = 105; diff --git a/SchoolGrades/frmSetup.Designer.cs b/SchoolGrades/frmSetup.Designer.cs index 5904a95..4c74c93 100644 --- a/SchoolGrades/frmSetup.Designer.cs +++ b/SchoolGrades/frmSetup.Designer.cs @@ -389,14 +389,13 @@ private void InitializeComponent() // this.chkAskPassword.AutoSize = true; this.chkAskPassword.Enabled = false; - this.chkAskPassword.Location = new System.Drawing.Point(539, 72); + this.chkAskPassword.Location = new System.Drawing.Point(859, 86); this.chkAskPassword.Name = "chkAskPassword"; this.chkAskPassword.Size = new System.Drawing.Size(152, 22); this.chkAskPassword.TabIndex = 112; this.chkAskPassword.Text = "Chiedi la password"; this.toolTip1.SetToolTip(this.chkAskPassword, "Se abilitato il programma chiede una password per entrare"); this.chkAskPassword.UseVisualStyleBackColor = true; - this.chkAskPassword.Visible = false; // // chkSaveBackup // diff --git a/SchoolGrades/frmSetup.cs b/SchoolGrades/frmSetup.cs index 58c6d66..3b68697 100644 --- a/SchoolGrades/frmSetup.cs +++ b/SchoolGrades/frmSetup.cs @@ -255,7 +255,9 @@ private void TxtPathStartLinks_TextChanged(object sender, EventArgs e) private void btnUsersManagement_Click(object sender, EventArgs e) { - MessageBox.Show("Parte da fare"); + MessageBox.Show("Form da completare!"); + frmUsersManagement f = new frmUsersManagement(); + f.Show(); } } } diff --git a/SchoolGrades/frmUsersManagement.Designer.cs b/SchoolGrades/frmUsersManagement.Designer.cs index 1f1054e..ad10070 100644 --- a/SchoolGrades/frmUsersManagement.Designer.cs +++ b/SchoolGrades/frmUsersManagement.Designer.cs @@ -29,25 +29,25 @@ protected override void Dispose(bool disposing) /// private void InitializeComponent() { - this.listBox1 = new System.Windows.Forms.ListBox(); + this.lstUsers = new System.Windows.Forms.ListBox(); this.SuspendLayout(); // // listBox1 // - this.listBox1.FormattingEnabled = true; - this.listBox1.ItemHeight = 20; - this.listBox1.Location = new System.Drawing.Point(29, 33); - this.listBox1.Name = "listBox1"; - this.listBox1.Size = new System.Drawing.Size(150, 484); - this.listBox1.TabIndex = 0; - this.listBox1.SelectedIndexChanged += new System.EventHandler(this.listBox1_SelectedIndexChanged); + this.lstUsers.FormattingEnabled = true; + this.lstUsers.ItemHeight = 20; + this.lstUsers.Location = new System.Drawing.Point(29, 33); + this.lstUsers.Name = "listBox1"; + this.lstUsers.Size = new System.Drawing.Size(150, 484); + this.lstUsers.TabIndex = 0; + this.lstUsers.SelectedIndexChanged += new System.EventHandler(this.lstUsers_SelectedIndexChanged); // // frmUsersManagement // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(980, 551); - this.Controls.Add(this.listBox1); + this.Controls.Add(this.lstUsers); this.Name = "frmUsersManagement"; this.Text = "frmUsersManagement"; this.Load += new System.EventHandler(this.frmUsersManagement_Load); @@ -57,6 +57,6 @@ private void InitializeComponent() #endregion - private System.Windows.Forms.ListBox listBox1; + private System.Windows.Forms.ListBox lstUsers; } } \ No newline at end of file diff --git a/SchoolGrades/frmUsersManagement.cs b/SchoolGrades/frmUsersManagement.cs index 2a0c5ae..f2c918f 100644 --- a/SchoolGrades/frmUsersManagement.cs +++ b/SchoolGrades/frmUsersManagement.cs @@ -1,18 +1,15 @@ using System; using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Text; using System.Windows.Forms; -using SchoolGrades.BusinessLayer; using SchoolGrades.DbClasses; namespace SchoolGrades { public partial class frmUsersManagement : Form { - BusinessLayer.BusinessLayer bl = new BusinessLayer.BusinessLayer(); + BusinessLayer.BusinessLayer bl = new BusinessLayer.BusinessLayer(); + + List listOfAllUsers; public frmUsersManagement() { @@ -21,12 +18,13 @@ public frmUsersManagement() private void frmUsersManagement_Load(object sender, EventArgs e) { - listBox1.DataSource = bl.GetAllUsers(); + listOfAllUsers = bl.GetAllUsers(); + lstUsers.DataSource = listOfAllUsers; } - private void listBox1_SelectedIndexChanged(object sender, EventArgs e) + private void lstUsers_SelectedIndexChanged(object sender, EventArgs e) { - UserControl currentUser = (User)listBox1[listBox1.SelectedIndex]; + User currentUser = (User)(listOfAllUsers[lstUsers.SelectedIndex]); } } }