private void GetSelectionPicture(int type) { if (Globals.ThisAddIn.Application.Selection.Range.Text != null) { //保存range数据 this.label1.Visible = false; exerciseUnClassified = jsonFileHelper.GetProblemSetFromFile(Globals.ThisAddIn.exerciseJsonPath + "exerciseUnClassified.json"); string imgName = imgHelper.GetSelectionImg("exerciseUnClassified"); if (imgName.Equals("")) { return; } Image img = Image.FromFile(Globals.ThisAddIn.exerciseJsonPath + "exerciseUnClassified\\" + imgName); this.textBox1.Visible = false; this.pictureBox1.Visible = true; //this.pictureBox1.Width = 660; double beishu = (double)660 / (double)img.Width; this.pictureBox1.Height = (int)(img.Height * beishu); this.panel1.Height = panle1_Height + this.pictureBox1.Height - pictureBox1_Height; this.pictureBox1.Image = img; exerciseTemp.Question = imgName; exerciseTemp.QuestionType = type; if (this.button7.Visible == true) { ExerciseWithRange exRange = new ExerciseWithRange(); exRange.RangeStart = Globals.ThisAddIn.Application.Selection.Range.Start; exRange.RangeEnd = Globals.ThisAddIn.Application.Selection.Range.End; rangeList.Add(exRange); try { jsonFileHelper.WriteFileString(JsonConvert.SerializeObject(rangeList), @"D:\新建文件夹\imgJsonList.json"); } catch { } } //exerciseUnClassified.ExerciseList.Add(exerciseTemp); //jsonFileHelper.WriteFileString(JsonConvert.SerializeObject(exerciseUnClassified), Globals.ThisAddIn.exerciseJsonPath + "exerciseUnClassified.json"); } }
public void SetQuestionImg() { string filePath = Globals.ThisAddIn.exerciseJsonPath + paperName + ".json"; paper = jsonFileHelper.GetPaperFromFile(filePath); problemSet = jsonFileHelper.GetProblemSetFromFile(filePath); //Exercise pointExercise = new Exercise(); if (paper.PaperNodeList.Count != 0 && problemSet.ExerciseList.Count == 0) { exerciseOrderCount = 0; pointExercise = GetExerciseByOrder(paper.PaperNodeList as List <PaperNode>); } else if (paper.PaperNodeList.Count == 0 && problemSet.ExerciseList.Count != 0) { exerciseOrderCount = 0; pointExercise = GetExerciseByOrder(problemSet.ExerciseList as List <Exercise>); } ReSetQuestionDetail(); }
private void FormTest_Load(object sender, EventArgs e) { string str = jsonFileHelper.GetFileString(@"D:\新建文件夹\imgJsonList.json"); List <ExerciseWithRange> rangeExerciseList = new List <ExerciseWithRange>(); rangeExerciseList = (List <ExerciseWithRange>)JsonConvert.DeserializeObject(str, rangeExerciseList.GetType()); ProblemSet problemSet = new ProblemSet(); problemSet = jsonFileHelper.GetProblemSetFromFile(Globals.ThisAddIn.exerciseJsonPath + "exerciseUnClassified.json"); List <Exercise> ExerciseList = problemSet.ExerciseList; int oldImgLocation_x = 0; int oldImgWidth = 660; int marginTop = 0; if (rangeExerciseList.Count != 0) { for (int i = 0; i < rangeExerciseList.Count; i++) { Image img = Image.FromFile(@"D:\新建文件夹\" + rangeExerciseList[i].Question); marginTop += img.Height; } this.panel1.Height = marginTop + 100; marginTop = 0; for (int i = 0; i < rangeExerciseList.Count; i++) { Image img = Image.FromFile(@"D:\新建文件夹\" + rangeExerciseList[i].Question); PictureBox pictureBox = new PictureBox(); pictureBox.Image = img; pictureBox.SizeMode = PictureBoxSizeMode.Zoom; pictureBox.Size = new System.Drawing.Size(img.Width, img.Height); pictureBox.Location = new Point(0, marginTop); this.panel1.Controls.Add(pictureBox); marginTop += img.Height; if (img.Width > oldImgWidth) { oldImgWidth = img.Width; } if (pictureBox.Location.X + pictureBox.Width > oldImgLocation_x) { oldImgLocation_x = pictureBox.Location.X + pictureBox.Width; } } } oldImgLocation_x += 10; marginTop = 0; if (ExerciseList.Count != 0) { for (int i = 0; i < ExerciseList.Count; i++) { Image img = Image.FromFile(Globals.ThisAddIn.exerciseJsonPath + "exerciseUnClassified\\" + ExerciseList[i].Question); marginTop += (int)(((double)oldImgWidth / (double)img.Width) * img.Height); } if (this.panel1.Height < marginTop) { this.panel1.Height = marginTop + 100; } marginTop = 0; for (int i = 0; i < ExerciseList.Count; i++) { Image img = Image.FromFile(Globals.ThisAddIn.exerciseJsonPath + "exerciseUnClassified\\" + ExerciseList[i].Question); PictureBox pictureBox = new PictureBox(); pictureBox.Image = img; pictureBox.SizeMode = PictureBoxSizeMode.Zoom; pictureBox.Size = new System.Drawing.Size(oldImgWidth, (int)(((double)oldImgWidth / (double)img.Width) * img.Height)); pictureBox.Location = new Point(oldImgLocation_x, marginTop); this.panel1.Controls.Add(pictureBox); marginTop += (int)(((double)oldImgWidth / (double)img.Width) * img.Height); } } }
private void CleanDash() { try { if (!Directory.Exists(_exerciseJsonPath)) { Directory.CreateDirectory(_exerciseJsonPath); } if (!Directory.Exists(_exerciseJsonPath + "Deleted")) { Directory.CreateDirectory(_exerciseJsonPath + "Deleted"); } if (!Directory.Exists(_exerciseJsonPath + "Uploaded")) { Directory.CreateDirectory(_exerciseJsonPath + "Uploaded"); } if (!Directory.Exists(_exerciseJsonPath + "exerciseUnClassified")) { Directory.CreateDirectory(_exerciseJsonPath + "exerciseUnClassified"); } //每次程序开始时,清理已组卷的题目图片 string[] zipName = Directory.GetFiles(Globals.ThisAddIn.exerciseJsonPath); foreach (string s in zipName) { int index = s.LastIndexOf("."); string fileType = ""; if (index + 4 == s.Length) { fileType = s.Substring(index, 4); } if (fileType.ToLower().Equals(".zip")) { File.Delete(s); } } //每次程序开始时,清理已组卷的题目图片 if (!Directory.Exists(_exerciseJsonPath)) { Directory.CreateDirectory(_exerciseJsonPath); } string jsonStr = jsonFileHelper.GetFileString(_exerciseJsonPath + "exerciseUnClassified.json"); ProblemSet exerciseUnClassified = new ProblemSet(); exerciseUnClassified = jsonFileHelper.GetProblemSetFromFile(_exerciseJsonPath + "exerciseUnClassified.json"); string[] allImg = Directory.GetFiles(Globals.ThisAddIn.exerciseJsonPath + "exerciseUnClassified"); if (exerciseUnClassified.ExerciseList.Count != 0) { foreach (string s in allImg) { string[] nameSplit = s.Split('\\'); if (!jsonStr.Contains(nameSplit[nameSplit.Length - 1])) { File.Delete(s); } } } else { foreach (string s in allImg) { File.Delete(s); } } //每次程序开始时,清理已上传的试卷图片 string[] imgDire = Directory.GetDirectories(Globals.ThisAddIn.exerciseJsonPath); foreach (string d in imgDire) { string[] dSplit = d.Split('\\'); string jsonFileName = dSplit[dSplit.Length - 1]; string[] jsonFile = Directory.GetFiles(Globals.ThisAddIn.exerciseJsonPath); bool ISEX = false; foreach (string s in jsonFile) { string[] jsonFileSplit = s.Split('\\'); string fullJsonFileName = jsonFileSplit[jsonFileSplit.Length - 1]; if ((jsonFileName + ".json").Equals(fullJsonFileName)) { ISEX = true; } } if (!ISEX && (!jsonFileName.Equals("Uploaded") && !jsonFileName.Equals("Papers") && !jsonFileName.Equals("Deleted"))) { Directory.Delete(Globals.ThisAddIn.exerciseJsonPath + jsonFileName, true); } } } catch { MessageBox.Show("无法清理垃圾文件"); } }