Example #1
0
        public virtual Lfx.Types.OperationResult OnCreate()
        {
            if (Lbl.Sys.Config.Actual.UsuarioConectado.TienePermiso(this.Definicion.ElementoTipo, Lbl.Sys.Permisos.Operaciones.Crear))
            {
                Lbl.IElementoDeDatos NuevoElem = this.Crear();
                if (NuevoElem == null)
                {
                    return(new Lfx.Types.CancelOperationResult());
                }

                Lfc.FormularioEdicion FormNuevo = Lfc.Instanciador.InstanciarFormularioEdicion(NuevoElem);
                if (FormNuevo != null)
                {
                    FormNuevo.MdiParent = this.MdiParent;
                    FormNuevo.Show();

                    return(new Lfx.Types.SuccessOperationResult());
                }
                else
                {
                    return(new Lfx.Types.FailureOperationResult("No se puede crear el elemento"));
                }
            }
            else
            {
                return(new Lfx.Types.NoAccessOperationResult());
            }
        }
Example #2
0
        public static ImpresorElemento InstanciarImpresor(Lbl.IElementoDeDatos elemento, IDbTransaction transaction)
        {
            Type tipo = InferirImpresor(elemento.GetType());

            System.Reflection.ConstructorInfo TConstr = tipo.GetConstructor(new Type[] { typeof(Lbl.ElementoDeDatos), typeof(IDbTransaction) });
            return((ImpresorElemento)(TConstr.Invoke(new object[] { elemento, transaction })));
        }
Example #3
0
        public static bool ValidateAccess(Lbl.IElementoDeDatos elemento, Lbl.Sys.Permisos.Operaciones operacion)
        {
            bool Tiene = Lbl.Sys.Config.Actual.UsuarioConectado.TienePermiso(elemento, operacion);

            if (Tiene == false)
            {
                Lfx.Workspace.Master.RunTime.Toast("No tiene permiso para realizar la operación solicitada.", "Error");
            }
            return(Tiene);
        }
Example #4
0
        // Compatibilidad con Lfc.FormularioEdicion
        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.Elemento = row;
            this.ActualizarControl();
        }
Example #5
0
        public virtual Lbl.IElementoDeDatos Crear()
        {
            if (this.Definicion.ElementoTipo == null)
            {
                return(null);
            }

            Lbl.IElementoDeDatos El = Lbl.Instanciador.Instanciar(this.Definicion.ElementoTipo, Lfx.Workspace.Master.GetNewConnection("Crear " + this.Definicion.ElementoTipo.ToString()) as Lfx.Data.Connection);
            El.Crear();
            return(El);
        }
Example #6
0
 /// <summary>
 /// Elimina un elemento por su Id.
 /// </summary>
 public void RemoveById(int id)
 {
     for (int i = 0; i < this.Count; i++)
     {
         Lbl.IElementoDeDatos El2 = this[i] as Lbl.IElementoDeDatos;
         if (El2 != null && El2.Id == id)
         {
             base.RemoveAt(i);
             this.HayQuitados = true;
             break;
         }
     }
 }
Example #7
0
        /// <summary>
        /// Devuelve una colección de elementos nuevos, en comparación con una colección original.
        /// </summary>
        /// <param name="original">La colección original.</param>
        /// <returns>La colección de los elementos presentes en esta colección, pero no en la original.</returns>
        public ColeccionGenerica <T> Agregados(ColeccionGenerica <T> original)
        {
            ColeccionGenerica <T> Res = new ColeccionGenerica <T>();

            foreach (T El in this)
            {
                Lbl.IElementoDeDatos El2 = El as Lbl.IElementoDeDatos;
                if (original.Contains(El2.Id) == false)
                {
                    Res.Add(El);
                }
            }
            return(Res);
        }
Example #8
0
        /// <summary>
        /// Devuelve una colección de elementos faltantes, en comparación con una colección original.
        /// </summary>
        /// <param name="original">La colección original.</param>
        /// <returns>La colección de los elementos no presentes en esta colección, pero si en la original.</returns>
        public ColeccionGenerica <T> Quitados(ColeccionGenerica <T> original)
        {
            ColeccionGenerica <T> Res = new ColeccionGenerica <T>();

            foreach (T Elem in original)
            {
                Lbl.IElementoDeDatos El2 = Elem as Lbl.IElementoDeDatos;
                if (this.Contains(El2.Id) == false)
                {
                    Res.Add(Elem);
                }
            }
            return(Res);
        }
Example #9
0
        /// <summary>
        /// Crea un formulario de edición para el ElementoDeDatos proporcionado.
        /// </summary>
        /// <param name="elemento">El ElementoDeDatos que se quiere editar.</param>
        /// <returns>Un formulario derivado de Lfc.FormularioEdicion.</returns>
        public static Lfc.FormularioEdicion InstanciarFormularioEdicion(Lbl.IElementoDeDatos elemento)
        {
            Lfc.FormularioEdicion Res = new Lfc.FormularioEdicion();
            Type TipoControlEdicion   = InferirControlEdicion(elemento.GetType());

            if (TipoControlEdicion == null)
            {
                return(null);
            }

            Res.ControlUnico = InstanciarControlEdicion(TipoControlEdicion);
            Res.FromRow(elemento);

            return(Res);
        }
Example #10
0
        public int[] GetAllIds()
        {
            int[] Res = new int[this.Count];
            int   i   = 0;

            foreach (T El in this)
            {
                Lbl.IElementoDeDatos El2 = El as Lbl.IElementoDeDatos;
                if (El2 != null)
                {
                    Res[i++] = El2.Id;
                }
            }
            return(Res);
        }
Example #11
0
        public override Lbl.IElementoDeDatos Crear()
        {
            Lbl.IElementoDeDatos Res = base.Crear();
            if (Res is Lbl.Comprobantes.ComprobanteDeCompra)
            {
                string Tipo = this.Tipo;
                using (Crear FormCrear = new Crear())
                {
                    FormCrear.TipoComprob = Tipo;
                    if (FormCrear.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        Tipo = FormCrear.TipoComprob;
                    }
                    else
                    {
                        return(null);
                    }
                }
                Lbl.Comprobantes.ComprobanteDeCompra Comprob = Res as Lbl.Comprobantes.ComprobanteDeCompra;

                switch (Tipo)
                {
                case "FP":
                    Tipo = "FA";
                    break;

                case "NC":
                    Tipo = "NCA";
                    break;

                case "ND":
                    Tipo = "NDA";
                    break;
                }

                if (Lbl.Comprobantes.Tipo.TodosPorLetra.ContainsKey(Tipo))
                {
                    Comprob.Tipo = Lbl.Comprobantes.Tipo.TodosPorLetra[Tipo];
                }
                else
                {
                    throw new InvalidOperationException("No se puede crear el tipo " + Tipo);
                }
            }
            return(Res);
        }
