miércoles, 3 de diciembre de 2014

Clase Ejemplo de Conexión a SQLite en C#


Clase Ejemplo de Conexión a SQLite en C#
 
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
// Clase Base de Datos SQLite                                                    //
// Version 1.0.0                                                                 //
// Freddy de Jesus Perez T. 27 Noviembre 2014                                    //
// 
freperez98@gmail.com  Twitter. freperez98                                     //
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SQLite;
using System.Data;

 
namespace Camila_
{
    public class cBaseDatosSQLite
    {
        private SQLiteConnection vConexion_;
        bool hayConexion_ = false;
        private String vNomBaseDeDatos_ = "BDCamila.sqlite";
        private String vVersion_ = "Version=3";

        public void inicializar()
        {
            //crearBaseDatosSQLite();
            conectarSQLite();
            crearOActualizarTablas();
        }

        public bool crearOActualizarTablas()
        {
            if (!hayConexion_) return false;
            String vsql;
            if (!tablaExiste("camila_tipoDocumento"))
            {
                vsql = " CREATE TABLE camila_tipoDocumento ( ";
                vsql += "id_tipo     INTEGER   PRIMARY KEY AUTOINCREMENT, ";
                vsql += "tipo        INT,";
                vsql += "descripcion CHAR( 20 ) ";
                vsql += ");";

                ejecutarQuery(vsql);
                vsql = " INSERT INTO camila_tipoDocumento (tipo,descripcion) VALUES ('09','Presupuestos');";
                ejecutarQuery(vsql);
                vsql = " INSERT INTO camila_tipoDocumento (tipo,descripcion) VALUES ('10','Pedidos');";
                ejecutarQuery(vsql);
                vsql = " INSERT INTO camila_tipoDocumento (tipo,descripcion) VALUES ('11','Nota de Credito');";
                ejecutarQuery(vsql);
                vsql = " INSERT INTO camila_tipoDocumento (tipo,descripcion) VALUES ('12','Facturas');";
                ejecutarQuery(vsql);
                vsql = " INSERT INTO camila_tipoDocumento (tipo,descripcion) VALUES ('13','Nota de Entrega');";
                ejecutarQuery(vsql);
                vsql = " INSERT INTO camila_tipoDocumento (tipo,descripcion) VALUES ('14','Apartados');";
                ejecutarQuery(vsql);
            }

            if (!tablaExiste("camila_a2Sistemas"))
            {
                vsql = " CREATE TABLE camila_a2Sistemas ( ";
                vsql += "id_sistema          INTEGER   PRIMARY KEY  UNIQUE, ";
                vsql += "descripcion CHAR( 20 ), ";
                vsql += "sta_sistema BOOLEAN ";
                vsql += ");";
                ejecutarQuery(vsql);

                 vsql = " INSERT INTO camila_a2Sistemas (id_sistema,descripcion,sta_sistema) VALUES (1,'a2Softway',1);";
                ejecutarQuery(vsql);
                vsql = " INSERT INTO camila_a2Sistemas (id_sistema,descripcion,sta_sistema) VALUES (2,'a2Nomina',1);";
                ejecutarQuery(vsql);
                vsql = " INSERT INTO camila_a2Sistemas (id_sistema,descripcion,sta_sistema) VALUES (3,'a2Contabilidad',1);";
                ejecutarQuery(vsql);
            }
            if (!tablaExiste("camila_a2SistemasTablas"))
            {
                vsql = " CREATE TABLE camila_a2SistemasTablas ( ";
                vsql += "id_tabla  INTEGER   PRIMARY KEY  UNIQUE, ";
                vsql += "id_sistema CHAR( 20 ),";
                vsql += "descripcion CHAR( 20 ),";
                vsql += "sta_tabla BOOLEAN ";
                vsql += ");";
                ejecutarQuery(vsql);
                vsql = " INSERT INTO camila_a2SistemasTablas (id_tabla,id_sistema,descripcion,sta_tabla) VALUES (1,1,'soperacioninv',1);";
                ejecutarQuery(vsql);
                vsql = " INSERT INTO camila_a2SistemasTablas (id_tabla,id_sistema,descripcion,sta_tabla) VALUES (2,1,'sdetalleventa',1);";
                ejecutarQuery(vsql);
            }
            return true;
        }

        public bool tablaExiste( String tableName)
        {
            if (!hayConexion_) return false;
            DataSet myDataSet = null;
            String vsql="";
            String vCuantos = "0";
            if (tableName == null)
            {
                return false;
            }

            vsql = "SELECT COUNT(*) as Cuantos FROM sqlite_master WHERE type = 'table' AND name = '" + tableName + "'";
            myDataSet = ejecutarQuerySinTranDataSet(vsql);
            foreach (DataRow renglon in myDataSet.Tables[0].Rows)
            {
                vCuantos = renglon["Cuantos"].ToString();
                break;
            }
            if (vCuantos != "0") { return true; }
            return false;
        }

        public SQLiteConnection obtenerconexionBD()
        {
            return vConexion_;
        }

        public void asignarConexion(SQLiteConnection pConexion)
        {
            vConexion_ = pConexion;
        }

        public int ejecutarQuery(string psql)
        {
            if (!hayConexion_) return 0;
            SQLiteCommand command = null;
            int cuantos = 0;
            try
            {
                command = new SQLiteCommand(psql, vConexion_);
                cuantos = command.ExecuteNonQuery();
            }
            catch (SQLiteException ex)
            {
                System.Windows.Forms.MessageBox.Show(psql + ex.Message, "Base De Datos");
                return cuantos;
            }
            catch (System.InvalidOperationException ex)
            {
                System.Windows.Forms.MessageBox.Show(psql + ex.Message, "Base De Datos");
                return cuantos;
            }
            catch (NullReferenceException ex)
            {
                System.Windows.Forms.MessageBox.Show(psql + ex.Message, "Base De Datos");
                return cuantos;
            }
            return cuantos;
        }

        public DataSet ejecutarQuerySinTranDataSet(string psql)
        {
            DataSet myDataSet= new DataSet();
            try
            {
                var da = new SQLiteDataAdapter(psql, vConexion_);
                da.Fill(myDataSet);
            }
            catch (ArgumentNullException ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message, "Base De Datos");
            }
            catch (InvalidOperationException ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message, "Base De Datos");
            }
            catch (NullReferenceException ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message, "Base De Datos");
            }
            return myDataSet;
        }

        public bool crearBaseDatosSQLite()
        {
            try
            {
               SQLiteConnection.CreateFile(vNomBaseDeDatos_);
                return true;
            }
            catch (System.InvalidOperationException ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message, "Base De Datos");
                return false;
            }
            catch (ArgumentException ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message, "Base De Datos");
                return false;
            }
        }

        public bool conectarSQLite()
        {
            hayConexion_ = false;
            try
            {
                vConexion_ = new SQLiteConnection("Data Source="+vNomBaseDeDatos_+";"+vVersion_+";");
                vConexion_.Open();
                hayConexion_ = true;
                return true;
            }
            catch (System.InvalidOperationException ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message, "Base De Datos");
                return false;
            }
            catch (ArgumentException ex)
            {
               System.Windows.Forms.MessageBox.Show(ex.Message, "Base De Datos");
                return false;
            }
        }

        public void desconectar()        {
            if (hayConexion_)
            {
                hayConexion_ = false;
                vConexion_.Close();
                vConexion_.Dispose();
            }
        }
    }
}

Freddy Perez Computacion y Sistemas freperez98@gmail.com 0426-530.95.11 Aragua Venezuela

viernes, 22 de agosto de 2014

Cuicas, Trujillo. De dónde eres?


Cuicas, Trujillo.


De dónde eres?

 
Mi respuesta fue

De un pueblito (y) que tal vez  ni lo conozcas

Un Pueblito?:/ =DJajajajajajaj


 

Si de un pueblito y Sabes una vaina CON ORGULLO! Soy del pueblo... Donde todo el mundo te saluda  y te pregunta… cómo estás? ; Tanto tiempo sin vernos! ; Eres  el hijo de…? ; Con tu papá fuimos a la escuela! ; Con tu mamá salíamos a bailar.Soy de un pueblo donde no hay nada, pero lo tiene todo. Un pueblo donde hay gente que cuando uno necesita del otro, siempre estamos para ayudarnos. Soy de un pueblo donde indicamos las direcciones diciendo: al lado de… al frente de… a la vuelta de.... Soy de un pueblo donde poseemos riqueza natural Donde cualquier excusa es sinónimo de fiesta : ni pa una*beer, donde todos queremos estudiar  y prepararnos, donde siempre el que está por fuera , añora regresar , y en el mes  de diciembre  la alegría aumenta, ya que  volvemos a sentarnos en la esquina con los amigos de toda la vida, cada diciembre es el premio al esfuerzo de todo el año, SOY DE UN Pueblo llamado CUICAS edo TRUJILLO, Somos parranderos*beer, buenos amigos. q viva mi pueblo hermoso, que viva mi gente bella CUIQUENSE, de allí vengo yo orgullosamente (y)si estas orgulloso de tu pueblo pasa la cadena sin pena de decir de donde eres! Yo Soy CUIQUENSE

 

Freddy Perez Computacion y Sistemas freperez98@gmail.com 0426-530.95.11 Aragua Venezuela

ODBC NO SE VE. MAPEANDO COMO UNIDAD DE RED

ODBC NO SE VE. MAPEANDO COMO UNIDAD DE RED Para configurar el  EnableLinkedConnections  valor de registro: Haga clic en Inicio, escriba rege...