📄 ratedlg.cpp
字号:
// RateDlg.cpp : implementation file
//
#include "stdafx.h"
#include "tel2006.h"
#include "RateDlg.h"
#include "Rate2Dlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define VIEW_COLCOUNT 10
/*T_TypeID 通话类型编号 Char 2
T_Code 标志号码 Char 10
T_TypeName 通话类型 Char 10
T_Place 地点 Char 10 只用显示
T_StaySec 起算秒数 Char 4
T_FirstSec 首次时长 Char 4 单位秒
T_FirstPrice 首次价格 Char 10
T_EverySec 每次时长 Char 4 单位秒
T_EveryPrice 每次价格 Char 10
T_Adrate1 附加费1元/次 Char 4*/
static char s_view_colname[VIEW_COLCOUNT][10] = {"类型编号", "标志号码","通话类型",\
"地点","起算秒数","首次时长","首次价格","每次时长","每次价格","附加费"};
static int s_view_colwidth[VIEW_COLCOUNT] = {40,80,80,80,80,80,80,80,80,80};
/////////////////////////////////////////////////////////////////////////////
// CRateDlg dialog
CRateDlg::CRateDlg(CWnd* pParent /*=NULL*/)
: CDialog(CRateDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CRateDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
//m_manager = new CDataManager();
}
void CRateDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CRateDlg)
DDX_Control(pDX, IDC_LIST, m_list);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CRateDlg, CDialog)
//{{AFX_MSG_MAP(CRateDlg)
ON_BN_CLICKED(IDC_ADD_BUTTON, OnAddButton)
ON_BN_CLICKED(IDC_MODIFY_BUTTON, OnModifyButton)
ON_BN_CLICKED(IDC_DEL_BUTTON, OnDelButton)
ON_BN_CLICKED(IDC_EXIT_BUTTON, OnExitButton)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CRateDlg message handlers
void CRateDlg::OnAddButton()
{
CRate2Dlg dlg;
if ( IDCANCEL == dlg.DoModal() ) return;
if(JudgeTypeID(dlg.GetTypeID()))
{
AfxMessageBox("类型编号错误");
return ;
}
InsertData(dlg.GetTypeID(),dlg.GetCode(),dlg.GetTypeName(),
dlg.GetPlace(),dlg.GetStaySec(),dlg.GetFirstSec(),
dlg.GetFirstPrice(),dlg.GetEverySec(),
dlg.GetEveryPrice(),dlg.GetAdrate1());
AddList(dlg.GetTypeID(),dlg.GetCode(),dlg.GetTypeName(),
dlg.GetPlace(),dlg.GetStaySec(),dlg.GetFirstSec(),
dlg.GetFirstPrice(),dlg.GetEverySec(),
dlg.GetEveryPrice(),dlg.GetAdrate1());
}
void CRateDlg::OnModifyButton()
{
CRate2Dlg dlg;
int n= m_list.GetSelectionMark();
dlg.SetTypeID(m_list.GetItemText(n,0));
dlg.SetCode(m_list.GetItemText(n,1));
dlg.SetTypeName(m_list.GetItemText(n,2));
dlg.SetPlace(m_list.GetItemText(n,3));
dlg.SetStaySec(m_list.GetItemText(n,4));
dlg.SetFirstSec(m_list.GetItemText(n,5));
dlg.SetFirstPrice(m_list.GetItemText(n,6));
dlg.SetEverySec(m_list.GetItemText(n,7));
dlg.SetEveryPrice(m_list.GetItemText(n,8));
dlg.SetAdrate1(m_list.GetItemText(n,9));
if ( IDCANCEL == dlg.DoModal() ) return;
if(JudgeTypeID(dlg.GetTypeID()))
{
AfxMessageBox("类型编号错误");
return ;
}
ModifyData(m_list.GetItemText(n,1),dlg.GetTypeID(),
dlg.GetCode(),dlg.GetTypeName(),dlg.GetPlace(),
dlg.GetStaySec(),dlg.GetFirstSec(),dlg.GetFirstPrice(),
dlg.GetEverySec(),dlg.GetEveryPrice(),dlg.GetAdrate1());
ModifyList(dlg.GetTypeID(),dlg.GetCode(),dlg.GetTypeName(),
dlg.GetPlace(),dlg.GetStaySec(),dlg.GetFirstSec(),
dlg.GetFirstPrice(),dlg.GetEverySec(),dlg.GetEveryPrice(),
dlg.GetAdrate1());
}
void CRateDlg::OnDelButton()
{
int n = m_list.GetSelectionMark();
DeleteData(m_list.GetItemText(n,1));
m_list.DeleteItem(n);
}
void CRateDlg::OnExitButton()
{
m_AdoConn.ExitConnect();
CDialog::OnCancel();
}
BOOL CRateDlg::OnInitDialog()
{
CDialog::OnInitDialog();
InitList();
m_AdoConn.OnInitADOConn(".");
ShowList();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
/*******************************
* InitList
*
* Remark: 初始化List控件
******************************/
void CRateDlg::InitList()
{
LV_COLUMN lvC;
int i;
ListView_SetImageList(m_list.m_hWnd, ImageList_Create(1, 16, ILC_COLOR, 1, 1), LVSIL_SMALL);
ListView_SetExtendedListViewStyle(m_list.m_hWnd, LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);
lvC.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
lvC.fmt = LVCFMT_LEFT;
for (i = 0; i < VIEW_COLCOUNT; i++)
{
lvC.pszText = s_view_colname[i];
lvC.cx = s_view_colwidth[i];
lvC.iSubItem = i;
if (ListView_InsertColumn(m_list.m_hWnd, i, &lvC) == -1) return;
}
ListView_SetItemCount(m_list.m_hWnd, VIEW_COLCOUNT);
//m_list.SetSelectionMark(1);
}
/***********************************************
* 函数名: CPhoneDlg::ShowList
*
* 功 能: 显示
*
* 返回值: void
***********************************************/
void CRateDlg::ShowList()
{
_variant_t var;
CString strCount("");
//ADOConn m_AdoConn;
//m_AdoConn.OnInitADOConn(m_strDataBase);
//设置SELECT语句
CString strSQL;
strSQL.Format("select * from R_TelRate order by T_TypeID");
_bstr_t vSQL =strSQL;
_RecordsetPtr m_pRecordset;
m_pRecordset = m_AdoConn.GetRecordSet(vSQL);
// Get RecordCout
long lCount = 0;
lCount = m_pRecordset->GetRecordCount();
if (lCount == -1)
{
if (m_pRecordset->adoEOF != VARIANT_TRUE)
m_pRecordset->MoveFirst();
while (m_pRecordset->adoEOF != VARIANT_TRUE)
{
lCount++;
m_pRecordset->MoveNext();
}
if (lCount >=0)
m_pRecordset->MoveFirst();
}
int n = 0;
m_list.DeleteAllItems();
m_list.Invalidate(TRUE);
while(!m_pRecordset->adoEOF)
{
m_list.InsertItem(n,"");
var = m_pRecordset->GetCollect("T_TypeID");
if(var.vt != VT_NULL)
m_list.SetItemText(n,0,(LPCSTR)_bstr_t(var));
var = m_pRecordset->GetCollect("T_Code");
if(var.vt != VT_NULL)
m_list.SetItemText(n,1,(LPCSTR)_bstr_t(var));
var = m_pRecordset->GetCollect("T_TypeName");
if(var.vt != VT_NULL)
m_list.SetItemText(n,2,(LPCSTR)_bstr_t(var));
var = m_pRecordset->GetCollect("T_Place");
if(var.vt != VT_NULL)
m_list.SetItemText(n,3,(LPCSTR)_bstr_t(var));
var = m_pRecordset->GetCollect("T_StaySec");
if(var.vt != VT_NULL)
m_list.SetItemText(n,4,(LPCSTR)_bstr_t(var));
var = m_pRecordset->GetCollect("T_FirstSec");
if(var.vt != VT_NULL)
m_list.SetItemText(n,5,(LPCSTR)_bstr_t(var));
var = m_pRecordset->GetCollect("T_FirstPrice");
if(var.vt != VT_NULL)
m_list.SetItemText(n,6,(LPCSTR)_bstr_t(var));
var = m_pRecordset->GetCollect("T_EverySec");
if(var.vt != VT_NULL)
m_list.SetItemText(n,7,(LPCSTR)_bstr_t(var));
var = m_pRecordset->GetCollect("T_EveryPrice");
if(var.vt != VT_NULL)
m_list.SetItemText(n,8,(LPCSTR)_bstr_t(var));
var = m_pRecordset->GetCollect("T_Adrate1");
if(var.vt != VT_NULL)
m_list.SetItemText(n,9,(LPCSTR)_bstr_t(var));
n++;
m_pRecordset->MoveNext();
}
//m_AdoConn.ExitConnect();
}
/*************************************
* AddList
*
* Parameters: structData // 结构体
*
* Remark: 添加入ListView中,显示
************************************/
void CRateDlg::AddList(CString strTypeID, CString strCode,
CString strTypeName, CString strPlace,
CString strStaySec, CString strFirstSec,
CString strFirstPrice, CString strEverySec,
CString strEveryPrice, CString strAdrate1)
{
int Count = m_list.GetItemCount();
m_list.InsertItem(Count,"");
m_list.SetItemText(Count,0,strTypeID);
m_list.SetItemText(Count,1,strCode);
m_list.SetItemText(Count,2,strTypeName);
m_list.SetItemText(Count,3,strPlace);
m_list.SetItemText(Count,4,strStaySec);
m_list.SetItemText(Count,5,strFirstSec);
m_list.SetItemText(Count,6,strFirstPrice);
m_list.SetItemText(Count,7,strEverySec);
m_list.SetItemText(Count,8,strEveryPrice);
m_list.SetItemText(Count,9,strAdrate1);
}
void CRateDlg::ModifyList(CString strTypeID,CString strCode,CString strTypeName,
CString strPlace,CString strStaySec,CString strFirstSec,
CString strFirstPrice,CString strEverySec,CString strEveryPrice,
CString strAdrate1)
{
int n = m_list.GetSelectionMark();
m_list.SetItemText(n,0,strTypeID);
m_list.SetItemText(n,1,strCode);
m_list.SetItemText(n,2,strTypeName);
m_list.SetItemText(n,3,strPlace);
m_list.SetItemText(n,4,strStaySec);
m_list.SetItemText(n,5,strFirstSec);
m_list.SetItemText(n,6,strFirstPrice);
m_list.SetItemText(n,7,strEverySec);
m_list.SetItemText(n,8,strEveryPrice);
m_list.SetItemText(n,9,strAdrate1);
}
void CRateDlg::InsertData(CString strTypeID,CString strCode,CString strTypeName,
CString strPlace,CString strStaySec,CString strFirstSec,
CString strFirstPrice,CString strEverySec,CString strEveryPrice,
CString strAdrate1)
{
CString strSQL("");
try
{
strSQL.Format ("INSERT INTO R_TelRate(T_TypeID, T_Code, \
T_TypeName, T_Place, T_StaySec, T_FirstSec, T_FirstPrice, \
T_EverySec,T_EveryPrice,T_Adrate1) VALUES ('%s', '%s', '%s', \
'%s', '%s', '%s', '%s', '%s', '%s', '%s')", \
strTypeID,strCode,strTypeName,strPlace,strStaySec, \
strFirstSec,strFirstPrice, strEverySec,strEveryPrice, \
strAdrate1);
_bstr_t vSQL =strSQL;
m_AdoConn.ExecuteSQL(vSQL);
}
catch (_com_error e)
{
CString errormessage;
errormessage.Format("自定义错误信息3:%s",e.ErrorMessage());
AfxMessageBox(errormessage);///显示错误信息
}
}
void CRateDlg::DeleteData(CString strCode)
{
CString strSQL("");
try
{
strSQL.Format("Delete from R_TelRate where T_Code = '%s'",strCode);
_bstr_t vSQL =strSQL;
m_AdoConn.ExecuteSQL(vSQL);
}
catch (_com_error e)
{
CString errormessage;
errormessage.Format("自定义错误信息2:%s",e.ErrorMessage());
AfxMessageBox(errormessage);///显示错误信息
}
}
void CRateDlg::ModifyData(CString strOldCode,CString strTypeID,
CString strCode,CString strTypeName,
CString strPlace,CString strStaySec,
CString strFirstSec,CString strFirstPrice,
CString strEverySec,CString strEveryPrice,
CString strAdrate1)
{
CString strSQL("");
try
{
strSQL.Format("update R_TelRate SET T_TypeID = '%s',T_Code= '%s', \
T_TypeName = '%s',T_Place = '%s',T_StaySec = '%s',T_FirstSec = \
'%s',T_FirstPrice = '%s',T_EverySec = '%s',T_EveryPrice = '%s', \
T_Adrate1 = '%s' WHERE T_Code ='%s'",strTypeID,strCode,strTypeName,\
strPlace,strStaySec,strFirstSec,strFirstPrice,strEverySec,\
strEveryPrice,strAdrate1,strOldCode);
_bstr_t vSQL =strSQL;
m_AdoConn.ExecuteSQL(vSQL);
}
catch (_com_error e)
{
CString errormessage;
errormessage.Format("自定义错误信息3:%s",e.ErrorMessage());
AfxMessageBox(errormessage);///显示错误信息
}
}
BOOL CRateDlg::JudgeTypeID(CString strTypeID)
{
if(strTypeID == "01" ||strTypeID == "02" ||strTypeID == "03" ||
strTypeID == "04" ||strTypeID == "05" ||strTypeID == "06" )
return false;
else
return true;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -