📄 chargeitem.cpp
字号:
// ChargeItem.cpp : implementation file
//
#include "stdafx.h"
#include "StuChgManager.h"
#include "ChargeItem.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern CStuChgManagerApp theApp; //引入外部变量
/////////////////////////////////////////////////////////////////////////////
// CChargeItem dialog
CChargeItem::CChargeItem(CWnd* pParent /*=NULL*/)
: CDialog(CChargeItem::IDD, pParent)
{
//{{AFX_DATA_INIT(CChargeItem)
m_chgitem = _T("");
m_chgspe = _T("");
m_chgyear = _T("");
m_chgbook = 0.0f;
m_chgdorm = 0.0f;
m_chgfile = 0.0f;
m_chgincid = 0.0f;
m_chginsur = 0.0f;
m_chgmactime = 0.0f;
m_chgtatol = 0.0f;
m_chgtuition = 0.0f;
//}}AFX_DATA_INIT
}
void CChargeItem::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CChargeItem)
DDX_Control(pDX, IDC_CHGtotal, m_ctrlchgtatol);
DDX_Control(pDX, IDC_CHGfile, m_ctrlchgfile);
DDX_Control(pDX, IDC_CHGdorm, m_ctrlchgdorm);
DDX_Control(pDX, IDC_CHGbook, m_ctrlchgbook);
DDX_Control(pDX, IDC_CHGyear, m_ctrlchgyear);
DDX_Control(pDX, IDC_CHGtuition, m_ctrlchgtuition);
DDX_Control(pDX, IDC_CHGspe, m_ctrlchgspe);
DDX_Control(pDX, IDC_CHGmactime, m_ctrlchgmac);
DDX_Control(pDX, IDC_CHGincidental, m_ctrlchgincid);
DDX_Control(pDX, IDC_CHGinsurance, m_ctrlchginsur);
DDX_Control(pDX, IDC_CHGitem, m_ctrlchgitem);
DDX_Text(pDX, IDC_CHGitem, m_chgitem);
DDX_Text(pDX, IDC_CHGspe, m_chgspe);
DDX_Text(pDX, IDC_CHGyear, m_chgyear);
DDX_Control(pDX, IDC_DATAGRID8, m_chggrid);
DDX_Text(pDX, IDC_CHGbook, m_chgbook);
DDX_Text(pDX, IDC_CHGdorm, m_chgdorm);
DDX_Text(pDX, IDC_CHGfile, m_chgfile);
DDX_Text(pDX, IDC_CHGincidental, m_chgincid);
DDX_Text(pDX, IDC_CHGinsurance, m_chginsur);
DDX_Text(pDX, IDC_CHGmactime, m_chgmactime);
DDX_Text(pDX, IDC_CHGtotal, m_chgtatol);
DDX_Text(pDX, IDC_CHGtuition, m_chgtuition);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CChargeItem, CDialog)
//{{AFX_MSG_MAP(CChargeItem)
ON_BN_CLICKED(IDC_CHGITEMINSERT, OnChgiteminsert)
ON_BN_CLICKED(IDC_CHGITEMSELECT, OnChgitemenquire)
ON_BN_CLICKED(IDC_CHGITEMDELE, OnChgitemdele)
ON_BN_CLICKED(IDC_CHGITEMSUBMIT, OnChgitemsubmit)
ON_BN_CLICKED(IDC_CHGITEMNEW, OnChgitemnew)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CChargeItem message handlers
BOOL CChargeItem::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
insertItem = false; ///初始全部操作失效
deleteItem = false;
queryItem = false;
m_ctrlchgspe.SetWindowText("");//将Edit框清空
m_ctrlchgitem.SetWindowText("");
m_ctrlchgyear.SetWindowText("");
m_ctrlchgtuition.EnableWindow(false);//初始相应对话框
m_ctrlchgbook.EnableWindow(false);
m_ctrlchgdorm.EnableWindow(false);
m_ctrlchgfile.EnableWindow(false);
m_ctrlchgincid.EnableWindow(false);
m_ctrlchginsur.EnableWindow(false);
m_ctrlchgmac.EnableWindow(false);
m_ctrlchgtatol.EnableWindow(false);
// m_ctrlchgtatol.EnableWindow(false);
m_ctrlchgspe.EnableWindow(false);
m_ctrlchgitem.EnableWindow(false);
m_ctrlchgyear.EnableWindow(false);
m_ctrlchgitem.SetFocus();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CChargeItem::OnChgiteminsert()
{
// TODO: Add your control notification handler code here
insertItem = true; //初始插入操作有效
deleteItem = false;
queryItem = false;
m_ctrlchgspe.SetWindowText("");//将Edit框清空
m_ctrlchgitem.SetWindowText("");
m_ctrlchgyear.SetWindowText("");
m_ctrlchgtuition.EnableWindow(true);//初始相应对话框
m_ctrlchgbook.EnableWindow(true);
m_ctrlchgdorm.EnableWindow(true);
m_ctrlchgfile.EnableWindow(true);
m_ctrlchgincid.EnableWindow(true);
m_ctrlchginsur.EnableWindow(true);
m_ctrlchgmac.EnableWindow(true);
m_ctrlchgtatol.EnableWindow(true);
m_ctrlchgtatol.EnableWindow(true);
m_ctrlchgspe.EnableWindow(true);
m_ctrlchgitem.EnableWindow(true);
m_ctrlchgyear.EnableWindow(true);
m_ctrlchgitem.SetFocus();
}
void CChargeItem::OnChgitemenquire()
{
// TODO: Add your control notification handler code here
insertItem = false; //初始查询操作有效
deleteItem = false;
queryItem = true;
m_ctrlchgspe.SetWindowText("");//将Edit框清空
m_ctrlchgitem.SetWindowText("");
m_ctrlchgyear.SetWindowText("");
m_ctrlchgtuition.EnableWindow(false);//初始相应对话框
m_ctrlchgbook.EnableWindow(false);
m_ctrlchgdorm.EnableWindow(false);
m_ctrlchgfile.EnableWindow(false);
m_ctrlchgincid.EnableWindow(false);
m_ctrlchginsur.EnableWindow(false);
m_ctrlchgmac.EnableWindow(false);
m_ctrlchgtatol.EnableWindow(false);
m_ctrlchgtatol.EnableWindow(false);
m_ctrlchgspe.EnableWindow(false);
m_ctrlchgitem.EnableWindow(true);
m_ctrlchgyear.EnableWindow(false);
m_ctrlchgitem.SetFocus();
}
void CChargeItem::OnChgitemdele()
{
// TODO: Add your control notification handler code here
insertItem = false; //初始删除操作有效
deleteItem = true;
queryItem = false;
m_ctrlchgspe.SetWindowText("");//将Edit框清空
m_ctrlchgitem.SetWindowText("");
m_ctrlchgyear.SetWindowText("");
m_ctrlchgtuition.EnableWindow(false); //初始相应对话框
m_ctrlchgbook.EnableWindow(false);
m_ctrlchgdorm.EnableWindow(false);
m_ctrlchgfile.EnableWindow(false);
m_ctrlchgincid.EnableWindow(false);
m_ctrlchginsur.EnableWindow(false);
m_ctrlchgmac.EnableWindow(false);
m_ctrlchgtatol.EnableWindow(false);
m_ctrlchgtatol.EnableWindow(false);
m_ctrlchgspe.EnableWindow(false);
m_ctrlchgitem.EnableWindow(true);
m_ctrlchgyear.EnableWindow(false);
m_ctrlchgitem.SetFocus();
}
bool CChargeItem::notExist(CString str)
{
CString sql; //查询相应记录
sql.Format("select * from ChargeItem where ItemID = '%s'",str);
theApp.record1->raw_Close();//关闭当前数据集
theApp.record1->CursorLocation = adUseClient;
theApp.record1->Open((_bstr_t)sql,theApp.connection.GetInterfacePtr(),adOpenKeyset,adLockOptimistic,adCmdText);
if(theApp.record1->RecordCount == 0)
return true;
return false;
}
void CChargeItem::RefreshInfo()
{
//赋初值
m_chgtuition=0;
m_chgbook=0;
m_chgdorm=0;
m_chgfile=0;
m_chgincid=0;
m_chginsur=0;
m_chgmactime=0;
m_chgtatol=0;
m_chgtatol=0;
UpdateData(false);
//将Edit框清空
m_ctrlchgspe.SetWindowText("");
m_ctrlchgitem.SetWindowText("");
m_ctrlchgyear.SetWindowText("");
m_chggrid.SetRefDataSource(NULL);
CString sql;//查询相应记录
sql = "select ItemID,SpeID, ChgYear,Tuition,Incidental, MacTimeFee,Insurance,DormFee,BookFee,FileFee,TotalFee from chargeitem";
theApp.record->raw_Close(); //关闭当前的数据集
theApp.record->CursorLocation = adUseClient;
try //捕捉异常
{
theApp.record->Open((_bstr_t)sql,theApp.connection.GetInterfacePtr(),adOpenKeyset,adLockPessimistic,adCmdText);
}
catch(_com_error & e)
{
AfxMessageBox(e.Description());
return; //捕捉到异常后就不在继续执行
}
if(theApp.record->RecordCount > 0) //非空集合
{
m_chggrid.SetRefDataSource((LPUNKNOWN)theApp.record->DataSource); //将查询结果显示到DataGrid控件
m_chggrid.Refresh();
}
}
void CChargeItem::OnChgitemsubmit()
{
// TODO: Add your control notification handler code here
UpdateData(true);
if(deleteItem) //如果是删除
{
if(m_chgitem.GetLength() == 0)
{
MessageBox("收费项目代号不能为空!");
m_ctrlchgitem.SetFocus();
return;
}
if(notExist(m_chgitem))
{
MessageBox("删除项目不存在!");
m_ctrlchgitem.SetFocus();
return;
}
CString sql; //执行存储过程spDeleteChargeItem
sql.Format("exec spDeleteChargeItem \'%s\' ",m_chgitem);
theApp.record->raw_Close(); //关闭当前的数据集
theApp.record->CursorLocation = adUseClient;
try //捕捉异常
{
theApp.record->Open((_bstr_t)sql,theApp.connection.GetInterfacePtr(),adOpenKeyset,adLockPessimistic,adCmdText);
}
catch(_com_error & e)
{
AfxMessageBox(e.Description());
return; //捕捉到异常后就不在继续执行
}
RefreshInfo(); //刷新
MessageBox("删除成功!");
m_ctrlchgitem.SetFocus();
}
if(queryItem) //如果是查询
{
if(m_chgitem.GetLength() == 0)
{
MessageBox("收费项目代号不能为空!");
m_ctrlchgitem.SetFocus();
return;
}
if(notExist(m_chgitem))
{
MessageBox("删除项目不存在!");
m_ctrlchgitem.SetFocus();
return;
}
CString sql; //查询相应数据
sql.Format("select * from ChargeItem where ItemID = \'%s\' ",m_chgitem);
theApp.record->raw_Close(); //关闭当前的数据集
theApp.record->CursorLocation = adUseClient;
try //捕捉异常
{
theApp.record->Open((_bstr_t)sql,theApp.connection.GetInterfacePtr(),adOpenKeyset,adLockPessimistic,adCmdText);
}
catch(_com_error & e)
{
AfxMessageBox(e.Description());
return; //捕捉到异常后就不在继续执行
}
if(theApp.record->RecordCount > 0) //非空集合
{
m_chggrid.SetRefDataSource((LPUNKNOWN)theApp.record->DataSource); //将查询结果显示到DataGrid控件
m_chggrid.Refresh();
}
MessageBox("成功查询!");
m_ctrlchgitem.SetFocus();
}
if(insertItem) //如果是插入
{
if(m_chgbook < 0)
{
MessageBox("书费不能为负!");
m_ctrlchgbook.SetFocus();
return;
}
if(m_chgdorm < 0)
{
MessageBox("住宿费不能为负!");
m_ctrlchgdorm.SetFocus();
return;
}
if(m_chgfile<0)
{
MessageBox("资料费不能为负!");
m_ctrlchgfile.SetFocus();
return;
}
if(m_chgincid< 0)
{
MessageBox("杂费不能为负!");
m_ctrlchgincid.SetFocus();
return;
}
if(m_chginsur< 0)
{
MessageBox("保险费不能为负!");
m_ctrlchginsur.SetFocus();
return;
}
if(m_chgmactime< 0)
{
MessageBox("机时费不能为负!");
m_ctrlchgmac.SetFocus();
return;
}
if(m_chgitem.GetLength() == 0)
{
MessageBox("收费项目代号不能为空!");
m_ctrlchgitem.SetFocus();
return;
}
if(m_chgspe.GetLength() == 0)
{
MessageBox("所属学院代码不能为空! ");
m_ctrlchgspe.SetFocus();
return;
}
if(m_chgtatol < 0)
{
MessageBox("总费用不能为负!");
m_ctrlchgspe.SetFocus();
return;
}
if(m_chgtuition < 0)
{
MessageBox("学费不能为负!");
m_ctrlchgtuition.SetFocus();
return;
}
if(m_chgyear.GetLength() == 0)
{
MessageBox("收费年度不能为空!");
m_ctrlchgyear.SetFocus();
return;
}
if(!notExist(m_chgitem))
{
MessageBox("此项收费项目已存在,请仔细核对!");
m_ctrlchgitem.SetFocus();
return;
}
if((m_chgtuition+m_chgincid+m_chgmactime+m_chginsur+m_chgdorm+m_chgbook+m_chgfile)!=m_chgtatol)
{
MessageBox("各收费项目之和与总费用不一致,请核对!");
m_ctrlchgtuition.SetFocus();
return;
}
CString sql; //执行插入操作
sql.Format("Insert into chargeitem values(\'%s\',\'%s\',\'%s\',%d,%d,%d,%d,%d,%d,%d,%d)",m_chgitem,m_chgspe,m_chgyear,m_chgtuition,m_chgincid,m_chgmactime,m_chginsur,m_chgdorm,m_chgbook,m_chgfile,m_chgtatol);
theApp.record->raw_Close(); //关闭当前的数据集
theApp.record->CursorLocation = adUseClient;
try //捕捉异常
{
theApp.record->Open((_bstr_t)sql,theApp.connection.GetInterfacePtr(),adOpenKeyset,adLockPessimistic,adCmdText);
}
catch(_com_error & e)
{
AfxMessageBox(e.Description());
return; //捕捉到异常后就不在继续执行
}
RefreshInfo(); //刷新
MessageBox("成功插入数据!");
m_ctrlchgitem.SetFocus();
}
}
void CChargeItem::OnChgitemnew()
{
// TODO: Add your control notification handler code here
RefreshInfo(); //刷新
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -