Arquivos

Arquivo para a categoria ‘Flex’

Acrescentando quebra de linha em um campo CLOB

Esse método realiza a transformação de um campo CLOB do banco ORACLE e retorna um campo CLOB com quebra de linha.


public static function parserClob(texto: String): String 
{			  
	var tipoTexto: String = "N";
	  
	while (texto.indexOf("\t") > -1) 
	{
		tipoTexto = "S";
		break;
	}			  
	if (tipoTexto == "S")
	{		 
		while (texto.indexOf("\t") > -1) {
			texto = texto.replace("\t", "\r");
		}			  
	}else{
		 while (texto.indexOf("\r") > -1) {
			texto = texto.replace("\r", "\t");
		 }
	}
	return texto;
}
CategoriasFlex Tags:,

Calcular idade completa com Flex

Bueno, Essa função recebe como parâmetro uma data de nascimento e retorna uma String com o ano, mes e dia. A função foi feita validando o resultado no site http://www.timeanddate.com


public static function calcularIdadeCompleta(niver:Date, hoje:Date = null):String
{
	if (!hoje)
	{
		hoje = new Date();
	}

	var idade:String;

	var dias:Number;
	var meses:Number;
	var anos:Number;

	// Já fez aniversário
	if (hoje.getMonth() > niver.getMonth())
	{
		anos = hoje.getFullYear() - niver.getFullYear();

		if (hoje.getDate() < niver.getDate())
		{
			/* remove 1 mês, porque no mês corrente ainda
			 não ultrapassou o dia da data de aniversário */
			meses = hoje.getMonth() - niver.getMonth() - 1;

			// a soma dos dias ultrapassados após o dia da data de aniversário
			dias = hoje.getDate() + (31 - niver.getDate());
		}
		else
		{
			meses = hoje.getMonth() - niver.getMonth();
			dias = hoje.getDate() - niver.getDate();
		}
	}
	else if (hoje.getMonth() < niver.getMonth())
	{
		// remove 1 ano porque ainda não fez aniversário
		anos = hoje.getFullYear() - niver.getFullYear() - 1;

		if (hoje.getDate() < niver.getDate())
		{
			meses = hoje.getMonth();

			// a soma dos dias ultrapassados após o dia da data de aniversário
			dias = hoje.getDate() + (31 - niver.getDate());
		}
		else
		{
			// adiciona 1 mês porque já passou do dia da data de aniversário
			meses = hoje.getMonth() + 1;
			dias = hoje.getDate() - niver.getDate();
		}
	}
	else if (hoje.getMonth() == niver.getMonth())
	{
		if (hoje.getDate() < niver.getDate())
		{
			// remove 1 ano porque ainda não fez aniversário
			anos = hoje.getFullYear() - niver.getFullYear() - 1;
			meses = hoje.getMonth() + 1;
			// a soma dos dias ultrapassados após o dia da data de aniversário
			dias = hoje.getDate() + (31 - niver.getDate());
		}
		else
		{
			anos = hoje.getFullYear() - niver.getFullYear();
			meses = hoje.getMonth() - niver.getMonth();
			dias = hoje.getDate() - niver.getDate();
		}
	}
	idade = anos + "a " + meses + "m " + dias + "d ";
	return idade;
}


Abraço.

Transformando RGB para Decimal

Conforme solicitado por e-mail segue a baixo outro exemplo de “cast” de RGB mas agora transformandoo em Decimal, no post anterior tem o exemplo para transformar RGB para Hexadecimal.


public static function rgbDecimal(cp:ColorPicker):String
{
	var input:String = rgbHexaDecimal(cp);
	input = input.substring(input.length - 6, input.length);
	var rgbDecimal:String = "";
	var r:int;
	var g:int;
	var b:int;

	for(var i:int = 0; i < input.length; i++)
	{
		r = parseInt(input.charAt(i), 16);
		i++;
		g = parseInt(input.charAt(i), 16)
		b = (r * 16) + (g * 1);
		rgbDecimal += new String(b) + ",";
	}
	rgbDecimal = rgbDecimal.substring(0, rgbDecimal.length - 1);

	return rgbDecimal;
}

Abraços.

CategoriasFlex Tags:, , , ,

Transformando RGB para Hexadecimal

Bueno, para salvar uma cor no banco normalmente se utiliza uma string no formato RGB, e na aplicação é necessário que essa informação esteja em formato Hexadecimal para ser utilizada, portanto fiz essa função que recebe como parâmetro uma string com o código em RGB e transforma em Hexadecimal.
Exemplo: Formato RGB = “r255g255b255″ transforma em Hexadecinal “#ffffff”.


public static function rgbToHex(str:String):String
{
	if (str == null)
	{
		return "";
	}
	var r:Number, g:Number, b:Number = 0;
	var regExp:RegExp = /[rgb]/g;
	var match:String;
	while((match = regExp.exec(str)) != null)
	{
		var s:String = "";
		for (var i:Number = regExp.lastIndex; i  -1)
                {
			var char:String = str.charAt(i);
                        if (char.search("[0-9]") > -1){
				s += char;
			} else {
				break;
			}
		}
		if (match == "r")
		{
			r = new Number(s);
		} else if (match == "g")
		{
			g = new Number(s);
		} else
		{
			b = new Number(s);
		}
	}
	return "#" + toHex(r) + toHex(g) + toHex(b);
}

Flw.

CategoriasFlex Tags:, , , ,
Seguir

Obtenha todo post novo entregue na sua caixa de entrada.