/// <summary>
 /// Build import target for a local single file import.
 /// </summary>
 /// <param name="option">A single file option</param>
 /// <param name="needUpdate">If records with same business PK, set to true; if only need insert, set to false.</param>
 /// <param name="targetTableName">The table name the csv should import to</param>
 /// <param name="columns">The table columns</param>
 /// <param name="keyColumns">The business PK columns</param>
 /// <returns></returns>
 public static SingleFileImportOption BuildImportTarget(this SingleFileImportOption option, bool needUpdate, string targetTableName, List <string> columns, List <string> keyColumns)
 {
     option.ImportTargetOption.NeedUpdate      = needUpdate;
     option.ImportTargetOption.KeyColumns      = keyColumns;
     option.ImportTargetOption.TargetTableName = targetTableName;
     option.ImportTargetOption.Columns         = columns;
     return(option);
 }
        /// <summary>
        /// Create an Importer instance
        /// </summary>
        /// <param name="singleFileImportOption">A single file import option</param>
        /// <returns>Importer instance</returns>
        public static Importer CreateInstance(SingleFileImportOption singleFileImportOption)
        {
            Importer importer = null;

            switch (singleFileImportOption.DatabaseConnectOption.DatabaseType)
            {
            case Enum.DatabaseType.SQLServer:
                importer = new SqlServerImporter(singleFileImportOption);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            return(importer);
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            var columns = "Id,ApplicationNumber,OverdueDays,AveOverdueDays,OverdueLevel,OverdueMoney,OverduePeriods,HavePayPeriods,FinancingMaturity,TheHightOverduePeriods,TotalOverduePeriods,RemitDays,OverdueStatus,RiskLevel,FiveLevelClass,IsOverdueNow,CarAge,RedBookOfSecondHand,SaleActualSurplusMoney,SaleCurrentSurplusMoney,DQSYZJ,FinancialActualSurplusMoney,FinancialCurrentSurplusMoney,DisposalAssessmentAmount,DisposalAmount,CLSFSH,VehicleRecyclingNotice,ElectricityStatus,ElectricityOperate,LitigationStatus,LitigationOperators,LitigationDate,FamilyVisitState,HomeVisitsOperator,FamilyVisitApplicationDate,CollectState,CollectOperator,CollectApplicationDate,VehicleDisposalStatus,VehicleDisposalOperator,VehicleDisposalApplicationDate,ChargeOffStatus,ChargeOffApplicationDate,ChargeOffMoney,ChargeOffOperate,YQRQ".Split(',').ToList();
            var keys    = new List <string>()
            {
                "ApplicationNumber"
            };
            var connectionString = "data source=.;initial catalog=sa;persist security info=True;user id=dht_test;password=123456;MultipleActiveResultSets=True;";

            var singleFileImportOption = new SingleFileImportOption()
                                         .BuildDatabaseConnect(DatabaseType.SQLServer, connectionString)
                                         .BuildImportTarget(true, "OverdueInfo", columns, keys)
                                         .BuildLocalFileSource(@"E:\OverdueInfo.csv");
            var importer = ImporterFactory.CreateInstance(singleFileImportOption);

            importer.Import();
        }
Beispiel #4
0
 public Importer(SingleFileImportOption singleFileImportOption)
 {
     _singleFileImportOption = singleFileImportOption;
     _singleFileImportOption.Validate();
     _streamer = StreamerFactory.CreateInstance(singleFileImportOption.FileSourceOption.FileSourceType);
 }
 public SqlServerImporter(SingleFileImportOption singleFileImportOption) : base(singleFileImportOption)
 {
 }
 /// <summary>
 /// Build data base connect for a local single file import.
 /// </summary>
 /// <param name="option">A single file option</param>
 /// <param name="databaseType">The database type</param>
 /// <param name="connectionString">The connetion string</param>
 /// <returns>SingleFileImportOption</returns>
 public static SingleFileImportOption BuildDatabaseConnect(this SingleFileImportOption option, DatabaseType databaseType, string connectionString)
 {
     option.DatabaseConnectOption.DatabaseType     = databaseType;
     option.DatabaseConnectOption.ConnectionString = connectionString;
     return(option);
 }
 /// <summary>
 /// Build a local single file source option for import.
 /// </summary>
 /// <param name="option">A single file option</param>
 /// <param name="filePath">The file path of local file</param>
 /// <returns>SingleFileImportOption</returns>
 public static SingleFileImportOption BuildLocalFileSource(this SingleFileImportOption option, string filePath)
 {
     option.FileSourceOption = new LocalFileSourceOption(filePath);
     return(option);
 }