Пример #1
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
            {
                return("");
            }

            var    doc = (Documents)value;
            string str = String.Format("{0}/{1}", RsaUtils.GetShowedNumDoc(doc.fat_n_doc), doc.fat_registro);

            return(str);
        }
        public void SetField()
        {
            m_cli_cod.Text = "0";
            m_dst_cod.Text = "0";
            if (_cli != null)
            {
                m_cli_cod.Text     = _cli.cli_codice.ToString();
                cli_desc.Text      = _cli.cli_desc;
                cli_indirizzo.Text = _cli.cli_indirizzo;
                cli_citta.Text     = _cli.cli_citta;
            }
            else
            {
                m_cli_cod.Text     = "0";
                cli_desc.Text      = "";
                cli_indirizzo.Text = "";
                cli_citta.Text     = "";
            }
            if (_dst != null)
            {
                m_dst_cod.Text     = _dst.dst_codice.ToString();
                dst_desc.Text      = _dst.dst_desc;
                dst_indirizzo.Text = _dst.dst_indirizzo;
                dst_citta.Text     = _dst.dst_citta;
            }
            else
            {
                m_dst_cod.Text     = "0";
                dst_desc.Text      = "";
                dst_indirizzo.Text = "";
                dst_citta.Text     = "";
            }

            m_n_doc.Value     = RsaUtils.GetShowedNumDoc(_parent.doc.fat_n_doc);
            m_d_doc.Date      = _parent.doc.fat_d_doc;
            fat_registro.Text = _parent.doc.fat_registro;
        }
Пример #3
0
        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);
        }
