public bool UpdateConfig(Config config) { System.Data.OleDb.OleDbCommand odCom1 = BuildUpdateCmd("Config", new string[] { "ScheduledBackup" ,"BackupPeriod" ,"BackupDay" ,"BackupTime" ,"BackupFolder" ,"BackupRemind" ,"BackupRemindPeriod" ,"LastestBackup" ,"LastestBackupFile" ,"RestoreFromLatest" ,"RestoreFromFile" ,"AttendanceRecordInterval" ,"RecordRoundingValue" }, new object[] { config.ScheduledBackup ,config.BackupPeriod ,config.BackupDay ,config.BackupTime ,config.BackupFolder ,config.BackupRemind ,config.BackupRemindPeriod ,config.LastestBackup ,config.LastestBackupFile ,config.RestoreFromLatest ,config.RestoreFromFile ,config.AttendanceRecordInterval ,config.RecordRoundingValue }, "ID=@ID", new object[] { "@ID", config.ID } ); return odCom1.ExecuteNonQuery() > 0 ? true : false; }
private int AddConfig(Config config) { System.Data.OleDb.OleDbCommand odCom1 = BuildInsertCmd("Config", new string[] { "ScheduledBackup" ,"BackupPeriod" ,"BackupDay" ,"BackupTime" ,"BackupFolder" ,"BackupRemind" ,"BackupRemindPeriod" ,"LastestBackup" ,"LastestBackupFile" ,"RestoreFromLatest" ,"RestoreFromFile" ,"AttendanceRecordInterval" ,"RecordRoundingValue" }, new object[] { config.ScheduledBackup ,config.BackupPeriod ,config.BackupDay ,config.BackupTime ,config.BackupFolder ,config.BackupRemind ,config.BackupRemindPeriod ,config.LastestBackup ,config.LastestBackupFile ,config.RestoreFromLatest ,config.RestoreFromFile ,config.AttendanceRecordInterval ,config.RecordRoundingValue } ); if (odCom1.ExecuteNonQuery() == 1) { odCom1.CommandText = "SELECT @@IDENTITY"; return (int)odCom1.ExecuteScalar(); } return -1; }
public Config GetConfig() { OleDbCommand odCom = BuildSelectCmd("Config", "TOP 1 *", "1=1"); OleDbDataReader odRdr = odCom.ExecuteReader(); Config config = null; if (odRdr.Read()) { config = new Config(); config.ID = (int)odRdr["ID"]; config.ScheduledBackup = Convert.ToBoolean(odRdr["ScheduledBackup"]); config.BackupPeriod = (int)odRdr["BackupPeriod"]; config.BackupDay = (int)odRdr["BackupDay"]; config.BackupTime = odRdr["BackupTime"].GetType() != typeof(DBNull) ? Convert.ToDateTime(odRdr["BackupTime"]) : Config.MinDate; config.BackupFolder = odRdr["BackupFolder"].ToString(); config.BackupRemind = Convert.ToBoolean(odRdr["BackupRemind"]); config.BackupRemindPeriod = (int)odRdr["BackupRemindPeriod"]; config.LastestBackup = odRdr["LastestBackup"].GetType() != typeof(DBNull) ? Convert.ToDateTime(odRdr["LastestBackup"]) : Config.MinDate; config.LastestBackupFile = odRdr["LastestBackupFile"].ToString(); config.RestoreFromLatest = Convert.ToBoolean(odRdr["RestoreFromLatest"]); config.RestoreFromFile = odRdr["RestoreFromFile"].ToString(); config.AttendanceRecordInterval = (int)odRdr["AttendanceRecordInterval"]; config.RecordRoundingValue = (int)odRdr["RecordRoundingValue"]; } else { config = new Config(); config.BackupFolder = ""; config.RestoreFromFile = ""; config.LastestBackupFile = ""; config.BackupPeriod = 1; config.BackupRemindPeriod = 1; config.AttendanceRecordInterval = 5; config.RecordRoundingValue = 10; config.LastestBackup = DateTime.Now; AddConfig(config); return GetConfig(); } odRdr.Close(); return config; }