private void GuardarDatos() { // Se inicializa el proceso de guardado, si aplica if (this.IndiceGuardado == 0) { if (this.dgvDatos.Rows.Count <= 0) return; this.btnMostrar.Enabled = false; this.btnProcesar.Enabled = false; this.btnGuardar.Enabled = false; // this.pgbGuardado.Maximum = this.dgvDatos.Rows.Count ; this.pgbGuardado.Value = 0; this.lblGuardadas.Text = "0"; this.lblTotalPartes.Text = this.dgvDatos.Rows.Count.ToString(GlobalClass.FormatoEntero); this.btnPausar.Enabled = true; this.btnPausar.Tag = false; this.pnlGuardado.Visible = true; // Se deshabilita el "Sort" de las columnas foreach (DataGridViewColumn oCol in this.dgvDatos.Columns) oCol.SortMode = DataGridViewColumnSortMode.NotSortable; } // Se inicia el proceso Datos.StartPersistentContext(); DataGridViewRow Fila; int iParteID; ParteAbc oParte; int iFilas = this.dgvDatos.Rows.Count; for (int iFila = this.IndiceGuardado; iFila < iFilas; iFila++) { Fila = this.dgvDatos.Rows[iFila]; iParteID = Util.Entero(Fila.Cells["ParteID"].Value); oParte = Datos.GetEntity<ParteAbc>(q => q.ParteID == iParteID); // Si no existe, se crea if (oParte == null) oParte = new ParteAbc() { ParteID = iParteID }; // oParte.AbcDeVentas = (string)Fila.Cells["AbcDeVentas"].Value; oParte.AbcDeUtilidad = (string)Fila.Cells["AbcDeUtilidad"].Value; oParte.AbcDeNegocio = (string)Fila.Cells["AbcDeNegocio"].Value; oParte.AbcDeProveedor = (string)Fila.Cells["AbcDeProveedor"].Value; oParte.AbcDeLinea = (string)Fila.Cells["AbcDeLinea"].Value; Datos.Guardar<ParteAbc>(oParte); // Se reporta el progreso y se ejecutan los eventos (para que la aplicación no se trabe) this.IndiceGuardado = iFila; this.pgbGuardado.Value = (iFila + 1); this.lblGuardadas.Text = (iFila + 1).ToString(GlobalClass.FormatoEntero); Application.DoEvents(); if (this.PausaSolicitada) return; } Datos.EndPersistentContext(); // Se finaliza this.IndiceGuardado = 0; this.btnMostrar.Enabled = true; this.btnProcesar.Enabled = true; this.btnGuardar.Enabled = true; this.btnPausar.Enabled = false; //this.pnlGuardado.Visible = false; foreach (DataGridViewColumn oCol in this.dgvDatos.Columns) oCol.SortMode = DataGridViewColumnSortMode.Automatic; UtilLocal.MostrarNotificacion("Proceso completado correctamente."); }
private void GuardarDatos() { // Se inicializa el proceso de guardado, si aplica if (this.IndiceGuardado == 0) { if (this.dgvDatos.Rows.Count <= 0) { return; } this.btnMostrar.Enabled = false; this.btnProcesar.Enabled = false; this.btnGuardar.Enabled = false; // this.pgbGuardado.Maximum = this.dgvDatos.Rows.Count; this.pgbGuardado.Value = 0; this.lblGuardadas.Text = "0"; this.lblTotalPartes.Text = this.dgvDatos.Rows.Count.ToString(GlobalClass.FormatoEntero); this.btnPausar.Enabled = true; this.btnPausar.Tag = false; this.pnlGuardado.Visible = true; // Se deshabilita el "Sort" de las columnas foreach (DataGridViewColumn oCol in this.dgvDatos.Columns) { oCol.SortMode = DataGridViewColumnSortMode.NotSortable; } } // Se inicia el proceso Datos.StartPersistentContext(); DataGridViewRow Fila; int iParteID; ParteAbc oParte; int iFilas = this.dgvDatos.Rows.Count; for (int iFila = this.IndiceGuardado; iFila < iFilas; iFila++) { Fila = this.dgvDatos.Rows[iFila]; iParteID = Util.Entero(Fila.Cells["ParteID"].Value); oParte = Datos.GetEntity <ParteAbc>(q => q.ParteID == iParteID); // Si no existe, se crea if (oParte == null) { oParte = new ParteAbc() { ParteID = iParteID } } ; // oParte.AbcDeVentas = (string)Fila.Cells["AbcDeVentas"].Value; oParte.AbcDeUtilidad = (string)Fila.Cells["AbcDeUtilidad"].Value; oParte.AbcDeNegocio = (string)Fila.Cells["AbcDeNegocio"].Value; oParte.AbcDeProveedor = (string)Fila.Cells["AbcDeProveedor"].Value; oParte.AbcDeLinea = (string)Fila.Cells["AbcDeLinea"].Value; Datos.Guardar <ParteAbc>(oParte); // Se reporta el progreso y se ejecutan los eventos (para que la aplicación no se trabe) this.IndiceGuardado = iFila; this.pgbGuardado.Value = (iFila + 1); this.lblGuardadas.Text = (iFila + 1).ToString(GlobalClass.FormatoEntero); Application.DoEvents(); if (this.PausaSolicitada) { return; } } Datos.EndPersistentContext(); // Se finaliza this.IndiceGuardado = 0; this.btnMostrar.Enabled = true; this.btnProcesar.Enabled = true; this.btnGuardar.Enabled = true; this.btnPausar.Enabled = false; //this.pnlGuardado.Visible = false; foreach (DataGridViewColumn oCol in this.dgvDatos.Columns) { oCol.SortMode = DataGridViewColumnSortMode.Automatic; } UtilLocal.MostrarNotificacion("Proceso completado correctamente."); } #endregion }