async void OnAggiungiClicked(object sender, System.EventArgs e) { var fat = new Fatture(); LocalImpo lim = null; Agenti age = null; SQLiteAsyncConnection dbcon_ = DependencyService.Get <ISQLiteDb>().GetConnection(); busyIndicator.IsBusy = true; // // Leggiamo le impostazioni // try { lim = await dbcon_.GetAsync <LocalImpo>(1); } catch { busyIndicator.IsBusy = false; await DisplayAlert("Attenzione!", "Impostazioni locali non trovate!\nRiavviare l'App.", "OK"); return; } if (!lim.data_download) { busyIndicator.IsBusy = false; await DisplayAlert("Attenzione!", "Dati non presenti sul dispositivo!\nPer procedere è necessario scaricare i dati dal server.", "OK"); return; } if (string.IsNullOrWhiteSpace(lim.registro)) { busyIndicator.IsBusy = false; await DisplayAlert("Attenzione!", "Registro non impostato!\nPer inserire documenti è necessario fare le impostazioni iniziali.", "OK"); return; } if (lim.age == 0) { busyIndicator.IsBusy = false; await DisplayAlert("Attenzione!", "Agente non impostato!\nPer inserire documenti è necessario fare le impostazioni iniziali.", "OK"); return; } if (lim.dep == 0) { busyIndicator.IsBusy = false; await DisplayAlert("Attenzione!", "Deposito non impostato!\nPer inserire documenti è necessario fare le impostazioni iniziali.", "OK"); return; } // // Leggiamo i dati dell' agente // try { age = await dbcon_.GetAsync <Agenti>(lim.age); } catch { busyIndicator.IsBusy = false; await DisplayAlert("Attenzione!", "L' Agente impostato non è presente in archivio!", "OK"); return; } bool nuova = true; // // Inizializziamo il documento // fat.fat_n_doc = 1; fat.fat_tipo = (short)tipo_; fat.fat_registro = lim.registro; fat.fat_d_doc = DateTime.Now; fat.fat_editable = true; fat.fat_local_doc = true; fat.fat_age = lim.age; try { fat.fat_n_doc = 1; var sql = string.Format("SELECT * FROM fatture2 WHERE fat_tipo = {0} AND fat_n_doc > {1} AND fat_n_doc <= {2} ORDER BY fat_n_doc DESC LIMIT 1", (short)tipo_, RsaUtils.GetFirstRegNumber(lim.registro), RsaUtils.GetLastRegNumber(lim.registro)); var list = await dbcon_.QueryAsync <Fatture>(sql); foreach (var doc in list) { fat.fat_n_doc += doc.fat_n_doc; break; } } catch (Exception ex) { await DisplayAlert("Attenzione!", ex.Message, "OK"); return; } var page = new DocumentiEdit(ref fat, ref nuova); await Navigation.PushAsync(page); busyIndicator.IsBusy = false; }