📄 sortmag.cpp
字号:
// SortMag.cpp : implementation file
//
#include "stdafx.h"
#include "BOOKS.h"
#include "SortMag.h"
#include "Sortset.h"
#include "Deletedoc.h"
//#include "BOOKSSet.h"
//#include "BOOKSView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSortMag dialog
CSortMag::CSortMag(CWnd* pParent /*=NULL*/)
: CDialog(CSortMag::IDD, pParent)
{
//{{AFX_DATA_INIT(CSortMag)
m_sortname = _T("");
m_sortpath = _T("");
//}}AFX_DATA_INIT
m_isaddopen=false;
m_iseditopen=false;
bExpand=1;
bExpand2=3;
}
void CSortMag::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSortMag)
DDX_Control(pDX, IDC_TOPICLISTDLG, m_topiclist);
DDX_Text(pDX, IDC_SORTNAME, m_sortname);
DDX_Text(pDX, IDC_SORTPATH, m_sortpath);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSortMag, CDialog)
//{{AFX_MSG_MAP(CSortMag)
ON_BN_CLICKED(IDC_ADDSORT, OnAddsort)
ON_BN_CLICKED(IDC_MODIFYSORT, OnModifysort)
ON_NOTIFY(NM_CLICK, IDC_TOPICLISTDLG, OnClickTopiclistdlg)
ON_BN_CLICKED(IDC_CHECK, OnCheck)
ON_BN_CLICKED(IDC_DELETE, OnDelete)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSortMag message handlers
BOOL CSortMag::OnInitDialog()
{
CDialog::OnInitDialog();
if(m_pSort.IsOpen())
m_pSort.Close();
m_pSort.m_strFilter="";
m_pSort.m_strSort="";
m_pSort.Open();
m_topiclist.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
m_topiclist.InsertColumn(0,"类别名称",LVCFMT_LEFT,154);
m_topiclist.InsertColumn(1,"存储路径",LVCFMT_LEFT,300);
RushListctrl(&m_pSort,m_topiclist,"");
ExpandDialog(IDC_EXPAND_LINE,1);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CSortMag::RushListctrl(CRecordset *m_pRecord, CListCtrl &m_list, CString m_str)
{
if(m_pRecord->IsOpen())
m_pRecord->Close();
m_pRecord->m_strFilter=m_str;
//if(m_pRecord==m_pSet)
m_pRecord->m_strSort="SORT ASC";
m_pRecord->Open();
LV_ITEM lvi;
lvi.mask=LVIF_TEXT|LVIF_IMAGE|LVIF_PARAM;
lvi.iSubItem=0;
//lvi.pszText=(char *)data[0];
lvi.iImage = 0;
lvi.iItem=0;
for(int count=0;!m_pRecord->IsEOF();m_pRecord->MoveNext(),count++)
{//插入表项
//char str[10];
int k=m_pRecord->GetODBCFieldCount();
CString data[8];
//itoa(m_pRecord->m_ID,str,10);
CDBVariant varvalue;
for(int i=0;i<k;i++)
{
m_pRecord->GetFieldValue((short)i,varvalue);
if(DBVT_LONG==varvalue.m_dwType)
data[i].Format("%d",varvalue.m_lVal);
if(DBVT_STRING==varvalue.m_dwType)
data[i].Format("%s",varvalue.m_pstring->GetBuffer(1));
if(DBVT_DATE==varvalue.m_dwType)
data[i].Format("%d-%d",varvalue.m_pdate->year,varvalue.m_pdate->month);
}
lvi.pszText=data[0].GetBuffer(1);
m_list.InsertItem(&lvi);
//for (int j=1;j<k;j++)
m_list.SetItemText(count,1,data[1]);
}
m_pRecord->Close();
m_pRecord->m_strFilter="";
m_pRecord->m_strSort="";
m_pRecord->Open();
m_editSORT="";
}
void CSortMag::ExpandDialog(int nResourceID, int bExpand)
{
// 对话框被nResourceID分成上下两部分,如果bExpand的值为TRUE
// 对话框被完整显示,否则对话框显示上半部分。
static CRect rcLarge;
static CRect rcSmall;
CString sExpand;
//开始时,对话框只显示上半部分
if (rcLarge.IsRectNull())
{
CRect rcLandmark;
CWnd* pWndLandmark = GetDlgItem (nResourceID);
ASSERT(pWndLandmark);
GetWindowRect (rcLarge);
pWndLandmark->GetWindowRect (rcLandmark);
rcSmall = rcLarge;
rcSmall.bottom = rcLandmark.top;
}
if (0==bExpand)
{
//扩展对话框到最大尺寸
SetWindowPos(NULL, 0, 0, rcLarge.Width(), rcLarge.Height(),
SWP_NOMOVE | SWP_NOZORDER);
sExpand = "添加<<";
EnableVisibleChildren();
SetDlgItemText (IDC_ADDSORT, sExpand);
SetDlgItemText (IDC_CHECK, "添加");
m_check=true;
}
else if(1==bExpand)
{
//只显示对话框的上半部分
SetWindowPos(NULL, 0, 0, rcSmall.Width(), rcSmall.Height(),
SWP_NOMOVE | SWP_NOZORDER);
sExpand = "添加>>";
EnableVisibleChildren();
SetDlgItemText (IDC_ADDSORT, sExpand);
}
else if (2==bExpand)
{
//扩展对话框到最大尺寸
SetWindowPos(NULL, 0, 0, rcLarge.Width(), rcLarge.Height(),
SWP_NOMOVE | SWP_NOZORDER);
sExpand = "修改<<";
EnableVisibleChildren();
SetDlgItemText (IDC_MODIFYSORT, sExpand);
SetDlgItemText (IDC_CHECK, "修改");
m_check=false;
}
else if(3==bExpand)
{
//只显示对话框的上半部分
SetWindowPos(NULL, 0, 0, rcSmall.Width(), rcSmall.Height(),
SWP_NOMOVE | SWP_NOZORDER);
sExpand = "修改>>";
EnableVisibleChildren();
SetDlgItemText (IDC_MODIFYSORT, sExpand);
}
}
void CSortMag::EnableVisibleChildren()
{
//去掉没有显示的对话框的控件的功能和快捷键。
//得到第一个窗口
CWnd *pWndCtl = GetWindow (GW_CHILD);
CRect rcTest;
CRect rcControl;
CRect rcShow;
//得到对话框的完整矩形框
GetWindowRect(rcShow);
while (pWndCtl != NULL)
{ //得到当前显示的对话框的矩形尺寸
pWndCtl->GetWindowRect (rcControl);
if (rcTest.IntersectRect (rcShow, rcControl))
pWndCtl->EnableWindow(TRUE);
else
pWndCtl->EnableWindow(FALSE);
//得到第二个矩形框
pWndCtl = pWndCtl->GetWindow (GW_HWNDNEXT);
}
}
void CSortMag::OnAddsort()
{
// TODO: Add your control notification handler code here
if(!m_iseditopen)
{
if(1==bExpand)
{
bExpand=0;
ExpandDialog (IDC_EXPAND_LINE, bExpand);
m_isaddopen=true;
}
else if(0==bExpand)
{
bExpand=1;
ExpandDialog (IDC_EXPAND_LINE, bExpand);
m_isaddopen=false;
}
}
// bExpand = !bExpand;
}
void CSortMag::OnModifysort()
{
if(""==m_sortname&&!m_isaddopen)
MessageBox("请选择一条记录!");
if(!m_isaddopen&&""!=m_sortname)
{
// TODO: Add your control notification handler code here
if(2==bExpand2)
{
bExpand2=3;
ExpandDialog (IDC_EXPAND_LINE, bExpand2);
m_sortname="";
m_iseditopen=false;
}
else if(3==bExpand2)
{
bExpand2=2;
ExpandDialog (IDC_EXPAND_LINE, bExpand2);
UpdateData(false);
m_iseditopen=true;
}
/*char pathfrom[256];
char pathto[256];
// SHFILEOPSTRUCT frto;
memset(pathto,0,sizeof(pathto));
memset(pathfrom,0,sizeof(pathfrom));
// memset(&frto, 0, sizeof(frto));
strcpy(pathfrom,m_editSORT);
UpdateData();
strcpy(pathto,m_sortpath);
if(m_pSort.IsOpen())
m_pSort.Close();
m_pSort.Open();
m_pSort.m_PATH=m_sortpath;
m_pSort.m_SORT=m_sortname;*/
}
}
void CSortMag::OnClickTopiclistdlg(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
POSITION pos = m_topiclist.GetFirstSelectedItemPosition();
if(pos)
{
int nItem=m_topiclist.GetNextSelectedItem(pos);
m_sortname=m_topiclist.GetItemText(nItem,0);
m_sortpath=m_topiclist.GetItemText(nItem,1);
if(!m_check)
UpdateData(false);
}
*pResult = 0;
}
void CSortMag::OnCheck()
{
// TODO: Add your control notification handler code here
if(m_pSort.IsOpen())
m_pSort.Close();
m_pSort.Open();
if(m_check)
{
m_pSort.AddNew();
UpdateData(true);
m_pSort.m_SORT=m_sortname;
m_pSort.m_PATH=m_sortpath;
if(m_pSort.Update())
MessageBox("更新成功!");
m_sortname="";
m_sortpath="";
UpdateData(false);
}
else
{
if(m_pSort.IsOpen())
m_pSort.Close();
(m_pSort.m_strFilter).Format(_T("SORT='%s'"),m_sortname);
m_pSort.Open();
m_pSort.Edit();
UpdateData(true);
m_pSort.m_SORT=m_sortname;
m_pSort.m_PATH=m_sortpath;
if(m_pSort.Update())
MessageBox("修改成功!");
UpdateData(false);
}
m_topiclist.DeleteAllItems();
RushListctrl(&m_pSort,m_topiclist,"");
}
void CSortMag::OnDelete()
{
// TODO: Add your control notification handler code here
if(!m_sortname.IsEmpty())
{
if(m_pSort.IsOpen())
m_pSort.Close();
(m_pSort.m_strFilter).Format(_T("SORT='%s'"),m_sortname);
m_pSort.Open();//打开类别记录集
CDeletedoc dlg;
if(IDOK==dlg.DoModal())//确认删除
{
m_pSort.Delete();//删除记录
//m_pSort.Update();
if(m_pBook.IsOpen())
m_pBook.Close();
(m_pBook.m_strFilter).Format(_T("SORT='%s'"),m_sortname);
m_pBook.Open();//打开档案记录集
while(!m_pBook.IsEOF())
{
m_pBook.Edit();
m_pBook.m_SORT="未分类";
m_pBook.Update();//更新档案类别
m_pBook.MoveNext();
}
MessageBox("删除成功!");
}
m_sortname="";
m_pSort.Close();
m_pSort.m_strFilter="";
m_pSort.Open();
m_pBook.Close();
m_pBook.m_strFilter="";
m_pBook.Open();
}
else
MessageBox("请选择一条记录!");
m_topiclist.DeleteAllItems();
RushListctrl(&m_pSort,m_topiclist,"");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -