コード例 #1
0
        private void ButtonSaveFillBlank_Click(object sender, RoutedEventArgs e)
        {
            int x = 0;

            while (File.Exists(exerciseDataFolderPath + x.ToString("X8") + ".json"))
            {
                x++;
            }
            string fileName = exerciseDataFolderPath + x.ToString("X8") + ".json";

            EnglishFillBlank englishFillBlank = new EnglishFillBlank();

            englishFillBlank.ExerciseCommonData = GetExerciseCommonData();
            englishFillBlank.Text            = TextBoxFillBlank.Text;
            englishFillBlank.BlankDefination = BlankDefination;
            englishFillBlank.Answer          = TextBoxFillBlankAnswer.Text;

            string json = JsonConvert.SerializeObject(englishFillBlank, Formatting.Indented, new JsonSerializerSettings
            {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            });

            if (!Directory.Exists(exerciseDataFolderPath))
            {
                Directory.CreateDirectory(exerciseDataFolderPath);
            }
            File.WriteAllText(fileName, json);

            if (CheckBoxAutoClear.IsChecked == true)
            {
                TextBoxFillBlank.Text       = "";
                TextBoxFillBlankAnswer.Text = "";
            }
        }
コード例 #2
0
        private void ButtonSaveAll_Click(object sender, RoutedEventArgs e)
        {
            string output = "Output.rtf";

            RichTextBox richTextBox = new RichTextBox();

            richTextBox.FontSize   = 14;
            richTextBox.FontFamily = new FontFamily("Times New Roman");
            richTextBox.Document.Blocks.Clear();
            richTextBox.Document.LineHeight = 25;

            bool[] isFileExist = new bool[0x3F3F3F3F];
            int    maxN        = 0;

            foreach (FileInfo fileInfo in new DirectoryInfo(exerciseDataFolderPath).GetFiles())
            {
                int n = Convert.ToInt32(Path.GetFileNameWithoutExtension(fileInfo.FullName), 16);
                maxN           = Math.Max(n, maxN);
                isFileExist[n] = true;
            }

            int k = 1;

            for (int i = 0; i <= maxN; i++)
            {
                EnglishFillBlank englishFillBlank = JsonConvert.DeserializeObject <EnglishFillBlank>(
                    File.ReadAllText(exerciseDataFolderPath + i.ToString("X8") + ".json"));
                if (englishFillBlank.ExerciseCommonData.OutputMark)
                {
                    string text = englishFillBlank.Text;
                    if (CheckBoxAutoFix.IsChecked == true)
                    {
                        text = TextAutoFix(text);
                    }
                    if (englishFillBlank.ExerciseCommonData.SourceFrom != "")
                    {
                        text = "[" + englishFillBlank.ExerciseCommonData.SourceFrom + "] " + text;
                    }
                    text = text.Replace(englishFillBlank.BlankDefination, "__________");
                    RichTextBoxAppend(richTextBox,
                                      string.Format("{0}\t{1}", k++ + ".", text));
                    //string.Format("{0,-5}{1}", k++ + ".", text));
                }
            }

            RichTextBoxAppend(richTextBox, "");
            RichTextBoxAppend(richTextBox, "");
            RichTextBoxAppend(richTextBox, "答案:");

            k = 1;
            for (int i = 0; i <= maxN; i++)
            {
                EnglishFillBlank englishFillBlank = JsonConvert.DeserializeObject <EnglishFillBlank>(
                    File.ReadAllText(exerciseDataFolderPath + i.ToString("X8") + ".json"));
                if (englishFillBlank.ExerciseCommonData.OutputMark)
                {
                    RichTextBoxAppend(richTextBox, string.Format("{0}\t{1}", k++ + ".", englishFillBlank.Answer));
                }
            }

            File.WriteAllText(output, RichTextBoxEx.RTF(richTextBox));
        }