C#期末文档--家庭财务管理系统 - 图文(4)

2019-05-26 21:49

FormLogin.cs

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 FormLogin : Form {

string ConnectionString = \

\Catalog=家庭财务管理系统;Persist Security Info=True; \

\

//封装链接字符串,协调统一数据库链接信息 public string getCS()

13

{

return ConnectionString; } SqlConnection conn; string strSQL;

SqlCommand Command; SqlDataReader reader; public FormLogin() {

InitializeComponent(); } static string Uname = \

//封装登录的用户名,便于登录后显示 private void setUname(string s) {

Uname = s; }

public string getUname() {

return Uname; }

14

static string Role = \ //封装用户身份

private void setRole(string s) {

Role = s; }

public string getRole() {

return Role; }

//初始化参数

private void FormLogin_Load(object sender, EventArgs e) {

//取出系统的所有用户名

//显示在下拉列表,这样用户登录的时候 //选择用户名就可以了,不用再输入用户名了 conn = new SqlConnection(ConnectionString); strSQL = \账号 FROM family\ try {

Command = new SqlCommand(strSQL, conn); conn.Open();

15

reader = Command.ExecuteReader();//结果集放到reader对 int flag = 0; //把数据库账号加载到组合框中 while (reader.Read()) {

this.comboBox1.Items.Add(reader[0].ToString()); //如果能加载账号,则选中密码框 if (flag == 0) {

textBox1.Focus(); textBox1.Select(); } flag++; }

//如果系统存在用户,则默认选中第一个用户 if (flag > 0)

this.comboBox1.SelectedIndex = 0; }

16

象中

catch (Exception ex) {

ex.GetBaseException(); } finally

码为空

{

reader.Close(); Command.Dispose(); } }

//确定,完成登陆

private void button1_Click(object sender, EventArgs e) {

int flag = 0; if (textBox1.Text == \ {

showError(\账号或密码为空!\第一种错误,账号或密 return; } 17


C#期末文档--家庭财务管理系统 - 图文(4).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:苏教版第四章第三节第一课时导学案4.3.1细胞呼吸的概念和过程

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

马上注册会员

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