본문 바로가기

.NET/MOSS

MOSS => WebPart

 ImageRotate

이미지 로그를 배너와 비슷한 형식으로 이미지를 계속 돌리는  WebPart


using System;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization;

using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;

namespace ImageRotate
{
    [Guid("609ecd10-540b-4220-b29f-2366b3c5f231")]
    public class ImageRotate : System.Web.UI.WebControls.WebParts.WebPart
    {
        public ImageRotate()
        {
            this.ExportMode = WebPartExportMode.All;
        }

        protected override void Render(HtmlTextWriter writer)
        {
            SPWeb web = SPContext.GetContext(this.Context).Web;
            SPListItemCollection list = web.Lists["그림"].Items;
            string path = "/" + list.List.DefaultViewUrl.Split('/')[1] + "/_t/";

            writer.Write("<" + "script>");
            writer.Write("var ___st___ep = -1, ___stime = 10, ___wtime = 1000, ___ep;");
            writer.Write("var sle___ep = ___stime, ___cell = 94, ___total = " + string.Format("{0}", ((list.Count > 10) ? 10 : list.Count) - 2) + ", ___width = ___cell * ___total;");
            writer.Write("function ___do_stop(){");
            writer.Write("clearTimeout(___ep);");
            writer.Write("}");
            writer.Write("function ___do_move(){");
            writer.Write("var obj = document.getElementById('photo_layer').style;");
            writer.Write("obj.pixelLeft = (obj.pixelLeft + ___st___ep) % ___width;");
            writer.Write("if (obj.pixelLeft % ___cell == 1) sle___ep = ___wtime;");
            writer.Write("___ep = setTimeout(\"___do_move()\",sle___ep);");
            writer.Write("sle___ep = ___stime;");
            writer.Write("}");
            writer.Write("window.onload = function(){ ___do_move(); }");
            writer.Write("<" + "/script>");
            writer.Write("<div style=\"width:282px; height:78px; overflow:hidden\" onmouseout=\"___do_move()\" onmouseover=\"___do_stop()\">");
            writer.Write("<div id=\"photo_layer\" style=\"width:282px; height:78px; position:absolute; left:1px; top:0px; z-index:1;\"> ");
            writer.Write("<table height=\"78\" cellspacing=\"0\" cellpadding=\"0\" id=\"table7\">");
            writer.Write("<tr valign=\"top\" height=78 bgcolor=\"#cccccc\">");

            int i = 0;
            while (i < list.Count && i <= 10)
            {
                SPListItem item = list[i];
                writer.WriteLine("<td width=98 height=\"78\"><a href=\"#\">");
                writer.WriteLine("<img src=\"" + path + item.Name.Replace('.', '_') + ".jpg\" width=\"94\" border=\"0\" />");
                writer.WriteLine("</td>");
                i++;
            }

            writer.Write("</tr>");
            writer.Write("</table>");
            writer.Write("</div>");
            writer.Write("</div>");
        }
    }
}

'.NET > MOSS' 카테고리의 다른 글

MOSS 개발 환경  (0) 2007.10.08
MOSS =>출.퇴근 체크  (2) 2007.10.04
MOSS => WebPart  (1) 2007.10.04
InfoPath 개발자를 위한 새로운 기능  (1) 2007.09.19
InfoPath 2007  (0) 2007.09.13
Microsoft Office SharePoint Server 2007 개요  (1) 2007.09.11