private void Imprimir() { Lfx.Types.OperationResult Res; if (this.ReadOnly) { Res = new Lfx.Types.SuccessOperationResult(); } else { if (this.Elemento.Existe == false) { // Si es nuevo, lo guardo sin preguntar. Res = this.Save(); } else if (this.Changed) { // Si es edición, y hay cambios, pregunto si quiere guardar using (Lui.Forms.YesNoDialog Pregunta = new Lui.Forms.YesNoDialog("Hay modificaciones sin guardar (subrayadas en color rojo). Antes de imprimir el ducumento se guardarán las modificaciones. ¿Desea continuar?", "Imprimir")) { Pregunta.DialogButtons = Lui.Forms.DialogButtons.YesNo; this.ShowChanged = true; if (Pregunta.ShowDialog() == System.Windows.Forms.DialogResult.OK) { Res = this.Save(); } else { Res = new Lfx.Types.CancelOperationResult(); } this.ShowChanged = false; } } else { // Es edición y no hay cambios... continúo Res = new Lfx.Types.SuccessOperationResult(); } } if (Res.Success) { Res = this.ControlUnico.BeforePrint(); } if (Res.Success) { Lbl.Impresion.Impresora Impresora = null; if ((System.Windows.Forms.Control.ModifierKeys & Keys.Shift) == Keys.Shift) { using (Lui.Printing.PrinterSelectionDialog FormularioSeleccionarImpresora = new Lui.Printing.PrinterSelectionDialog()) { if (FormularioSeleccionarImpresora.ShowDialog() == DialogResult.OK) { Impresora = FormularioSeleccionarImpresora.SelectedPrinter; } else { return; } } } string NombreDocumento = Elemento.ToString(); Lbl.Impresion.CargasPapel Carga = Lbl.Impresion.CargasPapel.Automatica; if (Impresora != null && Impresora.CargaPapel == Lbl.Impresion.CargasPapel.Manual) { Carga = Lbl.Impresion.CargasPapel.Manual; } else if (this.Elemento is Lbl.Comprobantes.ComprobanteConArticulos) { Lbl.Comprobantes.ComprobanteConArticulos Comprob = this.Elemento as Lbl.Comprobantes.ComprobanteConArticulos; if (Lbl.Comprobantes.PuntoDeVenta.TodosPorNumero[Comprob.PV].Tipo == Lbl.Comprobantes.TipoPv.Fiscal) { Carga = Lbl.Impresion.CargasPapel.Automatica; } else { // El tipo de comprobante puede forzar a una carga manual Carga = Comprob.Tipo.CargaPapel; // Intento averiguar el número de comprobante, en caso de que aun no esté numerado if (Comprob.Numero == 0) { int ProximoNumero = Lbl.Comprobantes.Numerador.ProximoNumero(Comprob); NombreDocumento = NombreDocumento.Replace("00000000", ProximoNumero.ToString("00000000")); } } } if (Carga == Lbl.Impresion.CargasPapel.Manual) { using (Lui.Printing.ManualFeedDialog FormularioCargaManual = new Lui.Printing.ManualFeedDialog()) { FormularioCargaManual.DocumentName = NombreDocumento; // Muestro el nombre de la impresora if (Impresora != null) { FormularioCargaManual.PrinterName = Impresora.Nombre; } else { System.Drawing.Printing.PrinterSettings ObjPrint = new System.Drawing.Printing.PrinterSettings(); FormularioCargaManual.PrinterName = ObjPrint.PrinterName; } if (FormularioCargaManual.ShowDialog() == DialogResult.Cancel) { return; } } } if (Impresora != null && Impresora.EsVistaPrevia) { Lazaro.Impresion.ImpresorElemento ImpresorVistaPrevia = Lazaro.Impresion.Instanciador.InstanciarImpresor(this.Elemento, null); ImpresorVistaPrevia.PrintController = new System.Drawing.Printing.PreviewPrintController(); Lui.Printing.PrintPreviewForm VistaPrevia = new Lui.Printing.PrintPreviewForm(); VistaPrevia.MdiParent = this.ParentForm.MdiParent; VistaPrevia.PrintPreview.Document = ImpresorVistaPrevia; VistaPrevia.Show(); } else { Lfx.Types.OperationProgress Progreso = new Lfx.Types.OperationProgress("Imprimiendo", "El documento se está enviando a la impresora."); if (Impresora != null) { Progreso.Description = "El documento se está enviando a la impresora " + Impresora.ToString(); } Progreso.Modal = false; Progreso.Begin(); using (IDbTransaction Trans = this.Elemento.Connection.BeginTransaction()) { Lazaro.Impresion.ImpresorElemento Impresor = Lazaro.Impresion.Instanciador.InstanciarImpresor(this.Elemento, Trans); Impresor.Impresora = Impresora; try { Res = Impresor.Imprimir(); } catch (Exception ex) { Res = new Lfx.Types.FailureOperationResult(ex.Message); } Progreso.End(); if (Res.Success == false) { if (Impresor.Transaction != null) { // Puede que la transacción ya haya sido finalizada por el impresor Impresor.Transaction.Rollback(); } Lui.Forms.MessageBox.Show(Res.Message, "Error"); } else { if (Impresor.Transaction != null) { // Puede que la transacción ya haya sido finalizada por el impresor Impresor.Transaction.Commit(); } this.Elemento.Cargar(); this.FromRow(this.Elemento); this.ControlUnico.AfterPrint(); } } } } if (Res.Success == false && Res.Message != null) { Lui.Forms.MessageBox.Show(Res.Message, "Imprimir"); } }
private void Imprimir() { Lfx.Types.OperationResult Res; if (this.ReadOnly) { Res = new Lfx.Types.SuccessOperationResult(); } else { if (this.Elemento.Existe == false) { // Si es nuevo, lo guardo sin preguntar. Res = this.Save(); } else if (this.Changed) { // Si es edición, y hay cambios, pregunto si quiere guardar using (Lui.Forms.YesNoDialog Pregunta = new Lui.Forms.YesNoDialog("Hay modificaciones sin guardar (subrayadas en color rojo). Antes de imprimir el ducumento se guardarán las modificaciones. ¿Desea continuar?", "Imprimir")) { Pregunta.DialogButtons = Lui.Forms.DialogButtons.YesNo; this.ShowChanged = true; if (Pregunta.ShowDialog() == System.Windows.Forms.DialogResult.OK) { Res = this.Save(); } else { Res = new Lfx.Types.CancelOperationResult(); } this.ShowChanged = false; } } else { // Es edición y no hay cambios... continúo Res = new Lfx.Types.SuccessOperationResult(); } } if (Res.Success) Res = this.ControlUnico.BeforePrint(); if (Res.Success) { Lbl.Impresion.Impresora Impresora = null; if ((System.Windows.Forms.Control.ModifierKeys & Keys.Shift) == Keys.Shift) { using (Lui.Printing.PrinterSelectionDialog FormularioSeleccionarImpresora = new Lui.Printing.PrinterSelectionDialog()) { if (FormularioSeleccionarImpresora.ShowDialog() == DialogResult.OK) { Impresora = FormularioSeleccionarImpresora.SelectedPrinter; } else { return; } } } string NombreDocumento = Elemento.ToString(); Lbl.Impresion.CargasPapel Carga = Lbl.Impresion.CargasPapel.Automatica; if (Impresora != null && Impresora.CargaPapel == Lbl.Impresion.CargasPapel.Manual) { Carga = Lbl.Impresion.CargasPapel.Manual; } else if (this.Elemento is Lbl.Comprobantes.ComprobanteConArticulos) { Lbl.Comprobantes.ComprobanteConArticulos Comprob = this.Elemento as Lbl.Comprobantes.ComprobanteConArticulos; if (Lbl.Comprobantes.PuntoDeVenta.TodosPorNumero[Comprob.PV].Tipo == Lbl.Comprobantes.TipoPv.Fiscal) { Carga = Lbl.Impresion.CargasPapel.Automatica; } else { // El tipo de comprobante puede forzar a una carga manual Carga = Comprob.Tipo.CargaPapel; // Intento averiguar el número de comprobante, en caso de que aun no esté numerado if (Comprob.Numero == 0) { int ProximoNumero = Lbl.Comprobantes.Numerador.ProximoNumero(Comprob); NombreDocumento = NombreDocumento.Replace("00000000", ProximoNumero.ToString("00000000")); } } } if (Carga == Lbl.Impresion.CargasPapel.Manual) { using (Lui.Printing.ManualFeedDialog FormularioCargaManual = new Lui.Printing.ManualFeedDialog()) { FormularioCargaManual.DocumentName = NombreDocumento; // Muestro el nombre de la impresora if (Impresora != null) { FormularioCargaManual.PrinterName = Impresora.Nombre; } else { System.Drawing.Printing.PrinterSettings ObjPrint = new System.Drawing.Printing.PrinterSettings(); FormularioCargaManual.PrinterName = ObjPrint.PrinterName; } if (FormularioCargaManual.ShowDialog() == DialogResult.Cancel) return; } } if (Impresora != null && Impresora.EsVistaPrevia) { Lazaro.Impresion.ImpresorElemento ImpresorVistaPrevia = Lazaro.Impresion.Instanciador.InstanciarImpresor(this.Elemento, null); ImpresorVistaPrevia.PrintController = new System.Drawing.Printing.PreviewPrintController(); Lui.Printing.PrintPreviewForm VistaPrevia = new Lui.Printing.PrintPreviewForm(); VistaPrevia.MdiParent = this.ParentForm.MdiParent; VistaPrevia.PrintPreview.Document = ImpresorVistaPrevia; VistaPrevia.Show(); } else { Lfx.Types.OperationProgress Progreso = new Lfx.Types.OperationProgress("Imprimiendo", "El documento se está enviando a la impresora."); if (Impresora != null) Progreso.Description = "El documento se está enviando a la impresora " + Impresora.ToString(); Progreso.Modal = false; Progreso.Begin(); using (IDbTransaction Trans = this.Elemento.Connection.BeginTransaction()) { Lazaro.Impresion.ImpresorElemento Impresor = Lazaro.Impresion.Instanciador.InstanciarImpresor(this.Elemento, Trans); Impresor.Impresora = Impresora; try { Res = Impresor.Imprimir(); } catch (Exception ex) { Res = new Lfx.Types.FailureOperationResult(ex.Message); } Progreso.End(); if (Res.Success == false) { if (Impresor.Transaction != null) // Puede que la transacción ya haya sido finalizada por el impresor Impresor.Transaction.Rollback(); Lui.Forms.MessageBox.Show(Res.Message, "Error"); } else { if (Impresor.Transaction != null) // Puede que la transacción ya haya sido finalizada por el impresor Impresor.Transaction.Commit(); this.Elemento.Cargar(); this.FromRow(this.Elemento); this.ControlUnico.AfterPrint(); } } } } if (Res.Success == false && Res.Message != null) { Lui.Forms.MessageBox.Show(Res.Message, "Imprimir"); } }
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); }
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; }