sábado, 21 de septiembre de 2019

 

CONVERTIR DE NÚMEROS A LETRAS EN C# VISUAL ESTUDIO 2019

Hola gente programador@ como están espero que bien.bueno yo aquí publicando nuevos artículos de programación espero que sea de su ayuda.

En este post realizaremos a como convertir de números a letras.

--Primero diseñamos nuestro form en visual estudio 20222















--programación

primeramente crea la clase convertir .
copia y pega el codigo a tu clase creada anteriormente.

class Convertir 
    { 
        public string enletras(string num) 
        { 
            string res, dec = ""; 
            Int64 entero; 
            int decimales; 
            double nro; 
  
            try 
            { 
                nro = Convert.ToDouble(num); 
            } 
            catch 


            { 
                return ""; 
            } 
  
            entero = Convert.ToInt64(Math.Truncate(nro)); 
            decimales = Convert.ToInt32(Math.Round((nro - entero) * 100, 2)); 
            if (decimales > 0) 
            { 
                dec = " CON " + decimales.ToString() + "/100"; 
            } 
  
            res = toText(Convert.ToDouble(entero)) + dec; 
            return res; 
        } 
  
        private string toText(double value) 
        { 
            string Num2Text = ""; 
            value = Math.Truncate(value); 
            if (value == 0) Num2Text = "CERO"; 
            else if (value == 1) Num2Text = "UNO"; 
            else if (value == 2) Num2Text = "DOS"; 
            else if (value == 3) Num2Text = "TRES"; 
            else if (value == 4) Num2Text = "CUATRO"; 
            else if (value == 5) Num2Text = "CINCO"; 
            else if (value == 6) Num2Text = "SEIS"; 
            else if (value == 7) Num2Text = "SIETE"; 
            else if (value == 8) Num2Text = "OCHO"; 
            else if (value == 9) Num2Text = "NUEVE"; 
            else if (value == 10) Num2Text = "DIEZ"; 
            else if (value == 11) Num2Text = "ONCE"; 
            else if (value == 12) Num2Text = "DOCE"; 
            else if (value == 13) Num2Text = "TRECE"; 
            else if (value == 14) Num2Text = "CATORCE"; 
            else if (value == 15) Num2Text = "QUINCE"; 
            else if (value < 20) Num2Text = "DIECI" + toText(value - 10); 
            else if (value == 20) Num2Text = "VEINTE"; 
            else if (value < 30) Num2Text = "VEINTI" + toText(value - 20); 
            else if (value == 30) Num2Text = "TREINTA"; 
            else if (value == 40) Num2Text = "CUARENTA"; 
            else if (value == 50) Num2Text = "CINCUENTA"; 
            else if (value == 60) Num2Text = "SESENTA"; 
            else if (value == 70) Num2Text = "SETENTA"; 
            else if (value == 80) Num2Text = "OCHENTA"; 
            else if (value == 90) Num2Text = "NOVENTA"; 
            else if (value < 100) Num2Text = toText(Math.Truncate(value / 10) * 10) + " Y " + toText(value % 10); 
            else if (value == 100) Num2Text = "CIEN"; 
            else if (value < 200) Num2Text = "CIENTO " + toText(value - 100); 
            else if ((value == 200) || (value == 300) || (value == 400) || (value == 600) || (value == 800)) Num2Text = toText(Math.Truncate(value / 100)) + "CIENTOS"; 
            else if (value == 500) Num2Text = "QUINIENTOS"; 
            else if (value == 700) Num2Text = "SETECIENTOS"; 
            else if (value == 900) Num2Text = "NOVECIENTOS"; 
            else if (value < 1000) Num2Text = toText(Math.Truncate(value / 100) * 100) + " " + toText(value % 100); 
            else if (value == 1000) Num2Text = "MIL"; 
            else if (value < 2000) Num2Text = "MIL " + toText(value % 1000); 
            else if (value < 1000000) 
            { 
                Num2Text = toText(Math.Truncate(value / 1000)) + " MIL"; 
                if ((value % 1000) > 0) Num2Text = Num2Text + " " + toText(value % 1000); 
            } 
  
            else if (value == 1000000) Num2Text = "UN MILLON"; 
            else if (value < 2000000) Num2Text = "UN MILLON " + toText(value % 1000000); 
            else if (value < 1000000000000) 
            { 
                Num2Text = toText(Math.Truncate(value / 1000000)) + " MILLONES "; 
                if ((value - Math.Truncate(value / 1000000) * 1000000) > 0) Num2Text = Num2Text + " " + toText(value - Math.Truncate(value / 1000000) * 1000000); 
            } 
  
            else if (value == 1000000000000) Num2Text = "UN BILLON"; 
            else if (value < 2000000000000) Num2Text = "UN BILLON " + toText(value - Math.Truncate(value / 1000000000000) * 1000000000000); 
  
            else 
            { 
                Num2Text = toText(Math.Truncate(value / 1000000000000)) + " BILLONES"; 
                if ((value - Math.Truncate(value / 1000000000000) * 1000000000000) > 0) Num2Text = Num2Text + " " + toText(value - Math.Truncate(value / 1000000000000) * 1000000000000); 
            } 
            return Num2Text; 
  
        } 
  
    } 


