private void ParseXmlMember(XmlReader reader, DocBody body, string elementName) { while (reader.Read()) { var type = reader.NodeType; if (type == XmlNodeType.EndElement && reader.Name == elementName) { break; } if (type == XmlNodeType.Element && reader.Name == "summary") { body.summary = ReadTextBlock(reader, body, "summary"); } if (type == XmlNodeType.Element && reader.Name == "param") { var pname = reader.GetAttribute("name"); var ptext = ReadSingleTextBlock(reader, body, "param"); if (!string.IsNullOrEmpty(ptext)) { body.parameters[pname] = ptext; } } if (type == XmlNodeType.Element && reader.Name == "returns") { body.returns = ReadSingleTextBlock(reader, body, "returns"); } } }
private string ReadSingleTextBlock(XmlReader reader, DocBody body, string elementName) { //_sb.Clear(); _sb.Remove(0, _sb.Length); if (!reader.IsEmptyElement) { while (reader.Read()) { var type = reader.NodeType; if (type == XmlNodeType.EndElement && reader.Name == elementName) { break; } if (type == XmlNodeType.Element && reader.Name == "para") { _sb.Append(ReadElementContentAsString(reader, body, "para")); _sb.Append(' '); } if (type == XmlNodeType.Text) { _sb.Append(reader.Value); } } } return(_sb.ToString()); }
private string[] ReadTextBlock(XmlReader reader, DocBody body, string elementName) { var lines = new List <string>(); if (!reader.IsEmptyElement) { while (reader.Read()) { var type = reader.NodeType; if (type == XmlNodeType.EndElement && reader.Name == elementName) { break; } if (type == XmlNodeType.Element && reader.Name == "para") { lines.Add(ReadElementContentAsString(reader, body, "para")); } else if (type == XmlNodeType.Text || type == XmlNodeType.CDATA) { foreach (var line in reader.Value.Split('\n')) { var trim = line.Trim(); if (trim.Length > 0) { lines.Add(trim); } } } } } return(lines.ToArray()); }
/// <summary> /// 处理表单post数据 /// </summary> private DocBody ProcessFormPost() { ProjectClass pjt = new ProjectClass(); int cstRightToApproveDocument = 2; // 验证 if (Request.IsAuthenticated) { // 处理表单传递参数 DocBody docbody = new DocBody(); docbody.DocTitle = this.txtTitle.Value; docbody.DocContent = this.txtContent.Value; docbody.DocAddedBy = Username; docbody.DocClassID = Int32.Parse(ClassID); docbody.DocAddedDate = DateTime.Now.ToString(); docbody.DocApprover = (pjt.GetAccessPermission(Int32.Parse(ClassID), Username, cstRightToApproveDocument))?Username:""; docbody.DocApproveDate = (pjt.GetAccessPermission(Int32.Parse(ClassID), Username, cstRightToApproveDocument))?DateTime.Now.ToString():""; docbody.DocApproved = (docbody.DocApprover == "")?0:1; docbody.DocAttribute = 0; docbody.DocType = 0; return(docbody); } else { return(null); } }
/// <summary> /// 文档处理处理,包括文档处理及附件处理 /// </summary> private void DocProcess(MailMainBody mailbody, ArrayList upattlist) { string DocID = ""; int cstRightToApproveDocument = 2; ProjectClass pjt = new ProjectClass(); DocBody docbody = new DocBody(); docbody.DocTitle = mailbody.MailSubject; docbody.DocContent = mailbody.MailBody; docbody.DocAddedBy = mailbody.MailSender; docbody.DocClassID = mailbody.MailClassID; docbody.DocAddedDate = DateTime.Now.ToString(); docbody.DocApprover = (pjt.GetAccessPermission(Int32.Parse(ClassID), Username, cstRightToApproveDocument))?Username:""; docbody.DocApproveDate = (pjt.GetAccessPermission(Int32.Parse(ClassID), Username, cstRightToApproveDocument))?DateTime.Now.ToString():""; docbody.DocApproved = (docbody.DocApprover == "")?0:1; docbody.DocAttribute = 0; docbody.DocType = 0; DocumentClass doc = new DocumentClass(); // 添加文档,并返回ID DocID = doc.AddDocBody(docbody); foreach (UDS.Components.MailAttachFile att in upattlist) { try { DocAttachFile docatt = new DocAttachFile(); // Mail Attach File 类转换为Doc Attach File docatt.FileAttribute = 0; docatt.FileSize = att.FileSize; docatt.FileName = att.FileName; docatt.FileAuthor = Username; docatt.FileCatlog = "文档"; docatt.FileVisualPath = "Mail" + att.FileVisualPath; docatt.FileAddedDate = DateTime.Now.ToString(); docatt.DocID = Int32.Parse(DocID); // 转换结束 // 附件数据库处理 doc.AddAttach(docatt, Int32.Parse(DocID)); } catch (Exception ioex) { UDS.Components.Error.Log(ioex.ToString()); Server.Transfer("../../Error.aspx"); } } }
private string ReadElementContentAsString(XmlReader reader, DocBody body, string elementName) { var text = string.Empty; while (reader.Read()) { var type = reader.NodeType; if (type == XmlNodeType.EndElement && reader.Name == elementName) { break; } if (type == XmlNodeType.Text) { text = reader.Value; } } return(text); }
public bool ParseXml(string filename) { if (!File.Exists(filename)) { return(false); } // Debug.LogFormat("read doc: {0}", filename); using (var fs = File.OpenRead(filename)) { using (var reader = XmlReader.Create(fs)) { while (reader.Read()) { var type = reader.NodeType; if (type == XmlNodeType.Element && reader.Name == "member") { var body = new DocBody(); var name = reader.GetAttribute("name"); if (name.Length > 2) { var subname = name.Substring(2); body.name = subname; switch (name[0]) { case 'F': _fdocs[subname] = body; break; case 'P': _pdocs[subname] = body; break; case 'M': _mdocs[subname] = body; break; case 'T': _tdocs[subname] = body; break; } } ParseXmlMember(reader, body, "member"); } } } } return(true); }
private string[] ReadTextBlock(XmlReader reader, DocBody body, string elementName) { var lines = new List <string>(); if (!reader.IsEmptyElement) { while (reader.Read()) { var type = reader.NodeType; if (type == XmlNodeType.EndElement && reader.Name == elementName) { break; } if (type == XmlNodeType.Element && reader.Name == "para") { lines.Add(ReadElementContentAsString(reader, body, "para")); } } } return(lines.ToArray()); }
private void btnSubmit_Click(object sender, System.EventArgs e) { string DocID = ""; DocBody docbody = ProcessFormPost(); DocumentClass doc = new DocumentClass(); // 添加文档,并返回ID DocID = doc.AddDocBody(docbody); ArrayList listattfile = (ArrayList)Session["listattfile"]; foreach (UDS.Components.DocAttachFile att in listattfile) { try { if (!Directory.Exists(Server.MapPath(".") + "\\AttachFiles\\" + Username)) { Directory.CreateDirectory(Server.MapPath(".") + "\\AttachFiles\\" + Username); } //Directory.Move(att.FileVisualPath.ToString().Replace(att.FileName,""),Server.MapPath(".")+"\\AttachFiles\\"+Username+"\\"); Random TempNameInt = new Random(); string NewDocDirName = TempNameInt.Next(100000000).ToString(); Directory.CreateDirectory(Server.MapPath(".") + "\\AttachFiles\\" + Username + "\\" + NewDocDirName); File.Move(Server.MapPath(".") + "\\" + att.FileVisualPath, Server.MapPath(".") + "\\AttachFiles\\" + Username + "\\" + NewDocDirName + "\\" + att.FileName); Directory.Delete(Server.MapPath(".") + "\\" + att.FileVisualPath.ToString().Replace(att.FileName, ""), true); att.FileVisualPath = "\\AttachFiles\\" + Username + "\\" + NewDocDirName + "\\" + att.FileName; att.FileAddedDate = DateTime.Now.ToString(); // 附件数据库处理 doc.AddAttach(att, Int32.Parse(DocID)); } catch (Exception ioex) { UDS.Components.Error.Log(ioex.ToString()); Server.Transfer("../../Error.aspx"); } } Response.Write("<script language=javascript>alert('文档提交成功!');self.location='../Switch.aspx?Action=1&ClassID=" + ClassID + "';</script>"); }
public void MailIncoming(string MailID, string ClassID) { SqlDataReader dataReader = null; if (MailID != "" && ClassID != "") { try { throw new Exception("错误测试"); String Username = Request.Cookies["Username"].Value.ToString(); MailClass mailclass = new MailClass(); ProjectClass pjt = new ProjectClass(); DocBody docbody = new DocBody(); DocumentClass doc = new DocumentClass(); dataReader = mailclass.GetMailCompleteInfoDbreader(MailID); if (dataReader.Read()) { int cstRightToApproveDocument = 2; docbody.DocTitle = dataReader["MailSubject"].ToString(); docbody.DocContent = dataReader["MailBody"].ToString();; docbody.DocAddedBy = dataReader["MailSender"].ToString();; docbody.DocClassID = Int32.Parse(ClassID); docbody.DocAddedDate = DateTime.Now.ToString(); docbody.DocApprover = (pjt.GetAccessPermission(Int32.Parse(ClassID), Username, cstRightToApproveDocument)) ? Username : ""; docbody.DocApproveDate = (pjt.GetAccessPermission(Int32.Parse(ClassID), Username, cstRightToApproveDocument)) ? DateTime.Now.ToString() : ""; docbody.DocApproved = (docbody.DocApprover == "") ? 0 : 1; docbody.DocAttribute = 0; docbody.DocType = 0; } dataReader.Close(); string DocID = doc.AddDocBody(docbody); dataReader = mailclass.GetMailAttInfoDbreader(MailID); while (dataReader.Read()) { DocAttachFile docatt = new DocAttachFile(); docatt.FileAttribute = 0; docatt.FileSize = Int32.Parse(dataReader["FileSize"].ToString()); docatt.FileName = dataReader["FileName"].ToString(); docatt.FileAuthor = Username; docatt.FileCatlog = "文档"; docatt.FileVisualPath = "Mail" + dataReader["FileVisualPath"].ToString(); docatt.FileAddedDate = DateTime.Now.ToString(); docatt.DocID = Int32.Parse(DocID); doc.AddAttach(docatt, Int32.Parse(DocID)); } dataReader = null; pjt = null; docbody = null; } catch (Exception oe) { throw new Exception(oe.Message); } finally { if (null != dataReader) { if (!dataReader.IsClosed) { dataReader.Close(); } } } } }