private async void TxtCVR_EditValueChanged(object sender, DevExpress.Xpf.Editors.EditValueChangedEventArgs e) { var s = sender as TextEditor; if (s != null && s.IsLoaded) { var cvr = s.Text?.Trim(); if (cvr == null || cvr.Length < 5) { return; } var allIsLetter = cvr.All(x => char.IsLetter(x)); if (allIsLetter) { return; } CompanyInfo ci = null; try { #if !SILVERLIGHT ci = await CVR.CheckCountry(cvr, editrow._Country); #else var lookupApi = new Uniconta.API.System.UtilityAPI(api); ci = await lookupApi.LookupCVR(cvr, editrow._Country); #endif } catch (Exception ex) { UnicontaMessageBox.Show(ex); return; } if (!onlyRunOnce) { if (ci == null) { return; } if (!string.IsNullOrWhiteSpace(ci?.life?.name)) { var address = ci.address; if (address != null) { var streetAddress = address.CompleteStreet; if (ci.life.name == editrow._Name && streetAddress == editrow._Address1 && address.zipcode == editrow._ZipCode) { return; // we wil not override since address has not changed } onlyRunOnce = true; if (editrow._Address1 == null) { editrow.Address1 = address.CompleteStreet; editrow.ZipCode = address.zipcode; editrow.City = address.cityname; editrow.Country = address.Country; } else { var result = UnicontaMessageBox.Show(Uniconta.ClientTools.Localization.lookup("UpdateAddress"), Uniconta.ClientTools.Localization.lookup("Information"), UnicontaMessageBox.YesNo); if (result != UnicontaMessageBox.Yes) { return; } { editrow.Address1 = address.CompleteStreet; editrow.ZipCode = address.zipcode; editrow.City = address.cityname; editrow.Country = address.Country; } } } if (string.IsNullOrWhiteSpace(editrow._Name)) { editrow.Name = ci.life.name; } var contact = ci.contact; if (contact != null) { editrow.Phone = contact.phone; editrow.ContactEmail = contact.email; editrow.Www = contact.www; } } } else { onlyRunOnce = false; } } }
private async void txtCVR_OnEditValueChanged(object sender, EditValueChangedEventArgs e) { var s = sender as TextEditor; if (s != null && s.IsLoaded) { var cvr = s.Text?.Trim(); if (cvr == null || cvr.Length < 5) { return; } var allIsLetter = cvr.All(x => char.IsLetter(x)); if (allIsLetter) { return; } CompanyInfo ci = null; try { #if !SILVERLIGHT ci = await CVR.CheckCountry(cvr, editrow.Country); #else var lookupApi = new Uniconta.API.System.UtilityAPI(api); ci = await lookupApi.LookupCVR(cvr, editrow.Country); #endif } catch (Exception ex) { UnicontaMessageBox.Show(ex); return; } if (!onlyRunOnce) { if (ci == null) { return; } if (!string.IsNullOrWhiteSpace(ci?.life?.name)) { var address = ci.address; if (address != null) { onlyRunOnce = true; var streetAddress = address.CompleteStreet; if (string.IsNullOrWhiteSpace(editrow.Address1)) { editrow.Address1 = streetAddress; editrow.Address2 = address.ZipCity; editrow.Country = address.Country; } else { var result = UnicontaMessageBox.Show(Uniconta.ClientTools.Localization.lookup("UpdateAddress"), Uniconta.ClientTools.Localization.lookup("Information"), UnicontaMessageBox.YesNo); if (result != UnicontaMessageBox.Yes) { return; } { editrow.Address1 = streetAddress; editrow.Address2 = address.ZipCity; editrow.Country = address.Country; } } } if (string.IsNullOrWhiteSpace(editrow._Name)) { editrow._Name = ci.life.name; } if (!string.IsNullOrEmpty(ci.contact?.phone)) { editrow.Phone = ci.contact.phone; } } } else { onlyRunOnce = false; } } }