Пример #1
0
        public static DateTime?[] Load(string _path)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(XMLSerial));

            try
            {
                FileStream fs  = File.OpenRead(_path);
                XMLSerial  xms = (XMLSerial)serializer.Deserialize(fs);
                fs.Close();

                Member.list       = xms.listMembers;
                Position.listRoot = xms.listPositions;

                Position.list = new List <Position>(Position.listRoot);

                foreach (Position pos in Position.listRoot)
                {
                    Position.list.AddRange(pos.FindDescendents());
                }

                Position.list = Position.Sort(Position.list);
                Position.setCount();

                foreach (Position pos in Position.list)
                {
                    pos.listChildren = Position.Sort(pos.listChildren);

                    foreach (Position child in pos.listChildren)
                    {
                        child.posParent = pos;
                    }

                    pos.listConditions.AddRange(pos.listPre);
                    pos.listConditions.AddRange(pos.listSuf);
                    pos.listConditions.AddRange(pos.listPreSuf);
                    pos.listConditions.AddRange(pos.listCs);

                    pos.listConditions = Condition.Sort(pos.listConditions);
                }

                return(new DateTime?[] { xms.dtStart, xms.dtEnd });
            }
            catch
            {
                MessageBox.Show("Unable to read data from file. The file may be corrupt, incorrectly formatted, or inaccessible.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            return(null);
        }
Пример #2
0
        public static void Save(string _path, DateTime?_start, DateTime?_end)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(XMLSerial));

            XMLSerial xms = new XMLSerial(Member.list, Position.listRoot, _start, _end);

            foreach (Position pos in Position.list)
            {
                pos.listPre    = new List <PreCondition>();
                pos.listSuf    = new List <SufCondition>();
                pos.listPreSuf = new List <PreSufCondition>();
                pos.listCs     = new List <CsCondition>();

                foreach (Condition con in pos.listConditions)
                {
                    if (con is PreCondition)
                    {
                        pos.listPre.Add((PreCondition)con);
                    }
                    else if (con is SufCondition)
                    {
                        pos.listSuf.Add((SufCondition)con);
                    }
                    else if (con is PreSufCondition)
                    {
                        pos.listPreSuf.Add((PreSufCondition)con);
                    }
                    else if (con is CsCondition)
                    {
                        pos.listCs.Add((CsCondition)con);
                    }
                }
            }

            if (File.Exists(_path))
            {
                File.Delete(_path);
            }

            FileStream fs = File.Create(_path);

            serializer.Serialize(fs, xms);
            fs.Close();
        }
Пример #3
0
 private void BgwLoadProfile_DoWork(object sender, DoWorkEventArgs e)
 {
     e.Result = XMLSerial.Load((string)e.Argument);
 }
Пример #4
0
        private void BgwSaveProfile_DoWork(object sender, DoWorkEventArgs e)
        {
            Tuple <string, DateTime?, DateTime?> arg = (Tuple <string, DateTime?, DateTime?>)e.Argument;

            XMLSerial.Save(arg.Item1, arg.Item2, arg.Item3);
        }