renardein před 4 roky
rodič
revize
0b3b553bf6

+ 121 - 11
Course_Project/Forms/AdminPanel.Designer.cs

@@ -41,6 +41,7 @@
             this.PasswordBox = new System.Windows.Forms.TextBox();
             this.LoginBox = new System.Windows.Forms.TextBox();
             this.groupBox2 = new System.Windows.Forms.GroupBox();
+            this.deleteUserButton = new System.Windows.Forms.Button();
             this.dataGridView1 = new System.Windows.Forms.DataGridView();
             this.loginDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
             this.userGroupDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
@@ -50,13 +51,22 @@
             this.usersTableAdapter = new Course_Project.courseDataSetTableAdapters.UsersTableAdapter();
             this.groupBox3 = new System.Windows.Forms.GroupBox();
             this.SystemInfoBox = new System.Windows.Forms.TextBox();
-            this.deleteUserButton = new System.Windows.Forms.Button();
+            this.groupBox4 = new System.Windows.Forms.GroupBox();
+            this.resetPassNewConfirm = new System.Windows.Forms.TextBox();
+            this.label8 = new System.Windows.Forms.Label();
+            this.label5 = new System.Windows.Forms.Label();
+            this.resetPassNewPass = new System.Windows.Forms.TextBox();
+            this.ChangePassButton = new System.Windows.Forms.Button();
+            this.label7 = new System.Windows.Forms.Label();
+            this.resetPassLoginBox = new System.Windows.Forms.TextBox();
+            this.ChangePassWarn = new System.Windows.Forms.Label();
             this.groupBox1.SuspendLayout();
             this.groupBox2.SuspendLayout();
             ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.usersBindingSource)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.courseDataSet)).BeginInit();
             this.groupBox3.SuspendLayout();
+            this.groupBox4.SuspendLayout();
             this.SuspendLayout();
             // 
             // groupBox1
@@ -179,6 +189,16 @@
             this.groupBox2.TabStop = false;
             this.groupBox2.Text = "Пользователи";
             // 
+            // deleteUserButton
+            // 
+            this.deleteUserButton.Location = new System.Drawing.Point(201, 124);
+            this.deleteUserButton.Name = "deleteUserButton";
+            this.deleteUserButton.Size = new System.Drawing.Size(75, 23);
+            this.deleteUserButton.TabIndex = 1;
+            this.deleteUserButton.Text = "Удалить";
+            this.deleteUserButton.UseVisualStyleBackColor = true;
+            this.deleteUserButton.Click += new System.EventHandler(this.deleteUserButton_Click);
+            // 
             // dataGridView1
             // 
             this.dataGridView1.AutoGenerateColumns = false;
@@ -201,12 +221,14 @@
             this.loginDataGridViewTextBoxColumn.DataPropertyName = "Login";
             this.loginDataGridViewTextBoxColumn.HeaderText = "Имя пользователя";
             this.loginDataGridViewTextBoxColumn.Name = "loginDataGridViewTextBoxColumn";
+            this.loginDataGridViewTextBoxColumn.ReadOnly = true;
             // 
             // userGroupDataGridViewTextBoxColumn
             // 
             this.userGroupDataGridViewTextBoxColumn.DataPropertyName = "UserGroup";
             this.userGroupDataGridViewTextBoxColumn.HeaderText = "Роль в системе";
             this.userGroupDataGridViewTextBoxColumn.Name = "userGroupDataGridViewTextBoxColumn";
+            this.userGroupDataGridViewTextBoxColumn.ReadOnly = true;
             // 
             // usersBindingSource
             // 
@@ -220,7 +242,7 @@
             // 
             // logoutButton
             // 
-            this.logoutButton.Location = new System.Drawing.Point(4, 415);
+            this.logoutButton.Location = new System.Drawing.Point(745, 415);
             this.logoutButton.Name = "logoutButton";
             this.logoutButton.Size = new System.Drawing.Size(113, 23);
             this.logoutButton.TabIndex = 2;
@@ -251,21 +273,98 @@
             this.SystemInfoBox.Size = new System.Drawing.Size(270, 132);
             this.SystemInfoBox.TabIndex = 0;
             // 
