/// <summary> /// 功能描述:修改数据(如果实体启用记录修改字段功能,则修改主键可用,否则请重新该函数并使用dal的UpdateEx函数进行处理) /// </summary> /// <param name="strJson">strJson</param> /// <returns>返回值</returns> public virtual string Update(string strJson) { TEntity entity = strJson.ToJsonObject <TEntity>(); try { Type type = entity.GetType(); //取的LstModifyFields PropertyInfo pi = type.GetProperty("LstModifyFields"); Dictionary <string, object> LstModifyFields = null; if (pi != null) { LstModifyFields = pi.GetValue(entity, null) as Dictionary <string, object>; } //是否修改内容包含主键 bool blnIsHas = false; bool blnUpdate = false; if (LstModifyFields != null && LstModifyFields.Count > 0) { List <string> lst = LstModifyFields.Keys.ToList(); MethodInfo miIsHasPrimaryKey = type.GetMethod("IsHasPrimaryKey", new Type[] { lst.GetType() }); blnIsHas = (bool)miIsHasPrimaryKey.Invoke(entity, new object[] { lst }); } if (blnIsHas) { //处理包含主键的修改 MethodInfo miCreateWhereDictWithModifyFields = type.GetMethod("CreateWhereDictWithModifyFields", new Type[] { }); Dictionary <string, object> lstDicWhere = (Dictionary <string, object>)miCreateWhereDictWithModifyFields.Invoke(entity, null); blnUpdate = dal.UpdateEx(entity, LstModifyFields.Keys.ToList(), lstDicWhere); } else { //普通修改 blnUpdate = dal.Update(entity, LstModifyFields == null ? null : LstModifyFields.Keys.ToList(), null); } if (pi != null) { MethodInfo mi = entity.GetType().GetMethod("ClearRecord"); if (mi != null) { mi.Invoke(entity, null); } } if (blnUpdate) { return(ExcuteMessage.Sucess(entity)); } else { return(ExcuteMessage.Error("更新失败。")); } } catch (Exception ex) { return(ExcuteMessage.ErrorOfException(ex)); } }
/// <summary> /// 功能描述:根据条件查询一条数据 /// </summary> /// <param name="strWhere">条件</param> /// <returns>返回值</returns> public virtual string SelectByWhere(string strWhere) { try { var entity = dal.QueryEntity(strWhere); return(ExcuteMessage.Sucess(entity)); } catch (Exception ex) { return(ExcuteMessage.ErrorOfException(ex)); } }
/// <summary> /// 功能描述:查询一条单表数据 /// </summary> /// <param name="strID">ID</param> /// <returns>数据对象</returns> public virtual string Select(string strID) { try { var entity = dal.QueryByID(strID); return(ExcuteMessage.Sucess(entity)); } catch (Exception ex) { return(ExcuteMessage.ErrorOfException(ex)); } }
/// <summary> /// 功能描述:查询数据 /// </summary> /// <param name="strSqlwhere">strSqlwhere</param> /// <returns>返回值</returns> public virtual string Search(string strSqlwhere) { try { List <TEntity> list = dal.QueryList(strSqlwhere); return(ExcuteMessage.Sucess(list)); } catch (Exception ex) { return(ExcuteMessage.ErrorOfException(ex)); } }
/// <summary> /// 功能描述:数据条数 /// </summary> /// <param name="strWhere">strWhere</param> /// <returns>返回值</returns> public string SelectCount(string strWhere) { try { int intCount = dal.SelectCount(strWhere); return(ExcuteMessage.Sucess(intCount)); } catch (Exception ex) { return(ExcuteMessage.ErrorOfException(ex)); } }
/// <summary> /// 功能描述:根据条件删除 /// </summary> /// <param name="strWhere">strJson</param> /// <returns>返回值</returns> public virtual string DeleteByWhere(string strWhere) { try { dal.Delete(strWhere); return(ExcuteMessage.Sucess(true)); } catch (Exception ex) { return(ExcuteMessage.ErrorOfException(ex)); } }
/// <summary> /// 功能描述:删除数据 /// </summary> /// <param name="strJson">strJson</param> /// <returns>返回值</returns> public virtual string Delete(string strJson) { TEntity entity = strJson.ToJsonObject <TEntity>(); try { dal.Delete(entity); return(ExcuteMessage.Sucess(entity)); } catch (Exception ex) { return(ExcuteMessage.ErrorOfException(ex)); } }
public virtual string UpdateLst(string strJson) { List <TEntity> entity = strJson.ToJsonObject <List <TEntity> >(); try { if (dal.Update(entity.ToArray()) > 0) { return(ExcuteMessage.Sucess("更新成功")); } else { return(ExcuteMessage.Error("更新失败。")); } } catch (Exception ex) { return(ExcuteMessage.ErrorOfException(ex)); } }
/// <summary> /// 功能描述:批量插入 /// </summary> /// <param name="strJson">strJson</param> /// <returns>返回值</returns> public virtual string InsertLst(string strJson) { List <TEntity> entity = strJson.ToJsonObject <List <TEntity> >(); try { if (dal.Insert(entity.ToArray())) { return(ExcuteMessage.Sucess("新增成功")); } else { return(ExcuteMessage.Error("新增失败。")); } } catch (Exception ex) { return(ExcuteMessage.ErrorOfException(ex)); } }
/// <summary> /// 功能描述:新增数据 /// </summary> /// <param name="strJson">strJson</param> /// <returns>返回值</returns> public virtual string Insert(string strJson) { TEntity entity = strJson.ToJsonObject <TEntity>(); try { if (dal.Insert(entity)) { return(ExcuteMessage.Sucess(entity)); } else { return(ExcuteMessage.Error("新增失败。")); } } catch (Exception ex) { return(ExcuteMessage.ErrorOfException(ex)); } }
public string PostSource(string strJson) { try { if (string.IsNullOrEmpty(strJson)) { return("传入参数为空!"); } PostSourceEntity entity = strJson.ToJsonObject <PostSourceEntity>(); string str = string.Empty; str = JZ.Server.PublicServer.CallFunction(entity); return(str); } catch (Exception ex) { return(ExcuteMessage.ErrorOfException(ex)); } }
/// <summary> /// 功能描述:反射调用方法 /// </summary> /// <param name="source">source</param> /// <param name="action">推送广播</param> /// <returns>返回值</returns> public static string CallFunction(PostSourceEntity source) { try { Type type; if (string.IsNullOrEmpty(source.ClassTName)) { type = Assembly.Load("JZ.Server").GetType(string.Format("{0}.{1}", source.NameSpace, source.ClassName)); } else { type = Assembly.Load("JZ.Server").GetType(string.Format("{0}.{1}`1", source.NameSpace, source.ClassName)); Type typeArgument = Assembly.Load(source.TAssemblyName).GetType(source.ClassTName); // MakeGenericType is badly named type = type.MakeGenericType(typeArgument); } object obj = Activator.CreateInstance(type); if (obj == null) { return(ExcuteMessage.Error("没有找到指定的逻辑对象。")); } object[] parameters = null; MethodInfo method = null; if (source.Parameters != null) { method = type.GetMethod(source.FunctionName, new Type[] { typeof(string) }); parameters = new object[] { source.Parameters }; } else { method = type.GetMethod(source.FunctionName, new Type[] { }); } if (method == null) { return(ExcuteMessage.Error("没有找到指定的函数。")); } if (string.IsNullOrEmpty(source.MethodTName)) { object objReturn = method.Invoke(obj, parameters); if (objReturn != null) { return(objReturn.ToString()); } } else { object objReturn = method.MakeGenericMethod(new Type[] { Assembly.Load(source.TAssemblyName).GetType(source.ClassTName) }).Invoke(obj, parameters); if (objReturn != null) { return(objReturn.ToString()); } } return(""); } catch (Exception ex) { return(ExcuteMessage.ErrorOfException(ex)); } }