Example #12
0
        public virtual void ImportarRegistro(MapaDeTabla mapa, Lfx.Data.Row importedRow)
        {
            object ImportIdValue = importedRow.Fields[mapa.ColumnaIdLazaro].Value;
            string ImportIdSqlValue;

            if (ImportIdValue is string)
            {
                ImportIdSqlValue = "'" + ImportIdValue.ToString() + "'";
            }
            else if (ImportIdValue is decimal || ImportIdValue is double)
            {
                ImportIdSqlValue = Lfx.Types.Formatting.FormatNumberSql(System.Convert.ToDecimal(ImportIdValue));
            }
            else if (ImportIdValue is DateTime)
            {
                ImportIdSqlValue = "'" + Lfx.Types.Formatting.FormatDateTimeSql(System.Convert.ToDateTime(ImportIdValue)) + "'";
            }
            else
            {
                ImportIdSqlValue = ImportIdValue.ToString();
            }

            Lfx.Data.Row         CurrentRow = this.Connection.FirstRowFromSelect("SELECT * FROM " + mapa.TablaLazaro + " WHERE " + mapa.ColumnaIdLazaro + "=" + ImportIdSqlValue);
            Lbl.IElementoDeDatos Elem       = ConvertirRegistroEnElemento(mapa, importedRow, CurrentRow);

            if (Elem != null)
            {
                this.GuardarElemento(mapa, Elem);

                if (this.Opciones.ImportarStock && Elem is Lbl.Articulos.Articulo && importedRow.Fields.Contains("stock_actual"))
                {
                    // Actualizo el stock
                    Lbl.Articulos.Articulo Art = Elem as Lbl.Articulos.Articulo;

                    decimal StockActual = Art.ObtenerExistencias();
                    decimal NuevoStock  = System.Convert.ToDecimal(importedRow["stock_actual"]);
                    decimal Diferencia  = NuevoStock - StockActual;

                    if (Diferencia != 0)
                    {
                        Art.MoverExistencias(null, Diferencia, "Stock importado desde " + this.Nombre, null, new Articulos.Situacion(this.Connection, Lfx.Workspace.Master.CurrentConfig.Productos.DepositoPredeterminado), null);
                    }
                }
            }
        }
Example #13
0
        private static object ExecCrearEditar(bool crear, string comando)
        {
            string SubComando = Lfx.Types.Strings.GetNextToken(ref comando, " ").Trim();

            System.Type TipoLbl = Lbl.Instanciador.InferirTipo(SubComando);
            Lbl.Atributos.Nomenclatura AtrNombre = TipoLbl.GetAttribute <Lbl.Atributos.Nomenclatura>();

            if (crear && Lbl.Sys.Config.Actual.UsuarioConectado.TienePermiso(TipoLbl, Lbl.Sys.Permisos.Operaciones.Crear) == false)
            {
                return(new Lfx.Types.NoAccessOperationResult());
            }

            if (Lbl.Sys.Config.Actual.UsuarioConectado.TienePermiso(TipoLbl, Lbl.Sys.Permisos.Operaciones.Ver) == false)
            {
                return(new Lfx.Types.NoAccessOperationResult());
            }

            var ConnEditar = Lfx.Workspace.Master.GetNewConnection("Editar " + (AtrNombre == null ? SubComando : AtrNombre.NombreSingular)) as Lfx.Data.Connection;

            Lbl.IElementoDeDatos Elemento = null;
            if (crear)
            {
                Elemento = Lbl.Instanciador.Instanciar(TipoLbl, ConnEditar);
                Elemento.Crear();
            }
            else
            {
                int ItemId = Lfx.Types.Parsing.ParseInt(Lfx.Types.Strings.GetNextToken(ref comando, " "));
                Elemento = Lbl.Instanciador.Instanciar(TipoLbl, ConnEditar, ItemId);
            }

            Lfc.FormularioEdicion FormularioDeEdicion = Lfc.Instanciador.InstanciarFormularioEdicion(Elemento);
            FormularioDeEdicion.DisposeConnection = true;

            if (FormularioDeEdicion == null)
            {
                return(null);
            }

            return(FormularioDeEdicion);
        }
