Exemple #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="partys"> Список партий</param>
        /// <param name="operations">Список операций</param>
        /// <param name="equipments_">Список оборудований</param>
        public static void ReadData(out List <IParty> partys, out Dictionary <int, IOperation> operations, out Dictionary <int, IEquipment> equipments_)
        {
            partys     = null;
            operations = null;
            equipments = null;

            List <Interval> intlist     = new List <Interval>();
            List <Interval> doneintlist = new List <Interval>();

            equipments = new Dictionary <int, IEquipment>();

            DateTime start = new DateTime();
            DateTime end   = new DateTime();
            XElement root  = sdata.Root;

            df = sdata.Root.Name.Namespace;

            foreach (XElement elm in root.Descendants(df + "CalendarInformation"))
            {
                if (elm.Attribute("date_begin") != null)
                {
                    string date = elm.Attribute("date_begin").Value;
                    DateTime.TryParseExact(date, datapattern, null, System.Globalization.DateTimeStyles.None, out start);
                }
                if (elm.Attribute("date_end") != null)
                {
                    string date = elm.Attribute("date_end").Value;
                    DateTime.TryParseExact(date, datapattern, null, System.Globalization.DateTimeStyles.None, out end);
                }
                foreach (XElement eg in elm.Elements(df + "EquipmentGroup"))
                {
                    foreach (XElement inc in eg.Elements(df + "Include"))
                    {
                        DateTime tmpdata = start;
                        while (tmpdata != end)
                        {
                            if ((int)tmpdata.DayOfWeek == int.Parse(inc.Attribute("day_of_week").Value))
                            {
                                int ind = inc.Attribute("time_period").Value.IndexOf("-");
                                int sh  = int.Parse(inc.Attribute("time_period").Value.Substring(0, 1));
                                int eh  = int.Parse(inc.Attribute("time_period").Value.Substring(ind + 1, 2));

                                intlist.Add(new Interval(new DateTime(tmpdata.Year, tmpdata.Month, tmpdata.Day, sh, 0, 0), new DateTime(tmpdata.Year, tmpdata.Month, tmpdata.Day, eh, 0, 0)));
                            }
                            tmpdata = tmpdata.AddDays(1);
                        }
                    }
                    foreach (XElement exc in eg.Elements(df + "Exclude"))
                    {
                        foreach (Interval t in intlist)
                        {
                            if ((int)t.GetStartTime().DayOfWeek == int.Parse(exc.Attribute("day_of_week").Value))
                            {
                                int ind = exc.Attribute("time_period").Value.IndexOf("-");
                                int sh  = int.Parse(exc.Attribute("time_period").Value.Substring(0, 2));
                                int eh  = int.Parse(exc.Attribute("time_period").Value.Substring(ind + 1, 2));

                                DateTime dt = t.GetStartTime().AddHours(-t.GetStartTime().Hour);
                                Interval tmpint;
                                doneintlist.Add(SeparateInterval(t, dt.AddHours(sh), dt.AddHours(eh), out tmpint));
                                doneintlist.Add(tmpint);
                            }
                        }
                    }
                }
            }

            calendar = new Calendar(doneintlist);


            foreach (XElement elm in root.Descendants(df + "EquipmentInformation").Elements(df + "EquipmentGroup"))
            {
                ReadEquipment(elm, null);
            }

            root   = tdata.Root;
            df     = root.Name.Namespace;
            partys = new List <IParty>();

            operations = new Dictionary <int, IOperation>();
            List <IOperation> tmpOperationsp;

            foreach (XElement product in root.Descendants(df + "Product"))
            {
                foreach (XElement part in product.Elements(df + "Part"))
                {
                    DateTime.TryParseExact(part.Attribute("date_begin").Value, datapattern, null, System.Globalization.DateTimeStyles.None, out begin);
                    DateTime.TryParseExact(part.Attribute("date_end").Value, datapattern, null, System.Globalization.DateTimeStyles.None, out end);
                    Party parent = new Party(begin, end, int.Parse(part.Attribute("priority").Value), part.Attribute("name").Value, int.Parse(part.Attribute("num_products").Value));
                    tmpOperationsp = ReadOperations(part, parent, operations);
                    foreach (IOperation op in tmpOperationsp)
                    {
                        parent.AddOperationToForParty(op);
                    }
                    foreach (XElement subpart in part.Elements(df + "SubPart"))
                    {
                        Party sp = new Party(subpart.Attribute("name").Value, int.Parse(subpart.Attribute("num_products").Value));
                        tmpOperationsp = ReadOperations(subpart, parent, operations);
                        foreach (IOperation op in tmpOperationsp)
                        {
                            sp.AddOperationToForParty(op);
                        }
                        parent.AddSubParty(sp);
                        //partys.Add(sp);
                    }
                    partys.Add(parent);
                }
            }
            equipments_ = equipments;
        }