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

📄 xiahuaview.cpp

📁 彩电故障维修信息管理系统
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// xiahuaView.cpp : implementation of the CXiahuaView class
//

#include "stdafx.h"
#include "xiahua.h"

#include "xiahuaDoc.h"
#include "xiahuaView.h"
#include "infodlg.h"
#include "resource.h"
#include "mainfrm.h"
#include "iostream.h"
#include "logindlg.h"
#include "record.h"
#include "modpswd.h"
#include "adduser.h"
#include "deluser.h"


#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CXiahuaView

IMPLEMENT_DYNCREATE(CXiahuaView, CListView)

BEGIN_MESSAGE_MAP(CXiahuaView, CListView)
	ON_WM_CONTEXTMENU()
	//{{AFX_MSG_MAP(CXiahuaView)
	ON_NOTIFY_REFLECT(LVN_COLUMNCLICK, OnColumnclick)
	ON_COMMAND(ID_RECORD_ADD, OnRecordAdd)
	ON_COMMAND(ID_RECORD_DEL, OnRecordDel)
	ON_UPDATE_COMMAND_UI(ID_RECORD_DEL, OnUpdateRecordDel)
	ON_COMMAND(ID_RECORD_SEARCH, OnRecordSearch)
	ON_COMMAND(ID_RECORD_ALL, OnRecordShowAll)
	ON_COMMAND(ID_RECORD_EDIT, OnRecordEdit)
	ON_NOTIFY_REFLECT(NM_DBLCLK, OnDblclk)
	ON_COMMAND(ID_PASSWARD_EDIT, OnPasswardEdit)
	ON_COMMAND(ID_RECORD_VIEW, OnRecordView)
	ON_COMMAND(ID_USER_ADD, OnUserAdd)
	ON_COMMAND(ID_USER_DEL, OnUserDel)
	ON_UPDATE_COMMAND_UI(ID_RECORD_EDIT, OnUpdateRecordEdit)
	ON_UPDATE_COMMAND_UI(ID_RECORD_VIEW, OnUpdateRecordView)
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CListView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CListView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CListView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CXiahuaView construction/destruction

CXiahuaView::CXiahuaView()
{
	// TODO: add construction code here

}

CXiahuaView::~CXiahuaView()
{
}

BOOL CXiahuaView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CListView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CXiahuaView drawing

void CXiahuaView::OnDraw(CDC* pDC)
{
	CXiahuaDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
}


//初始化窗口;
void CXiahuaView::OnInitialUpdate()
{
	CListView::OnInitialUpdate();
	// TODO: You may populate your ListView with items by directly accessing
	CListCtrl &ctl=GetListCtrl();
	ctl.ModifyStyle(0,LVS_REPORT|LVS_SINGLESEL);
	ctl.SetExtendedStyle(LVS_EX_FLATSB|LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);

	m_pSet=&GetDocument()->m_dataSet;               //初始化m_pSet指针,m_pSet原型为CDataSet* m_pSet
	m_pLset=&GetDocument()->m_dataLset;             //初始化m_pLset指针,m_pLset原型为CLoginSet* m_pLset
	if(m_pSet->IsOpen())
		m_pSet->Close();
	m_pSet->Open();                                 //打开数据库
    GetDocument()->SetTitle("彩电故障信息共享系统");//设置标题
	CString str;
	//以下是设置控件按钮显示字符
	str.LoadString(IDS_SERIAL);
	ctl.InsertColumn(0,str);
	
	/*CDaoFieldInfo fieldInfo;
	for(short i=0;i<m_pSet->m_nFields;i++)
	{
	    m_pSet->GetFieldInfo(i,fieldInfo);
		ctl.InsertColumn(i+1,fieldInfo.m_strName);
	}*/
	ctl.InsertColumn(1,"显象管");
    ctl.InsertColumn(2,"机芯");
	ctl.InsertColumn(3,"机壳");
	ctl.InsertColumn(4,"器件");
	ctl.InsertColumn(5,"技术员");
	ctl.InsertColumn(6,"时间");
	ctl.InsertColumn(7,"其他");
	ctl.InsertColumn(8,"信息名");
	ctl.InsertColumn(9,"具体内容");
	m_bIsAsc=TRUE;
	m_bIsShowAll=TRUE;
	ShowTableData();                                 //调用显示数据函数,显示数据
}

/////////////////////////////////////////////////////////////////////////////
// CXiahuaView printing

BOOL CXiahuaView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CXiahuaView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CXiahuaView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CXiahuaView diagnostics

#ifdef _DEBUG
void CXiahuaView::AssertValid() const
{
	CListView::AssertValid();
}

void CXiahuaView::Dump(CDumpContext& dc) const
{
	CListView::Dump(dc);
}

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

/////////////////////////////////////////////////////////////////////////////
// CXiahuaView message handlers



//显示表格数据;
void CXiahuaView::ShowTableData()
{
    CListCtrl &ctl=GetListCtrl();
	ctl.DeleteAllItems();       //删除所有已显示内容

	m_pSet->MoveFirst();        //将m_pSet指针指向首条记录
	int i=0;
	int ColWidth[10]={0};
	while(!m_pSet->IsEOF())     //如果没有到达数据末尾,则显示数据
	{
		LV_ITEM lvItem;
		lvItem.mask = LVIF_TEXT;
		lvItem.iItem = i;
		
		lvItem.iSubItem=0;
		CString str;
		str.Format("%d",i+1);   //序号列
		lvItem.pszText=(LPTSTR)(LPCTSTR)str;
		if(ctl.GetStringWidth(lvItem.pszText)>ColWidth[0])
			ColWidth[0]=ctl.GetStringWidth(lvItem.pszText);
		ctl.InsertItem(&lvItem);
	    //以下显示各条内容
		lvItem.iSubItem = 1;    
		lvItem.pszText=(LPTSTR)(LPCTSTR)(m_pSet->m_crt);
		if(ctl.GetStringWidth(lvItem.pszText)>ColWidth[1])
			ColWidth[1]=ctl.GetStringWidth(lvItem.pszText);
		ctl.SetItem(&lvItem);
		
		lvItem.iSubItem=2;
		lvItem.pszText=(LPTSTR)(LPCTSTR)(m_pSet->m_clips);
		if(ctl.GetStringWidth(lvItem.pszText)>ColWidth[2])
			ColWidth[2]=ctl.GetStringWidth(lvItem.pszText);
		ctl.SetItem(&lvItem);
		
		lvItem.iSubItem=3;
		lvItem.pszText=(LPTSTR)(LPCTSTR)(m_pSet->m_case);
		if(ctl.GetStringWidth(lvItem.pszText)>ColWidth[3])
			ColWidth[3]=ctl.GetStringWidth(lvItem.pszText);
		ctl.SetItem(&lvItem);

		lvItem.iSubItem=4;
		lvItem.pszText=(LPTSTR)(LPCTSTR)(m_pSet->m_device);
		if(ctl.GetStringWidth(lvItem.pszText)>ColWidth[4])
			ColWidth[4]=ctl.GetStringWidth(lvItem.pszText);
		ctl.SetItem(&lvItem);

		lvItem.iSubItem=5;
		lvItem.pszText=(LPTSTR)(LPCTSTR)(m_pSet->m_workor);
		if(ctl.GetStringWidth(lvItem.pszText)>ColWidth[5])
			ColWidth[5]=ctl.GetStringWidth(lvItem.pszText);
		ctl.SetItem(&lvItem);

        lvItem.iSubItem=6;
		//CString stTmp =m_pSet->m_date.Format("%Y-%m-%d");// %H:%M:%S
		//strcpy(lvItem.pszText,(LPSTR)(LPCSTR)stTmp);
		lvItem.pszText=(LPTSTR)(LPCTSTR)(m_pSet->m_date);
		if(ctl.GetStringWidth(lvItem.pszText)>ColWidth[6])
			ColWidth[6]=ctl.GetStringWidth(lvItem.pszText);
		ctl.SetItem(&lvItem);

		lvItem.iSubItem=7;
		lvItem.pszText=(LPTSTR)(LPCTSTR)(m_pSet->m_other);
		if(ctl.GetStringWidth(lvItem.pszText)>ColWidth[7])
			ColWidth[7]=ctl.GetStringWidth(lvItem.pszText);
		ctl.SetItem(&lvItem);
		
		lvItem.iSubItem=8;
		lvItem.pszText=(LPTSTR)(LPCTSTR)(m_pSet->m_info);
		if(ctl.GetStringWidth(lvItem.pszText)>ColWidth[8])
			ColWidth[8]=ctl.GetStringWidth(lvItem.pszText);
		ctl.SetItem(&lvItem);

		lvItem.iSubItem=9;
		lvItem.pszText=(LPTSTR)(LPCTSTR)(m_pSet->m_content);
		if(ctl.GetStringWidth(lvItem.pszText)>ColWidth[9])
			ColWidth[9]=ctl.GetStringWidth(lvItem.pszText);
		ctl.SetItem(&lvItem);
		i++;
		m_pSet->MoveNext();           //将m_pSet指针指向下条记录
	}
	//设置各数据项的显示宽度
	for(int j=0;j<8;j++)
	{
	ctl.SetColumnWidth(j,ColWidth[j]+30);
	}
	ctl.SetColumnWidth(8,100);
	ctl.SetColumnWidth(9,100);
    m_pSet->MoveFirst();              //将m_pSet指针再指向首条记录,便于下次操作
}

//当单击上方时,按所列的数据进行排序
void CXiahuaView::Sort(BOOL isAsc)
{
    CDaoFieldInfo fieldInfo;
	m_pSet->GetFieldInfo(0,fieldInfo);
	if(isAsc)
	{
		//AfxMessageBox(fieldInfo.m_strName,MB_ICONEXCLAMATION);
		m_pSet->m_strSort=fieldInfo.m_strName+" ASC";
		m_bIsAsc=TRUE;
	}
	else
	{
		m_pSet->m_strSort=fieldInfo.m_strName+" DESC";
		m_bIsAsc=FALSE;
	}
	m_pSet->Requery();
}

//响应单击事件;
void CXiahuaView::OnColumnclick(NMHDR* pNMHDR, LRESULT* pResult) 
{
	NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
	// TODO: Add your control notification handler code here
	
	
		Sort(!m_bIsAsc);
		ShowTableData();
	
	*pResult = 0;
}


//增加数据函数;
void CXiahuaView::OnRecordAdd() 
{
	// TODO: Add your command handler code here
	if(memberright()==0)
		return;
	else
	{
        CInfoDlg addDlg;
        if(addDlg.DoModal()==IDOK)
        {
        	CString crt;
        	crt=addDlg.m_strCrt;
        	if(addDlg.m_strInfo.IsEmpty())
	        {
	        	AfxMessageBox(_T("为保证数据的有效性,\n请确定您已输入有效信息"),MB_ICONEXCLAMATION);
	        	OnRecordAdd();
		        addDlg.m_strCrt=crt;
            }
			else
			{
	        addDlg.m_strCrt.TrimLeft(" ");
	        addDlg.m_strCrt.TrimRight(" ");
	        addDlg.m_strCase.TrimLeft(" ");
        	addDlg.m_strCase.TrimRight(" ");
        	addDlg.m_strInfo.TrimLeft(" ");
        	addDlg.m_strInfo.TrimRight(" ");
        	addDlg.m_strDate.TrimLeft(" ");
        	addDlg.m_strDate.TrimRight(" ");
        	addDlg.m_strDevice.TrimLeft(" ");
        	addDlg.m_strDevice.TrimRight(" ");
        	addDlg.m_strClips.TrimLeft(" ");
        	addDlg.m_strClips.TrimRight(" ");
        	addDlg.m_strContent.TrimLeft(" ");
        	addDlg.m_strContent.TrimRight(" ");
        	addDlg.m_strOther.TrimLeft(" ");
        	addDlg.m_strOther.TrimRight(" ");
	        addDlg.m_strWorkor.TrimLeft(" ");
        	addDlg.m_strWorkor.TrimRight(" ");
	
	        m_pSet->AddNew();
        	m_pSet->m_crt=addDlg.m_strCrt;
        	m_pSet->m_info=addDlg.m_strInfo;
        	m_pSet->m_case=addDlg.m_strCase;
	        m_pSet->m_date=addDlg.m_strDate;
        	m_pSet->m_device=addDlg.m_strDevice;
        	m_pSet->m_clips=addDlg.m_strClips;
	        m_pSet->m_content=addDlg.m_strContent;
        	m_pSet->m_other=addDlg.m_strOther;
        	m_pSet->m_workor=addDlg.m_strWorkor;
        	m_pSet->Update();
	        Sort(m_bIsAsc);
        	ShowTableData();
			}
		}
	}
}

