Beispiel #1
0
        private void cmdObjektIn_Click(object sender, EventArgs e)
        {
            Person[] personFeld = new Person[3];
            personFeld[0] = new Person("Maier", "Hans", 6714, 3500.0, new DateTime(1962, 3, 5));
            personFeld[1] = new Person("Schmitz", "Peter", 81343, 3750.0, new DateTime(1958, 4, 12));
            personFeld[2] = new Person("Mertens", "Julia", 2297, 3621.5, new DateTime(1959, 12, 30));

            XmlTextWriter xw = new XmlTextWriter("C:\\Temp\\firma.xml", new UnicodeEncoding());
            xw.WriteStartDocument();
            xw.WriteStartElement("firma");

            foreach (Person p in personFeld)
            {
                p.AlsXmlElementSchreiben(xw);
            }
            ////xw.WriteEndElement();
            xw.Close();
        }
Beispiel #2
0
        private void cmdObjekteLesen_Click(object sender, EventArgs e)
        {
            lblAnzeigen.Text = "";

            if (!File.Exists("C:\\Temp\\firma.xml"))
            {
                return;
            }

            Person[] personFeld = new Person[3];
            string na = "";
            string vo = "";
            int pe = 0;
            double ge = 0.0;
            DateTime gt = new DateTime();
            int i;

            XmlReader xr = new XmlTextReader("C:\\Temp\\firma.xml");

            i = 0;

            while (xr.Read())
            {
                if (xr.NodeType == XmlNodeType.Element)
                {
                    if (xr.AttributeCount > 0)
                    {
                        while (xr.MoveToNextAttribute())
                        {
                            switch (xr.Name)
                            {
                                case "name":
                                    na = xr.Value;
                                    break;
                                case "vorname":
                                    vo = xr.Value;
                                    break;
                                case "personalnummer":
                                    pe = Convert.ToInt32(xr.Value);
                                    break;
                                case "gehalt":
                                    ge = Convert.ToSingle(xr.Value);
                                    break;
                                case "geburtstag":
                                    int jahr = Convert.ToInt32(xr.Value.Substring(6, 4));
                                    int monat = Convert.ToInt32(xr.Value.Substring(3, 2));
                                    int tag = Convert.ToInt32(xr.Value.Substring(0, 2));
                                    gt = new DateTime(jahr, monat, tag);
                                    break;
                            }
                            personFeld[i] = new Person(na, vo, pe, ge, gt);
                            i = i + 1;

                        }
                        xr.Close();
                        foreach (Person p in personFeld)
                        {
                            lblAnzeigen.Text += p.ausgabe() + "\n";
                        }
                    }
                }
            }
        }