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; }
public async Task <int> PrintDocHeaderAsync(Fatture doc, int row, bool stprice) { Destinazioni dst = null; Agenti age = null; var cli = await dbcon_.GetAsync <Clienti>(doc.fat_inte); if (doc.fat_dest != 0) { dst = await dbcon_.GetAsync <Destinazioni>(doc.fat_dest); } if (doc.fat_age != 0) { age = await dbcon_.GetAsync <Agenti>(doc.fat_age); } int col = 0; int last_hor = 0; string logo = ""; IFolder rootFolder = FileSystem.Current.LocalStorage; string path = rootFolder.Path + "/images/" + "logo.prn"; IFile file = await rootFolder.CreateFileAsync(path, CreationCollisionOption.OpenIfExists); if (file != null) { logo = await file.ReadAllTextAsync(); } string str = "^XA" + // Inizializziamo la stampa "^PW800" + // Settiamo la Larghezza "^MN" + // Settiamo la stampa in continuos mode "^POI" + "^LH0,0"; // Settiamo la posizione Iniziale // Settiamo la lunghezza iniziale del modulo str = str + $"^LL{_mod_len}"; if (logo != "") { str = str + logo; } col = 0; row = 30 * 8; // Scriviamo il Tipo di Documento string num = ""; switch (doc.fat_tipo) { case (int)DocTipo.TIPO_BOL: num = "B O L L A"; break; case (int)DocTipo.TIPO_DDT: num = "DOCUMENTO GENERALE DI TRASPORTO"; break; case (int)DocTipo.TIPO_BUO: num = "B U O N O D I C O N S E G N A"; break; case (int)DocTipo.TIPO_ORD: num = "O R D I N E"; break; default: num = "FATTURA/NOTA CONSEGNA TENTATA VENDITA D.P.R.472/96 art.1 comma 3"; break; } str = str + $"^FO{col},{row}" + "^A0,N,23,23" + $"^FB784,1,0,R,0^FD{num}^FS"; // Disegniamo il box col = 0; row += 3 * 8; last_hor = row; str = str + $"^FO{col},{row}" + "^GB800,388,2^FS"; row += 1 * 8; col = 3; str = str + $"^FO{col},{row}" + "^A0,N,19,19" + "^FDNum. Doc.^FS"; col = 16 * 8; str = str + $"^FO{col},{row}" + "^A0,N,19,19" + "^FDData^FS"; col = 32 * 8; str = str + $"^FO{col},{row}" + "^A0,N,19,19" + "^FDCod.Cli.^FS"; col = 42 * 8; str = str + $"^FO{col},{row}" + "^A0,N,19,19" + "^FDCod.Age.^FS"; col = 52 * 8; str = str + $"^FO{col},{row}" + "^A0,N,19,19" + "^FDTarga^FS"; col = 73 * 8; str = str + $"^FO{col},{row}" + "^A0,N,19,19" + "^FDTelefono^FS"; // Tracciamo le linee Verticali col = 15 * 8; str = str + $"^FO{col},{last_hor}" + $"^GB1,{7 * 8},2^FS"; col = 31 * 8; str = str + $"^FO{col},{last_hor}" + $"^GB1,{7 * 8},2^FS"; col = 41 * 8; str = str + $"^FO{col},{last_hor}" + $"^GB1,{7 * 8},2^FS"; col = 51 * 8; str = str + $"^FO{col},{last_hor}" + $"^GB1,{7 * 8},2^FS"; col = 71 * 8; str = str + $"^FO{col},{last_hor}" + $"^GB1,{7 * 8},2^FS"; row += 3 * 8; col = 1; num = string.Format("{0:#,#}/{1}", RsaUtils.GetShowedNumDoc(doc.fat_n_doc), RsaUtils.GetRegistroFromStoredNumDoc(doc.fat_n_doc)); str = str + $"^FO{col},{row}" + "^A0,N,23,23" + $"^FB{14 * 8},1,0,R,0^FD{num}^FS"; col = 16 * 8; str = str + $"^FO{col},{row}" + "^A0,N,23,23" + $"^FB{14 * 8},1,0,C,0^FD{doc.fat_d_doc:dd/MM/yyy}^FS"; col = 32 * 8; num = string.Format("{0:#}", doc.fat_inte); str = str + $"^FO{col},{row}" + "^A0,N,25,25" + $"^FB{8 * 8},1,0,R,0^FD{num}^FS"; col = 42 * 8; num = string.Format("{0:#}", doc.fat_age); str = str + $"^FO{col},{row}" + "^A0,N,25,25" + $"^FB{8 * 8},1,0,R,0^FD{num}^FS"; col = 52 * 8; if (age != null) { str = str + $"^FO{col},{row}" + "^A0,N,25,25" + $"^FB{18 * 8},1,0,L,0^FD{age.age_targa.Trim()}^FS"; } col = 73 * 8; if (age != null) { str = str + $"^FO{col},{row}" + "^A0,N,25,25" + $"^FD{age.age_targa.Trim()}^FS"; } // Tracciamo la linea orizzontale col = 0; row += 3 * 8; last_hor = row; str = str + $"^FO{col},{row}" + $"^GB800,1,2^FS"; // Intestazione Cliente row += 1 * 8; col = 1 * 8; str = str + $"^FO{col},{row}" + "^A0,N,19,19" + "^FDCliente / Cessionario^FS"; col = 80 * 8; str = str + $"^FO{col},{row}" + "^A0,N,23,23" + $"^FB{18 * 8},1,0,R,0^FD{_codcli}^FS"; row += 4 * 8; col = 1 * 8; str = str + $"^FO{col},{row}" + "^A0,N,23,23" + $"^FD{cli.cli_rag_soc1.Trim()}^FS"; row += 3 * 8; str = str + $"^FO{col},{row}" + "^A0,N,23,23" + $"^FD{cli.cli_rag_soc2.Trim()}^FS"; row += 3 * 8; str = str + $"^FO{col},{row}" + "^A0,N,23,23" + $"^FD{cli.cli_indirizzo.Trim()}^FS"; row += 3 * 8; num = string.Format("{0} {1} {2}", cli.cli_cap, cli.cli_citta, cli.cli_prov); str = str + $"^FO{col},{row}" + "^A0,N,23,23" + $"^FD{num.Trim()}^FS"; row += 3 * 8; num = ""; if (!string.IsNullOrWhiteSpace(cli.cli_piva)) { num = $"P.IVA {cli.cli_piva}"; } num = num + " "; if (!string.IsNullOrWhiteSpace(cli.cli_codfis)) { num = num + $"Cod. Fiscale {cli.cli_codfis}"; } str = str + $"^FO{col},{row}" + "^A0,N,23,23" + $"^FD{num.Trim()}^FS"; // Tracciamo la linea orizzontale col = 0; row += 3 * 8; last_hor = row; str = str + $"^FO{col},{row}" + $"^GB800,1,2^FS"; // Intestazione Destinazione row += 1 * 8; col = 1 * 8; str = str + $"^FO{col},{row}" + "^A0,N,19,19" + "^FDDestinatario e Luogo di Consegna (se diverso dal cessionario) ^FS"; col = 80 * 8; str = str + $"^FO{col},{row}" + "^A0,N,23,23" + $"^FB{18 * 8},1,0,R,0^FD{_coddst}^FS"; col = 1 * 8; row += 4 * 8; if (dst != null) { str = str + $"^FO{col},{row}" + "^A0,N,25,25" + $"^FD{dst.dst_rag_soc1.Trim()}^FS"; } row += 3 * 8; if (dst != null) { str = str + $"^FO{col},{row}" + "^A0,N,25,25" + $"^FD{dst.dst_rag_soc2.Trim()}^FS"; } row += 3 * 8; if (dst != null) { str = str + $"^FO{col},{row}" + "^A0,N,25,25" + $"^FD{dst.dst_indirizzo.Trim()}^FS"; } row += 3 * 8; if (dst != null) { num = string.Format("{0} {1} {2}", dst.dst_cap, dst.dst_citta, dst.dst_prov); str = str + $"^FO{col},{row}" + "^A0,N,25,25" + $"^FD{num.Trim()}^FS"; } // Tracciamo la linea orizzontale col = 0; row += 3 * 8; last_hor = row; str = str + $"^FO{col},{row}" + $"^GB800,1,2^FS"; col = 1 * 8; row += 1 * 8; str = str + $"^FO{col},{row}" + "^A0,N,19,19" + "^FDCodice^FS"; col = 15 * 8; str = str + $"^FO{col},{row}" + "^A0,N,19,19" + "^FDDescrizione^FS"; if (stprice) { col = 30 * 8; str = str + $"^FO{col},{row}" + "^A0,N,19,19" + "^FDU.M.^FS"; col = 43 * 8; str = str + $"^FO{col},{row}" + "^A0,N,19,19" + "^FDQuantita'^FS"; col = 58 * 8; str = str + $"^FO{col},{row}" + "^A0,N,19,19" + "^FDPrezzo^FS"; col = 70 * 8; str = str + $"^FO{col},{row}" + "^A0,N,19,19" + "^FDSconti^FS"; col = 83 * 8; str = str + $"^FO{col},{row}" + "^A0,N,19,19" + "^FDTotale^FS"; col = 92 * 8; str = str + $"^FO{col},{row}" + "^A0,N,19,19" + "^FDCod.Iva^FS"; } else { col = 77 * 8; str = str + $"^FO{col},{row}" + "^A0,N,19,19" + "^FDU.M.^FS"; col = 92 * 8; str = str + $"^FO{col},{row}" + "^A0,N,19,19" + "^FDQuantita'^FS"; } //str = str + "^XZ"; var t = new UTF8Encoding().GetBytes(str); _con.Write(t); PostPrintCheckStatus(); row += 3; return(82 * 8); }