//---------------------------------------------------------------------------
void __fastcall TfrmEditReplaceRule::btnOkClick(TObject *Sender)
{
  try
  {
    int n = StrToInt(txtReplaceCount->Text);
    if(n < 0)
      throw new Exception("");
  }
  catch(...)
  {
    MessageBox(Handle,"替换次数必须是一个大于-1的整数!","提示",MB_OK | MB_ICONWARNING);
    txtReplaceCount->SetFocus();
    txtReplaceCount->SelectAll();
    return;
  }
  if(txtFrom->Text != From || txtTo->Text != To || cbxPosition->Text != Position || Count != txtReplaceCount->Text)
  {
    From     = XMLEncode(txtFrom->Text);
    To       = XMLEncode(txtTo->Text);
    Position = cbxPosition->Text;
    Count    = txtReplaceCount->Text;
    ModalResult = mrOk;
  }
  else
    ModalResult = mrCancel;
}
Пример #2
0
void CSvsFile::SaveXML()
{
	ofstream outStream(m_strFile.c_str());
	if (!outStream)
	{
		string errorStr = m_strFile;
		errorStr = errorStr + "打开时候发生错误,请检查是否有其他程序正在使用中!";
		GenErr(errorStr);
	}
	outStream << sStrHeadInfo;
	string strTopLeft = m_vecTR[0][0].m_sTDValue;
	trim(strTopLeft);
	if(strTopLeft.size() >= 5)
	{
		strTopLeft = strTopLeft.substr(0, 5);
		//transform(strTopLeft.begin(), strTopLeft.end(), strTopLeft.begin(), toupper);	//这句不知为何运行报错
		//if(strcmp(strupr(const_cast<char*>(strTopLeft.c_str())), "NOTE:") == 0 && m_vecTR.size() > 1)
		if(strTopLeft == "NOTE:" && m_vecTR.size() > 1)
			m_uTitleLineNo = 1;
	}
	vector<string> m_sColName;
	//printf("m_uTitleLineNo = %d, m_vecTR[m_uTitleLineNo].size() = %d\n", m_uTitleLineNo, m_vecTR[m_uTitleLineNo].size());
	//m_sColName.resize(m_vecTR[m_uTitleLineNo].size());		//这句不知为何在Release下会报错
	for(size_t col = 0; col < m_vecTR[m_uTitleLineNo].size(); ++col)
	{
		m_sColName.push_back(m_vecTR[m_uTitleLineNo][col].m_sTDValue);
		XMLEncode(m_sColName.back(), true);
		m_sColName.back() = gbk_to_utf8(m_sColName.back());
	}
	for(size_t row = 0; row < m_vecTR.size(); ++row)
	{
		outStream << "<tr>\n";
		for(size_t col = 0; col < m_vecTR[row].size(); ++col)
		{
			outStream << "<td n=\"" << m_sColName[col] << "\">\n<p t=\"";
			TableData& aTD = m_vecTR[row][col];
			switch(aTD.m_eTDType)
			{
			case eTDT_None:
				outStream << "\"/>";
				break;
			case eTDT_String:
				XMLEncode(aTD.m_sTDValue);
				outStream << "string\">" << gbk_to_utf8(aTD.m_sTDValue) << "</p>";
				break;
			case eTDT_Float:
				outStream << "float\">" << aTD.m_sTDValue << "</p>";
				break;
			default:
				{
					stringstream str;
					str << aTD.m_eTDType;
					GenErr("CSvsFile::SaveXML() aTD.m_eTDType类型错误", str.str());
				}
			}
			outStream << "</td>\n";
		}
		outStream << "</tr>\n";
	}
	outStream << sStrEndInfo;
	outStream.close();
}