通过web更新网站(1)

联系:手机/微信(+86 17813235971) QQ(107644445)

标题:通过web更新网站(1)

作者:惜分飞©版权所有[未经本人同意,不得以任何形式转载,否则有进一步追究法律责任的权利.]

现在维护的网站比较多,经常因为要修改一个小小的东西,要远程登录,或者ftp登录上去下载下来,然后在修改后,再上传上去,总之比较麻烦,我现在总体设想是通过web实现手工的更新网站,既实现通过web下载、上传、删除、编辑。
今天是实现了对整个站点的文件显示,下载和上传到对应目录,为该程序的第一部分
aspx代码

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript">
        function select_dir() {
            var select = document.getElementById("selectType");
            document.getElementById("h_dir").value = select.options[select.selectedIndex].value; ;
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <input id="h_dir" type="hidden" runat="server"/>
    <asp:Label ID="lbl_dir" runat="server" ></asp:Label>
    <asp:Button ID="btn_select" runat="server" Text="查看文件"
        onclick="btn_select_Click" />
    <div style="width:400px; height:500px; overflow:auto">
        <asp:Label ID="show_file" runat="server" ></asp:Label>
    </div>
    <asp:FileUpload ID="file_up" runat="server" />
    <asp:Button ID="btn_up" runat="server"   Text="上传文件" onclick="btn_up_Click" />
    </form>
</body>
</html>

cs代码

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Data;
using System.Threading;
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string web_file=Server.MapPath(".");
            DirectoryInfo thisOne = new DirectoryInfo(web_file);
           lbl_dir.Text="<select id='selectType' onclick='select_dir();' ><option value='" + System.Web.HttpContext.Current.Server.UrlEncode(web_file) + "'>网站目录</option>" + ListSelectShow(thisOne, 0, "") + "</select>";
           h_dir.Value = System.Web.HttpContext.Current.Server.UrlEncode(web_file);
           if (Request.QueryString["F"]!=null)
           {
                string d_file = System.Web.HttpContext.Current.Server.UrlDecode(Request.QueryString["F"].ToString());
               //求文件名
               string[] fs = d_file.Split('\\');
                string   ext = fs[fs.Length - 1];
               //下载文件
                Page.Response.Clear();
                bool success = ResponseFile(Page.Request, Page.Response, ext, d_file, 1024000);
                if (!success)
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('下载文件失败,请重试');", true);
                Page.Response.End();
           }
        }
    }
    public  string ListTreeShow(DirectoryInfo theDir, int nLevel, string Rn)//递归目录和 文件,树形结构显示
    {
        if (nLevel == 0)
        {
            FileInfo[] fileInfo = theDir.GetFiles();
            foreach (FileInfo fInfo in fileInfo)
            {
                Rn += "├";
                Rn += "<a href='Default.aspx?F=";
                Rn = Rn + System.Web.HttpContext.Current.Server.UrlEncode(fInfo.FullName);
                Rn += "'>";
                Rn += fInfo.Name.ToString() + "</a> <br />";
            }
        }
        DirectoryInfo[] subDirectories = theDir.GetDirectories();//获得目录
        foreach (DirectoryInfo dirinfo in subDirectories)
        {
            if (nLevel == 0)
            {
                Rn += "├";
            }
            else
            {
                string _s = "";
                for (int i = 1; i <= nLevel; i++)
                {
                    _s += "│&nbsp;";
                }
                Rn += _s + "├";
            }
            Rn += "<b>" + dirinfo.Name.ToString() + "</b><br />";
            FileInfo[] fileInfo = dirinfo.GetFiles();   //目录下的文件
            foreach (FileInfo fInfo in fileInfo)
            {
                if (nLevel == 0)
                {
                    Rn += "│&nbsp;├";
                }
                else
                {
                    string _f = "";
                    for (int i = 1; i <= nLevel; i++)
                    {
                        _f += "│&nbsp;";
                    }
                    Rn += _f + "│&nbsp;├";
                }
                Rn += "<a href='Default.aspx?F=";
                Rn = Rn + System.Web.HttpContext.Current.Server.UrlEncode(fInfo.FullName);
                Rn += "'>";
                Rn += fInfo.Name.ToString() + "</a><br />";
            }
            Rn = ListTreeShow(dirinfo, nLevel + 1, Rn);
        }
        return Rn;
    }
    public static string ListSelectShow(DirectoryInfo theDir, int nLevel, string Rn)//递归目录下拉框显示
    {
        DirectoryInfo[] subDirectories = theDir.GetDirectories();//获得目录
        foreach (DirectoryInfo dirinfo in subDirectories)
        {
            Rn += "<option value=\"" +System.Web.HttpContext.Current.Server.UrlEncode( dirinfo.FullName) + "\" >";
            if (nLevel == 0)
            {
                Rn += "├";
            }
            else
            {
                string _s = "";
                for (int i = 1; i <= nLevel; i++)
                {
                    _s += "│&nbsp;";
                }
                Rn += _s + "├";
            }
            Rn += "" + dirinfo.Name.ToString() + "</option>";
            Rn = ListSelectShow(dirinfo, nLevel + 1, Rn);
        }
        return Rn;
    }
    protected void btn_select_Click(object sender, EventArgs e)
    {
        string first_dir = System.Web.HttpContext.Current.Server.UrlDecode(h_dir.Value);
          DirectoryInfo thisOne = new DirectoryInfo(first_dir);
          show_file.Text = ListTreeShow(thisOne, 0, "");
    }
    public bool ResponseFile(HttpRequest _Request, HttpResponse _Response, string _fileName, string _fullPath, long _speed)//下载文件
    {
        try
        {
            FileStream myFile = new FileStream(_fullPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            BinaryReader br = new BinaryReader(myFile);
            try
            {
                _Response.AddHeader("Accept-Ranges", "bytes");
                _Response.Buffer = false;
                long fileLength = myFile.Length;
                long startBytes = 0;
                double pack = 10240; //10K bytes
                //int sleep = 200;   //每秒5次   即5*10K bytes每秒
                int sleep = (int)Math.Floor(1000 * pack / _speed) + 1;
                if (_Request.Headers["Range"] != null)
                {
                    _Response.StatusCode = 206;
                    string[] range = _Request.Headers["Range"].Split(new char[] { '=', '-' });
                    startBytes = Convert.ToInt64(range[1]);
                }
                _Response.AddHeader("Content-Length", (fileLength - startBytes).ToString());
                if (startBytes != 0)
                {
                    //Response.AddHeader("Content-Range", string.Format(" bytes {0}-{1}/{2}", startBytes, fileLength-1, fileLength));
                }
                _Response.AddHeader("Connection", "Keep-Alive");
                _Response.ContentType = "application/octet-stream";
                _Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(_fileName, System.Text.Encoding.UTF8));
                br.BaseStream.Seek(startBytes, SeekOrigin.Begin);
                int maxCount = (int)Math.Floor((fileLength - startBytes) / pack) + 1;
                for (int i = 0; i < maxCount; i++)
                {
                    if (_Response.IsClientConnected)
                    {
                        _Response.BinaryWrite(br.ReadBytes(int.Parse(pack.ToString())));
                        Thread.Sleep(sleep);
                    }
                    else
                    {
                        i = maxCount;
                    }
                }
            }
            catch
            {
                return false;
            }
            finally
            {
                br.Close();
                myFile.Close();
            }
        }
        catch
        {
            return false;
        }
        return true;
    }
    protected void btn_up_Click(object sender, EventArgs e)
    {
        if (file_up.HasFile)
        {
            try
            {
                string path = System.Web.HttpContext.Current.Server.UrlDecode(h_dir.Value);
                string file = file_up.FileName;
                file_up.SaveAs(path + "/" + file);
                DirectoryInfo thisOne = new DirectoryInfo(path);
                show_file.Text = ListTreeShow(thisOne, 0, "");
            }
            catch
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('上传文件失败,请重试');", true);
            }
        }
        else
        {
            Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('请选择文件');", true);
        }
    }
}

效果

主要难点是对站点中的文件和目录递归树形显示

flash幻灯片

联系:手机/微信(+86 17813235971) QQ(107644445)

标题:flash幻灯片

作者:惜分飞©版权所有[未经本人同意,不得以任何形式转载,否则有进一步追究法律责任的权利.]

以前一直想写这个这个类此的东西,都苦于没有项目驱动,这次因项目需要,真的搞了一个出来
js代码(导入js文件未给出)

AC_FL_RunContent('type', 'application/x-shockwave-flash', 'data', 'img/advertising.swf?xml=ahsx/flash.ashx', 'width', '300', 'height','200', 'id', 'xifenfei_flash', 'movie', 'img/advertising?xml=ashx/flash.ashx');

c#生成类xml代码

System.Text.StringBuilder str = new System.Text.StringBuilder();
 str.Append("<data>  <channel>");
 str.Append("   <item><link>http://www.baidu.com</link>").Append("   <image>1.jpg</image>").Append("   <title>111111</title></item>");
 str.Append("  <item> <link>http://http://www.baidu.com</link>").Append("   <image>2.jpg</image>").Append("   <title>222222</title></item>");
 str.Append(" <item>   <link>http://www.baidu.com</link>").Append("   <image>3.jpg</image>").Append("   <title>333333</title></item>");
 str.Append("   <item> <link>http://www.baidu.com</link>").Append("   <image>1.jpg</image>").Append("   <title>444444</title></item>");
 str.Append("   <item> <link>http://www.baidu.com</link>").Append("   <image>2.jpg</image>").Append("   <title>555555</title></item>");
 str.Append("   <item> <link>http://www.baidu.com</link>").Append("   <image>3.jpg</image>").Append("   <title>666666</title></item>");
 str.Append(" </channel>");
 str.Append("</data>");
 context.Response.Write(str.ToString());

note:仅供测试,没有和数据库关联起来
flash幻灯片附件

fckeditor使用说明

联系:手机/微信(+86 17813235971) QQ(107644445)

标题:fckeditor使用说明

作者:惜分飞©版权所有[未经本人同意,不得以任何形式转载,否则有进一步追究法律责任的权利.]

在asp.net中使用fckeditor比freetextbox复杂的多,但是这个是完全开源,开源自己控制
配置:web.config中

<appSettings>
<add key="FCKeditor:BasePath" value="~/fckeditor/"/>
</appSettings>

修改fckcofig.js文件(主要)

var _FileBrowserLanguage    = 'aspx' ;
var _QuickUploadLanguage = 'aspx'; 

修改config.asx文件,主要是为了实现不同用户的文件夹放置位置不同

private bool CheckAuthentication()
 {
 if (Session["vip"] == null ||Session["vip"].ToString() == "")
 {
 Session["vip"] = "public";
 }
 return true;
}
UserFilesPath = "../../../../../upload/" + Session["vip"].ToString();
string file_path = folder.Create_folder("../../../../../upload/" + Session["vip"].ToString());
 UserFilesAbsolutePath = file_path;TypeConfig[ "Image" ].AllowedExtensions            = new string[] { "bmp", "gif", "jpeg", "jpg", "png" };
 TypeConfig[ "Image" ].DeniedExtensions            = new string[] { };
 TypeConfig[ "Image" ].FilesPath                    = "%UserFilesPath%"+Session["vip"].ToString()+"/";
 TypeConfig[ "Image" ].FilesAbsolutePath            = ( UserFilesAbsolutePath == "" ? "" : "%UserFilesAbsolutePath%" );
 TypeConfig[ "Image" ].QuickUploadPath            = "%UserFilesPath%";
 TypeConfig[ "Image" ].QuickUploadAbsolutePath    = ( UserFilesAbsolutePath == "" ? "" : "%UserFilesAbsolutePath%" );

修改后的fckeditor

网站流量统计

联系:手机/微信(+86 17813235971) QQ(107644445)

标题:网站流量统计

