Exemple #1
0
        //Гибкое расписание
        private StartSequence GetSequence(string id)
        {
            StartSequence result = new StartSequence();
            Connector connector = new Connector();

            #region SQL

            string commandLine = "SET @@lc_time_names='ru_RU';";
            commandLine += @"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=" + id + @" 
                                                    order by seqelem.number";

            #endregion

            using (MySqlConnection connect = new MySqlConnection(connector.ConnectionString))
            using (MySqlCommand cmd = new MySqlCommand(commandLine, connect))
            {
                bool flag = false;
                connect.Open();
                IDataReader rdr = cmd.ExecuteReader();
                while (rdr.Read())
                {
                    if (!flag)
                    {
                        result = SequenceFromReader(rdr);
                        flag = true;
                    }
                    result.Elements.Add(new StartSequence.SeqElem()
                    {
                        Number = (int) rdr["number"],
                        StartTime = rdr["start_time"].ToString(),
                        EndTime = rdr["end_time"].ToString()
                    });
                }
                connect.Close();
            }
            return result;
        }
Exemple #2
0
        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();
        }