Example #1
0
        private void btnGuardar_Click(object sender, EventArgs e)
        {
            try
            {
                string rpta = "";

                if (this.txtNombre.Text == string.Empty || this.txtIdCategorias.Text == string.Empty || this.txtCodigoVentas.Text == string.Empty)
                {
                    MensajeError("Falta Ingresar algunos datos, seran remarcados");
                    errorIcono.SetError(txtNombre, "Ingrese un valor");
                    errorIcono.SetError(txtCodigoVentas, "Ingrese un Codigo de articulo");
                    errorIcono.SetError(txtCategorias, "Ingrese una Categoria");
                }
                else
                {
                    System.IO.MemoryStream ms = new System.IO.MemoryStream();
                    this.pxImagen.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Png); // guardar imagen en el buffer

                    byte[] imagen = ms.GetBuffer();                                       // obtener imagen del buffer y covertirka en array

                    if (this.IsNuevo)
                    {
                        rpta = NArticulos.Insertar(this.txtCodigoVentas.Text.Trim().ToUpper(), this.txtNombre.Text.Trim().ToUpper(), this.txtDescripcion.Text.Trim().ToUpper(), imagen, Convert.ToInt32(this.txtIdCategorias.Text), Convert.ToInt32(this.cbIdPresentacion.SelectedValue));
                    }
                    else
                    {
                        rpta = NArticulos.Editar(Convert.ToInt32(this.txtIdArticulo.Text.Trim()), this.txtCodigoVentas.Text.Trim().ToUpper(), this.txtNombre.Text.Trim().ToUpper(), this.txtDescripcion.Text.Trim().ToUpper(), imagen, Convert.ToInt32(this.txtIdCategorias.Text), Convert.ToInt32(this.cbIdPresentacion.SelectedValue));
                    }

                    if (rpta.Equals("OK"))
                    {
                        if (this.IsNuevo)
                        {
                            MensajeOk("Se inserto de forma correcta el registro");
                        }
                        else
                        {
                            MensajeOk("Se actualizo de forma correcta el registro");
                        }
                    }
                    else
                    {
                        MensajeError(rpta);
                    }

                    this.IsNuevo  = false;
                    this.IsEditar = false;
                    this.Botones();
                    this.limpiar();
                    this.Mostrar();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + ex.StackTrace);
            }
        }
        private void btnGuardar_Click(object sender, EventArgs e)
        {
            try
            {
                string rpta = "";



                if (this.txtIdarticulo.Text == string.Empty && this.IsEditar)
                {
                    MensajeError("Hay campos vacios, porfavor verifique");
                    errorIcono.SetError(txtIdarticulo, "Ingrese un Valor");
                }
                else if (this.txtNombreArticulo.Text == string.Empty)
                {
                    MensajeError("Hay campos vacios, porfavor verifique");
                    errorIcono.SetError(txtNombreArticulo, "Ingrese un Valor");
                }

                else
                {
                    System.IO.MemoryStream ms = new System.IO.MemoryStream();
                    this.pxImagen.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Png);

                    byte[] imagen = ms.GetBuffer();


                    if (this.IsNuevo)
                    {
                        rpta = NArticulos.Insertar(this.txtNombreArticulo.Text.Trim().ToUpper(), this.txtDescripcion.Text.Trim(), imagen); //En caso de error donde pidan Idcategoria o Idpresentacion, aqui y....
                    }
                    else
                    {
                        rpta = NArticulos.Editar(Convert.ToInt32(this.txtIdarticulo.Text)
                                                 , this.txtNombreArticulo.Text.Trim().ToUpper(),
                                                 this.txtDescripcion.Text.Trim(), imagen); //aqui iban Convert.ToInt32(this.txtIdcategoria.Text),Convert.ToInt32(this.cbIdpresentacion.SelectedValue)
                    }

                    if (rpta.Equals("OK"))
                    {
                        if (this.IsNuevo)
                        {
                            this.MensajeOk("Se Insertó de forma correcta el registro");
                        }
                        else
                        {
                            this.MensajeOk("Se Actualizó de forma correcta el registro");
                        }
                    }
                    else
                    {
                        this.MensajeError(rpta);
                    }

                    this.IsNuevo  = false;
                    this.IsEditar = false;
                    this.Botones();
                    this.Limpiar();
                    this.Mostrar();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + ex.StackTrace);
            }
        }