// - -  - -  - -  - -  - -  - -  - -  - -  - -  - -  - -  - -  - -  - -  -

        public void OpenDB(HttpRequest request)
        {
            if (DB_SQL._ViewModel == null || !DB_SQL._ViewModel.CheckConnection())
            {
                string ConnectionString = GetConnectionString("ZeConnectionString");

                //#if DEBUG
                if (string.IsNullOrEmpty(ConnectionString))
                {
                    //if (request.Host.ToString().ToUpper().Contains("DEV") || request.Host.ToString().ToUpper().Contains("LOCALHOST"))
                    //{
                    //   string Server = "sql6005.site4now.net";
                    //   string DBase = "DB_A44F11_StockAPPro2dev";
                    //   string User = "******";
                    //   string Password = "";

                    //   ConnectionString = $"Data Source={Server};Initial Catalog={DBase};Persist Security Info=True;User ID={User};Password={Password};MultipleActiveResultSets=True";
                    //}
                    //else
                    {
                        string Server   = "sql6007.site4now.net";
                        string DBase    = "DB_A44F11_HorsDA";
                        string User     = "******";
                        string Password = "******";

                        ConnectionString = $"Data Source={Server};Initial Catalog={DBase};Persist Security Info=True;User ID={User};Password={Password};MultipleActiveResultSets=True";
                    };
                }
                ;
                //#endif

                if (string.IsNullOrEmpty(ConnectionString))
                {
                    MainViewModel.Current.Connection.LastError = "No ConnectionString ...";
                    return;
                }
                ;

                Connection        = new DBSQLViewModel(new SQLServerEngine());
                DB_SQL._ViewModel = Connection;
                Log.Write("", $"{ConnectionString} {(Connection.Open(ConnectionString, true) ? "OK" : "KO")}");

                //CleanAuditTrail();
                //ToDo:  UpdateSessions();

                //if (!MainViewModel.Current.CheckDB())
                //{
                //   Log.Write(new AuditTrail()
                //   {
                //      Application = "wsStockAPPro",
                //      Message = "Version de base de données incompatible!",
                //      Level = ErrorLevel.Critical,
                //   });
                //};
            }
            ;
        }
        public void Init_AT_SQLServer2()
        {
            string server   = "SQL6005.site4now.net";
            string db       = "DB_A44F11_StockAPPro2dev";
            string user     = "******";
            string password = "******";

            DBSQLViewModel AuditTrailConnection = null;

            AuditTrailConnection = new DBSQLViewModel(new SQLServerEngine());
            string AT_ConnectionString = DB_SQL.GenConnectionString(DBType.SQLServer, server, db, user, password);

            AuditTrailConnection.Open(AT_ConnectionString, true);

            AuditTrailViewModel.Current.Init(new DBAndFileAuditTrailWriter(AuditTrailConnection, string.Format(@"{0}", AuditTrailFileName)));
            // AuditTrailViewModel.Current.MaxLines = 5;
            //AuditTrailViewModel.Current.Clean(); // prend en compte uniquement nombre ligne

            Assert.AreEqual(true, AuditTrailConnection.CheckConnection());
        }
        public void Init_AT_PG()
        {
            string server   = "postgresql-zpf.alwaysdata.net";
            string db       = "zpf_postgresql";
            string user     = "******";
            string password = "******";

            DBSQLViewModel AuditTrailConnection = null;

            AuditTrailConnection = new DBSQLViewModel(new PostgreSQLEngine());
            string AT_ConnectionString = DB_SQL.GenConnectionString(DBType.PostgreSQL, server, db, user, password);

            AuditTrailConnection.Open(AT_ConnectionString, true);

            AuditTrailViewModel.Current.Init(new DBAndFileAuditTrailWriter(AuditTrailConnection, string.Format(@"{0}", AuditTrailFileName)));
            AuditTrailViewModel.Current.MaxLines = 5;
            AuditTrailViewModel.Current.Clean(); // prend en compte uniquement nombre ligne

            Assert.AreEqual(true, AuditTrailConnection.CheckConnection());
        }