注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

回忆之旅

我很向往山村的农庄生活,他们的热情,让我无法抗拒! 51EOO.COM

 
 
 

日志

 
 

Asp.net 格子网制作代码  

2010-01-22 09:32:38|  分类: 技术分享 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;


using System.Data.OleDb;
using System.IO;


public partial class WebUserControl : System.Web.UI.UserControl
{

    delegate void ClientClick(string str);

    protected void Page_Load(object sender, EventArgs e)
    {
        CreateTable();

        string unit = "px";
        string strconn = ConnManager.Data_Conn().ToString();
        OleDbConnection conn = new OleDbConnection(strconn);
        OleDbCommand Ad = new OleDbCommand("select * from View_Grid", conn);
        conn.Open();
        OleDbDataReader read = Ad.ExecuteReader();
        while (read.Read())
        {
            int x = Convert.ToInt32(read["x"].ToString()); //横排第几格
            int y = Convert.ToInt32(read["y"].ToString()); //竖排第几格
            int number_x = Convert.ToInt32(read["number_x"].ToString()); //横排占几格
            int number_y = Convert.ToInt32(read["number_y"].ToString()); //竖排占几格
            string width = Convert.ToString(100 * number_x).ToString();
            string height = Convert.ToString(100 * number_y).ToString();
            string left = Convert.ToString((x - 1) * 100) + unit;
            string top = Convert.ToString((y - 1) * 100) + unit;
            string bottom = height + unit;
            string right = width + unit;
            ImageMap map = new ImageMap();
            map.DescriptionUrl = read["Dealer_ID"].ToString();
            map.ToolTip = read["Dealer_DoMainName"].ToString();
            map.ImageUrl = read["images"].ToString();
            FileInfo file = new FileInfo(Server.MapPath(read["images"].ToString()));
            if (!file.Exists)
            {
                map.BackColor = System.Drawing.Color.Red;
                string top1 = Convert.ToString((y - 1) * 100+30) + unit;
                string left1 = Convert.ToString((x - 1) * 100+10) + unit;
                CreateLinkButton(read["Dealer_ID"].ToString(), read["title"].ToString(), read["Dealer_DoMainName"].ToString(), right, bottom, left1, top1);
            }           
            MapAtribue(map);
            MapStyle(map);
            this.SetStyle(map.Style, right, bottom, left, top);
            map.Click += new ImageMapEventHandler(ImageMap1_Click);
            this.Controls.Add(map);
            RHS(map, 100 * number_x, 100 * number_y, map.ToolTip);
        }
        conn.Close();

    }

    /// <summary>
    /// 添加ImageMpa信息
    /// </summary>
    /// <param name="map"></param>
    /// <param name="right"></param>
    /// <param name="bottom"></param>
    /// <param name="descriptionUrl"></param>
    protected void RHS(ImageMap map, int right, int bottom, string tooltip)
    {
        RectangleHotSpot re = new RectangleHotSpot();
        re.Left = 0;
        re.Right = right;
        re.Bottom = bottom;
        re.Top = 0;
        re.PostBackValue = "Client";
        re.Target = "_blank";
        re.HotSpotMode = HotSpotMode.PostBack;
        re.NavigateUrl = tooltip;
        re.AlternateText = tooltip;       
        map.HotSpots.Add((HotSpot)re);

    }

    /// <summary>
    /// 设置ImageMap属性
    /// </summary>
    /// <param name="map"></param>
    protected void MapAtribue(ImageMap map)
    {
        map.HotSpotMode = HotSpotMode.PostBack;
        map.ImageAlign = ImageAlign.AbsMiddle;
    }

    /// <summary>
    /// 设置ImageMap样式
    /// </summary>
    /// <param name="map"></param>
    protected void MapStyle(ImageMap map)
    {
        Style Style = new Style();
        Style.CssClass = "image";
        map.ApplyStyle(Style);
    }

    /// <summary>
    /// 设置ImageMap样式
    /// </summary>
    /// <param name="style"></param>
    /// <param name="width"></param>
    /// <param name="height"></param>
    /// <param name="left"></param>
    /// <param name="top"></param>
    private void SetStyle(CssStyleCollection style, string width, string height, string left, string top)
    {
        style.Add("width", width);
        style.Add("height", height);
        style.Add("margin-left", left);
        style.Add("margin-top", top);
    }

    /// <summary>
    /// ImageMap1单击事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void ImageMap1_Click(object sender, ImageMapEventArgs e)
    {
        ImageMap im = (ImageMap)(sender);
        int id = Convert.ToInt32(im.DescriptionUrl.ToString());
        UpdateClick(id);
    }


