Пример #1
0
        private void RestoreState(string sourceFile)
        {
            Reset();
            fileName = sourceFile;
            List <WorkData> allWork = new List <WorkData>();

            Auto        car;
            XmlDocument sourceDoc = new XmlDocument();
            WorkData    wd;

            int maxVehIndex = 0;

            try
            {
                FileStream fs = new FileStream(sourceFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                sourceDoc.Load(fs);

                DateTime sourceDate = DateTime.Parse(sourceDoc.DocumentElement.Attributes["date"].Value);
                dateChooser.Value = sourceDate;

                //Autók
                XmlNode         xmlNode  = sourceDoc.DocumentElement.ChildNodes[0];
                List <WorkData> workList = new List <WorkData>();
                int             dest;

                foreach (XmlNode node in xmlNode.ChildNodes)
                {
                    car = new Auto(node.Attributes[0].Value);

                    car.Kapacitas  = int.Parse(node.Attributes[1].Value);
                    car.Lizingdij  = float.Parse(node.Attributes[8].Value);
                    car.Fogyasztas = float.Parse(node.Attributes[9].Value);

                    car.SetNapszakFordulok(0, int.Parse(node.Attributes[2].Value));
                    car.SetNapszakFordulok(1, int.Parse(node.Attributes[3].Value));
                    car.SetNapszakFordulok(2, int.Parse(node.Attributes[4].Value));

                    car.Index = int.Parse(node.Attributes[5].Value);
                    if (car.Index > maxVehIndex)
                    {
                        maxVehIndex = car.Index;
                    }

                    car.Sofor = node.Attributes[6].Value;
                    car.Seged = node.Attributes[7].Value;



                    //Fordulók

                    foreach (XmlNode groupNode in node.ChildNodes)
                    {
                        workList.Clear();
                        dest = int.Parse(groupNode.Attributes[0].Value);
                        foreach (XmlNode workNode in groupNode.ChildNodes)
                        {
                            wd = new WorkData();
                            wd.ParseFromXml(workNode);

                            wd.ParseFold(workNode);
                            wd.ParseKoord(workNode);

                            summary.UpdateWith(wd);

                            workList.Add(wd);
                            allWork.Add(wd);
                        }

                        car.AddFuvar(workList, dest);
                    }

                    vehicles.Add(car);
                }

                if (!Properties.Settings.Default.mentettAuto)
                {
                    dao.GetAutoAdat(vehicles);
                }

                Auto.AutoIndex = maxVehIndex + 1;

                //Csórikák
                xmlNode = sourceDoc.DocumentElement.ChildNodes[1];

                foreach (XmlNode cimNode in xmlNode.ChildNodes)
                {
                    wd = new WorkData();
                    wd.ParseFromXml(cimNode);

                    wd.ParseFold(cimNode);
                    wd.ParseKoord(cimNode);

                    summary.UpdateWith(wd);
                    allWork.Add(wd);

                    if (wd.WorkCapacity <= WorkData.BigCapacityLimit)
                    {
                        if (!wd.Jozsai)
                        {
                            unfive[wd.Napszak - 1]++;
                            m3small[0] += wd.WorkCapacity;
                        }
                        else
                        {
                            unfive[wd.Napszak + 2]++;
                            m3small[1] += wd.WorkCapacity;
                        }
                    }
                    else
                    {
                        if (!wd.Jozsai)
                        {
                            unbig[wd.Napszak - 1]++;
                            m3big[0] += wd.WorkCapacity;
                        }
                        else
                        {
                            unbig[wd.Napszak + 2]++;
                            m3big[1] += wd.WorkCapacity;
                        }
                    }
                }

                if (!Properties.Settings.Default.mentettFold)
                {
                    dao.GetFoldLatLng(allWork);
                }
                if (!Properties.Settings.Default.mentettKoord)
                {
                    dao.GetLatLng(allWork);
                }

                Properties.Settings.Default.lastDir = sourceFile.Substring(0, sourceFile.LastIndexOf('\\'));
                LoadMarkersFromData(allWork);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Állomány megnyitása sikertelen.\nEz a verzió valószínűleg nem kompatibilis a régebbi mentésekkel.",
                                "Megnyitás sikertelen", MessageBoxButtons.OK, MessageBoxIcon.Error);

                AppLogger.WriteException(ex);
                AppLogger.WriteEvent("A kivétel elkapva.");
                Reset();
            }

            AppLogger.WriteOpen(fileName);
        }