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);
}
///
/// 返回日期几
///
///
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
}
}