作者:惜分飞©版权所有[未经本人同意,不得以任何形式转载,否则有进一步追究法律责任的权利.]

本程序采用.net平台和mysql数据库实现
mysql数据库中表:

CREATE TABLE `web_statistics` (
 `id` int(10) unsigned NOT NULL auto_increment,
 `Cur_url` varchar(500) NOT NULL,
 `Pre_url` varchar(500) NOT NULL default '未知',
 `Os` varchar(50) NOT NULL default '未知',
 `Ip` varchar(15) NOT NULL,
 `Browser` varchar(50) NOT NULL default '未知',
 `Access_Time` datetime NOT NULL,
 `Host_Name` varchar(45) NOT NULL default '未知',
 PRIMARY KEY  (`id`)
)

mysql存储过程:

CREATE  PROCEDURE `proc_statistics`(Cur_url varchar(500),Pre_url varchar(500),Os varchar(50),Brows varchar(50),Host_Name varchar(45),Ip varchar(15))
begin
insert into web_statistics(Cur_url,Pre_url,Os,Ip,Browser,Access_Time,Host_Name)
values(Cur_url,Pre_url,Os,Ip,Brows,now(),Host_Name);
end

ashx执行平台代码:

using System;
using System.Web;
using MySql.Data;
using MySql.Data.MySqlClient;
using MySql.Data.Types;
using System.Data;
public class Statistics : IHttpHandler {
 public void ProcessRequest (HttpContext context) {
 context.Response.ContentType = "image/jpg";
 string url_cur = "加载当前Url错误";
 string url_pre = "直接访问";
 if (context.Request.QueryString["d"] != null)
 {
 url_pre = System.Web.HttpContext.Current.Server.UrlDecode(context.Request.QueryString["d"].ToString()).Replace("`","&");
 if (url_pre == "")
 {
 url_pre = "直接访问";
 }
 }
 if (context.Request.QueryString["u"] != null)
 {
 url_cur = System.Web.HttpContext.Current.Server.UrlDecode(context.Request.QueryString["u"].ToString()).Replace("`", "&");
 }
 string[] data = GetData();
 string con_mysql = System.Configuration.ConfigurationManager.ConnectionStrings["mysql"].ToString();
 MySqlConnection conn;
 MySqlCommand cmd ;
 try
 {
 conn = new MySqlConnection(con_mysql);
 conn.Open();
 cmd = new MySqlCommand();
 cmd.Connection = conn;
 //存储过程实现
 cmd.CommandText = "proc_statistics";
 cmd.CommandType = CommandType.StoredProcedure;
 MySqlParameter para1 = new MySqlParameter("Cur_url", MySqlDbType.VarChar, 500);
 MySqlParameter para2 = new MySqlParameter("Pre_url", MySqlDbType.VarChar, 500);
 MySqlParameter para3 = new MySqlParameter("Os", MySqlDbType.VarChar, 50);
 MySqlParameter para4 = new MySqlParameter("Ip", MySqlDbType.VarChar, 15);
 MySqlParameter para5 = new MySqlParameter("Brows", MySqlDbType.VarChar, 50);
 MySqlParameter para7 = new MySqlParameter("Host_Name", MySqlDbType.VarChar, 45);
 para1.Value = url_cur;
 para2.Value = url_pre;
 para3.Value = data[1];
 para4.Value = data[3];
 para5.Value = data[2];
 para7.Value = data[0];
 cmd.Parameters.Add(para1);
 cmd.Parameters.Add(para2);
 cmd.Parameters.Add(para3);
 cmd.Parameters.Add(para4);
 cmd.Parameters.Add(para5);
 cmd.Parameters.Add(para7);
 //参数实现
 /*
 cmd.CommandType = CommandType.Text;
 //直接拼接字符串实现
 //string sql = "insert into web_statistics(Cur_url,Pre_url,Os,Ip,Browser,Access_Time,Host_Name)values('"+url_cur+"','"+url_pre+"','"+data[1]+"','"+data[3]+"','"+data[2]+"',now(),'"+data[0]+"')";
 //sql语句参数实现
 string sql = "insert into web_statistics(Cur_url,Pre_url,Os,Ip,Browser,Access_Time,Host_Name)values(?Cur_url,?Pre_url,?Os,?Ip,?Brows,now(),?Host_Name)";
 cmd.CommandText = sql;
 MySqlParameter para1 = new MySqlParameter("?Cur_url", MySqlDbType.VarChar,500);
 MySqlParameter para2 = new MySqlParameter("?Pre_url", MySqlDbType.VarChar, 500);
 MySqlParameter para3 = new MySqlParameter("?Os", MySqlDbType.VarChar, 50);
 MySqlParameter para4 = new MySqlParameter("?Ip", MySqlDbType.VarChar, 15);
 MySqlParameter para5 = new MySqlParameter("?Brows", MySqlDbType.VarChar, 50);
 MySqlParameter para7 = new MySqlParameter("?Host_Name", MySqlDbType.VarChar, 45);
 para1.Value = url_cur;
 para2.Value = url_pre;
 para3.Value = data[1];
 para4.Value = data[3];
 para5.Value=data[2];
 para7.Value = data[0];
 cmd.Parameters.Add(para1);
 cmd.Parameters.Add(para2);
 cmd.Parameters.Add(para3);
 cmd.Parameters.Add(para4);
 cmd.Parameters.Add(para5);
 cmd.Parameters.Add(para7);
 */
 cmd.ExecuteNonQuery();
 cmd.Dispose();
 conn.Close();
 }
 catch {}
 //输入图片
 string img_name = "statistics.jpg";
 //直接输出图片
 //  context.Response.WriteFile(context.Server.MapPath(img_name));
 //缓冲输出图片
 byte[] datas;
 if (HttpContext.Current.Cache["datacache"] != null)
 {
 datas = (byte[])HttpContext.Current.Cache["datacache"];
 }
 else
 {
 //记得修改文件图片名称
 datas = System.IO.File.ReadAllBytes(context.Server.MapPath(img_name));
 HttpContext.Current.Cache.Insert("datacache", datas, null, DateTime.MaxValue, TimeSpan.FromHours(12));
 }
 context.Response.OutputStream.Write(datas, 0, datas.Length);
 }
 public  string[] GetData()
 {
 string[] data = new string[4];
 string userAgent = System.Web.HttpContext.Current.Request.UserAgent == null ? "无" : System.Web.HttpContext.Current.Request.UserAgent;
 data[0] = System.Web.HttpContext.Current.Request.ServerVariables.Get("Remote_Host").ToString(); //主机名(暂时有问题)
 data[1] = System.Web.HttpContext.Current.Request.Browser.Platform.ToString() + ":" + GetOSNameByUserAgent(userAgent);//操作系统
 data[2] = System.Web.HttpContext.Current.Request.Browser.Browser.ToString() + ":" + System.Web.HttpContext.Current.Request.Browser.Version.ToString();//浏览器名称和版本
 string result = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
 if (null == result || result == String.Empty)
 {
 result = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
 }
 if (null == result || result == String.Empty)
 {
 result = HttpContext.Current.Request.UserHostAddress;
 }
 data[3] = result;//ip地址
 return data;
 }
 private  string GetOSNameByUserAgent(string userAgent)
 {
 string osVersion = "未知";
 if (userAgent.Contains("NT 6.1"))
 {
 osVersion = "Windows 7/Server 2008 R2";
 }
 else if (userAgent.Contains("NT 5.2"))
 {
 osVersion = "Windows Server 2003";
 }
 else if (userAgent.Contains("NT 5.1"))
 {
 osVersion = "Windows XP";
 }
 else if (userAgent.Contains("NT 6.0"))
 {
 osVersion = "Windows Vista/Server 2008";
 }
 else if (userAgent.Contains("NT 5"))
 {
 osVersion = "Windows 2000";
 }
 else if (userAgent.Contains("Linux"))
 {
 osVersion = "Linux";
 }
 else if (userAgent.Contains("NT 4"))
 {
 osVersion = "Windows NT4";
 }
 else if (userAgent.Contains("Me"))
 {
 osVersion = "Windows Me";
 }
 else if (userAgent.Contains("98"))
 {
 osVersion = "Windows 98";
 }
 else if (userAgent.Contains("95"))
 {
 osVersion = "Windows 95";
 }
 else if (userAgent.Contains("Mac"))
 {
 osVersion = "Mac";
 }
 else if (userAgent.Contains("Unix"))
 {
 osVersion = "UNIX";
 }
 else if (userAgent.Contains("SunOS"))
 {
 osVersion = "SunOS";
 }
 return osVersion;
 }
 public bool IsReusable {
 get {
 return false;
 }
 }
}

