/// <summary>
        /// Initializes a new instance of the <see cref="AddRepairForm" /> class.
        /// </summary>
        /// <param name="serviceSystem">The current service system</param>
        /// <param name="repairService">the repair service</param>
        public AddRepairForm(ServiceSystem serviceSystem, RepairService repairService)
            : this(serviceSystem)
        {
            this.rtbxTramID.Text = repairService.Tram.ID.ToString();

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

            this.serviceSystem = serviceSystem;
            this.rtbxRepair.Text = repairService.StartingTime + ", " + repairService.IsLarge.ToString();
            this.RepairService = repairService;
        }
 /// <summary>
 /// Adds a new repair service.
 /// </summary>
 /// <param name="repairService">The repair service which is to be added.</param>
 /// <param name="tram">The tram for which the repair service needs to be added.</param>
 public void AddRepairService(RepairService repairService, Tram tram)
 {
     DatabaseManager.AddRepairService(repairService, tram);
 }
        /// <summary>
        /// Confirms the adding of a new repair service.
        /// </summary>
        /// <param name="sender">This is the object</param>
        /// <param name="e">This is the event</param>
        private void BtnConfirm_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);

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

            if (this.tramDepotManagementSystem != null)
            {
                try
                {
                    this.tramDepotManagementSystem.AddRepairService(repairService, tram);
                    this.DialogResult = DialogResult.OK;
                    this.Close();
                }
                catch (Exception ex)
                {
                    this.ShowErrorMessage("The repair service could not be added:" + System.Environment.NewLine + ex.Message);
                }
            }
            else
            {
                try
                {
                    this.serviceSystem.AddRepairService(repairService, tram);
                    this.DialogResult = DialogResult.OK;
                    this.Close();
                }
                catch (Exception ex)
                {
                    this.ShowErrorMessage("The repair service could not be added:" + System.Environment.NewLine + ex.Message);
                }
            }
        }
 /// <summary>
 /// Adds a repair service to the schedule
 /// </summary>
 /// <param name="repairService">This is the given repair 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 AddRepairService(RepairService repairService, Tram tram)
 {
     DatabaseManager.AddRepairService(repairService, tram);
     return false;
 }
        /// <summary>
        /// Completes the given service by adding the ending time and the account to the row in the database.
        /// </summary>
        /// <param name="repairService">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 FinishRepairService(RepairService repairService, bool closeConnection = true)
        {
            try
            {
                OracleCommand command = CreateOracleCommand("UPDATE BEURT SET eindTijdstip = :EndingTime, beschrijving = :Description WHERE ID = :RepairServiceID");

                command.Parameters.Add(":EndingTime", repairService.EndingTime.Value);
                command.Parameters.Add(":Description", repairService.Description);
                command.Parameters.Add(":RepairServiceID", repairService.ID);

                ExecuteNonQuery(command);

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

                command2.Parameters.Add(":AccountID", repairService.Account.ID);
                command2.Parameters.Add(":RepairServiceID", repairService.ID);

                ExecuteNonQuery(command2);
            }
            finally
            {
                if (closeConnection)
                {
                    connection.Close();
                }
            }
        }
        /// <summary>
        /// Adds the given repair service to the database.
        /// </summary>
        /// <param name="repairService">The repair service to add.</param>
        /// <param name="tram">The tram the service is for.</param>
        /// <param name="closeConnection">Whether the database connection should be closed at the end of this method.</param>
        /// <returns>The repair service with it's database ID set.</returns>
        public static RepairService AddRepairService(RepairService repairService, Tram tram, bool closeConnection = true)
        {
            try
            {
                OracleCommand command = CreateOracleCommand("INSERT INTO BEURT(ID, startTijdstip, WAGEN_ID, beschrijving, isGroot) VALUES(SEQ_BEURTID.NEXTVAL, :StartTime, :TramID, :Description, :IsLarge)");

                int isLarge = repairService.IsLarge ? 1 : 0;

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

                bool isAdded = ExecuteNonQuery(command);

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

                OracleCommand command2 = CreateOracleCommand("INSERT INTO SERVICEBEURT(ID) VALUES (SEQ_BEURTID.CURRVAL)");

                ExecuteNonQuery(command2);

                OracleCommand command3 = CreateOracleCommand("SELECT MAX(ID) AS ID FROM SERVICEBEURT");
                OracleDataReader reader = ExecuteQuery(command3);
                reader.Read();

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

                repairService.ID = id;

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