Exemple #1
0
        private void buttonCreaPDF_Click(object sender, RoutedEventArgs e)
        {
            string rtf_text = "";

            rtf_text += "{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1040\\deflangfe1040\\deftab709";
            rtf_text += "{\\fonttbl{\\f0 Arial}}";
            rtf_text += "{\\colortbl;\\red0\\green255\\blue255;\\red204\\green204\\blue204;\\red255\\green255\\blue255;\\red230\\green230\\blue230;}";
            rtf_text += "\\viewkind4\\uc1";

            rtf_text += "\\fs30 " + _cliente + " \\fs20 \\line \\line ";

            rtf_text += "\\fs30 " + "SOSPESI" + " \\fs20 \\line \\line ";



            string sessione = "";

            int[] artab = new int[8];
            artab[0] = 0;
            artab[1] = 2;
            artab[2] = 3;
            artab[3] = 5;
            artab[4] = 7;
            artab[5] = 4;
            artab[6] = 6;
            artab[7] = 1;

            for (int k = 0; k < artab.Length; k++)
            {
                tabControlSospesi.SelectedIndex = artab[k];
                //    rtf_text += "\\fs30 " + labelAttivita.Content + " \\fs20 \\line \\line ";
                rtf_text += "\\fs30 " + ((System.Windows.Controls.HeaderedContentControl)tabControlSospesi.Items[tabControlSospesi.SelectedIndex]).Header.ToString() + " \\fs20 \\line \\line ";
                if (doctree.InnerXml != "")
                {
                    foreach (XmlNode item in doctree.SelectSingleNode("/Tree").SelectNodes("//Node"))
                    {
                        try
                        {
                            foreach (XmlNode itemSessione in item.SelectNodes("Sessioni/Sessione"))
                            {
                                if (itemSessione.Attributes["Sospesi"] != null && itemSessione.Attributes["Sospesi"].Value != "")
                                {
                                    if (sessione != itemSessione.Attributes["Alias"].Value.Replace("\r\n", " "))
                                    {
                                        sessione  = itemSessione.Attributes["Alias"].Value.Replace("\r\n", " ");
                                        rtf_text += "\\fs26 " + itemSessione.Attributes["Alias"].Value.Replace("\r\n", " ") + " \\fs20 \\line \\line ";
                                    }

                                    rtf_text += "\\b " + item.Attributes["Codice"].Value + " " + item.Attributes["Titolo"].Value + " \\b0 \\line ";

                                    {
                                        string istruzione = itemSessione.Attributes["Sospesi"].Value;

                                        if (istruzione.Trim() != "")
                                        {
                                            //    rtf_text += "\\fs20 " + istruzione + " \\fs20 \\line ";
                                        }
                                    }

                                    rtf_text += " ";
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            string log = ex.Message;
                        }
                    }
                }
            }
            rtf_text += "}";

            rtf_text = Convert2RTF(rtf_text);

            string filename = App.AppTempFolder + Guid.NewGuid().ToString();

            TextWriter tw = new StreamWriter(filename + ".rtf");

            tw.Write(rtf_text);
            tw.Close();


            //MM
            cDocNet wrdDoc = new cDocNet();

            wrdDoc.PageSetupPaperSize = "A4";
            wrdDoc.SaveAs(filename + ".doc", filename + ".rtf", "WdSaveFormat.wdFormatDocument");
            //MM



            FileInfo fi = new FileInfo(filename + ".rtf");

            fi.Delete();

            System.Diagnostics.Process process = new System.Diagnostics.Process();
            process.Refresh();
            process.StartInfo.FileName    = filename + ".doc";
            process.StartInfo.ErrorDialog = false;
            process.StartInfo.Verb        = "open";
            process.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Maximized;
            process.Start();

            //System.Diagnostics.Process.Start(filename + ".doc");
        }
        private bool CreatePDF()
        {
            try
            {
                changedID = ht[cmbCartediLavoro.SelectedValue].ToString();

                string rtf_text = "";
                rtf_text += "{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1040\\deflangfe1040\\deftab709";
                rtf_text += "{\\fonttbl{\\f0 Cambria}}";
                rtf_text += "{\\colortbl;\\red0\\green255\\blue255;\\red204\\green204\\blue204;\\red255\\green255\\blue255;\\red230\\green230\\blue230;}";
                rtf_text += "\\viewkind4\\uc1";

                rtf_text += "\\fs24 \\qc \\b " + _Cliente + " \\b0 \\line \\line ";
                //rtf_text += "\\fs24 \\qc " + _Esercizio + " \\line \\line ";

                rtf_text += "\\fs18 \\ql \\b 3.3.1 - Campionamento - numeri casuali \\b0 \\line \\ql La funzione ha generato i numeri casuali esposti nel presente documento \\line \\line ";

                rtf_text += "\\fs18 \\ql \\b Documento associato alla carta di lavoro: \\b0 \\line \\ql " + cmbCartediLavoro.SelectedValue.ToString() + " \\line \\line ";

                rtf_text += "\\fs18 \\ql \\b Scopo della ricerca casuale: \\b0 \\line \\ql " + txtScopo.Text + " \\line \\line ";


                rtf_text += "\\fs18 \\qc \\b N° " + txtQuantita.Text + " numeri casuali generati da " + txtFrom.Text + " a " + txtTo.Text + " \\b0 \\line \\line ";

                string inizioriga  = "\\trowd\\trpaddl50\\trpaddt15\\trpaddr50\\trpaddb15\\trpaddfl3\\trpaddft3\\trpaddfr3\\trpaddfb3 ";
                string colore2     = "\\clcbpat3";
                string bordi       = "\\clbrdrl\\brdrw10\\brdrs\\clbrdrt\\brdrw10\\brdrs\\clbrdrr\\brdrw10\\brdrs\\clbrdrb\\brdrw10\\brdrs"; //\\clpadt100
                string cell2       = "\\clvertalc\\cellx9900";
                string inizioriga2 = "\\pard\\intbl\\tx2291";
                string fineriga    = "\\row ";

                rtf_text += " \\pard\\keep";

                rtf_text += "\\pard\\bgdkdcross\\cfpat1\\shading59110\\tx2291\\par";

                rtf_text += inizioriga + colore2 + bordi + cell2 + inizioriga2;

                rtf_text += " \\fs18 \\ql ";

                bool firstonedone = false;

                foreach (int item in txtChosen.Items)
                {
                    if (firstonedone == true)
                    {
                        rtf_text += " - ";
                    }
                    else
                    {
                        firstonedone = true;
                    }

                    rtf_text += item.ToString();
                }

                rtf_text += " \\cell";

                rtf_text += fineriga;

                rtf_text += "\\pard\\bgdkdcross\\cfpat1\\shading59110\\tx2291\\par";

                rtf_text += "}";

                rtf_text = Convert2RTF(rtf_text);

                string filename = App.AppTempFolder + Guid.NewGuid().ToString();

                TextWriter tw = new StreamWriter(filename + ".rtf");
                tw.Write(rtf_text);
                tw.Close();

                //MM
                cDocNet wrdDoc = new cDocNet();
                wrdDoc.PageSetupPaperSize = "A4";
                wrdDoc.SaveAs(filename + ".pdf", filename + ".rtf", "WdSaveFormat.wdFormatPDF");
                //MM

                FileInfo fi = new FileInfo(filename + ".rtf");
                fi.Delete();
                DataTable dati = cBusinessObjects.GetData(int.Parse(changedID), typeof(ArchivioDocumenti), int.Parse(_IDCliente), int.Parse(_IDSessione));

                DataRow dt = dati.Rows.Add(int.Parse(changedID), int.Parse(_IDCliente), int.Parse(_IDSessione));

                DataTable tempdt = cBusinessObjects.ExecutesqlDataTable("SELECT MAX(ID) AS LASTID FROM ArchivioDocumenti");
                foreach (DataRow dd in tempdt.Rows)
                {
                    if (dd["LASTID"].ToString() == "")
                    {
                        dt["ID"] = 1;
                    }
                    else
                    {
                        dt["ID"] = int.Parse(dd["LASTID"].ToString()) + 1;
                    }
                }
                string newName = dt["ID"].ToString() + ".pdf";
                dt["File"]                  = newName;
                dt["Visualizza"]            = "True";
                dt["NodoExtended"]          = cmbCartediLavoro.SelectedValue;
                dt["Tree"]                  = _IDTree;
                dt["Titolo"]                = txtTitolo.Text;
                cBusinessObjects.idcliente  = int.Parse(_IDCliente);
                cBusinessObjects.idsessione = int.Parse(_IDSessione);
                dt["Tipo"]                  = ((rdbCorrente.IsChecked == true) ? (Convert.ToInt32(TipoDocumento.Corrente)).ToString() : (Convert.ToInt32(TipoDocumento.Permanente)).ToString());
                dt["TipoExtended"]          = ((rdbCorrente.IsChecked == true) ? "Corrente" : "Permanente");



                string directory = App.AppModelliFolder;

                string file = filename + ".pdf";

                FileInfo fi2 = new FileInfo(file);
                if (fi2.Exists)
                {
                    string   newfile = App.AppDocumentiFolder + "\\" + newName;
                    FileInfo newf    = new FileInfo(newfile);
                    if (newf.Exists)
                    {
                        File.Delete(newfile);
                    }

                    fi2.CopyTo(newfile);
                }

                cBusinessObjects.SaveData(int.Parse(changedID), dati, typeof(ArchivioDocumenti));

                MessageBox.Show("Documento numeri casuali generato con successo");
            }
            catch (Exception ex)
            {
                cBusinessObjects.logger.Error(ex, "wCampionamento.CreatePDF exception");

                MessageBox.Show(ex.Message);
                return(false);
            }

            return(true);
        }
        private void buttonCreaPDF_Click(object sender, RoutedEventArgs e)
        {
            string rtf_text = "";

            rtf_text += "{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1040\\deflangfe1040\\deftab709";
            rtf_text += "{\\fonttbl{\\f0 Cambria}}";
            rtf_text += "{\\colortbl;\\red0\\green255\\blue255;\\red204\\green204\\blue204;\\red255\\green255\\blue255;\\red230\\green230\\blue230;}";
            rtf_text += "\\viewkind4\\uc1";

            rtf_text += "\\fs28 \\qc " + Cliente + " \\ql \\fs28 \\line \\line ";

            rtf_text += "\\fs24 Siamo ad informarvi che nella sessione prevista per il giorno " + Data + " l'organo di controllo eseguirà i seguenti controlli: \\fs24 \\line \\line ";

            foreach (XmlNode item in _xTXP.Document.SelectSingleNode("/Tree").SelectNodes("//Node"))
            {
                try
                {
                    if (item.Attributes["NotaTDL"] != null && item.Attributes["Checked"] != null && item.Attributes["Checked"].Value == "True")
                    {
                        rtf_text += "\\b " + item.Attributes["Codice"].Value + " " + item.Attributes["Titolo"].Value + ": \\b0  ";

                        {
                            string istruzione = item.Attributes["NotaTDL"].Value;

                            if (istruzione.Trim() != "")
                            {
                                rtf_text += "\\pard\\keepn \\i " + istruzione + " \\i0\\par";
                            }
                        }

                        rtf_text += " \\line \\line ";
                    }
                }
                catch (Exception ex)
                {
                    string log = ex.Message;
                }
            }

            rtf_text += "}";

            rtf_text = Convert2RTF(rtf_text);

            string filename = App.AppTempFolder + Guid.NewGuid().ToString();

            TextWriter tw = new StreamWriter(filename + ".rtf");

            tw.Write(rtf_text);
            tw.Close();

            //MM
            cDocNet wrdDoc = new cDocNet();

            wrdDoc.PageSetupPaperSize   = "A4";
            wrdDoc.PageSetupOrientation = WdOrientation.wdOrientLandscape;
            wrdDoc.SaveAs(filename + ".pdf", filename + ".rtf", "WdSaveFormat.wdFormatPDF");
            //MM



            FileInfo fi = new FileInfo(filename + ".rtf");

            fi.Delete();

            //System.Diagnostics.Process process = new System.Diagnostics.Process();
            //process.Refresh();
            //process.StartInfo.FileName = filename + ".doc";
            //process.StartInfo.ErrorDialog = false;
            //process.StartInfo.Verb = "open";
            //process.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Maximized;
            //process.Start();

            System.Diagnostics.Process.Start(filename + ".pdf");
        }