PHP 也有CACHE設定喔!

快取 CACHE 功能:

使用WEBSERVER將網頁的內容一直存取在SERVER的記憶體內,
當有瀏覽者瀏覽該網頁時, 記憶體就會直接抓出來, 是效率提高.
CACHE也可以設定時數, 也就是規定幾分鐘之內才更新.
(而不會讓網頁一直停留在同一個狀態, 讓瀏覽者以為網站都不會更新)

詳細設定可參考以下網址:

http://www.ilovejackdaniels.com/php/caching-output-in-php/

 

ASP.NET (VB) 用UserControl 建立快速查詢資料

UserControl是 .NET FRAMEWORK 2.0 非常好用的功能,
一旦物件建立之後, 包裝起來. 就可以重複使用.

testQuery.aspx

<%@ Page Language=”VB” %>

<%@ Register Src=”ucQueryCustomers.ascx” TagName=”ucQueryCustomers” TagPrefix=”uc1″ %>

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd“>

<script runat=”server”>

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        UcQueryCustomers1.Visible = True
    End Sub

    ‘3, 使用事件
    Protected Sub UcQueryCustomers1_Selected(ByVal sender As Object, ByVal e As System.EventArgs)
        TextBox1.Text = UcQueryCustomers1.CustomerID
        UcQueryCustomers1.Visible = False
    End Sub
</script>

<html xmlns=”http://www.w3.org/1999/xhtml” >
<head runat=”server”>
    <title>Untitled Page</title>
</head>
<body>
    <form id=”form1″ runat=”server”>
    <div>
        訂單<br />
        <br />
        Customer ID :
        <asp:TextBox ID=”TextBox1″ runat=”server”></asp:TextBox>
        <asp:Button ID=”Button1″ runat=”server” OnClick=”Button1_Click” Text=”…” /><br />
        <br />
        <uc1:ucQueryCustomers ID=”UcQueryCustomers1″ runat=”server” Visible=”false” OnSelected=”UcQueryCustomers1_Selected” />
   
    </div>
    </form>
</body>
</html>

———

(User Control: UcQueryCustomers1.ascx)

———

<%@ Control Language=”VB” ClassName=”ucQueryCustomers” %>

<script runat=”server”>

    Public ReadOnly Property CustomerID() As String
        Get
            Return GridView1.SelectedValue
        End Get
    End Property
   
    ‘1, 對外宣告事件
    Public Event Selected As EventHandler
   
    ‘2, 在正確時間點觸發事件給外界
    Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        RaiseEvent Selected(sender, e)
    End Sub
</script>

<div>
    查詢 :
    <asp:TextBox ID=”TextBox1″ runat=”server”></asp:TextBox>
    <asp:Button ID=”Button1″ runat=”server” Text=”查詢” /><br />
    <asp:GridView ID=”GridView1″ runat=”server” AllowPaging=”True” AutoGenerateColumns=”False”
        CellPadding=”4″ DataKeyNames=”CustomerID” DataSourceID=”SqlDataSource1″ EmptyDataText=”There are no data records to display.”
        ForeColor=”#333333″ GridLines=”None” OnSelectedIndexChanged=”GridView1_SelectedIndexChanged”>
        <FooterStyle BackColor=”#1C5E55″ Font-Bold=”True” ForeColor=”White” />
        <Columns>
            <asp:CommandField ShowSelectButton=”True” />
            <asp:BoundField DataField=”CustomerID” HeaderText=”CustomerID” ReadOnly=”True” SortExpression=”CustomerID” />
            <asp:BoundField DataField=”ContactTitle” HeaderText=”ContactTitle” SortExpression=”ContactTitle” />
            <asp:BoundField DataField=”CompanyName” HeaderText=”CompanyName” SortExpression=”CompanyName” />
            <asp:BoundField DataField=”ContactName” HeaderText=”ContactName” SortExpression=”ContactName” />
        </Columns>
        <RowStyle BackColor=”#E3EAEB” />
        <EditRowStyle BackColor=”#7C6F57″ />
        <SelectedRowStyle BackColor=”#C5BBAF” Font-Bold=”True” ForeColor=”#333333″ />
        <PagerStyle BackColor=”#666666″ ForeColor=”White” HorizontalAlign=”Center” />
        <HeaderStyle BackColor=”#1C5E55″ Font-Bold=”True” ForeColor=”White” />
        <AlternatingRowStyle BackColor=”White” />
    </asp:GridView>
    <asp:SqlDataSource ID=”SqlDataSource1″ runat=”server” ConnectionString=”<%$ ConnectionStrings:NorthwindConnectionString1 %>”
        DeleteCommand=”DELETE FROM [Customers] WHERE [CustomerID] = @CustomerID” InsertCommand=”INSERT INTO [Customers] ([CustomerID], [ContactTitle], [CompanyName], [ContactName]) VALUES (@CustomerID, @ContactTitle, @CompanyName, @ContactName)”
        ProviderName=”<%$ ConnectionStrings:NorthwindConnectionString1.ProviderName %>”
        SelectCommand=”SELECT [CustomerID], [ContactTitle], [CompanyName], [ContactName] FROM [Customers] WHERE ([CompanyName] LIKE ‘%’ + @CompanyName + ‘%’)”
        UpdateCommand=”UPDATE [Customers] SET [ContactTitle] = @ContactTitle, [CompanyName] = @CompanyName, [ContactName] = @ContactName WHERE [CustomerID] = @CustomerID”>
        <DeleteParameters>
            <asp:Parameter Name=”CustomerID” Type=”String” />
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Name=”ContactTitle” Type=”String” />
            <asp:Parameter Name=”CompanyName” Type=”String” />
            <asp:Parameter Name=”ContactName” Type=”String” />
            <asp:Parameter Name=”CustomerID” Type=”String” />
        </UpdateParameters>
        <SelectParameters>
            <asp:ControlParameter ControlID=”TextBox1″ Name=”CompanyName” PropertyName=”Text”
                Type=”String” />
        </SelectParameters>
        <InsertParameters>
            <asp:Parameter Name=”CustomerID” Type=”String” />
            <asp:Parameter Name=”ContactTitle” Type=”String” />
            <asp:Parameter Name=”CompanyName” Type=”String” />
            <asp:Parameter Name=”ContactName” Type=”String” />
        </InsertParameters>
    </asp:SqlDataSource>
</div>

—————-

 

Adobe 為學術界提供Adobe Flex Builder 3 Pro 免費授權

想擁有一套免費的Adobe Flex Builder 3 Pro嗎?
不用再辛苦去搜尋引擎找盜版的來使用,
也不必擔心程式用了60天就掛點..

Adobe 為了鼓勵學術界使用Adobe Flex Builder 3,
特別提供免費的授權序號, 讓您無後顧之憂!

下載步驟:
1. 先到Adobe 官方網站下載 Adobe Flex Builder 3 試用版 (60天)
2. 到 http://www.flexregistration.com/ 註冊您的EMAIL 及上傳一張學生證或在學證明
3. 大概過了一到二星期就會回覆您的EMAIL啦~

Cheers~

ASP.NET (VB) 如何存取,加解密 Web.Config 的 AppSettings

<%@ Page Language=”VB” %>

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd“>

<script runat=”server”>

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Label1.Text = WebConfigurationManager.AppSettings(TextBox1.Text)
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        If Not Page.IsPostBack Then
            DropDownList1.DataSource = WebConfigurationManager.AppSettings.Keys
            DropDownList1.DataBind()
            TextBox2.Text = WebConfigurationManager.AppSettings(DropDownList1.SelectedValue)
        End If
    End Sub

    Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        TextBox2.Text = WebConfigurationManager.AppSettings(DropDownList1.SelectedValue)
    End Sub

    Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        ‘1, 寫入Runtimeg設定
        ‘WebConfigurationManager.AppSettings.Set(DropDownList1.SelectedValue, TextBox2.Text)
        ‘2, 修改Web.config
        ‘2-1, 開啟web.config
        Dim cfg As System.Configuration.Configuration = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath)
        ‘2-2, 修改設定
        cfg.AppSettings.Settings(DropDownList1.SelectedValue).Value = TextBox2.Text
        ‘2-3, 存檔
        cfg.Save()
    End Sub

    Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        ‘1, 開啟web.config
        Dim cfg As System.Configuration.Configuration = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath)
        ‘2, 取得appSettings設定區段
        Dim cs As ConfigurationSection = cfg.GetSection(“appSettings”)
        ‘3, 判斷是否有加密過, 以決定加密或解密
        If cs.SectionInformation.IsProtected Then
            cs.SectionInformation.UnprotectSection()
            Response.Write(“已解密…”)
        Else
            cs.SectionInformation.ProtectSection(“DataProtectionConfigurationProvider”)
            Response.Write(“已加密…”)
        End If
        ‘4, 存檔
        cfg.Save()
    End Sub
</script>

<html xmlns=”http://www.w3.org/1999/xhtml” >
<head runat=”server”>
    <title>Untitled Page</title>
</head>
<body>
    <form id=”form1″ runat=”server”>
    <div>
        key :
        <asp:TextBox ID=”TextBox1″ runat=”server”></asp:TextBox>
        <asp:Button ID=”Button1″ runat=”server” OnClick=”Button1_Click” Text=”Get Value” />
        <asp:Label ID=”Label1″ runat=”server” Text=”Label”></asp:Label><br />
        <br />
        <br />
        keys :
        <asp:DropDownList ID=”DropDownList1″ runat=”server” AutoPostBack=”True” OnSelectedIndexChanged=”DropDownList1_SelectedIndexChanged”>
        </asp:DropDownList>
        <asp:TextBox ID=”TextBox2″ runat=”server”></asp:TextBox>
        <asp:Button ID=”Button2″ runat=”server” Text=”修改” OnClick=”Button2_Click” />
        <asp:Button ID=”Button3″ runat=”server” OnClick=”Button3_Click” Text=”加密/解密” /></div>
    </form>
</body>
</html>

Adobe Flex 製作動畫效果

學Adobe Flex最酷的效果莫過於看到button 的移動了…
用Adobe Flex可以用程式寫效果, 不用再用FLASH畫也可以做出相對效果.
以下是一些特效的範例:

<?xml version=”1.0″ encoding=”utf-8″?>
<mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml” layout=”vertical”>

<mx:Script>
 <![CDATA[
  
  import mx.effects.easing.Back;
  
 ]]>
</mx:Script>
 <mx:Button label=”Button” width=”273″ height=”99″  mouseDownEffect=”{effect1}”/>
 <mx:Button label=”MoveIT” mouseDownEffect=”{effect2}”/>
 <mx:AnimateProperty id=”effect1″ property=”x” fromValue=”10″
  toValue=”100″ duration=”2000″
   easingFunction=”Back.easeOut”
  />
  <!– East In, East Out, 回彈效果–>
  
 <mx:Blur id=”effect2″ blurXFrom=”0″ blurXTo=”100″ duration=”2000″ />
 <!– 模糊 –>
 <!– blurXTo 間距 –> 
 
 
 <mx:Button label=”Dissolve” mouseDownEffect=”{effect3}”/>
 <mx:Dissolve id=”effect3″  alphaFrom=”1″ alphaTo=”0″ duration=”2000″ />
 <!– 溶解 –>
 
 <mx:Button label=”Fade” mouseDownEffect=”{effect4}”/>
 <mx:Fade id=”effect4″  alphaFrom=”0″ alphaTo=”1″ duration=”3000″ />
 <!– 淡入 –>
 
 <mx:Button label=”Glow” mouseDownEffect=”{effect5}” width=”267″ height=”100″/>
 <mx:Glow id=”effect5″  alphaFrom=”0″ alphaTo=”1″  blurXFrom=”0″ blurXTo=”100″ duration=”500″  repeatCount=”3″ repeatDelay=”4″/>
 <!– 光暈 –>
 
</mx:Application>

Adobe Flex 調整基本外觀範例

  1. 在Adobe Flex 中調整外觀的方式有很多, 在這裡Show出了幾種方法:
  2. 使用CSS (記得並不是所有的CSS都能夠使用)
  3. 直接在TAG裡面指定屬性(但這樣維護會很麻煩, 因為以後若要改就要大動工程)
  4. 用ActionScript的SetStyle method. (缺點是一次只能指定一個屬性)

注意事項:

  • 使用setSyle雖然一次只能指定一個, 但是某些效果卻只有他能做到.
  • 使用CSS時, 不用body, 要用Global來調整全部的網頁的屬性(比如說統一字型, 統一顏色等)
  • 使用CSS class時, 在<mx: > 中記得屬性是 styleName=”css class name”

若style之間有衝突, STYLE的先後順序:

  1. 在MXML裡面的一定先取
  2. class style
  3. type style
  4. 程式內的parent container
  5. 程式內的parent container 的 class
  6. 程式內的parent container 的 type selector
  7. Global Style

 

<?xml version=”1.0″ encoding=”utf-8″?>
<mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml” layout=”vertical” creationComplete=”init()”>

<mx:Style>
Button {
 
 font-style: italic;
 fontFamily: “Comic Sans Ms”;
 
}
global{
 
 font-size:20px;
 
}

.thisisclass{

 font-weight:bold; 

}
</mx:Style>

 <mx:Script>
  <![CDATA[
   //one time on one property, not suggest
   private function init() {
    myButton.setStyle(“fontSize”, 15); 
   }
   
  ]]>
 </mx:Script>
 <mx:Text text=”haha” />
 <mx:Button id=”myButton” label=”click me”  alpha=”10″ width=”282″ height=”149″/>
 <mx:Text text=”UsingClass”   styleName=”thisisclass” />
 
