protected void LoadUserGroup(int siteId) { var cUserGroup = new CUserGroup(); RadComboBoxUserGroup.Text = string.Empty; RadComboBoxUserGroup.DataSource = cUserGroup.GetUserGroupList(siteId); RadComboBoxUserGroup.DataTextField = "Name"; RadComboBoxUserGroup.DataValueField = "Value"; RadComboBoxUserGroup.DataBind(); }
// POST api/usergroupapi public CUserGroup Post(CUserGroup value) { var user = (CSign)HttpContext.Current.Session[ConfigurationManager.AppSettings["AuthSaveKey"]]; if (user == null) { throw new HttpResponseException(new SiginFailureMessage()); } using (var dal = DalBuilder.CreateDal(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString, 0)) { bool ok; try { dal.Open(); ok = UserGroupBll.Create(dal, value, string.Format("{0}-{1}", user.UserCode, user.UserName)); } catch (Exception ex) { if (ex.Message.StartsWith("违反了 UNIQUE KEY 约束")) { throw new HttpResponseException(new PrimaryRepeatedMessge()); } LogBll.Write(dal, new CLog { LogUser = string.Format("{0}-{1}", user.UserCode, user.UserName), LogContent = string.Format("{0}#{1}", "UserGroup.Post", ex.Message), LogType = LogType.系统异常 }); throw new HttpResponseException(new SystemExceptionMessage()); } if (!ok) { LogBll.Write(dal, new CLog { LogUser = string.Format("{0}-{1}", user.UserCode, user.UserName), LogContent = string.Format("新建用户组{0}-{1}", value.GroupCode, value.GroupName), LogType = LogType.操作失败 }); throw new HttpResponseException(new DealFailureMessage()); } LogBll.Write(dal, new CLog { LogUser = string.Format("{0}-{1}", user.UserCode, user.UserName), LogContent = string.Format("新建用户组{0}-{1}", value.GroupCode, value.GroupName), LogType = LogType.操作成功 }); dal.Close(); return(value); } }
/// <summary> /// 删除用户组 /// </summary> /// <param name="dal"></param> /// <param name="id"></param> /// <param name="hisUserGroup"></param> /// <returns></returns> public static bool Delete(IDal dal, int id, out CUserGroup hisUserGroup) { int i; hisUserGroup = Get(dal, id); if (hisUserGroup == null) { return(false); } dal.BeginTran(); dal.Execute("UPDATE tUser SET GroupCode=null WHERE GroupCode=@GroupCode", out i, dal.CreateParameter("@GroupCode", hisUserGroup.GroupCode)); dal.Execute("DELETE FROM tUserGroupFun WHERE GroupCode=@GroupCode", out i, dal.CreateParameter("@GroupCode", hisUserGroup.GroupCode)); dal.Execute("DELETE FROM tUserGroup WHERE Id=@Id", out i, dal.CreateParameter("@Id", id)); dal.CommitTran(); return(true); }
/// <summary> /// 新建用户组 /// </summary> /// <param name="dal"></param> /// <param name="userGroup"></param> /// <param name="user"></param> /// <returns></returns> public static bool Create(IDal dal, CUserGroup userGroup, string user) { int i; dal.BeginTran(); dal.Execute( "INSERT INTO tUserGroup( GroupCode ,GroupName ,BuildUser ,EditUser,GroupType) VALUES ( @GroupCode , @GroupName,@BuildUser,@EditUser,@GroupType)", out i, dal.CreateParameter("@GroupCode", userGroup.GroupCode.Trim()), dal.CreateParameter("@GroupName", userGroup.GroupName.Trim()), dal.CreateParameter("@GroupType", (short)(userGroup.GroupType)), dal.CreateParameter("@BuildUser", user), dal.CreateParameter("@EditUser", user) ); if (i == 0) { return(false); } var dt = dal.Select("SELECT Id FROM tUserGroup WHERE GroupCode =@GroupCode", out i, dal.CreateParameter("@GroupCode", userGroup.GroupCode)); if (i == 0) { return(false); } userGroup.Id = Convert.ToInt16(dt.Rows[0]["Id"]); foreach (var fun in userGroup.GroupFun) { fun.GroupCode = userGroup.GroupCode; UserGroupFunBll.Create(dal, fun, user); } dal.CommitTran(); userGroup.Fun = UserGroupFunBll.CountGroupFun(dal, userGroup.GroupCode); userGroup.People = UserBll.CountPeople(dal, userGroup.GroupCode); return(true); }
/// <summary> /// 修改用户组 /// </summary> /// <param name="dal"></param> /// <param name="userGroup"></param> /// <param name="user"></param> /// <returns></returns> public static bool Update(IDal dal, CUserGroup userGroup, string user) { int i; dal.BeginTran(); dal.Execute("UPDATE tUserGroup SET GroupName=@GroupName,EditUser=@EditUser,EditDate=GETDATE(),GroupType=@GroupType WHERE Id=@Id", out i, dal.CreateParameter("@GroupName", userGroup.GroupName.Trim()), dal.CreateParameter("@EditUser", user), dal.CreateParameter("@Id", userGroup.Id), dal.CreateParameter("@GroupType", userGroup.GroupType)); if (i == 0) { return(false); } foreach (var fun in userGroup.GroupFun) { UserGroupFunBll.Update(dal, fun, user); } dal.CommitTran(); userGroup.Fun = UserGroupFunBll.CountGroupFun(dal, userGroup.GroupCode); userGroup.People = UserBll.CountPeople(dal, userGroup.GroupCode); return(true); }
protected void Page_Load(object sender, EventArgs e) { //http://localhost:12358/TF_WebH5/login.aspx?rUser=d3lz&rPwd=d3lz if (Request.Cookies["m_username"] != null) { sUserName = Request.Cookies["m_username"].Value; sUserName = System.Web.HttpUtility.UrlDecode(sUserName); } try { string sLoginType = "1"; if (Request.Cookies["m_logintype"] != null) { sLoginType = Request.Cookies["m_logintype"].Value; } object sUserID = Session["m_userid"]; if (sUserID == null) { Response.Write(BllCommon.Transferlocation()); return; } if (!IsPostBack) { //获取车组 if (sLoginType == "1") { DataSet ds = BllVehicle.GetVehGroupFromLogin(Convert.ToInt32(sUserID)); List <CVehGroup> lstVehGroup = new List <CVehGroup>(); Hashtable htGroupPID = new Hashtable(); Hashtable htGroupID = new Hashtable(); if (ds != null && ds.Tables.Count > 0) { foreach (DataRow dr in ds.Tables[0].Rows) { string id = "G" + dr["VehGroupID"]; string PID = "G" + dr["fVehGroupID"]; if (!htGroupPID.ContainsKey(PID)) { htGroupPID.Add(PID, id); } if (!htGroupID.ContainsKey(id)) { htGroupID.Add(id, PID); } } foreach (DataRow dr in ds.Tables[0].Rows) { CVehGroup vehGroup = new CVehGroup(); vehGroup.id = "G" + dr["VehGroupID"]; vehGroup.name = dr["VehGroupName"].ToString(); vehGroup.PID = "G" + dr["fVehGroupID"]; vehGroup.HasChild = 0; vehGroup.Root = 0; if (htGroupPID.ContainsKey(vehGroup.id)) { vehGroup.HasChild = 1; } if (!htGroupID.ContainsKey(vehGroup.PID)) { vehGroup.Root = 1; } lstVehGroup.Add(vehGroup); } } string json5 = JsonHelper.SerializeObject(lstVehGroup); sVehGroup = json5; //获取用户信息 int iGroupID = -1; DataSet dsUserGroup = BllVehicle.GetUserGroupFromLogin(Convert.ToInt32(sUserID)); if (dsUserGroup == null || dsUserGroup.Tables.Count == 0 || dsUserGroup.Tables[0].Rows.Count == 0) { CUserGroup cModel = new CUserGroup(); cModel.HasChild = 0; cModel.id = "U_User"; cModel.name = "用户管理"; cModel.PID = ""; cModel.Root = 1; List <CUserGroup> lstUserGroup = new List <CUserGroup>(); lstUserGroup.Add(cModel); string jsonUserGroup = JsonHelper.SerializeObject(lstUserGroup); sUserGroup = jsonUserGroup; } else { List <CUserGroup> lstUserGroup = new List <CUserGroup>(); CUserGroup cModel = new CUserGroup(); cModel.HasChild = 0; cModel.id = "M_User"; cModel.name = "用户管理"; cModel.PID = ""; cModel.Root = 1; lstUserGroup.Add(cModel); foreach (DataRow dr in dsUserGroup.Tables[0].Rows) { cModel = new CUserGroup(); cModel.HasChild = 0; iGroupID = Convert.ToInt32(dr["UserGroupID"]); cModel.id = "U" + dr["UserGroupID"].ToString(); cModel.name = dr["UserGroupName"].ToString(); cModel.PID = "M_User"; cModel.Root = 1; lstUserGroup.Add(cModel); } string jsonUserGroup = JsonHelper.SerializeObject(lstUserGroup); sUserGroup = jsonUserGroup; } //获取用户 DataSet dsUser = BllVehicle.GetUserFromLogin(Convert.ToInt32(sUserID), iGroupID); if (dsUser == null || dsUser.Tables.Count == 0 || dsUser.Tables[0].Rows.Count == 0) { List <CUser> lstUser = new List <CUser>(); string jsonUser = JsonHelper.SerializeObject(lstUser); sUser = jsonUser; } else { List <CUser> lstUser = new List <CUser>(); foreach (DataRow dr in dsUser.Tables[0].Rows) { if (sUserID.Equals(dr["UserID"].ToString())) { sUserType = dr["UserTypeID"].ToString(); break; } } foreach (DataRow dr in dsUser.Tables[0].Rows) { if (sUserType == "1" || sUserID.Equals(dr["UserID"].ToString())) { CUser cModel = new CUser(); cModel.HasChild = 0; cModel.id = "R" + dr["UserID"].ToString(); cModel.name = dr["UserName"].ToString(); cModel.PID = "U" + dr["UserGroupID"].ToString(); lstUser.Add(cModel); } } string jsonUser = JsonHelper.SerializeObject(lstUser); sUser = jsonUser; } } else { List <CVehGroup> lstVehGroup = new List <CVehGroup>(); CVehGroup vehGroup = new CVehGroup(); vehGroup.id = "G0"; vehGroup.name = "我的车辆"; vehGroup.PID = "G-1"; vehGroup.HasChild = 0; vehGroup.Root = 1; lstVehGroup.Add(vehGroup); string json5 = JsonHelper.SerializeObject(lstVehGroup); sVehGroup = json5; } } } catch (Exception Exception) { } }