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

📄 xiahuaview.cpp

📁 彩电故障维修信息管理系统
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	}
}

//显示所有数据;
void CXiahuaView::OnRecordShowAll() 
{
	// TODO: Add your command handler code here
	//if(m_bIsShowAll)
		//return;
	m_pSet->m_strFilter.Empty();
	m_pSet->Requery();
	ShowTableData();
	m_bIsShowAll=TRUE;
	CListView::OnInitialUpdate();
}

//修改数据函数;
void CXiahuaView::OnRecordEdit() 
{
	// TODO: Add your command handler code here
	if(memberright()==0)
		return;
	else
	{
        CListCtrl &ctl=GetListCtrl();
        POSITION pos=ctl.GetFirstSelectedItemPosition();
        if(pos==NULL)
		{
        	AfxMessageBox(_T("没有选中记录"),MB_ICONEXCLAMATION);
		}
       	else
		{
            int nItem=ctl.GetNextSelectedItem(pos);
            m_pSet->Move(nItem);
            CRecordEdit editDlg;
            editDlg.m_strCrt=m_pSet->m_crt;
            editDlg.m_strCase=m_pSet->m_case;
            editDlg.m_strClips=m_pSet->m_clips;
            editDlg.m_strDevice=m_pSet->m_device;
            editDlg.m_strWorkor=m_pSet->m_workor;
            editDlg.m_strOther=m_pSet->m_other;
            editDlg.m_strDate=m_pSet->m_date;
        	 editDlg.m_strContent=m_pSet->m_content;
            editDlg.m_strInfo=m_pSet->m_info;

             if(editDlg.DoModal()==IDOK)
             {
	             m_pSet->Edit();
	             m_pSet->m_crt=editDlg.m_strCrt;
                 m_pSet->m_case=editDlg.m_strCase;
                 m_pSet->m_clips=editDlg.m_strClips;
                 m_pSet->m_device=editDlg.m_strDevice;
                 m_pSet->m_workor=editDlg.m_strWorkor;
                 m_pSet->m_other=editDlg.m_strOther;
                 m_pSet->m_date=editDlg.m_strDate;
                 m_pSet->m_info=editDlg.m_strInfo;
                 m_pSet->m_content=editDlg.m_strContent;
	             m_pSet->Update();
	             ShowTableData();
             }
		}
	}
}

//双击响应函数;
void CXiahuaView::OnDblclk(NMHDR* pNMHDR, LRESULT* pResult) 
{
    OnRecordView();
	*pResult = 0;
}

//打印预览
void CXiahuaView::OnPrint(CDC* pDC, CPrintInfo* pInfo) 
{
	// TODO: Add your specialized code here and/or call the base class
	pDC->SetMapMode(MM_LOENGLISH);
	CXiahuaDoc* pDoc=GetDocument();
	ASSERT_VALID(pDoc);

	TEXTMETRIC textMetric;
	CRect rect(30,-30,783,-1081);//pInfo->m_rectDraw.right-10,pInfo->m_rectDraw.bottom+55
	int y=rect.top;
	CString strTitle;
	
	CSize oFontSize;
	/*int iRowCount=1;
	char lpstrRow[6]="1";
	CString cLine="";*/
	
	CString strText;
//	CString strTextRtmp;
//	CString strText1;
//	CString strTextLeft;
	int i=0;
 //   CPoint point;
	CPen oPen;
	CBrush oBrush;
//	CFont oTextFont;
	CFont oHeadFont;
//	CFont oColFont;
	//LOGFONT lfFont;
	
	COLORREF clrRef;
//	int iRowPos=90;
//	int iTextHeight=0;
	

	clrRef=0X00000000;
	oPen.CreatePen(PS_SOLID,2,clrRef);
	pDC->SelectObject(&oPen);

	clrRef=0X00C000C0;
	oBrush.CreateSolidBrush(clrRef);
	pDC->SelectObject(&oBrush);

	oHeadFont.CreatePointFont(160,"Areal",pDC);
	pDC->SelectObject(&oHeadFont);

	//pDC->Ellipse(300,iRowPos-50,1300,iRowPos+120);
	pDC->SetBkMode(TRANSPARENT);
	CListCtrl &ctl=GetListCtrl();
	POSITION pos=ctl.GetFirstSelectedItemPosition();
	if(pos==NULL)
	{
		AfxMessageBox(_T("没有选中记录"),MB_ICONEXCLAMATION);
		return;
	}
	else
	{
        int nItem=ctl.GetNextSelectedItem(pos);
        m_pSet->Move(nItem);
		strTitle.Format("%s",m_pSet->m_info);
		oFontSize=pDC->GetOutputTextExtent(strTitle);
	    pDC->SetTextAlign(TA_CENTER);
        //int n=strlen(strTitle);
		//CString strn;
		//strn.Format("%d",n);
		int x=360;
		
		pDC->TextOut(rect.left+x,y,strTitle);
		pDC->GetTextMetrics(&textMetric);
		y-=2*textMetric.tmHeight;
		int y1=y;
		int y2;
		pDC->MoveTo(rect.left+20,y);
		pDC->LineTo(rect.right-40,y);
		//textMetric.tmHeight;
        CString str2[4]={"显象管","机  芯","机  壳","其  他"};//"器件","技术员","时间","其他","信息名","具体内容"
        CString str3[4]={"器  件","技术员","时  间"," "};
		CString str4[4];
		CString str5[4];
		CString str6="具体内容";
        CString str7;
		str7.Format("%s",m_pSet->m_content);
		str4[0].Format("%s",m_pSet->m_crt);
		str4[1].Format("%s",m_pSet->m_clips);
		str4[2].Format("%s",m_pSet->m_case);
		str4[3].Format("%s",m_pSet->m_other);
        
		str5[0].Format("%s",m_pSet->m_device);
		str5[1].Format("%s",m_pSet->m_workor);
		str5[2].Format("%s",m_pSet->m_date);
		str5[3].Format(" ");
		for(int i=0;i<4;i++)
		{
			y-=5;
			pDC->SetTextAlign(TA_RIGHT);
			pDC->TextOut(rect.left+90,y,str2[i]);
			pDC->TextOut(rect.left+460,y,str3[i]);
			pDC->SetTextAlign(TA_CENTER);
			pDC->TextOut(rect.left+250,y,str4[i]);
			pDC->TextOut(rect.left+600,y,str5[i]);
	        y-=textMetric.tmHeight+5;
			pDC->MoveTo(rect.left+20,y);
		    pDC->LineTo(rect.right-40,y);
			if(i==2)
				y2=y;
		}
		
		pDC->MoveTo(rect.left+95,y1);
		pDC->LineTo(rect.left+95,y);
		pDC->MoveTo(rect.left+390,y1);
		pDC->LineTo(rect.left+390,y2);
		pDC->MoveTo(rect.left+465,y1);
		pDC->LineTo(rect.left+465,y2);
		
		y-=5;
		pDC->SetTextAlign(TA_CENTER);
		pDC->TextOut(rect.left+360,y,str6);
		y-=textMetric.tmHeight+5;
		pDC->MoveTo(rect.left+20,y);
		pDC->LineTo(rect.right-40,y);
		y-=5;
		//CRect rect(90,-200,500,-1081);
		pDC->SetTextAlign(TA_LEFT);
		pDC->TextOut(rect.left+60,y,str7);
		pDC->MoveTo(rect.left+20,y1);
		pDC->LineTo(rect.left+20,-500);
		pDC->MoveTo(rect.right-40,y1);
		pDC->LineTo(rect.right-40,-500);
		pDC->MoveTo(rect.left+20,-500);
		pDC->LineTo(rect.right-40,-500);
		y=rect.bottom;
		y+=textMetric.tmHeight;
		pDC->MoveTo(rect.left,y);
		pDC->LineTo(rect.right,y);
		y-=2;
		//oHeadFont.CreatePointFont(100,"Areal",pDC);
		CTime theTime=CTime::GetCurrentTime();
		pDC->SetTextAlign(TA_LEFT);
		pDC->TextOut(rect.left,y,theTime.Format("%a %b %d %Y, %I:%M:%S %p"));
        strText.Format("第%d页",pInfo->m_nCurPage);
		pDC->SetTextAlign(TA_RIGHT);
		pDC->TextOut(rect.right,y,strText);
	CListView::OnPrint(pDC, pInfo);
	}
}
/*
//页眉
void CXiahuaView::PrintPageHeader(CDC *pDc, CPrintInfo *pInfo)
{

}

//页脚;
void CXiahuaView::PrintPageFooter(CDC *pDC)
{

}
*/

