");
//sets the table border, cell spacing, border color, font of the text, background, foreground, font height
HttpContext.Current.Response.Write("
");
//am getting my grid's column headers
int columnscount = table.Columns.Count;
for (int j = 0; j < columnscount; j++)
{ //write in new column
HttpContext.Current.Response.Write("
");
//Get column headers and make it as bold in excel columns
HttpContext.Current.Response.Write("");
HttpContext.Current.Response.Write(table.Columns[j].ColumnName.ToString());
HttpContext.Current.Response.Write("");
HttpContext.Current.Response.Write("
");
}
HttpContext.Current.Response.Write("
");
int rowNum = 0, totalBorderRows = table.Rows.Count - 5;
foreach (DataRow row in table.Rows)
{//write in new row
HttpContext.Current.Response.Write("
");
for (int i = 0; i < table.Columns.Count; i++)
{
if (fileName == "AccountStatement" && rowNum > totalBorderRows)
{
HttpContext.Current.Response.Write("
");
HttpContext.Current.Response.Write("");
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();
}
public static DataTable ConvertHTMLTableToDataSet(string HTML)
{
// Declarations
DataSet ds = new DataSet();
DataTable dt = null;
DataRow dr = null;
string TableExpression = "
]*>(.*?)
";
string HeaderExpression = "
]*>(.*?)
";
string RowExpression = "
]*>(.*?)
";
string ColumnExpression = "
]*>(.*?)
";
bool HeadersExist = false;
int iCurrentColumn = 0;
int iCurrentRow = 0;
// Get a match for all the tables in the HTML
MatchCollection Tables = Regex.Matches(HTML, TableExpression, RegexOptions.Multiline | RegexOptions.Singleline | RegexOptions.IgnoreCase);
// Loop through each table element
foreach (Match Table in Tables)
{
// Reset the current row counter and the header flag
iCurrentRow = 0;
HeadersExist = false;
// Add a new table to the DataSet
dt = new DataTable();
// Create the relevant amount of columns for this table (use the headers if they
// exist, otherwise use default names)
if (Table.Value.Contains("
", string.Empty);
// Increase the current column
iCurrentColumn += 1;
}
// Add the DataRow to the DataTable
dt.Rows.Add(dr);
}
// Increase the current row counter
iCurrentRow += 1;
}
// Add the DataTable to the DataSet
ds.Tables.Add(dt);
}
return ds.Tables[0];
}
public static string GetCSVFileInTable(string path, bool hasHeader, int numberOfObjects = 0)
{
var dt = new DataTable();
var columnList = new ArrayList();
var sb = new StringBuilder("");
using (CsvReader reader = new CsvReader(path))
{
foreach (string[] values in reader.RowEnumerator)
{
if (hasHeader)
{
dt.Columns.Clear();
dt.Clear();
foreach (var itm in values)
{
var data = itm.Replace(" ", "_").Replace("\"", "");
columnList.Add(data.ToUpper());
}
hasHeader = false;
continue;
}
if (values.Length > 0)
{
sb.Append("");
}
}
}
sb.Append("");
return sb.ToString();
}
public static string GetCSVFileInTableForTxnSyncInficare(string path, bool hasHeader, int numberOfObjects = 0)
{
var dt = new DataTable();
var columnList = new ArrayList();
var sb = new StringBuilder("");
using (CsvReader reader = new CsvReader(path))
{
foreach (string[] values in reader.RowEnumerator)
{
if (hasHeader)
{
dt.Columns.Clear();
dt.Clear();
foreach (var itm in values)
{
var data = itm.Replace(" ", "_").Replace("\"", "").Replace(".", "");
if (string.IsNullOrEmpty(data))
{
data = "AgentName";
}
columnList.Add(data.ToUpper());
}
hasHeader = false;
continue;
}
if (values.Length > 0)
{
sb.Append("");
}
}
}
sb.Append("");
return sb.ToString();
}
public static DataTable GetHistoryChangedList(string logType, string oldData, string newData)
{
var stringSeparators = new[] { "-:::-" };
var oldDataList = oldData.Split(stringSeparators, StringSplitOptions.None);
var newDataList = newData.Split(stringSeparators, StringSplitOptions.None);
var dt = new DataTable();
var col1 = new DataColumn("Field");
var col2 = new DataColumn("Old Value");
var col3 = new DataColumn("New Value");
var col4 = new DataColumn("hasChanged");
dt.Columns.Add(col1);
dt.Columns.Add(col2);
dt.Columns.Add(col3);
dt.Columns.Add(col4);
var colCount = newData == "" ? oldDataList.Length : newDataList.Length;
for (var i = 0; i < colCount; i++)
{
var changeList = ParseChangesToArray(logType, (oldData == "") ? "" : oldDataList[i], (newData == "") ? "" : newDataList[i]);
var row = dt.NewRow();
row[col1] = changeList[0];
row[col2] = changeList[1];
row[col3] = changeList[2];
if (changeList[1] == changeList[2])
{
row[col4] = "N";
}
else
{
row[col4] = "Y";
}
dt.Rows.Add(row);
}
return dt;
}
//
//public static string ToFilterStringNativeTrim(this string strVal)
//{
// var db = new RemittanceDao();
// var str = db.FilterQuoteNative(strVal);
// if (str.ToLower() != "null") str = "'" + str + "'"; else str = "";
// return str;
//}
private static string[] ParseChangesToArray(string logType, string oldData, string newData)
{
const string seperator = "=";
var oldValue = "";
var newValue = "";
var field = "";
if (logType.ToLower() == "insert" || logType.ToLower() == "i" || logType.ToLower() == "update" || logType.ToLower() == "u" || logType.ToLower() == "login fails" || logType.ToLower() == "log in")
{
var seperatorPos = newData.IndexOf(seperator);
if (seperatorPos > -1)
{
field = newData.Substring(0, seperatorPos - 1).Trim();
newValue = newData.Substring(seperatorPos + 1).Trim();
}
}
if (logType.ToLower() == "delete" || logType.ToLower() == "d" || logType.ToLower() == "update" || logType.ToLower() == "u")
{
var seperatorPos = oldData.IndexOf(seperator);
if (seperatorPos > -1)
{
if (field == "")
field = oldData.Substring(0, seperatorPos - 1).Trim();
oldValue = oldData.Substring(seperatorPos + 1).Trim();
}
}
return new[] { field, oldValue, newValue };
}
internal static string ParseOfacJson(string ofacRes, string senderReceiverName)
{
List _listOfac = JsonConvert.DeserializeObject>(ofacRes);
if (_listOfac == null || _listOfac.Count <= 0)
{
return "";
}
StringBuilder sb = new StringBuilder();
sb.AppendLine("
");
sb.Append("
S. No.
OFAC Remarks
");
var strArr = senderReceiverName.Split(' ');
int sNo = 1;
foreach (var item in _listOfac)
{
string data = item.rmrks;
sb.Append("
");
sb.AppendLine("
" + item.sno + "
");
for (int j = 0; j < strArr.Length; j++)
{
if (!string.IsNullOrWhiteSpace(strArr[j]))
{
if (strArr[j].Length > 2)
{
data = data.ToUpper().Replace(strArr[j], GetStatic.PutRedBackGround(strArr[j]));
}
}
}
sb.AppendLine("
" + data + "
");
sb.Append("
");
sNo++;
}
sb.Append("
");
return sb.ToString();
}
internal static string ParseOfacJsonAndGetTopResult(string ofacRes)
{
List _listOfac = JsonConvert.DeserializeObject>(ofacRes);
if (_listOfac == null || _listOfac.Count <= 0)
{
return "";
}
return _listOfac[0].rmrks.ToString();
}
public static DataTable GetHistoryChangedListForAgent(string oldData, string newData)
{
var applicationLogsDao = new ApplicationLogsDao();
return applicationLogsDao.GetAuditDataForAgent(oldData, newData);
}
public static DataTable GetHistoryChangedListForFunction(string oldData, string newData)
{
var applicationLogsDao = new ApplicationLogsDao();
return applicationLogsDao.GetAuditDataForFunction(oldData, newData);
}
public static DataTable GetHistoryChangedListForRole(string oldData, string newData)
{
var applicationLogsDao = new ApplicationLogsDao();
return applicationLogsDao.GetAuditDataForRole(oldData, newData);
}
public static DataTable GetHistoryChangedListForRuleCriteria(string oldData, string newData)
{
var applicationLogsDao = new ApplicationLogsDao();
return applicationLogsDao.GetAuditDataForRuleCriteria(oldData, newData);
}
public static double RoundOff(double num, int place, int currDecimal)
{
if (currDecimal != 0)
return Math.Round(num, currDecimal);
else if (place != 0)
return (Math.Round(num / place)) * place;
return Math.Round(num, 0);
}
public static Boolean IsNumeric(string stringToTest)
{
int result;
return int.TryParse(stringToTest, out result);
}
#region Userpool
public static string GetFullName(string firstName, string middleName, string lastName1, string lastName2)
{
var fullName = firstName;
if (!string.IsNullOrWhiteSpace(middleName))
fullName += " " + middleName;
if (!string.IsNullOrWhiteSpace(lastName1))
fullName += " " + lastName1;
if (!string.IsNullOrEmpty(lastName2))
fullName += " " + lastName2;
return fullName;
}
public static string GetAgent()
{
return ReadSession("agent", "");
}
public static string GetCountry()
{
return ReadSession("country", "");
}
public static string GetUser()
{
var user = ReadSession("admin", "");
WriteSession("admin", user);
//WriteSession("lastActiveTS", DateTime.Now.ToString());
return user;
}
public static string GetAgentId()
{
var branchId = ReadSession("branchId", "");
//WriteSession("lastActiveTS", DateTime.Now.ToString());
return branchId;
}
public static string GetUserType()
{
var userType = ReadSession("userType", "");
//WriteSession("lastActiveTS", DateTime.Now.ToString());
return userType;
}
public static void RemoveUserSession()
{
WriteSession("admin", "");
}
#endregion Userpool
public static string GetBranch()
{
return ReadSession("branch", "");
}
public static string GetDcInfo()
{
return GetLoggedInUser().DcInfo;
return HttpContext.Current.Request.ClientCertificate["SERIALNUMBER"] + ":" + HttpContext.Current.Request.ClientCertificate["SUBJECTCN"];
}
public static string GetIp()
{
return GetLoggedInUser().IPAddress;
return HttpContext.Current.Request.ClientCertificate["REMOTE_ADDR"];
}
public static string ToShortDate(string datetime)
{
try
{
DateTime dt;
DateTime.TryParse(datetime, out dt);
return dt.ToShortDateString();
}
catch
{
return "";
}
}
public static string GetSessionId()
{
return HttpContext.Current.Session.SessionID;
}
public static string EncryptPassword(string pwd)
{
return pwd;
}
public static int GetSessionTimeOut()
{
return 0;
}
#region Read/Write Data
public static string ReadCookie(string key, string defVal)
{
var cookie = HttpContext.Current.Request.Cookies[key];
return cookie == null ? defVal : HttpContext.Current.Server.HtmlEncode(cookie.Value);
}
public static string ReadFormData(string key, string defVal)
{
return HttpContext.Current.Request.Form[key] ?? defVal;
}
public static string GetCountDownInSec()
{
return (ReadWebConfig("countDownInSec") ?? "0").ToString();
}
public static string ReadQueryString(string key, string defVal)
{
return HttpContext.Current.Request.QueryString[key] ?? defVal;
}
public static string ReadValue(string gridName, string key)
{
key = gridName + "_ck_" + key;
var ck = ReadCookie(key, "");
return ck;
}
public static void WriteValue(string gridName, ref DropDownList ddl, string key)
{
key = gridName + "_ck_" + key;
WriteCookie(key, ddl.Text);
}
public static void WriteValue(string gridName, ref TextBox tb, string key)
{
key = gridName + "_ck_" + key;
WriteCookie(key, tb.Text);
}
#endregion Read/Write Data
public static string ReadSession(string key, string defVal)
{
try
{
return HttpContext.Current.Session[key] == null ? defVal : HttpContext.Current.Session[key].ToString();
}
catch (Exception ex)
{
return "";
}
}
public static DataTable ReadSessionAsTable(string key)
{
try
{
return HttpContext.Current.Session[key] == null ? null : HttpContext.Current.Session[key] as DataTable;
}
catch (Exception ex)
{
return null;
}
}
public static void WriteSessionAsDataTable(string key, DataTable dt)
{
HttpContext.Current.Session[key] = dt;
}
public static void WriteSession(string key, string value)
{
HttpContext.Current.Session[key] = value;
}
public static void RemoveSession(string key)
{
if (HttpContext.Current.Session[key] == null)
{
return;
}
HttpContext.Current.Session.Remove(key);
}
public static void DeleteCookie(string key)
{
if (HttpContext.Current.Request.Cookies[key] != null)
{
var aCookie = new HttpCookie(key);
aCookie.Expires = DateTime.Now.AddDays(-1);
HttpContext.Current.Response.Cookies.Add(aCookie);
}
}
public static void AttachJSFunction(ref Button ctl, string evt, string function)
{
ctl.Attributes.Add(evt, function);
}
public static void AttachConfirmMsg(ref Button ctl)
{
AttachConfirmMsg(ref ctl, "Are you sure?");
}
public static void AttachJSFunction(ref DropDownList ctl, string evt, string function)
{
ctl.Attributes.Add(evt, function);
}
public static void AttachJSFunction(ref TextBox ctl, string evt, string function)
{
ctl.Attributes.Add(evt, function);
}
public static void AttachConfirmMsg(ref Button ctl, string confirmText)
{
var function = "return confirm('" + confirmText + "');";
ctl.Attributes.Add("onclick", function);
}
public static LoggedInUser GetLoggedInUser()
{
var userPool = UserPool.GetInstance();
return userPool.GetUser(GetUser());
}
public static void WriteCookie(string key, string value)
{
if (string.IsNullOrEmpty(value.Trim()))
{
DeleteCookie(key);
return;
}
var httpCookie = new HttpCookie(key, value);
httpCookie.Expires = DateTime.Now.AddDays(1);
HttpContext.Current.Response.Cookies.Add(httpCookie);
}
public static string FormatData(string data)
{
if (string.IsNullOrEmpty(data))
return "";
decimal m;
decimal.TryParse(data, out m);
return m.ToString("F2");
}
public static string FormatData(string data, string dataType)
{
if (string.IsNullOrEmpty(data))
return " ";
if (data == "-")
return data;
if (dataType == "D")
{
DateTime d;
DateTime.TryParse(data, out d);
return d.Year + "/" + d.Month.ToString("00") + "/" + d.Day.ToString("00");
}
if (dataType == "DT")
{
DateTime t;
DateTime.TryParse(data, out t);
return t.Year + "/" + t.Month.ToString("00") + "/" + t.Day.ToString("00") + " " + t.Hour.ToString("00") + ":" + t.Minute.ToString("00");
}
if (dataType == "M")
{
decimal m;
decimal.TryParse(data, out m);
return m.ToString("N");
}
return data;
}
public static string FormatDataForForm(string data, string dataType)
{
if (string.IsNullOrEmpty(data))
return "";
if (data == "-")
return data;
if (dataType == "D")
{
DateTime d;
DateTime.TryParse(data, out d);
return d.Year + "/" + d.Month.ToString("00") + "/" + d.Day.ToString("00");
}
if (dataType == "DT")
{
DateTime t;
DateTime.TryParse(data, out t);
return t.Year + "/" + t.Month.ToString("00") + "/" + t.Day.ToString("00") + " " + t.Hour.ToString("00") + ":" + t.Minute.ToString("00");
}
if (dataType == "M")
{
decimal m;
decimal.TryParse(data, out m);
return m.ToString("N");
}
return data;
}
public static string NumberToWord(string data)
{
var str = data.Split('.');
int number = Convert.ToInt32(str[0]);
int dec = 0;
if (str.Length > 1)
dec = Convert.ToInt32(str[1].Substring(0, 2));
if (number == 0) return "Zero";
if (number == -2147483648)
return
"Minus Two Hundred and Fourteen Crore Seventy Four Lakh Eighty Three Thousand Six Hundred and Forty Eight Rupees Fifty Paisa";
int[] num = new int[4];
int first = 0;
int u, h, t;
StringBuilder sb = new System.Text.StringBuilder();
if (number < 0)
{
sb.Append("Minus ");
number = -number;
}
string[] words0 = {
"", "One ", "Two ", "Three ", "Four ",
"Five ", "Six ", "Seven ", "Eight ", "Nine "
};
string[] words1 = {
"Ten ", "Eleven ", "Twelve ", "Thirteen ", "Fourteen ",
"Fifteen ", "Sixteen ", "Seventeen ", "Eighteen ", "Nineteen "
};
string[] words2 = {
"Twenty ", "Thirty ", "Forty ", "Fifty ", "Sixty ",
"Seventy ", "Eighty ", "Ninety "
};
string[] words3 = { "Thousand ", "Lakh ", "Crore " };
num[0] = number % 1000; // units
num[1] = number / 1000;
num[2] = number / 100000;
num[1] = num[1] - 100 * num[2]; // thousands
num[3] = number / 10000000; // crores
num[2] = num[2] - 100 * num[3]; // lakhs
for (int i = 3; i > 0; i--)
{
if (num[i] != 0)
{
first = i;
break;
}
}
for (int i = first; i >= 0; i--)
{
if (num[i] == 0) continue;
u = num[i] % 10; // ones
t = num[i] / 10;
h = num[i] / 100; // hundreds
t = t - 10 * h; // tens
if (h > 0) sb.Append(words0[h] + "Hundred ");
if (u > 0 || t > 0)
{
if (h > 0 && i == 0) sb.Append("and ");
if (t == 0)
sb.Append(words0[u]);
else if (t == 1)
sb.Append(words1[u]);
else
sb.Append(words2[t - 2] + words0[u]);
}
if (i != 0) sb.Append(words3[i - 1]);
}
//sb.Append(" Rupees ");
int d1 = dec / 10;
int d2 = dec % 10;
if (d1 == 0)
sb.Append(words0[d1]);
else if (d1 == 1)
sb.Append(words1[d2]);
else
sb.Append(words2[d1 - 2] + words0[d2]);
//if (dec > 0)
// sb.Append(" Paisa");
return sb.ToString().TrimEnd() + " only";
}
public static string NumberToWord(string data, string currName, string currDecimal)
{
var str = data.Split('.');
int number = Convert.ToInt32(str[0]);
int dec = 0;
if (str.Length > 1)
dec = Convert.ToInt32(str[1].Substring(0, 2));
if (number == 0) return "Zero";
if (number == -2147483648)
return
"Minus Two Hundred and Fourteen Crore Seventy Four Lakh Eighty Three Thousand Six Hundred and Forty Eight Rupees Fifty Paisa";
int[] num = new int[4];
int first = 0;
int u, h, t;
StringBuilder sb = new System.Text.StringBuilder();
if (number < 0)
{
sb.Append("Minus ");
number = -number;
}
string[] words0 = {
"", "One ", "Two ", "Three ", "Four ",
"Five ", "Six ", "Seven ", "Eight ", "Nine "
};
string[] words1 = {
"Ten ", "Eleven ", "Twelve ", "Thirteen ", "Fourteen ",
"Fifteen ", "Sixteen ", "Seventeen ", "Eighteen ", "Nineteen "
};
string[] words2 = {
"Twenty ", "Thirty ", "Forty ", "Fifty ", "Sixty ",
"Seventy ", "Eighty ", "Ninety "
};
//string[] words3 = { "Thousand ", "Lakh ", "Crore " };
string[] words3 = { "Thousand ", "Million ", "Billion " };
num[0] = number % 1000; // units
num[1] = number / 1000;
num[2] = number / 1000000;
num[1] = num[1] - 1000 * num[2]; // thousands
num[3] = number / 1000000000; // billions
num[2] = num[2] - 1000 * num[3]; // millions
for (int i = 3; i > 0; i--)
{
if (num[i] != 0)
{
first = i;
break;
}
}
//for (int i = first; i >= 0; i--)
//{
// if (num[i] == 0) continue;
// u = num[i] % 10; // ones
// t = num[i] / 10;
// h = num[i] / 100; // hundreds
// t = t - 10 * h; // tens
// if (h > 0) sb.Append(words0[h] + "Hundred ");
// if (u > 0 || t > 0)
// {
// if (h > 0 || i < first) sb.Append("and ");
// if (t == 0)
// sb.Append(words0[u]);
// else if (t == 1)
// sb.Append(words1[u]);
// else
// sb.Append(words2[t - 2] + words0[u]);
// }
// if (i != 0) sb.Append(words3[i - 1]);
//}
//num[0] = number % 1000; // units
//num[1] = number / 1000;
//num[2] = number / 100000;
//num[1] = num[1] - 100 * num[2]; // thousands
//num[3] = number / 10000000; // crores
//num[2] = num[2] - 100 * num[3]; // lakhs
//for (int i = 3; i > 0; i--)
//{
// if (num[i] != 0)
// {
// first = i;
// break;
// }
//}
for (int i = first; i >= 0; i--)
{
if (num[i] == 0) continue;
u = num[i] % 10; // ones
t = num[i] / 10;
h = num[i] / 100; // hundreds
t = t - 10 * h; // tens
if (h > 0) sb.Append(words0[h] + "Hundred ");
if (u > 0 || t > 0)
{
if (h > 0 && i == 0) sb.Append("and ");
//if (h > 0 || i < first) sb.Append("and ");
//if (h > 0) sb.Append("and ");
if (t == 0)
sb.Append(words0[u]);
else if (t == 1)
sb.Append(words1[u]);
else
sb.Append(words2[t - 2] + words0[u]);
}
if (i != 0) sb.Append(words3[i - 1]);
}
sb.Append(" " + currName + " ");
int d1 = dec / 10;
int d2 = dec % 10;
if (d1 == 0)
sb.Append(words0[d1]);
else if (d1 == 1)
sb.Append(words1[d2]);
else
sb.Append(words2[d1 - 2] + words0[d2]);
if (dec > 0 && !string.IsNullOrEmpty(currDecimal))
sb.Append(" " + currDecimal);
return sb.ToString().TrimEnd() + " only";
}
#region Read From Web Config
public static string GetAppRoot()
{
return ReadWebConfig("root");
}
public static string GetFilePath()
{
return ReadWebConfig("filePath");
}
public static string GetCustomerFilePath()
{
return ReadWebConfig("customerDocPath");
}
public static string GetUrlRoot()
{
return ReadWebConfig("urlRoot");
}
public static string GetVirtualDirName()
{
return ReadWebConfig("virtualDirName");
}
public static string GetDBUrlRoot()
{
return ReadWebConfig("dbUrlRoot");
}
public static string GetDBRoot()
{
return ReadWebConfig("dbRoot");
}
public static string GetReportPagesize()
{
return ReadWebConfig("reportPageSize");
}
public static string GetUploadFileSize()
{
return ReadWebConfig("fileSize");
}
#endregion Read From Web Config
public static DataTable GetStringToTable(string data)
{
var stringSeparators = new[] { "-:::-" };
var dataList = data.Split(stringSeparators, StringSplitOptions.None);
var dt = new DataTable();
var col1 = new DataColumn("field1");
var col2 = new DataColumn("field2");
var col3 = new DataColumn("field3");
dt.Columns.Add(col1);
dt.Columns.Add(col2);
dt.Columns.Add(col3);
var colCount = dataList.Length;
for (var i = 0; i < colCount; i++)
{
var changeList = dataList[i].Split('=');
var changeListCout = changeList.Length;
var value1 = changeListCout > 0 ? changeList[0].Trim() : "";
var value2 = changeListCout > 1 ? changeList[1].Trim() : "";
var value3 = changeListCout > 2 ? changeList[2].Trim() : "";
var row = dt.NewRow();
row[col1] = value1;
row[col2] = value2;
row[col3] = value3;
dt.Rows.Add(row);
}
return dt;
}
public static DbResult GetPasswordStatus()
{
DbResult dr = null;
if (HttpContext.Current.Session["passwordStatus"] != null)
{
dr = (DbResult)HttpContext.Current.Session["passwordStatus"];
}
return dr;
}
public static void SetPasswordStatus(DbResult dr)
{
HttpContext.Current.Session["passwordStatus"] = dr;
}
public static string GetUserName()
{
var identityArray = HttpContext.Current.User.Identity.Name.Split('\\');
return identityArray.Length > 1 ? identityArray[1] : identityArray[0];
}
public static string GetLogoutPage()
{
return GetUrlRoot() + "/Logout.aspx";
}
public static string GetErrorPage()
{
return GetUrlRoot() + "/Error.aspx";
}
public static string GetAuthenticationPage()
{
return GetUrlRoot() + "/Authentication.aspx";
}
public static string NoticeMessage
{
get { return ReadSession("message", ""); }
set { WriteSession("message", value); }
}
public static bool ToImage(this string value)
{
value = value.ToLower();
if (!value.Contains("."))
{
value = "." + value;
}
if (value == ".jpeg" || value == ".jpg" || value == ".png" || value == ".gif" || value == ".bmp")
return true;
else
{
return false;
}
}
public static string DataTable2ExcelXML(ref DataTable dt)
{
var date = DateTime.Now.Date.ToString("yyyy-MM-dd");
var header = new StringBuilder("");
header.AppendLine("");
header.AppendLine("");
header.AppendLine("");
header.AppendLine("");
header.AppendLine("" + date + "");
header.AppendLine("" + date + "");
header.AppendLine("12.00");
header.AppendLine("");
header.AppendLine("");
header.AppendLine("");
header.AppendLine("");
header.AppendLine("");
header.AppendLine("8010");
header.AppendLine("14805");
header.AppendLine("240");
header.AppendLine("105");
header.AppendLine("False");
header.AppendLine("False");
header.AppendLine("");
header.AppendLine("");
header.AppendLine("");
header.AppendLine("");
header.AppendLine("");
header.AppendLine("");
header.AppendLine("
");
var footer = new StringBuilder("");
footer.AppendLine("
");
footer.AppendLine("");
footer.AppendLine("");
footer.AppendLine("");
footer.AppendLine("");
footer.AppendLine("");
footer.AppendLine("");
footer.AppendLine("300");
footer.AppendLine("300");
footer.AppendLine("");
footer.AppendLine("");
footer.AppendLine("");
footer.AppendLine("");
footer.AppendLine("3");
footer.AppendLine("1");
footer.AppendLine("");
footer.AppendLine("");
footer.AppendLine("False");
footer.AppendLine("False");
footer.AppendLine("");
footer.AppendLine("");
footer.AppendLine("");
const string dataTemplate = "{data}";
var body = new StringBuilder("");
var columnCount = dt.Columns.Count;
body.AppendLine("");
for (var i = 0; i < columnCount; i++)
{
body.AppendLine(dataTemplate.Replace("{data}", dt.Columns[i].ColumnName));
}
body.AppendLine("");
foreach (DataRow dr in dt.Rows)
{
body.AppendLine("");
for (var i = 0; i < columnCount; i++)
{
body.AppendLine(dataTemplate.Replace("{data}", dr[i].ToString()));
}
body.AppendLine("");
}
header.AppendLine(body.ToString());
header.AppendLine(footer.ToString());
return header.ToString().Replace("{rows}", (dt.Rows.Count + 1).ToString()).Replace("{columns}",
dt.Columns.Count.ToString());
}
public static string ReadWebConfig(string key)
{
return ReadWebConfig(key, "");
}
public static string ReadWebConfig(string key, string defValue)
{
return ConfigurationManager.AppSettings[key] ?? defValue;
}
public static string PutYellowBackGround(string mes)
{
return "" + mes + "";
}
public static string PutRedBackGround(string mes)
{
return "" + mes + "";
}
public static string PutBlueBackGround(string mes)
{
return "" + mes + "";
}
public static string PutHalfYellowBackGround(string mes)
{
return "" + mes + "";
}
public static long ReadNumericDataFromQueryString(string key)
{
var tmpId = ReadQueryString(key, "0");
long tmpIdLong;
long.TryParse(tmpId, out tmpIdLong);
return tmpIdLong;
}
public static decimal ReadDecimalDataFromQueryString(string key)
{
var tmpId = ReadQueryString(key, "0");
decimal tmpIdDecimal;
decimal.TryParse(tmpId, out tmpIdDecimal);
return tmpIdDecimal;
}
public static void SetActiveMenu(string menuFunctionId)
{
HttpContext.Current.Session["activeMenu"] = menuFunctionId;
}
public static void ResizeFrame(Page page)
{
// CallBackJs1(page, "Resize Iframe", "window.parent.resizeIframe();");
}
///
/// Set DbResult in Session
///
public static void SetMessage(DbResult value)
{
HttpContext.Current.Session["message"] = value;
}
///
/// Set Error Code and Message in Session
///
///
/// Error Code
///
///
/// Message
///
public static void SetMessage(string errorCode, string msg)
{
var dbResult = new DbResult { ErrorCode = errorCode, Msg = msg };
SetMessage(dbResult);
}
///
/// Jquery Print Message from session
///
public static void PrintMessage(Page page)
{
if (HttpContext.Current.Session["message"] == null)
{
//CallBackJs1(page, "Remove Message", "window.parent.RemoveMessageBox();");
return;
}
var dbResult = GetMessage();
CallBackJs1(page, "Set Message", "window.parent.SetMessageBox(\"" + dbResult.Msg + "\",\"" + dbResult.ErrorCode + "\");");
HttpContext.Current.Session.Remove("message");
}
///
/// Jquery Print Message from session
///
public static void PrintMessageAPI(Page page, JsonResponse apiResponse)
{
CallBackJs1(page, "Set Message", "window.parent.SetMessageBox(\"" + apiResponse.Msg + "\",\"" + apiResponse.ResponseCode + "\");");
HttpContext.Current.Session.Remove("message");
}
///
/// Jquery Print Message from DbResult
///
public static void PrintMessage(Page page, DbResult dbResult)
{
CallBackJs1(page, "Set Message", "window.parent.SetMessageBox(\"" + dbResult.Msg + "\",\"" + dbResult.ErrorCode + "\");");
}
///
/// Jquery Print Message directly passing Error Code and Message
///
public static void PrintMessage(Page page, string errorCode, string msg)
{
CallBackJs1(page, "Set Message", "window.parent.SetMessageBox(\"" + msg + "\",\"" + errorCode + "\");");
}
public static void PrintSuccessMessage(Page page, string msg)
{
PrintMessage(page, "0", msg);
}
public static void PrintErrorMessage(Page page, string msg)
{
PrintMessage(page, "1", msg);
}
///
/// Alert Message from session
///
public static void AlertMessage(Page page)
{
if (HttpContext.Current.Session["message"] == null)
return;
var dbResult = GetMessage();
if (dbResult.Msg == "")
return;
CallBackJs1(page, "Alert Message", "alert(\"" + FilterMessageForJs(dbResult.Msg) + "\");");
HttpContext.Current.Session.Remove("message");
}
///
/// Alert Message directly passing Message
///
public static void AlertMessage(Page page, string msg)
{
CallBackJs1(page, "Alert Message", "alert(\"" + FilterMessageForJs(msg) + "\");");
}
public static void ShowSuccessMessage(string msg)
{
HttpContext.Current.Server.Transfer(GetVirtualDirName() + "/PrintMessage.aspx?errorCode=0&msg=" + msg);
}
public static void ShowErrorMessage(string msg)
{
HttpContext.Current.Server.Transfer(GetVirtualDirName() + "/PrintMessage.aspx?errorCode=1&msg=" + msg);
}
public static string GetActiveMenu()
{
return ReadSession("activeMenu", "");
}
public static string GetBoolToChar(bool chk)
{
return chk ? "Y" : "N";
}
public static bool GetCharToBool(string value)
{
return value.ToUpper() == "Y" ? true : false;
}
public static DbResult GetMessage()
{
return (DbResult)HttpContext.Current.Session["message"];
}
public static void Redirect(Page page, string url)
{
page.ClientScript.RegisterStartupScript(typeof(string), "script", "");
}
public static void CloseDialog(Page page, string returnValue)
{
page.ClientScript.RegisterStartupScript(typeof(string), "scriptClose", "");
}
public static bool VerifyMode()
{
return ReadQueryString("mode", "") == "verify" ? true : false;
}
public static string GetVoucherName(string vType)
{
switch (vType.ToLower())
{
case "j":
return "Journal Voucher";
case "c":
return "Contra Voucher";
case "y":
return "Payment Voucher";
case "r":
return "Receipt Voucher";
case "s":
return "Remittance Voucher";
default:
return "";
}
}
public static String ShowWithoutDecimal(String strVal)
{
if (strVal != "")
return String.Format("{0:0,0}", double.Parse(strVal));
else
return strVal;
}
public static String ShowDecimal(String strVal)
{
if (strVal != "")
return String.Format("{0:0,0.00}", double.Parse(strVal));
else
return strVal;
}
public static String ShowDecimalRate(String strVal)
{
if (strVal != "")
return String.Format("{0:0,0.0000}", double.Parse(strVal));
else
return strVal;
}
public static String ShowAbsDecimal(String strVal)
{
if (strVal != "")
{
strVal = Math.Abs(ParseDouble(strVal)).ToString();
return String.Format("{0:0,0.00}", double.Parse(strVal));
}
else
return strVal;
}
public static string GetNegativeFigureOnBrac(string Amount)
{
var FIndex = Amount[0].ToString();
if (FIndex.Equals("-"))
{
return "(" + ShowDecimal(Amount.Substring(1).ToString()) + ")";
}
else
return ShowDecimal(Amount);
}
public static string ShowDecimal_Account(string Amount)
{
var FIndex = Amount[0].ToString();
if (FIndex.Equals("-"))
{
return ShowAbsDecimal(Amount);
}
else
return "(" + ShowDecimal(Amount.ToString()) + ")";
}
public static string GetRowData(DataRow dr, string fieldName, string defValue)
{
return dr == null ? defValue : dr[fieldName].ToString();
}
public static string GetRowData(DataRow dr, string fieldName)
{
return GetRowData(dr, fieldName, "");
}
public static string GetRowDataInShortDateFormat(DataRow dr, string fieldName)
{
return dr[fieldName].ToString() == "" ? "" : Convert.ToDateTime(dr[fieldName].ToString()).ToShortDateString();
}
public static string ParseResultJsPrint(DbResult dbResult)
{
return dbResult.ErrorCode + "-:::-" + dbResult.Msg.Replace("'", "").Replace(" ", "").Replace(System.Environment.NewLine, "") + "-:::-" + dbResult.Id;
}
public static void CallBackJs1(Page page, String scriptName, string functionName)
{
ScriptManager.RegisterStartupScript(page, page.GetType(), scriptName, functionName, true);
}
public static void CallJSFunction(Page page, string functionName)
{
ScriptManager.RegisterStartupScript(page, page.GetType(), "cb", functionName, true);
}
public static void CallBackJs2(Page page, string scriptName, string functionName)
{
ScriptManager.RegisterStartupScript(page, page.GetType(), scriptName, functionName, true);
}
public static double ParseDouble(string value)
{
double tmp;
double.TryParse(value, out tmp);
return tmp;
}
public static decimal ParseDecimal(string value)
{
decimal tmp;
decimal.TryParse(value, out tmp);
return tmp;
}
public static int ParseInt(string value)
{
int tmp;
int.TryParse(value, out tmp);
return tmp;
}
public static string DataTableToCheckBox(DataTable dt, string name, string valueField, string textField)
{
var sb = new StringBuilder();
foreach (DataRow row in dt.Rows)
{
sb.AppendLine("" + row[textField] + " ");
}
return sb.ToString();
}
public static string ParseMinusValue(double data)
{
var retVal = Math.Abs(data).ToString("N");
if (data < 0)
{
return "(" + retVal + ")";
}
return retVal;
}
public static string ParseMinusValue(string data)
{
var m = ParseDouble(data);
return ParseMinusValue(m);
}
public static DataTable GetHistoryChangedListForIdCriteria(string oldData, string newData, string id)
{
var applicationLogsDao = new ApplicationLogsDao();
return applicationLogsDao.GetAuditDataForIdCriteria(oldData, newData, id);
}
public static DataTable GetHistoryChangedListForCommissionPackage(string oldData, string newData)
{
var applicationLogsDao = new ApplicationLogsDao();
if (string.IsNullOrEmpty(oldData))
oldData = newData;
if (string.IsNullOrEmpty(newData))
newData = oldData;
return applicationLogsDao.GetAuditDataForCommissionPackage(oldData, newData);
}
public static FullName ParseName(string fullName)
{
var fn = new FullName();
var name = fullName.Split(' ');
var names = name.Length;
fn.FirstName = name[0];
fn.MiddleName = "";
fn.LastName1 = "";
fn.LastName2 = "";
if (names > 1)
{
fn.LastName1 = name[1];
if (names > 2)
{
fn.MiddleName = name[1];
fn.LastName1 = name[2];
if (names > 3)
fn.LastName2 = name[3];
if (names > 4)
fn.LastName2 += " " + name[4];
}
}
return fn;
}
//DateTime dt = GetStatic.GMTDatetime();
public static DateTime GMTDatetime()
{
System.DateTime CurrTime = System.DateTime.Now;
System.DateTime CurrUTCTime = CurrTime.ToUniversalTime();
var dt1 = CurrUTCTime.AddMinutes(345);
return dt1;
}
public static String FilterMessageForJs(string strVal)
{
if (strVal.ToLower() != "null")
{
strVal = strVal.Replace("\"", "");
}
return strVal;
}
public static void ReloadJQueryDatePicket(Page p, string textBoxName)
{
CallBackJs1(p, "ajax", "AsyncDone('#" + textBoxName + "');");
//This script handles ajax postbacks, by registering the js to run at the end of *AJAX* requests
//p.ClientScript.RegisterStartupScript(typeof(Page), "ajaxTrigger", "Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);", true);
//p.ClientScript.RegisterClientScriptBlock(typeof(Page), "EndRequest", "function EndRequestHandler(sender, args){" + callBack + ";}", true);
}
public static String GetPopupHelpmsg()
{
var sb = new StringBuilder("");
sb.AppendLine("");
sb.AppendLine("");
sb.AppendLine("");
return sb.ToString();
}
public static string ToRomanNumeral(this int value)
{
if (value < 0)
{
// throw new ArgumentOutOfRangeException("Please use a positive integer greater than zero.");
return "";
}
StringBuilder sb = new StringBuilder();
int remain = value;
while (remain > 0)
{
if (remain >= 1000) { sb.Append("M"); remain -= 1000; }
else if (remain >= 900) { sb.Append("CM"); remain -= 900; }
else if (remain >= 500) { sb.Append("D"); remain -= 500; }
else if (remain >= 400) { sb.Append("CD"); remain -= 400; }
else if (remain >= 100) { sb.Append("C"); remain -= 100; }
else if (remain >= 90) { sb.Append("XC"); remain -= 90; }
else if (remain >= 50) { sb.Append("L"); remain -= 50; }
else if (remain >= 40) { sb.Append("XL"); remain -= 40; }
else if (remain >= 10) { sb.Append("X"); remain -= 10; }
else if (remain >= 9) { sb.Append("IX"); remain -= 9; }
else if (remain >= 5) { sb.Append("V"); remain -= 5; }
else if (remain >= 4) { sb.Append("IV"); remain -= 4; }
else if (remain >= 1) { sb.Append("I"); remain -= 1; }
else
{
//throw new Exception("Unexpected error."); // <<-- shouldn't be possble to get here, but it ensures that we will never have an infinite loop (in case the computer is on crack that day).
}
}
return sb.ToString();
}
public static string getCompanyHead()
{
var headerSplit = ReadWebConfig("companyName", "").Split('|');
string header = "" + headerSplit[0].ToString() + "";
header += " " + headerSplit[1].ToString();
return header;
}
public static string IntToLetter(this int value)
{
string result = string.Empty;
while (--value >= 0)
{
result = (char)('a' + value % 26) + result;
value /= 26;
}
return result + ".";
}
public static string GetVoucherType(string vType, string def)
{
string vt = "";
if (vType.ToLower() == "s")
{
vt = "Sales";
}
else if (vType.ToLower() == "p")
{
vt = "Purchase";
}
else if (vType.ToLower() == "c")
{
vt = "Contra";
}
else if (vType.ToLower() == "y")
{
vt = "Payment";
}
else if (vType.ToLower() == "r")
{
vt = "Receipt";
}
else if (vType.ToLower() == "j")
{
vt = "Journal";
}
else
{
vt = def;
}
return vt;
}
///
///
///
///
///
///
///
///
///
/// 1 - Jquery Message, 2 - Js Alert Message
///
#region for Remittance use only
public static string GetDomesticSuperAgentId()
{
return ReadWebConfig("domesticSuperAgentId");
}
public static string GetHoAgentId()
{
return ReadWebConfig("hoAgentId");
}
#endregion for Remittance use only
public static string GetDomesticCountryId()
{
return ReadWebConfig("domesticCountryId");
}
public static string GetCountryId()
{
return ReadSession("countryId", "");
}
public static string GetDefaultPage()
{
switch (ReadCookie("loginType", "").ToUpper())
{
case "ADMIN":
return GetUrlRoot() + "/admin";
case "AGENT":
return GetUrlRoot() + "/agentlogin";
}
return GetUrlRoot();
}
internal static string GetDefaultDocPath()
{
switch (ReadCookie("loginType", "").ToUpper())
{
case "ADMIN":
return GetUrlRoot() + "/admin";
case "AGENT":
return GetUrlRoot() + "/agentlogin";
}
return GetUrlRoot();
}
public static string GetDefaultDocPathMortgage()
{
return ReadWebConfig("defaultDocPath");
}
public static string GetSendEmailId()
{
return ReadWebConfig("SendEmailId");
}
public static string GetSendEmailPwd()
{
return ReadWebConfig("SendEmailPwd");
}
public static string GetSmtpPort()
{
return ReadWebConfig("SmtpPort");
}
public static string GetSmtpServer()
{
return ReadWebConfig("SmtpServer");
}
public static void JsonResponse(T obk, Page page, DataTable dt = null)
{
string jsonString = "";
if (dt == null)
{
JavaScriptSerializer jsonData = new JavaScriptSerializer();
jsonData.MaxJsonLength = Int32.MaxValue;
jsonString = jsonData.Serialize(obk);
}
else
{
jsonString = DataTableToJson(dt);
}
page.Response.ContentType = "application/json";
page.Response.Write(jsonString);
page.Response.End();
}
public static string DataTableToJson(DataTable table)
{
if (table == null)
return "";
var list = new List>();
foreach (DataRow row in table.Rows)
{
var dict = new Dictionary();
foreach (DataColumn col in table.Columns)
{
dict[col.ColumnName] = string.IsNullOrEmpty(row[col].ToString()) ? "" : row[col];
}
list.Add(dict);
}
var serializer = new JavaScriptSerializer();
string json = serializer.Serialize(list);
return json;
}
public static void DataTableToJson(DataTable table, Page page)
{
if (null == table)
{
page.Response.ContentType = "application/json";
page.Response.Write("");
page.Response.End();
}
else
{
var list = new List>();
foreach (DataRow row in table.Rows)
{
var dict = new Dictionary();
foreach (DataColumn col in table.Columns)
{
dict[col.ColumnName] = string.IsNullOrEmpty(row[col].ToString()) ? "" : row[col];
}
list.Add(dict);
}
var serializer = new JavaScriptSerializer();
string json = serializer.Serialize(list);
page.Response.ContentType = "application/json";
page.Response.Write(json);
page.Response.End();
}
}
public static string ObjectToXML(object input)
{
try
{
StringWriter stringwriter = new StringWriter();
XmlSerializer serializer = new XmlSerializer(input.GetType());
serializer.Serialize(stringwriter, input);
return stringwriter.ToString();
}
catch (Exception ex)
{
if (ex.InnerException != null)
ex = ex.InnerException;
return "Could not convert: " + ex.Message;
}
}
public static string MakeAutoCompleteControl(string uniqueKey, string category, string selectedValue = "", string selectedText = "")
{
var url = GetStatic.GetUrlRoot() + "/Component/AutoComplete/DataSource.asmx/GetList";
var usr = GetStatic.GetUser();
var sb = new StringBuilder();
//var strClientID = rowId + "_" + f.Key;
var ctlValue = uniqueKey + "_aValue";
var ctlText = uniqueKey + "_aText";
var ctlSearch = uniqueKey + "_aSearch";
//grdRole_gl_code_aText_c_admin////grdRole_gl_code_aSearch
sb.Append("");
sb.Append("");
sb.Append("");
sb.Append("");
return sb.ToString();
}
public static string MakeAutoCompleteControlNew(string uniqueKey, string category, string selectedValue = "", string selectedText = "")
{
var url = GetStatic.GetUrlRoot() + "/Component/AutoComplete/DataSource.asmx/GetList";
var usr = GetStatic.GetUser();
var sb = new StringBuilder();
//var strClientID = rowId + "_" + f.Key;
var ctlValue = uniqueKey + "_aValue";
var ctlText = uniqueKey + "_aText";
var ctlSearch = uniqueKey + "_aSearch";
//grdRole_gl_code_aText_c_admin////grdRole_gl_code_aSearch
sb.Append("");
sb.Append("");
sb.Append("");
sb.Append("");
return sb.ToString();
}
public static Location GetLocation(string ipAddress)
{
if (ReadWebConfig("UseLocationAPI", "") == "N")
{
return new Location
{
errorCode = "1",
errorMsg = "Called from DEV, so no API Called!"
};
}
string apiKey = GetStatic.ReadWebConfig("GeoLocationIpInfoKey");
string url = string.Format("http://api.ipinfodb.com/v3/ip-city/?key={0}&ip={1}", apiKey, ipAddress);
JavaScriptSerializer serializer = new JavaScriptSerializer();
try
{
var HttpWReq = (HttpWebRequest)WebRequest.Create(url);
HttpWReq.Method = "GET";
var HttpWResp = (HttpWebResponse)HttpWReq.GetResponse();
System.IO.StreamReader reader = new System.IO.StreamReader(HttpWResp.GetResponseStream());
string content = reader.ReadToEnd();
var _arrLoc = content.Split(';');
if (_arrLoc[0].ToUpper() == "OK")
{
Location _loc = new Location
{
errorCode = "0",
IpAddress = _arrLoc[2],
CountryCode = _arrLoc[3],
CountryName = _arrLoc[4],
Region = _arrLoc[5],
City = _arrLoc[6],
ZipCode = _arrLoc[7],
Lat = _arrLoc[8],
Long = _arrLoc[9],
TimeZone = _arrLoc[10]
};
return _loc;
}
else
{
Location _loc = new Location
{
errorCode = "1",
errorMsg = _arrLoc[0] + " : " + _arrLoc[1]
};
return _loc;
}
}
catch (Exception ex)
{
return new Location
{
errorCode = "1",
errorMsg = ex.Message
};
}
}
public static string GetSMSTextForTxn(DataRow sRow)
{
FullName _fullNameS = GetStatic.ParseName(sRow["senderName"].ToString());
FullName _fullNameR = GetStatic.ParseName(sRow["receiverName"].ToString());
string sms = "";
if (sRow["paymentMethod"].ToString().ToLower() == "bank deposit")
{
FullName _bankName = GetStatic.ParseName(sRow["pBankName"].ToString());
sms += "Dear Mr/Ms " + _fullNameS.FirstName + ", your money sent to account of Mr/Ms " + _fullNameR.FirstName + " in ";
sms += _bankName.FirstName + "... Bank. Amt sent: JPY " + GetStatic.ShowWithoutDecimal(sRow["cAmt"].ToString());
sms += ", Deposit Amt " + sRow["payoutCurr"].ToString() + " " + GetStatic.ShowWithoutDecimal(sRow["pAmt"].ToString()) + ". Thank you-JME.";
}
else
{
sms += "Dear Mr/Ms " + _fullNameS.FirstName + ", your money sent to Mr/Ms " + _fullNameR.FirstName + ". Amt sent: JPY ";
sms += GetStatic.ShowWithoutDecimal(sRow["cAmt"].ToString()) + ", Payout Amt " + sRow["payoutCurr"].ToString() + " " + GetStatic.ShowWithoutDecimal(sRow["pAmt"].ToString()) + ". PIN NO: " + sRow["controlNo"].ToString() + ". Thank you-JME.";
}
return sms;
}
public static string SendEmail(string msgSubject, string msgBody, string toEmailId)
{
SmtpMailSetting mail = new SmtpMailSetting
{
MsgBody = msgBody,
MsgSubject = msgSubject,
ToEmails = toEmailId
};
return mail.SendSmtpMail(mail);
}
private static string InitFunction(string filter, string url, string rowId, string width)
{
var sb = new StringBuilder();
sb.Append("LoadAutoCompleteTextBox(");
sb.Append(@"""" + url + @"""");
sb.Append(@",""#" + rowId + @"""");
sb.Append(@",""" + width + @"""");
sb.Append(@",""" + filter + @""");");
return sb.ToString();
}
public static string UploadSignatureImage(string imageData, string registerDate, string membershipId, string customerId)
{
string errorCode = "1";
try
{
string fileExtension = ".png";
string fileName = customerId + "_signature_" + DateTime.Now.Hour.ToString() + DateTime.Now.Millisecond.ToString() + "_" + registerDate.Replace("-", "_") + fileExtension;
string path = GetStatic.GetCustomerFilePath() + "CustomerDocument\\" + registerDate.Replace("-", "\\") + "\\" + membershipId;
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
string fName = path + "\\" + fileName;
using (FileStream fs = new FileStream(fName, FileMode.CreateNew))
{
using (BinaryWriter bw = new BinaryWriter(fs))
{
byte[] data = Convert.FromBase64String(imageData);
bw.Write(data);
bw.Close();
}
}
errorCode = fileName;
}
catch (Exception ex)
{
errorCode = "1";
}
return errorCode;
}
public static string HTMLToPDF(string htmlString, string user, string fileSaveLocation, string filePrefix = "")
{
string fileName = GetDateTimeStamp() + "_" + user + ".pdf";
if (!string.IsNullOrEmpty(filePrefix))
fileName = filePrefix + "_" + fileName;
HtmlToPdf converter = new HtmlToPdf();
if (!File.Exists(fileSaveLocation))
Directory.CreateDirectory(fileSaveLocation);
PdfDocument doc = converter.ConvertHtmlString(htmlString, ReadWebConfig("root", ""));
doc.Save(fileSaveLocation + fileName);
doc.Close();
return fileName;
}
public static string GetDateTimeStamp()
{
return DateTime.Now.ToString("yyyyMMddHHmmssffff");
}
public static string DataSetToJSON(DataSet ds)
{
ArrayList root = new ArrayList();
List> table;
Dictionary data;
foreach (DataTable dt in ds.Tables)
{
table = new List>();
foreach (DataRow dr in dt.Rows)
{
data = new Dictionary();
foreach (DataColumn col in dt.Columns)
{
data.Add(col.ColumnName, dr[col]);
}
table.Add(data);
}
root.Add(table);
}
JavaScriptSerializer serializer = new JavaScriptSerializer();
return serializer.Serialize(root);
}
#region MIME TYPE
private static IDictionary _mappings = new Dictionary(StringComparer.InvariantCultureIgnoreCase)
{
{".jpe", "image/jpeg"},
{".jpeg", "image/jpeg"},
{".jpg", "image/jpeg"},
{".png", "image/png"},
{".bmp", "image/bmp"},
{".tif", "image/tiff"},
{".tiff", "image/tiff"},
{".pdf", "application/pdf"},
{".gif", "image/gif"},
{".xls", "application/vnd.ms-excel"},
{".xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"},
{".xml", "text/xml"},
{".xps", "application/vnd.ms-xpsdocument"},
{".txt", "text/plain"},
{".csv", "text/csv"},
};
public static string GetFileExtension(this string fileName)
{
string ext = string.Empty;
int fileExtPos = fileName.LastIndexOf(".", StringComparison.Ordinal);
if (fileExtPos >= 0)
ext = fileName.Substring(fileExtPos, fileName.Length - fileExtPos);
return ext;
}
public static string GetMimeType(this string extension)
{
if (extension == null)
{
throw new ArgumentNullException("extension");
}
if (!extension.StartsWith("."))
extension = "." + extension;
string mime;
return _mappings.TryGetValue(extension, out mime) ? mime : "text/plain";
}
#endregion
public static DbResult LogError(Exception lastError, string userid = "")
{
Exception err = lastError;
if (lastError.InnerException != null)
err = lastError.InnerException;
RemittanceDao db = new RemittanceDao();
var errPage = db.FilterString(HttpContext.Current.Request.Url.ToString());
var errMsg = db.FilterString(err.Message);
var errDetails = db.FilterString(lastError.ToString());
var user = !string.IsNullOrWhiteSpace(userid) ? userid : GetUser();
string sql = string.Format(@"EXEC proc_ErrorLogs @flag = 'i', @errorPage={0}, @errorMsg={1}, @errorDetails={2}, @user = {3}", errPage, errMsg, errDetails, user);
DbResult _db = db.ParseDbResult(sql);
return _db;
}
public static String ShowDecimalWithoutZero(String strVal)
{
if (strVal != "")
return String.Format("{0:0,0}", double.Parse(strVal));
else
return "0";
}
public static string GetMIMEExtension(this string contentType)
{
return MimeTypes.MimeTypeMap.GetExtension(contentType);
}
}
}