/// <summary> /// 删除 /// </summary> /// <param name="entity">业务实体</param> public void Delete(EmpGroup entity) { if (entity == null) { return; } //如果是系统组,则不允许删除 if (entity.EGrp_IsSystem) { return; } using (DbTrans tran = Gateway.Default.BeginTrans()) { try { tran.Delete <EmpAcc_Group>(EmpAcc_Group._.EGrp_Id == entity.EGrp_Id); tran.Delete <Purview>(Purview._.EGrp_Id == entity.EGrp_Id); tran.Delete <EmpGroup>(entity); tran.Commit(); } catch { tran.Rollback(); throw; } finally { tran.Close(); } } }
/// <summary> /// 添加 /// </summary> /// <param name="entity">业务实体</param> public void Add(EmpGroup entity) { //添加对象,并设置排序号 object obj = Gateway.Default.Max <EmpGroup>(EmpGroup._.EGrp_Tax, EmpGroup._.EGrp_Tax > -1 && EmpGroup._.Org_ID == entity.Org_ID); entity.EGrp_Tax = obj is int?(int)obj + 1 : 1; Gateway.Default.Save <EmpGroup>(entity); }
public void AddUserGroupByGroupName(string GroupName) { PrinteryContext db = new PrinteryContext(); var newGroup = new EmpGroup() { GroupId = Guid.NewGuid().ToString(), GroupName = GroupName, Tip = "" }; db.EmpGroup.Add(newGroup); db.SaveChanges(); }
/// <summary> /// 当前对象名称是否重名 /// </summary> /// <param name="entity">业务实体</param> /// <returns>重名返回true,否则返回false</returns> public bool IsExist(EmpGroup entity) { EmpGroup mm = null; //如果是一个新对象 if (entity.EGrp_Id == 0) { mm = Gateway.Default.From <EmpGroup>().Where(EmpGroup._.EGrp_Name == entity.EGrp_Name).ToFirst <EmpGroup>(); } else { //如果是一个已经存在的对象,则不匹配自己 mm = Gateway.Default.From <EmpGroup>().Where(EmpGroup._.EGrp_Name == entity.EGrp_Name && EmpGroup._.EGrp_Id != entity.EGrp_Id).ToFirst <EmpGroup>(); } return(mm != null); }
/// <summary> /// 将当前栏目向下移动;仅在当前对象的同层移动,即同一父节点下的对象之间移动; /// </summary> /// <param name="id"></param> /// <returns>如果已经处于最底端,则返回false;移动成功,返回true</returns> public bool RemoveDown(int orgid, int id) { //当前对象 EmpGroup current = Gateway.Default.From <EmpGroup>().Where(EmpGroup._.EGrp_Id == id).ToFirst <EmpGroup>(); //当前对象排序号 int orderValue = (int)current.EGrp_Tax; //下一个对象,即弟弟对象; EmpGroup down = Gateway.Default.From <EmpGroup>() .Where(EmpGroup._.Org_ID == orgid && EmpGroup._.EGrp_Tax > orderValue) .OrderBy(EmpGroup._.EGrp_Tax.Asc).ToFirst <EmpGroup>(); if (down == null) { return(false); } //交换排序号 current.EGrp_Tax = down.EGrp_Tax; down.EGrp_Tax = orderValue; using (DbTrans tran = Gateway.Default.BeginTrans()) { try { tran.Save <EmpGroup>(current); tran.Save <EmpGroup>(down); tran.Commit(); } catch { tran.Rollback(); throw; } finally { tran.Close(); } } return(true); }
public JsonResult Get(int draw, int start) { //List<Records> tmp = (from a in _db.ProductInfoes // join b in _db.Records // on a.ProductNo equals b.ProductNo // where a.ProductNo == "dddd" // select new Records // { // UserId = b.UserId, // Unit = b.Unit, // ProductNo = a.ProductNo // }).ToList(); var employeeNo = ""; var countEmpNo = ""; int count = 0; int index = 0; List <EmpGroup> rows = new List <EmpGroup>(); List <string> rowsCount = new List <string>(); List <EmpGroup> tbrows = new List <EmpGroup>(); string parameter = Request.Query["search[value]"].FirstOrDefault(); EmpGroupCondition condition = null; var counttmp = _db.tbEmployee.Select(m => m.EmployeeNo).Distinct().AsQueryable(); var tmp = (from a in _db.tbEmployee from b in _db.tbEmpGroup .Where(f => f.EmployeeNo == a.EmployeeNo) select new { a.EmployeeNo, a.EmployeeName, b.GroupID } into x join c in _db.tbGroup on x.GroupID equals c.GroupID into gj from y in gj.DefaultIfEmpty() select new EmpGroup { EmployeeNo = x.EmployeeNo, EmployeeName = x.EmployeeName, GroupName = (y == null ? String.Empty : y.GroupName) }).AsQueryable(); //var tmp = (from a in _db.tbEmployee // join b in _db.tbEmpGroup // on a.EmployeeNo equals b.EmployeeNo into list1 // from l1 in list1.DefaultIfEmpty() // join c in _db.tbGroup // on l1.GroupID equals c.GroupID into list12 // from l2 in list12.DefaultIfEmpty() // select new EmpGroup // { // EmployeeNo = a.EmployeeNo, // EmployeeName = a.EmployeeName, // EmployeeEName = a.EmployeeEName, // GroupName = l2.GroupName // }).AsQueryable(); // var tmp = (from a in _db.tbEmployee // from OD in _db.tbEmpGroup //.Where(OD => OD.EmployeeNo == a.EmployeeNo).DefaultIfEmpty() // join c in _db.tbGroup // on OD.GroupID equals c.GroupID // select new EmpGroup // { // EmployeeNo = a.EmployeeNo, // EmployeeName = a.EmployeeName, // EmployeeEName = a.EmployeeEName, // GroupName = (OD == null ? String.Empty : c.GroupName) // }).AsQueryable(); if (parameter != "") { condition = (EmpGroupCondition)JsonConvert.DeserializeObject(parameter, typeof(EmpGroupCondition)); } if (condition != null) { if (condition.EmployeeNo != "") { tmp = tmp.Where(e => e.EmployeeNo.Contains(condition.EmployeeNo)); } if (condition.EmployeeName != "") { tmp = tmp.Where(e => e.EmployeeName.Contains(condition.EmployeeName)); } } rows = tmp.OrderBy(e => e.EmployeeNo).ToList(); //for (int i = rows.Count - 1; i >= 0; i--) //{ // if (!rows[i].EmployeeNo.Equals(employeeNo)) // { // index = i; // employeeNo = rows[i].EmployeeNo; // } // else // { // rows[index].GroupName = rows[index].GroupName + "," + rows[i].GroupName; // rows.RemoveAt(i); // } //} EmpGroup EmpGroup = new EmpGroup(); for (int i = 0; i < rows.Count; i++) { if (!rows[i].EmployeeNo.Equals(countEmpNo)) { countEmpNo = rows[i].EmployeeNo; count++; } if (count > (start + 10)) { break; } if (count > start) { if (!rows[i].EmployeeNo.Equals(employeeNo)) { if (!employeeNo.Equals("")) { tbrows.Add(EmpGroup); } EmpGroup = new EmpGroup(); employeeNo = rows[i].EmployeeNo; EmpGroup.EmployeeNo = employeeNo; EmpGroup.EmployeeName = rows[i].EmployeeName; EmpGroup.GroupName = rows[i].GroupName; } else { EmpGroup.GroupName = EmpGroup.GroupName + "," + rows[i].GroupName; } } } if (rows.Count != 0) { tbrows.Add(EmpGroup); } int recordsTotal = counttmp.Count(); //rows = filteredData.OrderBy(e => e.GroupID).Skip(start).Take(10).ToList(); var renderModel = new DataTablesRenderModel { draw = draw, data = tbrows, length = tbrows.Count(), recordsFiltered = recordsTotal, recordsTotal = recordsTotal }; return(Json(renderModel)); }
public async Task <int> Add(EmpGroup EmpGroup) { await db.EmpGroup.AddAsync(EmpGroup); return(await db.SaveChangesAsync()); }
/// <summary> /// 修改 /// </summary> /// <param name="entity">业务实体</param> public void Save(EmpGroup entity) { Gateway.Default.Save <EmpGroup>(entity); }
/// <summary> /// 获取单一实体对象,按主键ID; /// </summary> /// <param name="identify">实体的主键</param> /// <returns></returns> public EmpGroup GetSingle(int identify) { EmpGroup group = Gateway.Default.From <EmpGroup>().Where(EmpGroup._.EGrp_Id == identify).ToFirst <EmpGroup>(); return(group); }
/// <summary> /// 删除,按主键ID; /// </summary> /// <param name="identify">实体的主键</param> public void Delete(int identify) { EmpGroup entity = this.GetSingle(identify); this.Delete(entity); }