コード例 #1
0
ファイル: Mapper.cs プロジェクト: powerfxxx/passext
        public Schedule ScheduleFromXML(string xml)
        {

            XElement element = XElement.Parse(xml);

            Schedule Sched = new Schedule();
            Sched.ID = element.Attribute("ID").Value;
            Sched.WayID = element.Attribute("WayID").Value;
            Sched.Start_time = element.Attribute("StartTime").Value;
            Sched.End_time = element.Attribute("EndTime").Value;
            Sched.Days = element.Attribute("Days").Value;
            Sched.UDate = element.Attribute("UDate").Value;
            Sched.Sequence_ID = element.Attribute("seq_id").Value == "undefined"
                ? ""
                : element.Attribute("seq_id").Value;
            Sched.dflag = element.Attribute("dflag").Value;
            IEnumerable<XElement> PGroups = element.Descendants("pgroup");
            foreach (XElement e in PGroups)
                Sched.PGroups.Add(
                    new PGroup()
                    {
                        ID = Int32.Parse(e.Attribute("PGroupID").Value),
                        TakeTime = e.Attribute("TakeTime").Value
                    });
            if (element.Descendants("seq").Count() != 0)
            {
                XElement Seq = element.Descendants("seq").First();
                Sched.Sequence = new StartSequence() {ID = "", FirstDate = DateTime.Parse(Seq.Attribute("fdate").Value)};
                IEnumerable<XElement> SeqElems = Seq.Descendants("seqel");
                foreach (XElement se in SeqElems)
                    Sched.Sequence.Elements.Add(new StartSequence.SeqElem()
                    {
                        Number = Int16.Parse(se.Attribute("num").Value),
                        StartTime = se.Attribute("st").Value,
                        EndTime = se.Attribute("et").Value
                    });
            }
            return Sched;
        }
コード例 #2
0
ファイル: Mapper.cs プロジェクト: powerfxxx/passext
        public void GetSchedules()
        {
            ConnectToDatabase(ConnectionString);
            IDbCommand Command = new MySqlCommand(@"select 
                                                    sch.id,
                                                    sch.way_id,
                                                    date_format(sch.start_time, '%H:%i') start_time,
                                                    date_format(sch.end_time, '%H:%i') end_time,
                                                    sch.days,
                                                    date_format(sch.udate, '%d.%m.%Y') udate,
                                                    sch.sequence_id,
                                                    sch.dflag,
                                                    sp.schedule_id,
                                                    sp.pgroup_id,
                                                    date_format(sp.taketime, '%H:%i') taketime,
                                                    ws.goback
                                                    from schedule sch
                                                    left join schedule_points sp on sch.id = sp.schedule_id
                                                    left join ways ws on sch.way_id = ws.id
                                                    order by sch.id
                                                    ", (MySqlConnection) DatabaseConnection);
            IDataReader ResultReader = ExecuteReadCommand(Command);
            SharedObjects.Schedules.Clear();
            Schedule curSched = new Schedule();
            bool flag = false;
            while (ResultReader.Read())
            {
                if (curSched.ID != ResultReader["id"].ToString())
                {
                    if (flag) SharedObjects.Schedules.Add(curSched);
                    else flag = true;
                    curSched = ScheduleFromReader(ResultReader);
                }
                if (ResultReader["pgroup_id"].ToString() != "")
                    curSched.PGroups.Add(new PGroup()
                    {
                        ID = (int) ResultReader["pgroup_id"],
                        TakeTime = ResultReader["taketime"].ToString()
                    });
            }
            SharedObjects.Schedules.Add(curSched);

            foreach (Schedule sched in SharedObjects.Schedules)
            {
                ResultReader.Close();
                if (sched.Sequence_ID != null && sched.Sequence_ID != "")
                {
                    Command = new MySqlCommand(@"select
                                                    seq.id,
                                                    date_format(seq.first_date, '%d.%m.%Y') first_date,
                                                    seqelem.number,
                                                    date_format(seqelem.start_time, '%H:%i') start_time,
                                                    date_format(seqelem.end_time, '%H:%i') end_time
                                                    from sequences seq
                                                    left join seqelem on seqelem.sequence_id = seq.id
                                                    where seq.id=" + sched.Sequence_ID + @" 
                                                    order by seqelem.number
                                                    ", (MySqlConnection) DatabaseConnection);

                    StartSequence curSeq = new StartSequence();
                    flag = false;
                    ResultReader = ExecuteReadCommand(Command);
                    while (ResultReader.Read())
                    {
                        if (!flag)
                        {
                            curSeq = SequenceFromReader(ResultReader);
                            curSeq.DayStr = sched.Days;
                            flag = true;
                        }
                        curSeq.Elements.Add(new StartSequence.SeqElem()
                        {
                            Number = (int) ResultReader["number"],
                            StartTime = ResultReader["start_time"].ToString(),
                            EndTime = ResultReader["end_time"].ToString()
                        });
                    }
                    sched.Sequence = curSeq;
                }
            }

            DisconnectFromDatabase();
        }