示例#1
0
        public void AgregarProducto(ProductoEntidad entidad)
        {
            MySqlConnection conexion = null;

            try
            {
                conexion = ConexionDB.GetConexion();
                conexion.Open();
                string sql = "insert into productos (codigo, descripcion,precio,fecha) values " +
                             "(@codigo, @descripcion, @precio, @fecha)";
                MySqlCommand comando = new MySqlCommand(sql, conexion);
                comando.Parameters.AddWithValue("@codigo", entidad.Codigo);
                comando.Parameters.AddWithValue("@descripcion", entidad.Descripcion);
                comando.Parameters.AddWithValue("@precio", entidad.Precio);
                comando.Parameters.AddWithValue("@fecha", entidad.Fecha);
                comando.ExecuteNonQuery();
                //obtiene el ultimo id ingresado
                long id = comando.LastInsertedId;
            }
            catch (MySqlException ex)
            {
                string mensaje = ex.ToString();
                Console.WriteLine("hola" + mensaje);
            }
            finally
            {
                if (conexion != null)
                {
                    conexion.Close();
                }
            }
        }
示例#2
0
        public void EliminarProducto(long idproductos)
        {
            MySqlConnection conexion = null;

            try
            {
                conexion = ConexionDB.GetConexion();
                conexion.Open();
                string       sql     = "delete from productos where id_productos=@id";
                MySqlCommand comando = new MySqlCommand(sql, conexion);
                comando.Parameters.AddWithValue("@id", idproductos);
                comando.ExecuteNonQuery();
            }
            catch (MySqlException ex)
            {
                string mensaje = ex.ToString();
                Console.WriteLine("hola" + mensaje);
            }
            finally
            {
                if (conexion != null)
                {
                    conexion.Close();
                }
            }
        }
示例#3
0
        public void EditarProducto(ProductoEntidad entidad)
        {
            MySqlConnection conexion = null;

            try
            {
                conexion = ConexionDB.GetConexion();
                conexion.Open();

                string sql = "UPDATE productos SET codigo=@codigo, descripcion=@descripcion, " +
                             "precio= @precio, fecha= @fecha WHERE id_productos= @id";
                MySqlCommand comando = new MySqlCommand(sql, conexion);
                comando.Parameters.AddWithValue("@codigo", entidad.Codigo);
                comando.Parameters.AddWithValue("@descripcion", entidad.Descripcion);
                comando.Parameters.AddWithValue("@precio", entidad.Precio);
                comando.Parameters.AddWithValue("@fecha", entidad.Fecha);
                comando.Parameters.AddWithValue("@id", entidad.Id_productos);
                comando.ExecuteNonQuery();
            }
            catch (MySqlException ex)
            {
                string mensaje = ex.ToString();
                Console.WriteLine("hola" + mensaje);
            }
            finally
            {
                if (conexion != null)
                {
                    conexion.Close();
                }
            }
        }
示例#4
0
        public void Agregar(long idDiagnostico, long idUsuario, string mensaje)
        {
            //hago el insert
            //throw new NotImplementedException();
            MySqlConnection conexion = null;

            try
            {
                conexion = ConexionDB.GetConexion();
                conexion.Open();
                string       sql     = @"insert into chat (id_usuario, id_diag ,mensaje) 
                                values (?idusuario,?idiag,?mensaje)";
                MySqlCommand comando = new MySqlCommand(sql, conexion);
                comando.Parameters.Add("?idusuario", MySqlDbType.Int64).Value = idUsuario;
                comando.Parameters.Add("?idiag", MySqlDbType.Int64).Value     = idDiagnostico;
                comando.Parameters.Add("?mensaje", MySqlDbType.String).Value  = mensaje;
                comando.ExecuteNonQuery();
                //obtiene el ultimo id ingresado
                long id = comando.LastInsertedId;
            }
            catch (MySqlException ex)
            {
                string mensajeError = ex.ToString();
                Console.WriteLine("hola" + mensajeError);
            }
            finally
            {
                if (conexion != null)
                {
                    conexion.Close();
                    conexion.Dispose();
                }
            }
        }
示例#5
0
        public List <MensajeEntidad> GetMensajes(long diag)
        {
            List <MensajeEntidad> list     = new List <MensajeEntidad>();
            MySqlDataReader       reader   = null;
            MySqlConnection       conexion = null;

            try
            {
                conexion = ConexionDB.GetConexion();
                conexion.Open();
                string sql;
                sql = @"select nombre, mensaje from chat
                        inner join usuarios on usuarios.id = chat.id_usuario
                        where chat.id_diag=?diag";
                MySqlCommand comando = new MySqlCommand(sql, conexion);
                //comando.Parameters.AddWithValue("@diag", diag);
                comando.Parameters.Add("?diag", MySqlDbType.Int64).Value = diag;
                reader = comando.ExecuteReader();
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        string         nombre      = (reader[0] != DBNull.Value) ? reader.GetString(0) : "";
                        string         mensaje     = (reader[1] != DBNull.Value) ? reader.GetString(1) : "";
                        MensajeEntidad dataMensaje = new MensajeEntidad(nombre, mensaje);
                        list.Add(dataMensaje);
                    }
                }
            }
            catch (MySqlException ex)
            {
                string mensaje = ex.ToString();
                Console.WriteLine("hola" + mensaje);
            }
            finally
            {
                if (conexion != null)
                {
                    conexion.Close();
                    conexion.Dispose();
                }
                if (reader != null)
                {
                    reader.Close();
                    reader.Dispose();
                }
            }
            return(list);
        }
示例#6
0
        public bool Ingresar(string nombreUsuario, string password, string programa)
        {
            string passEncriptado = Encriptar.Encriptar.sha256(password);//1234
            //03ac674216f3e15c761ee1a5e255f067953623c8b388b4459e13f978d7c846f4
            int  largo   = passEncriptado.Length;
            bool ingreso = false;
            List <ProductoEntidad> list     = new List <ProductoEntidad>();
            MySqlConnection        conexion = null;

            try
            {
                MySqlDataReader reader = null;
                conexion = ConexionDB.GetConexion();
                conexion.Open();
                string       sql     = "SELECT nombre, pwd,rol FROM usuarios where nombre=@nombre";
                MySqlCommand comando = new MySqlCommand(sql, conexion);
                comando.Parameters.AddWithValue("@nombre", nombreUsuario);
                reader = comando.ExecuteReader();
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        string id      = (reader[0] != DBNull.Value) ? reader.GetString(1) : "";
                        string pwdbase = (reader[1] != DBNull.Value) ? reader.GetString(1) : "";
                        string rolbase = (reader[2] != DBNull.Value) ? reader.GetString(2) : "";
                        if (pwdbase == passEncriptado &&
                            rolbase == programa)
                        {
                            ingreso = true;
                        }
                    }
                }
            }
            catch (MySqlException ex)
            {
                string mensaje = ex.ToString();
                Console.WriteLine("hola" + mensaje);
            }
            finally
            {
                if (conexion != null)
                {
                    conexion.Close();
                }
            }
            return(ingreso);
        }//end Ingresar
示例#7
0
        public List <ProductoEntidad> ListarProductos(string consulta = null)
        {
            List <ProductoEntidad> list     = new List <ProductoEntidad>();
            MySqlConnection        conexion = null;

            try
            {
                MySqlDataReader reader = null;
                conexion = ConexionDB.GetConexion();
                conexion.Open();
                string sql;
                if (consulta == null)
                {
                    sql = "SELECT id_productos, codigo,descripcion,precio,fecha FROM productos";
                }
                else
                {
                    sql = "SELECT id_productos, codigo,descripcion,precio,fecha FROM productos " +
                          "WHERE codigo LIKE @consulta OR descripcion LIKE @consulta";
                }

                string searchTerm = string.Format("%{0}%", consulta);


                //Command.Parameters.Add(new SqlParameter("@name", searchTerm));

                MySqlCommand comando = new MySqlCommand(sql, conexion);
                comando.Parameters.AddWithValue("@consulta", searchTerm);
                reader = comando.ExecuteReader();
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        string id = reader.GetString(0);

                        /*string codigo = (reader[1] != DBNull.Value) ? reader.GetString(1) : ""; ;
                         * if (reader[1] != DBNull.Value)
                         * {
                         *  string codigo = reader.GetString(1)
                         * }
                         * else
                         * {
                         *  codigo = "";
                         * }*/
                        string          codigo      = (reader[1] != DBNull.Value) ? reader.GetString(1) : "";;
                        string          descripcion = (reader[2] != DBNull.Value) ? reader.GetString(2) : "";
                        string          precio      = (reader[3] != DBNull.Value) ? reader.GetString(3) : "0";
                        string          fecha       = (reader[4] != DBNull.Value) ? reader.GetString(4) : "1/1/2000 0:00:00";
                        ProductoEntidad prod        = new ProductoEntidad
                        {
                            Id_productos = long.Parse(id),
                            Codigo       = codigo,
                            Descripcion  = descripcion,
                            Precio       = float.Parse(precio)
                        };
                        DateTime fechaD = DateTime.ParseExact(fecha, "d/M/yyyy H:mm:ss", System.Globalization.CultureInfo.InvariantCulture);
                        prod.Fecha = fechaD;
                        list.Add(prod);
                    }
                }
            }
            catch (MySqlException ex)
            {
                string mensaje = ex.ToString();
                Console.WriteLine("hola" + mensaje);
            }
            finally
            {
                if (conexion != null)
                {
                    conexion.Close();
                }
            }
            return(list);
        }