Beispiel #1
0
        private void AddTree(int Pid, TreeNode PNode)
        {
            Corporation corporation             = (Corporation)Session["corporation"];
            CorpoBooktypeTableAdapter ta_fatype = new CorpoBooktypeTableAdapter();
            CorpoBookTableAdapter     ta_book   = new CorpoBookTableAdapter();


            Connect connect = new Connect();
            string  sql     = "SELECT CorpoBooktype.abooktype_id AS id,CorpoBooktype.name,CorpoBooktype.parent_id FROM CorpoBooktype " +
                              " WHERE dbo.CorpoBooktype.corporation_id =" + corporation.id;
            DataTable dt_fa = connect.GetDataTable(sql);

            dt_fa = connect.GetDataTable(sql);
            sql   = "SELECT (CorpoBook.abook_id-100000) AS id,CorpoBook.name,CorpoBT.cbooktype_id AS parent_id " +
                    "FROM CorpoBook INNER JOIN CorpoBT ON CorpoBT.cbook_id = CorpoBook.abook_id AND CorpoBT.corporation_id=CorpoBook.corporation_id " +
                    "INNER JOIN CorpoBooktype ON CorpoBT.cbooktype_id = CorpoBooktype.abooktype_id AND CorpoBooktype.corporation_id=CorpoBook.corporation_id " +
                    "WHERE CorpoBook.corporation_id = " + corporation.id;
            DataTable dt_book = connect.GetDataTable(sql);

            dt_fa.Merge(dt_book);
            if (dt_fa.Rows.Count > 0)
            {
                DataView dv = new DataView(dt_fa);
                //过滤ParentID,得到当前的所有子节点 ParentID为父节点ID
                dv.RowFilter = "[parent_id] = " + Pid;
                //循环递归
                foreach (DataRowView Row in dv)
                {
                    //声明节点
                    TreeNode Node = new TreeNode();
                    //绑定超级链接
                    //Node.NavigateUrl = String.Format("javascript:show('{0}')", Row["name"].ToString());
                    //开始递归
                    if (PNode == null)
                    {
                        //添加根节点
                        Node.Text  = Row["name"].ToString();
                        Node.Value = Row["id"].ToString();
                        name       = Node.Text;
                        tree.Nodes.Add(Node);
                        Node.Expanded = false;                            //节点状态收缩
                        AddTree(Int32.Parse(Row["id"].ToString()), Node); //再次递归
                    }
                    else
                    {
                        //添加当前节点的子节点
                        Node.Text  = Row["name"].ToString();
                        Node.Value = Row["id"].ToString();
                        name       = Node.Text;
                        PNode.ChildNodes.Add(Node);
                        Node.Expanded = false;                            //节点状态收缩
                        AddTree(Int32.Parse(Row["id"].ToString()), Node); //再次递归
                    }
                }
            }
        }
        protected void rep_adminlist_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName.Equals("read"))
            {
                string      cbook_path;
                Corporation corporation = (Corporation)Session["corporation"];
                cbook_path = "~/corporation/upload/" + corporation.name + "\\";
                CorpoBookTableAdapter ta_book = new CorpoBookTableAdapter();
                string   book_name            = ta_book.GetCBookById(corporation.id, Convert.ToInt32(e.CommandArgument)).Rows[0]["name"].ToString();
                string   fileName             = book_name;
                string   fileExtention        = fileName.Substring(fileName.LastIndexOf(".") + 1);
                string   pdfFileName;
                bool     fileOK            = false;
                String[] allowedExtensions =
                { "doc", "ppt", "xls", "docx", "html" }; //允许上传的文件格式
                for (int i = 0; i < allowedExtensions.Length; i++)
                {
                    if (fileExtention == allowedExtensions[i])
                    {
                        fileOK = true;
                        break;
                    }
                }
                if (fileOK == true)
                {
                    string filePath = HttpContext.Current.Server.MapPath("~/attachment\\") + fileName;
                    //上传选中文件到attachment文件夹
                    string admin_bookpath = HttpContext.Current.Server.MapPath(cbook_path) + fileName;
                    if (!File.Exists(filePath))
                    {
                        FileInfo adminway = new FileInfo(admin_bookpath);
                        adminway.CopyTo(filePath);
                    }
                    //将office文件转换成PDF,保存到PDF文件夹下
                    pdfFileName = fileName.Substring(0, fileName.LastIndexOf(".")) + ".pdf";
                    string fileOutPath = HttpContext.Current.Server.MapPath("~/pdf\\") + pdfFileName;
                    ExportPdf(filePath, fileOutPath);
                }

                else
                {
                    string filePath = HttpContext.Current.Server.MapPath("~/pdf\\") + fileName;

                    string admin_bookpath = HttpContext.Current.Server.MapPath(cbook_path) + fileName;
                    if (!File.Exists(filePath))
                    {
                        FileInfo adminway = new FileInfo(admin_bookpath);
                        adminway.CopyTo(filePath);
                    }

                    pdfFileName = fileName.Substring(0, fileName.LastIndexOf(".")) + ".pdf";
                }
                //切记,使用pdf2swf.exe 打开的文件名之间不能有空格,否则会失败
                string cmdStr      = HttpContext.Current.Server.MapPath("~/SWFTools/pdf2swf.exe");
                string savePath    = HttpContext.Current.Server.MapPath("~/pdf/");
                string saveSWFPath = HttpContext.Current.Server.MapPath("~/SWF/");
                //将PDF文件转换成SWF格式文件
                //要转换的pdf文件路径
                string sourcePath = @"""" + savePath + pdfFileName + @"""";

                //转换之后swf文件存放的目标路径
                string targetPath = @"""" + saveSWFPath + pdfFileName.Substring(0, pdfFileName.LastIndexOf(".")) + ".swf" + @"""";
                //@"""" 四个双引号得到一个双引号,如果你所存放的文件所在文件夹名有空格的话,要在文件名的路径前后加上双引号,才能够成功
                // -t 源文件的路径
                // -s 参数化(也就是为pdf2swf.exe 执行添加一些窗外的参数(可省略))
                string argsStr = "  -t " + sourcePath + " -s flashversion=9 -o " + targetPath;

                //执行pdf到swf的转换
                ExcutedCmd(cmdStr, argsStr);

                Response.Redirect("../viewer.aspx?id=" + HttpUtility.HtmlEncode(fileName.Substring(0, fileName.LastIndexOf(".")) + ".swf"));
            }
        }