miércoles, 3 de diciembre de 2014

Operaciones con DateTime en c#


Fecha Desde Hasta
Mes Actual
Ultimos 30 Dias
Anterior a 30 Dias

private void cmbOtros_SelectedIndexChanged(object sender, EventArgs e)
        {
            DateTime vfechatemp;
            DateTime vfecha1;
            DateTime vfecha2;

            vfechatemp = DateTime.Today;
            if (cmbOtros.Text.Trim() == "Mes Actual")
            {
                vfecha1 = new DateTime(vfechatemp.Year, vfechatemp.Month, 1);
                if (vfechatemp.Month == 12)
                {
                    vfecha2 = new DateTime(vfechatemp.AddYears(1).Year, vfechatemp.AddMonths(1).Month, 1).AddDays(-1);
                }
                else {
                    vfecha2 = new DateTime(vfechatemp.Year, vfechatemp.AddMonths(1).Month, 1).AddDays(-1);
                }
                dateFechaDesde.Value = vfecha1;
                dateFechaHasta.Value = vfecha2;
            } else
                if (cmbOtros.Text.Trim() == "Ultimos 30 Dias")
                {
                    vfecha1 = new DateTime(vfechatemp.Year, vfechatemp.AddMonths(-1).Month, vfechatemp.Day);
                    dateFechaDesde.Value = vfecha1;
                    dateFechaHasta.Value = vfechatemp;
                }
            if (cmbOtros.Text.Trim() == "Anterior a 30 Dias")
            {
                vfecha2 = new DateTime(vfechatemp.Year, vfechatemp.AddMonths(-1).Month, vfechatemp.Day);
                vfecha1 = new DateTime(vfecha2.AddYears(-1).Year, vfecha2.Month, 1);
                dateFechaDesde.Value = vfecha1;
                dateFechaHasta.Value = vfecha2;
            }
        }

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

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

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...