实现调用:
因为我把本程序部署在dag.wzu.edu.cn域名的服务器上,所以可以直接通过html+js代码就可以实现客户端的访问统计功能

<img  style="width:0px;height:0px;border:0px" id="statistics_id_fei" /><script type="text/javascript"> window.onload = function () { document.getElementById("statistics_id_fei").src = "http://dag.wzu.edu.cn/statistics.ashx?d="+ encodeURI(document.referrer).replace('&', '`') + "&u=" + encodeURI(document.location.href).replace('&', '`') + "&x=" + Math.random(); }</script>

说明:
1、在执行文件ashx上,采用了多种可选方式,其中数据库方面有直接拼接sql,sql参数方法,存储过程调用三种方法;
2、为了能够是js中的onload事件能够执行,加载完ashx文件后,生成一个对应的图片文件,采用了直接加载cache缓存方式实现;
3、只要直接把这里的html和js代码复制到你网址的直接的任何地方就可以实现自己站点的访问量统计。

dropdownlist 省市县三级联动

联系:手机/微信(+86 17813235971) QQ(107644445)

标题:dropdownlist 省市县三级联动

作者:惜分飞©版权所有[未经本人同意,不得以任何形式转载,否则有进一步追究法律责任的权利.]

因为开发环境是asp.net所以采用服务器端控件实现三级联动
HTML代码:

<asp:DropDownList ID="ddls" runat="server"></asp:DropDownList>
<asp:DropDownList ID="ddlc" runat="server"></asp:DropDownList>
<asp:DropDownList ID="ddlx" runat="server"></asp:DropDownList>
<input id="h_s" type="hidden"  runat="server"/>
 <input id="h_c" type="hidden" runat="server"/>
 <input id="h_a" type="hidden" runat="server"/>

note:hidden 是为了以后在c#代码中能够取到dropdownlist选中的值
js代码:

$(document).ready(function () {
 //选择省操作
 $("#ddls").change(function () {
 var selects_v = $("#ddls").val();
 $("#h_s").val(selects_v);
 if (selects_v == "0") {
 $("#ddlc option:first").attr("selected", "selected");
 $("#ddlx option:first").attr("selected", "selected");
 $("#ddlc").attr("disabled", "disabled");
 $("#ddlx").attr("disabled", "disabled");
 }
 else {
 $("#ddlc option").remove();
 $("#ddlc").attr("disabled", "");
 $("#ddlx option:first").attr("selected", "selected");
 $("#ddlx").attr("disabled", "disabled");
 $("#ddlc").append("<option value='0'>请选择市</option>");
 $.getJSON("./ashx/select_province.ashx?s=" + selects_v + "&a" + Math.random(), function (data) {
 $.each(data.root, function (id, item) {
 $("#ddlc").append("<option value='" + item.code + "'>" + item.name + "</option>");
 });
 });
 }
 });
 //ddlx选择市
 $("#ddlc").change(function () {
 var s_c = $("#ddlc").val();
 $("#h_c").val(s_c);
 if (s_c == "0") {
 $("#ddlx")[0].selectedIndex = 0;
 $("#ddlx").attr("disabled", "disabled");
 }
 else {
 $("#ddlx option").remove();
 $("#ddlx").attr("disabled", "");
 $("#ddlx").append("<option value='0'>请选择县</option>");
 $.getJSON("./ashx/select_city.ashx?s=" + s_c + "&a" + Math.random(), function (data) {
 $.each(data.root, function (id, item) {
 $("#ddlx").append("<option value='" + item.code + "'>" + item.name + "</option>");
 });
 });
 }
 });
 //选择对应的县
 $("#ddlx").change(function () {
 var s_a = $("#ddlx").val();
 $("#h_a").val(s_a);
 });
});