Example #14
0
        protected override Lfx.Types.OperationResult OnEdit(int itemId)
        {
            Lfx.Data.Row Movim = Lfx.Workspace.Master.Tables["cajas_movim"].FastRows[itemId];
            if (Movim != null)
            {
                if (Movim.Fields["id_recibo"].Value != null)
                {
                    int  IdRecibo   = Movim.Fields["id_recibo"].ValueInt;
                    Type TipoRecibo = typeof(Lbl.Comprobantes.Recibo);
                    Lfx.Data.Connection   NuevaDb   = Lfx.Workspace.Master.GetNewConnection("Editar " + TipoRecibo.ToString() + " " + IdRecibo) as Lfx.Data.Connection;
                    Lbl.IElementoDeDatos  Elem      = Lbl.Instanciador.Instanciar(TipoRecibo, NuevaDb, IdRecibo);
                    Lfc.FormularioEdicion FormNuevo = Lfc.Instanciador.InstanciarFormularioEdicion(Elem);
                    FormNuevo.DisposeConnection = true;
                    FormNuevo.MdiParent         = this.MdiParent;
                    FormNuevo.Show();

                    return(new Lfx.Types.SuccessOperationResult());
                }
                else if (Movim.Fields["id_comprob"].Value != null)
                {
                    int  IdComprob                  = Movim.Fields["id_comprob"].ValueInt;
                    Type TipoRecibo                 = typeof(Lbl.Comprobantes.ComprobanteConArticulos);
                    var  NuevaDb                    = Lfx.Workspace.Master.GetNewConnection("Editar " + TipoRecibo.ToString() + " " + IdComprob) as Lfx.Data.Connection;
                    Lbl.IElementoDeDatos  Elem      = Lbl.Instanciador.Instanciar(TipoRecibo, NuevaDb, IdComprob);
                    Lfc.FormularioEdicion FormNuevo = Lfc.Instanciador.InstanciarFormularioEdicion(Elem);
                    FormNuevo.DisposeConnection = true;
                    FormNuevo.MdiParent         = this.MdiParent;
                    FormNuevo.Show();

                    return(new Lfx.Types.SuccessOperationResult());
                }
                else
                {
                    return(new Lfx.Types.CancelOperationResult());
                }
            }
            else
            {
                return(new Lfx.Types.CancelOperationResult());
            }
        }
Example #15
0
 public virtual Lbl.IElementoDeDatos ToRow()
 {
     if (this.ControlUnico != null)
     {
         Lbl.IElementoDeDatos Res = this.ControlUnico.ToRow();
         if (this.MuestraPanel != Lbl.Atributos.PanelExtendido.Nunca)
         {
             if (Res is Lbl.IElementoConImagen)
             {
                 EntradaImagen.ActualizarElemento();
             }
             //EntradaComentarios.ActualizarElemento();
             EntradaTags.ActualizarElemento();
         }
         return(Res);
     }
     else
     {
         return(this.Elemento);
     }
 }
