private void btnReglasCopiar_Click(object sender, EventArgs e) { if (this.dgvReglas.CurrentRow == null) return; int iSucursalID = Util.Entero(this.cmbSucursal.SelectedValue); var frmValor = new MensajeObtenerValor("¿A qué sucursal deseas copiar la regla seleccionada?", 0, MensajeObtenerValor.Tipo.Combo); frmValor.CargarCombo("SucursalID", "NombreSucursal", Datos.GetListOf<Sucursal>(q => q.SucursalID != iSucursalID)); frmValor.Combo.DropDownStyle = ComboBoxStyle.DropDownList; frmValor.Combo.SelectedIndex = 0; if (frmValor.ShowDialog(Principal.Instance) == DialogResult.OK) { // Se obtiene el orden correspondiente int iCopiaSucID = Util.Entero(frmValor.Valor); int iOrden = 1; var oReglasSuc = Datos.GetListOf<ParteMaxMinRegla>(q => q.SucursalID == iCopiaSucID && q.Estatus); if (oReglasSuc.Count > 0) iOrden = (oReglasSuc.Max(q => q.Orden) + 1); // Se inserta la nueva regla var oRegla = new ParteMaxMinRegla() { SucursalID = iCopiaSucID, Orden = iOrden, Regla = Util.Cadena(this.dgvReglas.CurrentRow.Cells["Reglas_Regla"].Value), Condicion = Util.Cadena(this.dgvReglas.CurrentRow.Cells["Reglas_Condicion"].Value), Maximo = Util.Cadena(this.dgvReglas.CurrentRow.Cells["Reglas_Maximo"].Value), Minimo = Util.Cadena(this.dgvReglas.CurrentRow.Cells["Reglas_Minimo"].Value) }; Datos.Guardar<ParteMaxMinRegla>(oRegla); UtilLocal.MostrarNotificacion("Regla copiada correctamente."); } frmValor.Dispose(); }
private void GuardarReglas() { Cargando.Mostrar(); int iSucursalID = Util.Entero(this.cmbSucursal.SelectedValue); ParteMaxMinRegla oRegla = null; DataGridViewRow Fila = null; for (int iFila = 0; iFila < this.dgvReglas.Rows.Count; iFila++) { Fila = this.dgvReglas.Rows[iFila]; int iCambio = Util.Entero(Fila.Cells["Reglas_Cambio"].Value); if (iCambio == Cat.TiposDeAfectacion.SinCambios) continue; else if (iCambio == Cat.TiposDeAfectacion.Agregar) { oRegla = new ParteMaxMinRegla(); oRegla.SucursalID = iSucursalID; } else { int iReglaID = Util.Entero(Fila.Cells["ParteMaxMinReglaID"].Value); oRegla = Datos.GetEntity<ParteMaxMinRegla>(q => q.ParteMaxMinReglaID == iReglaID && q.Estatus); } if (iCambio == Cat.TiposDeAfectacion.Borrar) { // Se manda hacer el borrado lógico Datos.Eliminar<ParteMaxMinRegla>(oRegla, true); this.dgvReglas.Rows.Remove(Fila); iFila--; } else { // Se llenan los datos oRegla.Orden = Util.Entero(Fila.Cells["Reglas_Orden"].Value); oRegla.Regla = Util.Cadena(Fila.Cells["Reglas_Regla"].Value); oRegla.Condicion = Util.Cadena(Fila.Cells["Reglas_Condicion"].Value); oRegla.Maximo = Util.Cadena(Fila.Cells["Reglas_Maximo"].Value); oRegla.Minimo = Util.Cadena(Fila.Cells["Reglas_Minimo"].Value); oRegla.Descripcion = Util.Cadena(Fila.Cells["Reglas_Descripcion"].Value); // Se valida la regla if (!this.ValidarRegla(oRegla)) { Fila.ErrorText = "Error al validar la regla."; Fila.DefaultCellStyle.ForeColor = Color.Red; continue; } // Se guarda Datos.Guardar<ParteMaxMinRegla>(oRegla); Fila.Cells["ParteMaxMinReglaID"].Value = oRegla.ParteMaxMinReglaID; // Se restablece el color Fila.Cells["Reglas_Cambio"].Value = Cat.TiposDeAfectacion.SinCambios; this.dgvReglas.Rows[iFila].Cells["Reglas_Cambio"].Value = Cat.TiposDeAfectacion.SinCambios; Fila.DefaultCellStyle.ForeColor = Color.Black; Fila.ErrorText = ""; } } Cargando.Cerrar(); }
private bool ValidarRegla(ParteMaxMinRegla oRegla) { return ( oRegla.Orden > 0 && oRegla.Condicion != "" && oRegla.Maximo != "" && oRegla.Minimo != "" ); }