/// <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="strJson">strJson</param> /// <returns>返回值</returns> public string GetCacheSource(string strJson) { if (string.IsNullOrEmpty(strJson)) { return(ExcuteMessage.Error("参数为空。")); } Dictionary <string, object> lstParas = strJson.ToJsonObject <Dictionary <string, object> >(); string strProperty = lstParas["Property"].ToString(); string strTableName = lstParas["table"].ToString(); string strWhere = lstParas["where"].ToString(); Type type = Assembly.Load("JZ.Cache").GetType("JZ.Cache.CacheHelper"); PropertyInfo pi = type.GetProperty(strProperty); if (pi == null) { if (string.IsNullOrWhiteSpace(strTableName)) { return(ExcuteMessage.Sucess(new DataTable())); } //不存在缓存对象 PublicRepository dal = new PublicRepository(); DataTable dt = dal.GetTableByName(strTableName, strWhere); return(ExcuteMessage.Sucess(dt)); } else if (pi.GetValue(null, null) == null) { if (string.IsNullOrWhiteSpace(strTableName)) { return(ExcuteMessage.Sucess(new DataTable())); } //缓存无值 PublicRepository dal = new PublicRepository(); DataTable dt = dal.GetTableByName(strTableName, strWhere); pi.SetValue(null, dt.ToJsonHasNull().ToJsonObject(pi.PropertyType), null); return(ExcuteMessage.Sucess(dt)); } else { //返回缓存内容 return(ExcuteMessage.Sucess(pi.GetValue(null, null))); } }
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)); } }
private static void Rec(SocketHelper.Sockets sks) { if (sks.ex != null) { //string.Format("客户端出现异常:{0}.!", sks.ex.Message); } else { if (sks.NewClientFlag) { //string.Format("新客户端:{0}连接成功.!", sks.Ip) } else { byte[] buffer = new byte[sks.Offset]; Array.Copy(sks.RecBuffer, buffer, sks.Offset); string str = string.Empty; if (sks.Offset == 0) { str = "客户端下线"; } else { str = Encoding.UTF8.GetString(buffer); if (string.IsNullOrEmpty(str)) { server.SendToClient(sks.Ip, ExcuteMessage.Error("传入参数为空!")); return; } PostSourceEntity entity = str.ToJsonObject <PostSourceEntity>(); str = JZ.Server.PublicServer.CallFunction(entity); server.SendToClient(sks.Ip, str); } } } }
public string Test() { return(ExcuteMessage.Error("测试消息")); }
/// <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)); } }