承接MOSS各种工作流开发 联系人:王先生.电话:18618405729QQ:252385878 QQ群:41696750 MSN:wanghao-3@hotmail.com

导航

OA实用的套壳工具(精品)

      最近,在网上认识一个妹子,跟我提拉一个需求,她想做一个动态的导航菜单,但是不想用数控件,向我求救,我跟他说,直接在 moss里面动态 画一个不就可以拉,我在我这里交他的方法,现在我在这里教大家怎么画出一个比较万能的数控件,其实这个控键比较的简单,说白拉就一个WebPart 的连接的问题,,一边做导航,一边做View,下面 就来介绍一个qq菜单的样子,大概就是这个样子的,比较好看把。其实代码很简单,,我把代码贴出来恭大家参考,我这个Demo的主要是你在工具拦定制好 合理的xml就可以出现你想要的 qq菜单。。这个功能非常强大,可以套整个oa系统全部都可以套出来
提供类:

using System;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
using Microsoft.SharePoint.WebPartPages.Communication;
using Microsoft.SharePoint.Utilities;
using System.Security;
using System.Security.Permissions;
using System.Xml;
using System.Xml.Schema;
using System.Drawing;
namespace Lh_Provider
{
    public class NavLinkButton : LinkButton
    {
        public string Url;
        public string target;

    }

    public class NavImageButton : ImageButton
    {
        public string Url;
        public string target;

    }

   // [Guid("43590815-8821-46bf-ad75-d933b7604796")]
    [DefaultProperty("Text"),
  ToolboxData("<{0}:RightProvider runat=server></{0}:RightProvider>"),
  XmlRoot(Namespace="RightProviderConsumer")]
    public class Lh_Provider :Microsoft.SharePoint.WebPartPages.WebPart,IRowProvider
    {

        private DataTable dtTransfer = null;  //我们要把dtTransfer.Rows传递出去
        private uint curIndex = 0;      //当前选择的菜单编号

        private bool dbFirst = false;
        private string strImagePath = "/_layouts/images/";

        private NavLinkButton[] menus;           // 1 level menu
        private NavLinkButton[][] items;      //two level menu

        private NavImageButton[][] itemsImage;

        //note error info
        private string strError = "";
        public event RowProviderInitEventHandler RowProviderInit;
        public event RowReadyEventHandler RowReady;

        private bool _connected = false;
        private string _connectedWebPartTitle = string.Empty;
        private string _registrationErrorMsg = "occurred";
        private bool _registrationErrorOccurred = false;
        private string _notConnectedMsg = "Not Connection ";

        //declare variables for row information

        private string[] _rowFieldNames;
        private string[] _rowFieldDisplayNames;

        private const string defaultXml = "";
        private string xml = defaultXml;
        [Browsable(true),
        Category("导航设置--xml"),
        DefaultValue(defaultXml),
        Description("Xml文本"),
        FriendlyName("Xml"),
        WebPartStorage(Storage.Personal)]
        public string Xml
        {
            get
            {
                return xml;
            }

            set
            {
                xml = value;
            }
        }

        //对应display属性  
        private const string con_display = "";
        private string display = con_display;
        [Browsable(true),
        Category("显示标题"),
        DefaultValue(con_display),
        Description("显示标题"),
        FriendlyName("显示标题"),
        WebPartStorage(Storage.Personal)]
        public string Display
        {
            get
            {
                return display;
            }

            set
            {
                display = value;
            }
        }

        //默认页面属性,在CreateDataTableForTransfer()里用到。

        private const string cdefaultUrl = "";
        private string defaultUrl = cdefaultUrl;
        [Browsable(true),
        Category("导航设置--defaultUrl"),
        DefaultValue(cdefaultUrl),
        Description("初始化时Consumer跳转到的页面"),
        FriendlyName("默认页面"),
        WebPartStorage(Storage.Personal)]
        public string DefaultUrl
        {
            get
            {
                return defaultUrl;
            }

            set
            {
                defaultUrl = value;
            }
        }

        public enum xmldbtype
        {
            db,
            xml
        };

        private const xmldbtype defaultSource = xmldbtype.db;
        //private xmldbtype xmlOrDB=defaultSource;
        private xmldbtype xmlOrDB = xmldbtype.xml;
        [Browsable(true),
        Category("导航信息来源"),
        DefaultValue(defaultSource),
        WebPartStorage(Storage.Personal),
        FriendlyName("选择导航信息来源:如果是Xml,请选择\"xml\",如果是数据库,请填\"db\""),
        Description("选择导航信息来源:如果是Xml,请选择\"xml\",如果是数据库,请填\"db\"")
        ]
        public xmldbtype XmlOrDB
        {
            get
            {
                return xmlOrDB;
            }

            set
            {
                xmlOrDB = value;
            }
        }
 
        public Lh_Provider()
        {
            this.ExportMode = WebPartExportMode.All;
            this.FrameType = Microsoft.SharePoint.WebPartPages.FrameType.None;
            this.Load += new EventHandler(Lh_Provider_Load);
        }

        void Lh_Provider_Load(object sender, EventArgs e)
        {
            //throw new Exception("The method or operation is not implemented.");
            dtTransfer = CreateDataTableForTransfer();
        }


        /// <summary>
        /// 从Xml属性中的字符串读取导航信息.
        /// </summary>
        private void ReadXml()
        {
            XmlDocument myDoc = new XmlDocument();
            myDoc.LoadXml(Xml);
            XmlNodeList menusList = myDoc.GetElementsByTagName("Menu");

            menus = new NavLinkButton[menusList.Count];
            items = new NavLinkButton[menusList.Count][];
            itemsImage = new NavImageButton[menusList.Count][];

            for (int i = 0; i < menusList.Count; i++)  //foreach menu
            {
                menus[i] = new NavLinkButton();
                menus[i].Click += new EventHandler(NavProvider_Menu_Click);
                menus[i].Text = menusList[i].Attributes["Name"].Value;
                //menus[i].target ="_blank";
                try
                {
                    menus[i].Url = menusList[i].Attributes["Url"].Value;
                }
                catch { }
                try
                {
                    //menus[i].WindowWidth = Convert.ToInt32( menusList[i].Attributes["WindowWidth"].Value );
                }
                catch { }
                try
                {
                    //menus[i].WindowHeight = Convert.ToInt32( menusList[i].Attributes["WindowHeight"].Value );
                }
                catch { }

                this.Controls.Add(menus[i]);

                XmlNodeList curitems = ((XmlElement)menusList[i]).GetElementsByTagName("Item");

                items[i] = new NavLinkButton[curitems.Count];
                itemsImage[i] = new NavImageButton[curitems.Count];
                for (int j = 0; j < curitems.Count; j++) //foreach item
                {
                    // 创建Linkbutton
                    items[i][j] = new NavLinkButton();
                    items[i][j].Click += new EventHandler(NavProvider_Item_Click);
                    items[i][j].Text = curitems[j].Attributes["Name"].Value;
                    items[i][j].Url = curitems[j].Attributes["Url"].Value;
                    //items[i][j].target = "_blank";
                    itemsImage[i][j] = new NavImageButton();
                    itemsImage[i][j].Click += new ImageClickEventHandler(NavProvider_Image_Click);
                    try
                    {
                        itemsImage[i][j].ImageUrl = strImagePath + curitems[j].Attributes["Image"].Value;
                    }
                    catch { }
                    itemsImage[i][j].Url = curitems[j].Attributes["Url"].Value;


                    // 下面读取可能不存在的信息。
                    try
                    {
                        //items[i][j].WindowWidth = Convert.ToInt32( curitems[j].Attributes["WindowWidth"].Value );
                        //itemsImage[i][j].WindowWidth = items[i][j].WindowWidth;
                    }
                    catch { }
                    try
                    {
                        //items[i][j].WindowHeight = Convert.ToInt32( curitems[j].Attributes["WindowHeight"].Value );
                        //itemsImage[i][j].WindowHeight = items[i][j].WindowHeight;
                    }
                    catch { }
                    // 添加控件。
                    this.Controls.Add(items[i][j]);
                    this.Controls.Add(itemsImage[i][j]);
                }
            }
        }

        public override void EnsureInterfaces()
        {
            //base.EnsureInterfaces();
            try
            {
                RegisterInterface("MyRowProviderInterface", InterfaceTypes.IRowProvider,Microsoft.SharePoint.WebPartPages.WebPart.UnlimitedConnections, ConnectionRunAt.Server, this, "", "Provider Row to ", "Provides a row to a consumer webPart", true);

            }
            catch (SecurityException se)
            {
                _registrationErrorOccurred = true;
            }
           
        }

        public override ConnectionRunAt CanRunAt()
        {
            return ConnectionRunAt.ServerAndClient;
        }

        public override void PartCommunicationConnect(string interfaceName, Microsoft.SharePoint.WebPartPages.WebPart connectedPart, string connectedInterfaceName, ConnectionRunAt runAt)
        {
            //base.PartCommunicationConnect(interfaceName, connectedPart, connectedInterfaceName, runAt);
            if (interfaceName == "MyRowProviderInterface")
            {
                _connected = true;
                _connectedWebPartTitle = SPEncode.HtmlEncode(connectedPart.Title);
            }
        }

        public override void PartCommunicationInit()
        {
            //base.PartCommunicationInit();
            EnsureChildControls();

            if (_connected)
            {
                //If there is a listener, fire the RowProviderInit event.
                if (RowProviderInit != null)
                {
                    //Create the RowProviderInitEventArgs object for the RowProviderInit event.
                    RowProviderInitEventArgs rowProviderInitEventArgs = new RowProviderInitEventArgs();

                    //Set the row field names.
                    rowProviderInitEventArgs.FieldList = _rowFieldNames;

                    //Set the row field display names.
                    rowProviderInitEventArgs.FieldDisplayList = _rowFieldDisplayNames;

                    //Fire the RowProviderInit event.
                    RowProviderInit(this, rowProviderInitEventArgs);
                }
            }
        }

        public override void PartCommunicationMain()
        {
            if (_connected)
            {
                //If there is a listener, fire the RowReady event.
                if (RowReady != null)
                {
                    //Create the RowReadyEventArgs object for the RowReady event.
                    RowReadyEventArgs rowReadyEventArgs = new RowReadyEventArgs();

                    //设置要传输的Rows
                    DataRow[] dr = new DataRow[1];
                    dr[0] = dtTransfer.Rows[0];
                    rowReadyEventArgs.Rows = dr;

                    //这个selectionStatus没用。
                    string selectionStatus = "";
                    rowReadyEventArgs.SelectionStatus = selectionStatus;

                    //Fire the RowReady event.
                    RowReady(this, rowReadyEventArgs);
                }
            }
        }

        public override InitEventArgs GetInitEventArgs(string InterfaceName)
        {
            //Check if this is my particular row interface.
            if (InterfaceName == "MyRowProviderInterface")
            {
                //Ensure controls have been created.
                EnsureChildControls();

                //Create the RowProviderInitEventArgs object for the RowProviderInit event.
                RowProviderInitEventArgs rowProviderInitEventArgs = new RowProviderInitEventArgs();

                //Set the field names.
                rowProviderInitEventArgs.FieldList = _rowFieldNames;

                //Set the field display names.
                rowProviderInitEventArgs.FieldDisplayList = _rowFieldDisplayNames;

                //return the RowProviderInitEventArgs object.
                return (rowProviderInitEventArgs);
            }
            else
            {
                return (null);
            }
        }


        protected SPWeb GetWeb()//如果当前用户所处位置为sps,则返回sps区域,如果用户所处位置为wss站点,则放回wss的web
        {
            SPWeb CurrentWeb = SPControl.GetContextWeb(Context);
            return CurrentWeb;
        }

        private void myReader(HtmlTextWriter output)
        {
            output.Write("<Script language=\"Javascript\">\n");
            output.WriteLine("function showHiddenWebDiv(strObjName){");
            output.WriteLine("for(var i = 0; i < nDivLayerCount; i ++){");
            output.WriteLine("var obj = document.getElementById(\"divLayer_\" + i + \"_End\");");
            output.WriteLine("obj.style.display = \"none\";");
            output.WriteLine("}");
            output.WriteLine("var obj2 = document.getElementById(\"divLayer_\" + strObjName + \"_End\");");
            output.WriteLine("obj2.style.display = \"\";");
            output.WriteLine("return true;");
            output.WriteLine("}");
            output.WriteLine("</Script>");
            try
            {
                output.Write("<TABLE border=\"0\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\">");
                output.Write("<tr><td><img height=\"18\" src=\"" + this.strImagePath + "left_01.gif\" width=\"150\"></td></tr>");
                output.Write("<tr><td vAlign=\"top\" background=\"" + this.strImagePath + "bg(11).gif\">");
                for (uint arg1 = uint.MinValue; arg1 < this.menus.Length; arg1 += 1)
                {
                    output.WriteLine(string.Concat(new object[] { "<TR><TD background=\"", this.strImagePath, "bg.gif\" height=\"30\"  valign=\"middle\" align=\"center\" onclick=\"Javascript:showHiddenWebDiv(", arg1, ")\">" }));
                    output.WriteLine("<A HREF=\"javascript:;\">");
                    if (this.menus[(int)((IntPtr)arg1)].Url == "")
                    {
                        output.Write(this.menus[(int)((IntPtr)arg1)].Text);
                    }
                    else
                    {
                        this.menus[(int)((IntPtr)arg1)].RenderControl(output);
                    }
                    output.Write("</A></TD></TR><TR><TD bgcolor=\"#FFFFFF\" align=\"Center\">");
                    output.WriteLine("<Div ID=\"divLayer_" + arg1 + "_End\" style=\"display:none\"><font color=\"#000000\">");
                    output.WriteLine("<table cellSpacing=\"1\" cellPadding=\"1\" bgColor=\"#dedfde\" border=\"0\"  width=\"100%\">");
                    for (uint i = uint.MinValue; i < this.items[(int)((IntPtr)arg1)].Length; i += 1)
                    {
                        output.WriteLine("<tr><td bgColor=\"#ffffff\">");
                        this.items[(int)((IntPtr)arg1)][(int)((IntPtr)i)].ForeColor = Color.Black;
                        try
                        {
                            this.itemsImage[(int)((IntPtr)arg1)][(int)((IntPtr)i)].Width = (Unit)11;
                            this.itemsImage[(int)((IntPtr)arg1)][(int)((IntPtr)i)].RenderControl(output);
                        }
                        catch
                        {
                        }
                        output.WriteLine("&nbsp;&nbsp;");
                        this.items[(int)((IntPtr)arg1)][(int)((IntPtr)i)].RenderControl(output);
                        output.WriteLine("</td></tr>");
                    }
                    output.WriteLine("</table>");
                    output.WriteLine("</font></Div></TD></TR>");
                }
                output.Write("</TD></TR>");
                output.WriteLine("<Script Language=\"Javascript\">var nDivLayerCount=" + this.menus.Length + ";");
                output.WriteLine("showHiddenWebDiv(" + this.curIndex + ");</Script>");
                output.Write("</td></tr>");
                output.Write("<tr><td><img height=\"18\" src=\"" + this.strImagePath + "left_02.gif\" width=\"150\"></td></tr>");
                output.Write("</TABLE>");
            }
            catch (Exception exception1)
            {
                output.Write(exception1.ToString());
                output.Write("</TD></TR></TABLE>");
            }
        }

        // Create the Web Part user interface controls.
        protected override void CreateChildControls()
        {
            // 尝试从两种可能的数据来源读取导航信息。
            if (this.XmlOrDB == xmldbtype.db)
            {
                dbFirst = true;
            }
            else if (this.XmlOrDB == xmldbtype.xml)
            {
                dbFirst = false;
            }
            else { }


            if (dbFirst) //数据库优先
            {
                try
                {
                    //ReadDatabase();
                }
                catch (Exception e)
   
                {
             
                    strError += e.Message;
                }
            }
            else
            {
                try
                {
                    ReadXml();
                }
                catch (Exception e)
                {
             
                    strError += e.Message;
                }
            }
        }


        private DataTable CreateDataTableForTransfer()
        {
            //dt包括三列:string Url, int WindowWidth, int WindowHeight
            DataTable dt = new DataTable();

            // Add four column objects to the table.
            DataColumn urlColumn = new DataColumn();
            urlColumn.DataType = System.Type.GetType("System.String");
            urlColumn.ColumnName = "Url";
            urlColumn.Caption = "Url";
            dt.Columns.Add(urlColumn);

            DataColumn windowwidthColumn = new DataColumn();
            windowwidthColumn.DataType = System.Type.GetType("System.Int32");
            windowwidthColumn.ColumnName = "WindowWidth";
            windowwidthColumn.Caption = "WindowWidth";
            dt.Columns.Add(windowwidthColumn);

            DataColumn windowheightColumn = new DataColumn();
            windowheightColumn.DataType = System.Type.GetType("System.Int32");
            windowheightColumn.ColumnName = "WindowHeight";
            windowheightColumn.Caption = "WindowHeight";
            dt.Columns.Add(windowheightColumn);

            // 加入一行,作为初始值
            DataRow dataRow;

            dataRow = dt.NewRow();
            // 在这里设置了默认页面!!!
            dataRow["Url"] = DefaultUrl;

            // 新功能:如果页面url带参数则此参数指定的url最优先。
            string pagename = this.Page.Request.QueryString["pagename"];
            strError = pagename;
            if (pagename != null)
                dataRow["Url"] = pagename;
            //邱附加的代码(下面)
            if (this.Page.Request.QueryString.Count > 2)
            {
                dataRow["Url"] += "?";
                for (int i = 1; i < this.Page.Request.QueryString.Count; i++)
                {
                    dataRow["Url"] += this.Page.Request.QueryString.Keys[i].ToString() + "=" + this.Page.Request.QueryString[i].ToString() + "&";
                }
                dataRow["Url"] = dataRow["Url"].ToString().Substring(0, dataRow["Url"].ToString().Length - 1);

            }
            //邱附加的代码(上面)
            //dataRow["WindowWidth"] = defaultWindowWidth;
            //dataRow["WindowHeight"] = defaultWindowHeight;

            // 更新dt,确保其中只有一行。
            dt.Rows.Clear();
            dt.Rows.Add(dataRow);

            return dt;


        }


        protected override void Render(HtmlTextWriter output)
        {
            if (_registrationErrorOccurred)
            {
                output.Write(_registrationErrorMsg);
                return;
            }

            // Ensure that all of the Web Part's controls are created.
            EnsureChildControls();

            // Check if connected.
            if (_connected)
            {
                // 绘制工作放在myRender函数里。
                myReader(output);
            }
            else
            {
                // The Web Part isn't connected.
                output.Write(_notConnectedMsg);
            }
        }


        /// <summary>
        /// 点击事件发生后,生成要传输过去的字符串。该串将自动被发送。
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void NavProvider_Item_Click(object sender, EventArgs e)
        {
            // 根据被点击的按钮,创建dataRow
            string target = ((NavLinkButton)sender).target;
            if (target == "_blank")
            {
                this.Page.Response.Write("<script language=javascript> window.open ('" + ((NavLinkButton)sender).Url + "');</script>");
                for (uint i = 0; i < items.Length; i++)
                    for (uint j = 0; j < items[i].Length; j++)
                        if (items[i][j] == ((NavLinkButton)sender))
                        {
                            curIndex = i;
                            return;
                        }

            }
            else
            {
                // 更新dtTransfer,确保其中只有一行。
                dtTransfer.Rows.Clear();
                DataRow dataRow;
                dataRow = dtTransfer.NewRow();
                dataRow["Url"] = ((NavLinkButton)sender).Url;
                //dataRow["WindowWidth"] = ((NavLinkButton)sender).WindowWidth;
                //dataRow["WindowHeight"] = ((NavLinkButton)sender).WindowHeight;


                dtTransfer.Rows.Add(dataRow);

                for (uint i = 0; i < items.Length; i++)
                    for (uint j = 0; j < items[i].Length; j++)
                        if (items[i][j] == ((NavLinkButton)sender))
                        {
                            curIndex = i;
                            return;
                        }
            }
        }
        private void NavProvider_Menu_Click(object sender, EventArgs e)
        {
            string target = ((NavLinkButton)sender).target;
            if (target == "_blank")
            {
                this.Page.Response.Write("<script language=javascript> window.open ('" + ((NavLinkButton)sender).Url + "');</script>");
                for (uint i = 0; i < menus.Length; i++)
                    if (menus[i] == ((NavLinkButton)sender))
                    {
                        curIndex = i;
                        break;
                    }

            }
            else
            {
                // 根据被点击的按钮,创建dataRow
                dtTransfer.Rows.Clear();
                DataRow dataRow;
                dataRow = dtTransfer.NewRow();
                dataRow["Url"] = ((NavLinkButton)sender).Url;
                //dataRow["WindowWidth"] = ((NavLinkButton)sender).WindowWidth;
                //dataRow["WindowHeight"] = ((NavLinkButton)sender).WindowHeight;

                // 更新dtTransfer,确保其中只有一行。

                dtTransfer.Rows.Add(dataRow);

                for (uint i = 0; i < menus.Length; i++)
                    if (menus[i] == ((NavLinkButton)sender))
                    {
                        curIndex = i;
                        break;
                    }
            }
        }

        private void NavProvider_Image_Click(object sender, ImageClickEventArgs e)
        {
            string target = ((NavImageButton)sender).target;
            if (target == "_blank")
            {
                this.Page.Response.Write("<script language=javascript> window.open ('" + ((NavLinkButton)sender).Url + "');</script>");
                for (uint i = 0; i < itemsImage.Length; i++)
                    for (uint j = 0; j < itemsImage[i].Length; j++)
                        if (itemsImage[i][j] == ((NavImageButton)sender))
                        {
                            curIndex = i;
                            return;
                        }
            }
            else
            {

                // 根据被点击的按钮,创建dataRow
                // 更新dtTransfer,确保其中只有一行。
                dtTransfer.Rows.Clear();
                DataRow dataRow;
                dataRow = dtTransfer.NewRow();
                dataRow["Url"] = ((NavImageButton)sender).Url;
                //dataRow["WindowWidth"] = ((NavImageButton)sender).WindowWidth;
                //dataRow["WindowHeight"] = ((NavImageButton)sender).WindowHeight;

                // 更新dtTransfer,确保其中只有一行。
                dtTransfer.Rows.Clear();
                dtTransfer.Rows.Add(dataRow);
                for (uint i = 0; i < itemsImage.Length; i++)
                    for (uint j = 0; j < itemsImage[i].Length; j++)
                        if (itemsImage[i][j] == ((NavImageButton)sender))
                        {
                            curIndex = i;
                            return;
                        }
            }
        }
    }
}



接受类:

using System.Data;

using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Xml.Serialization;
using System.Security;
using System.Security.Permissions;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.WebPartPages;
using Microsoft.SharePoint.WebPartPages.Communication;

namespace Lh_Consumer
{
    [DefaultProperty("Text"),
    ToolboxData("<{0}:RightConsumer runat=server></{0}:RightConsumer>"),
    XmlRoot(Namespace = "RightProviderConsumer")]
    public class Lh_Consumer : Microsoft.SharePoint.WebPartPages.WebPart,IRowConsumer
    {

        private const int defaultWindowHeight = 500;
        private int windowHeight = defaultWindowHeight;

        [Browsable(true)]
        [Category("导航设置")]
        [DefaultValue(defaultWindowHeight)]
        [WebPartStorage(Storage.Personal)]
        [FriendlyName("链接页面高度")]
        [Description("链接页面高度")]

        public int WindowHeight
        {
            get
            {
                return windowHeight;
            }
            set
            {
                windowHeight = value;
            }
        }

        private const int defaultWindowWidth = 800;
        private int windowWidth = defaultWindowWidth;

        [Browsable(true),
        Category("导航设置"),
        DefaultValue(defaultWindowWidth),
        WebPartStorage(Storage.Personal),
        FriendlyName("链接页面宽度"),
        Description("链接页面宽度")]
        public int WindowWidth
        {
            get
            {
                return windowWidth;
            }

            set
            {
                windowWidth = value;
            }
        }


        //Frame控件
        private Microsoft.SharePoint.WebPartPages.PageViewerWebPart _myFrameWebPart = new PageViewerWebPart();

        //Declare variables for keeping track of connection state.
        private bool _connected = false;
        private string _connectedWebPartTitle = string.Empty;
        private string _registrationErrorMsg = "An error has occurred trying to register your connection interfaces.";
        private bool _registrationErrorOccurred = false;
        private string _notConnectedMsg = "NOT CONNECTED. To use this Web Part connect it to a Row Provider Web Part.";

        //Declare variables for Web Part user interface.
        //private string _connectedWebPartLabel = "Connected to Web Part";
        private string _selectionStatus = string.Empty;

        //Declare variables for row information.
        private string[] _rowFieldDisplayNames;
        DataRow[] _rowFieldValues = new DataRow[1];


        public Lh_Consumer()
        {
          //  this.ExportMode = WebPartExportMode.All;
        }

        public override void EnsureInterfaces()
        {
            //base.EnsureInterfaces();

            try
            {
                RegisterInterface("MyRowConsumerInterface",                 //InterfaceName   
                    InterfaceTypes.IRowConsumer,                            //InterfaceType
                    WebPart.LimitOneConnection,                             //MaxConnections
                    ConnectionRunAt.Server,                                 //RunAtOptions
                    this,                                                   //InterfaceObject
                    "",                                                     //InterfaceClientReference
                    "Consume Row From",                                     //MenuLabel
                    "Consumes a single row from another Web Part.");        //Description
            }
            catch (SecurityException se)
            {
                _registrationErrorOccurred = true;
            }
        }

 

        public override ConnectionRunAt CanRunAt()
        {
            //This Web Part can run on the server.
            return ConnectionRunAt.ServerAndClient;
        }

        public override void PartCommunicationConnect(string interfaceName,
            WebPart connectedPart,
            string connectedInterfaceName,
            ConnectionRunAt runAt)
        {
            //Keep track of the connection state.
            if (interfaceName == "MyRowConsumerInterface")
            {
                _connected = true;
                _connectedWebPartTitle = SPEncode.HtmlEncode(connectedPart.Title);
            }
        }

        public void RowProviderInit(object sender, RowProviderInitEventArgs rowProviderInitEventArgs)
        {
            //Store the field list
            _rowFieldDisplayNames = rowProviderInitEventArgs.FieldDisplayList;
        }

        public void RowReady(object sender, RowReadyEventArgs rowReadyEventArgs)
        {
            //Store the row values.
            if (rowReadyEventArgs.Rows[0] != null)
            {
                _rowFieldValues[0] = rowReadyEventArgs.Rows[0];
            }

            //读取传入信息,设置_myFrameWebPart
            //在下面代码中加入用户信息部分username将后面的参数拼在后面。
            string url = rowReadyEventArgs.Rows[0]["Url"].ToString();
            _myFrameWebPart.ContentLink = url;


            try
            {
                //_myFrameWebPart.Width  = rowReadyEventArgs.Rows[0]["WindowWidth"].ToString();
                _myFrameWebPart.Width = this.WindowWidth.ToString();
            }
            catch
            { }
            try
            {
                //_myFrameWebPart.Height = rowReadyEventArgs.Rows[0]["WindowHeight"].ToString();
                _myFrameWebPart.Height = this.WindowHeight.ToString();
            }
            catch
            { }

            //本程序中没有用到SelectionStatus
            _selectionStatus = rowReadyEventArgs.SelectionStatus;
        }

   
        protected override void OnLoad(EventArgs e)
        {
            //清除边框
            this.FrameType = Microsoft.SharePoint.WebPartPages.FrameType.None;
        }

        protected override void CreateChildControls()
        {
            _myFrameWebPart.FrameType = Microsoft.SharePoint.WebPartPages.FrameType.None;
            this.Controls.Add(_myFrameWebPart);
        }

        protected override void Render(HtmlTextWriter output)
        {
            if (_registrationErrorOccurred)
            {
                output.Write(_registrationErrorMsg);
                return;
            }
            if (_connected)
            {
                //显示Frame
                _myFrameWebPart.RenderControl(output);
            }
            else
            {
                output.Write(_notConnectedMsg);
            }
        }
    }
}


然后 xml规则

