コード例 #1
0
ファイル: openXML.cs プロジェクト: ozeta/VisualFiParser
        /// <summary>
        /// genera il file D2 per il singolo atleta
        /// </summary>
        /// <param name="team">oggetto contenente i dati di squadra ed atleti</param>
        /// <param name="i">indice dell'atleta selezionato</param>
        public void fillD2(Team team, int i)
        {
            String[] athleteDictionary = team.Athlete_list[0];      //indice atleta
            String[] athlete = team.Athlete_list[i];                //dati singolo atleta
            String[] teamDictionary = team.Athlete_team[0];         //indice squadra dell'atleta
            String[] teamArray = team.Athlete_team[1];              //dati squadra dell'atleta
            String[] homeTeamDictionary = team.Home_team[0];        //indice squadra di casa
            String[] homeTeamArray = team.Home_team[1];             //dati squadra di casa

            //crea il nome di output
            string var = getModuloD2PathBySurname(athlete[1]);

            //using: apre documento da parsare, crea il nuovo documento
            using (WordprocessingDocument mainDoc = WordprocessingDocument.Open(getModuloD2templatePath(), true))
            using (WordprocessingDocument resultDoc = WordprocessingDocument.Create(var, mainDoc.DocumentType))
            {
                //ricopia le parti del vecchio documento nel nuovo
                foreach (var part in mainDoc.Parts)
                    resultDoc.AddPart(part.OpenXmlPart, part.RelationshipId);
                string docText = null;
                //stringhifica il file
                using (StreamReader sr = new StreamReader(resultDoc.MainDocumentPart.GetStream()))
                {
                    docText = sr.ReadToEnd();
                }
                //sostituisce i dati dell'atleta, se esistenti
                docText = regFields(athlete, athleteDictionary, docText);
                //sostituisce i dati della squadra dell'atleta, se esistenti
                docText = regFields(teamArray, teamDictionary, docText);
                //sostituisce i dati della squadra di casa, se esistenti
                docText = regFields(homeTeamArray, homeTeamDictionary, docText);

                //scrive il nuovo file su disco
                using (StreamWriter sw = new StreamWriter(resultDoc.MainDocumentPart.GetStream(FileMode.Create)))
                {
                    sw.Write(docText);
                }
            }
        }
コード例 #2
0
ファイル: openXML.cs プロジェクト: ozeta/VisualFiParser
        /// <summary>
        /// riempie il modulo D ( elenco atleti ) usando il file excel
        /// </summary>
        /// <param name="team"></param>
        public void fillD(Team team)
        {
            //dati singolo atleta
            String[][] athletes = team.Athlete_list;
            //indice squadra dell'atleta
            String[] teamDictionary = team.Athlete_team[0];
            //dati squadra dell'atleta
            String[] teamArray = team.Athlete_team[1];
            //indice squadra di casa
            String[] homeTeamDictionary = team.Home_team[0];
            //dati squadra di casa
            String[] homeTeamArray = team.Home_team[1];
            string var = getModuloDOutputPath();
            string var1 = getModuloDtemplatePath();
            //using: apre documento da parsare, crea il nuovo documento
            using (WordprocessingDocument mainDoc = WordprocessingDocument.Open(var1, true))
            using (WordprocessingDocument resultDoc = WordprocessingDocument.Create(var, mainDoc.DocumentType))
            {
                //ricopia le parti del vecchio documento nel nuovo
                foreach (var part in mainDoc.Parts)
                    resultDoc.AddPart(part.OpenXmlPart, part.RelationshipId);

                //riempie la tabella di dati
                Body bod = resultDoc.MainDocumentPart.Document.Body;
                foreach (DocumentFormat.OpenXml.Wordprocessing.Table t in bod.Descendants<DocumentFormat.OpenXml.Wordprocessing.Table>())
                {
                    this.fillTable(t, team);
                }


            }
            //chiudo il flusso e lo riapro per salvare gli altri dati del modulo.
            //devo eseguire queste 2 procedure in sequenza perché la prima lavora sul body, la seconda
            //sullo stream xml
            using (WordprocessingDocument finalDoc = WordprocessingDocument.Open(var, true))
            {
                string docText = null;
                using (StreamReader sr = new StreamReader(finalDoc.MainDocumentPart.GetStream()))
                {
                    //leggo il flusso e lo converto in stringa
                    docText = sr.ReadToEnd();
                    //sostituisco i dati del team ospite e quello di casa
                    docText = regFields(teamArray, teamDictionary, docText);
                    docText = regFields(homeTeamArray, homeTeamDictionary, docText);
                }

                //salvo tutto su disco
                using (StreamWriter sw = new StreamWriter(finalDoc.MainDocumentPart.GetStream(FileMode.Create)))
                {
                    sw.Write(docText);
                }


            }

        }
コード例 #3
0
        public MainWindow()
        {
            InitializeComponent();
            /*
            DateTime now = Program.getTime();
            int year = now.Year;
            int month = now.Month;
            if (year != 2016 && month > 2)
            {
                DialogBox.write(caption, "Il Periodo di prova è scaduto! 😟", MessageBoxImage.Stop);

                Environment.Exit(0);
            }
            */
            string jsonPath = settings;
            bool jsonExists = System.IO.File.Exists(jsonPath);
            bool updateFileExists = System.IO.File.Exists(update_path);

            try
            {
                createTexBoxes(panel0, tb0);
                createTexBoxes(panel1, tb1);
                createTexBoxes(panel2, tb2);
                createTexBoxes(panel3, tb3);
                tb00 = tb0.Concat(tb1).ToArray();
                tb01 = tb2.Concat(tb3).ToArray();
                team_arr[0] = new string[7] { "NOME_SOC", "CITTA_SOC", "INDIRIZZO_SOC", "MAIL_SOC", "PROV_SOC", "CAP_SOC", "TEL_SOC" };
                team_arr[1] = new string[7];
                team_hom[0] = new string[5] { "GAME_NAME", "GAME_HOME", "GAME_TEAM", "GAME_DATA", "TEAM_HOME" };
                team_hom[1] = new string[5];

                try
                {
                    if (updateFileExists)
                    {
                        Update test;
                        currentVersion = Update.readFiletoObject(update_path);
                        if ((test = currentVersion.isRemoteUpdateAvaible(updateUrl)) != null)
                        {
                            Window2 win2 = new Window2(test.Release, setupUrl);
                            win2.Show();
                            win2.Topmost = true;

                        }
                    }
                }
                catch (Exception ex)
                {
                    Trace.WriteLine(ex.Message);
                    Trace.WriteLine(ex.StackTrace);

                }

                if (jsonExists)
                {
                    team = Team.readFiletoObject(settings);

                    for (int i = 0; i < team.Athlete_team[0].Length; i++)
                    {
                        tb00[i].Text = team.Athlete_team[1][i];
                    }
                    for (int i = 0; i < team.Home_team[0].Length; i++)
                    {
                        tb01[i].Text = team.Home_team[1][i];
                    }

                    if (!team.Excel_path.Equals(""))
                    {
                        this.excel_full_path = team.Excel_path;
                        file_atleti.Text = team.Excel_path;
                        Output_path = team.Excel_path;
                        team.Athlete_list = (new openXML(this.excel_full_path, sheetName)).parseSpreadSheet(COLUMNS);
                        outputpath_label.Content = "I moduli verranno salvati nella cartella " + Output_path;
                    }

                }
                else
                {
                    team = new Team();

                }

            }
            catch (System.IO.FileNotFoundException ex)
            {
                DialogBox.write(caption, ex.Message + "\nDevi selezionare un File valido", MessageBoxImage.Information);
            }
            catch (System.IO.FileLoadException ex)
            {
                DialogBox.write(caption, ex.Message, MessageBoxImage.Information);
            }
            catch (NullReferenceException ex)
            {
                System.IO.File.Delete(jsonPath);
                Trace.WriteLine(ex.Message);
                Trace.WriteLine(ex.StackTrace);

            }
            catch (System.ArgumentException ex)
            {
                string message = "Non è stato possibile ripristinare il file degli atleti salvato in precedenza, devi selezionarne uno nuovo\n";
                DialogBox.write(caption, message + ex.Message, MessageBoxImage.Information);
            }
            catch (Exception ex)
            {
                DialogBox.write(caption, ex.Message, MessageBoxImage.Information);
            }
        }
コード例 #4
0
ファイル: openXML.cs プロジェクト: ozeta/VisualFiParser
        /// <summary>
        /// riempie la tabella word con gli atleti, nel modulo D. usa la funzione getalignedarray
        /// per ottenere una lista di parametri già ordinati da inserire in modo sequenziale.
        /// La funzione richiede che l'oggetto Team sia stato creato tramite foglio excel
        /// </summary>
        /// <param name="t">Tabella word</param>
        /// <param name="team">team degli atleti</param>
        private void fillTable(DocumentFormat.OpenXml.Wordprocessing.Table t, Team team)
        {
            int j = 0;
            //array atleti. serve solo per snellire il codice
            String[][] athletes = team.Athlete_list;
            //sequenza info da estrapolare: 
            //2, 1, 4, CAT, SPEC, Tempo, 11, 12
            String[][] alignedMatrix = new String[athletes.Length - 1][];
            TableCell[][] cellArray = new TableCell[athletes.Length - 1][];

            for (int i = 1; i < athletes.Length; i++)
            {
                alignedMatrix[i - 1] = getAlignedArray(athletes[i]);
                cellArray[i - 1] = new TableCell[alignedMatrix[0].Length];
                for (j = 0; j < alignedMatrix[0].Length; j++)
                {
                    cellArray[i - 1][j] = new TableCell((new Paragraph(new DocumentFormat.OpenXml.Wordprocessing.Run(new DocumentFormat.OpenXml.Wordprocessing.Text(alignedMatrix[i - 1][j])))));
                }
                t.Append(new TableRow(cellArray[i - 1]));

            }


        }
コード例 #5
0
        //salva modulo
        //salva campi
        private void saveModifiedFields()
        {
            try
            {
                if (team.Athlete_team == null || team.Home_team == null)
                {
                }
                team = parseTexboxToTeam();

                team.writeToFile(settings);
                string messageBoxText = "I dati sono stati salvati e verranno ripristinati alla prossima esecuzione";
                DialogBox.write(caption, messageBoxText, MessageBoxImage.Information);

            }
            catch (Exception ex)
            {
                DialogBox.write(caption, ex.Message, MessageBoxImage.Error);

            }
        }