private DataTable InformacionDeLosContendoresPorSeccion() { DataTable ODatos = null; try { ProductoSustitutosEN oRegistroEN = new ProductoSustitutosEN(); ProductoSustitutosLN oRegistroLN = new ProductoSustitutosLN(); oRegistroEN.oProductoEN.idProducto = ValorLlavePrimariaEntidad; oRegistroEN.OrderBy = " Order By p.Nombre asc "; if (oRegistroLN.ListadoDeProductosXIdProducto(oRegistroEN, Program.oDatosDeConexion)) { ODatos = oRegistroLN.TraerDatos(); return(ODatos); } else { throw new ArgumentException(oRegistroLN.Error); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Información de los productos asociados", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(ODatos); } }
private bool InsertarActualizarOEliminarContenedor() { try { this.Cursor = Cursors.WaitCursor; if (EvaluarDataGridView(dgvListar) == false) { MessageBox.Show("No se encontró registros a procesar", "Evaluación de registros en la lista", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(true); } else { MessageBox.Show(DescripcionDetallaDelContenedor(dgvListar), "Registros a procesar", MessageBoxButtons.OK, MessageBoxIcon.Information); } int RowsContacto = dgvListar.Rows.Count; if (RowsContacto > 0) { MostrarBarraDeProgreso(); InicializarBarraDeProgreso(RowsContacto, 0); int indice = 0; int IndiceProgreso = 0; int TotalDeFilasMarcadasParaEliminar = TotalDeFilasMarcadas(dgvListar, "Eliminar"); //Aqui Volvemos dinamica El codigo poniendo el valor de la llave primaria string NombreLavePrimariaDetalle = "idProductoSustitutos"; while (indice <= dgvListar.Rows.Count - 1) { this.Cursor = Cursors.WaitCursor; IncrementarBarraDeProgreso(IndiceProgreso + 1); DataGridViewRow Fila = dgvListar.Rows[indice]; int ValorDelaLLavePrimaria; int.TryParse(Fila.Cells[NombreLavePrimariaDetalle].Value.ToString(), out ValorDelaLLavePrimaria); Boolean Actualizar = Convert.ToBoolean(Fila.Cells["Actualizar"].Value); Boolean Eliminar = Convert.ToBoolean(Fila.Cells["Eliminar"].Value); if (ValorDelaLLavePrimaria == 0 && Actualizar == false) { if (Eliminar == true) { Fila.DefaultCellStyle.Font = new Font(Font.Name, Font.Size, FontStyle.Regular); Fila.DefaultCellStyle.ForeColor = Color.Black; Fila.DefaultCellStyle.SelectionForeColor = Color.Black; Fila.Cells["Eliminar"].Value = false; } indice++; IndiceProgreso++; continue; } if (LosDatosIngresadosEnGrillaSonCorrectos(Fila) == false) { if (indice < dgvListar.Rows.Count - 1) { if (MessageBox.Show("¿Desea continuar con los restantes registros a procesar?", "Confirmación", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.No) { OcultarBarraDeProgreso(); return(false); } else { indice++; IndiceProgreso++; continue; } } else { OcultarBarraDeProgreso(); return(false); } } ProductoSustitutosEN oRegistroEN = InformacionDelProductoSustituto(Fila); ProductoSustitutosLN oRegistroLN = new ProductoSustitutosLN(); //DETERMINAMOS LA OPERACION A REALIZAR string Operacion = ""; //El orden es importante porque si un usuario agrego una nueva persona pero lo marco para eliminar, no hacemos nada, solo lo quitamos de la lista. if (ValorDelaLLavePrimaria == 0 && Eliminar == true) { Operacion = "ELIMINAR FILA EN GRILLA"; } //VALIDAREMOS QUE LA LLAVE PRIMARIA SEA CERO Y EL CONTARO SEA MAYOR A CERO PARA UN NUEVO VINCULO ENTRE PROVEEDOR Y CONTACTO else if (ValorDelaLLavePrimaria == 0) { Operacion = "AGREGAR"; } //VALIDAREMOS PARA PODER ELIMINAR EL REGISTRO.... else if (ValorDelaLLavePrimaria > 0 && Eliminar == true) { Operacion = "ELIMINAR"; } //VALIDAREMOS PARA PODER ACTUALIZAR EL REGISTRO else if (ValorDelaLLavePrimaria > 0 && Actualizar == true) { Operacion = "ACTUALIZAR"; } //NO EXISTE NINGUNA OPERACION else if (ValorDelaLLavePrimaria >= 0 && Actualizar == false && Eliminar == false) { Operacion = "NINGUNA"; } //Validaciones if (Operacion == "ELIMINAR FILA EN GRILLA") { dgvListar.Rows.Remove(Fila); if (dgvListar.RowCount <= 0) { indice++; IndiceProgreso++; } continue; } if (Operacion == "NINGUNA") { indice++; IndiceProgreso++; continue; } if (Operacion == "AGREGAR") { if (oRegistroLN.ValidarRegistroDuplicado(oRegistroEN, Program.oDatosDeConexion, Operacion)) { OcultarBarraDeProgreso(); this.Cursor = Cursors.Default; MessageBox.Show(oRegistroLN.Error, Operacion, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(false); } } if (Operacion == "ACTUALIZAR") { if (oRegistroLN.ValidarRegistroDuplicado(oRegistroEN, Program.oDatosDeConexion, Operacion)) { OcultarBarraDeProgreso(); this.Cursor = Cursors.Default; MessageBox.Show(oRegistroLN.Error, Operacion, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(false); } } if (Operacion == "ELIMINAR") { //if (oRegistrosLN.ExisteEmpleadoVinculadoAAuxiliaresDePlanillaGeneralDetalle(oRegistrosEN, Program.oDatosConexionesEN, "ELIMINAR")) //{ // this.Cursor = Cursors.Default; // DialogResult Respuesta = MessageBox.Show(oRegistrosLN.Error + "\n\n¿Desea continuar con el proceso de eliminación para los empleados restantes?", this.OperacionARealizar, MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation); // if (Respuesta == DialogResult.No) // { // OcultarBarraDeProgreso(); // return false; // } // else // { // indice++; // indice_progreso++; // continue; // } //} } //OPERACIONES if (Operacion == "AGREGAR") { if (oRegistroLN.Agregar(oRegistroEN, Program.oDatosDeConexion)) { Fila.Cells[NombreLavePrimariaDetalle].Value = oRegistroEN.idProductoSustitutos; Fila.Cells["Actualizar"].Value = false; oRegistroEN = null; oRegistroLN = null; indice++; IndiceProgreso++; continue; } else { OcultarBarraDeProgreso(); this.Cursor = Cursors.Default; MessageBox.Show(oRegistroLN.Error, Operacion, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); oRegistroEN = null; oRegistroLN = null; return(false); } } if (Operacion == "ACTUALIZAR") { if (oRegistroLN.Actualizar(oRegistroEN, Program.oDatosDeConexion)) { dgvListar.Rows[Fila.Index].Cells["Actualizar"].Value = false; oRegistroEN = null; oRegistroLN = null; indice++; IndiceProgreso++; continue; } else { this.Cursor = Cursors.Default; MessageBox.Show(oRegistroLN.Error, Operacion, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); OcultarBarraDeProgreso(); oRegistroEN = null; oRegistroLN = null; return(false); } } if (Operacion == "ELIMINAR") { if (oRegistroLN.Eliminar(oRegistroEN, Program.oDatosDeConexion)) { dgvListar.Rows.Remove(Fila); oRegistroEN = null; oRegistroLN = null; if (dgvListar.RowCount <= 0) { indice++; } IndiceProgreso++; continue; } else { OcultarBarraDeProgreso(); this.Cursor = Cursors.Default; MessageBox.Show(oRegistroLN.Error, Operacion, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); oRegistroEN = null; oRegistroLN = null; return(false); } } this.Cursor = Cursors.Default; } OcultarBarraDeProgreso(); return(true); } else { return(true); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Información del Contenedor", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } finally { this.Cursor = Cursors.Default; } }