【数据库课程设计】用户登录(一)
學(xué)生成績(jī)管理系統(tǒng)
背景資料:
1) 一個(gè)學(xué)校有不同專(zhuān)業(yè),不同年級(jí)的若干學(xué)生。2) 每個(gè)專(zhuān)業(yè)有不同的課程,每個(gè)學(xué)生選修不同的課程,每門(mén)課程被多個(gè)學(xué)生選修。3) 每個(gè)學(xué)生選修某門(mén)課程得到一個(gè)成績(jī)。
設(shè)計(jì)要求:
4) 進(jìn)行需求分析,編寫(xiě)數(shù)據(jù)字典。5) 設(shè)計(jì)E-R圖。
1) 實(shí)現(xiàn)學(xué)生基本情況的錄入、修改、刪除等基本操作。對(duì)學(xué)生基本信息提供靈活的查詢(xún)方式。2) 實(shí)現(xiàn)學(xué)生成績(jī)的錄入、修改、刪除等基本操作。
3) 能方便的對(duì)學(xué)生成績(jī)進(jìn)行查詢(xún)。4) 實(shí)現(xiàn)分類(lèi)查詢(xún)。5) 能夠刪除畢業(yè)學(xué)生的數(shù)據(jù)。6) 要有用戶(hù)登陸和身份驗(yàn)證部分;
首先創(chuàng)建一個(gè)數(shù)據(jù)庫(kù)StudentManage.mdf,新建第一個(gè)表:StudentAccount,其中ID設(shè)為主鍵+標(biāo)識(shí)(Name用戶(hù)名,Password密碼,UserType賬號(hào)類(lèi)型)
我們剛開(kāi)始先弄button,label,textbox,就這樣排版,屬性可以修改顯示名稱(chēng)
右鍵查看代碼,或者雙擊控件也能進(jìn)去
連接數(shù)據(jù)庫(kù),這里工具里面直接搞
進(jìn)入App.config設(shè)置一下數(shù)據(jù)庫(kù)吧
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
<connectionStrings>
<add name="SQL"
connectionString="Data Source=(LocalDB)MSSQLLocalDB;AttachDbFilename=E:codeTEXTSQLStudentManage.mdf;Integrated Security=True;Connect Timeout=30"
providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
回到Form代碼界面,準(zhǔn)備一些引用,
沒(méi)學(xué)過(guò)C#,下面代碼是模仿他人寫(xiě)的(以后會(huì)填坑?)
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.Configuration;
namespace ClassHomeWork
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public static string UserName;
public static string UserType;
public static int ID;
string connstr = ConfigurationManager.ConnectionStrings["StudentSql"].ConnectionString;
//定義全局變量 獲取類(lèi)型+學(xué)號(hào)+id
// 鏈接數(shù)據(jù)庫(kù),命名為connstr
private void label2_Click(object sender, EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(connstr);
//一個(gè)數(shù)據(jù)庫(kù)到conn的鏈接
string sql = "select Password,UserType,ID from StudentAcconut where Name='" + textBox1.Text + "'";
SqlCommand cmd = new SqlCommand(sql, conn);
conn.Open();//打開(kāi)連接
SqlDataReader reader = cmd.ExecuteReader();
if (reader.Read())
{
string pwd = reader.GetString(0).Trim();
string utype = reader.GetString(1);
int id = reader.GetInt32(2);
if (pwd == textBox2.Text)
{
UserName = textBox1.Text;
UserType = utype;
ID = id;
MessageBox.Show("系統(tǒng)登錄成功,正在跳轉(zhuǎn)主頁(yè)面...");
// MainForm mainForm = new MainForm();
// mainForm.Show();
this.Hide();
}
else
{
MessageBox.Show("密碼錯(cuò)誤!請(qǐng)?jiān)俅屋斎?");
textBox2.Text = "";
}
}
else
{
MessageBox.Show("用戶(hù)名不存在,請(qǐng)重新輸入!");
textBox1.Text = "";
}
}
}
}
運(yùn)行結(jié)果(第一版沒(méi)什么好說(shuō)的)
哦哦,密碼是不能給人家看的,屬性設(shè)置一下吧
總結(jié)
以上是生活随笔為你收集整理的【数据库课程设计】用户登录(一)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 鞋子255码是多大码(男士255的鞋是多
- 下一篇: 微信里通讯录备份在哪(微信怎么查看经常联