コード例 #1
0
        public void OneTimeSetUp()
        {
            Lfx.Workspace.Master           = new Lfx.Workspace("test", false, false);
            Lfx.Workspace.Master.DebugMode = true;

            // Habilito el gestor de configuración
            Lbl.Sys.Config.Actual = new Lbl.Sys.Configuracion.Global();
            Lbl.Sys.Config.Cargar();

            // Habilito la recuperación de conexiones
            Lfx.Workspace.Master.MasterConnection.EnableRecover = false;

            //Lbl.Componentes.Cargador.CargarComponentes();

            Connection = Lfx.Workspace.Master.GetNewConnection("Pruebas unitarias") as Lfx.Data.Connection;
            Trans      = Connection.BeginTransaction();
        }
コード例 #2
0
        private void FormPrincipal_KeyDown(object sender, KeyEventArgs e)
        {
            switch (e.KeyCode)
            {
            case Keys.F10:
            case Keys.F12:
                if (e.Shift == false && e.Alt == false && e.Shift == false)
                {
                    e.Handled = true;
                    if (FormInicio == null)
                    {
                        MostrarAyuda("Menú principal", "Utilice las teclas de cursor (flechas) para navegar el menú. Pulse <Intro> (o <Enter>) para ejecutar una opción.");
                        System.Windows.Forms.SendKeys.Send("%S");
                    }
                    else
                    {
                        MostrarAyuda("Pantalla de inicio", "Si no encuentra lo que busca en la pantalla de inicio utilice el menú en la parte superior.");
                        FormInicio.Focus();
                    }
                }
                break;

            case Keys.I:
                if (e.Control == true && e.Alt == true && Lbl.Sys.Config.Actual.UsuarioConectado.TieneAccesoGlobal())
                {
                    e.Handled = true;
                    System.Windows.Forms.OpenFileDialog DialogoArchivo = new System.Windows.Forms.OpenFileDialog();
                    DialogoArchivo.DefaultExt  = "sql";
                    DialogoArchivo.Filter      = "Archivo SQL|*.sql";
                    DialogoArchivo.Multiselect = false;
                    DialogoArchivo.Title       = "Inyectar SQL";
                    if (DialogoArchivo.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        using (System.IO.Stream Archivo = System.IO.File.OpenRead(DialogoArchivo.FileName))
                            using (System.IO.StreamReader Lector = new System.IO.StreamReader(Archivo, System.Text.Encoding.Default))
                                using (Lfx.Data.Connection ConexionActualizar = Lfx.Workspace.Master.GetNewConnection("Inyectar SQL"))
                                    using (IDbTransaction Trans = ConexionActualizar.BeginTransaction()) {
                                        string SqlActualizacion = ConexionActualizar.CustomizeSql(Lector.ReadToEnd());
                                        do
                                        {
                                            string Comando = Lfx.Data.Connection.GetNextCommand(ref SqlActualizacion);
                                            try {
                                                ConexionActualizar.ExecuteSql(Comando);
                                            } catch (Exception ex) {
                                                Lfx.Workspace.Master.RunTime.Toast(Comando + System.Environment.NewLine + System.Environment.NewLine + ex.Message, "Error al inyectar datos");
                                            }
                                        }while (SqlActualizacion.Length > 0);
                                        Trans.Commit();
                                    }
                    }
                }
                break;

            case Keys.B:
                if (e.Control && e.Alt == false && e.Shift == false)
                {
                    e.Handled             = true;
                    BarraInferior.Visible = !BarraInferior.Visible;
                    Lfx.Workspace.Master.CurrentConfig.WriteLocalSetting("Sistema", "Apariencia.BarraInformacion", BarraInferior.Visible ? 1 : 0);
                }
                break;

            case Keys.J:
                if (e.Control == true && e.Alt == false && e.Shift == false)
                {
                    e.Handled = true;
                    string Cmd = Lui.Forms.InputBox.ShowInputBox("Comando");
                    if (Cmd != null && Cmd.Length > 0)
                    {
                        Ejecutor.Exec(Cmd);
                    }
                }
                break;

            case Keys.F:
                if (e.Control == true && e.Alt == false && e.Shift == false)
                {
                    e.Handled = true;
                    Ejecutor.Exec("CREAR Lbl.Comprobantes.Factura");
                }
                break;

            case Keys.T:
                if (e.Control == true && e.Alt == false && e.Shift == false)
                {
                    e.Handled = true;
                    Ejecutor.Exec("CREAR Lbl.Comprobantes.Ticket");
                }
                break;

            case Keys.P:
                if (e.Control == true && e.Alt == false && e.Shift == false)
                {
                    e.Handled = true;
                    Ejecutor.Exec("CREAR Lbl.Comprobantes.Presupuesto");
                }
                break;

            case Keys.R:
                if (e.Control == true && e.Alt == false && e.Shift == false)
                {
                    e.Handled = true;
                    Ejecutor.Exec("CREAR Lbl.Comprobantes.ReciboDeCobro");
                }
                break;

            case Keys.L:
                if (e.Control == true && e.Alt == false && e.Shift == false)
                {
                    e.Handled = true;
                    Ejecutor.Exec("CALC");
                }
                break;
            }
        }
コード例 #3
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);
        }
コード例 #4
0
ファイル: Manager.cs プロジェクト: solutema/ultralight
        public void Restore(string backupName)
        {
            string Carpeta = backupName + System.IO.Path.DirectorySeparatorChar;

            Lfx.Environment.Folders.EnsurePathExists(this.BackupPath);

            if (Carpeta != null && Carpeta.Length > 0 && System.IO.Directory.Exists(this.BackupPath + Carpeta))
            {
                bool UsandoArchivoComprimido = false;

                Lfx.Types.OperationProgress Progreso = new Lfx.Types.OperationProgress("Restaurando copia de seguridad", "Este proceso va a demorar varios minutos. Por favor no lo interrumpa");
                Progreso.Modal = true;

                /* Progreso.ChangeStatus("Descomprimiendo");
                 * // Descomprimir backup si está comprimido
                 * if (System.IO.File.Exists(BackupPath + Carpeta + "backup.7z")) {
                 *      Lfx.FileFormats.Compression.Archive ArchivoComprimido = new Lfx.FileFormats.Compression.Archive(BackupPath + Carpeta + "backup.7z");
                 *      ArchivoComprimido.ExtractAll(BackupPath + Carpeta);
                 *      UsandoArchivoComprimido = true;
                 * } */

                Progreso.ChangeStatus("Eliminando datos actuales");
                using (Lfx.Data.Connection DataBase = Lfx.Workspace.Master.GetNewConnection("Restauración de copia de seguridad")) {
                    Progreso.ChangeStatus("Acomodando estructuras");
                    Lfx.Workspace.Master.Structure.TagList.Clear();
                    Lfx.Workspace.Master.Structure.LoadFromFile(this.BackupPath + Carpeta + "dbstruct.xml");
                    Lfx.Workspace.Master.CheckAndUpdateDataBaseVersion(true, true);

                    using (BackupReader Lector = new BackupReader(this.BackupPath + Carpeta + "dbdata.lbd"))
                        using (IDbTransaction Trans = DataBase.BeginTransaction()) {
                            DataBase.EnableConstraints(false);

                            Progreso.ChangeStatus("Incorporando tablas de datos");

                            Progreso.Max = (int)(Lector.Length / 1024);
                            string           TablaActual   = null;
                            string[]         ListaCampos   = null;
                            object[]         ValoresCampos = null;
                            int              CampoActual   = 0;
                            bool             EndTable      = false;
                            qGen.BuilkInsert Insertador    = new qGen.BuilkInsert();
                            do
                            {
                                string Comando = Lector.ReadString(4);
                                switch (Comando)
                                {
                                case ":TBL":
                                    TablaActual = Lector.ReadPrefixedString4();
                                    string NombreTabla;
                                    if (Lfx.Workspace.Master.Structure.Tables.ContainsKey(TablaActual) && Lfx.Workspace.Master.Structure.Tables[TablaActual].Label != null)
                                    {
                                        NombreTabla = Lfx.Workspace.Master.Structure.Tables[TablaActual].Label;
                                    }
                                    else
                                    {
                                        NombreTabla = TablaActual.ToTitleCase();
                                    }
                                    EndTable = false;
                                    Progreso.ChangeStatus("Cargando " + NombreTabla);

                                    qGen.Delete DelCmd = new qGen.Delete(TablaActual);
                                    DelCmd.EnableDeleleteWithoutWhere = true;
                                    DataBase.Execute(DelCmd);
                                    break;

                                case ":FDL":
                                    ListaCampos   = Lector.ReadPrefixedString4().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                                    ValoresCampos = new object[ListaCampos.Length];
                                    CampoActual   = 0;
                                    break;

                                case ":FLD":
                                    ValoresCampos[CampoActual++] = Lector.ReadField();
                                    break;

                                case ".ROW":
                                    qGen.Insert Insertar = new qGen.Insert(TablaActual);
                                    for (int i = 0; i < ListaCampos.Length; i++)
                                    {
                                        Insertar.Fields.AddWithValue(ListaCampos[i], ValoresCampos[i]);
                                    }
                                    Insertador.Add(Insertar);

                                    ValoresCampos = new object[ListaCampos.Length];
                                    CampoActual   = 0;
                                    break;

                                case ":REM":
                                    Lector.ReadPrefixedString4();
                                    break;

                                case ".TBL":
                                    EndTable = true;
                                    break;
                                }
                                if (EndTable || Insertador.Count >= 1000)
                                {
                                    if (Insertador.Count > 0)
                                    {
                                        DataBase.Execute(Insertador);
                                    }
                                    Insertador.Clear();
                                    Progreso.Value = (int)(Lector.Position / 1024);
                                }
                            } while (Lector.Position < Lector.Length);
                            Lector.Close();

                            if (Lfx.Workspace.Master.MasterConnection.SqlMode == qGen.SqlModes.PostgreSql)
                            {
                                // PostgreSql: Tengo que actualizar las secuencias
                                Progreso.ChangeStatus("Actualizando secuencias");
                                string PatronSecuencia = @"nextval\(\'(.+)\'(.*)\)";
                                foreach (string Tabla in Lfx.Data.DataBaseCache.DefaultCache.GetTableNames())
                                {
                                    string OID = DataBase.FieldString("SELECT c.oid FROM pg_catalog.pg_class c LEFT JOIN pg_catalog.pg_namespace n ON n.oid=c.relnamespace WHERE pg_catalog.pg_table_is_visible(c.oid) AND c.relname ~ '^" + Tabla + "$'");
                                    System.Data.DataTable Campos = DataBase.Select("SELECT a.attname,pg_catalog.format_type(a.atttypid, a.atttypmod),(SELECT substring(d.adsrc for 128) FROM pg_catalog.pg_attrdef d WHERE d.adrelid = a.attrelid AND d.adnum = a.attnum AND a.atthasdef), a.attnotnull, a.attnum FROM pg_catalog.pg_attribute a WHERE a.attrelid = '" + OID + "' AND a.attnum > 0 AND NOT a.attisdropped ORDER BY a.attnum");
                                    foreach (System.Data.DataRow Campo in Campos.Rows)
                                    {
                                        if (Campo[2] != DBNull.Value && Campo[2] != null)
                                        {
                                            string DefaultCampo = System.Convert.ToString(Campo[2]);
                                            if (Regex.IsMatch(DefaultCampo, PatronSecuencia))
                                            {
                                                string NombreCampo = System.Convert.ToString(Campo[0]);
                                                foreach (System.Text.RegularExpressions.Match Ocurrencia in Regex.Matches(DefaultCampo, PatronSecuencia))
                                                {
                                                    string Secuencia = Ocurrencia.Groups[1].ToString();
                                                    int    MaxId     = DataBase.FieldInt("SELECT MAX(" + NombreCampo + ") FROM " + Tabla) + 1;
                                                    DataBase.ExecuteSql("ALTER SEQUENCE " + Secuencia + " RESTART WITH " + MaxId.ToString());
                                                }
                                            }
                                        }
                                    }
                                }
                            }

                            if (System.IO.File.Exists(this.BackupPath + Carpeta + "blobs.lst"))
                            {
                                // Incorporar Blobs
                                Progreso.ChangeStatus("Incorporando imágenes");
                                System.IO.StreamReader LectorBlobs = new System.IO.StreamReader(this.BackupPath + Carpeta + "blobs.lst", System.Text.Encoding.Default);
                                string InfoImagen = null;
                                do
                                {
                                    InfoImagen = LectorBlobs.ReadLine();
                                    if (InfoImagen != null && InfoImagen.Length > 0)
                                    {
                                        string Tabla               = Lfx.Types.Strings.GetNextToken(ref InfoImagen, ",");
                                        string Campo               = Lfx.Types.Strings.GetNextToken(ref InfoImagen, ",");
                                        string CampoId             = Lfx.Types.Strings.GetNextToken(ref InfoImagen, ",");
                                        string NombreArchivoImagen = Lfx.Types.Strings.GetNextToken(ref InfoImagen, ",");

                                        // Guardar blob nuevo
                                        qGen.Update ActualizarBlob = new qGen.Update(DataBase, Tabla);
                                        ActualizarBlob.WhereClause = new qGen.Where(Campo, CampoId);

                                        System.IO.FileStream ArchivoImagen = new System.IO.FileStream(this.BackupPath + Carpeta + NombreArchivoImagen, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                                        byte[] Contenido = new byte[System.Convert.ToInt32(ArchivoImagen.Length) - 1 + 1];
                                        ArchivoImagen.Read(Contenido, 0, System.Convert.ToInt32(ArchivoImagen.Length));
                                        ArchivoImagen.Close();

                                        ActualizarBlob.Fields.AddWithValue(Campo, Contenido);
                                        DataBase.Execute(ActualizarBlob);
                                    }
                                }while (InfoImagen != null);
                                LectorBlobs.Close();
                            }

                            if (UsandoArchivoComprimido)
                            {
                                Progreso.ChangeStatus("Eliminando archivos temporales");
                                // Borrar los archivos que descomprim temporalmente
                                System.IO.DirectoryInfo Dir = new System.IO.DirectoryInfo(this.BackupPath + Carpeta);
                                foreach (System.IO.FileInfo DirItem in Dir.GetFiles())
                                {
                                    if (DirItem.Name != "backup.7z" && DirItem.Name != "info.txt")
                                    {
                                        System.IO.File.Delete(this.BackupPath + Carpeta + DirItem.Name);
                                    }
                                }
                            }
                            Progreso.ChangeStatus("Terminando transacción");
                            Trans.Commit();
                        }
                    Progreso.End();
                }

                Lfx.Workspace.Master.RunTime.Toast("La copia de seguridad se restauró con éxito. A continuación se va a reiniciar la aplicación.", "Copia Restaurada");
            }
        }