//On<Insert|Updat|Delet|Execut><ed|ing><EntitySetName|ActionName>其中ing的前提交,并ed于提交后。 #region T_XT_Data_Entity #region 新增 protected void OnInsertingT_XT_Data_Entity(T_XT_Data_Entity entityset) { try { if (string.IsNullOrEmpty(entityset.DataId)) { entityset.DataId = Guid.NewGuid().ToString("N"); } entityset.CreateTime = DateTime.Now; entityset.IsDeleted = false; entityset.SubItemAmount = 0; #region 更新子节点数量 using (TeamWorkDbContext et = new TeamWorkDbContext()) { T_XT_Data_Entity _p = et.T_XT_Data_Entity.FirstOrDefault(k => k.DataId == entityset.ParentId); if (_p != null) { _p.SubItemAmount = et.T_XT_Data_Entity.Where(k => k.ParentId == _p.DataId && k.IsDeleted == false).Count() + 1; et.SaveChanges(); } } #endregion } catch (Exception) { throw; } }
protected void OnDeletingT_XT_Data_Entity(T_XT_Data_Entity entityset) { entityset.ModifyTime = DateTime.Now; entityset.IsDeleted = true; #region 更新子节点数量 using (TeamWorkDbContext et = new TeamWorkDbContext()) { T_XT_Data_Entity _p = et.T_XT_Data_Entity.FirstOrDefault(k => k.DataId == entityset.ParentId); if (_p != null) { _p.SubItemAmount = et.T_XT_Data_Entity.Where(k => k.ParentId == _p.DataId && k.IsDeleted == false).Count() - 1; et.SaveChanges(); } } #endregion }
/// <summary> /// 获取Excel模板版本号 /// </summary> /// <param name="dataId"></param> /// <returns></returns> public string getExcelVersion(string dataId) { string ret = ""; try { using (TeamWorkDbContext et = new TeamWorkDbContext()) { T_XT_Data_Entity _data = et.T_XT_Data_Entity.FirstOrDefault(k => k.DataId == dataId); if (_data != null) { ret = _data.DataName; } } } catch (Exception) { } return(ret); }
public JsonResult XTStaticDatasDelete(string delId) { JsonRetModel ret = new JsonRetModel { Ret = false }; try { using (TeamWorkDbContext et = new TeamWorkDbContext()) { T_XT_Data_Entity _d = et.T_XT_Data_Entity.FirstOrDefault(k => k.DataId == delId); if (_d != null) { _d.ModifyTime = DateTime.Now; _d.IsDeleted = true; T_XT_Data_Entity _p = et.T_XT_Data_Entity.FirstOrDefault(k => k.DataId == _d.ParentId); if (_p != null) { _p.SubItemAmount = et.T_XT_Data_Entity.Where(k => k.ParentId == _p.DataId && k.IsDeleted == false).Count() - 1; } et.SaveChanges(); ret.Ret = true; ret.Msg = "操作成功!"; } else { ret.Msg = "操作失败,此节点可能已经被删除!"; } } } catch (Exception ex) { ret.Msg = ex.Message; } return(Json(ret)); }
protected void OnUpdatingT_XT_Data_Entity(T_XT_Data_Entity entityset) { entityset.ModifyTime = DateTime.Now; }
public JsonResult XTStaticDatasSort(string DataId, string SortFlag) { JsonRetModel ret = new JsonRetModel { Ret = false }; try { using (TeamWorkDbContext et = new TeamWorkDbContext()) { T_XT_Data_Entity _d = et.T_XT_Data_Entity.Where(item => item.DataId == DataId).FirstOrDefault(); if (_d != null) { var list = et.T_XT_Data_Entity.Where(item => item.ParentId == _d.ParentId && item.IsDeleted == false).OrderBy(k => k.SortIndex); var _list = list.ToList(); if (_list.Any()) { if (SortFlag == "up" && _list.FirstOrDefault().DataId == DataId) { ret.Msg = "已经是第一个了!"; } else if (SortFlag == "down" && _list.LastOrDefault().DataId == DataId) { ret.Msg = "已经是最后一个了!"; } else { int _index = 0, _target = 0; foreach (var d in list) { d.SortIndex = _index++; if (d.DataId == DataId) { _target = Convert.ToInt32(d.SortIndex); } } T_XT_Data_Entity dd = list.Skip(_target).FirstOrDefault(); switch (SortFlag) { case "up": dd.SortIndex--; var _prev = list.Skip(_target - 1).FirstOrDefault(); _prev.SortIndex++; break; case "down": dd.SortIndex++; var _next = list.Skip(_target + 1).FirstOrDefault(); _next.SortIndex--; break; default: break; } et.SaveChanges(); ret.Ret = true; ret.Msg = "操作成功!"; } } } } } catch (Exception ex) { ret.Msg = ex.Message; } return(Json(ret)); }