Ejemplo n.º 1
0
        //metodo guardar datos
        private void btnGuardar_Click(object sender, EventArgs e)
        {
            //insertar datos
            try
            {
                string rpta = "";
                if (this.txtNombre.Text == string.Empty || this.txtDescripcion.Text == string.Empty)
                {
                    MensajeError("Falta ingresar algunos datos, serán remarcados.");
                    errorIcono.SetError(this.txtNombre, "Ingrese un nombre");
                    errorIcono.SetError(this.txtDescripcion, "Ingrese una descripcion");
                }
                else
                {
                    if (this.EsNuevo)
                    {
                        //nombre,descripcion,imagen,activa
                        rpta = NUnidad.Insertar(this.txtNombre.Text.Trim().ToUpper(),
                                                this.txtDescripcion.Text.Trim().ToUpper());
                    }
                    else
                    {
                        //id,nombre,descripcion,imagen,activa
                        rpta = NUnidad.Editar(Convert.ToInt32(this.txtCodigo.Text),
                                              this.txtNombre.Text.Trim().ToUpper(), this.txtDescripcion.Text.Trim().ToUpper());
                    }

                    if (rpta.Equals("OK"))
                    {
                        if (this.EsNuevo)
                        {
                            this.MensajeOK("Se inserto de forma correcta el registro.");
                        }
                        else
                        {
                            this.MensajeOK("Se modificó de forma correcta el registro.");
                        }
                    }
                    else
                    {
                        this.MensajeError(rpta);
                    }

                    //preparamos para nuevos datos
                    this.EsNuevo  = false;
                    this.EsEditar = false;
                    this.Botones();
                    this.LimpiarControles();
                    this.MostrarDatos();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + ex.StackTrace);
            }
        }
Ejemplo n.º 2
0
        private void btnGuardar_Click(object sender, EventArgs e)
        {
            DateTime FechaActual = DateTime.Now;

            try
            {
                string rpta = "";
                if (txtCodigo.Text == string.Empty | txtNombre.Text == string.Empty)
                {
                    if (txtCodigo.Text == string.Empty)
                    {
                        MensajeError("Falta ingresar algunos datos, serán remarcados");
                        errorIcono.SetError(txtCodigo, "Ingrese el código de la presentación");
                    }
                    if (txtNombre.Text == string.Empty)
                    {
                        MensajeError("Falta ingresar algunos datos, serán remarcados");
                        errorIcono.SetError(txtNombre, "Ingrese el nombre de la presentación");
                    }
                }
                else
                {
                    if (IsNuevo)
                    {
                        rpta = NUnidad.Insertar(Convert.ToInt32(txtCodigo.Text),
                                                txtNombre.Text, FechaActual,
                                                Convert.ToInt16(chkDime.Checked),
                                                Convert.ToInt16(chkFecha.Checked),
                                                Convert.ToInt16(chkI.Checked),
                                                Convert.ToInt16(chkSerial.Checked));
                    }
                    else
                    {
                        rpta = NUnidad.Editar(Convert.ToInt32(txtCodigo.Text),
                                              txtNombre.Text, FechaActual,
                                              Convert.ToInt16(chkDime.Checked),
                                              Convert.ToInt16(chkFecha.Checked),
                                              Convert.ToInt16(chkI.Checked),
                                              Convert.ToInt16(chkSerial.Checked));
                    }
                    if (rpta.Equals("OK"))
                    {
                        if (IsNuevo)
                        {
                            MensajeOk("El registro fue ingresado con exito");
                        }
                        else
                        {
                            MensajeOk("El registro fue modificado con exito");
                        }
                    }
                    else
                    {
                        MensajeError(rpta);
                    }
                    IsNuevo  = false;
                    IsEditar = false;
                    Botones();
                    LimpiarFrm();
                    Mostrar();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + ex.StackTrace);
            }
        }