本文整理汇总了C#中Person.SetBirthDate方法的典型用法代码示例。如果您正苦于以下问题:C# Person.SetBirthDate方法的具体用法?C# Person.SetBirthDate怎么用?C# Person.SetBirthDate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Person
的用法示例。
在下文中一共展示了Person.SetBirthDate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuildFamilyMembersFromXml
/// <summary>
/// Takes the given XML element and creates a family member collection.
/// If the person already exists, their record will be loaded otherwise
/// a new person will be created using all the attributes for the given
/// 'person' tag.
/// </summary>
/// <param name="elemMembers"></param>
/// <param name="rockContext">The rock context.</param>
/// <returns>a list of family members.</returns>
private List<GroupMember> BuildFamilyMembersFromXml( XElement elemMembers, RockContext rockContext )
{
var familyMembers = new List<GroupMember>();
// First add each person to the familyMembers collection
foreach ( var personElem in elemMembers.Elements( "person" ) )
{
var groupMember = new GroupMember();
Guid guid = Guid.Parse( personElem.Attribute( "guid" ).Value.Trim() );
// Attempt to find an existing person...
Person person = null;
if ( _personCache.ContainsKey( guid ) )
{
person = _personCache[guid];
}
if ( person == null )
{
person = new Person();
person.CreatedByPersonAliasId = CurrentPersonAliasId;
person.CreatedDateTime = RockDateTime.Now;
person.Guid = guid;
person.FirstName = personElem.Attribute( "firstName" ).Value.Trim();
if ( personElem.Attribute( "suffix") != null )
{
person.SuffixValueId = GetOrAddDefinedValueId( personElem.Attribute( "suffix" ).Value.Trim(), _suffixDefinedType, rockContext );
}
if ( personElem.Attribute( "nickName" ) != null )
{
person.NickName = personElem.Attribute( "nickName" ).Value.Trim();
}
else
{
person.NickName = personElem.Attribute( "firstName" ).Value.Trim();
}
if ( personElem.Attribute( "lastName" ) != null )
{
person.LastName = personElem.Attribute( "lastName" ).Value.Trim();
}
if ( personElem.Attribute( "birthDate" ) != null )
{
person.SetBirthDate( DateTime.Parse( personElem.Attribute( "birthDate" ).Value.Trim(), new CultureInfo( "en-US" ) ) );
}
if ( personElem.Attribute( "grade" ) != null )
{
int? grade = personElem.Attribute( "grade" ).Value.AsIntegerOrNull();
if (grade.HasValue)
{
// convert the grade (0-12 where 12 = Senior), to a GradeOffset (12-0 where 12 = K and 0 = Senior)
int gradeOffset = 12 - grade.Value;
person.GradeOffset = gradeOffset >= 0 ? gradeOffset : (int?)null;
}
}
else if ( personElem.Attribute( "graduationDate" ) != null )
{
person.GraduationYear = DateTime.Parse( personElem.Attribute( "graduationDate" ).Value.Trim(), new CultureInfo( "en-US" ) ).Year;
}
// Now, if their age was given we'll change the given birth year to make them
// be this age as of Today.
if ( personElem.Attribute( "age" ) != null )
{
int age = int.Parse( personElem.Attribute( "age" ).Value.Trim() );
int ageDiff = person.Age - age ?? 0;
person.SetBirthDate( person.BirthDate.Value.AddYears( ageDiff ) );
}
person.EmailPreference = EmailPreference.EmailAllowed;
if ( personElem.Attribute( "email" ) != null )
{
var emailAddress = personElem.Attribute( "email" ).Value.Trim();
if ( emailAddress.IsValidEmail() )
{
person.Email = emailAddress;
person.IsEmailActive = personElem.Attribute( "emailIsActive" ) != null && personElem.Attribute( "emailIsActive" ).Value.AsBoolean();
if ( personElem.Attribute( "emailDoNotEmail" ) != null && personElem.Attribute( "emailDoNotEmail" ).Value.AsBoolean() )
{
person.EmailPreference = EmailPreference.DoNotEmail;
}
}
}
if ( personElem.Attribute( "photoUrl" ) != null )
{
//.........这里部分代码省略.........
示例2: lbSubmit_Click
protected void lbSubmit_Click( object sender, EventArgs e )
{
if ( Page.IsValid )
{
RockContext rockContext = new RockContext();
var adultRole = new GroupTypeRoleService( rockContext ).Get( Rock.SystemGuid.GroupRole.GROUPROLE_FAMILY_MEMBER_ADULT.AsGuid() );
var childRole = new GroupTypeRoleService( rockContext ).Get( Rock.SystemGuid.GroupRole.GROUPROLE_FAMILY_MEMBER_CHILD.AsGuid() );
Person parent = new Person();
parent.FirstName = rtbParentFirstName.Text;
parent.LastName = rtbParentLastName.Text;
parent.LoadAttributes( rockContext );
PhoneNumber parentPhone = new PhoneNumber();
parentPhone.Number = pnbParentPhoneNumber.Number;
parent.PhoneNumbers.Add( parentPhone );
List<GroupMember> familyMembers = new List<GroupMember>();
GroupMember parentGM = new GroupMember();
parentGM.Person = parent;
parentGM.GroupRoleId = adultRole.Id;
familyMembers.Add( parentGM );
foreach ( KidData kidData in kidsList )
{
Person kid = new Person();
kid.FirstName = kidData.FirstName;
kid.LastName = kidData.LastName;
kid.Gender = kidData.Gender;
kid.SetBirthDate( kidData.Birthdate );
kid.GradeOffset = kidData.Grade.Value.AsIntegerOrNull();
kid.LoadAttributes( rockContext );
kid.SetAttributeValue( "AbilityLevel", kidData.AbilityLevel.Guid.ToString() );
kid.SetAttributeValue( "Allergy", kidData.Allergy );
kid.SetAttributeValue( "LegalNotes", kidData.LegalNotes );
GroupMember kidGM = new GroupMember();
kidGM.Person = kid;
kidGM.GroupRoleId = childRole.Id;
familyMembers.Add( kidGM );
}
Group family = GroupService.SaveNewFamily( rockContext, familyMembers, cpCampus.SelectedValueAsInt(), true );
if ( !String.IsNullOrWhiteSpace( GetAttributeValue( "PersonDetailsPage" ) ) )
{
NavigateToLinkedPage( "PersonDetailsPage", new Dictionary<string, string>() { { "PersonId", parent.Id.ToString() } } );
}
else
{
NavigateToCurrentPage( new Dictionary<string, string>() { { "PersonId", parent.Id.ToString() } } );
}
}
}
示例3: btnSave_Click
//.........这里部分代码省略.........
demographicChanges.Add( "Created" );
var person = new Person();
person.TitleValueId = familyMember.TitleValueId;
History.EvaluateChange( demographicChanges, "Title", string.Empty, DefinedValueCache.GetName( person.TitleValueId) );
person.FirstName = familyMember.FirstName;
person.NickName = familyMember.NickName;
History.EvaluateChange( demographicChanges, "First Name", string.Empty, person.FirstName );
person.LastName = familyMember.LastName;
History.EvaluateChange( demographicChanges, "Last Name", string.Empty, person.LastName );
person.SuffixValueId = familyMember.SuffixValueId;
History.EvaluateChange( demographicChanges, "Suffix", string.Empty, DefinedValueCache.GetName( person.SuffixValueId ) );
person.Gender = familyMember.Gender;
History.EvaluateChange( demographicChanges, "Gender", null, person.Gender );
person.MaritalStatusValueId = familyMember.MaritalStatusValueId;
History.EvaluateChange( demographicChanges, "Marital Status", string.Empty, DefinedValueCache.GetName( person.MaritalStatusValueId ) );
DateTime? birthdate = familyMember.BirthDate;
if ( birthdate.HasValue )
{
// If setting a future birthdate, subtract a century until birthdate is not greater than today.
var today = RockDateTime.Today;
while ( birthdate.Value.CompareTo( today ) > 0 )
{
birthdate = birthdate.Value.AddYears( -100 );
}
}
person.SetBirthDate( birthdate );
History.EvaluateChange( demographicChanges, "Birth Date", null, person.BirthDate );
person.GradeOffset = familyMember.GradeOffset;
History.EvaluateChange( demographicChanges, "Graduation Year", null, person.GraduationYear );
person.ConnectionStatusValueId = familyMember.ConnectionStatusValueId;
History.EvaluateChange( demographicChanges, "Connection Status", string.Empty, DefinedValueCache.GetName( person.ConnectionStatusValueId ) );
person.IsEmailActive = true;
History.EvaluateChange( demographicChanges, "Email Active", true.ToString(), ( person.IsEmailActive ?? true ).ToString() );
person.RecordTypeValueId = DefinedValueCache.Read( Rock.SystemGuid.DefinedValue.PERSON_RECORD_TYPE_PERSON.AsGuid() ).Id;
History.EvaluateChange( demographicChanges, "Record Type", string.Empty, DefinedValueCache.GetName( person.RecordTypeValueId.Value ) );
if ( !isChild )
{
person.GivingGroupId = _family.Id;
History.EvaluateChange( demographicChanges, "Giving Group", string.Empty, _family.Name );
}
person.EmailPreference = EmailPreference.EmailAllowed;
groupMember.Person = person;
}
else
{
// added from other family
groupMember.Person = personService.Get( familyMember.Id );
}
if ( recordStatusValueID > 0 )
{