using Swift.API.Common; using Swift.DAL.BL.Remit.Transaction; using Swift.DAL.BL.Remit.Transaction.PayTransaction; using Swift.DAL.BL.System.Notification; using Swift.DAL.SwiftDAL; using Swift.web.SwiftSystem.UserManagement.ApplicationUserPool; using System; using System.Collections; using System.Collections.Generic; using System.Configuration; using System.Data; using System.Text; using System.Text.RegularExpressions; using System.Web; using System.Web.Script.Serialization; using System.Web.UI; using System.Web.UI.WebControls; using Swift.DAL.Common; using System.Net; using System.IO; using System.Xml.Serialization; using SelectPdf; using Newtonsoft.Json; //using SelectPdf; namespace Swift.web.Library { public static class GetStatic { public static DbResult LogError(HttpException lastError, string page) { Exception err = lastError; if (lastError.InnerException != null) err = lastError.InnerException; RemittanceDao db = new RemittanceDao(); var errPage = db.FilterString(page); var errMsg = db.FilterString(err.Message); var errDetails = db.FilterString(lastError.GetHtmlErrorMessage()); var user = string.IsNullOrWhiteSpace(GetUser()) ? "'UNKNOWN'" : GetUser(); string sql = string.Format(@"EXEC proc_ErrorLogs @flag = 'i', @errorPage={0}, @errorMsg={1}, @errorDetails={2}, @user = {3}", errPage, errMsg, errDetails, user); return db.ParseDbResult(sql); } internal static void AttachConfirmMsg(ref object btnApprove, string v) { throw new NotImplementedException(); } public static string UploadDocument(HttpPostedFile doc, string customerId, string documentTypeName, string membershipId, string registeredDate, out string fileType) { fileType = ""; string fName = ""; string documentExtension = ""; try { fileType = doc.ContentType; string fileExtension = new FileInfo(doc.FileName).Extension; if (documentTypeName.ToLower() == "other_document" || documentTypeName.ToLower() == "registration_form" || documentTypeName.ToLower() == "beneficiary_registration_form") { documentExtension = GetStatic.ReadWebConfig("customerDocFileExtensionForOtherDoc", ""); } else { documentExtension = GetStatic.ReadWebConfig("customerDocFileExtension", ""); } if (documentExtension.ToLower().Contains(fileExtension.ToLower())) { string fileName = documentTypeName + "_" + GetStatic.GetDateTimeStamp() + "_" + GetStatic.GetUser() + fileExtension; string path = GetStatic.GetCustomerFilePath() + "CustomerDocument\\" + registeredDate.Replace("-", "\\") + "\\" + membershipId; if (!Directory.Exists(path)) Directory.CreateDirectory(path); doc.SaveAs(path + "/" + fileName); fName = fileName; } else { fName = "notValid"; } } catch (Exception ex) { fName = ""; } return fName; } public static void EmailNotificationLog(SmtpMailSetting smtpMail) { RemittanceDao db = new RemittanceDao(); string sql = ""; sql = "EXEC proc_emailNotes @flag = 'i'"; sql += ", @sendFrom=" + db.FilterString(smtpMail.SendEmailId); sql += ", @sendTo=" + db.FilterString(smtpMail.ToEmails); sql += ", @sendCc=" + db.FilterString(smtpMail.CcEmails); sql += ", @sendBcc=" + db.FilterString(smtpMail.BccEmails); sql += ", @subject=" + db.FilterString(smtpMail.MsgSubject); sql += ", @user=''"; sql += ", @sendStatus=" + db.FilterString(smtpMail.Status); sql += ", @errorMsg=" + db.FilterString(smtpMail.MsgBody); db.ExecuteDataRow(sql); } public static int ToInt(this string val) { int myval; if (int.TryParse(val.Trim(), out myval)) { return myval; } else return 0; } public static decimal ToDecimal(this string val) { decimal myval; if (decimal.TryParse(val.Trim(), out myval)) { return myval; } else return 0; } public static DateTime? ParseDateTime(this string val) { DateTime myval; if (DateTime.TryParse(val.Trim(), out myval)) { return myval; } else return null; } public static string ToDate(this string val) { DateTime myval; if (DateTime.TryParse(val.Trim(), out myval)) { return myval.ToString("yyyy-MM-dd"); } else return ""; } public static string RemoveComaFromMoney(string amt) { try { var Split = amt.Split('.'); amt = Split[0]; } catch (Exception e) { amt = ""; } return amt.Replace(",", ""); } public static DbResult CheckSlab(string pcnt, string minAmt, string maxAmt) { //bool PreError = false; var dbResult = new DbResult(); if ((pcnt == "" ? "0" : pcnt) != "0") { if ((minAmt == "" ? "0" : minAmt) == "0" || (maxAmt == "" ? "0" : maxAmt) == "0") { dbResult.Id = "1"; dbResult.Msg = "Please set Min or Max Amt .."; //PreError = true; } } else if ((pcnt == "" ? "0" : pcnt) == "0" && (minAmt == "" ? "0" : minAmt) == "0") { dbResult.Id = "1"; dbResult.Msg = "Please set Min Amt .."; //PreError = true; } return dbResult; } public static void Process(ref Button ctl) { var function = "return Process();"; ctl.Attributes.Add("onclick", function); } public static double GetPayAmountLimit(string controlNo) { var pay = new PayDao(); var limitAmount = pay.GetPayAmountLimit(GetStatic.GetUser(), controlNo); return limitAmount; } public static string GetSendingCountryBySCurr(string sCurr) { //var db = new SwiftDao(); RemittanceDao db = new RemittanceDao(); var sql = "EXEC proc_transactionUtility @flag='sCountry', @user=" + db.FilterString(GetUser()) + ", @curr=" + db.FilterString(sCurr); return db.GetSingleResult(sql); } public static string GetOFACSDN() { return ReadWebConfig("OFAC_SDN"); } public static string GetOFACALT() { return ReadWebConfig("OFAC_ALT"); } public static string GetOFACADD() { return ReadWebConfig("OFAC_ADD"); } public static string GetOFACUNSCR() { return ReadWebConfig("OFAC_UNSCR"); } public static string RemoveAllTags(string html) { var loop = true; var pFrom = 0; var pTo = 0; var refined = html; while (loop) { pFrom = refined.IndexOf("<"); pTo = refined.IndexOf(">"); var t = refined.Substring(pFrom, pTo + 1 - pFrom); if (string.IsNullOrWhiteSpace(t)) { return refined.Trim(); } refined = refined.Replace(t, ""); loop = refined.Contains("<") || refined.Contains(">"); } return refined.Trim(); } public static string RemoveHtmlTagsRegex(string input) { return Regex.Replace(input, "<.*?>", string.Empty); } public static String ShowFormatedCommaAmt(string strVal) { if (strVal != "") { var amt = double.Parse(strVal); amt = (amt < 0 ? amt * -1 : amt); return amt.ToString("C", System.Globalization.CultureInfo.CreateSpecificCulture("ko-KR")); } //return String.Format("{0:c}", double.Parse(strVal)); else return strVal; } //public static string ReplaceFirst(string text, string search, string replace) //{ // int pos = text.IndexOf(search); // if (pos < 0) // { // return text; // } // return text.Substring(0, pos) + replace + text.Substring(pos + search.Length); //} public static void GetPDF(string data) { //string newData = ReplaceFirst(data, ""; return html; } public static void DataTable2ExcelDownload(ref DataTable table, string fileName) { string fileName_forSave = fileName + "_" + DateTime.Now.Year + "_" + DateTime.Now.Month + "_" + DateTime.Now.Day + "_" + DateTime.Now.ToString("hhmmss"); HttpContext.Current.Response.Clear(); HttpContext.Current.Response.ClearContent(); HttpContext.Current.Response.ClearHeaders(); HttpContext.Current.Response.Buffer = true; HttpContext.Current.Response.ContentType = "application/ms-excel"; HttpContext.Current.Response.Write(@""); HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName_forSave + ".xls"); HttpContext.Current.Response.Charset = "utf-8"; HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("windows-1250"); //sets font HttpContext.Current.Response.Write(""); HttpContext.Current.Response.Write("


"); //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(""); } 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(""); rowNum++; } 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("
"); } else { HttpContext.Current.Response.Write(""); } //HttpContext.Current.Response.Write(""); HttpContext.Current.Response.Write(row[i].ToString()); 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(""); var strArr = senderReceiverName.Split(' '); int sNo = 1; foreach (var item in _listOfac) { string data = item.rmrks; sb.Append(""); sb.AppendLine(""); 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(""); sb.Append(""); sNo++; } sb.Append("
S. No.OFAC Remarks
" + item.sno + "" + data + "
"); 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("