Ejemplo n.º 1
0
        public static DPalabras PalabraRandom(String pPalabra, String pCategoria, String pRegion)
        {
            DPalabras palabra = new DPalabras();

            try
            {
                SqlCommand obtenerPalabraRandom = new SqlCommand("PalabraRandom", DConexion.ObtnerConexion());
                obtenerPalabraRandom.CommandType = CommandType.StoredProcedure;
                obtenerPalabraRandom.Parameters.Add("@palabra", SqlDbType.VarChar, 30).Value    = pPalabra;
                obtenerPalabraRandom.Parameters.Add("@categoria", SqlDbType.VarChar, 500).Value = pCategoria;
                obtenerPalabraRandom.Parameters.Add("@region", SqlDbType.VarChar, 300).Value    = pRegion;
                SqlDataReader rdr = obtenerPalabraRandom.ExecuteReader(CommandBehavior.CloseConnection);
                rdr.Read();
                palabra.Palabra    = rdr.GetString(0);
                palabra.Definicion = rdr.GetString(1);
                palabra.Imagen     = rdr.GetString(2);
                palabra.Seña       = rdr.GetString(3);
                palabra.Categoria  = rdr.GetString(4);
                palabra.Region     = rdr.GetString(5);
                return(palabra);
            }
            catch (Exception)
            {
                return(palabra);
            }
        }
Ejemplo n.º 2
0
        public static bool InsertarCategoria(String pCategoria)
        {
            SqlCommand sql = new SqlCommand("InsertCategorias", DConexion.ObtnerConexion());

            sql.CommandType = CommandType.StoredProcedure;
            sql.Parameters.Add("@Categoria", SqlDbType.VarChar, 20).Value = pCategoria;
            try
            {
                int r = sql.ExecuteNonQuery();
                sql.Connection.Close();
                return(r > 0);
            }
            catch (Exception)
            {
                sql.Connection.Close();
                return(false);
            }
        }
Ejemplo n.º 3
0
        public static bool DeleteRegion(String pRegion)
        {
            SqlCommand sql = new SqlCommand("DeleteRegiones", DConexion.ObtnerConexion());

            sql.CommandType = CommandType.StoredProcedure;
            sql.Parameters.Add("@Region", SqlDbType.VarChar, 20).Value = pRegion;
            try
            {
                int r = sql.ExecuteNonQuery();
                sql.Connection.Close();
                return(r > 0);
            }
            catch (Exception)
            {
                sql.Connection.Close();
                return(false);
            }
        }
Ejemplo n.º 4
0
        public static bool DeleteUsuario(int pId)
        {
            SqlCommand sql = new SqlCommand("DeleteUsuarios", DConexion.ObtnerConexion());

            sql.CommandType = CommandType.StoredProcedure;

            sql.Parameters.Add("@Id", SqlDbType.Int).Value = pId;

            try
            {
                int r = sql.ExecuteNonQuery();
                sql.Connection.Close();
                return(r > 0);
            }
            catch (Exception)
            {
                sql.Connection.Close();
                return(false);
            }
        }
Ejemplo n.º 5
0
        public static bool InsertarPalabra(String pPalabra, String pDefinicion, String pImagen, String pSeña, List <string> pRegion, List <string> pCategoria)
        {
            try
            {
                SqlCommand Insert = new SqlCommand("InsertPalabras", DConexion.ObtnerConexion());
                Insert.CommandType = CommandType.StoredProcedure;
                Insert.Parameters.Add("@Palabra", SqlDbType.VarChar, 30).Value     = pPalabra;
                Insert.Parameters.Add("@Definicion", SqlDbType.VarChar, 500).Value = pDefinicion;
                Insert.Parameters.Add("@imagen", SqlDbType.VarChar, 300).Value     = pImagen;
                int r = Insert.ExecuteNonQuery();
                Insert.Connection.Close();

                foreach (var item in pCategoria)
                {
                    SqlCommand RelCategoriaPalabra = new SqlCommand("InsertRelCategoriaPalabra", DConexion.ObtnerConexion());
                    RelCategoriaPalabra.CommandType = CommandType.StoredProcedure;
                    RelCategoriaPalabra.Parameters.Add("@Palabra", SqlDbType.VarChar, 20).Value   = pPalabra;
                    RelCategoriaPalabra.Parameters.Add("@categoria", SqlDbType.VarChar, 20).Value = item;

                    r = RelCategoriaPalabra.ExecuteNonQuery();
                    RelCategoriaPalabra.Connection.Close();
                }

                foreach (var item in pRegion)
                {
                    SqlCommand InsertSenia = new SqlCommand("InsertSenia", DConexion.ObtnerConexion());
                    InsertSenia.CommandType = CommandType.StoredProcedure;
                    InsertSenia.Parameters.Add("@Palabra", SqlDbType.VarChar, 20).Value = pPalabra;
                    InsertSenia.Parameters.Add("@Region", SqlDbType.VarChar, 20).Value  = item;
                    InsertSenia.Parameters.Add("@senia", SqlDbType.VarChar, 300).Value  = pSeña;
                    r = InsertSenia.ExecuteNonQuery();
                    InsertSenia.Connection.Close();
                }

                return(r > 0);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Ejemplo n.º 6
0
        public static List <DRegiones> ObtenerRegiones()
        {
            List <DRegiones> LRegiones = new List <DRegiones>();

            SqlConnection conexion = DConexion.ObtnerConexion();

            SqlCommand command = new SqlCommand("SelectRegiones", conexion);

            command.CommandType = System.Data.CommandType.StoredProcedure;
            SqlDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {
                DRegiones Region = new DRegiones();
                Region.Id     = Convert.ToInt32(reader["Id"].ToString());
                Region.Region = reader["Region"].ToString();
                LRegiones.Add(Region);
            }
            conexion.Close();
            return(LRegiones);
        }
Ejemplo n.º 7
0
        public static List <DCategorias> ObtenerCategorias()
        {
            List <DCategorias> LCategorias = new List <DCategorias>();

            SqlConnection conexion = DConexion.ObtnerConexion();

            SqlCommand command = new SqlCommand("SelectCategorias", conexion);

            command.CommandType = System.Data.CommandType.StoredProcedure;
            SqlDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {
                DCategorias Categoria = new DCategorias();
                Categoria.Id        = Convert.ToInt32(reader["Id"].ToString());
                Categoria.Categoria = reader["Categoria"].ToString();
                LCategorias.Add(Categoria);
            }
            conexion.Close();
            return(LCategorias);
        }
Ejemplo n.º 8
0
        public static bool InsertarUsuario(String pNombre, String pPassword, String pPerfil)
        {
            SqlCommand sql = new SqlCommand("InsertUsuarios", DConexion.ObtnerConexion());

            sql.CommandType = CommandType.StoredProcedure;

            sql.Parameters.Add("@Nombre", SqlDbType.VarChar, 20).Value   = pNombre;
            sql.Parameters.Add("@Password", SqlDbType.VarChar, 50).Value = pPassword;
            sql.Parameters.Add("@Perfil", SqlDbType.VarChar, 15).Value   = pPerfil;

            try
            {
                int r = sql.ExecuteNonQuery();
                sql.Connection.Close();
                return(r > 0);
            }
            catch (Exception)
            {
                sql.Connection.Close();
                return(false);
            }
        }
Ejemplo n.º 9
0
        public static List <DUsuarios> Usuarios()
        {
            List <DUsuarios> LUsuarios = new List <DUsuarios>();

            SqlConnection conexion = DConexion.ObtnerConexion();

            SqlCommand command = new SqlCommand("SelectUsuarios", conexion);

            command.CommandType = System.Data.CommandType.StoredProcedure;
            SqlDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {
                DUsuarios Usuario = new DUsuarios();
                Usuario.Id       = Convert.ToInt32(reader["Id"].ToString());
                Usuario.Nombre   = reader["Nombre"].ToString();
                Usuario.Password = reader["Password"].ToString();
                Usuario.Perfil   = reader["Perfil"].ToString();
                LUsuarios.Add(Usuario);
            }
            conexion.Close();
            return(LUsuarios);
        }
Ejemplo n.º 10
0
        public static DataTable BuscarCredenciales(string tipo_busqueda, string texto_busqueda,
                                                   out string rpta)
        {
            StringBuilder consulta = new StringBuilder();

            consulta.Append("SELECT * FROM Credenciales_empleado ");

            if (tipo_busqueda.Equals("ID EMPLEADO"))
            {
                consulta.Append("WHERE Id_empleado = @Texto_busqueda ");
            }

            consulta.Append("ORDER BY Fecha_modificacion DESC ");

            DataTable        DtResultado = new DataTable("Credenciales");
            SQLiteConnection SqlCon      = DConexion.Conex(out rpta);

            try
            {
                if (SqlCon == null)
                {
                    throw new Exception(rpta);
                }

                SqlCon.Open();
                SQLiteCommand SqlCmd = new SQLiteCommand
                {
                    Connection  = SqlCon,
                    CommandText = Convert.ToString(consulta),
                    CommandType = CommandType.Text
                };

                SQLiteParameter Texto_busqueda = new SQLiteParameter
                {
                    ParameterName = "@Texto_busqueda",
                    Size          = 50,
                    Value         = texto_busqueda.Trim().ToUpper()
                };
                SqlCmd.Parameters.Add(Texto_busqueda);

                SQLiteDataAdapter SqlData = new SQLiteDataAdapter(SqlCmd);
                SqlData.Fill(DtResultado);

                if (DtResultado.Rows.Count < 1)
                {
                    DtResultado = null;
                }
            }
            catch (SQLiteException ex)
            {
                rpta        = ex.Message;
                DtResultado = null;
            }
            catch (Exception ex)
            {
                rpta        = ex.Message;
                DtResultado = null;
            }
            finally
            {
                if (SqlCon.State == ConnectionState.Open)
                {
                    SqlCon.Close();
                }
            }

            return(DtResultado);
        }
Ejemplo n.º 11
0
        public static DataTable BuscarCarrerasPerdidas(string tipo_busqueda, string texto_busqueda,
                                                       out string rpta)
        {
            string comprobacion = Comprobaciones.ComprobacionTablaCarrerasPerdidas("Carreras_perdidas");

            if (!comprobacion.Equals("OK"))
            {
                rpta = comprobacion;
                return(null);
            }

            StringBuilder consulta = new StringBuilder();

            consulta.Append("SELECT * " +
                            "FROM Carreras_perdidas cp " +
                            "INNER JOIN Turnos tur ON cp.Id_turno = tur.Id_turno " +
                            "INNER JOIN Clientes cl ON cp.Id_cliente = cl.Id_cliente ");

            if (tipo_busqueda.Equals("ID CLIENTE"))
            {
                consulta.Append("WHERE cp.Id_cliente = @Texto_busqueda ");
            }
            else if (tipo_busqueda.Equals("ID TURNO"))
            {
                consulta.Append("WHERE cp.Id_turno = @Texto_busqueda ");
            }

            consulta.Append("ORDER BY cp.Id_turno DESC ");

            DataTable        DtResultado = new DataTable("CarrerasPerdidas");
            SQLiteConnection SqlCon      = DConexion.Conex(out rpta);

            try
            {
                if (SqlCon == null)
                {
                    throw new Exception(rpta);
                }

                SqlCon.Open();
                SQLiteCommand SqlCmd = new SQLiteCommand
                {
                    Connection  = SqlCon,
                    CommandText = Convert.ToString(consulta),
                    CommandType = CommandType.Text
                };

                SQLiteParameter Texto_busqueda = new SQLiteParameter
                {
                    ParameterName = "@Texto_busqueda",
                    Size          = 50,
                    Value         = texto_busqueda.Trim().ToUpper()
                };
                SqlCmd.Parameters.Add(Texto_busqueda);

                SQLiteDataAdapter SqlData = new SQLiteDataAdapter(SqlCmd);
                SqlData.Fill(DtResultado);

                if (DtResultado.Rows.Count < 1)
                {
                    DtResultado = null;
                }
            }
            catch (SQLiteException ex)
            {
                rpta        = ex.Message;
                DtResultado = null;
            }
            catch (Exception ex)
            {
                rpta        = ex.Message;
                DtResultado = null;
            }
            finally
            {
                if (SqlCon.State == ConnectionState.Open)
                {
                    SqlCon.Close();
                }
            }

            return(DtResultado);
        }
Ejemplo n.º 12
0
        public static DataTable BuscarBases(string tipo_busqueda, string texto_busqueda,
                                            out string rpta)
        {
            StringBuilder consulta = new StringBuilder();

            consulta.Append("SELECT * FROM Bases_clientes ");

            if (tipo_busqueda.Equals("NOMBRE"))
            {
                consulta.Append("WHERE Nombre_base like '@Texto_busqueda%' ");
            }
            else if (tipo_busqueda.Equals("ID BASE"))
            {
                consulta.Append("WHERE Id_base = @Texto_busqueda ");
            }

            consulta.Append("ORDER BY Id_base ASC ");

            DataTable        DtResultado = new DataTable("Bases");
            SQLiteConnection SqlCon      = DConexion.Conex(out rpta);

            try
            {
                if (SqlCon == null)
                {
                    throw new Exception(rpta);
                }

                SqlCon.Open();
                SQLiteCommand SqlCmd = new SQLiteCommand
                {
                    Connection  = SqlCon,
                    CommandText = Convert.ToString(consulta),
                    CommandType = CommandType.Text
                };

                SQLiteParameter Texto_busqueda = new SQLiteParameter
                {
                    ParameterName = "@Texto_busqueda",
                    Size          = 50,
                    Value         = texto_busqueda.Trim().ToUpper()
                };
                SqlCmd.Parameters.Add(Texto_busqueda);

                SQLiteDataAdapter SqlData = new SQLiteDataAdapter(SqlCmd);
                SqlData.Fill(DtResultado);

                if (DtResultado.Rows.Count < 1)
                {
                    DtResultado = null;
                }
            }
            catch (SQLiteException ex)
            {
                rpta        = ex.Message;
                DtResultado = null;
            }
            catch (Exception ex)
            {
                rpta        = ex.Message;
                DtResultado = null;
            }
            finally
            {
                if (SqlCon.State == ConnectionState.Open)
                {
                    SqlCon.Close();
                }
            }

            return(DtResultado);
        }
Ejemplo n.º 13
0
        public static DataTable BuscarCorreos(string tipo_busqueda, string texto_busqueda,
                                              out string rpta)
        {
            string comprobacion = Comprobaciones.ComprobacionTablaCorreos("ConfiguracionCorreos");

            if (!comprobacion.Equals("OK"))
            {
                rpta = comprobacion;
                return(null);
            }

            StringBuilder consulta = new StringBuilder();

            consulta.Append("SELECT * " +
                            "FROM ConfiguracionCorreos ");

            if (tipo_busqueda.Equals("TIPO"))
            {
                consulta.Append("WHERE Tipo_correo = '" + texto_busqueda + "' ");
            }
            else if (tipo_busqueda.Equals("ID CORREO"))
            {
                consulta.Append("WHERE Id_correo = " + texto_busqueda + " ");
            }

            consulta.Append("ORDER BY Id_correo DESC ");

            DataTable        DtResultado = new DataTable("Correos");
            SQLiteConnection SqlCon      = DConexion.Conex(out rpta);

            try
            {
                if (SqlCon == null)
                {
                    throw new Exception(rpta);
                }

                SqlCon.Open();
                SQLiteCommand SqlCmd = new SQLiteCommand
                {
                    Connection  = SqlCon,
                    CommandText = Convert.ToString(consulta),
                    CommandType = CommandType.Text
                };

                SQLiteParameter Texto_busqueda = new SQLiteParameter
                {
                    ParameterName = "@Texto_busqueda",
                    Size          = 50,
                    Value         = texto_busqueda.Trim().ToUpper()
                };
                SqlCmd.Parameters.Add(Texto_busqueda);

                SQLiteDataAdapter SqlData = new SQLiteDataAdapter(SqlCmd);
                SqlData.Fill(DtResultado);

                if (DtResultado.Rows.Count < 1)
                {
                    DtResultado = null;
                }
            }
            catch (SQLiteException ex)
            {
                rpta        = ex.Message;
                DtResultado = null;
            }
            catch (Exception ex)
            {
                rpta        = ex.Message;
                DtResultado = null;
            }
            finally
            {
                if (SqlCon.State == ConnectionState.Open)
                {
                    SqlCon.Close();
                }
            }

            return(DtResultado);
        }
Ejemplo n.º 14
0
        public static DataTable Login(string nombre_empleado, string password,
                                      out string rpta)
        {
            StringBuilder consulta = new StringBuilder();

            consulta.Append("SELECT * FROM " +
                            "Empleados em INNER JOIN Credenciales_empleado cred ON em.Id_empleado = cred.Id_empleado " +
                            "WHERE em.Nombre_empleado = @Nombre and " +
                            "cred.Password = @Password " +
                            "ORDER BY cred.Fecha_modificacion DESC ");

            DataTable        DtResultado = new DataTable("Empleados");
            SQLiteConnection SqlCon      = DConexion.Conex(out rpta);

            try
            {
                if (SqlCon == null)
                {
                    throw new Exception(rpta);
                }

                SqlCon.Open();
                SQLiteCommand SqlCmd = new SQLiteCommand
                {
                    Connection  = SqlCon,
                    CommandText = Convert.ToString(consulta),
                    CommandType = CommandType.Text
                };

                SQLiteParameter Nombre = new SQLiteParameter
                {
                    ParameterName = "@Nombre",
                    Size          = 150,
                    Value         = nombre_empleado
                };
                SqlCmd.Parameters.Add(Nombre);

                SQLiteParameter Texto_busqueda = new SQLiteParameter
                {
                    ParameterName = "@Password",
                    Size          = 50,
                    Value         = password
                };
                SqlCmd.Parameters.Add(Texto_busqueda);

                SQLiteDataAdapter SqlData = new SQLiteDataAdapter(SqlCmd);
                SqlData.Fill(DtResultado);

                if (DtResultado.Rows.Count < 1)
                {
                    DtResultado = null;
                }
            }
            catch (SQLiteException ex)
            {
                rpta        = ex.Message;
                DtResultado = null;
            }
            catch (Exception ex)
            {
                rpta        = ex.Message;
                DtResultado = null;
            }
            finally
            {
                if (SqlCon.State == ConnectionState.Open)
                {
                    SqlCon.Close();
                }
            }

            return(DtResultado);
        }
Ejemplo n.º 15
0
        public static DataTable BuscarCronogramas(string tipo_busqueda, string texto_busqueda1, string texto_busqueda2,
                                                  out string rpta)
        {
            StringBuilder consulta = new StringBuilder();

            consulta.Append("SELECT * FROM Vehiculos vh " +
                            "LEFT JOIN Cronogramas_vehiculos crvh ON vh.Id_vehiculo = crvh.Id_vehiculo ");

            if (tipo_busqueda.Equals("FECHA ID VEHICULO"))
            {
                consulta.Append("WHERE crvh.Fecha_cronograma = '@Texto_busqueda1' and crvhh.Id_vehiculo = @Texto_busqueda2 ");
            }
            else if (tipo_busqueda.Equals("ID CRONOGRAMA"))
            {
                consulta.Append("WHERE crvh.Id_cronograma = @Texto_busqueda ");
            }
            else if (tipo_busqueda.Equals("ID VEHICULO"))
            {
                consulta.Append("WHERE crvh.Id_vehiculo = @Texto_busqueda ");
            }

            consulta.Append("ORDER BY crvh.Id_cronograma DESC ");

            DataTable        DtResultado = new DataTable("Cronogramas");
            SQLiteConnection SqlCon      = DConexion.Conex(out rpta);

            try
            {
                if (SqlCon == null)
                {
                    throw new Exception(rpta);
                }

                SqlCon.Open();
                SQLiteCommand SqlCmd = new SQLiteCommand
                {
                    Connection  = SqlCon,
                    CommandText = Convert.ToString(consulta),
                    CommandType = CommandType.Text
                };

                SQLiteParameter Texto_busqueda1 = new SQLiteParameter
                {
                    ParameterName = "@Texto_busqueda1",
                    Size          = 50,
                    Value         = texto_busqueda1.Trim().ToUpper()
                };
                SqlCmd.Parameters.Add(Texto_busqueda1);

                SQLiteParameter Texto_busqueda2 = new SQLiteParameter
                {
                    ParameterName = "@Texto_busqueda2",
                    Size          = 50,
                    Value         = texto_busqueda2.Trim().ToUpper()
                };
                SqlCmd.Parameters.Add(Texto_busqueda2);

                SQLiteDataAdapter SqlData = new SQLiteDataAdapter(SqlCmd);
                SqlData.Fill(DtResultado);

                if (DtResultado.Rows.Count < 1)
                {
                    DtResultado = null;
                }
            }
            catch (SQLiteException ex)
            {
                rpta        = ex.Message;
                DtResultado = null;
            }
            catch (Exception ex)
            {
                rpta        = ex.Message;
                DtResultado = null;
            }
            finally
            {
                if (SqlCon.State == ConnectionState.Open)
                {
                    SqlCon.Close();
                }
            }

            return(DtResultado);
        }
Ejemplo n.º 16
0
        public static DataTable BuscarDireccionClientes(string tipo_busqueda, string texto_busqueda,
                                                        out string rpta)
        {
            StringBuilder consulta = new StringBuilder();

            consulta.Append("SELECT * " +
                            "FROM Direccion_clientes dcl " +
                            "INNER JOIN Clientes cl " +
                            "ON dcl.Id_cliente = cl.Id_cliente " +
                            "INNER JOIN Bases_clientes bcl " +
                            "ON cl.Id_base = bcl.Id_base " +
                            "INNER JOIN Barrios ba " +
                            "ON dcl.Id_barrio = ba.Id_barrio ");

            if (tipo_busqueda.Equals("COMPLETO"))
            {
                consulta.Append("WHERE Estado_direccion = 'ACTIVO' ");
            }
            else if (tipo_busqueda.Equals("NOMBRE"))
            {
                consulta.Append("WHERE cl.Nombre_cliente like '@Texto_busqueda%' " +
                                "and cl.Estado_cliente = 'ACTIVO' ");
            }
            else if (tipo_busqueda.Equals("CELULAR"))
            {
                consulta.Append("WHERE cl.Celular_cliente like '@Texto_busqueda%' " +
                                "and cl.Estado_cliente = 'ACTIVO' ");
            }
            else if (tipo_busqueda.Equals("ESTADO"))
            {
                consulta.Append("WHERE Estado_direccion = '@Texto_busqueda ");
            }
            else if (tipo_busqueda.Equals("ID CLIENTE"))
            {
                consulta.Append("WHERE cl.Id_cliente = @Texto_busqueda ");
            }
            else if (tipo_busqueda.Equals("CODIGO"))
            {
                consulta.Append("WHERE cl.Codigo_cliente = '" + texto_busqueda + "' ");
            }

            consulta.Append("ORDER BY Id_direccion DESC ");

            DataTable        DtResultado = new DataTable("DireccionesCliente");
            SQLiteConnection SqlCon      = DConexion.Conex(out rpta);

            try
            {
                if (SqlCon == null)
                {
                    throw new Exception(rpta);
                }

                SqlCon.Open();
                SQLiteCommand SqlCmd = new SQLiteCommand
                {
                    Connection  = SqlCon,
                    CommandText = Convert.ToString(consulta),
                    CommandType = CommandType.Text
                };

                SQLiteParameter Texto_busqueda = new SQLiteParameter
                {
                    ParameterName = "@Texto_busqueda",
                    Size          = 50,
                    Value         = texto_busqueda.Trim().ToUpper()
                };
                SqlCmd.Parameters.Add(Texto_busqueda);

                SQLiteDataAdapter SqlData = new SQLiteDataAdapter(SqlCmd);
                SqlData.Fill(DtResultado);

                if (DtResultado.Rows.Count < 1)
                {
                    DtResultado = null;
                }
            }
            catch (SQLiteException ex)
            {
                rpta        = ex.Message;
                DtResultado = null;
            }
            catch (Exception ex)
            {
                rpta        = ex.Message;
                DtResultado = null;
            }
            finally
            {
                if (SqlCon.State == ConnectionState.Open)
                {
                    SqlCon.Close();
                }
            }

            return(DtResultado);
        }
Ejemplo n.º 17
0
        public static string ComprobacionTablaCarrerasPerdidas(string nombreTabla)
        {
            string        rpta     = "OK";
            StringBuilder consulta = new StringBuilder();

            consulta.Append("SELECT name FROM sqlite_master WHERE TYPE='table' AND name='" + nombreTabla + "' ");

            DataTable        DtResultado = new DataTable("Comprobacion");
            SQLiteConnection SqlCon      = DConexion.Conex(out rpta);

            try
            {
                if (SqlCon == null)
                {
                    throw new Exception(rpta);
                }

                SqlCon.Open();
                SQLiteCommand SqlCmd = new SQLiteCommand
                {
                    Connection  = SqlCon,
                    CommandText = Convert.ToString(consulta),
                    CommandType = CommandType.Text
                };

                SQLiteDataAdapter SqlData = new SQLiteDataAdapter(SqlCmd);
                SqlData.Fill(DtResultado);

                if (DtResultado.Rows.Count < 1)
                {
                    consulta = new StringBuilder();
                    consulta.Append("CREATE TABLE Carreras_perdidas ( " +
                                    "Id_turno INTEGER NOT NULL, " +
                                    "Id_cliente INTEGER NOT NULL, " +
                                    "FOREIGN KEY('Id_cliente') REFERENCES 'Clientes'('Id_cliente'), " +
                                    "FOREIGN KEY('Id_turno') REFERENCES 'Turnos'('Id_turno')); ");

                    SqlCmd = new SQLiteCommand
                    {
                        Connection  = SqlCon,
                        CommandText = Convert.ToString(consulta),
                        CommandType = CommandType.Text
                    };

                    SqlCmd.ExecuteNonQuery();

                    consulta = new StringBuilder();
                    consulta.Append("SELECT name FROM sqlite_master WHERE TYPE='table' AND name='" + nombreTabla + "' ");

                    SqlCmd = new SQLiteCommand
                    {
                        Connection  = SqlCon,
                        CommandText = Convert.ToString(consulta),
                        CommandType = CommandType.Text
                    };

                    SqlData = new SQLiteDataAdapter(SqlCmd);
                    SqlData.Fill(DtResultado);

                    if (DtResultado.Rows.Count < 1)
                    {
                        DtResultado = null;
                        rpta        = "No se creo a tabla " + nombreTabla;
                    }
                }
            }
            catch (SQLiteException ex)
            {
                rpta        = ex.Message;
                DtResultado = null;
            }
            catch (Exception ex)
            {
                rpta        = ex.Message;
                DtResultado = null;
            }
            finally
            {
                if (SqlCon.State == ConnectionState.Open)
                {
                    SqlCon.Close();
                }
            }

            return(rpta);
        }
Ejemplo n.º 18
0
        public static string ComprobacionTablaCorreos(string nombreTabla)
        {
            string        rpta     = "OK";
            StringBuilder consulta = new StringBuilder();

            consulta.Append("SELECT name FROM sqlite_master WHERE TYPE='table' AND name='" + nombreTabla + "' ");

            DataTable        DtResultado = new DataTable("Comprobacion");
            SQLiteConnection SqlCon      = DConexion.Conex(out rpta);

            try
            {
                if (SqlCon == null)
                {
                    throw new Exception(rpta);
                }

                SqlCon.Open();
                SQLiteCommand SqlCmd = new SQLiteCommand
                {
                    Connection  = SqlCon,
                    CommandText = Convert.ToString(consulta),
                    CommandType = CommandType.Text
                };

                SQLiteDataAdapter SqlData = new SQLiteDataAdapter(SqlCmd);
                SqlData.Fill(DtResultado);

                if (DtResultado.Rows.Count < 1)
                {
                    consulta = new StringBuilder();
                    consulta.Append("CREATE TABLE ConfiguracionCorreos ( " +
                                    "Id_correo INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, " +
                                    "Correo_remitente TEXT NOT NULL, " +
                                    "Clave_correo_remitente TEXT NOT NULL, " +
                                    "Correo_destinatario TEXT NOT NULL, " +
                                    "Correo_copia TEXT NOT NULL, " +
                                    "Tipo_correo TEXT NOT NULL, " +
                                    "Estado_correo TEXT NOT NULL DEFAULT 'ACTIVO'); " +
                                    "INSERT INTO ConfiguracionCorreos (Correo_remitente, Clave_correo_remitente, Correo_destinatario, Correo_copia, Tipo_correo, Estado_correo) " +
                                    "VALUES ('', '', '', '', 'REPORTES', 'ACTIVO'); " +
                                    "INSERT INTO ConfiguracionCorreos (Correo_remitente, Clave_correo_remitente, Correo_destinatario, Correo_copia, Tipo_correo, Estado_correo) " +
                                    "VALUES ('', '', '', '', 'ERRORES', 'ACTIVO'); ");

                    SqlCmd = new SQLiteCommand
                    {
                        Connection  = SqlCon,
                        CommandText = Convert.ToString(consulta),
                        CommandType = CommandType.Text
                    };

                    SqlCmd.ExecuteNonQuery();

                    consulta = new StringBuilder();
                    consulta.Append("SELECT name FROM sqlite_master WHERE TYPE='table' AND name='" + nombreTabla + "' ");

                    SqlCmd = new SQLiteCommand
                    {
                        Connection  = SqlCon,
                        CommandText = Convert.ToString(consulta),
                        CommandType = CommandType.Text
                    };

                    SqlData = new SQLiteDataAdapter(SqlCmd);
                    SqlData.Fill(DtResultado);

                    if (DtResultado.Rows.Count < 1)
                    {
                        DtResultado = null;
                        rpta        = "No se creo a tabla " + nombreTabla;
                    }
                }
            }
            catch (SQLiteException ex)
            {
                rpta        = ex.Message;
                DtResultado = null;
            }
            catch (Exception ex)
            {
                rpta        = ex.Message;
                DtResultado = null;
            }
            finally
            {
                if (SqlCon.State == ConnectionState.Open)
                {
                    SqlCon.Close();
                }
            }

            return(rpta);
        }
Ejemplo n.º 19
0
        public static string InsertarCarreraPerdida(List <string> vs)
        {
            string rpta         = "";
            string comprobacion = Comprobaciones.ComprobacionTablaCarrerasPerdidas("Carreras_perdidas");

            if (!comprobacion.Equals("OK"))
            {
                rpta = comprobacion;
                return(null);
            }

            string consulta = "INSERT INTO Carreras_perdidas(Id_turno, Id_cliente) " +
                              "VALUES(@Id_turno, @Id_cliente); ";

            SQLiteConnection SqlCon = DConexion.Conex(out rpta);

            try
            {
                int contador = 0;

                if (SqlCon == null)
                {
                    throw new Exception(rpta);
                }

                SqlCon.Open();
                SQLiteCommand SqlCmd = new SQLiteCommand
                {
                    Connection  = SqlCon,
                    CommandText = consulta,
                    CommandType = CommandType.Text
                };

                SQLiteParameter Id_turno = new SQLiteParameter
                {
                    ParameterName = "@Id_turno",
                    Value         = Convert.ToInt32(vs[contador])
                };
                SqlCmd.Parameters.Add(Id_turno);
                contador += 1;

                SQLiteParameter Id_cliente = new SQLiteParameter
                {
                    ParameterName = "@Id_cliente",
                    Value         = Convert.ToInt32(vs[contador])
                };
                SqlCmd.Parameters.Add(Id_cliente);
                contador += 1;

                rpta = SqlCmd.ExecuteNonQuery() >= 1 ? "OK" : "NO se ingresó el registro";

                if (!rpta.Equals("OK"))
                {
                    if (Mensaje_respuesta != null)
                    {
                        rpta = Mensaje_respuesta;
                    }
                }
            }
            //Mostramos posible error que tengamos
            catch (SQLiteException ex)
            {
                rpta = ex.Message;
            }
            catch (Exception ex)
            {
                rpta = ex.Message;
            }
            finally
            {
                //Si la cadena SqlCon esta abierta la cerramos
                if (SqlCon.State == ConnectionState.Open)
                {
                    SqlCon.Close();
                }
            }
            return(rpta);
        }
Ejemplo n.º 20
0
        public static DataTable BuscarCarrerasReporte(int id_vehiculo,
                                                      out DataTable dtVehiculos, out DataTable dtVehiculosEstado,
                                                      out string rpta)
        {
            StringBuilder consulta1 = new StringBuilder();

            //Tabla dtPrincipal
            consulta1.Append("SELECT car.Estado_carrera, COUNT(*) as CantidadServicios " +
                             "FROM Vehiculos vh INNER JOIN Carreras car ON vh.Id_vehiculo = car.Id_vehiculo " +
                             "WHERE car.Id_vehiculo = @Id_vehiculo " +
                             "GROUP BY car.Estado_carrera ");

            StringBuilder consulta2 = new StringBuilder();

            //Tabla dtVehiculos
            consulta2.Append("SELECT vh.*, COUNT(*) as CantidadServicios " +
                             "FROM Vehiculos vh INNER JOIN Carreras car ON vh.Id_vehiculo = car.Id_vehiculo " +
                             "WHERE car.Id_vehiculo = @Id_vehiculo " +
                             "GROUP BY car.Id_vehiculo ");

            StringBuilder consulta3 = new StringBuilder();

            //Tabla dtVehiculosEstadoCarreras
            consulta3.Append("SELECT * FROM " +
                             "(SELECT vh.*, car.*, COUNT(*) as CantidadServicios " +
                             "FROM Vehiculos vh " +
                             "INNER JOIN Carreras car ON vh.Id_vehiculo = car.Id_vehiculo " +
                             "WHERE car.Estado_carrera = 'PENDIENTE' " +
                             "GROUP BY vh.Id_vehiculo " +
                             "UNION " +
                             "SELECT vh.*, car.*, COUNT(*) as CantidadServicios " +
                             "FROM Vehiculos vh " +
                             "INNER JOIN Carreras car ON vh.Id_vehiculo = car.Id_vehiculo " +
                             "WHERE car.Estado_carrera = 'CANCELADA' " +
                             "GROUP BY vh.Id_vehiculo " +
                             "UNION " +
                             "SELECT vh.*, car.*, COUNT(*) as CantidadServicios " +
                             "FROM Vehiculos vh " +
                             "INNER JOIN Carreras car ON vh.Id_vehiculo = car.Id_vehiculo " +
                             "WHERE car.Estado_carrera = 'TERMINADA' " +
                             "GROUP BY vh.Id_vehiculo) Carrerass " +
                             "WHERE Carrerass.Id_vehiculo = @Id_vehiculo ");

            DataTable DtPrincipal = new DataTable("DtPrincipal");

            dtVehiculos       = new DataTable("DtVehiculos");
            dtVehiculosEstado = new DataTable("DtVehiculosEstado");
            SQLiteConnection SqlCon = DConexion.Conex(out rpta);

            try
            {
                if (SqlCon == null)
                {
                    throw new Exception(rpta);
                }

                SqlCon.Open();

                #region CONSULTA TABLA PRINCIPAL
                SQLiteCommand SqlCmd = new SQLiteCommand
                {
                    Connection  = SqlCon,
                    CommandText = Convert.ToString(consulta1),
                    CommandType = CommandType.Text
                };

                SQLiteParameter Id_vehiculo = new SQLiteParameter
                {
                    ParameterName = "@Id_vehiculo",
                    Value         = id_vehiculo
                };
                SqlCmd.Parameters.Add(Id_vehiculo);

                SQLiteDataAdapter SqlData = new SQLiteDataAdapter(SqlCmd);
                SqlData.Fill(DtPrincipal);

                if (DtPrincipal.Rows.Count < 1)
                {
                    DtPrincipal = null;
                }

                #endregion

                #region CONSULTA TABLA VEHICULOS

                SqlCmd.CommandText = Convert.ToString(consulta2);
                SqlCmd.Parameters.Add(Id_vehiculo);
                SqlData = new SQLiteDataAdapter(SqlCmd);
                SqlData.Fill(dtVehiculos);

                if (dtVehiculos.Rows.Count < 1)
                {
                    dtVehiculos = null;
                }

                #endregion

                #region CONSULTA TABLA VEHICULOS ESTADO

                SqlCmd.CommandText = Convert.ToString(consulta3);
                SqlCmd.Parameters.Add(Id_vehiculo);
                SqlData = new SQLiteDataAdapter(SqlCmd);
                SqlData.Fill(dtVehiculosEstado);

                if (dtVehiculosEstado.Rows.Count < 1)
                {
                    dtVehiculosEstado = null;
                }

                #endregion
            }
            catch (SQLiteException ex)
            {
                rpta              = ex.Message;
                DtPrincipal       = null;
                dtVehiculos       = null;
                dtVehiculosEstado = null;
            }
            catch (Exception ex)
            {
                rpta              = ex.Message;
                DtPrincipal       = null;
                dtVehiculos       = null;
                dtVehiculosEstado = null;
            }
            finally
            {
                if (SqlCon.State == ConnectionState.Open)
                {
                    SqlCon.Close();
                }
            }

            return(DtPrincipal);
        }
Ejemplo n.º 21
0
        public static DataTable BuscarVehiculos(string tipo_busqueda, string texto_busqueda,
                                                out string rpta)
        {
            StringBuilder consulta = new StringBuilder();

            consulta.Append("SELECT * FROM Vehiculos ");

            if (tipo_busqueda.Equals("COMPLETO"))
            {
                consulta.Append("WHERE Estado_vehiculo = 'ACTIVO' ");
            }
            else if (tipo_busqueda.Equals("PLACA"))
            {
                consulta.Append("WHERE Placa like '%@Texto_busqueda%' " +
                                "and Estado_vehiculo = 'ACTIVO' ");
            }
            else if (tipo_busqueda.Equals("CHOFER"))
            {
                consulta.Append("WHERE Chofer like '@Texto_busqueda%' " +
                                "and Estado_vehiculo = 'ACTIVO' ");
            }
            else if (tipo_busqueda.Equals("ESTADO"))
            {
                consulta.Append("WHERE Estado_vehiculo = '@Texto_busqueda ");
            }
            else if (tipo_busqueda.Equals("ID VEHICULO"))
            {
                consulta.Append("WHERE Id_vehiculo = @Texto_busqueda ");
            }
            else if (tipo_busqueda.Equals("TODO"))
            {
                consulta.Append("WHERE Placa like '%Texto_busqueda%' OR " +
                                "Chofer like '%Texto_busqueda%' OR " +
                                "Marca like '%Texto_busqueda%' ");
            }

            consulta.Append("ORDER BY Id_vehiculo DESC ");

            DataTable        DtResultado = new DataTable("Vehiculos");
            SQLiteConnection SqlCon      = DConexion.Conex(out rpta);

            try
            {
                if (SqlCon == null)
                {
                    throw new Exception(rpta);
                }

                SqlCon.Open();
                SQLiteCommand SqlCmd = new SQLiteCommand
                {
                    Connection  = SqlCon,
                    CommandText = Convert.ToString(consulta),
                    CommandType = CommandType.Text
                };

                SQLiteParameter Texto_busqueda = new SQLiteParameter
                {
                    ParameterName = "@Texto_busqueda",
                    Size          = 50,
                    Value         = texto_busqueda.Trim().ToUpper()
                };
                SqlCmd.Parameters.Add(Texto_busqueda);

                SQLiteDataAdapter SqlData = new SQLiteDataAdapter(SqlCmd);
                SqlData.Fill(DtResultado);

                if (DtResultado.Rows.Count < 1)
                {
                    DtResultado = null;
                }
            }
            catch (SQLiteException ex)
            {
                rpta        = ex.Message;
                DtResultado = null;
            }
            catch (Exception ex)
            {
                rpta        = ex.Message;
                DtResultado = null;
            }
            finally
            {
                if (SqlCon.State == ConnectionState.Open)
                {
                    SqlCon.Close();
                }
            }

            return(DtResultado);
        }
        public static DataTable BuscarDetalleVehiculosCarreras(string tipo_busqueda, string texto_busqueda,
                                                               out string rpta)
        {
            StringBuilder consulta = new StringBuilder();

            /**Para devolver una única tabla de DetalleVehículosCarreras
             * Se debe hacer lo siguiente:
             * 1- Consultar los vehículos que están en DetalleVehiculosCarreras con una fecha en específico
             * 2- Consultar todos los vehículos que tenemos en la base de datos
             * 3- Después de tener los resultados correctos, recorremos la tabla VehiculosDetalles y con cada ID
             * vehiculo que aparezca lo removemos de la tabla Vehiculos luego
             * combinamos las dos tablas, usando DataTable.Merge()**/

            DataTable        DtResultado = new DataTable("Vehiculos_detalle");
            SQLiteConnection SqlCon      = DConexion.Conex(out rpta);

            try
            {
                if (SqlCon == null)
                {
                    throw new Exception(rpta);
                }

                SqlCon.Open();

                #region PRIMER CONSULTA
                //Primer consulta --> Consultar los que estén en vehículos y en detalle con fecha espefícifca
                consulta.Append("SELECT * " +
                                "FROM Detalle_vehiculo_estado dvh INNER JOIN Vehiculos vh " +
                                "ON dvh.Id_vehiculo = vh.Id_vehiculo " +
                                "LEFT JOIN (SELECT car.Id_vehiculo, COUNT(*) as CantidadServicios " +
                                "FROM Carreras car INNER JOIN Vehiculos vh ON car.Id_vehiculo = vh.Id_vehiculo " +
                                "WHERE car.Id_turno = @Texto_busqueda AND car.Estado_carrera = 'TERMINADA' " +
                                "GROUP BY car.Id_vehiculo) as dcar " +
                                "ON dvh.Id_vehiculo = dcar.Id_vehiculo " +
                                "INNER JOIN Estados_vehiculos es ON dvh.Id_estado = es.Id_estado " +
                                "INNER JOIN Turnos tur ON dvh.Id_turno = tur.Id_turno " +
                                "WHERE dvh.Fecha = @Fecha " +
                                "and vh.Estado_vehiculo = 'ACTIVO' " +
                                "and dvh.Id_turno = @Texto_busqueda " +
                                "ORDER BY es.Estado_order, dcar.CantidadServicios ASC ");

                //Tabla para almacenar la consulta
                DataTable     dtVehiculosDetalle = new DataTable();
                SQLiteCommand SqlCmd             = new SQLiteCommand
                {
                    Connection  = SqlCon,
                    CommandText = Convert.ToString(consulta),
                    CommandType = CommandType.Text
                };

                SQLiteParameter Fecha = new SQLiteParameter
                {
                    ParameterName = "@Fecha",
                    Size          = 50,
                    Value         = DateTime.Now.ToString("yyyy-MM-dd")
                };
                SqlCmd.Parameters.Add(Fecha);

                SQLiteParameter Texto_busqueda = new SQLiteParameter
                {
                    ParameterName = "@Texto_busqueda",
                    Size          = 50,
                    Value         = texto_busqueda
                };
                SqlCmd.Parameters.Add(Texto_busqueda);

                SQLiteDataAdapter SqlData = new SQLiteDataAdapter(SqlCmd);
                SqlData.Fill(dtVehiculosDetalle);

                if (dtVehiculosDetalle.Rows.Count < 1)
                {
                    dtVehiculosDetalle = null;
                }
                #endregion

                #region SEGUNDA CONSULTA
                //Segunda consulta --> Consultar todos los vehículos
                consulta = new StringBuilder();
                consulta.Append("SELECT * FROM Vehiculos vh " +
                                "WHERE vh.Estado_vehiculo = 'ACTIVO' ");

                SqlCmd.CommandText = consulta.ToString();
                //Tabla para almacenar los vehículos
                DataTable dtVehiculos = new DataTable();

                SqlData = new SQLiteDataAdapter(SqlCmd);
                SqlData.Fill(dtVehiculos);

                if (dtVehiculos.Rows.Count < 1)
                {
                    dtVehiculos = null;
                }
                #endregion

                //Procedimientos con las dos tablas -> Recorrer tabla VehiculosDetalles
                if (dtVehiculosDetalle != null)
                {
                    //Iniciar ciclo
                    foreach (DataRow row in dtVehiculosDetalle.Rows)
                    {
                        //Capturar el id del vehiculo, que buscaremos en la tabla vehículos
                        int       id_vehiculo = Convert.ToInt32(row["Id_vehiculo"]);
                        DataRow[] filas       =
                            dtVehiculos.Select("Id_vehiculo = '" + id_vehiculo.ToString() + "'");
                        //Comprobamos si encontró filas
                        if (filas != null)
                        {
                            //Removemos las filas que encontró
                            if (filas.Length > 0)
                            {
                                dtVehiculos.Rows.Remove(filas[0]);
                            }
                        }
                    }
                    dtVehiculosDetalle.Merge(dtVehiculos);
                    DtResultado = dtVehiculosDetalle;
                }
                else
                {
                    if (dtVehiculos != null)
                    {
                        DataColumn column1 = new DataColumn("Id_detalle_vehiculo", typeof(string));
                        DataColumn column2 = new DataColumn("Fecha", typeof(string));
                        DataColumn column3 = new DataColumn("Id_vehiculo1", typeof(string));
                        DataColumn column4 = new DataColumn("Estado", typeof(string));
                        dtVehiculos.Columns.Add(column1);
                        dtVehiculos.Columns.Add(column2);
                        dtVehiculos.Columns.Add(column3);
                        dtVehiculos.Columns.Add(column4);
                        DtResultado = dtVehiculos;
                    }
                    else
                    {
                        DtResultado = null;
                    }
                }
            }
            catch (SQLiteException ex)
            {
                rpta        = ex.Message;
                DtResultado = null;
            }
            catch (Exception ex)
            {
                rpta        = ex.Message;
                DtResultado = null;
            }
            finally
            {
                if (SqlCon.State == ConnectionState.Open)
                {
                    SqlCon.Close();
                }
            }

            return(DtResultado);
        }
        public static DataTable BuscarDetalleVehiculos(string tipo_busqueda, string texto_busqueda,
                                                       out string rpta)
        {
            StringBuilder consulta = new StringBuilder();

            consulta.Append("SELECT * " +
                            "FROM Vehiculos vh " +
                            "INNER JOIN Detalle_vehiculo_estado dvh " +
                            "ON vh.Id_vehiculo = dvh.Id_vehiculo " +
                            "INNER JOIN Turnos tur " +
                            "ON dvh.Id_turno = tur.Id_turno " +
                            "INNER JOIN Estados_vehiculos estvh " +
                            "ON dvh.Id_estado = estvh.Id_estado ");

            if (tipo_busqueda.Equals("COMPLETO"))
            {
                consulta.Append("WHERE vh.Estado_vehiculo = 'ACTIVO' ");
            }
            else if (tipo_busqueda.Equals("COMPLETO FECHA"))
            {
                consulta.Append("WHERE dvh.Fecha = '" + texto_busqueda + "' " +
                                "and vh.Estado_vehiculo = 'ACTIVO' ");
            }
            else if (tipo_busqueda.Equals("ID TURNO"))
            {
                consulta.Append("WHERE dvh.Id_turno = " + texto_busqueda + " " +
                                "and vh.Estado_vehiculo = 'ACTIVO' ");
            }
            else if (tipo_busqueda.Equals("ID VEHICULO"))
            {
                consulta.Append("WHERE dvh.Id_vehiculo = @Texto_busqueda ");
            }

            consulta.Append("ORDER BY dvh.Id_detalle_vehiculo DESC ");

            DataTable        DtResultado = new DataTable("Vehiculos_detalle");
            SQLiteConnection SqlCon      = DConexion.Conex(out rpta);

            try
            {
                if (SqlCon == null)
                {
                    throw new Exception(rpta);
                }

                SqlCon.Open();
                SQLiteCommand SqlCmd = new SQLiteCommand
                {
                    Connection  = SqlCon,
                    CommandText = Convert.ToString(consulta),
                    CommandType = CommandType.Text
                };

                SQLiteParameter Texto_busqueda = new SQLiteParameter
                {
                    ParameterName = "@Texto_busqueda",
                    Size          = 50,
                    Value         = texto_busqueda.Trim().ToUpper()
                };
                SqlCmd.Parameters.Add(Texto_busqueda);

                SQLiteDataAdapter SqlData = new SQLiteDataAdapter(SqlCmd);
                SqlData.Fill(DtResultado);

                if (DtResultado.Rows.Count < 1)
                {
                    DtResultado = null;
                }
            }
            catch (SQLiteException ex)
            {
                rpta        = ex.Message;
                DtResultado = null;
            }
            catch (Exception ex)
            {
                rpta        = ex.Message;
                DtResultado = null;
            }
            finally
            {
                if (SqlCon.State == ConnectionState.Open)
                {
                    SqlCon.Close();
                }
            }

            return(DtResultado);
        }
Ejemplo n.º 24
0
        public static DataTable BuscarTurnos(string tipo_busqueda, string texto_busqueda,
                                             out string rpta)
        {
            StringBuilder consulta = new StringBuilder();

            consulta.Append("SELECT * " +
                            "FROM Turnos tu " +
                            "INNER JOIN Empleados em ON tu.Id_empleado = em.Id_empleado ");

            if (tipo_busqueda.Equals("FECHA"))
            {
                consulta.Append("WHERE Fecha_turno = '" + texto_busqueda + "' ");
            }
            else if (tipo_busqueda.Equals("ID TURNO"))
            {
                consulta.Append("WHERE Id_turno = " + texto_busqueda + " ");
            }

            consulta.Append("ORDER BY Id_turno DESC ");

            DataTable        DtResultado = new DataTable("Turnos");
            SQLiteConnection SqlCon      = DConexion.Conex(out rpta);

            try
            {
                if (SqlCon == null)
                {
                    throw new Exception(rpta);
                }

                SqlCon.Open();
                SQLiteCommand SqlCmd = new SQLiteCommand
                {
                    Connection  = SqlCon,
                    CommandText = Convert.ToString(consulta),
                    CommandType = CommandType.Text
                };

                SQLiteParameter Texto_busqueda = new SQLiteParameter
                {
                    ParameterName = "@Texto_busqueda",
                    Size          = 50,
                    Value         = texto_busqueda.Trim().ToUpper()
                };
                SqlCmd.Parameters.Add(Texto_busqueda);

                SQLiteDataAdapter SqlData = new SQLiteDataAdapter(SqlCmd);
                SqlData.Fill(DtResultado);

                if (DtResultado.Rows.Count < 1)
                {
                    DtResultado = null;
                }
            }
            catch (SQLiteException ex)
            {
                rpta        = ex.Message;
                DtResultado = null;
            }
            catch (Exception ex)
            {
                rpta        = ex.Message;
                DtResultado = null;
            }
            finally
            {
                if (SqlCon.State == ConnectionState.Open)
                {
                    SqlCon.Close();
                }
            }

            return(DtResultado);
        }
Ejemplo n.º 25
0
        public static DataTable BuscarCarreras(string tipo_busqueda, string texto_busqueda,
                                               out string rpta)
        {
            StringBuilder consulta = new StringBuilder();

            consulta.Append("SELECT * FROM Carreras car " +
                            "INNER JOIN Clientes cl ON car.Id_cliente = cl.Id_cliente " +
                            "INNER JOIN Direccion_clientes dcl ON car.Id_direccion = dcl.Id_direccion " +
                            "INNER JOIN Barrios bar ON dcl.Id_barrio = bar.Id_barrio " +
                            "INNER JOIN Vehiculos veh ON car.Id_vehiculo = veh.Id_vehiculo " +
                            "INNER JOIN Empleados em ON car.Id_empleado = em.Id_empleado " +
                            "INNER JOIN Turnos tur ON car.Id_turno = tur.Id_turno ");

            if (tipo_busqueda.Equals("COMPLETO FECHA TERMINADO"))
            {
                consulta.Append("WHERE Estado_carrera = 'TERMINADO' and " +
                                "Fecha_carrera = @Texto_busqueda ");
            }
            else if (tipo_busqueda.Equals("COMPLETO FECHA PENDIENTE"))
            {
                consulta.Append("WHERE Estado_carrera = 'PENDIENTE' and " +
                                "Fecha_carrera = @Texto_busqueda ");
            }
            else if (tipo_busqueda.Equals("COMPLETO FECHA CANCELADO"))
            {
                consulta.Append("WHERE Estado_carrera = 'CANCELADO' and " +
                                "Fecha_carrera = @Texto_busqueda ");
            }
            else if (tipo_busqueda.Equals("ID CLIENTE TERMINADO"))
            {
                consulta.Append("WHERE car.Id_cliente = @Texto_busqueda " +
                                "and Estado_carrera = 'TERMINADO' ");
            }
            else if (tipo_busqueda.Equals("ID CLIENTE PENDIENTE"))
            {
                consulta.Append("WHERE car.Id_cliente = @Texto_busqueda " +
                                "and Estado_carrera = 'PENDIENTE' ");
            }
            else if (tipo_busqueda.Equals("ID CLIENTE CANCELADO"))
            {
                consulta.Append("WHERE car.Id_cliente = @Texto_busqueda " +
                                "and Estado_carrera = 'CANCELADO' ");
            }
            else if (tipo_busqueda.Equals("ID CLIENTE COMPLETO"))
            {
                consulta.Append("WHERE car.Id_cliente = @Texto_busqueda ");
            }
            else if (tipo_busqueda.Equals("COMPLETO FECHA"))
            {
                consulta.Append("WHERE Fecha_carrera = @Texto_busqueda ");
            }
            else if (tipo_busqueda.Equals("COMPLETO ID TURNO"))
            {
                consulta.Append("WHERE car.Id_turno = @Texto_busqueda ");
            }

            consulta.Append("ORDER BY Id_carrera DESC ");

            DataTable        DtResultado = new DataTable("Carreras");
            SQLiteConnection SqlCon      = DConexion.Conex(out rpta);

            try
            {
                if (SqlCon == null)
                {
                    throw new Exception(rpta);
                }

                SqlCon.Open();
                SQLiteCommand SqlCmd = new SQLiteCommand
                {
                    Connection  = SqlCon,
                    CommandText = Convert.ToString(consulta),
                    CommandType = CommandType.Text
                };

                SQLiteParameter Texto_busqueda = new SQLiteParameter
                {
                    ParameterName = "@Texto_busqueda",
                    Size          = 50,
                    Value         = texto_busqueda.Trim()
                };
                SqlCmd.Parameters.Add(Texto_busqueda);

                SQLiteDataAdapter SqlData = new SQLiteDataAdapter(SqlCmd);
                SqlData.Fill(DtResultado);

                if (DtResultado.Rows.Count < 1)
                {
                    DtResultado = null;
                }
            }
            catch (SQLiteException ex)
            {
                rpta        = ex.Message;
                DtResultado = null;
            }
            catch (Exception ex)
            {
                rpta        = ex.Message;
                DtResultado = null;
            }
            finally
            {
                if (SqlCon.State == ConnectionState.Open)
                {
                    SqlCon.Close();
                }
            }

            return(DtResultado);
        }