示例#1
0
 static public void Serialize(Stream s)
 {
     using (StreamWriter sw = new StreamWriter(s))
     {
         LessCont Cont = new LessCont();
         Cont.Create();
         xmlSerializer.Serialize(sw, Cont);
     }
 }
示例#2
0
 static public void Deserialize(Stream s)
 {
     Serialize(new FileStream("backup.xml", FileMode.Create));
     using (StreamReader sr = new StreamReader(s))
     {
         LessCont lessCont = (LessCont)xmlSerializer.Deserialize(sr);
         lessCont.Update();
     }
 }
示例#3
0
        private void XmlButton_Click(object sender, EventArgs e)
        {
            Type type = null;
            FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();

            if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
            {
                int Number = 0;
                foreach (List <object> res in arrays)
                {
                    LessCont nlist1 = new LessCont();
                    if (res[0] is Address)
                    {
                        List <_Address> nlist = new List <_Address>();
                        foreach (Address a in res)
                        {
                            nlist.Add(_Address.Trans(a));
                        }
                        type = typeof(_Address);
                        nlist1.AddressSet = nlist;
                    }
                    else if (res[0] is City)
                    {
                        List <_City> nlist = new List <_City>();
                        foreach (City a in res)
                        {
                            nlist.Add(_City.Trans(a));
                        }
                        type           = typeof(_City);
                        nlist1.CitySet = nlist;
                    }
                    else if (res[0] is Customer)
                    {
                        List <_Customer> nlist = new List <_Customer>();
                        foreach (Customer a in res)
                        {
                            nlist.Add(_Customer.Trans(a));
                        }
                        type = typeof(_Customer);
                        nlist1.CustomerSet = nlist;
                    }
                    else if (res[0] is House)
                    {
                        List <_House> nlist = new List <_House>();
                        foreach (House a in res)
                        {
                            nlist.Add(_House.Trans(a));
                        }
                        type            = typeof(_House);
                        nlist1.HouseSet = nlist;
                    }
                    else if (res[0] is Meter)
                    {
                        List <_Meter> nlist = new List <_Meter>();
                        foreach (Meter a in res)
                        {
                            nlist.Add(_Meter.Trans(a));
                        }
                        type            = typeof(_Meter);
                        nlist1.MeterSet = nlist;
                    }
                    else if (res[0] is MeterType)
                    {
                        List <_MeterType> nlist = new List <_MeterType>();
                        foreach (MeterType a in res)
                        {
                            nlist.Add(_MeterType.Trans(a));
                        }
                        type = typeof(_MeterType);
                        nlist1.MeterTypeSet = nlist;
                    }
                    else if (res[0] is Order)
                    {
                        List <_Order> nlist = new List <_Order>();
                        foreach (Order a in res)
                        {
                            nlist.Add(_Order.Trans(a));
                        }
                        type            = typeof(_Order);
                        nlist1.OrderSet = nlist;
                    }
                    else if (res[0] is OrderEntry)
                    {
                        List <_OrderEntry> nlist = new List <_OrderEntry>();
                        foreach (OrderEntry a in res)
                        {
                            nlist.Add(_OrderEntry.Trans(a));
                        }
                        type = typeof(_OrderEntry);
                        nlist1.OrderEntrySet = nlist;
                    }
                    else if (res[0] is Person)
                    {
                        List <_Person> nlist = new List <_Person>();
                        foreach (Person a in res)
                        {
                            nlist.Add(_Person.Trans(a));
                        }
                        type = typeof(_Person); nlist1.PersonSet = nlist;
                    }
                    else if (res[0] is Status)
                    {
                        List <_Status> nlist = new List <_Status>();
                        foreach (Status a in res)
                        {
                            nlist.Add(_Status.Trans(a));
                        }
                        type = typeof(_Status); nlist1.StatusSet = nlist;
                    }
                    else if (res[0] is Street)
                    {
                        List <_Street> nlist = new List <_Street>();
                        foreach (Street a in res)
                        {
                            nlist.Add(_Street.Trans(a));
                        }
                        type = typeof(_Street); nlist1.StreetSet = nlist;
                    }
                    else if (res[0] is Stavka)
                    {
                        List <_Stavka> nlist = new List <_Stavka>();
                        foreach (Stavka a in res)
                        {
                            nlist.Add(_Stavka.Trans(a));
                        }
                        type = typeof(_Stavka); nlist1.StavkaSet = nlist;
                    }
                    else if (res[0] is User)
                    {
                        List <_User> nlist = new List <_User>();
                        foreach (User a in res)
                        {
                            nlist.Add(_User.Trans(a));
                        }
                        type = typeof(_User); nlist1.UserSet = nlist;
                    }
                    XmlSerializer xmlSerializer = new XmlSerializer(typeof(LessCont));
                    using (StreamWriter sw = new StreamWriter(folderBrowserDialog.SelectedPath + '\\' + (++Number) + ".xml"))
                        xmlSerializer.Serialize(sw, nlist1);
                }
            }
        }