CommonMethod.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace GDNXFD.Data
  7. {
  8. public class CommonMethod
  9. {
  10. public static DateTime ConvertIntDateTime(double utc)
  11. {
  12. System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1));
  13. startTime = startTime.AddSeconds(utc);
  14. //startTime = startTime.AddHours(8);
  15. return startTime;
  16. }
  17. public static int ConvertDateTimeInt(DateTime time)
  18. {
  19. int utc = 0;
  20. System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1));
  21. utc = (int)(time - startTime).TotalSeconds;
  22. return utc;
  23. }
  24. public static DateTime GetQuarterFloor(DateTime time)
  25. {
  26. var m = time.Minute;
  27. if (m < 15)
  28. return DateTime.Parse(time.ToString("yyyy-MM-dd HH:") + "00:00");
  29. else if (m < 30)
  30. return DateTime.Parse(time.ToString("yyyy-MM-dd HH:") + "15:00");
  31. else if (m < 45)
  32. return DateTime.Parse(time.ToString("yyyy-MM-dd HH:") + "30:00");
  33. else
  34. return DateTime.Parse(time.ToString("yyyy-MM-dd HH:") + "45:00");
  35. }
  36. public static string BuildPointId(string PointID)
  37. {
  38. if (string.IsNullOrWhiteSpace(PointID))
  39. return string.Empty;
  40. string[] ids = PointID.Split('.');
  41. if (ids != null && ids.Length == 3)
  42. {
  43. PointID = ids[1] + "_" + ids[2];
  44. }
  45. return PointID;
  46. }
  47. public static string[] BuildPointIds(string[] ids)
  48. {
  49. string[] ret = null;
  50. if (ids != null)
  51. {
  52. ret = new string[ids.Length];
  53. for (int i = 0; i < ids.Length; i++)
  54. {
  55. ret[i] = BuildPointId(ids[i]);
  56. }
  57. }
  58. return ret;
  59. }
  60. public static string ConvertWindturbineAlertRank(string warnLevel)
  61. {
  62. switch (warnLevel)
  63. {
  64. case "ZC_BJ":
  65. return "1";
  66. case "YJ_BJ":
  67. return "2";
  68. case "GZ_BJ":
  69. return "3";
  70. case "WH_BJ":
  71. return "4";
  72. case "XD_BJ":
  73. return "5";
  74. }
  75. return "3";
  76. }
  77. public static string ConvertIFixAlertRank(string warnLevel)
  78. {
  79. switch (warnLevel)
  80. {
  81. case "LOLO":
  82. return "1";
  83. case "LO":
  84. return "2";
  85. case "MEDIUM":
  86. return "3";
  87. case "HI":
  88. return "4";
  89. case "HIHI":
  90. return "5";
  91. }
  92. return "3";
  93. }
  94. public static string StringCopy(string src, int maxLen)
  95. {
  96. if (src.Length < maxLen)
  97. return src;
  98. else
  99. return src.Substring(0, maxLen);
  100. }
  101. /// <summary>
  102. /// 返回日期几
  103. /// </summary>
  104. /// <returns></returns>
  105. public static string DayOfWeek(DateTime dt)
  106. {
  107. switch (dt.DayOfWeek.ToString("D"))
  108. {
  109. case "0":
  110. return "星期日 ";
  111. case "1":
  112. return "星期一 ";
  113. case "2":
  114. return "星期二 ";
  115. case "3":
  116. return "星期三 ";
  117. case "4":
  118. return "星期四 ";
  119. case "5":
  120. return "星期五 ";
  121. case "6":
  122. return "星期六 ";
  123. }
  124. return "";
  125. }
  126. #region 文件路径分解
  127. public static string GetFilePath(string fullPath)
  128. {
  129. string[] pathInfo = fullPath.Split('\\');
  130. if (pathInfo.Length > 1)
  131. {
  132. int idx = fullPath.LastIndexOf('\\');
  133. string resultStr = fullPath.Substring(0, idx - 0);
  134. return resultStr;
  135. }
  136. return "";
  137. }
  138. public static string GetFileName(string fullPath)
  139. {
  140. string[] pathInfo = fullPath.Split('\\');
  141. if (pathInfo.Length > 1)
  142. {
  143. return pathInfo[pathInfo.Length - 1];
  144. }
  145. return "";
  146. }
  147. public static string GetFileNameNoExtend(string fullPath)
  148. {
  149. string fileName = GetFileName(fullPath);
  150. if (fileName.Length > 0)
  151. {
  152. string[] extInfo = fileName.Split('.');
  153. if (extInfo.Length > 1)
  154. {
  155. int idx = fileName.LastIndexOf('.');
  156. string finalStr = fileName.Substring(0, idx - 0);
  157. return finalStr;
  158. }
  159. }
  160. return "";
  161. }
  162. public static string GetFileExtend(string fullPath)
  163. {
  164. string fileName = GetFileName(fullPath);
  165. if (fileName.Length > 0)
  166. {
  167. string[] extInfo = fileName.Split('.');
  168. if (extInfo.Length > 1)
  169. {
  170. int idx = fileName.LastIndexOf('.');
  171. string finalStr = fileName.Substring(idx + 1, fileName.Length - idx - 1);
  172. return finalStr;
  173. }
  174. }
  175. return "";
  176. }
  177. #endregion
  178. }
  179. }