martes, 28 de mayo de 2013

Horas / Minutos transcurridos entre dos fechas

select
rtrim(DATEDIFF(MI, '27/05/2013 09:52:00','27/05/2013 11:41:00') / 60) +
':' +
rtrim(DATEDIFF(MI, '27/05/2013 09:52:00','27/05/2013 11:41:00') % 60)

viernes, 17 de mayo de 2013

Pasar más de un parámetro al jQuery autocomplete

Normalmente pasamos un sólo valor al autocomplete: el valor escrito en el textbox (request.term). ¿Y si queremos pasar algún otro valor, por ejemplo, para usarlo como parámetro en un sp?
 
HTML
====
<table width="800px" border="0">
    <tr>
        <td style="width:90px;">
            N° Nota Salida
        </td>
        <td>
            <asp:TextBox ID="txtNumeroDoc" runat="server" Width="80px" MaxLength="10" CssClass="IntegerType">

        </td>
        <td>
             <asp:HiddenField runat="server" ID="hdnCodUsuario" Value="1" />
        </td>
    </tr>
</table>


Javascript
==========
$(document).ready(function () {

    $('#txtNumeroDoc').autocomplete({
        source: function (request, response) {
            $.ajax({
                type: 'POST',
                contentType: 'application/json; charset=utf-8',
                url: '../../ws/autocomplete.asmx/NotaIngresoSalida',
                data: "{'tag': '" + request.term + "', 'CodUsuario': '" + $('#hdnCodUsuario').val() + "'}",
          
                dataType: 'json',
                async: true,
                success: function (data) {
                    response($.map(data.d, function (item) {
                        return {
                            value: item.value,
                            label: item.label,
                            seriedoc: item.seriedoc,
                            numerodoc: item.numerodoc
                        };
                    }));
                },
                error: function (result) {
                    alert('No se pudo cargar la lista de notas de salida.');
                }
            });
        },
        minLength: 2,
        select: function (event, ui) {
            NotaIngresoSalida_Buscar(ui.item.seriedoc, ui.item.numerodoc);
        }
    });

});

function NotaIngresoSalida_Buscar(strSerieDoc, strNumeroDoc) {
    alert(strSerieDoc + '-' + strNumeroDoc);

    return false;
}



WebServices
===========
   <WebMethod()> _
    Public Function NotaIngresoSalida(ByVal tag As String, ByVal CodUsuario As String) As Object
        Dim output As String = ""

        Dim lhtbResultado = New With {.value = "", .label = "", .seriedoc = "", .numerodoc = ""}
        Dim Lista = {lhtbResultado}.ToList()

        Try
            Dim objbnNotaIngresoSalida As New bnNotaIngresoSalida
            Dim dt As New DataTable

            dt = objbnNotaIngresoSalida.pf_NotaIngresoSalida_Salidas_Autocomplete(tag, CodUsuario)

            If dt.Rows.Count > 0 Then
                Lista.RemoveAt(0)

                For i = 0 To dt.Rows.Count - 1
                    Dim lhtbItem = New With {.value = "", .label = "", .seriedoc = "", .numerodoc = ""}

                    With lhtbItem
                        .value = dt(i).Item(0)
                        .label = dt(i).Item(0)
                        .seriedoc = dt(i).Item(1)
                        .numerodoc = dt(i).Item(2)
                    End With

                    Lista.Add(lhtbItem)
                Next
            End If

            output = Lista.ToString()

        Catch ex As Exception

        End Try

        Return Lista
    End Function

lunes, 13 de mayo de 2013

Obtener el id del tr que contiene un input específico

¿Cuál es el ID de la fila de una tabla que contiene un textbox que está siendo procesado por nuestro script?

HTML
==== 
<div id="divMod2" class="divNeumatConfig" style="display:none;">
    <table style="width:850px;" class="ui-widget ui-widget-content ui-corner-all">
        <tr>
            <td align="center">                                          
                <table border="0" width="840px">
                    <tr id="trMod2Eje1">
                        <td colspan="2" align="right">
                            <asp:TextBox runat="server" ID="txtMod2Pos1" Width="80px" CssClass="CodNeumatico" style="text-align:center"></asp:TextBox>
                        </td>
                        <td class="celdanegra">1</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td class="celdanegra">2</td>
                        <td colspan="2" align="left">
                            <asp:TextBox runat="server" ID="txtMod2Pos2" Width="80px" CssClass="CodNeumatico" style="text-align:center"></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2" align="right">
                            <asp:TextBox runat="server" ID="txtMod2Pos1Med" CssClass="BorderlessRight"></asp:TextBox><asp:ImageButton ID="imgMod2Pos1" runat="server" CssClass="imgMarca" ImageUrl="~/images/neumaticos/nothing.png" Height="27px" Width="30px" ImageAlign="AbsMiddle"/>
                        </td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td colspan="2">                                                      
                            <asp:ImageButton ID="imgMod2Pos2" runat="server" CssClass="imgMarca" ImageUrl="~/images/neumaticos/nothing.png" Height="27px" Width="30px" ImageAlign="AbsMiddle"/><asp:TextBox runat="server" ID="txtMod2Pos2Med" CssClass="BorderlessLeft"></asp:TextBox>
                        </td>
                    </tr>
                </table>                                          
            </td>
        </tr>
    </table>      
</div>


JavaScript
==========
$('#divMod' + $(Contenedor + 'hdnModeloCfg').val() + ' .CodNeumatico').each(function (index) {
    intPosicion = parseInt(this.id.split('Pos')[1], 10);       
    intEje = parseInt($(this).closest('tr').attr('id').split('Eje')[1],10);

    var objNeumatConf = {
        CodNeumatico: $('#' + this.id).val(),
        Eje: intEje,
        Posicion: intPosicion
    };

    arrNeumaticos.push(objNeumatConf);
});