Saturday, March 31, 2012

Jquey Autofill with return value


  Sys.Application.add_load(function () {

        $("#<%= txtto.ClientID %>").autocomplete('bolfill.ashx').result(function (event, data, formatted) {
            if (data) {
                var type = document.getElementById('<%=ddBOLtotype.ClientID %>').value;
                if (type == "1") {
                    var suploc = data[1].split("-");
                    var sup = suploc[0];
                    var loc = suploc[1];
                    $("#<%= hdnSupplier.ClientID %>").val(sup);
                    var hid = document.getElementById('<%=hdnSupplier.ClientID %>').value;

                    $("#<%= hdnLocation.ClientID %>").val(loc);
                    var hid = document.getElementById('<%=hdnLocation.ClientID %>').value;

                }
                else if (type == "2") {
                    $("#<%= hdncontainerid.ClientID %>").val(data[1]);
                    var hid = document.getElementById('<%=hdncontainerid.ClientID %>').value;

                }
                $("#<%= hdnto.ClientID %>").val(data[0]);
                var hid = document.getElementById('<%=hdnto.ClientID %>').value;
             
            }
            else {
                $("#<%= hdncontainerid.ClientID %>").val('-1');

            }
        });


    });




Imports System.Web
Imports System.Web.Services
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.Text
Imports System.Web.SessionState

Public Class bolfill
    Implements System.Web.IHttpHandler
    Implements IRequiresSessionState

    Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest

        Dim clientid As String = Convert.ToString(HttpContext.Current.Session("clientid"))
        Dim name As String
        Dim id As String

        If clientid <> "" Then
            Dim type As String = Convert.ToString(HttpContext.Current.Session("boltype"))
            Dim prefixText As String = context.Request.QueryString("q")

            Dim conn As SqlConnection = New SqlConnection
            conn.ConnectionString = ConfigurationManager _
                    .ConnectionStrings("SurgereConnection").ConnectionString
            Dim stbuilder As New StringBuilder()

            If type = "1" Then

                stbuilder.Clear()
                stbuilder.Append("select s.Supplier_id,l.Supplier_location_id, s.Supplier_name,l.Location_name  ")
                stbuilder.Append("from Supplier s inner join Supplier_location l on s.Supplier_id=l.Supplier_id ")
                stbuilder.Append("where s.Client_id=" & Convert.ToInt64(Convert.ToString(HttpContext.Current.Session("clientid"))))
                stbuilder.Append(" and (s.Supplier_name +'-'+ upper(isnull(l.Location_name,'')) ) LIKE '" & prefixText & "%'")
                Dim cmd As SqlCommand = New SqlCommand
                cmd.CommandText = stbuilder.ToString()
                cmd.Connection = conn
                Dim sb As StringBuilder = New StringBuilder
                conn.Open()
                Dim sdr As SqlDataReader = cmd.ExecuteReader
                While sdr.Read
                    name = sdr("Supplier_name").ToString & "-" & sdr("Location_name").ToString
                    id = sdr("Supplier_id").ToString & "-" & sdr("Supplier_location_id").ToString
                    sb.Append(String.Format("{0}|{1}|{2}", name, id, Environment.NewLine))
                    ' sb.Append(sdr("Supplier_name").ToString & "-" & sdr("Location_name").ToString) _
                    '.Append(Environment.NewLine)
                End While
                conn.Close()
                context.Response.Write(sb.ToString)

            ElseIf type = "2" Then


                Dim str As String = ""
                str = "select container_id,container_nbr from container where client_id=" & Convert.ToInt64(HttpContext.Current.Session("clientid")) & " and container_nbr like '" & prefixText & "%'"


                Dim cmd As SqlCommand = New SqlCommand
                cmd.CommandText = str
                cmd.Connection = conn
                Dim sb As StringBuilder = New StringBuilder
                conn.Open()
                Dim sdr As SqlDataReader = cmd.ExecuteReader
                While sdr.Read
                    name = sdr("container_nbr").ToString
                    id = sdr("container_id").ToString
                    sb.Append(String.Format("{0}|{1}|{2}", name, id, Environment.NewLine))
                    ' sb.Append(sdr("Supplier_name").ToString & "-" & sdr("Location_name").ToString) _
                    '.Append(Environment.NewLine)
                End While
                conn.Close()
                context.Response.Write(sb.ToString)
            End If

        End If
    End Sub

    ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
        Get
            Return False
        End Get
    End Property

End Class

No comments:

Using Authorization with Swagger in ASP.NET Core

 Create Solution like below LoginModel.cs using System.ComponentModel.DataAnnotations; namespace UsingAuthorizationWithSwagger.Models {     ...