2014年2月26日 星期三

指定網頁編碼

需求 :

發送的網頁是asp ,編碼big5  ,網址傳值,其中傳送的值有中文字

接收的網頁是asp.net,預設編碼utf-8,Request到的值是亂碼


我的解法是在web.config

  <system.web>
    <globalization requestEncoding="big5" responseEncoding="big5"/>


完畢。


==============================
以下方法自行轉換utf8 和 big5

ASP.NET撰寫 utf8網頁
1. HTML Head
<meta http-equiv="content-type" content="text/html; charset=UTF-8">

2. ASP.NET Code
Session.CodePage=65001
Response.CharSet="UFT8"

//Response.Charset = "BIG5";
//Session.CodePage = 950

3. 將 ASPX 利用編碼的方式儲存,建議使用 UTF-8  有簽章 (CodePage 65001)

4. 存放在 SQL Server 欄位必須使用 nchar / nvarchar ,Insert 時必須使用大寫 N

5. IE 測試時請先關閉「自動編碼」




ASP撰寫 utf8網頁
1.HTML Head
<meta http-equiv="Content-Type" content="text/html; charset=utf8">
最好寫在<title>前面 (For IE6 bug)

2.要用記事本另存指定編碼為utf8
這樣才算完整的utf8網頁




2014年2月12日 星期三

[Javascript]在搜尋輸入框輸入字串,按ENTER即送出查詢


龍偷內兜搜尋引擎

在搜尋輸入框輸入字串,按ENTER即送出查詢。


<INPUT type="text" name="strQuery" id="strQuery" style="font-size:

9pt;HEIGHT:17PX;width:110px; background-color: #ffffff; border: 1 solid #FF9900" value="請

輸入關鍵字" accesskey="S" onFocus="javascript:if(value=='請輸入關鍵字'){value='';}"

onKeyPress="javascript:if(event.keyCode == 13){search(this,event)}">

<a href="javascript:search()"><img src="images/index_top05.gif" alt="搜尋按鈕" height="17"

border="0"></a>


在搜尋結果頁面按回上一頁設定Focus


<body onLoad="setFocus()">




<script LANGUAGE="JavaScript">
function search()
{
document.search_form.p.value = document.search_form.strQuery.value;
  document.search_form.submit();
}
function setFocus()
{
   if(document.search_form.strQuery.value != "請輸入關鍵字")
 document.search_form.strQuery.focus();
}
</script>

=======================
完畢。

2014年1月27日 星期一

[javascript]核取方塊checkbox是否被勾選

JavaScript練習題
有三個核取方塊checkbox選項,
選了第一個選項,第二個選項才能被勾選;
選了第二個選項,第三個選項才能被勾選;

反之,
取消選擇第二個選項,則第三個選項不可被勾選。


程式如下







      <p><INPUT id=checkbox1 type=checkbox name=checkbox1 value="1" onclick='show_item()'
>開會用
         <INPUT id=checkbox2 type=checkbox name=checkbox2 value="1" disabled
onclick='show_item()' >不發通知單
         <INPUT id=checkbox3 type=checkbox name=checkbox3 value="1" disabled>電子會議
         第四<INPUT id=checkbox4 type=checkbox name=checkbox4 value="1"<%if
mid(cstr(r_week),4,1)="1" then %>checked<%end if%>>
         第五<INPUT id=checkbox5 type=checkbox name=checkbox5 value="1"<%if
mid(cstr(r_week),5,1)="1" then %>checked<%end if%>>
 <P>


<script language=javascript>

//顯示選項:不發通知單、電子會議
function show_item(){
   if (document.all("checkbox1").checked)
   {
      document.all("checkbox2").disabled = false
   }
   else
   {
      document.all("checkbox2").checked = false
      document.all("checkbox2").disabled = true
      document.all("checkbox3").checked = false
      document.all("checkbox3").disabled = true
   }
   if (document.all("checkbox2").checked)
   {
      document.all("checkbox3").disabled = false
   }
   else
   {
      document.all("checkbox3").checked = false
      document.all("checkbox3").disabled = true
   }
}


</script>


2014年1月16日 星期四

[sql]抓取最新資料

每五分鐘抓取資料。資料庫有一欄位CreateTime,格式是字串yyyyMMddhhmmss,作為版本識別。


Select COUNT(*)   FROM [DBNAME].[dbo].[Tpe]
Where CreateTime = (select Max(CreateTime) FROM [DBNAME].[dbo].[Tpe] ) 

2013年12月30日 星期一

WebClient運用:可以每天自動抓yahoo股票行情


        WebClient wc = new WebClient();
        byte[] b = wc.DownloadData("http://tw.yahoo.com");

        string html = Encoding.Default.GetString(b);
        Response.Write(html);


========================
同場加映:
WebClient運用:自動下載遠端網路檔案

2013年12月24日 星期二

壓縮log檔語法.sql


use DBName
backup log DBName with no_log
dbcc shrinkfile(DBName_Log,1)


當log 膨脹太大,下指令瘦身一下

2013年12月12日 星期四

將資料匯出成excel檔案

這個方法是asp& asp.net都適用

1.要匯出的資料來源:

  (1)要匯出的資料是GridView,


  (2)要匯出的資料不是GridView
    將要匯出的資料組成html的<table>字串,包括字型大小、跨欄置中等。
    換行</br>時,你可能會需要用到這個語法<br style='mso-data-placement:same-cell;' />,達到換行的目的。
    UI -- 上放一個Panel, visible設為false,
       -- Panel裡面放一個Label,將html字串給Label.text



            this.Label3.Text = result;


            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
            HttpContext.Current.Response.ContentType = "application/vnd.xls";

            //HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=" + HttpUtility.UrlEncode("中文檔名", System.Text.Encoding.UTF8) + ".xls");     //解決中文檔名變成亂碼
            HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=aa.xls");
            HttpContext.Current.Response.AddHeader("mata", "http-equiv=Content-Type content=text/html;charset=big5");

            System.IO.StringWriter sw = new System.IO.StringWriter();
            System.Web.UI.HtmlTextWriter htw = new System.Web.UI.HtmlTextWriter(sw);
            //this.Gridview1.RenderControl(htw);    //將Gridview匯出成excel
            this.Panel1.RenderControl(htw);         //將Panel匯出成excel



            HttpContext.Current.Response.Write(sw.ToString().Replace("<div>", "").Replace("</div>", ""));
            HttpContext.Current.Response.End();



完畢。