CsvConnectionStringBuilder.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. using System.Text;
  2. using System.Data.Common;
  3. using System.Globalization;
  4. namespace FastReport.Data
  5. {
  6. /// <summary>
  7. /// Represents the CsvDataConnection connection string builder.
  8. /// </summary>
  9. /// <remarks>
  10. /// Use this class to parse connection string returned by the <b>CsvDataConnection</b> class.
  11. /// </remarks>
  12. public class CsvConnectionStringBuilder : DbConnectionStringBuilder
  13. {
  14. #region Properties
  15. /// <summary>
  16. /// Gets or sets the path to .csv file.
  17. /// </summary>
  18. public string CsvFile
  19. {
  20. get
  21. {
  22. object csvFile;
  23. if (TryGetValue("CsvFile", out csvFile))
  24. {
  25. return (string)csvFile;
  26. }
  27. return "";
  28. }
  29. set { base["CsvFile"] = value; }
  30. }
  31. /// <summary>
  32. /// Gets or sets the codepage of .csv file.
  33. /// </summary>
  34. public int Codepage
  35. {
  36. get
  37. {
  38. object codepage;
  39. if (TryGetValue("Codepage", out codepage))
  40. {
  41. return int.Parse((string)codepage);
  42. }
  43. return Encoding.Default.CodePage;
  44. }
  45. set { base["Codepage"] = value; }
  46. }
  47. /// <summary>
  48. /// Gets or sets the separator.
  49. /// </summary>
  50. public string Separator
  51. {
  52. get
  53. {
  54. object separator;
  55. if (TryGetValue("Separator", out separator))
  56. {
  57. return (string)separator;
  58. }
  59. return ";";
  60. }
  61. set { base["Separator"] = value; }
  62. }
  63. /// <summary>
  64. /// Gets or sets the value indicating that field names should be loaded from the first string of the file.
  65. /// </summary>
  66. public bool FieldNamesInFirstString
  67. {
  68. get
  69. {
  70. object fieldNamesInFirstString;
  71. if (TryGetValue("FieldNamesInFirstString", out fieldNamesInFirstString))
  72. {
  73. return fieldNamesInFirstString.ToString().ToLower() == "true";
  74. }
  75. return false;
  76. }
  77. set { base["FieldNamesInFirstString"] = value.ToString().ToLower(); }
  78. }
  79. /// <summary>
  80. /// Gets or sets the value indicating that quotation marks should be removed.
  81. /// </summary>
  82. public bool RemoveQuotationMarks
  83. {
  84. get
  85. {
  86. object removeQuotationMarks;
  87. if (TryGetValue("RemoveQuotationMarks", out removeQuotationMarks))
  88. {
  89. return removeQuotationMarks.ToString().ToLower() == "true";
  90. }
  91. return true;
  92. }
  93. set { base["RemoveQuotationMarks"] = value.ToString().ToLower(); }
  94. }
  95. /// <summary>
  96. /// Gets or sets the value indicating that field types should be converted.
  97. /// </summary>
  98. public bool ConvertFieldTypes
  99. {
  100. get
  101. {
  102. object convertFieldTypes;
  103. if (TryGetValue("ConvertFieldTypes", out convertFieldTypes))
  104. {
  105. return convertFieldTypes.ToString().ToLower() == "true";
  106. }
  107. return true;
  108. }
  109. set { base["ConvertFieldTypes"] = value.ToString().ToLower(); }
  110. }
  111. /// <summary>
  112. /// Gets or sets locale name used to auto-convert numeric fields, e.g. "en-US".
  113. /// </summary>
  114. public string NumberFormat
  115. {
  116. get
  117. {
  118. object numberFormat;
  119. if (TryGetValue("NumberFormat", out numberFormat))
  120. {
  121. return numberFormat.ToString();
  122. }
  123. return CultureInfo.CurrentCulture.Name;
  124. }
  125. set { base["NumberFormat"] = value; }
  126. }
  127. /// <summary>
  128. /// Gets or sets locale name used to auto-convert currency fields, e.g. "en-US".
  129. /// </summary>
  130. public string CurrencyFormat
  131. {
  132. get
  133. {
  134. object currencyFormat;
  135. if (TryGetValue("CurrencyFormat", out currencyFormat))
  136. {
  137. return currencyFormat.ToString();
  138. }
  139. return CultureInfo.CurrentCulture.Name;
  140. }
  141. set { base["CurrencyFormat"] = value; }
  142. }
  143. /// <summary>
  144. /// Gets or sets locale name used to auto-convert datetime fields, e.g. "en-US".
  145. /// </summary>
  146. public string DateTimeFormat
  147. {
  148. get
  149. {
  150. object dateTimeFormat;
  151. if (TryGetValue("DateTimeFormat", out dateTimeFormat))
  152. {
  153. return dateTimeFormat.ToString();
  154. }
  155. return CultureInfo.CurrentCulture.Name;
  156. }
  157. set { base["DateTimeFormat"] = value; }
  158. }
  159. #endregion Properties
  160. #region Constructors
  161. /// <summary>
  162. /// Initializes a new instance of the <see cref="CsvConnectionStringBuilder"/> class.
  163. /// </summary>
  164. public CsvConnectionStringBuilder()
  165. {
  166. ConnectionString = "";
  167. }
  168. /// <summary>
  169. /// Initializes a new instance of the <see cref="CsvConnectionStringBuilder"/> class with a specified connection string.
  170. /// </summary>
  171. /// <param name="connectionString">The connection string.</param>
  172. public CsvConnectionStringBuilder(string connectionString) : base()
  173. {
  174. ConnectionString = connectionString;
  175. }
  176. #endregion Constructors
  177. }
  178. }