📄 studentview.cpp
字号:
// studentView.cpp : implementation of the CStudentView class
//
#include "stdafx.h"
#include "student.h"
#include "studentDoc.h"
#include "studentView.h"
#include "Hbar.h"
#include "ado.h"
#include "bybysdlg.h"
#include "bycldlg.h"
#include "byjysdlg.h"
#include "cjcxdlg.h"
#include "cjrkdlg.h"
#include "dacxdlg.h"
#include "dadjxsdlg.h"
#include "xjdjjcdlg.h"
#include "xjxfxdlg.h"
#include "yhdlg.h"
#include "PrintCjDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CStudentView
IMPLEMENT_DYNCREATE(CStudentView, CFormView)
BEGIN_MESSAGE_MAP(CStudentView, CFormView)
//{{AFX_MSG_MAP(CStudentView)
ON_WM_MOUSEMOVE()
ON_COMMAND(ID_MENU_BY_BYS, OnMenuByBys)
ON_COMMAND(ID_MENU_BY_CL, OnMenuByCl)
ON_COMMAND(ID_MENU_CJ_CX, OnMenuCjCx)
ON_COMMAND(ID_MENU_CJ_RK, OnMenuCjRk)
ON_COMMAND(ID_MENU_DA_CX, OnMenuDaCx)
ON_COMMAND(ID_MENU_DA_DJXS, OnMenuDaDjxs)
ON_COMMAND(ID_MENU_XJ_DJJC, OnMenuXjDjjc)
ON_COMMAND(ID_MENU_XJ_XFX, OnMenuXjXfx)
ON_COMMAND(ID_MENU_YH, OnMenuYh)
ON_COMMAND(ID_MENUI_BY_JYS, OnMenuiByJys)
ON_NOTIFY(NM_CLICK, IDC_LIST_GN, OnClickListGn)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CFormView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CFormView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CFormView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CStudentView construction/destruction
CStudentView::CStudentView()
: CFormView(CStudentView::IDD)
{
//{{AFX_DATA_INIT(CStudentView)
//}}AFX_DATA_INIT
// TODO: add construction code here
m_barIndex = -2;
IsInit = true;
m_myBarX = 0;
PrintDlg = NULL;
PrintOption = 0;
//ADO连接
m_conn = new CADODatabase;
this->m_conn->Open(ADOCONNSTR,"","");
m_recSet = new CADORecordset(m_conn);
m_recSetTemp = new CADORecordset(m_conn);
//图标列表
imageList = new CImageList;
imageList->Create(IDB_BITMAP1,0,0,NULL);
CBitmap *bitmap=new CBitmap;
bitmap->LoadBitmap(IDB_BITMAP2);
imageList->Add(bitmap,RGB(0,0,0));
bitmap = new CBitmap();
bitmap->LoadBitmap(IDB_BITMAP3);
imageList->Add(bitmap,RGB(0,0,0));
bitmap = new CBitmap();
bitmap->LoadBitmap(IDB_BITMAP4);
imageList->Add(bitmap,RGB(0,0,0));
bitmap = new CBitmap();
bitmap->LoadBitmap(IDB_BITMAP5);
imageList->Add(bitmap,RGB(0,0,0));
bitmap = new CBitmap();
bitmap->LoadBitmap(IDB_BITMAP6);
imageList->Add(bitmap,RGB(0,0,0));
bitmap = new CBitmap();
bitmap->LoadBitmap(IDB_BITMAP7);
imageList->Add(bitmap,RGB(0,0,0));
bitmap = new CBitmap();
bitmap->LoadBitmap(IDB_BITMAP8);
imageList->Add(bitmap,RGB(0,0,0));
bitmap = new CBitmap();
bitmap->LoadBitmap(IDB_BITMAP9);
imageList->Add(bitmap,RGB(0,0,0));
bitmap = new CBitmap();
bitmap->LoadBitmap(IDB_BITMAP10);
imageList->Add(bitmap,RGB(0,0,0));
//功能对话框
m_Dlg_ByBys =NULL;
m_Dlg_ByCl =NULL;
m_Dlg_ByJys =NULL;
m_Dlg_CjCx =NULL;
m_Dlg_CjRk =NULL;
m_Dlg_DaCx =NULL;
m_Dlg_DaDjxs=NULL;
m_Dlg_XjDjjc=NULL;
m_Dlg_XjXfx =NULL;
m_Dlg_Yh =NULL;
}
CStudentView::~CStudentView()
{
if(m_Dlg_ByBys !=NULL)
{
delete m_Dlg_ByBys;
}
if(m_Dlg_ByCl !=NULL)
{
delete m_Dlg_ByCl;
}
if(m_Dlg_ByJys !=NULL)
{
delete m_Dlg_ByJys;
}
if(m_Dlg_CjCx !=NULL)
{
delete m_Dlg_CjCx;
}
if(m_Dlg_CjRk !=NULL)
{
delete m_Dlg_CjRk;
}
if(m_Dlg_DaCx !=NULL)
{
delete m_Dlg_DaCx;
}
if(m_Dlg_DaDjxs !=NULL)
{
delete m_Dlg_DaDjxs;
}
if(m_Dlg_XjDjjc !=NULL)
{
delete m_Dlg_XjDjjc;
}
if(m_Dlg_XjXfx !=NULL)
{
delete m_Dlg_XjXfx;
}
if(m_Dlg_Yh !=NULL)
{
delete m_Dlg_Yh;
}
if(imageList !=NULL)
{
delete imageList;
}
m_conn->Close();
imageList->DeleteImageList();
}
void CStudentView::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CStudentView)
DDX_Control(pDX, IDC_LIST_GN, m_listCtrlGN);
DDX_Control(pDX, IDC_MYLOG, m_myLog);
DDX_Control(pDX, IDC_MYMENULIST, m_myMenuList);
DDX_Control(pDX, IDC_FORMBAR, m_formBar);
DDX_Control(pDX, IDC_COMMANDBUTTON1, m_B1);
DDX_Control(pDX, IDC_COMMANDBUTTON2, m_B2);
DDX_Control(pDX, IDC_COMMANDBUTTON3, m_B3);
DDX_Control(pDX, IDC_COMMANDBUTTON4, m_B4);
//}}AFX_DATA_MAP
IsInit = false;
}
BOOL CStudentView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CFormView::PreCreateWindow(cs);
}
void CStudentView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit();
}
/////////////////////////////////////////////////////////////////////////////
// CStudentView printing
BOOL CStudentView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CStudentView::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo)
{
// TODO: add extra initialization before printing
}
void CStudentView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
if(PrintOption == IDD_DLG_CJ_CX)
{
PrintOption = 0;
CCjCxDlg *dlg =(CCjCxDlg *)PrintDlg;
if(dlg->PrintKCNameList != NULL)
{
dlg->PrintKCNameList->FreeExtra();
dlg->PrintKCNameList = NULL;
}
dlg->PrintKCNameCount = 0;
}
}
void CStudentView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
{
// TODO: add customized printing code here
if(PrintOption == IDD_DLG_CJ_CX)
{
CCjCxDlg *dlg =(CCjCxDlg *)PrintDlg;
int ColCount = dlg->PrintKCNameCount;
ColCount+=3;
// start printing the lines
//二维点阵
int *x_pos = new int[ColCount+1];
int RowCount = 41;
int *y_pos = new int[RowCount+1];
int i;
//设置横坐标
for (i=0; i<=RowCount; i++)
y_pos[i] = 230 + (70 * i);
CString *str =new CString[ColCount] ;
str[0].Format("编号");
str[1].Format("学号");
str[2].Format("姓名");
for(i = 3;i<ColCount;i++)
{
str[i].Format("%s",dlg->PrintKCNameList[i-3]);
}
//设置纵坐标
x_pos[0] = (pInfo->m_rectDraw.Width() - (700+(ColCount-3)*200)) /2;
x_pos[1] = x_pos[0] + 100;
x_pos[2] = x_pos[1] + 300;
x_pos[3] = x_pos[2] + 300;
for(i = 4;i<=ColCount;i++)
{
if(str[i-1].GetLength()<=4)
{
x_pos[i] = x_pos[i-1] + 200;
}
else
{
x_pos[i] = x_pos[i-1] +str[i-1].GetLength()*26;
}
}
//打印30行
for (i=0; i<=RowCount; i++)
{
pDC->MoveTo(x_pos[0], y_pos[i]);
pDC->LineTo(x_pos[ColCount], y_pos[i]);
}
for (i=0;i<=ColCount;i++)
{
pDC->MoveTo(x_pos[i],y_pos[0]);
pDC->LineTo(x_pos[i],y_pos[RowCount]);
}
CSize Size;
CRect StrRect; //Draw text in Rect
CFont NewFont1;
NewFont1.CreateFont(100,40,0,0,
FW_HEAVY,
false,false,false,
ANSI_CHARSET,
OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY,
DEFAULT_PITCH|FF_DONTCARE,
"黑体");
CFont NewFont2;
NewFont2.CreateFont(55,21,0,0,
FW_HEAVY,
false,false,false,
ANSI_CHARSET,
OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY,
DEFAULT_PITCH|FF_DONTCARE,
"黑体");
CFont NewFont3;
NewFont3.CreateFont(40,18,0,0,
FW_HEAVY,
false,false,false,
ANSI_CHARSET,
OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY,
DEFAULT_PITCH|FF_DONTCARE,
"宋体");
pDC->SelectObject(&NewFont1);
StrRect.SetRect(x_pos[0], 100, x_pos[ColCount], 200);
pDC->DrawText("成 绩 单", StrRect, DT_CENTER| DT_VCENTER |DT_SINGLELINE);
pDC->SelectObject(&NewFont2);
for (i=0; i<ColCount; i++)
{
StrRect.SetRect(x_pos[i], y_pos[0], x_pos[i+1], y_pos[1]);
pDC->DrawText(str[i], StrRect, DT_CENTER| DT_VCENTER |DT_SINGLELINE);
}
pDC->SelectObject(&NewFont3);
CString SID;
CString SName;
CString sqlt;
CString temp;
double d_Zcj;
CString s_Zcj;
m_recSet->Open(dlg->sql.GetBuffer(200));
for(i=0;(i<RowCount-1 && !m_recSet->IsEOF());i++)
{
m_recSet->GetFieldValue(0,SID);
m_recSet->GetFieldValue("S_Name",SName);
temp.Format("%d",i);
StrRect.SetRect(x_pos[0], y_pos[i+1], x_pos[1], y_pos[i+2]);
pDC->DrawText(temp, StrRect, DT_CENTER| DT_VCENTER |DT_SINGLELINE);
StrRect.SetRect(x_pos[1], y_pos[i+1], x_pos[2], y_pos[i+2]);
pDC->DrawText(SID, StrRect, DT_CENTER| DT_VCENTER |DT_SINGLELINE);
StrRect.SetRect(x_pos[2], y_pos[i+1], x_pos[3], y_pos[i+2]);
pDC->DrawText(SName, StrRect, DT_CENTER| DT_VCENTER |DT_SINGLELINE);
for(int j=0;j<ColCount-3;j++)
{
sqlt.Format("SELECT [CJ_Ps]+[CJ_Ks] AS ZCJ FROM CjTable INNER JOIN KcTable ON CjTable.KC_ID=KcTable.KC_ID WHERE (((CjTable.S_ID)='%s') AND ((KcTable.KC_Name)='%s'))"\
,SID,str[j+3]);
m_recSetTemp->Open(sqlt.GetBuffer(200));
if(!m_recSetTemp->IsEOF())
{
m_recSetTemp->GetFieldValue("ZCJ",d_Zcj);
s_Zcj.Format("%.2f",d_Zcj);
StrRect.SetRect(x_pos[j+3], y_pos[i+1], x_pos[j+4], y_pos[i+2]);
pDC->DrawText(s_Zcj, StrRect,DT_CENTER| DT_VCENTER |DT_SINGLELINE);
}
m_recSetTemp->Close();
}
m_recSet->MoveNext();
}
m_recSet->Close();
//~~
delete x_pos;
delete y_pos;
// delete str;
str->FreeExtra();
}
}
/////////////////////////////////////////////////////////////////////////////
// CStudentView diagnostics
#ifdef _DEBUG
void CStudentView::AssertValid() const
{
CFormView::AssertValid();
}
void CStudentView::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
CStudentDoc* CStudentView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CStudentDoc)));
return (CStudentDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CStudentView message handlers
BEGIN_EVENTSINK_MAP(CStudentView, CFormView)
//{{AFX_EVENTSINK_MAP(CStudentView)
ON_EVENT(CStudentView, IDC_COMMANDBUTTON1, -600 /* Click */, OnClickCommandbutton1, VTS_NONE)
ON_EVENT(CStudentView, IDC_COMMANDBUTTON1, -606 /* MouseMove */, OnMouseMoveCommandbutton1, VTS_I2 VTS_I2 VTS_R4 VTS_R4)
ON_EVENT(CStudentView, IDC_COMMANDBUTTON2, -606 /* MouseMove */, OnMouseMoveCommandbutton2, VTS_I2 VTS_I2 VTS_R4 VTS_R4)
ON_EVENT(CStudentView, IDC_COMMANDBUTTON3, -606 /* MouseMove */, OnMouseMoveCommandbutton3, VTS_I2 VTS_I2 VTS_R4 VTS_R4)
ON_EVENT(CStudentView, IDC_COMMANDBUTTON4, -606 /* MouseMove */, OnMouseMoveCommandbutton4, VTS_I2 VTS_I2 VTS_R4 VTS_R4)
ON_EVENT(CStudentView, IDC_COMMANDBUTTON2, -600 /* Click */, OnClickCommandbutton2, VTS_NONE)
ON_EVENT(CStudentView, IDC_COMMANDBUTTON3, -600 /* Click */, OnClickCommandbutton3, VTS_NONE)
ON_EVENT(CStudentView, IDC_COMMANDBUTTON4, -600 /* Click */, OnClickCommandbutton4, VTS_NONE)
//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()
void CStudentView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call defau
if(this->m_barIndex == -1)
{
}
else
{
this->RefreshMyBar(-1);
// this->Invalidate(true);
this->m_barIndex = -1;
}
CFormView::OnMouseMove(nFlags, point);
}
void CStudentView::OnMouseMoveCommandbutton1(short Button, short Shift, float X, float Y)
{
// TODO: Add your control notification handler code here
this->RefreshMyBar(0);
}
void CStudentView::OnMouseMoveCommandbutton2(short Button, short Shift, float X, float Y)
{
// TODO: Add your control notification handler code here
this->RefreshMyBar(1);
}
void CStudentView::OnMouseMoveCommandbutton3(short Button, short Shift, float X, float Y)
{
// TODO: Add your control notification handler code here
this->RefreshMyBar(2);
}
void CStudentView::OnMouseMoveCommandbutton4(short Button, short Shift, float X, float Y)
{
// TODO: Add your control notification handler code here
this->RefreshMyBar(3);
}
void CStudentView::RefreshMyBar(int index)
{
if(this->m_barIndex != index)
{
CHBar mybar(STATIC_MYBAR_BUCOUNT,STATIC_MYBAR_MINW,STATIC_MYBAR_MAXW,STATIC_MYBAR_MINH,STATIC_MYBAR_MAXH,STATIC_MYBAR_MAXY);
mybar.Get(index,0);
m_B1.MoveWindow(m_myBarX+mybar.m_x,STATIC_Y-mybar.m_y,mybar.m_w,mybar.m_h);
mybar.Get(index,1);
m_B2.MoveWindow(m_myBarX+mybar.m_x,STATIC_Y-mybar.m_y,mybar.m_w,mybar.m_h);
mybar.Get(index,2);
m_B3.MoveWindow(m_myBarX+mybar.m_x,STATIC_Y-mybar.m_y,mybar.m_w,mybar.m_h);
mybar.Get(index,3);
m_B4.MoveWindow(m_myBarX+mybar.m_x,STATIC_Y-mybar.m_y,mybar.m_w,mybar.m_h);
}
this->m_barIndex = index;
}
void CStudentView::CalcWindowRect(LPRECT lpClientRect, UINT nAdjustType)
{
// TODO: Add your specialized code here and/or call the base class
if(!IsInit)
{
m_formBar.MoveWindow(0,0,lpClientRect->right,lpClientRect->bottom);
//工具栏位置
this->m_myBarX = 5+(lpClientRect->right-(STATIC_MYBAR_BUCOUNT)*STATIC_MYBAR_MAXW)/2;
if(this->m_myBarX <5)
{
m_myBarX =5;
}
//菜单列表位置
m_myMenuList.MoveWindow(3,STATIC_MYWIN_TOP,STATIC_MYWIN_LEFT,lpClientRect->bottom-STATIC_MYWIN_TOP);
m_listCtrlGN.MoveWindow(3,STATIC_MYWIN_TOP+6,STATIC_MYWIN_LEFT,lpClientRect->bottom-STATIC_MYWIN_TOP-6);
//LOG位置
m_myLog.MoveWindow(STATIC_MYWIN_LEFT+3,STATIC_MYWIN_TOP,lpClientRect->right-(STATIC_MYWIN_LEFT+4),lpClientRect->bottom-STATIC_MYWIN_TOP);
if(m_Dlg_DaDjxs !=NULL)
{
if(m_Dlg_DaDjxs->m_zp.Buffer !=NULL)
{
m_Dlg_DaDjxs->ShowDataImage();
}
}
}
CFormView::CalcWindowRect(lpClientRect, nAdjustType);
}
bool CStudentView::OpenGNDlg(int nID)
{
if(m_Dlg_ByBys !=NULL)
{
m_Dlg_ByBys->ShowWindow(SW_HIDE);
}
if(m_Dlg_ByCl !=NULL)
{
m_Dlg_ByCl->ShowWindow(SW_HIDE);
}
if(m_Dlg_ByJys !=NULL)
{
m_Dlg_ByJys->ShowWindow(SW_HIDE);
}
if(m_Dlg_CjCx !=NULL)
{
m_Dlg_CjCx->ShowWindow(SW_HIDE);
}
if(m_Dlg_CjRk !=NULL)
{
m_Dlg_CjRk->ShowWindow(SW_HIDE);
}
if(m_Dlg_DaCx !=NULL)
{
m_Dlg_DaCx->ShowWindow(SW_HIDE);
}
if(m_Dlg_DaDjxs !=NULL)
{
m_Dlg_DaDjxs->ShowWindow(SW_HIDE);
}
if(m_Dlg_XjDjjc !=NULL)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -