/// <summary> /// 设定群组对应的用户 /// </summary> /// <param name="groupID"></param> /// <param name="empIDList"></param> public static void SetGroupUsers(string groupID, List <string> empIDList) { SqlConnection conn = new SqlConnection(Config.ConnectionString); try { conn.Open(); SqlTransaction trans = conn.BeginTransaction(); try { SqlHelper.DeleteTable <SysGroupUser>(trans, ColumnFilterList.New("group_id", groupID)); //insert group_users foreach (string empID in empIDList) { SysGroupUser entity = new SysGroupUser(groupID, empID); SqlHelper.Insert(trans, entity); } trans.Commit(); } catch (Exception ex) { trans.Rollback(); throw ex; } } finally { conn.Close(); } }
public ActionResult SaveGroupUser(int groupId, string user) { try { string[] listUserId = user.Split(','); if (listUserId.Length > 0) { for (int i = 0; i < listUserId.Length; i++) { var model = new SysGroupUser(); model.CreatedBy = WebSecurity.CurrentUserId; model.CreatedDate = DateTime.Now; model.GroupId = groupId; model.Orders = 2; model.UserId = CommonHelper.Convert.ConvertToInt32(listUserId[i]); model.UsedState = Ultity.Constant.Active; _sysGroupUserAction.Add(model); } } return(Json(new { status = "success", Message = Ultity.Constant.Ajax_Success, Data = string.Empty })); } catch (Exception exception) { Ultity.TFunction.WriteToLog(exception); return(Json(new { status = "fail", Message = Ultity.Constant.Ajax_Fail })); } }
public string RemoveUser(string OrgID, string Ids) { if (string.IsNullOrEmpty(OrgID)) { return("0"); } string[] idList = JsonConvert.DeserializeObject <string[]>(Ids); if (idList != null && idList.Length > 0) { SysGroupUser.DoBatchDelete(OrgID, idList);//* OrgID:组织结构ID } return("1"); }
public int Update(SysGroupUser sysGroupUser) { return ((int) SqlHelper.ExecuteScalar( SqlConnection, CommonHelper.Config.GetFullyQualifiedName("SysGroupUser_Update"), sysGroupUser.Id, sysGroupUser.GroupId, sysGroupUser.UserId, sysGroupUser.Orders, sysGroupUser.UsedState, CommonHelper.Null.GetNull(sysGroupUser.CreatedDate), CommonHelper.Null.GetNull(sysGroupUser.CreatedBy), sysGroupUser.ModifiedDate, sysGroupUser.ModifiedBy)); }
public int Add(SysGroupUser sysGroupUser) { var deciResult = (decimal) SqlHelper.ExecuteScalar(SqlConnection, CommonHelper.Config.GetFullyQualifiedName("SysGroupUser_Insert"), sysGroupUser.GroupId, sysGroupUser.UserId, sysGroupUser.Orders, sysGroupUser.UsedState, sysGroupUser.CreatedDate, sysGroupUser.CreatedBy, CommonHelper.Null.GetNull(sysGroupUser.ModifiedDate), CommonHelper.Null.GetNull(sysGroupUser.ModifiedBy)); return(CommonHelper.Convert.ConvertToInt32(deciResult)); }
protected void RefreshData(object sender, StoreReadDataEventArgs e) { int start = e.Start; int pageSize = e.Limit; int total = 0; //查询条件 string Where = " 1=1 "; string Name = Request["UserQuery"] + ""; Name = Name.Replace("输入姓名简拼", ""); if (!string.IsNullOrEmpty(Name)) { Where += " and SysUserName like '%" + Name + "%' or (" + GetPinyinWhereString("SysUserName", Name) + ") "; } if (e.Parameters.GetParameter("PID") != null) { var PID = e.Parameters.GetParameter("PID").Value; if (PID == "root") { } else { Where += " and SysGroupID='" + PID + "' "; SysGroupUser[] SysOUserEnt = DataHelper.GetPageList <SysGroupUser>(start, pageSize, new Order[] { new Order("CreateTime", false) }, out total, Expression.Sql(Where)); e.Total = total; IList <SysUser> UserList = SysGroupUser.GetUsersByEnts(SysOUserEnt); foreach (var item in SysOUserEnt) { var ent = UserList.Where(ten => ten.ID == item.SysUserID).First(); if (ent != null) { UserList.Add(ent); } } UserStore.Data = UserList; UserStore.DataBind(); return; } } //默认情况 SysUser[] Arr = DataHelper.GetPageList <SysUser>(start, pageSize, new Order[] { new Order("CreateTime", false) }, out total, Expression.Sql(Where)); e.Total = total; UserStore.Data = Arr; UserStore.DataBind(); }
public string RefUserToOrg(string Json, string PID) { var OrgEnt = SysGroupOrRole.Find(PID); var Ents = JSON.Deserialize <SysUser[]>(Json); foreach (var item in Ents) { //去除重复 int a = SysGroupUser.GetCount(Expression.Sql("SysUserID='" + item.ID + "' and SysGroupID='" + OrgEnt.ID + "'")); if (a > 0) { continue; } SysGroupUser OrgUsr = new SysGroupUser(); OrgUsr.SysGroupID = OrgEnt.ID; OrgUsr.SysGroupName = OrgEnt.GroupName; OrgUsr.SysUserID = item.ID; OrgUsr.SysUserName = item.Name; OrgUsr.DoCreate(); } return("1"); }
public string DeleteData(string ID) { var Ent = SysGroupOrRole.Find(ID); //删除相关联的数据 var GUEnts = SysGroupUser.FindAllByProperties(SysGroupUser.Prop_SysGroupID, Ent.ID); var OrgEnts = SysOrgRefGroupOrRole.FindAllByProperty(SysOrgRefGroupOrRole.Prop_GroupOrRoleID, Ent.ID); if (GUEnts.Length > 0) { foreach (var item in GUEnts) { item.DoDelete(); } } if (OrgEnts.Length > 0) { foreach (var item in OrgEnts) { item.DoDelete(); } } Ent.DoDelete(); return("1"); }
public ActionResult AddTeacher(SysUser sysModel) { if (sysModel.Id == 0) { sysModel.UserName = sysModel.UserName.Trim(); sysModel.FullName = string.IsNullOrEmpty(sysModel.FullName) ? string.Empty : sysModel.FullName.Trim(); if (!WebSecurity.UserExists(sysModel.UserName)) { try { //Create User Membership if (AuthorizeUser.IsAction(Ultity.Constant.Add) || AuthorizeUser.IsAction(Ultity.Constant.ViewEditAll)) { WebSecurity.CreateUserAndAccount(sysModel.UserName.Trim(), sysModel.Password.Trim()); //Get UserByName int userId = WebSecurity.GetUserId(sysModel.UserName); if (userId > 0) { //Create CoreSys User try { #region + Thêm vào bảng SysUser var model = new SysUser(); model.Id = userId; model.UserId = userId; model.CreatedBy = WebSecurity.CurrentUserId; model.FullName = sysModel.FullName.Trim(); model.UserName = sysModel.UserName.Trim(); model.Email = sysModel.Email; model.ImageUrl = sysModel.ImageUrl; model.Phone = sysModel.Phone; model.Summary = sysModel.Summary; model.Host = sysModel.Host; model.Gender = sysModel.Gender; model.BCoin = 0; model.UsedState = sysModel.UsedState; model.CreatedDate = DateTime.Now; _sysAction.Insert(model); #endregion #region +Thêm vào nhóm Giáo viên var sysGroupUser = new SysGroupUser(); sysGroupUser.CreatedBy = WebSecurity.CurrentUserId; sysGroupUser.CreatedDate = DateTime.Now; sysGroupUser.GroupId = 20; sysGroupUser.Orders = 2; sysGroupUser.UserId = userId; sysGroupUser.UsedState = Ultity.Constant.Active; new SysGroupUserAction().Add(sysGroupUser); #endregion } catch (Exception exception) { ((SimpleMembershipProvider)Membership.Provider).DeleteUser(sysModel.UserName.Trim(), true); new SysAdminAction <SysUser>().Deletes("UserId=" + userId); } } return(Json(new { status = "success" })); } return(Json(new { status = "error", Message = "Đã tồn tại Username này trong hệ thống !" })); } catch (Exception exception) { Ultity.TFunction.WriteToLog(exception); return(Json(new { status = "error", Message = "Đã tồn tại Username này trong hệ thống !" })); } } else { return(Json(new { status = "exits", Message = "Đã tồn tại Username này trong hệ thống !" })); } } else { //Get User By Id SysUser item = _sysAction.GetById(sysModel.Id); if (item != null) { if (!string.IsNullOrEmpty(sysModel.Password)) { var token = WebSecurity.GeneratePasswordResetToken(sysModel.UserName); // link directed to an action with form to capture password WebSecurity.ResetPassword(token, sysModel.Password); } if (AuthorizeUser.IsAction(Ultity.Constant.Edit) || AuthorizeUser.IsAction(Ultity.Constant.ViewEditAll)) { item.ModifiedBy = WebSecurity.CurrentUserId; item.FullName = sysModel.FullName.Trim(); item.Email = sysModel.Email; item.Phone = sysModel.Phone; item.Host = sysModel.Host; item.BCoin = sysModel.BCoin; item.Gender = sysModel.Gender; item.Summary = sysModel.Summary; item.ImageUrl = sysModel.ImageUrl; item.UsedState = sysModel.UsedState; item.ModifiedDate = DateTime.Now; item.CreatedDate = DateTime.Now; _sysAction.Update(item); } } } return(Json(new { status = "success", Message = Ultity.Constant.Ajax_Fail })); }
public void Update(string BranchID,int GroupID,string UserID) { SysGroupUser item = new SysGroupUser(); item.MarkOld(); item.IsLoaded = true; item.BranchID = BranchID; item.GroupID = GroupID; item.UserID = UserID; item.Save(UserName); }
public void Insert(string BranchID,int GroupID,string UserID) { SysGroupUser item = new SysGroupUser(); item.BranchID = BranchID; item.GroupID = GroupID; item.UserID = UserID; item.Save(UserName); }