Esempio n. 1
0
        public List <string[]> getMatchInvites(string uid)
        {
            List <string[]> matchInvites = new List <string[]>();
            Matches         match        = new Matches();
            string          queryString  = "SELECT invite_match, invite_sender FROM invites WHERE invite_resever=@uid";

            using (SqlConnection connection = new SqlConnection(cs))
            {
                SqlCommand command = new SqlCommand(queryString, connection);
                try
                {
                    command.Connection.Open();
                    command.Parameters.AddWithValue("@uid", uid);


                    SqlDataReader reader = command.ExecuteReader();

                    if (reader.HasRows)
                    {
                        while (reader.Read() && match.checkMatchAvailability(reader.GetValue(0).ToString()))
                        {
                            string[] info = new string[3];

                            //MATCH ID
                            info[0] = reader.GetValue(0).ToString();
                            //SENDER ID
                            info[1] = reader.GetValue(1).ToString();

                            matchInvites.Add(info);
                        }
                    }
                    else
                    {
                        matchInvites = null;
                    }

                    reader.Close();
                }
                catch (SqlException ex)
                {
                    for (int i = 0; i < ex.Errors.Count; i++)
                    {
                        errorMessages.Append("Index #" + i + "\n" +
                                             "Message: " + ex.Errors[i].Message + "\n" +
                                             "LineNumber: " + ex.Errors[i].LineNumber + "\n" +
                                             "Source: " + ex.Errors[i].Source + "\n" +
                                             "Procedure: " + ex.Errors[i].Procedure + "\n");
                    }
                    Console.WriteLine(errorMessages.ToString());
                    string[] err = new string[1];
                    err[0] = errorMessages.ToString();
                    matchInvites.Add(err);
                }
                finally
                {
                    command.Connection.Close();
                }
            }

            return(matchInvites);
        }