http://www.sufeinet.com/plugin.php?id=keke_group

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

分布式系统框架(V2.0) 轻松承载百亿数据,千万流量!讨论专区 - 源码下载 - 官方教程

HttpHelper爬虫框架(V2.7-含.netcore) HttpHelper官方出品,爬虫框架讨论区 - 源码下载 - 在线测试和代码生成

HttpHelper爬虫类(V2.0) 开源的爬虫类,支持多种模式和属性 源码 - 代码生成器 - 讨论区 - 教程- 例子

查看: 11494|回复: 2
打印 上一主题 下一主题

[功能帮助类] Assistant创建显示图像的标签和文件

[复制链接]
跳转到指定楼层
楼主
发表于 2012-10-29 11:07:09 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
导读部分
-------------------------------------------------------------------------------------------------------------
C#基类|C#自定义类|C#帮助类--系列导航文章
http://www.sufeinet.com/thread-655-1-1.html

下载之前你首先要注册成为会员哦,注册之后就可以直接下载啦
更新时间:2012-10-29
最新的Assistant类下载:
Assistant.zip (3.18 KB, 下载次数: 163)
下面看看代码吧
[C#] 纯文本查看 复制代码
/// <summary>
/// 类说明:Assistant 
/// 联系方式:361983679  
/// 更新网站:[url=http://www.sufeinet.com/thread-655-1-1.html]http://www.sufeinet.com/thread-655-1-1.html[/url]
/// </summary>
using System;
using System.Text;
using System.Data;
using OWCChart;

namespace DotNet.Utilities
{
    /// <summary>
    /// Assistant 的摘要说明。
    /// </summary>
    public sealed class Assistant
    {


        #region 创建显示图像的标签

        /// <summary>
        /// 创建显示图像的标签(flash加点击)
        /// </summary>
        public static string CreateTag(string ADID, string filename, string desc, string FileType, string LinkURL, int Width, int High)
        {
            StringBuilder TagStr = new StringBuilder();
            switch (FileType)
            {
                case "image/gif":
                case "image/bmp":
                case "image/pjpeg":
                    {
                        if ((LinkURL.Trim() != "") && (LinkURL.Trim() != "http://"))//非空
                        {
                            TagStr.Append("<a href=\"");
                            TagStr.Append(ConfigHelper.GetConfigString("URL") + "/FormAdHit.aspx?ADID=" + ADID);
                            TagStr.Append("&LinkURL=" + LinkURL.Replace("&", "$$$"));
                            TagStr.Append("\"");
                            TagStr.Append(" target=\"_blank\">");
                        }
                        TagStr.Append(" <IMG alt=\"" + desc + "\"");
                        TagStr.Append(" src=\"" + filename + "\"");
                        TagStr.Append(" width=\"" + Width + "\" height=\"" + High + "\" ");
                        TagStr.Append(" border=\"0\">");
                        if ((LinkURL.Trim() != "") && (LinkURL.Trim() != "http://"))
                        {
                            TagStr.Append("</a>");
                        }
                        break;
                    }

                case "application/x-shockwave-flash":
                    {
                        //          TagStr.Append("<object ");
                        ////          TagStr.Append(" width="+Width+" height="+High+" ");
                        //          TagStr.Append("  classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\"  ");
                        //          TagStr.Append(" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0\"> ");
                        ////          TagStr.Append(" <param name=\"movie\" value=\""+filename+"?clickthru=");
                        ////          TagStr.Append("FormAdHit.aspx?ADID="+ADID);
                        ////          TagStr.Append("_LinkURL="+LinkURL);
                        ////          TagStr.Append("\"> ");          
                        //          TagStr.Append(" <param name=\"wmode\" value=\"opaque\"> ");
                        //          TagStr.Append(" <param name=\"quality\" value=\"autohigh\"> ");
                        //          
                        //          TagStr.Append(" <embed  ");
                        //          TagStr.Append(" width="+Width+" height="+High+"  ");
                        //          TagStr.Append(" src=\""+filename+"?clickthru=");
                        //          TagStr.Append("FormAdHit.aspx?ADID="+ADID);
                        //          if((LinkURL.Trim()!="")&&(LinkURL.Trim()!="http://"))
                        //          {
                        //            TagStr.Append("_LinkURL="+LinkURL);
                        //          }
                        //          TagStr.Append("\"  ");  
                        //          TagStr.Append(" quality=\"high\" wmode=\"opaque\" type=\"application/x-shockwave-flash\"  ");
                        //          TagStr.Append(" plugspace=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\"> ");
                        //          TagStr.Append(" </embed></object> ");

                        TagStr.Append(" <embed ");
                        TagStr.Append(" src=\"" + filename + "\" ");
                        //          TagStr.Append(" src=\""+filename+"?clickthru=");
                        //          TagStr.Append("FormAdHit.aspx?ADID="+ADID);
                        //          if((LinkURL.Trim()!="")&&(LinkURL.Trim()!="http://"))
                        //          {
                        //            TagStr.Append("_LinkURL="+LinkURL);
                        //          }
                        //          TagStr.Append("\"  ");  
                        TagStr.Append(" width=" + Width + " height=" + High + "  ");
                        TagStr.Append(" quality=\"high\" ");
                        TagStr.Append(" ></embed>");

                    }

                    break;

                case "video/x-ms-wmv":
                case "video/mpeg":
                case "video/x-ms-asf":
                case "video/avi":
                case "audio/mpeg":
                case "audio/mid":
                case "audio/wav":
                case "audio/x-ms-wma":
                    TagStr.Append("<embed");
                    TagStr.Append(" src=\"" + filename + "\" border=\"0\" ");
                    TagStr.Append(" width=\"" + Width + "\" height=\"" + High + "\"");
                    TagStr.Append(" autoStart=\"1\" playCount=\"0\" enableContextMenu=\"0\"");
                    TagStr.Append(" type=\"application/x-mplayer2\"></embed>");
                    break;

                default:
                    //TagStr.Append("不允许该格式文件显示!");
                    break;
            }

            return TagStr.ToString();

        }


        /// <summary>
        /// 创建显示图像的标签(flash无点击)
        /// </summary>    
        public static string CreateTag2(string ADID, string filename, string desc, string FileType, string LinkURL, int Width, int High)
        {
            StringBuilder TagStr = new StringBuilder();
            switch (FileType)
            {
                case "image/gif":
                case "image/bmp":
                case "image/pjpeg":
                    {
                        TagStr.Append("<a href=\"");
                        TagStr.Append(ConfigHelper.GetConfigString("URL") + "\\FormAdHit.aspx?ADID=" + ADID);
                        TagStr.Append("&LinkURL=" + LinkURL);
                        TagStr.Append("\"");
                        TagStr.Append(" target=\"_blank\">");
                        TagStr.Append(" <IMG alt=\"" + desc + "\"");
                        TagStr.Append(" src=\"" + filename + "\"");
                        TagStr.Append(" width=\"" + Width + "\" height=\"" + High + "\" ");
                        TagStr.Append(" border=\"0\">");
                        TagStr.Append("</a>");
                        break;
                    }

                case "application/x-shockwave-flash":
                    {
                        //          TagStr.Append("<a href=\"");
                        //          TagStr.Append(LinkURL);
                        //          TagStr.Append("FormAdHit.aspx?ADID="+ADID);
                        //          TagStr.Append("&LinkURL="+LinkURL);
                        //          TagStr.Append("\"");
                        //          TagStr.Append(" target=\"_blank\">");

                        TagStr.Append(" <embed src=\"" + filename + "\" ");
                        TagStr.Append(" quality=\"high\" bgcolor=\"#f5f5f5\" ");
                        TagStr.Append(" ></embed>");

                        //          TagStr.Append("</a>");
                    }

                    break;

                case "video/x-ms-wmv":
                case "video/mpeg":
                case "video/x-ms-asf":
                case "video/avi":
                case "audio/mpeg":
                case "audio/mid":
                case "audio/wav":
                case "audio/x-ms-wma":

                    //          TagStr.Append("<a href=\"");
                    //          TagStr.Append(LinkURL);
                    //          TagStr.Append("FormAdHit.aspx?ADID="+ADID);
                    //          TagStr.Append("&LinkURL="+LinkURL);
                    //          TagStr.Append("\"");
                    //          TagStr.Append(" target=\"_blank\">");
                    TagStr.Append("<embed");
                    TagStr.Append(" src=\"" + filename + "\" border=\"0\" ");
                    TagStr.Append(" width=\"" + Width + "\" height=\"" + High + "\"");
                    TagStr.Append(" autoStart=\"1\" playCount=\"0\" enableContextMenu=\"0\"");
                    TagStr.Append(" type=\"application/x-mplayer2\"></embed>");
                    //          TagStr.Append("</a>");


                    break;

                default:
                    //          TagStr.Append("不允许该格式文件显示!");
                    break;
            }

            return TagStr.ToString();

        }


        /// <summary>
        /// 创建显示图像的标签(重载),无宽高限制,(flash加点击)
        /// </summary>
        public static string CreateTag(string ADID, string filename, string desc, string FileType, string LinkURL)
        {
            StringBuilder TagStr = new StringBuilder();
            switch (FileType)
            {
                case "image/gif":
                case "image/bmp":
                case "image/pjpeg":
                    {
                        TagStr.Append("<a href=\"");
                        TagStr.Append(ConfigHelper.GetConfigString("URL") + "\\FormAdHit.aspx?ADID=" + ADID);
                        TagStr.Append("&LinkURL=" + LinkURL);
                        TagStr.Append("\"");
                        TagStr.Append(" target=\"_blank\">");
                        TagStr.Append(" <IMG alt=\"" + desc + "\"");
                        TagStr.Append(" src=\"" + filename + "\"");
                        //          TagStr.Append(" width=\""+Width+"\" height=\""+High+"\" ");
                        TagStr.Append(" border=\"0\">");
                        TagStr.Append("</a>");
                        break;
                    }

                case "application/x-shockwave-flash":
                    {
                        TagStr.Append("<object ");
                        //          TagStr.Append(" width="+Width+" height="+High+" ");
                        TagStr.Append("  classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\"  ");
                        TagStr.Append(" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0\"> ");
                        //          TagStr.Append(" <param name=\"movie\" value=\""+filename+"?clickthru=");
                        //          TagStr.Append("FormAdHit.aspx?ADID="+ADID);
                        //          TagStr.Append("_LinkURL="+LinkURL);
                        //          TagStr.Append("\"> ");          
                        TagStr.Append(" <param name=\"wmode\" value=\"opaque\"> ");
                        TagStr.Append(" <param name=\"quality\" value=\"autohigh\"> ");
                        TagStr.Append(" <embed  ");
                        //          TagStr.Append(" width="+Width+" height="+High+"  ");
                        TagStr.Append(" src=\"" + filename + "?clickthru=");
                        TagStr.Append(ConfigHelper.GetConfigString("URL") + "\\FormAdHit.aspx?ADID=" + ADID);
                        TagStr.Append("_LinkURL=" + LinkURL);
                        TagStr.Append("\"  ");
                        TagStr.Append(" quality=\"autohigh\" wmode=\"opaque\" type=\"application/x-shockwave-flash\"  ");
                        TagStr.Append(" plugspace=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\"> ");
                        TagStr.Append(" </embed></object> ");
                    }

                    break;

                case "video/x-ms-wmv":
                case "video/mpeg":
                case "video/x-ms-asf":
                case "video/avi":
                case "audio/mpeg":
                case "audio/mid":
                case "audio/wav":
                case "audio/x-ms-wma":
                    TagStr.Append("<embed");
                    TagStr.Append(" src=\"" + filename + "\" border=\"0\" ");
                    //          TagStr.Append(" width=\""+Width+"\" height=\""+High+"\"");  
                    TagStr.Append(" autoStart=\"1\" playCount=\"0\" enableContextMenu=\"0\"");
                    TagStr.Append(" type=\"application/x-mplayer2\"></embed>");


                    break;

                default:
                    break;
            }

            return TagStr.ToString();

        }


        /// <summary>
        /// 创建显示图像的标签(重载),无宽高限制,(flash无点击)
        /// </summary>
        public static string CreateTag2(string ADID, string filename, string desc, string FileType, string LinkURL)
        {
            StringBuilder TagStr = new StringBuilder();
            switch (FileType)
            {
                case "image/gif":
                case "image/bmp":
                case "image/pjpeg":
                    {
                        TagStr.Append("<a href=\"");
                        TagStr.Append("FormAdHit.aspx?ADID=" + ADID);
                        TagStr.Append("&LinkURL=" + LinkURL);
                        TagStr.Append("\"");
                        TagStr.Append(" target=\"_blank\">");
                        TagStr.Append(" <IMG alt=\"" + desc + "\"");
                        TagStr.Append(" src=\"" + filename + "\"");
                        //          TagStr.Append(" width=\""+Width+"\" height=\""+High+"\" ");
                        TagStr.Append(" border=\"0\">");
                        TagStr.Append("</a>");
                        break;
                    }

                case "application/x-shockwave-flash":
                    {
                        TagStr.Append(" <embed src=\"" + filename + "\" ");
                        TagStr.Append(" quality=\"high\" bgcolor=\"#f5f5f5\" ");
                        TagStr.Append(" ></embed>");
                    }

                    break;

                case "video/x-ms-wmv":
                case "video/mpeg":
                case "video/x-ms-asf":
                case "video/avi":
                case "audio/mpeg":
                case "audio/mid":
                case "audio/wav":
                case "audio/x-ms-wma":
                    TagStr.Append("<embed");
                    TagStr.Append(" src=\"" + filename + "\" border=\"0\" ");
                    //          TagStr.Append(" width=\""+Width+"\" height=\""+High+"\"");  
                    TagStr.Append(" autoStart=\"1\" playCount=\"0\" enableContextMenu=\"0\"");
                    TagStr.Append(" type=\"application/x-mplayer2\"></embed>");


                    break;

                default:
                    break;
            }

            return TagStr.ToString();

        }


        #region
        /// <summary>
        /// 创建显示图像的标签
        /// </summary>
        /// <param name="filename"></param>
        /// <param name="desc"></param>
        /// <param name="FileType"></param>
        /// <param name="LinkURL"></param>
        /// <param name="Width"></param>
        /// <param name="High"></param>
        /// <returns></returns>
        public static string CreateTagOld(string filename, string desc, string FileType, string LinkURL, int Width, int High)
        {
            StringBuilder TagStr = new StringBuilder();
            switch (FileType)
            {
                case "image/gif":
                case "image/bmp":
                case "image/pjpeg":
                    {
                        TagStr.Append("<a href=\"");
                        TagStr.Append(LinkURL);
                        TagStr.Append("\"");
                        TagStr.Append(" target=\"_blank\">");
                        TagStr.Append(" <IMG alt=\"" + desc + "\"");
                        TagStr.Append(" src=\"" + filename + "\"");
                        TagStr.Append(" width=\"" + Width + "\" height=\"" + High + "\" border=\"0\">");
                        TagStr.Append("</a>");
                        break;
                    }

                case "application/x-shockwave-flash":
                    {
                        TagStr.Append("<a href=\"");
                        TagStr.Append(LinkURL);
                        TagStr.Append("\"");
                        TagStr.Append(" target=\"_blank\">");
                        TagStr.Append(" <embed src=\"" + filename + "\" ");
                        TagStr.Append(" quality=\"high\" bgcolor=\"#f5f5f5\"");
                        TagStr.Append(" ></embed>");

                        //          TagStr.Append(" <embed src=\""+filename+"\" ");    
                        //          TagStr.Append("pluginspage=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\"");          
                        //          TagStr.Append(" type=\"application/x-shockwave-flash\"");
                        //          TagStr.Append(" width=\""+Width+"\" height=\""+High+"\"");
                        //          TagStr.Append(" play=\"true\" loop=\"true\" quality=\"high\" scale=\"showall\" ");          
                        //          TagStr.Append(" ></embed>");

                        TagStr.Append("</a>");
                    }

                    break;

                case "video/x-ms-wmv":
                case "video/mpeg":
                case "video/x-ms-asf":
                case "video/avi":
                case "audio/mpeg":
                case "audio/mid":
                case "audio/wav":
                case "audio/x-ms-wma":
                    //          TagStr.Append("<a href=\"");
                    //          TagStr.Append(LinkURL);
                    //          TagStr.Append("\"");
                    //          TagStr.Append(" target=\"_blank\">");
                    //          TagStr.Append("<OBJECT  classid=\"clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6\" VIEWASTEXT>");
                    //          TagStr.Append("<PARAM NAME=\"URL\" VALUE=\""+filename+"\">");
                    //          TagStr.Append("<PARAM NAME=\"autoStart\" VALUE=\"1\">");
                    //          TagStr.Append("<PARAM NAME=\"enableContextMenu\" VALUE=\"0\" ></OBJECT>");  
                    //          TagStr.Append("</a>");

                    TagStr.Append("<a href=\"");
                    TagStr.Append(LinkURL);
                    TagStr.Append("\"");
                    TagStr.Append(" target=\"_blank\">");
                    TagStr.Append("<embed");
                    TagStr.Append(" src=\"" + filename + "\" border=\"0\" width=\"" + Width + "\" height=\"" + High + "\"");
                    TagStr.Append(" autoStart=\"1\" playCount=\"0\" enableContextMenu=\"0\"");
                    TagStr.Append(" type=\"application/x-mplayer2\"></embed>");
                    TagStr.Append("</a>");


                    break;

                default://其他类型作为附件链接下载
                    TagStr.Append("不允许该格式文件显示!");
                    break;
            }

            return TagStr.ToString();

        }

        #endregion

        #endregion

        #region   创建数据图形文件

        /// <summary>
        /// 创建数据图形文件
        /// </summary>
        /// <param name="dt">数据源</param>
        /// <param name="CharType">图类型 Column,Pie</param>
        /// <param name="ImagePath">图像存放目录</param>
        /// <param name="Title">图形标题</param>
        /// <returns></returns>
        public static string CreateChart(DataTable dt, string CharType, string ImagePath, string Title)
        {
            String PhaysicalImagePath = ImagePath;
            OWCChart.OWCChartFactory mychart = new OWCChartFactory(Title, PhaysicalImagePath, 530, 300, new OWCChartFontStyle());
            OWCChart.OWCSeriesClass MyItem = new OWCSeriesClass();

            MyItem.SeriesName = "次数";
            MyItem.SetDataSource(dt, "Item", "Value");
            switch (CharType)
            {
                case "Column":
                    mychart.CreateOneColumn("时间", "次", MyItem);
                    break;
                case "Pie":
                    mychart.CreateSinglePie(MyItem);
                    break;

            }
            String imageName = mychart.ExportPictuire();
            return imageName;
            //      Image1.ImageUrl = ".\\"+m_imagePath+imageName;

        }
        public static string CreateMultiColumns(DataTable[] dts, string ImagePath, string Title)
        {
            String PhaysicalImagePath = ImagePath;
            OWCChart.OWCChartFactory mychart = new OWCChartFactory(Title, PhaysicalImagePath, 530, 300, new OWCChartFontStyle());
            OWCChart.OWCSeriesClass[] MyItems = new OWCSeriesClass[dts.Length];

            MyItems[0] = new OWCSeriesClass();
            MyItems[0].SeriesName = "显示次数";
            MyItems[0].SetDataSource(dts[0], "Item", "Value");

            MyItems[1] = new OWCSeriesClass();
            MyItems[1].SeriesName = "点击次数";
            MyItems[1].SetDataSource(dts[1], "Item", "Value");


            mychart.CreateMultiColumns("时间", "次", MyItems);


            String imageName = mychart.ExportPictuire();
            return imageName;

        }

        public static string CreateSingleBar(DataTable dt, string CharType, string ImagePath, string Title)
        {
            String PhaysicalImagePath = ImagePath;
            OWCChart.OWCChartFactory mychart = new OWCChartFactory(Title, PhaysicalImagePath, 500, 600, new OWCChartFontStyle());
            OWCChart.OWCSeriesClass MyItem = new OWCSeriesClass();

            MyItem.SeriesName = "次数";
            MyItem.SetDataSource(dt, "Item", "Value");
            mychart.CreateSingleBar(" ", "", MyItem);
            String imageName = mychart.ExportPictuire();
            return imageName;
        }
        public static string CreateMultiBar(DataTable[] dts, string ImagePath, string Title)
        {
            String PhaysicalImagePath = ImagePath;
            OWCChart.OWCChartFactory mychart = new OWCChartFactory(Title, PhaysicalImagePath, 500, 600, new OWCChartFontStyle());
            OWCChart.OWCSeriesClass[] MyItems = new OWCSeriesClass[dts.Length];

            MyItems[0] = new OWCSeriesClass();
            MyItems[0].SeriesName = "显示次数";
            MyItems[0].SetDataSource(dts[0], "Item", "Value");

            MyItems[1] = new OWCSeriesClass();
            MyItems[1].SeriesName = "点击次数";
            MyItems[1].SetDataSource(dts[1], "Item", "Value");


            mychart.CreateMultiBar(" ", "", MyItems);


            String imageName = mychart.ExportPictuire();
            return imageName;

        }

        #endregion

        #region

        /// <summary>
        /// 从字符串里随机得到,规定个数的字符串.
        /// </summary>
        /// <param name="allChar"></param>
        /// <param name="CodeCount"></param>
        /// <returns></returns>
        private string GetRandomCode(string allChar, int CodeCount)
        {
            //string allChar = "1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,i,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z"; 
            string[] allCharArray = allChar.Split(',');
            string RandomCode = "";
            int temp = -1;
            Random rand = new Random();
            for (int i = 0; i < CodeCount; i++)
            {
                if (temp != -1)
                {
                    rand = new Random(temp * i * ((int)DateTime.Now.Ticks));
                }

                int t = rand.Next(allCharArray.Length - 1);

                while (temp == t)
                {
                    t = rand.Next(allCharArray.Length - 1);
                }

                temp = t;
                RandomCode += allCharArray[t];
            }

            return RandomCode;
        }
        #endregion
    }
}




1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
沙发
发表于 2012-11-16 19:08:54 | 只看该作者
想提一个建议,以后最好附上一些关于此功能的实现的效果截图
板凳
发表于 2014-4-7 11:58:26 | 只看该作者
可以像Excel中图表一样生成图表吗?
您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

QQ|手机版|小黑屋|手机版|联系我们|关于我们|广告合作|苏飞论坛 ( 豫ICP备18043678号-2)

GMT+8, 2024-11-25 06:37

© 2014-2021

快速回复 返回顶部 返回列表