📄 powerset.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.OleDb;
using System.IO;
namespace PM
{
/// <summary>
/// PowerSet 的摘要说明。
/// </summary>
public class PowerSet : System.Windows.Forms.Form
{
private System.Windows.Forms.ToolBar toolBar1;
private System.Windows.Forms.ToolBarButton toolBarButton1;
private System.Windows.Forms.ToolBarButton toolBarButton2;
private System.Windows.Forms.ToolBarButton toolBarButton3;
private System.Windows.Forms.ToolBarButton toolBarButton4;
private System.Windows.Forms.ToolBarButton toolBarButton5;
private System.Windows.Forms.ToolBarButton toolBarButton6;
private System.Windows.Forms.ImageList imageList1;
private System.Windows.Forms.ToolBarButton toolBarButton7;
private System.Windows.Forms.ToolBarButton toolBarButton8;
private System.Windows.Forms.DataGrid dataGrid1;
private System.ComponentModel.IContainer components;
private DataTable dt = new DataTable();
private static string connstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Directory.GetCurrentDirectory() + "\\manange.mdb";
private OleDbConnection conn = new OleDbConnection(connstr);
private OleDbDataAdapter da;
private CurrencyManager cm;
public PowerSet()
{
//
// 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()
{
this.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(PowerSet));
this.toolBar1 = new System.Windows.Forms.ToolBar();
this.toolBarButton1 = new System.Windows.Forms.ToolBarButton();
this.toolBarButton2 = new System.Windows.Forms.ToolBarButton();
this.toolBarButton3 = new System.Windows.Forms.ToolBarButton();
this.toolBarButton4 = new System.Windows.Forms.ToolBarButton();
this.toolBarButton5 = new System.Windows.Forms.ToolBarButton();
this.toolBarButton6 = new System.Windows.Forms.ToolBarButton();
this.toolBarButton7 = new System.Windows.Forms.ToolBarButton();
this.toolBarButton8 = new System.Windows.Forms.ToolBarButton();
this.imageList1 = new System.Windows.Forms.ImageList(this.components);
this.dataGrid1 = new System.Windows.Forms.DataGrid();
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
this.SuspendLayout();
//
// toolBar1
//
this.toolBar1.Appearance = System.Windows.Forms.ToolBarAppearance.Flat;
this.toolBar1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.toolBar1.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
this.toolBarButton1,
this.toolBarButton2,
this.toolBarButton3,
this.toolBarButton4,
this.toolBarButton5,
this.toolBarButton6,
this.toolBarButton7,
this.toolBarButton8});
this.toolBar1.DropDownArrows = true;
this.toolBar1.ImageList = this.imageList1;
this.toolBar1.Location = new System.Drawing.Point(0, 0);
this.toolBar1.Name = "toolBar1";
this.toolBar1.ShowToolTips = true;
this.toolBar1.Size = new System.Drawing.Size(528, 29);
this.toolBar1.TabIndex = 0;
this.toolBar1.TextAlign = System.Windows.Forms.ToolBarTextAlign.Right;
this.toolBar1.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.toolBar1_ButtonClick);
//
// toolBarButton1
//
this.toolBarButton1.ImageIndex = 0;
this.toolBarButton1.Text = "首记录";
this.toolBarButton1.ToolTipText = "首记录";
//
// toolBarButton2
//
this.toolBarButton2.ImageIndex = 1;
this.toolBarButton2.Text = "上记录";
this.toolBarButton2.ToolTipText = "上记录";
//
// toolBarButton3
//
this.toolBarButton3.ImageIndex = 2;
this.toolBarButton3.Text = "下记录";
this.toolBarButton3.ToolTipText = "下记录";
//
// toolBarButton4
//
this.toolBarButton4.ImageIndex = 3;
this.toolBarButton4.Text = "尾记录";
this.toolBarButton4.ToolTipText = "尾记录";
//
// toolBarButton5
//
this.toolBarButton5.ImageIndex = 4;
this.toolBarButton5.Text = "删除";
this.toolBarButton5.ToolTipText = "删除";
//
// toolBarButton6
//
this.toolBarButton6.ImageIndex = 5;
this.toolBarButton6.Text = "提交";
this.toolBarButton6.ToolTipText = "提交";
//
// toolBarButton7
//
this.toolBarButton7.ImageIndex = 6;
this.toolBarButton7.Text = "取消";
this.toolBarButton7.ToolTipText = "取消";
//
// toolBarButton8
//
this.toolBarButton8.ImageIndex = 7;
this.toolBarButton8.Text = "退出";
this.toolBarButton8.ToolTipText = "退出";
//
// imageList1
//
this.imageList1.ImageSize = new System.Drawing.Size(16, 16);
this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));
this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
//
// dataGrid1
//
this.dataGrid1.DataMember = "";
this.dataGrid1.Dock = System.Windows.Forms.DockStyle.Fill;
this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataGrid1.Location = new System.Drawing.Point(0, 29);
this.dataGrid1.Name = "dataGrid1";
this.dataGrid1.Size = new System.Drawing.Size(528, 344);
this.dataGrid1.TabIndex = 1;
//
// PowerSet
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(528, 373);
this.Controls.Add(this.dataGrid1);
this.Controls.Add(this.toolBar1);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.Name = "PowerSet";
this.Text = "用户权限设置";
this.Load += new System.EventHandler(this.PowerSet_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
this.ResumeLayout(false);
}
#endregion
private void PowerSet_Load(object sender, System.EventArgs e)
{
DBDataGrid();
Grid();
this.cm = (CurrencyManager)BindingContext[this.dt];
}
private void DBDataGrid()
{
string str = "select uId as 用户编号,uName as 用户名称,uPassword as 用户密码,uPower as 用户权限 from UserInfo";
try
{
this.da = new OleDbDataAdapter(str,this.conn);
this.conn.Open();
this.da.Fill(this.dt);
this.dataGrid1.DataSource = this.dt.DefaultView;
this.conn.Close();
}
catch(Exception error)
{
MessageBox.Show(error.ToString());
}
}
private void Grid()
{
DataGridTableStyle style = new DataGridTableStyle();
style.MappingName = this.dt.TableName;
this.dataGrid1.TableStyles.Add(style);
this.dataGrid1.Select(0);
DataGridTextBoxColumn DataBox = (DataGridTextBoxColumn)this.dataGrid1.TableStyles[0].GridColumnStyles["用户权限"];
ComboBox cb = new ComboBox();
cb.Items.AddRange(new string[3] {"系统管理员","管理员","一般用户"});
cb.Cursor = Cursors.Arrow;
cb.DropDownStyle = ComboBoxStyle.DropDownList;
cb.Dock = DockStyle.Fill;
cb.SelectionChangeCommitted +=new EventHandler(cb_SelectionChangeCommitted);
DataBox.TextBox.Controls.Add(cb);
}
private void cb_SelectionChangeCommitted(object sender, System.EventArgs e)
{
this.dataGrid1[this.dataGrid1.CurrentCell] = ((ComboBox)sender).SelectedItem.ToString();
}
private void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
{
switch(e.Button.ToolTipText)
{
case "首记录":
{
if(cm.Position != 0)
{
this.dataGrid1.UnSelect(cm.Position);
cm.Position = 0;
this.dataGrid1.Select(cm.Position);
this.dataGrid1.CurrentRowIndex = cm.Position;
}
break;
}
case "上记录":
{
if(cm.Position > 0)
{
this.dataGrid1.UnSelect(cm.Position );
cm.Position -= 1;
this.dataGrid1.Select(cm.Position);
this.dataGrid1.CurrentRowIndex = cm.Position;
}
break;
}
case "下记录":
{
if(cm.Position < cm.Count - 1)
{
this.dataGrid1.UnSelect(cm.Position );
cm.Position += 1;
this.dataGrid1.Select(cm.Position);
this.dataGrid1.CurrentRowIndex = cm.Position;
}
break;
}
case "尾记录":
{
if(cm.Position != cm.Count - 1)
{
this.dataGrid1.UnSelect(cm.Position);
cm.Position = cm.Count - 1;
this.dataGrid1.Select(cm.Count - 1);
this.dataGrid1.CurrentRowIndex = cm.Position;
}
break;
}
case "删除":
{
DialogResult result = MessageBox.Show("是否确定删除此记录?","提示!",MessageBoxButtons.YesNo,MessageBoxIcon.Question);
if(result == DialogResult.Yes)
{
cm.RemoveAt(cm.Position);
cm.EndCurrentEdit();
}
else if(result == DialogResult.No)
{
return;
}
break;
}
case "提交":
{
cm.EndCurrentEdit();
OleDbCommandBuilder cb=new OleDbCommandBuilder(this.da);
this.da.Update(this.dt);
MessageBox.Show("提交成功!");
break;
}
case "取消":
{
this.cm.CancelCurrentEdit();
this.dt.RejectChanges();
break;
}
case "退出":
{
this.Close();
break;
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -