private static Expression <Func <Log, bool> > CreateFilter(string search) { var serializer = new JavaScriptSerializer(); var dict = serializer.Deserialize <Dictionary <string, object> >(search); var predicate = PredicateBuilder.True <Log>(); if (CheckEmpty.String(ref dict, "Module") != "") { predicate = predicate.And(p => p.Module.Id == dict["Module"].ToString()); } if (CheckEmpty.String(ref dict, "Action") != "") { predicate = predicate.And(p => p.Action.Contains(dict["Action"].ToString())); } if (CheckEmpty.String(ref dict, "Text") != "") { predicate = predicate.And(p => p.Text.Contains(dict["Text"].ToString())); } if (CheckEmpty.String(ref dict, "UserId") != "") { predicate = predicate.And(p => p.UserId == Convert.ToInt64(dict["UserId"])); } if (CheckEmpty.String(ref dict, "BranchId") != "") { predicate = predicate.And(p => p.BranchId == Convert.ToInt64(dict["BranchId"])); } if (CheckEmpty.String(ref dict, "DateFilter") != "") { var dtLimits = DateUtilities.GetDateFilter(dict["DateFilter"].ToString(), dict["FromDate"].ToString(), dict["ToDate"].ToString()); predicate = predicate.And(p => p.EntryDate >= dtLimits.FromDate); predicate = predicate.And(p => p.EntryDate <= dtLimits.ToDate); } return(predicate); }
public static DateTime Date(object val) { if (val == null) { return(DateUtilities.GetInvariantDate(DateTime.MinValue)); } if (val == DBNull.Value) { return(DateUtilities.GetInvariantDate(DateTime.MinValue)); } try { DateTime dateTime; DateTime.TryParse(val.ToString(), out dateTime); return(DateUtilities.GetInvariantDate(DateTime.Parse(val.ToString()))); } catch (Exception) { return(DateUtilities.GetInvariantDate(new DateTime(1900, 1, 1))); } }
public static bool Backup(string dbName) { var sourceServerName = ConfigurationManager.AppSettings["DbSourceServer"]; EventLog.WriteEntry("PPSM", sourceServerName, EventLogEntryType.Error); var sourceServerUserName = ConfigurationManager.AppSettings["DbSourceServerSQLLogin"]; EventLog.WriteEntry("PPSM", sourceServerUserName, EventLogEntryType.Error); var sourceServerPassword = Cryptography.Decrypt(ConfigurationManager.AppSettings["DbSourceServerSQLPassword"], true); EventLog.WriteEntry("PPSM", sourceServerPassword, EventLogEntryType.Error); var sourceDbName = dbName; EventLog.WriteEntry("PPSM", dbName, EventLogEntryType.Error); var backUpName = sourceDbName + "_backup_" + DateUtilities.GetDateStamp(DateTime.Now, true) + ".bak"; EventLog.WriteEntry("PPSM", backUpName, EventLogEntryType.Error); var backUpDestinationPath = ConfigurationManager.AppSettings["DbBackupPath"]; //Create backup directory if does not exist if (!Directory.Exists(backUpDestinationPath)) { Directory.CreateDirectory(backUpDestinationPath); } backUpDestinationPath += backUpName; EventLog.WriteEntry("PPSM", backUpDestinationPath, EventLogEntryType.Error); var restoreSourcePath = ConfigurationManager.AppSettings["DbRestorePath"]; //Create backup directory if does not exist if (!Directory.Exists(restoreSourcePath)) { Directory.CreateDirectory(restoreSourcePath); } restoreSourcePath += backUpName; EventLog.WriteEntry("PPSM", restoreSourcePath, EventLogEntryType.Error); var sqlBackup = new Backup { Action = BackupActionType.Database, BackupSetDescription = "ArchiveDataBase:" + DateTime.Now.ToShortDateString(), BackupSetName = "Archive", Database = sourceDbName }; var deviceItem = new BackupDeviceItem(backUpDestinationPath, DeviceType.File); var sourceConn = new ServerConnection(sourceServerName, sourceServerUserName, sourceServerPassword); var sourceServer = new Server(sourceConn); EventLog.WriteEntry("PPSM", sourceConn.ConnectionString, EventLogEntryType.Error); sqlBackup.Initialize = true; sqlBackup.Checksum = true; sqlBackup.ContinueAfterError = true; sqlBackup.Devices.Add(deviceItem); sqlBackup.Incremental = false; EventLog.WriteEntry("PPSM", "4", EventLogEntryType.Error); sqlBackup.ExpirationDate = DateTime.Now.AddDays(3); sqlBackup.LogTruncation = BackupTruncateLogType.Truncate; sqlBackup.FormatMedia = false; EventLog.WriteEntry("PPSM", "5", EventLogEntryType.Error); sqlBackup.SqlBackup(sourceServer); EventLog.WriteEntry("PPSM", "6", EventLogEntryType.Error); if (backUpDestinationPath != restoreSourcePath) { File.Copy(backUpDestinationPath, restoreSourcePath, true); } return(true); }