public static VehicleEntrance Select(int id)
        {
            if (id == 0)
            {
                throw new NotFoundIDEntity("A chave primaria não pode ser igual a 0");
            }

            VehicleEntrance vehicle = null;
            string          sql     = string.Format("SELECT * FROM VehicleEntrance WHERE id = {0}", id);

            using (MySqlCommand command = new MySqlCommand(sql, ConnectMysql.GetInstance()))
            {
                using (MySqlDataReader reader = command.ExecuteReader())
                {
                    if (!reader.Read())
                    {
                        throw new NotExecuteCommandSql("Erro na leitura de uma data do banco ou a placa do veiculo não existe na base");
                    }

                    double   hourPrice       = reader.GetDouble(1);
                    string   board           = reader.GetString(2);
                    DateTime dateTimeInitial = reader.GetDateTime(3);
                    DateTime dateTimeFinal   = reader.GetDateTime(4);
                    double   priceCharged    = reader.GetDouble(5);
                    vehicle           = new VehicleEntrance(id, board, dateTimeInitial);
                    vehicle.HourPrice = hourPrice;
                    if (!vehicle.InvalidDatetime(dateTimeFinal))
                    {
                        vehicle.DateOut = dateTimeFinal;
                    }
                }
            }
            return(vehicle);
        }
        public static List <VehicleEntrance> SelectAll(int limit = 1000)
        {
            List <VehicleEntrance> list = new List <VehicleEntrance>();
            string sql = string.Format("SELECT * FROM VehicleEntrance LIMIT {0}", limit);

            using (MySqlCommand command = new MySqlCommand(sql, ConnectMysql.GetInstance()))
            {
                using (MySqlDataReader reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        int             id        = reader.GetInt32(0);
                        double          hourPrice = reader.GetDouble(1);
                        string          board     = reader.GetString(2);
                        DateTime        dateIn    = reader.GetDateTime(3);
                        DateTime        dateOut   = reader.GetDateTime(4);
                        VehicleEntrance ve        = new VehicleEntrance(id, board, dateIn);
                        ve.HourPrice = hourPrice;
                        if (!ve.InvalidDatetime(dateOut))
                        {
                            ve.DateOut = dateOut;
                        }
                        list.Add(ve);
                    }
                }
            }
            return(list);
        }
Exemple #3
0
        public void GetPriceMinuteTest()
        {
            DateTime initialDateControl = new DateTime(2015, 8, 16, 0, 0, 0);
            DateTime finalDateControl   = new DateTime(2015, 11, 15, 23, 59, 59);
            double   hourPrice          = 5;

            ValidityControl.AddDateControl(hourPrice, initialDateControl, finalDateControl);

            VehicleEntrance vehicleTest = GetVehicleTest();

            vehicleTest.DateOut = new DateTime(2015, 9, 25, 15, 45, 0); // 15m
            Assert.AreEqual(2.5, vehicleTest.PriceCharged);

            vehicleTest.DateOut = new DateTime(2015, 9, 25, 16, 0, 0); // 30m
            Assert.AreEqual(2.5, vehicleTest.PriceCharged);

            vehicleTest.DateOut = new DateTime(2015, 9, 25, 16, 30, 10); // 1H
            Assert.AreEqual(5, vehicleTest.PriceCharged);

            vehicleTest.DateOut = new DateTime(2015, 9, 25, 16, 40, 10); // 1H 10m
            Assert.AreEqual(5, vehicleTest.PriceCharged);

            vehicleTest.DateOut = new DateTime(2015, 9, 25, 16, 41, 0); // 1H 11m
            Assert.AreEqual(10, vehicleTest.PriceCharged);

            vehicleTest.DateOut = new DateTime(2015, 9, 25, 17, 35, 2); // 2H 5m
            Assert.AreEqual(10, vehicleTest.PriceCharged);

            vehicleTest.DateOut = new DateTime(2015, 9, 25, 17, 41, 0); // 2H 11m
            Assert.AreEqual(15, vehicleTest.PriceCharged);
        }
        public static VehicleEntrance Select(string vehicleBoard)
        {
            VehicleEntrance vehicle = null;
            string          sql     = string.Format("SELECT * FROM VehicleEntrance WHERE Board = \"{0}\"", vehicleBoard);

            using (MySqlCommand command = new MySqlCommand(sql, ConnectMysql.GetInstance()))
            {
                using (MySqlDataReader reader = command.ExecuteReader())
                {
                    if (!reader.Read())
                    {
                        throw new NotExecuteCommandSql("Erro na leitura de uma data do banco ou a placa do veiculo não existe na base");
                    }

                    int      id              = reader.GetInt32(0);
                    double   hourPrice       = reader.GetDouble(1);
                    DateTime dateTimeInitial = reader.GetDateTime(3);
                    DateTime dateTimeFinal   = reader.GetDateTime(4);
                    double   priceCharged    = reader.GetDouble(5);
                    vehicle = new VehicleEntrance(id, vehicleBoard, dateTimeInitial);
                    if (!vehicle.InvalidDatetime(dateTimeFinal))
                    {
                        vehicle.DateOut = dateTimeFinal;
                    }
                    vehicle.HourPrice    = hourPrice;
                    vehicle.PriceCharged = priceCharged;
                }
            }
            return(vehicle);
        }
Exemple #5
0
        public ActionResult Update(int id)
        {
            VehicleUpdateViewModel model   = new VehicleUpdateViewModel();
            VehicleEntrance        vehicle = VehicleEntranceModel.Select(id);

            model.HourPrice   = vehicle.HourPrice.ToString().Replace(".", ",");
            model.Board       = vehicle.Board;
            model.InitialDate = vehicle.DateIn.ToString("dd/MM/yyyy HH:mm:ss");
            model.FinalDate   = vehicle.DateOut.ToString("dd/MM/yyyy HH:mm:ss");;
            return(View(model));
        }
Exemple #6
0
 public void StayTimeReturnDateOutInvalidTest()
 {
     try
     {
         VehicleEntrance entrance = GetVehicleTest();
         Assert.Fail("Deveria ter lançado uma ArgumentException");
     }
     catch (NotFoundDateControl e)
     {
         Assert.IsTrue(true);
     }
 }
        public static void Insert(VehicleEntrance vehicle)
        {
            string initialDate = vehicle.DateIn.ToString("yyyy-MM-dd HH:mm:ss");
            string finalDate   = vehicle.DateOut.ToString("yyyy-MM-dd HH:mm:ss");
            string sql         = string.Format(
                "INSERT INTO VehicleEntrance (HourPrice, Board, DateIn, DateOut, PriceCharged) VALUES ({0}, \"{1}\", \"{2}\", \"{3}\", {4});"
                , MySqlHelper.DoubleQuoteString(vehicle.HourPrice.ToString()).Replace(",", "."), vehicle.Board, initialDate, finalDate, MySqlHelper.DoubleQuoteString(vehicle.PriceCharged.ToString()).Replace(",", "."));

            using (MySqlCommand command = new MySqlCommand(sql, ConnectMysql.GetInstance()))
            {
                command.CommandText = sql;
                command.ExecuteNonQuery();
            }
        }
Exemple #8
0
        public void SetVehicleListTest()
        {
            DateTime initialDateControl = new DateTime(2015, 8, 16, 0, 0, 0);
            DateTime finalDateControl   = new DateTime(2015, 11, 15, 23, 59, 59);
            double   hourPrice          = 5;

            ValidityControl.AddDateControl(hourPrice, initialDateControl, finalDateControl);

            string          board   = "ABC 8801";
            DateTime        dateIn  = new DateTime(2015, 9, 25, 15, 30, 0);
            VehicleEntrance vehicle = new VehicleEntrance(board, dateIn);

            VehicleControl.AddVehicle(vehicle);
            Assert.AreEqual(vehicle, VehicleControl.GetVehicleInside(vehicle.Board));
        }
        public static void Update(VehicleEntrance vehicle)
        {
            if (vehicle.ID == 0)
            {
                throw new NotFoundIDEntity("A objeto atualizado não possue uma chave primária");
            }
            string initialDate = vehicle.DateIn.ToString("yyyy-MM-dd HH:mm:ss");
            string finalDate   = vehicle.DateOut.ToString("yyyy-MM-dd HH:mm:ss");
            string sql         = string.Format(
                "UPDATE VehicleEntrance SET HourPrice={0}, Board=\"{1}\", DateIn=\"{2}\", DateOut=\"{3}\", PriceCharged={4} WHERE id = {5};"
                , MySqlHelper.DoubleQuoteString(vehicle.HourPrice.ToString()).Replace(",", "."), vehicle.Board, initialDate, finalDate, MySqlHelper.DoubleQuoteString(vehicle.PriceCharged.ToString()).Replace(",", "."), vehicle.ID);

            using (MySqlCommand command = new MySqlCommand(sql, ConnectMysql.GetInstance()))
            {
                command.CommandText = sql;
                command.ExecuteNonQuery();
            }
        }
Exemple #10
0
        public void test01()
        {
            DateTime initialDateControl = new DateTime(2015, 8, 16, 0, 0, 0);
            DateTime finalDateControl   = new DateTime(2015, 11, 15, 23, 59, 59);
            double   price = 5;

            ValidityControl.AddDateControl(price, initialDateControl, finalDateControl);

            //Insert
            VehicleEntrance vehicle = new VehicleEntrance("ABC 1234", new DateTime(2015, 8, 16, 15, 0, 0))
            {
                DateOut = new DateTime(2015, 8, 16, 15, 30, 0)
            };

            VehicleEntranceModel.Insert(vehicle);

            //Select by board
            VehicleEntrance selectedVehicle = VehicleEntranceModel.Select(vehicle.Board);

            Assert.IsTrue(vehicle.IsSameVehicle(selectedVehicle), "Objeto de veiculo esperado é diferente do retornado");

            selectedVehicle = VehicleEntranceModel.Select(selectedVehicle.ID);
            Assert.IsTrue(vehicle.IsSameVehicle(selectedVehicle), "Objeto de veiculo esperado é diferente do retornado");
            vehicle.ID = selectedVehicle.ID;

            //Update
            vehicle.HourPrice = 100;
            VehicleEntranceModel.Update(vehicle);
            VehicleEntrance updatedVehicle = VehicleEntranceModel.Select(vehicle.Board);

            Assert.IsTrue(!selectedVehicle.IsSameVehicle(updatedVehicle));

            //Delete
            VehicleEntranceModel.Delete(updatedVehicle);
            try
            {
                VehicleEntrance deletedVehicle = VehicleEntranceModel.Select(updatedVehicle.Board);
                Assert.Fail("Deveria ter lançado uma exceção pois não deveria existir objeto na base");
            }
            catch (NotExecuteCommandSql e)
            {
                Assert.IsTrue(true);
            }
        }
Exemple #11
0
        public void DateOutExceptionTest()
        {
            DateTime initialDateControl = new DateTime(2017, 1, 1, 0, 0, 0);
            DateTime finalDateControl   = new DateTime(2017, 12, 10, 23, 59, 59);
            double   hourPrice          = 5;

            ValidityControl.AddDateControl(hourPrice, initialDateControl, finalDateControl);

            VehicleEntrance vehicle = new VehicleEntrance("ABC 1234", new DateTime(2017, 1, 2, 0, 0, 0));

            vehicle.DateOut = new DateTime(2017, 1, 2, 0, 0, 1); // um segundo depois
            try
            {
                vehicle.DateOut = new DateTime(2017, 1, 1, 0, 0, 0); // um dia anterior
                Assert.Fail("Deveria ter lançado uma exceção ao usar uma data de saída menor que a data de entrada.");
            }
            catch (DateOutEarlierThanDateIn e)
            {
                Assert.IsTrue(true);
            }
        }
Exemple #12
0
        public void EntryTest()
        {
            DateTime initialDateControl = new DateTime(2017, 1, 1, 0, 0, 0);
            DateTime finalDateControl   = new DateTime(2017, 12, 15, 23, 59, 59);
            double   hourPrice          = 5;

            ValidityControl.AddDateControl(hourPrice, initialDateControl, finalDateControl);

            string   board  = "ABC 1236";
            DateTime dateIn = new DateTime(2017, 1, 1, 2, 0, 0);

            VehicleControl.Entry(board, dateIn);

            // deu entrada em um carro no estacionamento, não tem data de saida
            VehicleEntrance vehicleInside = VehicleControl.GetVehicleInside(board);

            Assert.IsTrue(vehicleInside.Board == board && vehicleInside.InvalidDatetime(vehicleInside.DateOut));

            // saida do estacionamento
            VehicleControl.Out(vehicleInside.Board, new DateTime(2017, 1, 1, 2, 30, 0));

            VehicleControl.DeleteVehicleByID(vehicleInside.ID);
        }
 public static void Delete(VehicleEntrance vehicle)
 {
     DeleteByID(vehicle.ID);
 }