Example #16
0
        public override IElementoDeDatos ConvertirRegistroEnElemento(MapaDeTabla mapa, Lfx.Data.Row externalRow, Lfx.Data.Row internalRow)
        {
            switch (mapa.TablaGestion)
            {
            case "ctacte":
                Lbl.IElementoDeDatos             ElemMovim = base.ConvertirRegistroEnElemento(mapa, externalRow, internalRow);
                Lbl.CuentasCorrientes.Movimiento Movim     = ElemMovim as Lbl.CuentasCorrientes.Movimiento;
                if (Movim != null)
                {
                    if (Movim.IdCliente == 0)
                    {
                        return(null);
                    }

                    Movim.Auto = true;
                    string TipoComprobVentre = externalRow["original_TIPO"].ToString();
                    if (TipoComprobVentre == "FCB")
                    {
                        TipoComprobVentre = "Factura";
                    }
                    else if (TipoComprobVentre == "RCB")
                    {
                        TipoComprobVentre = "Recibo";
                        Movim.Importe     = -Movim.Importe;
                    }
                    else if (TipoComprobVentre == "NCB")
                    {
                        TipoComprobVentre = "Nota de Crédito";
                        Movim.Importe     = -Movim.Importe;
                    }
                    Movim.Nombre = TipoComprobVentre + " 0001-" + System.Convert.ToInt32(externalRow["original_NROCOM"]).ToString("00000000");
                }
                return(ElemMovim);

            case "comprob_detalle":
                // Busco una factura a la cual adosar este detalle
                string Tipo = externalRow["TIPO"].ToString(), TipoGestion = null;
                bool   Compra = false;
                int    Numero = Lfx.Types.Parsing.ParseInt(externalRow["NROCOM"].ToString());
                switch (Tipo)
                {
                case "FCA":
                    TipoGestion = "FA";
                    break;

                case "FCB":
                    TipoGestion = "FB";
                    break;

                case "ING":
                    TipoGestion = "FA";
                    Compra      = true;
                    break;

                case "DEV":
                    TipoGestion = "NCB";
                    break;
                }

                if (Numero > 0 && TipoGestion != null)
                {
                    // Es una factura válida
                    Lbl.Comprobantes.Factura Fac;

                    qGen.Select SelFac = new qGen.Select("comprob");
                    SelFac.WhereClause = new qGen.Where();
                    SelFac.WhereClause.AddWithValue("tipo_fac", TipoGestion);
                    SelFac.WhereClause.AddWithValue("compra", Compra ? 1 : 0);
                    SelFac.WhereClause.AddWithValue("numero", Numero);
                    Lfx.Data.Row FacRow = this.Connection.FirstRowFromSelect(SelFac);

                    if (FacRow == null)
                    {
                        int Cliente = System.Convert.ToInt32(externalRow["CLIENTE"]);
                        if (Cliente <= 0)
                        {
                            Cliente = 999;
                        }
                        qGen.Insert NewFac = new qGen.Insert("comprob");
                        NewFac.ColumnValues.AddWithValue("id_formapago", 1);
                        NewFac.ColumnValues.AddWithValue("tipo_fac", TipoGestion);
                        NewFac.ColumnValues.AddWithValue("pv", 1);
                        NewFac.ColumnValues.AddWithValue("numero", Numero);
                        NewFac.ColumnValues.AddWithValue("situacionorigen", 1);
                        NewFac.ColumnValues.AddWithValue("situaciondestino", 999);
                        NewFac.ColumnValues.AddWithValue("fecha", System.Convert.ToDateTime(externalRow["FECHA"]));
                        NewFac.ColumnValues.AddWithValue("id_vendedor", 1);
                        NewFac.ColumnValues.AddWithValue("id_cliente", Cliente);
                        NewFac.ColumnValues.AddWithValue("impresa", 1);
                        NewFac.ColumnValues.AddWithValue("id_sucursal", 1);
                        NewFac.ColumnValues.AddWithValue("estado", 1);
                        this.Connection.ExecuteNonQuery(NewFac);

                        FacRow = this.Connection.FirstRowFromSelect(SelFac);
                    }

                    Fac = new Comprobantes.Factura(this.Connection, FacRow);
                    if (internalRow != null)
                    {
                        internalRow.Fields.AddWithValue("id_comprob", Fac.Id);
                    }
                    Lbl.IElementoDeDatos             Elem   = base.ConvertirRegistroEnElemento(mapa, externalRow, internalRow);
                    Lbl.Comprobantes.DetalleArticulo DetArt = Elem as Lbl.Comprobantes.DetalleArticulo;
                    if (DetArt != null)
                    {
                        if (DetArt.Articulo == null)
                        {
                            DetArt.Nombre = externalRow["original_CODIGO"].ToString();
                        }
                        DetArt.IdComprobante = Fac.Id;
                    }
                    return(Elem);
                }
                break;
            }

            return(base.ConvertirRegistroEnElemento(mapa, externalRow, internalRow));
        }
Example #17
0
        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);
        }
Example #18
0
        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);
        }
Example #19
0
                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);
                }
