失物查询系统(4)

2019-03-28 11:14

6 程序源代码说明书

6.1 程序源代码 6.1.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 LostQuery {

public partial class Main : Form {

public Main() {

InitializeComponent(); }

// “登记/修改” 按钮的响应

private void btn_input_Click(object sender, EventArgs e) {

Login login = new Login(); login.Show(); }

//“查询”按钮的响应

private void btn_query_Click(object sender, EventArgs e) {

Query query = new Query(); query.Show(); } } }

6.1.2 登录 页面代码:

using System;

11

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

using System.Windows.Forms;

namespace LostQuery {

public partial class Login : Form {

public Login() {

InitializeComponent(); }

//“登录”按钮添加响应

private void btn_login_Click(object sender, EventArgs e) {

//判断是否输入为空

if (this.tb_account.Text == \ || this.tb_password.Text == \) {

MessageBox.Show(\请输入用户名和密码\, \提示\, MessageBoxButtons.OK, MessageBoxIcon.Information);

this.tb_account.Focus(); this.tb_password.Focus(); } else {

//用户名和密码输入正确

if (this.tb_account.Text == \ && this.tb_password.Text == \) {

Input input = new Input(); input.Show(); this.Visible = false; }

//用户名或密码不正确 else {

MessageBox.Show(\对不起,你输入的用户名或密码不正确,不能进行登记\, \提示\, MessageBoxButtons.OK, MessageBoxIcon.Information);

12

this.tb_account.Focus(); this.tb_password.Focus(); } } }

//“清除”按钮添加响应

private void btn_clear_Click(object sender, EventArgs e) {

tb_account.Clear(); tb_password.Clear(); } } }

6.1.3 登记/修改 页面代码:

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;

using System.Text.RegularExpressions;

namespace LostQuery {

public partial class Input : Form {

public Input() {

InitializeComponent(); }

/*****************************************************************************/ /* 登记新的失物信息模块 */ /*****************************************************************************/

//给确定按钮添加响应

13

private void btnOk_Click(object sender, EventArgs e) {

//失物类型不允许为空 if (this.tbType.Text == \)

MessageBox.Show(\请输入失物类型\, \提示\, MessageBoxButtons.OK, MessageBoxIcon.Information); else {

//把失物信息写入数据库 string connString =

\Security=True\;//新建connection对象

SqlConnection connection = new SqlConnection(connString);

string sqlString = \

listLost(type,feature,lostLocation,date,status) values('\ + tbType.Text.Trim() + \ + tbFeature.Text.Trim() + \ + tbAddress.Text.Trim() + \ +

dateTimePicker1.Value.ToShortDateString() + \未领取')\;//登记的物品状态都设置为未领取 try {

connection.Open();

MessageBox.Show(\打开数据库连接成功\);

SqlCommand command = new SqlCommand(sqlString, connection); int result = command.ExecuteNonQuery(); MessageBox.Show(\添加成功\); }

catch (Exception) {

MessageBox.Show(\打开失败\); } finally {

connection.Close();

MessageBox.Show(\关闭数据库连接成功\); } } }

//“清除”按钮添加响应

private void btnClear_Click(object sender, EventArgs e) {

tbType.Clear();

14

tbFeature.Clear(); tbAddress.Clear(); }

/*****************************************************************************/ /* 修改状态模块 */ /*****************************************************************************/

//“确定”按钮添加响应

private void buttonOK_Click(object sender, EventArgs e) {

//输入为空

if (this.tbGet.Text == \)

MessageBox.Show(\请输入领取编号!\, \提示\, MessageBoxButtons.OK, MessageBoxIcon.Information); else {

//判断输入的是不是数字

string isNum = this.tbGet.Text;

Regex reg = new Regex(\); //判断是不是数据,要不是就表示没有选择,则从隐藏域里读出来

Match ma = reg.Match(isNum); if (ma.Success) {

int num = Convert.ToInt32(isNum); //是数字

string connString =

\Security=True\;//新建connection对象

SqlConnection connection = new SqlConnection(connString);

string sqlString = \已领取' where id='\+num+\;

try {

connection.Open();

MessageBox.Show(\打开数据库连接成功\);

SqlCommand command = new SqlCommand(sqlString, connection); int result = command.ExecuteNonQuery(); MessageBox.Show(\状态更改成功\); }

15


失物查询系统(4).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:毕业设计计算书 - 副本

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

马上注册会员

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