Ejemplo de JqueryUI Autocomplete cuando el source no contiene label y value

Fuente: http://www.jensbits.com/2011/08/24/using-jquery-autocomplete-when-remote-source-json-does-not-contain-label-or-value-fields/

Using jQuery Autocomplete When Remote Source JSON Does Not Contain ‘Label’ or ‘Value’ Fields

If the jQuery autocomplete plugin uses a remote datasource, the autocomplete expects it to return json data with a ‘label’ and/or a ‘value’ field. If you return one, either ‘label’ or ‘value’, the autocomplete uses it for both the suggestion menu and the value of the input box. If you return both, it uses the ‘label’ for the suggestion menu and the ‘value’ for the value of the input box.
What happens when the remote source returns neither a ‘label’ or ‘value’ and you cannot change the returned json of the remote source? Or, better yet, it does return them but you want different values used in the autocomplete?
For example, the remote source json string below has neither a ‘label’ or a ‘value’ field. Using this would result in the autocomplete not functioning at all.
[{"id":"3","state":"Alaska","abbrev":"AK"},{"id":"4","state":"Alabama","abbrev":"AL"},{"id":"9","state":"California","abbrev":"CA"}]
You can work around this by modifying the ‘source’ option of the autocomplete to assign one or both of the ‘label’ and ‘value’ fields values found in the json result.
To modify the ‘source’ option of the autocomplete, we add an ajax call to the source and, in the ‘success’ callback, we assign the values of all the variables we want the autocomplete to use.
$("#state").autocomplete({
                source: function( request, response ) {
                $.ajax({
                    url: "states_remote.php",
                    dataType: "json",
                    data: {term: request.term},
                    success: function(data) {
                                response($.map(data, function(item) {
                                return {
                                    label: item.state,
                                    id: item.id,
                                    abbrev: item.abbrev
                                    };
                            }));
                        }
                    });
                },
                minLength: 2,
                select: function(event, ui) {
                    $('#state_id').val(ui.item.id);
                    $('#abbrev').val(ui.item.abbrev);
                }
            });
To break this down, the ajax function has the following options:
  1. url: url of page that returns the json; subject to same origin policy (you should use jsonp for cross-domain url’s)
  2. dataType: sets the data coming back to the ajax function as json
  3. data: sets the query parameter of ‘term’ to the value of ‘request.term’ which is what the user types into the input box
  4. success: callback function that maps the returned json and sets the variables that the autcomplete will use
In this example, the ‘select’ option of the autocomplete sets the label field used by the autocomplete in the suggest menu and as the value of the input box. It also sets the values of some additional fields in the form. They are returned to the page in the demo to verify that they are set. ‘id’ is a hidden field in the form and ‘abbrev’ populates a read-only input box in the form.
And, if the json result does set the ‘label’ and/or ‘value’ fields but you don’t want those values in the autocomplete, you can adjust the ‘return’ of the ‘success’ function in th ‘ajax’ call:
return {
    label: item.value,
    yourVar1: item.id,
    yourVar2: item.label
};
// or however you want it as long as a 'label' and/or 'value' field is set
Remember, the autocomplete needs a ‘label’ or ‘value’. Don’t forget to set one, the other, or both.






Ejemplo simple Autocomplete y JSON

data.json

[{
"label": "C++",
"value": "C++"
}, {
"label": "Java",
"value": "Java"
}]



prueba.html:

$('#campo").autocomplete({
     source: "/url_del_servidor/data.json"
});


Enumerar las inner classes de un proyecto (clases anidadas)

Ej, si se quieren obtener todas las inner classes de LibX.dll:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using LibX;
using System.IO;

namespace ConsoleApplication1
{
    class Program
    {
        static StreamWriter sw;

