sábado, 29 de mayo de 2010

asp.net Autenticar por formulario

http://www.elguille.info/net/aspnet/tutorialLogin/tutorialLogin.htm

jueves, 27 de mayo de 2010

Leer XML con Jquery

Tenemos el siguiente XML:


<NewDataSet>
<Table1>
<idUsuario>123456</idUsuario>
<nombre>Angelica Maria</nombre>
<apellidoPaterno>Roca</apellidoPaterno>
<apellidoMaterno>Fong</apellidoMaterno>
</Table1>
<Table1>
<idUsuario>1738043</idUsuario>
<nombre>Angélica María</nombre>
<apellidoPaterno>Roca</apellidoPaterno>
<apellidoMaterno>Fong</apellidoMaterno>
</Table1>
<Table1>
<idUsuario>2984560</idUsuario>
<nombre>Jorge Rodolfo</nombre>
<apellidoPaterno>Roca</apellidoPaterno>
<apellidoMaterno>Mercado</apellidoMaterno>
</Table1>
<Table1>
<idUsuario>3394347</idUsuario>
<nombre>Paola Lenny</nombre>
<apellidoPaterno>Márquez</apellidoPaterno>
<apellidoMaterno>Pinto</apellidoMaterno>
</Table1>
<Table1>
<idUsuario>3830628</idUsuario>
<nombre>SHIRLEY DANNY</nombre>
<apellidoPaterno>TOTOLA</apellidoPaterno>
<apellidoMaterno>MORÓN</apellidoMaterno>
</Table1>
</NewDataSet>


Para leer un XML (aplicado al xml del ejemplo):
// tenemos que tener referenciados los archivos de Jquery "jquery.js"
// xml (variable de tipo XML)
// trabaja como un 'foreach' ...

$(xml).find('Table1').each(function(){
var atributo1 = $(this).attr('id'); //para leer los atributos del tag, si los tubiera
var idusuario = $(this).find('idUsuario').text();
var nombre = $(this).find('nombre').text();
var apMaterno = $(this).find('apellidoMaterno').text()
var apPaterno = $(this).find('apellidoPaterno').text()
});


A continuacion un ejemplo :
en un archivo Javascript, por ejemplo la siguiente funcion:

function TraerDatosUsuarios() {

// Estamos realizando una llamada ajax de JQuery
// url: la ruta del servidor, data: le mandamos los parametros necesarios
// success: la funcion que se va a ejecutar con los datos xml que retorne la llamada
// en la funcion se esta leyendo el xml "datos" con JQuery
$.ajax({
type: "POST",
datetype: "xml",
url: "../Utilidades/comunicador.ashx",
data: "consulta=obtenerpersonas",
success: function(datos) {
if ($(datos).find('NewDataSet').length > 0) {
var j = 0;
$(datos).find('Table1').each(function() {
var DatosUnicos = new Object();
DatosUnicos.legajo = $(this).find('idUsuario').text();
DatosUnicos.nombre = $(this).find('nombre').text() + ' ' + $(this).find('apellidoPaterno').text() + ' ' + $(this).find('apellidoMaterno').text();

});
}
}
});

}


-------------------------------------------------
Para preguntarse si un elemento es null:
if ($(this).find('FK_PadreValor').length == 0)

lunes, 24 de mayo de 2010

Documentar proyectos C# e integrarlo en la IDE de Visual Studio .NET

http://www.elguille.info/colabora/puntoNET/jtorres_HelpNDoc.htm

Message Box in ASP.NET 2.0

http://www.beansoftware.com/ASP.NET-Tutorials/Message-Box.aspx

viernes, 21 de mayo de 2010

SQL - Case

Select
PK_Persona,
Nombre
(CASE WHEN TipoRelacion = 1 THEN
'Empleado'
WHEN TipoRelacion = 0 THEN 'Contratista' END) as Tipo
From Persona

jueves, 20 de mayo de 2010

SQL - Cantidad de días en el mes de la fecha que especifiques

declare @fecha as datetime;
set @fecha = '01/02/2010';
--este servidor sql recibe las fechas en formato 'dia/mes/año'
--cambiar segun la configuracion del servidor sql


SET @fecha = CONVERT(VARCHAR(10), @fecha, 101)

SET @fecha = @fecha - DAY(@fecha) + 1

select DATEDIFF(DD, @fecha, DATEADD(MM, 1, @fecha))



Con esto ya podes saber la fecha fin de un mes especifico en SQL :)

martes, 11 de mayo de 2010

Adicionar Filas dinamicamente a una Tabla HTML (vamos a adicionar Texto)

Adicionar filas dinamicamente a una tabla HTML en JavaScript.
En este ejemplo vamos a adicionar texto

