コード例 #1
0
        public void BatUpload()
        {
            string Case = Request["case"] ?? "";

            if (!string.IsNullOrEmpty(Case))
            {
                string myCase = Server.UrlDecode(Case);
                SafeSC.CreateDir("~/uploadFiles/DocTemp/", myCase);
                string path = Server.MapPath("~/uploadFiles/DocTemp/" + myCase + "/");
                //目录建好了,然后我们开始存文档
                Response.Clear();
                //ID为文档的主键,如果ID不为空,则更新数据,否则新建一条记录
                string ID = Request.Params["ID"];
                string DocTitle, content;
                DocTitle = "test";
                if (!string.IsNullOrEmpty(ID))
                {
                    DocTitle = Server.UrlDecode(Request.Params["DocTitle"]);
                }
                DocTitle = Server.UrlDecode(Request.Params["DocTitle"]);
                content  = Server.UrlDecode(Request.Params["content"]);
                if (Request.Files.Count > 0)
                {
                    HttpPostedFileBase upPhoto = Request.Files[0];
                    int    upPhotoLength       = upPhoto.ContentLength;
                    byte[] PhotoArray          = new Byte[upPhotoLength];
                    Stream PhotoStream         = upPhoto.InputStream;
                    PhotoStream.Read(PhotoArray, 0, upPhotoLength); //这些编码是把文件转换成二进制的文件
                    if (DocTitle.ToLower().Contains(".cshtml") || DocTitle.ToLower().Contains(".aspx") || DocTitle.ToLower().Contains(".exe"))
                    {
                        return;
                    }
                    SafeSC.SaveFile(path, DocTitle, PhotoArray);
                }
                Response.ContentType = "text/plain";
                Response.Write("Complete"); Response.Flush(); Response.End(); return;
            }
        }
コード例 #2
0
        public IActionResult Index()
        {
            SQLiteConnection m_dbConnection = new SQLiteConnection("Data Source =D:/seeker.db; New=False");

            m_dbConnection.Open();

            /*
             * SELECT D.DocumentID, D.DocumentTitle, D.NumParagraphs, p.PhraseText, PL.ParagraphIndex
             *  from document D JOIN PhraseLocation PL
             *  on D.DocumentID=PL.DocumentID
             *  JOIN phrase p on PL.PhraseID = p.PhraseID
             *  where D.DocumentID<6
             */
            string           sql     = "SELECT D.DocumentID, D.DocumentTitle, D.NumParagraphs,D.DocumentText, p.PhraseText, PL.ParagraphIndex from document D JOIN PhraseLocation PL on D.DocumentID = PL.DocumentID JOIN phrase p on PL.PhraseID = p.PhraseID where D.DocumentID < 21";
            SQLiteCommand    command = new SQLiteCommand(sql, m_dbConnection);
            SQLiteDataReader reader  = command.ExecuteReader();

            DocumentSet DocSet = new DocumentSet
            {
                Documents = new List <Document>()
            };
            int       DocumentId = -1;
            string    DocTitle;
            string    originalText;
            int       numParagraphs;
            int       NextDocId;
            int       paragraphIndex = -1;
            int       nextParagraphIndex;
            int       year;
            Document  doc = null;
            Paragraph par = null;

            while (reader.Read())
            {
                if (DocumentId == -1)
                {
                    DocumentId     = (int)(long)reader["DocumentID"];
                    paragraphIndex = (int)reader["ParagraphIndex"];
                    DocTitle       = reader["DocumentTitle"].ToString();
                    year           = Convert.ToInt32(DocTitle.Substring(0, 4));
                    numParagraphs  = (int)(long)reader["NumParagraphs"];
                    originalText   = reader["DocumentText"].ToString();
                    par            = new Paragraph
                    {
                        Text = new List <string>()
                    };
                    par.Text.Add(reader["PhraseText"].ToString());
                    doc = new Document()
                    {
                        DocumentId         = DocumentId,
                        DocumentTitle      = DocTitle,
                        Paragraphs         = new List <Paragraph>(),
                        NumParagraphs      = numParagraphs,
                        Year               = year,
                        OriginalText       = originalText,
                        OriginalParagraphs = originalText.Split("\\r?\\n")
                    };
                }
                else
                {
                    NextDocId = (int)(long)reader["DocumentID"];
                    if (NextDocId == DocumentId)
                    {
                        nextParagraphIndex = (int)reader["ParagraphIndex"];
                        if (paragraphIndex == nextParagraphIndex)
                        {
                            par.Text.Add(reader["PhraseText"].ToString());
                        }
                        else
                        {
                            doc.Paragraphs.Add(par);
                            par = new Paragraph
                            {
                                Text = new List <string>()
                            };
                            par.Text.Add(reader["PhraseText"].ToString());
                            paragraphIndex = nextParagraphIndex;
                        }
                    }
                    else
                    {
                        doc.Paragraphs.Add(par);
                        DocSet.Documents.Add(doc);
                        DocumentId     = NextDocId;
                        paragraphIndex = (int)reader["ParagraphIndex"];
                        DocTitle       = reader["DocumentTitle"].ToString();
                        year           = Convert.ToInt32(DocTitle.Substring(0, 4));
                        originalText   = reader["DocumentText"].ToString();
                        numParagraphs  = (int)(long)reader["NumParagraphs"];
                        par            = new Paragraph
                        {
                            Text = new List <string>()
                        };
                        par.Text.Add(reader["PhraseText"].ToString());
                        doc = new Document()
                        {
                            DocumentId         = DocumentId,
                            DocumentTitle      = DocTitle,
                            Paragraphs         = new List <Paragraph>(),
                            NumParagraphs      = numParagraphs,
                            OriginalText       = originalText,
                            Year               = year,
                            OriginalParagraphs = originalText.Split("\r\n")
                        };
                    }
                }
            }
            DocSet.Documents = DocSet.Documents.OrderBy(x => x.Year).ToList();
            var documentset = JsonConvert.SerializeObject(DocSet);

            ViewBag.documentset = documentset;

            return(View(DocSet));
        }