public static void ManageRecord(HtmlFormPost f, string xml) { int i; var exists = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); var count = int.Parse(f.Values["phonecnt"]); for (i = 1; i <= count; i++) { exists.Add(f.Values[$"phone_{i}"], f.Values[$"phoneKey_{i}"]); f.Remove($"phoneKey_{i}", $"phone_{i}", $"cntPhoneType_{i}", $"primaryPhone_{i}"); } i = 0; var xml2 = XDocument.Parse($"<r>{xml}</r>"); var typeOptions = f.Selects[$"cntPhoneType_0"].ToDictionary(x => x.Value, x => x.Key); foreach (var item in xml2.Descendants("n")) { i++; var(phone, phoneType, primaryIndicator) = (item.Attributes("pn").FirstOrDefault()?.Value, item.Attributes("pt").FirstOrDefault()?.Value, item.Attributes("pi").FirstOrDefault()?.Value == "Y"); if (exists.TryGetValue(phone, out var exist)) { exists.Remove(phone); f.Add($"phoneKey_{i}", "hidden", exist); } f.Add($"phone_{i}", "text", phone); f.Add($"cntPhoneType_{i}", "select", typeOptions.TryGetValue(phoneType, out var option) ? option : null); f.Add($"primaryPhone_{i}", "checkbox", "true", primaryIndicator); } f.Values["phonecnt"] = $"{i}"; }
/// <summary> /// Runs the report. /// </summary> /// <param name="report">The report.</param> /// <param name="action">The action.</param> /// <param name="executeFolder">The execute folder.</param> /// <param name="interceptFilename">The intercept filename.</param> /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns> /// <exception cref="InvalidOperationException">unexpected form action returned from unanet</exception> public async Task <bool> RunReportAsync(string report, Action <HtmlFormPost> action, string executeFolder, Func <string, string> interceptFilename = null) { string body, url; // parse { var d0 = await this.TryFuncAsync(() => this.DownloadDataAsync(HttpMethod.Get, $"{UmbUri}/{report}")).ConfigureAwait(false); if (d0.IndexOf("Session Expired") != -1) { throw new LoginRequiredException(); } var d1 = d0.ExtractSpan("<form name=\"parameterForm\"", "</form>"); if (string.IsNullOrEmpty(d1)) { throw new InvalidOperationException("Report error"); } var htmlForm = new HtmlFormPost(d1); action(htmlForm); body = htmlForm.ToString(); url = $"{UmbUri}/{Path.GetDirectoryName(report)}/{htmlForm.Action}"; } // download { var d0 = await this.TryFuncAsync(() => this.DownloadFileAsync(executeFolder, HttpMethod.Get, url, body, interceptFilename : interceptFilename)).ConfigureAwait(false); return(!string.IsNullOrEmpty(d0)); } }
public static void ManageRecord(HtmlFormPost f, string xml) { int i; var exists = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); var count = int.Parse(f.Values["addresscnt"]); for (i = 1; i <= count; i++) { exists.Add(f.Values[$"street_{i}"], f.Values[$"streetKey_{i}"]); f.Remove($"streetKey_{i}", $"street_{i}", $"city_{i}", $"state_province_{i}", $"postal_code_{i}", $"country_{i}", $"cntAddressType_{i}", $"primaryAddress_{i}"); } i = 0; var xml2 = XDocument.Parse($"<r>{xml}</r>"); var typeOptions = f.Selects[$"cntAddressType_0"].ToDictionary(x => x.Value, x => x.Key); foreach (var item in xml2.Descendants("a")) { i++; var(street, city, state_province, postal_code, country, addressType, primaryIndicator) = ( item.Attributes("sa").FirstOrDefault()?.Value, item.Attributes("c").FirstOrDefault()?.Value, item.Attributes("sp").FirstOrDefault()?.Value, item.Attributes("pc").FirstOrDefault()?.Value, item.Attributes("c").FirstOrDefault()?.Value, item.Attributes("at").FirstOrDefault()?.Value, item.Attributes("pi").FirstOrDefault()?.Value == "Y"); if (exists.TryGetValue(street, out var exist)) { exists.Remove(street); f.Add($"streetKey_{i}", "hidden", exist); } f.Add($"street_{i}", "text", street); f.Add($"city_{i}", "text", city); f.Add($"state_province_{i}", "text", state_province); f.Add($"postal_code_{i}", "text", postal_code); f.Add($"country_{i}", "text", country); f.Add($"cntAddressType_{i}", "select", typeOptions.TryGetValue(addressType, out var option) ? option : null); f.Add($"primaryAddress_{i}", "checkbox", "true", primaryIndicator); } f.Values["addresscnt"] = $"{i}"; }