using Swift.DAL.Remittance; using Swift.DAL.SwiftDAL; using Swift.web.SwiftSystem.UserManagement.ApplicationUserPool; using System; using System.Collections.Generic; using System.Configuration; using System.Data; using System.Net.Mail; using System.Security; using System.Security.Cryptography; using System.Text; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; //using Swift.DAL.BL.Remit.Transaction.MoneyGram; namespace Swift.web.Library.Remittance { public static class RemittanceStatic { /* public static MoneyGramDao GetMoneyGramInstance() { MoneyGramDao md = new MoneyGramDao(); md.SetCredential(GetPointCode(), GetUserLogin(), GetUserPassword()); return md; } public static MoneyGramDao GetMoneyGramInstance(string branchId) { MoneyGramDao md = new MoneyGramDao(); var sql = "EXEC proc_ws_moneyGramUtility @flag='pointcode'"; sql += ", @branchId=" + md.FilterString(branchId); sql += ", @userType=" + md.FilterString(GetUserType()); var dr = md.ParseDbResult(sql); var pointCode = dr.ErrorCode; var userLogin = dr.Msg; var userPassword = dr.Id; md.SetCredential(pointCode, userLogin, userPassword); return md; } */ public static string ParseXmlData(string data) { return SecurityElement.Escape(data); } public static string GetPointCode() { return ReadSession("mgPointCode", ""); } public static string GetUserLogin() { return ReadSession("mgUserLogin", ""); } public static string GetUserPassword() { return ReadSession("mgUserPassword", ""); } 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 CalculateMD5Hash(string input) { // step 1, calculate MD5 hash from input MD5 md5 = MD5.Create(); byte[] inputBytes = Encoding.ASCII.GetBytes(input); byte[] hash = md5.ComputeHash(inputBytes); // step 2, convert byte array to hex string StringBuilder sb = new StringBuilder(); for (int i = 0; i < hash.Length; i++) { sb.Append(hash[i].ToString("X2")); } return sb.ToString(); } public static bool HasOnlyDigit(string value) { var pattern = "0123456789"; for (var i = 0; i < value.Length; i++) { if (!pattern.Contains(value.Substring(i, 1))) { return false; } } return true; } public static string GetDateInC2CFormat(string strDate) { var date = DateTime.Parse(strDate); return date.ToString("yyyyMMdd"); } public static string GetDateInMGFormat(string strDate) { var date = DateTime.Parse(strDate); return date.ToString("dd.MM.yyyy 00:00:00"); } public static DbResult LogError(HttpException lastError, string page, string referer = "") { Exception err = lastError; if (lastError.InnerException != null) err = lastError.InnerException; var db = new SwiftDao(); var errPage = db.FilterString(page); var errMsg = db.FilterString(err.Message); var errDetails = db.FilterString(lastError.GetHtmlErrorMessage()); var user = GetUser(); var ipAddress = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]; var dcIdNo = HttpContext.Current.Request.ClientCertificate["SERIALNUMBER"]; var dcUserName = HttpContext.Current.Request.ClientCertificate["SUBJECTCN"]; if (string.IsNullOrWhiteSpace(user)) { user = ipAddress; } string sql = string.Format(@"EXEC proc_ErrorLogs @flag = 'i' ,@errorPage={0}, @errorMsg={1}, @errorDetails={2}, @user = {3}, @referer={4}, @ipAddress={5}, @dcUserName={6}, @dcIdNo={7}", errPage, errMsg, errDetails, db.FilterString(user), db.FilterString(referer), db.FilterString(ipAddress), db.FilterString(dcUserName), db.FilterString(dcIdNo)); return db.ParseDbResult(sql); } public static DbResult GetResultInDbResultFormat(string sql) { var db = new SwiftDao(); return db.ParseDbResult(sql); } public static string GetSingleResult(string sql) { var db = new SwiftDao(); return db.GetSingleResult(sql); } 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 double RoundDecimal(double num, int currDecimal) { return Math.Round(num, currDecimal); } public static Boolean IsNumeric(string stringToTest) { int result; return int.TryParse(stringToTest, out result); } public static string ShowVoucherType(string vType) { var voucher = ""; vType.ToLower(); if (vType == "j") voucher = "Journal Voucher"; else if (vType == "c") voucher = "Contra Voucher"; else if (vType == "r") voucher = "Receipt Voucher"; else if (vType == "y") voucher = "Payment Voucher"; else voucher = "Voucher Type not defined"; return voucher; } #region Userpool public static LoggedInUser GetLoggedInUser() { var userPool = UserPool.GetInstance(); return userPool.GetUser(GetUser()); } public static string GetAgentId() { return GetBranch(); } /* public static string GetAgentType() { return GetLoggedInUser().AgentType; } public static string GetActAsBranchFlag() { return GetLoggedInUser().IsActAsBranch; } * */ public static string GetUserDateTime() { var db = new SwiftDao(); var sql = "EXEC proc_MatrixReport @flag = 'udt', @user = '" + GetUser() + "'"; return db.GetSingleResult(sql); } public static string GetAgentNameByMapCodeInt(string mapCodeInt) { var db = new SwiftDao(); var sql = "SELECT agent_name FROM FastMoneyPro_account.dbo.agentTable with(nolock) where map_code = '" + mapCodeInt + "'"; return db.GetSingleResult(sql); } public static string GetScRefund(string tranId) { var db = new SwiftDao(); var sql = "SELECT dbo.ShowDecimalExceptComma(ISNULL(scRefund,0)) FROM tranCancelrequest WITH(NOLOCK) WHERE tranId=" + tranId + ""; return db.GetSingleResult(sql); } public static string GetTellerBalance(string user) { var db = new SwiftDao(); var sql = "SELECT dbo.FNAGetTellerBalance('" + user + "')"; return db.GetSingleResult(sql); } public static string GetUser() { var user = ReadSession("admin", ""); WriteSession("admin", user); //WriteSession("lastActiveTS", DateTime.Now.ToString()); return user; } public static void SetXmwsSessionID(string xmwsSessionID) { WriteSession("xmwsSessionID", xmwsSessionID); } public static string GetXmwsSessionID() { return ReadSession("xmwsSessionID", ""); } public static string GetUser1() { var user = ReadSession("admin1", ""); return user; } public static void RemoveUserSession() { WriteSession("admin", ""); } #endregion Userpool public static string ToShortDate(string datetime) { try { if (string.IsNullOrWhiteSpace(datetime)) return ""; DateTime dt; DateTime.TryParse(datetime, out dt); return dt.ToShortDateString(); } catch { return ""; } } public static string GetToday() { return DateTime.Today.ToShortDateString(); } // GetStatic.GetDcId() //41-05-72-dd-00-01-00-00-71-67 public static string GetDcId() { return HttpContext.Current.Request.ClientCertificate["SERIALNUMBER"]; } //GetStatic.GetDcUserName() //Basant Tandan (IME-IRH) public static string GetDcUserName() { return HttpContext.Current.Request.ClientCertificate["SUBJECTCN"]; } //GetStatic.GetDcInfo() //41-05-72-dd-00-01-00-00-71-67:Basant Tandan (IME-IRH) public static string GetIp() { return GetLoggedInUser().IPAddress; return HttpContext.Current.Request.ClientCertificate["REMOTE_ADDR"]; } public static string GetUserFullName() { return ReadSession("fullname", ""); } public static string GetCountryId() { return ReadSession("countryId", ""); } public static string GetCountry() { return ReadSession("country", ""); } public static string GetBranch() { return ReadSession("branch", ""); } public static string GetParentId() { return ReadSession("parentId", ""); } public static string GetBranchName() { return ReadSession("branchName", ""); } public static string GetAgent() { return ReadSession("agent", ""); } public static string GetAgentName() { return ReadSession("agentName", ""); } public static string GetSuperAgent() { return ReadSession("superAgent", ""); } public static string GetSuperAgentName() { return ReadSession("superAgentName", ""); } public static string GetSettlingAgent() { return ReadSession("settlingAgent", ""); } public static string GetMapCodeInt() { return ReadSession("mapCodeInt", ""); } public static string GetParentMapCodeInt() { return ReadSession("parentMapCodeInt", ""); } public static string GetMapCodeDom() { return ReadSession("mapCodeDom", ""); } public static string GetAgentType() { return ReadSession("agentType", ""); } public static string GetIsActAsBranch() { return ReadSession("isActAsBranch", ""); } public static string GetUserType() { return ReadSession("userType", ""); } public static string GetFromSendTrnTime() { return ReadSession("fromSendTrnTime", ""); } public static string GetToSendTrnTime() { return ReadSession("toSendTrnTime", ""); } public static string GetFromPayTrnTime() { return ReadSession("fromPayTrnTime", ""); } public static string GetToPayTrnTime() { return ReadSession("toPayTrnTime", ""); } public static string GetIsHeadOffice() { return ReadSession("isHeadOffice", ""); } public static string GetAgentLocation() { return ReadSession("agentLocation", ""); } public static string GetAgentGroup() { return ReadSession("agentGrp", ""); } public static string GetSessionId() { return HttpContext.Current.Session.SessionID; } public static string GetAgentEmail() { return ReadSession("agentEmail", ""); } public static string GetAgentPhone() { return ReadSession("agentPhone", ""); } public static string EncryptPassword(string pwd) { return pwd; } #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 ReadReportFormData(string key, string defVal) { var prefix = ReadWebConfig("controlNamePrefix"); return ReadFormData(prefix + key, defVal); } public static string GetWarningInMiliSec() { return (ParseInt((ReadWebConfig("idleWarningInSec") ?? "0").ToString()) * 1000).ToString(); } public static string GetCountDownInSec() { return (ReadWebConfig("countDownInSec") ?? "0").ToString(); } 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 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 defVal; } } public static void WriteSession(string key, string value) { try { HttpContext.Current.Session[key] = value; } catch { } } 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 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) { AttachConfirmMsg(ref ctl, "Are you sure?"); } public static void AttachConfirmMsg(ref Button ctl, string confirmText) { var function = "return confirm('" + confirmText + "');"; ctl.Attributes.Add("onclick", function); } public static void Process(ref Button ctl) { var function = "return Process();"; ctl.Attributes.Add("onclick", function); } public static void ProcessWithConfirm(ref Button ctl) { var function = "return ProcessWithConfirm();"; ctl.Attributes.Add("onclick", function); } public static void ProcessWithConfirm(ref Button ctl, string msg) { var function = "return ProcessWithConfirm('" + msg.Replace("'", "").Replace(@"""", "") + "');"; ctl.Attributes.Add("onclick", function); } 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 " "; dataType = dataType.ToUpper(); 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 data1) { double data = double.Parse(data1); var str = data.ToString().Split('.'); int number = Convert.ToInt32(str[0]); int dec = 0; if (str.Length > 1) if (str[1].Length > 1) dec = Convert.ToInt32(str[1].Substring(0, 2)); else dec = Convert.ToInt32(str[1]); 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(""); 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]); } //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(" And "); // sb.Append(words0[dec]); // 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 GetHoAgentId() { return ReadWebConfig("hoAgentId"); } public static string GetDomesticCountryId() { return ReadWebConfig("domesticCountryId"); } public static string GetDomesticSuperAgentId() { return ReadWebConfig("domesticSuperAgentId"); } public static string GetAcSystemUrl() { return ReadWebConfig("acSystemUrl"); } public static string GetGBLAPIUrl() { return ReadWebConfig("GBLAPIUrl"); } public static string GetGBLAPIUsername() { return ReadWebConfig("GBLAPIUsername"); } public static string GetGBLAPIPwd() { return ReadWebConfig("GBLAPIPwd"); } public static string GetIsApiFlag() { return ReadWebConfig("isAPI"); } public static string GetAppRoot() { return ReadWebConfig("root"); } public static string GetFilePath() { return ReadWebConfig("filePath"); } public static string TXNDocumentUploadPath() { return ReadWebConfig("txnDocumentUploadPath"); } public static string GetUrlRoot() { return ReadWebConfig("urlRoot"); } public static string GetJQuerySubmitURL() { return GetUrlRoot() + "/SwiftSystem/Utility/jquerySubmit.aspx"; } public static string GetVirtualDirName() { return ReadWebConfig("virtualDirName"); } public static string GetIMEMalaysiaAgentId() { return ReadWebConfig("imeMalaysiaAgentId"); } public static string GetTranNoName() { return ReadWebConfig("tranNoName"); } public static string GetCurrencyList() { return ReadWebConfig("currencyList"); } public static string GetParent() { return ReadWebConfig("parent"); } public static string GetDBUrlRoot() { return ReadWebConfig("dbUrlRoot"); } public static string GetDBRoot() { return ReadWebConfig("dbRoot"); } public static string GetReportPagesize() { return ReadWebConfig("reportPageSize"); } public static string GetAdminReportRoot() { return ReadWebConfig("adminReport"); } public static string GetAgentReportRoot() { return ReadWebConfig("agentReport"); } #endregion Read From Web Config 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 GetHistoryChangedListForTellerLimit(string oldData, string newData) { var applicationLogsDao = new ApplicationLogsDao(); return applicationLogsDao.GetAuditDataForTellerLimit(oldData, newData); }*/ public static DataTable GetHistoryChangedListForAgent(string oldData, string newData) { var applicationLogsDao = new ApplicationLogsDao(); return applicationLogsDao.GetAuditDataForAgent(oldData, newData); } public static DataTable GetHistoryChangedListForRuleCriteria(string oldData, string newData) { var applicationLogsDao = new ApplicationLogsDao(); return applicationLogsDao.GetAuditDataForRuleCriteria(oldData, newData); } public static DataTable GetHistoryChangedListForIdCriteria(string oldData, string newData, string id) { var applicationLogsDao = new ApplicationLogsDao(); return applicationLogsDao.GetAuditDataForIdCriteria(oldData, newData, id); } //public static DataTable GetHistoryChangedListForSendingAmountThreshold(string oldData, string newData) //{ // var applicationLogsDao = new ApplicationLogsDao(); // return applicationLogsDao.GetAuditDataForSendingAmountThreshold(oldData, newData); //} 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 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 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; } 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 }; } 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 GetDefaultPage() { switch (ReadCookie("loginType", "").ToUpper()) { case "ADMIN": return GetUrlRoot() + "/admin"; case "AGENT": return GetUrlRoot() + "/agentlogin"; } return GetUrlRoot(); } 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 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("