Beispiel #1
0
        public override string ToString()
        {
            StringBuilder output = new StringBuilder();

            output.Append(String.Format("{0}, weight: {1}, belongs to the category of products: {2}", Name, Weight, this.Category.ToString()));
            output.Append(String.Format("\n was made by {0} on {1}", Producer, ProductionDate.ToLongDateString()));

            if (IsSafeToUse())
            {
                if (this.category != ProductCategory.Beverages)
                {
                    output.Append(String.Format("\n can be used another {0} days", ExpireIn()));
                }
                else
                {
                    int expire = ExpireIn();
                    if (expire > 0)
                    {
                        output.Append(String.Format("\n can be used another {0} months", expire));
                    }
                    else
                    {
                        DateTime now = DateTime.Now;
                        output.Append(String.Format("\n can be used another {0} days", this.ExpirationDate.Subtract(now).Days));
                    }
                }
            }
            else
            {
                output.Append(String.Format("\n it expired on {0} ", ExpirationDate.ToLongDateString()));
            }

            return(output.ToString());
        }
Beispiel #2
0
 protected override void AddDescriptions()
 {
     base.AddDescriptions();
     AddDescription(nameof(Name), Name.ToStr());
     AddDescription(nameof(CategoryId), CategoryId.ToStr());
     AddDescription(nameof(ColorId), ColorId.ToStr());
     AddDescription(nameof(Price), Price.ToStr());
     AddDescription(nameof(ProductionDate), ProductionDate.ToStr());
 }
Beispiel #3
0
        /// <summary>
        /// Updates car data in database.
        /// </summary>
        /// <param name="id">Integer that represents id of car.</param>
        /// <returns>True if update succeeded, false if update failed.</returns>
        public bool UpdateCar(int id)
        {
            bool success = false;

            using (SqlConnection sqlConnection = new SqlConnection())
            {
                sqlConnection.ConnectionString = Helpers.connectionString;
                sqlConnection.Open();

                SqlCommand command = new SqlCommand($"UPDATE samochody SET Klasa = @category, " +
                                                    $"Marka = @manufacturer, " +
                                                    $"Model = @model, " +
                                                    $"[Rok produkcji] = @date, " +
                                                    $"[Rodzaj napędu] = @driveType, " +
                                                    $"[Skrzynia biegów] = @gearbox, " +
                                                    $"Silnik = @engine, " +
                                                    $"[Koszt wynajęcia] = @cost, " +
                                                    $"VIN = @vin, " +
                                                    $"[Numer rejestracyjny] = @licensePlateNum " +
                                                    $"WHERE Id = @id", sqlConnection);

                command.Parameters.Add(new SqlParameter("category", Category));
                command.Parameters.Add(new SqlParameter("manufacturer", Manufacturer));
                command.Parameters.Add(new SqlParameter("model", Model));
                command.Parameters.Add(new SqlParameter("date", ProductionDate.ToString("yyyy-MM-dd")));
                command.Parameters.Add(new SqlParameter("driveType", DriveType));
                command.Parameters.Add(new SqlParameter("gearbox", Gearbox));
                command.Parameters.Add(new SqlParameter("engine", Engine));
                command.Parameters.Add(new SqlParameter("cost", SqlDbType.Decimal)
                {
                    Precision = 18,
                    Scale     = 2
                }).Value = Cost;
                command.Parameters.Add(new SqlParameter("vin", VIN));
                command.Parameters.Add(new SqlParameter("licensePlateNum", LicensePlateNum));
                command.Parameters.Add(new SqlParameter("id", id));

                try
                {
                    command.ExecuteNonQuery();
                    success = true;
                }
                catch (Exception exp)
                {
                    throw;
                }
            }

            return(success);
        }
Beispiel #4
0
 public override string ToString()
 {
     return(string.Format(
                "Id: {0}, Brand: {1}, Type: {2}, NrSeats: {3}, NrDoors: {4}, Power: {5}, Date: {6}, Reservoir: {7}",
                ID,
                Brand,
                Type,
                NrSeats,
                NrDoors,
                Power.PrintInFormat("KW"),
                ProductionDate.ToShortDateString(),
                ReservoirType
                ));
 }
        public string IsExpired()
        {
            DateTime expireDate = ProductionDate.AddDays(7);
            var      isExpired  = expireDate > DateTime.Now;
            var      resultText = "";

            if (isExpired)
            {
                resultText += "expired!";
            }
            else
            {
                resultText += "not expired!";
            }
            return(resultText);
        }
Beispiel #6
0
        /// <summary>
        /// Save new car to database.
        /// </summary>
        /// <returns>True if save succeeded, false if save failed.</returns>
        public bool AddNewCar()
        {
            bool success = false;

            using (SqlConnection sqlConnection = new SqlConnection())
            {
                sqlConnection.ConnectionString = Helpers.connectionString;
                sqlConnection.Open();

                SqlCommand command = new SqlCommand("INSERT INTO samochody (klasa, marka, model, [rok produkcji], [rodzaj napędu], [skrzynia biegów], silnik, status, [koszt wynajęcia], vin, [numer rejestracyjny]) " +
                                                    $"VALUES(@category, @manufacturer, @model, @productionDate, @driveType, @gearbox, @engine, @status, @cost, @VIN, @licensePlateNum)", sqlConnection);

                command.Parameters.Add(new SqlParameter("category", Category));
                command.Parameters.Add(new SqlParameter("manufacturer", Manufacturer.ToUpper()));
                command.Parameters.Add(new SqlParameter("model", Model.ToUpper()));
                command.Parameters.Add(new SqlParameter("productionDate", ProductionDate.ToString("yyyy-MM-dd")));
                command.Parameters.Add(new SqlParameter("driveType", DriveType));
                command.Parameters.Add(new SqlParameter("gearbox", Gearbox));
                command.Parameters.Add(new SqlParameter("engine", Engine));
                command.Parameters.Add(new SqlParameter("status", EnumStatus.Dostępny.ToString()));
                command.Parameters.Add(new SqlParameter("cost", Cost));
                command.Parameters.Add(new SqlParameter("VIN", VIN.ToUpper()));
                command.Parameters.Add(new SqlParameter("licensePlateNum", LicensePlateNum.ToUpper()));

                try
                {
                    command.ExecuteNonQuery();
                    success = true;
                }
                catch (Exception)
                {
                    throw;
                }
            }

            return(success);
        }
Beispiel #7
0
 public override string ToString()
 {
     return("code:" + code + " MachineNO:" + MachineNo + " productionDate:" + ProductionDate.ToString() + " errType:" + errType + " processType:" + ProcessType + " workUnit:" + workUnit + " Note:" + Note + " Coderange:" + codeRange);
 }
Beispiel #8
0
 public bool EqualsProductionDate(LotInformation info)
 {
     return(ProductionDate.Equals(info.ProductionDate));
 }
Beispiel #9
0
 public bool Equals(LotInformation lot)
 {
     return(ProductionDate.Equals(lot.ProductionDate) && QuantityProduct == lot.QuantityProduct);
 }
Beispiel #10
0
 //Increment, Decriment
 public int CompareTo(object obj)
 {
     return(-ProductionDate.CompareTo(((LotInformation)obj).ProductionDate));
 }