namespace BLL
{
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Data.Linq;
using System.Reflection;
///
/// 通用方法类。
///
public static class Funs
{
///
/// 每页数量
///
public static int PageSize
{
get;
set;
} = 15;
///
/// 维护一个DB集合
///
private static Dictionary dataBaseLinkList = new System.Collections.Generic.Dictionary();
///
/// 维护一个DB集合
///
public static System.Collections.Generic.Dictionary DBList
{
get
{
return dataBaseLinkList;
}
}
///
/// 数据库连接字符串
///
private static string connString;
///
/// 数据库连结字符串。
///
public static string ConnString
{
get
{
if (connString == null)
{
throw new NotSupportedException("请设置连接字符串!");
}
return connString;
}
set
{
if (connString != null)
{
throw new NotSupportedException("连接已设置!");
}
connString = value;
}
}
///
/// 单位设置
///
public static string UnitSet
{
get;
set;
}
///
/// 路径
///
public static string RootPath
{
get;
set;
}
///
/// 系统名
///
public static string SystemName
{
get;
set;
}
// ldap 地址
public static string LdapUrl
{
get;
set;
}
///
/// 数据库上下文。
///
public static Model.EProjectDB DB
{
get
{
if (!DBList.ContainsKey(System.Threading.Thread.CurrentThread.ManagedThreadId))
{
DBList.Add(System.Threading.Thread.CurrentThread.ManagedThreadId, new Model.EProjectDB(connString));
}
return DBList[System.Threading.Thread.CurrentThread.ManagedThreadId];
}
}
public static void PleaseSelect(System.Web.UI.WebControls.DropDownList DDL, string itemText)
{
DDL.Items.Insert(0, new System.Web.UI.WebControls.ListItem(itemText, BLL.Const._Null));
return;
}
// 单点登陆ClientId参数
public static string ClientId
{
get;
set;
}
// 单点登陆ClientSecret参数
public static string ClientSecret
{
get;
set;
}
// 单点登陆Redirect_url参数
public static string Redirect_url
{
get;
set;
}
///
/// 为目标下拉框加上 "请选择" 项
///
/// 目标下拉框
public static void FineUIPleaseSelect(FineUIPro.DropDownList DDL)
{
DDL.Items.Insert(0, new FineUIPro.ListItem("", BLL.Const._Null));
return;
}
///
/// 为目标下拉框加上 "请选择" 项
///
/// 目标下拉框
public static void FineUINA(FineUIPro.DropDownList DDL)
{
DDL.Items.Insert(0, new FineUIPro.ListItem(" N/A ", BLL.Const._Null));
return;
}
///
/// 类型请选择
///
///
public static void FineUIPleaseSelectJobType(FineUIPro.DropDownList DDL)
{
DDL.Items.Insert(0, new FineUIPro.ListItem("Select Job Type", BLL.Const._Null));
return;
}
///
/// 状态请选择
///
///
public static void FineUIPleaseSelectJobStatus(FineUIPro.DropDownList DDL)
{
DDL.Items.Insert(0, new FineUIPro.ListItem("Select Job Status", BLL.Const._Null));
return;
}
///
/// 专业请选择
///
///
public static void FineUIPleaseSelectDivision(FineUIPro.DropDownList DDL)
{
DDL.Items.Insert(0, new FineUIPro.ListItem("Select Division", BLL.Const._Null));
return;
}
///
/// 尾项专业请选择
///
///
public static void FineUIPleaseSelectPunshDiscipline(FineUIPro.DropDownList DDL)
{
DDL.Items.Insert(0, new FineUIPro.ListItem("Select Punch Discipline", BLL.Const._Null));
return;
}
public static void FineUIPleaseSelectPunshClass(FineUIPro.DropDownList DDL)
{
DDL.Items.Insert(0, new FineUIPro.ListItem("Select Punch Priority", BLL.Const._Null));
return;
}
public static void FineUIPleaseSelect(FineUIPro.DropDownList DDL, string itemText)
{
DDL.Items.Insert(0, new FineUIPro.ListItem(itemText, BLL.Const._Null));
return;
}
///
/// 为目标下拉框加上 "重新编制" 项
///
/// 目标下拉框
//public static void ReCompileSelect(System.Web.UI.WebControls.DropDownList DDL)
//{
// DDL.Items.Insert(0, new System.Web.UI.WebControls.ListItem("重新编制", "0"));
// return;
//}
///
/// 为目标下拉框加上 "重新编制" 项
///
/// 目标下拉框
//public static void FineUIReCompileSelect(FineUIPro.DropDownList DDL)
//{
// DDL.Items.Insert(0, new FineUIPro.ListItem("重新编制", "0"));
// return;
//}
///
/// 字符串是否为浮点数
///
/// 要检查的字符串
/// 返回是或否
public static bool IsDecimal(string decimalStr)
{
if (String.IsNullOrEmpty(decimalStr))
{
return false;
}
try
{
Convert.ToDecimal(decimalStr, NumberFormatInfo.InvariantInfo);
return true;
}
catch (Exception ex)
{
ErrLogInfo.WriteLog(ex);
return false;
}
}
///
/// 判断一个字符串是否是整数
///
/// 要检查的字符串
/// 返回是或否
public static bool IsInteger(string integerStr)
{
if (String.IsNullOrEmpty(integerStr))
{
return false;
}
try
{
Convert.ToInt32(integerStr, NumberFormatInfo.InvariantInfo);
return true;
}
catch (Exception ex)
{
ErrLogInfo.WriteLog(ex);
return false;
}
}
///
/// 获取新的数字
///
/// 要转换的数字
/// 新的数字
public static string InterceptDecimal(object number)
{
if (number == null)
{
return null;
}
decimal newNumber = 0;
string newNumberStr = "";
int an = -1;
string numberStr = number.ToString();
int n = numberStr.IndexOf(".");
if (n == -1)
{
return numberStr;
}
for (int i = n + 1; i < numberStr.Length; i++)
{
string str = numberStr.Substring(i, 1);
if (str == "0")
{
if (GetStr(numberStr, i))
{
an = i;
break;
}
}
}
if (an == -1)
{
newNumber = Convert.ToDecimal(numberStr);
}
else if (an == n + 1)
{
newNumberStr = numberStr.Substring(0, an - 1);
newNumber = Convert.ToDecimal(newNumberStr);
}
else
{
newNumberStr = numberStr.Substring(0, an);
newNumber = Convert.ToDecimal(newNumberStr);
}
return newNumber.ToString();
}
///
/// 判断字符串从第n位开始以后是否都为0
///
/// 要判断的字符串
/// 开始的位数
/// false不都为0,true都为0
public static bool GetStr(string number, int n)
{
for (int i = n; i < number.Length; i++)
{
if (number.Substring(i, 1) != "0")
{
return false;
}
}
return true;
}
///
/// 获取三位流水号
///
///
///
public static string GetThreeNumber(string num)
{
int number = 0;
string reValue = string.Empty;
try
{
number = Int32.Parse(num) + 1;
if (number.ToString().Length == 1)
{
reValue = "00" + number.ToString();
}
else if (number.ToString().Length == 2)
{
reValue = "0" + number.ToString();
}
else
{
reValue = number.ToString();
}
return reValue;
}
catch (Exception ex)
{
ErrLogInfo.WriteLog(ex);
return "";
}
}
///
/// 截取字符串长度
///
/// 要截取的字符串
/// 长度
/// 截取后字符串
public static string GetSubStr(object str, object n)
{
if (str != null)
{
if (str.ToString().Length > Convert.ToInt32(n))
{
return str.ToString().Substring(0, Convert.ToInt32(n)) + "....";
}
else
{
return str.ToString();
}
}
return "";
}
///
/// 输入文本转换时间类型
///
///
public static DateTime? GetNewDateTime(string time)
{
if (!String.IsNullOrEmpty(time))
{
try
{
return DateTime.Parse(time);
}
catch (Exception ex)
{
ErrLogInfo.WriteLog(ex);
return null;
}
}
else
{
return null;
}
}
///
/// 输入文本转换数字
///
///
public static decimal? GetNewDecimal(string value)
{
if (!String.IsNullOrEmpty(value))
{
try
{
return decimal.Parse(value);
}
catch (Exception ex)
{
ErrLogInfo.WriteLog(ex);
return null;
}
}
else
{
return null;
}
}
public static double? GetNewDouble(string value)
{
if (!String.IsNullOrEmpty(value))
{
try
{
return double.Parse(value);
}
catch (Exception ex)
{
ErrLogInfo.WriteLog(ex);
return null;
}
}
else
{
return null;
}
}
///
/// 输入文本转换数字
///
///
public static decimal GetNewDecimalOrZero(string value)
{
decimal returnValue = 0;
if (!String.IsNullOrEmpty(value))
{
try
{
returnValue = decimal.Parse(value);
}
catch (Exception ex)
{
ErrLogInfo.WriteLog(ex);
return returnValue;
}
}
return returnValue;
}
///
/// 输入文本转换数字类型
///
///
public static int? GetNewInt(string value)
{
if (!String.IsNullOrEmpty(value))
{
try
{
return Int32.Parse(value);
}
catch (Exception ex)
{
ErrLogInfo.WriteLog(ex);
return null;
}
}
else
{
return null;
}
}
///
/// 输入文本转换数字类型
///
///
public static int GetNewIntOrZero(string value)
{
int returnValue = 0;
if (!String.IsNullOrEmpty(value))
{
try
{
returnValue = Int32.Parse(value);
}
catch (Exception ex)
{
ErrLogInfo.WriteLog(ex);
return returnValue;
}
}
return returnValue;
}
///
/// 指定上传文件的名称
///
///
public static string GetNewFileName()
{
Random rm = new Random(System.Environment.TickCount);
return System.DateTime.Now.ToString("yyyyMMddhhmmss") + rm.Next(1000, 9999).ToString();
}
///
/// 根据标识返回字符串list
///
///
///
///
public static List GetStrListByStr(string str, char n)
{
List strList = new List();
if (!string.IsNullOrEmpty(str))
{
strList.AddRange(str.Split(n));
}
return strList;
}
///
/// 本时区日期时间转时间戳
///
///
/// long=Int64
public static long DateTimeToTimestamp(DateTime datetime)
{
DateTime dd = new DateTime(1970, 1, 1, 0, 0, 0, 0);
DateTime timeUTC = DateTime.SpecifyKind(datetime, DateTimeKind.Utc);//本地时间转成UTC时间
TimeSpan ts = (timeUTC - dd);
return (Int64)ts.TotalMilliseconds;//精确到毫秒
}
}
}