Exemple #1
0
        private static string SerializeToXML(AuditFieldContainer Value)
        {
            XmlSerializer serializer = new XmlSerializer(Value.GetType());

            StringBuilder     xml      = new StringBuilder();
            XmlWriterSettings settings = new XmlWriterSettings();

            settings.Encoding = Encoding.UTF8;
            settings.Indent   = true;

            using (XmlWriter writer = XmlWriter.Create(xml, settings))
            {
                if (writer != null)
                {
                    serializer.Serialize(writer, Value);
                }
            }

            return(xml.ToString());
        }
Exemple #2
0
        private static void CreateLog_Wizard(SqlConnection Connection, SqlTransaction Transaction, AuditLog.AuditLogType AuditLogType, Guid?AuditKey, string AuditSource, string AuditName, string ReferenceTable, Guid?ReferenceID, DataRow CurrentData, DataRow NewData, Guid?UserID, string UserName)
        {
            if (CurrentData != null || NewData != null)
            {
                AuditFieldContainer  objContainer  = new AuditFieldContainer();
                List <AuditField>    fieldList     = new List <AuditField>();
                List <AuditField>    fullFieldList = new List <AuditField>();
                AuditLog.AuditAction auditAction   = default(AuditLog.AuditAction);
                Nullable <Guid>      auditGroupID  = default(Nullable <Guid>);
                if (CurrentData == null)
                {
                    auditAction = AuditLog.AuditAction.Insert;
                    //Add
                    foreach (DataColumn co in NewData.Table.Columns)
                    {
                        AuditField fieldObj = new AuditField();
                        fieldObj.FieldName  = co.ColumnName;
                        fieldObj.FieldValue = NewData[co.ColumnName].ToString();
                        fieldList.Add(fieldObj);
                    }
                    foreach (DataColumn co in NewData.Table.Columns)
                    {
                        AuditField fieldObj = new AuditField();
                        fieldObj.FieldName  = co.ColumnName;
                        fieldObj.FieldValue = NewData[co.ColumnName].ToString();
                        fullFieldList.Add(fieldObj);
                    }
                }
                else if (NewData == null)
                {
                    //Delete
                    auditAction  = AuditLog.AuditAction.Delete;
                    auditGroupID = GetLastAuditGroupID_Wizard(Connection, Transaction, AuditLogType, AuditName, AuditSource, AuditKey);
                    foreach (DataColumn co in CurrentData.Table.Columns)
                    {
                        AuditField fieldObj = new AuditField();
                        fieldObj.FieldName  = co.ColumnName;
                        fieldObj.FieldValue = CurrentData[co.ColumnName].ToString();
                        fieldList.Add(fieldObj);
                    }
                    foreach (DataColumn co in CurrentData.Table.Columns)
                    {
                        AuditField fieldObj = new AuditField();
                        fieldObj.FieldName  = co.ColumnName;
                        fieldObj.FieldValue = CurrentData[co.ColumnName].ToString();
                        fullFieldList.Add(fieldObj);
                    }
                }
                else
                {
                    //Update
                    auditAction  = AuditLog.AuditAction.Update;
                    auditGroupID = GetLastAuditGroupID_Wizard(Connection, Transaction, AuditLogType, AuditName, AuditSource, AuditKey);
                    foreach (DataColumn co in CurrentData.Table.Columns)
                    {
                        if (CurrentData[co.ColumnName].ToString() != NewData[co.ColumnName].ToString())
                        {
                            AuditField fieldObj = new AuditField();
                            fieldObj.FieldName  = co.ColumnName;
                            fieldObj.FieldValue = NewData[co.ColumnName].ToString();
                            fieldList.Add(fieldObj);
                        }
                    }
                    foreach (DataColumn co in CurrentData.Table.Columns)
                    {
                        AuditField fieldObj = new AuditField();
                        fieldObj.FieldName  = co.ColumnName;
                        fieldObj.FieldValue = NewData[co.ColumnName].ToString();
                        fullFieldList.Add(fieldObj);
                    }
                }

                if (fieldList.Count > 0)
                {
                    objContainer.AuditFields     = fieldList.ToArray();
                    objContainer.FullAuditFields = fullFieldList.ToArray();
                    AccelTeam.Utilities.Data Data = new AccelTeam.Utilities.Data(ConfigurationSettings.AppSettings["CRM"].ToString());
                    Guid   auditID = Guid.NewGuid();
                    string xml     = SerializeToXML(objContainer);
                    if (!auditGroupID.HasValue)
                    {
                        auditGroupID = Guid.NewGuid();
                    }
                    AuditLog.InsertAuditLog(Connection, Transaction, auditID, AuditSource, AuditKey, AuditName, AuditLogType, auditAction, "", ReferenceTable, ReferenceID, xml, auditGroupID, UserID, UserName);
                }
            }
        }