Exemplo n.º 1
0
        /// <summary>
        /// 写入作业日志(更新操作)
        /// </summary>
        /// <param name="oldObj">旧实体对象</param>
        /// <param name="newObj">新实体对象</param>
        /// <param name="OperationType">操作类型</param>
        /// <param name="Status">状态</param>
        /// <param name="Remark">操作说明</param>
        /// <returns></returns>
        public void WriteLog <T>(T oldObj, T newObj, OperationType OperationType, string Status, string Remark = "")
        {
            IDatabase     database    = DataFactory.Database();
            DbTransaction isOpenTrans = database.BeginTrans();

            try
            {
                SysLog.SysLogId       = CommonHelper.GetGuid;
                SysLog.ObjectId       = DatabaseCommon.GetKeyFieldValue(newObj).ToString();
                SysLog.LogType        = CommonHelper.GetString((int)OperationType);
                SysLog.IPAddress      = ManageProvider.Provider.Current().IPAddress;
                SysLog.IPAddressName  = ManageProvider.Provider.Current().IPAddressName;
                SysLog.CompanyId      = ManageProvider.Provider.Current().CompanyId;
                SysLog.DepartmentId   = ManageProvider.Provider.Current().DepartmentId;
                SysLog.CreateUserId   = ManageProvider.Provider.Current().UserId;
                SysLog.CreateUserName = ManageProvider.Provider.Current().UserName;
                SysLog.ModuleId       = DESEncrypt.Decrypt(CookieHelper.GetCookie("ModuleId"));
                if (Remark == "")
                {
                    SysLog.Remark = DatabaseCommon.GetClassName <T>();
                }
                SysLog.Remark = Remark;
                SysLog.Status = Status;
                database.Insert(SysLog, isOpenTrans);
                //添加日志详细信息
                Type objTye = typeof(T);
                foreach (PropertyInfo pi in objTye.GetProperties())
                {
                    object oldVal = pi.GetValue(oldObj, null);
                    object newVal = pi.GetValue(newObj, null);
                    if (!Equals(oldVal, newVal))
                    {
                        if (oldVal != null && oldVal.ToString() != "&nbsp;" && oldVal.ToString() != "" && newVal != null && newVal.ToString() != "&nbsp;" && newVal.ToString() != "")
                        {
                            Base_SysLogDetail syslogdetail = new Base_SysLogDetail();
                            syslogdetail.SysLogDetailId = CommonHelper.GetGuid;
                            syslogdetail.SysLogId       = SysLog.SysLogId;
                            syslogdetail.PropertyField  = pi.Name;
                            syslogdetail.PropertyName   = DatabaseCommon.GetFieldText(pi);
                            syslogdetail.NewValue       = "" + newVal + "";
                            syslogdetail.OldValue       = "" + oldVal + "";
                            database.Insert(syslogdetail, isOpenTrans);
                        }
                    }
                }
                DataFactory.Database().Commit();
            }
            catch
            {
                database.Rollback();
                database.Close();
                throw;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 写入作业日志(删除操作)
        /// </summary>
        /// <param name="oldObj">旧实体对象</param>
        /// <param name="KeyValue">对象主键</param>
        /// <param name="Status">状态</param>
        /// <param name="Remark">操作说明</param>
        public void WriteLog <T>(string[] KeyValue, string Status, string Remark = "") where T : new()
        {
            IDatabase     database    = DataFactory.Database();
            DbTransaction isOpenTrans = database.BeginTrans();

            try
            {
                foreach (var item in KeyValue)
                {
                    T Oldentity = database.FindEntity <T>(item.ToString());
                    SysLog.SysLogId       = CommonHelper.GetGuid;
                    SysLog.ObjectId       = item;
                    SysLog.LogType        = CommonHelper.GetString((int)OperationType.Delete);
                    SysLog.IPAddress      = ManageProvider.Provider.Current().IPAddress;
                    SysLog.IPAddressName  = ManageProvider.Provider.Current().IPAddressName;
                    SysLog.CompanyId      = ManageProvider.Provider.Current().CompanyId;
                    SysLog.DepartmentId   = ManageProvider.Provider.Current().DepartmentId;
                    SysLog.CreateUserId   = ManageProvider.Provider.Current().UserId;
                    SysLog.CreateUserName = ManageProvider.Provider.Current().UserName;
                    SysLog.ModuleId       = DESEncrypt.Decrypt(CookieHelper.GetCookie("ModuleId"));
                    if (Remark == "")
                    {
                        SysLog.Remark = DatabaseCommon.GetClassName <T>();
                    }
                    SysLog.Remark = Remark;
                    SysLog.Status = Status;
                    database.Insert(SysLog, isOpenTrans);
                    //添加日志详细信息
                    Type objTye = typeof(T);
                    foreach (PropertyInfo pi in objTye.GetProperties())
                    {
                        object value = pi.GetValue(Oldentity, null);
                        if (value != null && value.ToString() != "&nbsp;" && value.ToString() != "")
                        {
                            Base_SysLogDetail syslogdetail = new Base_SysLogDetail();
                            syslogdetail.SysLogDetailId = CommonHelper.GetGuid;
                            syslogdetail.SysLogId       = SysLog.SysLogId;
                            syslogdetail.PropertyField  = pi.Name;
                            syslogdetail.PropertyName   = DatabaseCommon.GetFieldText(pi);
                            syslogdetail.NewValue       = "" + value + "";
                            database.Insert(syslogdetail, isOpenTrans);
                        }
                    }
                }
                database.Commit();
            }
            catch
            {
                database.Rollback();
                database.Close();
                throw;
            }
        }