/*JULIO CESAR LEYVA RODRIGUEZ 

 * 15 DE JUNIO DE 2013

 */

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Data.SQLite;

 

 

namespace Prueba

{

    

    //HACEMOS LA CLASE PARA LA CONEXION

    class conexion

    {

        

        /* HACEMOS LAS VARIABLES DE CONEXION, SE NECESITARAN INSTALAR Y AGREGAR LAS LIBRERIAS DE

         * SQLITE http://www.sqlite.org/download.html

         */

        public SQLiteConnection sqlCon;

        public SQLiteCommand sqlCmd;

 

        public conexion()

        {

            //ESTABLECEMOS LA DIRECCION DEL ARCHIVO DE LA BASE DE DATOS Y ABRIMOS CONEXION

            sqlCon = new SQLiteConnection("Data Source=|DataDirectory|compras.s3db;");

            sqlCon.Open();

        }

        

        //FUNCION PARA CERRAR LA CONEXION

        public void cerrarConexion()

        {

            sqlCon.Close();

        }

 

        //EJECUTA LA CONSULTA QUE SE LE MANDA COMO PARAMETRO

        public void ejecutar(string sql)

        {

            sqlCmd = new SQLiteCommand(sql, sqlCon);

            sqlCmd.ExecuteNonQuery();

        }

 

       

        //FUNCION DE PRUEBA QUE SIRVE DE ACCESO A UN USUARIO

        public bool acceso(string usuario, string cont)

        {

            string  sql = "select * from usuarios where usuario='" + usuario + "' and contra='" + cont + "'";

            sqlCmd = new SQLiteCommand(sql, sqlCon);

            sqlCmd.ExecuteNonQuery();

            bool chekar  = sqlCmd.ExecuteReader().HasRows;

            return chekar;

        }

 

    }

 

}