📄 addspecialty.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Runtime.InteropServices;
namespace WindowsApplication1
{
/// <summary>
/// tjzy 的摘要说明。
/// </summary>
public class AddSpecialty : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Data.OleDb.OleDbConnection oleDbConnection1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
/// <summary>
/// 必需的设计器变量。
/// </summary>
[DllImport("User32.dll")]
public static extern int MessageBox(int h,string m,string c,int type);
private System.ComponentModel.Container components = null;
public AddSpecialty()
{
//
// 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.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.oleDbConnection1 = new System.Data.OleDb.OleDbConnection();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.textBox1.ForeColor = System.Drawing.SystemColors.ControlText;
this.textBox1.Location = new System.Drawing.Point(96, 36);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(331, 25);
this.textBox1.TabIndex = 0;
this.textBox1.Text = "";
//
// textBox2
//
this.textBox2.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.textBox2.ForeColor = System.Drawing.SystemColors.ControlText;
this.textBox2.Location = new System.Drawing.Point(96, 82);
this.textBox2.Multiline = true;
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(331, 83);
this.textBox2.TabIndex = 1;
this.textBox2.Text = "";
//
// button1
//
this.button1.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.button1.ForeColor = System.Drawing.SystemColors.ControlText;
this.button1.Location = new System.Drawing.Point(53, 185);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(100, 30);
this.button1.TabIndex = 2;
this.button1.Text = "确定";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.button2.ForeColor = System.Drawing.SystemColors.ControlText;
this.button2.Location = new System.Drawing.Point(309, 185);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(100, 30);
this.button2.TabIndex = 3;
this.button2.Text = "取消";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// oleDbConnection1
//
this.oleDbConnection1.ConnectionString = "Data Source=xsxxdb.mdb;Jet OLEDB:Engine Type=5;Provider=Microsoft.Jet." +
"OLEDB.4.0;";
//
// label1
//
this.label1.AutoSize = true;
this.label1.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label1.ForeColor = System.Drawing.SystemColors.ControlText;
this.label1.Location = new System.Drawing.Point(192, 10);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(67, 21);
this.label1.TabIndex = 4;
this.label1.Text = "添加专业";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label2.ForeColor = System.Drawing.SystemColors.ControlText;
this.label2.Location = new System.Drawing.Point(11, 41);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(67, 21);
this.label2.TabIndex = 5;
this.label2.Text = "专业名称";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label3.ForeColor = System.Drawing.SystemColors.ControlText;
this.label3.Location = new System.Drawing.Point(11, 82);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(67, 21);
this.label3.TabIndex = 6;
this.label3.Text = "专业描述";
//
// AddSpecialty
//
this.AutoScaleBaseSize = new System.Drawing.Size(8, 18);
this.ClientSize = new System.Drawing.Size(461, 224);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.Name = "AddSpecialty";
this.Text = "添加专业";
this.ResumeLayout(false);
}
#endregion
private void button1_Click(object sender, System.EventArgs e)
{
if ((textBox1.Text.Trim()=="") || (textBox2.Text.Trim()==""))
MessageBox(0,"请输入完整的专业信息","提示",0);
else
{
oleDbConnection1.Open();
OleDbCommand cmd=new OleDbCommand("select * from specialtyinfo where specialtyname='"+textBox1.Text.Trim()+"'",oleDbConnection1);
if (null!=cmd.ExecuteScalar())
MessageBox(0,"专业名称发生重复","提示",0);
else
{
string sql="insert into specialtyinfo (specialtyname,remark) values ('"+textBox1.Text.Trim()+"','"+textBox2.Text.Trim()+"')";
cmd.CommandText=sql;
cmd.ExecuteNonQuery();
MessageBox(0,"专业信息添加成功","提示",0);
textBox1.Clear();
textBox2.Clear();
}
oleDbConnection1.Close();
}
}
private void button2_Click(object sender, System.EventArgs e)
{
this.Close();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -