⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 getdatabase.cpp

📁 一个通过PCI卡向LED屏发送股票实时行情的系统
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// GetDatabase.cpp: implementation of the CGetDatabase class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "GetDatabase.h"

#include <string.h>
#include <stdio.h>
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CGetDatabase::CGetDatabase()
{
	int ii,jj;
	m_AcurRecord=1;
	m_BcurRecord=1;
	for(ii=0;ii<4;ii++)
		for(jj=0;jj<MAX_HOTNUMBER;jj++)
		{
			m_HotStock[ii][jj].m_zjcj=0;
			m_HotStock[ii][jj].m_sd=0;
			m_HotStock[ii][jj].m_sdf=0;
			m_HotStock[ii][jj].m_cjsl=0;
			m_HotStock[ii][jj].m_zrsp=0;
		}
	for(ii=0;ii<50;ii++)
	{
		strcpy(m_NewStock[ii].m_NewStockCode,"");
		m_NewStock[ii].m_bExist=FALSE;
	}
	m_NewStockNum=0;
	m_nNoExistNewGuCount=0;
} 

CGetDatabase::~CGetDatabase()
{
}

BOOL CGetDatabase::Open(LPCTSTR lpszSQL)
{
	int aa=m_Db.Open(lpszSQL);
	if(aa)
	{	

		m_set.m_pDatabase=&m_Db;
		return TRUE;
	}
	else
		return FALSE;

}

void CGetDatabase::Close()
{
	if(m_set.IsOpen())
	{
		m_set.Close();
	}	
	if(m_Db.IsOpen())
	{
		m_Db.Close();
	}

}

BOOL CGetDatabase::GetSzHq(LPCTSTR lpszSQL)
{
	if(!m_Db.IsOpen())
	{
		AfxMessageBox("数据库没有打开!");
		return FALSE;
	}

	if(m_set.IsOpen())
	{
		m_set.Close();
		return FALSE;
	}

	m_set.Open(lpszSQL);

	short i,j;
	short nFields;
	CString str;
	int kk;
	CString temp;
	CString temp1;
	double  temp2;
	int jijin_flag;
	int flag;
	_variant_t vars; 

	nFields=(short)m_set.GetFieldCount();
	i=0;
	if(m_set.IsEOF())
	{
		AfxMessageBox("当前视图没有记录!");
		return FALSE;
	}

    m_set.MoveFirst();
    i=0;   
	//////////////测试新股
	if(m_NewStockNum>10||m_NewStockNum<0)
		m_NewStockNum=0;
	/////////////////
	while(!m_set.IsEOF()&&i<(short)m_NewStockNum )
	{
		vars.Clear();
		vars=m_set.GetFieldValue(0);
		temp=vars.bstrVal;
		temp.TrimLeft();
		temp.TrimRight();
		flag=0;
		for(kk=0;kk<m_NewStockNum;kk++)
		{
			if(temp==m_NewStock[kk].m_NewStockCode)
			{
				flag=1;
				m_NewStock[kk].m_bExist=TRUE;
				break;
			}
		}

		if(temp.Left(2)=="18")
			jijin_flag=1;
		else 
			jijin_flag=0;
		
		if(flag)
		{
			AGu[i]=" ";
			AGu[i].Empty();
	    	vars.Clear();
	    	vars=m_set.GetFieldValue(5);///////////hqcjsl
            temp=GetVariantString(vars);
			if(temp.Find("#")!=-1)	
			{//数据太大
				temp=temp.Left(temp.GetLength()-1);//去掉#
				temp="999999999999";
			}

			temp.TrimLeft();
 			if(temp.GetLength()<=2)
				temp="0";
			else
				temp=temp.Left(temp.GetLength()-2);
			if(temp.GetLength()>6)
				temp="---";
			temp1.Empty();
			for(j=0;j<(6-(int)strlen(temp));j++)
				temp1+=" ";
			AGu[i]=temp1+temp;
		
	    	vars.Clear();
	    	vars=m_set.GetFieldValue(12);///////////hqjsd1
            temp=GetVariantString(vars);
			if(temp.Find("#")!=-1)	
			{//数据太大
				temp=temp.Left(temp.GetLength()-1);//去掉#
				temp="999999999999";
			}
			temp.TrimLeft();
			temp2=atof(temp);
			if(temp2>99999||temp2==0.00)
			{
				temp="---";
				AGu_Color[i]=3;
			}
			else if(temp2>0.0005)
			{
				AGu_Color[i]=1;
				if(temp2>999)
					temp.Format(_T("%+6.0f"),temp2);
				else
				{
					if(jijin_flag==1)
						temp.Format(_T("%+6.3f"),temp2);
					else
						temp.Format(_T("%+6.2f"),temp2);
				}
			}
			else 
			{
				AGu_Color[i]=2;
				if(temp2>999)
					temp.Format(_T("%+6.0f"),temp2);
				else
				{
					if(jijin_flag==1)
						temp.Format(_T("%+6.3f"),temp2);
					else
						temp.Format(_T("%+6.2f"),temp2);
				}
//					temp.Format(_T("%+6.2f"),temp2);
			}
			temp1.Empty();
			for(j=0;j<(6-(int)strlen(temp));j++)
				temp1+=" ";
			AGu[i]=AGu[i]+temp1+temp;
			
	    	vars.Clear();
	    	vars=m_set.GetFieldValue(4);///////////hqzjcj
            temp=GetVariantString(vars);
			if(temp.Find("#")!=-1)	
			{//数据太大
				temp=temp.Left(temp.GetLength()-1);//去掉#
				temp="999999999999";
			}
			temp.TrimLeft();
			temp2=atof(temp);
			if(temp2>9999||temp2==0.00)
				temp="---";
			else if(temp2>999)
                temp.Format(_T("%7.0f"),temp2);
			else
			{
				if(jijin_flag==1)
					temp.Format(_T("%+7.3f"),temp2);
				else
					temp.Format(_T("%+7.2f"),temp2);
			}
//                temp.Format(_T("%7.2f"),temp2);
			temp1.Empty();
			for(j=0;j<(7-(int)strlen(temp));j++)
				temp1+=" ";
			AGu[i]=AGu[i]+temp1+temp;
			
	    	vars.Clear();
	    	vars=m_set.GetFieldValue(1);///////////hqzqjc
		    temp=vars.bstrVal;
			temp.TrimLeft();
			temp1.Empty();
			for(j=0;j<(9-(int)strlen(temp));j++)
				temp1+=" ";
			AGu[i]=AGu[i]+temp1+temp;
 			i++;

		}
		m_set.MoveNext();
	}
	//检查是否有不存在的新股
	temp="";
	m_nNoExistNewGuCount=0;
	for(kk=0;kk<m_NewStockNum;kk++)
	{
		if(!m_NewStock[kk].m_bExist)
		{
			m_nNoExistNewGuCount++;
			temp+=m_NewStock[kk].m_NewStockCode;
			temp+=" ";
/*			for(int NoStock=kk;NoStock<m_NewStockNum;NoStock++)
			{
				strcpy(m_NewStock[NoStock].m_NewStockCode,m_NewStock[NoStock+1].m_NewStockCode);
				m_NewStock[NoStock].m_bExist=m_NewStock[NoStock+1].m_bExist;
			}
			m_NewStockNum--;*///不自动删除,用户自己手工删除
		}
	}
	//报告新股不存在
	if(!temp.IsEmpty())
		m_sNewGuAlarm=temp+"新股不存在";
	else
		m_sNewGuAlarm="";

    m_set.MoveFirst();
	m_set.Move(m_AcurRecord);
//////////////////////////// A 股
//	i=m_NewStockNum;//i值无须更改
	while(!m_set.IsEOF()&&i<18 )
	{ 
		vars.Clear();
		vars=m_set.GetFieldValue(0);
		temp=vars.bstrVal;
		temp.TrimLeft();
		temp.TrimRight();
		flag=0;
		if(temp.Left(2)=="00"&&temp!="000000")
			flag=1;
		for(kk=0;kk<m_NewStockNum;kk++)
		{
			if(temp==m_NewStock[kk].m_NewStockCode)
			{
				flag=0;
				break;
			}
		}
		if(flag)
		{
			AGu[i]=" ";
			AGu[i].Empty();
	    	vars.Clear();
	    	vars=m_set.GetFieldValue(5);///////////hqcjsl
            temp=GetVariantString(vars);
			if(temp.Find("#")!=-1)	
			{//数据太大
				temp=temp.Left(temp.GetLength()-1);//去掉#
				temp="999999999999";
			}
			temp.TrimLeft();
 			if(temp.GetLength()<=2)
				temp="0";
			else
				temp=temp.Left(temp.GetLength()-2);
			if(temp.GetLength()>6)
				temp="---";
			temp1.Empty();
			for(j=0;j<(6-(int)strlen(temp));j++)
				temp1+=" ";
			AGu[i]=temp1+temp;
		
	    	vars.Clear();
	    	vars=m_set.GetFieldValue(12);///////////hqjsd1
            temp=GetVariantString(vars);
			if(temp.Find("#")!=-1)	
			{//数据太大
				temp=temp.Left(temp.GetLength()-1);//去掉#
				temp="999999999999";
			}
			temp.TrimLeft();
			temp2=atof(temp);
			if(temp2>99999||temp2==0.00)
			{
				temp="---";
				AGu_Color[i]=3;
			}
			else if(temp2>0.0005)
			{
				AGu_Color[i]=1;
				if(temp2>999)
					temp.Format(_T("%+6.0f"),temp2);
				else
					temp.Format(_T("%+6.2f"),temp2);
			}
			else 
			{
				AGu_Color[i]=2;
				if(temp2>999)
					temp.Format(_T("%+6.0f"),temp2);
				else
					temp.Format(_T("%+6.2f"),temp2);
			}
			temp1.Empty();
			for(j=0;j<(6-(int)strlen(temp));j++)
				temp1+=" ";
			AGu[i]=AGu[i]+temp1+temp;
			
	    	vars.Clear();
	    	vars=m_set.GetFieldValue(4);///////////hqzjcj
            temp=GetVariantString(vars);
			if(temp.Find("#")!=-1)	
			{//数据太大
				temp=temp.Left(temp.GetLength()-1);//去掉#
				temp="999999999999";
			}
			temp.TrimLeft();
			temp2=atof(temp);
			if(temp2>99999||temp2==0.00)
				temp="---";
			else if(temp2>999)
                temp.Format(_T("%7.0f"),temp2);
			else
                temp.Format(_T("%7.2f"),temp2);
			temp1.Empty();
			for(j=0;j<(7-(int)strlen(temp));j++)
				temp1+=" ";
			AGu[i]=AGu[i]+temp1+temp;
			
	    	vars.Clear();
	    	vars=m_set.GetFieldValue(1);///////////hqzqjc
		    temp=vars.bstrVal;
			temp1.Empty();
			for(j=0;j<(9-(int)strlen(temp));j++)
				temp1+=" ";
			AGu[i]=AGu[i]+temp1+temp;
 			i++;

		}
		m_set.MoveNext();
		m_AcurRecord++;
	}
	if(m_set.IsEOF())
		m_AcurRecord=1;  
 
////////////////////////////  B 股
	m_set.MoveFirst();
	m_set.Move(m_BcurRecord);
	i=0;
	while(!m_set.IsEOF()&&i<18 )
	{ 
		vars.Clear();
		vars=m_set.GetFieldValue(0);
		temp=vars.bstrVal;
		temp.TrimLeft();
		temp.TrimRight();
		if((temp.Left(2)=="18")|| (temp.Left(2)=="20")|| (temp.Left(2)=="10")|| (temp.Left(2)=="11"))	
		{
			if(temp.Left(2)=="18")
				jijin_flag=1;
			else 
				jijin_flag=0;

			vars.Clear();
	    	vars=m_set.GetFieldValue(1);///////////hqzqjc
		    temp=vars.bstrVal;
			BGu[i]=temp;

	    	vars.Clear();
	    	vars=m_set.GetFieldValue(4);///////////hqzjcj
            temp=GetVariantString(vars);
			if(temp.Find("#")!=-1)	
			{//数据太大
				temp=temp.Left(temp.GetLength()-1);//去掉#
				temp="999999999999";
			}
			temp.TrimLeft();
			temp2=atof(temp);
			if(jijin_flag==1)
			{
				if(temp2>99999||temp2==0.00)
					temp="---";
				else if(temp2>99)
					temp.Format(_T("%6.0f"),temp2);
				else
				{
					if(jijin_flag==1)
						temp.Format(_T("%6.3f"),temp2);
					else
						temp.Format(_T("%6.2f"),temp2);
				}
				temp1.Empty();
				for(j=0;j<(6-(int)strlen(temp));j++)
					temp1+=" ";
			}
			else
			{
				if(temp2>99999||temp2==0.00)
					temp="---";
				else if(temp2>99)
					temp.Format(_T("%7.0f"),temp2);
				else
				{
					if(jijin_flag==1)
						temp.Format(_T("%7.3f"),temp2);
					else
						temp.Format(_T("%7.2f"),temp2);
				}
				temp1.Empty();
				for(j=0;j<(7-(int)strlen(temp));j++)
					temp1+=" ";
			}
			BGu[i]=BGu[i]+temp1+temp;

	    	vars.Clear();
	    	vars=m_set.GetFieldValue(12);///////////hqjsd1
            temp=GetVariantString(vars);
			if(temp.Find("#")!=-1)	
			{//数据太大
				temp=temp.Left(temp.GetLength()-1);//去掉#
				temp="999999999999";
			}
			temp.TrimLeft();
			temp2=atof(temp);
			if(temp2>99999||temp2==0.00)
			{
				temp="---";
				BGu_Color[i]=3;
			}
			else if(temp2>0.0005)
			{
				BGu_Color[i]=1;
				if(temp2>99)
				{
                    if(jijin_flag==1)
						temp.Format(_T("%+7.0f"),temp2);
					else
						temp.Format(_T("%+6.0f"),temp2);
				}
				else
				{
					if(jijin_flag==1)
						temp.Format(_T("%+7.3f"),temp2);
					else
						temp.Format(_T("%+6.2f"),temp2);
				}
//					temp.Format(_T("%+6.2f"),temp2);
			}
			else 
			{
				BGu_Color[i]=2;
				if(temp2>999)
				{
                    if(jijin_flag==1)
						temp.Format(_T("%+7.0f"),temp2);
					else
						temp.Format(_T("%+6.0f"),temp2);
					//temp.Format(_T("%+6.0f"),temp2);
				}
				else
				{
					if(jijin_flag==1)
						temp.Format(_T("%+7.3f"),temp2);
					else
						temp.Format(_T("%+6.2f"),temp2);
				}
//					temp.Format(_T("%+6.2f"),temp2);
			}

			temp1.Empty();
			if(jijin_flag==1)
				for(j=0;j<(7-(int)strlen(temp));j++)
					temp1+=" ";
			else
				for(j=0;j<(6-(int)strlen(temp));j++)
					temp1+=" ";
			BGu[i]=BGu[i]+temp1+temp;

	    	vars.Clear();
	    	vars=m_set.GetFieldValue(5);///////////hqcjsl
            temp=GetVariantString(vars);
			if(temp.Find("#")!=-1)	
			{//数据太大
				temp=temp.Left(temp.GetLength()-1);//去掉#
				temp="999999999999";
			}
			temp.TrimLeft();
			if(temp.GetLength()<=2)
				temp="0";
			else

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -