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);
        }
        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);
        }
        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);
        }
Example #4
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);
        }