void CXiahuaView::OnPasswardEdit() 
{
	// TODO: Add your command handler code here
	UpdateData(TRUE);
	COleVariant var;
	CModPswd modpswd;
	if(modpswd.DoModal()==IDCANCEL)
		return;
	else
	{
        CLoginSet *m_daorecordset=new CLoginSet(&pDatabase);
		CString strSQL;
		CString str1;
		strSQL.Format("select * from login where user='%s'",modpswd.m_strUser);
		m_daorecordset->Open(AFX_DAO_USE_DEFAULT_TYPE,strSQL);
		if(m_daorecordset->GetRecordCount()==0)
		{
            AfxMessageBox(_T("无此用户!\n请向管理员咨询"),MB_ICONEXCLAMATION);
			m_daorecordset->Close();
			OnPasswardEdit();
		}
        else
		{
		   m_daorecordset->Close();//先关闭,以便以后再次打开记录集体对象
		   strSQL.Format("select * from login where user='%s' and passward='%s'",modpswd.m_strUser,modpswd.m_strFormerps);
		   m_daorecordset->Open(AFX_DAO_USE_DEFAULT_TYPE,strSQL);
		   if(m_daorecordset->GetRecordCount()==0)
		   {
              AfxMessageBox(_T("密码错误!\n请注意大小写"),MB_ICONEXCLAMATION);
		   }
		   else
		   {
			   if(modpswd.m_strNewps.Compare(modpswd.m_strConfirps)!=0)
			   {
				   
				   AfxMessageBox(_T("两遍新密码输入不一致!\n    请重输!"),MB_ICONEXCLAMATION);
                   modpswd.m_strNewps.Empty();
				   modpswd.m_strConfirps.Empty();
				   UpdateData(FALSE);
			   }
			   else
			   {
                   m_daorecordset->Edit();//使记录集可编辑
				   m_daorecordset->m_passward=modpswd.m_strNewps;
				   m_daorecordset->Update();//修改后刷新
				   AfxMessageBox(_T("密码修改成功!\n请记住新密码!"),MB_ICONEXCLAMATION);
			   }
		   }
		}
		/*m_daorecordset->GetFieldValue(1,var);
		str1.Format("%s",var);
		if(modpswd.m_strFormerps.Compare(str1)!=0)
		{
			AfxMessageBox(_T("密码错误!\n请重新输入"),MB_ICONEXCLAMATION);
		}*/
	}

}

void CXiahuaView::OnRecordView() 
{
	// TODO: Add your command handler code here
	CListCtrl &ctl=GetListCtrl();
	POSITION pos=ctl.GetFirstSelectedItemPosition();
	if(pos==NULL)
	{
		AfxMessageBox(_T("没有选中记录"),MB_ICONEXCLAMATION);
	}
		//return;
	else
	{
	int nItem=ctl.GetNextSelectedItem(pos);
	m_pSet->Move(nItem);
	//CRecordEdit editDlg;
	CRecord viewDlg;
	viewDlg.m_strCrt=m_pSet->m_crt;
	viewDlg.m_strCase=m_pSet->m_case;
	viewDlg.m_strClips=m_pSet->m_clips;
	viewDlg.m_strDevice=m_pSet->m_device;
	viewDlg.m_strWorkor=m_pSet->m_workor;
	viewDlg.m_strOther=m_pSet->m_other;
	viewDlg.m_strDate=m_pSet->m_date;
	viewDlg.m_strContent=m_pSet->m_content;
	viewDlg.m_strInfo=m_pSet->m_info;

	if(viewDlg.DoModal()==IDOK)
	{
		//m_pSet->Edit();
		/*m_pSet->m_crt=viewDlg.m_strCrt;
	    m_pSet->m_case=viewDlg.m_strCase;
	    m_pSet->m_clips=viewDlg.m_strClips;
	    m_pSet->m_device=viewDlg.m_strDevice;
	    m_pSet->m_workor=viewDlg.m_strWorkor;
	    m_pSet->m_other=viewDlg.m_strOther;
	    m_pSet->m_date=viewDlg.m_strDate;
	    m_pSet->m_info=viewDlg.m_strInfo;
	    m_pSet->m_content=viewDlg.m_strContent;*/
        
		//m_pSet->Update();
		ShowTableData();
		
	}
	}
}
//添加用户
void CXiahuaView::OnUserAdd() 
{
	// TODO: Add your command handler code here
	CLoginSet *m_daorecordset=new CLoginSet(&pDatabase);//初始化连接数据库指针
    CString strSQL;
	if(adiministrator()==0)  //管理员权限验证,失败返回
		return;
    else
	{
    	CAddUser adduser;//进入增加用户窗口
    	if(adduser.DoModal()==IDCANCEL)
		    return;
    	else
		{
	    	m_daorecordset->Close();
			strSQL.Format("select * from login where user='%s'",adduser.m_strUser);
            m_daorecordset->Open(AFX_DAO_USE_DEFAULT_TYPE,strSQL);
            if(m_daorecordset->GetRecordCount()!=0)
			{
				AfxMessageBox(_T("         对不起!\n"+adduser.m_strUser+"已经存在,请尝试用其他名字!"),MB_ICONEXCLAMATION);
			}
			else
			{
				if(adduser.m_strPswd.Compare(adduser.m_strCompswd)!=0)
				{
			    	AfxMessageBox(_T("两遍新密码输入不一致!\n请重输!"),MB_ICONEXCLAMATION);
				}
		    	else
				{
			        adduser.m_strUser.TrimLeft(" ");
			        adduser.m_strUser.TrimRight(" ");
			    	m_daorecordset->AddNew();
			    	m_daorecordset->m_user=adduser.m_strUser;
			    	m_daorecordset->m_passward=adduser.m_strPswd;
			    	CString str1,str2;
		    		str1.Format("%s",adduser.m_strUser);
			    	str2.Format("\n欢迎您的加入!");
				    str1=str1+str2;
		    		AfxMessageBox(str1,MB_ICONEXCLAMATION);
			    	m_daorecordset->Update();//增加成功,刷新数据库
				}
			}
		}
	}
}

void CXiahuaView::OnUserDel() 
{
	// TODO: Add your command handler code here
	CLoginSet *m_daorecordset=new CLoginSet(&pDatabase);
    CString strSQL;
	CString user;
	user.Format("administrator");
	if(adiministrator()==0)//管理员权限验证,失败返回
		return;
	else
	{
		CDelUser deluser;//成功。调入删除用户窗口
		if(deluser.DoModal()==IDCANCEL)
            return;
        else
		{
		    if(deluser.m_strUser.Compare(user)==0)
			{
				AfxMessageBox(_T("   对不起!\n不允许删除管理员"),MB_ICONEXCLAMATION);
			}
			else
			{
			    CString str1;
				str1.Format("%s",deluser.m_strUser);
				if(AfxMessageBox("确定要删除"+str1+"吗?",MB_YESNO|MB_ICONEXCLAMATION)==IDYES)
				{
       	           strSQL.Format("delete from login where user='%s'",deluser.m_strUser);
		            pDatabase.Execute(strSQL);
				}
			}
		}
	}
}

void CXiahuaView::OnUpdateRecordEdit(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	CListCtrl &ctl=GetListCtrl();
	POSITION pos=ctl.GetFirstSelectedItemPosition();
	if(pos==NULL)
		pCmdUI->Enable(FALSE);
	else
		pCmdUI->Enable();
}

void CXiahuaView::OnUpdateRecordView(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	CListCtrl &ctl=GetListCtrl();
	POSITION pos=ctl.GetFirstSelectedItemPosition();
	if(pos==NULL)
		pCmdUI->Enable(FALSE);
	else
		pCmdUI->Enable();
}

int CXiahuaView::adiministrator()
{
    CLoginDlg logindlg;
	if(logindlg.DoModal()==IDCANCEL)
		return 0;
	else
	{
    	CLoginSet *m_daorecordset=new CLoginSet(&pDatabase);//初始化连接数据库指针
	    CString strSQL;
		CString user;
		user.Format("administrator");
		if(logindlg.m_strUser.Compare(user)!=0)
		{
			AfxMessageBox(_T("       对不起!\n只有管理员才可以允许"),MB_ICONEXCLAMATION);
		    return 0;
		}
		else
		{
	        strSQL.Format("select * from login where user='%s' and passward='%s'",logindlg.m_strUser,logindlg.m_strPass);
	        m_daorecordset->Open(AFX_DAO_USE_DEFAULT_TYPE,strSQL);
	        if(m_daorecordset->GetRecordCount()==0)
			{
			    CString strdel;
			    strdel.Format("        非法尝试!\n请注意密码与用户名是否一致");
			    AfxMessageBox(strdel,MB_ICONEXCLAMATION);
				return 0;
			}
			else
				return 1;
		}
	}
}

int CXiahuaView::memberright()
{
    CLoginDlg logindlg;
	if(logindlg.DoModal()==IDCANCEL)
		return 0;
	else
	{
		CLoginSet *m_daorecordset=new CLoginSet(&pDatabase);
	    CString strSQL;
	    strSQL.Format("select * from login where user='%s' and passward='%s'",logindlg.m_strUser,logindlg.m_strPass);
	    m_daorecordset->Open(AFX_DAO_USE_DEFAULT_TYPE,strSQL);
	    if(m_daorecordset->GetRecordCount()==0)
		{
			CString strdel;
			strdel.Format("     非法尝试!\n请注意密码与用户名是否一致\n或者您还没注册");
			AfxMessageBox(strdel,MB_ICONEXCLAMATION);
			return 0;
		}
		else
			return 1;
	}
}

⌨️ 快捷键说明

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