using System;
using System.ComponentModel;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Serialization;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.WebPartPages;
using Microsoft.SharePoint.WebControls;
namespace SzseWebPart
{
 /// <summary>
 /// Description for PictureChange.
 /// </summary>
 [DefaultProperty("Text"),
  ToolboxData("<{0}:PictureChange runat=server></{0}:PictureChange>"),
  XmlRoot(Namespace="SzseWebPart")]
 public class PictureChange : Microsoft.SharePoint.WebPartPages.WebPart
 {
  private const string defaultText = "http://tuyq-n:2000";
  private const string defaultText1 = "/sites/jituan";
  private const string defaultText2 = "testttt";
  private const string defaultText3 = "test12323";

  private string localhost= defaultText;

  private string strsite=defaultText1;

  private string text=defaultText2;

  private string strview = defaultText3;

  [Browsable(true),
  Category("设置"),
  DefaultValue(defaultText),
  WebPartStorage(Storage.Personal),
  FriendlyName("localhost地址"),
  Description("要显示的图片的服务器地址")]
  public string LocalHost
  {
   get
   {
    return localhost;
   }

   set
   {
    localhost = value;
   }
  }

  [Browsable(true),
  Category("设置"),
  DefaultValue(defaultText1),
  WebPartStorage(Storage.Personal),
  FriendlyName("Portal的路径"),
  Description("输入站点的路径")]
  public string StrSite
  {
   get
   {
    return strsite;
   }

   set
   {
    strsite = value;
   }
  }

  [Browsable(true),
   Category("设置"),
   DefaultValue(defaultText2),
   WebPartStorage(Storage.Personal),
   FriendlyName("图片库名称"),
   Description("要显示的图片库名称")]
  public string Text
  {
   get
   {
    return text;
   }

   set
   {
    text = value;
   }
  }

  [Browsable(true),
  Category("设置"),
  DefaultValue(defaultText3),
  WebPartStorage(Storage.Personal),
  FriendlyName("视图的名称"),
  Description("要显示的视图的名称")]
  public string StrView
  {
   get
   {
    return strview;
   }

   set
   {
    strview = value;
   }
  }

 
 
  /// <summary>
  /// This method gets the custom tool parts for this Web Part by overriding the
  /// GetToolParts method of the WebPart base class. You must implement
  /// custom tool parts in a separate class that derives from
  /// Microsoft.SharePoint.WebPartPages.ToolPart.
  /// </summary>
  ///<returns>An array of references to ToolPart objects.</returns>
//  public override ToolPart[] GetToolParts()
//  {
//   ToolPart[] toolparts = new ToolPart[2];
//   WebPartToolPart wptp = new WebPartToolPart();
//   CustomPropertyToolPart custom = new CustomPropertyToolPart();
//   toolparts[0] = wptp;
//   toolparts[1] = custom;
//   return toolparts;
//  }
 
  /// <summary>
  /// Render this Web Part to the output parameter specified.
  /// </summary>
  /// <param name="output"> The HTML writer to write out to </param>
  protected override void RenderWebPart(HtmlTextWriter output)
  {
   output.Write(this.GetPicture());
  }
  
  private string GetPicture()
  {
   
   #region

   string result1 = @"<table cellspacing='0' cellpadding='0' border='0' align='center' width='100%'>
       <tr>
        <td height='8'></td>
       </tr>
       <tr align='center'>
        <td align='center' width='100%' >
         <a name='aAD' id='aAD' href='' target='blank'>
          <img name='imgAD' id='imgAD'>
         </a>
        </td>
       </tr>
       <tr align='center'>
        <td align='center'>
         <label id='lblAD'>
        </td>
       </tr>
       </table>
       <script language='javascript'>
         var ImgTitle = new Array();
         var Img = new Array();
         var ImgLink = new Array();
         ";
   string result2 = @"
         var i = 1;

         function playImg()
         {
         ";
   string result3 = @"i = i % {0};";
   string result4 = @"
          i = i == 0 ? 1 : i;
          document.all.imgAD.src = Img[i-1];
          document.all.aAD.href = ImgLink[i-1];
          document.all.lblAD.innerText = ImgTitle[i-1];
          i++;
          window.setTimeout('playImg();',2000);
         }

         playImg();


        </script>";

   string scriptImgData = "";
   int ItemCount = 0;
 
   SPSite mysite = new SPSite(LocalHost);
   SPWeb myweb=mysite.OpenWeb(StrSite);
   //SPWeb myweb = SPControl.GetContextWeb(this.Context);
   SPList list = myweb.Lists[Text];
   SPView sview = list.Views[StrView];
   SPListItemCollection listItems = list.GetItems(sview);
   foreach(SPListItem item in listItems)
   {
    if(item.File!=null)
    {
     ItemCount ++;
     string img_name = item.File.Name.ToString().Trim().Replace(".","_").ToString();
     string img = myweb.Url + "/"+item.File.ParentFolder.ToString()+"/_t/"+item.File.Name.ToString().Trim().Replace(".","_").ToString()+".jpg";
     string img_link = myweb.Url + "/"+item.File.ParentFolder.ToString()+"/_w/"+item.File.Name.ToString().Trim().Replace(".","_").ToString()+".jpg";
     scriptImgData += string.Format(
      @"
          Img[{3}] = '{0}';
          ImgLink[{3}] = '{1}';
          ImgTitle[{3}] = '{2}';
         ",img
         ,img_link
      //",myweb.Url + "/"+item.File.ParentFolder.ToString()+"/_w/"+item.File.Name.ToString().Trim().Replace(".","_").ToString()+".jpg"
//      ,myweb.Url + "/" +item.File.Url
      ,item.File.Name,ItemCount - 1);
    }
   }
   //return string.Format(result,scriptImgData,ItemCount);
   return result1 + scriptImgData + result2 + string.Format(result3, ItemCount + 1) + result4;
#endregion

  }
  

 }
}

posted on 2006-07-21 17:53  volitation  阅读(503)  评论(0)    收藏  举报