课程设计报告-示例(3)

2019-03-09 14:15

第4章 系统实现

4.1 登录模块实现

本系统的登录界面如图4-1所示,输入姓名和密码,点击确定,判断用户名和密码是否正确,正确可进入系统主界面,否则提示错误信息。点击取消,退出登录窗口

using System;

using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text;

using System.Windows.Forms; using System.Data.SqlClient;

namespace WindowsFormsApplication1 {

public partial class Form1 : Form {

public Form1() {

InitializeComponent(); }

private void button1_Click(object sender, EventArgs e)

{

SqlConnection sq1; string connectionStr; string strName; string strPwd; int count = 0; connectionStr

=

\

Source='.'; Initial Catalog='wygl';integrated security=True\;

sq1 = new

SqlConnection(connectionStr);

try {

sq1.Open(); } catch {

MessageBox.Show(\连?接ó失骸?败悒?!?!?!?\);

}

if (glybt.Checked) {

string sql1 = \from dbo.gly\;

string sql2 = \count (glyid) from dbo.gly\;

SqlCommand command1 = new SqlCommand(sql1, sq1);

SqlDataReader dataReader1 = command1.ExecuteReader();

while (dataReader1.Read())

{

count++; strName

=

(string)dataReader1[\];

7

if (strName.Equals(dlyhm.Text))

{

count = 0; strPwd =

(string)dataReader1[1];

if (strPwd.Equals(dlmm.Text))

{

Form2 f2 = new Form2();

this.Hide();

f2.Show(); break; } else {

MessageBox.Show(\用?户§名?和í密ü码?不?匹¥配?!?!?!?\);

} } }

dataReader1.Close(); command1 =

new SqlCommand(sql2, sq1);

int

a

=

Convert.ToInt32(command1.ExecuteScalar().ToString());

if (a <= count) {

MessageBox.Show(\用?户§名?不?存?在ú!?!?!?\);

}

sq1.Close(); }

if (yhbt.Checked) {

string sql1 = \from dbo.yh\;

string sql2 = \count (yhm) from dbo.yh\;

SqlCommand command1 = new SqlCommand(sql1, sq1);

SqlDataReader dataReader1 = command1.ExecuteReader();

while (dataReader1.Read())

{

count++; strName =

(string)dataReader1[\];

if (strName.Equals(dlyhm.Text))

{

count = 0; strPwd =

(string)dataReader1[1];

if (strPwd.Equals(dlmm.Text))

{

Form6 f6 = new Form6();

this.Hide();

f6.Show(); break; } else

8

{

MessageBox.Show(\用?户§名?和í密ü码?不?匹¥配?!?!?!?\);

} } }

dataReader1.Close(); command1 =

new

SqlCommand(sql2, sq1);

int

a

=

Convert.ToInt32(command1.ExecuteScalar().ToString());

if (a <= count) {

MessageBox.Show(\用?户§名?不?存?在ú!?!?!?\);

}

sq1.Close(); }

}

private void button2_Click(object sender, EventArgs e)

{

SqlConnection sql; string str1

=

\

Source='.';Initial Catalog='wygl';integrated

security=true\;

sql = new SqlConnection(str1); try {

sql.Open(); }

catch {

MessageBox.Show(\打洙?开a链ⅰ?接ó错洙?误ó!?!?!?\);

}

if (glybt.Checked) {

MessageBox.Show(\无T法ぁ?注痢?册á管ü理え?员±!?\, \警ˉ告?\, MessageBoxButtons.OKCancel, MessageBoxIcon.Information);

}

if (yhbt.Checked) {

string

str3

=

string.Format(\into dbo.yh(yhm,yhpwd) values('{0}','{1}');\, dlyhm.Text, dlmm.Text);

string

sql4

=

string.Format(\yhm='{0}'\, dlyhm.Text);

SqlCommand comman2 = new SqlCommand(sql4, sql);

int count1 =

(int)comman2.ExecuteScalar();

if (count1 != 0)

{

MessageBox.Show(\用?户§名?已?存?在ú!?\, \错洙?误ó\, MessageBoxButtons.OKCancel, MessageBoxIcon.Information);

} else {

9

if (dlyhm.Text == \ || dlmm.Text == \)

{

MessageBox.Show(\用?户§名?或ò密ü码?不?能ü为a空?!?\, \错洙?误ó\, MessageBoxButtons.OKCancel, MessageBoxIcon.Information);

} else {

string

sql5

=

string.Format(\INTO dbo.yh(yhm,yhpwd) VALUES('{0}','{1}')\, dlyhm.Text, dlmm.Text);

SqlCommand comman3 = new SqlCommand(sql5, sql);

MessageBox.Show(\注痢?册á成é功|!?\, \恭§喜2\, MessageBoxButtons.OKCancel, MessageBoxIcon.Information);

comman3.ExecuteNonQuery();

} }

sql.Close(); } }

private

void

yhbt_CheckedChanged(object sender, EventArgs e)

{

}

private void Form1_Load(object sender, EventArgs e)

{

}

private

void

glybt_CheckedChanged(object sender, EventArgs e)

{

}

private

void

pictureBox1_Click(object sender, EventArgs e)

{

this.Close(); }

private

void

pictureBox1_Click_1(object sender, EventArgs e)

{

Application.Exit(); }

private

void linkLabel1_LinkClicked(object sender,

LinkLabelLinkClickedEventArgs e)

{

linkLabel1.LinkVisited = true;

System.Diagnostics.Process.Start(\iae.edu.cn/index0.asp\);

} }

}

10

11


课程设计报告-示例(3).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:知情同意书落实情况持续改进

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: