asp.net右键弹出上下文菜单

xtreeView.js

---==========================================================

var ie5=document.all&&document.getElementById
var ns6=document.getElementById&&!document.all
if (ie5||ns6)
var menuobj=document.getElementById("Panel2")

function showmenuie5(e)
{
   
    document.getElementById("url").value = e.srcElement.firstChild.nodeValue;
   
var rightedge=ie5? document.body.clientWidth-event.clientX : window.innerWidth-e.clientX
var bottomedge=ie5? document.body.clientHeight-event.clientY : window.innerHeight-e.clientY

//if the horizontal distance isn't enough to accomodate the width of the context menu
if (rightedge<menuobj.offsetWidth)
//move the horizontal position of the menu to the left by it's width
menuobj.style.left=ie5? document.body.scrollLeft+event.clientX-menuobj.offsetWidth : window.pageXOffset+e.clientX-menuobj.offsetWidth
else
//position the horizontal position of the menu where the mouse was clicked
menuobj.style.left=ie5? document.body.scrollLeft+event.clientX : window.pageXOffset+e.clientX

//same concept with the vertical position
if (bottomedge<menuobj.offsetHeight)
menuobj.style.top=ie5? document.body.scrollTop+event.clientY-menuobj.offsetHeight : window.pageYOffset+e.clientY-menuobj.offsetHeight
else
menuobj.style.top=ie5? document.body.scrollTop+event.clientY : window.pageYOffset+e.clientY

if(ie5)
    window.event.cancelBubble = true;
else if(ns6)
    e.stopPropagation();

menuobj.style.visibility="visible"

   
return false
}

 

 

function hidemenuie5(e){
menuobj.style.visibility="hidden"
}

function highlightie5(e){
var firingobj=ie5? event.srcElement : e.target
if (firingobj.className=="menuitems"||ns6&&firingobj.parentNode.className=="menuitems"){
if (ns6&&firingobj.parentNode.className=="menuitems")
firingobj=firingobj.parentNode //up one node

firingobj.style.backgroundColor="highlight"

}
}

function lowlightie5(e){
var firingobj=ie5? event.srcElement : e.target
if (firingobj.className=="menuitems"||ns6&&firingobj.parentNode.className=="menuitems"){
if (ns6&&firingobj.parentNode.className=="menuitems")
firingobj=firingobj.parentNode //up one node

firingobj.style.backgroundColor=""


window.status=''
}
}

function jumptoie5(e){
var firingobj=ie5? event.srcElement : e.target
if (firingobj.className=="menuitems"||ns6&&firingobj.parentNode.className=="menuitems"){
if (ns6&&firingobj.parentNode.className=="menuitems")
var firingobj2=firingobj.parentNode
// the click can be controlled by firingobj
// if the click was generated by the div tag enclosing the link buttons
//then the value of firingobj=htmlDivElement el
// else if the click was generated by the linkbutton
// then the value of firingobj will be href of the link button and the value of firingobj2 will be htmlDivElement
// the code for controlling the clciks goes here

}
}

if (ie5||ns6){
menuobj.style.display=''
document.οnclick=hidemenuie5

}

--=====================

 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Left.aspx.cs" Inherits="Left" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>

    <script src="../css/calendar.js" type="text/javascript"></script>
    <style type="text/css" >
        html{           
          
            font-size:12px;
            font-family:SimSun;
            border-left:#ECF1F4 0px solid;
            border-right:#ECF1F4 0px solid;
            margin:0;                              /*控制滚动条左右侧实线颜色*/
            overflow-x:hidden;                      /*隐藏底部的横向滚动条*/
            scrollbar-arrow-color:#034079;          /*三角箭头的颜色*/
            scrollbar-3dlight-color:#ADD9E6;        /*立体滚动条亮边的颜色*/
            scrollbar-highlight-color:#89C4D5;      /*滚动条空白部分的颜色*/
            scrollbar-shadow-color:#89C4D5;        /*立体滚动条阴影的颜色*/
            scrollbar-darkshadow-color:#ADD9E6;    /*滚动条强阴影颜色*/
            scrollbar-track-color:#ADD9E6;          /*立体滚动条背景颜色*/
            scrollbar-base-color:#ADD9E6;          /*滚动条的基本颜色*/
       }
.skin0{
position:absolute;
width:100px;
border:2px solid black;
background-color:menu;
font-family:Verdana;
line-height:20px;
cursor:default;
font-size:12px;
z-index:100;
visibility:hidden;
text-align:center;
}

.menuitems{
font-family:Verdana;
font-size:12px;
color:black;
}


        #dt_start
        {
            width: 90px;
        }


    </style>

</head>
<body>
    <form id="form1" runat="server">

   
       <div>
          
             <INPUT id="dt_start"   type="text" name="dt_start" runat="server" οnfοcus="calendar();" />
          
                  <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/Image/button.png"
                      οnclick="ImageButton1_Click" Width="61px" />
          
           
        
  
           </div>
       <div>
     
               <asp:ImageButton ID="ImageButton2" runat="server"  ImageUrl="~/Image/rr.gif"
               Height="38px" Width="170px" οnclick="ImageButton2_Click" />
          
       </div >
       <div>
         <asp:TreeView ID="TreeView1" Width="148px" runat="server" ImageSet="Simple"
               ontreenodecollapsed="TreeView1_TreeNodeCollapsed"
               >
               <ParentNodeStyle Font-Bold="False" />
                    <HoverNodeStyle Font-Underline="True" ForeColor="#5555DD" />
                    <SelectedNodeStyle Font-Underline="True" ForeColor="#5555DD"
                        HorizontalPadding="0px" VerticalPadding="0px" />
                    <Nodes>
                        <asp:TreeNode  ImageUrl="~/Image/file.gif" Text="日志记录"  Value="日志记录"
                           Selected="false" SelectAction="Expand"   ></asp:TreeNode>
                    </Nodes>
                    <NodeStyle Font-Names="Tahoma" Font-Size="10pt" ForeColor="Black"
                        HorizontalPadding="0px" NodeSpacing="0px" VerticalPadding="0px" />
        </asp:TreeView>
       </div>
       <div  style="width:100px;float:right; padding-right:20px;">

            <asp:Panel ID="Panel2"  runat="server"  display:none  BorderColor="Black" CssClass="skin0" onMouseover="highlightie5(event)" onMouseout="lowlightie5(event)" onClick="jumptoie5(event)"  >
                <div class="menuitems">
                 <asp:HiddenField ID="url" runat="server" />
                <asp:LinkButton ID="LinkButton1" runat="server"   CssClass="menuitems"
                        οnclick="LinkButton1_Click" >下载单个记录
                </asp:LinkButton></div>
            </asp:Panel>
            <br />

          <script src="../css/xtreeview.js" type="text/javascript"></script>
         </div>
    </form>
</body>
</html>

 

--==================

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using ICSharpCode.SharpZipLib.Zip;
using ICSharpCode.SharpZipLib.Checksums;
using ICSharpCode.SharpZipLib.GZip;

public partial class Left : System.Web.UI.Page
{
    ICSharpCode.SharpZipLib.Zip.ZipOutputStream zos = null;
    String strBaseDir = "";
    protected void Page_Load(object sender, EventArgs e)
    {

        if (!this.IsPostBack)
        {
            this.dt_start.Value = DateTime.Now.ToString("yyyy-MM-dd");
            string FilePath = Server.MapPath("../XmlFile/");
            if (Directory.Exists(FilePath))
            {
                ReadXMLToTree.PopulateTreeView(FilePath,this.TreeView1.Nodes[0]);
            }
          
       
        }
    }
    /// <summary>
    /// 下载单个文件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
           string Selecturl = this.url.Value.ToString();
        if (!String.IsNullOrEmpty(Selecturl))
        {
                string SelectUrl = Server.MapPath("~/XmlFile/") + Selecturl + ".XML";
                FileInfo File = new FileInfo(SelectUrl);
                if (File.Exists)
                {
                    //以字符流的形式下载文件
                    FileStream fs = new FileStream(File.FullName, FileMode.Open);
                    byte[] bytes = new byte[(int)fs.Length];
                    fs.Read(bytes, 0, bytes.Length);
                    fs.Close();
                    Response.ContentType = "application/octet-stream";
                    //通知浏览器下载文件而不是打开
                    Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(Path.GetFileName(File.FullName), System.Text.Encoding.UTF8));
                    Response.BinaryWrite(bytes);
                    Response.Flush();
                    Response.End();

 

                }
                else
                {;
                    this.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('选中对应目录不存在!');</script>");
                }

 

        }
        else
        {
            this.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('未选中有效的树形节点!');</script>");
       
        }

    }

  
    /// <summary>
    /// 获取单日数据
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        if (!String.IsNullOrEmpty(this.dt_start.Value.ToString()))
        {
               string url = Server.MapPath("~/XmlFile/") + this.dt_start.Value + ".XML";
                url = "List.aspx?Url=" + Server.UrlEncode(url);
                Response.Write("<script language=javascript>");
                Response.Write("window.parent.frames['mainFrame'].location.href='" + url + "'");
                Response.Write("</script>");
           
          
       
        }

    }

    /// <summary>
    /// 下载全部
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
    {
        dlZipDir(Server.MapPath(@"~/XmlFile"),"日志记录下载");


    }

    /// <summary>
    /// 在线压缩下载
    /// </summary>
    /// <param name="strPath"></param>
    /// <param name="strFileName"></param>
    protected void dlZipDir(string strPath, string strFileName)
    {
        try
        {
            if (Directory.Exists(strPath))
            {
                MemoryStream ms = null;
                Response.ContentType = "application/octet-stream";
                strFileName = HttpUtility.UrlEncode(strFileName).Replace('+', ' ');
                Response.AddHeader("Content-Disposition", "attachment;   filename=" + strFileName + ".zip");
                ms = new MemoryStream();
                zos = new ZipOutputStream(ms);
                strBaseDir = strPath + "//";
                addZipEntry(strBaseDir);
                zos.Finish();
                zos.Close();
                Response.Clear();
                Response.BinaryWrite(ms.ToArray());
                Response.End();
            }
            else
            {
                this.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('下载目录不存在!');</script>");
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }

    /// <summary>
    /// 递归循环文件夹压缩
    /// </summary>
    /// <param name="PathStr"></param>
    protected void addZipEntry(string PathStr)
    {
        try
        {
            DirectoryInfo di = new DirectoryInfo(PathStr);
            if (di.Exists)
            {
                foreach (DirectoryInfo item in di.GetDirectories())
                {
                    addZipEntry(item.FullName);
                }
                foreach (FileInfo item in di.GetFiles())
                {
                    FileStream fs = File.OpenRead(item.FullName);
                    byte[] buffer = new byte[fs.Length];
                    fs.Read(buffer, 0, buffer.Length);
                    string strEntryName = item.FullName.Replace(strBaseDir, "");
                    ZipEntry entry = new ZipEntry(strEntryName);
                    zos.PutNextEntry(entry);
                    zos.Write(buffer, 0, buffer.Length);
                    fs.Close();
                }
            }
            else
            {
                this.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('目录不存在!');</script>");
            }
        }
        catch (Exception ex)
        {

            throw ex;

        }
    }

 

 
    protected void TreeView1_TreeNodeCollapsed(object sender, TreeNodeEventArgs e)
    {
        string FilePath = Server.MapPath("../XmlFile/");
        if (Directory.Exists(FilePath))
        {
            this.TreeView1.Nodes[0].ChildNodes.Clear();
            ReadXMLToTree.PopulateTreeView(FilePath, e.Node);
        }

    }
   
}

 

CS.../

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using System.IO;
using System.Web.UI.WebControls;
using System.Data;

/// <summary>
///ReadXMLToTree 的摘要说明
/// </summary>
public class ReadXMLToTree
{

    private static DataTable SortTable = null;
   
 public ReadXMLToTree()
 {
  //
  //TODO: 在此处添加构造函数逻辑
  //
 }
    public static void PopulateTreeView(string directory, TreeNode parentNode)
    {
      
        if (SortTable != null)
        {
            SortTable.Rows.Clear();
        }
        string[] directoryArray = Directory.GetDirectories(directory);
        string[] filesArray = Directory.GetFiles(directory);
        if (directoryArray.Length > 0)
        {    foreach (string item in directoryArray)
            {
                if (item != string.Empty && !item.Contains(".svn"))
                {
                    FileInfo cinfo = new FileInfo(item);
                    TreeNode nodes = new TreeNode();
                   
                    nodes.Text = cinfo.Name;
                   
                    nodes.ImageUrl = "~/Image/file.gif";
                    parentNode.ChildNodes.Add(nodes);
                    PopulateTreeView(item, nodes);
                }
            }
        }
        if (filesArray.Length > 0)
        {
            int Count=filesArray.Length;

            for (int i = 0; i < Count; i++)
            {
                string item = filesArray[i].ToString();
                if (item != string.Empty && item.Contains(".Xml"))
                    {
                        FileInfo cinfo = new FileInfo(item);
                        //TreeNode nodes = new TreeNode();

                        string Urt = "<a   href='List.aspx?Url=" + cinfo.FullName + "'target='mainFrame'><b id='b1' οncοntextmenu='return showmenuie5(event)'>" + Path.GetFileNameWithoutExtension(cinfo.FullName) + "</b></a>";
                        SortNewTable(i, Urt, cinfo.FullName);
                        //nodes.Text = Urt;
                        //nodes.Value = cinfo.FullName;
                        //nodes.ImageUrl = "~/Image/xml.gif";
                        parentNode.ChildNodes.Add(nodes);
                    }
                //}
            }


            if (SortTable != null)
            {
                DataView SortView = SortTable.DefaultView;
                SortView.Sort = "Index Desc";

                DataTable ReturnTabel = SortView.ToTable();
                foreach (DataRow row in ReturnTabel.Rows)
                {
                 
                    TreeNode nodes = new TreeNode();
                    nodes.Text = row["Text"].ToString(); ;
                    nodes.Value = row["Value"].ToString();
                    nodes.ImageUrl = "~/Image/xml.gif";
                    parentNode.ChildNodes.Add(nodes);

               
                }

           
           
            }

 

 

 

        }
    }

    /// <summary>
    /// 创建啊临时表存储数据
    /// </summary>
    /// <param name="index"></param>
    /// <param name="text"></param>
    /// <param name="Value"></param>
    public static void SortNewTable(int index,string text ,string Value)
    {
        if (SortTable == null)
        {
            SortTable = new DataTable("SortTable");
            SortTable.Columns.Add("Index", Type.GetType("System.Int32")).DefaultValue = 0;
            SortTable.Columns.Add("Text", Type.GetType("System.String")).DefaultValue = string.Empty;
            SortTable.Columns.Add("Value", Type.GetType("System.String")).DefaultValue = string.Empty;
        }

        DataRow sorRow = SortTable.NewRow();
        sorRow["Index"] = index;
        sorRow["Text"] = text;
        sorRow["Value"] = Value;
        SortTable.Rows.Add(sorRow);
         
    }

 

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值