这样的窗体菜单怎么做,求大神指点!!!附加代码给我c#窗体程序

 我来答
你猜我猜哇擦猜
2015-10-07 · TA获得超过2.8万个赞
知道大有可为答主
回答量:2万
采纳率:0%
帮助的人:6748万
展开全部
登录界面:
后台代码:
//登录按钮单击事件
private void button1_Click(object sender, EventArgs e)
{
string loginname = this.txt_LoginName.Text;
string password = this.txt_PassWord.Text;
UserInfo model = new UserInfo();
model = UserInfoManager.GetUserInfoByuserName(loginname); //调用BLL里面的
if (model != null)
{
if (model.PassWord == password)
{
this.DialogResult = DialogResult.OK;
this.Close();
}
else
{
this.lb_massge.Text = "您输入的密码错误!";
}
}
else
{
this.lb_massge.Text = "您输入的用户名不存在!";
}
}
Bll:
namespace HIS.BLL
{
public class UserInfoManager
{
UserInfoService dal = new UserInfoService();
//根据用户名查询单条用户信息
public static UserInfo GetUserInfoByuserName(string userName)
{
return UserInfoService.GetUserInfoByuserName(userName); //调用DAL里面的
}
}
}
DAL:
/// <summary>
/// 根据用户名查询
/// </summary>
/// <returns></returns>
public static UserInfo GetUserInfoByuserName(string userName)
{
UserInfo userInfo = null;
string sql = "select * from userInfo where userName=@UserName";
SqlParameter[] spr = new SqlParameter[]{
new SqlParameter("@UserName",userName)};
SqlDataReader reader = DBHelper.DBHelper.Reader(sql, spr); //调用DBHelper里面的Reader方法
if (reader.Read())
{
userInfo = new UserInfo();
userInfo.UserId = Convert.ToInt32(reader["UserId"]);
userInfo.UserName = Convert.ToString(reader["UserName"]);
userInfo.PassWord = Convert.ToString(reader["PassWord"]);
userInfo.Email = Convert.ToString(reader["Email"]);
userInfo.ProtectPass = Convert.ToInt32(reader["ProtectPass"]);
}
reader.Close();
HIS.DBHelper.DBHelper.Connection.Close(); //调用DBHelper里面的Connection
return userInfo;
}
DBHelper:
/// <summary>
/// 获取全部的信息,带参数
/// </summary>
/// <param name="sql"></param>
/// <param name="spr"></param>
/// <returns></returns>
public static SqlDataReader Reader(string sql, SqlParameter[] spr)
{
SqlConnection conn = new SqlConnection(connString); //connString链接字符串
conn.Open();
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.Parameters.AddRange(spr);
SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
return reader;
}
//链接字符串
private static string connString = System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"].ToString(); //获取app.config里面的
private static SqlConnection connection = null;
//连接
public static SqlConnection Connection
{
get
{
connection = new SqlConnection(connString);
if (connection.State == ConnectionState.Closed)
connection.Open();
if (connection.State == ConnectionState.Broken)
{
connection.Close();
connection.Open();
}
return connection;
}
}
自己建一个配置文件:
app.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="ConnectionString" value="Data Source=.;Initial Catalog=数据库名称;User ID=用户名;Password=密码" />
</appSettings>
</configuration>
祝你好运!
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式