using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void 打开OToolStripMenuItem_Click(object sender, EventArgs e)
{
Form2 s = new Form2();
s.Show();
}
private void 文件FToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void menuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
Form2 ss = new Form2();
ss.MdiParent = this;
ss.BindGrade();
ss.Show();
}
private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void toolStripButton2_Click(object sender, EventArgs e)
{
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.Data;
namespace WindowsFormsApplication1
{
class DBHelper
{
// 数据库连接字符串
private string connString = @"Data Source=.;Initial Catalog=MySchool;Integrated Security=True";
// 数据库连接 Connection 对象
private SqlConnection connection;
/// <summary>
/// Connection对象
/// </summary>
public SqlConnection Connection
{
get
{
if (connection == null)
{
connection = new SqlConnection(connString);
}
return connection;
}
}
/// <summary>
/// 打开数据库连接
/// </summary>
public void OpenConnection()
{
if (Connection.State == ConnectionState.Closed)
{
Connection.Open();
}
else if (Connection.State == ConnectionState.Broken)
{
Connection.Close();
Connection.Open();
}
}
/// <summary>
/// 关闭数据库连接
/// </summary>
public void CloseConnection()
{
if (Connection.State == ConnectionState.Open || Connection.State == ConnectionState.Broken)
{
Connection.Close();
}
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Data;
namespace WindowsFormsApplication1
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
}
private void label6_Click(object sender, EventArgs e)
{
}
private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
{
}
private void Form2_Load(object sender, EventArgs e)
{
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
DBHelper SS = new DBHelper();
}
public bool BindGrade()
{
DBHelper abhelper = new DBHelper();
try
{
string sql = "SELECT*FROM [Grade]";
abhelper.OpenConnection();
SqlCommand command = new SqlCommand(sql, abhelper.Connection);
SqlDataReader myReader = command.ExecuteReader();
while (myReader.Read())
{
string gradeName = myReader["GradeName"].ToString();
nianji.Items.Add(gradeName);
}
myReader.Close();
return true;
}
catch (Exception ex)
{
MessageBox.Show("系统发生错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return false;
}
finally {
abhelper.CloseConnection();
}}
private void button1_Click_1(object sender, EventArgs e)
{
}
public bool che() {
if(this.textmima.Text.Equals("")){
MessageBox.Show("请输入密码","提示!",MessageBoxButtons.OK);
return false;
}
else if (this.xingming.Text.Equals(""))
{
MessageBox.Show("请输入姓名", "提示!", MessageBoxButtons.OK);
return false;
}
else if(this.nan.Text.Equals("") ||this.nu.Text.Equals("")){
MessageBox.Show("请输入性别", "提示!", MessageBoxButtons.OK);
return false;
}
else if(this.nianji.Text.Equals("")){
MessageBox.Show("请输入年级", "提示!", MessageBoxButtons.OK);
return false;
}
else if (this.textE.Text.Equals(""))
{
int i = this.textE.Text.IndexOf("@");
if (i == -1)
{
MessageBox.Show("请输入Email", "提示!", MessageBoxButtons.OK);
return false;
}
else
{
return true;
}
}
else {
return true;
}
}
}
}