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);
                }
            }
        }
    }

    风雪七月花溅墨
  • 相关阅读:
    阿里云centos7.2自己安装mysql5.7远程不能访问解决方案
    Delphi中的线程类
    简单说说Delphi中线程的释放
    delphi杀进程的两种方式
    delphi备份恢复剪切板(使用了GlobalLock API函数和CopyMemory)
    Delphi 7下使用Log4Delphi 0.8日志组件
    Demo+在Linux下运行(CentOS7+dotnetcore sdk)
    反射
    解析表达式树
    JS面向对象编程之:封装、继承、多态
  • 原文地址:https://www.cnblogs.com/bobo41/p/3068399.html
Copyright © 2011-2022 走看看