Files
gjm 164968b62e chore
把非utf8-bom编码的cpp/h文件改为 utf8 bom 编码, msvc识别utf8编码时,如果不是bom格式的,会使用当前cp_oem来解码.
2026-10-04 00:04:20 +08:00

240 lines
5.7 KiB
C++

#include "stdafx.h"
#include "DataStoreDlg.h"
#include "RBList.h"
#include "globalFunc.h"
#include "PickEntSet.h"
#include "DbfTools.h"
int InvokeDataStore(int iMode, LPCTSTR psz)
{
CAcModuleResourceOverride vTemp;
CDataStoreDlg dlg(iMode, psz);
if (dlg.DoModal()==IDOK)
{
ads_retstr(dlg.m_csSel);
return RTNORM;
}
return RTNORM;
}
/////////////////////////////////////////////////////////////////////////////
// CDataStoreDlg dialog
CDataStoreDlg::CDataStoreDlg(int type, const TCHAR* szCaption, CWnd* pParent /*=NULL*/)
: CDialog(CDataStoreDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CDataStoreDlg)
m_csSel = _T("");
m_csLen = _T("");
m_csWidth = _T("");
m_csDemo = _T("");
//}}AFX_DATA_INIT
m_csCaption = szCaption;
m_iType = type;
}
void CDataStoreDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDataStoreDlg)
DDX_Control(pDX, IDC_LIST_STORE, m_listStore);
DDX_Text(pDX, IDC_EDIT_LEN, m_csLen);
DDX_Text(pDX, IDC_EDIT_WIDTH, m_csWidth);
DDX_Text(pDX, IDC_STATIC_DEMO, m_csDemo);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDataStoreDlg, CDialog)
//{{AFX_MSG_MAP(CDataStoreDlg)
ON_LBN_SELCHANGE(IDC_LIST_STORE, OnSelchangeListStore)
ON_BN_CLICKED(IDC_BUT_ADD, OnButAdd)
ON_BN_CLICKED(IDC_BUT_REMOVE, OnButRemove)
ON_LBN_DBLCLK(IDC_LIST_STORE, OnDblclkListStore)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDataStoreDlg message handlers
BOOL CDataStoreDlg::OnInitDialog()
{
CDialog::OnInitDialog();
CodeBase db;
int Number;
CString csType, csValue, csRemark;
XString fullFile;
if(!GlobalFunc::FindFile(_T("DataStore.dbf"), fullFile)) {
MessageBox(_T("对不起,没有发现DataStore.dbf文件!"));
return TRUE;
}
DbfTable *pTable = db.Open(fullFile);
if(!pTable) {
MessageBox(_T("DataStore.dbf文件出错!"));
return TRUE;
}
pTable->MoveFirst();
while(!pTable->IsEOF()) {
GET_FIELD(pTable, _T("TypeNumber"), Number);
GET_FIELD(pTable, _T("TypeName"), csType);
GET_FIELD(pTable, _T("TypeValue"), csValue);
GET_FIELD(pTable, _T("REMARK"), csRemark);
if(csType == m_csCaption && Number == m_iType){
CDataStore* pStore = new CDataStore(csValue, csRemark);
m_lstStore.Append(pStore);
m_lstType.Append(tstrnew(csValue));
}
pTable->MoveNext();
}
int nFontSize = 20;
CFont font;
font.CreateFont(nFontSize, 0, 0, 0, 700, FALSE, FALSE, 0, ANSI_CHARSET,
OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH&FF_SWISS,
_T("Arial"));
m_listStore.SetFont(&font);
for(int i=0;i<m_lstType.Length();i++){
m_listStore.AddString(m_lstType[i]);
}
SetWindowText(m_csCaption);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CDataStoreDlg::OnOK()
{
UpdateData(TRUE);
CDialog::OnOK();
}
void CDataStoreDlg::OnSelchangeListStore()
{
UpdateData(TRUE);
int sel = m_listStore.GetCurSel();
if (sel == -1)
{
return;
}
m_listStore.GetText(sel, m_csSel);
for(int i=0;i<m_lstStore.Length();i++){
if(m_lstStore[i]->m_csType == m_csSel){
m_csDemo = m_lstStore[i]->m_csRemark;
break;
}
}
UpdateData(FALSE);
}
void CDataStoreDlg::OnButAdd()
{
UpdateData(TRUE);
// cet 2018.1.26 add 判断数据有效性
m_csLen.TrimLeft(_T(" "));
m_csLen.TrimRight(_T(" "));
m_csWidth.TrimLeft(_T(" "));
m_csWidth.TrimRight(_T(" "));
if (m_csLen.IsEmpty() || m_csWidth.IsEmpty() ||
!IsInteger(m_csLen) || !IsInteger(m_csWidth) ||
_tstoi(m_csLen) < 1 || _tstoi(m_csWidth) < 1)
{
MessageBox(_T("请输入有效数据!"), _T("数据检查"), MB_OK | MB_ICONWARNING);
return;
}
m_csSel = m_csLen + _T("*") + m_csWidth;
if(m_lstType.Index(m_csSel) < 0)
m_lstType.Append(tstrnew(m_csSel));
else
return; //已经存在
m_listStore.ResetContent();
for (int m =0; m < m_lstType.Length(); m++)
{
m_listStore.AddString(m_lstType[m]);
}
int nIndex = m_listStore.FindStringExact(0, m_csSel);
if (nIndex != -1)
{
m_listStore.SetCurSel(nIndex);
}
CodeBase db;
XString fullFile;
if(!GlobalFunc::FindFile(_T("DataStore.dbf"), fullFile)) {
MessageBox(_T("对不起,没有发现DataStore.dbf文件!"));
return;
}
DbfTable *pTable = db.Open(fullFile);
if(pTable) {
pTable->AppendBegin();
SET_FIELD(pTable, _T("TypeNumber"), m_iType);
SET_FIELD(pTable, _T("TypeName"), (const TCHAR*)m_csCaption);
SET_FIELD(pTable, _T("TypeValue"), (const TCHAR*)m_csSel);
pTable->AppendEnd();
}
}
void CDataStoreDlg::OnButRemove()
{
UpdateData(TRUE);
int sel = m_listStore.GetCurSel();
if(sel < 0)
return;
CString csSel;
m_listStore.GetText(sel, csSel);
m_lstType.Remove(sel);
m_listStore.ResetContent();
for (int m =0; m < m_lstType.Length(); m++)
m_listStore.AddString(m_lstType[m]);
CodeBase db;
XString fullFile;
if(!GlobalFunc::FindFile(_T("DataStore.dbf"), fullFile)) {
MessageBox(_T("对不起,没有发现DataStore.dbf文件!"));
return;
}
DbfTable *pTable = db.Open(fullFile);
int Number;
CString csType, csValue;
if(pTable) {
pTable->MoveFirst();
while(!pTable->IsEOF()) {
GET_FIELD(pTable, _T("TypeNumber"), Number);
GET_FIELD(pTable, _T("TypeName"), csType);
GET_FIELD(pTable, _T("TypeValue"), csValue);
if(csValue == csSel && Number == m_iType && csType == m_csCaption){
pTable->Delete();
return;
}
pTable->MoveNext();
}
}
}
void CDataStoreDlg::OnDblclkListStore()
{
OnOK();
}
bool CDataStoreDlg::IsInteger(const CString &sText)
{
if (sText.IsEmpty())
{
return false;
}
int nLen = sText.GetLength();
for (int i = 0; i < nLen; ++i)
{
TCHAR ch = sText.GetAt(i);
if (ch < _T('0') || ch > _T('9'))
{
return false;
}
}
return true;
}