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]); } } }