using System; using System.Collections.Generic; using System.Configuration; using System.Linq; using System.Text; using System.Threading.Tasks; namespace HH.AMS.Common { public static class DBFun { public static string dbType = ConfigurationManager.ConnectionStrings["DataType"].ToString(); public static DBTYPE Now_dbType { get { if (dbType.Equals("MYSQL")) return DBTYPE.MYSQL; if (dbType.Equals("MSSQL")) return DBTYPE.MSSQL; if (dbType.Equals("ORACLE")) return DBTYPE.ORACLE; return DBTYPE.ORTHER; } } public static string GetDate() { switch (Now_dbType) { case DBTYPE.MYSQL: return " now() "; case DBTYPE.MSSQL: return " getDate() "; case DBTYPE.ORACLE: return " SYSDATE "; default: return ""; } } public static string StringToTime(string time) { switch (Now_dbType) { case DBTYPE.MYSQL: return "str_to_date('" + time + "', '%Y-%m-%d %H:%i:%s')"; case DBTYPE.MSSQL: return " convert(datetime,'" + time + "') "; case DBTYPE.ORACLE: return " to_date('" + time + "','yyyy-mm-dd hh24:mi:ss') "; default: return ""; } } public static string StringAddDay(string time, int day) { switch (Now_dbType) { case DBTYPE.MYSQL: return "date_add('" + time + "',interval " + day + " day)"; case DBTYPE.MSSQL: return " convert(datetime,'" + time + "')+" + day; //case DBTYPE.ORACLE: return " SYSDATE() "; default: return ""; } } public enum DBTYPE { MYSQL, MSSQL, ORACLE, ORTHER } public static string Guid() { switch (Now_dbType) { case DBTYPE.MYSQL: return " UUID() "; case DBTYPE.MSSQL: return " NEWID() "; //case DBTYPE.ORACLE: return " SYSDATE() "; default: return ""; } } } }