コード例 #1
0
        private void btnguardar_Click(object sender, EventArgs e)
        {
            try
            {
                string respuesta = "";
                if (this.txtnombre.Text == string.Empty || this.txtidcategoria.Text == string.Empty || this.txtcodigo.Text == string.Empty)
                {
                    Mensajeerror(" Faltan ingresar algunos datos");
                    erroricono.SetError(txtnombre, "Ingrese un valor");
                    erroricono.SetError(txtcodigo, "Ingrese un valor");
                    erroricono.SetError(txtcategoria, "Ingrese un valor");
                }
                else
                {
                    System.IO.MemoryStream ms = new System.IO.MemoryStream();
                    this.picimagen.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Png);

                    byte[] imagen = ms.GetBuffer();
                    if (this.Isnuevo)
                    {
                        respuesta = Narticulo.Insertar(this.txtcodigo.Text, this.txtnombre.Text.Trim().ToUpper(), this.txtdescripcion.Text.Trim(),
                                                       imagen, Convert.ToInt32(this.txtidcategoria.Text),
                                                       Convert.ToInt32(this.cmbidpresentacion.SelectedValue));
                    }
                    else
                    {
                        respuesta = Narticulo.Editar(Convert.ToInt32(this.txtidarticulo.Text),
                                                     this.txtcodigo.Text, this.txtnombre.Text.Trim().ToUpper(), this.txtdescripcion.Text.Trim(),
                                                     imagen, Convert.ToInt32(this.txtidcategoria.Text),
                                                     Convert.ToInt32(this.cmbidpresentacion.SelectedValue));
                    }

                    if (respuesta.Equals("OK"))
                    {
                        if (this.Isnuevo)
                        {
                            this.Mensajeok(" Se inserto de forma correcta el registro");
                        }
                        else
                        {
                            this.Mensajeok(" Se actualizó de forma correcta el registro");
                        }
                    }
                    else
                    {
                        this.Mensajeerror(respuesta);
                    }

                    this.Isnuevo  = false;
                    this.Iseditar = false;
                    this.Botones();
                    this.limpiar();
                    this.mostrar();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + ex.StackTrace);
            }
        }
コード例 #2
0
        private void btnGuardar_Click(object sender, EventArgs e)
        {
            try
            {
                string respuesta = "";

                if (txtNombre.Text == string.Empty)
                {
                    Utilidades.MensajeError("Falta ingresar algunos datos.");
                    errorIcono.SetError(txtNombre, "Ingrese un nombre");
                }
                else if (txtIdCategoria.Text == string.Empty)
                {
                    Utilidades.MensajeError("Falta ingresar algunos datos.");
                    errorIcono.SetError(txtCategoria, "Seleccione una Categoria");
                }
                else if (txtCodigos.Text == string.Empty)
                {
                    Utilidades.MensajeError("Falta ingresar algunos datos.");
                    errorIcono.SetError(txtCodigos, "Ingrese un valor");
                }
                else
                {
                    System.IO.MemoryStream ms = new System.IO.MemoryStream();

                    pxImagen.Image = Utilidades.CambiarTamanoImagen(pxImagen.Image, 50, 50);
                    pxImagen.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Png); //Formato de la imagen.

                    byte[] imagen = ms.GetBuffer();

                    if (isNuevo)
                    {
                        respuesta = Narticulo.Insertar(txtCodigos.Text, txtNombre.Text.Trim().ToUpper(), txtDescripcion.Text.Trim(), imagen, Convert.ToInt32(txtIdCategoria.Text), Convert.ToInt32(cbPresentacion.SelectedValue));
                    }
                    else
                    {
                        respuesta = Narticulo.Editar(Convert.ToInt32(txtIdArticulo.Text), txtCodigos.Text.Trim(), txtNombre.Text.Trim().ToUpper(), txtDescripcion.Text.Trim(), imagen, Convert.ToInt32(txtIdCategoria.Text), Convert.ToInt32(cbPresentacion.SelectedValue));
                    }

                    if (respuesta.Equals("Ok"))
                    {
                        if (isNuevo)
                        {
                            Utilidades.MensajeOK("El artículo se agregó correctamente");
                        }
                        else
                        {
                            Utilidades.MensajeOK("La artículo se editó correctamente");
                        }
                    }
                    else
                    {
                        Utilidades.MensajeError(respuesta);
                    }
                    isNuevo = false;
                    isEditar = false;
                    HabilitarBotones();
                    Limpiar();
                    Mostrar();
                }

            }
            catch (Exception ex)
            {
                Utilidades.MensajeError(ex.Message + ex.StackTrace);
            }
        }