Archive for the ‘CSharp’ Category
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
Tags: C#, CSharp
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()
{
Tags: C#, CSharp
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.
Tags: C#, CSharp
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
{
Tags: C#, CSharp
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.
Tags: C#, CSharp
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:
Tags: C#, CSharp
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.
Tags: C#, CSharp
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
Tags: C#, CSharp
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: C#, CSharp
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
Tags: C#, CSharp
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: C#, CSharp
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: C#, CSharp
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: C#, CSharp
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.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);
Tags: C#, CSharp, WindowsCE
Posted in CSharp, WindowsCE | 2 Comments »
CSharp - Incrementar número hexadecimal
Written by lopezatienza on 29 Octubre 2008 – 16:47 -
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++;
}
Tags: C#, CSharp
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: C#, CSharp
Posted in CSharp | No Comments »
CSharp - Diferencia de Fechas
Written by lopezatienza on 29 Octubre 2008 – 16:44 -Este ejemplo devolverá el total de segundos que hay de diferencia entre dos fechas:
DateTime inicio = DateTime.Now;
// EJECUCIÓN de un proceso
DateTime final = DateTime.Now;
TimeSpan duracion = final - inicio;
double segundosTotales = duracion.TotalSeconds; // Calcula la diferencia en segundos, por ejemplo si ha pasado 1:30 contará 90 segundos
int segundos = duracion.Seconds; // Este es un error frecuente, ya que si ha pasado 1:30 segundos no contaría 90, sino 30
Posted in CSharp | No Comments »
CSharp - Formato de Fechas
Written by lopezatienza on 29 Octubre 2008 – 16:42 -// Format : 07 / 03 / 2004
formattedDate = DateTime.Now.ToString("dd / MM / yyyy");
// Format : 7 / 3 / 2004 (without the preceding zeroes)
formattedDate = DateTime.Now.ToString("d / M / yyyy");
// Format : 07 / Mar / 2004
formattedDate = DateTime.Now.ToString("dd / MMM / yy");
// How to get the name of the day ?
// Format : Wednesday
formattedDate = DateTime.Today.DayOfWeek.ToString();
Posted in CSharp | No Comments »
CSharp - Escribir en un fichero sin borrar lo existente
Written by lopezatienza on 29 Octubre 2008 – 16:37 -System.IO.FileStream FS;
System.IO.StreamWriter SW;
string Fichero = Application.StartupPath + @"\Fichero.txt";
FS = new System.IO.FileStream(Fichero, System.IO.FileMode.Append, System.IO.FileAccess.Write);
SW = new System.IO.StreamWriter(FS);
SW.WriteLine("Texto que deseamos introducir");
SW.Close();
Posted in CSharp | No Comments »
CSharp - Leer archivos
Written by lopezatienza on 29 Octubre 2008 – 16:32 -using System;
using System.IO;
class LeerArchivo {
publicstaticvoid Main()
{
Tags: C#, CSharp
Posted in CSharp | No Comments »
