1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| using System;
using System.Collections;
using System.Text;
using System.Xml.Serialization;
using System.Xml;
using System.IO;
namespace SmartCode
{
class WriteXmlFile
{
private StreamWriter writer;
private string dts="";
public void Open()
{
//génération du nom du fichier xml en fonction de la date et de l'heure
dts += DateTime.Now.Date.ToLongDateString() + ",à " + DateTime.Now.Hour.ToString()+ "H" +DateTime.Now.Minute.ToString()+ ".xml";
//puis on le génère
writer = File.CreateText(@".\" + dts);
//génération de l'en-tête XML
writer.WriteLine("<?xml version=\"1.0\" encoding=\"utf-8\" ?>");
writer.WriteLine("<ArrayOfArticle xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">");
}
public void Make(ArrayList list)
{
// XmlSerializer x = new XmlSerializer(typeof(ArrayList));
// x.Serialize(writer, list);
foreach(Article article in list)
{
writer.WriteLine("\t<Article>\n\t\t<CodeBarre>{0}</CodeBarre>\n\t\t<Quantite>{1}</Quantite>\n\t\t<Palette>{2}</Palette>\n\t</Article>",article.getCode,article.getQuantite,article.getPalette);
}
writer.WriteLine("</ArrayOfArticle>");
}
public void Close()
{
writer.Close();
}
public void Copy()
{
// File.Copy(@".\" + dts + ".xml", @"\\ST-00\partage\" + dts + "1.xml");
}
}
} |