private void Modifica(bool nuovo)
        {
            var continua = true;

            if (!nuovo)
            {
                continua = ChiediPsw(GetSelectedUserIndex());
            }

            if (continua)
            {
                using (var f = new fDettaglioUtente())
                {
                    if (!nuovo)
                    {
                        f.ID_ = GetSelectedUserID();
                    }

                    if (f.ShowDialog() == DialogResult.OK)
                    {
                        Carica();
                    }
                }
            }
        }
        private void AggiungiQuestoDBAllaLista(string FileName, string psw)
        {
            if (System.IO.File.Exists(FileName))
            {
                var Presente = false;
                var u        = new DB.DataWrapper.cUtente();
                u.CaricaByPath(FileName);

                if (u.ID > -1)
                {
                    for (var i = 0; i < (eUtenti?.Length ?? 0); i++)
                    {
                        if (eUtenti[i].ID_ == u.ID)
                        {
                            Presente = true;
                            cGB.MsgBox("Questo utente è gia presente!", MessageBoxIcon.Exclamation);
                            break;
                        }
                    }
                }

                if (!Presente)
                {
                    u.nome           = System.IO.Path.GetFileNameWithoutExtension(FileName);
                    u.path           = FileName;
                    u.Email          = u.nome;
                    u.psw            = psw;
                    u.UltimaModifica = DateTime.Now;
                    u.SetTipoDBByExtension(System.IO.Path.GetExtension(FileName));

                    using (var fd = new fDettaglioUtente(u))
                        if (fd.ShowDialog() == DialogResult.OK)
                        {
                            Carica();
                        }
                }
            }
        }
        private void AggiungiQuestoDBAllaLista(string FileName, string psw)
        {
            if (File.Exists(FileName))
            {
                var Presente = false;
                var u        = new cUtenti();
                u.CaricaByPath(FileName);

                if (u.ID > -1)
                {
                    for (var i = 0; i < (eUtenti?.Length ?? 0); i++)
                    {
                        if (eUtenti[i].ID_ == u.ID)
                        {
                            Presente = true;
                            cGB.MsgBox("Questo utente è gia presente!", MessageBoxIcon.Exclamation);
                            break;
                        }
                    }
                }

                if (!Presente)
                {
                    u.Nome  = Path.GetFileNameWithoutExtension(FileName);
                    u.Path  = FileName;
                    u.Email = u.Nome;
                    u.SetTipoDBByExtension(Path.GetExtension(FileName));

                    cGB.sDB = new cDB(false, cDB.DataBase.SQLite, FileName);

                    using (var fd = new fDettaglioUtente(u))
                        if (fd.ShowDialog() == DialogResult.OK)
                        {
                            Carica();
                        }
                }
            }
        }
Beispiel #4
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();
                    }
                }
            }
        }
    }