From 894e796f73eadf58bc754272bc0314c480838a86 Mon Sep 17 00:00:00 2001 From: Twitchy Date: Tue, 26 Jul 2011 21:42:51 +1200 Subject: [PATCH] DB Editor v1.1.0 - Adds User Manager, Ban Manager - Changes visuals of program - Makes things more user friendly. --- DBEditor/Main.Designer.cs | 725 +++++++++++++++++++++++++++++++++----- DBEditor/Main.cs | 390 +++++++++++++++++--- 2 files changed, 983 insertions(+), 132 deletions(-) diff --git a/DBEditor/Main.Designer.cs b/DBEditor/Main.Designer.cs index 21366eb3..f9cf85e6 100644 --- a/DBEditor/Main.Designer.cs +++ b/DBEditor/Main.Designer.cs @@ -39,12 +39,16 @@ this.label2 = new System.Windows.Forms.Label(); this.label1 = new System.Windows.Forms.Label(); this.tabPage2 = new System.Windows.Forms.TabPage(); - this.lst_inheritgrps = new System.Windows.Forms.ComboBox(); - this.label11 = new System.Windows.Forms.Label(); - this.txt_grpname = new System.Windows.Forms.TextBox(); - this.label10 = new System.Windows.Forms.Label(); + this.groupBox2 = new System.Windows.Forms.GroupBox(); + this.label12 = new System.Windows.Forms.Label(); this.btn_deletegroup = new System.Windows.Forms.Button(); + this.lbl_grpchild = new System.Windows.Forms.Label(); + this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.label11 = new System.Windows.Forms.Label(); this.btn_newgroup = new System.Windows.Forms.Button(); + this.txt_grpname = new System.Windows.Forms.TextBox(); + this.lst_inheritgrps = new System.Windows.Forms.ComboBox(); + this.label10 = new System.Windows.Forms.Label(); this.label4 = new System.Windows.Forms.Label(); this.label3 = new System.Windows.Forms.Label(); this.btn_moveAllLeftCmd = new System.Windows.Forms.Button(); @@ -54,29 +58,79 @@ this.btn_moveAllRightCmd = new System.Windows.Forms.Button(); this.lst_bannedCmds = new System.Windows.Forms.ListBox(); this.lst_groupList = new System.Windows.Forms.ListBox(); + this.tabPage5 = new System.Windows.Forms.TabPage(); + this.groupBox4 = new System.Windows.Forms.GroupBox(); + this.lbl_useraddstatus = new System.Windows.Forms.Label(); + this.btn_adduser = new System.Windows.Forms.Button(); + this.label20 = new System.Windows.Forms.Label(); + this.label22 = new System.Windows.Forms.Label(); + this.txt_newusername = new System.Windows.Forms.TextBox(); + this.txt_newuserpass = new System.Windows.Forms.TextBox(); + this.txt_newuserip = new System.Windows.Forms.TextBox(); + this.lst_newusergrplist = new System.Windows.Forms.ComboBox(); + this.label24 = new System.Windows.Forms.Label(); + this.label25 = new System.Windows.Forms.Label(); + this.groupBox3 = new System.Windows.Forms.GroupBox(); + this.label13 = new System.Windows.Forms.Label(); + this.btn_deluser = new System.Windows.Forms.Button(); + this.label23 = new System.Windows.Forms.Label(); + this.txt_username = new System.Windows.Forms.TextBox(); + this.txt_userpass = new System.Windows.Forms.TextBox(); + this.txt_userip = new System.Windows.Forms.TextBox(); + this.lst_usergrplist = new System.Windows.Forms.ComboBox(); + this.label21 = new System.Windows.Forms.Label(); + this.label14 = new System.Windows.Forms.Label(); + this.lst_userlist = new System.Windows.Forms.ListBox(); + this.tabPage6 = new System.Windows.Forms.TabPage(); + this.groupBox6 = new System.Windows.Forms.GroupBox(); + this.lbl_newbanstatus = new System.Windows.Forms.Label(); + this.label16 = new System.Windows.Forms.Label(); + this.btn_bannew = new System.Windows.Forms.Button(); + this.txt_newbanip = new System.Windows.Forms.TextBox(); + this.txt_newbanreason = new System.Windows.Forms.TextBox(); + this.txt_newbanname = new System.Windows.Forms.TextBox(); + this.label27 = new System.Windows.Forms.Label(); + this.label26 = new System.Windows.Forms.Label(); + this.groupBox5 = new System.Windows.Forms.GroupBox(); + this.label17 = new System.Windows.Forms.Label(); + this.txt_banip = new System.Windows.Forms.TextBox(); + this.btn_bandelete = new System.Windows.Forms.Button(); + this.txt_banname = new System.Windows.Forms.TextBox(); + this.label19 = new System.Windows.Forms.Label(); + this.txt_banreason = new System.Windows.Forms.TextBox(); + this.label18 = new System.Windows.Forms.Label(); + this.lst_bans = new System.Windows.Forms.ListBox(); this.tabControl1 = new System.Windows.Forms.TabControl(); this.tabPage3 = new System.Windows.Forms.TabPage(); this.btn_OpenLocalDB = new System.Windows.Forms.Button(); this.tabPage4 = new System.Windows.Forms.TabPage(); this.btn_connect = new System.Windows.Forms.Button(); this.label9 = new System.Windows.Forms.Label(); - this.txt_password = new System.Windows.Forms.TextBox(); + this.txt_dbpassword = new System.Windows.Forms.TextBox(); this.label8 = new System.Windows.Forms.Label(); - this.txt_username = new System.Windows.Forms.TextBox(); + this.txt_dbusername = new System.Windows.Forms.TextBox(); this.txt_port = new System.Windows.Forms.TextBox(); this.txt_dbname = new System.Windows.Forms.TextBox(); this.txt_hostname = new System.Windows.Forms.TextBox(); this.label7 = new System.Windows.Forms.Label(); this.label6 = new System.Windows.Forms.Label(); this.label5 = new System.Windows.Forms.Label(); - this.label12 = new System.Windows.Forms.Label(); - this.lbl_grpchild = new System.Windows.Forms.Label(); + this.groupBox7 = new System.Windows.Forms.GroupBox(); this.tabControl.SuspendLayout(); this.tabPage1.SuspendLayout(); this.tabPage2.SuspendLayout(); + this.groupBox2.SuspendLayout(); + this.groupBox1.SuspendLayout(); + this.tabPage5.SuspendLayout(); + this.groupBox4.SuspendLayout(); + this.groupBox3.SuspendLayout(); + this.tabPage6.SuspendLayout(); + this.groupBox6.SuspendLayout(); + this.groupBox5.SuspendLayout(); this.tabControl1.SuspendLayout(); this.tabPage3.SuspendLayout(); this.tabPage4.SuspendLayout(); + this.groupBox7.SuspendLayout(); this.SuspendLayout(); // // itemListBanned @@ -99,6 +153,8 @@ // this.tabControl.Controls.Add(this.tabPage1); this.tabControl.Controls.Add(this.tabPage2); + this.tabControl.Controls.Add(this.tabPage5); + this.tabControl.Controls.Add(this.tabPage6); this.tabControl.Location = new System.Drawing.Point(12, 143); this.tabControl.Name = "tabControl"; this.tabControl.SelectedIndex = 0; @@ -126,7 +182,7 @@ // // btn_moveAllLeft // - this.btn_moveAllLeft.Location = new System.Drawing.Point(288, 193); + this.btn_moveAllLeft.Location = new System.Drawing.Point(288, 108); this.btn_moveAllLeft.Name = "btn_moveAllLeft"; this.btn_moveAllLeft.Size = new System.Drawing.Size(27, 23); this.btn_moveAllLeft.TabIndex = 8; @@ -136,7 +192,7 @@ // // btn_moveAllRight // - this.btn_moveAllRight.Location = new System.Drawing.Point(288, 106); + this.btn_moveAllRight.Location = new System.Drawing.Point(288, 79); this.btn_moveAllRight.Name = "btn_moveAllRight"; this.btn_moveAllRight.Size = new System.Drawing.Size(27, 23); this.btn_moveAllRight.TabIndex = 7; @@ -146,7 +202,7 @@ // // btn_moveLeft // - this.btn_moveLeft.Location = new System.Drawing.Point(288, 164); + this.btn_moveLeft.Location = new System.Drawing.Point(288, 195); this.btn_moveLeft.Name = "btn_moveLeft"; this.btn_moveLeft.Size = new System.Drawing.Size(27, 23); this.btn_moveLeft.TabIndex = 6; @@ -156,7 +212,7 @@ // // btn_moveRight // - this.btn_moveRight.Location = new System.Drawing.Point(288, 135); + this.btn_moveRight.Location = new System.Drawing.Point(288, 166); this.btn_moveRight.Name = "btn_moveRight"; this.btn_moveRight.Size = new System.Drawing.Size(27, 23); this.btn_moveRight.TabIndex = 5; @@ -184,14 +240,8 @@ // // tabPage2 // - this.tabPage2.Controls.Add(this.lbl_grpchild); - this.tabPage2.Controls.Add(this.label12); - this.tabPage2.Controls.Add(this.lst_inheritgrps); - this.tabPage2.Controls.Add(this.label11); - this.tabPage2.Controls.Add(this.txt_grpname); - this.tabPage2.Controls.Add(this.label10); - this.tabPage2.Controls.Add(this.btn_deletegroup); - this.tabPage2.Controls.Add(this.btn_newgroup); + this.tabPage2.Controls.Add(this.groupBox2); + this.tabPage2.Controls.Add(this.groupBox1); this.tabPage2.Controls.Add(this.label4); this.tabPage2.Controls.Add(this.label3); this.tabPage2.Controls.Add(this.btn_moveAllLeftCmd); @@ -209,42 +259,30 @@ this.tabPage2.Text = "Group Manager"; this.tabPage2.UseVisualStyleBackColor = true; // - // lst_inheritgrps + // groupBox2 // - this.lst_inheritgrps.FormattingEnabled = true; - this.lst_inheritgrps.Location = new System.Drawing.Point(375, 84); - this.lst_inheritgrps.Name = "lst_inheritgrps"; - this.lst_inheritgrps.Size = new System.Drawing.Size(100, 21); - this.lst_inheritgrps.TabIndex = 23; + this.groupBox2.Controls.Add(this.label12); + this.groupBox2.Controls.Add(this.btn_deletegroup); + this.groupBox2.Controls.Add(this.lbl_grpchild); + this.groupBox2.Location = new System.Drawing.Point(222, 6); + this.groupBox2.Name = "groupBox2"; + this.groupBox2.Size = new System.Drawing.Size(374, 54); + this.groupBox2.TabIndex = 27; + this.groupBox2.TabStop = false; + this.groupBox2.Text = "Selected Group"; // - // label11 + // label12 // - this.label11.AutoSize = true; - this.label11.Location = new System.Drawing.Point(299, 87); - this.label11.Name = "label11"; - this.label11.Size = new System.Drawing.Size(65, 13); - this.label11.TabIndex = 22; - this.label11.Text = "Inherit From:"; - // - // txt_grpname - // - this.txt_grpname.Location = new System.Drawing.Point(375, 55); - this.txt_grpname.Name = "txt_grpname"; - this.txt_grpname.Size = new System.Drawing.Size(100, 20); - this.txt_grpname.TabIndex = 21; - // - // label10 - // - this.label10.AutoSize = true; - this.label10.Location = new System.Drawing.Point(299, 58); - this.label10.Name = "label10"; - this.label10.Size = new System.Drawing.Size(70, 13); - this.label10.TabIndex = 20; - this.label10.Text = "Group Name:"; + this.label12.AutoSize = true; + this.label12.Location = new System.Drawing.Point(6, 26); + this.label12.Name = "label12"; + this.label12.Size = new System.Drawing.Size(65, 13); + this.label12.TabIndex = 24; + this.label12.Text = "Group Child:"; // // btn_deletegroup // - this.btn_deletegroup.Location = new System.Drawing.Point(215, 82); + this.btn_deletegroup.Location = new System.Drawing.Point(183, 19); this.btn_deletegroup.Name = "btn_deletegroup"; this.btn_deletegroup.Size = new System.Drawing.Size(78, 23); this.btn_deletegroup.TabIndex = 19; @@ -252,9 +290,41 @@ this.btn_deletegroup.UseVisualStyleBackColor = true; this.btn_deletegroup.Click += new System.EventHandler(this.btn_deletegroup_Click); // + // lbl_grpchild + // + this.lbl_grpchild.AutoSize = true; + this.lbl_grpchild.Location = new System.Drawing.Point(77, 26); + this.lbl_grpchild.Name = "lbl_grpchild"; + this.lbl_grpchild.Size = new System.Drawing.Size(31, 13); + this.lbl_grpchild.TabIndex = 25; + this.lbl_grpchild.Text = "none"; + // + // groupBox1 + // + this.groupBox1.Controls.Add(this.label11); + this.groupBox1.Controls.Add(this.btn_newgroup); + this.groupBox1.Controls.Add(this.txt_grpname); + this.groupBox1.Controls.Add(this.lst_inheritgrps); + this.groupBox1.Controls.Add(this.label10); + this.groupBox1.Location = new System.Drawing.Point(222, 66); + this.groupBox1.Name = "groupBox1"; + this.groupBox1.Size = new System.Drawing.Size(374, 76); + this.groupBox1.TabIndex = 26; + this.groupBox1.TabStop = false; + this.groupBox1.Text = "Create New Group"; + // + // label11 + // + this.label11.AutoSize = true; + this.label11.Location = new System.Drawing.Point(6, 25); + this.label11.Name = "label11"; + this.label11.Size = new System.Drawing.Size(65, 13); + this.label11.TabIndex = 22; + this.label11.Text = "Inherit From:"; + // // btn_newgroup // - this.btn_newgroup.Location = new System.Drawing.Point(215, 53); + this.btn_newgroup.Location = new System.Drawing.Point(183, 47); this.btn_newgroup.Name = "btn_newgroup"; this.btn_newgroup.Size = new System.Drawing.Size(78, 23); this.btn_newgroup.TabIndex = 18; @@ -262,6 +332,30 @@ this.btn_newgroup.UseVisualStyleBackColor = true; this.btn_newgroup.Click += new System.EventHandler(this.btn_newgroup_Click); // + // txt_grpname + // + this.txt_grpname.Location = new System.Drawing.Point(77, 49); + this.txt_grpname.Name = "txt_grpname"; + this.txt_grpname.Size = new System.Drawing.Size(100, 20); + this.txt_grpname.TabIndex = 21; + // + // lst_inheritgrps + // + this.lst_inheritgrps.FormattingEnabled = true; + this.lst_inheritgrps.Location = new System.Drawing.Point(77, 22); + this.lst_inheritgrps.Name = "lst_inheritgrps"; + this.lst_inheritgrps.Size = new System.Drawing.Size(100, 21); + this.lst_inheritgrps.TabIndex = 23; + // + // label10 + // + this.label10.AutoSize = true; + this.label10.Location = new System.Drawing.Point(1, 52); + this.label10.Name = "label10"; + this.label10.Size = new System.Drawing.Size(70, 13); + this.label10.TabIndex = 20; + this.label10.Text = "Group Name:"; + // // label4 // this.label4.AutoSize = true; @@ -282,7 +376,7 @@ // // btn_moveAllLeftCmd // - this.btn_moveAllLeftCmd.Location = new System.Drawing.Point(291, 300); + this.btn_moveAllLeftCmd.Location = new System.Drawing.Point(291, 225); this.btn_moveAllLeftCmd.Name = "btn_moveAllLeftCmd"; this.btn_moveAllLeftCmd.Size = new System.Drawing.Size(27, 23); this.btn_moveAllLeftCmd.TabIndex = 15; @@ -292,7 +386,7 @@ // // btn_moveLeftCmd // - this.btn_moveLeftCmd.Location = new System.Drawing.Point(291, 270); + this.btn_moveLeftCmd.Location = new System.Drawing.Point(290, 313); this.btn_moveLeftCmd.Name = "btn_moveLeftCmd"; this.btn_moveLeftCmd.Size = new System.Drawing.Size(27, 23); this.btn_moveLeftCmd.TabIndex = 14; @@ -302,7 +396,7 @@ // // btn_moveRightCmd // - this.btn_moveRightCmd.Location = new System.Drawing.Point(291, 240); + this.btn_moveRightCmd.Location = new System.Drawing.Point(290, 284); this.btn_moveRightCmd.Name = "btn_moveRightCmd"; this.btn_moveRightCmd.Size = new System.Drawing.Size(27, 23); this.btn_moveRightCmd.TabIndex = 13; @@ -320,7 +414,7 @@ // // btn_moveAllRightCmd // - this.btn_moveAllRightCmd.Location = new System.Drawing.Point(291, 210); + this.btn_moveAllRightCmd.Location = new System.Drawing.Point(290, 196); this.btn_moveAllRightCmd.Name = "btn_moveAllRightCmd"; this.btn_moveAllRightCmd.Size = new System.Drawing.Size(27, 23); this.btn_moveAllRightCmd.TabIndex = 11; @@ -345,6 +439,415 @@ this.lst_groupList.TabIndex = 0; this.lst_groupList.SelectedIndexChanged += new System.EventHandler(this.lst_groupList_SelectedIndexChanged); // + // tabPage5 + // + this.tabPage5.Controls.Add(this.groupBox4); + this.tabPage5.Controls.Add(this.groupBox3); + this.tabPage5.Controls.Add(this.lst_userlist); + this.tabPage5.Location = new System.Drawing.Point(4, 22); + this.tabPage5.Name = "tabPage5"; + this.tabPage5.Padding = new System.Windows.Forms.Padding(3); + this.tabPage5.Size = new System.Drawing.Size(602, 381); + this.tabPage5.TabIndex = 2; + this.tabPage5.Text = "User Manager"; + this.tabPage5.UseVisualStyleBackColor = true; + // + // groupBox4 + // + this.groupBox4.Controls.Add(this.lbl_useraddstatus); + this.groupBox4.Controls.Add(this.btn_adduser); + this.groupBox4.Controls.Add(this.label20); + this.groupBox4.Controls.Add(this.label22); + this.groupBox4.Controls.Add(this.txt_newusername); + this.groupBox4.Controls.Add(this.txt_newuserpass); + this.groupBox4.Controls.Add(this.txt_newuserip); + this.groupBox4.Controls.Add(this.lst_newusergrplist); + this.groupBox4.Controls.Add(this.label24); + this.groupBox4.Controls.Add(this.label25); + this.groupBox4.Location = new System.Drawing.Point(294, 173); + this.groupBox4.Name = "groupBox4"; + this.groupBox4.Size = new System.Drawing.Size(296, 161); + this.groupBox4.TabIndex = 15; + this.groupBox4.TabStop = false; + this.groupBox4.Text = "New User"; + // + // lbl_useraddstatus + // + this.lbl_useraddstatus.AutoSize = true; + this.lbl_useraddstatus.Location = new System.Drawing.Point(87, 135); + this.lbl_useraddstatus.Name = "lbl_useraddstatus"; + this.lbl_useraddstatus.Size = new System.Drawing.Size(146, 13); + this.lbl_useraddstatus.TabIndex = 23; + this.lbl_useraddstatus.Text = "Status messages display here"; + this.lbl_useraddstatus.Visible = false; + // + // btn_adduser + // + this.btn_adduser.Location = new System.Drawing.Point(6, 130); + this.btn_adduser.Name = "btn_adduser"; + this.btn_adduser.Size = new System.Drawing.Size(75, 23); + this.btn_adduser.TabIndex = 22; + this.btn_adduser.Text = "Add User"; + this.btn_adduser.UseVisualStyleBackColor = true; + this.btn_adduser.Click += new System.EventHandler(this.btn_adduser_Click); + // + // label20 + // + this.label20.AutoSize = true; + this.label20.Location = new System.Drawing.Point(6, 28); + this.label20.Name = "label20"; + this.label20.Size = new System.Drawing.Size(63, 13); + this.label20.TabIndex = 14; + this.label20.Text = "User Name:"; + // + // label22 + // + this.label22.AutoSize = true; + this.label22.Location = new System.Drawing.Point(13, 107); + this.label22.Name = "label22"; + this.label22.Size = new System.Drawing.Size(56, 13); + this.label22.TabIndex = 21; + this.label22.Text = "Password:"; + // + // txt_newusername + // + this.txt_newusername.Location = new System.Drawing.Point(75, 25); + this.txt_newusername.Name = "txt_newusername"; + this.txt_newusername.Size = new System.Drawing.Size(221, 20); + this.txt_newusername.TabIndex = 18; + // + // txt_newuserpass + // + this.txt_newuserpass.Location = new System.Drawing.Point(75, 104); + this.txt_newuserpass.Name = "txt_newuserpass"; + this.txt_newuserpass.Size = new System.Drawing.Size(221, 20); + this.txt_newuserpass.TabIndex = 19; + // + // txt_newuserip + // + this.txt_newuserip.Location = new System.Drawing.Point(75, 78); + this.txt_newuserip.Name = "txt_newuserip"; + this.txt_newuserip.Size = new System.Drawing.Size(221, 20); + this.txt_newuserip.TabIndex = 20; + // + // lst_newusergrplist + // + this.lst_newusergrplist.FormattingEnabled = true; + this.lst_newusergrplist.Location = new System.Drawing.Point(75, 51); + this.lst_newusergrplist.Name = "lst_newusergrplist"; + this.lst_newusergrplist.Size = new System.Drawing.Size(221, 21); + this.lst_newusergrplist.TabIndex = 16; + // + // label24 + // + this.label24.AutoSize = true; + this.label24.Location = new System.Drawing.Point(49, 81); + this.label24.Name = "label24"; + this.label24.Size = new System.Drawing.Size(20, 13); + this.label24.TabIndex = 17; + this.label24.Text = "IP:"; + // + // label25 + // + this.label25.AutoSize = true; + this.label25.Location = new System.Drawing.Point(30, 54); + this.label25.Name = "label25"; + this.label25.Size = new System.Drawing.Size(39, 13); + this.label25.TabIndex = 15; + this.label25.Text = "Group:"; + // + // groupBox3 + // + this.groupBox3.Controls.Add(this.label13); + this.groupBox3.Controls.Add(this.btn_deluser); + this.groupBox3.Controls.Add(this.label23); + this.groupBox3.Controls.Add(this.txt_username); + this.groupBox3.Controls.Add(this.txt_userpass); + this.groupBox3.Controls.Add(this.txt_userip); + this.groupBox3.Controls.Add(this.lst_usergrplist); + this.groupBox3.Controls.Add(this.label21); + this.groupBox3.Controls.Add(this.label14); + this.groupBox3.Location = new System.Drawing.Point(294, 7); + this.groupBox3.Name = "groupBox3"; + this.groupBox3.Size = new System.Drawing.Size(302, 159); + this.groupBox3.TabIndex = 14; + this.groupBox3.TabStop = false; + this.groupBox3.Text = "Current User"; + // + // label13 + // + this.label13.AutoSize = true; + this.label13.Location = new System.Drawing.Point(6, 26); + this.label13.Name = "label13"; + this.label13.Size = new System.Drawing.Size(63, 13); + this.label13.TabIndex = 1; + this.label13.Text = "User Name:"; + // + // btn_deluser + // + this.btn_deluser.Location = new System.Drawing.Point(6, 128); + this.btn_deluser.Name = "btn_deluser"; + this.btn_deluser.Size = new System.Drawing.Size(75, 23); + this.btn_deluser.TabIndex = 8; + this.btn_deluser.Text = "Delete User"; + this.btn_deluser.UseVisualStyleBackColor = true; + this.btn_deluser.Click += new System.EventHandler(this.btn_deluser_Click); + // + // label23 + // + this.label23.AutoSize = true; + this.label23.Location = new System.Drawing.Point(13, 105); + this.label23.Name = "label23"; + this.label23.Size = new System.Drawing.Size(56, 13); + this.label23.TabIndex = 13; + this.label23.Text = "Password:"; + // + // txt_username + // + this.txt_username.Location = new System.Drawing.Point(75, 23); + this.txt_username.Name = "txt_username"; + this.txt_username.ReadOnly = true; + this.txt_username.Size = new System.Drawing.Size(221, 20); + this.txt_username.TabIndex = 9; + // + // txt_userpass + // + this.txt_userpass.Location = new System.Drawing.Point(75, 102); + this.txt_userpass.Name = "txt_userpass"; + this.txt_userpass.ReadOnly = true; + this.txt_userpass.Size = new System.Drawing.Size(221, 20); + this.txt_userpass.TabIndex = 10; + // + // txt_userip + // + this.txt_userip.Location = new System.Drawing.Point(75, 76); + this.txt_userip.Name = "txt_userip"; + this.txt_userip.ReadOnly = true; + this.txt_userip.Size = new System.Drawing.Size(221, 20); + this.txt_userip.TabIndex = 12; + // + // lst_usergrplist + // + this.lst_usergrplist.FormattingEnabled = true; + this.lst_usergrplist.Location = new System.Drawing.Point(75, 49); + this.lst_usergrplist.Name = "lst_usergrplist"; + this.lst_usergrplist.Size = new System.Drawing.Size(221, 21); + this.lst_usergrplist.TabIndex = 4; + this.lst_usergrplist.SelectedIndexChanged += new System.EventHandler(this.lst_usergrplist_SelectedIndexChanged); + // + // label21 + // + this.label21.AutoSize = true; + this.label21.Location = new System.Drawing.Point(49, 79); + this.label21.Name = "label21"; + this.label21.Size = new System.Drawing.Size(20, 13); + this.label21.TabIndex = 6; + this.label21.Text = "IP:"; + // + // label14 + // + this.label14.AutoSize = true; + this.label14.Location = new System.Drawing.Point(30, 52); + this.label14.Name = "label14"; + this.label14.Size = new System.Drawing.Size(39, 13); + this.label14.TabIndex = 3; + this.label14.Text = "Group:"; + // + // lst_userlist + // + this.lst_userlist.FormattingEnabled = true; + this.lst_userlist.Location = new System.Drawing.Point(9, 7); + this.lst_userlist.Name = "lst_userlist"; + this.lst_userlist.Size = new System.Drawing.Size(275, 368); + this.lst_userlist.TabIndex = 0; + this.lst_userlist.SelectedIndexChanged += new System.EventHandler(this.lst_userlist_SelectedIndexChanged); + // + // tabPage6 + // + this.tabPage6.Controls.Add(this.groupBox7); + this.tabPage6.Controls.Add(this.groupBox6); + this.tabPage6.Controls.Add(this.groupBox5); + this.tabPage6.Location = new System.Drawing.Point(4, 22); + this.tabPage6.Name = "tabPage6"; + this.tabPage6.Padding = new System.Windows.Forms.Padding(3); + this.tabPage6.Size = new System.Drawing.Size(602, 381); + this.tabPage6.TabIndex = 3; + this.tabPage6.Text = "Ban Manager"; + this.tabPage6.UseVisualStyleBackColor = true; + // + // groupBox6 + // + this.groupBox6.Controls.Add(this.lbl_newbanstatus); + this.groupBox6.Controls.Add(this.label16); + this.groupBox6.Controls.Add(this.btn_bannew); + this.groupBox6.Controls.Add(this.txt_newbanip); + this.groupBox6.Controls.Add(this.txt_newbanreason); + this.groupBox6.Controls.Add(this.txt_newbanname); + this.groupBox6.Controls.Add(this.label27); + this.groupBox6.Controls.Add(this.label26); + this.groupBox6.Location = new System.Drawing.Point(296, 165); + this.groupBox6.Name = "groupBox6"; + this.groupBox6.Size = new System.Drawing.Size(300, 137); + this.groupBox6.TabIndex = 12; + this.groupBox6.TabStop = false; + this.groupBox6.Text = "New Ban"; + // + // lbl_newbanstatus + // + this.lbl_newbanstatus.AutoSize = true; + this.lbl_newbanstatus.Location = new System.Drawing.Point(90, 113); + this.lbl_newbanstatus.Name = "lbl_newbanstatus"; + this.lbl_newbanstatus.Size = new System.Drawing.Size(146, 13); + this.lbl_newbanstatus.TabIndex = 16; + this.lbl_newbanstatus.Text = "Status messages display here"; + this.lbl_newbanstatus.Visible = false; + // + // label16 + // + this.label16.AutoSize = true; + this.label16.Location = new System.Drawing.Point(2, 33); + this.label16.Name = "label16"; + this.label16.Size = new System.Drawing.Size(65, 13); + this.label16.TabIndex = 10; + this.label16.Text = "*IP Address:"; + // + // btn_bannew + // + this.btn_bannew.Location = new System.Drawing.Point(9, 108); + this.btn_bannew.Name = "btn_bannew"; + this.btn_bannew.Size = new System.Drawing.Size(75, 23); + this.btn_bannew.TabIndex = 10; + this.btn_bannew.Text = "New Ban"; + this.btn_bannew.UseVisualStyleBackColor = true; + this.btn_bannew.Click += new System.EventHandler(this.btn_bannew_Click); + // + // txt_newbanip + // + this.txt_newbanip.Location = new System.Drawing.Point(73, 30); + this.txt_newbanip.Name = "txt_newbanip"; + this.txt_newbanip.Size = new System.Drawing.Size(221, 20); + this.txt_newbanip.TabIndex = 13; + // + // txt_newbanreason + // + this.txt_newbanreason.Location = new System.Drawing.Point(74, 82); + this.txt_newbanreason.Multiline = true; + this.txt_newbanreason.Name = "txt_newbanreason"; + this.txt_newbanreason.Size = new System.Drawing.Size(220, 20); + this.txt_newbanreason.TabIndex = 15; + // + // txt_newbanname + // + this.txt_newbanname.Location = new System.Drawing.Point(74, 56); + this.txt_newbanname.Name = "txt_newbanname"; + this.txt_newbanname.Size = new System.Drawing.Size(220, 20); + this.txt_newbanname.TabIndex = 14; + // + // label27 + // + this.label27.AutoSize = true; + this.label27.Location = new System.Drawing.Point(25, 59); + this.label27.Name = "label27"; + this.label27.Size = new System.Drawing.Size(42, 13); + this.label27.TabIndex = 11; + this.label27.Text = "*Name:"; + // + // label26 + // + this.label26.AutoSize = true; + this.label26.Location = new System.Drawing.Point(21, 85); + this.label26.Name = "label26"; + this.label26.Size = new System.Drawing.Size(47, 13); + this.label26.TabIndex = 12; + this.label26.Text = "Reason:"; + // + // groupBox5 + // + this.groupBox5.Controls.Add(this.label17); + this.groupBox5.Controls.Add(this.txt_banip); + this.groupBox5.Controls.Add(this.btn_bandelete); + this.groupBox5.Controls.Add(this.txt_banname); + this.groupBox5.Controls.Add(this.label19); + this.groupBox5.Controls.Add(this.txt_banreason); + this.groupBox5.Controls.Add(this.label18); + this.groupBox5.Location = new System.Drawing.Point(296, 23); + this.groupBox5.Name = "groupBox5"; + this.groupBox5.Size = new System.Drawing.Size(300, 129); + this.groupBox5.TabIndex = 11; + this.groupBox5.TabStop = false; + this.groupBox5.Text = "Selected Ban"; + // + // label17 + // + this.label17.AutoSize = true; + this.label17.Location = new System.Drawing.Point(6, 26); + this.label17.Name = "label17"; + this.label17.Size = new System.Drawing.Size(61, 13); + this.label17.TabIndex = 3; + this.label17.Text = "IP Address:"; + // + // txt_banip + // + this.txt_banip.Location = new System.Drawing.Point(73, 23); + this.txt_banip.Name = "txt_banip"; + this.txt_banip.ReadOnly = true; + this.txt_banip.Size = new System.Drawing.Size(221, 20); + this.txt_banip.TabIndex = 6; + // + // btn_bandelete + // + this.btn_bandelete.Location = new System.Drawing.Point(9, 100); + this.btn_bandelete.Name = "btn_bandelete"; + this.btn_bandelete.Size = new System.Drawing.Size(75, 23); + this.btn_bandelete.TabIndex = 9; + this.btn_bandelete.Text = "Delete Ban"; + this.btn_bandelete.UseVisualStyleBackColor = true; + this.btn_bandelete.Click += new System.EventHandler(this.btn_bandelete_Click); + // + // txt_banname + // + this.txt_banname.Location = new System.Drawing.Point(74, 49); + this.txt_banname.Name = "txt_banname"; + this.txt_banname.ReadOnly = true; + this.txt_banname.Size = new System.Drawing.Size(220, 20); + this.txt_banname.TabIndex = 7; + // + // label19 + // + this.label19.AutoSize = true; + this.label19.Location = new System.Drawing.Point(21, 78); + this.label19.Name = "label19"; + this.label19.Size = new System.Drawing.Size(47, 13); + this.label19.TabIndex = 5; + this.label19.Text = "Reason:"; + // + // txt_banreason + // + this.txt_banreason.Location = new System.Drawing.Point(74, 75); + this.txt_banreason.Multiline = true; + this.txt_banreason.Name = "txt_banreason"; + this.txt_banreason.Size = new System.Drawing.Size(220, 20); + this.txt_banreason.TabIndex = 8; + this.txt_banreason.TextChanged += new System.EventHandler(this.txt_banreason_TextChanged); + // + // label18 + // + this.label18.AutoSize = true; + this.label18.Location = new System.Drawing.Point(30, 52); + this.label18.Name = "label18"; + this.label18.Size = new System.Drawing.Size(38, 13); + this.label18.TabIndex = 4; + this.label18.Text = "Name:"; + // + // lst_bans + // + this.lst_bans.FormattingEnabled = true; + this.lst_bans.Location = new System.Drawing.Point(6, 19); + this.lst_bans.Name = "lst_bans"; + this.lst_bans.Size = new System.Drawing.Size(272, 329); + this.lst_bans.TabIndex = 0; + this.lst_bans.SelectedIndexChanged += new System.EventHandler(this.lst_bans_SelectedIndexChanged); + // // tabControl1 // this.tabControl1.Controls.Add(this.tabPage3); @@ -380,9 +883,9 @@ // this.tabPage4.Controls.Add(this.btn_connect); this.tabPage4.Controls.Add(this.label9); - this.tabPage4.Controls.Add(this.txt_password); + this.tabPage4.Controls.Add(this.txt_dbpassword); this.tabPage4.Controls.Add(this.label8); - this.tabPage4.Controls.Add(this.txt_username); + this.tabPage4.Controls.Add(this.txt_dbusername); this.tabPage4.Controls.Add(this.txt_port); this.tabPage4.Controls.Add(this.txt_dbname); this.tabPage4.Controls.Add(this.txt_hostname); @@ -416,12 +919,12 @@ this.label9.TabIndex = 9; this.label9.Text = "Password:"; // - // txt_password + // txt_dbpassword // - this.txt_password.Location = new System.Drawing.Point(272, 33); - this.txt_password.Name = "txt_password"; - this.txt_password.Size = new System.Drawing.Size(100, 20); - this.txt_password.TabIndex = 8; + this.txt_dbpassword.Location = new System.Drawing.Point(272, 33); + this.txt_dbpassword.Name = "txt_dbpassword"; + this.txt_dbpassword.Size = new System.Drawing.Size(100, 20); + this.txt_dbpassword.TabIndex = 8; // // label8 // @@ -432,12 +935,12 @@ this.label8.TabIndex = 7; this.label8.Text = "Username:"; // - // txt_username + // txt_dbusername // - this.txt_username.Location = new System.Drawing.Point(272, 7); - this.txt_username.Name = "txt_username"; - this.txt_username.Size = new System.Drawing.Size(100, 20); - this.txt_username.TabIndex = 6; + this.txt_dbusername.Location = new System.Drawing.Point(272, 7); + this.txt_dbusername.Name = "txt_dbusername"; + this.txt_dbusername.Size = new System.Drawing.Size(100, 20); + this.txt_dbusername.TabIndex = 6; // // txt_port // @@ -489,23 +992,15 @@ this.label5.TabIndex = 0; this.label5.Text = "Hostname:"; // - // label12 + // groupBox7 // - this.label12.AutoSize = true; - this.label12.Location = new System.Drawing.Point(215, 8); - this.label12.Name = "label12"; - this.label12.Size = new System.Drawing.Size(65, 13); - this.label12.TabIndex = 24; - this.label12.Text = "Group Child:"; - // - // lbl_grpchild - // - this.lbl_grpchild.AutoSize = true; - this.lbl_grpchild.Location = new System.Drawing.Point(286, 8); - this.lbl_grpchild.Name = "lbl_grpchild"; - this.lbl_grpchild.Size = new System.Drawing.Size(16, 13); - this.lbl_grpchild.TabIndex = 25; - this.lbl_grpchild.Text = " "; + this.groupBox7.Controls.Add(this.lst_bans); + this.groupBox7.Location = new System.Drawing.Point(6, 23); + this.groupBox7.Name = "groupBox7"; + this.groupBox7.Size = new System.Drawing.Size(284, 352); + this.groupBox7.TabIndex = 13; + this.groupBox7.TabStop = false; + this.groupBox7.Text = "Ban List"; // // TShockDBEditor // @@ -521,10 +1016,25 @@ this.tabPage1.PerformLayout(); this.tabPage2.ResumeLayout(false); this.tabPage2.PerformLayout(); + this.groupBox2.ResumeLayout(false); + this.groupBox2.PerformLayout(); + this.groupBox1.ResumeLayout(false); + this.groupBox1.PerformLayout(); + this.tabPage5.ResumeLayout(false); + this.groupBox4.ResumeLayout(false); + this.groupBox4.PerformLayout(); + this.groupBox3.ResumeLayout(false); + this.groupBox3.PerformLayout(); + this.tabPage6.ResumeLayout(false); + this.groupBox6.ResumeLayout(false); + this.groupBox6.PerformLayout(); + this.groupBox5.ResumeLayout(false); + this.groupBox5.PerformLayout(); this.tabControl1.ResumeLayout(false); this.tabPage3.ResumeLayout(false); this.tabPage4.ResumeLayout(false); this.tabPage4.PerformLayout(); + this.groupBox7.ResumeLayout(false); this.ResumeLayout(false); } @@ -558,9 +1068,9 @@ private System.Windows.Forms.Label label5; private System.Windows.Forms.Button btn_connect; private System.Windows.Forms.Label label9; - private System.Windows.Forms.TextBox txt_password; + private System.Windows.Forms.TextBox txt_dbpassword; private System.Windows.Forms.Label label8; - private System.Windows.Forms.TextBox txt_username; + private System.Windows.Forms.TextBox txt_dbusername; private System.Windows.Forms.TextBox txt_port; private System.Windows.Forms.TextBox txt_dbname; private System.Windows.Forms.TextBox txt_hostname; @@ -574,6 +1084,51 @@ private System.Windows.Forms.Label label10; private System.Windows.Forms.Label lbl_grpchild; private System.Windows.Forms.Label label12; + private System.Windows.Forms.TabPage tabPage5; + private System.Windows.Forms.Label label14; + private System.Windows.Forms.Label label13; + private System.Windows.Forms.ListBox lst_userlist; + private System.Windows.Forms.ComboBox lst_usergrplist; + private System.Windows.Forms.TabPage tabPage6; + private System.Windows.Forms.ListBox lst_bans; + private System.Windows.Forms.Label label18; + private System.Windows.Forms.Label label17; + private System.Windows.Forms.TextBox txt_banreason; + private System.Windows.Forms.TextBox txt_banname; + private System.Windows.Forms.TextBox txt_banip; + private System.Windows.Forms.Label label19; + private System.Windows.Forms.Button btn_bannew; + private System.Windows.Forms.Button btn_bandelete; + private System.Windows.Forms.Label label21; + private System.Windows.Forms.Button btn_deluser; + private System.Windows.Forms.Label label23; + private System.Windows.Forms.TextBox txt_userip; + private System.Windows.Forms.TextBox txt_userpass; + private System.Windows.Forms.TextBox txt_username; + private System.Windows.Forms.GroupBox groupBox2; + private System.Windows.Forms.GroupBox groupBox1; + private System.Windows.Forms.GroupBox groupBox3; + private System.Windows.Forms.GroupBox groupBox4; + private System.Windows.Forms.Button btn_adduser; + private System.Windows.Forms.Label label20; + private System.Windows.Forms.Label label22; + private System.Windows.Forms.TextBox txt_newusername; + private System.Windows.Forms.TextBox txt_newuserpass; + private System.Windows.Forms.TextBox txt_newuserip; + private System.Windows.Forms.ComboBox lst_newusergrplist; + private System.Windows.Forms.Label label24; + private System.Windows.Forms.Label label25; + private System.Windows.Forms.Label lbl_useraddstatus; + private System.Windows.Forms.GroupBox groupBox6; + private System.Windows.Forms.GroupBox groupBox5; + private System.Windows.Forms.Label label16; + private System.Windows.Forms.TextBox txt_newbanip; + private System.Windows.Forms.TextBox txt_newbanreason; + private System.Windows.Forms.TextBox txt_newbanname; + private System.Windows.Forms.Label label27; + private System.Windows.Forms.Label label26; + private System.Windows.Forms.Label lbl_newbanstatus; + private System.Windows.Forms.GroupBox groupBox7; } } diff --git a/DBEditor/Main.cs b/DBEditor/Main.cs index 40c5388f..bf3b5a7f 100644 --- a/DBEditor/Main.cs +++ b/DBEditor/Main.cs @@ -6,6 +6,7 @@ using System.Drawing; using System.Linq; using System.Text; using System.IO; +using System.Security.Cryptography; using Community.CsharpSqlite.SQLiteClient; using MySql.Data.MySqlClient; @@ -29,12 +30,9 @@ namespace TShockDBEditor dialog.Filter = "SQLite Database (*.sqlite)|*.sqlite"; } - public void LoadSqliteDatabase(string path) + public void LoadDB() { - string sql = dialog.FileName; - DB = new SqliteConnection(string.Format("uri=file://{0},Version=3", sql)); - DB.Open(); - dbtype = "sqlite"; + itemListBanned.Items.Clear(); lst_groupList.Items.Clear(); lst_AvailableCmds.Items.Clear(); @@ -57,12 +55,46 @@ namespace TShockDBEditor com.CommandText = "SELECT * FROM GroupList"; + lst_groupList.Items.Add("superadmin"); + lst_usergrplist.Items.Add("superadmin"); + lst_newusergrplist.Items.Add("superadmin"); using (var reader = com.ExecuteReader()) { while (reader.Read()) { lst_groupList.Items.Add(reader.Get("GroupName")); lst_inheritgrps.Items.Add(reader.Get("GroupName")); + lst_usergrplist.Items.Add(reader.Get("GroupName")); + lst_newusergrplist.Items.Add(reader.Get("GroupName")); + } + } + } + using (var com = DB.CreateCommand()) + { + com.CommandText = + "SELECT * FROM Users"; + + using (var reader = com.ExecuteReader()) + { + while (reader.Read()) + { + if (reader.Get("UserName") != "") + lst_userlist.Items.Add(reader.Get("UserName")); + else + lst_userlist.Items.Add(reader.Get("IP")); + } + } + } + using (var com = DB.CreateCommand()) + { + com.CommandText = + "SELECT * FROM Bans"; + + using (var reader = com.ExecuteReader()) + { + while (reader.Read()) + { + lst_bans.Items.Add(reader.Get("Name")); } } } @@ -74,53 +106,27 @@ namespace TShockDBEditor } } - public void LoadMySqlDatabase(string hostname = "localhost", string port = "3306", string database = "", string username = "", string password = "") + public void LoadSqliteDatabase(string path) + { + string sql = dialog.FileName; + DB = new SqliteConnection(string.Format("uri=file://{0},Version=3", sql)); + DB.Open(); + dbtype = "sqlite"; + LoadDB(); + } + + public void LoadMySqlDatabase(string hostname = "localhost", string port = "3306", string database = "", string dbusername = "", string dbpassword = "") { DB = new MySqlConnection(); DB.ConnectionString = "Server='" + hostname + "';Port='" + port + "';Database='" + database + - "';Uid='" + username + - "';Pwd='" + password + "';"; + "';Uid='" + dbusername + + "';Pwd='" + dbpassword + "';"; DB.Open(); dbtype = "mysql"; - itemListBanned.Items.Clear(); - lst_groupList.Items.Clear(); - lst_AvailableCmds.Items.Clear(); - lst_bannedCmds.Items.Clear(); - itemListAvailable.Items.Clear(); - - using (var com = DB.CreateCommand()) - { - com.CommandText = - "SELECT * FROM Itembans"; - - using (var reader = com.ExecuteReader()) - { - while (reader.Read()) - itemListBanned.Items.Add(reader.Get("ItemName")); - } - } - using (var com = DB.CreateCommand()) - { - com.CommandText = - "SELECT * FROM GroupList"; - - using (var reader = com.ExecuteReader()) - { - while (reader.Read()) - { - lst_groupList.Items.Add(reader.Get("GroupName")); - } - } - } - - for (int i = 0; i < Itemlist.ItemList.Count; i++) - { - if (!itemListBanned.Items.Contains(Itemlist.ItemList[i])) - itemListAvailable.Items.Add(Itemlist.ItemList[i]); - } + LoadDB(); } #region BannedItemsTab @@ -361,7 +367,7 @@ namespace TShockDBEditor com.CommandText = "INSERT IGNORE INTO GroupList SET GroupName=@groupname, Commands=@commands;"; com.AddParameter("@groupname", txt_grpname.Text); - if(lst_inheritgrps.SelectedIndex > -1) + if (lst_inheritgrps.SelectedIndex > -1) com.AddParameter("@commands", lst_inheritgrps.Items[lst_inheritgrps.SelectedIndex]); else com.AddParameter("@commands", ""); @@ -372,6 +378,7 @@ namespace TShockDBEditor { lst_groupList.Items.Add(txt_grpname.Text); lst_inheritgrps.Items.Add(txt_grpname.Text); + lst_usergrplist.Items.Add(txt_grpname.Text); txt_grpname.Text = ""; } } @@ -396,6 +403,7 @@ namespace TShockDBEditor lst_groupList.Items.Remove(lst_groupList.Items[lst_groupList.SelectedIndex]); lst_inheritgrps.Items.Clear(); + lst_usergrplist.Items.Clear(); com.CommandText = "SELECT * FROM GroupList"; using (var reader = com.ExecuteReader()) @@ -403,6 +411,7 @@ namespace TShockDBEditor while (reader.Read()) { lst_inheritgrps.Items.Add(reader.Get("GroupName")); + lst_usergrplist.Items.Add(reader.Get("GroupName")); } } } @@ -427,10 +436,297 @@ namespace TShockDBEditor private void btn_connect_Click(object sender, EventArgs e) { - LoadMySqlDatabase(txt_hostname.Text, txt_port.Text, txt_dbname.Text, txt_username.Text, txt_password.Text); + LoadMySqlDatabase(txt_hostname.Text, txt_port.Text, txt_dbname.Text, txt_dbusername.Text, txt_dbpassword.Text); tabControl.Visible = true; } - #endregion + #endregion + + #region BansTab + + private void lst_bans_SelectedIndexChanged(object sender, EventArgs e) + { + using (var com = DB.CreateCommand()) + { + if (lst_bans.SelectedIndex > -1) + { + com.CommandText = + "SELECT * FROM Bans WHERE Name=@name"; + com.AddParameter("@name", lst_bans.Items[lst_bans.SelectedIndex]); + + using (var reader = com.ExecuteReader()) + { + if (reader.Read()) + { + txt_banip.Text = reader.Get("IP"); + txt_banname.Text = reader.Get("Name"); + txt_banreason.Text = reader.Get("Reason"); + } + } + } + } + } + + private void btn_bandelete_Click(object sender, EventArgs e) + { + using (var com = DB.CreateCommand()) + { + com.CommandText = + "DELETE FROM Bans WHERE IP=@ip"; + com.AddParameter("@ip", txt_banip.Text); + + using (var reader = com.ExecuteReader()) + { + if (reader.RecordsAffected > 0) + { + txt_banip.Text = ""; + txt_banname.Text = ""; + txt_banreason.Text = ""; + lst_bans.Items.Remove(lst_bans.Items[lst_bans.SelectedIndex]); + } + } + } + } + + private void btn_bannew_Click(object sender, EventArgs e) + { + using (var com = DB.CreateCommand()) + { + if (dbtype == "sqlite") + com.CommandText = "INSERT INTO Bans (IP, Name, Reason) VALUES (@ip, @name, @reason);"; + else if (dbtype == "mysql") + com.CommandText = "INSERT INTO Bans SET IP=@ip, Name=@name, Reason=@reason;"; + if (txt_newbanip.Text != "" && txt_newbanname.Text != "") + { + com.AddParameter("@ip", txt_newbanip.Text); + com.AddParameter("@name", txt_newbanname.Text); + com.AddParameter("@reason", txt_newbanreason.Text); + com.ExecuteNonQuery(); + + lst_bans.Items.Add(txt_newbanname.Text); + txt_newbanip.Text = ""; + txt_newbanname.Text = ""; + txt_newbanreason.Text = ""; + lbl_newbanstatus.Text = "Ban added successfully!"; + } + else + lbl_newbanstatus.Text = "Required field('s) empty"; + + lst_bans.Items.Add(txt_newbanname.Text); + txt_newbanip.Text = ""; + txt_newbanname.Text = ""; + } + } + + private void txt_banreason_TextChanged(object sender, EventArgs e) + { + if (txt_banip.Text != "") + { + using (var com = DB.CreateCommand()) + { + com.CommandText = + "UPDATE Bans SET Reason=@reason WHERE IP=@ip"; + com.AddParameter("@reason", txt_banreason.Text); + com.AddParameter("@ip", txt_banip.Text); + com.ExecuteNonQuery(); + } + } + } + + #endregion + + private void lst_userlist_SelectedIndexChanged(object sender, EventArgs e) + { + txt_username.Text = "None Selected"; + txt_userip.Text = "None Selected"; + lst_usergrplist.SelectedIndex = -1; + bool flag = false; + + + if (lst_userlist.SelectedIndex > -1) + { + using (var com = DB.CreateCommand()) + { + com.CommandText = + "SELECT * FROM Users WHERE Username=@name"; + com.AddParameter("@name", lst_userlist.Items[lst_userlist.SelectedIndex]); + + using (var reader = com.ExecuteReader()) + { + if (reader.Read()) + { + txt_username.Text = reader.Get("Username"); + + if (reader.Get("IP") != "") + txt_userip.Text = reader.Get("IP"); + else + txt_userip.Text = "User does not have IP"; + + if (reader.Get("Password") != "") + txt_userpass.Text = reader.Get("Password"); + else + txt_userpass.Text = "User does not have Pasword"; + + foreach (string name in lst_usergrplist.Items) + { + if (name == reader.Get("Usergroup")) + { + lst_usergrplist.SelectedItem = name; + break; + } + } + } + else + flag = true; + } + } + + if (flag) + { + using (var com = DB.CreateCommand()) + { + com.CommandText = + "SELECT * FROM Users WHERE IP=@ip"; + com.AddParameter("@ip", lst_userlist.Items[lst_userlist.SelectedIndex]); + + using (var reader = com.ExecuteReader()) + { + if (reader.Read()) + { + if (reader.Get("Password") != "") + txt_userpass.Text = reader.Get("Password"); + else + txt_userpass.Text = "User does not have Pasword"; + + txt_userip.Text = lst_userlist.Items[lst_userlist.SelectedIndex].ToString(); + + foreach (string name in lst_usergrplist.Items) + { + if (name == reader.Get("Usergroup")) + { + lst_usergrplist.SelectedItem = name; + break; + } + } + } + } + } + } + } + } + + private void lst_usergrplist_SelectedIndexChanged(object sender, EventArgs e) + { + if (lst_userlist.SelectedIndex > -1) + { + using (var com = DB.CreateCommand()) + { + com.CommandText = + "UPDATE Users SET Usergroup=@group WHERE Username=@user OR IP=@ip"; + com.AddParameter("@group", lst_usergrplist.SelectedItem); + com.AddParameter("@user", txt_username.Text); + com.AddParameter("@ip", txt_userip.Text); + com.ExecuteNonQuery(); + } + } + } + + private void btn_deluser_Click(object sender, EventArgs e) + { + if (lst_userlist.SelectedIndex > -1) + { + using (var com = DB.CreateCommand()) + { + com.CommandText = + "DELETE FROM Users WHERE IP=@ip OR Username=@user"; + com.AddParameter("@user", txt_username.Text); + com.AddParameter("@ip", txt_userip.Text); + com.ExecuteNonQuery(); + lst_userlist.Items.Remove(lst_userlist.SelectedItem); + txt_userip.Text = ""; + txt_username.Text = ""; + txt_userpass.Text = ""; + lst_usergrplist.SelectedIndex = -1; + lst_userlist.SelectedIndex = -1; + } + } + } + + private void btn_adduser_Click(object sender, EventArgs e) + { + lbl_useraddstatus.Visible = true; + + for (int i = 0; i == 0; i++) + { + + if ((txt_newusername.Text == "" && txt_newuserpass.Text != "")) + { + lbl_useraddstatus.Text = "Username field cannot be empty"; + break; + } + + if ((txt_newusername.Text != "" && txt_newuserpass.Text == "")) + { + lbl_useraddstatus.Text = "Password field cannot be empty"; + break; + } + + if (txt_newuserip.Text == "" && (txt_newusername.Text == "" || txt_newuserpass.Text == "")) + { + lbl_useraddstatus.Text = "IP field cannot be empty"; + break; + } + + if (lst_newusergrplist.SelectedIndex == -1) + { + lbl_useraddstatus.Text = "Group must be selected"; + break; + } + + using (var com = DB.CreateCommand()) + { + com.CommandText = "INSERT INTO Users (Username, Password, UserGroup, IP) VALUES (@name, @password, @group, @ip);"; + com.AddParameter("@name", txt_newusername.Text); + com.AddParameter("@password", HashPassword(txt_newuserpass.Text)); + + com.AddParameter("@group", lst_newusergrplist.SelectedItem); + com.AddParameter("@ip", txt_newuserip.Text); + + using (var reader = com.ExecuteReader()) + { + if (reader.RecordsAffected > 0) + { + if (txt_newusername.Text != "") + lst_userlist.Items.Add(txt_newusername.Text); + else + lst_userlist.Items.Add(txt_newuserip.Text); + + txt_newuserip.Text = ""; + txt_newusername.Text = ""; + txt_newuserpass.Text = ""; + lst_newusergrplist.SelectedIndex = -1; + + lbl_useraddstatus.Text = "User added successfully!"; + } + else + lbl_useraddstatus.Text = "SQL error while adding user"; + } + } + + } + } + + public static string HashPassword(string password) + { + using (var sha = new SHA512CryptoServiceProvider()) + { + if (password == "") + { + return "nonexistent-password"; + } + var bytes = sha.ComputeHash(Encoding.ASCII.GetBytes(password)); + return bytes.Aggregate("", (s, b) => s + b.ToString("X2")); + } + } } } \ No newline at end of file