private static List<AuditLog> GetAuditList(string Q, SqlParameterCollection oParams, SqlUtil sql, TDatabase AuditDB) { if (sql == null) sql = SqlUtil.Get(AuditDB); List<AuditLog> headers = new List<AuditLog>(); if ((long)oParams["@ID"].Value == 0) return headers; DataTable oTable = sql.ExecuteSingleResultSetSQLQuery(Q, oParams); if (oTable.Rows.Count == 0) return headers; //each unique header has a list of the details long CurrId = -1; long id; AuditFields fields = null; foreach (DataRow r in oTable.Rows) { id = DataUtils.LongZeroIfNull(r["ID"]); if (id != CurrId) { AuditLog a = new AuditLog(r, false); headers.Add(a); fields = a.mFieldChanges; CurrId = id; } fields.Add(r); } return headers; }
/// <summary> /// paramater are gotten from the ApplicationParamater table in the client and Shared DBs. the client DB can have values that are global to that client or /// parms for spcific application. /// </summary> private static void LoadParms() { mParms = mAllClientParms[DBLocator.ActiveClientName]; if (mParms != null) return; mParms = new Dictionary<string, Dictionary<string, string>>(); mAllClientParms[DBLocator.ActiveClientName] = mParms; Dictionary<string, string> SharedClientParms = new Dictionary<string, string>(); Dictionary<string, string> GlobalParms = new Dictionary<string, string>(); mParms[".client"] = SharedClientParms; mParms[".global"] = GlobalParms; SqlUtil sql = new SqlUtil(TDatabase.Client); string TableName = "ApplicationParameter"; //need to specila case Shared since the applicationparater table in Shared is used for default values for all client for all apps //the problem is Shared has aps of its own that its needs to configure. if (DBLocator.ActiveClientName == "Shared") TableName = "Shared_" + TableName; DataTable dt = sql.ExecuteSingleResultSetSQLQuery("select * from " + TableName + " order by App"); string AppName; string parm; string val; Dictionary<string, string> dict; foreach (DataRow r in dt.Rows) { AppName = (string)DataUtils.BlankIfNull(r["App"]); parm = (string)r["Parm"]; val = (string)r["Value"]; if (AppName == "") dict = SharedClientParms; else { dict = mParms[AppName]; if (dict == null) { dict = new Dictionary<string, string>(); mParms[AppName] = dict; } } dict[parm.ToLower()] = val; } //go to shared db and only get the GLOBAL sql = new SqlUtil(TDatabase.Shared); dt = sql.ExecuteSingleResultSetSQLQuery("select * from ApplicationParameter"); foreach (DataRow r in dt.Rows) { AppName = (string)DataUtils.BlankIfNull(r["App"]); parm = ((string)r["Parm"]).ToLower(); val = (string)r["Value"]; if (AppName == "global") dict = GlobalParms; else { dict = mParms[AppName]; if (dict == null) { dict = new Dictionary<string, string>(); mParms[AppName] = dict; } //dont allow parms found in the shared app parms table to override client settings if (dict.ContainsKey(parm)) continue; } dict[parm] = val; } }
/// <summary> /// you can supply your own SQL object and force the audit to go to that database. Used by GT /// </summary> /// <param name="status"></param> /// <param name="CompletionMsg"></param> /// <param name="SQL"></param> /// <returns></returns> public long Save(CompletionStatus status, string CompletionMsg, SqlUtil SQL) { //save it - just in case of recovery mCompletionStatus = status; mCompletionMsg = CompletionMsg; string sql; SqlParameterCollection oParameters = new SqlCommand().Parameters; long ID = -1; oParameters.AddWithValue("@iDataType", DataUtils.DBNullIfNull(mDataType)); oParameters.AddWithValue("@iDataID", DataUtils.DBNullIfNull(mDataID)); oParameters.AddWithValue("@iCorrespondenceID", DataUtils.DBNullIfNull(mCorrespondenceID)); oParameters.AddWithValue("@iEventID", DataUtils.DBNullIfNull(mEventID)); oParameters.AddWithValue("@iEventDescription", DataUtils.DBNullIfNull(mEventDescription)); oParameters.AddWithValue("@iCompletionMsg", DataUtils.DBNullIfNull(CompletionMsg)); oParameters.AddWithValue("@iCompletionStatus", DataUtils.DBNullIfNull(status)); if (mLogTime == DateTime.MinValue) mLogTime = DateTimeUtility.ServerDateNoRefresh(); oParameters.AddWithValue("@iTime", mLogTime); sql = "set ansi_warnings off;INSERT INTO AuditHeader (DataType,DataID,CorrespondenceID,EventID,EventDescription,CompletionMsg,CompletionStatus,LogTime)" + " VALUES (@iDataType,@iDataID,@iCorrespondenceID,@iEventID,@iEventDescription,@iCompletionMsg,@iCompletionStatus,@iTime)"; sql += "; select @@IDENTITY as ID"; DataTable oTable; try { oTable = SQL.ExecuteSingleResultSetSQLQuery(sql, oParameters); } catch (Exception x) { if (mRecover && SqlRecover.SaveForRecovery(x, true, this, "auditheader")) return 0; else throw new Exception("sql error", x); } if (oTable.Rows.Count == 0) return -1; ID = DataUtils.LongZeroIfNull(oTable.Rows[0]["ID"]); if (ID < 1) return -1; if (mFieldChanges != null) { string o; string n; oParameters = new SqlCommand().Parameters; foreach (string field in mFieldChanges.UpdateList.Keys) { mFieldChanges.GetAuditValue(field, out o, out n); oParameters.AddWithValue("@iAuditID", ID); oParameters.AddWithValue("@iField", DataUtils.DBNullIfNull(field)); oParameters.AddWithValue("@iOldVal", DataUtils.DBNullIfNull(o)); oParameters.AddWithValue("@iNewVal", DataUtils.DBNullIfNull(n)); sql = "set ansi_warnings off;INSERT INTO AuditDetail(AuditID,Field, OldValue,NewValue) " + " VALUES (@iAuditID,@iField, @iOldVal,@iNewVal);"; SQL.ExecuteNoResultSetSQLQuery(sql, oParameters); oParameters.Clear(); } } return ID; }