private void LoadControls(cUtenti u, bool forza = false) { if (forza || u.ID > -1) { var p = ""; bScegliDB.Enabled = false; try { p = Path.GetDirectoryName(u.Path); } catch { //not found } if (cGB.sDB == null) { cGB.DatiDBFisico = new cUtenti(u.ID); cGB.sDB = new cDB(true, cDB.DataBase.SQLite); } var dbU = new cDBInfo(u.Email); ePsw.Text = dbU.Psw; eNome.Text = dbU.Nome; eEmail.Text = dbU.Email; ePathDB.Text = p; RecuperaDB = u.Path; eValuta.SelectedValue = dbU.Valuta; var jem = u.Email; if (jem == null || jem.Equals("")) { jem = eNome.Text; } CaricaImg(Path.Combine(ePathDB.Text, jem + ".jpg")); } }
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); if (cGB.ControllaGiaInEsecuzione_SeContinuare()) { Inizio: cGB.DoTheAutoUpdate(); try { cGB.RestartMe = false; cGB.sPC = new cDB(false, cDB.DataBase.SQLite, cGB.PathDBUtenti); } catch (Exception ex) { cGB.MsgBox("Errore apertura DB: " + ex.Message); } var CaricaQuestoIDUtente = -1; if (cGB.Parametri != null && !cGB.Parametri.Equals("") && File.Exists(cGB.Parametri)) //se fai doppio click su un file { var u = new cUtenti(); u.CaricaByPath(cGB.Parametri); CaricaQuestoIDUtente = u.ID; if (u.ID < 0) { using (var du = new fDettaglioUtente()) { du.DBPath = cGB.Parametri; du.ShowDialog(); } } } var ok = false; if (CaricaQuestoIDUtente > -1) { var u = new cUtenti(CaricaQuestoIDUtente); if (u.ID > -1) { var ute = new cDBInfo(u.Email); using (var psw = new fPsw(ute.Email, ute.Psw)) ok = psw.ShowDialog() == DialogResult.OK; } } else { try { using (var fus = new fListaUtenti()) { ok = fus.ShowDialog() == DialogResult.OK; if (ok) { CaricaQuestoIDUtente = fus.IDUtente; } } } catch (Exception ex) { cGB.MsgBox("Errore lista utenti: " + ex.Message); } } if (ok) { cGB.DatiDBFisico = new cUtenti(CaricaQuestoIDUtente); cGB.sDB = new cDB(true, cDB.DataBase.SQLite); cGB.DatiUtente = new cDBInfo(cGB.DatiDBFisico.Email); cGB.ControllaDBSulServer(); if (cGB.sDB.Connessione.State == ConnectionState.Closed) { cGB.sDB.Connessione.Open(); } cGB.initCulture(); Application.CurrentCulture = cGB.valutaCorrente; Thread.CurrentThread.CurrentUICulture = CultureInfo.InstalledUICulture; //System.Threading.Thread.CurrentThread.CurrentCulture = cGB.valutaCorrente; //System.Threading.Thread.CurrentThread.CurrentUICulture = cGB.valutaCorrente; using (cGB.RationesCurareMainForm = new fMain()) { Application.Run(cGB.RationesCurareMainForm); if (cGB.RestartMe) { goto Inizio; } //if (!cGB.IAmInDebug) if (cGB.DatiUtente.SincronizzaDB) { cGB.sDB.SQLiteVacuum(); var mc = new MikyCloud(cGB.DatiDBFisico.Path, cGB.DatiUtente.Email, cGB.DatiUtente.Psw); mc.MandaDBSulSito(cGB.sDB.UltimaModifica); } } } } }
private void Salva() { var erro = false; var a = ""; if (cGB.MsgBox("Tutto corretto?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { if (Controlla()) { var dbda = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); dbda = Path.Combine(dbda, "standard.rqd8"); a = Path.Combine(ePathDB.Text, eEmail.Text + ".rqd8"); if (RecuperaDB.Equals("")) { //crea DB nuovo if (ID__ <= -1) { try { if (!Directory.Exists(ePathDB.Text)) { Directory.CreateDirectory(ePathDB.Text); } if (!File.Exists(a)) { File.Copy(dbda, a, false); } } catch (Exception ex) { erro = true; cGB.MsgBox("Errore! : " + ex.Message, MessageBoxIcon.Error); } } } else { // recupero DB try { if (!Directory.Exists(ePathDB.Text)) { Directory.CreateDirectory(ePathDB.Text); } if (!File.Exists(a)) { File.Copy(RecuperaDB, a, false); } } catch (Exception ex) { erro = true; cGB.MsgBox("Errore! : " + ex.Message, MessageBoxIcon.Error); } } //copia img try { var t = Path.GetExtension(ImgPath); var imga = Path.Combine(ePathDB.Text, eEmail.Text); File.Copy(ImgPath, Path.ChangeExtension(imga + t, ".jpg"), true); } catch //(Exception ex) { //erro = true; //cGB.MsgBox("Errore! : " + ex.Message, MessageBoxIcon.Error); } if (!erro) { cGB.sDB = new cDB(true, cDB.DataBase.SQLite, a); var x = new cUtenti(ID_) { Nome = eNome.Text, Psw = ePsw.Text, Email = eEmail.Text, Path = a, TipoDB = "S" }; var u = new cDBInfo(eEmail.Text) { Nome = eNome.Text, Psw = ePsw.Text, Email = eEmail.Text, UltimaModifica = DateTime.Now, Valuta = eValuta.SelectedValue as string }; if (x.Salva() > 0 && (u.DatiCaricati && u.Aggiorna() > 0 || u.Inserisci() > 0)) { DialogResult = DialogResult.OK; } else { MsgErroreSalvataggio(); } } } } }