public static long Insert(InsEditLog logCur) { if (RemotingClient.RemotingRole == RemotingRole.ClientWeb) { logCur.InsEditLogNum = Meth.GetLong(MethodBase.GetCurrentMethod(), logCur); return(logCur.InsEditLogNum); } return(Crud.InsEditLogCrud.Insert(logCur)); }
///<summary>Manual log entry. Creates a new InsEditLog based on information passed in. PKey should be 0 unless LogType = Benefit. ///Use the automatic MakeLogEntry overload if possible. This only be used when manual UPDATE/INSERT/DELETE queries are run on the logged tables.</summary> public static void MakeLogEntry(string fieldName, long userNum, string oldVal, string newVal, InsEditLogType logType, long fKey, long pKey, string descript) { //No need to check RemotingRole; no call to db. InsEditLog logCur = new InsEditLog() { FieldName = fieldName, UserNum = userNum, OldValue = oldVal, NewValue = newVal, LogType = logType, FKey = fKey, ParentKey = pKey, Description = descript, }; Insert(logCur); }
///<summary>Gets all logs with the passed-in FKey of the specified LogType. ///Only returns logs that occurred before the passed-in log. ///Called from GetChangedLogs and, between the two methods, recursively retrieves logs linked to the logs that are returned from this method.</summary> private static List <InsEditLog> GetLinkedLogs(long FKey, InsEditLogType logType, InsEditLog logCur, List <InsEditLog> listLogs) { //No need to check RemotingRole; private static. string command = "SELECT * FROM inseditlog " + "WHERE FKey = " + POut.Long(FKey) + " " + "AND LogType = " + POut.Int((int)logType) + " " + "AND DateTStamp < " + POut.DateT(logCur.DateTStamp) + " " + "AND InsEditLogNum NOT IN( " + string.Join(",", listLogs.Select(x => POut.Long(x.InsEditLogNum)).ToList()) + ")"; List <InsEditLog> listLinkedLogs = Crud.InsEditLogCrud.SelectMany(command); GetChangedLogs(listLinkedLogs); return(listLinkedLogs); }
///<summary>Automatic log entry. Fills in table and column names based on items passed in. ///Compares whole table excluding CrudColumnSpecialTypes of DateEntry, DateTEntry, ExcludeFromUpdate, and TimeStamp. ///Pass in null for ItemOld if the item was just inserted. Pass in null for ItemCur if the item was just deleted. ///Both itemCur and itemOld cannot be null.</summary> public static void MakeLogEntry <T>(T itemCur, T itemOld, InsEditLogType logType, long userNumCur) { //No need to check RemotingRole; no call to db. T priKeyItem = itemCur == null ? itemOld : itemCur; FieldInfo priKeyField = priKeyItem.GetType().GetFields().Where(x => x.IsDefined(typeof(CrudColumnAttribute)) && ((CrudColumnAttribute)x.GetCustomAttribute(typeof(CrudColumnAttribute))).IsPriKey).First(); long priKey = (long)priKeyField.GetValue(priKeyItem); string priKeyColName = priKeyField.Name; long parentKey = priKeyItem.GetType() == typeof(Benefit) ? ((Benefit)(object)priKeyItem).PlanNum : 0; //parentKey only filled for Benefits. string descript = ""; switch (logType) //always default the descript to the priKeyItem (preferring current unless deleted). { case InsEditLogType.InsPlan: descript = priKeyItem is InsPlan ? ((priKeyItem as InsPlan).GroupNum + " - " + (priKeyItem as InsPlan).GroupName) : ""; break; case InsEditLogType.Carrier: descript = priKeyItem is Carrier ? ((priKeyItem as Carrier).CarrierNum + " - " + (priKeyItem as Carrier).CarrierName) : ""; break; case InsEditLogType.Benefit: descript = priKeyItem is Benefit?Benefits.GetCategoryString(priKeyItem as Benefit) : ""; break; case InsEditLogType.Employer: descript = (priKeyItem as Employer)?.EmpName ?? ""; break; default: break; } InsEditLog logCur; if (itemOld == null) //new, just inserted. Show PriKey Column only. { logCur = new InsEditLog() { FieldName = priKeyColName, UserNum = userNumCur, OldValue = "NEW", NewValue = priKey.ToString(), LogType = logType, FKey = priKey, ParentKey = parentKey, Description = descript, }; Insert(logCur); return; } List <InsEditLog> listLogsForInsert = new List <InsEditLog>(); foreach (FieldInfo prop in priKeyItem.GetType().GetFields()) { if (prop.IsDefined(typeof(CrudColumnAttribute)) && (((CrudColumnAttribute)prop.GetCustomAttribute(typeof(CrudColumnAttribute))).SpecialType.HasFlag(CrudSpecialColType.DateEntry) || ((CrudColumnAttribute)prop.GetCustomAttribute(typeof(CrudColumnAttribute))).SpecialType.HasFlag(CrudSpecialColType.DateTEntry) || ((CrudColumnAttribute)prop.GetCustomAttribute(typeof(CrudColumnAttribute))).SpecialType.HasFlag(CrudSpecialColType.ExcludeFromUpdate) || ((CrudColumnAttribute)prop.GetCustomAttribute(typeof(CrudColumnAttribute))).SpecialType.HasFlag(CrudSpecialColType.TimeStamp))) { continue; //skip logs that are not user editable. } object valOld = prop.GetValue(itemOld) ?? ""; if (itemCur == null) //deleted, show all deleted columns { logCur = new InsEditLog() { FieldName = prop.Name, UserNum = userNumCur, OldValue = valOld.ToString(), NewValue = "DELETED", LogType = logType, FKey = priKey, ParentKey = parentKey, Description = descript, }; } else //updated, just show changes. { object valCur = prop.GetValue(itemCur) ?? ""; if (valCur.ToString() == valOld.ToString()) { continue; } logCur = new InsEditLog() { FieldName = prop.Name, UserNum = userNumCur, OldValue = valOld.ToString(), NewValue = valCur.ToString(), LogType = logType, FKey = priKey, ParentKey = parentKey, Description = descript, }; } listLogsForInsert.Add(logCur); } if (listLogsForInsert.Count > 0) { InsertMany(listLogsForInsert); } }
///<summary>Gets all logs with the passed-in FKey of the specified LogType. ///Only returns logs that occurred before the passed-in log. ///Called from GetChangedLogs and, between the two methods, recursively retrieves logs linked to the logs that are returned from this method.</summary> private static List <InsEditLog> GetLinkedLogs(long FKey, InsEditLogType logType, InsEditLog logCur, List <InsEditLog> listLogs) { if (RemotingClient.RemotingRole == RemotingRole.ClientWeb) { return(Meth.GetObject <List <InsEditLog> >(MethodBase.GetCurrentMethod(), FKey, logType, logCur, listLogs)); } string command = "SELECT * FROM inseditlog " + "WHERE FKey = " + POut.Long(FKey) + " " + "AND LogType = " + POut.Int((int)logType) + " " + "AND DateTStamp < " + POut.DateT(logCur.DateTStamp) + " " + "AND InsEditLogNum NOT IN( " + string.Join(",", listLogs.Select(x => POut.Long(x.InsEditLogNum)).ToList()) + ")"; List <InsEditLog> listLinkedLogs = Crud.InsEditLogCrud.SelectMany(command); GetChangedLogs(listLinkedLogs); return(listLinkedLogs); }
///<summary>Gets all logs with the passed-in FKey of the specified LogType. ///Only returns logs that occurred before the passed-in log. ///Called from GetChangedLogs and, between the two methods, recursively retrieves logs linked to the logs that are returned from this method.</summary> private static List <InsEditLog> GetLinkedLogs(long FKey, InsEditLogType logType, InsEditLog logCur, bool isRecursive) { if (RemotingClient.RemotingRole == RemotingRole.ClientWeb) { return(Meth.GetObject <List <InsEditLog> >(MethodBase.GetCurrentMethod(), FKey, logType, logCur, isRecursive)); } string command = "SELECT * FROM inseditlog " + "WHERE FKey = " + POut.Long(FKey) + " " + "AND LogType = " + POut.Int((int)logType) + " " + "AND DateTStamp < " + POut.DateT(logCur.DateTStamp) + " " + "AND InsEditLogNum != " + POut.Long(logCur.InsEditLogNum); List <InsEditLog> listLogs = Crud.InsEditLogCrud.SelectMany(command); GetChangedLogs(listLogs); return(listLogs); }