public ActionResult SetApproval(string dataCode) { AjaxResult ar = new AjaxResult(); if (string.IsNullOrEmpty(dataCode)) { ar.state = ResultType.error.ToString(); ar.message = "提交的数据为空,上报失败"; return(Json(ar, JsonRequestBehavior.AllowGet)); } var information = _informationBLL.GetInformation(dataCode); var currentUser = LoginManager.GetCurrentUser(); if (information == null) { ar.state = ResultType.error.ToString(); ar.message = "不存在相应的数据条目,上报失败"; } else { //把数据的状态设置为 待审核状态就是上报 information.State = (int)InformatinState.PendApproval; using (var db = new DCSDBContext()) { using (var trans = db.Database.BeginTransaction()) { try { db.Set <Information>().Attach(information); db.Entry(information).State = System.Data.Entity.EntityState.Modified; currentUser.Apcount += 1; db.Set <Member>().Attach(currentUser); db.Entry(currentUser).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); trans.Commit(); DataCacheManager.Clear(CachaKey.Key); 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 = "系统错误,上报失败"; } } } } return(Json(ar, JsonRequestBehavior.AllowGet)); }
public bool Clear() { using (var trans = db.Database.BeginTransaction()) { try { var entitys = db.Set <T>(); entitys.ToList().ForEach(entity => db.Entry(entity).State = System.Data.Entity.EntityState.Deleted); //不加这句也可以,为什么? db.Set <T>().RemoveRange(entitys); SaveChanges(); trans.Rollback(); return(true); } catch (Exception) { trans.Rollback(); return(false); } } }
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 Import(Information InformationModel, List <FormModel> CustomItemModel) { AjaxResult ar = new AjaxResult(); if (InformationModel == null) { ar.state = ResultType.error.ToString(); ar.message = "提交数据有误,添加新纪录失败"; return(Json(ar, JsonRequestBehavior.AllowGet)); } try { var currentUser = LoginManager.GetCurrentUser(); if (!_informationBLL.IsExsit(InformationModel.Phone, InformationModel.QQ, InformationModel.WebCat, currentUser.CompanyCode)) { #region 注释 //var state = _informationBLL.AddInformation(InformationModel, currentUser.Account, currentUser.CompanyCode); //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 = "添加新纪录成功"; //} #endregion using (var db = new DCSDBContext()) { #region 开始一个事务 using (var trans = db.Database.BeginTransaction()) { try { InformationModel.InsertMember = InformationModel.UsageMember = currentUser.Account; InformationModel.State = (int)InformatinState.UnAssigned; InformationModel.InsertTime = DateTime.Now; InformationModel.UpdateTime = DateTime.Now; InformationModel.CompanyCode = currentUser.CompanyCode; InformationModel.DataCode = "DC" + currentUser.CompanyCode + TimeManager.GetTimeSpan() + RandomManager.GenerateRandom(5); db.Informations.Add(InformationModel); List <CustomItem> customItemList = new List <CustomItem>(); _customItemBLL.GetCustomItems(currentUser.Account, ref customItemList); foreach (var item in customItemList) { var cm = CustomItemModel.Where(n => n.name == item.ItemName).SingleOrDefault(); CustomItemValue cv = new CustomItemValue(); cv.InforId = InformationModel.Id; cv.InsertTime = cv.UpdateTime = DateTime.Now; cv.IsDeleted = false; cv.ItemValue = cm.value ?? ""; cv.CustomItemId = item.Id; cv.ItemName = item.ItemName; db.CustomItemValues.Add(cv); } db.SaveChanges(); // 修改用户的以收集数据的数量 + 1 currentUser.Cocount += 1; db.Set <Member>().Attach(currentUser); db.Entry(currentUser).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); trans.Commit(); 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 } } else { ar.state = ResultType.error.ToString(); 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 Approval(string dataCode) { AjaxResult ar = new AjaxResult(); var currentUser = LoginManager.GetCurrentUser(); if (string.IsNullOrEmpty(dataCode)) { ar.state = ResultType.error.ToString(); ar.message = "提交数据为空,审批失败"; return(Json(ar, JsonRequestBehavior.AllowGet)); } var information = _informationBLL.GetInformation(dataCode); if (information == null) { ar.state = ResultType.error.ToString(); ar.message = "不存在相应的数据,审批失败"; } else { information.State = (int)InformatinState.UnAssigned; var usageMember = information.UsageMember; information.UsageMember = currentUser.Account; using (var db = new DCSDBContext()) { using (var trans = db.Database.BeginTransaction()) { try { db.Set <Information>().Attach(information); db.Entry(information).State = System.Data.Entity.EntityState.Modified; var member = db.Set <Member>().Where(n => n.Account == usageMember).SingleOrDefault(); member.Apcount -= 1; member.Ascount -= 1; db.Set <Member>().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 = "系统错误,审批失败"; } } } } return(Json(ar, JsonRequestBehavior.AllowGet)); }