/// <summary> /// Looks up a list of account names and returns information about each in a <see cref="SystemAccountInfo"/> class. Requires the /// <see cref="DesiredAccess.LookupNames"/> right. /// </summary> /// <returns>Contains a corresponding result for each name provided in <paramref name="sids"/>.</returns> /// <exception cref="ArgumentException">At least one user name must be supplied.</exception> public IList <SystemAccountInfo> GetAccountInfo(bool preferInternetNames, bool disallowConnectedAccts, params SecurityIdentifier[] sids) { if (sids == null || sids.Length == 0) { throw new ArgumentException(@"At least one SecurityIdentifier must be supplied.", nameof(sids)); } var opts = (preferInternetNames ? LsaLookupSidsFlags.LSA_LOOKUP_PREFER_INTERNET_NAMES : 0) | (disallowConnectedAccts ? LsaLookupSidsFlags.LSA_LOOKUP_DISALLOW_CONNECTED_ACCOUNT_INTERNET_SID : 0); var psids = sids.Select(s => new PinnedSid(s)); var ret = LsaLookupSids2(Handle, opts, (uint)sids.Length, psids.Select(s => s.PSID).ToArray(), out var domains, out var names); if (ret != NTStatus.STATUS_SUCCESS && ret != NTStatus.STATUS_SOME_NOT_MAPPED) { ThrowIfLsaError(ret); } var d = domains.DangerousGetHandle().ToStructure <LSA_REFERENCED_DOMAIN_LIST>().DomainList.ToArray(); var tn = names.DangerousGetHandle().ToIEnum <LSA_TRANSLATED_NAME>(sids.Length).ToArray(); var retVal = new SystemAccountInfo[sids.Length]; for (var i = 0; i < sids.Length; i++) { retVal[i] = new SystemAccountInfo(tn[i].Name.ToString(), tn[i].Use, sids[i], tn[i].DomainIndex, d); } return(retVal); }
public ActionResult Create(SystemAccountInfo model) { bool issuc = false; model.Password = Security.DESEncrypt(model.Password); model.CreateDate = DateTime.Now; model.CreateIP = this.GetIP; model.IsCanDelete = true; int id = accountMgr.Create(model); if (id > 0) { issuc = true; } MsgInfo msgInfo = new MsgInfo(); if (issuc) { msgInfo.IsError = false; msgInfo.Msg = "操作成功!"; msgInfo.MsgNo = (int)ErrorEnum.成功; } else { msgInfo.IsError = true; msgInfo.Msg = "操作失败!"; msgInfo.MsgNo = (int)ErrorEnum.失败; } return(Content(JsonConvert.SerializeObject(msgInfo))); }
public ActionResult Destroy(FormCollection col) { string id = col["Id"]; SystemAccountInfo model = accountMgr.Get(int.Parse(id)); if (model != null && !model.IsCanDelete) { return(Content("false")); } bool res = accountMgr.Delete(new SystemAccountInfo { Id = int.Parse(id) }); MsgInfo msgInfo = new MsgInfo(); if (res) { msgInfo.IsError = false; msgInfo.Msg = "删除成功!"; msgInfo.MsgNo = (int)ErrorEnum.成功; } else { msgInfo.IsError = true; msgInfo.Msg = "删除失败!"; msgInfo.MsgNo = (int)ErrorEnum.失败; } return(Content(JsonConvert.SerializeObject(msgInfo))); }
public ActionResult Destroys(FormCollection col) { string Ids = col["Ids"]; string[] _Ids = Ids.Split(','); List <string> ids = new List <string>(); SystemAccountInfo model = null; foreach (string id in _Ids) { model = accountMgr.Get(int.Parse(id)); if (model != null && model.IsCanDelete) { ids.Add(model.Id.ToString()); } } bool res = accountMgr.Deletes(string.Join(",", ids)); MsgInfo msgInfo = new MsgInfo(); if (res) { msgInfo.IsError = false; msgInfo.Msg = "删除成功!"; msgInfo.MsgNo = (int)ErrorEnum.成功; } else { msgInfo.IsError = true; msgInfo.Msg = "删除失败!"; msgInfo.MsgNo = (int)ErrorEnum.失败; } return(Content(JsonConvert.SerializeObject(msgInfo))); }
public int Create(SystemAccountInfo model) { Database db = DBHelper.CreateDataBase(); StringBuilder sb = new StringBuilder(); sb.Append("insert into SystemAccount("); sb.Append("Account,Password,UserName,NickName,RoleId,Department,IsEnable,IsCanDelete,CreateIP,CreateDate,Remarks"); sb.Append(") values("); sb.Append("@Account,@Password,@UserName,@NickName,@RoleId,@Department,@IsEnable,@IsCanDelete,@CreateIP,@CreateDate,@Remarks);SELECT @@IDENTITY;"); DbCommand dbCommand = db.GetSqlStringCommand(sb.ToString()); db.AddInParameter(dbCommand, "@Account", DbType.String, model.Account); db.AddInParameter(dbCommand, "@Password", DbType.String, model.Password); db.AddInParameter(dbCommand, "@UserName", DbType.String, model.UserName); db.AddInParameter(dbCommand, "@NickName", DbType.String, model.NickName); db.AddInParameter(dbCommand, "@RoleId", DbType.Int32, model.RoleId); db.AddInParameter(dbCommand, "@Department", DbType.Int32, model.Department); db.AddInParameter(dbCommand, "@IsEnable", DbType.Boolean, model.IsEnable); db.AddInParameter(dbCommand, "@IsCanDelete", DbType.Boolean, model.IsCanDelete); db.AddInParameter(dbCommand, "@CreateIP", DbType.String, model.CreateIP); db.AddInParameter(dbCommand, "@CreateDate", DbType.DateTime, model.CreateDate); db.AddInParameter(dbCommand, "@Remarks", DbType.String, model.Remarks); int id = Convert.ToInt32(db.ExecuteScalar(dbCommand)); return(id); }
public ActionResult Modify(SystemAccountInfo model) { bool issuc = false; SystemAccountInfo _model = accountMgr.Get(model.Id); if (_model != null) { _model.UserName = model.UserName; _model.RoleId = model.RoleId; _model.IsEnable = model.IsEnable; _model.Remarks = model.Remarks; if (!string.IsNullOrEmpty(model.Password)) { _model.Password = Security.DESEncrypt(model.Password); } issuc = accountMgr.Update(_model); } MsgInfo msgInfo = new MsgInfo(); if (issuc) { msgInfo.IsError = false; msgInfo.Msg = "操作成功!"; msgInfo.MsgNo = (int)ErrorEnum.成功; } else { msgInfo.IsError = true; msgInfo.Msg = "操作失败!"; msgInfo.MsgNo = (int)ErrorEnum.失败; } return(Content(JsonConvert.SerializeObject(msgInfo))); }
public bool Delete(SystemAccountInfo model) { Database db = DBHelper.CreateDataBase(); StringBuilder sb = new StringBuilder(); sb.Append("delete from SystemAccount"); sb.Append(" where Id=@Id"); DbCommand dbCommand = db.GetSqlStringCommand(sb.ToString()); db.AddInParameter(dbCommand, "@Id", DbType.Int32, model.Id); return(db.ExecuteNonQuery(dbCommand) < 1 ? false : true); }
public SystemAccountInfo Get(int Id) { Database db = DBHelper.CreateDataBase(); StringBuilder sb = new StringBuilder(); sb.Append("select * from SystemAccount where Id=@Id"); DbCommand dbCommand = db.GetSqlStringCommand(sb.ToString()); db.AddInParameter(dbCommand, "@Id", DbType.Int32, Id); SystemAccountInfo model = null; using (IDataReader dataReader = db.ExecuteReader(dbCommand)) { if (dataReader.Read()) { model = FillList(dataReader); } } return(model); }
/// <summary> /// Looks up a list of account names and returns information about each in a <see cref="SystemAccountInfo"/> class. Requires the /// <see cref="DesiredAccess.LookupNames"/> right. /// </summary> /// <param name="localOnly">If set to <c>true</c> restrict the search to only local accounts.</param> /// <param name="names"> /// The account names to lookup. These strings can be the names of user, group, or local group accounts, or the names of domains. /// Domain names can be DNS domain names or NetBIOS domain names. /// </param> /// <returns>Contains a corresponding result for each name provided in <paramref name="names"/>.</returns> /// <exception cref="ArgumentException">At least one user name must be supplied.</exception> public IList <SystemAccountInfo> GetAccountInfo(bool localOnly, params string[] names) { if (names == null || names.Length == 0) { throw new ArgumentException(@"At least one user name must be supplied.", nameof(names)); } var ret = LsaLookupNames2(Handle, localOnly ? LsaLookupNamesFlags.LSA_LOOKUP_ISOLATED_AS_LOCAL : 0, (uint)names.Length, names, out var domains, out var sids); if (ret != NTStatus.STATUS_SUCCESS && ret != NTStatus.STATUS_SOME_NOT_MAPPED) { ThrowIfLsaError(ret); } var d = domains.DangerousGetHandle().ToStructure <LSA_REFERENCED_DOMAIN_LIST>().DomainList.ToArray(); var ts = sids.DangerousGetHandle().ToIEnum <LSA_TRANSLATED_SID2>(names.Length).ToArray(); var retVal = new SystemAccountInfo[names.Length]; for (var i = 0; i < names.Length; i++) { retVal[i] = new SystemAccountInfo(names[i], ts[i].Use, IsValidSid(ts[i].Use) ? new SecurityIdentifier((IntPtr)ts[i].Sid) : null, ts[i].DomainIndex, d); } return(retVal); }
public bool Update(SystemAccountInfo model) { Database db = DBHelper.CreateDataBase(); StringBuilder sb = new StringBuilder(); sb.Append("update SystemAccount set "); sb.Append("Account=@Account,Password=@Password,UserName=@UserName,NickName=@NickName,RoleId=@RoleId,Department=@Department,IsEnable=@IsEnable,IsCanDelete=@IsCanDelete,CreateIP=@CreateIP,CreateDate=@CreateDate,Remarks=@Remarks"); sb.Append(" where Id=@Id"); DbCommand dbCommand = db.GetSqlStringCommand(sb.ToString()); db.AddInParameter(dbCommand, "@Id", DbType.Int32, model.Id); db.AddInParameter(dbCommand, "@Account", DbType.String, model.Account); db.AddInParameter(dbCommand, "@Password", DbType.String, model.Password); db.AddInParameter(dbCommand, "@UserName", DbType.String, model.UserName); db.AddInParameter(dbCommand, "@NickName", DbType.String, model.NickName); db.AddInParameter(dbCommand, "@RoleId", DbType.Int32, model.RoleId); db.AddInParameter(dbCommand, "@Department", DbType.Int32, model.Department); db.AddInParameter(dbCommand, "@IsEnable", DbType.Boolean, model.IsEnable); db.AddInParameter(dbCommand, "@IsCanDelete", DbType.Boolean, model.IsCanDelete); db.AddInParameter(dbCommand, "@CreateIP", DbType.String, model.CreateIP); db.AddInParameter(dbCommand, "@CreateDate", DbType.DateTime, model.CreateDate); db.AddInParameter(dbCommand, "@Remarks", DbType.String, model.Remarks); return(db.ExecuteNonQuery(dbCommand) < 1 ? false : true); }
private SystemAccountInfo FillList(IDataReader dataReader) { SystemAccountInfo model = new SystemAccountInfo(); object ojb; ojb = dataReader["Id"]; if (ojb != null && ojb != DBNull.Value) { model.Id = (int)(ojb); } ojb = dataReader["Account"]; if (ojb != null && ojb != DBNull.Value) { model.Account = (string)(ojb); } ojb = dataReader["Password"]; if (ojb != null && ojb != DBNull.Value) { model.Password = (string)(ojb); } ojb = dataReader["UserName"]; if (ojb != null && ojb != DBNull.Value) { model.UserName = (string)(ojb); } ojb = dataReader["NickName"]; if (ojb != null && ojb != DBNull.Value) { model.NickName = (string)(ojb); } ojb = dataReader["RoleId"]; if (ojb != null && ojb != DBNull.Value) { model.RoleId = (int)(ojb); } ojb = dataReader["Department"]; if (ojb != null && ojb != DBNull.Value) { model.Department = (int)(ojb); } ojb = dataReader["IsEnable"]; if (ojb != null && ojb != DBNull.Value) { model.IsEnable = (bool)(ojb); } ojb = dataReader["IsCanDelete"]; if (ojb != null && ojb != DBNull.Value) { model.IsCanDelete = (bool)(ojb); } ojb = dataReader["CreateIP"]; if (ojb != null && ojb != DBNull.Value) { model.CreateIP = (string)(ojb); } ojb = dataReader["CreateDate"]; if (ojb != null && ojb != DBNull.Value) { model.CreateDate = (DateTime)(ojb); } ojb = dataReader["Remarks"]; if (ojb != null && ojb != DBNull.Value) { model.Remarks = (string)(ojb); } return(model); }
public bool Delete(SystemAccountInfo model) { return(dal.Delete(model)); }
public bool Update(SystemAccountInfo model) { return(dal.Update(model)); }
public int Create(SystemAccountInfo model) { int id = dal.Create(model); return(id); }