You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
106 lines
3.1 KiB
106 lines
3.1 KiB
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Configuration;
|
|
using System.Security.Cryptography;
|
|
using System.Text;
|
|
using System.Web;
|
|
|
|
namespace Common.Utility
|
|
{
|
|
public static class GetStatic
|
|
{
|
|
public static string ReadQueryString(string key, string defVal)
|
|
{
|
|
////string str=HttpContext.Current.Request.QueryString[key] ?? defVal;
|
|
////str = str.Replace("#", "");
|
|
////return str;
|
|
return HttpContext.Current.Request.QueryString[key] ?? defVal;
|
|
}
|
|
|
|
public static string ComputeSha256Hash(string rawData)
|
|
{
|
|
// Create a SHA256
|
|
using (SHA256 sha256Hash = SHA256.Create())
|
|
{
|
|
// ComputeHash - returns byte array
|
|
byte[] bytes = sha256Hash.ComputeHash(Encoding.UTF8.GetBytes(rawData));
|
|
|
|
// Convert byte array to a string
|
|
StringBuilder builder = new StringBuilder();
|
|
for (int i = 0; i < bytes.Length; i++)
|
|
{
|
|
builder.Append(bytes[i].ToString("x2"));
|
|
}
|
|
return builder.ToString();
|
|
}
|
|
}
|
|
|
|
public static string ConvertToJson(object obj)
|
|
{
|
|
return JsonConvert.SerializeObject(obj);
|
|
}
|
|
|
|
public static T ConvertToObject<T>(string input) where T : class
|
|
{
|
|
return JsonConvert.DeserializeObject<T>(input);
|
|
}
|
|
|
|
public static string GetSessionId()
|
|
{
|
|
return HttpContext.Current.Session.SessionID;
|
|
}
|
|
|
|
public static double ParseDouble(string value)
|
|
{
|
|
double tmp;
|
|
double.TryParse(value, out tmp);
|
|
return tmp;
|
|
}
|
|
public static long ParseLong(string value)
|
|
{
|
|
long tmp;
|
|
long.TryParse(value, out tmp);
|
|
return tmp;
|
|
}
|
|
|
|
public static string ObjectToJson(object obj)
|
|
{
|
|
return JsonConvert.SerializeObject(obj);
|
|
}
|
|
public static string ReadWebConfig(string key, string defVal)
|
|
{
|
|
try
|
|
{
|
|
return ConfigurationManager.AppSettings[key].ToString() == null ? defVal : ConfigurationManager.AppSettings[key].ToString();
|
|
}
|
|
catch
|
|
{
|
|
return defVal;
|
|
}
|
|
}
|
|
public static String ShowDecimal(String strVal)
|
|
{
|
|
if (strVal != "")
|
|
return String.Format("{0:0,0.00}", double.Parse(strVal));
|
|
else
|
|
return strVal;
|
|
}
|
|
|
|
public static String ShowTwoDecimal(String strVal)
|
|
{
|
|
if (strVal != "")
|
|
return double.Parse(strVal).ToString("0.00");
|
|
else
|
|
return strVal;
|
|
}
|
|
public static string Truncate(this string value, int maxLength)
|
|
{
|
|
var returnValue = "";
|
|
if (string.IsNullOrEmpty(value)) return value;
|
|
|
|
returnValue = value.Length <= maxLength ? value : value.Substring(0, maxLength);
|
|
|
|
return returnValue;
|
|
}
|
|
}
|
|
}
|