Ajout de données dans fichier XML - Page 2

Précédent
  • 1
  • 2
Tintin2256 Messages postés 26 Statut Membre
 

Dans ma seconde fonction , je dois générer ceci:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<LDExchangeFile>
	<fileHeader company="Schneider Automation" product="Control Expert V14.1 - 191122A" dateTime="date_and_time#2022-11-17-14:38:39" content="Fichier source LD" DTDVersion="41"></fileHeader>
	<contentHeader name="Station" version="0.0.156" dateTime="date_and_time#2022-11-5-18:21:51"></contentHeader>
	<program>
		<identProgram name="Def_ANA_609_623" type="section" task="MAST"></identProgram>
		<LDSource nbColumns="11">
			<networkLD>
				<typeLine>
					<emptyLine nbRows="2"></emptyLine>
				</typeLine>
				<typeLine>
					<contact typeContact="openContact" contactVariableName="TJRS_0"></contact>
					<HLink nbCells="9"></HLink>
					<coil typeCoil="setCoil" coilVariableName="DEF_609"></coil>
				</typeLine>
				<typeLine>
					<emptyLine nbRows="1"></emptyLine>
				</typeLine>
				<typeLine>
					<contact typeContact="openContact" contactVariableName="TJRS_0"></contact>
					<HLink nbCells="9"></HLink>
					<coil typeCoil="setCoil" coilVariableName="DEF_610"></coil>
				</typeLine>
				<typeLine>
					<emptyCell nbCells="4"></emptyCell>
					<FFBBlock instanceName="DEF_ANA_EANA_01" typeName="DEF_ANA" additionnalPinNumber="0" enEnO="false" width="16" height="8">
						<objPosition posX="4" posY="5"></objPosition>
						<descriptionFFB execAfter="">
							<inputVariable invertedPin="false" formalParameter="EN"></inputVariable>
							<inputVariable invertedPin="false" formalParameter="DEF_EANA"></inputVariable>
							<inputVariable invertedPin="false" formalParameter="BIT_SEC" effectiveParameter="BIT_1S"></inputVariable>
							<inputVariable invertedPin="false" formalParameter="MARCHE"></inputVariable>
							<inputVariable invertedPin="false" formalParameter="TAB_PARAM_DEFAUT" effectiveParameter="TAB_PARAM_DEF_EANA[1]"></inputVariable>
							<inputVariable invertedPin="false" formalParameter="MESURE_REEL" effectiveParameter="EANA_01"></inputVariable>
							<inputVariable invertedPin="false" formalParameter="FONCT_EN_DELTA_CONSIGNE" effectiveParameter="TJRS_0"></inputVariable>
							<outputVariable invertedPin="false" formalParameter="ENO"></outputVariable>
							<outputVariable invertedPin="false" formalParameter="DEFAUT_SEUIL_BAS"></outputVariable>
							<outputVariable invertedPin="false" formalParameter="ALARM_SEUIL_BAS"></outputVariable>
							<outputVariable invertedPin="false" formalParameter="ALARM_SEUIL_HAUT"></outputVariable>
							<outputVariable invertedPin="false" formalParameter="DEFAUT_SEUIL_HAUT"></outputVariable>
						</descriptionFFB>
					</FFBBlock>
					<emptyCell nbCells="5"></emptyCell>
				</typeLine>
				<typeLine>
					<emptyLine nbRows="1"></emptyLine>
				</typeLine>
				<typeLine>
					<shortCircuit>
						<VLink></VLink>
						<contact typeContact="openContact" contactVariableName="DEF_609"></contact>
					</shortCircuit>
					<HLink nbCells="3"></HLink>
					<emptyCell nbCells="2"></emptyCell>
					<HLink nbCells="4"></HLink>
					<coil typeCoil="setCoil" coilVariableName="DEF_611"></coil>
				</typeLine>
				<typeLine>
					<contact typeContact="openContact" contactVariableName="DEF_610"></contact>
					<emptyCell nbCells="5"></emptyCell>
					<HLink nbCells="4"></HLink>
					<coil typeCoil="coil" coilVariableName="DEF_612"></coil>
				</typeLine>
				<typeLine>
					<HLink nbCells="1"></HLink>
					<contact typeContact="openContact" contactVariableName="TJRS_0"></contact>
					<HLink nbCells="2"></HLink>
					<emptyCell nbCells="2"></emptyCell>
					<HLink nbCells="4"></HLink>
					<coil typeCoil="coil" coilVariableName="DEF_613"></coil>
				</typeLine>
				<typeLine>
					<emptyCell nbCells="6"></emptyCell>
					<HLink nbCells="4"></HLink>
					<coil typeCoil="setCoil" coilVariableName="DEF_614"></coil>
				</typeLine>
				<typeLine>
					<emptyLine nbRows="5"></emptyLine>
				</typeLine>
				<typeLine>
					<contact typeContact="openContact" contactVariableName="TJRS_0"></contact>
					<HLink nbCells="9"></HLink>
					<coil typeCoil="setCoil" coilVariableName="DEF_615"></coil>
				</typeLine>
				<typeLine>
					<emptyLine nbRows="2"></emptyLine>
				</typeLine>
				<typeLine>
					<contact typeContact="openContact" contactVariableName="TJRS_0"></contact>
					<HLink nbCells="9"></HLink>
					<coil typeCoil="setCoil" coilVariableName="DEF_616"></coil>
				</typeLine>
				<typeLine>
					<emptyCell nbCells="4"></emptyCell>
					<FFBBlock instanceName="DEF_ANA_EANA_02" typeName="DEF_ANA" additionnalPinNumber="0" enEnO="false" width="16" height="8">
						<objPosition posX="4" posY="20"></objPosition>
						<descriptionFFB execAfter="">
							<inputVariable invertedPin="false" formalParameter="EN"></inputVariable>
							<inputVariable invertedPin="false" formalParameter="DEF_EANA"></inputVariable>
							<inputVariable invertedPin="false" formalParameter="BIT_SEC" effectiveParameter="BIT_1S"></inputVariable>
							<inputVariable invertedPin="false" formalParameter="MARCHE"></inputVariable>
							<inputVariable invertedPin="false" formalParameter="TAB_PARAM_DEFAUT" effectiveParameter="TAB_PARAM_DEF_EANA[2]"></inputVariable>
							<inputVariable invertedPin="false" formalParameter="MESURE_REEL" effectiveParameter="EANA_02"></inputVariable>
							<inputVariable invertedPin="false" formalParameter="FONCT_EN_DELTA_CONSIGNE" effectiveParameter="TJRS_0"></inputVariable>
							<outputVariable invertedPin="false" formalParameter="ENO"></outputVariable>
							<outputVariable invertedPin="false" formalParameter="DEFAUT_SEUIL_BAS"></outputVariable>
							<outputVariable invertedPin="false" formalParameter="ALARM_SEUIL_BAS"></outputVariable>
							<outputVariable invertedPin="false" formalParameter="ALARM_SEUIL_HAUT"></outputVariable>
							<outputVariable invertedPin="false" formalParameter="DEFAUT_SEUIL_HAUT"></outputVariable>
						</descriptionFFB>
					</FFBBlock>
					<emptyCell nbCells="5"></emptyCell>
				</typeLine>
				<typeLine>
					<emptyLine nbRows="1"></emptyLine>
				</typeLine>
				<typeLine>
					<shortCircuit>
						<VLink></VLink>
						<contact typeContact="openContact" contactVariableName="DEF_615"></contact>
					</shortCircuit>
					<HLink nbCells="3"></HLink>
					<emptyCell nbCells="2"></emptyCell>
					<HLink nbCells="4"></HLink>
					<coil typeCoil="setCoil" coilVariableName="DEF_617"></coil>
				</typeLine>
				<typeLine>
					<contact typeContact="openContact" contactVariableName="DEF_616"></contact>
					<emptyCell nbCells="5"></emptyCell>
					<HLink nbCells="4"></HLink>
					<coil typeCoil="coil" coilVariableName="DEF_618"></coil>
				</typeLine>
				<typeLine>
					<HLink nbCells="1"></HLink>
					<contact typeContact="openContact" contactVariableName="TJRS_0"></contact>
					<HLink nbCells="2"></HLink>
					<emptyCell nbCells="2"></emptyCell>
					<HLink nbCells="4"></HLink>
					<coil typeCoil="coil" coilVariableName="DEF_619"></coil>
				</typeLine>
				<typeLine>
					<emptyCell nbCells="6"></emptyCell>
					<HLink nbCells="4"></HLink>
					<coil typeCoil="setCoil" coilVariableName="DEF_620"></coil>
				</typeLine>
				<typeLine>
					<emptyLine nbRows="3"></emptyLine>
				</typeLine>
				<textBox width="2" height="1">Défaut dépassement<objPosition posX="0" posY="18"></objPosition>
				</textBox>
				<textBox width="2" height="1">Défaut dépassement<objPosition posX="0" posY="3"></objPosition>
				</textBox>
				<textBox width="2" height="1">Défaut rupture fil<objPosition posX="0" posY="1"></objPosition>
				</textBox>
				<textBox width="2" height="1">Défaut rupture fil<objPosition posX="0" posY="15"></objPosition>
				</textBox>
				<textBox width="11" height="1">Gestion défauts analogiques EANA_02<objPosition posX="0" posY="14"></objPosition>
				</textBox>
				<textBox width="11" height="1">Gestion défauts analogiques EANA_01<objPosition posX="0" posY="0"></objPosition>
				</textBox>
			</networkLD>
		</LDSource>
	</program>
	<dataBlock>
		<variables name="EANA_01" typeName="REAL" topologicalAddress="%MW900"></variables>
		<variables name="EANA_02" typeName="REAL" topologicalAddress="%MW902">
	</dataBlock>
</LDExchangeFile>

Ma base excel est la même que celle que je t'ai donné la première fois à un détail près donc je te redonne un fichier à jour pour correspondre:

https://cjoint.com/c/LKrnRzsz5tI

J'ai commencé ma prog et j'arrive à générer les textbox et la partie "datablock" dans sa globalité mais je seche pour la génération du reste. Je dois absolument garder l'organisation comme elle est. On retrouve une architecture de base mais je ne parviens pas à la créer de manière "paramétrable"

<typeLine>
					<emptyLine nbRows="2"></emptyLine>
				</typeLine>
				<typeLine>
					<contact typeContact="openContact" contactVariableName="TJRS_0"></contact>
					<HLink nbCells="9"></HLink>
					<coil typeCoil="setCoil" coilVariableName="DEF_609"></coil>
				</typeLine>
				<typeLine>
					<emptyLine nbRows="1"></emptyLine>
				</typeLine>
				<typeLine>
					<contact typeContact="openContact" contactVariableName="TJRS_0"></contact>
					<HLink nbCells="9"></HLink>
					<coil typeCoil="setCoil" coilVariableName="DEF_610"></coil>
				</typeLine>
				<typeLine>
					<emptyCell nbCells="4"></emptyCell>
					<FFBBlock instanceName="DEF_ANA_EANA_01" typeName="DEF_ANA" additionnalPinNumber="0" enEnO="false" width="16" height="8">
						<objPosition posX="4" posY="5"></objPosition>
						<descriptionFFB execAfter="">
							<inputVariable invertedPin="false" formalParameter="EN"></inputVariable>
							<inputVariable invertedPin="false" formalParameter="DEF_EANA"></inputVariable>
							<inputVariable invertedPin="false" formalParameter="BIT_SEC" effectiveParameter="BIT_1S"></inputVariable>
							<inputVariable invertedPin="false" formalParameter="MARCHE"></inputVariable>
							<inputVariable invertedPin="false" formalParameter="TAB_PARAM_DEFAUT" effectiveParameter="TAB_PARAM_DEF_EANA[1]"></inputVariable>
							<inputVariable invertedPin="false" formalParameter="MESURE_REEL" effectiveParameter="EANA_01"></inputVariable>
							<inputVariable invertedPin="false" formalParameter="FONCT_EN_DELTA_CONSIGNE" effectiveParameter="TJRS_0"></inputVariable>
							<outputVariable invertedPin="false" formalParameter="ENO"></outputVariable>
							<outputVariable invertedPin="false" formalParameter="DEFAUT_SEUIL_BAS"></outputVariable>
							<outputVariable invertedPin="false" formalParameter="ALARM_SEUIL_BAS"></outputVariable>
							<outputVariable invertedPin="false" formalParameter="ALARM_SEUIL_HAUT"></outputVariable>
							<outputVariable invertedPin="false" formalParameter="DEFAUT_SEUIL_HAUT"></outputVariable>
						</descriptionFFB>
					</FFBBlock>
					<emptyCell nbCells="5"></emptyCell>
				</typeLine>
				<typeLine>
					<emptyLine nbRows="1"></emptyLine>
				</typeLine>
				<typeLine>
					<shortCircuit>
						<VLink></VLink>
						<contact typeContact="openContact" contactVariableName="DEF_609"></contact>
					</shortCircuit>
					<HLink nbCells="3"></HLink>
					<emptyCell nbCells="2"></emptyCell>
					<HLink nbCells="4"></HLink>
					<coil typeCoil="setCoil" coilVariableName="DEF_611"></coil>
				</typeLine>
				<typeLine>
					<contact typeContact="openContact" contactVariableName="DEF_610"></contact>
					<emptyCell nbCells="5"></emptyCell>
					<HLink nbCells="4"></HLink>
					<coil typeCoil="coil" coilVariableName="DEF_612"></coil>
				</typeLine>
				<typeLine>
					<HLink nbCells="1"></HLink>
					<contact typeContact="openContact" contactVariableName="TJRS_0"></contact>
					<HLink nbCells="2"></HLink>
					<emptyCell nbCells="2"></emptyCell>
					<HLink nbCells="4"></HLink>
					<coil typeCoil="coil" coilVariableName="DEF_613"></coil>
				</typeLine>
				<typeLine>
					<emptyCell nbCells="6"></emptyCell>
					<HLink nbCells="4"></HLink>
					<coil typeCoil="setCoil" coilVariableName="DEF_614"></coil>
				</typeLine>

Voici mon code:

            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            ////////////////////////////////////                                                                            ////////////////////////////////////
            ////////////////////////////////////                       Génération section de défauts                        ////////////////////////////////////
            ////////////////////////////////////                                                                            ////////////////////////////////////            
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

            if (SectionDefauts.Checked == true)
            {
                int Index_EANA = 0;
                //Constitution de la liste d'EntreeSortie
                List<EntreesANA> entreesANAS = new List<EntreesANA>();
                for (int Index = 0; Index <= nb_lignesES - 1; Index++)
                {
                    //Ajout des différentes entrées ANA
                    if (Tableau_SourceES[Index, 1].Contains("AI_"))
                    {
                        entreesANAS.Add(new EANA(dataSetES.Tables[0].Rows[Index], Index_EANA));
                        Index_EANA = Index_EANA + 1;
                    }
                }




                    //Création du fichier XML source
                    XDocument XmlDoc2 = new XDocument(new XDeclaration("1.0", "UTF-8", "yes"), new XElement("LDExchangeFile", new XElement("fileHeader", new XAttribute("company", "Schneider Automation"), new XAttribute("product", "Control Expert V14.1 - 191122A"), new XAttribute("dateTime", "date_and_time#2018-3-12-16:50:53"), new XAttribute("content", "Fichier source ST"), new XAttribute("DTDVersion", "41")),
                                                                                                                     new XElement("contentHeader", new XAttribute("name", "Station"), new XAttribute("version", "0.0.710"), new XAttribute("dateTime", "date_and_time#2018-2-14-14:39:27")),
                                                                                                                     new XElement("program", new XElement("identProgram", new XAttribute("name", "Def_ANA"), new XAttribute("type", "section"), new XAttribute("task", "MAST")),
                                                                                                                     new XElement("LDSource", new XAttribute("nbColumns", "11"),
                                                                                                                     new XElement("networkLD", from es in entreesANAS
                                                                                                                                               select new XElement("textBox", new XAttribute("width", "11"), new XAttribute("height", "1"), new XElement("objPosition", new XAttribute("posX", "0"), new XAttribute("posY", 16 * es.Index), "Gestion défauts analogiques " + es.Mnemonique)),
                                                                                                                                               
                                                                                                                                               from es in entreesANAS
                                                                                                                                               select new XElement("textBox", new XAttribute("width", "2"), new XAttribute("height", "1"), new XElement("objPosition", new XAttribute("posX", "0"), new XAttribute("posY", 1 + 16 * es.Index), "Défaut rupture fil")),

                                                                                                                                               from es in entreesANAS
                                                                                                                                               select new XElement("textBox", new XAttribute("width", "2"), new XAttribute("height", "1"), new XElement("objPosition", new XAttribute("posX", "0"), new XAttribute("posY", 4 + 16 * es.Index), "Défaut dépassement"))
                                                                                                                                               



                                                                                                                                               ))),

                                                                                                                     new XElement("dataBlock", from es in entreesANAS
                                                                                                                     select new XElement("variables", new XAttribute("name", es.Nom_DFB), new XAttribute("typeName", "DEF_ANA")))


                                                                                                                     ));
                //Test si le fichier existe déjà
                if (File.Exists(NomDossierDest.Text + @"\Sections_LD.xld"))
                {
                    MessageBox.Show("Un fichier section existe déjà dans le dossier de destination. Annulation de l'opération");
                }
                else
                {
                    //Récupération du nom de la zone pour définir le nom du fichier
                    XmlDoc2.Save(NomDossierDest.Text + @"\Sections_LD.xld");
                }

            }



    public abstract class EntreesANA
    {
        /// <summary>
        /// Le constructeur prend en paramètres un tableau de string qui correspond à une ligne du csv, et l'index
        /// </summary>
        /// <param name="LigneCSV"></param>
        /// <param name="Index"></param>
        public EntreesANA(DataRow LigneCSV, int Index)
        {
            this.Mnemonique = LigneCSV[9].ToString();
            this.Adresse = LigneCSV[1].ToString();
            this.Comment = $"{LigneCSV[5]} {LigneCSV[7]}";
            this.Index = Index;
            this.Nom_DFB = $"DEF_ANA_{LigneCSV[9]}";

        }
        public string Nom_DFB { get; set; }
        public string Mnemonique { get; set; }
        public string Adresse { get; set; }
        public int Index { get; set; }
        public string Comment { get; set; }
    }

    public class EANA : EntreesANA
    {
        //le constructeur appelle directement celui de la classe abstraite, et rien d'autre
        public EANA(DataRow LigneCSV, int Index) : base(LigneCSV, Index)
        {
        }

        //Overrider ToString est utile pour le débug, quand on regarde le contenu d'une liste, c'est ça qui est affiché
        public override string ToString()
        {
            return $"Index: {Index}, Adresse: {Adresse}, Mnémonique: {Mnemonique}";
        }
    }
}
0
Précédent
  • 1
  • 2