167 lines
3.9 KiB
C++
167 lines
3.9 KiB
C++
#if !defined(AFX_ACCOUNT_AREA_DLG_H)
|
|
#define AFX_ACCOUNT_AREA_DLG_H
|
|
|
|
#if _MSC_VER > 1000
|
|
#pragma once
|
|
#endif // _MSC_VER > 1000
|
|
|
|
#include "Resource.h"
|
|
#include <tchar.h>
|
|
|
|
// 面积计算对话框,add by fxj 090617
|
|
// lgh modify 101104,根据8.5新需求,增加了括号、乘、除、退格等功能
|
|
class CAccountAreaDlg: public CModelessDialog
|
|
{
|
|
public:
|
|
CAccountAreaDlg(CWnd* pParent=NULL);
|
|
|
|
enum EAreaStat{eSelect, eDrawText, eSelectFirst};
|
|
|
|
// Dialog Data
|
|
//{{AFX_DATA(CAccountAreaDlg)
|
|
enum {IDD=IDD_AREA_ACCOUNT};
|
|
CEdit m_editExpression;
|
|
CString m_sExpression;
|
|
double m_dResult;
|
|
BOOL m_bUseEsc;
|
|
// int m_nPath;
|
|
EAreaStat m_ePath;
|
|
//}}AFX_DATA
|
|
|
|
// void SetCurs(int nStart,int nEnd);
|
|
// void InsertData(int nBegin,CString str);
|
|
void SetCurs();
|
|
void InsertData(CString sInsert);
|
|
|
|
void SetAreaState(EAreaStat eState);
|
|
BOOL CalcResult();
|
|
BOOL IsNoneSelect();
|
|
BOOL Amount();
|
|
|
|
// 向文本框中输入一个字符
|
|
void AddText(LPCTSTR sText);
|
|
|
|
//{{AFX_VIRTUAL(CAccountAreaDlg)
|
|
protected:
|
|
virtual void DoDataExchange(CDataExchange* pDX);
|
|
virtual BOOL OnInitDialog();
|
|
virtual BOOL PreTranslateMessage(MSG* pMsg);
|
|
//}}AFX_VIRTUAL
|
|
|
|
protected:
|
|
//{{AFX_MSG(CAccountAreaDlg)
|
|
afx_msg void OnKillFocus();
|
|
afx_msg void OnC();
|
|
afx_msg void OnPoint();
|
|
afx_msg void OnAdd();
|
|
afx_msg void OnDe();
|
|
afx_msg void OnAmount();
|
|
afx_msg void OnZero();
|
|
afx_msg void OnOne();
|
|
afx_msg void OnTwo();
|
|
afx_msg void OnThree();
|
|
afx_msg void OnFour();
|
|
afx_msg void OnFive();
|
|
afx_msg void OnSix();
|
|
afx_msg void OnSeven();
|
|
afx_msg void OnEight();
|
|
afx_msg void OnNine();
|
|
afx_msg void OnLabel();
|
|
afx_msg void OnSelArea();
|
|
afx_msg void OnClose();
|
|
afx_msg void OnBackspace();
|
|
afx_msg void OnLeftBracket();
|
|
afx_msg void OnRightBracket();
|
|
afx_msg void OnMultiply();
|
|
afx_msg void OnDivision();
|
|
//}}AFX_MSG
|
|
|
|
DECLARE_MESSAGE_MAP()
|
|
|
|
private:
|
|
BOOL IsOperationSymbol(TCHAR ch) const;
|
|
|
|
private:
|
|
int m_nCursStart;
|
|
int m_nCursEnd;
|
|
};
|
|
|
|
// 面积计算的上下文类
|
|
class CAccountAreaContext
|
|
{
|
|
public:
|
|
CAccountAreaContext();
|
|
~CAccountAreaContext();
|
|
|
|
public:
|
|
enum EAreaCMDState {eCMDSelectFirst = 0, eCMDSelect, eCMDDrawText};
|
|
|
|
// 初始化命令的环境
|
|
void Init();
|
|
// 恢复命令运行前的环境
|
|
void Reset();
|
|
|
|
void SetCancel(BOOL b = TRUE);
|
|
BOOL GetCancel();
|
|
|
|
void SetCmdState(CAccountAreaContext::EAreaCMDState eState) ;
|
|
EAreaCMDState GetCmdState() const;
|
|
|
|
BOOL IsCMDModel() const;
|
|
|
|
public:
|
|
// 命令行下的选择模式
|
|
void DoCMDSelectState();
|
|
// 对话框下的选择
|
|
void DoSelectState();
|
|
// 文本绘制通用
|
|
void DoDrawState();
|
|
void CloseSwitch();
|
|
private:
|
|
static void CreateDlg(CAccountAreaContext *pContex, BOOL bShow = TRUE);
|
|
static int DealSelectResult(PickSet &ssArea, CStringArray &arSArea);
|
|
static void DealSelectSArea(CString &sArea);
|
|
static CString GetResultAreaString(CAccountAreaContext *pCtx);
|
|
static double CalcSumOfArea(CStringArray &arSArea);
|
|
|
|
public:
|
|
CAccountAreaDlg *m_pDlg; // default to NULL, wait for create
|
|
CStringArray m_arSArea;
|
|
|
|
private:
|
|
BOOL m_bCancel;
|
|
EAreaCMDState m_eCmdState;
|
|
int m_nSysVar;
|
|
PickSet m_ssAreaAll;
|
|
bool m_bSwitch; // 是否允许切换,只允许第一次切换,过后不能在切换lgh. add 20110306
|
|
static bool m_bCMD; // 记忆面积计算的模式,在对话框和命令行两种方式中切换
|
|
};
|
|
|
|
|
|
class CExpressionParser
|
|
{
|
|
public:
|
|
enum EErrorStat{
|
|
eOk = 0,
|
|
eBracketNotMatch, // 括号不匹配
|
|
eErrorCharacter, // 无法识别的字符(数字)
|
|
eZeroDivisor, // 除0错误
|
|
eOperationMissed, // 算号缺少
|
|
eOperationRedundant, // 算号多出
|
|
};
|
|
|
|
static EErrorStat Expression_Parser( CString &sExpression, double &dResult );
|
|
|
|
private:
|
|
static double DegTorad( double deg );
|
|
static EErrorStat Trans( CString &a, TCHAR b[] );
|
|
static EErrorStat Compvalue( TCHAR exp[], double &dResult);
|
|
|
|
private:
|
|
static const unsigned m_uMaxValue;// 最大容忍字符
|
|
static const unsigned m_uRealMaxValue;// 实际存储的空间,大一些
|
|
};
|
|
|
|
|
|
|
|
#endif |