?? usersetting.cs
字號:
using System;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using Library.Class;
namespace Library
{
/// <summary>
/// UserSetting 的摘要說明。
/// </summary>
public class UserSetting : System.Windows.Forms.Form
{
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.TextBox textBox3;
private System.Windows.Forms.ListView listView1;
private System.Windows.Forms.CheckBox checkBox1;
private System.Windows.Forms.CheckBox checkBox2;
private System.Windows.Forms.CheckBox checkBox3;
private System.Windows.Forms.CheckBox checkBox4;
private System.Windows.Forms.CheckBox checkBox5;
private System.Windows.Forms.CheckBox checkBox6;
private System.Windows.Forms.Button button4;
private System.Windows.Forms.Button button5;
/// <summary>
/// 必需的設計器變量。
/// </summary>
private System.ComponentModel.Container components = null;
private SqlCommand cmd;
private SqlDataReader dr;
private Library.Class.HashMethod hm = new HashMethod();
private bool isUpdate = false;
public UserSetting()
{
//
// Windows 窗體設計器支持所必需的
//
InitializeComponent();
listView1.Columns.Add("編號",40,HorizontalAlignment.Left);
listView1.Columns.Add("用戶名",50,HorizontalAlignment.Left);
listView1.Columns.Add("系統(tǒng)設置",70,HorizontalAlignment.Left);
listView1.Columns.Add("圖書設置",70,HorizontalAlignment.Left);
listView1.Columns.Add("圖書管理",70,HorizontalAlignment.Left);
listView1.Columns.Add("讀者管理",70,HorizontalAlignment.Left);
listView1.Columns.Add("系統(tǒng)查詢",70,HorizontalAlignment.Left);
listView1.Columns.Add("統(tǒng)計排名",70,HorizontalAlignment.Left);
}
/// <summary>
/// 清理所有正在使用的資源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗體設計器生成的代碼
/// <summary>
/// 設計器支持所需的方法 - 不要使用代碼編輯器修改
/// 此方法的內容。
/// </summary>
private void InitializeComponent()
{
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.checkBox6 = new System.Windows.Forms.CheckBox();
this.checkBox5 = new System.Windows.Forms.CheckBox();
this.checkBox4 = new System.Windows.Forms.CheckBox();
this.checkBox3 = new System.Windows.Forms.CheckBox();
this.checkBox2 = new System.Windows.Forms.CheckBox();
this.checkBox1 = new System.Windows.Forms.CheckBox();
this.listView1 = new System.Windows.Forms.ListView();
this.textBox3 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.textBox1 = new System.Windows.Forms.TextBox();
this.label5 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.button4 = new System.Windows.Forms.Button();
this.button5 = new System.Windows.Forms.Button();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// groupBox1
//
this.groupBox1.Controls.Add(this.checkBox6);
this.groupBox1.Controls.Add(this.checkBox5);
this.groupBox1.Controls.Add(this.checkBox4);
this.groupBox1.Controls.Add(this.checkBox3);
this.groupBox1.Controls.Add(this.checkBox2);
this.groupBox1.Controls.Add(this.checkBox1);
this.groupBox1.Controls.Add(this.listView1);
this.groupBox1.Controls.Add(this.textBox3);
this.groupBox1.Controls.Add(this.textBox2);
this.groupBox1.Controls.Add(this.textBox1);
this.groupBox1.Controls.Add(this.label5);
this.groupBox1.Controls.Add(this.label4);
this.groupBox1.Controls.Add(this.label3);
this.groupBox1.Controls.Add(this.label1);
this.groupBox1.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.groupBox1.Location = new System.Drawing.Point(16, 16);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(512, 344);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "基本設置";
//
// checkBox6
//
this.checkBox6.Enabled = false;
this.checkBox6.Location = new System.Drawing.Point(360, 128);
this.checkBox6.Name = "checkBox6";
this.checkBox6.Size = new System.Drawing.Size(80, 24);
this.checkBox6.TabIndex = 6;
this.checkBox6.Text = "統(tǒng)計排名";
//
// checkBox5
//
this.checkBox5.Enabled = false;
this.checkBox5.Location = new System.Drawing.Point(232, 128);
this.checkBox5.Name = "checkBox5";
this.checkBox5.Size = new System.Drawing.Size(80, 24);
this.checkBox5.TabIndex = 5;
this.checkBox5.Text = "系統(tǒng)查詢";
//
// checkBox4
//
this.checkBox4.Enabled = false;
this.checkBox4.Location = new System.Drawing.Point(104, 128);
this.checkBox4.Name = "checkBox4";
this.checkBox4.Size = new System.Drawing.Size(80, 24);
this.checkBox4.TabIndex = 4;
this.checkBox4.Text = "讀者管理";
//
// checkBox3
//
this.checkBox3.Enabled = false;
this.checkBox3.Location = new System.Drawing.Point(360, 88);
this.checkBox3.Name = "checkBox3";
this.checkBox3.Size = new System.Drawing.Size(80, 24);
this.checkBox3.TabIndex = 3;
this.checkBox3.Text = "圖書管理";
//
// checkBox2
//
this.checkBox2.Enabled = false;
this.checkBox2.Location = new System.Drawing.Point(232, 88);
this.checkBox2.Name = "checkBox2";
this.checkBox2.Size = new System.Drawing.Size(80, 24);
this.checkBox2.TabIndex = 2;
this.checkBox2.Text = "圖書設置";
//
// checkBox1
//
this.checkBox1.Enabled = false;
this.checkBox1.Location = new System.Drawing.Point(104, 88);
this.checkBox1.Name = "checkBox1";
this.checkBox1.Size = new System.Drawing.Size(80, 24);
this.checkBox1.TabIndex = 1;
this.checkBox1.Text = "系統(tǒng)設置";
//
// listView1
//
this.listView1.FullRowSelect = true;
this.listView1.GridLines = true;
this.listView1.Location = new System.Drawing.Point(24, 200);
this.listView1.Name = "listView1";
this.listView1.Size = new System.Drawing.Size(464, 120);
this.listView1.TabIndex = 9;
this.listView1.View = System.Windows.Forms.View.Details;
this.listView1.Click += new System.EventHandler(this.listView1_Click);
//
// textBox3
//
this.textBox3.Enabled = false;
this.textBox3.Location = new System.Drawing.Point(360, 168);
this.textBox3.Name = "textBox3";
this.textBox3.PasswordChar = '*';
this.textBox3.Size = new System.Drawing.Size(128, 21);
this.textBox3.TabIndex = 8;
this.textBox3.Text = "";
//
// textBox2
//
this.textBox2.Enabled = false;
this.textBox2.Location = new System.Drawing.Point(104, 168);
this.textBox2.Name = "textBox2";
this.textBox2.PasswordChar = '*';
this.textBox2.Size = new System.Drawing.Size(128, 21);
this.textBox2.TabIndex = 7;
this.textBox2.Text = "";
//
// textBox1
//
this.textBox1.Enabled = false;
this.textBox1.Location = new System.Drawing.Point(104, 30);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(208, 21);
this.textBox1.TabIndex = 0;
this.textBox1.Text = "";
//
// label5
//
this.label5.AutoSize = true;
this.label5.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.label5.Location = new System.Drawing.Point(256, 170);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(91, 17);
this.label5.TabIndex = 4;
this.label5.Text = "管理員密碼確認";
//
// label4
//
this.label4.AutoSize = true;
this.label4.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.label4.Location = new System.Drawing.Point(24, 170);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(66, 17);
this.label4.TabIndex = 3;
this.label4.Text = "管理員密碼";
//
// label3
//
this.label3.AutoSize = true;
this.label3.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.label3.Location = new System.Drawing.Point(24, 64);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(66, 17);
this.label3.TabIndex = 2;
this.label3.Text = "管理員權限";
//
// label1
//
this.label1.AutoSize = true;
this.label1.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.label1.Location = new System.Drawing.Point(24, 32);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(66, 17);
this.label1.TabIndex = 0;
this.label1.Text = "管理員名稱";
//
// button1
//
this.button1.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.button1.Location = new System.Drawing.Point(136, 376);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(64, 23);
this.button1.TabIndex = 10;
this.button1.Text = "新增";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.button2.Location = new System.Drawing.Point(216, 376);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(64, 23);
this.button2.TabIndex = 11;
this.button2.Text = "更改";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// button3
//
this.button3.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.button3.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.button3.Location = new System.Drawing.Point(456, 376);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(64, 23);
this.button3.TabIndex = 12;
this.button3.Text = "關閉";
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// button4
//
this.button4.Enabled = false;
this.button4.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.button4.Location = new System.Drawing.Point(296, 376);
this.button4.Name = "button4";
this.button4.Size = new System.Drawing.Size(64, 23);
this.button4.TabIndex = 13;
this.button4.Text = "保存";
this.button4.Click += new System.EventHandler(this.button4_Click);
//
// button5
//
this.button5.Enabled = false;
this.button5.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.button5.Location = new System.Drawing.Point(376, 376);
this.button5.Name = "button5";
this.button5.Size = new System.Drawing.Size(64, 23);
this.button5.TabIndex = 14;
this.button5.Text = "刪除";
this.button5.Click += new System.EventHandler(this.button5_Click);
//
// UserSetting
//
this.AcceptButton = this.button4;
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.CancelButton = this.button3;
this.ClientSize = new System.Drawing.Size(546, 416);
this.ControlBox = false;
this.Controls.Add(this.button5);
this.Controls.Add(this.button4);
this.Controls.Add(this.button3);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.groupBox1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.Name = "UserSetting";
this.ShowInTaskbar = false;
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "管理員設置";
this.Load += new System.EventHandler(this.UserSetting_Load);
this.groupBox1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 初始化界面
/// </summary>
private void initializeScreen()
{
button1.Enabled = true;
button2.Enabled = false;
button4.Enabled = false;
button5.Enabled = false;
checkBox1.Checked = false;
checkBox2.Checked = false;
checkBox3.Checked = false;
checkBox4.Checked = false;
checkBox5.Checked = false;
checkBox6.Checked = false;
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
listView1.Items.Clear();
string str = "select * from 管理員";
cmd.CommandText = str;
ListViewItem item = null;
try
{
dr = cmd.ExecuteReader();
while(dr.Read())
{
item = new ListViewItem(dr.GetInt32(0).ToString());
item.SubItems.Add(dr.GetString(1));
for(int i = 2;i<=7;i++)
{
if(dr.GetInt32(i) == 1)
{
item.SubItems.Add("是");
}
else if(dr.GetInt32(i) == 0)
{
item.SubItems.Add("否");
}
//item.SubItems.Add();
}
listView1.Items.Add(item);
}
dr.Close();
}
catch(Exception ex)
{
if(dr != null) dr.Close();
MessageBox.Show(ex.ToString());
}
finally
{
if(dr != null) dr.Close();
}
}
/// <summary>
/// 驗證用戶輸入是否合法,即是否包含不合法字符
/// </summary>
/// <param name="validchars"></param>
/// <param name="userinput"></param>
/// <returns></returns>
private bool ValidateInput(String validchars, String userinput)
{
foreach(Char c in userinput)
{
if(validchars.IndexOf(c) < 0)
{
return false;
}
}
return true;
}
/// <summary>
/// 檢查字符串
/// </summary>
/// <param name="str_01"></param>
/// <param name="str_02"></param>
/// <returns></returns>
private void CheckString(string str_01,string str_02)
{
//vChars提供字符驗證所需的字符
String vChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz*&%$#!";
if(ValidateInput(vChars, str_01))
{
if(ValidateInput(vChars,str_02)!=true)
{
MessageBox.Show("密碼非法!可能是含有非法字符串。","錯誤");
textBox2.SelectAll();
return;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -