我还是要做一个简易的学生管理系统,使用winform的控件来完成页面的搭建,c sharp完成逻辑的填充,使用mysql来存储数据。
登录这里的最主要的逻辑就是点击登录按钮后连接数据库进行判断然后登录到主页面。其次是当用户输入完成用户名之后会自动寻找匹配的图片并显示出来。
注册这里就是简单的添加一下,然后给密码、身份证、手机号加一个判断格式的正则,顺便在加入数据库的时候计算出年龄、性别、出生年月。
重置密码这里也是差不多的逻辑。
显示主页面只有一些基础的功能,用listView来显示数据库的数据。
修改这里我设置只能修改用户自己的各项信息。
这里我先写了登录页面的一部分代码。
Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.Common;
using System.Drawing;
using System.Linq;
using System.Runtime.Remoting.Messaging;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
namespace _1.登录页面
{
public partial class Form1 : Form
{
MySqlConnection conn;
public Form1()
{
InitializeComponent();
}
//焦点在textBox1
private void Form1_Activated(object sender, EventArgs e)
{
textBox1.Focus();
}
private void button2_Click(object sender, EventArgs e)
{
ZhuCe zhuce = new ZhuCe();
if(zhuce.ShowDialog() == DialogResult.OK)
{
textBox1.Text= zhuce.textBox1.Text;
textBox2.Text= zhuce.textBox2.Text;
Conn c = new Conn();
conn = c.conn();
ImageLoad load = new ImageLoad();
string str = load.load(conn, textBox1.Text);
if (str != null)
{
Bitmap bmp = new Bitmap(str);
pictureBox2.Image = bmp;
}
else { pictureBox2.Image = null; }
conn.Close();
}
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (checkBox1.Checked)
{
textBox2.PasswordChar = '\0';
}
else
{
textBox2.PasswordChar = '*';
}
}
private void textBox1_Leave(object sender, EventArgs e)
{
Conn c = new Conn();
conn = c.conn();
ImageLoad load = new ImageLoad();
string str = load.load(conn, textBox1.Text);
if (str != null)
{
Bitmap bmp = new Bitmap(str);
pictureBox2.Image = bmp;
}
else { pictureBox2.Image = null; }
conn.Close();
}
private void button3_Click(object sender, EventArgs e)
{
Mima mima = new Mima();
if(mima.ShowDialog() == DialogResult.OK)
{
textBox1.Text = mima.textBox1.Text;
textBox2.Text = mima.textBox4.Text;
Conn c = new Conn();
conn = c.conn();
ImageLoad load = new ImageLoad();
string str = load.load(conn, textBox1.Text);
if (str != null)
{
Bitmap bmp = new Bitmap(str);
pictureBox2.Image = bmp;
}
else { pictureBox2.Image = null; }
conn.Close();
}
}
private void button1_Click(object sender, EventArgs e)
{
Student student = new Student();
student.Name = textBox1.Text;
student.Password = textBox2.Text;
Conn c = new Conn();
conn = c.conn();
DengLu dengLu = new DengLu();
if(dengLu.login(conn, student))
{
this.Dispose(false);
MainForm main=new MainForm();
main.Show();
}
}
private void uiButton1_Click(object sender, EventArgs e)
{
Student student = new Student();
student.Name = textBox1.Text;
student.Password = textBox2.Text;
Conn c = new Conn();
conn = c.conn();
DengLu dengLu = new DengLu();
if (dengLu.login(conn, student))
{
this.Dispose(false);
MainForm main = new MainForm();
main.Show();
}
}
private void uiButton2_Click(object sender, EventArgs e)
{
MainForm main = new MainForm();
main.Show();
}
}
}
Form.Designer.cs
namespace _1.登录页面
{
partial class Form1
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.button2 = new System.Windows.Forms.Button();
this.checkBox1 = new System.Windows.Forms.CheckBox();
this.button3 = new System.Windows.Forms.Button();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.pictureBox2 = new System.Windows.Forms.PictureBox();
this.uiButton1 = new Sunny.UI.UIButton();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).BeginInit();
this.SuspendLayout();
//
// label1
//
this.label1.Anchor = System.Windows.Forms.AnchorStyles.None;
this.label1.AutoSize = true;
this.label1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))));
this.label1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.label1.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label1.Location = new System.Drawing.Point(170, 158);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(78, 23);
this.label1.TabIndex = 0;
this.label1.Text = "用户:";
//
// label2
//
this.label2.Anchor = System.Windows.Forms.AnchorStyles.None;
this.label2.AutoSize = true;
this.label2.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))));
this.label2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.label2.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label2.Location = new System.Drawing.Point(170, 204);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(78, 23);
this.label2.TabIndex = 1;
this.label2.Text = "密码:";
//
// textBox1
//
this.textBox1.Anchor = System.Windows.Forms.AnchorStyles.None;
this.textBox1.Location = new System.Drawing.Point(259, 155);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(196, 28);
this.textBox1.TabIndex = 2;
this.textBox1.Leave += new System.EventHandler(this.textBox1_Leave);
//
// textBox2
//
this.textBox2.Anchor = System.Windows.Forms.AnchorStyles.None;
this.textBox2.Location = new System.Drawing.Point(259, 201);
this.textBox2.Name = "textBox2";
this.textBox2.PasswordChar = '*';
this.textBox2.Size = new System.Drawing.Size(196, 28);
this.textBox2.TabIndex = 2;
//
// button2
//
this.button2.Anchor = System.Windows.Forms.AnchorStyles.None;
this.button2.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(192)))), ((int)(((byte)(255)))));
this.button2.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
this.button2.Location = new System.Drawing.Point(233, 276);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(84, 36);
this.button2.TabIndex = 3;
this.button2.Text = "注册";
this.button2.UseVisualStyleBackColor = false;
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// checkBox1
//
this.checkBox1.Anchor = System.Windows.Forms.AnchorStyles.None;
this.checkBox1.AutoSize = true;
this.checkBox1.BackColor = System.Drawing.Color.PaleTurquoise;
this.checkBox1.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
this.checkBox1.Location = new System.Drawing.Point(470, 205);
this.checkBox1.Name = "checkBox1";
this.checkBox1.Size = new System.Drawing.Size(106, 22);
this.checkBox1.TabIndex = 4;
this.checkBox1.Text = "显示密码";
this.checkBox1.UseVisualStyleBackColor = false;
this.checkBox1.CheckedChanged += new System.EventHandler(this.checkBox1_CheckedChanged);
//
// button3
//
this.button3.Anchor = System.Windows.Forms.AnchorStyles.None;
this.button3.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(192)))), ((int)(((byte)(255)))));
this.button3.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
this.button3.Location = new System.Drawing.Point(380, 276);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(101, 36);
this.button3.TabIndex = 3;
this.button3.Text = "忘记密码";
this.button3.UseVisualStyleBackColor = false;
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// pictureBox1
//
this.pictureBox1.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBox1.Image = global::_1.登录页面.Properties.Resources._2;
this.pictureBox1.Location = new System.Drawing.Point(0, 0);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(703, 462);
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.pictureBox1.TabIndex = 5;
this.pictureBox1.TabStop = false;
//
// pictureBox2
//
this.pictureBox2.Location = new System.Drawing.Point(293, 26);
this.pictureBox2.Name = "pictureBox2";
this.pictureBox2.Size = new System.Drawing.Size(117, 111);
this.pictureBox2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.pictureBox2.TabIndex = 7;
this.pictureBox2.TabStop = false;
//
// uiButton1
//
this.uiButton1.Cursor = System.Windows.Forms.Cursors.Hand;
this.uiButton1.FillColor = System.Drawing.Color.FromArgb(((int)(((byte)(110)))), ((int)(((byte)(190)))), ((int)(((byte)(40)))));
this.uiButton1.FillColor2 = System.Drawing.Color.FromArgb(((int)(((byte)(110)))), ((int)(((byte)(190)))), ((int)(((byte)(40)))));
this.uiButton1.FillHoverColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(192)))), ((int)(((byte)(128)))));
this.uiButton1.FillPressColor = System.Drawing.Color.FromArgb(((int)(((byte)(88)))), ((int)(((byte)(152)))), ((int)(((byte)(32)))));
this.uiButton1.FillSelectedColor = System.Drawing.Color.FromArgb(((int)(((byte)(88)))), ((int)(((byte)(152)))), ((int)(((byte)(32)))));
this.uiButton1.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.uiButton1.LightColor = System.Drawing.Color.FromArgb(((int)(((byte)(245)))), ((int)(((byte)(251)))), ((int)(((byte)(241)))));
this.uiButton1.Location = new System.Drawing.Point(286, 342);
this.uiButton1.MinimumSize = new System.Drawing.Size(1, 1);
this.uiButton1.Name = "uiButton1";
this.uiButton1.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)(110)))), ((int)(((byte)(190)))), ((int)(((byte)(40)))));
this.uiButton1.RectHoverColor = System.Drawing.Color.FromArgb(((int)(((byte)(139)))), ((int)(((byte)(203)))), ((int)(((byte)(83)))));
this.uiButton1.RectPressColor = System.Drawing.Color.FromArgb(((int)(((byte)(88)))), ((int)(((byte)(152)))), ((int)(((byte)(32)))));
this.uiButton1.RectSelectedColor = System.Drawing.Color.FromArgb(((int)(((byte)(88)))), ((int)(((byte)(152)))), ((int)(((byte)(32)))));
this.uiButton1.Size = new System.Drawing.Size(124, 57);
this.uiButton1.Style = Sunny.UI.UIStyle.Custom;
this.uiButton1.TabIndex = 8;
this.uiButton1.Text = "登录";
this.uiButton1.TipsFont = new System.Drawing.Font("宋体", 14F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.uiButton1.Click += new System.EventHandler(this.uiButton1_Click);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 18F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(703, 462);
this.Controls.Add(this.uiButton1);
this.Controls.Add(this.pictureBox2);
this.Controls.Add(this.checkBox1);
this.Controls.Add(this.button3);
this.Controls.Add(this.button2);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.pictureBox1);
this.Name = "Form1";
this.Text = "学生管理系统";
this.Activated += new System.EventHandler(this.Form1_Activated);
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.CheckBox checkBox1;
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.PictureBox pictureBox2;
private Sunny.UI.UIButton uiButton1;
}
}
别的逻辑还没有填充完,之后一起放出来。