这里是测试文字。
下面是表格:
1 | 2 |
3 | 4 |
下面是插入的图片。
代码片段:
using System;
using System.Collections.Generic;
using System.Text;
using System.EnterpriseServices;
using System.IO;
using System.Xml;
using System.Globalization;
namespace OrderProcessing
{
[EventTrackingEnabled]
public class CourseComponent:ServicedComponent,IOrder
{
public CourseComponent()
{
}
#region IOrder 成员
public void Order(string xmlOrder)
{
CreateFile();
XmlDocument doc = new XmlDocument();
doc.LoadXml(xmlOrder);
XmlNodeList courses = doc.GetElementsByTagName("Course");
foreach (XmlNode nodeCourse in courses)
{
XmlElement xmlCourse = nodeCourse as XmlElement;
if (xmlCourse != null)
{
string courseNumber = xmlCourse.GetAttribute("Number");
string title = GetText(xmlCourse, "Title")[0];
DateTime date = DateTime.Parse(GetText(xmlCourse, "StartDate")[0]);
string[] attendees = GetText(xmlCourse, "Attendee");
foreach (string attendee in attendees)
{
WriteToFile(courseNumber, title, date, attendee);
}
}
}
CloseFile();
}
#endregion
private StreamWriter writer = null;
private void CreateFile()
{
string uniqueName = Guid.NewGuid().ToString();
writer=new StreamWriter(@"f:/temp/Courses "+uniqueName+".txt");
}
private void CloseFile()
{
writer.Close();
}
private void WriteToFile(string courseNumber, string title, DateTime startDate, string attendee)
{
writer.WriteLine("{0};{1}'{2};{3}", courseNumber, title, startDate.ToString("d",CultureInfo.InvariantCulture), attendee);
}
private string[] GetText(XmlElement xmlCourse, string tagName)
{
string[] text = null;
XmlNodeList nodeList = xmlCourse.GetElementsByTagName(tagName);
if (nodeList.Count < 1)
throw new Exception("No element of type <" + tagName + "> available!");
text=new string[nodeList.Count];
for (int i = 0; i < nodeList.Count; i++)
{
text[i] = (nodeList[i] as XmlElement).InnerText;
}
return text;
}
}
}