Beispiel #1
0
        //Implementación de método de la interfaz

        //método para agregar datos
        public void Agregar()
        {
            try
            {
                if (VerificarInformacion())
                {
                    conexion.AbrirConexion();

                    cmd = new SqlCommand("insert into Multicentro.dbo.servicio (codigoservicio,nombre,precio)" +
                                         " values('" + int.Parse(codigo) + "', '" + nombre + "', '" + int.Parse(precio) + "')", conexion.GetSqlConnection());
                    cmd.ExecuteNonQuery();
                    conexion.CerrarConexion();

                    busqueda.BuscarPorCodigo(guiServiciosIngreso.GetCodigo(), guiServiciosIngreso.GetDataView());
                    MessageBox.Show("Información agregada");
                }
            }
            catch (FormatException ex)
            {
                MensajesStandard.MensajeFormatoIncorrectoDatos();
            }
            catch (SqlException ex)
            {
                MensajesStandard.MensajeCodigoNuevoYaExistente();
            }
            catch (Exception ex)
            {
                MensajesStandard.MensajeGeneralExcepcionGenerica(ex);
            }
        }
        //Implementación de método de la interfaz

        /// <summary>
        /// método para agregar datos a servicios
        /// </summary>
        public bool Agregar()
        {
            busqueda = new ServiciosBusquedaBD();
            conexion = new ConexionesBasicasAbrirCerrarBD();
            Nombre   = guiServiciosIngreso.GetNombre();
            Codigo   = guiServiciosIngreso.GetCodigo();
            Precio   = guiServiciosIngreso.GetPrecio();
            try
            {
                if (VerificarInformacion())
                {
                    conexion.AbrirConexion();

                    cmd = new SqlCommand("insert into Multicentro.dbo.servicio (codigoservicio,nombre,precio)" +
                                         " values('" + int.Parse(Codigo) + "', '" + Nombre + "', '" + double.Parse(Precio) + "')", conexion.GetSqlConnection());
                    cmd.ExecuteNonQuery();
                    conexion.CerrarConexion();

                    busqueda.BuscarPorCodigo(guiServiciosIngreso.GetCodigo(), guiServiciosIngreso.GetDataView());
                    MessageBox.Show("Información agregada");
                    return(true);
                }
            }

            catch (FormatException ex)
            {
                MensajesStandard.MensajeFormatoIncorrectoDatos();
                return(false);
            }
            catch (SqlException ex)
            {
                MensajesStandard.MensajeErrorGeneralBaseDatos();
                return(false);
            }
            catch (Exception ex)
            {
                MensajesStandard.MensajeGeneralExcepcionGenerica(ex);
                return(false);
            }
            return(false);
        }