Пример #1
0
        public static void ApriConnessione(DataBase db_, string path_db = "", bool ForceClose = false)
        {
            DataBaseAttuale = db_;
            var s = DammiStringaConnessione(path_db);

            if (ForceClose)
            {
                ChiudiConnessione();
            }

            try
            {
                if (DataBaseAttuale == DataBase.Access)
                {
                    Connessione = new System.Data.OleDb.OleDbConnection(s);
                }
                else if (DataBaseAttuale == DataBase.SQLite)
#if __MonoCS__
                { Connessione = new Mono.Data.Sqlite.SqliteConnection(s); }
#else
                { Connessione = new System.Data.SQLite.SQLiteConnection(s); }
#endif

                Connessione.Open();
            }
            catch (Exception ex)
            {
                cGB.MsgBox("Non riesco a connettermi al DB (" + ex.Message + ")", System.Windows.Forms.MessageBoxIcon.Error);
            }

            try
            {
                var ca = new DataWrapper.cAggiornamenti();
                ca.EseguiUpdate();
            }
            catch
            {
                //errore
            }
        }
Пример #2
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            if (cGB.ControllaGiaInEsecuzione_SeContinuare())
            {
Inizio:
                cGB.DoTheAutoUpdate();

                try
                {
                    cGB.RestartMe        = false;
                    cGB.OpzioniProgramma = cOpzioniProgramma.Carica();

                    DB.cDB.ApriConnessione(DB.cDB.DataBase.SQLite, cGB.PathDBUtenti, true);
                }
                catch (Exception ex)
                {
                    cGB.MsgBox("Errore apertura DB: " + ex.Message);
                }

                var CaricaQuestoIDUtente = -1;
                if (cGB.Parametri != null && !cGB.Parametri.Equals("") && System.IO.File.Exists(cGB.Parametri)) //se fai doppio click su un file
                {
                    var u = new DB.DataWrapper.cUtente();
                    u.CaricaByPath(cGB.Parametri);

                    CaricaQuestoIDUtente = u.ID;

                    if (u.ID < 0)
                    {
                        using (var du = new UI.Forms.fDettaglioUtente())
                        {
                            du.DBPath = cGB.Parametri;
                            du.ShowDialog();
                        }
                    }
                }

                var ok = false;
                if (CaricaQuestoIDUtente > -1)
                {
                    var u = new DB.DataWrapper.cUtente(CaricaQuestoIDUtente);

                    if (u.ID > -1)
                    {
                        using (var psw = new UI.Forms.fPsw(u.Email, u.psw))
                            ok = (psw.ShowDialog() == DialogResult.OK);
                    }

                    if (ok)
                    {
                        cGB.UtenteConnesso = new cGB.sUtente()
                        {
                            PathDB   = u.path,
                            UserName = u.nome,
                            ID       = u.ID,
                            Psw      = u.psw,
                            Email    = u.Email,
                            TipoDB   = u.TipoDB
                        }
                    }
                    ;
                }
                else
                {
                    try
                    {
                        using (var fus = new UI.Forms.fListaUtenti())
                            ok = (fus.ShowDialog() == DialogResult.OK);
                    }
                    catch (Exception ex)
                    {
                        cGB.MsgBox("Errore lista utenti: " + ex.Message);
                    }
                }

                if (ok)
                {
                    cGB.ControllaDBSulServer();

                    DB.cDB.ApriConnessione(cGB.UtenteConnesso.TipoDB.Equals("S") ? DB.cDB.DataBase.SQLite : DB.cDB.DataBase.Access, true);

                    using (cGB.RationesCurareMainForm = new UI.Forms.fMain())
                    {
                        Application.Run(cGB.RationesCurareMainForm);

                        cGB.UtenteConnesso.ID = -1;
                        if (cGB.RestartMe)
                        {
                            goto Inizio;
                        }

                        //if (!cGB.IAmInDebug)
                        if (cGB.OpzioniProgramma.SincronizzaDB)
                        {
                            var mc = new GB.MikyCloud(cGB.UtenteConnesso);
                            mc.MandaDBSulSito(DB.cDB.UltimaModifica);
                        }

                        DB.cDB.ApriConnessione(DB.cDB.DataBase.SQLite, cGB.PathDBUtenti, true);

                        var ca = new DB.DataWrapper.cAggiornamenti();
                        ca.AggiornaDataDB(DB.cDB.UltimaModifica);

                        DB.cDB.ChiudiConnessione();
                    }
                }
            }
        }
    }