var lst = dt.AsEnumerable()
.Select(r => r.Table.Columns.Cast<DataColumn>()
.Select(c => new KeyValuePair<string, object>(c.ColumnName, r[c.Ordinal])
).ToDictionary(z=>z.Key,z=>z.Value)
).ToList();
var serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
return serializer.Serialize(lst);
JQuery
2015年8月17日 星期一
DataTable to JSON string
2015年8月3日 星期一
Json傳輸 參數字串轉為 javascript function
{
"param1" : "str1",
"num1" : 1,
"someFunction" : "function(){alert(1);}"
}
var obj = JSON.parse(str,turnStrToFunction);
/*************
JSON.parse(str,reviver)
reviver function = > 轉換字串成為javascript function
**************/
function turnStrToFunction (key, value) {
if (value && (typeof value === 'string') && value.indexOf("function(") === 0) {
var jsFunc = new Function('return ' + value)();
return jsFunc;
}
return value;
};
2015年3月28日 星期六
SQL Group By Like , 欄位橫轉直(pivot)
select Year
,Month
,SUM(contactUs)contactUs
,SUM(contactUs)contactUs
,SUM(mamaClubCancel)mamaClubCancel
,SUM(mamaClubSignUp)mamaClubSignUp
,SUM(memberAdd)memberAdd
,SUM(memberLogin)memberLogin
,SUM(mamaClubLogin)mamaClubLogin from (
--pivot start
select YEAR,Month ,contactUs, mamaClubCancel, mamaClubSignUp, memberAdd, memberLogin , mamaClubLogin
from
(
--groupby start
SELECT Year(cdate) AS 'Year'
, Month(cdate) AS 'Month'
, case when i_name like 'mamaClubLogin%' then 'mamaClubLogin' else i_name end i_name
, COUNT(DISTINCT fno) total
, COUNT(DISTINCT ino) distint
from SUB_FlowTracking D
GROUP BY Year(cdate), Month(cdate),
--Group By Like
case when i_name like 'mamaClubLogin%' then 'mamaClubLogin' else i_name end
--groupby end
) d
pivot
( --sum field
SUM(d.total)
--field source field
for i_name in (contactUs, mamaClubCancel, mamaClubSignUp, memberAdd, memberLogin , mamaClubLogin)
) piv
--pivot end
) T Group by Year,Month
,Month
,SUM(contactUs)contactUs
,SUM(contactUs)contactUs
,SUM(mamaClubCancel)mamaClubCancel
,SUM(mamaClubSignUp)mamaClubSignUp
,SUM(memberAdd)memberAdd
,SUM(memberLogin)memberLogin
,SUM(mamaClubLogin)mamaClubLogin from (
--pivot start
select YEAR,Month ,contactUs, mamaClubCancel, mamaClubSignUp, memberAdd, memberLogin , mamaClubLogin
from
(
--groupby start
SELECT Year(cdate) AS 'Year'
, Month(cdate) AS 'Month'
, case when i_name like 'mamaClubLogin%' then 'mamaClubLogin' else i_name end i_name
, COUNT(DISTINCT fno) total
, COUNT(DISTINCT ino) distint
from SUB_FlowTracking D
GROUP BY Year(cdate), Month(cdate),
--Group By Like
case when i_name like 'mamaClubLogin%' then 'mamaClubLogin' else i_name end
--groupby end
) d
pivot
( --sum field
SUM(d.total)
--field source field
for i_name in (contactUs, mamaClubCancel, mamaClubSignUp, memberAdd, memberLogin , mamaClubLogin)
) piv
--pivot end
) T Group by Year,Month
2014年12月31日 星期三
ashx繼承方式
public class BaseHandler : IHttpHandler, IRequiresSessionState { public void ProcessRequest(HttpContext context) { OnLoad(context); } public bool IsReusable { get { return false; } } public virtual void OnLoad(HttpContext context) { } }
================================
public class test : BaseHandler { public override void OnLoad(HttpContext context) { //DOSomething } }
2014年12月15日 星期一
Javascript HTML Encode & Decode
function htmlEncode(value){
//create a in-memory div, set it's inner text(which jQuery automatically encodes)
//then grab the encoded contents back out. The div never exists on the page.
return $('<div/>').text(value).html();
}
function htmlDecode(value){
return $('<div/>').html(value).text();
}
2014年11月17日 星期一
上傳檔案 透過 Ajax To Ashx
Script:
<script type="text/javascript"> $(document).ready(function () { $("#Button1").click(function (evt) { var fileUpload = $("#FileUpload1").get(0); var files = fileUpload.files; var data = new FormData(); for (var i = 0; i < files.length; i++) { data.append(files[i].name, files[i]); }
//額外的參數
data.append("Key", "Value");
var options = {}; options.url = "FileUploadHandler.ashx"; options.type = "POST"; options.data = data; options.contentType = false; options.processData = false; options.success = function (result) { alert(result); }; options.error = function (err) { alert(err.statusText); }; $.ajax(options); evt.preventDefault(); }); }); </script>
ashx:
public void ProcessRequest(HttpContext context) {
//額外參數
string para1 = context.Request.Params.Get("key") == null ? "" : context.Request.Params.Get("key");
if (context.Request.Files.Count > 0) { HttpFileCollection files = context.Request.Files; for (int i = 0; i < files.Count;i++ ) { HttpPostedFile file = files[i]; string fname = context.Server.MapPath("~/uploads/" + file.FileName); file.SaveAs(fname); } } context.Response.ContentType = "text/plain"; context.Response.Write("File(s) Uploaded Successfully!"); }
訂閱:
文章 (Atom)