CSharp - Clase de conversiones de tipos

Written by lopezatienza on 17 Febrero 2010 – 23:10 -

Buenas a todos.

Aquí os dejo una clase abstracta para realizar conversiones de tipos.

Las conversiones que puede realizar son las siguientes:

  • String to Bool
  • Object to Bool
  • Object to DateTime
  • String to Int
  • Object to Int
  • Decimal to String
  • Object to String

Read more »


Tags: ,
Posted in CSharp | No Comments »

CSharp - Leer un fichero

Written by lopezatienza on 13 Diciembre 2009 – 23:17 -

Aquí os dejo el código en C# para poder leer desde un fichero:


using System;

using System.IO;

 

class Test

{

    public static void Main()

    {

Read more »


Tags: ,
Posted in CSharp | No Comments »

CSharp - Clase Fichero (Tratamiento de ficheros)

Written by lopezatienza on 13 Diciembre 2009 – 23:01 -

Aquí os dejo una clase de tratamiento de ficheros con las siguientes opciones entre otras:

  • Apertura de ficheros.
  • Cerrar ficheros.
  • Lectura de ficheros.
  • Escritura de ficheros.
  • Existencia de ficheros.
  • Borrar ficheros.
  • Búsqueda de palabras en ficheros.
  • Búsqueda dicotómica.

Read more »


Tags: ,
Posted in CSharp | No Comments »

CSharp - Clase Convertir objetos en tipos de datos

Written by lopezatienza on 13 Diciembre 2009 – 22:38 -

Aquí os dejo una clase para convertir objetos en tipos de datos, evitando las excepciones producidas por la conversión de datos en tipos de datos no compatibles.

using System;

using System.Windows.Forms;

using System.Collections.Generic;

using System.Text;

 

public abstract class Convertir

{

  Read more »


Tags: ,
Posted in CSharp | 2 Comments »

CSharp - DataGridView + Select A Row + ContextMenuStrip

Written by lopezatienza on 8 Junio 2009 – 12:43 -

Aqui os dejo un ejemplo de cómo seleccionar una fila de un control DataGridView pulsando el botón derecho para que aparezca el ContextMenu.

Si de normal pulsaramos con el botón derecho encima de la fila que deseemos y seleccionamos del ContextMenu cualquier opción, en la siguiente función saltaría una excepción ya que intentamos acceder a la propiedad "dgPrueba.SelectedRows[0].Index", puesto que con el botón derecho NO se selecciona la Row.

En este ejemplo tenemos en nuestro formulario un DataGridView llamado dgPrueba y un ContextMenu llamado menuPRUEBA.

De un primer momento tendremos asociados el dgPrueba con el ContextMenu, que sería lo más normal, en la Solución veremos cómo no se precisa.

Read more »


Tags: ,
Posted in CSharp | No Comments »

CSharp - ListView Eventos, Funciones y otros

Written by lopezatienza on 18 Marzo 2009 – 10:46 -

Voy a ir añadiendo en esta entrada funcionalidad de este componente cuando vaya investigandolo a fondo.

De momento decir que este componente proviene de System.Windows.Forms.ListView

La creación de este en el Designer sería algo así con 3 columnas:

Read more »


Tags: ,
Posted in CSharp | No Comments »

CSharp - Añadir estilo CSS a un DataGrid

Written by lopezatienza on 8 Marzo 2009 – 21:00 -

He encontrado este interesante artículo en este link:

http://www.codeproject.com/KB/webforms/cssgrid.aspx

Introduction

It can be frustrating trying to apply CSS styles to .NET data grids - attempting to blindly apply styles does not usually work as expected, because of the way that the DataGrid is rendered to the browser. This article introduces some simple techniques to help get you started.

But first, why use styles at all? You could use the autoformat feature in Visual Studio .NET, but what happens when the "UI expert consultant" that your boss hired insists on extra spacing between the rows? You'll have to go to every grid on your project, and edit it. Using styles lets you control the appearance of all of your grids from a single place.

Read more »


Tags: ,
Posted in CSharp, Visual Basic .NET | 2 Comments »

CSharp - 101 Ejemplos en CSharp

Written by lopezatienza on 26 Enero 2009 – 16:01 -


Microsoft ha puesto a disposición de todos los programadores de 101 Ejemplos de Programación en C#.


Estas descargas incluyen una compilación de ejemplos C# que demuestran varios aspectos importantes del lenguaje como: sintaxis, acceso a datos, Windows Forms, desarrollo web, servicios web, XML, seguridad, Framework, sistemas de archivos, entrada y salida de datos, interoperabilidad y migración, COM+, ADO.NET, y tópicos avanzados incluyendo gráficos con GDI+, remoting, serialización, MSMQ, y servicios Windows.


Sistemas operativos: TabletPC, Windows 2000, Windows 2000 Service Pack 2, Windows 2000 Service Pack 3, Windows 2000 Service Pack 4, Windows 98, Windows 98 Second Edition, Windows ME, Windows NT, Windows Server 2003, Windows XP, Windows XP Media Center Edition


Aplicaciones para clientes con Visual Studio .NET 2003


Nota: Algunos ejemplos requieren acceso a la base de datos Northwind en SQL Server o Microsoft Data Engine.


Descarga de archivo

http://download.microsoft.com/download/6/4/7/6474467e-b2b7-40ea-a478-1d3296e78adf/CSharp.msi (tamaño 6.578MB)


Más información en

http://www.microsoft.com/downloads/details.aspx?FamilyID=08e3d5f8-033d-420b-a3b1-3074505c03f3&DisplayLang=en


Tags: ,
Posted in CSharp | No Comments »

CSharp - DataGrid with DataSet

Written by lopezatienza on 26 Diciembre 2008 – 9:52 -


Aquí os dejo un ejemplo de enlazar un DataGrid con DataSet.

Este ejemplo lo he tomado de: aquí

This is a simple C# Program that illustrate the usage of DataGrid with DataSet.

Create Database and Table accordingly.

/*
 * Simple C# example to illustrate the usage of Dataset with DataGrid
 * Need to change the url and query accordingly
*/
 
Read more »


Tags: ,
Posted in CSharp | 2 Comments »

CSharp - Clase FTP

Written by lopezatienza on 22 Diciembre 2008 – 17:23 -


Aquí os dejo una clase FTP:

 

 

using System;

using System.Net;

using System.IO;

using System.Text;

using System.Net.Sockets;

using System.Diagnostics;

 

namespace FtpService

{ Read more »


Tags: ,
Posted in CSharp | 2 Comments »

CSharp - Clase Ping

Written by lopezatienza on 22 Diciembre 2008 – 17:19 -

Aquí os dejo una clase Ping para hacer comprabaciones de Ping TCP/IP

using System;

using System.Drawing;

using System.Collections;

using System.Windows.Forms;

using System.Net;

using System.Net.Sockets;

using System.Runtime.InteropServices;

using System.Text; 

namespace NombreDelNamespace Read more »


Tags: ,
Posted in CSharp | No Comments »

CSharp - Comunicacion PPC ActiveSync con openNETCF

Written by lopezatienza on 18 Diciembre 2008 – 13:06 -

A continuación muestro el código de un ejemplo de Comunicación con un PPC mediante ActiveSync con openNETCF

using System;

using System.Drawing;

using System.Collections;

using System.ComponentModel;

using System.Windows.Forms; Read more »


Tags: ,
Posted in CSharp | 3 Comments »

CSharp - Enviar un Correo en C#

Written by lopezatienza on 12 Noviembre 2008 – 16:59 -

System.Net.Mail.MailMessage correo = new System.Net.Mail.MailMessage();

System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient();

try

{

correo.From = new System.Net.Mail.MailAddress("direccion de correo origen");

correo.To.Add("direccion correo destino (para poner varios hay que ponerlos separados por comas)");

Read more »


Tags: ,
Posted in CSharp | No Comments »

CSharp - Conexion Dial-up en C#

Written by lopezatienza on 12 Noviembre 2008 – 11:30 -

Primeramente crearemos una clase llamada RAS con el siguiente código:

using System;

using System.Runtime.InteropServices;

 ///

/// Descripción breve de RAS.

///

// Clase comunicaciones REMOTAS

 public class RAS

{

    [DllImport("coredll.dll", CharSet = CharSet.Unicode)]

    private static extern int RasDial(int dialExtensions, int phoneBookPath, IntPtr rasDialParam, int NotifierType, int notifier, ref int hRasConn);

 

    [DllImport("coredll.dll", CharSet = CharSet.Unicode)]

    private static extern int RasHangUp(int hRasConn);

  Read more »


Tags: , ,
Posted in CSharp, WindowsCE | 2 Comments »

CSharp - Incrementar número hexadecimal

Written by lopezatienza on 29 Octubre 2008 – 16:47 -

Esta función te devuelve null si hay algún fallo.Si se le envía un String que está formado por valores numéricos devolverá 1 número mas de éste, incluído si es una letra de la A a la F, lo cual devolverá el valor siguiente.

       

public string IncrementarHexadecimal(string Numero)

        {

            try

            {

                int aux = Numero.Length;

                int i = 1;

                string Numero2 = "";

 

                while (Numero.Substring(aux - i, 1) == "F")

                {

                    Numero2 = "0" + Numero2;

                    i++;

                }

  Read more »


Tags: ,
Posted in CSharp | No Comments »

CSharp - Incrementar String como si fuera numerico

Written by lopezatienza on 29 Octubre 2008 – 16:46 -



Esta función te devuelve null si hay algún fallo, por ejemplo que se le pase una cadena con letras.Si se le envía un String que está formado por valores numéricos devolverá 1 número mas de éste.

public string Incrementar(string Numero)

        {

            try

            {

                int aux = Numero.Length;

                int i = 1;

                string Numero2 = "";

 

                while (Numero.Substring(aux - i, 1) == "9")

                {

                    Numero2 = "0" + Numero2;

                    i++;

                }

                Numero2 = Convert.ToString(Convert.ToInt32(Numero.Substring(aux - i, 1)) + 1) + Numero2;

                Numero2 = Numero.Substring(0, aux - i) + Numero2;

                return Numero2;

            }

            catch { return null; }

        }

Read more »


Tags: ,
Posted in CSharp | No Comments »

CSharp - Leer archivos

Written by lopezatienza on 29 Octubre 2008 – 16:32 -

Crearemos un proyecto Windows Form en CSharp llamado LeerArchivo:

using System;

 

using System.IO;

class LeerArchivo {

    publicstaticvoid Main()

    {

Read more »


Tags: ,
Posted in CSharp | No Comments »

CSharp - Pulsación de teclas

Written by lopezatienza on 28 Octubre 2008 – 15:02 -

Para controlar la pulsación de teclas, se debe manejar el evento KeyPress.
Para saber que tecla se ha pulsado se usará el e.KeyChar.
Para que la pulsación quede invalidada o se quiera realizar una serie de métodos, pondremos la propiedad Handled así:

e.Handled = true;

private void txtNumero_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar != '1' && e.KeyChar != '2' && e.KeyChar != '3' && e.KeyChar != '4' && e.KeyChar != '5' && e.KeyChar != '6' && e.KeyChar != '7' && e.KeyChar != '8' && e.KeyChar != '9' && e.KeyChar != '0')
{
e.Handled = true; 'La tecla quedaría invalidada si no es numérica
}
}


Tags: ,
Posted in CSharp | No Comments »

CSharp - Confirmation Dialog Box ejemplo (ok, cancel)

Written by lopezatienza on 28 Octubre 2008 – 13:45 -


private void button1_Click(object sender, System.EventArgs e)

{

if

 (MessageBox.Show("¿Esta seguro?", "Mensaje Ventana", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
   {

            // Aquí entraría si devuelve DialogResult.Yes
   }
}


Tags: ,
Posted in CSharp | No Comments »

Csharp - Convertir de tipo byte[] a string

Written by lopezatienza on 28 Octubre 2008 – 13:41 -

Para convertir de tipo Array de byte[] a string debemos utilizar la clase System.Text, ya que tanto la clase String como la función Convert.. no permiten cambiar el tipo:

System.Text.Encoding enc = System.Text.Encoding.ASCII; 'Creamos un tipo System.Text.Encoding para poder llamar a la función
string myString = enc.GetString(myByteArray);
'Creamos un tipo string que almacenará la cadena pasada a ASCII


Tags: ,
Posted in CSharp | No Comments »
RSS