UserManage.cs
上传用户:chizxy
上传日期:2014-11-29
资源大小:407k
文件大小:10k
- using System;
- using System.Drawing;
- using System.Collections;
- using System.ComponentModel;
- using System.Windows.Forms;
- using System.Data;
- using System.Data.SqlClient;
- namespace MKIms3
- {
- /// <summary>
- /// UserManage 的摘要说明。
- /// </summary>
- public class UserManage : System.Windows.Forms.Form
- {
- private System.Windows.Forms.DataGridBoolColumn dataGridBoolColumn;
- // private DataBase myDB;
- private DataSet user_Set;
- private DataGridTableStyle GridTableStyle;
- private System.Windows.Forms.GroupBox groupBox1;
- private System.Windows.Forms.Label label1;
- private System.Windows.Forms.TextBox txt_uname;
- private System.Windows.Forms.Button btn_query;
- private System.Windows.Forms.Button btn_all;
- private System.Windows.Forms.Button btn_ok;
- private System.Windows.Forms.Label label2;
- private System.Windows.Forms.DataGrid dataGrid_user;
- private System.Windows.Forms.PictureBox pictureBox1;
- /// <summary>
- /// 必需的设计器变量。
- /// </summary>
- private System.ComponentModel.Container components = null;
- public UserManage()
- {
- //
- // Windows 窗体设计器支持所必需的
- //
- InitializeComponent();
- //
- // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
- //
- }
- /// <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()
- {
- System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(UserManage));
- this.dataGrid_user = new System.Windows.Forms.DataGrid();
- this.groupBox1 = new System.Windows.Forms.GroupBox();
- this.btn_all = new System.Windows.Forms.Button();
- this.btn_query = new System.Windows.Forms.Button();
- this.txt_uname = new System.Windows.Forms.TextBox();
- this.label1 = new System.Windows.Forms.Label();
- this.btn_ok = new System.Windows.Forms.Button();
- this.label2 = new System.Windows.Forms.Label();
- this.pictureBox1 = new System.Windows.Forms.PictureBox();
- ((System.ComponentModel.ISupportInitialize)(this.dataGrid_user)).BeginInit();
- this.groupBox1.SuspendLayout();
- this.SuspendLayout();
- //
- // dataGrid_user
- //
- this.dataGrid_user.AlternatingBackColor = System.Drawing.SystemColors.Info;
- this.dataGrid_user.CaptionText = "用户列表";
- this.dataGrid_user.DataMember = "";
- this.dataGrid_user.HeaderForeColor = System.Drawing.SystemColors.ControlText;
- this.dataGrid_user.Location = new System.Drawing.Point(176, 56);
- this.dataGrid_user.Name = "dataGrid_user";
- this.dataGrid_user.PreferredColumnWidth = 90;
- this.dataGrid_user.Size = new System.Drawing.Size(312, 160);
- this.dataGrid_user.TabIndex = 4;
- //
- // groupBox1
- //
- this.groupBox1.Controls.Add(this.btn_all);
- this.groupBox1.Controls.Add(this.btn_query);
- this.groupBox1.Controls.Add(this.txt_uname);
- this.groupBox1.Controls.Add(this.label1);
- this.groupBox1.Location = new System.Drawing.Point(176, 8);
- this.groupBox1.Name = "groupBox1";
- this.groupBox1.Size = new System.Drawing.Size(312, 40);
- this.groupBox1.TabIndex = 1;
- this.groupBox1.TabStop = false;
- this.groupBox1.Text = "操作区";
- //
- // btn_all
- //
- this.btn_all.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
- this.btn_all.Location = new System.Drawing.Point(232, 11);
- this.btn_all.Name = "btn_all";
- this.btn_all.Size = new System.Drawing.Size(75, 24);
- this.btn_all.TabIndex = 3;
- this.btn_all.Text = "浏览全部";
- this.btn_all.Click += new System.EventHandler(this.btn_all_Click);
- //
- // btn_query
- //
- this.btn_query.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
- this.btn_query.Location = new System.Drawing.Point(167, 11);
- this.btn_query.Name = "btn_query";
- this.btn_query.Size = new System.Drawing.Size(56, 24);
- this.btn_query.TabIndex = 2;
- this.btn_query.Text = "查询";
- this.btn_query.Click += new System.EventHandler(this.btn_query_Click);
- //
- // txt_uname
- //
- this.txt_uname.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
- this.txt_uname.Location = new System.Drawing.Point(61, 12);
- this.txt_uname.Name = "txt_uname";
- this.txt_uname.TabIndex = 1;
- this.txt_uname.Text = "";
- //
- // label1
- //
- this.label1.Location = new System.Drawing.Point(5, 12);
- this.label1.Name = "label1";
- this.label1.Size = new System.Drawing.Size(56, 23);
- this.label1.TabIndex = 0;
- this.label1.Text = "用户名:";
- this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
- //
- // btn_ok
- //
- this.btn_ok.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
- this.btn_ok.Location = new System.Drawing.Point(400, 222);
- this.btn_ok.Name = "btn_ok";
- this.btn_ok.Size = new System.Drawing.Size(64, 24);
- this.btn_ok.TabIndex = 2;
- this.btn_ok.Text = "提交修改";
- this.btn_ok.Click += new System.EventHandler(this.btn_ok_Click);
- //
- // label2
- //
- this.label2.Location = new System.Drawing.Point(13, 224);
- this.label2.Name = "label2";
- this.label2.Size = new System.Drawing.Size(392, 23);
- this.label2.TabIndex = 3;
- this.label2.Text = "系统提示:如果您对用户的资料进行了修改请提交修改以更新用户数据";
- this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
- //
- // pictureBox1
- //
- this.pictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
- this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
- this.pictureBox1.Location = new System.Drawing.Point(16, 16);
- this.pictureBox1.Name = "pictureBox1";
- this.pictureBox1.Size = new System.Drawing.Size(144, 200);
- this.pictureBox1.TabIndex = 5;
- this.pictureBox1.TabStop = false;
- //
- // UserManage
- //
- this.AcceptButton = this.btn_query;
- this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
- this.ClientSize = new System.Drawing.Size(496, 253);
- this.Controls.Add(this.pictureBox1);
- this.Controls.Add(this.btn_ok);
- this.Controls.Add(this.label2);
- this.Controls.Add(this.groupBox1);
- this.Controls.Add(this.dataGrid_user);
- this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
- this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
- this.Name = "UserManage";
- this.ShowInTaskbar = false;
- this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
- this.Text = "系统用户管理";
- this.Load += new System.EventHandler(this.UserManage_Load);
- ((System.ComponentModel.ISupportInitialize)(this.dataGrid_user)).EndInit();
- this.groupBox1.ResumeLayout(false);
- this.ResumeLayout(false);
- }
- #endregion
- #region 设置datagrid的列标题
- private void add_style(DataSet user_set)
- {
- CurrencyManager objcengCM;
- GridTableStyle = new DataGridTableStyle();
- GridTableStyle.MappingName = "users";
- objcengCM = (System.Windows.Forms.CurrencyManager)this.BindingContext[user_set.Tables[0]];
- GridTableStyle.GridColumnStyles.Add(new DataGridTextBoxColumn(objcengCM .GetItemProperties()["用户名"]));
- GridTableStyle.GridColumnStyles[0].MappingName = "用户名";
- GridTableStyle.GridColumnStyles[0].HeaderText = "用户名 ";
- GridTableStyle.GridColumnStyles[0].Width= 550;
- GridTableStyle.GridColumnStyles[0].Alignment = HorizontalAlignment.Left;
- GridTableStyle.GridColumnStyles[0].NullText = string.Empty;
-
- GridTableStyle.GridColumnStyles.Add(new DataGridTextBoxColumn(objcengCM .GetItemProperties()["用户密码"]));
- GridTableStyle.GridColumnStyles[1].MappingName = "用户密码";
- GridTableStyle.GridColumnStyles[1].HeaderText = "用户密码 ";
- GridTableStyle.RowHeaderWidth = 250;
- GridTableStyle.GridColumnStyles[1].Alignment = HorizontalAlignment.Left;
- GridTableStyle.GridColumnStyles[1].NullText = string.Empty;
-
- this.dataGridBoolColumn = new System.Windows.Forms.DataGridBoolColumn();
- dataGridBoolColumn.MappingName = "是否管理员";
- dataGridBoolColumn.FalseValue = 1;
- dataGridBoolColumn.TrueValue = 0;
- GridTableStyle.GridColumnStyles.Add(this.dataGridBoolColumn);
- GridTableStyle.GridColumnStyles[2].MappingName = "是否管理员";
- GridTableStyle.GridColumnStyles[2].HeaderText = "是否管理员";
- GridTableStyle.GridColumnStyles[2].Width = 50;
- GridTableStyle.GridColumnStyles[2].Alignment = HorizontalAlignment.Left;
- GridTableStyle.GridColumnStyles[2].NullText = string.Empty;
-
-
- }
- #endregion
- #region 得到所有的用户或者查询指定用户 ,提交更新
- /// <summary>
- /// 根据用户名得到指定的用户
- /// </summary>
- /// <param name="u_name">如果参数为""(空) 表示为所有用户</param>
- /// <returns></returns>
- private DataSet get_user(string u_name)
- {
- DataBase myDB = new DataBase();
- DataSet dataset = new DataSet();
- SqlParameter[] myParamers={new SqlParameter("@u_name",SqlDbType.Char,10)} ;
- myParamers[0].Value = u_name;
- dataset = myDB.RunProcedure("up_get_users",myParamers,"users");
- return dataset;
- }
- private bool update_user()
- {
- DataBase myDB = new DataBase();
- string select = "select u_name as 用户名,u_pass as 用户密码 , u_flag as 是否管理员 from users ";
- if(myDB.Run_change(select,this.user_Set,"users"))
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- #endregion
- private void UserManage_Load(object sender, System.EventArgs e)
- {
- user_Set = new DataSet();
- this.user_Set = get_user("");
- add_style(user_Set);
- this.dataGrid_user.SetDataBinding(user_Set,"users");
- }
- private void btn_query_Click(object sender, System.EventArgs e)
- {
- string u_name = this.txt_uname.Text.Trim();
- this.user_Set = get_user(u_name);
- this.dataGrid_user.SetDataBinding(user_Set,"users");
- }
- private void btn_all_Click(object sender, System.EventArgs e)
- {
- this.user_Set = get_user("");
- this.dataGrid_user.SetDataBinding(user_Set,"users");
-
- }
- private void btn_ok_Click(object sender, System.EventArgs e)
- {
- if(update_user())
- {
- MessageBox.Show("用户数据更新成功","提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
- }
- else
- {
- MessageBox.Show("用户数据更新失败","错误信息",MessageBoxButtons.OK,MessageBoxIcon.Warning);
- }
- }
- }
- }