private void SetInfo(Int32 Id, Int32 sysId, string newValue) { bool isExist = false; foreach (var i in _info) { // 找到了 if (i.Id == Id) { i.SysId = (short)sysId; i.SysValue = newValue; i.EditorId = LoginUserInfo.Id; i.LastUpdateTime = DateTimeHelper.GetServerDateTime2(); //创建时间 i.CurrentLoginUserId = Portal.gc.UserInfo.Id; isExist = true; break; } } if (isExist == false) { SysparameterInfo info = new SysparameterInfo(); info.Id = Id; info.SysId = (short)sysId; info.SysValue = newValue; info.EditorId = LoginUserInfo.Id; info.LastUpdateTime = DateTimeHelper.GetServerDateTime2(); //创建时间 info.CurrentLoginUserId = Portal.gc.UserInfo.Id; _info.Add(info); } }
/// <summary> /// 从数据库中获取对象 /// </summary> /// <typeparam name="T"></typeparam> /// <returns></returns> public T GetSetting <T>() where T : class { try { SystemParameterBll bll = new SystemParameterBll(_RepoUri); SysparameterInfo para = null; QueryResult <SysparameterInfo> result = null; Type t = typeof(T); result = bll.GetSysParameterByID(t.Name); if (result.Result == ResultCode.Successful) { para = result.QueryObject; string value = para.ParameterValue; if (!string.IsNullOrEmpty(value)) { byte[] data = Encoding.UTF8.GetBytes(value); using (MemoryStream stream = new MemoryStream(data)) { stream.Position = 0; DataContractSerializer ser = new DataContractSerializer(t); return(ser.ReadObject(stream) as T); } } } } catch (Exception ex) { ExceptionPolicy.HandleException(ex); } return(null); }
/// <summary> ///保存到数据库 /// </summary> /// <param name="info"></param> public CommandResult SaveSetting <T>(T info) where T : class { try { SystemParameterBll bll = new SystemParameterBll(_RepoUri); Type t = typeof(T); SysparameterInfo para; if (info != null) { DataContractSerializer ser = new DataContractSerializer(t); using (MemoryStream stream = new MemoryStream()) { ser.WriteObject(stream, info); stream.Position = 0; byte[] data = new byte[stream.Length]; stream.Read(data, 0, (int)stream.Length); string value = Encoding.UTF8.GetString(data); para = new SysparameterInfo(t.Name, value, string.Empty); } } else { para = new SysparameterInfo(t.Name, string.Empty, string.Empty); } return(bll.Insert(para)); } catch (Exception ex) { ExceptionPolicy.HandleException(ex); return(new CommandResult(ResultCode.Fail, ex.Message)); } }
public CommandResult Insert(SysparameterInfo info) { return(provider.Insert(info)); }
public CommandResult Delete(SysparameterInfo info) { return(provider.Delete(info)); }