예제 #1
0
        /// <summary>
        /// 操作任务日志
        /// </summary>
        /// <typeparam name="T">操作数据类型</typeparam>
        /// <param name="listInfo">实体集列表</param>
        /// <param name="dataOperator">数据库操作类型</param>
        /// <param name="error">错误信息</param>
        bool SystemLog <T>(List <T> listInfo, 数据库操作 dataOperator, out string error)
        {
            error = null;

            if (listInfo == null || listInfo.Count == 0)
            {
                error = "操作失败: 数据为空";
                return(false);
            }

            try
            {
                AccessParameter acc = new AccessParameter();

                if (!SystemLog <T>(acc, listInfo, dataOperator, out error))
                {
                    return(false);
                }

                if (!RunTransaction(acc))
                {
                    error = "操作失败:存储过程操作失败";
                    return(false);
                }

                return(true);
            }
            catch (Exception ex)
            {
                error = ex.Message;
                return(false);
            }
        }
예제 #2
0
        /// <summary>
        /// 操作任务日志
        /// </summary>
        /// <typeparam name="T">操作数据类型</typeparam>
        /// <typeparam name="accessParameter">数据上下文</typeparam>
        /// <param name="listInfo">实体集列表</param>
        /// <param name="dataOperator">数据库操作类型</param>
        /// <param name="error">错误信息</param>
        bool SystemLog <T>(AccessParameter accessParameter, List <T> listInfo, 数据库操作 dataOperator, out string error)
        {
            error = null;

            if (listInfo == null || listInfo.Count == 0)
            {
                error = "操作失败: 数据为空";
                return(false);;
            }

            try
            {
                List <ServiceEntity.DataBaseOperatorParmeters> listOperator = GetOperatorInfo <T>(listInfo, dataOperator);

                foreach (ServiceEntity.DataBaseOperatorParmeters item in listOperator)
                {
                    string strPrimary = "";
                    string strWhere   = "主键:";

                    foreach (KeyValuePair <string, object> primaryKey in item.PrimaryKey)
                    {
                        string strValue = "";

                        if (primaryKey.Value != null)
                        {
                            strValue = primaryKey.Value.ToString();
                        }

                        strWhere += " 【 " + primaryKey.Key + " 字段, 值: " + strValue + " 】";
                    }

                    foreach (KeyValuePair <string, DataValueType> info in item.OperatorInfo)
                    {
                        if (info.Key != null)
                        {
                            strWhere += "【 " + info.Key + " 字段,";

                            string strOld = info.Value.OldValue == null ? "" : info.Value.OldValue.ToString();
                            string strNew = info.Value.NewValue == null ? "" : info.Value.NewValue.ToString();

                            if (info.Value.NewValue != null)
                            {
                                strWhere += " 值: " + strNew;
                            }

                            if (item.DataOperator == 数据库操作.修改)
                            {
                                strWhere += " 原值: " + strNew;
                            }

                            strWhere += " 】";
                        }
                    }

                    DataEntity.PRJ_SystemLog sysLog = new DataEntity.PRJ_SystemLog();

                    sysLog.Content = "操作表: {[" + item.TableName + "]},操作类型:{" + item.DataOperator.ToString() + "}, {"
                                     + strPrimary + "}, 操作内容: {" + strWhere + "}";
                    sysLog.RecordTime = DateTime.Now;
                    sysLog.Recorder   = "";

                    List <DataEntity.PRJ_SystemLog> list = new List <DataEntity.PRJ_SystemLog>();
                    list.Add(sysLog);

                    if (!Insert <DataEntity.PRJ_SystemLog>(list, accessParameter, out error))
                    {
                        return(false);
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                error = ex.Message;
                return(false);
            }
        }
예제 #3
0
        /// <summary>
        /// 获得数据库操作参数实体集列表
        /// </summary>
        /// <typeparam name="T">数据类型</typeparam>
        /// <param name="listInfo">实体集列表</param>
        /// <param name="dataOperator">数据库操作类型</param>
        /// <returns>返回数据库操作参数实体集列表</returns>
        public List <ServiceEntity.DataBaseOperatorParmeters> GetOperatorInfo <T>(List <T> listInfo, 数据库操作 dataOperator)
        {
            if (listInfo == null || listInfo.Count == 0)
            {
                return(null);
            }

            Dictionary <string, Type> dic = GlobalObject.GeneralFunction.GetAttribute <T>();

            string name             = typeof(T).ToString();
            int    indexOfLastPoint = name.LastIndexOf('.');
            string strTableName     = name.Substring(indexOfLastPoint + 1);

            Dictionary <T, string> dicSelect = GetWhereDictionary <T>(listInfo);

            if (dicSelect == null)
            {
                return(null);
            }
            else
            {
                Dictionary <T, T> dicCompare = new Dictionary <T, T>();

                foreach (KeyValuePair <T, string> dicItemSelect in dicSelect)
                {
                    dicCompare.Add(dicItemSelect.Key, GetItem <T>(dicItemSelect.Value.ToString()));
                }

                List <ServiceEntity.DataBaseOperatorParmeters> listOpertaor = new List <ServiceEntity.DataBaseOperatorParmeters>();

                foreach (KeyValuePair <T, T> compareItem in dicCompare)
                {
                    ServiceEntity.DataBaseOperatorParmeters dbOperatorModel = new ServiceEntity.DataBaseOperatorParmeters();

                    dbOperatorModel.PrimaryKey   = new Dictionary <string, object>();
                    dbOperatorModel.OperatorInfo = new Dictionary <string, DataValueType>();
                    dbOperatorModel.TableName    = strTableName;
                    dbOperatorModel.DataOperator = dataOperator;

                    T oldModel = compareItem.Value;
                    T newModel = compareItem.Key;

                    foreach (KeyValuePair <string, Type> column in dic)
                    {
                        if (column.Value.FullName.Contains("List"))
                        {
                            continue;
                        }

                        string strColumnName = column.Key.ToString();

                        object objOldValue = null;
                        object objNewValue = null;

                        if (oldModel != null)
                        {
                            objOldValue = oldModel.GetType().GetProperty(strColumnName).GetValue(oldModel, null);
                        }

                        if (newModel != null)
                        {
                            objNewValue = newModel.GetType().GetProperty(strColumnName).GetValue(newModel, null);
                        }

                        DataValueType modelType = new DataValueType();
                        modelType.NewValue = objNewValue;
                        modelType.OldValue = objOldValue;

                        switch (dbOperatorModel.DataOperator)
                        {
                        case 数据库操作.添加:
                            dbOperatorModel.OperatorInfo.Add(column.Key, modelType);
                            break;

                        case 数据库操作.修改:
                            if (objOldValue != objNewValue)
                            {
                                string strOld = objOldValue == null ? "" : objOldValue.ToString();
                                string strNew = objNewValue == null ? "" : objNewValue.ToString();

                                if (strOld != strNew)
                                {
                                    dbOperatorModel.OperatorInfo.Add(column.Key, modelType);
                                }
                            }
                            break;

                        default:
                            break;
                        }
                    }

                    List <string> listPKeys = GetPrimaryKey <T>();

                    foreach (string primaryKeyName in listPKeys)
                    {
                        object objValue = null;

                        if (newModel != null)
                        {
                            objValue = newModel.GetType().GetProperty(primaryKeyName).GetValue(newModel, null);
                        }

                        dbOperatorModel.PrimaryKey.Add(primaryKeyName, objValue);
                    }

                    listOpertaor.Add(dbOperatorModel);
                }

                return(listOpertaor);
            }
        }