public QuestionnaireModel Create(QuestionnaireModel question) { if (!string.IsNullOrEmpty(question.id)) { throw new Exception("try to create questionnaire with id"); } var request = _authService.AddToken(WebRequest.Create(RestQuestionnaireApiUrl) as HttpWebRequest); request.Method = "POST"; request.ContentType = "application/json"; var bts = Encoding.UTF8.GetBytes(Serialize(question)); request.ContentLength = bts.Length; using (var reqStream = request.GetRequestStream()) { reqStream.Write(bts, 0, bts.Length); reqStream.Close(); } using (var response = (HttpWebResponse)request.GetResponse()) { using (var reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8)) { var responseData = reader.ReadToEnd(); var questionnareObject = JsonConvert.DeserializeObject<QuestionnaireModel>(responseData); return questionnareObject; } } }
public bool Compare(QuestionnaireModel q1, QuestionnaireModel q2) { if (q1.id != q2.id) { throw new Exception("comparing with different id"); } return q1.choices == q2.choices; }
private void setSlideButton_Click(object sender, RibbonControlEventArgs e) { var slide = _selectedSlide; var window = new QuestionnaireOptionsWindow(); if (_questionnaireUtil.Check(slide)) { window.Initialize(_questionnaireUtil.Deserialize(slide)); } if (window.ShowDialog() == true) { var choices = (int) window.ChoicesComboBox.SelectionBoxItem; if (!_questionnaireUtil.Check(slide)) { //CreateQuestionnaireSlideRecord var questionnaire = new QuestionnaireModel() { choices = choices }; try { CreateQuestionnaireSlideRecord(slide, questionnaire); } catch { _questionnaireUtil.Unmark(slide); MessageBox.Show("问卷设置失败了,这可能是个网络错误"); } finally { RefreshSetAndAdd(); } } else { //UpdateSelectedSlide var questionnaire = _questionnaireUtil.Deserialize(slide); questionnaire.choices = choices; _questionnaireUtil.Mark(slide, questionnaire); } } }
private void addNewSlideButton_Click(object sender, RibbonControlEventArgs e) { var window = new QuestionnaireOptionsWindow(); if (window.ShowDialog() == true) { var questionnaire = new QuestionnaireModel { choices = (int)window.ChoicesComboBox.SelectionBoxItem }; var slide = AddSlideByQuestionnaire(questionnaire); CreateQuestionnaireSlideRecord(slide, questionnaire); } }
private async void CreateQuestionnaireSlideRecord(PowerPoint.Slide slide, QuestionnaireModel questionnaire) { try { var created = await _questionnaireUtil.CreateAsync(questionnaire); _questionnaireUtil.Mark(slide, created); } catch (WebException) { slide.Delete(); MessageBox.Show("问卷添加失败了, 这可能是个网络错误."); } }
private PowerPoint.Slide AddSlideByQuestionnaire(QuestionnaireModel questionnaire) { var index = Globals.ThisAddIn.Application.ActivePresentation.Slides.Count + 1; var slide = AppWapper.App.ActivePresentation.Slides.Add(index, PowerPoint.PpSlideLayout.ppLayoutBlank); var textbox = slide.Shapes.AddTextbox(Office.MsoTextOrientation.msoTextOrientationHorizontal, 50, 50, 600, 50);//向当前PPT添加文本框 textbox.TextFrame.TextRange.Text = "调查:"; textbox.TextFrame.TextRange.Font.Size = 48;//设置文本字体大小 for (var i = 0; i < questionnaire.choices; i++) { var choiceTextbox = slide.Shapes.AddTextbox(Office.MsoTextOrientation.msoTextOrientationHorizontal, 50, 120 + 40 * i, 400, 50);//向当前PPT添加文本框 choiceTextbox.TextFrame.TextRange.Text = ChoiceString[i] + ":"; choiceTextbox.TextFrame.TextRange.Font.Size = 24;//设置文本字体大小 } _selectedSlide = slide; return _selectedSlide; }
public Task<QuestionnaireModel> UpdateAsync(QuestionnaireModel question) { return Task.Factory.StartNew(() => Update(question)); }
public string Serialize(QuestionnaireModel questionnaire) { return JsonConvert.SerializeObject(questionnaire); }
public void Mark(Slide slide, QuestionnaireModel questionnaire) { slide.Name = QuestionnaireMark + Serialize(questionnaire); }
public void Initialize(QuestionnaireModel questionnaire) { ChoicesComboBox.SelectedItem = questionnaire.choices; }