public void Import() { if ( !AppConfig.IsImportable) throw new BizException("Is Importable is false"); string sql = " select top 1 * from Sys_Sync "; DataSet ds = SqlHelper.ExecuteDataSet(sql); if ( Util.HasMoreRow(ds) ) throw new BizException("the table Sync is not empty"); TransactionOptions options = new TransactionOptions(); options.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted; options.Timeout = TransactionManager.DefaultTimeout; using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, options)) { SortedList sl = AppEnum.GetSync(); foreach(int syncType in sl.Keys) { SyncInfo oInfo = new SyncInfo(); oInfo.SyncType = syncType; oInfo.LastVersionTime = DateTime.Now; new SyncDac().Insert(oInfo); } scope.Complete(); } }
public int Insert(SyncInfo oParam) { string sql = @"INSERT INTO Sys_Sync ( SyncType, LastVersionTime ) VALUES ( @SyncType, @LastVersionTime );set @SysNo = SCOPE_IDENTITY();"; SqlCommand cmd = new SqlCommand(sql); SqlParameter paramSysNo = new SqlParameter("@SysNo", SqlDbType.Int,4); SqlParameter paramSyncType = new SqlParameter("@SyncType", SqlDbType.Int,4); SqlParameter paramLastVersionTime = new SqlParameter("@LastVersionTime", SqlDbType.DateTime); paramSysNo.Direction = ParameterDirection.Output; if ( oParam.SyncType != AppConst.IntNull) paramSyncType.Value = oParam.SyncType; else paramSyncType.Value = System.DBNull.Value; if ( oParam.LastVersionTime != AppConst.DateTimeNull) paramLastVersionTime.Value = oParam.LastVersionTime; else paramLastVersionTime.Value = System.DBNull.Value; cmd.Parameters.Add(paramSysNo); cmd.Parameters.Add(paramSyncType); cmd.Parameters.Add(paramLastVersionTime); return SqlHelper.ExecuteNonQuery(cmd, out oParam.SysNo); }
public int Update(SyncInfo oParam) { string sql = @"UPDATE Sys_Sync SET LastVersionTime=@LastVersionTime WHERE SyncType=@SyncType"; SqlCommand cmd = new SqlCommand(sql); SqlParameter paramSyncType = new SqlParameter("@SyncType", SqlDbType.Int,4); SqlParameter paramLastVersionTime = new SqlParameter("@LastVersionTime", SqlDbType.DateTime); if ( oParam.SyncType != AppConst.IntNull) paramSyncType.Value = oParam.SyncType; else paramSyncType.Value = System.DBNull.Value; if ( oParam.LastVersionTime != AppConst.DateTimeNull) paramLastVersionTime.Value = oParam.LastVersionTime; else paramLastVersionTime.Value = System.DBNull.Value; cmd.Parameters.Add(paramSyncType); cmd.Parameters.Add(paramLastVersionTime); return SqlHelper.ExecuteNonQuery(cmd); }
private void map(SyncInfo oParam, DataRow tempdr) { oParam.SysNo = Util.TrimIntNull(tempdr["SysNo"]); oParam.SyncType = Util.TrimIntNull(tempdr["SyncType"]); oParam.LastVersionTime = Util.TrimDateNull(tempdr["LastVersionTime"]); }
private Hashtable GetDbLastVersion() { string sql = "select * from sys_sync"; DataSet ds = SqlHelper.ExecuteDataSet(sql); if ( !Util.HasMoreRow(ds)) return null; Hashtable ht = new Hashtable(5); foreach(DataRow dr in ds.Tables[0].Rows) { SyncInfo oInfo = new SyncInfo(); map(oInfo, dr); ht.Add(oInfo.SyncType, oInfo); } return ht; }
public void SetDbLastVersion(int syncType) { SyncInfo oInfo = new SyncInfo(); oInfo.SyncType = syncType; oInfo.LastVersionTime = DateTime.Now; new SyncDac().Update(oInfo); }