//à»ÅÕºà·Õº ª×èͧ͢µÒÃÒ§»ÃÐàÀ· data { -1 is < ; 0 is == ; 1is > } public static int compareTable(string t1, string t2) { return(VsTableName.compareTable(t1, t2)); //int m1 = int.Parse(t1.Split('_')[1]); //int y1 = int.Parse(t1.Split('_')[2]); //int m2 = int.Parse(t2.Split('_')[1]); //int y2 = int.Parse(t2.Split('_')[2]); //if (y1 > y2) //{ // return 1; //} //else if (y1 == y2) //{ // if (m1 > m2) // { // return 1; // } // else if (m1 == m2) // { // return 0; // } //} //return -1; }
//ÃѺ string ª×èͧ͢µÒÃÒ§·Õèà¡èÒ·ÕèÊØ´ private static string getFirstTable(string[] strDataTable) { return(VsTableName.getOldestTimeTable(strDataTable, DateTime.Now)); //// string[] strDataTable = getStringDataTable(); //string firstTable = ""; //int firstY = 3000; //int firstM = 32; //foreach (string str in strDataTable) //{ // int m = int.Parse(str.Split('_')[1]); // int y = int.Parse(str.Split('_')[2]); // if (firstY > y) // { // firstY = y; // firstM = m; // firstTable = str; // } // else if (firstY == y) // { // if (firstM > m) // { // firstM = m; // firstTable = str; // } // } //} //return firstTable; }
private int getNumberOfMotion(DateTime timeBegin, DateTime timeEnd, string cameraID) { int number = 0; string[] TableNames = VsTableName.getMonthTableName("data", timeBegin, timeEnd); foreach (string tableName in TableNames) { MySqlConnection conn = this.connecting(ConnString); MySqlCommand comm = conn.CreateCommand(); comm.CommandText = String.Format( "SELECT COUNT(*) as quantity" + " FROM `{3}` where `m_date_start` >= '{0}' And `m_date_start` <='{1}' And `m_ip_camera` = '{2}' " + " ORDER BY `m_date_start` ", tConv(timeBegin), tConv(timeEnd), cameraID, tableName); try { MySqlDataReader aReader = comm.ExecuteReader(); if (aReader.Read()) { number += Int32.Parse(aReader["quantity"].ToString()); } } catch { } finally { conn.Close(); } } return(number); }
private VsFileURL getFileUrlOfMotion(string motionID, DateTime motionDateTime) { string tableName = VsTableName.getMonthTableName("data", motionDateTime); MySqlConnection conn = this.connecting(ConnString); MySqlCommand comm = conn.CreateCommand(); comm.CommandText = String.Format("SELECT `m_file_name` , `m_date_start` FROM `{0}` WHERE `m_id` = '{1}' ;", tableName, motionID); try { MySqlDataReader aReader = comm.ExecuteReader(); string fileName = ""; VsFileURL fUrl = new VsFileURL(); while (aReader.Read()) { fileName = aReader["m_file_name"].ToString(); fUrl.FilesName = aReader["m_date_start"].ToString(); } string ftpUser = ""; string ftpPass = ""; fUrl.FilesID = motionID; string s = fileName.Split(':')[1].Replace("\\", "/"); fUrl.FilesURL = "http://" + ftpUser + ftpPass + hostIP + s; return(fUrl); } catch { return(null); } finally { conn.Close(); } }
//***************************************************************************************** //á»Ã§¨Ò¡ª×è͵ÒÃÒ§à»ç¹ DateTime public static DateTime tableNameToDateTime(string tableName) { return(VsTableName.tableNameToDateTime(tableName)); //if (tableName != "" && tableName != null) //{ // int m = int.Parse(tableName.Split('_')[1]); // int y = int.Parse(tableName.Split('_')[2]); // return new DateTime(y, m, 1); //} //else //{ // return DateTime.Now; //} }
private List <VsMotion> getMotionOfCamAsPeriod(DateTime timeBegin, DateTime timeEnd, string cameraID) { List <VsMotion> motionList = new List <VsMotion>(); string[] TableNames = VsTableName.getMonthTableName("data", timeBegin, timeEnd); foreach (string tableName in TableNames) { MySqlConnection conn = this.connecting(ConnString); MySqlCommand comm = conn.CreateCommand(); comm.CommandText = String.Format( "SELECT `m_id` AS `MotionID`, `m_ip_camera` AS `CameraID`, `m_ip_processor` AS `Processor`, `m_date_start` AS `TimeBegin`, `m_date_end` AS `TimeEnd`, `m_algo_name` AS `algoName`, `m_detail` AS `detail` " + " FROM `{3}` " + " where `m_date_start` >= '{0}' And `m_date_start` <='{1}' And `m_ip_camera` = '{2}' ORDER BY `m_date_start` ", tConv(timeBegin), tConv(timeEnd), cameraID, tableName); try { MySqlDataReader aReader = comm.ExecuteReader(); while (aReader.Read()) { VsMotion m = new VsMotion(); m.MotionID = Int32.Parse(aReader["MotionID"].ToString()); m.cameraID = aReader["CameraID"].ToString(); m.processor = aReader["Processor"].ToString(); m.timeBegin = DateTime.Parse(aReader["TimeBegin"].ToString()); m.timeEnd = DateTime.Parse(aReader["TimeEnd"].ToString()); m.r_algo_name = aReader["algoName"].ToString(); m.r_detail = aReader["detail"].ToString(); motionList.Add(m); } } catch { } finally { conn.Close(); } } return(motionList); }
private List <int> getNumberOfMotionInYear(DateTime timeBegin, DateTime timeEnd, string cameraID) { List <int> valueList = new List <int>(); int[] values = new int[12]; string[] TableNames = VsTableName.getMonthTableName("data", timeBegin, timeEnd); foreach (string tableName in TableNames) { MySqlConnection conn = this.connecting(ConnString); MySqlCommand comm = conn.CreateCommand(); // comm.CommandText = String.Format( // "SELECT month ( `report`.`r_date_start`) as month , COUNT(*) as quantity" // + " FROM `report` Where `report`.`r_date_start` >= '{0}' And `report`.`r_date_start` <='{1}' And `report`.`r_ip_camera` = {2} " //+ " group by month(`report`.`r_date_start` ) ", tConv(timeBegin), tConv(timeEnd), cameraID); comm.CommandText = String.Format( "SELECT month ( `m_date_start`) as month , COUNT(*) as quantity" + " FROM `{3}` where `m_date_start` >= '{0}' And `m_date_start` <='{1}' And `m_ip_camera` = '{2}' " + " group by month (`m_date_start` ) ", tConv(timeBegin), tConv(timeEnd), cameraID, tableName); try { MySqlDataReader aReader = comm.ExecuteReader(); int number = 0; while (aReader.Read()) { number = Int32.Parse(aReader["quantity"].ToString()); values[Int32.Parse(aReader["month"].ToString()) - 1] += number; } } catch { } finally { conn.Close(); } } valueList.AddRange(values); return(valueList); }
//á»Å§¨Ò¡ DateTime à»ç¹ª×è͵ÒÃÒ§ public static string DateTimeToTableName(string tableType, DateTime date) { return(VsTableName.dateTimeToTableName(tableType, date));//String.Format("{0}_{1}_{2}", tableType, date.Month, date.Year); }