//删除数据函数;
void CXiahuaView::OnRecordDel() 
{
	// 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);
	        return;
		}
        int nItem=ctl.GetNextSelectedItem(pos);
        m_pSet->Move(nItem);
        CString str1,str2;
        str1.LoadString(IDS_WARN_1);
        str2.LoadString(IDS_WARN_2);
        str1=str1+str2;
        if(AfxMessageBox(str1,MB_YESNO|MB_ICONEXCLAMATION)==IDYES)
		{
        	m_pSet->Delete();
	        m_pSet->MoveFirst();
	        ShowTableData();
		}
	}
}

void CXiahuaView::OnUpdateRecordDel(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::OnContextMenu(CWnd*, CPoint point)
{
	// CG: This block was added by the Pop-up Menu component	{		if (point.x == -1 && point.y == -1){			//keystroke invocation			CRect rect;			GetClientRect(rect);			ClientToScreen(rect);			point = rect.TopLeft();			point.Offset(5, 5);		}		CMenu menu;		VERIFY(menu.LoadMenu(CG_IDR_POPUP_XIAHUA_VIEW));		CMenu* pPopup = menu.GetSubMenu(0);		ASSERT(pPopup != NULL);		CWnd* pWndPopupOwner = this;		while (pWndPopupOwner->GetStyle() & WS_CHILD)			pWndPopupOwner = pWndPopupOwner->GetParent();		pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y,			pWndPopupOwner);	}
}

//查询数据函数;
void CXiahuaView::OnRecordSearch() 
{
	// TODO: Add your command handler code here
	CRecordSearch search;
	CString str;

	if(search.DoModal()==IDCANCEL)return;
	else
	{
		ASSERT(m_pSet->CanRestart());
		search.m_strCrt.MakeLower();
		m_bIsShowAll=FALSE;
		CDaoFieldInfo fieldInfo;
		if(!search.m_strCrt.IsEmpty())
		{
            fieldInfo.m_strName="显象管";
	    	m_pSet->m_strFilter=fieldInfo.m_strName+" = "+"'"+search.m_strCrt+"'";
	        m_pSet->Requery();
		}
		else if(!search.m_strClips.IsEmpty())
		{
		    fieldInfo.m_strName="机芯";
		    m_pSet->m_strFilter=fieldInfo.m_strName+" = "+"'"+search.m_strClips+"'";
            m_pSet->Requery();
		}
		else if(!search.m_strCase.IsEmpty())
		{
           fieldInfo.m_strName="机壳";
	    	m_pSet->m_strFilter=fieldInfo.m_strName+" = "+"'"+search.m_strCase+"'";
           m_pSet->Requery();
		}
		else if(!search.m_strDevice.IsEmpty())
		{
	    	fieldInfo.m_strName="器件";
	    	m_pSet->m_strFilter=fieldInfo.m_strName+" = "+"'"+search.m_strDevice+"'";
            m_pSet->Requery();
		}
		else if(!search.m_strWorkor.IsEmpty())
		{
	    	fieldInfo.m_strName="技术员";
	    	m_pSet->m_strFilter=fieldInfo.m_strName+" = "+"'"+search.m_strWorkor+"'";
            m_pSet->Requery();
		}
		else if(!search.m_strDate.IsEmpty())
		{
	    	fieldInfo.m_strName="时间";
	    	m_pSet->m_strFilter=fieldInfo.m_strName+" = "+"'"+search.m_strDate+"'";
            m_pSet->Requery();
		}
		else if(!search.m_strOther.IsEmpty())
		{
	    	fieldInfo.m_strName="其他";
	    	m_pSet->m_strFilter=fieldInfo.m_strName+" = "+"'"+search.m_strOther+"'";
            m_pSet->Requery();
		}
		
		else if(!search.m_strInfo.IsEmpty())
		{
	    	fieldInfo.m_strName="信息名";
	     	m_pSet->m_strFilter=fieldInfo.m_strName+" = "+"'"+search.m_strInfo+"'";
            m_pSet->Requery();
		}
		else
		{
			AfxMessageBox(_T("请输入显象管型号"),MB_ICONEXCLAMATION);
			OnRecordSearch();
		}
		ShowTableData();

⌨️ 快捷键说明

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