Beispiel #1
0
        /// <summary>
        /// Creates a new event for the database
        /// </summary>
        /// <param name="Event">Event that has to be created</param>
        /// <returns>True if Database allows the changes false if not</returns>
        public static bool CreateEvent(Event Event)
        {
            bool Check = false;
            int  ID    = DatabaseGetHighestID.GetHighestID("Event");

            if (DatabaseConnectie.OpenConnection())
            {
                try
                {
                    DatabaseConnectie.OpenConnection();
                    SqlCommand cmd = new SqlCommand();
                    cmd.Connection = DatabaseConnectie.connect;

                    cmd.CommandText = "INSERT INTO Event (ID, Naam, Datum, Beschrijving, Locatie, Maxbezoekers, CampingID, AccountID) VALUES (@ID, @Name, @Date, @Description, @location, @MaxVisitors, @CampingID, @AccountID)";
                    cmd.Parameters.Add(new SqlParameter("ID", ID));
                    cmd.Parameters.Add(new SqlParameter("Name", Event.Name));
                    cmd.Parameters.Add(new SqlParameter("Date", Event.Date));
                    cmd.Parameters.Add(new SqlParameter("Description", Event.Description));
                    cmd.Parameters.Add(new SqlParameter("Location", Event.Location));
                    cmd.Parameters.Add(new SqlParameter("MaxVisitors", Event.MaxVisitors));
                    cmd.Parameters.Add(new SqlParameter("AccountID", Event.Account.ID));
                    if (Event.Camping == null)
                    {
                        cmd.Parameters.Add(new SqlParameter("CampingID", DBNull.Value));
                    }
                    else
                    {
                        cmd.Parameters.Add(new SqlParameter("CampingID", Event.Camping.ID));
                    }

                    cmd.ExecuteNonQuery();

                    DatabaseUpdateMaterial.UpdateMaterial(Event.MaterialList, ID);
                    Check = true;
                }
                catch (SqlException e)
                {
                    Console.WriteLine("Query Failed: " + e.StackTrace + e.Message.ToString());
                    Check = false;
                }
                finally
                {
                    DatabaseConnectie.CloseConnection();
                }
            }

            return(Check);
        }
        /// <summary>
        /// Creates an account with RFID attached
        /// </summary>
        /// <param name="RFIDTag">Tag that has to be added to the account</param>
        /// <param name="Acccount">Account that has to be created</param>
        /// <returns>True if Database allows the changes false if not</returns>
        public static bool CreateAccountWithRFID(Account Account, string RFIDTag)
        {
            bool Check = false;
            int  ID    = DatabaseGetHighestID.GetHighestID("Account");

            if (DatabaseConnectie.OpenConnection())
            {
                try
                {
                    DatabaseConnectie.OpenConnection();
                    SqlCommand cmd = new SqlCommand();
                    cmd.Connection = DatabaseConnectie.connect;

                    cmd.CommandText = "INSERT INTO Account (ID, Gebruikersnaam, Wachtwoord, Functie, Naam, RFID) VALUES (@ID, @UserName, @Password, @Function, @Name, @RFID)";
                    cmd.Parameters.Add(new SqlParameter("Name", Account.Name));
                    cmd.Parameters.Add(new SqlParameter("UserName", Account.Username));
                    cmd.Parameters.Add(new SqlParameter("Password", Account.Password));
                    cmd.Parameters.Add(new SqlParameter("@ID", ID));
                    cmd.Parameters.Add(new SqlParameter("Function", Account.Function.ToString()));
                    cmd.Parameters.Add(new SqlParameter("@RFID", RFIDTag));

                    cmd.ExecuteNonQuery();

                    Check = true;
                }
                catch (SqlException e)
                {
                    Console.WriteLine("Query Failed: " + e.StackTrace + e.Message.ToString());
                    Check = false;
                }
                finally
                {
                    DatabaseConnectie.CloseConnection();
                }
            }

            return(Check);
        }
        /// <summary>
        /// When a Event is being creater so does a timeline
        /// </summary>
        /// <returns>True if Database allows the changes false if not</returns>
        public static bool CreateTimeline()
        {
            bool Check   = false;
            int  ID      = DatabaseGetHighestID.GetHighestID("Tijdlijn");
            int  EventID = GetLatestEventID();

            if (DatabaseConnectie.OpenConnection())
            {
                try
                {
                    DatabaseConnectie.OpenConnection();
                    SqlCommand cmd = new SqlCommand();
                    cmd.Connection = DatabaseConnectie.connect;

                    cmd.CommandText = "INSERT INTO Tijdlijn (ID, EventID) VALUES (@ID, @EventID)";
                    cmd.Parameters.Add(new SqlParameter("ID", ID));
                    cmd.Parameters.Add(new SqlParameter("EventID", EventID));

                    if (EventID > 0)
                    {
                        cmd.ExecuteNonQuery();
                    }

                    Check = true;
                }
                catch (SqlException e)
                {
                    Console.WriteLine("Query Failed: " + e.StackTrace + e.Message.ToString());
                    Check = false;
                }
                finally
                {
                    DatabaseConnectie.CloseConnection();
                }
            }

            return(Check);
        }
        /// <summary>
        /// Creates a new column in the reservation table.
        /// </summary>
        /// <param name="Reservation">Reservation that need to be created</param>
        /// <returns>Returns true if the reservation is added and false if it failed.</returns>
        public static bool CreateReservation(Reservation Reservation)
        {
            bool Check = false;
            int  ID    = DatabaseGetHighestID.GetHighestID("Reservering");

            if (DatabaseConnectie.OpenConnection())
            {
                try
                {
                    DatabaseConnectie.OpenConnection();
                    SqlCommand cmd = new SqlCommand();
                    cmd.Connection = DatabaseConnectie.connect;

                    cmd.CommandText = "INSERT INTO Reservering (ID, PlaatsID, EventID, BetalingBedrag, BetalingStatus) VALUES (@ID, @PlaatsID, @EventID, @BetalingBedrag, @BetalingStatus)";
                    cmd.Parameters.Add(new SqlParameter("ID", Reservation.ID));

                    if (Reservation.Place != null)
                    {
                        cmd.Parameters.Add(new SqlParameter("PlaatsID", Reservation.Place.ID));
                    }
                    else
                    {
                        cmd.Parameters.Add(new SqlParameter("PlaatsID", null));
                    }

                    cmd.Parameters.Add(new SqlParameter("EventID", Reservation.Event.ID));
                    cmd.Parameters.Add(new SqlParameter("BetalingBedrag", Reservation.Payment.Amount));

                    //Converts the bool to a bit for the database.
                    int paymentStatus;
                    if (Reservation.Payment.Paid)
                    {
                        paymentStatus = 1;
                    }
                    else
                    {
                        paymentStatus = 0;
                    }

                    cmd.Parameters.Add(new SqlParameter("BetalingStatus", paymentStatus));

                    cmd.ExecuteNonQuery();

                    foreach (var account in Reservation.Accounts)
                    {
                        cmd.CommandText = "INSERT INTO Account_Reservering (AccountID, ReserveringID) VALUES (@AccountID, @ReserveringID)";
                        var para1 = cmd.Parameters.Add(new SqlParameter("AccountID", account.ID));
                        var para2 = cmd.Parameters.Add(new SqlParameter("ReserveringID", Reservation.ID));

                        cmd.ExecuteNonQuery();

                        cmd.Parameters.Remove(para1);
                        cmd.Parameters.Remove(para2);
                    }


                    Check = true;
                }
                catch (SqlException e)
                {
                    Console.WriteLine("Query Failed: " + e.StackTrace + e.Message.ToString());
                    Check = false;
                }
                finally
                {
                    DatabaseConnectie.CloseConnection();
                }
            }

            return(Check);
        }