Exemple #1
0
        public ModifyLogEntity ModifyRecord(HRInfoEntity entity)
        {
            var oldEntity = GetFirstOrDefault(entity.iGuid);

            if (oldEntity == null)
            {
                return(null);
            }
            else
            {
                string modifiedContent = string.Empty;
                System.Reflection.PropertyInfo[] properties = entity.GetType().GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);

                Dictionary <string, string> hrDicConvertTmp = ConvertHelper.DicConvert(hrDic);

                foreach (System.Reflection.PropertyInfo item in properties)
                {
                    string name = item.Name;
                    if (!hrDicConvertTmp[name].StartsWith("i"))
                    {
                        object value = item.GetValue(entity, null);
                        if (value == null)
                        {
                            value = "";
                        }
                        object valueOld = item.GetValue(oldEntity, null);
                        if (valueOld == null)
                        {
                            valueOld = "";
                        }
                        if (value.ToString() != valueOld.ToString() && (item.PropertyType.IsValueType || item.PropertyType.Name.StartsWith("String")))
                        {
                            modifiedContent += string.Format("{0}:[{1}]->[{2}] ;", hrDicConvertTmp[name], valueOld, value);
                        }
                    }
                }
                if (string.IsNullOrEmpty(modifiedContent))
                {
                    return(null);
                }
                modifiedContent = "基本信息:[" + entity.iName + "," + entity.iIdCard + "]" + modifiedContent;
                ModifyLogEntity en = new ModifyLogEntity();
                en.iId              = entity.iGuid;
                en.iModifiedBy      = entity.iUpdatedBy;
                en.iModifiedOn      = DateTime.Now;
                en.iModifiedContent = modifiedContent;
                en.iTableName       = "HRInfo";
                return(en);
            }
        }
Exemple #2
0
        /// <summary>
        /// 插入一条记录
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public void Insert(ModifyLogEntity entity)
        {
            entity.iId = Guid.NewGuid().ToString();
            IDbSession session = SessionFactory.CreateSession();

            try
            {
                session.BeginTrans();
                Repository.Insert <ModifyLogEntity>(session.Connection, entity, session.Transaction);
                session.Commit();
            }
            catch (System.Exception)
            {
                session.Rollback();
                throw;
            }
            finally
            {
                session.Dispose();
            }
        }