1.安装ASP.NET Ajax1.0 点击安装

2.在Web项目中添加引用:System.Web.Extensions(Version:1.0.61025.0)

3.更改web.config,在<system.web>节点加入子节点:

    <httpModules>
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</httpModules>

4.在相关的aspx.cs加入以下代码,注意是static方法

        [WebMethod]
public static string AjaxTest(string str)
{
return "Hello " + str;
}

5.JQuery调用:

    <script type="text/javascript">
function ajaxTest(str) {
$.ajax({
url: "/Default.aspx/AjaxTest",
type: "post",
dataType: "json",
contentType: "application/json",
data: "{'str':'" + str + "'}",
success: function(data) {
alert(data);
},
error: function(x, e) {
alert(x.responseText);
//alert("失败!!");
}
});
}
</script>
posted @ 2012-01-04 15:17 ahui 阅读(11) 评论(0) 编辑

插入实体的字段:

var data = new Comments();
data.ArticleId = 1;
data.AuditStatus = 2;
data.Company = 5;
data.Content = "测试";
data.CreateTime = DateTime.Now;
data.IP = "192.168.1.2";
data.NickName = "张三";
data.ReplyContent = string.Empty;
data.ReplyId = 0;
data.ReplyNickName = string.Empty;
data.ReplyTime = DateTime.Now;
data.Tel = "887964645";
data.UserId = 10;

 

插入1000条分别消耗的时间:

ADO.NET:

EF:

posted @ 2011-09-28 16:40 ahui 阅读(37) 评论(1) 编辑
int[] source = { 5, -3, 6, -7, -6, 1, 8, -4, 0, 0 };
int toRightIdx = 0;
int toLeftIdx = source.Length - 1;
int leftIdx = 0;
int rightIdx = source.Length - 1;
int[] result = new int[source.Length];

while (true)
{
    if (toLeftIdx >= 0)
    {
        int left = source[toRightIdx++];
        if (left < 0) result[leftIdx++] = left;

        int right = source[toLeftIdx--];
        if (right > 0) result[rightIdx--] = right;
    }
    else
    {
        result[rightIdx--] = 0;
    }
    if (leftIdx > rightIdx) break;
}

应该算是最好的解法了吧:P

posted @ 2011-09-19 09:10 ahui 阅读(26) 评论(0) 编辑

1.服务器端代码:

        /// <summary>
        /// 自定义Ext Ajax请求结果
        /// </summary>
        /// <param name="success">是否成功</param>
        /// <param name="value">结果</param>
        /// <returns></returns>
        protected ActionResult ExtJson(bool success)
        {
            return ExtJson(success, 0, string.Empty);
        }

        /// <summary>
        /// 自定义Ext Ajax请求结果
        /// </summary>
        /// <param name="success">是否成功</param>
        /// <param name="value">结果</param>
        /// <returns></returns>
        protected ActionResult ExtJson(bool success, object value)
        {
            return ExtJson(success, 0, value);
        }

        /// <summary>
        /// 自定义Ext Ajax请求结果
        /// </summary>
        /// <param name="success">是否成功</param>
        /// <param name="value">结果</param>
        /// <returns></returns>
        protected ActionResult ExtJson(bool success, int code, object value)
        {
            return Json(new { success = success, code = code, value = value }, "text/html", System.Text.Encoding.UTF8, JsonRequestBehavior.AllowGet);
        }

        /// <summary>
        /// 返回服务器端Model验证错误
        /// </summary>
        /// <returns></returns>
        protected ActionResult ModelError()
        {
            List<object> errors = new List<object>();
            foreach (var key in ModelState.Keys)
            {
                var state = ModelState[key];
                foreach (var error in state.Errors)
                {
                    errors.Add(new { id = key, msg = error.ErrorMessage });
                }
            }

            if (errors.Count > 0)
            {
                return ExtJson(false, errors);
            }

            return ExtJson(false, "未知错误,请检查输入!");
        }

action调用示例:

if (!ModelState.IsValid)
{
        return ModelError();
}

  

2.客户端代码

handler: function() {
    var form = theForm.getForm();
    if (form.isValid()) {
        form.submit({
            waitMsg: '正在提交...',
            success: function(form, action) {
                Ext.Msg.alert('成功', '保存成功!', function() {
                    win.hide();
                    store.loadPage();
                });
            },
            failure: function(form, action) {
                if (action.result) {
                    if (typeof(action.result.value) == 'string') Ext.Msg.alert('失败', action.result.value);
                    else if (action.result.value.constructor == Array) theForm.getForm().markInvalid(action.result.value);
                } else {
                    Ext.Msg.alert('失败', '未知错误');
                }
            }
        });
    }
}

 

posted @ 2011-09-18 10:51 ahui 阅读(55) 评论(1) 编辑
public static class ByteHexHelper
{
    private static char[] _buffedChars = null;
    private static byte[] _buffedBytes = null;

