initial commit
This commit is contained in:
		
							
								
								
									
										195
									
								
								Viewer/TrendViewer/Class/CFDBA.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										195
									
								
								Viewer/TrendViewer/Class/CFDBA.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,195 @@ | ||||
| using System.Collections.Generic; | ||||
| using System; | ||||
| using System.Drawing; | ||||
| using System.Diagnostics; | ||||
| using System.Data; | ||||
| using System.Collections; | ||||
| using System.Windows.Forms; | ||||
| using AR; | ||||
|  | ||||
| namespace vmsnet | ||||
| { | ||||
|     public class CFDBA | ||||
|     { | ||||
|         string _BaseDir; | ||||
|  | ||||
|         public CFDBA(params string[] dirarrays) | ||||
|         { | ||||
|             var dir = System.IO.Path.Combine(dirarrays); | ||||
|             _BaseDir = dir; | ||||
|             if (System.IO.Directory.Exists(_BaseDir) == false) | ||||
|             { | ||||
|                 System.IO.Directory.CreateDirectory(_BaseDir); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         ////지정한 기간내 파일의 존재여부를 확인합니다. | ||||
|         public int GetfileCount(DateTime sd, DateTime ed) | ||||
|         { | ||||
|             return GetfileS(sd, ed).Count; | ||||
|         } | ||||
|  | ||||
|  | ||||
|         ////기간내 존재하는 파일을 반환합니다(테이블단위) | ||||
|         public List<string> GetfileS(DateTime sd, DateTime ed) | ||||
|         { | ||||
|             List<string> REtval = new List<string>(); | ||||
|             int SttYear = sd.Year; | ||||
|             int EndYear = ed.Year; | ||||
|             if (EndYear < SttYear) | ||||
|             { | ||||
|                 return REtval; | ||||
|             } | ||||
|  | ||||
|             int SttMonth = sd.Month; | ||||
|             int EndMonth = ed.Month; | ||||
|  | ||||
|             int SttDay = sd.Day; | ||||
|             int EndDay = ed.Day; | ||||
|  | ||||
|             int si = System.Convert.ToInt32(sd.ToString("yyyyMMdd")); | ||||
|             int ei = System.Convert.ToInt32(ed.ToString("yyyyMMdd")); | ||||
|             bool SameDay = si == ei ? true : false; | ||||
|  | ||||
|             ////20140101 | ||||
|             for (int dayinfo = si; dayinfo <= ei; dayinfo++) | ||||
|             { | ||||
|                 string DayStr = dayinfo.ToString(); | ||||
|                 System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(_BaseDir + "\\" + DayStr.Substring(0, 4) + "\\" + DayStr.Substring(4, 2) + "\\" + DayStr.Substring(6)); | ||||
|                 if (!dir.Exists) | ||||
|                 { | ||||
|                     continue; | ||||
|                 } | ||||
|                 ////폴더가 존재하므로 해당 테이블파일이 존재하는지 확인한다 | ||||
|  | ||||
|                 if (SameDay) | ||||
|                 { | ||||
|                     ////동일날짜라면 해당 시간대만 조회하면됨 | ||||
|                     for (int hourinfo = int.Parse(sd.ToString("HH")); hourinfo <= int.Parse(ed.ToString("HH")); hourinfo++) | ||||
|                     { | ||||
|                         string fn = dir.FullName + "\\" + (hourinfo + 1).ToString("00") + ".txt"; | ||||
|                         if (System.IO.File.Exists(fn)) | ||||
|                         { | ||||
|                             REtval.Add(fn); | ||||
|                         } | ||||
|                     } | ||||
|                 } | ||||
|                 else | ||||
|                 { | ||||
|                     if (dayinfo == si) ////시작일이라면 시작시간부터 24시까지 이다. | ||||
|                     { | ||||
|                         for (int hourinfo = int.Parse(sd.ToString("HH")); hourinfo <= 23; hourinfo++) | ||||
|                         { | ||||
|                             string fn = dir.FullName + "\\" + (hourinfo + 1).ToString("00") + ".txt"; | ||||
|                             if (System.IO.File.Exists(fn)) | ||||
|                             { | ||||
|                                 REtval.Add(fn); | ||||
|                             } | ||||
|                         } | ||||
|                     } | ||||
|                     else if (dayinfo == ei) ////종료일이라면 1~ 종료시까지이다. | ||||
|                     { | ||||
|                         for (int hourinfo = 0; hourinfo <= int.Parse(ed.ToString("HH")); hourinfo++) | ||||
|                         { | ||||
|                             string fn = dir.FullName + "\\" + (hourinfo + 1).ToString("00") + ".txt"; | ||||
|                             if (System.IO.File.Exists(fn)) | ||||
|                             { | ||||
|                                 REtval.Add(fn); | ||||
|                             } | ||||
|                         } | ||||
|                     } | ||||
|                     else | ||||
|                     { | ||||
|                         ////중간에 끼어있는 날짜라면 1~24모두가 속한다. | ||||
|                         for (int hourinfo = 0; hourinfo <= 23; hourinfo++) | ||||
|                         { | ||||
|                             string fn = dir.FullName + "\\" + (hourinfo + 1).ToString("00") + ".txt"; | ||||
|                             if (System.IO.File.Exists(fn)) | ||||
|                             { | ||||
|                                 REtval.Add(fn); | ||||
|                             } | ||||
|                         } | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|             REtval.Sort(); | ||||
|             return REtval; | ||||
|         } | ||||
|  | ||||
|  | ||||
|         /// <summary> | ||||
|         /// 이번달이후의 데이터를 조회합니다. | ||||
|         /// </summary> | ||||
|         /// <param name="ch"></param> | ||||
|         /// <returns></returns> | ||||
|         /// <remarks></remarks> | ||||
|         public DocumentElement.ALARMDataTable GetAlarmData(int ch) | ||||
|         { | ||||
|             ////이번달이후의 데이터를 가져온다. | ||||
|             DateTime sd = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-01 00:00:00")); | ||||
|             DateTime ed = DateTime.Now; | ||||
|             return GetAlarmData(ch, sd, ed); | ||||
|         } | ||||
|  | ||||
|         public DocumentElement.ALARMDataTable GetAlarmData(DateTime sd, DateTime ed) | ||||
|         { | ||||
|             return GetAlarmData(-1, sd, ed); | ||||
|         } | ||||
|  | ||||
|         public DocumentElement.ALARMDataTable GetAlarmData(DateTime sd, DateTime ed, int rtypes, int rtypee) | ||||
|         { | ||||
|             return GetAlarmData(-1, sd, ed, rtypes, rtypee); | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// 지정된시간사이의 데이터를 조회합니다. | ||||
|         /// </summary> | ||||
|         /// <param name="stime">시작시간(20120319161800)</param> | ||||
|         /// <param name="etime">종료시간(년월일시분초)</param> | ||||
|         /// <returns></returns> | ||||
|         /// <remarks></remarks> | ||||
|         public DocumentElement.ALARMDataTable GetAlarmData(int ch, DateTime sd, DateTime ed, int rtypes = -1, int rtypee = -1) | ||||
|         { | ||||
|             List<string> files = GetfileS(sd, ed); | ||||
|  | ||||
|             DocumentElement.ALARMDataTable alaramDT = new DocumentElement.ALARMDataTable(); | ||||
|             foreach (string fn in files) | ||||
|             { | ||||
|                 foreach (string line in System.IO.File.ReadAllLines(fn)) | ||||
|                 { | ||||
|                     if (line.Trim() == "")  continue; | ||||
|  | ||||
|                     string[] buf = line.Split(System.Convert.ToChar("\t")); | ||||
|                     if (buf.GetUpperBound(0) < 8)  continue; ////데이터수량이 안맞다. | ||||
|  | ||||
|                     string chStr = buf[1]; | ||||
|                     if (chStr.IsNumeric() == false)   continue; ////채널정보가 일치하지 않는경우 | ||||
|  | ||||
|                     if (ch > -1 && chStr != ch.ToString()) continue; | ||||
|  | ||||
|                     if (rtypes != -1 && rtypee != -1) ////rtype도 검색한다. | ||||
|                     { | ||||
|                         if (buf[2] != rtypes.ToString() && buf[2] != rtypee.ToString())  continue; | ||||
|                     } | ||||
|  | ||||
|                     var newdr = alaramDT.NewALARMRow(); | ||||
|                     newdr.ATIME = buf[1]; | ||||
|                     newdr.CH = short.Parse(buf[2]); | ||||
|                     newdr.RTYPE = short.Parse(buf[3]); | ||||
|                     newdr.VOLT = float.Parse(buf[4]); | ||||
|                     newdr.ATYPE = short.Parse(buf[5]); | ||||
|                     newdr.MAXVOLT = float.Parse(buf[6]); | ||||
|                     newdr.MINVOLT = float.Parse(buf[7]); | ||||
|                     newdr.AM = buf[8]; | ||||
|                     newdr.AM2 = buf[9]; | ||||
|                     alaramDT.AddALARMRow(newdr); | ||||
|                 } | ||||
|             } | ||||
|             alaramDT.AcceptChanges(); | ||||
|             return alaramDT; | ||||
|         } | ||||
|  | ||||
|  | ||||
|     } | ||||
|  | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 Arin(asus)
					Arin(asus)