示例#1
0
        public AdminInfo GetAdmin(string userName)
        {
            AdminInfo       admin  = null;
            MySqlConnection myconn = null;
            MySqlCommand    mycmd  = null;

            try
            {
                DataTable dt = new DataTable();

                myconn = MyDBHelper.Instance.CreateConnection();
                myconn.Open();
                string cmdText = "select * from AdminInfo where `UserName` = @UserName";
                mycmd = new MySqlCommand(cmdText, myconn);
                mycmd.Parameters.AddWithValue("@UserName", DESEncrypt.EncryptDES(userName));
                MySqlDataAdapter adapter = new MySqlDataAdapter(mycmd);
                adapter.Fill(dt);
                if (dt.Rows.Count == 0)
                {
                    return(null);
                }
                admin = MetaDBAdapter <AdminInfo> .GetAdminInfoListFromDataTable(dt)[0];

                dt.Clear();
                dt.Dispose();
                adapter.Dispose();
                return(admin);
            }
            catch (Exception exc)
            {
                throw exc;
            }
            finally
            {
                MyDBHelper.Instance.DisposeConnection(myconn);
                if (mycmd != null)
                {
                    mycmd.Dispose();
                }
            }
        }
示例#2
0
        public AdminInfo[] GetAllAdmin()
        {
            AdminInfo[]     listAdmin = null;
            MySqlConnection myconn    = null;
            MySqlCommand    mycmd     = null;

            try
            {
                DataTable dt = new DataTable();

                myconn = MyDBHelper.Instance.CreateConnection();
                myconn.Open();
                string cmdText = "select * from admininfo";
                mycmd = new MySqlCommand(cmdText, myconn);
                MySqlDataAdapter adapter = new MySqlDataAdapter(mycmd);
                adapter.Fill(dt);
                listAdmin = MetaDBAdapter <AdminInfo> .GetAdminInfoListFromDataTable(dt);

                dt.Clear();
                dt.Dispose();
                adapter.Dispose();
                return(listAdmin);
            }
            catch (Exception exc)
            {
                throw exc;
            }
            finally
            {
                MyDBHelper.Instance.DisposeConnection(myconn);
                if (mycmd != null)
                {
                    mycmd.Dispose();
                }
            }
        }