📄 systemdlg.cpp
字号:
// SystemDlg.cpp : implementation file
//
#include "stdAfx.h"
#include "System.h"
#include "SystemDlg.h"
#include "excel.h"
#include "CSpreadSheet.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class 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()
/////////////////////////////////////////////////////////////////////////////
// CSystemDlg dialog
CSystemDlg::CSystemDlg(CWnd* pParent /*=NULL*/)
: CDialog(CSystemDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CSystemDlg)
m_number = _T("");
m_name = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_pImgBuffer = NULL;
}
void CSystemDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSystemDlg)
DDX_Control(pDX, IDC_PROG, m_progress);
DDX_Control(pDX, IDC_BUTTON14, m_bpre);
DDX_Control(pDX, IDC_BUTTON10, m_research);
DDX_Control(pDX, IDC_BUTTON6, m_button21);
DDX_Control(pDX, IDC_BUTTON5, m_button5);
DDX_Control(pDX, IDC_BUTTON3, m_button4);
DDX_Control(pDX, IDC_BUTTON2, m_button3);
DDX_Control(pDX, IDC_BUTTON9, m_button2);
DDX_Control(pDX, IDC_BUTTON8, m_button1);
DDX_Control(pDX, IDC_SHOWINFOMATION, m_ShowInformation);
DDX_Control(pDX, IDC_SHOW, m_Show);
DDX_Control(pDX, IDC_EDIT_OLD, m_Bold);
DDX_Control(pDX, IDC_EDIT_ADDR, m_Baddress);
DDX_Control(pDX, IDC_EDIT_NAME, m_Bname);
DDX_Control(pDX, IDC_EDIT_NUMBER, m_Bnumber);
DDX_Control(pDX, IDC_DATAGRID1, DBgrid);
DDX_Text(pDX, IDC_EDIT_NUMBER, m_number);
DDX_Text(pDX, IDC_EDIT_NAME, m_name);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSystemDlg, CDialog)
//{{AFX_MSG_MAP(CSystemDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON4, OnBtnExit)
ON_BN_CLICKED(IDC_BUTTON1, OnButtonAddInfo)
ON_BN_CLICKED(IDC_BUTTON2, OnBtnModify)
ON_BN_CLICKED(IDC_BUTTON3, OnBtnDel)
ON_BN_CLICKED(IDC_BUTTON7, OnBtntodisk)
ON_BN_CLICKED(IDC_BUTTON5, OnBtnAddOnePicture)
ON_BN_CLICKED(IDC_BUTTON10, OnBtnRearch)
ON_BN_CLICKED(IDC_BUTTON11, OnBtnReportSorted)
ON_BN_CLICKED(IDC_BUTTON12, OnBtnReportToDatabase)
ON_BN_CLICKED(IDC_BUTTON8, OnBtnPre)
ON_BN_CLICKED(IDC_BUTTON9, OnBrnNext)
ON_BN_CLICKED(IDC_BUTTON13, OnBtnTextToData)
ON_WM_SETCURSOR()
ON_BN_CLICKED(IDC_BUTTON6, OnBtnStopTrans)
ON_BN_CLICKED(IDC_BUTTON14, OnBtnOnePictureTran)
ON_WM_TIMER()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSystemDlg message handlers
BOOL CSystemDlg::OnInitDialog()
{
CDialog::OnInitDialog();
CRect dlgRect;
GetWindowRect(dlgRect);
CRect desktopRect;
GetDesktopWindow()->GetWindowRect(desktopRect);
int t1=desktopRect.Width();
int t2=dlgRect.Width();
int t3=desktopRect.Height();
int t4=dlgRect.Height();
MoveWindow((desktopRect.Height()-dlgRect.Height())/2,(desktopRect.Width()-dlgRect.Width())/2,0,0);
nWidth=dlgRect.Width();
nHeight=dlgRect.Height();
dx=2;
dy=4;
dx1=2;
dy1=2;
::SetTimer(this->m_hWnd,1,0,0);
RefreshShow();
m_button1.ModifyStyle(0,BS_ICON);
m_button1.SetIcon(theApp.LoadIcon(IDI_ICON2));
m_button2.ModifyStyle(0,BS_ICON);
m_button2.SetIcon(theApp.LoadIcon(IDI_ICON1));
// 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
// TODO: Add extra initialization here
m_cursor=AfxGetApp()->LoadCursor(IDC_CURSOR);
return TRUE; // return TRUE unless you set the focus to a control
}
void CSystemDlg::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 CSystemDlg::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
{
// CClientDC dc(this);
// ShowJpgGif(&dc,m_pImgBuffer,m_nFileLen,380,30);
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CSystemDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
BEGIN_EVENTSINK_MAP(CSystemDlg, CDialog)
//{{AFX_EVENTSINK_MAP(CSystemDlg)
ON_EVENT(CSystemDlg, IDC_DATAGRID1, -600 /* Click */, OnClickDatagrid, VTS_NONE)
//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()
void CSystemDlg::OnClickDatagrid()
{
CString str2,str3,str4,str5;
_variant_t temp1,temp2,temp3,temp4;
Destroypicture();
m_button3.EnableWindow();
m_button4.EnableWindow();
m_button5.EnableWindow();
m_button2.EnableWindow();
m_button1.EnableWindow(FALSE);
m_Show.SetWindowText("");
if((!theApp.datamanage->GetRecordset()->adoEOF)&&(!theApp.datamanage->GetRecordset()->BOF))
{
temp1=theApp.datamanage->GetRecordset()->GetFields()->GetItem((long)0)->Value;
temp2=theApp.datamanage->GetRecordset()->GetFields()->GetItem((long)1)->Value;
temp3=theApp.datamanage->GetRecordset()->GetFields()->GetItem((long)2)->Value;
temp4=theApp.datamanage->GetRecordset()->GetFields()->GetItem((long)3)->Value;
str1=temp1.bstrVal;
str2=temp2.bstrVal;
str3=temp3.bstrVal;
str4=temp4.bstrVal;
str5.Format("编号:%s 姓名: %s 年龄: %s 籍贯: %s",str1,str2,str3,str4);
m_Bnumber.SetWindowText(str1);
m_Bname.SetWindowText(str2);
m_Bold.SetWindowText(str3);
m_Baddress.SetWindowText(str4);
m_ShowInformation.SetWindowText(str5);
}
TextFromDataToWindow(str1);
}
void CSystemDlg::OnBtnExit()
{
PostQuitMessage(0);
}
void CSystemDlg::OnButtonAddInfo()
{
CString str1,str2,str3,str4;
m_Bnumber.GetWindowText(str1);
m_Bname.GetWindowText(str2);
m_Bold.GetWindowText(str3);
m_Baddress.GetWindowText(str4);
if((!str1.IsEmpty())&&(!str2.IsEmpty())&&(!str3.IsEmpty())&&(!str4.IsEmpty()))
{
if(!IsRepeated(str1))
{
try
{
CString sql;
sql.Format("insert into USERINFO(UID,UNAME,UOLD,UADDR) values('%s','%s','%s','%s')",str1,str2,str3,str4);
theApp.datamanage->ExecSQL(sql);
this->MessageBox("操作成功.","提示",64);
m_Bnumber.SetWindowText("");
m_Bname.SetWindowText("");
m_Bold.SetWindowText("");
m_Baddress.SetWindowText("");
m_Bnumber.SetFocus();
}
catch(...)
{
this->MessageBox("操作失败.","提示",64);
m_Bnumber.SetFocus();
m_Bnumber.SetSel(0);
}
RefreshShow();
}
else
{
if(MessageBox("该信息已存在!是否给已存信息添加图片","提示",MB_YESNO)==IDNO)
return;
else
{
this->MessageBox("操作成功.","提示",64);
m_Bnumber.SetWindowText("");
m_Bname.SetWindowText("");
m_Bold.SetWindowText("");
m_Baddress.SetWindowText("");
m_Bnumber.SetFocus();
}
}
}
else
AfxMessageBox("基本信息不能为空.",0,0);
}
bool CSystemDlg::IsRepeated(CString str)
{
CString sql;
sql.Format("select * from USERINFO where UID='%s'",str);
theApp.datamanage->Record1->raw_Close();
theApp.datamanage->Record1->Open((_bstr_t)sql,theApp.datamanage->GetConn().GetInterfacePtr(),adOpenKeyset,adLockOptimistic,adCmdText);
if(theApp.datamanage->Record1->RecordCount>0)
return true;
return false;
}
void CSystemDlg::RefreshShow()
{
DBgrid.SetRefDataSource(NULL);
theApp.datamanage->GetRecordset()->raw_Close();
theApp.datamanage->GetRecordset()->Open("select UID as 编号,UNAME as 姓名,UOLD as 年龄, UADDR as 地址 from USERINFO order by UID ",theApp.datamanage->GetConn().GetInterfacePtr(),adOpenKeyset,adLockPessimistic,adCmdText);
if(theApp.datamanage->GetRecordset()->RecordCount>0)
DBgrid.SetRefDataSource(theApp.datamanage->GetRecordset()->DataSource);
}
void CSystemDlg::OnBtnModify()
{
if(theApp.datamanage->GetRecordset()->RecordCount>0)
{
if(MessageBox("确实要修改当前数据?","提示",MB_YESNO)==IDYES)
{
CString str1,str2,str3,str4;
m_Bnumber.GetWindowText(str1);
m_Bname.GetWindowText(str2);
m_Bold.GetWindowText(str3);
m_Baddress.GetWindowText(str4);
if(str1.IsEmpty()|str2.IsEmpty()|str3.IsEmpty()|str4.IsEmpty())
{
MessageBox("基础信息不能为空","提示",64);
}
else
if(!IsRepeated(str1))
{
try
{
_bstr_t temp1=str1;
theApp.datamanage->GetRecordset()->GetFields()->GetItem((long)0)->Value=temp1;
theApp.datamanage->GetRecordset()->Update();
this->MessageBox("操作成功","提示",64);
m_Bnumber.SetWindowText("");
m_Bname.SetWindowText("");
m_Bold.SetWindowText("");
m_Baddress.SetWindowText("");
m_Bnumber.SetFocus();
}
catch(...)
{
MessageBox("操作失败","提示",64);
}
RefreshShow();
}
else
{
if((IsRepeated(str1))&&(IsRepeated(str2))&&(IsRepeated(str3))&&(IsRepeated(str4)))
{
MessageBox("信息已存在","提示",64);
}
else
{
try
{
_bstr_t temp2=str2,temp3=str3,temp4=str4;
theApp.datamanage->GetRecordset()->GetFields()->GetItem((long)1)->Value=temp2;
theApp.datamanage->GetRecordset()->GetFields()->GetItem((long)2)->Value=temp3;
theApp.datamanage->GetRecordset()->GetFields()->GetItem((long)3)->Value=temp4;
theApp.datamanage->GetRecordset()->Update();
this->MessageBox("操作成功","提示",64);
m_Bnumber.SetWindowText("");
m_Bname.SetWindowText("");
m_Bold.SetWindowText("");
m_Baddress.SetWindowText("");
m_Bnumber.SetFocus();
}
catch(...)
{
MessageBox("操作失败","提示",64);
}
RefreshShow();
}
}
}
}
else
MessageBox("当前没有可修改的数据.","提示",64);
}
void CSystemDlg::OnBtnDel()
{
if(MessageBox("确实要删除当前记录吗?","提示",MB_YESNO)==IDYES)
if(theApp.datamanage->GetRecordset()->RecordCount>0)
{
CString i;
m_Bnumber.GetWindowText(i);
if(!i.IsEmpty())
{
CString sql;
theApp.datamanage->GetRecordset()->raw_Close();
sql.Format("delete USERINFO where UID='%s'",i);
theApp.datamanage->GetConn()->Execute((_bstr_t)sql,NULL,0);
try
{
CString sql7;
theApp.datamanage->GetRecordset()->raw_Close();
sql7.Format("delete from tbTEXTINFO where Tid='%s'",i);
theApp.datamanage->GetConn()->Execute((_bstr_t)sql7,NULL,0);
}
catch(_com_error e)
{
AfxMessageBox(e.ErrorMessage());
}
RefreshShow();
MessageBox("信息已删除!","提示");
}
else
MessageBox("请在编辑框中输入信息或在表格里选择信息","提示");
}
else
MessageBox("当前没有可删除的记录!","提示");
}
BOOL CSystemDlg::LoadImgFile(const char *pFileName)
{
CFile imagefile;
if( !imagefile.Open( pFileName, CFile::modeRead) )
return FALSE;
m_nFileLen = imagefile.GetLength();
m_pImgBuffer = new char[m_nFileLen];
if(!m_pImgBuffer)
return FALSE;
if(imagefile.ReadHuge(m_pImgBuffer,m_nFileLen) != m_nFileLen)
return FALSE;
return TRUE;
}
BOOL CSystemDlg::ShowJpgGif(CDC *pDC, char *pBuffer, int size, int x, int y)
{
IStream *pStm;
HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, size);
if (hGlobal != NULL)
{
LPVOID pvData = NULL;
char* pmem = (char*)GlobalLock(hGlobal);
memcpy(pmem,pBuffer,size);
GlobalUnlock(hGlobal);
CreateStreamOnHGlobal(hGlobal, TRUE, &pStm);
}
else return false;
IPicture *pPic;
if(SUCCEEDED(OleLoadPicture(pStm,size,TRUE,IID_IPicture,(LPVOID*)&pPic)))
{
OLE_XSIZE_HIMETRIC hmWidth;
OLE_YSIZE_HIMETRIC hmHeight;
pPic->get_Width(&hmWidth);
pPic->get_Height(&hmHeight);
double fX,fY;
fX = (double)pDC->GetDeviceCaps(HORZRES)*(double)hmWidth/
((double)pDC->GetDeviceCaps(HORZSIZE)*105.0);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -