void CUserAddDlg::OnBnClickedOk()
{
	UpdateData();

	m_strName.TrimLeft();
	m_strName.TrimRight();
	m_strGroupName.TrimLeft();
	m_strGroupName.TrimRight();
	
	//验证输入的数据是否合法
	if ( "" == m_strName )
	{
		MessageBox(_CS("AccountMSG.EmptyName"), _CS("OneClick.Prompt"));
		return;
	}
	if(m_strName[0]=='&')
	{
		
		MessageBox(_CS("AccountMSG.ErrorName"), _CS("OneClick.Prompt"));
		
		return;
	}
	if(m_strName.Find('.')!=-1||m_strName.Find('[')!=-1||m_strName.Find(']')!=-1 || m_strName.Find('%') != -1)
	{
		
		MessageBox(_CS("AccountMSG.ErrorName"), _CS("OneClick.Prompt"));
		return;
	}

	//验证密码是否匹配
	if ( m_strPsw != m_strConfirm )
	{
		MessageBox(_CS("Error.PwdErr"), _CS("OneClick.Prompt"));
		return;
	}
	
	//验证用户名是否已经存在

	if ( FindUserName(m_strName.GetBuffer(0)) )
	{
		MessageBox(_CS("AccountMSG.AddUserExist"), _CS("OneClick.Prompt"));
		return;
	}

	USER_INFO userInfo;

	//获取选择的权限列表
	int nIndex = 0;
	int nSize = m_listAuthority.GetItemCount();
	for ( int i = 0; i < nSize; i ++ )
	{
		if ( m_listAuthority.GetCheck(i) )
		{
			CString strName = (char *)m_listAuthority.GetItemData(i);
			strcpy( userInfo.rights[nIndex ++], strName.GetBuffer(0) );
		}
	}
	userInfo.rigthNum = nIndex;
	if ( nIndex <= 0 )
	{
		MessageBox(_CS("AccountMSG.EmptyAuthority"), _CS("OneClick.Prompt"));

		return;
	}

	userInfo.reserved = false;
	userInfo.shareable = m_checkReuseable.GetCheck();
	strcpy ( userInfo.Groupname, m_strGroupName.GetBuffer(0) );
	strcpy ( userInfo.memo, m_strDescribe.GetBuffer(0) );
	strcpy ( userInfo.name, m_strName.GetBuffer(0) );
	strcpy ( userInfo.passWord, m_strPsw.GetBuffer(0) );
	
		//保存用户	
		int bRet = SaveuserInfo(&userInfo);
		if ( bRet <= 0 )
		{
			CString strMsg(_CS("User.AddUserFailed"));
			CString strError = GetSdkErrorInfo( bRet );
			strMsg += strError;
			MessageBox(strMsg, _CS("OneClick.Prompt"));

			return;
		}
	

	MessageBox(_CS("AccountMSG.AddUserSuccess"), _CS("OneClick.Prompt"));
	OnOK();
}
//---------------------------------------------------------------------------
void TFormScoreTests::ReadFile(const String& filename)
{
  const int row = StringGridStudents->RowCount - 1;
  const std::string file_stripped = RemoveExtension(RemovePath(filename.c_str()));
  ++StringGridStudents->RowCount;
  StringGridStudents->Cells[0][row] = row;
  StringGridStudents->Cells[1][row] = file_stripped.c_str();
  StringGridStudents->Cells[2][row] = "";
  StringGridStudents->Cells[3][row] = "";

  const int key = EditKey->Text.ToInt();
  const int penalty = EditPenalty->Text.ToInt();
  const Encranger e(key);


  //Load file
  std::vector<std::string> v = FileToVector(filename.c_str());

  const int sz = v.size();
  for (int i=0; i!=sz; ++i)
  {
    //Deencrypt file
    v[i] = e.Deencrypt(v[i]);
    //Remove asterisks
    v[i] = ReplaceAll(v[i],"*","");
  }

  const std::string username = FindUserName(v);

  if (username.empty())
  {
    StringGridStudents->Cells[3][row] = "Username not found";
    StringGridStudents->Cells[2][row] = "1.0 or 1.1";
    return;
  }

  if (username != file_stripped)
  {
    StringGridStudents->Cells[3][row] = "Filename differs from username";
    StringGridStudents->Cells[2][row] = "1.1";
    return;
  }


  int n_correct = 0;
  const int n_questions = CountQuestions(v);
  LabelNquestions->Caption = "#questions: " + IntToStr(n_questions);

  for (int i=0; i!=sz; ++i)
  {
    if (v[i].empty()) continue;

    const std::vector<std::string> line_markup = SeperateString(v[i],",");

    //Replace {comma} by a comma for each std::string in v
    const std::vector<std::string> line = ReplaceAll(line_markup,"{comma}",",");

    OutputDebugString(line.size() >= 1 ? line[0].c_str() : "line[0] = {}");
    OutputDebugString(line.size() >= 2 ? line[1].c_str() : "line[1] = {}");
    OutputDebugString(line.size() >= 3 ? line[2].c_str() : "line[2] = {}");
    OutputDebugString(line.size() >= 4 ? line[3].c_str() : "line[3] = {}");

    //assert(line.size() == 2); WORKAROUND



    if (line[0]=="NAME") continue;
    const bool is_correct = (line[line.size()-1]=="Y"); //WORKAROUND
    assert(line[line.size()-1]=="Y" || line[line.size()-1]=="N"); //WORKAROUND 
    if (is_correct) ++n_correct;
    ScoreQuestion(line[0],is_correct);
  }

  //Calculate student's score
  assert(n_questions - penalty > 0);
  const double fraction
      = static_cast<double>(n_correct - penalty)
      / static_cast<double>(n_questions - penalty);
  const double init_score = 1.0 + (9.0 * fraction);
  const double score_above_one = (init_score < 1.0 ? 1.0 : init_score);
  const double score_below_ten = (score_above_one > 10.0 ? 10.0 : score_above_one);
  const double score = score_below_ten;

  StringGridStudents->Cells[2][row] = score;
}