コード例 #1
0
ファイル: MainForm.cs プロジェクト: Kristd/backup
        /// <summary>
        /// 试卷内容对象序列化成xml结构数据,并生成xml文件
        /// </summary>
        /// <param name="paper"></param>
        private static string PaperSerializerXml(Paper paper)
        {
            XmlSerializer xmls = new XmlSerializer(typeof(Paper));
            StringWriter sw = new StringWriter();
            xmls.Serialize(sw, paper);

            XmlDocument xmldoc = new XmlDocument();
            xmldoc.LoadXml(sw.ToString());
            gXmlStr = sw.ToString();
            gXmlPath = System.Windows.Forms.Application.StartupPath + HtmlUtil.paperbak + paper.papername + ".xml";

            if (!Directory.Exists(System.Windows.Forms.Application.StartupPath + HtmlUtil.paperbak))
            {
                Directory.CreateDirectory(System.Windows.Forms.Application.StartupPath + HtmlUtil.paperbak);
            }

            if(System.IO.File.Exists(gXmlPath))
            {
                System.IO.File.Delete(gXmlPath);
            }

            xmldoc.Save(gXmlPath);
            return sw.ToString();
        }
コード例 #2
0
ファイル: MainForm.cs プロジェクト: Kristd/backup
        /// <summary>
        /// 压缩并上传拆分后的题目
        /// </summary>
        /// <param name="onlyZip"></param>
        private void zipFileAndUpload(bool onlyZip)
        {
            try
            {
                Paper paper = new Paper();

                //遍历子节点中的内容
                for (int i = 0; i < listSubject.Count; i++)
                {
                    SubjectItem subjectItem = new SubjectItem();

                    createSubjectItem(listSubject[i], ref subjectItem);
                    subjectItem.subjecttextcontent = SubjectTool.ReplaceHTML(listSubject[i].subjecthtmlcontent);
                    subjectItem.subjecthtmlcontent = SubjectTool.ReplaceHTML(listSubject[i].subjecthtmlcontent);
                    paper.bigSubject.Add(subjectItem);

                }
                if (paper.bigSubject.Count > 0)
                {
                    if (paper.bigSubject[0].subSubjectItemList.Count == 0)
                    {
                        MessageBox.Show("文件未被识别或第一个大题没有试题。", "提示");
                        return;
                    }
                }

                paper.examclipid = testpaper.ExamClipId;
                paper.xueke = testpaper.XueKe;
                paper.xueduan = Convert.ToInt32(testpaper.XuekDuan);
                paper.tag = testpaper.Tag;
                paper.papername = testpaper.PaperName;
                gPaper = paper;

                string xmlpaper = PaperSerializerXml(paper);    //生成xml文件

                //上传文件内容
                if (!onlyZip)
                {
                    PostPaper(xmlpaper);
                }
            }
            catch (Exception ex)
            {
                string strErr = ex.Message;
                MessageBox.Show("上传失败,请重新上传!", "错误");
            }
        }