cuteReader(CommandBehavior.CloseConnection);
return sqlread;
}
#endregion
}}
3.1.2 OperateAndValidate.cs类
OperateAndValidate.cs类文件中,首先在命名空间区域添加如下命名空间:
Using.System.Data.SqlClentSystem.Text.RegularExpressions用来进行数据库操作,生成BaseOperate类的一个对象,通过类对象调用类中的方法功能,是现在代码如下:
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
using System.Text.RegularExpressions;
using CrystalDecisions.CrystalReports.Engine;
namespace BS
{ class OperateAndValidate
{
BaseOperate boperate = new BaseOperate();//声明 BaseOperate 类的一个对象,以调用其方法
#region 绑定ComboBox控件
///
/// 对ComboBox控件进行数据绑定
///
///
SQL语句
///
表名
///
数据表中字段名
///
ComboBox控件ID
public void cboxBind(string P_str_sqlstr, string P_str_tb_Table, string P_str_tbMember, ComboBox cbox)
{
//调用BaseOperate类中的geds方法生成一个DataSet数据集对象
DataSet myds=boperate.getds(P_str_sqlstr,P_str_tb_Table);
//DataSource 属性用来获取或设置ComboBox控件的数据源
cbox.DataSource = myds.Tables[P_str_tb_Table];
//DisplayMember 属性用来获取或设置要为ComboBox控件显示的属性
cbox.DisplayMember = P_str_tbMember;
}
#endregion
}}
3.2 系统登录模块设计:
系统登录模块运行结果如图所示:
主要代码实现如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace BS
{
public partial class frmLogin : Form
{
public static string str_name;//记录登录用户名字
public static string str_pwd;//记录登录用户密码
public static string str_right;//记录登录用户权限
BS.BaseOperate boperate = new BS.BaseOperate();
BS.OperateAndValidate opAndvalidate = new BS.OperateAndValidate();
public frmLogin()
{
InitializeComponent();
}
private void timer1_Tick(object sender, EventArgs e)
{
DateTime dt = DateTime.Now; //在登录页面显示获取的系统当前时间
label5.Text = "当前时间:"+dt.Year + "年" + dt.Month + "月" + dt.Day + "日" + dt.Hour + "时" + dt.Minute + "分" + dt.Second + "秒";
}
private void button2_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void button1_Click(object sender, EventArgs e)
{
SqlDataReader sqlread = boperate.getread("select UserName,UserPwd from tb_User where UserName='" + cbox.Text.Trim() + "' and UserPwd='" + txtPwd
相关热词:cnet 通讯录 管理 系统 论文