2015年11月19日 星期四

Transaction in Linq to SQL

資料來源
http://neweden168.blogspot.tw/2014/08/transaction-in-linq-to-sql.html

Transaction in Linq to SQL 

1.Implicit Transaction: 當沒有設定DataContext.Transaction也沒有包TransactionScope時,Call SubmitChanges()會自動將新增/更新/刪除動作包成交易,最為簡便。但要注意,它限於同一個DataConext(當然,同一個DB Connection)且Transaction的範圍無法包含SELECT
2.Explicit Local Transaction: 前題是參與Transaction的DataContext要共用一條Connection,且要自己完成BeginTransaction、 Commit、Rollback等動作。設定DataContext.Transaction的時機可以決定是否將SELECT也納入 Transaction範圍。還有一點限制是,這種做法只限同一台DB,不支援分散式交易
3.Explicit Distributable Transaction: 彈性最大,可支援異種資料庫的分散式交易,但要注意所有包含在TransactionScope中的資料庫動作都會啟用LTM或OleTx,成本頗為昂貴 (輕巧的LTM適用的條件很嚴苛,只限SQL 2005,如果TransactionScope中有涉及一台以上DB或對遠端SQL 2005開啟兩條以上連線,一定是用貴森森的OleTx),可以視需要將不必參與Transaction的部分隔離開來,以增進效能。(延伸閱讀: .NET分散式交易程式開發FAQ )

2015年10月27日 星期二

自訂dialog

1.加入
/// 使用前需加入
///  <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
///  <script src="//code.jquery.com/jquery-1.10.2.js"></script>
///  <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
///  因model屬性無法使用,所以加入block ui套件,但同時加入會造成block ui 擋住dialog ,故需調整index


html 

javascript
  function confirdialog(param1, param2, title, content,btnid) {
        $.blockUI({ message:"", baseZ: -1, });  //如果用block ui 就必須調整階層位置
        $("#dialog").dialog({
            draggable: false,
            title: title,
            open: function () {
                var markup = content;
                $(this).html(markup);
            },
            buttons: [
                {
                    text: param1,
                    click: function () {
                        $('#'+btnid).click();
                    }
                },
                {
                    text: param2,
                    click: function () {
                        $.unblockUI();
                        $(this).dialog('close');
                    }
                }
            ],
            zIndex: 999
           
        }).prev().find(".ui-dialog-titlebar-close").hide();; //本行為隱藏dialog打叉按鍵
    
     
    }


<body>
 <div  id="dialog" style="display:none" >
  
    </div>

<asp:Button runat="server" ID="btnSubmitxt" OnClick="btnSubmitxt_Click" Text="自訂名稱"  />
   <asp:Button ID="Button1" runat="server" Text="Button" style = "display:none" OnClick="ConfirmAlert_Click" CausesValidation="false" />

</body>

cs.
ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "userControlCallClick", "confirdialog('" + actionText + "','" + closeText + "','" + title + "','" + content + "','" + Button1.ClientID + "')", true);

2015年8月26日 星期三

javascript 控制是否要啟用驗證控制項

javascript:
        $(document).ready(function () {
            if ($('#txt2').val() == '') {
                ValidatorEnable($('#rfvtxt')[0], true);

            } else
                ValidatorEnable($('#rfvtxt')[0], false);
            $('#txt2').change(function () {
                if ($('#txt2').val() =='') {
                    ValidatorEnable($('#rfvtxt')[0], true);

                } else
                    ValidatorEnable($('#rfvtxt')[0], false);
            });
        });
        function validatePage() {
            var flag = Page_ClientValidate("aaa");
            return flag;
        }
html:


    <asp:RequiredFieldValidator runat="server" ID="rfvtxt" ControlToValidate="TXT" ErrorMessage="*"   ValidationGroup="aaa"  Enabled="false"></asp:RequiredFieldValidator>
        <asp:Button runat="server" OnClick="Unnamed_Click"   OnClientClick="javascript:return validatePage();"/>


cs.
 Page.Validate();
        if (!Page.IsValid)
        {
            return;
        }


寫成function做法
http://techbrij.com/client-side-validation-using-asp-net-validator-controls-from-javascript



2015年8月11日 星期二

分頁

  //分頁格式水平數字擺設樣式1處理方法。
    //版本:v1.0;日期:20091116;作者:Wesley0917;說明:建立方法
    //撰寫語言:ASP.NET2.0
    //輸入1:索引頁面數。
    //輸入2:總分頁數。
    //輸入3:分頁顯示的筆數。
    //輸入4:要傳遞的網址頁面字串。
    //結果0:輸出分頁後水平數字擺設樣式。
    //範例0:CutPageStyle1Horizontal_Md(Request["Page"], "32", "10", "Default2.aspx?") 。結果:[前十頁]11 12 [13] 14 15 16 17 18 19 20 [後十頁]
    public static string CutPageStyle1Horizontal_Md(string strPageIndex_Val, string strTotalPages_Val, string strPageShowCounts_Val, string strURL_Val)
    {
        //宣告整數變數。(目前在第幾頁)
        int intPageIndex = Convert.ToInt32(strPageIndex_Val);
        //宣告整數變數。(資料的總頁數。搜尋到的資料,共需要「幾頁」才能全部呈現)
        int intPages = Convert.ToInt32(strTotalPages_Val);
        //宣告整數變數。(分頁顯示的筆數整數值)
        int intPageShowCounts = Convert.ToInt32(strPageShowCounts_Val);
        //宣告字串變數。(組合字串用)
        string strValue1 = null;
        string strValue2 = null;
        string strValue3 = null;

        //宣告整數變數。(十進位字數區隔)
        int intBlockPage = 0;
        //取得十進位數字結果。(例如:1~10=0; 11~20=1; 21~30=2)
        //取得除法的整數成果(商),如果有餘數則不去管它。
        intBlockPage = intPageIndex / intPageShowCounts;

        //當十進位數字大於0時,表示不是1~10的範圍。
        if (intBlockPage > 0)
        {
            //輸出結果。(前十頁的超連結)
            strValue1 = "<a href=" + strURL_Val + "Page=" + (((intBlockPage - 1) * intPageShowCounts) + (intPageShowCounts - 1)) + "> [前" + intPageShowCounts.ToString() + "頁]  </a>  ";
        }

        //以十進位為單位顯示所有號碼。0~10
        for (int K = 0; K <= intPageShowCounts; K++)
        {
            //當(十進位字數加上0~10迴圈單位數字)小於等於資料總頁數(intPages)範圍內時。例如:(2*10+1) <=43
            if ((intBlockPage * intPageShowCounts + K) <= intPages)
            {
                //當(十進位字數加上0~10迴圈單位數字)等於(目前在第幾頁)時。
                if (((intBlockPage * intPageShowCounts) + K) == intPageIndex)
                {
                    //組合字串結果。(目前頁次的超連結前後加上[ ]符號)
                    strValue2 += "[<b>" + intPageIndex + "</b>]" + "   ";
                }
                else
                {
                    //當(十進位字數加上0~10迴圈單位數字)不等於0時。
                    if (((intBlockPage * intPageShowCounts) + K) != 0)
                    {
                        //組合字串結果。(目前頁次範圍的數字超連結)
                        strValue2 += "<a href=" + strURL_Val + "Page=" + (intBlockPage * intPageShowCounts + K) + ">" + (intBlockPage * intPageShowCounts + K) + "</a>  ";
                    }
                }
            }
        }

        //當(十進位數字)小於等於總頁次時。
        if ((intBlockPage < (intPages / intPageShowCounts)) & (intPages >= (((intBlockPage + 1) * intPageShowCounts) + 1)))
        {
            //組合字串結果。(後十頁的超連結)
            strValue3 = "  <a href=" + strURL_Val + "Page=" + ((intBlockPage + 1) * intPageShowCounts + 1) + ">  [後" + intPageShowCounts.ToString() + "頁]  </a>";
        }

        //傳回結果。
        return strValue1 + strValue2 + strValue3;
    }

2015年7月15日 星期三

Checkbox 全選功能

內容轉載於:http://www.dotblogs.com.tw/alanjiang/archive/2013/06/30/107399.aspx 
 
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="default.aspx.cs" Inherits="Lab_CheckAllInGridView._default" %>

<!DOCTYPE html>

<html>
<head runat="server">
    <title>CheckBox 全選</title>
    <script type="text/javascript" src="Scripts/jquery-2.0.2.min.js"></script>
    <script type="text/javascript">

        //  選擇 GridView 全部的 checkbox
        //  傳入控制checkbox全選的checkbox物件
        function checkAll(header) {
            $('#<%= gvData.ClientID %> input[type=checkbox]').prop("checked", header.checked);
            
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:GridView ID="gvData" runat="server" AutoGenerateColumns="False">
            <Columns>
                <asp:TemplateField HeaderText="選取">
                    <HeaderTemplate>
                        <asp:CheckBox ID="cbHeader" runat="server" onclick="checkAll(this);" />
                        選取
                    </HeaderTemplate>
                    <ItemTemplate>
                        <asp:CheckBox ID="cbDel" runat="server" />
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="Name" HeaderText="姓名" />
                <asp:BoundField DataField="Age" HeaderText="年齡" />
            </Columns>
        </asp:GridView>
    </div>
    </form>
</body>
</html>

2015年7月14日 星期二

word-wrap文字換行筆記

轉錄文章:http://blog.csdn.net/gohands/article/details/2194782

word-wrap:break-word; overflow:hidden;

word-wrap是控制換行的。
使用break-word時,是將強制換行。中文沒有任何問題,英文語句也沒問題。但是對於長串的英文,就不起作用。
break-word是控制是否斷詞的。
normal是預設情況,英文單詞不被拆開。
break-all,是斷開單詞。在單詞到邊界時,下個字母自動到下一行。主要解決了長串英文的問題。
keep-all,是指Chinese, Japanese, and Korean不斷詞。即只用此時,不用word-wrap,中文就不會換行了。(英文語句正常。)


ie下:
使用word-wrap:break-word;所有的都正常。
ff下:
如這2個都不用的話,中文不會出任何問題。英文語句也不會出問題。但是,長串英文會出問題。
為了解決長串英文,一般用word-wrap:break-word;word-break:break-all;。但是,此方式會導致,普通的英文語句中的單詞會被斷開(ie下也是)。
目前主要的問題存在於 長串英文 和 英文單詞被斷開。其實長串英文就是一個比較長的單詞而已。
即英文單詞應不應該被斷開那?那問題很明顯了,顯然不應該被斷開了。
對於長串英文,就是惡意的東西,自然不用去管了。但是,也要想些辦法,不讓它把容器撐大。
用:overflow:auto; ie下,長串會自動折行。ff下,長串會被遮蓋。
所以,綜上,最好的方式是word-wrap:break-word;overflow:hidden;而不是word-wrap:break-word;word-break:break-all;
word-wrap:break-word;overflow:auto;ie下沒有任何問題。在ff下,長串會被遮住部分內容。