<?xml version="1.0" encoding="utf-8" ?><!-- edited with XMLSPY v5 U (http://www.xmlspy.com) by et8 (et8) --><NavMenu><Menu Name="个人日历" Url="/oa/uniteam/calendar/index.asp?systemkey=key7055475115&amp;mymkey=key2527276873&amp;myname=日历&amp;mykey=key8955150842&amp;myparentkey=key406915545&amp;mystatus=1">          <Item Name="日历" Url="/oa/uniteam/calendar/index.asp?systemkey=key7055475115&amp;mymkey=key2527276873&amp;myname=日历&amp;mykey=key8955150842&amp;myparentkey=key406915545&amp;mystatus=1"   Image="a1.gif" />           <Item Name="日历分配" Url="/oa/uniteam/calendar/frame1.asp?pagename=/oa/uniteam/calendar/add.asp&amp;group_task=yes&amp;systemkey=key7055475115&amp;mymkey=key8715936541&amp;myname=日程分配&amp;mykey=key6129353642&amp;myparentkey=key406915545&amp;mystatus=1"   Image="a2.gif" />          <Item Name="日程查询" Url="/oa/uniteam/calendar/select.asp?systemkey=key7055475115&amp;mymkey=key9047815203&amp;myname=日程查询&amp;mykey=key9458277225&amp;myparentkey=key406915545&amp;mystatus=1"   Image="a3.gif" />          <Item Name="日程类型配置" Url="/oa/uniteam/admin/type_admin.asp?systemkey=key7055475115&amp;mymkey=key1823999285&amp;myname=日程类型配置&amp;mykey=key7601999640&amp;myparentkey=key406915545&amp;mystatus=1"   Image="a5.gif" /> </Menu> <Menu Name="日程监控" Url="/oa/uniteam/ouplan/ourange.asp?systemkey=key7055475115&amp;mymkey=key4288598895&amp;myname=员工监控&amp;mykey=key1250683069&amp;myparentkey=key8398858904&amp;mystatus=1">       <Item Name="员工监控" Url="/oa/uniteam/ouplan/ourange.asp?systemkey=key7055475115&amp;mymkey=key4288598895&amp;myname=员工监控&amp;mykey=key1250683069&amp;myparentkey=key8398858904&amp;mystatus=1"   Image="a1.gif" />       <Item Name="权限管理" Url="/oa/uniteam/ouplan/frame1.asp?pagename=/oa/uniteam/ouplan/filetouser.asp&amp;systemkey=key7055475115&amp;mymkey=key8261682391&amp;myname=权限管理&amp;mykey=key9048054814&amp;myparentkey=key8398858904&amp;mystatus=1"   Image="a5.gif" /> </Menu> <Menu Name="工作总结" Url="/oa/uniteam/ouplan/frame1.asp?pagename=/oa/uniteam/ouplan/weekplan.asp&amp;systemkey=key7055475115&amp;mymkey=key4220697283&amp;myname=工作总结&amp;mykey=key283886194&amp;myparentkey=key7314874529&amp;mystatus=1">         <Item Name="工作总结" Url="/oa/uniteam/ouplan/frame1.asp?pagename=/oa/uniteam/ouplan/weekplan.asp&amp;systemkey=key7055475115&amp;mymkey=key4220697283&amp;myname=工作总结&amp;mykey=key283886194&amp;myparentkey=key7314874529&amp;mystatus=1"   Image="a1.gif" />         <Item Name="工作审批" Url="/oa/uniteam/ouplan/examine.asp?systemkey=key7055475115&amp;mymkey=key7996637225&amp;myname=工作审批&amp;mykey=key8081257939&amp;myparentkey=key7314874529&amp;mystatus=1"   Image="a5.gif" /> </Menu><Menu Name="项目管理" Url="/oa/uniteam/team/frame1.asp?pagename=/oa/uniteam/team/index.asp&amp;systemkey=key7055475115&amp;mymkey=key2452203631&amp;myname=项目列表&amp;mykey=key2651439905&amp;myparentkey=key9741021990&amp;mystatus=1">       <Item Name="项目列表" Url="/oa/uniteam/team/frame1.asp?pagename=/oa/uniteam/team/index.asp&amp;systemkey=key7055475115&amp;mymkey=key2452203631&amp;myname=项目列表&amp;mykey=key2651439905&amp;myparentkey=key9741021990&amp;mystatus=1"   Image="a1.gif" />       <Item Name="新增项目" Url="/oa/uniteam/team/frame1.asp?pagename=/oa/uniteam/team/add_team.asp&amp;systemkey=key7055475115&amp;mymkey=key5662042498&amp;myname=新增项目&amp;mykey=key448811650&amp;myparentkey=key9741021990&amp;mystatus=1"   Image="a5.gif" />        <Item Name="项目查询" Url="/oa/uniteam/team/select.asp?systemkey=key7055475115&amp;mymkey=key7245752215&amp;myname=项目查询&amp;mykey=key3777735233&amp;myparentkey=key9741021990&amp;mystatus=1"   Image="a2.gif" />        <Item Name="项目类别" Url="/oa/uniteam/team/show_class.asp?systemkey=key7055475115&amp;mymkey=key9937250018&amp;myname=项目类别&amp;mykey=key1921457648&amp;myparentkey=key9741021990&amp;mystatus=1"   Image="a3.gif" />        <Item Name="项目评估" Url="/oa/uniteam/team/pinggu.asp?systemkey=key7055475115&amp;mymkey=key8364374041&amp;myname=项目评估&amp;mykey=key9522913694&amp;myparentkey=key9741021990&amp;mystatus=1"   Image="a5.gif" /> </Menu> <Menu Name="假期管理" Url="/oa/holiday/shenqing.asp?systemkey=key7055475115&amp;mymkey=&amp;myname=假期申请&amp;mykey=key1675683856&amp;myparentkey=key7443811297&amp;mystatus=1">  <Item Name="假期申请" Url="/oa/holiday/shenqing.asp?systemkey=key7055475115&amp;mymkey=&amp;myname=假期申请&amp;mykey=key1675683856&amp;myparentkey=key7443811297&amp;mystatus=1"   Image="a1.gif" />  <Item Name="假期审批" Url="/oa/holiday/shenpi.asp?systemkey=key7055475115&amp;mymkey=&amp;myname=假期审批&amp;mykey=key6166650652&amp;myparentkey=key7443811297&amp;mystatus=1"   Image="a5.gif" />  <Item Name="申请结果" Url="/oa/holiday/jieguo.asp?systemkey=key7055475115&amp;mymkey=&amp;myname=申请结果&amp;mykey=key6440698504&amp;myparentkey=key7443811297&amp;mystatus=1"   Image="a2.gif" />  <Item Name="假期维护" Url="/oa/holiday/holiday.asp?systemkey=key7055475115&amp;mymkey=&amp;myname=假期维护&amp;mykey=key3544732928&amp;myparentkey=key7443811297&amp;mystatus=1"   Image="a3.gif" />  <Item Name="审批人管理" Url="/oa/holiday/checkmana.asp?systemkey=key7055475115&amp;mymkey=&amp;myname=审批人管理&amp;mykey=key7191430926&amp;myparentkey=key7443811297&amp;mystatus=1"   Image="a5.gif" />  <Item Name="申请统计" Url="/oa/holiday/tongji.asp?systemkey=key7055475115&amp;mymkey=&amp;myname=申请统计&amp;mykey=key7117425799&amp;myparentkey=key7443811297&amp;mystatus=1"   Image="a5.gif" /> </Menu> <Menu Name="奖金管理" Url="/oa/stipend/view.asp?systemkey=key7055475115&amp;mymkey=&amp;myname=查看奖金&amp;mykey=key724756121&amp;myparentkey=key1242944598&amp;mystatus=1">  <Item Name="查看奖金" Url="/oa/stipend/view.asp?systemkey=key7055475115&amp;mymkey=&amp;myname=查看奖金&amp;mykey=key724756121&amp;myparentkey=key1242944598&amp;mystatus=1"   Image="a1.gif" />  <Item Name="查询统计" Url="/oa/stipend/chaxun.asp?systemkey=key7055475115&amp;mymkey=&amp;myname=查询统计&amp;mykey=key6227685809&amp;myparentkey=key1242944598&amp;mystatus=1"   Image="a5.gif" />  <Item Name="奖金录入" Url="/oa/stipend/luru.asp?systemkey=key7055475115&amp;mymkey=&amp;myname=奖金录入&amp;mykey=key3146020770&amp;myparentkey=key1242944598&amp;mystatus=1"   Image="a2.gif" />  <Item Name="指标设置" Url="/oa/stipend/setting.asp?systemkey=key7055475115&amp;mymkey=&amp;myname=指标设置&amp;mykey=key3382837176&amp;myparentkey=key1242944598&amp;mystatus=1"   Image="a3.gif" />  <Item Name="奖金统计" Url="/oa/stipend/tongji.asp?systemkey=key7055475115&amp;mymkey=&amp;myname=奖金统计&amp;mykey=key2531396746&amp;myparentkey=key1242944598&amp;mystatus=1"   Image="a5.gif" /> </Menu>  <Menu Name="呼叫中心" Url="/C6/hujiaozhongxin/Lists/List/AllItems.aspx">  <Item Name="呼叫中心" Url="/C6/hujiaozhongxin/Lists/List/AllItems.aspx"   Image="a1.gif" /></Menu> </NavMenu>


配置好合理的 xml就可以拉。。是不是很简单。。也是实用。。。。
做一个,所有的页面 的导航 都ok 拉。。。嘿嘿,大家快去测试下哦。。


posted on 2007-08-06 10:45  A A  阅读(5023)  评论(24编辑  收藏  举报