public ActionResult Create([Bind(Include = "Id,BillTypeNumber,BillTypeName,BillNumber,StaffNumber,StaffName,ApplyDate,HopeLeaveDate,LeaveType,LeaveReason,Remark,AuditStatus")]StaffApplication staffApplication)
        {
            if (ModelState.IsValid)
            {
                staffApplication.AuditStatus = "未提交";

                db.StaffApplications.Add(staffApplication);
                db.SaveChanges();
                var fieldList = (from p in db.ReserveFields where p.TableName == "StaffApplications" select p).ToList();
                ViewBag.fieldList = fieldList;

                /*遍历,保存员工基本信息预留字段*/
                foreach (var temp in fieldList)
                {
                    StaffApplicationReserve sar = new StaffApplicationReserve();
                    sar.Number = staffApplication.Id;
                    sar.FieldId = temp.Id;
                    sar.Value = Request[temp.FieldName];
                    /*占位,为了在Index中显示整齐的格式*/
                    if (sar.Value == null) sar.Value = " ";
                    db.StaffApplicationReserves.Add(sar);
                    db.SaveChanges();
                }
                return RedirectToAction("Index");
            }

            return View(staffApplication);
        }
        public ActionResult Create([Bind(Include = "Id,TableName,FieldName,Description,Status")] ReserveField reserveField)
        {
            List<SelectListItem> items = new List<SelectListItem>();
            items.Add(new SelectListItem { Text = "部门信息表", Value = "Departments" });
            items.Add(new SelectListItem { Text = "员工档案表", Value = "Staffs" });
            items.Add(new SelectListItem { Text = "员工技能表", Value = "StaffSkills" });
            //items.Add(new SelectListItem { Text = "员工技能表", Value = "StaffSkills" });
            items.Add(new SelectListItem { Text = "人事变更申请表", Value = "StaffChanges" });
            items.Add(new SelectListItem { Text = "离职申请表", Value = "StaffApplications" });
            items.Add(new SelectListItem { Text = "离职档案表", Value = "StaffArchives" });
            items.Add(new SelectListItem { Text = "合同管理表", Value = "Contracts" });
            ViewBag.List = items;

            if (ModelState.IsValid)
            {

                var number = db.ReserveFields.Select(rf=>rf.Id).Max();
                reserveField.Id = number+1;
                db.ReserveFields.Add(reserveField);
                /*状态设置为有效*/
                reserveField.Status = "true";
                db.SaveChanges();
                //if (reserveField.TableName == "Contracts")
                //{
                //    StaffApplicationReserve sar = new ContractReserve();
                //    var staffApplication = db.StaffApplications.ToList();
                //    foreach (var temp in staffApplication)
                //    {
                //        sar.FieldId = reserveField.Id;
                //        sar.Number = temp.Id;
                //        sar.Value = " ";
                //        db.StaffApplicationReserves.Add(sar);
                //        db.SaveChanges();
                //    }
                //}

                //确保固定字段表、变化字段表和变化字段存储表的数据一致性。
                if (reserveField.TableName == "StaffApplications")
                {
                    StaffApplicationReserve sar = new StaffApplicationReserve();
                    var staffApplication = db.StaffApplications.ToList();
                    foreach (var temp in staffApplication)
                    {
                        sar.FieldId = reserveField.Id;
                        sar.Number = temp.Id;
                        sar.Value = " ";
                        db.StaffApplicationReserves.Add(sar);
                        db.SaveChanges();
                    }
                }
                if (reserveField.TableName == "StaffChanges")
                {
                    StaffChangeReserve scr = new StaffChangeReserve();
                    var staffchange = db.StaffChanges.ToList();
                    foreach (var temp in staffchange)
                    {
                        scr.FieldId = reserveField.Id;
                        scr.Number = temp.Id;
                        scr.Value = " ";
                        db.StaffChangeReserves.Add(scr);
                        db.SaveChanges();
                    }
                }
                if (reserveField.TableName == "StaffSkills")
                {
                    StaffSkillReserve ssr = new StaffSkillReserve();
                    var staffskill = db.StaffSkills.ToList();
                    foreach (var temp in staffskill)
                    {
                        ssr.FieldId = reserveField.Id;
                        ssr.Number = temp.Id;
                        ssr.Value = " ";
                        db.StaffSkillReserves.Add(ssr);
                        db.SaveChanges();
                    }
                }
                if (reserveField.TableName == "Staffs")
                {
                    StaffReserve sr = new StaffReserve();
                    var staff = db.Staffs.ToList();
                    foreach (var temp in staff)
                    {
                        sr.FieldId = reserveField.Id;
                        sr.Number = temp.Number;
                        sr.Value = " ";
                        db.StaffReserves.Add(sr);
                        db.SaveChanges();
                    }
                }
                if (reserveField.TableName == "Departments")
                {
                    DepartmentReserve dr = new DepartmentReserve();
                    var department = db.Departments.ToList();
                    foreach(var temp in department)
                    {
                        dr.FieldId=reserveField.Id;
                        dr.Number = temp.Id;
                        dr.Value = " ";
                        db.DepartmentReserves.Add(dr);
                        db.SaveChanges();
                    }
                }
                if (reserveField.TableName == "StaffArchives")
                {
                    StaffArchiveReserve sar = new StaffArchiveReserve();
                    var staffarchive = db.StaffArchives.ToList();
                    foreach (var temp in staffarchive)
                    {
                        sar.FieldId = reserveField.Id;
                        sar.Number = temp.Id;
                        sar.Value = " ";
                        db.StaffArchiveReserves.Add(sar);
                        db.SaveChanges();
                    }
                }

                return RedirectToAction("IndexInfo", new { table = reserveField.TableName });
            }

            return View(reserveField);
        }