📄 createrole.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data.OleDb;
namespace WindowsApplication1
{
/// <summary>
/// CreateRole 的摘要说明。
/// </summary>
public class CreateRole : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox textBox1;
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 button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.GroupBox groupBox1;
private System.Data.OleDb.OleDbConnection oleDbConnection1;
private System.Windows.Forms.GroupBox groupBox2;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public CreateRole()
{
//
// 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.label1 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.checkBox1 = new System.Windows.Forms.CheckBox();
this.checkBox2 = new System.Windows.Forms.CheckBox();
this.checkBox3 = new System.Windows.Forms.CheckBox();
this.checkBox4 = new System.Windows.Forms.CheckBox();
this.checkBox5 = new System.Windows.Forms.CheckBox();
this.checkBox6 = new System.Windows.Forms.CheckBox();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.oleDbConnection1 = new System.Data.OleDb.OleDbConnection();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(16, 32);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(67, 21);
this.label1.TabIndex = 0;
this.label1.Text = "角色名称";
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(88, 24);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(192, 25);
this.textBox1.TabIndex = 1;
this.textBox1.Text = "";
//
// checkBox1
//
this.checkBox1.Location = new System.Drawing.Point(16, 24);
this.checkBox1.Name = "checkBox1";
this.checkBox1.Size = new System.Drawing.Size(88, 24);
this.checkBox1.TabIndex = 2;
this.checkBox1.Text = "系统管理";
//
// checkBox2
//
this.checkBox2.Location = new System.Drawing.Point(112, 24);
this.checkBox2.Name = "checkBox2";
this.checkBox2.Size = new System.Drawing.Size(88, 24);
this.checkBox2.TabIndex = 3;
this.checkBox2.Text = "专业管理";
//
// checkBox3
//
this.checkBox3.Location = new System.Drawing.Point(208, 24);
this.checkBox3.Name = "checkBox3";
this.checkBox3.Size = new System.Drawing.Size(88, 24);
this.checkBox3.TabIndex = 4;
this.checkBox3.Text = "班级管理";
//
// checkBox4
//
this.checkBox4.Location = new System.Drawing.Point(16, 64);
this.checkBox4.Name = "checkBox4";
this.checkBox4.Size = new System.Drawing.Size(88, 24);
this.checkBox4.TabIndex = 5;
this.checkBox4.Text = "课程管理";
//
// checkBox5
//
this.checkBox5.Location = new System.Drawing.Point(112, 64);
this.checkBox5.Name = "checkBox5";
this.checkBox5.Size = new System.Drawing.Size(88, 24);
this.checkBox5.TabIndex = 6;
this.checkBox5.Text = "成绩管理";
//
// checkBox6
//
this.checkBox6.Location = new System.Drawing.Point(208, 64);
this.checkBox6.Name = "checkBox6";
this.checkBox6.Size = new System.Drawing.Size(88, 24);
this.checkBox6.TabIndex = 7;
this.checkBox6.Text = "学生管理";
//
// button1
//
this.button1.Location = new System.Drawing.Point(40, 208);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(88, 32);
this.button1.TabIndex = 8;
this.button1.Text = "创建";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(208, 208);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(88, 32);
this.button2.TabIndex = 9;
this.button2.Text = "取消";
//
// groupBox1
//
this.groupBox1.Controls.Add(this.checkBox4);
this.groupBox1.Controls.Add(this.checkBox2);
this.groupBox1.Controls.Add(this.checkBox6);
this.groupBox1.Controls.Add(this.checkBox3);
this.groupBox1.Controls.Add(this.checkBox1);
this.groupBox1.Controls.Add(this.checkBox5);
this.groupBox1.Location = new System.Drawing.Point(16, 96);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(304, 104);
this.groupBox1.TabIndex = 10;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "权限";
//
// oleDbConnection1
//
this.oleDbConnection1.ConnectionString = "Data Source=xsxxdb.mdb;Jet OLEDB:Engine Type=5;Provider=Microsoft.Jet." +
"OLEDB.4.0;";
//
// groupBox2
//
this.groupBox2.Controls.Add(this.textBox1);
this.groupBox2.Controls.Add(this.label1);
this.groupBox2.Location = new System.Drawing.Point(16, 16);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(304, 72);
this.groupBox2.TabIndex = 13;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "角色";
//
// CreateRole
//
this.AutoScaleBaseSize = new System.Drawing.Size(8, 18);
this.ClientSize = new System.Drawing.Size(336, 252);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Name = "CreateRole";
this.Text = "新建角色";
this.groupBox1.ResumeLayout(false);
this.groupBox2.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private void button1_Click(object sender, System.EventArgs e)
{
oleDbConnection1.Open();
string sql;
OleDbCommand cmd=new OleDbCommand("",oleDbConnection1);
if (textBox1.Text!="")
{
sql="select * from Roles where RoleName='"+textBox1.Text.Trim()+"'";
cmd.CommandText=sql;
if (null==cmd.ExecuteScalar())
{
sql="insert into Roles values ('"+textBox1.Text.Trim()+"',"+checkBox1.Checked+","+checkBox2.Checked+","+checkBox3.Checked+","+checkBox4.Checked+","+checkBox5.Checked+","+checkBox6.Checked+")";
cmd.CommandText=sql;
cmd.ExecuteNonQuery();
MessageBox.Show("角色创建成功");
}
else
MessageBox.Show("已有重名角色存在","提示");
}
else
MessageBox.Show("角色名称不能为空");
oleDbConnection1.Close();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -