예제 #1
0
        public Libro(string LibroID, ListadeLibros listadeLibros)
        {

            InitializeComponent();
            this.LibroID = LibroID;
            this.FormaPadre = listadeLibros;
            EstadoVentana = "Modificar";
            btGuardar.Text = "Modificar";
           TAlibro taLibros = new TAlibro();
           AccesodeDatos.DsSistemaBiblioteca.Tabla_LibrosRow renglon = taLibros.GetDataBy1LibroID(LibroID)[0];
           tbNombre.Text = renglon.NombreLibro;
           tbISBN.Text = renglon.ID_Libros;
           tbEdicion.Text = renglon.edicion;
           tbAño.Text = renglon.Año.ToString();
           tbAutor.Text = renglon.Autor;
           tbEditorial.Text = renglon.Editorial;
           tbLugar.Text = renglon.Lugar;
           tbClasificacion.Text = renglon.Clasificacion;
           mtbPrecio.Mask = null;
           mtbPrecio.Text = renglon.Precio.ToString();
           cbEjemplares.Visible = false;
           label2.Visible = false;
           cbEjemplares.Text= renglon.Ejemplares.ToString();
       
        }
예제 #2
0
        private void btGuardar_Click(object sender, EventArgs e)
        {
            AccesodeDatos.DsSistemaBibliotecaTableAdapters.EJEMPLARESTableAdapter taEjemplares = new AccesodeDatos.DsSistemaBibliotecaTableAdapters.EJEMPLARESTableAdapter();
            
            decimal dcPrecio = 0;
            string strNombre = tbNombre.Text;
            string strEdicion = tbEdicion.Text;
            string strEditorial = tbEditorial.Text;
            string strClasficacion = tbClasificacion.Text;
            string strLugar = tbLugar.Text;
            string MensajeErrorSQL = string.Empty;
            valPrecio = decimal.TryParse(mtbPrecio.Text,out dcPrecio);
            int intEjemplares = (int)cbEjemplares.SelectedIndex+1;
            String strAñodeLibro = tbAño.Text;
            int intAñodeLibro = int.Parse(tbAño.Text);
            string strIsbn = tbISBN.Text; 
            string strAutor = tbAutor.Text;
        
            TAlibro taLibro = new TAlibro();
            valClasificar = validarCajaDeTexto(tbClasificacion);
            valLugar = validarCajaDeTexto(tbLugar);
            valPrecio = ValidarMaskedTextBox(mtbPrecio);
            valNombre = validarCajaDeTexto(tbNombre);
            valEditorial = validarCajaDeTexto(tbEdicion);
            valAutor = validarCajaDeTexto(tbAutor);
            valISBN = validarCajaDeTexto(tbISBN);
            valAño = validarCajaDeTexto(tbAño);
       
            validarPrecio();
            if (valNombre&& valEditorial&&valLugar&&valClasificar&& valAño&& valAutor&&valISBN&&valClasificar )
            {
                if (EstadoVentana == "Insertar")
                {
                    try
                    {
                        taLibro.Insert1(strNombre, strEdicion, strEditorial, intAñodeLibro, strAutor, strLugar, intEjemplares, strClasficacion, dcPrecio, strIsbn);
                        taEjemplares.InsertarEjemplares(strIsbn, intEjemplares);
                        MessageBox.Show("El Libro " + strNombre + ", Fué Guardado Exitosamente", "Registro Almacenado Exitosamente", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        tbNombre.Clear();
                        tbEdicion.Clear();
                        tbEditorial.Clear();
                        tbClasificacion.Clear();
                        tbAño.Clear();
                        cbEjemplares.Text = "";
                        tbLugar.Clear();
                        tbISBN.Clear();
                        tbAutor.Clear();
                        mtbPrecio.Clear();
                        cbEjemplares.SelectedIndex = 0;
                    }
                catch (SqlException exc)
                {
                    SqlError error = exc.Errors[0];
                    if(error.Number==2627)
                    {

                            MensajeErrorSQL =MessageBox.Show( "Registro ya se encuentra en la base de datos","Error De Registro",MessageBoxButtons.OK,MessageBoxIcon.Error) + exc.Message;



                    }

                }

                }else 
                if(EstadoVentana=="Modificar")
                {
                    //Se hace la modificación en la base de datos
                    taLibro.UpdateQueryLibroID(strNombre, strEdicion, strEditorial, intAñodeLibro, strAutor, strLugar, intEjemplares, strClasficacion, dcPrecio, strIsbn, LibroID);
                    //Se modifican los ejemplares en la base de datos
                    for(int c=1; c<=intEjemplares; c++)
                    {
                        String strEjemplarIdNew = strIsbn + "_" + c;
                        String strEjemplarIdNewAnt = LibroID + "_" + c;
                        taEjemplares.modificarEjemplar(strIsbn, strEjemplarIdNew, strEjemplarIdNewAnt);
                    }
                   
                    //  taEjemplares.InsertarEjemplares(strIsbn, intEjemplares);
                    FormaPadre.ActualizarVentana();
                    MessageBox.Show("El Libro " + strNombre + ", Fue Actualizado Correctamente", "Registro Actualizado Exitosamente", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.Close();
                }
            }
            else
            {
                MessageBox.Show("Sus Campos No Estan Llenos Completamente", "Error De Validacion", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }