zoukankan      html  css  js  c++  java
  • 数据层

    数据层

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    using ThreeTies.Model;
    using ThreeTies.DBUtility;
    using System.Data.SqlClient;
    using System.Data;

    namespace ThreeTies.SqlServerDAL
    {
        //用户的基础服务类
        public class UserService
        {
            //添加用户
            public static int AddUser(User u)
            {
                try
                {
                    SqlParameter[] param = new SqlParameter[]{
                        new SqlParameter("@UserName",u.UserName),
                        new SqlParameter("@UserPassword",u.UserPassword),
                        new SqlParameter("@RoleID",u.Role.RoleID)
                    };
                    int i = DBHelp.ExecuteNoQuery("insert into [User] values(@userName,@UserPassword,@RoleID)", param);
                    return i;
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message);
                }
            }

            //根据用户的账号返回用户的信息
            public static User GetUserByUserID(string userName)
            {       
                User u=null;
                try
                {
                    SqlParameter[] param = new SqlParameter[]{
                        new SqlParameter("@UserName",userName)
                    };

                    DataTable dt = DBHelp.GetTable("select * from [User] where ", param);
                    //如果用户存在
                    if (dt.Rows.Count > 0)
                    {
                        u = new User();
                        u.UserName = dt.Rows[0]["UserName"].ToString();
                        u.UserPassword = dt.Rows[0]["UserPassword"].ToString();
                        u.Role = new Role();
                        u.Role = RoleService.GetRole(int.Parse(dt.Rows[0]["RoleID"].ToString()));
                    }
                    return u;
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message);
                }
            }
        }
    }

    风雪七月花溅墨
  • 相关阅读:
    mysqldump指定编码导出数据
    centos 自带mysql卸载时出现无法卸载情况
    Linux下如何彻底删除MySQL
    输出一行字符串中的最长单词---调用函数
    span设置固定宽度
    如何使用Reaver破解Wi-Fi网络的WPA密码
    kernel hexdump分析 (2.0)
    C++基础学习笔记----第七课(面向对象的基本概念)
    有关java中的final关键字
    测试framebuffer
  • 原文地址:https://www.cnblogs.com/bobo41/p/3068399.html
Copyright © 2011-2022 走看看