        static void Main(string[] args)
        {            
            if (File.Exists(@"c:\temp\out.txt"))
                File.Delete(@"c:\temp\out.txt");

            sw = File.AppendText(@"c:\temp\out.txt");


            var theList = Assembly.GetExecutingAssembly().GetTypes()
                      .Where(t => t.Namespace == "X")
                      .ToList();

            var asm = Assembly.LoadFile(@"C:\crusso\X\fuentes\Desarrollo\_DLL\LibX\bin\debug\LibX.dll");

            foreach (var t in asm.ExportedTypes)
            {
                Type[] typelist = GetTypesInNamespace(asm, t.Namespace);
                for (int i = 0; i < typelist.Length; i++)
                {
                    var jj = ListarInner(typelist[i]);
                    if (jj != "")
                    {
                        sw.WriteLine(jj);
                    }
                }
            }

            var namespaces = asm.GetTypes()
                                     .Select(t => t.Namespace)
                                     .Distinct();

            sw.Close();

            Console.ReadLine();
        }



        private static Type[] GetTypesInNamespace(Assembly assembly, string nameSpace)
        {
            return assembly.GetTypes().Where(t => String.Equals(t.Namespace, nameSpace, StringComparison.Ordinal)).ToArray();
        }

        public static string ListarInner(Type t)
        {
            Type myType = (t);

            Type[] myArrayType = myType.GetNestedTypes(BindingFlags.Public);
            foreach (var tt in myArrayType)
            {
                bool isStruct = tt.IsValueType && !tt.IsEnum;

                if (!tt.IsEnum && !isStruct)
                {
                    return tt + Environment.NewLine + ListarInner(tt);
                }
            }

            return "";
        }
    }
}



JqueryUI autocomplete con JSON

Código html:


<style>
.ui-autocomplete { height: 400px; overflow-y: scroll; overflow-x: hidden;}

</style>

<input id="id_mantis" type="text" size="6" style="" />

<script>
   $(document).ready(function() {
      CargarAutocompletar("nombre_del_campo_de_texto", 2);
   });
</script>

Código JS:

function CargarAutocompletar(id_input, modo)
{
$.ui.autocomplete.prototype._renderItem = function (ul, item) {
item.label = item.label.replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + $.ui.autocomplete.escapeRegex(this.term) + ")(?![^<>]*>)(?![^&;]+;)", "gi"), "<span style='font-weight:bold;color:Blue;'>$1</span>");
return $("<li></li>")
.data("item.autocomplete", item)
.append("<a>" + item.label + "</a>")
.appendTo(ul);
    };

jQuery.support.cors = true;
$.ajaxSetup({ cache: false });

var urlServicio = "http://" + window.self.location.hostname + "/wsX/Parametros.asmx/ObtenerChoiceListItemsJSON";

$("#" + id_input).autocomplete({
source: function( request, response ) {
$.ajax({
url: urlServicio,
dataType: "json",
data: {term: request.term,
  dcnFiltro: $("#" + id_input).val(),
  random: Math.floor(Math.random()*9999999999)},
success: function(data) {
response($.map(data, function(item) {
return {
label: item.dcn_cod,
id: item.dcn_dsc                                    
};
}));
}
});
},
minLength: 2,
select: function(event, ui) {
//quito tags html
var dcn = ui.item.label.replace(/<(?:.|\n)*?>/gm, '');
alert(dcn);                    
}
});
}

Internal Server Error 500 al intentar ejecutar un web service

descomentar la siguiente línea del web service:

<System.Web.Script.Services.ScriptService()> _


Llamado a un webservice asmx con AJAX

Código .NET

    Imports System.Web
    Imports System.Web.Services
    Imports System.Web.Services.Protocols
    Imports LibX.X
    Imports System.Web.Script.Services
    Imports System.Web.Script.Serialization

    <WebMethod> _
    <ScriptMethod(ResponseFormat:=ResponseFormat.Json)> _
    Sub ObtenerChoiceListItems2(ByVal cobnamtab As String, ByVal filtro As String)
        Dim js As New JavaScriptSerializer()
        Context.Response.Clear()
        Context.Response.ContentType = "application/json"

        Dim d As String = "{ " +
                               "'datos': { " +
                                   "'items': [{ " +
                                   "        'coddestab': '5', " +
                                   "        'deslartab': 'DESC ITEM 5' " +
                                   "    }, { " +
                                   "         'coddestab': '10', " +
                                   "         'deslartab': 'DESC ITEM 10' " +
                                   "     }, { " +
                                   "         'coddestab': '15', " +
                                   "         'deslartab': 'DESC ITEM 15' " +
                                   "}]" +
                                "}" +
                            "}"

        Context.Response.Write(js.Serialize(d))
    End Sub


