/// <summary> /// 从数据库中获取记录仪列表 /// </summary> public static List <NoiseRecorder> GetRecorders() { try { List <NoiseRecorder> recList = new List <NoiseRecorder>(); string sql = string.Empty; sql = "SELECT * FROM EN_NoiseRecorder"; DataTable dtRecorder = SQLHelper.ExecuteDataTable(sql); if (dtRecorder.Rows.Count == 0) { return(recList); //throw new Exception("记录仪数据为空。"); } for (int i = 0; i < dtRecorder.Rows.Count; i++) { NoiseRecorder rec = new NoiseRecorder(); rec.ID = Convert.ToInt32(dtRecorder.Rows[i]["RecorderId"]); rec.Remark = dtRecorder.Rows[i]["Remark"].ToString(); rec.AddDate = Convert.ToDateTime(dtRecorder.Rows[i]["AddDate"]); rec.GroupState = Convert.ToInt32(dtRecorder.Rows[i]["GroupState"]); sql = "SELECT * FROM MT_RecorderSet WHERE RecorderId = " + rec.ID.ToString(); DataTable recSet = SQLHelper.ExecuteDataTable(sql); rec.RecordTime = Convert.ToInt32(recSet.Rows[0]["RecordTime"]); rec.CommunicationTime = Convert.ToInt32(recSet.Rows[0]["CommunicationTime"]); rec.PickSpan = Convert.ToInt32(recSet.Rows[0]["PickSpan"]); rec.Power = Convert.ToInt32(recSet.Rows[0]["StartEnd_Power"]); rec.ControlerPower = Convert.ToInt32(recSet.Rows[0]["Controler_Power"]); rec.Power = Convert.ToInt32(recSet.Rows[0]["StartEnd_Power"]); rec.LeakValue = Convert.ToInt32(recSet.Rows[0]["LeakValue"]); sql = "SELECT GroupId,RecorderId,leakValue,FrequencyValue,OriginalData,CollTime,UnloadTime,HistoryFlag FROM DL_Noise_Real WHERE RecorderId = " + rec.ID + " ORDER BY CollTime DESC"; //DataTable dt_test = SQLiteHelper.ExecuteDataTable(sql, null); using (SqlDataReader reader = SQLHelper.ExecuteReader(sql, null)) { if (reader.Read()) { rec.Data = new NoiseData(); rec.Data.GroupID = Convert.ToInt32(reader["GroupId"]); rec.Data.ReadTime = Convert.ToDateTime(reader.GetString(5)); rec.Data.UploadTime = Convert.ToDateTime(reader.GetString(6)); rec.Data.UploadFlag = Convert.ToInt32(reader["HistoryFlag"]); string[] strAmp = reader["LeakValue"].ToString().Split(','); double[] amp = new double[strAmp.Length]; for (int j = 0; j < strAmp.Length && strAmp.Length > 1; j++) { if (!string.IsNullOrEmpty(strAmp[j])) { amp[j] = Convert.ToDouble(strAmp[j]); } } rec.Data.Amplitude = amp; string[] strFrq = reader["FrequencyValue"].ToString().Split(','); double[] frq = new double[strFrq.Length]; for (int j = 0; j < strFrq.Length && strFrq.Length > 1; j++) { if (!string.IsNullOrEmpty(strFrq[j])) { frq[j] = Convert.ToDouble(strFrq[j]); } } rec.Data.Frequency = frq; string[] strDa = reader["OriginalData"].ToString().Split(','); short[] da = new short[strDa.Length]; for (int j = 0; j < strDa.Length; j++) { if (strDa[j] != "") { da[j] = Convert.ToInt16(strDa[j]); } } rec.Data.OriginalData = da; } } sql = "SELECT GroupId,RecorderId,MinLeakValue,MinFrequencyValue,IsLeak,ESA,COllTime,UnloadTime,HistoryFlag,EnergyValue,LeakProbability FROM DL_NoiseAnalyse WHERE RecorderId = " + rec.ID + " ORDER BY CollTime DESC"; using (SqlDataReader reader = SQLHelper.ExecuteReader(sql, null)) { if (reader.Read()) { rec.Result = new NoiseResult(); rec.Result.GroupID = Convert.ToInt32(reader["GroupId"]); rec.Result.RecorderID = rec.ID; rec.Result.IsLeak = Convert.ToInt32(reader["IsLeak"]); rec.Result.ReadTime = Convert.ToDateTime(reader.GetString(6)); rec.Result.UploadTime = Convert.ToDateTime(reader.GetString(7)); rec.Result.LeakAmplitude = Convert.ToDouble(reader["MinLeakValue"]); rec.Result.LeakFrequency = Convert.ToDouble(reader["MinFrequencyValue"]); rec.Result.EnergyValue = Convert.ToDouble(reader["EnergyValue"]); rec.Result.LeakProbability = Convert.ToDouble(reader["LeakProbability"]); //rec.Result.UploadFlag = (int)reSet.Rows[0]["HistoryFlag"]; } } sql = @"SELECT GroupId FROM MP_GroupRecorder WHERE RecorderId = " + rec.ID.ToString(); object gID = SQLHelper.ExecuteScalar(sql); if (gID == null) { rec.GroupID = 0; } else { rec.GroupID = Convert.ToInt32(gID); } recList.Add(rec); } return(recList); } catch (Exception ex) { throw ex; } }