Example #1
0
        private void button4_Click(object sender, EventArgs e) //提交
        {
            XmlDocument xmldoc;
            XmlElement  xmlelem;

            xmldoc = new XmlDocument();
            XmlDeclaration xmldecl;

            xmldecl = xmldoc.CreateXmlDeclaration("1.0", "gb2312", null);
            xmldoc.AppendChild(xmldecl);

            xmlelem = xmldoc.CreateElement("", "NEWTPO", "");
            xmldoc.AppendChild(xmlelem);

            XmlNode root = xmldoc.SelectSingleNode("NEWTPO");

            xmlelem = xmldoc.CreateElement("IndWriting");
            xmlelem.SetAttribute("setid", textBox1.Text);
            xmlelem.SetAttribute("subject", indWritetext[1]);
            xmlelem.SetAttribute("stem", indWritetext[0]);
            xmlelem.SetAttribute("model", indWritetext[2]);
            root.AppendChild(xmlelem);

            xmlelem = xmldoc.CreateElement("ComWriting");
            xmlelem.SetAttribute("setid", textBox1.Text);
            xmlelem.SetAttribute("subject", comWritetext[1]);
            xmlelem.SetAttribute("stem", comWritetext[0]);
            xmlelem.SetAttribute("model", comWritetext[2]);
            xmlelem.SetAttribute("redmaterial", comWritetext[3]);
            root.AppendChild(xmlelem);

            xmlelem = xmldoc.CreateElement("Reading");
            XmlElement xmlelem2;

            //[i,0,0]是文章,[i,1~19,*]是题目, [i,1~19,0]是题目类型, 1是段落号, 2是题干, 3--9是选项, 10是ans, 11是解析
            for (int i = 0; i < 3; i++)
            {
                xmlelem2 = xmldoc.CreateElement("Reading" + i);
                XmlElement xmlarticle;
                xmlarticle = xmldoc.CreateElement("Article");
                xmlarticle.SetAttribute("article", Readtext[i, 0, 0]);
                xmlarticle.SetAttribute("title", Readtext[i, 0, 1]);
                xmlarticle.SetAttribute("setid", textBox1.Text);
                xmlarticle.SetAttribute("subject", Readtext[i, 0, 2]);
                int no = 0;
                for (no = 1; no <= 19; no++)
                {
                    if (Readtext[i, no, 2] == "")
                    {
                        break;
                    }
                }
                xmlarticle.SetAttribute("questionno", (no - 1).ToString());
                xmlelem2.AppendChild(xmlarticle);
                for (int j = 1; j <= 19; j++)
                {
                    if (Readtext[i, j, 2] == "")
                    {
                        continue;
                    }
                    XmlElement xmlQuestion;
                    xmlQuestion = xmldoc.CreateElement("question");
                    xmlQuestion.SetAttribute("id", j.ToString());
                    xmlQuestion.SetAttribute("articleid", (i + 1).ToString());
                    xmlQuestion.SetAttribute("num", j.ToString());
                    xmlQuestion.SetAttribute("type", Readtext[i, j, 0]);
                    string[] temp_para = Readtext[i, j, 1].Split(new char[2] {
                        ',', ' '
                    });
                    if (temp_para.Length == 1)
                    {
                        xmlQuestion.SetAttribute("paragraph", temp_para[0]);
                        xmlQuestion.SetAttribute("paragraph2", temp_para[0]);
                    }
                    else
                    {
                        xmlQuestion.SetAttribute("paragraph", temp_para[0]);
                        xmlQuestion.SetAttribute("paragraph2", temp_para[1]);
                    }
                    xmlQuestion.SetAttribute("stem", Readtext[i, j, 2]);
                    int k;
                    for (k = 0; k < 7; k++)
                    {
                        if (Readtext[i, j, k + 3] == "")
                        {
                            break;
                        }
                    }
                    xmlQuestion.SetAttribute("opnum", k.ToString());
                    for (int l = 0; l < 7; l++)
                    {
                        xmlQuestion.SetAttribute("option" + (l + 1), Readtext[i, j, 3 + l]);
                    }
                    xmlQuestion.SetAttribute("ans", Readtext[i, j, 10]);
                    xmlQuestion.SetAttribute("analysis", Readtext[i, j, 11]);

                    xmlelem2.AppendChild(xmlQuestion);
                }
                xmlelem.AppendChild(xmlelem2);
            }
            root.AppendChild(xmlelem);

            //string test;
            //test = "<?xml version=\"1.0\" encoding=\"gb2312\"?><NEWTPO><IndWriting setid=\"101\" subject=\"随便答题\" stem=\"为什么张夫洋最帅\" model=\"就是帅\" /><ComWriting setid=\"101\" subject=\"简单题\" stem=\"谁最帅\" model=\"张夫洋\" redmaterial=\"到底谁最帅\" /><Reading><Reading0><Article article=\"民工漫\" title=\"漫画\" setid=\"101\" subject=\"中文话题\" questionno=\"2\" /><question id=\"1\" articleid=\"1\" num=\"1\" type=\"错别字\" paragraph=\"1\" paragraph2=\"1\" stem=\"海贼王\" opnum=\"4\" option1=\"路费\" option2=\"娜美\" option3=\"香吉士\" option4=\"索隆\" option5=\"\" option6=\"\" option7=\"\" ans=\"A\" analysis=\"\" /><question id=\"2\" articleid=\"1\" num=\"2\" type=\"女性\" paragraph=\"2\" paragraph2=\"2\" stem=\"火影\" opnum=\"4\" option1=\"名人\" option2=\"宇智波鼬\" option3=\"佐助\" option4=\"小樱\" option5=\"\" option6=\"\" option7=\"\" ans=\"D\" analysis=\"\" /></Reading0><Reading1><Article article=\"NBA的题\" title=\"NBA\" setid=\"101\" subject=\"NBA话题\" questionno=\"1\" /><question id=\"1\" articleid=\"2\" num=\"1\" type=\"最nb\" paragraph=\"0\" paragraph2=\"1\" stem=\"NBA\" opnum=\"4\" option1=\"休斯顿火箭\" option2=\"圣安东尼奥马刺\" option3=\"奥克拉荷马雷霆\" option4=\"金州勇士\" option5=\"\" option6=\"\" option7=\"\" ans=\"D\" analysis=\"\" /></Reading1><Reading2><Article article=\"计算机知识\" title=\"计算机\" setid=\"101\" subject=\"计算机话题\" questionno=\"2\" /><question id=\"1\" articleid=\"3\" num=\"1\" type=\"随便选\" paragraph=\"20\" paragraph2=\"20\" stem=\"CPU\" opnum=\"5\" option1=\"主频\" option2=\"寄存器\" option3=\"时钟\" option4=\"cache\" option5=\"总线\" option6=\"\" option7=\"\" ans=\"D\" analysis=\"\" /><question id=\"2\" articleid=\"3\" num=\"2\" type=\"重要\" paragraph=\"5\" paragraph2=\"5\" stem=\"硬件\" opnum=\"5\" option1=\"cpu\" option2=\"内存\" option3=\"外存\" option4=\"显卡\" option5=\"显示器\" option6=\"\" option7=\"\" ans=\"A\" analysis=\"\" /></Reading2></Reading></NEWTPO>";
            // DatabaseHelp.ExecuteProc(test, "insert_new_tpo");
            try
            {
                DatabaseHelp.ExecuteProc(xmldoc.InnerXml, "insert_new_tpo");
            }
            catch
            {
                MessageBox.Show("输入有误!");
                return;
            }
            TransfEvent(textBox1.Text);
            this.Close();
            return;
        }