Example #20
0
        private static object ExecImprimir(string comando)
        {
            string SubComandoImprimir = Lfx.Types.Strings.GetNextToken(ref comando, " ").Trim();

            switch (SubComandoImprimir.ToUpperInvariant())
            {
            case "COMPROBANTE":
            case "COMPROB":
                int IdComprobante = Lfx.Types.Parsing.ParseInt(Lfx.Types.Strings.GetNextToken(ref comando, " "));

                Lfx.Types.OperationResult ResultadoImpresion;

                using (Lfx.Data.Connection DataBaseImprimir = Lfx.Workspace.Master.GetNewConnection("Imprimir comprobante"))
                    using (System.Data.IDbTransaction Trans = DataBaseImprimir.BeginTransaction()) {
                        Lbl.Comprobantes.ComprobanteConArticulos Comprob = new Lbl.Comprobantes.ComprobanteConArticulos(DataBaseImprimir, IdComprobante);
                        Lazaro.Impresion.Comprobantes.ImpresorComprobanteConArticulos Impresor = new Impresion.Comprobantes.ImpresorComprobanteConArticulos(Comprob, Trans);
                        ResultadoImpresion = Impresor.Imprimir();
                        if (ResultadoImpresion.Success)
                        {
                            Trans.Commit();
                        }
                        else
                        {
                            Trans.Rollback();
                        }
                    }

                return(ResultadoImpresion);

            default:
                int  itemId   = Lfx.Types.Parsing.ParseInt(Lfx.Types.Strings.GetNextToken(ref comando, " ").Trim());
                Type TipoElem = Lbl.Instanciador.InferirTipo(SubComandoImprimir);
                if (TipoElem != null && itemId > 0)
                {
                    using (Lfx.Data.Connection DbImprimir = Lfx.Workspace.Master.GetNewConnection("Imprimir " + TipoElem.ToString() + " " + itemId.ToString())) {
                        Lbl.IElementoDeDatos      Elem = Lbl.Instanciador.Instanciar(TipoElem, DbImprimir, itemId);
                        Lfx.Types.OperationResult Res;
                        using (System.Data.IDbTransaction Trans = DbImprimir.BeginTransaction()) {
                            Lazaro.Impresion.ImpresorElemento Impresor = Lazaro.Impresion.Instanciador.InstanciarImpresor(Elem, Trans);

                            string ImprimirEn = Lfx.Types.Strings.GetNextToken(ref comando, " ").Trim().ToUpperInvariant();
                            if (ImprimirEn == "EN")
                            {
                                // El nombre de la impresora es lo que resta del comando
                                // No lo puedo separar con GetNextToken porque puede contener espacios
                                string NombreImpresora = comando;
                                Impresor.Impresora = Lbl.Impresion.Impresora.InstanciarImpresoraLocal(DbImprimir, NombreImpresora);
                            }

                            Res = Impresor.Imprimir();
                            if (Res.Success)
                            {
                                Trans.Commit();
                            }
                            else
                            {
                                Trans.Rollback();
                            }
                        }
                        return(Res);
                    }
                }
                break;
            }

            return(null);
        }
Example #21
0
        private void ActualizarBarra()
        {
            this.SuspendLayout();

            switch (TablaSolicitada)
            {
            case "articulo":
            case "articulos":
                PanelProgreso.Visible = false;
                PanelAyuda.Visible    = false;
                PanelPersona.Visible  = false;
                PanelArticulo.Visible = true;
                Lbl.Articulos.Articulo Art;
                try {
                    Art = new Lbl.Articulos.Articulo(this.Connection, ItemSolicitado);
                } catch {
                    Art = null;
                }
                if (Art != null && Art.Existe)
                {
                    ElementoActual = Art;
                    ItemActual     = ItemSolicitado;
                    TablaActual    = TablaSolicitada;

                    string Codigos = Art.Id.ToString();
                    if (Art.Codigo1 != null && Art.Codigo1.Length > 0)
                    {
                        Codigos += System.Environment.NewLine + Art.Codigo1;
                    }
                    if (Art.Codigo2 != null && Art.Codigo2.Length > 0)
                    {
                        Codigos += System.Environment.NewLine + Art.Codigo2;
                    }
                    if (Art.Codigo3 != null && Art.Codigo3.Length > 0)
                    {
                        Codigos += System.Environment.NewLine + Art.Codigo3;
                    }
                    if (Art.Codigo4 != null && Art.Codigo4.Length > 0)
                    {
                        Codigos += System.Environment.NewLine + Art.Codigo4;
                    }
                    ArticuloCodigos.Text     = Codigos;
                    ArticuloNombre.Text      = Art.ToString();
                    ArticuloDescripcion.Text = Art.Descripcion;
                    ArticuloPvp.Text         = Lfx.Types.Formatting.FormatCurrency(Art.Pvp, Lfx.Workspace.Master.CurrentConfig.Moneda.Decimales);
                    ArticuloStock.Text       = Lfx.Types.Formatting.FormatCurrency(Art.Existencias, Lfx.Workspace.Master.CurrentConfig.Moneda.Decimales);
                    PanelArticulo.Visible    = true;
                }
                break;

            case "persona":
            case "personas":
                PanelProgreso.Visible = false;
                PanelAyuda.Visible    = false;
                PanelPersona.Visible  = true;
                PanelArticulo.Visible = false;
                Lbl.Personas.Persona Per;
                try {
                    Per = new Lbl.Personas.Persona(this.Connection, ItemSolicitado);
                } catch {
                    Per = null;
                }
                if (Per != null && Per.Existe)
                {
                    ElementoActual = Per;
                    ItemActual     = ItemSolicitado;
                    TablaActual    = TablaSolicitada;

                    PersonaNombre.Text    = Per.ToString();
                    PersonaDomicilio.Text = Per.Domicilio;
                    PersonaTelefono.Text  = Per.Telefono;
                    PersonaEmail.Text     = Per.Email;
                    if (Per.Grupo != null)
                    {
                        PersonaGrupo.Text = Per.Grupo.ToString();
                    }
                    else
                    {
                        PersonaGrupo.Text = "-";
                    }

                    decimal Saldo;

                    try {
                        Saldo = Per.CuentaCorriente.ObtenerSaldo(false);
                    } catch (Exception ex) {
                        System.Console.WriteLine(ex.ToString());
                        Saldo = 0;
                    }

                    if (Saldo > 0)
                    {
                        PersonaComentario.Text      = "Registra saldo impago en cuenta corriente por " + Lfx.Types.Formatting.FormatCurrency(Saldo, Lfx.Workspace.Master.CurrentConfig.Moneda.DecimalesFinal);
                        PersonaComentario.TextStyle = Lazaro.Pres.DisplayStyles.TextStyles.SmallWarning;
                        PersonaComentario.Visible   = true;
                    }
                    else if (Saldo < 0)
                    {
                        PersonaComentario.Text      = "Registra saldo a favor en cuenta corriente por " + Lfx.Types.Formatting.FormatCurrency(-Saldo, Lfx.Workspace.Master.CurrentConfig.Moneda.DecimalesFinal);
                        PersonaComentario.TextStyle = Lazaro.Pres.DisplayStyles.TextStyles.Small;
                        PersonaComentario.Visible   = true;
                    }
                    else
                    {
                        PersonaComentario.Visible = false;
                    }
                    PersonaImagen.Image  = Per.Imagen;
                    PanelPersona.Visible = true;
                }
                break;
            }
            this.ResumeLayout();
        }
Example #22
0
 /// <summary>
 /// Crea una instancia de un Lbl.ElementoDeDatos a partir de un id de registro.
 /// </summary>
 public static IElementoDeDatos Instanciar(Type tipo, Lfx.Data.IConnection dataBase, int id)
 {
     System.Reflection.ConstructorInfo TConstr = tipo.GetConstructor(new Type[] { typeof(Lfx.Data.Connection), typeof(int) });
     Lbl.IElementoDeDatos Res = (Lbl.IElementoDeDatos)(TConstr.Invoke(new object[] { dataBase, id }));
     return(Res);
 }
Example #23
0
 /// <summary>
 /// Guarda un elemento.
 /// </summary>
 /// <param name="mapa"></param>
 /// <param name="elemento"></param>
 protected virtual void GuardarElemento(MapaDeTabla mapa, Lbl.IElementoDeDatos elemento)
 {
     elemento.Guardar();
 }
Example #24
0
                private void ActualizarBarra()
                {
                        this.SuspendLayout();

                        switch (TablaSolicitada) {
                                case "articulo":
                                case "articulos":
                                        PanelProgreso.Visible = false;
                                        PanelAyuda.Visible = false;
                                        PanelPersona.Visible = false;
                                        PanelArticulo.Visible = true;
                                        Lbl.Articulos.Articulo Art;
                                        try {
                                                Art = new Lbl.Articulos.Articulo(this.DataBase, ItemSolicitado);
                                        } catch {
                                                Art = null;
                                        }
                                        if (Art != null && Art.Existe) {
                                                ElementoActual = Art;
                                                ItemActual = ItemSolicitado;
                                                TablaActual = TablaSolicitada;

                                                string Codigos = Art.Id.ToString();
                                                if (Art.Codigo1 != null && Art.Codigo1.Length > 0)
                                                        Codigos += System.Environment.NewLine + Art.Codigo1;
                                                if (Art.Codigo2 != null && Art.Codigo2.Length > 0)
                                                        Codigos += System.Environment.NewLine + Art.Codigo2;
                                                if (Art.Codigo3 != null && Art.Codigo3.Length > 0)
                                                        Codigos += System.Environment.NewLine + Art.Codigo3;
                                                if (Art.Codigo4 != null && Art.Codigo4.Length > 0)
                                                        Codigos += System.Environment.NewLine + Art.Codigo4;
                                                ArticuloCodigos.Text = Codigos;
                                                ArticuloNombre.Text = Art.ToString();
                                                ArticuloDescripcion.Text = Art.Descripcion;
                                                ArticuloPvp.Text = Lfx.Types.Formatting.FormatCurrency(Art.Pvp, Lfx.Workspace.Master.CurrentConfig.Moneda.Decimales);
                                                ArticuloStock.Text = Lfx.Types.Formatting.FormatCurrency(Art.Existencias, Lfx.Workspace.Master.CurrentConfig.Moneda.Decimales);
                                                PanelArticulo.Visible = true;
                                        }
                                        break;
                                case "persona":
                                case "personas":
                                        PanelProgreso.Visible = false;
                                        PanelAyuda.Visible = false;
                                        PanelPersona.Visible = true;
                                        PanelArticulo.Visible = false;
                                        Lbl.Personas.Persona Per;
                                        try {
                                                Per = new Lbl.Personas.Persona(this.DataBase, ItemSolicitado);
                                        } catch {
                                                Per = null;
                                        }
                                        if (Per != null && Per.Existe) {
                                                ElementoActual = Per;
                                                ItemActual = ItemSolicitado;
                                                TablaActual = TablaSolicitada;

                                                PersonaNombre.Text = Per.ToString();
                                                PersonaDomicilio.Text = Per.Domicilio;
                                                PersonaTelefono.Text = Per.Telefono;
                                                PersonaEmail.Text = Per.Email;
                                                if (Per.Grupo != null)
                                                        PersonaGrupo.Text = Per.Grupo.ToString();
                                                else
                                                        PersonaGrupo.Text = "-";
                                                decimal Saldo;
                                                try {
                                                        Saldo = Per.CuentaCorriente.ObtenerSaldo(false);
                                                } catch {
                                                        Saldo = 0;
                                                }
                                                if (Saldo > 0) {
                                                        PersonaComentario.Text = "Registra saldo impago en cuenta corriente por " + Lfx.Types.Formatting.FormatCurrency(Saldo, Lfx.Workspace.Master.CurrentConfig.Moneda.DecimalesFinal);
                                                        PersonaComentario.TextStyle = Lazaro.Pres.DisplayStyles.TextStyles.SmallWarning;
                                                        PersonaComentario.Visible = true;
                                                } else if (Saldo < 0) {
                                                        PersonaComentario.Text = "Registra saldo a favor en cuenta corriente por " + Lfx.Types.Formatting.FormatCurrency(-Saldo, Lfx.Workspace.Master.CurrentConfig.Moneda.DecimalesFinal);
                                                        PersonaComentario.TextStyle = Lazaro.Pres.DisplayStyles.TextStyles.Small;
                                                        PersonaComentario.Visible = true;
                                                } else {
                                                        PersonaComentario.Visible = false;
                                                }
                                                PersonaImagen.Image = Per.Imagen;
                                                PanelPersona.Visible = true;
                                        }
                                        break;
                        }
                        this.ResumeLayout();
                }
Example #25
0
                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;
                }