2012年10月23日 星期二

ASP.NET 提示使用者下載檔案

Response.Clear()
Response.Buffer = True
Response.HeaderEncoding = System.Text.Encoding.GetEncoding("big5")
Response.AppendHeader("Content-Disposition", "attachment;filename=" + "交通住宿名單.xml")
Response.ContentType = "application/vnd.ms-excel"
Response.Write(filestream)
Response.End()

SQL SERVER 2005 如何於查詢結果加上序號欄位

select rank() OVER (ORDER BY a.au_lname, a.au_fname) as rank, a.au_lname, a.au_fname from authors a order by rank

透過 jQuery 呼叫 code-behind webmethod


於網頁中加入以下函數
====
function CallPageMethod(methodName, onSuccess) {
            var args = '';
            var l = arguments.length;
            if (l > 2) {
                for (var i = 2; i < l - 1; i += 2) {
                    if (args.length != 0) args += ',';
                    args += '"' + arguments[i] + '":"' + arguments[i + 1] + '"';
                }
            }
            var loc = window.location.href;
            loc = (loc.substr(loc.length - 1, 1) == "/") ? loc + "default.aspx" : loc;
            $.ajax({
                type: "POST",
                url: loc + "/" + methodName,
                data: "{" + args + "}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: onSuccess
            });
        }

呼叫方式
====
CallPageMethod([webmethod name], [成功時呼叫的函數名稱], [參數名稱1], [參數值1],[參數名稱2], [參數值2],...);

function [成功時呼叫的函數名稱](response) {
            //do something, response.d=webmethod return value
        }

去除文字方塊前後空白


$("input[type=text]").focusout(function () { $(this).val($.trim($(this).val())); });

2012年10月6日 星期六

使用EPPlus 時如何設定頁首頁尾

設定頁首中間文字並指定為標楷體、粗體、大小為16
====
ws.HeaderFooter.EvenHeader.CenteredText = ws.HeaderFooter.OddHeader.CenteredText = "&\"標楷體,Bold\"&16這是頁首中間文字"; 

設定頁尾右邊加入日期、時間、目前頁數、總頁數
====
ws.HeaderFooter.EvenFooter.RightAlignedText = ws.HeaderFooter.OddFooter.RightAlignedText = "{0}  {1}  {2}/{3}".FormatString(ExcelHeaderFooter.CurrentDate,ExcelHeaderFooter.CurrentTime,ExcelHeaderFooter.PageNumber,ExcelHeaderFooter.NumberOfPages);

Entity Framework 建立新物件並儲存後馬上取得關聯資料

使用 CreateProxy 建立物件,不要直接 new var newmodel = _contextXXX.CreateProxy<yyy>(); ... _contextXXX.yyy.Add(newmodel); await _contextXXX.SaveC...