/// <summary>
        ///
        /// </summary>
        /// <param name="Member"></param>
        /// <returns></returns>
        public static ErrorCode Add(Family Member)
        {
            ErrorCode code = ErrorCode.Unknown_Error;

            using (FamilyRelationshipContext dbContext = new FamilyRelationshipContext())
            {
                if (dbContext.Family.Find(Member.FamilyName) != null)
                {
                    code = ErrorCode.DataAlreadyExist;
                }
                else
                {
                    dbContext.Family.Add(Member);
                    int rows = dbContext.SaveChanges();
                    if (rows <= 0)
                    {
                        code = ErrorCode.DataAddError;
                    }
                    else
                    {
                        code = ErrorCode.Success;
                    }
                }
            }
            return(code);
        }
        private void btInit_Click(object sender, EventArgs e)
        {
            FRSDbContext = new FamilyRelationshipContext();

            bool flag = FRSDbContext.Database.CreateIfNotExists();

            if (flag == true)
            {
                CertificateType type = new CertificateType();
                type.CertificateTypeName = "二代身份证";
                type.Description         = "二代身份证";
                FRSDbContext.CertificateType.Add(type);

                Role role = new Role();
                role.RoleName    = "System admin";
                role.Description = "System admin";
                FRSDbContext.Role.Add(role);

                User user = new User();
                user.UserName     = "******";
                user.Password     = "******";
                user.UserTrueName = "admin";
                user.RoleId       = 1;
                FRSDbContext.User.Add(user);

                FRSDbContext.SaveChanges();

                MessageBox.Show("数据库创建成功!");
            }
            else
            {
                //MessageBox.Show("数据库创建失败!");
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="Member"></param>
        /// <returns></returns>
        public static int Remove(Family Member)
        {
            int rows = 0;

            using (FamilyRelationshipContext dbContext = new FamilyRelationshipContext())
            {
                Family rem = dbContext.Family.Where <Family>(c => c.FamilyId == Member.FamilyId).FirstOrDefault();
                dbContext.Family.Remove(rem);
                rows = dbContext.SaveChanges();
            }
            return(rows);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="CertificateTypeId"></param>
        /// <returns></returns>
        public static int Remove(int CertificateTypeId)
        {
            int rows = 0;

            using (FamilyRelationshipContext dbContext = new FamilyRelationshipContext())
            {
                CertificateType rem = dbContext.CertificateType.Where <CertificateType>(c => c.CertificateTypeId == CertificateTypeId).FirstOrDefault();
                dbContext.CertificateType.Remove(rem);
                rows = dbContext.SaveChanges();
            }
            return(rows);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="Member"></param>
        /// <returns></returns>
        public static int Update(CertificateType Member)
        {
            int rows = 0;

            using (FamilyRelationshipContext dbContext = new FamilyRelationshipContext())
            {
                CertificateType up = dbContext.CertificateType.Where <CertificateType>(c => c.CertificateTypeId == Member.CertificateTypeId).FirstOrDefault();
                up.CertificateTypeName = Member.CertificateTypeName;
                up.Description         = Member.Description;
                rows = dbContext.SaveChanges();
            }
            return(rows);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="Member"></param>
        /// <returns></returns>
        public static int Update(Family Member)
        {
            int rows = 0;

            using (FamilyRelationshipContext dbContext = new FamilyRelationshipContext())
            {
                Family up = dbContext.Family.Where <Family>(c => c.FamilyId == Member.FamilyId).FirstOrDefault();
                up.FamilyName     = Member.FamilyName;
                up.FamilyOrigin   = Member.FamilyOrigin;
                up.FamilyHistory  = Member.FamilyHistory;
                up.GenerationInfo = Member.GenerationInfo;
                up.Other1         = Member.Other1;
                up.Other2         = Member.Other2;
                rows = dbContext.SaveChanges();
            }
            return(rows);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="Member"></param>
        /// <returns></returns>
        public static int Update(FamilyMember Member)
        {
            int rows = 0;

            using (FamilyRelationshipContext dbContext = new FamilyRelationshipContext())
            {
                FamilyMember up = dbContext.FamilyMember.Where <FamilyMember>(c => c.FamilyId == Member.FamilyId).FirstOrDefault();
                up.GenerationIndex       = Member.GenerationIndex;
                up.Address               = Member.Address;
                up.Age                   = Member.Age;
                up.Birthday              = Member.Birthday;
                up.CertificateNumber     = Member.CertificateNumber;
                up.CertificateTypeId     = Member.CertificateTypeId;
                up.Country               = Member.Country;
                up.Deathday              = Member.Deathday;
                up.Description           = Member.Description;
                up.Education             = Member.Education;
                up.LastName              = Member.LastName;
                up.Father_FamilyMemberId = Member.Father_FamilyMemberId;
                up.Father                = Member.Father;
                up.File                  = Member.File;
                up.GivenName             = Member.GivenName;
                up.Hometown              = Member.Hometown;
                up.Job                   = Member.Job;
                up.MiddleName            = Member.MiddleName;
                up.Mother_FamilyMemberId = Member.Mother_FamilyMemberId;
                up.Mother                = Member.Mother;
                up.Nationality           = Member.Nationality;
                up.OtherName1            = Member.OtherName1;
                up.OtherName2            = Member.OtherName2;
                up.PhotoImage            = Member.PhotoImage;
                up.Ranking               = Member.Ranking;
                up.CertificateType       = Member.CertificateType;
                up.Sex                   = Member.Sex;
                up.Spouse_FamilyMemberId = Member.Spouse_FamilyMemberId;
                up.Spouse                = Member.Spouse;
                up.FamilyId              = Member.FamilyId;
                up.Family                = Member.Family;
                rows = dbContext.SaveChanges();
            }
            return(rows);
        }