⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ex07bview.cpp

📁 ISO9000质量管理小程序
💻 CPP
字号:
// Ex07bView.cpp : implementation of the CEx07bView class
//

#include "stdafx.h"
#include "Ex07b.h"
#include "ScrollView.h"
#include "Ex07bDoc.h"
#include "Ex07bView.h"
#include "Tuxing.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

extern BOOL m_pmenu;
extern BOOL m_smenu;
extern BOOL m_zmenu;

/////////////////////////////////////////////////////////////////////////////
// CEx07bView

IMPLEMENT_DYNCREATE(CEx07bView, CFormView)

BEGIN_MESSAGE_MAP(CEx07bView, CFormView)
	//{{AFX_MSG_MAP(CEx07bView)
	ON_BN_CLICKED(IDC_NEXT, OnNextRecord)
	ON_BN_CLICKED(IDC_ADD, OnAddRecord)
	ON_BN_CLICKED(IDC_TONGJI, OnTongji)
	ON_BN_CLICKED(IDC_PLTXG, OnPltxg)
	ON_BN_CLICKED(IDC_INSERT, OnInsert)
	ON_BN_CLICKED(IDC_REMOVE, OnRemove)
	//}}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()

/////////////////////////////////////////////////////////////////////////////
// CEx07bView construction/destruction

CEx07bView::CEx07bView()
	: CFormView(CEx07bView::IDD)
{
	//{{AFX_DATA_INIT(CEx07bView)
	m_sName = _T("");
	m_lCode = 0.0f;
	//}}AFX_DATA_INIT
	// TODO: add construction code here

}

CEx07bView::~CEx07bView()
{
}

void CEx07bView::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CEx07bView)
	DDX_Text(pDX, IDC_NAME, m_sName);
	DDX_Text(pDX, IDC_CODE, m_lCode);
	//}}AFX_DATA_MAP
}

BOOL CEx07bView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs
// cs.style!=WS_MINIMIZE;
	return CFormView::PreCreateWindow(cs);
}

void CEx07bView::OnInitialUpdate()
{

	m_pmenu=false;  //设置控制排列图菜单的变量为真
	m_smenu=false;
	m_zmenu=false;

	CFormView::OnInitialUpdate();
	ResizeParentToFit();

 	CEx07bDoc *pDoc =GetDocument();
	ASSERT_VALID(pDoc);
	int m=pDoc->m_dataList.GetCount();
	if (m!=0)
	{
		m_pmenu=true;

		CStudent *pStudent=pDoc->m_dataList.GetAt(pDoc->curPos);

		m_lCode=pStudent->m_nCode;
		m_sName=pStudent->m_sName;
	  //成员变量的数据传给控制ID,在对话框中显示数据
		UpdateData(false); 
		pDoc->m_dataList.GetNext(pDoc->curPos);
		if(pDoc->curPos==NULL)
				pDoc->curPos=pDoc->m_dataList.GetHeadPosition();
	//控制控件的允许
		CWnd *m_Wnd=NULL;
		m_Wnd=GetDlgItem(IDC_TONGJI);
		m_Wnd->EnableWindow();
		m_Wnd=GetDlgItem(IDC_NEXT);
		m_Wnd->EnableWindow();
		m_Wnd=GetDlgItem(IDC_PLTXG);
		m_Wnd->EnableWindow();
		m_Wnd=GetDlgItem(IDC_INSERT);
		m_Wnd->EnableWindow();
		m_Wnd=GetDlgItem(IDC_REMOVE);
		m_Wnd->EnableWindow();
		
		m_Wnd=GetDlgItem(IDC_TONGJI);
		m_Wnd->EnableWindow(false);

	}
 //创建丰富的按钮
//添加数据
	m_btnAdd.SubclassDlgItem(IDC_ADD,this);
	m_btnAdd.SetIcon(IDI_ADD2,IDI_ADD1);
	m_btnAdd.SetActiveFgColor(RGB(255,0,0));
	m_btnAdd.SetBtnCursor(IDC_HAND);
//数据统计
	m_btnTongji.SubclassDlgItem(IDC_TONGJI,this);
	m_btnTongji.SetIcon(IDI_TONGJI1,IDI_TONGJI2);
	m_btnTongji.SetActiveFgColor(RGB(255,0,0));
	m_btnTongji.SetBtnCursor(IDC_HAND);
//修改数据
	m_btnXg.SubclassDlgItem(IDC_PLTXG,this);
	m_btnXg.SetIcon(IDI_XG1,IDI_XG2);
	m_btnXg.SetActiveFgColor(RGB(255,0,0));
	m_btnXg.SetBtnCursor(IDC_HAND);
//下一数据
	m_btnNext.SubclassDlgItem(IDC_NEXT,this);
	m_btnNext.SetIcon(IDI_NEXT1,IDI_NEXT2);
	m_btnNext.SetActiveFgColor(RGB(255,0,0));
	m_btnNext.SetBtnCursor(IDC_HAND);
//插入数据
	m_btnInsert.SubclassDlgItem(IDC_INSERT,this);
	m_btnInsert.SetIcon(IDI_INSERT1,IDI_INSERT2);
	m_btnInsert.SetActiveFgColor(RGB(255,0,0));
	m_btnInsert.SetBtnCursor(IDC_HAND);
//删除数据
  m_btnDel256.SubclassDlgItem(IDC_REMOVE, this);
  m_btnDel256.SetIcon(IDI_DEL1, IDI_DEL2);
  m_btnDel256.SetActiveFgColor(RGB(255,0,0));
  m_btnDel256.SetBtnCursor(IDC_HAND);
 // m_btnDel256.SetInactiveFgColor(RGB(0,192,192));


}

/////////////////////////////////////////////////////////////////////////////
// CEx07bView printing







//void CEx07bView::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/)
/*{
	// TODO: add customized printing code here
	
//	ASSERT_VALID(pDoc);
	// TODO: add draw code here
 	CEx07bDoc* pDoc = GetDocument();  
	char str[64];
	int top=50;
    int b=350;  
	int w=50;
	int left=50;
	int i=0;
	float tt=0;
	POSITION pos=pDoc->m_dataList.GetHeadPosition();
	while (pos!=NULL)
	{

		
		CStudent *pStudent=pDoc->m_dataList.GetAt(pos);

		RECT Rect3;
		Rect3.left=left+i*w;
		Rect3.top=b-(pStudent->m_lAge*(b-top)/100);
		Rect3.right=Rect3.left+w;
		Rect3.bottom=b;

		CBrush Brush3(RGB((50+i*210),((i-1)*310),(150+i*125)));
		CBrush *pOldBrush=pDC->SelectObject(&Brush3);
		pDC->FillRect(&Rect3,&Brush3);
		pDC->SelectObject(pOldBrush);
//写坐标下的项目
		pDC->SetTextColor(RGB((50+i*210),((i-1)*310),(150+i*125)));
		pDC->TextOut(left+i*w,b+10,pStudent->m_sName);
//写方框图上的频率
		sprintf(str,"%6.0f",pStudent->m_nCode);
		pDC->TextOut(left+i*w+5,Rect3.top-20,str);
		
//画累计百分比的线

		CPen Pen2;
		Pen2.CreatePen(PS_DOT,1,RGB(0,128,128));
		CPen* poldPen=pDC->SelectObject(&Pen2);
		pDC->SelectObject(&Pen2);
		if (i==0)
			pDC->MoveTo(left,b);//-(pStudent->m_lScore*(b-top)/100));
		else
		    pDC->MoveTo(left+i*w,tt);
		pDC->LineTo(left+(i+1)*w,b-(pStudent->m_lScore*(b-top)/100));
		tt=b-(pStudent->m_lScore*(b-top)/100);
		//写线上的累计百分比
		if (i!=0)
		{
			sprintf(str,"%6.2f",pStudent->m_lScore);
			pDC->TextOut(left+(i+1)*w,b-(pStudent->m_lScore*(b-top)/100),str);
			pDC->TextOut(left+(i+1)*w+40,b-(pStudent->m_lScore*(b-top)/100),"%");
		}


		pStudent=pDoc->m_dataList.GetNext(pos);

		i++;
		pDC->SelectObject(poldPen);
	}

	CPen Pen3;
	Pen3.CreatePen(PS_DASH,1,RGB(0,255,0));
	CPen* poldPen=pDC->SelectObject(&Pen3);
	pDC->SelectObject(&Pen3);
	pDC->MoveTo(left,b-(80*(b-top)/100));
	pDC->LineTo(left+i*w,b-(80*(b-top)/100));

	CPen Pen4;
	Pen4.CreatePen(PS_DASH,1,RGB(0,255,255));
	pDC->SelectObject(&Pen4);
	pDC->MoveTo(left,b-(90*(b-top)/100));
	pDC->LineTo(left+i*w,b-(90*(b-top)/100));


	CPen Pen;
	Pen.CreatePen(PS_SOLID,2,RGB(255,128,128));
	pDC->SelectObject(&Pen);
	pDC->BeginPath();
	pDC->MoveTo(left,top);
	pDC->LineTo((left+i*w),top);
	pDC->LineTo((left+i*w),b);
	pDC->LineTo(left,b);
	pDC->CloseFigure();
	pDC->EndPath();
	pDC->StrokePath();

	pDC->SelectObject(poldPen);




}
*/
/////////////////////////////////////////////////////////////////////////////
// CEx07bView diagnostics

#ifdef _DEBUG
void CEx07bView::AssertValid() const
{
	CFormView::AssertValid();
}

void CEx07bView::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}

CEx07bDoc* CEx07bView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CEx07bDoc)));
	return (CEx07bDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CEx07bView message handlers

void CEx07bView::OnNextRecord() 
{
	// TODO: Add your control notification handler code here
	CEx07bDoc *pDoc =GetDocument();
	ASSERT_VALID(pDoc);

//	CWnd::EnableWindow[false];
	if(pDoc->curPos!=NULL)   //
	{

		CStudent *pStudent=pDoc->m_dataList.GetNext(pDoc->curPos);

 	//	pDoc->m_dataList.GetNext(pDoc->curPos);
		m_lCode=pStudent->m_nCode;
		m_sName=pStudent->m_sName;
	  //成员变量的数据传给控制ID,在对话框中显示数据
		UpdateData(false); 
		
	//	pDoc->m_dataList.GetNext(pDoc->curPos);
		if(pDoc->curPos==NULL)
				pDoc->curPos=pDoc->m_dataList.GetHeadPosition();
		// 为进行下一轮循环做准备
	}
	else
		MessageBox("当前列表中没有数据!");
	pDoc->UpdateAllViews(this);
}

void CEx07bView::OnAddRecord() 
{
	// TODO: Add your control notification handler code here
	UpdateData();  //DDX: Control ID---->Member Variable
				//True
	CEx07bDoc *pDoc=GetDocument();

	ASSERT_VALID(pDoc);

	CStudent *pStudent;
	pStudent=new CStudent(m_lCode,m_sName);
					//CEx07aView 的数据成员
	pStudent->m_lScore=0;
	pStudent->m_lAge=0;
//	pStudent->Count
	pDoc->m_dataList.AddTail(pStudent);  //文档类中的数据
//...

	pDoc->curPos=pDoc->m_dataList.GetHeadPosition();

	pDoc->UpdateAllViews(this);
	pDoc->SetModifiedFlag();

//控制控件的允许,
	CWnd *m_Wnd=NULL;
	m_Wnd=GetDlgItem(IDC_TONGJI);
	m_Wnd->EnableWindow();
	m_Wnd=GetDlgItem(IDC_NEXT);
	m_Wnd->EnableWindow();
	m_Wnd=GetDlgItem(IDC_PLTXG);
	m_Wnd->EnableWindow();
	m_Wnd=GetDlgItem(IDC_INSERT);
	m_Wnd->EnableWindow();
	m_Wnd=GetDlgItem(IDC_REMOVE);
	m_Wnd->EnableWindow();



}




void CEx07bView::OnTongji() 
{
	// TODO: Add your control notification handler code here

	m_pmenu=true;


   CEx07bDoc *pDoc=GetDocument();
	POSITION pos=pDoc->m_dataList.GetHeadPosition();
    int i=0;
	float leiji=0;
	float baifenbi=0;
	
	//排序
//	while (pos!=NULL)
//	{
//		CStudent *pStudent=pDoc->m_dataList.GetNext(pos);			
//		i++;
//	}
//	i--;
//	i=pDoc->m_dataList.GetCount;
//	float lin[i];
///	pos=pDoc->m_dataList.GetHeadPosition();
//	for (int j=0;j<=i;j++)
//	{
//		CStudent *pStudent=pDoc->m_dataList.GetNext(pos);
//		lin[j]=pStudent->m_nCode;
//	}
//	for (int m=0;m<=i;m++)
//		for (int n=0;n<=j-m;n++)
		
//			if (lin[n]<a[n+1])
//			{float t=lin[n];lin[n]=lin[n+1];lin[n+1]=t;}
		


	//统计百分比
	while(pos!=NULL)
	{
		i++;
		CStudent *pStudent=pDoc->m_dataList.GetNext(pos);
	
		leiji=leiji+pStudent->m_nCode;
		pStudent->Hz=leiji;
		pStudent->Count=i;
	//	pDoc->m_dataList.GetNext(pDoc->curPos);
	
	}
   POSITION	pos1=pDoc->m_dataList.GetHeadPosition();
  
   //统计累计百分比
	while(pos1!=NULL)
	{
	    CStudent *pStudent2=pDoc->m_dataList.GetNext(pos1);
		pStudent2->m_lAge=(pStudent2->m_nCode*100/leiji);
	
		baifenbi=baifenbi+pStudent2->m_lAge;
		pStudent2->m_lScore=baifenbi;

//		pDoc->m_dataList.GetNext(pDoc->curPos);
		i++;
	}

    pDoc->UpdateAllViews(this);
	


	
}

void CEx07bView::OnPltxg() 
{
	// TODO: Add your control notification handler code here
	UpdateData();  //DDX: Control ID---->Member Variable
				
	CEx07bDoc *pDoc=GetDocument();

	ASSERT_VALID(pDoc);
	if(pDoc->curPos==NULL)
				pDoc->curPos=pDoc->m_dataList.GetTailPosition(); //.GetHeadPosition();

	pDoc->m_dataList.GetPrev(pDoc->curPos);
		if(pDoc->curPos==NULL)
				pDoc->curPos=pDoc->m_dataList.GetTailPosition();

	CStudent *pStudent;
	pStudent=pDoc->m_dataList.GetAt(pDoc->curPos);
//	pStudent=pDoc->m_dataList.GetPrev(pDoc->curPos);
	pStudent->m_nCode=m_lCode;
	pStudent->m_sName=m_sName;
	pDoc->m_dataList.GetNext(pDoc->curPos);
		if(pDoc->curPos==NULL)
				pDoc->curPos=pDoc->m_dataList.GetHeadPosition();

	pDoc->SetModifiedFlag();
	pDoc->UpdateAllViews(this);
	
}


void CEx07bView::OnInsert() 
{
	// TODO: Add your control notification handler code here
	CEx07bDoc *pDoc =GetDocument();
	ASSERT_VALID(pDoc);

	UpdateData(); 

	CStudent *pStudent;
	pStudent=new CStudent(m_lCode,m_sName);
					//CEx07aView 的数据成员
	pStudent->m_lScore=0;
	pStudent->m_lAge=0;

	pDoc->m_dataList.InsertBefore(pDoc->curPos,pStudent);

	pDoc->SetModifiedFlag();
	pDoc->UpdateAllViews(this);
	
}

void CEx07bView::OnRemove() 
{
	// TODO: Add your control notification handler code here
	CEx07bDoc *pDoc =GetDocument();
	ASSERT_VALID(pDoc);	
    
	CStudent *pStudent=pDoc->m_dataList.GetPrev(pDoc->curPos);
		if(pDoc->curPos==NULL)
				pDoc->curPos=pDoc->m_dataList.GetTailPosition();
	pDoc->m_dataList.RemoveAt(pDoc->curPos);
//	pStudent=pDoc->m_dataList.GetNext(pDoc->curPos);
	pDoc->curPos=pDoc->m_dataList.GetHeadPosition();

	pDoc->SetModifiedFlag();
	pDoc->UpdateAllViews(this);
}



BOOL CEx07bView::PreTranslateMessage(MSG* pMsg) 
{
	// TODO: Add your specialized code here and/or call the base class

	if (pMsg->message==WM_KEYDOWN&&pMsg->wParam==VK_RETURN)
	{
		if(pMsg->hwnd==(GetDlgItem(IDC_NAME)->m_hWnd))
		{	
			CEdit *pEdit=(CEdit*)(GetDlgItem(IDC_CODE));
			pEdit->SetFocus();
			pEdit->SetSel(0,-1,true);
		}

		if(pMsg->hwnd==(GetDlgItem(IDC_CODE)->m_hWnd))
		{
			UpdateData();  //DDX: Control ID---->Member Variable
				//True
			CEx07bDoc *pDoc=GetDocument();

			ASSERT_VALID(pDoc);

			CStudent *pStudent;
			pStudent=new CStudent(m_lCode,m_sName);
					//CEx07aView 的数据成员
			pStudent->m_lScore=0;
			pStudent->m_lAge=0;
//	pStudent->Count
			pDoc->m_dataList.AddTail(pStudent);  //文档类中的数据
//...

			pDoc->curPos=pDoc->m_dataList.GetHeadPosition();

			pDoc->UpdateAllViews(this);
			pDoc->SetModifiedFlag();

//控制控件的允许,
			CWnd *m_Wnd=NULL;
			m_Wnd=GetDlgItem(IDC_TONGJI);
			m_Wnd->EnableWindow();
			m_Wnd=GetDlgItem(IDC_NEXT);
			m_Wnd->EnableWindow();
			m_Wnd=GetDlgItem(IDC_PLTXG);
			m_Wnd->EnableWindow();
			m_Wnd=GetDlgItem(IDC_INSERT);
			m_Wnd->EnableWindow();
			m_Wnd=GetDlgItem(IDC_REMOVE);
			m_Wnd->EnableWindow();

			CEdit * pEdit=(CEdit*)(GetDlgItem(IDC_NAME));
			pEdit->SetFocus();
			pEdit->SetSel(0,-1,true);
		}
	}
	return CFormView::PreTranslateMessage(pMsg);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -