softdelete.cpp
来自「偶作的毕业设计程序」· C++ 代码 · 共 409 行
CPP
409 行
// SoftDelete.cpp : implementation file
//
#include "stdafx.h"
#include "SoftDocSystem.h"
#include "SoftDelete.h"
#include "LogMngr.h"
#include "PublicQuery.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSoftDelete dialog
CSoftDelete::CSoftDelete(CWnd* pParent /*=NULL*/)
: CDialog(CSoftDelete::IDD, pParent)
{
//{{AFX_DATA_INIT(CSoftDelete)
m_Xinghao = _T("");
m_Author = _T("");
m_Number = _T("");
m_SoftName = _T("");
m_GeShi = _T("");
m_SoftType = _T("");
//}}AFX_DATA_INIT
}
void CSoftDelete::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSoftDelete)
DDX_Control(pDX, IDC_LIST1, m_List);
DDX_Control(pDX, IDC_COMBO5, m_NumberCtrl);
DDX_Control(pDX, IDC_COMBO8, m_TypeCtrl);
DDX_Control(pDX, IDC_COMBO4, m_FormatCtrl);
DDX_Control(pDX, IDC_COMBO3, m_AuthorCtrl);
DDX_Control(pDX, IDC_COMBO2, m_XinghaoCtrl);
DDX_Control(pDX, IDC_COMBO1, m_NameCtrl);
DDX_CBString(pDX, IDC_COMBO2, m_Xinghao);
DDX_CBString(pDX, IDC_COMBO3, m_Author);
DDX_CBString(pDX, IDC_COMBO5, m_Number);
DDX_CBString(pDX, IDC_COMBO1, m_SoftName);
DDX_CBString(pDX, IDC_COMBO4, m_GeShi);
DDX_CBString(pDX, IDC_COMBO8, m_SoftType);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSoftDelete, CDialog)
//{{AFX_MSG_MAP(CSoftDelete)
ON_BN_CLICKED(IDOK, OnStartQuery)
ON_BN_CLICKED(IDC_BUTTON1, OnQuery)
ON_NOTIFY(NM_DBLCLK, IDC_LIST1, OnDblclkList1)
ON_WM_DESTROY()
ON_BN_CLICKED(IDC_BUTTON3, OnDelTotal)
ON_BN_CLICKED(IDC_BUTTON4, OnUndo)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSoftDelete message handlers
void CSoftDelete::OnStartQuery()
{
// TODO: Add your control notification handler code here
}
void CSoftDelete::OnCancel()
{
// TODO: Add extra cleanup here
DelRemain();
CDialog::OnCancel();
}
BOOL CSoftDelete::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
//改变字体
LOGFONT LogFont;
(CFont*)CWnd::GetFont()->GetLogFont(&LogFont);
strcpy(LogFont.lfFaceName,"华文彩云");
LogFont.lfHeight=LogFont.lfHeight*3;
LogFont.lfWidth=LogFont.lfWidth*3;
m_font.CreateFontIndirect(&LogFont);
GetDlgItem(IDC_HEADLINE)->SetFont(&m_font,true);
//初始化列抱框
InitList();
//连接数据库
CSoftDocSystemApp* myApp=(CSoftDocSystemApp*)AfxGetApp();
CString source_;
source_.Format ("driver={SQL Server};server=%s;database=SoftDocument",myApp->ConnectServer);
_bstr_t source=source_;
_bstr_t pwd=myApp->ConnectPwd;
_bstr_t user=myApp->ConnectUser;
HRESULT hr;
try{
hr = m_DBCnt.CreateInstance(_uuidof(Connection));
if(SUCCEEDED(hr))
hr = m_DBCnt->Open(source, user, pwd, 16);
if(SUCCEEDED(hr))
{m_fConnected = TRUE;
}
else
m_fConnected = FALSE;
}
catch (_com_error &e){
MessageBox(e.ErrorMessage());
m_fConnected = FALSE;
}
if(!m_fConnected)
{MessageBox("ADO数据源初始化失败!");
return false;}
else
m_strSource = (char * )source;
m_DelSum=0;
b[1]=b[2]=b[3]=b[0]=b[4]=b[5]=b[6]=0;
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CSoftDelete::OnQuery()
{
// TODO: Add your control notification handler code here
UpdateData();
CString sql_,str2,str;
_RecordsetPtr Myset;
_variant_t Holder;
CString geshi[6];
geshi[1]="软盘";
geshi[2]="光盘";
geshi[4]="文本";
geshi[3]="硬盘";
geshi[5]="其他";
if(((CButton*)GetDlgItem(IDC_CHECK7))->GetCheck())//如果是全选
sql_.Format("select * from SoftDocInfo");
else{
int SQLId=0;
sql_="select * from SoftDocInfo where";
m_SoftName.TrimRight(" ");
m_Xinghao.TrimRight (" ");
m_SoftType.TrimRight (" ");
if(!m_SoftType.IsEmpty ()){
str.Format (" 软件类型 ='%s'",m_SoftType);
sql_+=str;
SQLId=1;}
if(!m_SoftName.IsEmpty ()){
if(SQLId==1)
str.Format (" and 软件名称 ='%s'", m_SoftName);
else
str.Format (" 软件名称 ='%s'", m_SoftName);
sql_+=str;
SQLId=1;}
if(!m_Xinghao.IsEmpty ()){
if(SQLId==1)
str.Format (" and 所属型号 ='%s'",m_Xinghao);
else
str.Format (" 所属型号 ='%s'",m_Xinghao);
sql_+=str;
SQLId=1;}
if(!m_Author.IsEmpty ()){
if(SQLId==1)
str.Format(" and 作者 = '%s'",m_Author);
else
str.Format(" 作者 = '%s'",m_Author);
sql_+=str;
SQLId=1;}
if(!m_Number.IsEmpty ()){
if(SQLId==1)
str.Format (" or 软件编号 ='%s'",m_Number);
else
str.Format (" 软件编号 ='%s'",m_Number);
sql_+=str;
SQLId=1;}
if(SQLId==0)
{AfxMessageBox("你没有输入查询信息!");return;}
}
Myset.CreateInstance (__uuidof(Recordset));//查找所需软件文档
_bstr_t Mysql=sql_;
_bstr_t source=m_strSource;
m_List.DeleteAllItems ();
m_List.SetRedraw (false);
try{
Myset->Open (Mysql,source,adOpenDynamic,adLockOptimistic,adCmdText);
}
catch(_com_error &e){
AfxMessageBox(e.ErrorMessage());return;}
int Shumu=0;
while(!Myset->adoEOF)//记录数
{Shumu+=1;
Myset->MoveNext ();}
if(Shumu<1)return;
Myset->MoveFirst ();
int i=0;
int j=0;
CString mystr;
CString softnumber,softname,softauthor,softxinghao,softxitong,softtype,softgeshi,softfunction,softdate;
while(!Myset->adoEOF ){
//每一入库格式一行
Holder=Myset->GetCollect ("软件名称");
if(Holder.vt!=VT_NULL)
{softname=(char*)(_bstr_t)Holder;
softname.TrimRight(" ");}
else
softname="未知名称";
Holder=Myset->GetCollect ("软件编号");
if(Holder.vt!=VT_NULL)
{softnumber=(char*)(_bstr_t)Holder;
softnumber.TrimRight(" ");}
else
softnumber="未知编号";
Holder=Myset->GetCollect ("所属型号");
if(Holder.vt!=VT_NULL)
{softxinghao=(char*)(_bstr_t)Holder;
softxinghao.TrimRight(" ");}
else
softxinghao="未知型号";
Holder=Myset->GetCollect ("作者");
if(Holder.vt!=VT_NULL)
{softauthor=(char*)(_bstr_t)Holder;
softauthor.TrimRight(" ");}
else
softauthor="未知作者";
Holder=Myset->GetCollect ("软件类型");
if(Holder.vt!=VT_NULL)
{softtype=(char*)(_bstr_t)Holder;
softtype.TrimRight(" ");}
else
softtype="未知类型";
Holder=Myset->GetCollect ("所属系统");
if(Holder.vt!=VT_NULL)
{softxitong=(char*)(_bstr_t)Holder;
softxitong.TrimRight(" ");}
else
softxitong="未知系统";
Holder=Myset->GetCollect ("软件功能描述");
if(Holder.vt!=VT_NULL)
{softfunction=(char*)(_bstr_t)Holder;
softfunction.TrimRight(" ");}
else
softfunction="未知功能";
//判断格式
for(int i=1;i<6;i++)
{ _variant_t strgeshi=geshi[i];
Holder=Myset->GetCollect (strgeshi);
if(Holder.vt!=VT_NULL)
{mystr=(char*)(_bstr_t)Holder;
mystr.TrimRight(" ");
if(mystr=="在家"){//已借出的不能作废
m_List.InsertItem (j,softname);
m_List.SetItemText (j,1,softxinghao);
m_List.SetItemText (j,2,softauthor);
m_List.SetItemText (j,3,softtype);
m_List.SetItemText (j,4,geshi[i]);
m_List.SetItemText (j,5,softnumber);
m_List.SetItemText (j,6,softxitong);
m_List.SetItemText (j,7,softfunction);
j++;}
}
}Myset->MoveNext();}
m_List.SetRedraw(true);
// if(m_Log.Setup (m_DBCnt))m_Log.Addlog ("访问者","登录","未知");//操作日志
}
void CSoftDelete::InitList()
{
m_List.InsertColumn (0,"软件名称");
m_List.InsertColumn (1,"所属型号");
m_List.InsertColumn (2,"作者");
m_List.InsertColumn (3,"软件类型");
m_List.InsertColumn (4,"格式");
m_List.InsertColumn (5,"软件编号");
m_List.InsertColumn (6,"所属型号");
m_List.InsertColumn (7,"所属系统");
m_List.InsertColumn (8,"软件功能描述");
RECT rect;
m_List.GetWindowRect(& rect);
int wid=(rect.right -rect.left );
m_List.SetColumnWidth(0,wid/8);
m_List.SetColumnWidth(1,wid/5);
m_List.SetColumnWidth(2,wid/10);
m_List.SetColumnWidth(3,wid/5);
m_List.SetColumnWidth(4,wid/4);
m_List.SetExtendedStyle (LVS_EX_FULLROWSELECT);
}
void CSoftDelete::OnDblclkList1(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
int choice=AfxMessageBox("你将删除这条记录,确定吗?",MB_OKCANCEL|MB_ICONEXCLAMATION);
if(choice==IDOK){OnDel();}
*pResult = 0;
}
void CSoftDelete::OnDel()
{
int i,j;
if(m_DelSum==3)
DelFirst();//删除最先第一个记录
int n=(m_DelSum==3)?1:m_DelSum+1;
int m=b[n]*10;//本条记录应该保存的位置
i=m_List.GetSelectionMark ();
for(j=0;j<9;j++)
a[m+j]=m_List.GetItemText (i,j);//保存数据
m_List.DeleteItem (i);
int NowNumber=m_DelSum;
m_DelSum=(m_DelSum==3)?3:m_DelSum+1;//保存删除的记录数
if(NowNumber<3)b[NowNumber+1]=NowNumber;
else
{b[m_DelSum]=b[n];
for(j=1;j<m_DelSum+1;j++)//保存删除的顺序
b[j-1]=b[j];}
}
void CSoftDelete::DelFirst()
{
CString sql_,ApplyNumber,strGeshi;
ApplyNumber=a[b[1]*10+5];
strGeshi=a[b[1]*10+4];
int c=b[1]*10;
sql_.Format ("update SoftDocInfo set %s = '无' where 软件编号 ='%s'",strGeshi,ApplyNumber);
_bstr_t sql=sql_;
try{
m_DBCnt->Execute(sql,NULL,adCmdText);}
catch(_com_error &e){
AfxMessageBox(e.ErrorMessage ());return;
}
CTime tm=CTime::GetCurrentTime ();//作废记录登记
CString DiscardNumber,DiscardDate;
DiscardDate.Format ("%d-%d-%d %d:%d",tm.GetYear(),tm.GetMonth (),tm.GetDay(),tm.GetHour(),tm.GetMinute());
DiscardNumber.Format("CH%d%02d%02d%02d%02d%d",tm.GetYear (),tm.GetMonth (),tm.GetDay(),tm.GetHour(),tm.GetMinute(),tm.GetSecond());
sql_.Format("insert into DiscardSoft(作废编号,软件名称,所属型号,作者,软件类型,格式,软件编号,所属系统,软件功能描述,作废时间) values('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')",
DiscardNumber,a[c],a[c+1],a[c+2],a[c+3],a[c+4],a[c+5],a[c+6],a[c+7],DiscardDate);
try{
m_DBCnt->Execute(sql,NULL,adCmdText);}
catch(_com_error &e){
AfxMessageBox(e.ErrorMessage ());return;
}
}
void CSoftDelete::DelRemain()
{
CString sql_,ApplyNumber,strGeshi;
for(int i=1;i<m_DelSum+1;i++){
int c=b[i]*10;
ApplyNumber=a[c+5];
strGeshi=a[c+4];
sql_.Format ("update SoftDocInfo set %s = '无' where 软件编号 ='%s'",strGeshi,ApplyNumber);
_bstr_t sql=sql_;
try{
m_DBCnt->Execute(sql,NULL,adCmdText);}//删除记录
catch(_com_error &e){
AfxMessageBox(e.ErrorMessage ());return;
}
CTime tm=CTime::GetCurrentTime ();//作废记录登记
CString DiscardNumber,DiscardDate;
DiscardDate.Format ("%d-%d-%d-%d-%d",tm.GetYear(),tm.GetMonth (),tm.GetDay(),tm.GetHour(),tm.GetMinute());
DiscardNumber.Format("CH%d%02d%02d%02d%02d%d",tm.GetYear (),tm.GetMonth (),tm.GetDay(),tm.GetHour(),tm.GetMinute(),tm.GetSecond());
sql_.Format("insert into DiscardSoft(作废编号,软件名称,所属型号,作者,软件类型,格式,软件编号,所属系统,软件功能描述,作废时间) values('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')",
DiscardNumber,a[c],a[c+1],a[c+2],a[c+3],a[c+4],a[c+5],a[c+6],a[c+7],DiscardDate);
try{
m_DBCnt->Execute(sql,NULL,adCmdText);}
catch(_com_error &e){
AfxMessageBox(e.ErrorMessage ());return;
}
}
m_DelSum=0;
}
void CSoftDelete::OnDestroy()
{
CDialog::OnDestroy();
DelRemain();
if(m_DBCnt->GetState()==adStateOpen)m_DBCnt->Close();
// TODO: Add your message handler code here
}
void CSoftDelete::OnDelTotal()
{
//int m=m_List.GetItemCount();//所有记录
CPublicQuery dlg;
this->ShowWindow(SW_HIDE);
dlg.DoModal ();
this->ShowWindow (SW_SHOW);
}
void CSoftDelete::OnUndo()
{
// TODO: Add your control notification handler code here
int i,j=m_List.GetSelectionMark ();
if(m_DelSum>0){
int NowNumber=10*b[m_DelSum];
m_List.InsertItem (j,a[NowNumber]);
for(i=0;i<9;i++)
m_List.SetItemText (j,i,a[NowNumber+i]);
m_DelSum-=1;}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?