Example #1
0
        /// <summary>
        /// 转换格式化
        /// </summary>
        /// <param name="prop"></param>
        /// <param name="auditId"></param>
        /// <returns></returns>
        private static AuditDataLine GetAuditDataLine(Z.EntityFramework.Plus.AuditEntryProperty prop, string auditId)
        {
            if (prop == null)
            {
                return(null);
            }

            var p = new AuditDataLine
            {
                PropertyName      = prop.PropertyName,
                NewValueFormatted = prop.NewValueFormatted,
                OldValueFormatted = prop.OldValueFormatted,
                AuditId           = auditId
            };

            // 格式化数据,日期、浮点数字、整数
            FormatDataByType(prop, ref p);
            return(p);
        }
Example #2
0
        private static void FormatDataByType(Z.EntityFramework.Plus.AuditEntryProperty prop, ref AuditDataLine line)
        {
            try
            {
                var t = GetType(prop?.OldValue) ?? GetType(prop?.NewValue);
                if (t == null)
                {
                    return;
                }

                //1.处理日期
                if (t == typeof(DateTime))
                {
                    if (prop?.OldValue == null)
                    {
                        line.OldValueFormatted = string.Empty;
                    }
                    else
                    {
                        line.OldValueFormatted = string.Format("{0:yyyy/MM/dd HH:mm:ss}", prop.OldValue);
                    }

                    if (prop?.NewValue == null)
                    {
                        line.NewValueFormatted = string.Empty;
                    }
                    else
                    {
                        line.NewValueFormatted = string.Format("{0:yyyy/MM/dd HH:mm:ss}", prop.NewValue);
                    }
                }

                //2.处理浮点数字
                if (t == typeof(decimal) || t == typeof(double) || t == typeof(float))
                {
                    if (prop?.OldValue == null)
                    {
                        line.OldValueFormatted = string.Empty;
                    }
                    else
                    {
                        line.OldValueFormatted = string.Format("{0:#0.######}", prop.OldValue);
                    }

                    if (prop?.NewValue == null)
                    {
                        line.NewValueFormatted = string.Empty;
                    }
                    else
                    {
                        line.NewValueFormatted = string.Format("{0:#0.######}", prop.NewValue);
                    }
                }
                //3.处理整数
                if (t == typeof(int) || t == typeof(long) || t == typeof(byte))
                {
                    if (prop?.OldValue == null)
                    {
                        line.OldValueFormatted = string.Empty;
                    }
                    else
                    {
                        line.OldValueFormatted = prop.OldValue.ToString();
                    }

                    if (prop?.NewValue == null)
                    {
                        line.NewValueFormatted = string.Empty;
                    }
                    else
                    {
                        line.NewValueFormatted = prop.NewValue.ToString();
                    }
                }
            }
            catch (Exception ex)
            {
                logger.LogError(ex, "AuditTool.FormatDataByType().Error");
            }
        }