using System.Text; using System.Data.Common; using System.Globalization; namespace FastReport.Data { /// /// Represents the CsvDataConnection connection string builder. /// /// /// Use this class to parse connection string returned by the CsvDataConnection class. /// public class CsvConnectionStringBuilder : DbConnectionStringBuilder { #region Properties /// /// Gets or sets the path to .csv file. /// public string CsvFile { get { object csvFile; if (TryGetValue("CsvFile", out csvFile)) { return (string)csvFile; } return ""; } set { base["CsvFile"] = value; } } /// /// Gets or sets the codepage of .csv file. /// public int Codepage { get { object codepage; if (TryGetValue("Codepage", out codepage)) { return int.Parse((string)codepage); } return Encoding.Default.CodePage; } set { base["Codepage"] = value; } } /// /// Gets or sets the separator. /// public string Separator { get { object separator; if (TryGetValue("Separator", out separator)) { return (string)separator; } return ";"; } set { base["Separator"] = value; } } /// /// Gets or sets the value indicating that field names should be loaded from the first string of the file. /// public bool FieldNamesInFirstString { get { object fieldNamesInFirstString; if (TryGetValue("FieldNamesInFirstString", out fieldNamesInFirstString)) { return fieldNamesInFirstString.ToString().ToLower() == "true"; } return false; } set { base["FieldNamesInFirstString"] = value.ToString().ToLower(); } } /// /// Gets or sets the value indicating that quotation marks should be removed. /// public bool RemoveQuotationMarks { get { object removeQuotationMarks; if (TryGetValue("RemoveQuotationMarks", out removeQuotationMarks)) { return removeQuotationMarks.ToString().ToLower() == "true"; } return true; } set { base["RemoveQuotationMarks"] = value.ToString().ToLower(); } } /// /// Gets or sets the value indicating that field types should be converted. /// public bool ConvertFieldTypes { get { object convertFieldTypes; if (TryGetValue("ConvertFieldTypes", out convertFieldTypes)) { return convertFieldTypes.ToString().ToLower() == "true"; } return true; } set { base["ConvertFieldTypes"] = value.ToString().ToLower(); } } /// /// Gets or sets locale name used to auto-convert numeric fields, e.g. "en-US". /// public string NumberFormat { get { object numberFormat; if (TryGetValue("NumberFormat", out numberFormat)) { return numberFormat.ToString(); } return CultureInfo.CurrentCulture.Name; } set { base["NumberFormat"] = value; } } /// /// Gets or sets locale name used to auto-convert currency fields, e.g. "en-US". /// public string CurrencyFormat { get { object currencyFormat; if (TryGetValue("CurrencyFormat", out currencyFormat)) { return currencyFormat.ToString(); } return CultureInfo.CurrentCulture.Name; } set { base["CurrencyFormat"] = value; } } /// /// Gets or sets locale name used to auto-convert datetime fields, e.g. "en-US". /// public string DateTimeFormat { get { object dateTimeFormat; if (TryGetValue("DateTimeFormat", out dateTimeFormat)) { return dateTimeFormat.ToString(); } return CultureInfo.CurrentCulture.Name; } set { base["DateTimeFormat"] = value; } } #endregion Properties #region Constructors /// /// Initializes a new instance of the class. /// public CsvConnectionStringBuilder() { ConnectionString = ""; } /// /// Initializes a new instance of the class with a specified connection string. /// /// The connection string. public CsvConnectionStringBuilder(string connectionString) : base() { ConnectionString = connectionString; } #endregion Constructors } }