    static ByteHexHelper()
    {
        _buffedChars = new char[(byte.MaxValue - byte.MinValue + 1) * 2];
        int idx = 0;
        byte b = byte.MinValue;
        while (true)
        {
            string hexs = b.ToString("X2");
            _buffedChars[idx++] = hexs[0];
            _buffedChars[idx++] = hexs[1];

            if (b == byte.MaxValue) break;
            ++b;
        }

        _buffedBytes = new byte[0x67];
        idx = _buffedBytes.Length;
        while (--idx >= 0)
        {
            if ((0x30 <= idx) && (idx <= 0x39))
            {
                _buffedBytes[idx] = (byte)(idx - 0x30);
            }
            else
            {
                if ((0x61 <= idx) && (idx <= 0x66))
                {
                    _buffedBytes[idx] = (byte)((idx - 0x61) + 10);
                    continue;
                }
                if ((0x41 <= idx) && (idx <= 70))
                {
                    _buffedBytes[idx] = (byte)((idx - 0x41) + 10);
                }
            }
        }
    }

    /// <summary>
    /// 字节数组转16进制字符串
    /// </summary>
    /// <param name="bytes"></param>
    /// <returns></returns>
    public static string ByteToHex(byte[] bytes)
    {
        if (bytes == null)
        {
            return null;
        }

        char[] result = new char[bytes.Length * 2];
        for (int i = 0; i < bytes.Length; ++i)
        {
            int startIndex = (bytes[i] - byte.MinValue) * 2;
            result[i * 2] = _buffedChars[startIndex];
            result[i * 2 + 1] = _buffedChars[startIndex + 1];
        }

        return new string(result);
    }

    /// <summary>
    /// 16进制字符串转字节数组
    /// </summary>
    /// <param name="str"></param>
    /// <returns></returns>
    public static byte[] HexToByte(string str)
    {
        if (str == null || (str.Length & 1) == 1)
        {
            return null;
        }

        byte[] result = new byte[str.Length / 2];
        int charIndex = 0;
        int byteIndex = 0;
        int length = result.Length;
        while (--length >= 0)
        {
            int first = 0;
            int second = 0;
            try
            {
                first = _buffedBytes[str[charIndex++]];
                second = _buffedBytes[str[charIndex++]];
            }
            catch
            {
                return null;
            }
            result[byteIndex++] = (byte)((first << 4) + second);
        }
        return result;
    }
}

  

posted @ 2011-08-29 00:46 ahui 阅读(163) 评论(0) 编辑
摘要: function resizeImage(image, max) { if (Math.max(image.width, image.height) > max) { if (image.width > image.height) image.width = max; else image.height = max; } return true;} <img onload="var max=64;if(Math.max(this.width,this.height)>max){if(this.width>this.height)this.width=ma阅读全文
posted @ 2011-08-18 14:46 ahui 阅读(18) 评论(0) 编辑
摘要: EF通用的分页实现:/// <summary>/// 根据条件分页获得记录/// </summary>/// <param name="where">条件</param>/// <param name="orderBy">排序</param>/// <param name="ascending">是否升序</param>/// <param name="pageIndex">当前页码</param>阅读全文
posted @ 2011-08-04 14:03 ahui 阅读(377) 评论(8) 编辑
摘要: 假设消息头为16byte0-3 消息头标识4-7 消息体长度8-15 CRC校验码public class StreamHelper { #region 将消息转为包含消息头的字节数组 /// <summary> /// 将消息转为包含消息头的字节数组 /// </summary> /// <param name="stream"></param> /// <param name="message"></param> /// <returns></returns&g阅读全文
posted @ 2011-07-12 09:32 ahui 阅读(170) 评论(0) 编辑
摘要: #region 异步接收Socket数据/// <summary>/// 异步接收Socket数据/// </summary>/// <param name="socket"></param>/// <returns></returns>public static byte[] ReceiveData(Socket socket){ ReceiveObject state = new ReceiveObject() { Client = socket }; socket.BeginReceive(sta阅读全文
posted @ 2011-07-04 16:31 ahui 阅读(117) 评论(0) 编辑
摘要: set s=%date:~0,4%%date:~5,2%%date:~8,2%%time:~1,1%%time:~3,2%%time:~6,2%mysqldump -u root -ppasswd test> E:\51MobApp\Mysql\test_%s%_bak.sqlInstall.bat:@echo offcd /d %~dp0echo 执行此脚本会清除所有数据set /p svr=请输入Mysql服务器IP: echo mysql -u root -h %svr% -p < All.sqlmysql -u root -h %svr% -p < All.sqlpa阅读全文
posted @ 2011-06-24 10:12 ahui 阅读(9) 评论(0) 编辑