// xiahuaView.cpp : implementation of the CXiahuaView class
// Download by http://www.codefans.net
#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+" A