/// <summary>
        /// 找到当年SQL数据对应标的的最后一条数据的时间。为了插入新的数据做准备。
        /// </summary>
        /// <param name="code"></param>
        /// <param name="currentTime"></param>
        /// <returns></returns>
        private DateTime GetLatestTimeFromSql(string code, DateTime currentTime)
        {
            DateTime latest = default(DateTime);
            var      sqlStr = string.Format(@"declare @date date,@tb_name nvarchar(60), @index int,@latest_date datetime,@sqlStr nvarchar(300),@tem_date datetime
set @date ='{0}-01-01'
set @index =1
while @index <=12
begin
	set @tb_name='[StockMinuteTransaction'+datename(year,@date)+'].dbo.[Transaction'+ datename(year,@date)+'-'+datename(month,@date)+']'
	set @sqlStr ='select @tem_date=max([DateTime]) from '+@tb_name+' where code=''{1}'''
	if object_id(@tb_name) is not null
	begin
		exec sp_executesql @sqlStr,N'@tem_date datetime output',@tem_date output;
		if @tem_date is not null
		begin
			set @latest_date=@tem_date
		end
	end
	set @date = dateadd(month,1,@date)
	set @index=@index+1
end
select @latest_date", currentTime.Year, code.ToUpper());

            latest = sqlReader.ExecuteScriptScalar <DateTime>(sqlStr);
            return(latest);
        }
        /// <summary>
        /// 找到当月SQL数据对应标的的最后一条数据的时间。为了插入新的数据做准备。
        /// </summary>
        /// <param name="code"></param>
        /// <param name="currentTime"></param>
        /// <returns></returns>
        private DateTime GetLatestTimeOfMonthFromSql(string code, DateTime currentTime)
        {
            DateTime latest = default(DateTime);
            var      sqlStr = string.Format(@"SELECT max([DateTime])
  FROM [StockMinuteTransaction{0}].[dbo].[Transaction{1}] where Code='{2}'", currentTime.Year, currentTime.ToString("yyyy-MM"), code.ToUpper());

            latest = sqlReaderLocal.ExecuteScriptScalar <DateTime>(sqlStr);
            return(latest);
        }
        private bool ExistInSqlServer(string indexCode, string parameters)
        {
            var sqlScript = string.Format(@"use master
if db_id('Basis{0}') is not null
begin
	if object_id('[Basis{0}].dbo.[{1}]') is not null
	begin
		select 1 from [Basis{0}].dbo.[{1}] 
	end
end
else
begin
select 0
end ", indexCode, parameters);
            var res       = sqlReader.ExecuteScriptScalar <int>(sqlScript);

            return(res > default(int));
        }
Exemplo n.º 4
0
        private bool ExistInSqlServer(string code, DateTime date)
        {
            var sqlScript = string.Format(@"use master
if db_id('StockTickTransaction{0}') is not null
begin
	if object_id('[StockTickTransaction{0}].dbo.[{1}]') is not null
	begin
		select 1 from [StockTickTransaction{0}].dbo.[{1}] where rtrim(stkcd)='{2}'
	end
end
else
begin
select 0
end ", date.Year, date.ToString("yyyy-MM-dd"), code.ToUpper());
            var res       = sqlReader.ExecuteScriptScalar <int>(sqlScript);

            return(res > default(int));
        }
        private bool ExistInSqlServer(string code, DateTime date)
        {
            var sqlScript = string.Format(@"use master
if db_id('StockInfo') is not null
begin
	if object_id('[StockInfo].dbo.[BasicInfoDaily{0}]') is not null
	begin
		select 1 from [StockInfo].dbo.[BasicInfoDaily{0}] where rtrim(Code)='{1}'
	end
end
else
begin
select 0
end ", date.Year, code);
            var res       = sqlReader.ExecuteScriptScalar <int>(sqlScript);

            return(res > default(int));
        }
        private bool ExistInSqlServer(DateTime date)
        {
            var sqlScript = string.Format(@"use master
if db_id('ivix{0}') is not null
begin
	if object_id('[ivix{0}].dbo.[{1}]') is not null
	begin
		select 1 from [ivix{0}].dbo.[{1}] 
	end
end
else
begin
select 0
end ", date.Year, date.ToString("yyyy"));
            var res       = sqlReader.ExecuteScriptScalar <int>(sqlScript);

            return(res > default(int));
        }
        private bool ExistInSqlServer(string databaseName, string tableName)
        {
            var sqlScript = string.Format(@"use master
if db_id('{0}') is not null
begin
	if object_id('[{0}].dbo.[{1}]') is not null
	begin
		select 1 from [{0}].dbo.[{1}] 
	end
end
else
begin
select 0
end ", databaseName, tableName);
            var res       = sqlReader.ExecuteScriptScalar <int>(sqlScript);

            return(res > default(int));
        }