📄 assetenrolview.cpp
字号:
}
//如果用户选择的是空
else if(m_list.GetCurSel()<0 || m_list.GetCurSel() > m_list.GetCount())
{
m_list.SetCurSel(0);
}
int nID=MessageBox("确实要删除选定项吗?","提示~",IDOK);
if(nID==IDCANCEL)
{
return;
}
//记录移到第一个
m_pRecordset->MoveFirst();
//记录移到选定的项
m_pRecordset->Move(m_list.GetCurSel());
m_pRecordset->Delete(adAffectCurrent); //删除当前行记录
m_pRecordset->Update(); //更新列表
//获取选定项的下标
int nCurSel=m_list.GetCurSel();
//在列表中将选定项的内容删除
m_list.DeleteString(nCurSel);
//如果选择的是第一项进行删除
//并且还是选择第一列列表框串
if(nCurSel==0 && (m_list.GetCount()!=0))
{
m_list.SetCurSel(nCurSel);
}
//否则蓝色显示 会计电算化,,计算机二级证部分应该上移一个位置
else if(m_list.GetCount()!=0)
{
m_list.SetCurSel(nCurSel-1);
}
m_list.Invalidate();
this->UpdateWindow(); //更新对话框
}
void CAssetEnrolView::OnQuery()
{
// add...
extern CAssetEnrolApp theApp;
extern CString queryName;
_variant_t var;
//是否有找到记录
BOOL IsFind=FALSE;
CString name;
//符合条件的记录的位置
recordPos=0;
UpdateData(); //更新数据库
UpdateData(TRUE);
if(IsQuery!=TRUE)
{
queryName=m_Name;
name=m_Name;
}
//只有先按下“查询”按钮才可以进行下一个查询
IsQuery=TRUE;
//创建一个数据库连接
m_pRecordset.CreateInstance(__uuidof(Recordset));
if(m_Name=="")
{
AfxMessageBox("信息不完整! \n\n请输入品名 ");
return;
}
try
{
//打开AssetEnrol表(所有字段)
m_pRecordset->Open("SELECT * FROM AssetEnrol",theApp.m_pConnection.GetInterfacePtr(), adOpenDynamic, adLockOptimistic,adCmdText);
//m_list.ResetContent(); //清空列表
//OnRead();
m_pRecordset->MoveFirst();
//使用循环检索出所有匹配的第一个记录
while(!m_pRecordset->adoEOF && IsFind==FALSE)
{
recordPos++;
var=m_pRecordset->GetCollect("Name");
if(var.vt!=VT_NULL)
{
//如果有相匹配
//则将匹配项蓝色亮显
name=(LPCSTR)_bstr_t(var);
if(name.Find(m_Name)>=0)
{
//OnRead();
//OnSelchangeList1();
var=m_pRecordset->GetCollect("Unit");
if(var.vt!=VT_NULL)
m_Unit=(LPCSTR)_bstr_t(var);
var=m_pRecordset->GetCollect("Year");
if(var.vt!=VT_NULL)
m_Year=(LPCSTR)_bstr_t(var);
var=m_pRecordset->GetCollect("Month");
if(var.vt!=VT_NULL)
m_Month=(LPCSTR)_bstr_t(var);
var=m_pRecordset->GetCollect("Day");
if(var.vt!=VT_NULL)
m_Day=(LPCSTR)_bstr_t(var);
var=m_pRecordset->GetCollect("SerialNo");
if(var.vt!=VT_NULL)
m_SerialNo=(LPCSTR)_bstr_t(var);
var=m_pRecordset->GetCollect("Number");
if(var.vt!=VT_NULL)
m_Number=(LPCSTR)_bstr_t(var);
var=m_pRecordset->GetCollect("Value");
if(var.vt!=VT_NULL)
m_Value=(LPCSTR)_bstr_t(var);
else
m_Value="";
var=m_pRecordset->GetCollect("Custodian");
if(var.vt!=VT_NULL)
m_Custodian=(LPCSTR)_bstr_t(var);
var=m_pRecordset->GetCollect("Property");
if(var.vt!=VT_NULL)
m_Property=(LPCSTR)_bstr_t(var);
IsFind=TRUE; //是否有找到标志为:真 (退出)
//确保是第一个查到的记录可以显示出来
recordPos--;
m_list.SetTopIndex(recordPos);
m_list.SetCurSel(recordPos);
}
}
m_pRecordset->MoveNext();
}
if(IsFind==FALSE)
{
AfxMessageBox("没有找到任何记录!");
m_Name="";
UpdateData(FALSE);
return;
}
//使列表框无效
//m_listctrl.EnableWindow(FALSE);
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
}
m_Name=name;
//m_Unit=unit;
//将查询条件存放起来,便于进行下一个查询
strQuery=name;
UpdateData(FALSE);
}
void CAssetEnrolView::OnNext()
{
// add...
extern CAssetEnrolApp theApp;
extern CString queryName;
_variant_t var;
//是否有找到记录
BOOL IsFind=FALSE;
CString name;
UpdateData(); //更新数据库
UpdateData(TRUE);
//还没有按查询按钮
if(IsQuery==FALSE)
{
AfxMessageBox("没有按查询按钮\n\n或者根本就没有匹配记录!");
return;
}
//创建一个数据库连接
m_pRecordset.CreateInstance(__uuidof(Recordset));
//打开AssetEnrol表(所有字段)
m_pRecordset->Open("SELECT * FROM AssetEnrol",theApp.m_pConnection.GetInterfacePtr(), adOpenDynamic, adLockOptimistic,adCmdText);
m_pRecordset->MoveFirst();
//将指针移向上一个找到的记录的下一个记录
m_pRecordset->Move(recordPos+1);
//使用循环检索出所有匹配的第一个记录
while(!m_pRecordset->adoEOF && IsFind==FALSE)
{
recordPos++;
var=m_pRecordset->GetCollect("Name");
if(var.vt!=VT_NULL)
{
//如果有相匹配
//则将匹配项蓝色亮显
name=(LPCSTR)_bstr_t(var);
if(name.Find(queryName)>=0)
{
var=m_pRecordset->GetCollect("Unit");
if(var.vt!=VT_NULL)
m_Unit=(LPCSTR)_bstr_t(var);
var=m_pRecordset->GetCollect("Year");
if(var.vt!=VT_NULL)
m_Year=(LPCSTR)_bstr_t(var);
var=m_pRecordset->GetCollect("Month");
if(var.vt!=VT_NULL)
m_Month=(LPCSTR)_bstr_t(var);
var=m_pRecordset->GetCollect("Day");
if(var.vt!=VT_NULL)
m_Day=(LPCSTR)_bstr_t(var);
var=m_pRecordset->GetCollect("SerialNo");
if(var.vt!=VT_NULL)
m_SerialNo=(LPCSTR)_bstr_t(var);
var=m_pRecordset->GetCollect("Number");
if(var.vt!=VT_NULL)
m_Number=(LPCSTR)_bstr_t(var);
var=m_pRecordset->GetCollect("Value");
if(var.vt!=VT_NULL)
m_Value=(LPCSTR)_bstr_t(var);
else
m_Value="";
var=m_pRecordset->GetCollect("Custodian");
if(var.vt!=VT_NULL)
m_Custodian=(LPCSTR)_bstr_t(var);
var=m_pRecordset->GetCollect("Property");
if(var.vt!=VT_NULL)
m_Property=(LPCSTR)_bstr_t(var);
IsFind=TRUE; //是否有找到标志为:真 (退出)
//确保是第一个查到的记录可以显示出来
m_list.SetTopIndex(recordPos);
m_list.SetCurSel(recordPos);
}
}
m_pRecordset->MoveNext();
}
if(IsFind==FALSE)
{
AfxMessageBox("找不到匹配的记录!");
UpdateData(FALSE);
return;
}
UpdateData(FALSE);
}
void CAssetEnrolView::OnClearitem()
{
// add...
m_SerialNo=m_Name=m_Unit
=m_Number=m_Value=m_Custodian=m_Property="";
UpdateData(FALSE);
}
void CAssetEnrolView::OnCleartable()
{
// add...
// add...
extern CAssetEnrolApp theApp;
UpdateData();
int nID=MessageBox("一旦清空,数据将不可恢复...\n\n确实要删除数据库中所有选项吗?\n","警告!",IDOK);
if(nID==IDCANCEL)
{
return;
}
m_Year=m_Month=m_Day
=m_SerialNo=m_Name=m_Unit
=m_Number=m_Value=m_Custodian=m_Property="";
//创建一个数据库连接
m_pRecordset.CreateInstance(__uuidof(Recordset));
//打开AssetEnrol表(所有字段)
m_pRecordset->Open("SELECT * FROM AssetEnrol",theApp.m_pConnection.GetInterfacePtr(),
adOpenDynamic, adLockOptimistic,adCmdText);
if(!m_pRecordset->BOF)
m_pRecordset->MoveFirst();
else
{
AfxMessageBox("表内数据为空!");
return;
}
while(!m_pRecordset->adoEOF)
{
m_pRecordset->Delete(adAffectCurrent); //删除当前行记录
m_pRecordset->Update(); //更新列表
m_pRecordset->MoveNext();
}
OnRead();
UpdateData(FALSE);
}
BOOL CAssetEnrolView::DestroyWindow()
{
// TODO: Add your specialized code here and/or call the base class
return CFormView::DestroyWindow();
}
void CAssetEnrolView::OnClose()
{
// TODO: Add your message handler code here and/or call default
CFormView::OnClose();
}
void CAssetEnrolView::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView)
{
// add...
if(IsOne==TRUE)
{
UpdateData(TRUE);
CTime m_CurTime = CTime::GetCurrentTime();
m_CurTime.GetYear();
char m_str[20];
itoa(m_CurTime.GetYear(),m_str,10);
m_Year = m_str;
itoa(m_CurTime.GetMonth(),m_str,10);
m_Month = m_str;
//为了便于链表的按日期和时间排序显示
if(m_Month.GetLength()!=2)
{
CString Month;
Month.Format("%s",m_Day);;
m_Month="0"+m_Month;
}
itoa(m_CurTime.GetDay(),m_str,10);
m_Day = m_str;
//为了便于链表的按日期和时间排序显示
if(m_Day.GetLength()!=2)
{
CString Day;
Day.Format("%s",m_Day);;
m_Day="0"+m_Day;
}
IsOne=FALSE;
CRect rc;
m_Combox.GetWindowRect(&rc);
ScreenToClient(&rc);
m_Combox.MoveWindow(rc.left,rc.top,rc.Width(),rc.Height()*3);
m_Combox.AddString("否");
m_Combox.AddString("是");
m_Combox.SelectString(0,"否");
UpdateData(FALSE);
}
//CFormView::OnActivateView(bActivate, pActivateView, pDeactiveView);
}
void CAssetEnrolView::OnAsset()
{
// add...
extern CAssetEnrolApp theApp;
extern BOOL asset;
_variant_t var;
CString strYear;
CString strMonth;
CString strDay;
CString strSerialNo;
CString strName;
CString strNumber;
CString strUnit;
CString strValue;
CString strCustodian;
CString strProperty;
CString strIsFixed;
asset=TRUE;
UpdateData(TRUE);
//清空列表
m_list.ResetContent();
//创建一个数据库连接
m_pRecordset.CreateInstance(__uuidof(Recordset));
try
{
// 第一个参数:查询student表中所有字段
// 第二个参数:获取库接库的IDispatch指针
m_pRecordset->Open("SELECT * FROM AssetEnrol",theApp.m_pConnection.GetInterfacePtr(),
adOpenDynamic, adLockOptimistic,adCmdText);
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
}
//从数据库中读取数据并显示在链表中
try
{
if(!m_pRecordset->BOF)
m_pRecordset->MoveFirst();
else
{
AfxMessageBox("表内数据为空!");
return;
}
while(!m_pRecordset->adoEOF)
{
var=m_pRecordset->GetCollect("Year");
if(var.vt!=VT_NULL)
m_Year=strYear=(LPCSTR)_bstr_t(var);
var=m_pRecordset->GetCollect("Month");
if(var.vt!=VT_NULL)
m_Month=strMonth=(LPCSTR)_bstr_t(var);
var=m_pRecordset->GetCollect("Day");
if(var.vt!=VT_NULL)
m_Day=strDay=(LPCSTR)_bstr_t(var);
var=m_pRecordset->GetCollect("SerialNo");
if(var.vt!=VT_NULL)
strSerialNo=(LPCSTR)_bstr_t(var);
var=m_pRecordset->GetCollect("Name");
if(var.vt!=VT_NULL)
m_Name=strName=(LPCSTR)_bstr_t(var);
var=m_pRecordset->GetCollect("Unit");
if(var.vt!=VT_NULL)
m_Unit=strUnit=(LPCSTR)_bstr_t(var);
var=m_pRecordset->GetCollect("Number");
if(var.vt!=VT_NULL)
m_Number=strNumber=(LPCSTR)_bstr_t(var);
var=m_pRecordset->GetCollect("Value");
if(var.vt!=VT_NULL)
m_Value=strValue=(LPCSTR)_bstr_t(var);
else
m_Value=strValue="";
var=m_pRecordset->GetCollect("Custodian");
if(var.vt!=VT_NULL)
m_Custodian=strCustodian=(LPCSTR)_bstr_t(var);
var=m_pRecordset->GetCollect("Property");
if(var.vt!=VT_NULL)
m_Property=strProperty=(LPCSTR)_bstr_t(var);
var=m_pRecordset->GetCollect("IsFixed");
if(var.vt!=VT_NULL)
strIsFixed=(LPCSTR)_bstr_t(var);
//固定长度
//少则用空白补
int yearLength=strYear.GetLength();
int monthLength=strMonth.GetLength();
int dayLength=strDay.GetLength();
int serialNoLength=strSerialNo.GetLength();
int nameLength=strName.GetLength();
int unitLength=strUnit.GetLength();
int numberLength=strNumber.GetLength();
int valueLength=strValue.GetLength();
int custodianLength=strCustodian.GetLength();
int propertyLength=strProperty.GetLength();
if(yearLength<=4)
{
for(int i=0;i<=(4-yearLength);i++)
{
strYear+=" ";
}
}
if(monthLength<=2)
{
for(int i=0;i<=(2-monthLength);i++)
{
strMonth+=" ";
}
}
if(dayLength<=5)
{
for(int i=0;i<=(5-dayLength);i++)
{
strDay+=" ";
}
}
if(serialNoLength<=4)
{
for(int i=0;i<=(4-serialNoLength);i++)
{
strSerialNo+=" ";
}
}
if(nameLength<=41)
{
for(int i=0;i<=(41-nameLength);i++)
{
strName+=" ";
}
}
//名称太长,截取其中的一部分
else if(nameLength>=41)
strName=strName.Left(38)+" ";
if(unitLength<=6)
{
for(int i=0;i<=(6-unitLength);i++)
{
strUnit+=" ";
}
}
if(numberLength<=6)
{
for(int i=0;i<=(6-numberLength);i++)
{
strNumber+=" ";
}
}
if(valueLength<=8)
{
for(int i=0;i<=(8-valueLength);i++)
{
strValue+=" ";
}
}
if(custodianLength<=7)
{
for(int i=0;i<=(7-custodianLength);i++)
{
strCustodian+=" ";
}
}
if(propertyLength<=12)
{
for(int i=0;i<=(12-propertyLength);i++)
{
strProperty+=" ";
}
}
//固定资产要价值超过一千
//故其位数肯定大于等于4位
if(valueLength>=4 && strValue!="" && strIsFixed=="是")
{
m_list.AddString(" "+strYear+strMonth+strDay+strSerialNo
+strName+strUnit+strNumber+strValue+strCustodian+strProperty);
}
m_pRecordset->MoveNext();
}
//定位到第一行
m_list.SetCurSel(0);
OnSelchangeList1();
m_Year=m_Month=m_Day="";
UpdateData(FALSE);
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -