Exemplo n.º 1
0
 //查询单个(查ID)
 public int Select(ref M_AdminLogin Obj, int ID, ref string ErrMsg)
 {
     SqlConnection conn;
     using (conn = CreatConn())
     {
         SqlCommand cmd = new SqlCommand($"select ID,Username,Password from {TableName} where ID = {ID}", conn);
         SqlDataReader sdr;
         try
         {
             conn.Open();
             sdr = cmd.ExecuteReader();
             while (sdr.Read())
             {
                 Obj.ID = (int)sdr["ID"];
                 Obj.Password = (string)sdr["Password"];
                 Obj.Username = (string)sdr["Username"];
                 return 1;
             }
             return -1;
         }
         catch (Exception ex)
         {
             ErrMsg = ex.Message;
             return -1;
         }
         finally
         {
             cmd.Dispose();
         }
     }
 }
Exemplo n.º 2
0
        //查询多个(查ID)
        public int Select(ref List<M_AdminLogin> Obj, List<int> ID, ref string ErrMsg)
        {
            SqlConnection conn;
            using (conn = CreatConn())
            {
                SqlCommand cmd = new SqlCommand($"select ID,Username,Password from {TableName} where ID = @ID", conn);
                SqlDataReader sdr;
                SqlParameter par = new SqlParameter("@ID", SqlDbType.Int);
                cmd.Parameters.Add(par);

                int tmpOut = 0;
                try
                {
                    conn.Open();
                    foreach (int i in ID)
                    {
                        cmd.Parameters["@ID"].Value = i;
                        sdr = cmd.ExecuteReader();
                        while (sdr.Read())
                        {
                            M_AdminLogin TmpObj = new M_AdminLogin();
                            TmpObj.ID = (int)sdr["ID"];
                            TmpObj.Password = (string)sdr["Password"];
                            TmpObj.Username = (string)sdr["Username"];
                            Obj.Add(TmpObj);
                            tmpOut++;
                        }
                        sdr.Close();
                    }
                }
                catch (Exception ex)
                {
                    ErrMsg = ex.Message;
                    return -1;
                }
                finally
                {
                    cmd.Dispose();
                }
                if (ID.Count() == tmpOut)
                {
                    return 1;
                }
                else
                {
                    return -1;
                }
            }
        }
Exemplo n.º 3
0
        //更新单个(查ID)
        public int Update(M_AdminLogin Obj, ref string ErrMsg)
        {
            SqlConnection conn;
            using (conn = CreatConn())
            {
                SqlCommand cmd = new SqlCommand($"update {TableName} set User_ID = @User_ID, Username = @Username, Password = @Password where ID = @ID", conn);

                SqlParameter par = new SqlParameter("@User_ID", SqlDbType.Int);
                par.Value = Obj.User_ID;
                cmd.Parameters.Add(par);

                par = new SqlParameter("@Username", SqlDbType.Char, 50);
                par.Value = Obj.Username;
                cmd.Parameters.Add(par);

                par = new SqlParameter("@Password", SqlDbType.Char, 50);
                par.Value = Obj.Password;
                cmd.Parameters.Add(par);

                par = new SqlParameter("@ID", SqlDbType.Int);
                par.Value = Obj.ID;
                cmd.Parameters.Add(par);

                try
                {
                    conn.Open();
                    if (cmd.ExecuteNonQuery() > 0)
                    {
                        return 1;
                    }
                    else
                    {
                        return -1;
                    }
                }
                catch (Exception ex)
                {
                    ErrMsg = ex.Message;
                    return -1;
                }
                finally
                {
                    cmd.Dispose();
                }
            }
        }
Exemplo n.º 4
0
        //插入单个
        public int Insert(ref M_AdminLogin Obj, ref string ErrMsg)
        {
            SqlConnection conn;
            using (conn = CreatConn())
            {
                SqlCommand cmd = new SqlCommand($"insert into {TableName} (User_ID,Username,Password) values (@User_ID,@Username,@Password);select @@IDENTITY as int", conn);

                SqlParameter par = new SqlParameter("@User_ID", SqlDbType.Int);
                par.Value = Obj.User_ID;
                cmd.Parameters.Add(par);

                par = new SqlParameter("@Username", SqlDbType.Char, 50);
                par.Value = Obj.Username;
                cmd.Parameters.Add(par);

                par = new SqlParameter("@Password", SqlDbType.Char, 50);
                par.Value = Obj.Password;
                cmd.Parameters.Add(par);

                try
                {
                    conn.Open();
                    decimal d = (decimal)cmd.ExecuteScalar();
                    Obj.ID = (int)d;
                    if (Obj.ID > 0)
                    {
                        return 1;
                    }
                    else
                    {
                        return -1;
                    }
                }
                catch (Exception ex)
                {
                    ErrMsg = ex.Message;
                    return -1;
                }
                finally
                {
                    cmd.Dispose();
                }
            }
        }
Exemplo n.º 5
0
        //管理员登录
        public int Login(ref M_AdminLogin Obj, string username, string password, ref string ErrMsg)
        {
            SqlConnection conn;
            using (conn = CreatConn())
            {
                SqlCommand cmd = new SqlCommand($"Select * from {TableName} where Username = @username and Password = @password", conn);

                SqlParameter par = new SqlParameter("@username", SqlDbType.Char, 50);
                par.Value = username;
                cmd.Parameters.Add(par);

                par = new SqlParameter("@password", SqlDbType.Char, 50);
                par.Value = password;
                cmd.Parameters.Add(par);

                SqlDataReader sdr;
                try
                {
                    conn.Open();
                    sdr = cmd.ExecuteReader();
                    while (sdr.Read())
                    {
                        Obj.ID = (int)sdr["ID"];
                        Obj.Password = (string)sdr["Password"];
                        Obj.Username = (string)sdr["Username"];
                        return 1;
                    }
                    return -1;
                }
                catch (Exception ex)
                {
                    ErrMsg = ex.Message;
                    return -1;
                }
                finally
                {
                    cmd.Dispose();
                }
            }
        }
Exemplo n.º 6
0
 //查询单个(查ID)
 public static int Select(ref M_AdminLogin Obj, int ID, ref string ErrMsg)
 {
     I_AdminLogin I = (D_AdminLogin)SimpleFactory.CreateObject(DBType.AdminLogin);
     return I.Select(ref Obj, ID, ref ErrMsg);
 }
Exemplo n.º 7
0
 //更新单个(查ID)
 public static int Update(M_AdminLogin Obj, ref string ErrMsg)
 {
     I_AdminLogin I = (D_AdminLogin)SimpleFactory.CreateObject(DBType.AdminLogin);
     return I.Update(Obj, ref ErrMsg);
 }
Exemplo n.º 8
0
 //管理员登录
 public static int Login(ref M_AdminLogin Obj, string username, string password, ref string ErrMsg)
 {
     I_AdminLogin I = (D_AdminLogin)SimpleFactory.CreateObject(DBType.AdminLogin);
     return I.Login(ref Obj, username, password, ref ErrMsg);
 }