我是这样做的:
CDatabase db;
db.Open(NULL,FALSE,FALSE,_T("ODBC;DSN=DATABASENAME;UID=SA;PWD="),TRUE);CString strSQL;
strSQL.Format("完整的SQL语句");
db.ExecuteSQL(strSQL);

解决方案 »

  1.   

    // mymncgDlg.h : header file
    //#if !defined(AFX_MYMNCGDLG_H__D7B96591_DECC_42E3_8DC8_7061E1491E9D__INCLUDED_)
    #define AFX_MYMNCGDLG_H__D7B96591_DECC_42E3_8DC8_7061E1491E9D__INCLUDED_#include "SQLServer.h"
    #include "WDBF.H" // Added by ClassView
    #include "sqlfront.h" // Added by ClassView#if _MSC_VER > 1000
    #pragma once
    #endif // _MSC_VER > 1000/////////////////////////////////////////////////////////////////////////////
    // CMymncgDlg dialogtypedef  struct {
    char         stockcode[7];
    int          index;
    } S_INDEX;typedef struct {
    char        stockcode[7];
    int         index;
    } S_SHINDEX;class CMymncgDlg : public CDialog
    {
    // Construction
    public:

    CSQLServer     m_bLink;
    CString   strFileName[5];
    BOOL IsClearData( );
    void Initialize( );
    BOOL IsHoliday( );
    CString m_strIni;
    void DealShow128Dbf(CString strShow128);
    S_SHINDEX         s_Show[2000];
    S_INDEX           s_Hq[2000];
    S_INDEX           s_Mmp[2000];
    S_DBF_HEAD_STRUCT m_cDbf[5];    //0 show128.dbf, 1 z_zqxx.dbf, 2 z_hq.dbf, 3 z_mmp.dbf, 4 z_zs.dbf
    void CreateHqIndex(CString strHq);
    void DealZqxx(CString strZqxx, CString strHq);
    double GetDbfCp(CString strHq, CString stockcode);
    void Match( );
    void Liquidate( );
    BOOL EqualTime(CString   strDate);

    void CreateShow128Index( );
    void CreateMmpIndex( );
    double GetBuyPrice(CString strStockCode, int nExchangeCode);
    double GetSellPrice(CString strStockCode, int nExchangeCode);//取股票的卖一价格
    BOOL bStopFlag;
    int nAmS, nAmE, nPmS, nPmE; //分别表示上午撮合开始结束时间和下午撮合开始结束时间;
    void DealTimer1(); //初始化的timer
    void DealTimer2(); //撮合的timer
    void DealTimer3( ); //清算的timer
    BOOL LessTime(int nTime); //判断时间是不是大于系统时间(指小时和分钟)
    bool IsMatchTime( ); //判断是不是撮合时间段
    void ReadShow(); //读取上海股票的指数
    void ReadZs( ); //读取深证股票的指数
    int ShBinSearch(S_SHINDEX* S_ShStock, int nCount, CString cKey);//查找深圳股票代码
    int SzBinSearch(S_INDEX* S_SzStock, int nCount, CString cKey);//查找上海股票代码
    CMymncgDlg(CWnd* pParent = NULL); // standard constructor// Dialog Data
    //{{AFX_DATA(CMymncgDlg)
    enum { IDD = IDD_MYMNCG_DIALOG };
    CButton m_ctrLiquidate;
    CButton m_ctrContral;
    CButton m_ctrStart;
    CButton m_ctrExit;
    CString m_strCreate;
    CString m_strSh;
    CString m_strShAstock;
    CString m_strShBstock;
    CString m_strState;
    CString m_strSz;
    CString m_strSzAstock;
    CString m_strSzBstock;
    CString m_sysTime;
    //}}AFX_DATA // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CMymncgDlg)
    protected:
    virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
    //}}AFX_VIRTUAL// Implementation
    protected:
    HICON m_hIcon; int m_nShStockNum;
    int m_nSzStockNum;
    // Generated message map functions
    //{{AFX_MSG(CMymncgDlg)
    virtual BOOL OnInitDialog();
    afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
    afx_msg void OnPaint();
    afx_msg HCURSOR OnQueryDragIcon();
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
    };//{{AFX_INSERT_LOCATION}}
    // Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_MYMNCGDLG_H__D7B96591_DECC_42E3_8DC8_7061E1491E9D__INCLUDED_)// mymncgDlg.cpp : implementation file
    //#include "stdafx.h"
    #include "mymncg.h"
    #include "mymncgDlg.h"#include "SQLServer.h"
    #include "WDBF.H"
    #include "WarnDlg.h"#ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif/////////////////////////////////////////////////////////////////////////////
    // CAboutDlg dialog used for App Aboutclass CAboutDlg : public CDialog
    {
    public:
    CAboutDlg();// Dialog Data
    //{{AFX_DATA(CAboutDlg)
    enum { IDD = IDD_ABOUTBOX };
    //}}AFX_DATA // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CAboutDlg)
    protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
    //}}AFX_VIRTUAL// Implementation
    protected:
    //{{AFX_MSG(CAboutDlg)
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
    };CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
    {
    //{{AFX_DATA_INIT(CAboutDlg)
    //}}AFX_DATA_INIT
    }void CAboutDlg::DoDataExchange(CDataExchange* pDX)
    {
    CDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CAboutDlg)
    //}}AFX_DATA_MAP
    }BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
    //{{AFX_MSG_MAP(CAboutDlg)
    // No message handlers
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
    // CMymncgDlg dialogCMymncgDlg::CMymncgDlg(CWnd* pParent /*=NULL*/)
    : CDialog(CMymncgDlg::IDD, pParent)
    {
    //{{AFX_DATA_INIT(CMymncgDlg)
    m_strCreate = _T("");
    m_strSh = _T("");
    m_strShAstock = _T("");
    m_strShBstock = _T("");
    m_strState = _T("");
    m_strSz = _T("");
    m_strSzAstock = _T("");
    m_strSzBstock = _T("");
    m_sysTime = _T("");
    //}}AFX_DATA_INIT
    // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
    m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);

    //初始化&s_hq等
    memset(&s_Hq, 0, sizeof(s_Hq));
    memset(&s_Mmp, 0, sizeof(s_Mmp));
    memset(&s_Show, 0, sizeof(s_Show));

    //为m_cDbf[]赋初值
    bStopFlag = true;
    int       loop;
    for (loop = 0; loop < 5; loop++) { 
    m_cDbf[loop].ulRecordSum = 0;
    m_cDbf[loop].usHeadLen = 0;
    m_cDbf[loop].usRecLen = 0;
    } //获得mncg.ini的路径,赋给m_strIni
    CFile     m_cFile;
        CFileException  e;
        m_cFile.Open("mncg.ini", CFile::modeWrite, &e);
    m_strIni = m_cFile.GetFilePath();
        m_cFile.Close(); //获得各dbf的路径,并保存在strFileName[]中
    GetPrivateProfileString("DBF文件的路径", "show128.dbf的路径", "", strFileName[0].GetBuffer(64), 64, m_strIni);
        GetPrivateProfileString("DBF文件的路径", "z_zqxx.dbf的路径", "", strFileName[1].GetBuffer(64), 64, m_strIni);
        GetPrivateProfileString("DBF文件的路径", "z_hq.dbf的路径", "", strFileName[2].GetBuffer(64), 64, m_strIni);
        GetPrivateProfileString("DBF文件的路径", "z_mmp.dbf的路径", "", strFileName[3].GetBuffer(64), 64, m_strIni);
    GetPrivateProfileString("DBF文件的路径", "z_zs.dbf的路径", "", strFileName[4].GetBuffer(64), 64, m_strIni);

    //判断撮合时间是否正确
    char      cMatch[10];
    memset(cMatch, 0, sizeof(cMatch));
        GetPrivateProfileString("撮合", "上午撮合开始时间", "925", cMatch, sizeof(cMatch), m_strIni);
    nAmS = atoi(cMatch);
    GetPrivateProfileString("撮合", "上午撮合结束时间", "1100", cMatch, sizeof(cMatch), m_strIni);
    nAmE = atoi(cMatch);
    GetPrivateProfileString("撮合", "下午撮合开始时间", "1300", cMatch, sizeof(cMatch), m_strIni);
    nPmS = atoi(cMatch);
    GetPrivateProfileString("撮合", "下午撮合结束时间", "1500", cMatch, sizeof(cMatch), m_strIni);
    nPmE = atoi(cMatch);
    if ((nAmS < 0) || (nAmS/100 >23) || (nAmS%100 > 59)) {
    AfxMessageBox("上午撮合开始时间设置错误,请重新设置!");
    exit(1);
    }
    if ((nAmE < 0) || (nAmE/100 > 23) || (nAmE%100 > 59)) {
    AfxMessageBox("上午撮合结束时间设置错误,请重新设置!");
    exit(1);
    }
    if (nAmS > nAmE) {
    AfxMessageBox("上午撮合时间设置错误,请重新设置上午撮合开始和结束时间!");
    exit(1);
    }
    if ((nPmS < 0) || (nPmS/100 > 23) || (nPmS%100 > 59)) {
    AfxMessageBox("下午撮合开始时间设置错误,请重新设置!");
    exit(1);
    }
    if ((nPmE < 0) || (nPmE/100 > 23) || (nPmE%100 > 59)) {
    AfxMessageBox("下午撮合结束时间设置错误,请重新设置!");
    exit(1);
    }
    if (nPmS > nPmE) {
    AfxMessageBox("下午撮合时间设置错误,请重新设置下午撮合开始和结束时间!");
    exit(1);
    }
    if (nAmE > nPmS) {
    AfxMessageBox("下午撮合开始时间和上午撮合开始时间设置错误,请重新设置!");
    exit(1);
    }
    }
    void CMymncgDlg::DoDataExchange(CDataExchange* pDX)
    {
    CDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CMymncgDlg)
    DDX_Control(pDX, IDC_LIQUIDATE, m_ctrLiquidate);
    DDX_Control(pDX, IDC_CONTRAL, m_ctrContral);
    DDX_Control(pDX, ID_START, m_ctrStart);
    DDX_Control(pDX, ID_EXIT, m_ctrExit);
    DDX_Text(pDX, IDC_STATIC_CREATE, m_strCreate);
    DDV_MaxChars(pDX, m_strCreate, 12);
    DDX_Text(pDX, IDC_STATIC_SH, m_strSh);
    DDV_MaxChars(pDX, m_strSh, 12);
    DDX_Text(pDX, IDC_STATIC_SHASTOCK, m_strShAstock);
    DDV_MaxChars(pDX, m_strShAstock, 12);
    DDX_Text(pDX, IDC_STATIC_SHBSTOCK, m_strShBstock);
    DDV_MaxChars(pDX, m_strShBstock, 12);
    DDX_Text(pDX, IDC_STATIC_STATE, m_strState);
    DDV_MaxChars(pDX, m_strState, 24);
    DDX_Text(pDX, IDC_STATIC_SZ, m_strSz);
    DDV_MaxChars(pDX, m_strSz, 12);
    DDX_Text(pDX, IDC_STATIC_SZASTOCK, m_strSzAstock);
    DDV_MaxChars(pDX, m_strSzAstock, 12);
    DDX_Text(pDX, IDC_STATIC_SZBSTOCK, m_strSzBstock);
    DDV_MaxChars(pDX, m_strSzBstock, 12);
    DDX_Text(pDX, IDC_STATIC_Time, m_sysTime);
    DDV_MaxChars(pDX, m_sysTime, 20);
    //}}AFX_DATA_MAP
    }BEGIN_MESSAGE_MAP(CMymncgDlg, CDialog)
    //{{AFX_MSG_MAP(CMymncgDlg)
    ON_WM_SYSCOMMAND()
    ON_WM_PAINT()
    ON_WM_QUERYDRAGICON()
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
    // CMymncgDlg message handlersBOOL CMymncgDlg::OnInitDialog()
    {
    CDialog::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range.
    ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
    ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE);
    if (pSysMenu != NULL)
    {
    CString strAboutMenu;
    strAboutMenu.LoadString(IDS_ABOUTBOX);
    if (!strAboutMenu.IsEmpty())
    {
    pSysMenu->AppendMenu(MF_SEPARATOR);
    pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
    }
    } // Set the icon for this dialog.  The framework does this automatically
    //  when the application's main window is not a dialog
    SetIcon(m_hIcon, TRUE); // Set big icon
    SetIcon(m_hIcon, FALSE); // Set small icon

    //设置Timer1的循环时间
    SetTimer(1, 10, NULL); //设置Timer4的循环时间
    SetTimer(4, 1000, NULL);

    ReadShow();
    ReadZs(); CTime sysTime = CTime::GetCurrentTime();
    int sysYear = sysTime.GetYear();
    int sysMonth = sysTime.GetMonth();
    int sysDay = sysTime.GetDay();
    int sysHour = sysTime.GetHour();
    int sysMinute = sysTime.GetMinute();
    int sysSecond = sysTime.GetSecond();
    m_sysTime.Format("%d-%02d-%02d %02d:%02d:%02d", sysYear, sysMonth, sysDay, sysHour, sysMinute, sysSecond);
    UpdateData(false);

    return TRUE;  // return TRUE  unless you set the focus to a control
    }void CMymncgDlg::OnSysCommand(UINT nID, LPARAM lParam)
    {
    if ((nID & 0xFFF0) == IDM_ABOUTBOX)
    {
    CAboutDlg dlgAbout;
    dlgAbout.DoModal();
    }
    else
    {
    CDialog::OnSysCommand(nID, lParam);
    }
    }// If you add a minimize button to your dialog, you will need the code below
    //  to draw the icon.  For MFC applications using the document/view model,
    //  this is automatically done for you by the framework.void CMymncgDlg::OnPaint() 
    {
    if (IsIconic())
    {
    CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle
    int cxIcon = GetSystemMetrics(SM_CXICON);
    int cyIcon = GetSystemMetrics(SM_CYICON);
    CRect rect;
    GetClientRect(&rect);
    int x = (rect.Width() - cxIcon + 1) / 2;
    int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon
    dc.DrawIcon(x, y, m_hIcon);
    }
    else
    {
    CDialog::OnPaint();
    }
    }// The system calls this to obtain the cursor to display while the user drags
    //  the minimized window.
    HCURSOR CMymncgDlg::OnQueryDragIcon()
    {
    return (HCURSOR) m_hIcon;
    }INT CMymncgDlg::SzBinSearch(S_INDEX *S_SzStock, int nCount, CString cKey)
    {
    int nLow, nHigh, nMid;
    nLow = 0;
    nHigh = nCount-1;
    while (nLow <= nHigh) {
    nMid = (nLow+nHigh)/2;
    if (cKey.Compare(S_SzStock[nMid].stockcode) < 0)
    nHigh = nMid-1;
    else if (cKey.Compare(S_SzStock[nMid].stockcode) > 0)
    nLow = nMid+1;
    else return nMid;
    }
    return -1;
    }int CMymncgDlg::ShBinSearch(S_SHINDEX *S_ShStock, int nCount, CString cKey)
    {
    int nLow, nHigh, nMid;
    nLow = 0;
    nHigh = nCount-1;
    while (nLow <= nHigh) {
    nMid = (nLow+nHigh)/2;
    if (cKey.Compare(S_ShStock[nMid].stockcode) < 0)
    nHigh = nMid-1;
    else if (cKey.Compare(S_ShStock[nMid].stockcode) > 0)
    nLow = nMid+1;
    else return nMid;
    }
    return -1;
    }void CMymncgDlg::ReadZs()
    {
    WDBF    wZs;
    char    cSzExponent[10];
    memset(cSzExponent, 0, sizeof(cSzExponent));
        if (!(wZs.Open(strFileName[4], CFile::shareDenyNone | CFile::typeBinary))) {
      wZs.Goto(1);
      wZs.ReadFieldsWithMove(1, "FZJZS", cSzExponent);
      m_strSz = cSzExponent;
      m_strSz.TrimLeft();
      wZs.Goto(11);
      wZs.ReadFieldsWithMove(1, "FZJZS", cSzExponent);
      m_strSzAstock = cSzExponent;
      m_strSzAstock.TrimLeft();
      wZs.Goto(12);
      wZs.ReadFieldsWithMove(1, "FZJZS", cSzExponent);
      m_strSzBstock = cSzExponent;
      m_strSzBstock.TrimLeft();
      wZs.Goto(wZs.GetRecordNum());
      wZs.ReadFieldsWithMove(1, "FZJZS", cSzExponent);
              m_strCreate = cSzExponent;
      m_strCreate.TrimLeft();
      wZs.Close();
    //   UpdateData(false);
    }
    else { 
    AfxMessageBox("打开z_zs.dbf读取指数时出错!");
        exit(1);
    }
    }void CMymncgDlg::ReadShow()
    {
    WDBF     wShow;
    char     cShExponent[10];
    memset(cShExponent, 0, sizeof(cShExponent));
    double   dExponent; if (!(wShow.Open(strFileName[0], CFile::shareDenyNone | CFile::typeBinary))) {
    wShow.Goto(2);
    wShow.ReadFieldsWithMove(1, "S8", cShExponent);
    dExponent = atof(cShExponent);
    m_strSh.Format("%.3f", dExponent);
    wShow.Goto(3);
    wShow.ReadFieldsWithMove(1, "S8", cShExponent);
    dExponent = atof(cShExponent);
    m_strShAstock.Format("%.3f", dExponent);
    wShow.Goto(4);
    wShow.ReadFieldsWithMove(1, "S8", cShExponent);
    m_strShBstock = cShExponent;
    m_strShBstock.TrimLeft();
    wShow.Close();
    // UpdateData(false);
    }
    else {
    AfxMessageBox("打开show128.dbf读取指数时出错,!");
    exit(1);
    }
    }bool CMymncgDlg::IsMatchTime()
    {
    CTime   mTime = CTime::GetCurrentTime();
    int     mHour, mMint, ImTime;
    mHour = mTime.GetHour();
    mMint = mTime.GetMinute();
    ImTime = mHour*100+mMint;
    if (((nAmS < ImTime) && (ImTime < nAmE)) || ((nPmS < ImTime) && (ImTime < nPmE)))
    return (true);
    else
    return (false);
    }BOOL CMymncgDlg::LessTime(int nTime)
    {
    CTime  leTime = CTime::GetCurrentTime();
    int    leHour, leMint, lsTime;
    leHour = leTime.GetHour();
    leMint = leTime.GetMinute();
        lsTime = leHour*100+leMint;
    if (lsTime < nTime)
    return (true);
    else 
    return (false);
    }void CMymncgDlg::DealTimer3()
    {
     if (LessTime(100)) {     //判断是不是过了凌晨一点(是为了防止运行到这里才跨过24点)
         KillTimer(3);
         SetTimer(1, 10000, NULL);
     return;
     }  char     Liq[20];
     memset(Liq, 0, sizeof(Liq));
         GetPrivateProfileString("清算", "清算时间", "00000000", Liq, 9, m_strIni);
         if (EqualTime(Liq) == false) {     //看是否已经清算
         int   lStart, lEnd;
             if (m_bLink.ConnectDatabase()) {    //连接数据库,取清算开始时间和截止时间
             m_bLink.GetLiquidateTime();
         lStart = m_bLink.nLiqBegin;
         lEnd   = m_bLink.nLiqEnd;
     if ((lStart < 0) || (lStart/100 > 23) || (lStart%100 > 59)) {
         AfxMessageBox("系统清算开始时间设置错误,请重新设置!");
         exit(1);
     }
         if ((lEnd < 0) || (lEnd/100 > 23) || (lStart%100 > 59)) {
             AfxMessageBox("系统清算结束时间设置错误,请重新设置!");
         exit(1);
     }
     if (lStart > lEnd) {
     AfxMessageBox("系统清算时间设置错误,请重新设置系统清算开始时间和截止时间!");
         exit(1);
     }
         m_bLink.LogoutSQLServer();
     }
     else {
    AfxMessageBox("连接数据库错误!");
    exit(1);
     }  if (LessTime(lEnd)) {
     if (LessTime(lStart)) {
         m_strState = "系统正在空闲中!";
     UpdateData(FALSE);
     return;
     }
     
     }
       Liquidate();
     }
         KillTimer(3);
     m_strState = "系统正在空闲中!";
     UpdateData(FALSE);
     SetTimer(1, 10000, NULL);
    }void CMymncgDlg::DealTimer2()
    {
    if (LessTime(100)) {     //判断是不是过了凌晨一点(是为了防止运行到这里才跨过24点)
        KillTimer(2);
    SetTimer(1, 10000, NULL);
    return;
    } if (LessTime(nPmE) == false) {   //判断是不是过了下午撮合截止时间
    KillTimer(2);
    m_strState = "系统正在空闲中!";
    UpdateData(FALSE);
    SetTimer(3, 10000, NULL);
    return;
    }
        
    if (IsMatchTime())            //判断是不是撮合时间
    Match(); 
    else {                       //午休时间
    m_strState = "系统正在空闲中!";
    UpdateData(FALSE);
    }
    }void CMymncgDlg::DealTimer1()
    {}double CMymncgDlg::GetSellPrice(CString strStockCode, int nExchangeCode)
    {
    int   k;
    WDBF   sDbf;
    char   SellPrice[10];
    memset(SellPrice, 0, sizeof(SellPrice));
    double Sp; if (nExchangeCode == 1) {
          k = SzBinSearch(s_Mmp, m_nSzStockNum, strStockCode);
    if (k == -1) return 0;
    if (!sDbf.Open(strFileName[3], CFile::shareDenyNone | CFile::modeRead | CFile::typeBinary)) {
                sDbf.Goto(s_Mmp[k].index*6-3);
        sDbf.ReadFieldsWithMove(1, "FJW", SellPrice);
                sDbf.Close();
    }
            else {
        AfxMessageBox("打开z_mmp.dbf错误,取卖一价格出错!");
    exit(1);
    }
        
    } else {
      k = ShBinSearch(s_Show, m_nShStockNum, strStockCode);
    if (k == -1) return 0;
         if (!sDbf.Open(strFileName[0], CFile::shareDenyNone | CFile::typeBinary)) {
                sDbf.Goto(s_Show[k].index);
        sDbf.ReadFieldsWithMove(1, "S10", SellPrice);
                sDbf.Close();
    }
            else {
        AfxMessageBox("打开show128.dbf错误,取卖一价格出错!");
    exit(1);
    }
    } Sp = atof(SellPrice);
    return (Sp);
    }double CMymncgDlg::GetBuyPrice(CString strStockCode, int nExchangeCode)
    {
    int k;
    WDBF   m_dbf;
    char   BuyPrice[10];
    memset(BuyPrice, 0, sizeof(BuyPrice));
    double Bp; if (nExchangeCode == 1) {
      k = SzBinSearch(s_Mmp, m_nSzStockNum, strStockCode);
    if (k == -1) return 0;
         if (!m_dbf.Open(strFileName[3], CFile::shareDenyNone | CFile::typeBinary)) {
                m_dbf.Goto(s_Mmp[k].index*6-2);
        m_dbf.ReadFieldsWithMove(1, "FJW", BuyPrice);
                m_dbf.Close();
    }
            else {
        AfxMessageBox("打开z_mmp.dbf错误,取买一价格出错!");
    exit(1);
    }
        
    } else {
       k = ShBinSearch(s_Show, m_nShStockNum, strStockCode);
    if (k == -1) return 0; 
         if (!m_dbf.Open(strFileName[0], CFile::shareDenyNone | CFile::typeBinary)) {
                m_dbf.Goto(s_Show[k].index);
        m_dbf.ReadFieldsWithMove(1, "S9", BuyPrice);
                m_dbf.Close();
    }
            else {
        AfxMessageBox("打开show128.dbf错误,取买一价格出错!");
    exit(1);
    }
    } Bp = atof(BuyPrice);
    return (Bp);}void CMymncgDlg::CreateMmpIndex()
    {
        MSG      message;
    WDBF     m_cMmp;
    if (!m_cMmp.Open(strFileName[3], CFile::shareDenyNone | CFile::typeBinary)) {
    int        mLoop;
    char       strMmpCode[7];
    memset(strMmpCode, 0, sizeof(strMmpCode));

    m_nSzStockNum = m_cMmp.GetRecordNum()/6;
    for (mLoop = 1; mLoop <= m_nSzStockNum; mLoop++) {
     m_cMmp.Goto(mLoop*6-5);
     m_cMmp.ReadFieldsWithMove(1, "FZQDM", strMmpCode);
             strcpy(s_Mmp[mLoop].stockcode, strMmpCode);
     s_Mmp[mLoop].index = mLoop;  if (::PeekMessage(&message, NULL, 0, 0, PM_REMOVE)) {
     ::TranslateMessage(&message);
     ::DispatchMessage(&message);
     }
    }
    m_cMmp.Close();
    }
    else {
    AfxMessageBox("打开z_mmp.dbf建索引时出错!");
    exit(1);
    }
    }void CMymncgDlg::CreateShow128Index()
    {
    MSG      message;
    WDBF     wShow128;
    if (!wShow128.Open(strFileName[0], CFile::shareDenyNone | CFile::typeBinary)) {
    int        wLoop;
    char       strShow128Code[7];
    memset(strShow128Code, 0, sizeof(strShow128Code));

    m_nShStockNum = wShow128.GetRecordNum();
    for (wLoop = 1; wLoop <= m_nShStockNum; wLoop++) {
     wShow128.Goto(wLoop);
     wShow128.ReadFieldsWithMove(1, "S1", strShow128Code);
             strcpy(s_Show[wLoop].stockcode, strShow128Code);
     s_Show[wLoop].index = wLoop;  if (::PeekMessage(&message, NULL, 0, 0, PM_REMOVE)) {
     ::TranslateMessage(&message);
     ::DispatchMessage(&message);
     }
    }
    wShow128.Close();
    }
    else {
    AfxMessageBox("打开show128.dbf建索引时出错!");
    exit(1);
    }
    }BOOL CMymncgDlg::EqualTime(CString strDate)
    {
    CString   eDate;
    CTime   m_eTime = CTime::GetCurrentTime();
    int     eYear, eMonth, eDay;
    eYear = m_eTime.GetYear();
    eMonth = m_eTime.GetMonth();
    eDay = m_eTime.GetDay();
        eDate.Format("%d%02d%02d", eYear, eMonth, eDay);
    if (strcmp(strDate, eDate))
    return (false);
    else 
    return (true);
    }void CMymncgDlg::Liquidate()
    {
    WDBF        lWdbf;
    int         i;
    CString     lStockCode;
    char        cSzCode[10];
    char        ClosePrice[10];
    memset(cSzCode, 0, sizeof(cSzCode));
    memset(ClosePrice, 0, sizeof(ClosePrice));
    double      Ycp;
    MSG message;

    m_strState = "系统正在清算处理中!";
    UpdateData(FALSE);

    if (m_bLink.ConnectDatabase()) {    //把show128.dbf和z_hq.dbf中的昨收盘价写进stockcode表中
        if (!(lWdbf.Open(strFileName[0], CFile::shareDenyNone | CFile::typeBinary))) {
        for (i = 1; i < lWdbf.GetRecordNum()+1; i++) {
         lWdbf.Goto(i);
         lWdbf.ReadFieldsWithMove(2, "S1", lStockCode, "S8", ClosePrice);
         Ycp = atof(ClosePrice);
     m_bLink.UpdateCp(lStockCode, 2, Ycp);  if (::PeekMessage(&message, NULL, 0, 0, PM_REMOVE)) {
     ::TranslateMessage(&message);
     ::DispatchMessage(&message);
     }
     PostMessage(WM_TIMER, 4);
    }
    lWdbf.Close();
    }
            else {
        AfxMessageBox("清算时打开show128.dbf文件失败!");
    exit(1);
    } if (!(lWdbf.Open(strFileName[2], CFile::shareDenyNone | CFile::typeBinary))) {
    for (i = 1; i < lWdbf.GetRecordNum()+1; i++) {
         lWdbf.Goto(i);
     lWdbf.ReadFieldsWithMove(2, "FZQDM", cSzCode, "FZJCJ", ClosePrice);
     lStockCode.Format("%s", cSzCode);
     if (lStockCode.GetLength() < 6)
     lStockCode = "00" + lStockCode;
     Ycp = atof(ClosePrice);
     m_bLink.UpdateCp(lStockCode, 1, Ycp);

     if (::PeekMessage(&message, NULL, 0, 0, PM_REMOVE)) {
     ::TranslateMessage(&message);
     ::DispatchMessage(&message);
     }
     PostMessage(WM_TIMER, 4);

    }
    lWdbf.Close();
    }
    else { 
    AfxMessageBox("清算时打开z_hq.dbf文件失败!");
    exit(1);
    } /*调用清算处理*/
            m_bLink.DealAccount(); m_bLink.LogoutSQLServer();

    CTime LiqTime = CTime::GetCurrentTime();    //把清算时间写进配置文件中
    int   LiqYear, LiqMonth, LiqDay, LiqHour, LiqMint;
    LiqYear = LiqTime.GetYear();
    LiqMonth = LiqTime.GetMonth();
    LiqDay = LiqTime.GetDay();
    LiqHour = LiqTime.GetHour();
    LiqMint = LiqTime.GetMinute();
    CString   lTime;
    lTime.Format("%d%02d%02d%02d%02d", LiqYear, LiqMonth, LiqDay, LiqHour, LiqMint);
    WritePrivateProfileString("清算", "清算时间", lTime, m_strIni); m_strState = "系统清算处理完成!";
    UpdateData(FALSE);
    }
    else { 
    AfxMessageBox("连接数据库错误!");
            exit(1);
    }
    }void CMymncgDlg::Match()
    {
    if (m_bLink.ConnectDatabase()) {
         m_bLink.DealOrder();
    m_bLink.LogoutSQLServer();
    }
    else { 
            AfxMessageBox("连接数据库错误!");
    exit(1);
    }
    }double CMymncgDlg::GetDbfCp(CString strHq, CString stockcode)
    {
    int   k;
    k = SzBinSearch(s_Mmp, m_nSzStockNum, stockcode);
    if (k == -1) return 0;
    WDBF   m_wdbf;
    char   Ycp[10];
    memset(Ycp, 0, sizeof(Ycp));
    double Cp;
    if (!m_wdbf.Open(strHq, CFile::shareDenyNone | CFile::typeBinary)) {
            m_wdbf.Goto(s_Hq[k].index);
    m_wdbf.ReadFieldsWithMove(1, "FZRSP", Ycp);
            m_wdbf.Close();
    }
        else {
    AfxMessageBox("打开z_hq.dbf出错,取昨收盘价错误!");
    exit(1);
    }
    Cp = atof(Ycp);
    return (Cp);
    }void CMymncgDlg::DealZqxx(CString strZqxx, CString strHq)
    {
    m_bLink.ClearTable("indexofszstock"); MSG   message;
    CFile             m_cZqxx;
        CFileException    dbfZqxx;
    if (m_cZqxx.Open(strZqxx, CFile::shareDenyNone | CFile::typeBinary, &dbfZqxx)) {
        LONG     zOffset;
    ULONG    zLoop;
        char   cZqxxCode[5], strZqxxName[10], strZqxxPrice[10];
        memset(cZqxxCode, 0, sizeof(cZqxxCode));
        memset(strZqxxName, 0, sizeof(strZqxxName));
        memset(strZqxxPrice, 0, sizeof(strZqxxPrice));
        double   DbfZqxxCp, SqlZqxxCp, DiffCp;
    CString  strZqxxCode;

    zOffset = m_cDbf[1].usHeadLen+1;
        for (zLoop = 0; zLoop < m_cDbf[1].ulRecordSum; zLoop++) {
         m_cZqxx.Seek(zOffset, CFile::begin);
                 m_cZqxx.Read(cZqxxCode, 4);
     m_cZqxx.Seek(zOffset+4, CFile::begin);
     m_cZqxx.Read(strZqxxName, 8);
     strZqxxCode.Format("%s", cZqxxCode);
     if (strZqxxCode.GetLength() < 6) 
     strZqxxCode = "00"+strZqxxCode;

     S_StockType     m_szType;
     m_bLink.JudgeStockType(strZqxxCode, 1);
     m_szType = m_bLink.m_cStockType;
                 if (m_szType.StockType != -1) {
     DbfZqxxCp = GetDbfCp(strHq, cZqxxCode);
         if (m_bLink.IsExist(strZqxxCode, 1)) {
    // DbfZqxxCp = GetDbfCp(strHq, cZqxxCode);
                         SqlZqxxCp = m_bLink.GetClosePrice(strZqxxCode, 1);
     if (DbfZqxxCp = 0) DbfZqxxCp = SqlZqxxCp;
         DiffCp = SqlZqxxCp-DbfZqxxCp;
         if (DiffCp>0.01)
         m_bLink.WriteRightsWin(strZqxxCode, 1, DiffCp);     //写权益收益
     }
         else {
                      m_bLink.InsertTable(strZqxxCode, 1, strZqxxName, m_szType.StockType, DbfZqxxCp, 1);
    }
    m_bLink.CreateIndex("indexofszstock", strZqxxCode, zLoop+1);
     }

     zOffset = zOffset+m_cDbf[1].usRecLen;  if (::PeekMessage(&message, NULL, 0, 0, PM_REMOVE)) {
     ::TranslateMessage(&message);
     ::DispatchMessage(&message);
     }
     PostMessage(WM_TIMER, 4);
    }
    m_cZqxx.Close();
    }
    else {
    AfxMessageBox("初始化时打开z_zqxx.dbf出错!");
    exit(1);
    }
    }void CMymncgDlg::CreateHqIndex(CString strHq)
    {
    MSG  message;
    CFile            m_cHq;
    CFileException   dbfHq;
    if (m_cHq.Open(strHq, CFile::shareDenyNone | CFile::typeBinary, &dbfHq)) {
            LONG       hOffset;
    ULONG      hLoop;
    char       strHqCode[7];
    memset(strHqCode, 0, sizeof(strHqCode));

    hOffset = m_cDbf[2].usHeadLen+1;
    for (hLoop = 1; hLoop <= m_cDbf[2].ulRecordSum; hLoop++) {
         m_cHq.Seek(hOffset, CFile::begin);
         m_cHq.Read(strHqCode, 4);
             strcpy(s_Hq[hLoop].stockcode, strHqCode);
     s_Hq[hLoop].index = hLoop;
     hOffset = hOffset+m_cDbf[2].usRecLen;  if (::PeekMessage(&message, NULL, 0, 0, PM_REMOVE)) {
     ::TranslateMessage(&message);
     ::DispatchMessage(&message);
     }
     PostMessage(WM_TIMER, 4);
    }
    m_cHq.Close();
    }
    else {
    AfxMessageBox("为z_hq.dbf建索引时打开z_hq.dbf出错!");
        exit(1);
    }
    }void CMymncgDlg::DealShow128Dbf(CString strShow128)
    {
    MSG message;
    m_bLink.ClearTable("indexofshstock");

    CFile             m_cShow128;
        CFileException    dbfShow128;
    if (m_cShow128.Open(strShow128, CFile::shareDenyNone | CFile::typeBinary, &dbfShow128)) {
        LONG     nLocation;
    ULONG    Sloop;
        char   strShCode[7], strShName[10], strShPrice[10];
        memset(strShCode, 0, sizeof(strShCode));
        memset(strShName, 0, sizeof(strShName));
        memset(strShPrice, 0, sizeof(strShPrice));
        double   DbfClosePrice, SqlClosePrice, Difference;
            int      nNum;
    nNum = 0;
    nLocation = m_cDbf[0].usHeadLen+1+m_cDbf[0].usRecLen;
        for (Sloop = 0; Sloop < m_cDbf[0].ulRecordSum-1; Sloop++) {
         m_cShow128.Seek(nLocation, CFile::begin);
                 m_cShow128.Read(strShCode, 6);
     m_cShow128.Seek(nLocation+6, CFile::begin);
     m_cShow128.Read(strShName, 8);
     m_cShow128.Seek(nLocation+14, CFile::begin);
     m_cShow128.Read(strShPrice, 8);
     DbfClosePrice = atof(strShPrice);
     
     if ((strcmp("000001", strShCode) == 1) || (strcmp(strShCode, "000011") == 1)) {
         S_StockType     m_sType;
         m_bLink.JudgeStockType(strShCode, 2);
         m_sType = m_bLink.m_cStockType;
                     if (m_sType.StockType != -1) {
             if (m_bLink.IsExist(strShCode, 2)) {
                 SqlClosePrice = m_bLink.GetClosePrice(strShCode, 2);
             Difference = SqlClosePrice-DbfClosePrice;
             if (Difference>0.01)
             m_bLink.WriteRightsWin(strShCode, 2, Difference);    //写权益收益
     }
             else {
                 m_bLink.InsertTable(strShCode, 2, strShName, m_sType.StockType, DbfClosePrice, 1);
     }
     m_bLink.CreateIndex("indexofshstock", strShCode, Sloop+2);
     }
     }
     nLocation = nLocation+m_cDbf[0].usRecLen;
     
     if (::PeekMessage(&message, NULL, 0, 0, PM_REMOVE)) {
     ::TranslateMessage(&message);
     ::DispatchMessage(&message);
     }
                 PostMessage(WM_TIMER, 4);
    }
    m_cShow128.Close();
    }
    else {
    AfxMessageBox("初始化时打开show128.dbf出错!");
    exit(1);
    }
    }BOOL CMymncgDlg::IsHoliday()
    {
    CTime   m_wTime = CTime::GetCurrentTime();
    int     nDayOfWeek;
    nDayOfWeek = m_wTime.GetDayOfWeek();
    if (nDayOfWeek == 1 || nDayOfWeek == 7)
    return (true);
    else
    return (false);
    }void CMymncgDlg::Initialize()
    {
        m_strState = "系统正在初始化!";
        UpdateData(FALSE); if (m_bLink.ConnectDatabase()) 
            m_bLink.WriteTrustFlag(0, "系统正在初始化");
    else
    // exit(1);
    exit(1);

       m_bLink.WriteLiqFlag(); /*置清算标志为未清算*/   CFile           m_dbfFile;
       CFileException  dbf;
       ULONG           ulRecordSum[5];
       USHORT          usHeadLen[5], usRecLen[5];
       int             i;
       CString         strReadError, strWriteError;   
       //读出五个dbf的头结构信息
       for (i = 0; i < 5; i++) {
       if (m_dbfFile.Open(strFileName[i], CFile::shareDenyNone | CFile::typeBinary, &dbf)) {
       m_dbfFile.Seek(4, CFile::begin);
       m_dbfFile.Read((void *)&ulRecordSum[i], 4);
       m_cDbf[i].ulRecordSum = ulRecordSum[i];    m_dbfFile.Seek(8, CFile::begin);
       m_dbfFile.Read((void *)&usHeadLen[i], 2);
       m_cDbf[i].usHeadLen = usHeadLen[i];    m_dbfFile.Seek(10, CFile::begin);
       m_dbfFile.Read((void *)&usRecLen[i], 2);
       m_cDbf[i].usRecLen = usRecLen[i];
       m_dbfFile.Close();
       
       CFile     m_txtFile;
       CFileException    txt;
       CString sFileName[5];        GetPrivateProfileString("生成文件", "show128", "show128.txt", sFileName[0].GetBuffer(64), 64, m_strIni);
       GetPrivateProfileString("生成文件", "zqxx", "zqxx.txt", sFileName[1].GetBuffer(64), 64, m_strIni);
       GetPrivateProfileString("生成文件", "hq", "hq.txt", sFileName[2].GetBuffer(64), 64, m_strIni);
       GetPrivateProfileString("生成文件", "mmp", "mmp.txt", sFileName[3].GetBuffer(64), 64, m_strIni);
       GetPrivateProfileString("生成文件", "zs", "zs.txt", sFileName[4].GetBuffer(64), 64, m_strIni);    //把dbf的结构头信息写入txt文件中
       if (m_txtFile.Open(sFileName[i], CFile::modeCreate | CFile::modeWrite | CFile::typeBinary, &txt)) {
           char       pBuf[12];
       memset(pBuf, 0, sizeof(pBuf));
       
       m_txtFile.SeekToBegin();
       itoa(ulRecordSum[i], pBuf, 10);
       m_txtFile.Write(pBuf, 9);
     
       m_txtFile.Seek(9, CFile::begin);
       itoa(usHeadLen[i], pBuf, 10);
       m_txtFile.Write(pBuf, 8);    m_txtFile.Seek(17, CFile::begin);
       itoa(usRecLen[i], pBuf, 10);
       m_txtFile.Write(pBuf, 4);
       
       m_txtFile.Close();
       }
       else {
       strWriteError.Format("Write the %s file error!", sFileName[i]);
       AfxMessageBox(strWriteError);
       exit(1);
       }
       }  
       else {
               strReadError.Format("Read the %s file error!", strFileName[i]);
       AfxMessageBox(strReadError);
       exit(1);
       }
       }
       DealShow128Dbf(strFileName[0]);
       CreateShow128Index();      //为show128.dbf和z_mmp.dbf文件建索引
       CreateMmpIndex();
       CreateHqIndex(strFileName[2]);
       DealZqxx(strFileName[1], strFileName[2]);
       m_bLink.DealPreengage();   m_bLink.WriteTrustFlag(1, "可以委托下单");
       m_bLink.LogoutSQLServer();   PostMessage(WM_TIMER, 4);   CTime iTime = CTime::GetCurrentTime();    //把初始化时间写进配置文件中
       int      iYear, iMonth, iDay, iHour, iMint;
       iYear = iTime.GetYear();
       iMonth = iTime.GetMonth();
       iDay = iTime.GetDay();
       iHour = iTime.GetHour();
       iMint = iTime.GetMinute();   CString      striDate;
       striDate.Format("%d%02d%02d%02d%02d", iYear, iMonth, iDay, iHour, iMint);
       WritePrivateProfileString("初始化", "初始化时间", striDate, m_strIni);
       m_strState = "系统初始化完成!";
       UpdateData(FALSE);
    }BOOL CMymncgDlg::IsClearData()
    {
    BOOL    bClear;
    bClear = false;    BOOL   bShClearFlag;
    BOOL   bSzClearFlag; bShClearFlag = false;
    bSzClearFlag = false; CFile   m_dbfFile;
    CFileException  cShow, cZqxx; LONG    lOffset;
    USHORT usHeadLen; char strShMarket[20];
    char strSzMarket[20];
    memset(strShMarket, 0, sizeof(strShMarket));
    memset(strSzMarket, 0, sizeof(strSzMarket)); GetPrivateProfileString("DBF文件的路径", "show128.dbf的路径", NULL, strShMarket, sizeof(strShMarket), m_strIni);
        if (m_dbfFile.Open(strShMarket, CFile::shareDenyNone|CFile::typeBinary, &cShow)) {
    m_dbfFile.Seek(8, CFile::begin);
    m_dbfFile.Read((void *)&usHeadLen, 2); char     strShDate[20];
    char     year[5], month[3], day[3]; 
    memset(strShDate, 0, sizeof(strShDate));
    memset(year, 0, sizeof(year));
    memset(month, 0, sizeof(month));
    memset(day, 0, sizeof(day)); lOffset = usHeadLen+1+42;
    m_dbfFile.Seek(lOffset, CFile::begin);
    m_dbfFile.Read(strShDate, 12);
    strncpy(year, strShDate, 4);
    strncpy(month, strShDate+4, 2);
    strncpy(day, strShDate+6, 2); CTime m_ClearToday = CTime::GetCurrentTime();
    int m_nYear = m_ClearToday.GetYear();
    int m_nMonth = m_ClearToday.GetMonth();
    int m_nDay = m_ClearToday.GetDay();
            char strYear[5], strMonth[3], strDay[3];
    memset(strYear, 0, sizeof(strYear));
    memset(strMonth, 0, sizeof(strMonth));
    memset(strDay, 0, sizeof(strDay));
    sprintf(strYear, "%d", m_nYear);
    sprintf(strMonth, "%02d", m_nMonth);
    sprintf(strDay, "%02d", m_nDay);
             
            if (strcmp(strYear, year) || strcmp(strMonth, month) || strcmp(strDay, day))
    bShClearFlag = true;
    m_dbfFile.Close();
    }
        else { 
    AfxMessageBox("判断是不是清盘数据时打开show128.dbf出错!");
    exit(1);
    } GetPrivateProfileString("DBF文件的路径", "z_hq.dbf的路径", NULL, strSzMarket, sizeof(strSzMarket), m_strIni);
        if (m_dbfFile.Open(strSzMarket, CFile::shareDenyNone|CFile::typeBinary, &cZqxx)) {
    m_dbfFile.Seek(8, CFile::begin);
    m_dbfFile.Read((void*)&usHeadLen, 2); USHORT usRecLen;
            m_dbfFile.Seek(10, CFile::begin);
    m_dbfFile.Read((void*)&usRecLen, 2);
            
    char   newprice[10];
    double price;
    memset(newprice, 0, sizeof(newprice)); lOffset = usHeadLen+1+41;

    for (int i = 0; i < 5; i++) {
    m_dbfFile.Seek(lOffset, CFile::begin);
    m_dbfFile.Read((float*)&newprice, 7);
    price = atof(newprice);
    if ((price-0) > 0.0001)
    break;
    lOffset = lOffset + usHeadLen;
    } if (i == 5) 
    bSzClearFlag = true;
    m_dbfFile.Close();
    }
    else {
    AfxMessageBox("判断是不是清盘数据时打开z_hq.dbf文件出错!");
    exit(1);
    }
    bClear = bShClearFlag && bSzClearFlag;
        return (bClear);
    }
    // mymncgDlg.cpp : implementation file
    //#include "stdafx.h"
    #include "mymncg.h"
    #include "mymncgDlg.h"#include "SQLServer.h"
    #include "WDBF.H"
    #include "WarnDlg.h"#ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif/////////////////////////////////////////////////////////////////////////////
    // CAboutDlg dialog used for App Aboutclass CAboutDlg : public CDialog
    {
    public:
    CAboutDlg();// Dialog Data
    //{{AFX_DATA(CAboutDlg)
    enum { IDD = IDD_ABOUTBOX };
    //}}AFX_DATA // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CAboutDlg)
    protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
    //}}AFX_VIRTUAL// Implementation
    protected:
    //{{AFX_MSG(CAboutDlg)
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
    };CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
    {
    //{{AFX_DATA_INIT(CAboutDlg)
    //}}AFX_DATA_INIT
    }void CAboutDlg::DoDataExchange(CDataExchange* pDX)
    {
    CDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CAboutDlg)
    //}}AFX_DATA_MAP
    }BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
    //{{AFX_MSG_MAP(CAboutDlg)
    // No message handlers
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
    // CMymncgDlg dialogCMymncgDlg::CMymncgDlg(CWnd* pParent /*=NULL*/)
    : CDialog(CMymncgDlg::IDD, pParent)
    {
    //{{AFX_DATA_INIT(CMymncgDlg)
    m_strCreate = _T("");
    m_strSh = _T("");
    m_strShAstock = _T("");
    m_strShBstock = _T("");
    m_strState = _T("");
    m_strSz = _T("");
    m_strSzAstock = _T("");
    m_strSzBstock = _T("");
    m_sysTime = _T("");
    //}}AFX_DATA_INIT
    // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
    m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);

    //初始化&s_hq等
    memset(&s_Hq, 0, sizeof(s_Hq));
    memset(&s_Mmp, 0, sizeof(s_Mmp));
    memset(&s_Show, 0, sizeof(s_Show));

    //为m_cDbf[]赋初值
    bStopFlag = true;
    int       loop;
    for (loop = 0; loop < 5; loop++) { 
    m_cDbf[loop].ulRecordSum = 0;
    m_cDbf[loop].usHeadLen = 0;
    m_cDbf[loop].usRecLen = 0;
    } //获得mncg.ini的路径,赋给m_strIni
    CFile     m_cFile;
        CFileException  e;
        m_cFile.Open("mncg.ini", CFile::modeWrite, &e);
    m_strIni = m_cFile.GetFilePath();
        m_cFile.Close(); //获得各dbf的路径,并保存在strFileName[]中
    GetPrivateProfileString("DBF文件的路径", "show128.dbf的路径", "", strFileName[0].GetBuffer(64), 64, m_strIni);
        GetPrivateProfileString("DBF文件的路径", "z_zqxx.dbf的路径", "", strFileName[1].GetBuffer(64), 64, m_strIni);
        GetPrivateProfileString("DBF文件的路径", "z_hq.dbf的路径", "", strFileName[2].GetBuffer(64), 64, m_strIni);
        GetPrivateProfileString("DBF文件的路径", "z_mmp.dbf的路径", "", strFileName[3].GetBuffer(64), 64, m_strIni);
    GetPrivateProfileString("DBF文件的路径", "z_zs.dbf的路径", "", strFileName[4].GetBuffer(64), 64, m_strIni);

    //判断撮合时间是否正确
    char      cMatch[10];
    memset(cMatch, 0, sizeof(cMatch));
        GetPrivateProfileString("撮合", "上午撮合开始时间", "925", cMatch, sizeof(cMatch), m_strIni);
    nAmS = atoi(cMatch);
    GetPrivateProfileString("撮合", "上午撮合结束时间", "1100", cMatch, sizeof(cMatch), m_strIni);
    nAmE = atoi(cMatch);
    GetPrivateProfileString("撮合", "下午撮合开始时间", "1300", cMatch, sizeof(cMatch), m_strIni);
    nPmS = atoi(cMatch);
    GetPrivateProfileString("撮合", "下午撮合结束时间", "1500", cMatch, sizeof(cMatch), m_strIni);
    nPmE = atoi(cMatch);
    if ((nAmS < 0) || (nAmS/100 >23) || (nAmS%100 > 59)) {
    AfxMessageBox("上午撮合开始时间设置错误,请重新设置!");
    exit(1);
    }
    if ((nAmE < 0) || (nAmE/100 > 23) || (nAmE%100 > 59)) {
    AfxMessageBox("上午撮合结束时间设置错误,请重新设置!");
    exit(1);
    }
    if (nAmS > nAmE) {
    AfxMessageBox("上午撮合时间设置错误,请重新设置上午撮合开始和结束时间!");
    exit(1);
    }
    if ((nPmS < 0) || (nPmS/100 > 23) || (nPmS%100 > 59)) {
    AfxMessageBox("下午撮合开始时间设置错误,请重新设置!");
    exit(1);
    }
    if ((nPmE < 0) || (nPmE/100 > 23) || (nPmE%100 > 59)) {
    AfxMessageBox("下午撮合结束时间设置错误,请重新设置!");
    exit(1);
    }
    if (nPmS > nPmE) {
    AfxMessageBox("下午撮合时间设置错误,请重新设置下午撮合开始和结束时间!");
    exit(1);
    }
    if (nAmE > nPmS) {
    AfxMessageBox("下午撮合开始时间和上午撮合开始时间设置错误,请重新设置!");
    exit(1);
    }
    }
    void CMymncgDlg::DoDataExchange(CDataExchange* pDX)
    {
    CDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CMymncgDlg)
    DDX_Control(pDX, IDC_LIQUIDATE, m_ctrLiquidate);
    DDX_Control(pDX, IDC_CONTRAL, m_ctrContral);
    DDX_Control(pDX, ID_START, m_ctrStart);
    DDX_Control(pDX, ID_EXIT, m_ctrExit);
    DDX_Text(pDX, IDC_STATIC_CREATE, m_strCreate);
    DDV_MaxChars(pDX, m_strCreate, 12);
    DDX_Text(pDX, IDC_STATIC_SH, m_strSh);
    DDV_MaxChars(pDX, m_strSh, 12);
    DDX_Text(pDX, IDC_STATIC_SHASTOCK, m_strShAstock);
    DDV_MaxChars(pDX, m_strShAstock, 12);
    DDX_Text(pDX, IDC_STATIC_SHBSTOCK, m_strShBstock);
    DDV_MaxChars(pDX, m_strShBstock, 12);
    DDX_Text(pDX, IDC_STATIC_STATE, m_strState);
    DDV_MaxChars(pDX, m_strState, 24);
    DDX_Text(pDX, IDC_STATIC_SZ, m_strSz);
    DDV_MaxChars(pDX, m_strSz, 12);
    DDX_Text(pDX, IDC_STATIC_SZASTOCK, m_strSzAstock);
    DDV_MaxChars(pDX, m_strSzAstock, 12);
    DDX_Text(pDX, IDC_STATIC_SZBSTOCK, m_strSzBstock);
    DDV_MaxChars(pDX, m_strSzBstock, 12);
    DDX_Text(pDX, IDC_STATIC_Time, m_sysTime);
    DDV_MaxChars(pDX, m_sysTime, 20);
    //}}AFX_DATA_MAP
    }BEGIN_MESSAGE_MAP(CMymncgDlg, CDialog)
    //{{AFX_MSG_MAP(CMymncgDlg)
    ON_WM_SYSCOMMAND()
    ON_WM_PAINT()
    ON_WM_QUERYDRAGICON()
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
    // CMymncgDlg message handlersBOOL CMymncgDlg::OnInitDialog()
    {
    CDialog::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range.
    ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
    ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE);
    if (pSysMenu != NULL)
    {
    CString strAboutMenu;
    strAboutMenu.LoadString(IDS_ABOUTBOX);
    if (!strAboutMenu.IsEmpty())
    {
    pSysMenu->AppendMenu(MF_SEPARATOR);
    pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
    }
    } // Set the icon for this dialog.  The framework does this automatically
    //  when the application's main window is not a dialog
    SetIcon(m_hIcon, TRUE); // Set big icon
    SetIcon(m_hIcon, FALSE); // Set small icon

    //设置Timer1的循环时间
    SetTimer(1, 10, NULL); //设置Timer4的循环时间
    SetTimer(4, 1000, NULL);

    ReadShow();
    ReadZs(); CTime sysTime = CTime::GetCurrentTime();
    int sysYear = sysTime.GetYear();
    int sysMonth = sysTime.GetMonth();
    int sysDay = sysTime.GetDay();
    int sysHour = sysTime.GetHour();
    int sysMinute = sysTime.GetMinute();
    int sysSecond = sysTime.GetSecond();
    m_sysTime.Format("%d-%02d-%02d %02d:%02d:%02d", sysYear, sysMonth, sysDay, sysHour, sysMinute, sysSecond);
    UpdateData(false);

    return TRUE;  // return TRUE  unless you set the focus to a control
    }void CMymncgDlg::OnSysCommand(UINT nID, LPARAM lParam)
    {
    if ((nID & 0xFFF0) == IDM_ABOUTBOX)
    {
    CAboutDlg dlgAbout;
    dlgAbout.DoModal();
    }
    else
    {
    CDialog::OnSysCommand(nID, lParam);
    }
    }// If you add a minimize button to your dialog, you will need the code below
    //  to draw the icon.  For MFC applications using the document/view model,
    //  this is automatically done for you by the framework.void CMymncgDlg::OnPaint() 
    {
    if (IsIconic())
    {
    CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle
    int cxIcon = GetSystemMetrics(SM_CXICON);
    int cyIcon = GetSystemMetrics(SM_CYICON);
    CRect rect;
    GetClientRect(&rect);
    int x = (rect.Width() - cxIcon + 1) / 2;
    int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon
    dc.DrawIcon(x, y, m_hIcon);
    }
    else
    {
    CDialog::OnPaint();
    }
    }// The system calls this to obtain the cursor to display while the user drags
    //  the minimized window.
    HCURSOR CMymncgDlg::OnQueryDragIcon()
    {
    return (HCURSOR) m_hIcon;
    }INT CMymncgDlg::SzBinSearch(S_INDEX *S_SzStock, int nCount, CString cKey)
    {
    int nLow, nHigh, nMid;
    nLow = 0;
    nHigh = nCount-1;
    while (nLow <= nHigh) {
    nMid = (nLow+nHigh)/2;
    if (cKey.Compare(S_SzStock[nMid].stockcode) < 0)
    nHigh = nMid-1;
    else if (cKey.Compare(S_SzStock[nMid].stockcode) > 0)
    nLow = nMid+1;
    else return nMid;
    }
    return -1;
    }int CMymncgDlg::ShBinSearch(S_SHINDEX *S_ShStock, int nCount, CString cKey)
    {
    int nLow, nHigh, nMid;
    nLow = 0;
    nHigh = nCount-1;
    while (nLow <= nHigh) {
    nMid = (nLow+nHigh)/2;
    if (cKey.Compare(S_ShStock[nMid].stockcode) < 0)
    nHigh = nMid-1;
    else if (cKey.Compare(S_ShStock[nMid].stockcode) > 0)
    nLow = nMid+1;
    else return nMid;
    }
    return -1;
    }void CMymncgDlg::ReadZs()
    {
    WDBF    wZs;
    char    cSzExponent[10];
    memset(cSzExponent, 0, sizeof(cSzExponent));
        if (!(wZs.Open(strFileName[4], CFile::shareDenyNone | CFile::typeBinary))) {
      wZs.Goto(1);
      wZs.ReadFieldsWithMove(1, "FZJZS", cSzExponent);
      m_strSz = cSzExponent;
      m_strSz.TrimLeft();
      wZs.Goto(11);
      wZs.ReadFieldsWithMove(1, "FZJZS", cSzExponent);
      m_strSzAstock = cSzExponent;
      m_strSzAstock.TrimLeft();
      wZs.Goto(12);
      wZs.ReadFieldsWithMove(1, "FZJZS", cSzExponent);
      m_strSzBstock = cSzExponent;
      m_strSzBstock.TrimLeft();
      wZs.Goto(wZs.GetRecordNum());
      wZs.ReadFieldsWithMove(1, "FZJZS", cSzExponent);
              m_strCreate = cSzExponent;
      m_strCreate.TrimLeft();
      wZs.Close();
    //   UpdateData(false);
    }
    else { 
    AfxMessageBox("打开z_zs.dbf读取指数时出错!");
        exit(1);
    }
    }void CMymncgDlg::ReadShow()
    {
    WDBF     wShow;
    char     cShExponent[10];
    memset(cShExponent, 0, sizeof(cShExponent));
    double   dExponent; if (!(wShow.Open(strFileName[0], CFile::shareDenyNone | CFile::typeBinary))) {
    wShow.Goto(2);
    wShow.ReadFieldsWithMove(1, "S8", cShExponent);
    dExponent = atof(cShExponent);
    m_strSh.Format("%.3f", dExponent);
    wShow.Goto(3);
    wShow.ReadFieldsWithMove(1, "S8", cShExponent);
    dExponent = atof(cShExponent);
    m_strShAstock.Format("%.3f", dExponent);
    wShow.Goto(4);
    wShow.ReadFieldsWithMove(1, "S8", cShExponent);
    m_strShBstock = cShExponent;
    m_strShBstock.TrimLeft();
    wShow.Close();
    // UpdateData(false);
    }
    else {
    AfxMessageBox("打开show128.dbf读取指数时出错,!");
    exit(1);
    }
    }bool CMymncgDlg::IsMatchTime()
    {
    CTime   mTime = CTime::GetCurrentTime();
    int     mHour, mMint, ImTime;
    mHour = mTime.GetHour();
    mMint = mTime.GetMinute();
    ImTime = mHour*100+mMint;
    if (((nAmS < ImTime) && (ImTime < nAmE)) || ((nPmS < ImTime) && (ImTime < nPmE)))
    return (true);
    else
    return (false);
    }BOOL CMymncgDlg::LessTime(int nTime)
    {
    CTime  leTime = CTime::GetCurrentTime();
    int    leHour, leMint, lsTime;
    leHour = leTime.GetHour();
    leMint = leTime.GetMinute();
        lsTime = leHour*100+leMint;
    if (lsTime < nTime)
    return (true);
    else 
    return (false);
    }void CMymncgDlg::DealTimer3()
    {
     if (LessTime(100)) {     //判断是不是过了凌晨一点(是为了防止运行到这里才跨过24点)
         KillTimer(3);
         SetTimer(1, 10000, NULL);
     return;
     }  char     Liq[20];
     memset(Liq, 0, sizeof(Liq));
         GetPrivateProfileString("清算", "清算时间", "00000000", Liq, 9, m_strIni);
         if (EqualTime(Liq) == false) {     //看是否已经清算
         int   lStart, lEnd;
             if (m_bLink.ConnectDatabase()) {    //连接数据库,取清算开始时间和截止时间
             m_bLink.GetLiquidateTime();
         lStart = m_bLink.nLiqBegin;
         lEnd   = m_bLink.nLiqEnd;
     if ((lStart < 0) || (lStart/100 > 23) || (lStart%100 > 59)) {
         AfxMessageBox("系统清算开始时间设置错误,请重新设置!");
         exit(1);
     }
         if ((lEnd < 0) || (lEnd/100 > 23) || (lStart%100 > 59)) {
             AfxMessageBox("系统清算结束时间设置错误,请重新设置!");
         exit(1);
     }
     if (lStart > lEnd) {
     AfxMessageBox("系统清算时间设置错误,请重新设置系统清算开始时间和截止时间!");
         exit(1);
     }
         m_bLink.LogoutSQLServer();
     }
     else {
    AfxMessageBox("连接数据库错误!");
    exit(1);
     }  if (LessTime(lEnd)) {
     if (LessTime(lStart)) {
         m_strState = "系统正在空闲中!";
     UpdateData(FALSE);
     return;
     }
     
     }
       Liquidate();
     }
         KillTimer(3);
     m_strState = "系统正在空闲中!";
     UpdateData(FALSE);
     SetTimer(1, 10000, NULL);
    }void CMymncgDlg::DealTimer2()
    {
    if (LessTime(100)) {     //判断是不是过了凌晨一点(是为了防止运行到这里才跨过24点)
        KillTimer(2);
    SetTimer(1, 10000, NULL);
    return;
    } if (LessTime(nPmE) == false) {   //判断是不是过了下午撮合截止时间
    KillTimer(2);
    m_strState = "系统正在空闲中!";
    UpdateData(FALSE);
    SetTimer(3, 10000, NULL);
    return;
    }
        
    if (IsMatchTime())            //判断是不是撮合时间
    Match(); 
    else {                       //午休时间
    m_strState = "系统正在空闲中!";
    UpdateData(FALSE);
    }
    }void CMymncgDlg::DealTimer1()
    {}double CMymncgDlg::GetSellPrice(CString strStockCode, int nExchangeCode)
    {
    int   k;
    WDBF   sDbf;
    char   SellPrice[10];
    memset(SellPrice, 0, sizeof(SellPrice));
    double Sp; if (nExchangeCode == 1) {
          k = SzBinSearch(s_Mmp, m_nSzStockNum, strStockCode);
    if (k == -1) return 0;
    if (!sDbf.Open(strFileName[3], CFile::shareDenyNone | CFile::modeRead | CFile::typeBinary)) {
                sDbf.Goto(s_Mmp[k].index*6-3);
        sDbf.ReadFieldsWithMove(1, "FJW", SellPrice);
                sDbf.Close();
    }
            else {
        AfxMessageBox("打开z_mmp.dbf错误,取卖一价格出错!");
    exit(1);
    }
        
    } else {
      k = ShBinSearch(s_Show, m_nShStockNum, strStockCode);
    if (k == -1) return 0;
         if (!sDbf.Open(strFileName[0], CFile::shareDenyNone | CFile::typeBinary)) {
                sDbf.Goto(s_Show[k].index);
        sDbf.ReadFieldsWithMove(1, "S10", SellPrice);
                sDbf.Close();
    }
            else {
        AfxMessageBox("打开show128.dbf错误,取卖一价格出错!");
    exit(1);
    }
    } Sp = atof(SellPrice);
    return (Sp);
    }double CMymncgDlg::GetBuyPrice(CString strStockCode, int nExchangeCode)
    {
    int k;
    WDBF   m_dbf;
    char   BuyPrice[10];
    memset(BuyPrice, 0, sizeof(BuyPrice));
    double Bp; if (nExchangeCode == 1) {
      k = SzBinSearch(s_Mmp, m_nSzStockNum, strStockCode);
    if (k == -1) return 0;
         if (!m_dbf.Open(strFileName[3], CFile::shareDenyNone | CFile::typeBinary)) {
                m_dbf.Goto(s_Mmp[k].index*6-2);
        m_dbf.ReadFieldsWithMove(1, "FJW", BuyPrice);
                m_dbf.Close();
    }
            else {
        AfxMessageBox("打开z_mmp.dbf错误,取买一价格出错!");
    exit(1);
    }
        
    } else {
       k = ShBinSearch(s_Show, m_nShStockNum, strStockCode);
    if (k == -1) return 0; 
         if (!m_dbf.Open(strFileName[0], CFile::shareDenyNone | CFile::typeBinary)) {
                m_dbf.Goto(s_Show[k].index);
        m_dbf.ReadFieldsWithMove(1, "S9", BuyPrice);
                m_dbf.Close();
    }
            else {
        AfxMessageBox("打开show128.dbf错误,取买一价格出错!");
    exit(1);
    }
    } Bp = atof(BuyPrice);
    return (Bp);}void CMymncgDlg::CreateMmpIndex()
    {
        MSG      message;
    WDBF     m_cMmp;
    if (!m_cMmp.Open(strFileName[3], CFile::shareDenyNone | CFile::typeBinary)) {
    int        mLoop;
    char       strMmpCode[7];
    memset(strMmpCode, 0, sizeof(strMmpCode));

    m_nSzStockNum = m_cMmp.GetRecordNum()/6;
    for (mLoop = 1; mLoop <= m_nSzStockNum; mLoop++) {
     m_cMmp.Goto(mLoop*6-5);
     m_cMmp.ReadFieldsWithMove(1, "FZQDM", strMmpCode);
             strcpy(s_Mmp[mLoop].stockcode, strMmpCode);
     s_Mmp[mLoop].index = mLoop;  if (::PeekMessage(&message, NULL, 0, 0, PM_REMOVE)) {
     ::TranslateMessage(&message);
     ::DispatchMessage(&message);
     }
    }
    m_cMmp.Close();
    }
    else {
    AfxMessageBox("打开z_mmp.dbf建索引时出错!");
    exit(1);
    }
    }void CMymncgDlg::CreateShow128Index()
    {
    MSG      message;
    WDBF     wShow128;
    if (!wShow128.Open(strFileName[0], CFile::shareDenyNone | CFile::typeBinary)) {
    int        wLoop;
    char       strShow128Code[7];
    memset(strShow128Code, 0, sizeof(strShow128Code));

    m_nShStockNum = wShow128.GetRecordNum();
    for (wLoop = 1; wLoop <= m_nShStockNum; wLoop++) {
     wShow128.Goto(wLoop);
     wShow128.ReadFieldsWithMove(1, "S1", strShow128Code);
             strcpy(s_Show[wLoop].stockcode, strShow128Code);
     s_Show[wLoop].index = wLoop;  if (::PeekMessage(&message, NULL, 0, 0, PM_REMOVE)) {
     ::TranslateMessage(&message);
     ::DispatchMessage(&message);
     }
    }
    wShow128.Close();
    }
    else {
    AfxMessageBox("打开show128.dbf建索引时出错!");
    exit(1);
    }
    }BOOL CMymncgDlg::EqualTime(CString strDate)
    {
    CString   eDate;
    CTime   m_eTime = CTime::GetCurrentTime();
    int     eYear, eMonth, eDay;
    eYear = m_eTime.GetYear();
    eMonth = m_eTime.GetMonth();
    eDay = m_eTime.GetDay();
        eDate.Format("%d%02d%02d", eYear, eMonth, eDay);
    if (strcmp(strDate, eDate))
    return (false);
    else 
    return (true);
    }void CMymncgDlg::Liquidate()
    {
    WDBF        lWdbf;
    int         i;
    CString     lStockCode;
    char        cSzCode[10];
    char        ClosePrice[10];
    memset(cSzCode, 0, sizeof(cSzCode));
    memset(ClosePrice, 0, sizeof(ClosePrice));
    double      Ycp;
    MSG message;

    m_strState = "系统正在清算处理中!";
    UpdateData(FALSE);

    if (m_bLink.ConnectDatabase()) {    //把show128.dbf和z_hq.dbf中的昨收盘价写进stockcode表中
        if (!(lWdbf.Open(strFileName[0], CFile::shareDenyNone | CFile::typeBinary))) {
        for (i = 1; i < lWdbf.GetRecordNum()+1; i++) {
         lWdbf.Goto(i);
         lWdbf.ReadFieldsWithMove(2, "S1", lStockCode, "S8", ClosePrice);
         Ycp = atof(ClosePrice);
     m_bLink.UpdateCp(lStockCode, 2, Ycp);  if (::PeekMessage(&message, NULL, 0, 0, PM_REMOVE)) {
     ::TranslateMessage(&message);
     ::DispatchMessage(&message);
     }
     PostMessage(WM_TIMER, 4);
    }
    lWdbf.Close();
    }
            else {
        AfxMessageBox("清算时打开show128.dbf文件失败!");
    exit(1);
    } if (!(lWdbf.Open(strFileName[2], CFile::shareDenyNone | CFile::typeBinary))) {
    for (i = 1; i < lWdbf.GetRecordNum()+1; i++) {
         lWdbf.Goto(i);
     lWdbf.ReadFieldsWithMove(2, "FZQDM", cSzCode, "FZJCJ", ClosePrice);
     lStockCode.Format("%s", cSzCode);
     if (lStockCode.GetLength() < 6)
     lStockCode = "00" + lStockCode;
     Ycp = atof(ClosePrice);
     m_bLink.UpdateCp(lStockCode, 1, Ycp);

     if (::PeekMessage(&message, NULL, 0, 0, PM_REMOVE)) {
     ::TranslateMessage(&message);
     ::DispatchMessage(&message);
     }
     PostMessage(WM_TIMER, 4);

    }
    lWdbf.Close();
    }
    else { 
    AfxMessageBox("清算时打开z_hq.dbf文件失败!");
    exit(1);
    } /*调用清算处理*/
            m_bLink.DealAccount(); m_bLink.LogoutSQLServer();

    CTime LiqTime = CTime::GetCurrentTime();    //把清算时间写进配置文件中
    int   LiqYear, LiqMonth, LiqDay, LiqHour, LiqMint;
    LiqYear = LiqTime.GetYear();
    LiqMonth = LiqTime.GetMonth();
    LiqDay = LiqTime.GetDay();
    LiqHour = LiqTime.GetHour();
    LiqMint = LiqTime.GetMinute();
    CString   lTime;
    lTime.Format("%d%02d%02d%02d%02d", LiqYear, LiqMonth, LiqDay, LiqHour, LiqMint);
    WritePrivateProfileString("清算", "清算时间", lTime, m_strIni); m_strState = "系统清算处理完成!";
    UpdateData(FALSE);
    }
    else { 
    AfxMessageBox("连接数据库错误!");
            exit(1);
    }
    }void CMymncgDlg::Match()
    {
    if (m_bLink.ConnectDatabase()) {
         m_bLink.DealOrder();
    m_bLink.LogoutSQLServer();
    }
    else { 
            AfxMessageBox("连接数据库错误!");
    exit(1);
    }
    }double CMymncgDlg::GetDbfCp(CString strHq, CString stockcode)
    {
    int   k;
    k = SzBinSearch(s_Mmp, m_nSzStockNum, stockcode);
    if (k == -1) return 0;
    WDBF   m_wdbf;
    char   Ycp[10];
    memset(Ycp, 0, sizeof(Ycp));
    double Cp;
    if (!m_wdbf.Open(strHq, CFile::shareDenyNone | CFile::typeBinary)) {
            m_wdbf.Goto(s_Hq[k].index);
    m_wdbf.ReadFieldsWithMove(1, "FZRSP", Ycp);
            m_wdbf.Close();
    }
        else {
    AfxMessageBox("打开z_hq.dbf出错,取昨收盘价错误!");
    exit(1);
    }
    Cp = atof(Ycp);
    return (Cp);
    }void CMymncgDlg::DealZqxx(CString strZqxx, CString strHq)
    {
    m_bLink.ClearTable("indexofszstock"); MSG   message;
    CFile             m_cZqxx;
        CFileException    dbfZqxx;
    if (m_cZqxx.Open(strZqxx, CFile::shareDenyNone | CFile::typeBinary, &dbfZqxx)) {
        LONG     zOffset;
    ULONG    zLoop;
        char   cZqxxCode[5], strZqxxName[10], strZqxxPrice[10];
        memset(cZqxxCode, 0, sizeof(cZqxxCode));
        memset(strZqxxName, 0, sizeof(strZqxxName));
        memset(strZqxxPrice, 0, sizeof(strZqxxPrice));
        double   DbfZqxxCp, SqlZqxxCp, DiffCp;
    CString  strZqxxCode;

    zOffset = m_cDbf[1].usHeadLen+1;
        for (zLoop = 0; zLoop < m_cDbf[1].ulRecordSum; zLoop++) {
         m_cZqxx.Seek(zOffset, CFile::begin);
                 m_cZqxx.Read(cZqxxCode, 4);
     m_cZqxx.Seek(zOffset+4, CFile::begin);
     m_cZqxx.Read(strZqxxName, 8);
     strZqxxCode.Format("%s", cZqxxCode);
     if (strZqxxCode.GetLength() < 6) 
     strZqxxCode = "00"+strZqxxCode;

     S_StockType     m_szType;
     m_bLink.JudgeStockType(strZqxxCode, 1);
     m_szType = m_bLink.m_cStockType;
                 if (m_szType.StockType != -1) {
     DbfZqxxCp = GetDbfCp(strHq, cZqxxCode);
         if (m_bLink.IsExist(strZqxxCode, 1)) {
    // DbfZqxxCp = GetDbfCp(strHq, cZqxxCode);
                         SqlZqxxCp = m_bLink.GetClosePrice(strZqxxCode, 1);
     if (DbfZqxxCp = 0) DbfZqxxCp = SqlZqxxCp;
         DiffCp = SqlZqxxCp-DbfZqxxCp;
         if (DiffCp>0.01)
         m_bLink.WriteRightsWin(strZqxxCode, 1, DiffCp);     //写权益收益
     }
         else {
                      m_bLink.InsertTable(strZqxxCode, 1, strZqxxName, m_szType.StockType, DbfZqxxCp, 1);
    }
    m_bLink.CreateIndex("indexofszstock", strZqxxCode, zLoop+1);
     }

     zOffset = zOffset+m_cDbf[1].usRecLen;  if (::PeekMessage(&message, NULL, 0, 0, PM_REMOVE)) {
     ::TranslateMessage(&message);
     ::DispatchMessage(&message);
     }
     PostMessage(WM_TIMER, 4);
    }
    m_cZqxx.Close();
    }
    else {
    AfxMessageBox("初始化时打开z_zqxx.dbf出错!");
    exit(1);
    }
    }void CMymncgDlg::CreateHqIndex(CString strHq)
    {
    MSG  message;
    CFile            m_cHq;
    CFileException   dbfHq;
    if (m_cHq.Open(strHq, CFile::shareDenyNone | CFile::typeBinary, &dbfHq)) {
            LONG       hOffset;
    ULONG      hLoop;
    char       strHqCode[7];
    memset(strHqCode, 0, sizeof(strHqCode));

    hOffset = m_cDbf[2].usHeadLen+1;
    for (hLoop = 1; hLoop <= m_cDbf[2].ulRecordSum; hLoop++) {
         m_cHq.Seek(hOffset, CFile::begin);
         m_cHq.Read(strHqCode, 4);
             strcpy(s_Hq[hLoop].stockcode, strHqCode);
     s_Hq[hLoop].index = hLoop;
     hOffset = hOffset+m_cDbf[2].usRecLen;  if (::PeekMessage(&message, NULL, 0, 0, PM_REMOVE)) {
     ::TranslateMessage(&message);
     ::DispatchMessage(&message);
     }
     PostMessage(WM_TIMER, 4);
    }
    m_cHq.Close();
    }
    else {
    AfxMessageBox("为z_hq.dbf建索引时打开z_hq.dbf出错!");
        exit(1);
    }
    }void CMymncgDlg::DealShow128Dbf(CString strShow128)
    {
    MSG message;
    m_bLink.ClearTable("indexofshstock");

    CFile             m_cShow128;
        CFileException    dbfShow128;
    if (m_cShow128.Open(strShow128, CFile::shareDenyNone | CFile::typeBinary, &dbfShow128)) {
        LONG     nLocation;
    ULONG    Sloop;
        char   strShCode[7], strShName[10], strShPrice[10];
        memset(strShCode, 0, sizeof(strShCode));
        memset(strShName, 0, sizeof(strShName));
        memset(strShPrice, 0, sizeof(strShPrice));
        double   DbfClosePrice, SqlClosePrice, Difference;
            int      nNum;
    nNum = 0;
    nLocation = m_cDbf[0].usHeadLen+1+m_cDbf[0].usRecLen;
        for (Sloop = 0; Sloop < m_cDbf[0].ulRecordSum-1; Sloop++) {
         m_cShow128.Seek(nLocation, CFile::begin);
                 m_cShow128.Read(strShCode, 6);
     m_cShow128.Seek(nLocation+6, CFile::begin);
     m_cShow128.Read(strShName, 8);
     m_cShow128.Seek(nLocation+14, CFile::begin);
     m_cShow128.Read(strShPrice, 8);
     DbfClosePrice = atof(strShPrice);
     
     if ((strcmp("000001", strShCode) == 1) || (strcmp(strShCode, "000011") == 1)) {
         S_StockType     m_sType;
         m_bLink.JudgeStockType(strShCode, 2);
         m_sType = m_bLink.m_cStockType;
                     if (m_sType.StockType != -1) {
             if (m_bLink.IsExist(strShCode, 2)) {
                 SqlClosePrice = m_bLink.GetClosePrice(strShCode, 2);
             Difference = SqlClosePrice-DbfClosePrice;
             if (Difference>0.01)
             m_bLink.WriteRightsWin(strShCode, 2, Difference);    //写权益收益
     }
             else {
                 m_bLink.InsertTable(strShCode, 2, strShName, m_sType.StockType, DbfClosePrice, 1);
     }
     m_bLink.CreateIndex("indexofshstock", strShCode, Sloop+2);
     }
     }
     nLocation = nLocation+m_cDbf[0].usRecLen;
     
     if (::PeekMessage(&message, NULL, 0, 0, PM_REMOVE)) {
     ::TranslateMessage(&message);
     ::DispatchMessage(&message);
     }
                 PostMessage(WM_TIMER, 4);
    }
    m_cShow128.Close();
    }
    else {
    AfxMessageBox("初始化时打开show128.dbf出错!");
    exit(1);
    }
    }BOOL CMymncgDlg::IsHoliday()
    {
    CTime   m_wTime = CTime::GetCurrentTime();
    int     nDayOfWeek;
    nDayOfWeek = m_wTime.GetDayOfWeek();
    if (nDayOfWeek == 1 || nDayOfWeek == 7)
    return (true);
    else
    return (false);
    }void CMymncgDlg::Initialize()
    {
        m_strState = "系统正在初始化!";
        UpdateData(FALSE); if (m_bLink.ConnectDatabase()) 
            m_bLink.WriteTrustFlag(0, "系统正在初始化");
    else
    // exit(1);
    exit(1);

       m_bLink.WriteLiqFlag(); /*置清算标志为未清算*/   CFile           m_dbfFile;
       CFileException  dbf;
       ULONG           ulRecordSum[5];
       USHORT          usHeadLen[5], usRecLen[5];
       int             i;
       CString         strReadError, strWriteError;   
       //读出五个dbf的头结构信息
       for (i = 0; i < 5; i++) {
       if (m_dbfFile.Open(strFileName[i], CFile::shareDenyNone | CFile::typeBinary, &dbf)) {
       m_dbfFile.Seek(4, CFile::begin);
       m_dbfFile.Read((void *)&ulRecordSum[i], 4);
       m_cDbf[i].ulRecordSum = ulRecordSum[i];    m_dbfFile.Seek(8, CFile::begin);
       m_dbfFile.Read((void *)&usHeadLen[i], 2);
       m_cDbf[i].usHeadLen = usHeadLen[i];    m_dbfFile.Seek(10, CFile::begin);
       m_dbfFile.Read((void *)&usRecLen[i], 2);
       m_cDbf[i].usRecLen = usRecLen[i];
       m_dbfFile.Close();
       
       CFile     m_txtFile;
       CFileException    txt;
       CString sFileName[5];        GetPrivateProfileString("生成文件", "show128", "show128.txt", sFileName[0].GetBuffer(64), 64, m_strIni);
       GetPrivateProfileString("生成文件", "zqxx", "zqxx.txt", sFileName[1].GetBuffer(64), 64, m_strIni);
       GetPrivateProfileString("生成文件", "hq", "hq.txt", sFileName[2].GetBuffer(64), 64, m_strIni);
       GetPrivateProfileString("生成文件", "mmp", "mmp.txt", sFileName[3].GetBuffer(64), 64, m_strIni);
       GetPrivateProfileString("生成文件", "zs", "zs.txt", sFileName[4].GetBuffer(64), 64, m_strIni);    //把dbf的结构头信息写入txt文件中
       if (m_txtFile.Open(sFileName[i], CFile::modeCreate | CFile::modeWrite | CFile::typeBinary, &txt)) {
           char       pBuf[12];
       memset(pBuf, 0, sizeof(pBuf));
       
       m_txtFile.SeekToBegin();
       itoa(ulRecordSum[i], pBuf, 10);
       m_txtFile.Write(pBuf, 9);
     
       m_txtFile.Seek(9, CFile::begin);
       itoa(usHeadLen[i], pBuf, 10);
       m_txtFile.Write(pBuf, 8);    m_txtFile.Seek(17, CFile::begin);
       itoa(usRecLen[i], pBuf, 10);
       m_txtFile.Write(pBuf, 4);
       
      

  2.   

    赫赫,上面太多了,我改一下!
    // mymncgDlg.h : header file
    //#if !defined(AFX_MYMNCGDLG_H__D7B96591_DECC_42E3_8DC8_7061E1491E9D__INCLUDED_)
    #define AFX_MYMNCGDLG_H__D7B96591_DECC_42E3_8DC8_7061E1491E9D__INCLUDED_#include "SQLServer.h"
    #include "WDBF.H" // Added by ClassView
    #include "sqlfront.h" // Added by ClassView#if _MSC_VER > 1000
    #pragma once
    #endif // _MSC_VER > 1000/////////////////////////////////////////////////////////////////////////////
    // CMymncgDlg dialogtypedef  struct {
    char         stockcode[7];
    int          index;
    } S_INDEX;typedef struct {
    char        stockcode[7];
    int         index;
    } S_SHINDEX;class CMymncgDlg : public CDialog
    {
    // Construction
    public:

    CSQLServer     m_bLink;
    CString   strFileName[5];
    BOOL IsClearData( );
    void Initialize( );
    BOOL IsHoliday( );
    CString m_strIni;
    void DealShow128Dbf(CString strShow128);
    S_SHINDEX         s_Show[2000];
    S_INDEX           s_Hq[2000];
    S_INDEX           s_Mmp[2000];
    S_DBF_HEAD_STRUCT m_cDbf[5];    //0 show128.dbf, 1 z_zqxx.dbf, 2 z_hq.dbf, 3 z_mmp.dbf, 4 z_zs.dbf
    void CreateHqIndex(CString strHq);
    void DealZqxx(CString strZqxx, CString strHq);
    double GetDbfCp(CString strHq, CString stockcode);
    void Match( );
    void Liquidate( );
    BOOL EqualTime(CString   strDate);

    void CreateShow128Index( );
    void CreateMmpIndex( );
    double GetBuyPrice(CString strStockCode, int nExchangeCode);
    double GetSellPrice(CString strStockCode, int nExchangeCode);//取股票的卖一价格
    BOOL bStopFlag;
    int nAmS, nAmE, nPmS, nPmE; //分别表示上午撮合开始结束时间和下午撮合开始结束时间;
    void DealTimer1(); //初始化的timer
    void DealTimer2(); //撮合的timer
    void DealTimer3( ); //清算的timer
    BOOL LessTime(int nTime); //判断时间是不是大于系统时间(指小时和分钟)
    bool IsMatchTime( ); //判断是不是撮合时间段
    void ReadShow(); //读取上海股票的指数
    void ReadZs( ); //读取深证股票的指数
    int ShBinSearch(S_SHINDEX* S_ShStock, int nCount, CString cKey);//查找深圳股票代码
    int SzBinSearch(S_INDEX* S_SzStock, int nCount, CString cKey);//查找上海股票代码
    CMymncgDlg(CWnd* pParent = NULL); // standard constructor// Dialog Data
    //{{AFX_DATA(CMymncgDlg)
    enum { IDD = IDD_MYMNCG_DIALOG };
    CButton m_ctrLiquidate;
    CButton m_ctrContral;
    CButton m_ctrStart;
    CButton m_ctrExit;
    CString m_strCreate;
    CString m_strSh;
    CString m_strShAstock;
    CString m_strShBstock;
    CString m_strState;
    CString m_strSz;
    CString m_strSzAstock;
    CString m_strSzBstock;
    CString m_sysTime;
    //}}AFX_DATA // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CMymncgDlg)
    protected:
    virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
    //}}AFX_VIRTUAL// Implementation
    protected:
    HICON m_hIcon; int m_nShStockNum;
    int m_nSzStockNum;
    // Generated message map functions
    //{{AFX_MSG(CMymncgDlg)
    virtual BOOL OnInitDialog();
    afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
    afx_msg void OnPaint();
    afx_msg HCURSOR OnQueryDragIcon();
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
    };//{{AFX_INSERT_LOCATION}}
    // Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_MYMNCGDLG_H__D7B96591_DECC_42E3_8DC8_7061E1491E9D__INCLUDED_)
      

  3.   

    太长了,看不清楚,把程序发到我信箱里,我帮你看看,说不定我会搞定他
    [email protected]
      

  4.   

    要生成一个CRecordSet的类,然后就很好用了。
      

  5.   

    谢谢了!我已经发出去了
    而且刚才我发现把sqlserver.cpp加到程序里面就会这样。不知为什么。看英文的意思可能是有什么不明的外部标志。。不过我不明白什么意思哦
      

  6.   

    说简单点儿是这样的:
    我有一个程序A能连接SQLSERVER(可用)。
    现在想自己写一个程序B,需要连接SQLSERVER,所以,我把A里面连接SQLSERVER的类CSQLSERVER拿出来,也就是SQLSERVER.CPP和SQLSERVER.H,通过FILEVIEW把CSQLSERVER加到B里面去,但是编译的时候出现了这贴子最上面出现的问题
    怎么回事?
      

  7.   

    必须连接几个lib文件才行啊,odbc32.lib
      

  8.   

    没有lib,在setting中的link中加入lib,好像是 NtwdbLib.Lib