/// <summary>
        /// Initializes a new instance of the <see cref="AddCleaningForm" /> class.
        /// </summary>
        /// <param name="serviceSystem">This is the current service system</param>
        /// <param name="cleaningService">This is the cleaning service that needs to be added</param>
        public AddCleaningForm(ServiceSystem serviceSystem, CleaningService cleaningService)
            : this(serviceSystem)
        {
            rtbxTramID.Text = cleaningService.Tram.Number.ToString();

            rtbxTramID.ReadOnly = true;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="FinishCleaningForm" /> class.
        /// </summary>
        /// <param name="serviceSystem">The given service system</param>
        /// <param name="cleaningService">The given cleaning service</param>
        public FinishCleaningForm(ServiceSystem serviceSystem, CleaningService cleaningService)
        {
            this.InitializeComponent();

            this.serviceSystem = serviceSystem;
            this.rtbxCleaning.Text = cleaningService.StartingTime.Value.ToShortDateString() + ", " + cleaningService.IsLarge.ToString();
            this.CleaningService = cleaningService;
        }
 /// <summary>
 /// Adds a new cleaning service.
 /// </summary>
 /// <param name="cleaningService">The cleaning service which is to be added.</param>
 /// <param name="tram">The tram for which the cleaning service needs to be added.</param>
 public void AddCleaningService(CleaningService cleaningService, Tram tram)
 {
     DatabaseManager.AddCleaningService(cleaningService, tram);
 }
        /// <summary>
        /// Confirms the adding of a new cleaning service.
        /// </summary>
        /// <param name="sender">This is the object</param>
        /// <param name="e">This is the event</param>
        private void BtnOK_Click(object sender, EventArgs e)
        {
            string tramNumber = rtbxTramID.Text.Trim();
            bool isLarge;

            if (this.rbBig.Checked)
            {
                isLarge = true;
            }
            else
            {
                isLarge = false;
            }

            Tram tram = this.serviceSystem.GetTram(tramNumber);

            CleaningService cleaningService = new CleaningService(-1, DateTime.Now, null, isLarge, tram, LoggedInAccount.AccountLoggedIn);

            if (this.tramDepotManagementSystem != null)
            {
                try
                {
                    this.tramDepotManagementSystem.AddCleaningService(cleaningService, tram);
                    this.DialogResult = DialogResult.OK;
                    this.Close();
                }
                catch (Exception ex)
                {
                    this.ShowErrorMessage("The cleaning service could not be added:" + System.Environment.NewLine + ex.Message);
                }
            }
            else
            {
                try
                {
                    this.serviceSystem.AddCleaningService(cleaningService, tram);
                    this.DialogResult = DialogResult.OK;
                    this.Close();
                }
                catch (Exception ex)
                {
                    this.ShowErrorMessage("The cleaning service could not be added:" + System.Environment.NewLine + ex.Message);
                }
            }
        }
 /// <summary>
 /// Adds a cleaning service to the schedule
 /// </summary>
 /// <param name="cleaningService">This is the given cleaning service</param>
 /// <param name="tram">This is the given tram</param>
 /// <returns>Returns a true of false depending on the success of adding the service to the schedule</returns>
 public bool AddCleaningService(CleaningService cleaningService, Tram tram)
 {
     DatabaseManager.AddCleaningService(cleaningService, tram);
     return true;
 }
        /// <summary>
        /// Completes the given service by adding the ending time and the account to the row in the database.
        /// </summary>
        /// <param name="cleaningService">The service to round up.</param>
        /// <param name="closeConnection">If true, closes the database connection at the end of this method.</param>
        public static void FinishCleaningService(CleaningService cleaningService, bool closeConnection = true)
        {
            try
            {
                OracleCommand command = CreateOracleCommand("UPDATE BEURT SET eindTijdstip = :EndingTime, beschrijving = :Description WHERE ID = :CleaningServiceID");

                command.Parameters.Add(":EndingTime", cleaningService.EndingTime.Value);
                command.Parameters.Add(":Description", cleaningService.Description);
                command.Parameters.Add(":CleaningServiceID", cleaningService.ID);

                ExecuteNonQuery(command);

                OracleCommand command2 = CreateOracleCommand("UPDATE SCHOONMAAKBEURT SET ACCOUNT_ID = :AccountID WHERE ID = :CleaningServiceID");

                command2.Parameters.Add(":AccountID", cleaningService.Account.ID);
                command2.Parameters.Add(":CleaningServiceID", cleaningService.ID);

                ExecuteNonQuery(command2);
            }
            finally
            {
                if (closeConnection)
                {
                    connection.Close();
                }
            }
        }
        /// <summary>
        /// Adds the given cleaning service to the database.
        /// The ID of the given service is ignored, as the database will use it's next valid value (using PLSQL sequences).
        /// </summary>
        /// <param name="cleaningService">The cleaning service to add to the database.</param>
        /// <param name="tram">The tram the cleaning service is for.</param>
        /// <param name="closeConnection">Whether the database connection should be closed at the end of this method.</param>
        /// <returns>The cleaning service with it's database ID set.</returns>
        public static CleaningService AddCleaningService(CleaningService cleaningService, Tram tram, bool closeConnection = true)
        {
            try
            {
                // Inesrt Cleaning Service into service table
                OracleCommand command = CreateOracleCommand("INSERT INTO BEURT(ID, startTijdstip, WAGEN_ID, beschrijving, isGroot) VALUES(SEQ_BEURTID.NEXTVAL, :StartTime, :TramID, :Description, :IsLarge)");

                int isLarge = cleaningService.IsLarge ? 1 : 0;

                command.Parameters.Add(":StartTime", cleaningService.StartingTime);
                command.Parameters.Add(":TramID", tram.ID);
                command.Parameters.Add(":Description", cleaningService.Description);
                command.Parameters.Add(":IsLarge", isLarge);

                bool isAdded = ExecuteNonQuery(command);

                if (!isAdded)
                {
                    throw new Exception("The cleaning service could not be added to the database.");
                }

                // Fetch the database ID of the service
                OracleCommand command2 = CreateOracleCommand("SELECT MAX(ID) AS ID FROM BEURT");
                OracleDataReader reader = ExecuteQuery(command2);
                reader.Read();

                int id = Convert.ToInt32(reader["ID"].ToString());
                cleaningService.ID = id;

                // Insert the service into the cleaning service table
                OracleCommand command3 = CreateOracleCommand("INSERT INTO SCHOONMAAKBEURT(ID) VALUES (:ServiceID)");

                command3.Parameters.Add(":ServiceID", id);
                ExecuteNonQuery(command3);

                return cleaningService;
            }
            finally
            {
                if (closeConnection)
                {
                    connection.Close();
                }
            }
        }