private Contact updateContactData(Contact contact) { try { //从界面获取数据更新到contact中 if (contact == null) { contact = new Contact(); } //获取姓名 if (FirstNameTB.Text.Length > 0) { contact.firstName = FirstNameTB.Text; } if (lastNameTB.Text.Length > 0) { contact.lastName = lastNameTB.Text; } //获取电话号码 List <Phone> lPhone = contact.phones; if (phoneNumTB_1.Text.Length > 0) { if (lPhone == null) { lPhone = new List <Phone>(); } Phone phone; if (lPhone.Count > 0) { phone = lPhone[0]; phone.field = phoneNumTB_1.Text; phone.label = PhoneTypeCb_1.Text; } else { phone = new Phone(); phone.field = phoneNumTB_1.Text; phone.label = PhoneTypeCb_1.Text; lPhone.Add(phone); } } if (phoneNumTB_2.Text.Length > 0) { if (lPhone == null) { lPhone = new List <Phone>(); } Phone phone; if (lPhone.Count > 1) { phone = lPhone[1]; phone.field = phoneNumTB_2.Text; phone.label = PhoneTypeCb_2.Text; } else { phone = new Phone(); phone.field = phoneNumTB_2.Text; phone.label = PhoneTypeCb_2.Text; lPhone.Add(phone); } } contact.phones = lPhone; //获取邮件地址 List <EmailAdr> lEmail = contact.emailAddresses; if (EmailTB_1.Text.Length > 0) { if (lEmail == null) { lEmail = new List <EmailAdr>(); } EmailAdr emailAdr; if (lEmail.Count > 0) { emailAdr = lEmail[0]; emailAdr.field = EmailTB_1.Text; emailAdr.label = EmailTypeCb_1.Text; } else { emailAdr = new EmailAdr(); emailAdr.field = EmailTB_1.Text; emailAdr.label = EmailTypeCb_1.Text; lEmail.Add(emailAdr); } } if (EmailTB_2.Text.Length > 0) { if (lEmail == null) { lEmail = new List <EmailAdr>(); } EmailAdr emailAdr; if (lEmail.Count > 1) { emailAdr = lEmail[1]; emailAdr.field = EmailTB_2.Text; emailAdr.label = EmailTypeCb_2.Text; } else { emailAdr = new EmailAdr(); emailAdr.field = EmailTB_2.Text; emailAdr.label = EmailTypeCb_2.Text; lEmail.Add(emailAdr); } } contact.emailAddresses = lEmail; //获取即时通讯 List <IM> lIM = contact.IMs; if (IMTB_1.Text.Length > 0) { if (lIM == null) { lIM = new List <IM>(); } IM im; if (lIM.Count > 0) { im = lIM[0]; if (im.field == null) { im.field = new IMsfield(); } im.field.userName = IMTB_1.Text; im.field.IMService = IMTypeCb_1.Text; } else { im = new IM(); im.field = new IMsfield(); im.field.userName = IMTB_1.Text; im.field.IMService = IMTypeCb_1.Text; lIM.Add(im); } } if (IMTB_2.Text.Length > 0) { if (lIM == null) { lIM = new List <IM>(); } IM im; if (lIM.Count > 1) { im = lIM[1]; if (im.field == null) { im.field = new IMsfield(); } im.field.userName = IMTB_2.Text; im.field.IMService = IMTypeCb_2.Text; } else { im = new IM(); im.field = new IMsfield(); im.field.userName = IMTB_2.Text; im.field.IMService = IMTypeCb_2.Text; lIM.Add(im); } } contact.IMs = lIM; //获取通讯地址 List <StreetAdr> lStreetAdr = contact.streetAddresses; if (AddrCountryTB_1.Text.Length > 0 || AddrProvinceTB_1.Text.Length > 0 || AddrCityTB_1.Text.Length > 0 || AddrStreetTB_1.Text.Length > 0) { if (lStreetAdr == null) { lStreetAdr = new List <StreetAdr>(); } StreetAdr streetAdr; if (lStreetAdr.Count > 0) { streetAdr = lStreetAdr[0]; streetAdr.label = AddrTypeCb_1.Text; if (streetAdr.field == null) { streetAdr.field = new StreetField(); } streetAdr.field.country = AddrCountryTB_1.Text; streetAdr.field.state = AddrProvinceTB_1.Text; streetAdr.field.city = AddrCityTB_1.Text; streetAdr.field.street = AddrStreetTB_1.Text; } else { streetAdr = new StreetAdr(); streetAdr.label = AddrTypeCb_1.Text; streetAdr.field = new StreetField(); streetAdr.field.country = AddrCountryTB_1.Text; streetAdr.field.state = AddrProvinceTB_1.Text; streetAdr.field.city = AddrCityTB_1.Text; streetAdr.field.street = AddrStreetTB_1.Text; lStreetAdr.Add(streetAdr); } } if (AddrCountryTB_2.Text.Length > 0 || AddrProvinceTB_2.Text.Length > 0 || AddrCityTB_2.Text.Length > 0 || AddrStreetTB_2.Text.Length > 0 || AddrZipTB_2.Text.Length > 0) { if (lStreetAdr == null) { lStreetAdr = new List <StreetAdr>(); } StreetAdr streetAdr; if (lStreetAdr.Count > 1) { streetAdr = lStreetAdr[1]; streetAdr.label = AddrTypeCb_2.Text; if (streetAdr.field == null) { streetAdr.field = new StreetField(); } streetAdr.field.country = AddrCountryTB_2.Text; streetAdr.field.state = AddrProvinceTB_2.Text; streetAdr.field.city = AddrCityTB_2.Text; streetAdr.field.street = AddrStreetTB_2.Text; } else { streetAdr = new StreetAdr(); streetAdr.label = AddrTypeCb_2.Text; streetAdr.field = new StreetField(); streetAdr.field.country = AddrCountryTB_2.Text; streetAdr.field.state = AddrProvinceTB_2.Text; streetAdr.field.city = AddrCityTB_2.Text; streetAdr.field.street = AddrStreetTB_2.Text; lStreetAdr.Add(streetAdr); } } //获取备注 if (noteTB.Text.Length > 0) { contact.notes = noteTB.Text; } return(contact); } catch (System.Exception ex) { Console.WriteLine(ex.StackTrace); } return(null); }
private void ResolveContact(Contact contact) { try { ClearInterfaceData(); string firstName = contact.firstName; string lastName = contact.lastName; FirstNameTB.Text = firstName; lastNameTB.Text = lastName; //解析电话号码 只暂时显示前两个 List <Phone> lPhone = contact.phones; for (int i = 0; lPhone != null && i < lPhone.Count; i++) { if (i == 0) { Phone phone = lPhone[0]; string strPhone = phone.field; string strLabel = phone.label; phoneNumTB_1.Text = strPhone; PhoneTypeCb_1.Text = strLabel; } else if (i == 1) { Phone phone = lPhone[1]; string strPhone = phone.field; string strLabel = phone.label; phoneNumTB_2.Text = strPhone; PhoneTypeCb_2.Text = strLabel; } else { break; } } //end of for //解析邮件 只暂时显示前两个 List <EmailAdr> lEmailAdr = contact.emailAddresses; for (int i = 0; lEmailAdr != null && i < lEmailAdr.Count; i++) { if (i == 0) { EmailAdr emailAdr = lEmailAdr[0]; string strEmail = emailAdr.field; string strLabel = emailAdr.label; EmailTB_1.Text = strEmail; EmailTypeCb_1.Text = strLabel; } else if (i == 1) { EmailAdr emailAdr = lEmailAdr[1]; string strEmail = emailAdr.field; string strLabel = emailAdr.label; EmailTB_2.Text = strEmail; EmailTypeCb_2.Text = strLabel; } else { break; } } //end of for //即时通讯 只暂时显示前两个 List <IM> lIM = contact.IMs; for (int i = 0; lIM != null && i < lIM.Count; i++) { if (i == 0) { IM im = lIM[0]; string strUserName = im.field.userName; string strIMService = im.field.IMService; IMTB_1.Text = strUserName; IMTypeCb_1.Text = strIMService; } else if (i == 1) { IM im = lIM[1]; string strUserName = im.field.userName; string strIMService = im.field.IMService; IMTB_2.Text = strUserName; IMTypeCb_2.Text = strIMService; } else { break; } } //end of for //通讯地址解析,只暂时显示前两个 List <StreetAdr> lStreetAdr = contact.streetAddresses; for (int i = 0; lStreetAdr != null && i < lStreetAdr.Count; i++) { if (i == 0) { StreetAdr streetAdr = lStreetAdr[0]; string strCountry = streetAdr.field.country; string strState = streetAdr.field.state; string strCity = streetAdr.field.city; string strStreet = streetAdr.field.street; string strLabel = streetAdr.label; AddrCountryTB_1.Text = strCountry; AddrProvinceTB_1.Text = strState; AddrCityTB_1.Text = strCity; AddrStreetTB_1.Text = strStreet; AddrTypeCb_1.Text = strLabel; } else if (i == 1) { StreetAdr streetAdr = lStreetAdr[1]; string strCountry = streetAdr.field.country; string strState = streetAdr.field.state; string strCity = streetAdr.field.city; string strStreet = streetAdr.field.street; string strLabel = streetAdr.label; AddrCountryTB_2.Text = strCountry; AddrProvinceTB_2.Text = strState; AddrCityTB_2.Text = strCity; AddrStreetTB_2.Text = strStreet; AddrTypeCb_2.Text = strLabel; } else { break; } } //解析备注 if (contact.notes != null) { noteTB.Text = contact.notes; } } catch (System.Exception ex) { Console.WriteLine(ex.StackTrace); } }
private Contact updateContactData(Contact contact) { try { //从界面获取数据更新到contact中 if (contact == null) { contact = new Contact(); } //获取姓名 if (FirstNameTB.Text.Length > 0) { contact.firstName = FirstNameTB.Text; } if (lastNameTB.Text.Length > 0) { contact.lastName = lastNameTB.Text; } //获取电话号码 List<Phone> lPhone = contact.phones; if (phoneNumTB_1.Text.Length > 0) { if (lPhone == null) { lPhone = new List<Phone>(); } Phone phone; if (lPhone.Count > 0) { phone = lPhone[0]; phone.field = phoneNumTB_1.Text; phone.label = PhoneTypeCb_1.Text; } else { phone = new Phone(); phone.field = phoneNumTB_1.Text; phone.label = PhoneTypeCb_1.Text; lPhone.Add(phone); } } if (phoneNumTB_2.Text.Length > 0) { if (lPhone == null) { lPhone = new List<Phone>(); } Phone phone; if (lPhone.Count > 1) { phone = lPhone[1]; phone.field = phoneNumTB_2.Text; phone.label = PhoneTypeCb_2.Text; } else { phone = new Phone(); phone.field = phoneNumTB_2.Text; phone.label = PhoneTypeCb_2.Text; lPhone.Add(phone); } } contact.phones = lPhone; //获取邮件地址 List<EmailAdr> lEmail = contact.emailAddresses; if (EmailTB_1.Text.Length > 0) { if (lEmail == null) { lEmail = new List<EmailAdr>(); } EmailAdr emailAdr; if (lEmail.Count > 0) { emailAdr = lEmail[0]; emailAdr.field = EmailTB_1.Text; emailAdr.label = EmailTypeCb_1.Text; } else { emailAdr = new EmailAdr(); emailAdr.field = EmailTB_1.Text; emailAdr.label = EmailTypeCb_1.Text; lEmail.Add(emailAdr); } } if (EmailTB_2.Text.Length > 0) { if (lEmail == null) { lEmail = new List<EmailAdr>(); } EmailAdr emailAdr; if (lEmail.Count > 1) { emailAdr = lEmail[1]; emailAdr.field = EmailTB_2.Text; emailAdr.label = EmailTypeCb_2.Text; } else { emailAdr = new EmailAdr(); emailAdr.field = EmailTB_2.Text; emailAdr.label = EmailTypeCb_2.Text; lEmail.Add(emailAdr); } } contact.emailAddresses = lEmail; //获取即时通讯 List<IM> lIM = contact.IMs; if (IMTB_1.Text.Length > 0) { if (lIM == null) { lIM = new List<IM>(); } IM im; if (lIM.Count > 0) { im = lIM[0]; if (im.field == null) { im.field = new IMsfield(); } im.field.userName = IMTB_1.Text; im.field.IMService = IMTypeCb_1.Text; } else { im = new IM(); im.field = new IMsfield(); im.field.userName = IMTB_1.Text; im.field.IMService = IMTypeCb_1.Text; lIM.Add(im); } } if (IMTB_2.Text.Length > 0) { if (lIM == null) { lIM = new List<IM>(); } IM im; if (lIM.Count > 1) { im = lIM[1]; if (im.field == null) { im.field = new IMsfield(); } im.field.userName = IMTB_2.Text; im.field.IMService = IMTypeCb_2.Text; } else { im = new IM(); im.field = new IMsfield(); im.field.userName = IMTB_2.Text; im.field.IMService = IMTypeCb_2.Text; lIM.Add(im); } } contact.IMs = lIM; //获取通讯地址 List<StreetAdr> lStreetAdr = contact.streetAddresses; if (AddrCountryTB_1.Text.Length > 0 || AddrProvinceTB_1.Text.Length > 0 || AddrCityTB_1.Text.Length > 0 || AddrStreetTB_1.Text.Length > 0) { if (lStreetAdr == null) { lStreetAdr = new List<StreetAdr>(); } StreetAdr streetAdr; if (lStreetAdr.Count > 0) { streetAdr = lStreetAdr[0]; streetAdr.label = AddrTypeCb_1.Text; if (streetAdr.field == null) { streetAdr.field = new StreetField(); } streetAdr.field.country = AddrCountryTB_1.Text; streetAdr.field.state = AddrProvinceTB_1.Text; streetAdr.field.city = AddrCityTB_1.Text; streetAdr.field.street = AddrStreetTB_1.Text; } else { streetAdr = new StreetAdr(); streetAdr.label = AddrTypeCb_1.Text; streetAdr.field = new StreetField(); streetAdr.field.country = AddrCountryTB_1.Text; streetAdr.field.state = AddrProvinceTB_1.Text; streetAdr.field.city = AddrCityTB_1.Text; streetAdr.field.street = AddrStreetTB_1.Text; lStreetAdr.Add(streetAdr); } } if (AddrCountryTB_2.Text.Length > 0 || AddrProvinceTB_2.Text.Length > 0 || AddrCityTB_2.Text.Length > 0 || AddrStreetTB_2.Text.Length > 0 || AddrZipTB_2.Text.Length > 0) { if (lStreetAdr == null) { lStreetAdr = new List<StreetAdr>(); } StreetAdr streetAdr; if (lStreetAdr.Count > 1) { streetAdr = lStreetAdr[1]; streetAdr.label = AddrTypeCb_2.Text; if (streetAdr.field == null) { streetAdr.field = new StreetField(); } streetAdr.field.country = AddrCountryTB_2.Text; streetAdr.field.state = AddrProvinceTB_2.Text; streetAdr.field.city = AddrCityTB_2.Text; streetAdr.field.street = AddrStreetTB_2.Text; } else { streetAdr = new StreetAdr(); streetAdr.label = AddrTypeCb_2.Text; streetAdr.field = new StreetField(); streetAdr.field.country = AddrCountryTB_2.Text; streetAdr.field.state = AddrProvinceTB_2.Text; streetAdr.field.city = AddrCityTB_2.Text; streetAdr.field.street = AddrStreetTB_2.Text; lStreetAdr.Add(streetAdr); } } //获取备注 if (noteTB.Text.Length > 0) { contact.notes = noteTB.Text; } return contact; } catch (System.Exception ex) { Console.WriteLine(ex.StackTrace); } return null; }