Esempio n. 1
0
        /// <summary>
        /// 获取数据变更列表
        /// </summary>
        /// <param name="condition">查询条件</param>
        /// <param name="page">分页设置</param>
        /// <returns>数据页</returns>
        public DataPage GetList(DataMark condition, DataPage page)
        {
            string sql = null;
            List <DataParameter> parameters = new List <DataParameter>();

            try
            {
                //获取查询语句
                sql = this.GetQuerySql(condition, ref parameters);

                //分页关键字段及排序
                page.KeyName = "USERID";
                if (string.IsNullOrEmpty(page.SortExpression) == true)
                {
                    page.SortExpression = "OPERATETIME DESC";
                }

                using (IDataSession session = AppDataFactory.CreateMainSession())
                {
                    page = session.GetDataPage <DataMark>(sql, parameters.ToArray(), page);
                }

                return(page);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Esempio n. 2
0
 /// <summary>
 /// 获取数据变更列表
 /// </summary>
 /// <param name="condition">查询条件</param>
 /// <param name="page">分页设置</param>
 /// <returns>数据页</returns>
 public DataPage GetList(DataMark condition, DataPage page)
 {
     try
     {
         if (string.IsNullOrEmpty(condition.DATAKIND) == false)
         {
             condition.DATAKIND = this.GetTableName(condition.DATAKIND);
         }
         return(new DataChangeManageDAL().GetList(condition, page));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Esempio n. 3
0
        /// <summary>
        /// 获取查询语句
        /// </summary>
        /// <param name="user">查询条件</param>
        /// <param name="parameters">参数</param>
        /// <returns>查询语句</returns>
        private string GetQuerySql(DataMark condition, ref List <DataParameter> parameters)
        {
            StringBuilder sqlBuilder   = new StringBuilder();
            StringBuilder whereBuilder = new StringBuilder();

            try
            {
                sqlBuilder.Append("SELECT T1.MARKID,T1.OPERATETIME,T2.USERDES AS OPERATEUSER,T1.OPERATETYPE,T3.COMMENTS AS DATAKIND ");
                sqlBuilder.Append("FROM T_BD_DATAMARK T1 ");
                sqlBuilder.Append("left JOIN T_QM_USERINFO T2 ON t1.OPERATEUSER=T2.USERID ");
                sqlBuilder.Append("left JOIN ALL_TAB_COMMENTS T3 ON T3.OWNER='PLP' AND T1.DATAKIND=T3.TABLE_NAME ");

                if (string.IsNullOrEmpty(condition.STARTOPERATETIME) == false)
                {
                    whereBuilder.Append(" AND T1.OPERATETIME >= :DATE1");
                    parameters.Add(new DataParameter("DATE1", DateTime.Parse(condition.STARTOPERATETIME)));
                }

                if (string.IsNullOrEmpty(condition.ENDOPERATETIME) == false)
                {
                    whereBuilder.Append(" AND T1.OPERATETIME <= :DATE2");
                    parameters.Add(new DataParameter("DATE2", DateTime.Parse(condition.ENDOPERATETIME).AddDays(1).AddSeconds(-1)));
                }

                if (string.IsNullOrEmpty(condition.OPERATEUSER) == false)
                {
                    whereBuilder.Append(" AND (T2.USERNAME LIKE :OPERATEUSER OR T2.USERDES LIKE :OPERATEUSER)");
                    parameters.Add(new DataParameter("OPERATEUSER", "%" + condition.OPERATEUSER + "%"));
                }

                if (string.IsNullOrEmpty(condition.DATAKIND) == false)
                {
                    whereBuilder.Append(" AND T1.DATAKIND=:DATAKIND");
                    parameters.Add(new DataParameter("DATAKIND", condition.DATAKIND));
                }

                if (whereBuilder.Length > 0)
                {
                    sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
                }

                return(sqlBuilder.ToString());
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Esempio n. 4
0
        /// <summary>
        /// 获取数据变更痕迹数据
        /// </summary>
        /// <param name="info">变更痕迹</param>
        /// <returns>变更痕迹</returns>
        public DataMark GetInfo(DataMark info, ref DataTable columnDt)
        {
            StringBuilder        sqlBuilder = new StringBuilder();
            List <DataParameter> parameters = new List <DataParameter>();

            try
            {
                using (IDataSession session = AppDataFactory.CreateMainSession())
                {
                    sqlBuilder.Append("SELECT T1.MARKID,T1.OPERATETIME,T2.USERDES AS OPERATEUSER,T1.OPERATETYPE,T1.DATAKIND,T3.COMMENTS AS DATAKINDDES,T1.OriginalData,T1.ChangedData ");
                    sqlBuilder.Append("FROM T_BD_DATAMARK T1 ");
                    sqlBuilder.Append("left JOIN T_QM_USERINFO T2 ON t1.OPERATEUSER=T2.USERID ");
                    sqlBuilder.Append("left JOIN ALL_TAB_COMMENTS T3 ON T3.OWNER='PLP' AND T1.DATAKIND=T3.TABLE_NAME ");
                    sqlBuilder.Append("WHERE T1.MARKID=:MARKID");
                    //获取变更痕迹信息
                    info = session.Get <DataMark>(sqlBuilder.ToString(), new DataParameter("MARKID", info.MARKID));

                    //获取字段描述信息
                    if (columnDt != null)
                    {
                        sqlBuilder.Clear();
                        sqlBuilder.Append("SELECT T1.COLUMN_NAME AS COLUMNNAME, T1.COMMENTS AS COLUMNDES ");
                        sqlBuilder.Append("FROM USER_COL_COMMENTS T1, ALL_TAB_COMMENTS T2 ");
                        sqlBuilder.Append("WHERE T1.TABLE_NAME = T2.TABLE_NAME  AND T1.TABLE_NAME = :TABLENAME");
                        parameters.Add(new DataParameter("TABLENAME", info.DATAKIND));

                        session.FillTable(columnDt, sqlBuilder.ToString(), parameters.ToArray());
                    }
                }

                return(info);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Esempio n. 5
0
        /// <summary>
        /// 记录数据变更新信息
        /// </summary>
        /// <typeparam name="T">数据类型</typeparam>
        /// <param name="oprType">操作类型</param>
        /// <param name="OperateUser">操作者</param>
        /// <param name="oldInfo">原数据</param>
        /// <param name="newInfo">新数据</param>
        public void RecordDataChangeMark <T>(DataOprType oprType, string OperateUser, T oldInfo, T newInfo) where T : new()
        {
            string   tableName = "";
            DataMark mark      = new DataMark();

            try
            {
                Type type = typeof(T);

                //获取表名
                object[]         attrsClassAtt = type.GetCustomAttributes(typeof(DBTableAttribute), true);
                DBTableAttribute tableAtt      = (DBTableAttribute)attrsClassAtt[0];
                tableName = tableAtt.TableName;

                //创建痕迹信息
                mark.MARKID      = Guid.NewGuid().ToString();
                mark.OPERATEUSER = OperateUser;
                mark.DATAKIND    = tableName;
                mark.OPERATETIME = DateTime.Now;
                mark.OPERATETYPE = oprType.ToString();
                mark.DATAID      = "";

                mark.ORIGINALDATA = LAF.Common.Serialization.JsonConvertHelper.GetSerializes(oldInfo);

                if (oprType == DataOprType.Update)
                {
                    mark.CHANGEDDATA = LAF.Common.Serialization.JsonConvertHelper.GetSerializes(newInfo);
                }

                //保存痕迹信息
                Session.Insert <DataMark>(mark);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Esempio n. 6
0
        public DataMark GetInfo(DataMark info)
        {
            DataTable columnDt = new DataTable();
            object    oldInfo  = null;
            object    newInfo  = null;
            Type      entityType;

            try
            {
                //获取数据
                info = new DataChangeManageDAL().GetInfo(info, ref columnDt);

                //获取实体类型
                entityType = this.GetEntityTypeByTable(info.DATAKIND);

                info.DATAKIND = info.DATAKINDDES;

                //json格式数据转换为实体
                if (string.IsNullOrEmpty(info.ORIGINALDATA) == false)
                {
                    oldInfo = JsonConvertHelper.GetDeserialize(entityType, info.ORIGINALDATA);
                }

                if (string.IsNullOrEmpty(info.CHANGEDDATA) == false)
                {
                    newInfo = JsonConvertHelper.GetDeserialize(entityType, info.CHANGEDDATA);
                }

                //生成字段明细数据
                PropertyInfo[] pArray = entityType.GetProperties();

                info.Details = new List <DataMarkDetail>();
                //获取字段信息
                foreach (var item in pArray)
                {
                    object[] attrs = item.GetCustomAttributes(typeof(DBColumnAttribute), true);
                    if (attrs.Count() == 0)
                    {
                        continue;
                    }

                    DBColumnAttribute ca = (DBColumnAttribute)attrs[0];//字段属性

                    DataMarkDetail detail = new DataMarkDetail();

                    //原值
                    object oldValue = null;
                    if (oldInfo != null)
                    {
                        oldValue = BindHelper.GetPropertyValue(oldInfo, item.Name);
                    }

                    detail.OldValue = oldValue == null?"":oldValue.ToString();

                    //变更后值
                    object newValue = null;
                    if (newInfo != null)
                    {
                        newValue = BindHelper.GetPropertyValue(newInfo, item.Name);
                    }

                    detail.NewValue = newValue == null ? "" : newValue.ToString();

                    DataRow[] rows = columnDt.Select("COLUMNNAME='" + ca.ColumnName + "'");
                    if (rows.Length > 0)
                    {
                        detail.ColumnDes = rows[0]["COLUMNDES"].ToString();
                    }

                    if (string.IsNullOrEmpty(detail.ColumnDes) == true)
                    {
                        continue;
                    }

                    info.Details.Add(detail);
                }

                return(info);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }