///--------------------------------------------------------------------------------------------------------------------------
            /// <summary>
            /// Start() 함수를 호출한 시각부터 흐른 시간을 반환해주는 function.
            /// </summary>
            /// <param name="timeUnit">반환할 시간의 단위.</param>
            /// <param name="resetTimer">진행된 시간을 반환함과 동시에 타임를 리셋할 것인가를 나타낸다. 만약 타이머를 리셋하면
            /// 다음번 이 함수를 호출할 때에는 이 함수를 호출한 시점부터 진행된 시간을 반환하게 된다.</param>
            /// <returns>진행된 시간을 반환한다.</returns>
            public long GetElapsedTime(TIME_UNIT timeUnit, bool resetTimer)
            {
                // 현재 카운터 값 구하기.
                long currentCount;

                QueryPerformanceCounter(out currentCount);

                // 진행된 시간을 초 단위로 구하기.
                double elapsedTime = (currentCount - startCount) / (double)frequency;

                // 타이머를 리셋하도록 한 경우.
                if (resetTimer)
                {
                    startCount = currentCount;
                }

                // 진행된 시간 반환.
                switch (timeUnit)
                {
                case TIME_UNIT.SECOND: return((long)(elapsedTime * 1));

                case TIME_UNIT.MILLISECOND: return((long)(elapsedTime * 1000));

                case TIME_UNIT.MICROSECOND: return((long)(elapsedTime * 1000000));

                case TIME_UNIT.NANOSECOND: return((long)(elapsedTime * 1000000000));
                }

                return(0);
            }
Exemple #2
0
        public static DataSet Query(uint siteNum, uint sensorNum, DateTime begin, DateTime end, TIME_UNIT unit, bool isSum)
        {
            MySqlConnection connection = new MySqlConnection();

            try
            {
                connection.ConnectionString = GetString();
                connection.Open();
                string sqlFormat = "";
                switch (unit)
                {
                case TIME_UNIT.SECOND:
                    sqlFormat = "SELECT num_site as site,num_sensor as sensor,{4} as data,time_create as time FROM datas WHERE time_create>= '{0}' AND time_create <='{1}' AND num_sensor = {2} AND num_site ={3} order by time_create desc limit 4000";
                    break;

                case TIME_UNIT.MIN:
                    sqlFormat = "SELECT num_site as site,num_sensor as sensor,{4} as data,time_create as time FROM datas_min WHERE time_create>= '{0}' AND time_create <='{1}' AND num_sensor = {2} AND num_site ={3} order by time_create desc limit 4000";
                    break;

                case TIME_UNIT.HOUR:
                    sqlFormat = "SELECT num_site as site,num_sensor as sensor,{4} as data,time_create as time FROM datas_hour WHERE time_create>= '{0}' AND time_create <='{1}' AND num_sensor = {2} AND num_site ={3} order by time_create desc limit 4000";
                    break;

                case TIME_UNIT.DAY:
                    sqlFormat = "SELECT num_site as site,num_sensor as sensor,{4} as data,time_create as time FROM datas_day WHERE time_create>= '{0}' AND time_create <='{1}' AND num_sensor = {2} AND num_site ={3} order by time_create desc limit 4000";
                    break;

                case TIME_UNIT.MONTH:
                    sqlFormat = "SELECT num_site as site,num_sensor as sensor,{4} as data,time_create as time FROM datas_month WHERE time_create>= '{0}' AND time_create <='{1}' AND num_sensor = {2} AND num_site ={3} order by time_create desc limit 4000";
                    break;

                default:
                    break;
                }
                string dataCol = "data";
                if (unit != TIME_UNIT.SECOND)
                {
                    if (isSum)
                    {
                        dataCol = "data_sum";
                    }
                    else
                    {
                        dataCol = "data_avg";
                    }
                }
                MySqlCommand cmd = connection.CreateCommand();
                cmd.CommandText = String.Format(sqlFormat,
                                                begin.ToString("yyyy-MM-dd HH:mm:ss"),
                                                end.ToString("yyyy-MM-dd HH:mm:ss"),
                                                sensorNum,
                                                siteNum,
                                                dataCol);
                cmd.CommandType = CommandType.Text;
                //MySqlDataReader msd = cmd.ExecuteReader();
                MySqlDataAdapter msda = new MySqlDataAdapter(cmd);

                DataSet ret = new DataSet();
                msda.Fill(ret);
                return(ret);
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
                return(null);
            }
            finally
            {
                connection.Close();
            }


//             if (ShuiwenDbContext == null)
//             {
//                 ShuiwenDbContext = new ORDesignerDataContext(DbConnectString.GetString());
//             }
//             var ret =  ShuiwenDbContext.datas.Where(d => d.num_site == siteNum &&
//                 d.num_sensor == sensorNum &&
//                 d.time >= begin &&
//                 d.time <= end);
//             return ret
        }