public void FromRow(Lbl.IElementoDeDatos row) { // Si todavía no conozco el tipo de elemento de este formulario, lo tomo de row if (this.ElementoTipo == null || this.ElementoTipo == typeof(Lbl.ElementoDeDatos)) { this.ElementoTipo = row.GetType(); } this.ReadOnly = true; this.Connection = row.Connection; this.Elemento = row; if (this.Encabezado.Visible && this.Encabezado.DisplayStyle.Icon == null) { if (this.Elemento.Existe) { this.StockImage = "editar"; } else { this.StockImage = "crear"; } } bool PuedeVerHistorial = Lbl.Sys.Config.Actual.UsuarioConectado.TienePermiso(this.Elemento, Lbl.Sys.Permisos.Operaciones.Administrar) || Lbl.Sys.Config.Actual.UsuarioConectado.TienePermiso(typeof(Lbl.Sys.Log.Entrada), Lbl.Sys.Permisos.Operaciones.Ver); this.PanelAccionesTerciarias.FormActions["historial"].Visibility = (this.Elemento.Existe && PuedeVerHistorial) ? Lazaro.Pres.Forms.FormActionVisibility.Tertiary : Lazaro.Pres.Forms.FormActionVisibility.Hidden; this.PanelAccionesTerciarias.FormActions["comentarios"].Visibility = this.Elemento.Existe ? Lazaro.Pres.Forms.FormActionVisibility.Tertiary : Lazaro.Pres.Forms.FormActionVisibility.Hidden; Lbl.Atributos.Presentacion AttrMuestraPanel = this.ElementoTipo.GetAttribute <Lbl.Atributos.Presentacion>(); if (AttrMuestraPanel != null) { EntradaComentarios.Visible = this.Elemento.Existe; MuestraPanel = AttrMuestraPanel.PanelExtendido; this.PanelAccionesTerciarias.FormActions["panelextendido"].Visibility = (MuestraPanel != Lbl.Atributos.PanelExtendido.Nunca) ? Lazaro.Pres.Forms.FormActionVisibility.Tertiary : Lazaro.Pres.Forms.FormActionVisibility.Hidden; } if (this.ControlUnico != null) { this.ControlUnico.FromRow(row); if (this.MuestraPanel != Lbl.Atributos.PanelExtendido.Nunca) { if (row is Lbl.IElementoConImagen) { EntradaImagen.Elemento = row; EntradaImagen.ActualizarControl(); EntradaImagen.Visible = true; } else { EntradaImagen.Visible = false; } EntradaComentarios.Elemento = row; EntradaTags.Elemento = row; EntradaComentarios.ActualizarControl(); EntradaTags.ActualizarControl(); if (MuestraPanel == Lbl.Atributos.PanelExtendido.Siempre) { PanelExtendido.Show(); } } } Lbl.Atributos.Nomenclatura Attr = this.ElementoTipo.GetAttribute <Lbl.Atributos.Nomenclatura>(); if (row != null && row.Existe) { if (Attr != null && Attr.PrefijarNombreConTipo) { this.Text = Attr.NombreSingular + " " + row.ToString(); } else { this.Text = row.ToString(); } } else { if (Attr != null) { this.Text = "Creando " + Attr.NombreSingular.ToLowerInvariant(); } else { this.Text = "Creando " + row.GetType().ToString(); } } this.ReadOnly = !this.PuedeEditar(); this.PanelAccionesPrimariasYSecundarias.FormActions["imprimir"].Visibility = this.PuedeImprimir() ? Lazaro.Pres.Forms.FormActionVisibility.Main : Lazaro.Pres.Forms.FormActionVisibility.Hidden; this.ActualizarFormActions(); this.SetControlsChanged(this.Controls, false); }
public Lfx.Types.OperationResult Save() { if (this.ReadOnly) { return(new Lfx.Types.FailureOperationResult("No se puede guardar porque es un formulario sólo-lectura")); } Lfx.Types.OperationResult Resultado = this.ControlUnico.ValidarControl(); if (Resultado.Success == false) { return(Resultado); } Resultado = this.ControlUnico.BeforeSave(); if (Resultado.Success == false) { return(Resultado); } bool WasNew = !this.Elemento.Existe; this.Elemento = this.ToRow(); if (this.GetControlsChanged(this.Controls) || this.Elemento.Modificado) { // Guardo sólo si hubo cambios IDbTransaction Trans = null; if (this.Elemento.Connection.InTransaction == false) { Trans = this.Elemento.Connection.BeginTransaction(IsolationLevel.Serializable); } if (Lfx.Workspace.Master.DebugMode) { Resultado = this.Elemento.Guardar(); } else { try { Resultado = this.Elemento.Guardar(); } catch (Lfx.Types.DomainException dex) { if (Trans != null) { Trans.Rollback(); } Resultado = new Lfx.Types.FailureOperationResult(dex.Message); } catch (Exception ex) { if (Trans != null) { Trans.Rollback(); } if (this.Elemento != null && this.Name != null) { ex.HelpLink = this.Name + ".Save: " + this.ElementoTipo.ToString(); } throw ex; } } if (Resultado.Success) { this.ControlUnico.AfterSave(Trans); if (Trans != null) { Trans.Commit(); } } else { if (Trans != null) { Trans.Rollback(); } } } if (Resultado.Success) { this.SetControlsChanged(this.Controls, false); if (WasNew) { if (ControlDestino != null) { ControlDestino.Text = this.Elemento.Id.ToString(); ControlDestino.Focus(); } Lbl.Atributos.Presentacion AttrMuestraMsg = this.ElementoTipo.GetAttribute <Lbl.Atributos.Presentacion>(); if (AttrMuestraMsg != null && AttrMuestraMsg.MensajeAlCrear) { Lui.Forms.MessageBox.Show("Acaba de crear " + this.Elemento.ToString(), "Crear"); } } if (FormOpener != null) { FormOpener.Focus(); FormOpener.Activate(); } this.DialogResult = DialogResult.OK; } return(Resultado); }