?? findiliquidate.cpp
字號:
// FindILiquidate.cpp : implementation file
//
#include "stdafx.h"
#include "FixedAssets.h"
#include "FindILiquidate.h"
#include "CRACK.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CFindILiquidate dialog
CFindILiquidate::CFindILiquidate(CWnd* pParent /*=NULL*/)
: CDialog(CFindILiquidate::IDD, pParent)
{
//{{AFX_DATA_INIT(CFindILiquidate)
m_strAssetID = _T("");
m_CKAssetID = FALSE;
m_CKCRType = FALSE;
m_CKDate = FALSE;
m_CKName = FALSE;
m_CKPerson = FALSE;
m_CKSort = FALSE;
m_CKType = FALSE;
m_Date1 = -1;
m_Date2 = -1;
m_strName = _T("");
m_strPerson = _T("");
m_strType = _T("");
//}}AFX_DATA_INIT
flag1=0;
flag2=0;
}
void CFindILiquidate::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CFindILiquidate)
DDX_Control(pDX, IDC_FDCR_TYPE, m_CtrlCBType);
DDX_Control(pDX, IDC_FDCR_SORT, m_CtrlCBSort);
DDX_Control(pDX, IDC_FDCR_PERSON, m_CtrlCBPerson);
DDX_Control(pDX, IDC_FDCR_NAME, m_CtrlCBName);
DDX_Control(pDX, IDC_FDCR_LIST, m_List);
DDX_Control(pDX, IDC_FDCR_CRTYPE, m_CtrlCBCRType);
DDX_Control(pDX, IDC_FDCR_ASSETID, m_CtrlCBAssetID);
DDX_CBString(pDX, IDC_FDCR_ASSETID, m_strAssetID);
DDX_Check(pDX, IDC_FDCR_CKASSETID, m_CKAssetID);
DDX_Check(pDX, IDC_FDCR_CKCRTYPE, m_CKCRType);
DDX_Check(pDX, IDC_FDCR_CKDATE, m_CKDate);
DDX_Check(pDX, IDC_FDCR_CKNAME, m_CKName);
DDX_Check(pDX, IDC_FDCR_CKPERSON, m_CKPerson);
DDX_Check(pDX, IDC_FDCR_CKSORT, m_CKSort);
DDX_Check(pDX, IDC_FDCR_CKTYPE, m_CKType);
DDX_DateTimeCtrl(pDX, IDC_FDCR_DATE1, m_Date1);
DDX_DateTimeCtrl(pDX, IDC_FDCR_DATE2, m_Date2);
DDX_CBString(pDX, IDC_FDCR_NAME, m_strName);
DDX_CBString(pDX, IDC_FDCR_PERSON, m_strPerson);
DDX_CBString(pDX, IDC_FDCR_TYPE, m_strType);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CFindILiquidate, CDialog)
//{{AFX_MSG_MAP(CFindILiquidate)
ON_BN_CLICKED(IDC_FDCR_CKNAME, OnFdcrCkname)
ON_BN_CLICKED(IDC_FDCR_CKSORT, OnFdcrCksort)
ON_BN_CLICKED(IDC_FDCR_CKASSETID, OnFdcrCkassetid)
ON_BN_CLICKED(IDC_FDCR_CKTYPE, OnFdcrCktype)
ON_BN_CLICKED(IDC_FDCR_CKDATE, OnFdcrCkdate)
ON_BN_CLICKED(IDC_FDCR_CKCRTYPE, OnFdcrCkcrtype)
ON_BN_CLICKED(IDC_FDCR_CKPERSON, OnFdcrCkperson)
ON_BN_CLICKED(IDC_FDCR_FIND, OnFdcrFind)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFindILiquidate message handlers
int CFindILiquidate::DoModal()
{
// TODO: Add your specialized code here and/or call the base class
return CDialog::DoModal();
}
BOOL CFindILiquidate::DestroyWindow()
{
// TODO: Add your specialized code here and/or call the base class
m_pDatabase->Close();
delete m_pDatabase;
m_pDatabase=NULL;
return CDialog::DestroyWindow();
}
BOOL CFindILiquidate::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
m_List.SetExtendedStyle(LVS_EX_GRIDLINES);
//連接數據庫
m_pDatabase=new CDaoDatabase;
try{
m_pDatabase->Open("FixedAssets");
m_pRecordset=new CDaoRecordset(m_pDatabase);
}
catch(CDaoException *e)
{
e->ReportError();
delete m_pDatabase;
m_pDatabase=NULL;
e->Delete();
}
if(!m_pDatabase->IsOpen()) return 0;
if(!m_pRecordset) return 0;
if(m_pRecordset->IsOpen()) m_pRecordset->Close();
CString strSelect;
try
{
// 資產類別
strSelect = _T("Select 資產類別ID,資產類別 From 資產類別");
m_pRecordset->Open(dbOpenDynaset,strSelect);
while (!m_pRecordset->IsEOF())
{
COleVariant var;
var = m_pRecordset->GetFieldValue(0);
m_uaSort.Add(var.lVal);
var = m_pRecordset->GetFieldValue(1);
m_saSort.Add(CCrack::strVARIANT(var));
m_pRecordset->MoveNext();
}
m_pRecordset->Close();
// 清理方式
strSelect = _T("Select 清理方式ID,清理方式 From 清理方式");
m_pRecordset->Open(dbOpenDynaset,strSelect);
while (!m_pRecordset->IsEOF())
{
COleVariant var;
var = m_pRecordset->GetFieldValue(0);
m_uaClear.Add(var.lVal);
var = m_pRecordset->GetFieldValue(1);
m_saClear.Add(CCrack::strVARIANT(var));
m_pRecordset->MoveNext();
}
m_pRecordset->Close();
// 清理人
strSelect = _T("Select DISTINCT 清理人 From 清理資產");
m_pRecordset->Open(dbOpenDynaset,strSelect);
while (!m_pRecordset->IsEOF())
{
COleVariant var;
var = m_pRecordset->GetFieldValue(0);
m_CtrlCBPerson.AddString(CCrack::strVARIANT(var));
m_pRecordset->MoveNext();
}
m_pRecordset->Close();
strSelect = _T("Select DISTINCT 資產名稱 From 資產信息");
m_pRecordset->Open(dbOpenDynaset,strSelect);
while (!m_pRecordset->IsEOF())
{
COleVariant var;
var = m_pRecordset->GetFieldValue(0);
m_CtrlCBName.AddString(CCrack::strVARIANT(var));
m_pRecordset->MoveNext();
}
m_pRecordset->Close();
strSelect = _T("Select DISTINCT 資產編號 From 資產信息");
m_pRecordset->Open(dbOpenDynaset,strSelect);
while (!m_pRecordset->IsEOF())
{
COleVariant var;
var = m_pRecordset->GetFieldValue(0);
m_CtrlCBAssetID.AddString(CCrack::strVARIANT(var));
m_pRecordset->MoveNext();
}
m_pRecordset->Close();
strSelect = _T("Select DISTINCT 型號 From 資產信息");
m_pRecordset->Open(dbOpenDynaset,strSelect);
while (!m_pRecordset->IsEOF())
{
COleVariant var;
var = m_pRecordset->GetFieldValue(0);
m_CtrlCBType.AddString(CCrack::strVARIANT(var));
m_pRecordset->MoveNext();
}
m_pRecordset->Close();
}
catch (CDaoException* e)
{
e->ReportError();
e->Delete();
return 0;
}
int nIndex,i;
for(i=0;i<m_saSort.GetSize();i++) //初始化類別
{
nIndex =m_CtrlCBSort.AddString(m_saSort.GetAt(i));
m_CtrlCBSort.SetItemData(nIndex, m_uaSort.GetAt(i));
}
for(i=0;i<m_saClear.GetSize();i++) //初始化 清除方式
{
nIndex =m_CtrlCBCRType.AddString(m_saClear.GetAt(i));
m_CtrlCBCRType.SetItemData(nIndex, m_uaClear.GetAt(i));
}
strSelect=_T("Select * From 清理資產");
Refresh(strSelect);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CFindILiquidate::Refresh(CString strSelect)//刷新
{
m_strTableName = _T("清理資產");
if(!m_pDatabase->IsOpen()) return;
if(!m_pRecordset) return;
if(m_pRecordset->IsOpen()) m_pRecordset->Close();
//清空list控件
m_List.DeleteAllItems();
while(m_List.DeleteColumn(0));
CDaoFieldInfo fieldInfo;
int nFields;
CDaoTableDef td(m_pDatabase);
try
{
td.Open(m_strTableName);
nFields = td.GetFieldCount();
int nWidth;
for (int j=0; j < nFields; j++)
{
td.GetFieldInfo(j,fieldInfo);
nWidth = m_List.GetStringWidth(fieldInfo.m_strName) + 15;
if(j>=2)
m_List.InsertColumn(j+2,fieldInfo.m_strName, LVCFMT_LEFT, nWidth);
else
m_List.InsertColumn(j,fieldInfo.m_strName, LVCFMT_LEFT, nWidth);
}
nWidth=100;
m_List.InsertColumn(2,"資產編號", LVCFMT_LEFT, nWidth);
m_List.InsertColumn(3,"資產名稱", LVCFMT_LEFT, nWidth);
}
catch (CDaoException* e)
{
e->ReportError();
e->Delete();
return;
}
td.Close();
int nItem = 0,i;
try
{
CString select;
m_pRecordset->Open(dbOpenDynaset,strSelect);
while (!m_pRecordset->IsEOF())
{
COleVariant var;
//判斷清理時間是否在用戶規定的時間內
if(m_CKDate) //清理日期
{
if(m_Date1>m_Date2)
{
CTime temp;
temp=m_Date1;m_Date1=m_Date2;m_Date2=temp;
}
var = m_pRecordset->GetFieldValue(4);
CString year,month,day,str;
str=CCrack::strVARIANT(var);
if(str.GetAt(6)=='0')
year.Format("20%c%c",str.GetAt(6),str.GetAt(7));
else
year.Format("19%c%c",str.GetAt(6),str.GetAt(7));
month.Format("%c%c",str.GetAt(0),str.GetAt(1));
day.Format("%c%c",str.GetAt(3),str.GetAt(4));
CTime time(atoi(year),atoi(month),atoi(day),m_Date1.GetHour(),m_Date1.GetMinute(),m_Date1.GetSecond());
if(time<m_Date1||time>m_Date2)
{
m_pRecordset->MoveNext();
continue;
}
}
var = m_pRecordset->GetFieldValue(0);
m_List.InsertItem(nItem,CCrack::strVARIANT(var));
for (i=0; i < nFields; i++)
{
var = m_pRecordset->GetFieldValue(i);
if(i<=1)
m_List.SetItemText( nItem,i,CCrack::strVARIANT(var));
if(i==3)
{
int j;
bool flag=0;
for(j=0;j<m_uaClear.GetSize();j++)
{
if(m_uaClear[j]==unsigned(atoi(CCrack::strVARIANT(var))))
{
flag=1;
break;
}
}
if(flag)
m_List.SetItemText( nItem,i+2,m_saClear[j]);
else
m_List.SetItemText( nItem,i+2,"!!刪除!!");
}
if(i>=2&&i!=3)
{
m_List.SetItemText( nItem,i+2,CCrack::strVARIANT(var));
}
}
CDaoRecordset *m_pSet;
m_pSet=new CDaoRecordset(m_pDatabase);
var = m_pRecordset->GetFieldValue(1);
select.Format("select 資產編號,資產名稱 from 資產信息 where 資產ID=%d",atoi(CCrack::strVARIANT(var)));
try{
m_pSet->Open(dbOpenDynaset,select);
var = m_pSet->GetFieldValue(0);
m_List.SetItemText( nItem,2,CCrack::strVARIANT(var));
var = m_pSet->GetFieldValue(1);
m_List.SetItemText( nItem,3,CCrack::strVARIANT(var));
m_pSet->Close();
}
catch(CDaoException* e){
m_List.SetItemText( nItem,2,"該項已刪除");
m_List.SetItemText( nItem,3,"該項已刪除");
e->Delete();}
m_pRecordset->MoveNext();
nItem++;
}
}
catch (CDaoException* e)
{
e->ReportError();
e->Delete();
return;
}
}
void CFindILiquidate::OnFdcrCkname()
{
UpdateData(1);
if(!m_CKName)
{
m_strName.Empty();
UpdateData(0);
(CComboBox*)GetDlgItem(IDC_FDCR_NAME)->EnableWindow(0);
}
else
{
(CComboBox*)GetDlgItem(IDC_FDCR_NAME)->EnableWindow(1);
}
}
void CFindILiquidate::OnFdcrCksort()
{
// TODO: Add your control notification handler code here
UpdateData(1);
if(!m_CKSort)
{
m_CtrlCBSort.SetCurSel(-1);
UpdateData(0);
(CComboBox*)GetDlgItem(IDC_FDCR_SORT)->EnableWindow(0);
}
else
{
(CComboBox*)GetDlgItem(IDC_FDCR_SORT)->EnableWindow(1);
}
}
void CFindILiquidate::OnFdcrCkassetid()
{
// TODO: Add your control notification handler code here
UpdateData(1);
if(!m_CKAssetID)
{
m_strAssetID.Empty();
UpdateData(0);
(CComboBox*)GetDlgItem(IDC_FDCR_ASSETID)->EnableWindow(0);
}
else
{
(CComboBox*)GetDlgItem(IDC_FDCR_ASSETID)->EnableWindow(1);
}
}
void CFindILiquidate::OnFdcrCktype()
{
// TODO: Add your control notification handler code here
UpdateData(1);
if(!m_CKType)
{
m_strType.Empty();
UpdateData(0);
(CComboBox*)GetDlgItem(IDC_FDCR_TYPE)->EnableWindow(0);
}
else
{
(CComboBox*)GetDlgItem(IDC_FDCR_TYPE)->EnableWindow(1);
}
}
void CFindILiquidate::OnFdcrCkdate()
{
// TODO: Add your control notification handler code here
UpdateData(1);
if(!m_CKDate)
{
m_Date1=CTime::GetCurrentTime();
m_Date2=CTime::GetCurrentTime();
UpdateData(0);
(CComboBox*)GetDlgItem(IDC_FDCR_DATE1)->EnableWindow(0);
(CComboBox*)GetDlgItem(IDC_FDCR_DATE2)->EnableWindow(0);
}
else
{
(CComboBox*)GetDlgItem(IDC_FDCR_DATE1)->EnableWindow(1);
(CComboBox*)GetDlgItem(IDC_FDCR_DATE2)->EnableWindow(1);
}
}
void CFindILiquidate::OnFdcrCkcrtype()
{
// TODO: Add your control notification handler code here
UpdateData(1);
if(!m_CKCRType)
{
m_CtrlCBCRType.SetCurSel(-1);
UpdateData(0);
(CComboBox*)GetDlgItem(IDC_FDCR_CRTYPE)->EnableWindow(0);
}
else
{
(CComboBox*)GetDlgItem(IDC_FDCR_CRTYPE)->EnableWindow(1);
}
}
void CFindILiquidate::OnFdcrCkperson()
{
// TODO: Add your control notification handler code here
UpdateData(1);
if(!m_CKPerson)
{
m_strPerson.Empty();
UpdateData(0);
(CComboBox*)GetDlgItem(IDC_FDCR_PERSON)->EnableWindow(0);
}
else
{
(CComboBox*)GetDlgItem(IDC_FDCR_PERSON)->EnableWindow(1);
}
}
void CFindILiquidate::OnFdcrFind()
{
UpdateData(1);
if(!m_pDatabase->IsOpen()) return;
if(!m_pRecordset) return;
if(m_pRecordset->IsOpen()) m_pRecordset->Close();
CString sql,strSql="select * from 清理資產";
if(m_CKPerson)
{
if(m_strPerson.IsEmpty()==0)
{
sql.Format(" where 清理人 like '%s'",m_strPerson);
strSql+=sql;
flag1=1;
}
}
if(m_CKCRType)
{
if(m_CtrlCBCRType.GetCurSel()!=-1)
{
if(flag1)
sql.Format(" and 清理方式ID like %d",m_CtrlCBCRType.GetItemData(m_CtrlCBCRType.GetCurSel()));
else
sql.Format(" where 清理方式ID like %d",m_CtrlCBCRType.GetItemData(m_CtrlCBCRType.GetCurSel()));
strSql+=sql;
flag1=1;
}
}
if(m_CKName||m_CKSort||m_CKType||m_CKAssetID)
{
if(flag1)
sql.Format(" and 資產ID in (select 資產ID from 資產信息");
else
sql.Format(" where 資產ID in (select 資產ID from 資產信息");
strSql+=sql;
if(m_CKName)
{
if(m_strName.IsEmpty()==0)
{
sql.Format( " where 資產名稱= '%s'",m_strName );
flag2=1;
strSql+=sql;
}
}
if(m_CKAssetID)
{
if(m_strAssetID.IsEmpty()==0)
{
if(flag2)
sql.Format( " and 資產編號 ='%s'",m_strAssetID );
else
sql.Format( " where 資產編號= '%s'",m_strAssetID );
flag2=1;
strSql+=sql;
}
}
if(m_CKType)
{
if(m_strType.IsEmpty()==0)
{
if(flag2)
sql.Format( " and 型號 = '%s'",m_strType );
else
sql.Format( " where 型號= '%s'",m_strType );
flag2=1;
strSql+=sql;
}
}
if(m_CKSort)
{
if(m_CtrlCBSort.GetCurSel()!=-1)
{
if(flag2)
sql.Format( " and 資產類別ID=%d",m_CtrlCBSort.GetItemData(m_CtrlCBSort.GetCurSel()) );
else
sql.Format( " where 資產類別ID=%d",m_CtrlCBSort.GetItemData(m_CtrlCBSort.GetCurSel()) );
flag2=1;
strSql+=sql;
}
}
sql=")";
strSql+=sql;
}
flag1=0;
flag2=0;
Refresh(strSql);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -