Пример #1
0
        public RaiderPlayerBetInfo[] GetPlayerBetInfoByRoundID(int roundID, string userName, int pageItemCount, int pageIndex)
        {
            MySqlConnection myconn = null;
            MySqlCommand    mycmd  = null;

            try
            {
                myconn = MyDBHelper.Instance.CreateConnection();
                mycmd  = myconn.CreateCommand();

                string sqlTextA = "SELECT * FROM  raiderplayerbetinfo ";

                string sqlWhere = "";
                if (roundID > 0)
                {
                    sqlWhere = " where RaiderRoundID = @RaiderRoundID ";
                    mycmd.Parameters.AddWithValue("@RaiderRoundID", roundID);
                }
                if (!string.IsNullOrEmpty(userName))
                {
                    if (sqlWhere.Length == 0)
                    {
                        sqlWhere = " where ";
                    }
                    else
                    {
                        sqlWhere += " and ";
                    }

                    sqlWhere += " UserID = ( select id from   playersimpleinfo where UserName = @UserName ) ";
                    mycmd.Parameters.AddWithValue("@UserName", DESEncrypt.EncryptDES(userName));
                }

                string sqlOrderLimit = " order by id desc ";
                if (pageItemCount > 0)
                {
                    int start = pageIndex <= 0 ? 0 : (pageIndex - 1) * pageItemCount;
                    sqlOrderLimit += " limit " + start.ToString() + ", " + pageItemCount;
                }

                string sqlAllText = "select ttt.*, s.UserName as UserName from " +
                                    " ( " + sqlTextA + sqlWhere + sqlOrderLimit +
                                    " ) ttt " +
                                    "  left join   playersimpleinfo s  on ttt.UserID = s.id ";

                mycmd.CommandText = sqlAllText;
                myconn.Open();

                DataTable        table   = new DataTable();
                MySqlDataAdapter adapter = new MySqlDataAdapter(mycmd);
                adapter.Fill(table);

                var lists = MetaDBAdapter <RaiderPlayerBetInfo> .GetPlayerBetInfoFromDataTable(table);

                table.Clear();
                table.Dispose();
                adapter.Dispose();
                return(lists);
            }
            finally
            {
                if (mycmd != null)
                {
                    mycmd.Dispose();
                }
                if (myconn != null)
                {
                    myconn.Close();
                    myconn.Dispose();
                }
            }
        }