function addRowToTableDatos(pk, nombre, apellidos) {
var nombreTabla = 'tblPersona';
var tbl = document.getElementById(nombreTabla);
var lastRow = tbl.rows.length;
// if there's no header row in the table, then iteration = lastRow + 1
var iteration = lastRow;
var row = tbl.insertRow(lastRow);

//esta columna es no visible, por eso en su style.display ='none'
var cell0 = row.insertCell(0); //PK
cell0.style.display = 'none';
var textNode0 = document.createTextNode(pk);
cell0.appendChild(textNode0);

var cellNombre = row.insertCell(1);
var textNombre = document.createTextNode(nombre);
cellNombre .appendChild(textNombre );

var cellAp = row.insertCell(2);
var textAp = document.createTextNode(apellidos);
cellAp.appendChild(textAp);

}

viernes, 7 de mayo de 2010

ejecutar script js , usando updatepanel

Señores, como sabemos cuando utilizamos el ajax del framework de .net , en este caso scriptmanager y update panel, ningun javacript "$(document).ready(function(){...}", que se ejecuto la primera vez (en el cargado), se vuelve a ejecutar...

SOLUCION:

ScriptManager.RegisterClientScriptBlock(Me.Page, Me.Page.GetType(), Guid.NewGuid().ToString(), "toolMostrar();", True)



esto lo colocas en cualquier evento de un botno del servidor y listo , funciona 100% seguro!!
Pdta.- dedicado para la administradora de este blog que poco aporta..

miércoles, 5 de mayo de 2010

Ajustar el tamaño fisico de una imgen para que encaje e un DIV

Esta funcion me la acaban de pasar, (me parece que se puede optimizar) por ese motivo no la voy a explicar , pero garantizarles que si funciona, solo usenla ,no reinventen la rueda


Dim ImagePercentSize As Integer = 100



Protected Function GetThumbNailSizeImage(ByVal binaryData() As Byte) As Byte()
Dim ThumbNailBinaryData() As Byte = Nothing
Try
Dim TempMemStream As New System.IO.MemoryStream(binaryData)
Dim ImageObj As System.Drawing.Image
Dim ThumbSizeImageObj As System.Drawing.Image
ImageObj = System.Drawing.Image.FromStream(TempMemStream)
Dim temHeight As Integer
Dim temWidth As Integer
temHeight = ImageObj.Height
temWidth = ImageObj.Width
Dim TempFileStream As New System.IO.MemoryStream
'If Imagesize is less than 20*20 then return the original image
If (temWidth <= 460 And temHeight <= 211) Then
Dim ImageBinaryData() As Byte
ImageObj.Save(TempFileStream, System.Drawing.Imaging.ImageFormat.Jpeg)

ImageBinaryData = New Byte(CType(TempFileStream.Length, Integer)) {}
ImageBinaryData = TempFileStream.ToArray()
Return ImageBinaryData
End If
Dim ImagePercentSize As Double = Me.ImagePercentSize


Dim a, b As Double

If (460 > temWidth) And 211 > temHeight Then
a = 211 / temHeight
b = 460 / temWidth

If (a < b) Then
temHeight = CInt(temHeight * a)
temWidth = CInt(temWidth * a)
Else
temHeight = CInt(temHeight * b)
temWidth = CInt(temWidth * b)
End If

Else
a = 211 / temHeight
b = 460 / temWidth

If (a < b) Then
temHeight = CInt(temHeight * a)
temWidth = CInt(temWidth * a)
Else
temHeight = CInt(temHeight * b)
temWidth = CInt(temWidth * b)
End If

End If



'Create thumbnail size of the original Image ImageObj
If (Me.ImagePercentSize = 0.0) Then
ThumbSizeImageObj = ImageObj.GetThumbnailImage(temWidth, temHeight, Nothing, IntPtr.Zero)
Else
ThumbSizeImageObj = ImageObj.GetThumbnailImage(temWidth, temHeight, Nothing, IntPtr.Zero)
End If
ThumbSizeImageObj.Save(TempFileStream, System.Drawing.Imaging.ImageFormat.Jpeg)

ThumbNailBinaryData = New Byte(CType(TempFileStream.Length, Integer)) {}
ThumbNailBinaryData = TempFileStream.ToArray()
Catch ex As Exception

End Try
Return ThumbNailBinaryData
End Function


'----------- para llamar a la funcion
Dim binaryData() As Byte = f.Item(0) ' donde f.Item(0) es un conuto de Byte tra

Dim TempMemStream As New System.IO.MemoryStream(GetThumbNailSizeImage(binaryData))

'luego esta imagen redimencionada la puden guardar de la siguiente manera

Dim image_ As New Bitmap(TempMemStream)
Dim filepath As String = Server.MapPath("images/")
Dim dir As New DirectoryInfo(filepath)
Dim filecount As FileInfo() = dir.GetFiles()
Dim i As Integer = filecount.Length
Dim imagename As String = filepath + ((i + 1) & ".jpg")
image_.Save(imagename)

Nota.- cuando agregen la imagen al componente html , no usen las propiedades width ni heigth