Beispiel #1
0
        /// <summary>
        /// 压缩并上传拆分后的题目
        /// </summary>
        /// <param name="onlyZip"></param>
        private void zipFileAndUpload(bool onlyZip)
        {
            try
            {
                if (this.mainContent1.WordBrowers.document == null)
                {
                    MessageBox.Show("请先在程序中打开word文件。");
                    return;
                }
                if ( testpaper.学科 == null || testpaper.学科.Equals(""))
                {
                    MessageBox.Show("请先填写完整试卷信息。");
                    return;
                }
                //if (!Regex.IsMatch(testpaper.年份, @"^\d{4}$"))
                //{
                //    MessageBox.Show("年份只能为4位数字。");
                //    return;
                //}

                if (!onlyZip && MessageBox.Show("确定开始上传试卷吗?", "提示", MessageBoxButtons.OKCancel) != DialogResult.OK)
                {
                    return;
                }

                Paper root = new Paper();
                for (int i = 0; i < this.treeViewSubject.Nodes.Count; i++)
                {
                    SubjectItem subjectItem = new SubjectItem();
                    createSubjectItem(this.treeViewSubject.Nodes[i], this.treeViewSubject.Nodes[i].Text, ref subjectItem);
                    root.bigSubject.Add(subjectItem);

                }
                if (root.bigSubject.Count > 0)
                {
                    if (root.bigSubject[0].subSubjectItemList.Count == 0)
                    {
                        MessageBox.Show("文件未被识别无法打包上传。");
                        return;
                    }
                }
                //root.source = testpaper.来源;
                //root.stage = testpaper.阶段;
                //XmlDocument xmldocstage = new XmlDocument();
                //xmldocstage.Load(Application.StartupPath + MartianSimple.stagefilename);
                //XmlNodeList xnlstage = xmldocstage.SelectNodes("//Result");

                //for (int i = 0; i < xnlstage.Count; i++)
                //{
                //    XmlElement xmlstage = (XmlElement)xnlstage[i];
                //    string str = xmlstage.GetAttribute("Id");
                //    if (testpaper.阶段.Equals(str))
                //    {
                //        root.stage = (i + 1).ToString();
                //        break;
                //    }

                //}

                //root.xueke = testpaper.学科;
                XmlDocument xmldocclass = new XmlDocument();
                xmldocclass.Load(Application.StartupPath + MartianSimple.xuekefilename);
                XmlNodeList xnl = xmldocclass.SelectNodes("//Id");
                XmlNodeList xnltitle = xmldocclass.SelectNodes("//Title");
                for (int i = 0; i < xnl.Count; i++)
                {
                    //XmlNode xmlrr = xnl[i];
                    //XmlNode stagexmode = xmlrr.SelectSingleNode("//Title");
                    string strp = xnltitle[i].InnerText;
                    string strb = testpaper.学科;
                    if (strp.Equals(strb))
                    {
                        //XmlNode stagexmodeId = xnl[i].SelectSingleNode("//Id");
                        root.xueke = xnl[i].InnerText;
                        break;
                    }
                }

                //root.year = testpaper.年份;
                root.tag = testpaper.标签;
                root.papername = testpaper.试卷名称;

                XmlSerializer xmls = new XmlSerializer(typeof(Paper));
                StringWriter sw = new StringWriter();
                xmls.Serialize(sw, root);
                XmlDocument xmldoc = new XmlDocument();
                xmldoc.LoadXml(sw.ToString());
                string xmlpath = System.Windows.Forms.Application.StartupPath + HtmlUtil.uploadfile + "uploadfile.xml";
                if (!Directory.Exists(System.Windows.Forms.Application.StartupPath + HtmlUtil.uploadfile))
                {
                    Directory.CreateDirectory(System.Windows.Forms.Application.StartupPath + HtmlUtil.uploadfile);
                }
                xmldoc.Save(xmlpath);
                //压缩上传内容
                ZipHelper.CreateZip(System.Windows.Forms.Application.StartupPath + HtmlUtil.uploadfile, System.Windows.Forms.Application.StartupPath + @"\uploadfile.zip");

                //Directory.Delete(System.Windows.Forms.Application.StartupPath + HtmlUtil.uploadfile, true);

                //上传文件内容
                if (!onlyZip)
                {
                    XmlDocument xmldocc = new XmlDocument();
                    xmldoc.Load(Application.StartupPath + "/LoginConfig.xml");
                    XmlNode address = xmldoc.SelectSingleNode("//address");
                    XmlNode account = xmldoc.SelectSingleNode("//account");
                    XmlNode password = xmldoc.SelectSingleNode("//password");
                    //使用webservice上传
                    //Model_WebServicePortClient client = new Model_WebServicePortClient("Model_WebServicePort", address.InnerText);
                    //byte[] buffer = File.ReadAllBytes(System.Windows.Forms.Application.StartupPath + @"\uploadfile.zip");
                    ////StreamReader sr=new StreamReader(System.Windows.Forms.Application.StartupPath + @"\uploadfile.zip");
                    ////sr.Read(buffer,0,sr);
                    //string base64String = System.Convert.ToBase64String(buffer, 0, buffer.Length);
                    //client.itemupload("uploadfile.zip", base64String);
                    //client.ClientCredentials.UserName.UserName = account.InnerText;
                    //client.ClientCredentials.UserName.Password = password.InnerText;

                    //使用resetful上传
                    HttpHelper httphelper = new HttpHelper();
                    NameValueCollection namevaluec = new NameValueCollection();
                    namevaluec.Add("token", "apiupload");
                    //namevaluec.Add("xueke", this.testpaper.学科);
                    namevaluec.Add("username", account.InnerText);
                    string loginrequest = httphelper.postFile("http://" + address.InnerText + "/api/Item/post", System.Windows.Forms.Application.StartupPath + @"\uploadfile.zip", namevaluec);
                    //string loginrequest = httphelper.Upload_Request("http://*****:*****@"\uploadfile.zip", System.Windows.Forms.Application.StartupPath + @"\uploadfile.zip", namevaluec);
                    //string loginrequest = httphelper.UploadFileEx("http://" + address.InnerText + "/api/Item/post", System.Windows.Forms.Application.StartupPath + @"\uploadfile.zip", null, null, namevaluec, null);//http://" + address.InnerText + "/api/Item/post
                    XmlDocument docrequest = new XmlDocument();
                    docrequest.LoadXml(loginrequest.Trim());
                    XmlNode statusnode = docrequest.SelectSingleNode("//Status");
                    if (statusnode.InnerText.Equals("fail"))
                    {
                        XmlNode errormessagenode = docrequest.SelectSingleNode("//ErrorMessage");
                        MessageBox.Show(errormessagenode.InnerText);
                    }
                    else
                    {
                        MessageBox.Show("上传成功");
                        //if (Directory.Exists(System.Windows.Forms.Application.StartupPath + HtmlUtil.uploadfile))
                        // Directory.Delete(System.Windows.Forms.Application.StartupPath + HtmlUtil.uploadfile, true);
                    }
                }
                // File.Delete(System.Windows.Forms.Application.StartupPath + @"\uploadfile.zip");
            }
            catch (DirectoryNotFoundException ex)
            {
                MessageBox.Show("上传失败," + ex.Message);
            }
            catch (XmlException xmle)
            {
                MessageBox.Show("上传失败,请检查服务器地址设置是否正确。");
            }
            catch (Exception ex)
            {
                MessageBox.Show("上传失败,"+ex.Message);
            }
        }
Beispiel #2
0
        /// <summary>
        /// 上传试卷内容
        /// </summary>
        private void UploadPaperZip()
        {
            XmlDocument xmldocc = new XmlDocument();
            xmldocc.Load(Application.StartupPath + "/LoginConfig.xml");
            XmlNode address = xmldocc.SelectSingleNode("//address");
            XmlNode token = xmldocc.SelectSingleNode("//token");
            XmlNode account = xmldocc.SelectSingleNode("//account");
            XmlNode password = xmldocc.SelectSingleNode("//password");

            HttpHelper httphelper = new HttpHelper();
            NameValueCollection namevaluec = new NameValueCollection();
            namevaluec.Add("token", token.InnerText);
            namevaluec.Add("xueke", this.toolStripComboBoxClass.Text);
            namevaluec.Add("username", account.InnerText);
            string loginrequest = httphelper.postFile("http://" + address.InnerText + "/paperapi/index", System.Windows.Forms.Application.StartupPath + @"\uploadfile.zip", namevaluec);
            //string loginrequest = httphelper.Upload_Request("http://*****:*****@"\uploadfile.zip", System.Windows.Forms.Application.StartupPath + @"\uploadfile.zip", namevaluec);
            //string loginrequest = httphelper.UploadFileEx("http://" + address.InnerText + "/api/Item/post", System.Windows.Forms.Application.StartupPath + @"\uploadfile.zip", null, null, namevaluec, null);//http://" + address.InnerText + "/api/Item/post
            XmlDocument docrequest = new XmlDocument();
            docrequest.LoadXml(loginrequest.Trim());
            XmlNode statusnode = docrequest.SelectSingleNode("//Status");
            if (statusnode.InnerText.Equals("fail"))
            {
                XmlNode errormessagenode = docrequest.SelectSingleNode("//ErrorMessage");
                MessageBox.Show(errormessagenode.InnerText, "提示");
            }
            else
            {
                MessageBox.Show("上传成功", "提示");
            }
        }