-            // deleteUserButton
-            // 
-            this.deleteUserButton.Location = new System.Drawing.Point(201, 124);
-            this.deleteUserButton.Name = "deleteUserButton";
-            this.deleteUserButton.Size = new System.Drawing.Size(75, 23);
-            this.deleteUserButton.TabIndex = 1;
-            this.deleteUserButton.Text = "Удалить";
-            this.deleteUserButton.UseVisualStyleBackColor = true;
-            this.deleteUserButton.Click += new System.EventHandler(this.deleteUserButton_Click);
+            // groupBox4
+            // 
+            this.groupBox4.Controls.Add(this.ChangePassWarn);
+            this.groupBox4.Controls.Add(this.resetPassNewConfirm);
+            this.groupBox4.Controls.Add(this.label8);
+            this.groupBox4.Controls.Add(this.label5);
+            this.groupBox4.Controls.Add(this.resetPassNewPass);
+            this.groupBox4.Controls.Add(this.ChangePassButton);
+            this.groupBox4.Controls.Add(this.label7);
+            this.groupBox4.Controls.Add(this.resetPassLoginBox);
+            this.groupBox4.Location = new System.Drawing.Point(4, 172);
+            this.groupBox4.Name = "groupBox4";
+            this.groupBox4.Size = new System.Drawing.Size(282, 125);
+            this.groupBox4.TabIndex = 12;
+            this.groupBox4.TabStop = false;
+            this.groupBox4.Text = "Изменить пароль пользователя";
+            // 
+            // resetPassNewConfirm
+            // 
+            this.resetPassNewConfirm.Location = new System.Drawing.Point(92, 69);
+            this.resetPassNewConfirm.Name = "resetPassNewConfirm";
+            this.resetPassNewConfirm.PasswordChar = '*';
+            this.resetPassNewConfirm.Size = new System.Drawing.Size(183, 20);
+            this.resetPassNewConfirm.TabIndex = 19;
+            // 
+            // label8
+            // 
+            this.label8.AutoSize = true;
+            this.label8.Location = new System.Drawing.Point(6, 72);
+            this.label8.Name = "label8";
+            this.label8.Size = new System.Drawing.Size(83, 13);
+            this.label8.TabIndex = 18;
+            this.label8.Text = "Повтор пароля";
+            // 
+            // label5
+            // 
+            this.label5.AutoSize = true;
+            this.label5.Location = new System.Drawing.Point(6, 46);
+            this.label5.Name = "label5";
+            this.label5.Size = new System.Drawing.Size(80, 13);
+            this.label5.TabIndex = 17;
+            this.label5.Text = "Новый пароль";
+            // 
+            // resetPassNewPass
+            // 
+            this.resetPassNewPass.Location = new System.Drawing.Point(92, 43);
+            this.resetPassNewPass.Name = "resetPassNewPass";
+            this.resetPassNewPass.PasswordChar = '*';
+            this.resetPassNewPass.Size = new System.Drawing.Size(183, 20);
+            this.resetPassNewPass.TabIndex = 16;
+            // 
+            // ChangePassButton
+            // 
+            this.ChangePassButton.Location = new System.Drawing.Point(208, 95);
+            this.ChangePassButton.Name = "ChangePassButton";
+            this.ChangePassButton.Size = new System.Drawing.Size(67, 23);
+            this.ChangePassButton.TabIndex = 15;
+            this.ChangePassButton.Text = "Добавить";
+            this.ChangePassButton.UseVisualStyleBackColor = true;
+            this.ChangePassButton.Click += new System.EventHandler(this.ChangePassButton_Click);
+            // 
+            // label7
+            // 
+            this.label7.AutoSize = true;
+            this.label7.Location = new System.Drawing.Point(6, 21);
+            this.label7.Name = "label7";
+            this.label7.Size = new System.Drawing.Size(38, 13);
+            this.label7.TabIndex = 13;
+            this.label7.Text = "Логин";
+            // 
+            // resetPassLoginBox
+            // 
+            this.resetPassLoginBox.Location = new System.Drawing.Point(92, 17);
+            this.resetPassLoginBox.Name = "resetPassLoginBox";
+            this.resetPassLoginBox.Size = new System.Drawing.Size(183, 20);
+            this.resetPassLoginBox.TabIndex = 11;
+            // 
+            // ChangePassWarn
+            // 
+            this.ChangePassWarn.AutoSize = true;
+            this.ChangePassWarn.ForeColor = System.Drawing.Color.Red;
+            this.ChangePassWarn.Location = new System.Drawing.Point(8, 100);
+            this.ChangePassWarn.Name = "ChangePassWarn";
+            this.ChangePassWarn.Size = new System.Drawing.Size(0, 13);
+            this.ChangePassWarn.TabIndex = 20;
             // 
             // AdminPanel
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
             this.ClientSize = new System.Drawing.Size(870, 450);
