private void BtnGo_Click(object sender, EventArgs e) { try { this.Enabled = false; this.UseWaitCursor = true; Cursor.Current = Cursors.WaitCursor; if (string.IsNullOrWhiteSpace(txtAccountNumber.Text) || string.IsNullOrWhiteSpace(txtAWBNumber.Text)) { MessageBox.Show(@"Missing data."); return; } txtAccountNumber.Text = txtAccountNumber.Text.Trim(); txtAWBNumber.Text = txtAWBNumber.Text.Trim(); GloWS glows = new GloWS(Common.username, Common.password, (Common.IsProduction ? Common.restProductionBaseUrl : Common.restTestingBaseUrl)); EPodResponse ePod = glows.GetEPod(txtAWBNumber.Text , txtAccountNumber.Text // ReSharper disable once PossibleInvalidCastException , (Enums.EPodType)cmbPODType.SelectedItem); _lastJsonRequest = glows.LastJSONRequest; _lastJsonResponse = glows.LastJSONResponse; if (null != ePod) { string tempFilename = System.IO.Path.GetTempFileName(); System.IO.File.WriteAllBytes(tempFilename, ePod.EPod.Image); System.Diagnostics.Process.Start(tempFilename); } } catch (GloWSValidationException gvx) { txtResult.Text = GloWSValidationException.PrintResults(gvx.ExtractValidationResults(), 0); } catch (Exception ex) { txtResult.Text = ex.Message; } finally { this.Enabled = true; this.UseWaitCursor = false; Cursor.Current = Cursors.Default; } }
private void BtnGo_Click(object sender, EventArgs e) { try { this.Enabled = false; this.UseWaitCursor = true; Cursor.Current = Cursors.WaitCursor; if (string.IsNullOrWhiteSpace(txtAccountNumber.Text) || string.IsNullOrWhiteSpace(txtAWBNumber.Text)) { MessageBox.Show(@"Missing data."); return; } txtAccountNumber.Text = txtAccountNumber.Text.Trim(); txtAWBNumber.Text = txtAWBNumber.Text.Trim(); MyDHLAPI api = new MyDHLAPI(Common.CurrentCredentials["Username"] , Common.CurrentCredentials["Password"] , Common.CurrentRestBaseUrl); EPodResponse ePod = api.GetEPod(txtAWBNumber.Text , txtAccountNumber.Text // ReSharper disable once PossibleInvalidCastException , (Enums.EPodType)cmbPODType.SelectedItem); _lastJsonRequest = api.LastEPoDJSONRequest; _lastJsonResponse = api.LastEPoDJSONResponse; if (null != ePod && null != ePod.EPod) { string tempFilename = System.IO.Path.GetTempFileName(); switch (ePod.EPod.MimeType) { case "application/pdf": tempFilename += ".pdf"; break; case "image/jpeg": case "image/jpg": tempFilename += ".jpg"; break; case "image/png": tempFilename += ".png"; break; } System.IO.File.WriteAllBytes(tempFilename, ePod.EPod.Image); System.Diagnostics.Process.Start(tempFilename); } else { txtResult.Text = "ePOD not found for the supplied AWB # and Account # combination."; } } catch (MyDHLAPIValidationException gvx) { txtResult.Text = MyDHLAPIValidationException.PrintResults(gvx.ExtractValidationResults(), 0); } catch (Exception ex) { txtResult.Text = ex.Message; } finally { this.Enabled = true; this.UseWaitCursor = false; Cursor.Current = Cursors.Default; } }