public ActionResult GetCustomItemValues(string datacode) { AjaxResult ar = new Globals.AjaxResult(); if (datacode == string.Empty) { ar.state = ResultType.error.ToString(); ar.message = "提交的数据为空,获取自定义项失败"; return(Json(ar, JsonRequestBehavior.AllowGet)); } try { // 获取当前登录的用户 var currentUser = LoginManager.GetCurrentUser(); List <CustomItemValue> itemvalueList = new List <CustomItemValue>(); // 根据datacode获取到相应的数据 var infor = _informationBLL.GetInformation(datacode); // 获取自定义值列表 var state = _customItemValueBLL.GetCustomItemValueByMember(currentUser.Account, infor.Id, ref itemvalueList); if (state == OperatorState.empty) { ar.state = ResultType.error.ToString(); ar.message = "无法获取到当前用户信息,获取数据失败"; } else if (state == OperatorState.error) { ar.state = ResultType.error.ToString(); ar.message = "获取数据失败"; } else if (state == OperatorState.success) { List <CustomItemModel> cmList = ModelChangeManager.ChangeTOCustomItemModel(itemvalueList); ar.state = ResultType.success.ToString(); ar.data = cmList.ToJson(); } } catch (Exception ex) { LogHelper.writeLog_error(ex.Message); LogHelper.writeLog_error(ex.StackTrace); ar.state = ResultType.error.ToString(); ar.message = "系统错误,获取数据失败"; } return(Json(ar, JsonRequestBehavior.AllowGet)); }
public ActionResult DeleteMember(string Account) { AjaxResult ar = new Globals.AjaxResult(); if (Account == string.Empty || Account == null) { ar.state = ResultType.error.ToString(); ar.message = "提交的賬號爲空"; return(Json(ar, JsonRequestBehavior.AllowGet)); } try { var member = _memberBLL.GetUserByAccount(Account); if (member == null) { ar.state = ResultType.error.ToString(); ar.message = "要刪除的賬戶不存在"; return(Json(ar, JsonRequestBehavior.AllowGet)); } OperatorState result = _memberBLL.DeleteMember(member); if (result == OperatorState.error) { ar.state = ResultType.error.ToString(); ar.message = "刪除賬號失敗"; } else if (result == OperatorState.success) { ar.state = ResultType.success.ToString(); ar.message = "刪除賬號成功"; _underlingManager.SubUnderlingList(member); } } catch (Exception ex) { LogHelper.writeLog_error(ex.Message); LogHelper.writeLog_error(ex.StackTrace); ar.state = ResultType.error; ar.message = "系統錯誤,刪除賬號失敗"; } return(Json(ar, JsonRequestBehavior.AllowGet)); }
public ActionResult ResetPassword(PasswordModel model) { AjaxResult ar = new Globals.AjaxResult(); var currentUser = LoginManager.GetCurrentUser(); if (model == null) { ar.state = ResultType.error.ToString(); ar.message = "提交的数据为空,修改密码失败"; return(Json(ar, JsonRequestBehavior.AllowGet)); } if (string.IsNullOrEmpty(model.NewPassword)) { ar.state = ResultType.error.ToString(); ar.message = "新密码不能为空"; } else if (currentUser.Password != EncryptManager.SHA1(model.OldPassword)) { ar.state = ResultType.error.ToString(); ar.message = "旧密码不匹配,修改密码失败"; } else { var nPwd = EncryptManager.SHA1(model.NewPassword); currentUser.Password = nPwd; var state = _memberBLL.ResetPassword(currentUser.Account, nPwd); if (state == OperatorState.empty) { ar.state = ResultType.error.ToString(); ar.message = "提交的数据为空,修改密码失败"; } else if (state == OperatorState.error) { ar.state = ResultType.error.ToString(); ar.message = "系统错误,修改密码失败"; } else if (state == OperatorState.success) { ar.state = ResultType.success.ToString(); ar.message = "修改成功"; } } return(Json(ar, JsonRequestBehavior.AllowGet)); }
public ActionResult AddCustomItems(string customItemName) { AjaxResult ar = new Globals.AjaxResult(); if (customItemName == string.Empty) { ar.state = ResultType.error.ToString(); ar.message = "提交的数据为空,添加自定义项失败"; return(Json(ar, JsonRequestBehavior.AllowGet)); } try { var currentUser = LoginManager.GetCurrentUser(); CustomItem ci = new CustomItem(); var state = _customItemBLL.AddCustomItems(currentUser.Account, customItemName, ref ci); if (state == OperatorState.repeat) { ar.state = ResultType.error.ToString(); ar.message = "所提交自定义项已存在,添加自定义项失败"; } else if (state == OperatorState.error) { ar.state = ResultType.error.ToString(); ar.message = "添加自定义项失败"; } else if (state == OperatorState.success) { ar.state = ResultType.success.ToString(); ar.data = ModelChangeManager.ChangeTOCustomItemModel(ci).ToJson(); ar.message = "添加自定义项成功"; } } catch (Exception ex) { LogHelper.writeLog_error(ex.Message); LogHelper.writeLog_error(ex.StackTrace); ar.state = ResultType.error.ToString(); ar.message = "系统错误,添加自定义项失败"; } return(Json(ar, JsonRequestBehavior.AllowGet)); }
public ActionResult UpdateCustomItems(string customItemName, string customItemContent) { AjaxResult ar = new Globals.AjaxResult(); if (customItemName == string.Empty || customItemContent == string.Empty) { ar.state = ResultType.error.ToString(); ar.message = "提交的数据为空, 修改自定义项失败"; return(Json(ar, JsonRequestBehavior.AllowGet)); } try { CustomItem customItem = new CustomItem(); var state = _customItemBLL.UpdateCustomItems(customItemName, customItemContent); if (state == OperatorState.empty) { ar.state = ResultType.error.ToString(); ar.message = "不能找到相应的自定义项,修改自定义项失败"; } else if (state == OperatorState.error) { ar.state = ResultType.error.ToString(); ar.message = "修改自定义项失败"; } else if (state == OperatorState.success) { ar.state = ResultType.success.ToString(); } } catch (Exception ex) { LogHelper.writeLog_error(ex.Message); LogHelper.writeLog_error(ex.StackTrace); ar.state = ResultType.error.ToString(); ar.message = "系统错误,修改自定义项失败"; } return(Json(ar, JsonRequestBehavior.AllowGet)); }
public ActionResult LoadEnableAssignData() { AjaxResult ar = new Globals.AjaxResult(); var currentUser = LoginManager.GetCurrentUser(); try { var currentUserData = new List <InformationModel>(); var collectorData = new List <InformationModel>(); var currentUserState = _informationBLL.GetInformation(currentUser.Account, InformatinState.UnAssigned, ref currentUserData); foreach (var item in _memberBLL.GetUsersByRole(RolesManager.GetRolesCode(RolesCode.Collector.ToString()), currentUser.CompanyCode)) { var temp = new List <InformationModel>(); var tempstate = _informationBLL.GetInformation(item.Account, InformatinState.UnAssigned, ref temp); collectorData.AddRange(temp); } currentUserData.AddRange(collectorData); if (currentUserData == null || currentUserData.Count <= 0) { ar.state = ResultType.error.ToString(); ar.message = "没有获取到可供分配的数据"; } else { ar.state = ResultType.success.ToString(); ar.data = currentUserData.ToJson(); } } catch (Exception ex) { LogHelper.writeLog_error(ex.Message); LogHelper.writeLog_error(ex.StackTrace); ar.state = ResultType.error.ToString(); ar.message = "系统错误,无法获取到数据"; } return(Json(ar, JsonRequestBehavior.AllowGet)); }
public ActionResult Assign(string Account, string[] DataCodeList) { AjaxResult ar = new Globals.AjaxResult(); if (Account == string.Empty) { ar.state = ResultType.error.ToString(); ar.message = "分配的用户为空,分配失败"; return(Json(ar, JsonRequestBehavior.AllowGet)); } if (DataCodeList == null || DataCodeList.Length <= 0) { ar.state = ResultType.error.ToString(); ar.message = "分配的数据为空,请选择要分配的数据"; return(Json(ar, JsonRequestBehavior.AllowGet)); } var member = _memberBLL.GetUserByAccount(Account); if (member == null) { ar.state = ResultType.error.ToString(); ar.message = "无法获取到相应的用户,分配失败"; return(Json(ar, JsonRequestBehavior.AllowGet)); } #region 分配数据 给指定 的 用户 using (var db = new DCSDBContext()) { using (var trans = db.Database.BeginTransaction()) { try { var count = 0; List <Information> inforList = new List <Information>(); foreach (var item in DataCodeList) { var temp = _informationBLL.GetInformation(item); if (temp != null) { count++; temp.UsageMember = Account; temp.State = (int)InformatinState.Assigned; inforList.Add(temp); } } foreach (var item in inforList) { db.Informations.Attach(item); db.Entry(item).State = System.Data.Entity.EntityState.Modified; } ///int count = db.Informations.Update(inforList.AsQueryable(), n => new Information { UsageMember = Account}); //更新 已分配数据的数量 member.Ascount += count; db.Members.Attach(member); db.Entry(member).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); trans.Commit(); // 更新下属名单 _underlingManager.UpdateUnderlingList(member); ar.state = ResultType.success.ToString(); ar.message = "分配成功"; } catch (Exception ex) { LogHelper.writeLog_error(ex.Message); LogHelper.writeLog_error(ex.StackTrace); trans.Rollback(); ar.state = ResultType.error.ToString(); ar.message = "分配失败"; } } } #endregion return(Json(ar, JsonRequestBehavior.AllowGet)); }
public ActionResult UpdateInformation(string datacode, Information InformationModel, List <FormModel> CustomItemModel) { AjaxResult ar = new Globals.AjaxResult(); if (datacode == string.Empty || InformationModel == null) { ar.state = ResultType.error.ToString(); ar.message = "提交的数据为空"; return(Json(ar, JsonRequestBehavior.AllowGet)); } var currentUser = LoginManager.GetCurrentUser(); using (var db = new DCSDBContext()) { using (var trans = db.Database.BeginTransaction()) { try { var item = db.Informations.SingleOrDefault(n => n.DataCode == datacode); item.Address = InformationModel.Address; item.Age = InformationModel.Age; item.Children = InformationModel.Children; item.CustomerName = InformationModel.CustomerName; item.Email = InformationModel.Email; item.HasCar = InformationModel.HasCar; item.HasHouse = InformationModel.HasHouse; item.Hobby = InformationModel.Hobby; item.Income = InformationModel.Income; item.Industry = InformationModel.Industry; item.InvestConc = InformationModel.InvestConc; item.InvestLife = InformationModel.InvestLife; item.InvestProj = InformationModel.InvestProj; item.IsMarry = InformationModel.IsMarry; item.Note1 = InformationModel.Note1; item.Note2 = InformationModel.Note2; item.Note3 = InformationModel.Note3; item.Occupation = InformationModel.Occupation; item.Phone = InformationModel.Phone; item.QQ = InformationModel.QQ; item.Sex = InformationModel.Sex; item.UpdateTime = DateTime.Now; item.WebCat = InformationModel.WebCat; //db.Informations.Attach(InformationModel); db.Entry(item).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); List <CustomItem> cmList = new List <CustomItem>(); _customItemBLL.GetCustomItems(currentUser.Account, ref cmList); foreach (var cmItem in cmList) { var customItemValue = _customItemValueBLL.GetCustomItemValueByCustomItemIdAndInforId(cmItem.Id, item.Id); var cm = CustomItemModel.Where(n => n.name == cmItem.ItemName).SingleOrDefault(); if (cm != null) { customItemValue.ItemValue = cm.value; customItemValue.ItemName = cmItem.ItemName; //db.CustomItemValues.Attach(customItemValue); db.Entry(customItemValue).State = System.Data.Entity.EntityState.Modified; } } db.SaveChanges(); trans.Commit(); ar.state = ResultType.success.ToString(); } catch (Exception ex) { trans.Rollback(); LogHelper.writeLog_error(ex.Message); LogHelper.writeLog_error(ex.StackTrace); ar.state = ResultType.error.ToString(); ar.message = "系统错误,修改数据失败"; } } } return(Json(ar, JsonRequestBehavior.AllowGet)); }
public ActionResult Search(bool OnlyKeyword, ConditionModal conditionModel, string keyword) { AjaxResult ar = new Globals.AjaxResult(); if (conditionModel == null) { ar.state = ResultType.error.ToString(); ar.message = "提交的数据为空,查询数据失败"; return(Json(ar, JsonRequestBehavior.AllowGet)); } var currentUser = LoginManager.GetCurrentUser(); List <CustomItem> customItemList = new List <CustomItem>(); List <InformationModel> modelList = new List <InformationModel>(); try { var state = OperatorState.error; List <Member> memberList = _underlingManager.GetUnderlingList(); foreach (var member in memberList) { state = _customItemBLL.GetCustomItems(member.Account, ref customItemList); if (state == OperatorState.error) { ar.state = ResultType.error.ToString(); ar.message = "获取自定义项失败,无法搜索到数据"; return(Json(ar, JsonRequestBehavior.AllowGet)); } // 是否使用条件查询模式 if (OnlyKeyword) { state = _informationBLL.GetInformation(keyword, member.Account, conditionModel, customItemList, ref modelList); } else { state = _informationBLL.GetInformation(keyword, member.Account, null, customItemList, ref modelList); } } // 查询自己 state = _customItemBLL.GetCustomItems(currentUser.Account, ref customItemList); if (state == OperatorState.error) { ar.state = ResultType.error.ToString(); ar.message = "获取自定义项失败,无法搜索到数据"; return(Json(ar, JsonRequestBehavior.AllowGet)); } // 是否使用条件查询模式 if (OnlyKeyword) { state = _informationBLL.GetInformation(keyword, currentUser.Account, conditionModel, customItemList, ref modelList); } else { state = _informationBLL.GetInformation(keyword, currentUser.Account, null, customItemList, ref modelList); } if (state == OperatorState.empty) { ar.state = ResultType.error.ToString(); ar.message = "无法获取到当前用户,无法搜索到数据"; } else if (state == OperatorState.success) { if (modelList == null || modelList.Count <= 0) { ar.state = ResultType.error.ToString(); ar.message = "无法搜索到有关数据"; } else { ar.state = ResultType.success.ToString(); ar.data = modelList.ToJson(); DataCacheManager.SetDataCache(CachaKey.Key, modelList); } } } catch (Exception ex) { LogHelper.writeLog_error(ex.Message); LogHelper.writeLog_error(ex.StackTrace); ar.state = ResultType.error.ToString(); ar.message = "系统错误,获取数据失败"; } return(Json(ar, JsonRequestBehavior.AllowGet)); }
public ActionResult Upload(HttpPostedFileBase[] fileCollection) { AjaxResult ar = new Globals.AjaxResult(); if (fileCollection.First() == null) { ar.state = ResultType.error.ToString(); ar.message = "上传的文件为空,请重新上传"; return(Json(ar, JsonRequestBehavior.AllowGet)); } var currentUser = LoginManager.GetCurrentUser(); List <string> fileList = new List <string>(); fileList = FileManager.SaveFile(fileCollection, Server.MapPath("~/Files")); List <Information> informationList = new List <Information>(); List <CustomItem> customItemList = new List <CustomItem>(); _customItemBLL.GetCustomItems(currentUser.Account, ref customItemList); List <CustomItemValue> customItemValueList = new List <CustomItemValue>(); try { foreach (var item in fileList) { List <Information> tempInforList = new List <Information>(); _excelManager.Open(item); _excelManager.GetDataFromExcel(currentUser.Account, ref tempInforList, ref customItemList, ref customItemValueList); _excelManager.Close(); //关闭并删除文件 informationList.AddRange(tempInforList); } } catch (Exception ex) { LogHelper.writeLog_error(ex.Message); LogHelper.writeLog_error(ex.StackTrace); ar.state = ResultType.error.ToString(); ar.message = "解析数据失败"; return(Json(ar, JsonRequestBehavior.AllowGet)); } bool state = _dataManager.ExcelToDataBase(informationList, currentUser, customItemList, customItemValueList); if (state) { ar.state = ResultType.success.ToString(); ar.message = "导入成功"; } else { ar.state = ResultType.error.ToString(); ar.message = "导入数据失败"; } return(Json(ar, JsonRequestBehavior.AllowGet)); }