📄 myfunction.cpp
字号:
#include "stdafx.h"
#include "a1.h"
#include "myfunction.h"
#include "DrawDlg.h"
#include "ScrollPrintView.h"
_ConnectionPtr LRunSql::m_database;
LRunSql::LRunSql()
{
m_recordset.CreateInstance(__uuidof(Recordset));
}
LRunSql::~LRunSql()
{
}
bool LRunSql::RunSQL(CString sql)
{
_bstr_t sql_=sql;
try{
m_recordset=m_database->Execute(sql_,NULL,adCmdText);
}
catch(_com_error& e)
{
ErrorsPtr pErrors=m_database->GetErrors();
if (pErrors->GetCount()==0)
{
//AfxMessageBox(e.ErrorMessage());
afxDump<<e.ErrorMessage();
}
else
{
for (int i=0;i<pErrors->GetCount();i++)
{
_bstr_t desc=pErrors->GetItem((long)i)->GetDescription();
// AfxMessageBox(desc);
afxDump<<(char*)desc;
}
}
return false;
}
return true;
}
bool LRunSql::CheckSQLResult(CString sql)
{
if(!this->RunSQL(sql))
return false;
else
{
if(!this->m_recordset->adoEOF)
return true;
else
return false;
}
return true;
}
void DateToInt(CString date,int& year,int& month,int& day)
{
int a_1=date.Find('-',0);
int a_2=date.Find('-',5);
CString y=date.Mid(0,4);
CString m=date.Mid(a_1+1,a_2-a_1);
CString d=date.Mid(a_2+1,date.GetLength()-a_2);
year=atoi(y);
month=atoi(m);
day=atoi(d);
}
bool OpenPrintFrame(CWnd* parent,CDrawDlg * m_draw)
{
CA1App* app=(CA1App*)AfxGetApp();
ASSERT(app!=NULL);
if(app->pDocTemplate->m_frame!=NULL)
return true;
app->pDocTemplate->SetFrameParent(parent);//NULL
try{
// app->pDocTemplate->OpenDocumentFile(NULL);
app->m_pDocManager->OnFileNew();
// app->OnFileNew();
}
catch(...)
{
app->Dump(afxDump);
return false;
}
CMyFrame * temp=NULL;
temp=app->pDocTemplate->GetMyFrame();
if(temp==NULL||temp->m_hWnd==NULL)
{
AfxMessageBox("打印出错!");
return false;
}
ASSERT_KINDOF(CMyFrame,temp);
CString strTitle;
parent->GetWindowText(strTitle);
temp->SetWindowText(strTitle);
// AfxMessageBox(temp->GetTitle());
temp->SetTitle(strTitle);
CScrollPrintView* pView=(CScrollPrintView*)temp->GetActiveView();
pView->SelectDrawDlg(m_draw);
return true;
}
bool LRunSql::ConnectDataBase()
{
try{
m_database->Open(L"yaopin","","",-1);
}
catch(...)
{
::ShellExecute(NULL,"open","AutoConfig.exe",NULL,NULL,SW_HIDE);
return false;
}
return true;
}
bool LRunSql::InitConnectPtr()
{
::CoInitializeEx(NULL,COINIT_APARTMENTTHREADED);
if(FAILED(m_database.CreateInstance(__uuidof(Connection))))
return false;
if(ConnectDataBase()==false)
{
::Sleep(1000);
if(ConnectDataBase()==false)
{
MessageBox(NULL,"系统试图自动为您配置ODBC,但由于一些原因没有完成,请手工配置!","系统提示",MB_OK|MB_ICONSTOP);
return false;
}
}
return true;
}
bool LRunSql::Close()
{
return (!FAILED(m_database->Close()));
}
bool LRunSql::BeginTrans()
{
return (!FAILED(m_database->BeginTrans()));
}
bool LRunSql::CommitTrans()
{
return (!FAILED(m_database->CommitTrans()));
}
bool LRunSql::RollbackTrans()
{
return (!FAILED(m_database->RollbackTrans()));
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -