⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sourcecreatordlg.cpp

📁 基于dialogic语音卡的IVR系统源代码
💻 CPP
字号:
// SourceCreatorDlg.cpp : implementation file
//

#include "stdafx.h"
//#include "VoiceScript.h"
#include "SourceCreatorDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

int hwndLastFocus;
UINT uiLastFocus = 0;
int iWhichIF = -1;
int iCountOfConditions = 0;
/////////////////////////////////////////////////////////////////////////////
// CSourceCreatorDlg dialog


CSourceCreatorDlg::CSourceCreatorDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CSourceCreatorDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CSourceCreatorDlg)
	m_strLogical1 = _T("&&");
	m_strLogical2 = _T("&&");
	m_strCommonUseIF = _T("");
	m_strConditions = _T("");
	m_strOutParam = _T("none");
	m_iAction = 1;
	m_strIID = _T("");
	m_strInParam = _T("");
	m_strOnError = _T("0");
	m_strDO = _T("");
	m_strCommonUseDO = _T("");
	m_strNextIID = _T("");
	m_iWhichNext = 0;
	m_strOnError = _T("");
	m_strSourceWindow = _T("");
	//}}AFX_DATA_INIT
}


void CSourceCreatorDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSourceCreatorDlg)
	DDX_CBString(pDX, IDC_COMBO_LOGICAL1, m_strLogical1);
	DDX_CBString(pDX, IDC_COMBO_LOGICAL2, m_strLogical2);
	DDX_CBString(pDX, IDC_COMBO_COMMONUSE_IF, m_strCommonUseIF);
	DDX_Text(pDX, IDC_EDIT_CONDITIONS, m_strConditions);
	DDX_Text(pDX, IDC_EDIT_OUTPARAM, m_strOutParam);
	DDX_CBIndex(pDX, IDC_COMBO_ACTION, m_iAction);
	DDX_Text(pDX, IDC_EDIT_IID, m_strIID);
	DDX_Text(pDX, IDC_EDIT_INPARAM, m_strInParam);
	DDX_Text(pDX, IDC_EDIT_ONERROR, m_strOnError);
	DDX_Text(pDX, IDC_EDIT_DO, m_strDO);
	DDX_CBString(pDX, IDC_COMBO_COMMONUSE_DO, m_strCommonUseDO);
	DDX_Text(pDX, IDC_EDIT_NEXTIID, m_strNextIID);
	DDX_Radio(pDX, IDC_RADIO_NEXT1, m_iWhichNext);
	DDX_Text(pDX, IDC_EDIT_SOURCEWINDOW, m_strSourceWindow);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CSourceCreatorDlg, CDialog)
	//{{AFX_MSG_MAP(CSourceCreatorDlg)
	ON_CBN_SELCHANGE(IDC_COMBO_COMPARETYPE, OnSelchangeComboComparetype)
	ON_BN_CLICKED(IDC_RADIO_IF1, OnRadioIf1)
	ON_BN_CLICKED(IDC_RADIO_IF2, OnRadioIf2)
	ON_BN_CLICKED(IDC_RADIO_IF3, OnRadioIf3)
	ON_CBN_SELCHANGE(IDC_COMBO_COMMONUSE_IF, OnSelchangeComboCommonuseIf)
	ON_BN_CLICKED(IDC_RADIO_NEXT1, OnRadioNext1)
	ON_BN_CLICKED(IDC_RADIO_NEXT2, OnRadioNext2)
	ON_BN_CLICKED(IDC_RADIO_NEXT3, OnRadioNext3)
	ON_BN_CLICKED(IDC_BUTTON_CREATESOURCE, OnButtonCreatesource)
	ON_CBN_SELCHANGE(IDC_COMBO_COMMONUSE_DO, OnSelchangeComboCommonuseDo)
	ON_EN_CHANGE(IDC_EDIT_NEXTIID, OnChangeEditNextiid)
	ON_EN_CHANGE(IDC_EDIT_DO, OnChangeEditDo)
	//}}AFX_MSG_MAP
//	ON_CBN_EDITCHANGE(IDC_COMBO_GLOBALSTRING, OnEditchangeComboGlobal)
	ON_CONTROL_RANGE(EN_KILLFOCUS, IDC_EDIT_INPARAM, IDC_EDIT_INPARAM, OnKillFocus)
	ON_CONTROL_RANGE(EN_KILLFOCUS, IDC_EDIT_OUTPARAM, IDC_EDIT_OUTPARAM, OnKillFocus)
	ON_CONTROL_RANGE(EN_KILLFOCUS, IDC_EDIT_ONERROR, IDC_EDIT_ONERROR, OnKillFocus)
	ON_CONTROL_RANGE(EN_KILLFOCUS, IDC_EDIT_CONDITIONS, IDC_EDIT_CONDITIONS, OnKillFocus)
	ON_CONTROL_RANGE(EN_KILLFOCUS, IDC_EDIT_DO, IDC_EDIT_DO, OnKillFocus)

	ON_CONTROL_RANGE(EN_CHANGE, IDC_EDIT_DO, IDC_EDIT_DO, OnEditChange)
	ON_CONTROL_RANGE(EN_CHANGE, IDC_EDIT_CONDITIONS, IDC_EDIT_CONDITIONS, OnEditChange)
	ON_CONTROL_RANGE(EN_CHANGE, IDC_EDIT_INPARAM, IDC_EDIT_INPARAM, OnEditChange)
	ON_CONTROL_RANGE(EN_CHANGE, IDC_EDIT_OUTPARAM, IDC_EDIT_OUTPARAM, OnEditChange)
	ON_CONTROL_RANGE(EN_CHANGE, IDC_EDIT_ONERROR, IDC_EDIT_ONERROR, OnEditChange)
	ON_CONTROL_RANGE(EN_CHANGE, IDC_EDIT_IID, IDC_EDIT_IID, OnEditChange)
	ON_CONTROL_RANGE(EN_CHANGE, IDC_EDIT_NEXTIID, IDC_EDIT_NEXTIID, OnEditChange)

	ON_CONTROL_RANGE(CBN_SELCHANGE, IDC_COMBO_GLOBALSTRING, IDC_COMBO_GLOBALSTRING, OnEditchangeComboGlobal)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSourceCreatorDlg message handlers

BOOL CSourceCreatorDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	HWND hwnd;
/*	GetDlgItem(IDC_COMBO_LOGICAL1, &hwnd);
	::SendMessage(hwnd, CB_SETCURSEL, 0, 0);
	GetDlgItem(IDC_COMBO_LOGICAL2, &hwnd);
	::SendMessage(hwnd, CB_SETCURSEL, 0, 0);*/

	GetDlgItem(IDC_RADIO_IF1, &hwnd);
	::SendMessage(hwnd, BM_SETCHECK, TRUE, 0);
	iWhichIF = 1;
	GetDlgItem(IDC_RADIO_NEXT1, &hwnd);
	::SendMessage(hwnd, BM_SETCHECK, TRUE, 0);
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CSourceCreatorDlg::OnKillFocus(UINT uiControlID) 
{
	uiLastFocus = uiControlID;
}

void CSourceCreatorDlg::OnEditChange(UINT uiControlID) 
{
	UpdateData();
}

void CSourceCreatorDlg::OnSelchangeComboComparetype() 
{
HWND hwndCombo, hwndLastEdit;
char aszTemp[1000];
int iIndex;
CString strTemp;

	aszTemp[0] = 0;

	GetDlgItem(IDC_COMBO_COMPARETYPE, &hwndCombo);
	GetDlgItem(uiLastFocus, &hwndLastEdit);
	::SendMessage(hwndLastEdit, WM_GETTEXT, sizeof(aszTemp), (LPARAM)aszTemp);
	strTemp = aszTemp;
	if((iIndex = ::SendMessage(hwndCombo, CB_GETCURSEL, 0, 0)) == CB_ERR)
		return;
	if(::SendMessage(hwndCombo, CB_GETLBTEXT, iIndex, (LPARAM)aszTemp) == CB_ERR)
		return;
	strTemp += aszTemp;
	::SendMessage(hwndLastEdit, WM_SETTEXT, 0, (LPARAM)LPCTSTR(strTemp));
}

void CSourceCreatorDlg::OnRadioIf1() 
{
	iWhichIF = 1;	
}

void CSourceCreatorDlg::OnRadioIf2() 
{
	iWhichIF = 2;	
}

void CSourceCreatorDlg::OnRadioIf3() 
{
	iWhichIF = 3;	
}

void CSourceCreatorDlg::OnSelchangeComboCommonuseIf() 
{
HWND hwndCombo, hwndLastEdit;
char aszTemp[1000];
int iIndex;
CString strTemp;

	if(m_iWhichNext == -1 || m_strNextIID == "")
	{
		AfxMessageBox("请先指定流向");
		return;
	}

	aszTemp[0] = 0;

	GetDlgItem(IDC_COMBO_COMMONUSE_IF, &hwndCombo);
	if((iIndex = ::SendMessage(hwndCombo, CB_GETCURSEL, 0, 0)) == CB_ERR)
		return;
	if(::SendMessage(hwndCombo, CB_GETLBTEXT, iIndex, (LPARAM)aszTemp) == CB_ERR)
		return;
	m_strCommonUseIF = aszTemp;
	UpdateData(FALSE);
	UpdateData(TRUE);
	strTemp = m_strCommonUseIF;
	strTemp = m_strLogical1;

	int i, j;
	//如果是条件1
	if(iWhichIF == 1)
	{
		if(iCountOfConditions <= 1)
		{
			m_strConditions = m_strCommonUseIF;
			iCountOfConditions += 1;
			goto HERE;
		}
		if(iCountOfConditions == 2 && !m_strLogical1.IsEmpty())
		{
			i = m_strConditions.FindOneOf("|&");
			m_strConditions.Delete(0, i);
			m_strConditions = m_strCommonUseIF + m_strLogical1 + m_strConditions;
			goto HERE;
		}
		if(iCountOfConditions == 3 && !m_strLogical1.IsEmpty() && !m_strLogical2.IsEmpty())
		{
			i = m_strConditions.FindOneOf("|&");
			m_strConditions.Delete(0, i);
			m_strConditions = m_strCommonUseIF + m_strConditions;
			goto HERE;
		}
	}

	//如果是条件2
	if(iWhichIF == 2)
	{
		if(m_strConditions.IsEmpty())
		{
			AfxMessageBox("请先指定条件1");
			return;
		}

		if(iCountOfConditions == 1 && !m_strLogical1.IsEmpty())
		{
			m_strConditions += m_strLogical1 + m_strCommonUseIF;
			iCountOfConditions += 1;
			goto HERE;
		}
		if(iCountOfConditions == 2 && !m_strLogical1.IsEmpty())
		{
			i = m_strConditions.FindOneOf("|&");
			m_strConditions.Delete(i, -1);
			m_strConditions += m_strLogical1 + m_strCommonUseIF;
			goto HERE;
		}
		if(iCountOfConditions == 3 && !m_strLogical1.IsEmpty() && !m_strLogical2.IsEmpty())
		{
			i = m_strConditions.FindOneOf("|&");
			strTemp = m_strConditions.Mid(0, i + 2);
			m_strConditions.Delete(0, i + 2);
			j = m_strConditions.FindOneOf("|&");
			m_strConditions.Delete(0, j);
			m_strConditions = strTemp + m_strCommonUseIF + m_strConditions;
			goto HERE;
		}
	}

	//如果是条件3
	if(iWhichIF == 3)
	{
		if(iCountOfConditions < 2)
		{
			AfxMessageBox("请先指定条件1和2");
			return;
		}

		if(iCountOfConditions == 2 && !m_strLogical2.IsEmpty())
		{
			m_strConditions += m_strLogical2 + m_strCommonUseIF;
			iCountOfConditions += 1;
			goto HERE;
		}
		if(iCountOfConditions == 3 && !m_strLogical2.IsEmpty())
		{
			i = m_strConditions.FindOneOf("|&");
			strTemp = m_strConditions.Mid(0, i + 2);
			m_strConditions.Delete(0, i + 2);
			j = m_strConditions.FindOneOf("|&");
			m_strConditions = strTemp + m_strConditions.Mid(0, j + 2) + m_strCommonUseIF;
			goto HERE;
		}
	}

HERE:
	UpdateData(FALSE);

	switch(m_iWhichNext)
	{
	case 0:
		m_strTotalNext1 = "if(" + m_strConditions + ")"
						+ "do(" + m_strDO + ")"
						+ "goto(" + m_strNextIID + ")";
		break;

	case 1:
		m_strTotalNext2 = "if(" + m_strConditions + ")"
						+ "do(" + m_strDO + ")"
						+ "goto(" + m_strNextIID + ")";
		break;

	case 2:
		m_strTotalNext3 = "if(" + m_strConditions + ")"
						+ "do(" + m_strDO + ")"
						+ "goto(" + m_strNextIID + ")";
		break;

	default:
		break;
	}
}

void CSourceCreatorDlg::OnSelchangeComboCommonuseDo() 
{
HWND hwndCombo;
char aszTemp[1000];
CString strTemp;
int iIndex;

	GetDlgItem(IDC_COMBO_COMMONUSE_DO, &hwndCombo);
	if((iIndex = ::SendMessage(hwndCombo, CB_GETCURSEL, 0, 0)) == CB_ERR)
		return;
	if(::SendMessage(hwndCombo, CB_GETLBTEXT, iIndex, (LPARAM)aszTemp) == CB_ERR)
		return;
	m_strCommonUseDO = aszTemp;
	UpdateData(FALSE);
//	UpdateData(TRUE);
	if(m_strDO.IsEmpty())
	{
		m_strDO = m_strCommonUseDO;
	}
	else
	{
		if(m_strDO[m_strDO.GetLength() - 1] == ':')
		{
			m_strDO += m_strCommonUseDO;
		}
		else
		{
			m_strDO += ":" + m_strCommonUseDO;
		}
	}

	UpdateData(FALSE);
}

void CSourceCreatorDlg::OnEditchangeComboGlobal(UINT uiControlID) 
{
HWND hwndCombo, hwndEdit;
char aszTemp[1000];
int iIndex;

	GetDlgItem(IDC_COMBO_GLOBALSTRING, &hwndCombo);
	if((iIndex = ::SendMessage(hwndCombo, CB_GETCURSEL, 0, 0)) == CB_ERR)
		return;
	if(::SendMessage(hwndCombo, CB_GETLBTEXT, iIndex, (LPARAM)aszTemp) == CB_ERR)
		return;
	UpdateData(FALSE);
//	UpdateData(TRUE);

	if((hwndEdit = ::GetDlgItem(this->m_hWnd, uiLastFocus)) != NULL)
	{
		::SendMessage(hwndEdit, WM_SETTEXT, 0, (LPARAM)aszTemp);
		UpdateData();
	}

	UpdateData(FALSE);
}

void CSourceCreatorDlg::OnRadioNext1() 
{
	UpdateData();
}

void CSourceCreatorDlg::OnRadioNext2() 
{
	UpdateData();
	if(m_strTotalNext1 == "")
	{
		AfxMessageBox("请先指定条件1");
		m_iWhichNext = 0;
		UpdateData(FALSE);
		return;
	}
}

void CSourceCreatorDlg::OnRadioNext3() 
{
	UpdateData();
	if(m_strTotalNext1 == "")
	{
		AfxMessageBox("请先指定条件1");
		m_iWhichNext = 0;
		UpdateData(FALSE);
		return;
	}
	if(m_strTotalNext2 == "")
	{
		AfxMessageBox("请先指定条件2");
		m_iWhichNext = 1;
		UpdateData(FALSE);
		return;
	}
}

