2014年5月27日 星期二

到不了



范瑋琪寫給前男友的歌,聽說黑人為此吃醋不已。

旋律簡單好學,可以歸類為芭樂歌,但歌詞意境卻相當扣人心弦。
最喜歡的歌詞是前兩句
「你眼睛會笑    彎成一條橋」
每次看見她的笑容,就會想到這句歌詞

2014年5月22日 星期四

淚眼矇矓

還是相聲瓦舍20年大劇-鄧力軍的插曲
這次是第二幕結尾曲
「中場休息15分鐘~」

淚眼朦朧  窗外明月是那樣的溫柔
彷彿是你用溫暖的雙手  哦  將我輕輕碰
四處飄泊  我用情一生卻換來寂寞
而歲月不知不覺地走過  問我留下些什麼
出現在夢中  終於明白對你的愛依舊
是折磨  還躲在傷心絕望的角落
與你再相逢  是我日夜期待已久的夢
又錯過  原來情緣早已消散風中
淚眼朦朧  窗外明月是那樣的溫柔
彷彿是你用溫暖的雙手  哦  將我輕輕碰
四處飄泊  我用情一生卻換來寂寞
而歲月不知不覺地走過  問我留下些什麼

2014年5月20日 星期二

斷橋

照樣是相聲瓦舍20年大劇-鄧力軍的插曲
這是第二幕開場插曲
「來來來,唱完這首歌,再說吧」

與君一席酒  飲畢話別休
燃燭又見瘦  夢醒孤鵲樓
此情難長久  曲畢又三秋
憐影還拂袖  不忍上心頭

窗外懸一輪明月  映落在澄鏡湖面  微風切
切過那垂柳河邊  斑剝鳴咽
我聽見  我無言  還想著分手那夜
望著你消失不見  我的心痛徹撕裂

想起你哭泣的臉  又燃起無盡思念
這些年  你不在我的身邊  是否如願
我站在河堤邊  斷橋上望著秋月
遠方的飄落殘葉隨風層疊  說離別

2014年5月16日 星期五

弄堂

第一次是在相聲瓦舍的相聲劇大作-鄧力軍裡聽到
該劇全部的音樂歌曲皆由張穆庭製作
這首是片尾曲
Youtube上可以搜出好幾個結果,但我最喜歡這個
當然是因為洪瑞襄的緣故

繁華散盡 落葉飄
徒然一身幽居嘆寂寥
迎風身影燈火照 但求醉臥在今宵
不知何時才能 與你再相逢 也許是多年以後
此情忘不了 深藏在心中 但願你會記得我
如果不能與你長相守 只願我能化成飛煙隨你走
就在夢中一笑別離後 淚珠滑落臉龐 更心痛
如果不能與你長相守 只願我能化成飛煙隨你走
多年以後往事再回首 笑我一生孤獨 全成空

2014年5月10日 星期六

多組RadioButtonList互斥

一個同事的發問...

他在畫面上放了 3 組 RadioButtonList,希望其中一組選到時,另兩組可以自動清空選擇,於是我寫了這個範例

基本上兩種做法,偷懶的做法是放個 UpdatePanel,把 RadioButtonList 們都扔進去,比較好的做法是用 javascript 在 client 上處理。

首先是偷懶的做法
這是 aspx,有 3 個 RadioButtonList,都設定 SelectedIndexChanged 事件和設定 AutoPostBack=true
<form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <asp:RadioButtonList ID="rbl1" runat="server" RepeatDirection="Horizontal" RepeatLayout="Flow"
                OnSelectedIndexChanged="rbl1_SelectedIndexChanged" AutoPostBack="true">
                <asp:ListItem>Car</asp:ListItem>
                <asp:ListItem>Motocycle</asp:ListItem>
                <asp:ListItem>Bicycle</asp:ListItem>
            </asp:RadioButtonList>
            <br />
            <br />
            <asp:RadioButtonList ID="rbl2" runat="server" RepeatDirection="Horizontal" RepeatLayout="Flow"
                OnSelectedIndexChanged="rbl2_SelectedIndexChanged" AutoPostBack="true">
                <asp:ListItem>Apple</asp:ListItem>
                <asp:ListItem>Mango</asp:ListItem>
                <asp:ListItem>Pineapple</asp:ListItem>
            </asp:RadioButtonList>
            <br />
            <br />
            <asp:RadioButtonList ID="rbl3" runat="server" RepeatDirection="Horizontal" RepeatLayout="Flow"
                OnSelectedIndexChanged="rbl3_SelectedIndexChanged" AutoPostBack="true">
                <asp:ListItem>Frog</asp:ListItem>
                <asp:ListItem>Cat</asp:ListItem>
                <asp:ListItem>Dog</asp:ListItem>
            </asp:RadioButtonList>
        </ContentTemplate>
    </asp:UpdatePanel>
</form>
然後這是 aspx.cs
protected void rbl1_SelectedIndexChanged(object sender, EventArgs e)
{
    RadioButtonList radioButtonList = sender as RadioButtonList;
    if (radioButtonList.SelectedIndex > -1)
    {
        rbl2.SelectedIndex = -1;
        rbl3.SelectedIndex = -1;
    }
}

protected void rbl2_SelectedIndexChanged(object sender, EventArgs e)
{
    RadioButtonList radioButtonList = sender as RadioButtonList;
    if (radioButtonList.SelectedIndex > -1)
    {
        rbl1.SelectedIndex = -1;
        rbl3.SelectedIndex = -1;
    }
}

protected void rbl3_SelectedIndexChanged(object sender, EventArgs e)
{
    RadioButtonList radioButtonList = sender as RadioButtonList;
    if (radioButtonList.SelectedIndex > -1)
    {
        rbl2.SelectedIndex = -1;
        rbl1.SelectedIndex = -1;
    }
}

接著我們用 jquery 來做
一樣在 aspx 上放 3 個 RadioButtonList,然後把所有的 radio 都註冊 click 事件,當一個 radio 被 checked 時,往上找該 radio 的容器,然後把另兩個容器裡的 radio 都 uncheck
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="TestRadioButtonListExclusive.WebForm1" %>

<!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>用 jquery</title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript">
        //註冊所有 radio 的 click 事件
        $(document).ready(function(){
            var containers=["<%=rbl1.ClientID %>","<%=rbl2.ClientID %>","<%=rbl3.ClientID %>"];

            for(var i=0;i<containers.length;i++){
                $("#"+containers[i]+" :radio").each(function(){
                    $(this).click(function(event){
                        SetOtherRadioButtonListUncheck(this);
                    });
                });
            }
        });
        
        function SetOtherRadioButtonListUncheck(rObj){
            var containers=["<%=rbl1.ClientID %>","<%=rbl2.ClientID %>","<%=rbl3.ClientID %>"];
            
            //抓上層容器, RepeatLayout=Flow的話抓最近的span, RepeatLayout=Flow的話抓最近的table
            //var parentObj=$(rObj).closest("span"); //RepeatLayout=Flow
            var parentObj=$(rObj).closest("table"); //RepeatLayout=Table
            var parentId=parentObj.get(0).id;
            
            for(var i=0;i<containers.length;i++){
                //若不是觸發事件的容器, 則將該容器裡的radio uncheck
                if(containers[i]!=parentId){
                    $("#"+containers[i]).find(":radio").each(function(){
                        this.checked=false;
                    });
                }
            }
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <asp:RadioButtonList ID="rbl1" runat="server" RepeatDirection="Horizontal" RepeatLayout="Table">
            <asp:ListItem>Car</asp:ListItem>
            <asp:ListItem>Motocycle</asp:ListItem>
            <asp:ListItem>Bicycle</asp:ListItem>
        </asp:RadioButtonList>
        <br />
        <br />
        <asp:RadioButtonList ID="rbl2" runat="server" RepeatDirection="Horizontal" RepeatLayout="Table">
            <asp:ListItem>Apple</asp:ListItem>
            <asp:ListItem>Mango</asp:ListItem>
            <asp:ListItem>Pineapple</asp:ListItem>
        </asp:RadioButtonList>
        <br />
        <br />
        <asp:RadioButtonList ID="rbl3" runat="server" RepeatDirection="Horizontal" RepeatLayout="Table">
            <asp:ListItem>Frog</asp:ListItem>
            <asp:ListItem>Cat</asp:ListItem>
            <asp:ListItem>Dog</asp:ListItem>
        </asp:RadioButtonList>
    </form>
</body>
</html>

2014年4月29日 星期二

使用匿名方法賦值給匿名類別的屬性

好繞口... 

以北風資料庫的Products table 為例,假設我想做一個某家供應商的產品List,並把價格提高10%,於是我這麼寫...
var v = from product in dtNorthwindProduct.AsEnumerable()
        where product.Field<int>("SupplierID") == 1
        select new
        {
            pid = product.Field<int>("ProductID"),
            //以匿名方法重新計算價格
            price = () =>{ return product.Field<decimal>("UnitPrice") * 1.1M }
        };
.NET很乾脆地給我錯誤...

因為初始匿名型別的屬性有兩個限制
  1. 不能是null
  2. 不能用匿名方法賦值
所以要這麼寫...
var v = from product in dtNorthwindProduct.AsEnumerable()
        where product.Field<int>("SupplierID") == 1
        select new
        {
            pid = product.Field<int>("ProductID"),
            //以匿名方法重新計算價格
            price = new Func<decimal>(() => { return product.Field<decimal>("UnitPrice") * 1.1M; }).Invoke()
        };
就可以了...

參考連結
C#/.NET Little Wonders: The Joy of Anonymous Types
Assigning property of anonymous type via anonymous method

2014年4月24日 星期四

以 regular expression 驗證 Email 格式

筆記用...

檢查字串
/^.+@.+\..+$/

C#
public bool CheckEmailFormat(string email)
{
    //c#裡要把前後的斜線拿掉
    string emailFormat = @"^.+@.+\..+$";
    System.Text.Reqex reg = new System.Text.Regex(emailFormat);
    return reg.IsMatch(email);
}

Javascript
function IsEmail(value) {
    var objRegExp = /^.+@.+\..+$/;

    if (!objRegExp.test(value))
        return false;
    return true;
}

2014年3月17日 星期一

Supercell-ヒーロー


2014年3月12日 星期三

Supercell-君の知らない物語


每回聽這首歌就會想到戰場原的告白,然後眼睛就流汗了啊!!

2014年3月6日 星期四

使用ODP.NET連線出現 "Connection must be open for this operation" 錯誤

但其實不是connection沒開的問題,ODP.NET根本在整人...

2014年2月28日 星期五

Epic Split

一切都起源於這個Volvo廣告


接著宇宙最強的男人在聖誕節前後發表了這個惡搞版

基於是宇宙最強的男人,我想這還是可能的

最新消息,尚克勞德范達美不甘示弱

宇宙最強的男人會怎麼回應呢?讓我們看下去...

Let It Go - Demi Lovato


"Let It Go"
Let it go, let it go
Can't hold it back anymore
Let it go, let it go
Turn my back and slam the door

The snow glows white on the mountain tonight,
Not a footprint to be seen.
A kingdom of isolation and it looks like I'm the queen.
The wind is howling like this swirling storm inside.
Couldn't keep it in, Heaven knows I tried.

Don't let them in, don't let them see,
Be the good girl you always had to be.
Conceal, don't feel, don't let them know.
Well, now they know.

Let it go, let it go
Can't hold it back anymore
Let it go, let it go
Turn my back and slam the door
And here I stand and here I'll stay
Let it go, let it go
The cold never bothered me anyway

It's funny how some distance makes everything seem small
And the fears that once controlled me can't get to me at all.
Up here in the cold thin air I finally can breathe.
I know I left a life behind but I'm too relieved to grieve.

Let it go, let it go
Can't hold it back anymore
Let it go, let it go
Turn my back and slam the door
And here I stand, and here I'll stay
Let it go, let it go
The cold never bothered me anyway

Standing frozen
In the life I've chosen.
You won't find me.
The past is all behind me
Buried in the snow.

Let it go, let it go
Can't hold it back anymore
Let it go, let it go
Turn my back and slam the door
And here I stand, and here I'll stay
Let it go, let it go
The cold never bothered me anyway, yeah, whoa
(Na na, na na, na na na na) [4x]
Let it go yeah
Na, na.
Here I stand.
Let it go, let it go, oh
Let it go.

Let It Go - Idina Menzel



Let It Go


The snow glows white on the mountain tonight
Not a footprint to be seen
A kingdom of isolation,
And it looks like I’m the Queen.

The wind is howling like this swirling storm inside
Couldn’t keep it in, heaven knows I tried

Don’t let them in, don’t let them see
Be the good girl you always have to be
Conceal, don’t feel, don’t let them know
Well, now they know

Let it go, let it go
Can’t hold it back anymore
Let it go, let it go
Turn away and slam the door

I don’t care
What they’re going to say
Let the storm rage on,
The cold never bothered me anyway

It’s funny how some distance
Makes everything seem small
And the fears that once controlled me
Can’t get to me at all

It’s time to see what I can do
To test the limits and break through
No right, no wrong, no rules for me
I’m free

Let it go, let it go
I am one with the wind and sky
Let it go, let it go
You’ll never see me cry

Here I stand
And here I'll stay
Let the storm rage on

My power flurries through the air into the ground
My soul is spiraling in frozen fractals all around
And one thought crystallizes like an icy blast
I’m never going back,
The past is in the past

Let it go, let it go
And I'll rise like the break of dawn
Let it go, let it go
That perfect girl is gone

Here I stand
In the light of day
Let the storm rage on,
The cold never bothered me anyway

這是內建中文翻譯版本

2014年2月6日 星期四

春節記事-黑貓

(這圖是隨便抓來的,當時光線不夠,手機拍不起來)

大年初一凌晨,照慣例跟家人到附近土地公廟拜拜,一點半拜完離開時,突然聽到身後傳來一聲喵叫聲,回頭瞧半天卻不見喵影。
轉過身來竟看到一隻黑貓,毛色黑的像要融入背景,黃色的眼睛像懸在半空中似的,直勾勾地盯著我看。
難得遇到貓跟我對看超過3秒鐘沒逃跑的,於是我蹲下來對牠伸出手。沒想到這傢伙不理我的手,直接晃到我身後靠著我蹭了幾下,接著繞回前面,在距離一步的地方,背對我直挺挺的坐著,看著前方。
我試探著摸了摸牠的頭,不理我;在牠後頸抓了幾下後順著背部摸下來,不理我;改往下巴撓幾下,還是不理我。

整個就超~淡~定~

好吧,我被冷落了,只好再摸兩下頭後離開。

回到家後,摸摸口袋,原本帶去土地公廟要化掉的,以前在媽祖廟拿的護身符,不見了...

微妙...