Example #1
0
        public bool ReserveTeeTime(TeeTime requestedTeeTime, out string error)
        {
            bool confirmation = false;

            error = "";
            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                using (SqlCommand reserveTeeTime = new SqlCommand("ReserveTeeTime", connection)
                {
                    CommandType = System.Data.CommandType.StoredProcedure
                })
                {
                    reserveTeeTime.Parameters.AddWithValue("@date", requestedTeeTime.Datetime);
                    reserveTeeTime.Parameters.AddWithValue("@time", requestedTeeTime.Datetime);
                    reserveTeeTime.Parameters.AddWithValue("@numberOfCarts", requestedTeeTime.NumberOfCarts);
                    reserveTeeTime.Parameters.AddWithValue("@phone", requestedTeeTime.Phone);
                    reserveTeeTime.Parameters.AddWithValue("@reservedBy", requestedTeeTime.ReservedBy);
                    var golfers = new DataTable("@golfers");
                    golfers.Columns.Add("UserId");

                    foreach (var(Name, UserId) in requestedTeeTime.Golfers.ToArray())
                    {
                        golfers.Rows.Add(UserId);
                    }

                    reserveTeeTime.Parameters.AddWithValue("@golfers", golfers);
                    SqlParameter message = new SqlParameter("@message", SqlDbType.VarChar)
                    {
                        Direction = ParameterDirection.Output, Size = 8000
                    };
                    reserveTeeTime.Parameters.Add(message);

                    reserveTeeTime.Connection.Open();


                    try
                    {
                        confirmation = reserveTeeTime.ExecuteNonQuery() != 0;
                    }
                    catch (Exception ex)
                    {
                        confirmation = false;
                        error        = ex.Message;
                    }

                    reserveTeeTime.Connection.Close();
                }
            }

            return(confirmation);
        }
Example #2
0
        public List <TeeTime> FindReservedTeeTimes()
        {
            Stack <TeeTime> golferTeeTimes = new Stack <TeeTime>();

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                using (SqlCommand findReservedTeeTimes = new SqlCommand("FindReservedTeeTimes", connection)
                {
                    CommandType = CommandType.StoredProcedure
                })
                {
                    findReservedTeeTimes.Parameters.AddWithValue("@userID", userId);

                    connection.Open();

                    using (SqlDataReader reader = findReservedTeeTimes.ExecuteReader())
                    {
                        if (reader.HasRows)
                        {
                            do
                            {
                                while (reader.Read())
                                {
                                    if (golferTeeTimes.Any())
                                    {
                                        if (DateTime.Parse($"{reader["Date"]}").Add(DateTime.Parse($"{reader["Time"]}").TimeOfDay)
                                            == golferTeeTimes.Peek().Datetime)
                                        {
                                            golferTeeTimes.Peek().Golfers.Add((reader["Member Name"].ToString(), reader["UserId"].ToString()));
                                            continue;
                                        }
                                    }

                                    TeeTime reservedTeeTime = CreateTeeTimeFromReader(DateTime.Parse($"{reader["Date"]}"), reader);

                                    golferTeeTimes.Push(reservedTeeTime);
                                }
                            } while (reader.NextResult());
                        }
                    }
                }
            }

            return(golferTeeTimes.ToList());
        }
Example #3
0
        public DailyTeeSheet FindDailyTeeSheet(DateTime date)
        {
            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                using (SqlCommand findDailyTeeSheet = new SqlCommand("FindDailyTeeSheet", connection)
                {
                    CommandType = CommandType.StoredProcedure
                })
                {
                    findDailyTeeSheet.Parameters.AddWithValue("@date", date);
                    findDailyTeeSheet.Connection.Open();
                    using (SqlDataReader reader = findDailyTeeSheet.ExecuteReader())
                    {
                        if (reader.HasRows)
                        {
                            while (reader.Read())
                            {
                                if (teeTimes.Any())
                                {
                                    if (DateTime.Parse($"{date.ToLongDateString()} {reader["Time"]}") == teeTimes.Peek().Datetime)
                                    {
                                        teeTimes.Peek().Golfers.Add((reader["Member Name"].ToString(), reader["UserId"].ToString()));
                                        continue;
                                    }
                                }

                                TeeTime newTeeTime = CreateTeeTimeFromReader(date, reader);

                                teeTimes.Push(newTeeTime);
                            }
                        }
                    }
                }
            }
            return(new DailyTeeSheet()
            {
                Date = date, TeeTimes = teeTimes.Reverse().ToList()
            });
        }