// GET: Department/Details/5
        public ActionResult Details(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
<<<<<<< HEAD
            Department department = db.Departments.Find(id);
            if (department == null)
            {
                return HttpNotFound();
            }
            return View(department);
=======

            //左联:查询上级部门的名称
            var q = from d in db.Departments
                    join x in db.Departments on d.ParentDepartmentId equals x.DepartmentId
                        into gc
                    from x in gc.DefaultIfEmpty()
                    where d.Id == id
                    select new { Name = x.Name };
            Department department = db.Departments.Find(id);
            DepartmentViewModel qq = new DepartmentViewModel();

            /*Step1:部门表的固定字段*/
            if (q != null)
            {
                foreach (var temp in q)
                {
                    qq.DepartmentId = department.DepartmentId;
                    qq.Name = department.Name;
                    qq.ParentDepartmentName = temp.Name;
                    qq.StaffSize = department.StaffSize;
                    qq.Remark = department.Remark;
                }
            }
            else
            {
                qq.DepartmentId = department.DepartmentId;
                qq.Name = department.Name;
                qq.ParentDepartmentName = null;
                qq.StaffSize = department.StaffSize;
                qq.Remark = department.Remark;
            }
            /*Step2:查找部门表预留字段*/
            var p = (from df in db.DepartmentReserves
                     join rf in db.ReserveFields on df.FieldId equals rf.Id
                     where df.Number == id
                     select new DepartmentViewModel {Id= df.Number,Description = rf.Description, Value = df.Value }).ToList();
            ViewBag.List = p;

            if (qq == null)
            {
                return HttpNotFound();
            }
            return View(qq);

>>>>>>> 7f6daae59d3f52aeb49e3b88babd3194b0c3112d
        }
 // GET: Department/Delete/5
 public ActionResult Delete(int? id)
 {
     if (id == null)
     {
         return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
     }
     //左联:查询上级部门的名称
     var q = from d in db.Departments
             join x in db.Departments on d.ParentDepartmentId equals x.DepartmentId
                 into gc
             from x in gc.DefaultIfEmpty()
             where d.Id == id
             select new { Name = x.Name };
     Department department = db.Departments.Find(id);
     DepartmentViewModel qq = new DepartmentViewModel();
     //DepartmentViewModel显示部门信息(部门表的固定字段)
     if (q != null)
     {
         foreach (var temp in q)
         {
             qq.DepartmentId = department.DepartmentId;
             qq.Name = department.Name;
             qq.ParentDepartmentName = temp.Name;
             qq.StaffSize = department.StaffSize;
             qq.Remark = department.Remark;
         }
     }
     else
     {
         qq.DepartmentId = department.DepartmentId;
         qq.Name = department.Name;
         qq.ParentDepartmentName = null;
         qq.StaffSize = department.StaffSize;
         qq.Remark = department.Remark;
     }
     //DepartmentViewModel显示部门信息(部门表变化的字段)
     var p = (from df in db.DepartmentReserves
              join rf in db.ReserveFields on df.FieldId equals rf.Id
              where df.Number == id
              select new DepartmentViewModel { Description = rf.Description, Value = df.Value }).ToList();
     ViewBag.List = p;
     if (department == null)
     {
         return HttpNotFound();
     }
     if (qq == null)
     {
         return HttpNotFound();
     }
     return View(qq);
 }