+            this.Controls.Add(this.groupBox4);
             this.Controls.Add(this.groupBox3);
             this.Controls.Add(this.logoutButton);
             this.Controls.Add(this.groupBox2);
@@ -281,6 +380,8 @@
             ((System.ComponentModel.ISupportInitialize)(this.courseDataSet)).EndInit();
             this.groupBox3.ResumeLayout(false);
             this.groupBox3.PerformLayout();
+            this.groupBox4.ResumeLayout(false);
+            this.groupBox4.PerformLayout();
             this.ResumeLayout(false);
 
         }
@@ -309,5 +410,14 @@
         private System.Windows.Forms.GroupBox groupBox3;
         private System.Windows.Forms.TextBox SystemInfoBox;
         private System.Windows.Forms.Button deleteUserButton;
+        private System.Windows.Forms.GroupBox groupBox4;
+        private System.Windows.Forms.Label label5;
+        private System.Windows.Forms.TextBox resetPassNewPass;
+        private System.Windows.Forms.Button ChangePassButton;
+        private System.Windows.Forms.Label label7;
+        private System.Windows.Forms.TextBox resetPassLoginBox;
+        private System.Windows.Forms.TextBox resetPassNewConfirm;
+        private System.Windows.Forms.Label label8;
+        private System.Windows.Forms.Label ChangePassWarn;
     }
 }

+ 42 - 0
Course_Project/Forms/AdminPanel.cs

@@ -94,7 +94,49 @@ namespace Course_Project.Forms
 
         private void deleteUserButton_Click(object sender, EventArgs e)
         {
+            string selected = dataGridView1.CurrentCell.Value.ToString();
+            using (var db = new Database())
+            {
+
+          db.Database.ExecuteSqlCommand("DELETE FROM Users WHERE Login='"+ selected+"'");
+                this.usersTableAdapter.Fill(this.courseDataSet.Users);
+
+            }
+        }
+
+        private void ChangePassButton_Click(object sender, EventArgs e)
+        {
+            using (var db = new Database())
+            {
+                if (string.IsNullOrEmpty(resetPassLoginBox.Text) | string.IsNullOrEmpty(resetPassNewPass.Text) || string.IsNullOrEmpty(resetPassNewConfirm.Text))
+                {
+
+                    UserAddWarnLabel.Text = "Проверьте заполненность полей";
+                }
+                else
+                {
+                    if (resetPassNewPass.Text == resetPassNewConfirm.Text)
+                    {
+                        bool userExists = db.Users.Any(u => u.Login == LoginBox.Text);
+                        if (userExists)
+                        {
+                            db.Database.ExecuteSqlCommand("UPDATE Users SET Password ='" + resetPassNewPass.Text + "'"+ " WHERE Login='"+resetPassLoginBox.Text+"'");
+                            ChangePassWarn.ForeColor = Color.Green;
+                            ChangePassWarn.Text = "Пароль изменен";
+                            this.usersTableAdapter.Fill(this.courseDataSet.Users);
+                        }
+                        else
+                        {
+                            ChangePassWarn.Text = "Пользователь не существует";
+                        }
 
+                    }
+                    else
+                    {
+                        ChangePassWarn.Text = "Пароли не совпадают";
+                    }
+                }
+            }
         }
     }
 }

+ 0 - 3
Course_Project/Forms/AdminPanel.resx

@@ -123,9 +123,6 @@
   <metadata name="courseDataSet.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
     <value>17, 17</value>
   </metadata>
-  <metadata name="courseDataSet.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
-    <value>17, 17</value>
-  </metadata>
   <metadata name="usersTableAdapter.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
     <value>306, 17</value>
   </metadata>