Código javascript:

function cargarChoiceList(vNombreCombo, vCobnamtab)
{
jQuery.support.cors = true;

rndAux = '&random=' + Math.floor(Math.random()*9999999999);
jqxhr2 = jQuery.ajax({
 type:"GET",               
 data:{ cobnamtab: vCobnamtab,
filtro:"",
rnd: rndAux},  
 dataType:"json",
 url:"http://" + window.self.location.hostname + "/wsX/Parametros.asmx/ObtenerChoiceListItems2",
 beforeSend:function(){
  
 }
}).fail(function(jqXHR, textStatus){  
alert("Error: " + "Status: "+
 jqXHR.status +" detalle: "+ textStatus +
 " detalle: "+ jqXHR.responseText);
}).success(function(data){  
var v = getJSON(data); 
$("[name=" + vNombreCombo + "]").empty();
for (i=0; i<v.datos.items.length; i++)
{
$("[name=" + vNombreCombo + "]").append($('<option>', { 
value: v.datos.items[i]["coddestab"],
text : v.datos.items[i]["deslartab"]
}));
}
});  
}

function getJSON(data_obj)
{
   if (data_obj.d)
      data_ok = data_obj.d;
   else
      data_ok = data_obj;

   evalJson = eval("var varJSON = " + data_ok + ";"); 

   return varJSON;  
}


Ejemplo de llamado:

cargarChoiceList('WFF-SINO3', 'BANCOS');


Thermistor NTC3950 de 100K con Arduino






Codigo:

#include <math.h>

double Thermistor(int RawADC) {
 double Temp;
 Temp = log(10000.0*((1024.0/RawADC-1)));
 Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp );
 Temp = Temp - 273.15;        
 Temp = (Temp * 9.0)/ 5.0 + 32.0;
 return Temp;
}

void setup() {
 Serial.begin(9600);
}

void loop() {            
  int val;              
  double tempFahrenheith;          
  val=analogRead(2);    
 
  tempFahrenheith=Thermistor(val);

  double tempCelcius = (tempFahrenheith - 32) * 5/9;
 
  Serial.print("Temperature = ");
  Serial.print(tempCelcius);  
  Serial.println(" C");
  delay(1000);          
}



Breakpoint aparece en amarillo y muestra el error "No se pueden cargar los simbolos"

Primero ejecutar la aplicacion.

Luego ir a Debug / Windows / Modules

elegir el assembly que corresponda al sitio (ej, RetWeb.dll)
Click derecho, y seleccionar "Symbol Load Information"


Start debugging, as soon as you've arrived at a breakpoint or used Debug > Break All, use Debug > Windows > Modules. You'll see a list of all the assemblies that are loaded into the process. Locate the one you want to get debug info for. Right-click it and select Symbol Load Information. You'll get a dialog that lists all the directories where it looked for the .pdb file for the assembly. Verify that list against the actual .pdb location. Make sure it doesn't find an old one.
In normal projects, the assembly and its .pdb file should always have been copied by the IDE into the same folder as your .exe. The bin\Debug folder of your project. Make sure you remove one from the GAC if you've been playing with it

Exportar datos a un archivo de texto con MySql

*** Tener en cuenta que el archivo se genera en el servidor de MySql ***

SELECT *
INTO OUTFILE '/mantis/out.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
ESCAPED BY '\\'
LINES TERMINATED BY '\n'
FROM mantis_custom_field_string_table