</mx:Application>

不用開Browser也可以存取遠端MYSQL資料庫

不知道各位使用PHPMYADMIN時, 會不會覺得BROWSER端控制MYSQL資料庫有時候會有點慢,
尤其是當遠端SERVER在美國時, 每一次POSTBACK都要等上幾秒鐘, 這樣做其實相當沒有效率.
要怎麼提高效率呢?

我想到了兩種方法:
1. 自己設計WIN FORM, 使用GRIDVIEW存取資料庫的資料:
搭配VISUAL STUDIO 的MYSQL ADO.NET CONNECTOR, 你可以自己設計WIN FORM, 不只是專屬於你個人的WINFORM, 也可以傳給你的管理者. 使用離線資料庫的處理方式. 在GRIDVIEW內, 新增,刪除,修改都可以直接REAL TIME進行, 當確定更新的時候, 才傳送回去遠端的資料庫. 是不是大大節省了在PHPMYADMIN 按來按去等待的時間呢?

2. MYSQL 網站提供的QUERY BROWSER.
http://www.mysql.com 網站上有提供免費的GUI控制程式, 如果懶惰設計WIN FORM, 就可以直接下載來用. 也是相當不錯的選擇喔. 直接用別人寫好的APP, 可以省下大量的時間, 但有可能要花心思來學習怎麼使用了.

(以上兩種方法的使用前提是你的MYSQL帳號類型是允許遠端存取(%), 而不是localhost而已喔)

從PHP平臺搬移到.NET, MYSQL的資料該怎麼辦?

如果各位跟我一樣, 有從PHP平臺搬移到.NET的經驗, 一定會卡在資料庫的移轉問題.
我們知道Microsof SQL SERVER 很好用, 而且號稱跟.NET平臺結合得天衣無縫,
但是如果我以前的資料都存放在MYSQL, 那該怎麼辦?

方法其實有兩種,

方法一(如果您堅持要搬資料庫)
可以先使用PHPMYADMIN來做匯出EXCEL或CSV的動作,  然後再通過.NET的程式把資料送入,
這個方式需要在MSSQL重新建立資料表, 然後再把資料批次送入, 這樣做就可以把MYSQL的資料完全移轉到MSSQL, 但這樣做既費時, 又要寫程式, 而且也難保不會有資料遺失.

方法二
MYSQL 其實已經幫您想好了解決方案, 在http://www.mysql.com 的官網中其實已經提供了免費的NAMESPACE, .dll, 讓您直接安裝在VISUAL STUDIO(VS)上, 從此你就可以用VS 來編輯MYSQL資料庫, 他的ConnectionString, DataAdapter, DataCommand等宣告方式跟MSSQL是大同小異的, 因此您可以輕輕鬆鬆存取MYSQL的資料, 又不必擔心會有資料遺失的問題.

下載的原件名稱為: CONNECTOR ADO.NET 5.1
網址: http://dev.mysql.com/downloads/connector/net/5.1.html
安裝方法: 直接打開 msi檔就會自動安裝到VISUAL STUDIO的NAMESPACE FOLDER裡

附件還包括了MYSQL CLASSES的運用方法與範例, 讓您輕鬆學習上手

 

PHP物件導向

對PHP的物件導向程式設計是否一籌莫展?
其實寫久了PHP的網頁程式, 你會發現將程式包成一個個CLASS會比起你在個別的網頁寫FUNCTION來得更具規畫性, 先將您的網頁規劃成一個個物件, 每個物件裡面又有屬性, 方法等. 你可以把它看成是代數計算機, 代入了值進去, 經過計算再把答案丟出來(方法), 你也可以把它看成是一個直接提供值的東西(屬性).

物件導向程式設計說難不難, 說簡單其實也不簡單, 最大的好處就是讓你可以不必一直重複寫一些一直用到的程式, 他跟INCLUDE的觀念不太相同. INCLUDE只是當作是檔案的部分丟出來, 但CLASS的使用則是區域性計算.

Object Oriented Programming (OOP) 最重要的概念有三種:

  1.  封裝 (encapsulation)
  2.  繼承 (Inheritance)
  3.  多型 (Polymorphism)

說的那麼多, 直接看範例就了解了, PHP官網提供了一些基礎的範例, 相信聰明的你一看就會了解了 ^_^

http://www.php.net/manual/en/language.oop5.basic.php