private void buttonConfirm_Click(object sender, EventArgs e) { int wordsNumber = 0; if (!int.TryParse(textBoxNumber.Text.Trim(), out wordsNumber)) { textBoxNumber.Focus(); MessageBox.Show("请输入正确的数字", "提示信息"); return; } if (_dtVocabulary.Rows.Count == 0) { MessageBox.Show("没有可测验的单词了", "提示信息"); return; } if (wordsNumber == 0) { textBoxNumber.Focus(); MessageBox.Show("请输入正确的数字", "提示信息"); return; } //生成测验的单词列表 if (_dtVocabulary.Rows.Count < wordsNumber) { wordsNumber = _dtVocabulary.Rows.Count; } List <long> vocabularyIds = new List <long>(); for (int i = 0; i < wordsNumber; i++) { vocabularyIds.Add((long)_dtVocabulary.Rows[i]["VocabularyId"]); } //取唯一id NoodleIdGeneratorRequest noodleIdGeneratorRequest = new NoodleIdGeneratorRequest(); noodleIdGeneratorRequest.ClientRequestNo = Guid.NewGuid().ToString("N"); List <long> ids = _noodleTokenClient.DoPost(noodleIdGeneratorRequest); //生成测验记录 ExerciseAddRequest exerciseAddRequest = new ExerciseAddRequest(); exerciseAddRequest.ClientRequestNo = Guid.NewGuid().ToString("N"); exerciseAddRequest.Id = ids[0]; exerciseAddRequest.Comment = textBoxComment.Text.Trim(); exerciseAddRequest.VocabularyIds = vocabularyIds; _noodleTokenClient.DoPost(exerciseAddRequest); //刷新数据 MessageBox.Show("添加测验记录成功", "提示信息"); DialogResult = DialogResult.OK; }
private void saveWords() { //填充Words对象 Words words = new Words(); DataRow dr; int focusRow; if (_currentWordsId == 0) { NoodleIdGeneratorRequest noodleIdGeneratorRequest = new NoodleIdGeneratorRequest(); noodleIdGeneratorRequest.ClientRequestNo = Guid.NewGuid().ToString("N"); List <long> ids = _noodleTokenClient.DoPost(noodleIdGeneratorRequest); _currentWordsId = ids[0]; dr = _dtWords.NewRow(); dr["Id"] = _currentWordsId; dr["DictionaryId"] = _currentDictionaryId; focusRow = _dtWords.Rows.Count; } else { DataRow[] drs = _dtWords.Select("Id = " + _currentWordsId); dr = drs[0]; focusRow = dataGridViewWords.CurrentCell.RowIndex; } dr["Spelling"] = textBoxSpelling.Text; dr["Pronunciation"] = textBoxPronunciation.Text; dr["Explanation"] = textBoxExplanation.Text; if (dr.RowState.Equals(DataRowState.Detached)) { _dtWords.Rows.Add(dr); } _dtWords.AcceptChanges(); dataGridViewWords.CurrentCell = dataGridViewWords.Rows[focusRow].Cells["Spelling"]; words.Id = (long)dr["Id"]; words.DictionaryId = (long)dr["DictionaryId"]; words.Spelling = textBoxSpelling.Text; words.Pronunciation = textBoxPronunciation.Text; words.Explanation = textBoxExplanation.Text; WordsSaveRequest request = new WordsSaveRequest(); request.ClientRequestNo = Guid.NewGuid().ToString("N"); request.Words = words; _noodleTokenClient.DoPost(request); }
private void buttonSave_Click(object sender, EventArgs e) { //填充Dictionary对象 Dictionary dictionary = new Dictionary(); DataRow dr; if (_currentDictionaryId == 0) { NoodleIdGeneratorRequest noodleIdGeneratorRequest = new NoodleIdGeneratorRequest(); noodleIdGeneratorRequest.ClientRequestNo = Guid.NewGuid().ToString("N"); List <long> ids = _noodleTokenClient.DoPost(noodleIdGeneratorRequest); _currentDictionaryId = ids[0]; dr = _dtDictionary.NewRow(); dr["Id"] = _currentDictionaryId; dr["PublicFlag"] = UserInfo.AdminFlag > 0 ? "Y" : "N"; } else { DataRow[] drs = _dtDictionary.Select("Id = " + _currentDictionaryId); dr = drs[0]; } dr["Name"] = textBoxDictionary.Text; dr["Publisher"] = textBoxPublisher.Text; dr["ValidFlag"] = checkBoxValidFlag.Checked ? "Y" : "N"; if (dr.RowState.Equals(DataRowState.Detached)) { _dtDictionary.Rows.Add(dr); } _dtDictionary.AcceptChanges(); dictionary.Id = (long)dr["Id"]; dictionary.Name = textBoxDictionary.Text; dictionary.Publisher = textBoxPublisher.Text; dictionary.ValidFlag = (string)dr["ValidFlag"]; dictionary.PublicFlag = (string)dr["PublicFlag"]; DictionarySaveRequest request = new DictionarySaveRequest(); request.Dictionary = dictionary; _noodleTokenClient.DoPost(request); }
private void buttonConfirm_Click(object sender, EventArgs e) { if (textBoxMemoryLine.Text == null || textBoxMemoryLine.Text.Trim().Length == 0) { textBoxMemoryLine.Focus(); throw new ArgumentException("请输入正确的记忆曲线节点信息"); } if (textBoxNumber.Text == null || textBoxNumber.Text.Trim().Length == 0) { textBoxNumber.Focus(); throw new ArgumentException("请输入正确的单词数量"); } int wordsNumber = 0; if (!int.TryParse(textBoxNumber.Text.Trim(), out wordsNumber)) { textBoxNumber.Focus(); throw new ArgumentException("请输入正确的单词数量"); } //解析记忆曲线 string[] memoryLineArray = textBoxMemoryLine.Text.Trim().Split(','); if (memoryLineArray.Length < 4) { textBoxMemoryLine.Focus(); throw new ArgumentException("请输入正确的记忆曲线节点信息"); } int schedule1 = 0; if (!int.TryParse(memoryLineArray[0], out schedule1)) { textBoxMemoryLine.Focus(); throw new ArgumentException("请输入正确的记忆曲线节点信息"); } int schedule2 = 0; if (!int.TryParse(memoryLineArray[1], out schedule2)) { textBoxMemoryLine.Focus(); throw new ArgumentException("请输入正确的记忆曲线节点信息"); } int schedule3 = 0; if (!int.TryParse(memoryLineArray[2], out schedule3)) { textBoxMemoryLine.Focus(); throw new ArgumentException("请输入正确的记忆曲线节点信息"); } int schedule4 = 0; if (!int.TryParse(memoryLineArray[3], out schedule4)) { textBoxMemoryLine.Focus(); throw new ArgumentException("请输入正确的记忆曲线节点信息"); } //取唯一id NoodleIdGeneratorRequest noodleIdGeneratorRequest = new NoodleIdGeneratorRequest(); noodleIdGeneratorRequest.ClientRequestNo = Guid.NewGuid().ToString("N"); List <long> ids = _noodleTokenClient.DoPost(noodleIdGeneratorRequest); //生成背诵记录 ReciteAddRequest reciteAddRequest = new ReciteAddRequest(); reciteAddRequest.ClientRequestNo = Guid.NewGuid().ToString("N"); reciteAddRequest.Id = ids[0]; reciteAddRequest.Comment = textBoxComment.Text; reciteAddRequest.WordsNumber = wordsNumber; reciteAddRequest.Schedule1 = schedule1; reciteAddRequest.Schedule2 = schedule4; reciteAddRequest.Schedule3 = schedule3; reciteAddRequest.Schedule4 = schedule4; _noodleTokenClient.DoPost(reciteAddRequest); //查询生成的结果 ReciteWordsRequest reciteWordsRequest = new ReciteWordsRequest(); reciteWordsRequest.ClientRequestNo = Guid.NewGuid().ToString("N"); reciteWordsRequest.ReciteId = ids[0]; List <ReciteWordsDto> reciteWordsDtos = _noodleTokenClient.DoPost(reciteWordsRequest); DataTable dtReciteWords = DataTableHelper.ToDataTable <ReciteWordsDto>(reciteWordsDtos); dataGridViewReciteWords.DataSource = dtReciteWords; }