建立一个简单的学生信息管理系统实行简单的数据库增删改查(含数据库)【调试说明】通过SQLQuery1.sql 创建sql server数据库,无须修改数据库连接串 即可运行程序账号密码均为 admin
using System;using System.Data;using System.Drawing;using System.Windows.Forms;using System.Data.SqlClient;namespace 学生管理系统{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Button1_Click(object sender, EventArgs e) { //判断用户名和密码 String name = textBox1.Text.Trim(); String pwd = textBox2.Text.Trim(); if (String.IsNullOrEmpty(name) || String.IsNullOrEmpty(pwd)) { MessageBox.Show("用户名或密码不能为空!"); return; } //数据库链接 String mycon = "Data Source=.;Initial Catalog=userDB;Integrated Security=True"; SqlConnection con = new SqlConnection(mycon); con.Open(); if (con.State!=ConnectionState.Open) { MessageBox.Show("链接数据库失败"); return; } String sql = string.Format("select count(*) from T_user where username = '{0}'and userpwd='{1}'", name, pwd); SqlCommand cmd = new SqlCommand(sql, con); int i = Convert.ToInt32(cmd.ExecuteScalar()); if (i > 0)//如果大于1,说明记录存在,登录成功 { MessageBox.Show("登录成功!"); this.DialogResult = DialogResult.OK; con.Close(); this.Dispose(); this.Close(); } else { MessageBox.Show("用户名或者密码错误!"); } } private void Button2_Click(object sender, EventArgs e) { this.Close(); } //点击控件窗口最小化 private void Label3_Click(object sender, EventArgs e) { WindowState = FormWindowState.Minimized; } //鼠标移动到控件时背景颜色发生变化以及字体颜色变成白色 private void Label3_MouseMove(object sender, MouseEventArgs e) { label3.ForeColor = Color.White; label3.BackColor = Color.FromArgb(30, 0, 0, 0); } //鼠标离开最小化控件时字体颜色以及背景颜色恢复原样 private void Label3_MouseLeave(object sender, EventArgs e) { label3.ForeColor = Color.DimGray; label3.BackColor = Color.Transparent; } //点击控件关闭窗口 private void Label4_Click(object sender, EventArgs e) { this.Close(); } //鼠标移动到控件时背景颜色变成红色 private void Label4_MouseMove(object sender, MouseEventArgs e) { label4.BackColor = Color.Red; } //鼠标移动到控件时背景颜色变成透明 private void Label4_MouseLeave(object sender, EventArgs e) { label4.BackColor = Color.Transparent; } private Point mPoint; private void Form1_MouseDown(object sender, MouseEventArgs e) { mPoint = new Point(e.X, e.Y); } private void Form1_MouseMove(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { this.Location = new Point(this.Location.X e.X - mPoint.X, this.Location.Y e.Y - mPoint.Y); } } }}
评论