Beispiel #1
0
        public void ReturnVehicle(IVehicle vehicle)
        {
            Returned = DateTime.Now.AddDays(3);
            var days = RentDate.Duration(Returned);

            MilesReturned = vehicle.Odometer;
            Cost          = days * vehicle.CostPerDay + (MilesReturned - MilesRented) * vehicle.CostKM;
        }
Beispiel #2
0
        /// <summary>
        /// Tworzy nowy obiekt w bazie danych
        /// </summary>
        /// <param name="book">Książka do wyporzyczenia</param>
        /// <param name="student">Student który wyporzycza</param>
        /// <param name="rentDate">Data wyporzyczenia</param>
        /// <returns></returns>
        public void Create(uint bookId, uint studentId, DateTime rentDate)
        {
            if (Database.GetInstance() == null)
            {
                Database.Connect();
            }

            StringBuilder sb = new StringBuilder();

            sb.Append("INSERT INTO Rents (startDate, endDate, bookId, studentId) ");
            sb.Append("VALUES(@startDate, @endDate, @bookId, @studentId)");

            using (SqlCommand command = new SqlCommand(sb.ToString(), Database.GetInstance()))
            {
                command.Parameters.Add("@startDate", SqlDbType.Date);
                command.Parameters.Add("@endDate", SqlDbType.Date);
                command.Parameters.Add("@bookId", SqlDbType.BigInt);
                command.Parameters.Add("@studentId", SqlDbType.BigInt);

                command.Parameters["@startDate"].Value = rentDate.Date;
                command.Parameters["@endDate"].Value   = RentDate.AddDays(60).Date;
                command.Parameters["@bookId"].Value    = bookId;
                command.Parameters["@studentId"].Value = studentId;

                try
                {
                    command.ExecuteNonQuery();
                }
                catch (SqlException e)
                {
                    throw e;
                }
                catch (InvalidOperationException e)
                {
                    throw e;
                }
            }
        }
Beispiel #3
0
 public override string ToString()
 {
     return("[ ID = " + RentID + ". RentDate = " + RentDate.ToShortDateString() + ". DateGet = " + DateGet.ToShortDateString()
            + ". CarID = " + Car.CarID + ". ClientId = " + Client.Id + ". RentPrice = " + RentPrice + ". Paid = " + Paid.ToString() +
            ". WorkerFIO = " + WorkerFIO + ". ]");
 }