private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                this.Cursor = Cursors.WaitCursor;

                btnImportarDesdeExcel.Enabled = false;
                btnCerrarVentana.Enabled      = false;

                if (dgvListar.Rows.Count > 0)
                {
                    pbBarra.Visible    = true;
                    lbEtiqueta.Visible = true;
                    pbBarra.Maximum    = dgvListar.Rows.Count;
                    pbBarra.Minimum    = 1;

                    foreach (DataGridViewRow Fila in dgvListar.Rows)
                    {
                        pbBarra.Value = Fila.Index + 1;
                        Fila.Selected = true;
                        ProveedorEN oRegistroEN = InformacionDelProveedor(Fila);
                        ProveedorLN oRegistroLN = new ProveedorLN();

                        if (oRegistroLN.ValidarRegistroDuplicado(oRegistroEN, Program.oDatosDeConexion, "AGREGAR"))
                        {
                            string mensaje = string.Format("Se ha encontrado el siguiente error: {0} {1} {0} Desea continuar ingresando la información", Environment.NewLine, oRegistroLN.Error);

                            if (MessageBox.Show(mensaje, "Guardando información del proveedor", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel)
                            {
                                throw new ArgumentException("La operación asido cancelada por el usuario");
                            }
                            continue;
                        }

                        /*Primero agregaremos la entidad mayor...*/

                        EntidadEN oEntidadEN = informacionDeLaEntidad();
                        EntidadLN oEntidadLN = new EntidadLN();

                        if (oEntidadLN.Agregar(oEntidadEN, Program.oDatosDeConexion))
                        {
                            oRegistroEN.idProveedor = oEntidadEN.idEntidad;
                            if (oRegistroLN.Agregar(oRegistroEN, Program.oDatosDeConexion) == false)
                            {
                                string mensaje = string.Format("Se ha encontrado el siguiente error al Guardar la iformación del Proveedor: {0} {1} {0} Desea continuar ingresando la información", Environment.NewLine, oRegistroLN.Error);
                                oEntidadLN.Eliminar(oEntidadEN, Program.oDatosDeConexion);
                                if (MessageBox.Show(mensaje, "Guardando información del proveedor", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel)
                                {
                                    throw new ArgumentException("La operación asido cancelada por el usuario");
                                }
                            }
                        }
                        else
                        {
                            string mensaje = string.Format("Se ha encontrado el siguiente error: {0} {1} {0} Desea continuar ingresando la información", Environment.NewLine, oEntidadLN.Error);

                            if (MessageBox.Show(mensaje, "Guardando información del proveedor", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel)
                            {
                                throw new ArgumentException("La operación asido cancelada por el usuario");
                            }
                        }



                        /* if (oRegistroLN.AgregarUtilizandoLaMismaConexion(oRegistroEN, Program.oDatosDeConexion) == false)
                         * {
                         *   string mensaje = string.Format("Se ha encontrado el siguiente error: {0} {1} {0} Desea continuar ingresando la información", Environment.NewLine, oRegistroLN.Error);
                         *
                         *   if (MessageBox.Show(mensaje, "Guardando información del proveedor", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel)
                         *   {
                         *       throw new ArgumentException("La operación asido cancelada por el usuario");
                         *   }
                         * }*/

                        lbEtiqueta.Text = string.Format("{0} Registros Guardados de {1}", (Fila.Index + 1).ToString(), dgvListar.Rows.Count);
                    }
                }
            } catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Guardar información del proveedor", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            finally
            {
                pbBarra.Visible = false;
                btnImportarDesdeExcel.Enabled = true;
                btnCerrarVentana.Enabled      = true;
                lbEtiqueta.Visible            = false;
                this.Cursor = Cursors.Default;
            }
        }
Пример #2
0
        private void tsbGuardar_Click(object sender, EventArgs e)
        {
            try
            {
                this.Cursor = Cursors.WaitCursor;

                if (LosDatosIngresadosSonCorrectos())
                {
                    LaboratorioEN oRegistroEN = InformacionDelRegistro();
                    LaboratorioLN oRegistroLN = new LaboratorioLN();

                    if (oRegistroLN.ValidarRegistroDuplicado(oRegistroEN, Program.oDatosDeConexion, "AGREGAR"))
                    {
                        MessageBox.Show(oRegistroLN.Error, "Guardar información", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    if (Controles.IsNullOEmptyElControl(txtNoRUC) == false)
                    {
                        if (oRegistroLN.ValidarRegistroDuplicadoNoRUC(oRegistroEN, Program.oDatosDeConexion, "AGREGAR"))
                        {
                            MessageBox.Show(oRegistroLN.Error, "Guardar información", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                    }

                    EntidadEN oEntidadEN = informacionDeLaEntidad();
                    EntidadLN oEntidadLN = new EntidadLN();

                    if (oEntidadLN.Agregar(oEntidadEN, Program.oDatosDeConexion))
                    {
                        oRegistroEN.idLaboratorio = oEntidadEN.idEntidad;

                        if (oRegistroLN.Agregar(oRegistroEN, Program.oDatosDeConexion))
                        {
                            txtIdentificador.Text     = oRegistroEN.idLaboratorio.ToString();
                            ValorLlavePrimariaEntidad = oRegistroEN.idLaboratorio;
                            txtCodigo.Text            = oRegistroEN.Codigo;

                            GuardarActualizarVinculo();

                            EvaluarErrorParaMensajeAPantalla(oRegistroLN.Error, "Guardar");

                            if (CerrarVentana == true)
                            {
                                this.Cursor = Cursors.Default;
                                this.Close();
                            }
                            else
                            {
                                OperacionARealizar = "Modificar";
                                ObtenerValoresDeConfiguracion();
                                DeshabilitarControlesSegunOperacionesARealizar();
                                EstablecerTituloDeVentana();
                                LlamarMetodoSegunOperacion();
                            }
                        }
                        else
                        {
                            oEntidadLN.Eliminar(oEntidadEN, Program.oDatosDeConexion);
                            string mensaje = string.Format("Se ha encontrado el siguiente error al Guardar la iformación del Laboratorio: {0} {1} {0} Desea continuar ingresando la información del Laboratorio", Environment.NewLine, oRegistroLN.Error);
                            throw new ArgumentException(mensaje);
                        }
                    }
                    else
                    {
                        string mensaje = string.Format("Se ha encontrado el siguiente error: {0} {1} {0} Desea continuar ingresando la información", Environment.NewLine, oEntidadLN.Error);
                        throw new ArgumentException(mensaje);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Guardar la información del registro", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally {
                this.Cursor = Cursors.Default;
            }
        }