c#初始化dropdownlist数据

protected void Bindddls()
 {
 SqlDataReader dr = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.StoredProcedure, "get_province");
 ddls.DataTextField = "name";
 ddls.DataValueField = "code";
 ddls.DataSource = dr;
 ddls.DataBind();
 dr.Close();
 ddls.Items.Insert(0,new ListItem("请选择省", "0"));
 }
 protected void Bindddlc()
 {
 string sValue = ddls.SelectedValue;
 if (sValue == "0")
 {
 ddlc.Items.Add(new ListItem("请选择市", "0"));
 ddlc.Enabled = false;
 }
 else
 {
 SqlDataReader dr = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.StoredProcedure, "get_city");
 ddlc.DataTextField = "name";
 ddlc.DataValueField = "code";
 ddlc.DataSource = dr;
 ddlc.DataBind();
 dr.Close();
 ddlc.Items.Insert(0,new ListItem("请选择市", "0"));
 }
 }
 protected void Bindddla()
 {
 string cValue = ddlc.SelectedValue;
 if (cValue == "0")
 {
 ddlx.Items.Add(new ListItem("请选择县", "0"));
 ddlx.Enabled = false;
 }
 else
 {
 SqlDataReader dr = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.StoredProcedure, "get_area");
 ddlx.DataTextField = "name";
 ddlx.DataValueField = "code";
 ddlx.DataSource = dr;
 ddlx.DataBind();
 dr.Close();
 ddlx.Items.Insert(0, new ListItem("请选择县", "0"));
 }
 }

ashx文件代码
select_province.ashx文件

if (HttpContext.Current.Request["s"] != null)
 {
 string sv = HttpContext.Current.Request["s"].ToString();
 SqlDataReader dr = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.StoredProcedure
 , "get_city", new SqlParameter("@sid", sv));
 string json = Object_Json.ToJson(dr);
 dr.Close();
 HttpContext.Current.Response.Write(json);
 HttpContext.Current.Response.End();
 }
 else
 {
 HttpContext.Current.Response.Write("error");
 HttpContext.Current.Response.End();
 }

select_city.ashx文件

if (HttpContext.Current.Request["s"] != null)
 {
 string sv = HttpContext.Current.Request["s"].ToString();
 System.Data.SqlClient.SqlDataReader dr = xifenfei.mssql.SqlHelper.ExecuteReader(xifenfei.mssql.SqlHelper.ConnectionStringLocalTransaction, System.Data.CommandType.StoredProcedure
 , "get_area", new System.Data.SqlClient.SqlParameter("@sid", sv));
 string json = Object_Json.ToJson(dr);
 dr.Close();
 HttpContext.Current.Response.Write(json);
 HttpContext.Current.Response.End();
 }
 else
 {
 HttpContext.Current.Response.Write("error");
 HttpContext.Current.Response.End();
 }

效果:

Google Map 使用

联系:手机/微信(+86 17813235971) QQ(107644445)

标题:Google Map 使用

作者:惜分飞©版权所有[未经本人同意,不得以任何形式转载,否则有进一步追究法律责任的权利.]

因项目中要调用google地图,最近花了点时间阅读了下google  map 的api,google map的使用大致如下:
1、注册使用google地图api
地址为:http://code.google.com/intl/zh-CN/apis/maps/signup.html
2、阅读google 地图api
地址为:http://code.google.com/intl/zh-CN/apis/maps/documentation/javascript/basics.html
3、测试google 地图api
(1)一个地点定位并标明位置

  • 1添加JavaScript应用
<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=true;key=ABQIAAAAEBGBYRn2zjKnkDk35kXn-BT2yXp_ZAY8_ufC3CFXhHIE1NvwkxSQ7sVn7B1Wp1t33kMiQlXQKL-t7g"  type="text/javascript"></script>

note:我的key是localhost,如果其他测试请重新申请

  • 主要的js函数
function load(comName, comAddress, comPhone, dimensionality, longitude) {     //加载地图
 if (GBrowserIsCompatible()) {
 var map = new GMap2(document.getElementById("map"));
 map.addControl(new GSmallMapControl());    //放大缩小
 map.addControl(new GMapTypeControl());     //地图种类
 map.enableScrollWheelZoom();    //启用鼠标滚轮
 var point = new GLatLng(dimensionality, longitude);     // 位置
 map.setCenter(point, 14);   //地图坐标 三个参数分别为 "纬度" "经度" "比例尺"
 function createMarker(point, address, name, tel) {  //创建标记内容及标记的鼠标事件
 var marker = new GMarker(point);
 var html = '<div style="font-size:10px;">' +
 '<a >公司名称:' + name + '</a><br/>' +
 '<a >公司地址:' + address + '</a><br/>' +
 '<a >联系电话:' + tel + '</a>' +
 '</div>';
 GEvent.addListener(marker, "mouseover", function () {
 marker.openInfoWindowHtml(html);
 });
 GEvent.addListener(marker, "mouseout", function () {
 marker.closeInfoWindow();
 });
 GEvent.addListener(marker, "click", function () {
 map.setCenter(point, 16);
 //marker.openInfoWindowHtml(html);
 });
 return marker;
 }
 map.addOverlay(createMarker(point, comAddress, comName, comPhone)); //加入标记
 }
 else {
 alert("您的浏览器不支持Google地图,请升级到最新版再尝试");
 }
}

参数说明:
公司名称comName
公司地址comAddress
公司电话comPhone
公司维度 dimensionality
公司经度 longitude

  • 放置地图的html位置
<div id="map" style="width: 700px; height: 300px"></div>
  • js调用
  • $(document).ready(function () {
     load('飞飞','温州大学','13736325515',27.924806,120.699492);
     });


2、多个地点定位并标明

  • js代码
function load(dimensionality, longitude) {     //加载地图
 if (GBrowserIsCompatible()) {
 var map = new GMap2(document.getElementById("map"));
 map.addControl(new GSmallMapControl());    //放大缩小
 map.addControl(new GMapTypeControl());     //地图种类
 map.enableScrollWheelZoom();    //启用鼠标滚轮
 var point = new GLatLng(dimensionality, longitude);     // 位置
 map.setCenter(point, 14);   //地图坐标 三个参数分别为 "纬度" "经度" "比例尺"
 return map;
 }
}
function createMarker(map,point, address, name, tel) {  //创建标记内容及标记的鼠标事件
 var marker = new GMarker(point);
 var html = '<div style="font-size:12px;">' +
 '<a >公司名称:' + name + '</a><br/>' +
 '<a >公司地址:' + address + '</a><br/>' +
 '<a >联系电话:' + tel + '</a>' +
 '</div>';
 GEvent.addListener(marker, "mouseover", function () {
 marker.openInfoWindowHtml(html);
 });
 GEvent.addListener(marker, "mouseout", function () {
 marker.closeInfoWindow();
 });
 GEvent.addListener(marker, "click", function () {
 map.setCenter(point, 16);
 });
 return marker;
}
function Add_Marker(map,comName, comAddress, comPhone, dimensionality, longitude) {
 var point = new GLatLng(dimensionality, longitude);     // 设置标记
 map.addOverlay(createMarker(map,point, comAddress, comName, comPhone)); //加入标记
}
  • c#调用
string a = @" var map = load(27.924806, 120.699492);
 Add_Marker(map,'温州大学', '茶山', '13736325515', 27.924806, 120.699492);
 Add_Marker(map,'温州大学111', '茶山22', '13736325515',27.925526, 120.700479);";
 Page.ClientScript.RegisterStartupScript(this.GetType(), "ab", a, true);

note:
在一个定位的js中,也可以采用添加多个

var point1 = new GLatLng(27.925526, 120.700479);
 map.addOverlay(createMarker(point1, 'comAddress', 'comName', 'comPhone')); 

来实现多个地点的定位和标明,但是这样可控制性太差

多种方式的md5加密

联系:手机/微信(+86 17813235971) QQ(107644445)

标题:多种方式的md5加密

作者:惜分飞©版权所有[未经本人同意,不得以任何形式转载,否则有进一步追究法律责任的权利.]

一、oracle实现md5加密:

CREATE OR REPLACE function fn_md5(input_string VARCHAR2) return varchar2
IS
raw_input RAW(128) := UTL_RAW.CAST_TO_RAW(input_string);
decrypted_raw RAW(2048);
error_in_input_buffer_length EXCEPTION;
BEGIN
sys.dbms_obfuscation_toolkit.MD5(input => raw_input,checksum => decrypted_raw);
return rawtohex(decrypted_raw);
END;


二、mysql实现md5加密:

select upper(md5('abc')) from cdb_settings limit 1;


注意问题:在mysql中不知道为什么使用了upper不能转化为大写,尝试了几个编码的mysql库都不行,也许是我mysql版本的问题,先记录下mysql版本

三、Sql Server 实现md5加密

select hashbytes('MD5', 'abc');


四、C#实现md5加密:

string abc=System.Web.Security.FormsAuthentication.
HashPasswordForStoringInConfigFile("abc", "MD5") ;
 Response.Write(abc);


五、Javascript实现md5加密:

var hexcase = 0; function hex_md5(a)
{ return rstr2hex(rstr_md5(str2rstr_utf8(a))) }
function hex_hmac_md5(a, b)
{ return rstr2hex(rstr_hmac_md5(str2rstr_utf8(a), str2rstr_utf8(b))) }
 function md5_vm_test()
{ return hex_md5("abc").toLowerCase() == "900150983cd24fb0d6963f7d28e17f72" }
 function rstr_md5(a)
{ return binl2rstr(binl_md5(rstr2binl(a), a.length * 8)) }
 function rstr_hmac_md5(c, f)
{ var e = rstr2binl(c); if (e.length > 16)
{ e = binl_md5(e, c.length*8) }
 var a = Array(16), d = Array(16);
 for (var b = 0; b < 16; b++)
{ a[b] = e[b] ^ 909522486; d[b] = e[b] ^ 1549556828 }
var g = binl_md5(a.concat(rstr2binl(f)), 512 + f.length * 8);
return binl2rstr(binl_md5(d.concat(g), 512 + 128)) }
function rstr2hex(c) { try { hexcase } catch (g) { hexcase = 0 }
 var f = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
 var b = ""; var a; for (var d = 0; d < c.length; d++) { a = c.charCodeAt(d);
 b += f.charAt((a >>> 4) & 15) + f.charAt(a & 15) } return b } function str2rstr_utf8(c)
 { var b = ""; var d = -1; var a, e; while (++d < c.length)
{ a = c.charCodeAt(d); e = d + 1 < c.length ? c.charCodeAt(d + 1) : 0;
 if (55296 <= a && a <= 56319 && 56320 <= e && e <= 57343)
{ a = 65536 + ((a & 1023) << 10) + (e & 1023); d++ }
if (a <= 127) { b += String.fromCharCode(a) }
else { if (a <= 2047) { b += String.fromCharCode(192 | ((a >>> 6) & 31),
 128 | (a & 63)) } else { if (a <= 65535) { b += String.fromCharCode(224
| ((a >>> 12) & 15), 128 | ((a >>> 6) & 63), 128 | (a & 63)) }
else { if (a <= 2097151) { b += String.fromCharCode(240 |
((a >>> 18) & 7), 128 | ((a >>> 12) & 63), 128 | ((a >>> 6) & 63),
 128 | (a & 63)) } } } } } return b } function rstr2binl(b)
{ var a = Array(b.length >> 2); for (var c = 0; c<a.length; c++)
 { a = 0 } for (var c = 0; c <b.length*8;c =c+8 )
{ a |= (b.charCodeAt(c / 8 ) & 255) << (c % 32) } return a }
function binl2rstr(b) { var a = ""; for (var c = 0; c<b.length * 32; c=c+8)
 { a += String.fromCharCode((b >>> (c % 32)) & 255) }
 return a } function binl_md5(p, k) { p[k >> 5] |= 128 << ((k) % 32);
p[(((k + 64) >>> 9) << 4) + 14] = k; var o = 1732584193;
var n = -271733879; var m = -1732584194; var l = 271733878;
 for (var g = 0; g < p.length; g += 16) { var j = o; var h = n;
var f = m; var e = l; o = md5_ff(o, n, m, l, p[g + 0], 7, -680876936);
 l = md5_ff(l, o, n, m, p[g + 1], 12, -389564586); m = md5_ff(m, l, o, n, p[g + 2], 17, 606105819);
n = md5_ff(n, m, l, o, p[g + 3], 22, -1044525330); o = md5_ff(o, n, m, l, p[g + 4], 7, -176418897);
l = md5_ff(l, o, n, m, p[g + 5], 12, 1200080426); m = md5_ff(m, l, o, n, p[g + 6], 17, -1473231341);
 n = md5_ff(n, m, l, o, p[g + 7], 22, -45705983); o = md5_ff(o, n, m, l, p[g + 8], 7, 1770035416);
l = md5_ff(l, o, n, m, p[g + 9], 12, -1958414417); m = md5_ff(m, l, o, n, p[g + 10], 17, -42063);
 n = md5_ff(n, m, l, o, p[g + 11], 22, -1990404162); o = md5_ff(o, n, m, l, p[g + 12], 7, 1804603682);
 l = md5_ff(l, o, n, m, p[g + 13], 12, -40341101); m = md5_ff(m, l, o, n, p[g + 14], 17, -1502002290);
n = md5_ff(n, m, l, o, p[g + 15], 22, 1236535329); o = md5_gg(o, n, m, l, p[g + 1], 5, -165796510);
 l = md5_gg(l, o, n, m, p[g + 6], 9, -1069501632); m = md5_gg(m, l, o, n, p[g + 11], 14, 643717713);
n = md5_gg(n, m, l, o, p[g + 0], 20, -373897302); o = md5_gg(o, n, m, l, p[g + 5], 5, -701558691);
 l = md5_gg(l, o, n, m, p[g + 10], 9, 38016083); m = md5_gg(m, l, o, n, p[g + 15], 14, -660478335);
n = md5_gg(n, m, l, o, p[g + 4], 20, -405537848); o = md5_gg(o, n, m, l, p[g + 9], 5, 568446438);
l = md5_gg(l, o, n, m, p[g + 14], 9, -1019803690); m = md5_gg(m, l, o, n, p[g + 3], 14, -187363961);
 n = md5_gg(n, m, l, o, p[g + 8], 20, 1163531501); o = md5_gg(o, n, m, l, p[g + 13], 5, -1444681467);
 l = md5_gg(l, o, n, m, p[g + 2], 9, -51403784); m = md5_gg(m, l, o, n, p[g + 7], 14, 1735328473);
n = md5_gg(n, m, l, o, p[g + 12], 20, -1926607734); o = md5_hh(o, n, m, l, p[g + 5], 4, -378558);
l = md5_hh(l, o, n, m, p[g + 8], 11, -2022574463); m = md5_hh(m, l, o, n, p[g + 11], 16, 1839030562);
 n = md5_hh(n, m, l, o, p[g + 14], 23, -35309556); o = md5_hh(o, n, m, l, p[g + 1], 4, -1530992060);
 l = md5_hh(l, o, n, m, p[g + 4], 11, 1272893353); m = md5_hh(m, l, o, n, p[g + 7], 16, -155497632);
n = md5_hh(n, m, l, o, p[g + 10], 23, -1094730640); o = md5_hh(o, n, m, l, p[g + 13], 4, 681279174);
l = md5_hh(l, o, n, m, p[g + 0], 11, -358537222); m = md5_hh(m, l, o, n, p[g + 3], 16, -722521979);
n = md5_hh(n, m, l, o, p[g + 6], 23, 76029189); o = md5_hh(o, n, m, l, p[g + 9], 4, -640364487);
l = md5_hh(l, o, n, m, p[g + 12], 11, -421815835); m = md5_hh(m, l, o, n, p[g + 15], 16, 530742520);
n = md5_hh(n, m, l, o, p[g + 2], 23, -995338651); o = md5_ii(o, n, m, l, p[g + 0], 6, -198630844);
l = md5_ii(l, o, n, m, p[g + 7], 10, 1126891415); m = md5_ii(m, l, o, n, p[g + 14], 15, -1416354905);
n = md5_ii(n, m, l, o, p[g + 5], 21, -57434055); o = md5_ii(o, n, m, l, p[g + 12], 6, 1700485571);
l = md5_ii(l, o, n, m, p[g + 3], 10, -1894986606); m = md5_ii(m, l, o, n, p[g + 10], 15, -1051523);
n = md5_ii(n, m, l, o, p[g + 1], 21, -2054922799); o = md5_ii(o, n, m, l, p[g + 8], 6, 1873313359);
 l = md5_ii(l, o, n, m, p[g + 15], 10, -30611744); m = md5_ii(m, l, o, n, p[g + 6], 15, -1560198380);
n = md5_ii(n, m, l, o, p[g + 13], 21, 1309151649); o = md5_ii(o, n, m, l, p[g + 4], 6, -145523070);
l = md5_ii(l, o, n, m, p[g + 11], 10, -1120210379); m = md5_ii(m, l, o, n, p[g + 2], 15, 718787259);
n = md5_ii(n, m, l, o, p[g + 9], 21, -343485551); o = safe_add(o, j); n = safe_add(n, h);
m = safe_add(m, f); l = safe_add(l, e) } return Array(o, n, m, l) }
function md5_cmn(h, e, d, c, g, f) { return safe_add(bit_rol(safe_add(safe_add(e, h),
safe_add(c, f)), g), d) } function md5_ff(g, f, k, j, e, i, h)
{ return md5_cmn((f & k) | ((~f) & j), g, f, e, i, h) } function md5_gg(g, f, k, j, e, i, h)
{ return md5_cmn((f & j) | (k & (~j)), g, f, e, i, h) } function md5_hh(g, f, k, j, e, i, h)
{ return md5_cmn(f ^ k ^ j, g, f, e, i, h) } function md5_ii(g, f, k, j, e, i, h)
{ return md5_cmn(k ^ (f | (~j)), g, f, e, i, h) } function safe_add(a, d)
{ var c = (a & 65535) + (d & 65535); var b = (a >> 16) + (d >> 16) + (c >> 16);
return (b << 16) | (c & 65535) } function bit_rol(a, b) { return (a << b) | (a >>> (32 - b)) }

实现:

<script src="md5-min.js" type="text/javascript"></script>
 <script type="text/javascript">
 alert('abc经过md5加密后结果为:\n'+hex_md5('abc'));
 </script>


六、php实现md5加密:

echo strtoupper(md5('abc')) ;

FreeTextbox使用

联系:手机/微信(+86 17813235971) QQ(107644445)

标题:FreeTextbox使用

作者:惜分飞©版权所有[未经本人同意,不得以任何形式转载,否则有进一步追究法律责任的权利.]

在系统发邮件,新闻内容发布上要用到freetextbox,用起来是很爽的,但是感觉freetextbox中的定义菜单感觉困难,今天在网上找到了一些资料,和大家分享下
toolbarlayout=”ParagraphMenu,FontFacesMenu,FontSizesMenu,
FontForeColorsMenu,FontForeColorPicker,FontBackColorsMenu,
FontBackColorPicker|Bold,Italic,Underline,Strikethrough,Superscript,
Subscript,RemoveFormat|JustifyLeft,JustifyRight,JustifyCenter,
JustifyFull;BulletedList,NumberedList,Indent,Outdent;CreateLink,
Unlink,InsertImage|Cut,Copy,Paste,Delete;Undo,Redo,Print,Save|
SymbolsMenu,StylesMenu,InsertHtmlMenu|InsertRule,InsertDate,
InsertTime|InsertTable,EditTable;InsertTableRowAfter,
InsertTableRowBefore,DeleteTableRow;InsertTableColumnAfter,
InsertTableColumnBefore,DeleteTableColumn|InsertForm,InsertTextBox,
InsertTextArea,InsertRadioButton,InsertCheckBox,InsertDropDownList,
InsertButton|InsertDiv,EditStyle,InsertImageFromGallery,
Preview,SelectAll,WordClean,NetSpell”
Bold  加粗
BulletedList 项目符号
Copy  复制
CreateLink  插入链接
Cut   剪切
Delete  删除
DeleteTableColumn 删除一列(En)
DeleteTableRow  删除一行(En)
IeSpellCheck IE拼写检查(En 需要安装拼写检查软件)
Indent  增加缩进
InsertDate 插入日期
InsertImage 插入图片
InsertRule 插入水平线(En)
InsertTable 插入表格(En)
InsertTableColumnAfter 插入表格列在后面(En)
InsertTableColumnBefore 插入表格列在前面(En)
InsertTableRowAfter 插入表格行在后面(En)
InsertTableRowBefore 插入表格行在前面(En)
InsertTime 插入时间
Italic 斜体
JustifyCenter 居中
JustifyFull 两端对齐
JustifyLeft 左对齐
JustifyRight 右对齐
NetSpell 网络拼写检查(En)
NumberedList 编号
Outdent 减少缩进
Paste 粘贴
Print 打印
Redo  重复
RemoveFormat 删除所有格式
Save  保存(En)
StrikeThrough  删除线
SubScript 下标
SuperScript 上标
Underline 下划线
Undo  撤消
Unlink  删除链接
希望对大家有帮助

url重定向

联系:手机/微信(+86 17813235971) QQ(107644445)

标题:url重定向

作者:惜分飞©版权所有[未经本人同意,不得以任何形式转载,否则有进一步追究法律责任的权利.]

前两天一直忙着大学的最好的考试,现在好 了,学生时代基本上结束了,暂时可以一心的做开发,写写代码,在考试的这两天中,我只是看了下url重定向,并且稍微的写了点,基本上是可以满足项目 url rewrite的需求了,其实说真的,我在项目中想采用url rewrite,一是为了让url不显示显示很多的参数,给别人注入带来一定的方便;二是为了体验下这个技术,自己一直想写点这个的,因为暑假没有成功; 三是感觉上是静态网页,有成就感。现在稍微的介绍下结合网上的一般重归思路写出来的结果:
使用Intelligencia.UrlRewriter.dll来实现
在web.config中配置:
(1)在<configSections></configSections>节中加上<section name=”rewriter” requirePermission=”false” type=”Intelligencia.UrlRewriter.Configuration.RewriterConfigurationSectionHandler, Intelligencia.UrlRewriter” />;
(2)在<httpModules></httpModules>节中加上<add name=”UrlRewriter” type=”Intelligencia.UrlRewriter.RewriterHttpModule, Intelligencia.UrlRewriter”/>;
(3)在<configuration></configuration>节中添 加<rewriter>    <rewrite url=”~/(.+).html$” to=”~/ViewNews.aspx?ID=$1″ />  </rewriter>   <–重定性规则,按照自己的需求来写,这里对正则表达式基础有点要求–>
测试下,1232.html,是不是出现和id=1232一样的效果。
但是如果你点击该页面的服务器端事件是,url又会变成viewnews.aspx?id=`1232了,这个问题的解决方案网上有两种,一种是重 新form,另一种是重新page,我考虑到保持aspx页面的完整性,采用了重新page的方法来解决,就是一个类文件,在网上下载的叫做 URL.page的,有需要的朋友可以到网上去找下。