CsvDataConnection.DesignExt.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using System;
  2. using System.Data;
  3. using System.IO;
  4. using System.Net;
  5. using FastReport.Data.ConnectionEditors;
  6. using FastReport.Utils;
  7. namespace FastReport.Data
  8. {
  9. partial class CsvDataConnection
  10. {
  11. #region Public Methods
  12. /// <inheritdoc/>
  13. public override void TestConnection()
  14. {
  15. using (DataSet dataset = CreateDataSet())
  16. {
  17. }
  18. }
  19. /// <inheritdoc/>
  20. public override ConnectionEditorBase GetEditor()
  21. {
  22. return new CsvConnectionEditor();
  23. }
  24. /// <inheritdoc/>
  25. public override string GetConnectionId()
  26. {
  27. return "Csv: " + CsvFile;
  28. }
  29. #endregion Public Methods
  30. #region Private Methods
  31. /// <inheritdoc/>
  32. private string CheckForChangeConnection(CsvConnectionStringBuilder builder)
  33. {
  34. RelatedPathCheck(builder);
  35. if (File.Exists(builder.CsvFile))
  36. {
  37. ConnectionString = builder.ToString();
  38. return ConnectionString;
  39. }
  40. else
  41. {
  42. // added a check for the existence of a file when it is changed in the connection string in the properties (the CsvFile property)
  43. // from the local path to the uri.
  44. // the data in the table changes, but the name and list of fields on the "Data" tab do not change
  45. // the same thing happens when changing from a local path to another local path
  46. Uri uri = new Uri(builder.CsvFile);
  47. WebRequest request = WebRequest.Create(uri);
  48. try
  49. {
  50. using (WebResponse response = request.GetResponse())
  51. {
  52. ConnectionString = builder.ToString();
  53. return ConnectionString;
  54. }
  55. }
  56. catch
  57. {
  58. builder.CsvFile = ConnectionString;
  59. FRMessageBox.Error(Res.Get("ConnectionEditors,Common,ErrorUrlException"));
  60. return ConnectionString;
  61. }
  62. }
  63. }
  64. #endregion Private Methods
  65. }
  66. }