void CSourceCreatorDlg::OnButtonCreatesource() 
{
char aszTemp[1000];
CString strTemp;

	UpdateData();

	//校验所有的KEY是否都有值
	if(m_strIID == ""
		|| m_iAction < 0
		|| m_strInParam == ""
		|| m_strOutParam == ""
		|| m_strOnError == "")
	{
		AfxMessageBox("所有的KEY不能为空");
		return;
	}

	//得到IID
	strTemp += "[" + m_strIID + "]" + "\r\n";

	//得到ACTION
	::SendMessage(::GetDlgItem(this->m_hWnd, IDC_COMBO_ACTION), CB_GETLBTEXT, m_iAction, (LPARAM)aszTemp);
	strTemp = strTemp + "action=" + aszTemp + "\r\n";

	//得到INPARAM
	strTemp += "inparam=" + m_strInParam + "\r\n";

	//得到NEXT
	strTemp += "next=" + m_strTotalNext1 + m_strTotalDo1 + ",\r\n";
	if(m_strTotalNext2 != "")
		strTemp += m_strTotalNext2 + m_strTotalDo2 + ",\r\n";
	if(m_strTotalNext3 != "")
		strTemp += m_strTotalNext3 + m_strTotalDo3 + ",\r\n";

	//得到OUTPARAM
	strTemp += "outparam=" + m_strOutParam + "\r\n";

	//得到ONERROR
	strTemp += "onerror=" + m_strOnError + "\r\n\r\n";

	AfxMessageBox(LPCTSTR(strTemp));
	m_strSourceWindow = strTemp;
	UpdateData(FALSE);
}

void CSourceCreatorDlg::OnOK()
{
char aszTemp[100], aszTemp2[1000];

	CWnd *pwnd = GetFocus();
	CWnd *pwnd2 = pwnd->GetParent();	//注意:这才是COMBOX的HWND, GETFOCUS()找到的是COMBOX中的EDITBOX的HWND
	UINT id = ::GetDlgCtrlID(pwnd2->m_hWnd);
	if(id == IDC_COMBO_GLOBALSTRING
		|| id == IDC_COMBO_GLOBALINTEGER
		|| id == IDC_COMBO_GLOBALFLOAT
		|| id == IDC_COMBO_COMMONUSE_DO
		|| id == IDC_COMBO_COMMONUSE_IF)
	{
		::SendMessage(pwnd2->m_hWnd, WM_GETTEXT, sizeof(aszTemp), (LPARAM)aszTemp);
		if(::SendMessage(pwnd2->m_hWnd, CB_FINDSTRING, 0, (LPARAM)aszTemp) == CB_ERR)
		{
			::SendMessage(pwnd2->m_hWnd, CB_ADDSTRING, 0, (LPARAM)aszTemp);
		}

		if(uiLastFocus == 0)
			return;
		HWND hwnd = ::GetDlgItem(this->m_hWnd, uiLastFocus);
		::SendMessage(hwnd, WM_GETTEXT, sizeof(aszTemp2), (LPARAM)aszTemp2);
		strcat(aszTemp2, aszTemp);
		::SendMessage(hwnd, WM_SETTEXT, 0, (LPARAM)aszTemp2);

	}
}

void CSourceCreatorDlg::OnChangeEditNextiid() 
{
	UpdateData();
	
	switch(m_iWhichNext)
	{
	case 0:
		if(!m_strTotalNext1.IsEmpty())
		{
			if(m_strTotalNext1[0] != 'i')
			{
				m_strTotalNext1 = "goto(" + m_strNextIID + ")";
			}
		}
		else
		{
				m_strTotalNext1 = "goto(" + m_strNextIID + ")";
		}
		break;

	case 1:
		if(!m_strTotalNext2.IsEmpty())
		{
			if(m_strTotalNext2[0] != 'i')
			{
				m_strTotalNext2 = "goto(" + m_strNextIID + ")";
			}
		}
		else
		{
				m_strTotalNext2 = "goto(" + m_strNextIID + ")";
		}
		break;

	case 2:
		if(!m_strTotalNext3.IsEmpty())
		{
			if(m_strTotalNext3[0] != 'i')
			{
				m_strTotalNext3 = "goto(" + m_strNextIID + ")";
			}
		}
		else
		{
				m_strTotalNext3 = "goto(" + m_strNextIID + ")";
		}
		break;

	default:
		break;
	}
}

void CSourceCreatorDlg::OnChangeEditDo() 
{
	UpdateData();
	switch(m_iWhichNext)
	{
	case 0:
		m_strTotalDo1 = "do(" + m_strDO + ")";
		break;

	case 1:
		m_strTotalDo2 = "do(" + m_strDO + ")";
		break;

	case 2:
		m_strTotalDo3 = "do(" + m_strDO + ")";
		break;

	default:
		break;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -