예제 #1
0
        IDBTable GetTable(uint tableID, bool connect)
        {
            IDBTable tbl = AllTables.FirstOrDefault(t => t.ID == tableID);

            if (!connect)
            {
                return(tbl);
            }

            Dbg.Assert(Program.Settings.ClientInfo != null);

            if (tbl != null)
            {
                if (!tbl.IsConnected)
                {
                    try
                    {
                        tbl.Connect();

                        if (tbl.Tag != Program.Settings.ClientInfo.ClientID)
                        {
                            throw new BadTagException(tbl.Name);
                        }
                    }
                    catch (FileNotFoundException)
                    {
                        System.Diagnostics.Debug.WriteLine($"Impossible d'ouvrir la table {tbl.Name}\nLancement de la procedure de création...");

                        try
                        {
                            tbl.Create(1, Program.Settings.ClientInfo.ClientID);
                        }
                        catch (Exception ex)
                        {
                            System.Diagnostics.Debug.WriteLine($"Erreur lors de la création du fichier!\n Exception: {ex.Message}");
                            throw;
                        }

                        System.Diagnostics.Debug.WriteLine("Création ok");
                    }
                }
            }

            return(tbl);
        }