Exemplo n.º 1
0
        public static RankResult Total(int Start, int Count)
        {
            using (var db = DB.GetDB())
            {
                var transaction = db.BeginTransaction();
                RankResult result = new RankResult();

                try
                {
                    var command = new SqlCommand();
                    command.Connection = db;
                    command.Transaction = transaction;
                    command.CommandText = @"USP_RankTotal";
                    command.CommandType = CommandType.StoredProcedure;

                    command.Parameters.Add("@Start", SqlDbType.Int);
                    command.Parameters["@Start"].Value = Start;
                    command.Parameters.Add("@Count", SqlDbType.Int);
                    command.Parameters["@Count"].Value = Count;

                    command.Parameters.Add("@ResultCode", SqlDbType.Int);
                    command.Parameters["@ResultCode"].Direction = ParameterDirection.Output;
                    command.Parameters.Add("@Message", SqlDbType.VarChar, 300);
                    command.Parameters["@Message"].Direction = ParameterDirection.Output;

                    List<RankData> list = new List<RankData>();
                    var reader = command.ExecuteReader();

                    while (reader.Read())
                    {
                        //Dictionary<string, string> dict = new Dictionary<string, string>();
                        RankData data = new RankData();
                        data.UserID = (Int64)reader["UserID"];
                        data.FacebookID = reader["FacebookID"].ToString();
                        data.FacebookName = reader["FacebookName"].ToString();
                        data.FacebookPhotoURL = reader["FacebookPhotoURL"].ToString();
                        data.Point = (int)reader["Point"];
                        data.Rank = (int)reader["Rank"];
                        list.Add(data);
                    }
                    reader.Close();

                    result.ResultCode = (int)command.Parameters["@ResultCode"].Value;
                    result.Message = command.Parameters["@Message"].Value.ToString();

                    result.Data = list;

                    transaction.Commit();
                    return result;
                }
                catch (System.Exception ex)
                {
                    Console.Write(ex.Message);
                    transaction.Rollback();
                    throw ex;
                }
            }
        }
Exemplo n.º 2
0
        public static RankResult Friend(List<string> FriendList)
        {
            using (var db = DB.GetDB())
            {
                var transaction = db.BeginTransaction();
                RankResult result = new RankResult();

                try
                {
                    var command = new SqlCommand();
                    command.Connection = db;
                    command.Transaction = transaction;
                    command.CommandText = @"USP_FriendRank";
                    command.CommandType = CommandType.StoredProcedure;

                    for(int i = 0; i<FriendList.Count; i++)
                    {
                        FriendList[i] = "'" + FriendList[i] + "'";
                    }

                    string FriendListStr = string.Join(",", FriendList.ToArray());

                    command.Parameters.Add("@List", SqlDbType.VarChar);
                    command.Parameters["@List"].Value = FriendListStr;

                    command.Parameters.Add("@ResultCode", SqlDbType.Int);
                    command.Parameters["@ResultCode"].Direction = ParameterDirection.Output;
                    command.Parameters.Add("@Message", SqlDbType.VarChar, 300);
                    command.Parameters["@Message"].Direction = ParameterDirection.Output;

                    List<RankData> list = new List<RankData>();
                    var reader = command.ExecuteReader();

                    while (reader.Read())
                    {
                        RankData data = new RankData();
                        data.UserID = (Int64)reader["UserID"];
                        data.FacebookID = reader["FacebookID"].ToString();
                        data.FacebookName = reader["FacebookName"].ToString();
                        data.FacebookPhotoURL = reader["FacebookPhotoURL"].ToString();
                        data.Point = (int)reader["Point"];
                        data.Rank = (Int64)reader["Rank"];

                        list.Add(data);
                    }
                    reader.Close();

                    result.ResultCode = (int)command.Parameters["@ResultCode"].Value;
                    result.Message = command.Parameters["@Message"].Value.ToString();
                    result.Data = list;

                    transaction.Commit();
                    return result;
                }
                catch (System.Exception ex)
                {
                    Console.Write(ex.Message);
                    transaction.Rollback();
                    throw ex;
                }
            }
        }