コード例 #1
0
ファイル: Sucursales.cs プロジェクト: rodzter/HolaMundoForms
        public void ENVIAR_DATOS_NUEVO_REGISTRO()
        {
            int i = 0;
            //NUEVO OBJETO DE LA CLASE PRODUCTO de la carpeta BO (Cat_productos)
            Cat_sucursales oProducto = new Cat_sucursales();
            //Nuevo OBJETO DE LA CLASE DAO_producto de la carpeta DAO
            DAO_sucursal oProductoDAO = new DAO_sucursal();

            //LLENAR PROPIEDADES DEL OBJETO PRODUCTO, CON CADA DATO CAPTURADO EN LA PANTALLA
            //Objeto.Propiedad = Pantalla.ComponenteVisual.Valor;
            oProducto.Codigo          = this.txt_codigo.Text.Trim();
            oProducto.Nombre_sucursal = this.txt_nombre_sucursal.Text.Trim();
            oProducto.Direccion       = this.txt_direccion.Text.Trim();
            oProducto.Responsable     = this.txt_responsable.Text.Trim();

            //LLAMAMOS AL METODO DE LA CLASE DAO QUE HACE EL INSERT, le enviamos como parametro el objeto oProducto que
            //ya llenamos con los valores de la pantalla
            i = oProductoDAO.agregarNuevoRegistro(oProducto);
            //VERIFICAMOS SI SE HA EJECUTADO CORRECTAMENTE LA ACCION SOLICITADA
            if (i == 0)
            {
                MessageBox.Show("El proceso no se pudo realizar");
            }
            else
            {
                MessageBox.Show("El proceso se genero con éxito");
            }
            //MATAMOS A LOS OBJETOS UTILIZADOS
            oProducto    = null;
            oProductoDAO = null;
        }
コード例 #2
0
        //METODO PARA INSERTAR UN NUEVO REGISTRO EN LA BASE DE DATOS
        public int agregarNuevoRegistro(object elNuevoRegistro)
        {
            //convertimos nuestro objeto generico a uno de la clase
            Cat_sucursales objetoTablaProducto = (Cat_sucursales)elNuevoRegistro;

            //preparamos el commando de MySQL
            comandoMySQL = new MySqlCommand();
            //preparar el dataset
            dssucursales = new DataSet();
            //preparar el dataAdapter...
            datAdapterMySQL = new MySqlDataAdapter();
            //Establecer la conexion
            comandoMySQL.Connection = oBasedeDatos.miConectorNET;
            oBasedeDatos.establecerConexionNET();
            //ARMAR la instruccion MYSQL: insert
            instruccionSQL = "INSERT INTO cat_sucursal (" +
                             "codigo, nombre_sucursal, direccion, responsable" +
                             ") VALUES ( " +
                             objetoTablaProducto.Codigo.ToString() + "," +
                             pcs(objetoTablaProducto.Nombre_sucursal) + "," +
                             pcs(objetoTablaProducto.Direccion) + "," +
                             pcs(objetoTablaProducto.Responsable) +
                             " ) ";
            comandoMySQL.CommandText = instruccionSQL;
            int resultadodelComando = comandoMySQL.ExecuteNonQuery();

            if (resultadodelComando <= 0)
            {
                return(0); //HAY UN ERROR
            }
            return(1);
        }
コード例 #3
0
        //METODO PARA INSERTAR UN NUEVO REGISTRO EN LA BASE DE DATOS

        public int agregarNuevoRegistro(object elNuevoRegistro)
        {
            //CONVERTIMOS NUESTRO OBJETO GENERICO A UNO DE LA CLASE

            Cat_sucursales objetoTablaProducto = (Cat_sucursales)elNuevoRegistro;

            //PREPARAMOS EL COMANDO DE MYSQL

            comandoMYSQL = new MySqlCommand();

            //PREPARAR EL DATASET
            dsProductos = new DataSet();

            //PREPARAR EL DATAADAPTER....
            datAdapterMYSQL = new MySqlDataAdapter();

            //ESTABLECER LA CONEXION
            comandoMYSQL.Connection = oBasedeDatos.miConectorNET;
            oBasedeDatos.establecerConexionNET();

            //ARMAR LA INSTRUCCION MYSQL: INSERT
            instruccionSQL = "INSERT INTO cat_sucursales (" +
                             "codigo, nombre_sucursal, direccion, responsable" +
                             ") VALUES ( " +
                             pcs(objetoTablaProducto.Codigo) + "," +
                             pcs(objetoTablaProducto.Nombre_sucursal) + "," +
                             pcs(objetoTablaProducto.Direccion) + "," +
                             pcs(objetoTablaProducto.Responsable) +
                             ")";

            comandoMYSQL.CommandText = instruccionSQL;

            int resultadodelComando = comandoMYSQL.ExecuteNonQuery();

            if (resultadodelComando <= 0)
            {
                return(0); //HAY UN ERROR
            }



            return(1);
        }