예제 #1
0
        /// <summary>
        /// 根据表,获取一个SqlParameter数组
        /// </summary>
        /// <returns>SqlParameter[]</returns>
        public static SqlParameter[] GetSqlParameters(Admins AdminsExample)
        {
            List <SqlParameter> list_param = new List <SqlParameter>();

            if (!string.IsNullOrEmpty(AdminsExample.aaccount))
            {
                list_param.Add(new SqlParameter("@aaccount", AdminsExample.aaccount));
            }
            else
            {
                list_param.Add(new SqlParameter("@aaccount", DBNull.Value));
            }

            if (!string.IsNullOrEmpty(AdminsExample.apassword))
            {
                list_param.Add(new SqlParameter("@apassword", AdminsExample.apassword));
            }
            else
            {
                list_param.Add(new SqlParameter("@apassword", DBNull.Value));
            }
            if (AdminsExample.alogintime != new DateTime() && AdminsExample.alogintime != null)
            {
                list_param.Add(new SqlParameter("@alogintime", AdminsExample.alogintime.ToString("yyyy-MM-dd")));
            }
            else
            {
                list_param.Add(new SqlParameter("@alogintime", DBNull.Value));
            }

            if (!string.IsNullOrEmpty(AdminsExample.astate))
            {
                list_param.Add(new SqlParameter("@astate", AdminsExample.astate));
            }
            else
            {
                list_param.Add(new SqlParameter("@astate", DBNull.Value));
            }

            if (!string.IsNullOrEmpty(AdminsExample.atype))
            {
                list_param.Add(new SqlParameter("@atype", AdminsExample.atype));
            }
            else
            {
                list_param.Add(new SqlParameter("@atype", DBNull.Value));
            }
            SqlParameter[] param = new SqlParameter[list_param.Count];
            int            index = 0;

            foreach (SqlParameter p in list_param)
            {
                param[index] = p;
                index++;
            }
            return(param);
        }
예제 #2
0
        /// <summary>
        /// 从一个SqlDataReader里读数据
        /// </summary>
        /// <param name="Reader">SqlDataReader</param>
        /// <returns>AdminsExample</returns>
        public static Admins GetByReader(SqlDataReader Reader)
        {
            Admins AdminsExample = new Admins();

            AdminsExample.aid        = Reader["aid"] == DBNull.Value ? 0 : (int)Reader["aid"];
            AdminsExample.aaccount   = Reader["aaccount"] == DBNull.Value ? null : Reader["aaccount"].ToString();
            AdminsExample.apassword  = Reader["apassword"] == DBNull.Value ? null : Reader["apassword"].ToString();
            AdminsExample.alogintime = Reader["alogintime"] == DBNull.Value ? new DateTime() : Convert.ToDateTime(Reader["alogintime"]);
            AdminsExample.astate     = Reader["astate"] == DBNull.Value ? null : Reader["astate"].ToString();
            AdminsExample.atype      = Reader["atype"] == DBNull.Value ? null : Reader["atype"].ToString();
            return(AdminsExample);
        }
예제 #3
0
        /// <summary>
        /// 管理员密码修改
        /// </summary>
        /// <param name="admins"></param>
        /// <returns></returns>
        public int UpdatePwd(Admins admins)
        {
            string sql = "update Admins set LoginPwd={0} where AdminName='{1}' and LoginId='{2}'";

            sql = string.Format(sql, admins.LoginPwd, admins.AdminName, admins.LoginId);
            try
            {
                return(SQLHelper.ExecuteNonQuery(sql, null));
            }
            catch (Exception ex)
            {
                throw new Exception("修改密码出现数据库访问错误!", ex);
            }
        }
예제 #4
0
        /// <summary>
        /// 查询全部数据
        /// </summary>
        /// <returns>IList</returns>
        /*查看是否为视图*/
        public IList <Admins> SearchAll()
        {
            DBHelper.sqlstr = "select * from Admins ";
            List <Admins> list   = new List <Admins>();
            SqlDataReader reader = DBHelper.ExecuteReader();

            while (reader.Read())
            {
                Admins Obj = GetByReader(reader);
                list.Add(Obj);
            }
            reader.Close();
            return(list);
        }
예제 #5
0
        /// <summary>
        /// 根据aid,查询一条数据
        /// </summary>
        /// <param name="aid"></param>
        /// <returns></returns>
        /*查看是否为视图*/

        public Admins SearchByaid(int aid)
        {
            DBHelper.sqlstr = "select * from Admins where aid = @aid";
            SqlParameter[] param = new SqlParameter[] {
                new SqlParameter("@aid", aid)
            };
            SqlDataReader reader = DBHelper.ExecuteReader(param);
            Admins        Obj    = null;

            if (reader.Read())
            {
                Obj = GetByReader(reader);
            }
            reader.Close();
            return(Obj);
        }
예제 #6
0
        /// <summary>
        /// 根据Id,查询一条数据
        /// </summary>
        /// <param name="Id">编号</param>
        /// <returns></returns>
        /*查看是否为视图*/

        public Admins searchByAcc(string acc)
        {
            DBHelper.sqlstr = "select * from Admins where aaccount = @aaccount";
            SqlParameter[] param = new SqlParameter[] {
                new SqlParameter("@aaccount", acc)
            };
            SqlDataReader reader = DBHelper.ExecuteReader(param);
            Admins        Obj    = null;

            if (reader.Read())
            {
                Obj = GetByReader(reader);
            }
            reader.Close();
            return(Obj);
        }
예제 #7
0
        /// <summary>
        /// 修改用户信息
        /// </summary>
        /// <param name="m"></param>
        /// <returns></returns>
        public int AlterAdmins(Admins m)
        {
            string str = $"update Admins set Name='{m.Name}',Pwd='123',Email='{m.Email}'where Uid={m.Uid}";

            return(DBHelper.ExecuteNonQuery(str));
        }
예제 #8
0
        /// <summary>
        /// 登录用户
        /// </summary>
        /// <param name="m"></param>
        /// <returns></returns>
        public int Login(Admins m)
        {
            string sql = $"select count(1) from Admins where Name='{m.Name}' and Email='{m.Email}'";

            return((int)DBHelper.ExecuteScalar(sql));
        }
예제 #9
0
        /// <summary>
        /// 管理员注册
        /// </summary>
        /// <param name="m"></param>
        /// <returns></returns>
        public int AddAdmins(Admins m)
        {
            string str = $"insert into Admins values('{m.Name}','123','{m.Email}')";

            return(DBHelper.ExecuteNonQuery(str));
        }
예제 #10
0
 /// <summary>
 /// 更新
 /// </summary>
 /// <param name="Admins">Admins表实例</param>
 /// <returns>int</returns>
 public int Update(Admins AdminsExample)
 {
     DBHelper.sqlstr = "update Admins set aaccount=@aaccount,apassword=@apassword,alogintime=@alogintime,astate=@astate,atype=@atype where aid=" + AdminsExample.aid;
     return(DBHelper.ExecuteNonQuery(GetSqlParameters(AdminsExample)));
 }
예제 #11
0
 /// <summary>
 /// 插入方法
 /// </summary>
 /// <param name="Admins">Admins表实例</param>
 /// <returns>int</returns>
 public int Insert(Admins AdminsExample)
 {
     DBHelper.sqlstr = "insert into  Admins (aaccount,apassword,alogintime,astate,atype)values(@aaccount,@apassword,@alogintime,@astate,@atype)";
     return(DBHelper.ExecuteNonQuery(GetSqlParameters(AdminsExample)));
 }