public void LoadNewAttendanceInfo() { DatabaseAccess dba = DatabaseAccessFactory.CreateDatabase(); using (var conn = dba.GetOpenConnection()) { DateTime?lastDate = GetLastDate(dba); try { using (IdentityScope iss = new IdentityScope(userName, password, ip)) { CheckHistoryDirectory(); DirectoryInfo directory = new DirectoryInfo(directoryPath); FileInfo[] files = directory.GetFiles(); /* * if (lastDate != null) * { * DateTime now = DateTime.Now; * now = now.AddHours(-now.Hour) * .AddMinutes(-now.Minute) * .AddSeconds(-now.Second) * .AddMilliseconds(-now.Millisecond); * DateTime last = lastDate.Value; * last = last.AddHours(-last.Hour) * .AddMinutes(-last.Minute) * .AddSeconds(-last.Second) * .AddMilliseconds(-last.Millisecond); * //因为每天只能读取前一天的数据,所以数据库中的时间比文件名时间早一天 * last = last.AddDays(1); * int days = (now - last).Days; * if (days == 0) * { * return; * } * * string[] dateArray = new string[days]; * string dateFormat = "yyyyMMdd"; * for (int i = 1; i <= days; i++) * { * dateArray[i - 1] = last.AddDays(i).ToString(dateFormat); * } * files = files.Where(f => dateArray.Any(d => f.Name.StartsWith(d))).ToArray(); * } */ foreach (FileInfo file in files) { SaveAttendanceInfo(file, dba); MoveToHistory(file); } } } catch (Exception e) { Logger.Error(e.Message, e); } } }
static ApplicationSettingsDataProvider GetProvider(DatabaseAccess dba) { ApplicationSettingsDataProvider dataProvider = null; if (DatabaseAccessFactory.IsSQLServer(dba)) { dataProvider = new SqlSettingsDataProvider(); } if (dataProvider != null) { dataProvider.DatabaseAccess = dba; } return(dataProvider); }
public static ApplicationSettingsDataProvider GetProvider(string connectionStringName) { DatabaseAccess dba = DatabaseAccessFactory.CreateDatabase(connectionStringName); return(GetProvider(dba)); }
public static ApplicationSettingsDataProvider GetProvider() { DatabaseAccess dba = DatabaseAccessFactory.CreateDatabase(); return(GetProvider(dba)); }