public HttpResponseMessage History([FromBody] Input data) { db = new DBOperationService(); ChangeDataType change = new ChangeDataType(); CookieHeaderValue cookie = Request.Headers.GetCookies("session").FirstOrDefault(); UseHistory history = change.Mapper(data, cookie["session"].Values["email"], DateTime.Now); db.StoreHistory(history); TopObject <Input> result = new TopObject <Input>() { status = Convert.ToInt32(HttpStatusCode.OK), input = data, message = "記錄成功~!!" }; var resp = new HttpResponseMessage(HttpStatusCode.OK) { Content = new ObjectContent <TopObject <Input> >(result, new JsonMediaTypeFormatter()) }; return(resp); }
/// <summary> /// 加字段值 /// </summary> /// <param name="field"></param> /// <param name="memberData"></param> /// <param name="skill"></param> public static void AdditionField(FieldInfo field, VOBase memberData, VOBase changeData, VOBase changedData, IDictionary <string, ChangeDataType> changeDataTypeDic) { var propertyName = field.Name; ChangeDataType changeDataType = ChangeDataType.Absolute; // 读取赋值类型, 如果没有则默认使用绝对值 if (changeDataTypeDic.ContainsKey(propertyName)) { changeDataType = changeDataTypeDic[propertyName]; } // 修改float类型属性 if (field.FieldType == typeof(float)) { var sourceValue = Convert.ToSingle(field.GetValue(memberData)); var plusValue = Convert.ToSingle(field.GetValue(changeData)) * (changeDataType == ChangeDataType.Absolute ? 1 : sourceValue); field.SetValue(memberData, sourceValue + plusValue); // 保存变更数据 field.SetValue(changedData, plusValue); } // 修改bool类型属性 else if (field.FieldType == typeof(bool)) { field.SetValue(memberData, Convert.ToBoolean(field.GetValue(changeData))); // 保存变更数据 field.SetValue(changedData, field.GetValue(memberData)); } // 修改int,short,long类型属性 else if (field.FieldType == typeof(long) || field.FieldType == typeof(short) || field.FieldType == typeof(int)) { var sourceValue = Convert.ToInt64(field.GetValue(memberData)); var plusValue = Convert.ToInt64(field.GetValue(changeData)) * (changeDataType == ChangeDataType.Absolute ? 1 : sourceValue); field.SetValue(memberData, Convert.ChangeType((sourceValue + plusValue), field.FieldType)); // 保存变更数据 field.SetValue(changedData, Convert.ChangeType(plusValue, field.FieldType)); } }
/// <summary> /// 加属性值 /// </summary> /// <param name="property"></param> /// <param name="memberData"></param> public static void AdditionProperty(PropertyInfo property, VOBase memberData, VOBase changeData, VOBase changedData, IDictionary <string, ChangeDataType> changeDataTypeDic) { var propertyName = property.Name; ChangeDataType changeDataType = ChangeDataType.Absolute; // 读取赋值类型, 如果没有则默认使用绝对值 if (changeDataTypeDic.ContainsKey(propertyName)) { changeDataType = changeDataTypeDic[propertyName]; } // 修改float类型属性 if (property.PropertyType == typeof(float)) { var sourceValue = Convert.ToSingle(property.GetValue(memberData, null)); var plusValue = Convert.ToSingle(property.GetValue(changeData, null)) * (changeDataType == ChangeDataType.Absolute ? 1 : sourceValue); property.SetValue(memberData, sourceValue + plusValue, null); // 保存变更数据 property.SetValue(changedData, plusValue, null); } // 修改bool类型属性 else if (property.PropertyType == typeof(bool)) { property.SetValue(memberData, Convert.ToBoolean(property.GetValue(changeData, null)), null); // 保存变更数据 property.SetValue(changedData, property.GetValue(memberData, null), null); } // 修改int,short,long类型属性 else if (property.PropertyType == typeof(long) || property.PropertyType == typeof(short) || property.PropertyType == typeof(int)) { var sourceValue = Convert.ToInt64(property.GetValue(memberData, null)); var plusValue = Convert.ToInt64(property.GetValue(changeData, null)) * (changeDataType == ChangeDataType.Absolute ? 1 : sourceValue); property.SetValue(memberData, Convert.ChangeType((sourceValue + plusValue), property.PropertyType), null); // 保存变更数据 property.SetValue(changedData, Convert.ChangeType(plusValue, property.PropertyType), null); } }
/// <summary> /// 生成行为 /// </summary> /// <param name="paramsPacker"></param> /// <returns>行为节点</returns> public override IFormula GetFormula(FormulaParamsPacker paramsPacker) { IFormula result = null; string errorMsg = null; if (paramsPacker == null) { errorMsg = "调用参数 paramsPacker 为空."; } else if (string.IsNullOrEmpty(PropertyName) || property == null) { errorMsg = "属性名称为空."; } else if (string.IsNullOrEmpty(Value)) { errorMsg = "属性值为空"; } if (!string.IsNullOrEmpty(errorMsg)) { throw new Exception(errorMsg); } // 替换数据 ReplaceData(paramsPacker); // 数据本地化 var myFormulaType = FormulaType; var myPropertyName = PropertyName; var myValue = Value; var myChangeDataType = ChangeDataType; var myProperty = property; var myField = field; var target = ReceivePos == 0 ? paramsPacker.ReleaseMember.ClusterData.AllData.MemberData : paramsPacker.ReceiverMenber.ClusterData.AllData.MemberData; result = new Formula((callback, scope) => { var changeData = new VOBase(); // 给目标增加属性 if (myProperty != null) { myProperty.SetValue(changeData, Convert.ChangeType(myValue, myProperty.PropertyType), null); } else if (myField != null) { myField.SetValue(changeData, Convert.ChangeType(myValue, myField.FieldType)); } ChangeDataType tmpType = ChangeDataType.Absolute; if (paramsPacker.Skill.ChangeDataTypeDic.ContainsKey(myPropertyName)) { tmpType = paramsPacker.Skill.ChangeDataTypeDic[myPropertyName]; paramsPacker.Skill.ChangeDataTypeDic[myPropertyName] = myChangeDataType; } else { paramsPacker.Skill.ChangeDataTypeDic.Add(myPropertyName, myChangeDataType); } SkillBase.AdditionField(myField, target, changeData, paramsPacker.Skill.ChangedData, paramsPacker.Skill.ChangeDataTypeDic); paramsPacker.Skill.ChangeDataTypeDic[myPropertyName] = tmpType; }, myFormulaType); return(result); }