-
-
-
- #include "stdafx.h"
- #include "StudentAccess.h"
- #include "StudentAccessDlg.h"
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
- extern CStudentAccessApp theApp;
-
-
-
- class CAboutDlg : public CDialog
- {
- public:
- CAboutDlg();
-
-
-
- enum { IDD = IDD_ABOUTBOX };
-
-
-
-
- protected:
- virtual void DoDataExchange(CDataExchange* pDX);
-
-
-
- protected:
-
-
- DECLARE_MESSAGE_MAP()
- };
-
- CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
- {
-
-
- }
-
- void CAboutDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
-
-
- }
-
- BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
-
-
-
- END_MESSAGE_MAP()
-
-
-
-
- CStudentAccessDlg::CStudentAccessDlg(CWnd* pParent )
- : CDialog(CStudentAccessDlg::IDD, pParent)
- {
-
- m_hPhotoBitmap = NULL;
- m_pBMPBuffer = NULL;
-
-
- m_nAge = 0;
- m_strName = _T("");
- m_strMajor = _T("");
- m_strHome = _T("");
- m_strCollege = _T("");
- m_nLock = -1;
- m_nSecret = -1;
- m_strFileMsg = _T("");
-
-
- m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
- }
-
- void CStudentAccessDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
-
- DDX_Control(pDX, IDC_SECRET, m_comboSecret);
- DDX_Control(pDX, IDC_LOCK2, m_comboLock);
- DDX_Control(pDX, IDC_DATETIMEPICKER_DATE, m_dataTimedoc);
- DDX_Control(pDX, IDC_BUTTON_PARAMETER, m_btnParameter);
- DDX_Control(pDX, IDC_BUTTONREAD, m_btnRead);
- DDX_Control(pDX, IDC_BUTTONDELETE, m_btnDelete);
- DDX_Control(pDX, IDC_BUTTONEDIT, m_btnEdit);
- DDX_Control(pDX, IDC_BUTTONADD, m_btnAdd);
- DDX_Control(pDX, IDC_SEX, m_ComboBoxSex);
- DDX_Control(pDX, IDC_LISTACCESS, m_listAccess);
- DDX_Text(pDX, IDC_AGE, m_nAge);
- DDX_Text(pDX, IDC_NAME, m_strName);
- DDX_Text(pDX, IDC_MAJOR, m_strMajor);
- DDX_Text(pDX, IDC_HOME, m_strHome);
- DDX_Text(pDX, IDC_COLLEGE, m_strCollege);
- DDX_CBIndex(pDX, IDC_LOCK2, m_nLock);
- DDX_CBIndex(pDX, IDC_SECRET, m_nSecret);
- DDX_Text(pDX, IDC_FILENAME, m_strFileMsg);
-
- }
-
- BEGIN_MESSAGE_MAP(CStudentAccessDlg, CDialog)
-
- ON_WM_SYSCOMMAND()
- ON_WM_PAINT()
- ON_WM_QUERYDRAGICON()
- ON_BN_CLICKED(IDC_BUTTONREAD, OnReadAccess)
- ON_LBN_SELCHANGE(IDC_LISTACCESS, OnSelchangeListaccess)
- ON_BN_CLICKED(IDC_BUTTONDELETE, OnDelete)
- ON_BN_CLICKED(IDC_BUTTONEDIT, OnEdit)
- ON_BN_CLICKED(IDC_BUTTONADD, OnAdd)
- ON_BN_CLICKED(IDC_BUTTONFILE, OnSelectFile)
- ON_BN_CLICKED(IDC_BUTTON_PARAMETER, OnEditParameter)
- ON_WM_CTLCOLOR()
- ON_BN_CLICKED(IDC_BUTTONHELP, OnHelp)
-
- END_MESSAGE_MAP()
-
-
-
-
- BOOL CStudentAccessDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
-
-
-
-
- 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);
- }
- }
-
-
-
- SetIcon(m_hIcon, TRUE);
- SetIcon(m_hIcon, FALSE);
-
-
-
-
-
- if(!AfxOleInit())
- {
- AfxMessageBox("OLE初始化出错!");
- return FALSE;
- }
-
- m_pConnection.CreateInstance(__uuidof(Connection));
-
- m_pRecordset.CreateInstance(__uuidof(Recordset));
- m_pRecordsetPara.CreateInstance(__uuidof(Recordset));
-
- GetSystemTime(&m_CurTime);
-
- return TRUE;
- }
-
- void CStudentAccessDlg::OnSysCommand(UINT nID, LPARAM lParam)
- {
- if ((nID & 0xFFF0) == IDM_ABOUTBOX)
- {
- CAboutDlg dlgAbout;
- dlgAbout.DoModal();
- }
- else
- {
- CDialog::OnSysCommand(nID, lParam);
- }
- }
-
-
-
-
-
- void CStudentAccessDlg::OnPaint()
- {
- CPaintDC dc(this);
- if (IsIconic())
- {
- SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
-
-
- 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;
-
-
- dc.DrawIcon(x, y, m_hIcon);
- }
- else
- {
-
- DrawUserPhoto(170,300,&dc);
- CDialog::OnPaint();
- }
- }
-
-
-
- HCURSOR CStudentAccessDlg::OnQueryDragIcon()
- {
- return (HCURSOR) m_hIcon;
- }
-
-
-
-
-
- void CStudentAccessDlg::OnReadAccess()
- {
- _variant_t var;
- CString strName;
-
-
- m_listAccess.ResetContent();
- strName="";
-
- try
- {
- if(!m_pRecordset->BOF)
- m_pRecordset->MoveFirst();
- else
- {
- AfxMessageBox("表内数据为空");
- return;
- }
-
-
- while(!m_pRecordset->adoEOF)
- {
- var = m_pRecordset->GetCollect("Name");
- if(var.vt != VT_NULL)
- strName = (LPCSTR)_bstr_t(var);
-
- m_listAccess.AddString( strName );
-
- m_pRecordset->MoveNext();
- }
-
-
- m_listAccess.SetCurSel(0);
- OnSelchangeListaccess();
- }
- catch(_com_error *e)
- {
- AfxMessageBox(e->ErrorMessage());
- }
-
-
- this->m_btnAdd.EnableWindow(TRUE);
- this->m_btnEdit.EnableWindow(TRUE);
- this->m_btnDelete.EnableWindow(TRUE);
- }
-
-
-
-
-
- void CStudentAccessDlg::OnSelchangeListaccess()
- {
- int curSel = m_listAccess.GetCurSel();
- _variant_t var,varIndex;
-
- if(curSel < 0)
- return;
-
- try
- {
- DestroyPhoto();
-
-
- m_pRecordset->MoveFirst();
- m_pRecordset->Move(long(curSel));
-
- var = m_pRecordset->GetCollect("Name");
- if(var.vt != VT_NULL)
-
- m_strName = var.bstrVal;
- else
- m_strName = "";
-
- var = m_pRecordset->GetCollect("Sex");
- if(var.vt != VT_NULL)
- {
- m_nSex = var.iVal;
- if( m_nSex == 2 )
- m_nSex = -1;
- }
- this->m_ComboBoxSex.SetCurSel(m_nSex);
-
- #ifdef _DEBUG
- CString temp;
- temp.Format("m_nSex值为:%d",m_nSex);
- TRACE(temp);
- #endif
-
- var = m_pRecordset->GetCollect("Age");
- if(var.vt != VT_NULL)
- m_nAge = var.iVal;
- else
- m_nAge = 0;
-
- var = m_pRecordset->GetCollect("Home");
- if(var.vt != VT_NULL)
- m_strHome = (LPCSTR)_bstr_t(var);
- else
- m_strHome = "";
-
- var = m_pRecordset->GetCollect("College");
- if(var.vt != VT_NULL)
- m_strCollege = (LPCSTR)_bstr_t(var);
- else
- m_strCollege = "";
-
- var = m_pRecordset->GetCollect("Major");
- if(var.vt != VT_NULL)
- m_strMajor = (LPCSTR)_bstr_t(var);
- else
- m_strMajor = "";
-
-
- long lDataSize = m_pRecordset->GetFields()->GetItem("photo")->ActualSize;
- if(lDataSize > 0)
- {
- _variant_t varBLOB;
- varBLOB = m_pRecordset->GetFields()->GetItem("photo")->GetChunk(lDataSize);
- if(varBLOB.vt == (VT_ARRAY | VT_UI1))
- {
- if(m_pBMPBuffer = new char[lDataSize+1])
- {
- char *pBuf = NULL;
- SafeArrayAccessData(varBLOB.parray,(void **)&pBuf);
- memcpy(m_pBMPBuffer,pBuf,lDataSize);
- SafeArrayUnaccessData (varBLOB.parray);
- m_nFileLen = lDataSize;
- m_hPhotoBitmap = BufferToHBITMAP();
- }
- }
- }
-
- UpdateData(false);
-
- Invalidate();
- }
- catch(_com_error *e)
- {
- AfxMessageBox(e->ErrorMessage());
- }
- }
-
-
-
- BOOL CStudentAccessDlg::LoadBMPFile(const char *pBMPPathname)
- {
- CFile file;
- if( !file.Open( pBMPPathname, CFile::modeRead) )
- return FALSE;
- m_nFileLen = file.GetLength();
- m_pBMPBuffer = new char[m_nFileLen + 1];
- if(!m_pBMPBuffer)
- return FALSE;
- if(file.ReadHuge(m_pBMPBuffer,m_nFileLen) != m_nFileLen)
- return FALSE;
- return TRUE;
- }
-
-
- HBITMAP CStudentAccessDlg::BufferToHBITMAP()
- {
- HBITMAP hBmp;
- LPSTR hDIB,lpBuffer = m_pBMPBuffer;
- LPVOID lpDIBBits;
- BITMAPFILEHEADER bmfHeader;
- DWORD bmfHeaderLen;
-
- bmfHeaderLen = sizeof(bmfHeader);
- strncpy((LPSTR)&bmfHeader,(LPSTR)lpBuffer,bmfHeaderLen);
-
- if (bmfHeader.bfType != (*(WORD*)"BM")) return NULL;
- hDIB = lpBuffer + bmfHeaderLen;
- BITMAPINFOHEADER &bmiHeader = *(LPBITMAPINFOHEADER)hDIB ;
- BITMAPINFO &bmInfo = *(LPBITMAPINFO)hDIB ;
-
-
-
-
-
-
- //原来的代码。
- lpDIBBits=(lpBuffer)+((BITMAPFILEHEADER *)lpBuffer)->bfOffBits;
- CClientDC dc(this);
- hBmp = CreateDIBitmap(dc.m_hDC,&bmiHeader,CBM_INIT,lpDIBBits,&bmInfo,DIB_RGB_COLORS);
- return hBmp;
- }
-
-
- void CStudentAccessDlg::DrawUserPhoto(int x, int y, CDC *pDC)
- {
- if(!m_hPhotoBitmap) return;
- HBITMAP OldBitmap;
- CDC MemDC;
- MemDC.CreateCompatibleDC(pDC);
- OldBitmap=(HBITMAP)MemDC.SelectObject(m_hPhotoBitmap);
- pDC->BitBlt(x,y,100,130,&MemDC,0,0,SRCCOPY);
- MemDC.SelectObject(OldBitmap);
- }
-
-
- void CStudentAccessDlg::DestroyPhoto()
- {
- if(m_hPhotoBitmap)
- {
- DeleteObject(m_hPhotoBitmap);
- m_hPhotoBitmap = NULL;
- }
- if(m_pBMPBuffer)
- {
- delete m_pBMPBuffer;
- m_pBMPBuffer = NULL;
- }
- }
-
-
-
-
-
- void CStudentAccessDlg::OnDelete()
- {
- if(m_listAccess.GetCount() == 0)
- return;
- else if(m_listAccess.GetCurSel() < 0 || m_listAccess.GetCurSel() > m_listAccess.GetCount())
- m_listAccess.SetCurSel(0);
-
- try
- {
-
- m_pRecordset->Delete(adAffectCurrent);
- m_pRecordset->Update();
-
-
- int nCurSel = m_listAccess.GetCurSel();
- m_listAccess.DeleteString(nCurSel);
- if(nCurSel == 0 && (m_listAccess.GetCount() != 0))
- m_listAccess.SetCurSel(nCurSel);
- else if(m_listAccess.GetCount() != 0)
- m_listAccess.SetCurSel(nCurSel-1);
-
-
- OnSelchangeListaccess();
- }
- catch(_com_error *e)
- {
- AfxMessageBox(e->ErrorMessage());
- }
- }
-
- void CStudentAccessDlg::OnEdit()
- {
- CEditAdd dlgEditAdd;
- dlgEditAdd.m_bKind = 2;
-
- dlgEditAdd.m_strName = this->m_strName;
- dlgEditAdd.m_nSex = this->m_nSex;
- dlgEditAdd.m_nAge = this->m_nAge;
- dlgEditAdd.m_strHome = this->m_strHome;
- dlgEditAdd.m_strCollege = this->m_strCollege;
- dlgEditAdd.m_strMajor = this->m_strMajor;
- dlgEditAdd.m_hPhotoBitmap = this->m_hPhotoBitmap;
-
- if(dlgEditAdd.DoModal() == IDOK)
- {
-
- if( dlgEditAdd.m_strName == "" || dlgEditAdd.m_nAge == 0)
- {
- AfxMessageBox("姓名、年龄信息不能为空!");
- return;
- }
-
-
- try
- {
- _variant_t var;
-
- m_pRecordset->PutCollect( "Name", _variant_t(dlgEditAdd.m_strName) );
-
- if( dlgEditAdd.m_nSex != -1)
- {
- var.iVal = dlgEditAdd.m_nSex;
- m_pRecordset->PutCollect( "Sex", var.iVal );
- }
-
- var.iVal = dlgEditAdd.m_nAge;
- m_pRecordset->PutCollect( "Age", var.iVal );
-
-
- if( dlgEditAdd.m_strHome == "")
- dlgEditAdd.m_strHome = " ";
- m_pRecordset->PutCollect( "Home", _variant_t(dlgEditAdd.m_strHome) );
-
- if( dlgEditAdd.m_strCollege == "")
- dlgEditAdd.m_strCollege = " ";
- m_pRecordset->PutCollect( "College", _variant_t(dlgEditAdd.m_strCollege) );
-
- if( dlgEditAdd.m_strMajor == "")
- dlgEditAdd.m_strMajor = " ";
- m_pRecordset->PutCollect( "Major", _variant_t(dlgEditAdd.m_strMajor) );
-
-
- char *pBuf = dlgEditAdd.m_pBMPBuffer;
- VARIANT varBLOB;
- SAFEARRAY *psa;
- SAFEARRAYBOUND rgsabound[1];
- if(pBuf)
- {
- rgsabound[0].lLbound = 0;
- rgsabound[0].cElements = dlgEditAdd.m_nFileLen;
- psa = SafeArrayCreate(VT_UI1, 1, rgsabound);
- for (long i = 0; i < (long)dlgEditAdd.m_nFileLen; i++)
- SafeArrayPutElement (psa, &i, pBuf++);
- varBLOB.vt = VT_ARRAY | VT_UI1;
- varBLOB.parray = psa;
- m_pRecordset->GetFields()->GetItem("Photo")->AppendChunk(varBLOB);
- }
-
- m_pRecordset->Update();
-
- AfxMessageBox("成功更新用户信息!");
-
-
- int nCurSel = m_listAccess.GetCurSel();
- OnReadAccess();
- m_listAccess.SetCurSel(nCurSel);
-
- OnSelchangeListaccess();
- }
- catch(_com_error *e)
- {
- AfxMessageBox(e->ErrorMessage());
- }
- }
-
- }
-
-
-
-
-
- void CStudentAccessDlg::OnAdd()
- {
- CEditAdd dlgEditAdd;
- dlgEditAdd.m_bKind = 1;
-
- if(dlgEditAdd.DoModal() == IDOK)
- {
-
- if( dlgEditAdd.m_strName == "" || dlgEditAdd.m_nAge == 0)
- {
- AfxMessageBox("姓名、年龄信息不能为空!");
- return;
- }
-
-
-
-
-
-
- try
- {
- _variant_t var;
-
-
- m_pRecordset->AddNew();
-
- m_pRecordset->PutCollect( "Name", _variant_t(dlgEditAdd.m_strName) );
-
- if( dlgEditAdd.m_nSex != 2)
- var.iVal = dlgEditAdd.m_nSex;
- else
- var.iVal = 2;
- m_pRecordset->PutCollect( "Sex", var.iVal );
-
- var.iVal = dlgEditAdd.m_nAge;
- m_pRecordset->PutCollect( "Age", var.iVal );
-
- if( dlgEditAdd.m_strHome != "")
- m_pRecordset->PutCollect( "Home", _variant_t(dlgEditAdd.m_strHome) );
-
- if( dlgEditAdd.m_strCollege != "")
- m_pRecordset->PutCollect( "College", _variant_t(dlgEditAdd.m_strCollege) );
-
- if( dlgEditAdd.m_strMajor != "")
- m_pRecordset->PutCollect( "Major", _variant_t(dlgEditAdd.m_strMajor) );
-
-
- char *pBuf = dlgEditAdd.m_pBMPBuffer;
- VARIANT varBLOB;
- SAFEARRAY *psa;
- SAFEARRAYBOUND rgsabound[1];
- if(pBuf)
- {
- rgsabound[0].lLbound = 0;
- rgsabound[0].cElements = dlgEditAdd.m_nFileLen;
- psa = SafeArrayCreate(VT_UI1, 1, rgsabound);
- for (long i = 0; i < (long)dlgEditAdd.m_nFileLen; i++)
- SafeArrayPutElement (psa, &i, pBuf++);
- varBLOB.vt = VT_ARRAY | VT_UI1;
- varBLOB.parray = psa;
- m_pRecordset->GetFields()->GetItem("Photo")->AppendChunk(varBLOB);
- }
-
- m_pRecordset->Update();
-
- AfxMessageBox("插入成功!");
-
-
- int nCurSel = m_listAccess.GetCurSel();
- OnReadAccess();
- m_listAccess.SetCurSel(nCurSel);
-
- OnSelchangeListaccess();
- }
- catch(_com_error *e)
- {
- AfxMessageBox(e->ErrorMessage());
- }
- }
- }
-
-
-
-
-
- BOOL CStudentAccessDlg::DestroyWindow()
- {
-
- if(m_pConnection->State)
- m_pRecordset->Close();
- m_pRecordset = NULL;
- if(m_pConnection->State)
- m_pRecordsetPara->Close();
- m_pRecordsetPara = NULL;
-
-
- if(m_pConnection->State)
- m_pConnection->Close();
- m_pConnection= NULL;
-
- DestroyPhoto();
-
- return CDialog::DestroyWindow();
- }
-
-
-
-
-
- void CStudentAccessDlg::OnSelectFile()
- {
-
- CString strFileName;
- static char BASED_CODE szFilter[] = "Access Files (*.mdb)|*.mdb||";
- CFileDialog dlg(TRUE,"mdb",NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,szFilter);
- if(dlg.DoModal() == IDOK)
- {
- strFileName = dlg.GetFileName();
- }
-
-
- if( this->OpenConnection(strFileName) )
- {
- this->m_strFileMsg = "成功连接" + strFileName;
-
- this->m_btnRead.EnableWindow(TRUE);
- this->m_btnParameter.EnableWindow(TRUE);
-
- SelectRecordset( m_pRecordsetPara, "Parameter" );
-
- ReadParameter();
-
- SelectRecordset( m_pRecordset, "Student" );
- }
- else
- {
- this->m_strFileMsg = "无法连接" + strFileName;
- }
- UpdateData(FALSE);
- }
-
- bool CStudentAccessDlg::OpenConnection(CString strFileName)
- {
- try
- {
-
- if( m_pRecordsetPara->State )
- m_pRecordsetPara->Close();
- if( m_pRecordset->State )
- m_pRecordset->Close();
-
-
- if( m_pConnection->State )
- m_pConnection->Close();
-
- }
- catch(_com_error e)
- {
- AfxMessageBox("数据库连接无法正常关闭!");
- return false;
- }
-
- CString strProvider;
- strProvider.Format( "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%s", strFileName );
- try
- {
-
- m_pConnection->Open( (_bstr_t)strProvider,"","",adModeUnknown);
- }
- catch(_com_error e)
- {
- AfxMessageBox("数据库连接失败,确认" + strFileName +"数据库是否在当前路径下!");
- return false;
- }
- return true;
- }
-
- void CStudentAccessDlg::SelectRecordset(_RecordsetPtr pRecordset, CString strTableName)
- {
-
- if( pRecordset->State )
- pRecordset->Close();
-
- CString strSql;
- strSql.Format( "SELECT * FROM %s", strTableName );
-
- try
- {
- pRecordset->Open((_bstr_t)strSql,
- m_pConnection.GetInterfacePtr(),
- adOpenDynamic,
- adLockOptimistic,
- adCmdText);
- }
- catch(_com_error e)
- {
- AfxMessageBox( "确认数据库中是否存在正确格式的数据表" + strTableName );
- return;
- }
- }
-
-
- void CStudentAccessDlg::ReadParameter()
- {
- try
- {
- if(!m_pRecordsetPara->BOF)
- m_pRecordsetPara->MoveFirst();
- else
- {
- AfxMessageBox("文件参数表为空");
- return;
- }
-
- _variant_t var;
- while(!m_pRecordsetPara->adoEOF)
- {
- var = m_pRecordsetPara->GetCollect("Lock");
- if(var.vt != VT_NULL)
- {
- m_nLock = var.iVal;
- }
- this->m_comboLock.SetCurSel(m_nLock);
-
- var = m_pRecordsetPara->GetCollect("Secret");
- if(var.vt != VT_NULL)
- {
- m_nSecret = var.iVal;
- }
- this->m_comboSecret.SetCurSel(m_nSecret);
-
- var = m_pRecordsetPara->GetCollect("Timedoc");
- CString strTimedoc;
- if(var.vt != VT_NULL)
- {
- strTimedoc = (LPCSTR)_bstr_t(var);
- }
-
- m_CurTime.wYear = atoi(strtok(strTimedoc.GetBuffer(strTimedoc.GetLength()),"-"));
- m_CurTime.wMonth = atoi(strtok(NULL,"-"));
- m_CurTime.wDay = atoi(strtok(NULL,"-"));
- m_dataTimedoc.SetTime(&m_CurTime);
- strTimedoc.ReleaseBuffer();
-
- m_pRecordsetPara->MoveNext();
- }
- }
- catch(_com_error *e)
- {
- AfxMessageBox(e->ErrorMessage());
- }
- }
-
-
- void CStudentAccessDlg::OnEditParameter()
- {
- CSelectFileDlg dlgFilePara;
-
- dlgFilePara.m_nLock = this->m_nLock;
- dlgFilePara.m_nSecret = this->m_nSecret;
-
- this->m_dataTimedoc.GetWindowText(dlgFilePara.m_strTimedoc);
-
- if(dlgFilePara.DoModal() == IDOK)
- {
- CString strSql;
- strSql.Format("UPDATE Parameter SET Lock='%d',Secret='%d',Timedoc='%s' WHERE ID=1",
- dlgFilePara.m_nLock,dlgFilePara.m_nSecret,dlgFilePara.m_strTimedoc);
-
- this->ExecuteSql(strSql);
-
- SelectRecordset( m_pRecordsetPara, "Parameter" );
-
- ReadParameter();
- }
- }
-
-
- void CStudentAccessDlg::ExecuteSql(CString strSql)
- {
- _variant_t vAffected;
-
- try
- {
- m_pConnection->Execute(_bstr_t(strSql),&vAffected,adCmdText);
- AfxMessageBox("成功更新数据库!");
- }
- catch(_com_error e)
- {
- AfxMessageBox("无法执行Sql语句");
- return;
- }
- }
-
-
- HBRUSH CStudentAccessDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
- {
- HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
-
- if(nCtlColor==CTLCOLOR_LISTBOX)
- {
-
- pDC->SetTextColor(RGB(0,0,0));
- pDC->SetBkColor(RGB(233,233,220));
- HBRUSH b=CreateSolidBrush(RGB(233,233,220));
- return b;
- }
- else if(nCtlColor==CTLCOLOR_SCROLLBAR)
- {
-
- pDC->SetTextColor(RGB(0,0,0));
- pDC->SetBkColor(RGB(233,233,220));
- HBRUSH b=CreateSolidBrush(RGB(233,233,220));
- return b;
- }
- else if(nCtlColor==CTLCOLOR_EDIT)
- {
-
- pDC->SetTextColor(RGB(0,0,0));
- pDC->SetBkColor(RGB(233,233,220));
- HBRUSH b=CreateSolidBrush(RGB(233,233,220));
- return b;
- }
- else if(nCtlColor==CTLCOLOR_STATIC)
- {
- pDC->SetTextColor(RGB(0,0,0));
- pDC->SetBkColor(RGB(160,180,220));
- HBRUSH b=CreateSolidBrush(RGB(160,180,220));
- return b;
- }
- else if(nCtlColor==CTLCOLOR_DLG)
- {
- pDC->SetTextColor(RGB(0,0,0));
- pDC->SetBkColor(RGB(160,180,220));
- HBRUSH b=CreateSolidBrush(RGB(160,180,220));
- return b;
- }
-
- return hbr;
- }
-
- void CStudentAccessDlg::OnHelp()
- {
- ::ShellExecute(m_hWnd, NULL, "help.htm", NULL, NULL, SW_SHOWNORMAL);
- }
阅读(2015) | 评论(0) | 转发(0) |