123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace GDNXFD.Data
- {
- public class CommonMethod
- {
- public static DateTime ConvertIntDateTime(double utc)
- {
- System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1));
- startTime = startTime.AddSeconds(utc);
- //startTime = startTime.AddHours(8);
- return startTime;
- }
- public static int ConvertDateTimeInt(DateTime time)
- {
- int utc = 0;
- System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1));
- utc = (int)(time - startTime).TotalSeconds;
- return utc;
- }
- public static DateTime GetQuarterFloor(DateTime time)
- {
- var m = time.Minute;
- if (m < 15)
- return DateTime.Parse(time.ToString("yyyy-MM-dd HH:") + "00:00");
- else if (m < 30)
- return DateTime.Parse(time.ToString("yyyy-MM-dd HH:") + "15:00");
- else if (m < 45)
- return DateTime.Parse(time.ToString("yyyy-MM-dd HH:") + "30:00");
- else
- return DateTime.Parse(time.ToString("yyyy-MM-dd HH:") + "45:00");
- }
- public static string BuildPointId(string PointID)
- {
- if (string.IsNullOrWhiteSpace(PointID))
- return string.Empty;
- string[] ids = PointID.Split('.');
- if (ids != null && ids.Length == 3)
- {
- PointID = ids[1] + "_" + ids[2];
- }
- return PointID;
- }
- public static string[] BuildPointIds(string[] ids)
- {
- string[] ret = null;
- if (ids != null)
- {
- ret = new string[ids.Length];
- for (int i = 0; i < ids.Length; i++)
- {
- ret[i] = BuildPointId(ids[i]);
- }
- }
- return ret;
- }
- public static string ConvertWindturbineAlertRank(string warnLevel)
- {
- switch (warnLevel)
- {
- case "ZC_BJ":
- return "1";
- case "YJ_BJ":
- return "2";
- case "GZ_BJ":
- return "3";
- case "WH_BJ":
- return "4";
- case "XD_BJ":
- return "5";
- }
- return "3";
- }
- public static string ConvertIFixAlertRank(string warnLevel)
- {
- switch (warnLevel)
- {
- case "LOLO":
- return "1";
- case "LO":
- return "2";
- case "MEDIUM":
- return "3";
- case "HI":
- return "4";
- case "HIHI":
- return "5";
- }
- return "3";
- }
- public static string StringCopy(string src, int maxLen)
- {
- if (src.Length < maxLen)
- return src;
- else
- return src.Substring(0, maxLen);
- }
- /// <summary>
- /// 返回日期几
- /// </summary>
- /// <returns></returns>
- public static string DayOfWeek(DateTime dt)
- {
- switch (dt.DayOfWeek.ToString("D"))
- {
- case "0":
- return "星期日 ";
- case "1":
- return "星期一 ";
- case "2":
- return "星期二 ";
- case "3":
- return "星期三 ";
- case "4":
- return "星期四 ";
- case "5":
- return "星期五 ";
- case "6":
- return "星期六 ";
- }
- return "";
- }
- #region 文件路径分解
- public static string GetFilePath(string fullPath)
- {
- string[] pathInfo = fullPath.Split('\\');
- if (pathInfo.Length > 1)
- {
- int idx = fullPath.LastIndexOf('\\');
- string resultStr = fullPath.Substring(0, idx - 0);
- return resultStr;
- }
- return "";
- }
- public static string GetFileName(string fullPath)
- {
- string[] pathInfo = fullPath.Split('\\');
- if (pathInfo.Length > 1)
- {
- return pathInfo[pathInfo.Length - 1];
- }
- return "";
- }
- public static string GetFileNameNoExtend(string fullPath)
- {
- string fileName = GetFileName(fullPath);
- if (fileName.Length > 0)
- {
- string[] extInfo = fileName.Split('.');
- if (extInfo.Length > 1)
- {
- int idx = fileName.LastIndexOf('.');
- string finalStr = fileName.Substring(0, idx - 0);
- return finalStr;
- }
- }
- return "";
- }
- public static string GetFileExtend(string fullPath)
- {
- string fileName = GetFileName(fullPath);
- if (fileName.Length > 0)
- {
- string[] extInfo = fileName.Split('.');
- if (extInfo.Length > 1)
- {
- int idx = fileName.LastIndexOf('.');
- string finalStr = fileName.Substring(idx + 1, fileName.Length - idx - 1);
- return finalStr;
- }
- }
- return "";
- }
- #endregion
- }
- }
|