public ActionResult UserEdit() { int UserSysNo = 0; int.TryParse(Request["UserSysNo"], out UserSysNo); UserEdit_Model model = new UserEdit_Model(); if (UserSysNo != 0) { model.UserInfo = user_service.LoadSystemUser(UserSysNo); model.UserRoles = role_service.GetAllRolesByUserSysNo(UserSysNo); } else { model.UserInfo.CommonStatus = CommonStatus.Actived; } model.allApps = AuthServiceLocal.LoadAllSystemApplication(); return(View(model)); }
/// <summary> /// 设为管理员 (注释掉) /// </summary> /// <param name="user"></param> /// <returns></returns> //public ActionResult SetAdmin(int usersysno, int companysysno) //{ // AjaxResult result = new AjaxResult(); // if (usersysno <= 0 || companysysno <= 0) // { // throw new BusinessException("请选择正确的数据"); // } // if (CurrUser.MasterSysNo.GetValueOrDefault() > 0) // { // companysysno = CurrUser.MasterSysNo.Value; // } // var company = CompanyService.LoadCompany(companysysno); // if (company == null) // { // throw new BusinessException("未找到当前公司的相关信息"); // } // var user = user_service.LoadSystemUser(usersysno); // if (user == null) // { // throw new BusinessException("未找到当前用户的相关信息"); // } // if (CurrUser.MasterSysNo.GetValueOrDefault() > 0 && user.MasterSysNo.Value != CurrUser.MasterSysNo.Value) // { // throw new BusinessException("未找到当前用户的相关信息"); // } // if (user.CommonStatus == CommonStatus.DeActived) // { // throw new BusinessException("当前账号已被禁用,不能设为管理员"); // } // company.AccountSysNo = usersysno; // company.EditUserSysNo = CurrUser.UserSysNo; // company.EditUserName = CurrUser.UserDisplayName; // CompanyService.UpdateCompany(company); // result.Success = true; // return Json(result); //} public ActionResult SaveSystemUser(SystemUser user) { AjaxResult result = new AjaxResult(); if (user == null || string.IsNullOrEmpty(user.LoginName)) { throw new BusinessException("请输入正确的数据"); } if (user.SysNo == 0) { if (string.IsNullOrEmpty(user.LoginPassword)) { user.LoginPassword = AuthMgr.EncryptPassword(user.LoginName); } else { user.LoginPassword = AuthMgr.EncryptPassword(user.LoginPassword); } user.CellPhone = user.LoginName; SetEntityBaseUserInfo(user); if (CurrUser.MasterSysNo.GetValueOrDefault() > 0) { user.MasterSysNo = CurrUser.MasterSysNo.Value; } var usersysno = user_service.InsertSystemUser(user); if (usersysno > 0) { if (rolesysno != 0) { List <Role> roles = new List <Role> { new Role { SysNo = rolesysno } }; usersrole.SaveUsersRole(usersysno, roles, ConstValue.ApplicationID); } result.Data = usersysno; result.Success = true; return(Json(result)); } } else { var userr = user_service.LoadSystemUser(user.SysNo); if (userr == null) { throw new BusinessException("未找到当前用户的相关信息"); } if (CurrUser.MasterSysNo.GetValueOrDefault() > 0 && CurrUser.MasterSysNo.Value != userr.MasterSysNo) { throw new BusinessException("未找到当前用户的相关信息"); } userr.UserFullName = user.UserFullName; userr.CommonStatus = user.CommonStatus; userr.EditUserSysNo = CurrUser.UserSysNo; userr.EditUserName = CurrUser.UserDisplayName; user.EditDate = DateTime.Now; user_service.UpdateSystemUser(userr); if (rolesysno > 0) { var roles = usersrole.GetAllRolesByUserSysNo(userr.SysNo); var role = roles.Find(e => e.SysNo == rolesysno); if (role == null) { roles.Add(new Role { SysNo = rolesysno }); } usersrole.SaveUsersRole(userr.SysNo, roles, ConstValue.ApplicationID); } result.Data = userr.SysNo; result.Success = true; return(Json(result)); } result.Success = false; result.Message = "数据错误,请刷新后重试!"; return(Json(result)); }
public ActionResult AddSmokeDetector(SmokeDetector entity) { long deviceCode = 0; long.TryParse(entity.Code, out deviceCode); if (deviceCode <= 0) { return(Json(new AjaxResult() { Success = false, Message = "请扫描正确的设备二维码。" })); } //if (curentUser.UserType != UserType.Installer) //{ // return Json(new AjaxResult() { Success = false, Message = "您不是管理员,请绑定管理员账号。" }); //} //if ((entity.AddressSysNo == null || entity.AddressSysNo <= 0) && (entity.Memo == "" || entity.Memo == null)) //{ // return Json(new AjaxResult() { Success = false, Message = "请选择详细地址或者填写备注。" }); //} if ((!entity.AddressSysNo.HasValue || entity.AddressSysNo <= 0) && string.IsNullOrWhiteSpace(entity.Position)) { return(Json(new AjaxResult() { Success = false, Message = "请选择地址或填写设备具体位置。" })); } Address address = AddressDA.LoadAddress(entity.AddressSysNo.GetValueOrDefault()); if (address == null) { return(Json(new AjaxResult() { Success = false, Message = "位置信息错误,请重新选择后再试。" })); } entity.AddressCode = address.Code; entity.AddressName = address.PathName; if ((address.ParentSysNo == 0 || address.ParentSysNo == null) && (address.PathName == "" || address.PathName == null)) { entity.AddressName = address.Name; } entity.Status = SmokeDetectorStatus.Offline; if (curentUser.UserType == UserType.Installer) { entity.InstallerSysNo = curentUser.ManagerSysNo; } else { entity.InstallerSysNo = -curentUser.UserSysNo; } entity.InstallerName = HttpUtility.UrlDecode(curentUser.UserID); entity.InUserSysNo = curentUser.UserSysNo; entity.InUserName = HttpUtility.UrlDecode(curentUser.UserID); SmokeDetector smoke = SmokeDetectorServices.IsUniquenessCode(entity.Code); SystemUserService service = new SystemUserService(); SystemUser systemuser = service.LoadSystemUser(curentUser.ManagerSysNo.GetValueOrDefault(), ConstValue.ApplicationID); if (systemuser == null) { UserMgr.Logout(); return(Json(new AjaxResult() { Success = false, Message = "登录超时,请退出公众号重新进入。" })); } //if (smoke != null && smoke.CompanySysNo != systemuser.MasterSysNo) //{ // return Json(new AjaxResult() { Success = false, Message = "设备已安装,不能再安装。" }); //} //else if (smoke != null) { if (smoke.Status == SmokeDetectorStatus.Delete) { entity.Status = SmokeDetectorStatus.Offline; } else { entity.Status = smoke.Status; if (smoke.InstallerSysNo <= 0) { if (smoke.InstallerSysNo != -curentUser.UserSysNo) { return(Json(new AjaxResult() { Success = false, Message = "设备已安装,不能再安装。" })); } } else { if (!(smoke.CompanySysNo == systemuser.MasterSysNo && curentUser.UserType == UserType.Installer)) { return(Json(new AjaxResult() { Success = false, Message = "设备已安装,不能再安装。" })); } } }; CreateDeviceRequest reques = new CreateDeviceRequest() { IMei = entity.Code, IMsi = entity.Code, Desc = "测试设备", IsOnLine = 1, Observe = 1, Protocol = "LWM2M", Title = entity.Code, Tags = entity.Code + "," + entity.Code }; CreateDeviceResponse result = ONENETService.CreateDevice(reques); if (result.IsSuccess) { entity.DeviceId = result.DeviceId; } else { entity.DeviceId = smoke.DeviceId; } entity.SysNo = smoke.SysNo; SmokeDetectorServices.UpdateSmokeDetector(entity); if (curentUser.UserType != UserType.Installer) { Logger.WriteLog("Code:" + entity.Code); BindingDevicesApi(entity.Code); } return(Json(new AjaxResult() { Success = true, Message = "修改成功!" })); //} //else //{ // return Json(new AjaxResult() { Success = false, Message = "系统异常!" }); //} } else { CreateDeviceRequest reques = new CreateDeviceRequest() { IMei = entity.Code, IMsi = entity.Code, Desc = "测试设备", IsOnLine = 1, Observe = 1, Protocol = "LWM2M", Title = entity.Code, Tags = entity.Code + "," + entity.Code }; CreateDeviceResponse result = ONENETService.CreateDevice(reques); if (result.IsSuccess) { entity.DeviceId = result.DeviceId; } int i = SmokeDetectorServices.InsertSmokeDetector(entity); SmokeDetectorStatusLog statusLog = new SmokeDetectorStatusLog() { Status = entity.Status, BeginTime = DateTimeHelper.GetTimeZoneNow(), ReceivedJsonData = "", SmokeDetectorCode = entity.Code }; if (curentUser.UserType != UserType.Installer) { Logger.WriteLog("Code:" + entity.Code); BindingDevicesApi(entity.Code); } return(Json(new AjaxResult() { Success = true, Message = "添加成功!" })); } }
public ActionResult AddDevices() { Client user = ClientService.LoadClient(curentUser.UserSysNo); UIAddDetectorModel model = new UIAddDetectorModel(); model.CompanyList = new List <Company>(); model.List = new List <AddDetectorModel>(); if (user == null) { UserMgr.Logout(); throw new BusinessException("登录超时,请退出公众号重新进入。"); } if (user != null && user.ManagerSysNo > 0 && curentUser.UserType == UserType.Installer) { //model.CompanyList = AddressService.LoadInstallerCompany(user.ManagerSysNo.GetValueOrDefault()); SystemUserService service = new SystemUserService(); SystemUser systemuser = service.LoadSystemUser(curentUser.ManagerSysNo.GetValueOrDefault(), ConstValue.ApplicationID); if (systemuser != null && systemuser.MasterSysNo > 0) { model.CompanyList.Add(new Company() { SysNo = systemuser.MasterSysNo.GetValueOrDefault() }); } SmokeDetector info = SmokeDetectorServices.LoadSmokeDetectorByInstaller(curentUser.ManagerSysNo.GetValueOrDefault()); if (info != null && !string.IsNullOrWhiteSpace(info.AddressCode)) { List <Address> list = AddressService.LoadAddressByAddressCode(info.AddressCode, info.CompanySysNo); string code = info.AddressCode; List <AddDetectorModel> modelList = new List <AddDetectorModel>(); string scode = code; for (var i = code.Length - 2; i >= 2; i = i - 2) { AddDetectorModel item = new AddDetectorModel(); string ncode = code.Substring(0, i); List <Address> list1 = list.Where(x => x.Code.StartsWith(ncode) && x.Code.Length == i + 2).ToList(); item.ItemList = list1; item.SelectCode = scode; scode = ncode; modelList.Add(item); if (ncode.Length == 2) { List <Address> list2 = list.Where(x => x.Code == ncode).ToList(); model.FirstAddress = list2[0]; } } if (code.Length == 2) { model.FirstAddress = list[0]; } modelList.Reverse(); model.List = modelList; model.SelectCompany = info.CompanySysNo; } } else { string sysNo = ConfigurationManager.AppSettings["DummyCompanySysNo"]; int conpanySysNo = 1; int.TryParse(sysNo, out conpanySysNo); model.CompanyList.Add(new Company() { SysNo = conpanySysNo }); } return(View(model)); }