2014年3月30日 星期日

[JavaScript] BOM (Browser Object Model) methods或properties記錄

BOM function:

1. window object:
1.1 moveBy(dx, dy),dx表水平移動的像素,dy為垂直向下的像素,可為負數。
1.2 moveTo(x, y),將視窗移到螢幕的(x, y)處,可為負數。
1.3 resizeBy(dw, dh),dw表寬度增加的像素,dh為高度增加的像素,可為負數。
1.4 resizeTo(w, h),視窗寬度調為w像素,高度為h像素,不能負數。
1.5 open(URL, name, specs, replace),四個參數皆為optional,name可以為target屬性或式窗的名稱,如_blank, _self, _parent等,specs為特性字串,如height, width, menubar, resizable, scrollbar, toolbar等,replace為是否替代原視窗的bool值。
1.6 close(),關閉新開的視窗。
1.8 alert(), confirm(), prompt()
1.8 history.go(),  history.back(), history.forward()

2. document object:
2.1 write()

3. location object:
3.1 replace(URL),使用者無法back,會移除document history。
3.2 reload(bool),預設false,從暫存reload,反之從server。
3.3 href,導入新頁面。

4. navigator object:
4.1 userAgent,可獲取user agent字串。

5. screen object:
5.1 availHeight,視窗可使用的螢幕高度。
5.2 avaiWidth,視窗可使用的螢幕寬度。


參考資料:
http://www.w3schools.com/jsref/obj_window.asp

2014年3月27日 星期四

[ASP.NET] 套用MasterPage的Button權限控管

說明:有使用MasterPage,想根據用戶的權限代號(Authority)管控頁面上的新增/編輯/刪除等button,無權限則disable該button。


做法:在MasterPage的PreRender事件中使用ContentPlaceHolder控制項的findcontrol找到新增/編輯/刪除等button後,再分別disable該button。例:

//namespace
[Flags]
public enum Privilege
{
            None=0,
            View=1,
            Add=2,
            Edit=4,
            Remove=8,
            All = None|View|Add|Edit|Remove
}

//xxx.master.cs
protected override void OnPreRender(EventArgs e)
{
        try
        {
             Button btnAdd = (Button)ContentPlaceHolder1.FindControl("btnAdd");
             Button btnEdit = (Button)ContentPlaceHolder1.FindControl("btnEdit");
             Button btnDel = (Button)ContentPlaceHolder1.FindControl("btnDel");

             if (Authority == (int)Privilege.View)
             {
                 btnAdd.Disable = false;
                 btnEdit.Disable = false;
                 btnDel.Disable = false;
             }
             else if (Authority == (int)(Privilege.View | Privilege.Add))
             {
                 btnEdit.Disable = false;
                 btnDel.Disable = false;
             }
             ...以此類推
        }
        catch (Exception ex)
        {
            throw ex;
        }
        base.OnPreRender(e);
}


參考資料:

[C#] 判斷DataTable有無該欄位語法紀錄

說明:判斷DataTable有無該欄位。


語法:DataTable.Columns.Contains(欄位名稱);,例:
if (dtTemp.Columns.Contains("test")) {...}
esle {...}


參考資料:
http://www.programmer-club.com/showSameTitleN/csharp/2210.html

2014年3月26日 星期三

[T-SQL] 使用SSMS建立外來鍵(foreign key)

說明:使用SQL Server Management Studio建立外來鍵(FK),FK即關聯外部table的PK,以保持資料完整性。


作法:
1. 在物件總管中,在欲設定FK的table按右鍵->選擇[設計]。
2. 在欄位上按右鍵->選擇[關聯性]->點選[加入]。
3. 按一下[資料表和資料行規格]->再按右邊的省略符號 ([…])。
4. 在對話視窗中[主索引鍵]的下拉式清單中->選擇要關聯外部PK的table與欄位。
5. 對應右邊選擇要設定FK的table與欄位->按確定即可。


參考資料:
http://technet.microsoft.com/zh-tw/library/ms189049.aspx
http://msdn.microsoft.com/zh-tw/library/ms175464.aspx

2014年3月20日 星期四

[Subversion] 更新失敗:解壓縮時發生錯誤 ra_serf: An error occurred during decompression

說明:從subversion上更新資料時,發生更新失敗:ra_serf: An error occurred during decompression,使用collabnet subversion 1.8.8 on Windows 2008 R2 64bits。


解法:
Subversion Edge 4.x configures the server to use mod_deflate which improves performance. I cannot say what the problem is, you could try reporting it at users at subversion dot apache dot org. There are currently not any good ways to gather diagnostics out of the Serf library but if you can do a Wireshark there are people on the list that might be able to see something.

You can disable mod_deflate by renaming the file mod_deflate.so in the lib/modules folder of your server and stopping and starting the Subversion server via the Edge web UI. I would guess this will resolve the problem.



參考資料:
https://subversion.open.collab.net/ds/viewMessage.do?dsForumId=3&viewType=browseAll&dsMessageId=503878#messagefocus

[Subversion] 更新失敗:連線已被您主機上的軟體中止

說明:從subversion更新大量資料時,出現更新失敗:「連線已被您主機上的軟體中止」的訊息。使用collabnet subversion 1.8.8 on Windows 2008 R2 64bits。


解法:
1. 在subversion server上找到httpd.conf檔 (C:\Program Files\CollabNetEdge\data\conf)
2. 在裡面加上SVNAllowBulkUpdates Prefer,儲存後重新啟動subversion apache service即可.


參考資料:
https://groups.google.com/forum/#!topic/tortoisesvn-dev/idsTxNkMMsQ
http://subversion.apache.org/docs/release-notes/1.8.html#serf-skelta-default

2014年3月12日 星期三

[CSS] box-shadow使用記錄

說明:想將網頁刻出一塊對比的版面,使用CSS3的box-shadow。


語法:
box-shadow: x y blur spread color inset;
x: 陰影水平位移距離,必要值。
y: 陰影垂直位移句離,必要值。
blur: 模糊強度,預設為0,不能負值。
spread: 擴散強度,預設為0。
color: 陰影顏色。
inset: 內陰影。

例:
box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
搭配width: 來控制盒子寬度。
搭配margin: 控制盒子間隔。


參考資料:
http://boohover.pixnet.net/blog/post/35116159-%E9%99%B0%E5%BD%B1%E6%95%88%E6%9E%9C%E5%8F%8A%E5%85%89%E6%9A%88%E6%95%88%E6%9E%9C%E7%9A%84-box-shadow-(css-property)

2014年3月7日 星期五

[ASP.NET] 動態產生控制項TextBox、CalendarExtender與DropDownList並取值

說明:動態產生控制項TextBox、CalendarExtender與DropDownList並取值,其中產生控制項最好放在事件OnInit裡,可透過ViewState來更新控制項的屬性值。本例已有一列靜態控制項,並搭配HiddenField來紀錄資料列數。


語法:
//code behind
using AjaxControlToolkit;

protected void Page_Load(object sender, EventArgs e)
{
        if (IsPostBack)
        {
            int iNum = 0;
            if (!string.IsNullOrEmpty(hidNum.Value))
                iNum = int.Parse(hidNum.Value);
            AddRecord(iNum, false);
        }
}

protected void btnMore_Click(object sender, EventArgs e)
{
        int iNum = 0;
        if (!string.IsNullOrEmpty(hidNum.Value))
            iNum = int.Parse(hidNum.Value);
        iNum++;
        hidNum.Value = iNum.ToString();
        AddRecord(int.Parse(hidInvoiceNum.Value), true);
}

private void AddRecord(int iNum, bool blFlag)
{
        int iTemp = 1;
        if (blFlag) iTemp = iNum;
        for (int i=iTemp; i <= iNum; i++)
        {
            TableRow tr = new TableRow();

            TableCell tc1 = new TableCell();
            TextBox txtNo = new TextBox();
            txt.ID = "txtNo" + i;
            tc1.Controls.Add(txtNo);
            tr.Cells.Add(tc1);

            TableCell tc2 = new TableCell();
            TextBox txtDate = new TextBox();
            CalendarExtender ce = new CalendarExtender();
            txtDate.ID = "txtDate" + i;
            ce.TargetControlID = "txtDate" + i;
            ce.Format = "yyyy/MM/dd";
            this.PlaceHolder1.Controls.Add(ce);
            tc2.Controls.Add(txtDate);
            tr.Cells.Add(tc2);

            TableCell tc3 = new TableCell();
            DropDownList ddlType = new DropDownList();
            ddlType.ID = "ddlType" + i;
            ddlType.DataSource = datasource;
            ddlType.DataTextField = "Text";
            ddlType.DataValueField = "Value";
            ddlType.DataBind();
            tc3.Controls.Add(ddlType);
            tr.Cells.Add(tc3);

            //Add Server Control Table
            this.tbTest.Rows.Add(tr);
}

//取值
for (int i = 0; i <= int.Parse(hidNum.Value); i++)
{
        txtNo = (TextBox)tbTest.FindControl("txtNo" + i);
        txtDate = (TextBox)tbTest.FindControl("txtDate" + i);
        ddlType = (DropDownList)tbTest.FindControl("ddlType" + i);
}

[VB.NET] 三元運算子IIF

說明:
VB中的三元運算子該怎麼寫?C#為 value = condition ? first_expression : first_expression;


語法:
value = IIF (condition, first_expression, first_expression)


參考資料:
http://itgroup.blueshop.com.tw/shian/blog?n=convew&i=1770

[ASP.NET] 控制項tooltip與html title屬性文字斷行

說明:若使用html tag的title屬性,文字使用&#10;(ASCII的\n)或&#13;(ASCII的\r)來斷行,若用server control要做到同樣效果,如Panel的tooltip文字使用\n或\r或\r\n。

例:
//html title
<div id="pic" title="1. test1 &#10; 2. test2"></div>
//server control
this.Panel1.ToolTip = "1. test1 \n2. test2";


參考資料:
http://www.dotblogs.com.tw/aquarius6913/archive/2011/02/01/21179.aspx


2014年3月2日 星期日

[T-SQL] 調整維護計畫Log路徑 maintenance plan log file path

說明:常用維護計畫來設定執行資料庫的優化或備份作業,在新增維護計畫時,可設定「將報表寫入文字檔」,也就是寫log的路徑,一般皆預設在SQL Server目錄中的Log下,如果日後想調整,該怎麼改?


作法:
1. 打開SSMS->點開物件總管的維護計畫->在要修改的維護計畫名稱上->右鍵選修改->畫面上方找一個看起來像兩個報表的小圖示(在管理連線右邊)->點開即看到修改路徑。


參考資料:
http://www.sqlserver-dba.com/2012/07/sql-server-find-the-maintenance-plan-log-file-path.html
http://stackoverflow.com/questions/3290531/change-sql-server-maintenance-plan-report-location
http://ithelp.ithome.com.tw/question/10030033