public Response Update(CheckinClient checkinClient)
        {
            Response      response   = new Response();
            SqlConnection connection = new SqlConnection();

            connection.ConnectionString = ConnectionHelper.GetConnectionString();

            SqlCommand command = new SqlCommand();

            command.CommandText =
                "UPDATE CHECKIN_CLIENTS SET PREVISAOSAIDA = @PREVISAOSAIDA, IDCLIENTS = @IDCLIENTS, IDROOMS = @IDROOMS, IDEMPLOYEES = @IDEMPLOYEES WHERE ID = @ID";
            command.Parameters.AddWithValue("@PREVISAOSAIDA", checkinClient.ExitDate);
            command.Parameters.AddWithValue("@IDCLIENTS", checkinClient.ClientID);
            command.Parameters.AddWithValue("@IDROOMS", checkinClient.RoomID);
            command.Parameters.AddWithValue("@IDEMPLOYEES", checkinClient.EmployeesID);
            command.Parameters.AddWithValue("@ID", checkinClient.ID);

            command.Connection = connection;

            try
            {
                connection.Open();
                int nLinhasAfetadas = command.ExecuteNonQuery();
                if (nLinhasAfetadas != 1)
                {
                    response.Success = false;
                    response.Message = "Registro não encontrado!";
                    return(response);
                }

                response.Success = true;
                response.Message = "Atualizado com sucesso.";
            }
            catch (Exception ex)
            {
                response.Success        = false;
                response.Message        = "Erro no banco de dados, contate o administrador.";
                response.StackTrace     = ex.StackTrace;
                response.ExceptionError = ex.Message;
            }
            finally
            {
                connection.Close();
            }
            return(response);
        }
        public Response Insert(CheckinClient checkinClient)
        {
            Response response = new Response();

            SqlConnection connection = new SqlConnection();

            connection.ConnectionString = ConnectionHelper.GetConnectionString();

            SqlCommand command = new SqlCommand();

            command.CommandText =
                "INSERT INTO CHECKIN_CLIENTS (PREVISAOSAIDA, IDCLIENTS, IDROOMS, IDEMPLOYEES) VALUES (@PREVISAOSAIDA, @IDCLIENTS, @IDROOMS, @IDEMPLOYEES)";
            command.Parameters.AddWithValue("@PREVISAOSAIDA", checkinClient.ExitDate);
            command.Parameters.AddWithValue("@IDCLIENTS", checkinClient.ClientID);
            command.Parameters.AddWithValue("@IDROOMS", checkinClient.RoomID);
            command.Parameters.AddWithValue("@IDEMPLOYEES", checkinClient.EmployeesID);
            command.Parameters.AddWithValue("@ATIVO", true);

            command.Connection = connection;

            try
            {
                connection.Open();
                command.ExecuteNonQuery();
                response.Success = true;
                response.Message = "Cadastrado com sucesso.";
            }
            catch (Exception ex)
            {
                response.Success        = false;
                response.Message        = "Erro no banco de dados, contate o administrador.";
                response.StackTrace     = ex.StackTrace;
                response.ExceptionError = ex.Message;
            }
            finally
            {
                connection.Close();
            }
            return(response);
        }
Esempio n. 3
0
        public void PenaltyCalculation(CheckinClient checkin, CheckoutClient checkout)
        {
            if (checkin.ExitDate == checkout.ExitDate)
            {
                checkout.ExitOnTime = true;
                checkout.Penalty    = 0;
            }
            else if (checkin.ExitDate > checkout.ExitDate)
            {
                checkout.ExitOnTime = true;
                checkout.Penalty    = 0;
            }
            else
            {
                int roomTypeID = Convert.ToInt32(roomDAO.GetRoomTypeIDByRoomID(checkin.RoomID).Data);

                double dailyValue = Convert.ToDouble(roomTypeDAO.GetDailyValueByRoomTypeID(roomTypeID).Data);

                int days = checkout.ExitDate.Day - checkin.ExitDate.Day;

                checkout.ExitOnTime = false;
                checkout.Penalty    = dailyValue * days;
            }
        }