--ahora utilizaremos la clase convertir.

// llamar la clase.. modo publico
Convertir con = new Convertir();

codigo para button convertir

 private void Button1_Click(object sender, EventArgs e)
        {
            txtresultado.Text = con.enletras(txtnumero.Text).ToUpper();
        }

eso seria todo .espero haberlo ayudado..

link del proyecto COMPLETO .en github

Share:

sábado, 31 de agosto de 2019

 

como hacer un crud en php y mysql y bootstrap 4 (Leer Agregar Actualizar Eliminar) 2021

Hola amigos como estamos me imagino que bien.Bueno en este post les estare compartiendo a como hacer un crud en php y mysql .
pueden descargar el proyecto totalmente gratis























Primero crearemos nuestro bd.en mysql





-- Volcando estructura de base de datos para crudalumno

CREATE DATABASE IF NOT EXISTS `crudalumno` /*!40100 DEFAULT CHARACTER SET latin1 */;

USE `crudalumno`;



-- Volcando estructura para tabla crudalumno.alumnos

CREATE TABLE IF NOT EXISTS `alumnos` (

`Id` int(11) NOT NULL AUTO_INCREMENT,

`Nombres` varchar(50) NOT NULL,

`Direccion` varchar(50) NOT NULL,

PRIMARY KEY (`Id`)

) ENGINE=InnoDB AUTO_INCREMENT=22 DEFAULT CHARSET=latin1;



-- Volcando datos para la tabla crudalumno.alumnos: ~3 rows (aproximadamente)

DELETE FROM `alumnos`;

/*!40000 ALTER TABLE `alumnos` DISABLE KEYS */;

INSERT INTO `alumnos` (`Id`, `Nombres`, `Direccion`) VALUES

    (18, 'Cristian rojas', 'lima'),

    (20, 'cristian ', 'puente piedra'),

    (21, 'Yesenia Chavez', 'los olivos');


Para poder conectarse cambiar la cadena de conecion en(conexion.php)

<?php
$link = 'mysql:host=localhost;dbname=crudalumno';
$usuario ='root';
$contraseña= '';
$bd= 'crudalumno';
try {
$pdo = new PDO($link, $usuario, $contraseña);
//echo('conectado');
} catch (PDOException $e) {
print "¡Error!: " . $e->getMessage() . "<br/>";
die();
}

Click aqui para poder descargar proyecto completo

Descargar aqui

Share:

domingo, 19 de mayo de 2019

 

Leer archivo de texto json y mostrar en datagridview visual estudio 2022

Hola gente como están espero que bien. Bueno esta vez vengo con un aporte de como leer un archivo json de datos y mostrarlo en control Datagridview.


Primeramente creamos nuestro archivo json. y guardar con el nombre datos.json

[
  {
    "Nombre": "cristian Patricio izquierdo",
    "Direcion": "Lima -peru",
    "web": "cpiprodesign.com"

  },
  {
    "Nombre": "Diana",
    "Direcion": "Lima -peru",
    "web": "cpiprodesign.com"

  },
  {
    "Nombre": "Yesenia",
    "Direcion": "Lima -peru",
    "web": "cpiprodesign.com"

  },
  {
    "Nombre": "Yesenia",
    "Direcion": "Lima -peru",
    "web": "cpiprodesign.com"

  },
  {
    "Nombre": "Yesenia",
    "Direcion": "Lima -peru",
    "web": "cpiprodesign.com"

  },
  {
    "Nombre": "Yesenia",
    "Direcion": "Lima -peru",
    "web": "cpiprodesign.com"

  }
]

Diseñamos nuestro formulario




Vamos a programarlo.
primeramente agregar el paquete Newtonsoft.Json. desde  administardor de paquetes nuget.

codigo c#

//importamos las librerias a utilizar
using System;
using System.Data;
using System.Windows.Forms;
using Newtonsoft.Json;
using System.IO;

codigo para button leerJson

private void button1_Click(object sender, EventArgs e)
  {
     string fileJSON = File.ReadAllText(@"E:\JSON\datos.json");
     DataTable dt = (DataTable)JsonConvert.DeserializeObject(fileJSON, typeof(DataTable));
     this.dataGridView1.DataSource = dt;

  }

Link de proyecto -> aqui

bueno eso seria todo espero haber ayudado en algo..gracias
comenta y sugiere en los comentarios.



Share: