You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

203 lines
6.8 KiB

using Common.Model;
using log4net;
using Newtonsoft.Json;
using System;
using System.Configuration;
using System.Net.Mail;
using System.Runtime.Remoting.Messaging;
using System.Text.RegularExpressions;
namespace Common.Helper
{
public static class GetStatic
{
private static readonly ILog Log = LogManager.GetLogger(typeof(GetStatic));
public static string SQLtoAgentDTFormat(string data, bool isFullDt = false)
{
if (string.IsNullOrEmpty(data))
return "";
if (isFullDt)
return Convert.ToDateTime(data).ToString(GetdateFormat() + " hh:mm:ss tt");
else
{
string dd = Convert.ToDateTime(data).Day.ToString();
string mm = Convert.ToDateTime(data).Month.ToString();
string yy = Convert.ToDateTime(data).Year.ToString();
if (GetdateFormat().ToLower() == "dd/mm/yyyy")
{
return dd + "/" + mm + "/" + yy;
}
else if (GetdateFormat().ToLower() == "yyyy/mm/dd")
{
return yy + "/" + mm + "/" + dd;
}
else if (GetdateFormat().ToLower() == "mm/dd/yyyy")
{
return mm + "/" + dd + "/" + yy;
}
else
return Convert.ToDateTime(data).ToString(GetdateFormat());
}
}
public static string GetdateFormat()
{
if (string.IsNullOrWhiteSpace(ApplicationConfig.ReadWebConfig("dateFormat")))
return "dd/MM/yyyy";
return ApplicationConfig.ReadWebConfig("dateFormat");
}
public static String ShowDecimal(String strVal)
{
if (strVal != "")
return String.Format("{0:0,0.00}", double.Parse(strVal));
else
return strVal;
}
public static String ShowDecimal1(String strVal)
{
if (strVal != "")
return double.Parse(strVal).ToString("0.00");
else
return strVal;
}
public static String ShowCommaAmt(string strVal)
{
if (strVal != "")
{
var amt = double.Parse(strVal);
amt = (amt < 0 ? amt * -1 : amt);
return amt.ToString("C", System.Globalization.CultureInfo.CreateSpecificCulture("ko-MN"));
}
//return String.Format("{0:c}", double.Parse(strVal));
else
return strVal;
}
public static void SendEmail(EmailParameters emailParameters)
{
Log.Debug("SendEmail | Application trying to send the email " + JsonConvert.SerializeObject(emailParameters));
try
{
SmtpClient SmtpServer = new SmtpClient()
{
Host = ApplicationConfig.ReadWebConfig("smtp"),
Port = Convert.ToInt32(ApplicationConfig.ReadWebConfig("port")),
Credentials = new System.Net.NetworkCredential(ApplicationConfig.ReadWebConfig("mailFrom"), ApplicationConfig.ReadWebConfig("emailPwd")),
EnableSsl = true
};
MailMessage mail = new MailMessage(ApplicationConfig.ReadWebConfig("mailFrom"), emailParameters.To, emailParameters.MsgSubject, emailParameters.MsgBody);
mail.IsBodyHtml = true;
SmtpServer.Send(mail);
Log.Debug("SendEmail | Send email success");
}
catch (Exception ex)
{
Log.Error("Something Went Wrong, Please Try Again!!", ex);
//SendEmail(emailParameters);
}
}
public static void SendMultipleEmail(EmailParameters emailParameters)
{
Log.Debug("SendEmail | Application trying to send the email " + JsonConvert.SerializeObject(emailParameters));
try
{
SmtpClient SmtpServer = new SmtpClient()
{
Host = ApplicationConfig.ReadWebConfig("smtp"),
Port = Convert.ToInt32(ApplicationConfig.ReadWebConfig("port")),
Credentials = new System.Net.NetworkCredential(ApplicationConfig.ReadWebConfig("mailFrom"), ApplicationConfig.ReadWebConfig("emailPwd")),
EnableSsl = true,
};
// Multiple To
var message = new MailMessage();
message.To.Add(emailParameters.To);
message.To.Add(emailParameters.To_1);
message.From = new MailAddress(ApplicationConfig.ReadWebConfig("mailFrom"));
message.Subject = emailParameters.MsgSubject;
message.Body = emailParameters.MsgBody;
message.IsBodyHtml = true;
SmtpServer.Send(message);
Log.Debug("SendEmail | Send email success");
}
catch (Exception ex)
{
Log.Error("Something Went Wrong, Please Try Again!!", ex);
//SendEmail(emailParameters);
}
}
public static string RemoveComaFromMoney(string amt)
{
amt = amt.Replace(",", "");
amt = amt.Split('.')[0];
return amt;
}
public static double ParseDouble(string value)
{
double tmp;
double.TryParse(value, out tmp);
return tmp;
}
public static string GetFireBaseId()
{
var str = Convert.ToString(CallContext.GetData(Constants.FcmId));
Log.Debug(str);
return str;
}
public static string GetLanguage()
{
var str = Convert.ToString(CallContext.GetData(Constants.Language));
Log.Debug(str);
return str;
}
public static string ReadWebConfig(string key, string defVal)
{
try
{
return ConfigurationManager.AppSettings[key].ToString() == null ? defVal : ConfigurationManager.AppSettings[key].ToString();
}
catch (Exception ex)
{
return defVal;
}
}
public static bool IsValidMobile(string mobile)
{
if (mobile.Length > 11)
{
return false;
}
//var prefix = "010";
//var mobprefix = mobile.Substring(0, 3);
//if (mobprefix != prefix)
//{
// return false;
//}
return true;
}
public static bool IsUsernameValid(string username)
{
string pattern = @"^[a-zA-Z0-9_.@]*$";
Match userNameMatch = Regex.Match(username, pattern);
return userNameMatch.Success;
}
}
}