Beispiel #3
0
 private void uploadZipToolStripMenuItem_Click(object sender, EventArgs e)
 {
     try
     {
         if (openFileDialog2.ShowDialog() == DialogResult.OK)
         {
             XmlDocument xmldocc = new XmlDocument();
             xmldocc.Load(Application.StartupPath + "/LoginConfig.xml");
             XmlNode address = xmldocc.SelectSingleNode("//address");
             XmlNode account = xmldocc.SelectSingleNode("//account");
             HttpHelper httphelper = new HttpHelper();
             NameValueCollection namevaluec = new NameValueCollection();
             namevaluec.Add("token", "apiupload");
             namevaluec.Add("xueke", this.toolStripComboBoxClass.Text);
             namevaluec.Add("username", account.InnerText);
             string loginrequest = httphelper.postFile("http://" + address.InnerText + "/api/Item/post", openFileDialog2.FileName, namevaluec);
             //string loginrequest = httphelper.postFile("http://*****:*****@"\uploadfile.zip", System.Windows.Forms.Application.StartupPath + @"\uploadfile.zip", namevaluec);
             //string loginrequest = httphelper.UploadFileEx("http://" + address.InnerText + "/api/Item/post", System.Windows.Forms.Application.StartupPath + @"\uploadfile.zip", null, null, namevaluec, null);//http://" + address.InnerText + "/api/Item/post
             XmlDocument docrequest = new XmlDocument();
             docrequest.LoadXml(loginrequest.Trim());
             XmlNode statusnode = docrequest.SelectSingleNode("//Status");
             if (statusnode.InnerText.Equals("fail"))
             {
                 XmlNode errormessagenode = docrequest.SelectSingleNode("//ErrorMessage");
                 MessageBox.Show(errormessagenode.InnerText, "提示");
             }
             else
             {
                 MessageBox.Show("上传成功", "提示");
             }
         }
     }
     catch (DirectoryNotFoundException ex)
     {
         MessageBox.Show("上传失败," + ex.Message, "错误");
     }
     catch (XmlException xmle)
     {
         MessageBox.Show("上传失败,请检查服务器地址设置是否正确。", "错误");
     }
     catch (Exception ex)
     {
         MessageBox.Show("上传失败," + ex.Message, "错误");
     }
 }
Beispiel #4
0
        /// <summary>
        /// 上传图片附件
        /// </summary>
        private void UploadImages()
        {
            uploadimgsdic.Clear();
            XmlDocument xmldoc = new XmlDocument();
            xmldoc.Load(Application.StartupPath + "/LoginConfig.xml");
            XmlNode uploadimgurl = xmldoc.SelectSingleNode("//uploadimgurl");
            String upload = uploadimgurl.InnerText;
            //String upload = "http://192.168.1.104:3635/wiki/daoti2/";
            HttpHelper httphelper = new HttpHelper();
            NameValueCollection namevaluec = new NameValueCollection();

            DirectoryInfo di = new DirectoryInfo(System.Windows.Forms.Application.StartupPath + "/uploadfile");
            try
            {
                FileInfo[] fileInfo = di.GetFiles();
                int i = 1;
                foreach (FileInfo subinfo in fileInfo)
                {
                    string uoloadimgresp = httphelper.postFile(upload, subinfo.FullName, namevaluec);
                    using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(uoloadimgresp)))
                    {
                        DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(UploadImgResp));
                        UploadImgResp uploadimgresp = (UploadImgResp)serializer.ReadObject(ms);
                        if (uploadimgresp.state.Equals("SUCCESS"))
                        {
                            uploadimgsdic.Add(subinfo.Name, uploadimgresp.url);
                        }
                    }
                    float value = ((float)i++ / (float)fileInfo.Length) * 90;
                    this.progressBarSpot.Value = (int)value;
                    Thread.Sleep(50);
                    //MessageBox.Show(uoloadimgresp);
                }
            }
            catch (DirectoryNotFoundException dmfe)
            {
            }
            isUploadFinish = true;
        }