示例#1
0
        private void LoadKonwlegeTree(string keyWord)
        {
            this.treeView1.Nodes.Clear();
            string knowlegeList = jsonFileHelper.GetFileString(Globals.ThisAddIn.resourcesRootPath + "Configure\\knowlege.json");

            List <Knowlege> tempJson = new List <Knowlege>();

            tempJson = JsonConvert.DeserializeObject <List <Knowlege> >(knowlegeList);


            for (int i = 0; i < tempJson.Count; i++)
            {
                if (!keyWord.Equals("") && !tempJson[i].Name.ToString().Contains(keyWord))
                {
                    continue;
                }
                TreeNode node = new TreeNode();
                node.Name = tempJson[i].Id.ToString();
                node.Text = tempJson[i].Name.ToString();

                Knowlege knowlege = tempJson[i] as Knowlege;

                this.treeView1.Nodes.Add(node);
                //if (!AddTreeNode(this.treeView1, knowlege))
                //    this.treeView1.Nodes.Add(node);
            }
        }
示例#2
0
        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);
                }
            }
        }
示例#3
0
        private void button1_Click(object sender, EventArgs e)
        {
            string userName = this.textBoxUsername.Text.ToString();
            string password = this.textBoxPassword.Text.ToString();

            try
            {
                int returnUserID = apiHelper.CheckUser(userName, password);
                if (returnUserID > 0)
                {
                    this.Close();

                    Globals.ThisAddIn.editorID = returnUserID;

                    jsonFileHelper.WriteFileString(returnUserID + "", Globals.ThisAddIn.resourcesRootPath + "Configure\\user.txt");

                    bool ISExit = false;
                    foreach (CustomTaskPane ctp in Globals.ThisAddIn.CustomTaskPanes)
                    {
                        if (ctp.Title.ToString().Equals("题目选择器"))
                        {
                            ctp.Visible = true;
                            ISExit      = true;
                        }
                        else
                        {
                            ctp.Visible = false;
                        }
                    }
                    if (!ISExit)
                    {
                        CustomTaskPane _customTaskPane = null;
                        UserControl1   u = new UserControl1();
                        _customTaskPane = Globals.ThisAddIn.CustomTaskPanes.Add(u, "题目选择器");
                        //_customTaskPane.Width = 1024;
                        _customTaskPane.DockPosition = Microsoft.Office.Core.MsoCTPDockPosition.msoCTPDockPositionBottom;
                        _customTaskPane.Height       = (int)(SystemInformation.WorkingArea.Height / 3);
                        _customTaskPane.Visible      = true;
                    }
                }
                else
                {
                    MessageBox.Show("用户名或密码输入错误");
                }
            }
            catch
            {
                MessageBox.Show("无法连接网络");

                string FileuserID = jsonFileHelper.GetFileString(Globals.ThisAddIn.resourcesRootPath + "Configure\\user.txt");
                if (!FileuserID.Equals(""))
                {
                    Globals.ThisAddIn.editorID = int.Parse(FileuserID);

                    bool ISExit = false;
                    foreach (CustomTaskPane ctp in Globals.ThisAddIn.CustomTaskPanes)
                    {
                        if (ctp.Title.ToString().Equals("题目选择器"))
                        {
                            ctp.Visible = true;
                            ISExit      = true;
                        }
                        else
                        {
                            ctp.Visible = false;
                        }
                    }
                    if (!ISExit)
                    {
                        CustomTaskPane _customTaskPane = null;
                        UserControl1   u = new UserControl1();
                        _customTaskPane = Globals.ThisAddIn.CustomTaskPanes.Add(u, "题目选择器");
                        //_customTaskPane.Width = 1024;
                        _customTaskPane.DockPosition = Microsoft.Office.Core.MsoCTPDockPosition.msoCTPDockPositionBottom;
                        _customTaskPane.Height       = (int)(SystemInformation.WorkingArea.Height / 3);
                        _customTaskPane.Visible      = true;
                    }
                }
            }
        }
示例#4
0
        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("无法清理垃圾文件");
            }
        }