    /// <summary>
    /// 创建LinkButton
    /// </summary>
    /// <param name="id"></param>
    /// <param name="text"></param>
    /// <param name="right"></param>
    /// <param name="bottom"></param>
    /// <param name="left"></param>
    /// <param name="top"></param>
    protected void CreateLinkButton(string id, string text, string right,string tooltip, string bottom, string left, string top)
    {
        LinkButton link = new LinkButton();
        link.ID = id.ToString();
        link.Text = text;
        link.ToolTip = tooltip;       
        if (link.Text.Length > 20) {
            link.Text = link.Text.Substring(0, 18) + "...";
        }
        Style Style = new Style();
        Style.CssClass = "linkbutton1";
        link.Height = 25;
        link.Width = 80;
        link.ApplyStyle(Style);
        this.LinkStyle(link.Style, left, top);
        link.Attributes.Add("onMouseOver", "this.style.color='Blue';this.style.cursor='hand';this.style.font='normal small-caps bold 10pt serif';");
        link.Attributes.Add("onMouseOut", "this.style.color='DarkBlue';this.style.font='normal small-caps normal 9pt serif';");
        link.Click += new EventHandler(link_Click);
        this.Controls.Add(link);

    }


    /// <summary>
    /// 设置LinkButton样式
    /// </summary>
    /// <param name="map"></param>
    private void LinkStyle(CssStyleCollection style,string left, string top)
    {
        style.Add("margin-left", left);
        style.Add("margin-top", top);
    }

    /// <summary>
    /// LinkButton单击事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void link_Click(object sender, EventArgs e)
    {
        LinkButton link = (LinkButton)(sender);
        int id = Convert.ToInt32(link.ID.ToString());
        UpdateClick(id);

    }

    /// <summary>
    /// 更新信息
    /// </summary>
    /// <param name="id"></param>
    protected void UpdateClick(int id)
    {
       
        string select = "select * from View_Grid where Dealer_ID=" + id + "";
        DataTable table = Data_Manager.ExecuteDataSet(select, "view_grid").Tables[0];
        int Dealer_Clickcount = Convert.ToInt32(table.Rows[0]["Dealer_Clickcount"].ToString()) + 1;
        string update = "update Tb_DealerInfo set Dealer_Clickcount=" + Dealer_Clickcount + " where Dealer_ID=" + id + "";
        Data_Manager.ExecuteNonQuery(update);
        string path = table.Rows[0]["Dealer_DoMainName"].ToString();
        if (path == "http:/" + "/" || path == "" || table.Rows[0]["IsLogin"].ToString() == "True")
        {
            Session["Userid"] = id.ToString();           
            Response.Redirect("Index.aspx?userid=" + Session["Userid"].ToString() + "");
        }
        else
        {
            Response.Redirect(path, true);
        }
    }

    /// <summary>
    /// 创建Table框架
    /// </summary>
    protected void CreateTable() {
        int j = 1;
        Style tablestyle = new Style();
        tablestyle.CssClass = "table";

        Style style2 = new Style();
        style2.CssClass = "row";

        Style style = new Style();
        style.CssClass = "Cell";


        Table table = new Table();
        table.ApplyStyle(style2);
        table.Width = 1000;
        table.Height = 1000;
        table.BackColor = System.Drawing.Color.White;
        Random rad1 = new Random();

        for (int row = 0; row < 1000; row += 100)
        {
            TableRow tablerow = new TableRow();
            tablerow.Height = 100;
            int i = 1;
            Random rad2 = new Random();

            for (int cell = 0; cell < 1000; cell += 100)
            {

                Random rad = new Random();
                TableCell tablecell = new TableCell();
                tablecell.ToolTip = "行:" + j + "  列:" + i + "" + "(" + row + "px," + cell + "px)";
                tablecell.Width = 100;
                tablecell.Height = 100;
                tablecell.BorderWidth = 1;
                tablecell.Attributes.Add("onMouseOver", "this.style.backgroundColor='#e9e9e9';this.style.cursor='hand';");
                tablecell.Attributes.Add("onMouseOut", "this.style.backgroundColor='#FFFFFF'");
                tablerow.Cells.Add(tablecell);
                i++;
            }
            j++;
            tablerow.BorderWidth = 1;
            table.Rows.Add(tablerow);
        }
        this.Controls.Add(table);

    }
}


 



Asp.net 格子网制作代码 - Tony - 回忆之旅
  评论这张
 
阅读(84)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017