Пример #4
0
        public async Task <bool> PrintDoc(Fatture doc, bool stprice, short copie = 1)
        {
            var  result  = false;
            bool rewrite = false;

            try
            {
                _con = ConnectionBuilder.Current.Build(_printer);
                _con.Open();
                _prn = ZebraPrinterFactory.Current.GetInstance(_con);


                //
                // Leggiamo le righe del documento
                //
                string sql = String.Format("SELECT * FROM fatrow2 WHERE rig_tipo = {0} AND rig_n_doc = {1}", doc.fat_tipo, doc.fat_n_doc);
                _riglist = await dbcon_.QueryAsync <FatRow>(sql);

                //
                // Controlliamo che tutte le righe siano dello stesso fornitore
                //
                int codfor = -1;
                if (doc.fat_tipo == (int)DocTipo.TIPO_DDT)
                {
                    foreach (var rig in _riglist)
                    {
                        if (!string.IsNullOrWhiteSpace(rig.rig_art))
                        {
                            sql = String.Format("SELECT * FROM artanag WHERE ana_codice = {0} LIMIT 1", rig.rig_art.Trim().SqlQuote(false));
                            var ana = await dbcon_.QueryAsync <Artanag>(sql);

                            if (ana.Count > 0)
                            {
                                if (codfor == -1)
                                {
                                    codfor = ana[0].ana_for_abituale;
                                }
                                if (codfor != ana[0].ana_for_abituale)
                                {
                                    codfor = -1;
                                    break;
                                }
                            }
                        }
                    }
                    if (codfor == -1)
                    {
                        codfor = 0;
                    }


                    _codcli = "C.F. ";
                    _coddst = "C.C. ";
                    sql     = String.Format("SELECT * FROM agganci1 WHERE agg_forn = {0} AND agg_cli = {1} AND agg_dst = {2} LIMIT 1", codfor, doc.fat_inte, 0);
                    var agg = await dbcon_.QueryAsync <Agganci>(sql);

                    if (agg.Count > 0)
                    {
                        _codcli = _codcli + agg[0].agg_codice;
                        _coddst = _coddst + agg[0].agg_codice;
                    }
                    sql = String.Format("SELECT * FROM agganci1 WHERE agg_forn = {0} AND agg_cli = {1} AND agg_dst = {2} LIMIT 1", codfor, doc.fat_inte, doc.fat_dest);
                    agg = await dbcon_.QueryAsync <Agganci>(sql);

                    if (agg.Count > 0)
                    {
                        _coddst = "C.C. " + agg[0].agg_codice;
                    }
                    _codcli = _codcli.Trim();
                    _coddst = _coddst.Trim();
                    if (_codcli == "C.F.")
                    {
                        _codcli = "";
                    }
                    if (_coddst == "C.C.")
                    {
                        _coddst = "";
                    }

                    _codocr = "";
                    if (doc.fat_tipo_ven == (int)DocTipoVen.VEN_TRASFERT && codfor != 0)
                    {
                        sql = String.Format("SELECT * FROM fornito1 WHERE for_codice = {0} LIMIT 1", codfor);
                        var forList = await dbcon_.QueryAsync <Fornitori>(sql);

                        if (forList.Count > 0 && forList[0].for_nota != 0)
                        {
                            sql = String.Format("SELECT * FROM descriz1 WHERE des_codice = {0} LIMIT 1", forList[0].for_nota);
                            var desList = await dbcon_.QueryAsync <Descrizioni>(sql);

                            if (desList.Count > 0)
                            {
                                desList[0].des_newdes = desList[0].des_newdes.Trim();
                                doc.fat_n_from        = forList[0].for_codice;
                                if (desList[0].des_newdes.Length < 130)
                                {
                                    doc.fat_annotaz = desList[0].des_newdes;
                                }
                                else
                                {
                                    doc.fat_annotaz = desList[0].des_newdes.Substring(0, 129);
                                    if (desList[0].des_newdes.Length > 130)
                                    {
                                        doc.fat_desc_varie_0 = desList[0].des_newdes.Substring(130, desList[0].des_newdes.Length >= 260 ? 259 : desList[0].des_newdes.Length - 1);
                                    }
                                    if (desList[0].des_newdes.Length > 260)
                                    {
                                        doc.fat_desc_varie_1 = desList[0].des_newdes.Substring(260, desList[0].des_newdes.Length >= 390 ? 389 : desList[0].des_newdes.Length - 1);
                                    }
                                    if (desList[0].des_newdes.Length > 390)
                                    {
                                        doc.fat_desc_varie_2 = desList[0].des_newdes.Substring(390, desList[0].des_newdes.Length - 1);
                                    }
                                }
                                doc.fat_annotaz      = doc.fat_annotaz.Trim();
                                doc.fat_desc_varie_0 = doc.fat_desc_varie_0.Trim();
                                doc.fat_desc_varie_1 = doc.fat_desc_varie_1.Trim();
                                doc.fat_desc_varie_2 = doc.fat_desc_varie_2.Trim();
                                rewrite = true;
                            }
                        }
                        if (codfor == 1L)                         // NESTLE
                        {
                            int ocr = 0;
                            _codocr = string.Format("<{0}{1}{2:00}", RsaUtils.GetShowedNumDoc(doc.fat_n_doc), doc.fat_registro, 1);
                            for (int y = 1; y < _codocr.Length; y++)
                            {
                                ocr += _codocr[y] * y;
                            }
                            ocr     = ocr % 93;
                            _codocr = _codocr + $"{ocr:00}>";
                        }
                    }
                }

                if (rewrite)
                {
                    await dbcon_.UpdateAsync(doc);
                }

                Initialize();
                _mod_len = CalcLength(stprice) > _mod_len?CalcLength(stprice) : _mod_len;

                for (short idx = 0; idx < copie; idx++)
                {
                    int row = 0;

                    PrePrintCheckStatus();
                    row = await PrintDocHeaderAsync(doc, row, stprice);

                    row = await PrintDocBodyAsync(doc, row, stprice);

                    row = await PrintDocFooterAsync(doc, row, stprice);
                }
                result = true;
            }
            catch (ZebraExceptions ex)
            {
                Debug.WriteLine(ex.Message);
                throw;
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                throw;
            }
            finally
            {
                _con.Open();
                if ((_con != null) && (_con.IsConnected))
                {
                    _con.Close();
                }
                _con = null;
                _prn = null;
            }

            return(result);
        }
        private async Task Upload()
        {
            int cli_rec = 0;
            int dst_rec = 0;
            int rig_rec = 0;

            //
            // Leggiamo le impostazioni
            //
            try
            {
                lim = await dbcon_.GetAsync <LocalImpo>(1);
            }
            catch
            {
                await DisplayAlert("Attenzione!", "Impostazioni locali non trovate!\nRiavviare l'App.", "OK");

                await Navigation.PopModalAsync();

                return;
            }

            if (string.IsNullOrWhiteSpace(lim.ftpServer))
            {
                await DisplayAlert("Attenzione!", "Server non impostato o non valido.", "OK");

                await Navigation.PopModalAsync();

                return;
            }
            if (string.IsNullOrWhiteSpace(lim.user))
            {
                await DisplayAlert("Attenzione!", "Utente non impostato o non valido.", "OK");

                await Navigation.PopModalAsync();

                return;
            }
            if (lim.age == 0)
            {
                await DisplayAlert("Attenzione!", "Agente non impostato o non valido.", "OK");

                await Navigation.PopModalAsync();

                return;
            }

            busyIndicator.IsBusy        = true;
            busyIndicator.AnimationType = AnimationTypes.Ball;
            busyIndicator.Title         = "Estrazione Documenti";

            var docList = new List <Documento>();


            m_doc_ext.Source = "ic_hourglass_full_white.png";
            m_rig_ext.Source = "ic_hourglass_full_white.png";
            m_cli_ext.Source = "ic_hourglass_full_white.png";
            m_dst_ext.Source = "ic_hourglass_full_white.png";


            m_doc.FontSize  = m_doc.FontSize + 3;
            m_doc.TextColor = Color.Red;

            var sql     = "SELECT * FROM fatture2 WHERE fat_local_doc = 1";
            var fatList = await dbcon_.QueryAsync <Fatture>(sql);

            if (fatList.Count == 0)
            {
                busyIndicator.IsBusy = false;
                await DisplayAlert("Attenzione!", "Non ci sono documenti da inviare alla sede.", "OK");

                await Navigation.PopModalAsync();

                return;
            }

            m_doc_rec.Text  = $"{fatList.Count}";
            m_doc.FontSize  = m_doc.FontSize - 3;
            m_doc.TextColor = Color.White;

            busyIndicator.AnimationType = AnimationTypes.Gear;
            busyIndicator.Title         = "Estrazione Dati Documenti";
            foreach (var fat in fatList)
            {
                var doc = new Documento();
                doc.documento = fat;

                //
                // Inseriamo i dati del cliente
                //
                m_cli.FontSize  = m_cli.FontSize + 3;
                m_cli.TextColor = Color.Red;
                try
                {
                    cli_rec++;
                    doc.cliente = await dbcon_.GetAsync <Clienti>(fat.fat_inte);
                }
                catch
                {
                    throw new RsaException(RsaException.NotFoundMsg, RsaException.NotFoundErr);
                }
                m_cli_rec.Text  = $"{cli_rec}";
                m_cli.FontSize  = m_cli.FontSize - 3;
                m_cli.TextColor = Color.White;


                //
                // Inseriamo i dati del destinatario
                //
                if (fat.fat_dest != 0)
                {
                    m_dst.FontSize  = m_dst.FontSize + 3;
                    m_dst.TextColor = Color.Red;

                    try
                    {
                        dst_rec++;
                        doc.destinazione = await dbcon_.GetAsync <Destinazioni>(fat.fat_dest);
                    }
                    catch
                    {
                        throw new RsaException(RsaException.NotFoundMsg, RsaException.NotFoundErr);
                    }
                    m_dst.FontSize  = m_dst.FontSize - 3;
                    m_dst.TextColor = Color.White;
                }
                m_dst_rec.Text = $"{dst_rec}";

                //
                // Inseriamo le righe dei documenti
                //
                m_rig.FontSize  = m_rig.FontSize + 3;
                m_rig.TextColor = Color.Red;

                sql       = string.Format("SELECT * from fatrow2 WHERE rig_tipo = {0} AND rig_n_doc = {1} ORDER BY rig_tipo, rig_n_doc, rig_d_ins, rig_t_ins", fat.fat_tipo, fat.fat_n_doc);
                doc.righe = await dbcon_.QueryAsync <FatRow>(sql);

                m_rig.FontSize  = m_rig.FontSize - 3;
                m_rig.TextColor = Color.White;

                rig_rec       += doc.righe.Count;
                m_rig_rec.Text = $"{rig_rec}";

                if (doc.righe.Count == 0)
                {
                    sql = "";
                    busyIndicator.IsBusy = true;
                    switch (fat.fat_tipo)
                    {
                    case (short)DocTipo.TIPO_FAT:
                        sql = string.Format("La fattura N. {0}/{1} non contiene righe!\n\nVuoi continuare?", RsaUtils.GetShowedNumDoc(fat.fat_n_doc), fat.fat_registro);
                        break;

                    case (short)DocTipo.TIPO_DDT:
                        sql = string.Format("Il DDT N. {0}/{1} non contiene righe!\n\nVuoi continuare?", RsaUtils.GetShowedNumDoc(fat.fat_n_doc), fat.fat_registro);
                        break;

                    case (short)DocTipo.TIPO_ORD:
                        sql = string.Format("L' Ordine N. {0}/{1} non contiene righe!\n\nVuoi continuare?", RsaUtils.GetShowedNumDoc(fat.fat_n_doc), fat.fat_registro);
                        break;

                    default:
                        sql = string.Format("Il Documento N. {0}/{1} (Tipo - {2}) non contiene righe!\n\nVuoi continuare?", RsaUtils.GetShowedNumDoc(fat.fat_n_doc), fat.fat_registro, fat.fat_tipo);
                        break;
                    }
                    var test = await DisplayAlert("Attenzone", sql, "SI", "NO");

                    if (!test)
                    {
                        await Navigation.PopModalAsync();

                        return;
                    }
                }

                //
                // Aggiungiamo il documento alla lista di quelli esportati
                //
                docList.Add(doc);
            }
            m_doc_ext.Source = "ic_storage_black.png";
            m_rig_ext.Source = "ic_storage_black.png";
            m_cli_ext.Source = "ic_storage_black.png";
            m_dst_ext.Source = "ic_storage_black.png";

            //
            // Creiamo il file
            //
            m_doc_json.Source = "ic_hourglass_full_white.png";
            m_rig_json.Source = "ic_hourglass_full_white.png";
            m_cli_json.Source = "ic_hourglass_full_white.png";
            m_dst_json.Source = "ic_hourglass_full_white.png";

            busyIndicator.AnimationType = AnimationTypes.DoubleCircle;
            busyIndicator.Title         = "Serializzazione";

            //sql = JsonConvert.SerializeObject(docList, Formatting.Indented);

            IFolder rootFolder = FileSystem.Current.LocalStorage;
            String  localJson  = rootFolder.Path + "/" + "DOCUMENTI" + ".JSON";

            IFile json_file = await rootFolder.CreateFileAsync(localJson, CreationCollisionOption.ReplaceExisting);

            await json_file.WriteAllTextAsync(JsonConvert.SerializeObject(docList, Formatting.Indented));

            m_doc_json.Source = "ic_code_black.png";
            m_rig_json.Source = "ic_code_black.png";
            m_cli_json.Source = "ic_code_black.png";
            m_dst_json.Source = "ic_code_black.png";

            m_doc_upload.Source = "ic_file_download_black.png";
            m_rig_upload.Source = "ic_file_download_black.png";
            m_cli_upload.Source = "ic_file_download_black.png";
            m_dst_upload.Source = "ic_file_download_black.png";

            //
            // Trasmettiamo il file
            //
            busyIndicator.AnimationType = AnimationTypes.Globe;
            busyIndicator.Title         = "Trasmissione";

            string password     = "";
            string remoteServer = "";

            if (lim.ftpServer == "Facile - 01")
            {
                remoteServer = "ftp://www.facile2013.it";
            }

            if (lim.ftpServer == "Facile - 02")
            {
                remoteServer = "ftp://www.rsaweb.com";
            }

            if (lim.ftpServer == "Facile - 03")
            {
                remoteServer = "ftp://www.facilecloud.com";
            }

            if (remoteServer == "")
            {
                throw new Exception("Server non impostato o non valido");
            }

            if (lim.user != "demo2017")
            {
                password = $"$_{lim.user}_$";
            }
            else
            {
                password = lim.user;
            }

            var remotePath = $"/{lim.age}/out";

            m_doc_upload.Source = "ic_hourglass_full_white.png";
            m_rig_upload.Source = "ic_hourglass_full_white.png";
            m_cli_upload.Source = "ic_hourglass_full_white.png";
            m_dst_upload.Source = "ic_hourglass_full_white.png";

            var    ftp    = DependencyService.Get <IFtpWebRequest>();
            string result = await ftp.UploadFile(remoteServer, localJson, lim.user, password, remotePath);

            busyIndicator.IsBusy = false;
            if (result.StartsWith("2", StringComparison.CurrentCulture))
            {
                m_doc_upload.Source = "ic_cloud_black.png";
                m_rig_upload.Source = "ic_cloud_black.png";
                m_cli_upload.Source = "ic_cloud_black.png";
                m_dst_upload.Source = "ic_cloud_black.png";


                m_doc.TextColor = Color.Black;
                m_rig.TextColor = Color.Black;
                m_cli.TextColor = Color.Black;
                m_dst.TextColor = Color.Black;

                //
                // Marchiamo i documenti come non più editabili
                //
                foreach (var fat in fatList)
                {
                    fat.fat_editable = false;
                }
                await dbcon_.UpdateAllAsync(fatList);
                await DisplayAlert("Facile", "Invio documenti concluso con successo!", "OK");
            }
            else if (result.StartsWith("530", StringComparison.CurrentCulture))
            {
                await DisplayAlert("Facile", "Parametri di Login non validi!\nVerificare il nome utente configurato.", "OK");
            }
            else if (result.StartsWith("System.Net.WebException", StringComparison.CurrentCulture))
            {
                await DisplayAlert("Facile", result, "OK");
            }
            else
            {
                await DisplayAlert("Facile", "Impossibile caricare il file sul server!", "OK");
            }

            //
            // Rimuoviamo il file
            //
            await json_file.DeleteAsync();

            await Navigation.PopModalAsync();
        }