2015年10月19日 星期一

wine windows program loader 介紹


Wine的使用方法

執行Windows程式

安裝完Wine之後,Windows的執行檔應該就自動與Wine(Wine Windows Program Loader)
自動進行關聯了,因此只要直接在檔案瀏覽器開啟副檔名為「EXE」的檔案即可執行Windows程式。
Wine在執行Windows程式時可能會告知缺了什麼套件需要安裝,就讓它安裝吧!

Wine 路徑

在Wine的環境中,也是有「C槽」(C:)這樣的東西,它的實體路徑就在「~/.wine/dosdevices/c:」下,在這個目錄可以找到安裝軟體時通常會放置的「Program Files」目錄,以及系統檔案使用的「Windows」目錄。


Wine 移除程式

使用Wine來安裝Windows程式很簡單,但是安裝完要如何移除呢?只要輸入以下指令,就可以開啟Wine的「新增/移除程式」。

wine uninstaller

2015年10月8日 星期四

Trigger

Mysql 的 Trigger 觸發

trigger_name 觸發名稱
                     隨個人喜好命名

trigger_time 觸發時間 
                     只有 BEFORE 和AFTER兩種
                     BEFORE 是在進行trigger_event 之前
                     AFTER 在進行trigger_event 之後觸發

trigger_event 觸發事件
                     有 INSERT、DELETE、UPDATE 三種


以下有幾個注意點:

    1. INSERT INTO .. ON DUPLICATE UPDATE 
                     這語法造成的觸發行為由最後是 INSERT 或是 UPDATE 來決定
    2. 同一個 trigger_time +trigger_event  組合不得重覆。
    3. INSERT、LOAD DATA和REPLACE 都會觸發 INSERT event
        DELETE和REPLACE 都會觸發 DELETE。


trigger_stmt 是當觸發時要執行的語句。
如果您打算執行多個語句,可使用BEGIN ... END復合語句結構。
以下是範例(直接在Mysql console下指令,不要phpMyAdmin下操作):

DROP PROCEDURE IF EXISTS update_testTable ;

delimiter //
CREATE PROCEDURE update_testTable ( IN id varchar(32)) 
BEGIN 

   DELETE c
   FROM a
   WHERE a.id = id ;

   INSERT INTO a (  id )
                    value ( id ) ;

END //
delimiter ;  
delimiter //

DROP TRIGGER IF EXISTS trigger_INSERT_testTable ;

CREATE TRIGGER trigger_INSERT_testTable
AFTER INSERT ON testTable
FOR EACH ROW  
        BEGIN  
            CALL update_testTable (NEW.id
END //
delimiter ;   
delimiter //

DROP TRIGGER IF EXISTS trigger_UPDATE_testTable ;

CREATE TRIGGER trigger_UPDATE_testTable
AFTER INSERT ON testTable
FOR EACH ROW  
        BEGIN  
            CALL update_testTable (NEW.id
END //
delimiter ;   
delimiter //

DROP TRIGGER IF EXISTS trigger_DELETE_testTable ;

CREATE TRIGGER trigger_DELETE_testTable
AFTER INSERT ON testTable
FOR EACH ROW  
        BEGIN  
            CALL update_testTable (OLD.id
END //
delimiter ; 
delimiter //



查看trigger 內容
mysql> show triggers;


刪除trigger 
mysql> drop TRIGGER trigger_name;

2015年9月22日 星期二

Javascript刷新頁面的幾種方法

Javascript刷新頁面的幾種方法:


1   history.go(0) 
2   location.reload() 
3   location=location 
4   location.assign(location) 
5   document.execCommand('Refresh') 
6   window.navigate(location) 
7   location.replace(location) 
8   document.URL=location.href



頁面自動刷新:把如下代碼加入<head>區域中



<meta http-equiv="refresh" content="20">
其中20指每隔20秒刷新一次頁面.

<meta http-equiv="refresh" content="20;url=http://www.wyxg.com">
其中20指隔20秒後跳轉到http://www.wyxg.com頁面



<script language="JavaScript">

        function myrefresh()
        {
                window.location.reload();
        }
         setTimeout('myrefresh()',1000); //指定1秒刷新一次
</script>



如果想關閉窗口時刷新或者想開窗時刷新的話,在<body>中調用以下語句即可。



<body onload="opener.location.reload()"> 開窗時刷新
<body onUnload="opener.location.reload()"> 關閉時刷新

<script language="javascript">
        window.opener.document.location.reload()
</script>


2015年9月21日 星期一


自己在開發的時候, 常用到的指令筆記


條件判斷


-- 判斷變數是否被定義

{% if var is not defined %}
      變數不存在
{% else %}
      變數存在
{% endif %}

jQuery UI Sortable 拖曳更改順序並記錄



原文出處:
http://elliotttravel.blogspot.tw/2015/01/jquery-ui-sortable.html




jQuery UI有個很好用的功能,可以使用拖曳的方式,直接調整畫面的順序,請見jQuery UI官網 jqueryui.com

但拖曳完後,要怎麼把排列順序存入後端呢?

資料庫設計了CategoryId、CategoryName、CategoryOrder三個欄位(CategoryOrder記錄順序)

首先先處理html的部份

1. 先加入jvavscript (因為套bootstrap畫面較好看,所以順便加入)
<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<script src="~/Scripts/jquery-ui-1.11.2.min.js"></script>
<script src="~/Scripts/bootstrap.min.js"></script>

2. 加入css (可省略,只是為了加入bootstrap畫面較好看)
<link href="~/Content/bootstrap.min.css" rel="stylesheet" type="text/css" />

3. 設計表格,Sortable 也可支援<ul></ul>不一定要使用table
<table id="mytable" class="table">
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.CategoryName)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.CategoryOrder)
        </th>
        <th></th>
    </tr>
    <tbody id="myfruit">
        @foreach (var item in Model.OrderBy(r => r.CategoryOrder))
        {
            <tr id="@Html.DisplayFor(modelItem => item.CategoryOrder)">
                <td>
                    @Html.DisplayFor(modelItem => item.CategoryName)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.CategoryOrder)
                </td>
                <td>
                    @Html.ActionLink("Edit", "Edit", new { id = item.CategoryId }) |
                    @Html.ActionLink("Details", "Details", new { id = item.CategoryId }) |
                    @Html.ActionLink("Delete", "Delete", new { id = item.CategoryId })
                </td>
            </tr>
        }
    </tbody>
</table>

4.套入jQuery UI Sortable效果,在update裡使用$(this).sortable('toArray').toString();將表格裡的<tr id="@Html.DisplayFor(modelItem => item.CategoryOrder)">串成字串,但此方法只能將id轉成字串,較好的方法應該是取td裡的CategoryOrder欄位,但sortable好像沒辦法直接取到,可能要用jquery想辦法去取…就沒有做測試了

最後將組好的字串傳到後端處理,存進資料庫就大功告成囉~~
另外,因為沒有使用Angular或Knockout來做Data binding,而且傳到後端的是取tr的id…所以每次必需Reload畫面,讓id更新才行,較好的方法應該是使用Data binding,讓畫面上的CategoryOrder會即時更改,並取出傳至後端,就不需要每次重load了。

$(function () {
    $('#mytable tbody').sortable({
        opacity: 0.6,
        cursor: 'move',
        axis: 'y',
        update: function (event, ui) {
            var productOrder = $(this).sortable('toArray').toString();
            $.ajax({
                type: 'post',
                url: '/Home/DragItem',
                data: {
                    orders: productOrder
                },
                success: function (result) {
                    window.location.href = result.redirectToUrl;
                }
            });
        }
    });
});
-------------------------2015.01.17更新------------------------------------------------

更新jQuery UI Sortable取得oldIndex和newIndex的方法,只需要傳兩個值到後端,就能夠偵對order進行排序,無需傳入一整個list囉。
$('#grid tbody').sortable({
        opacity: 0.6,
        cursor: 'move',
        axis: 'y',
        start: function (event, ui) {
            var start_pos = ui.item.index();
            ui.item.data('start_pos', start_pos);
        },
        update: function (event, ui) {
            //var productOrder = $(this).sortable('toArray').toString();
            var oldIndex = ui.item.data('start_pos');
            var newIndex = ui.item.context.rowIndex;
            $.ajax({
                type: 'post',
                url: '/PeopleGroups/DropOrderItem',
                data: {
                    oldIndex: oldIndex + 1,
                    newIndex: newIndex + 1,
                    page: currPage,
                    pageSize: pageSize
                }
            });
        }
    });


1. start,當拖曳動作開始,就會先執行這一段,這使用ui.item.index(),就可以取得目前使用者拖曳的item的index,在用ui.item.data('start_pos', start_pos),把index填進此item的'start_pos'(這個名字可以自訂),tag中,產生出來的html會變成 <tr start_pos = "index"></tr>

2. 在update時,就可以使用ui.item.data('start_pos'),將剛才存下來的index取出來,在使用ui.item.context.rowIndex取得最新的index,將這兩個index傳到後端就大空告成了!!

3.  順便附上後端的c# code供大家參考

if (oldIndex < newIndex)
            {
                var currGroup = ESHCloudsContext.PeopleGroups.SingleOrDefault(r => r.GroupOrder == oldIndex);
                if (currGroup == null)
                    return false;

                var peopleGroupList = ESHCloudsContext.PeopleGroups
                    .Where(r =>
                        r.GroupOrder <= newIndex &&
                        r.GroupOrder > oldIndex &&
                        r.GroupID != currGroup.GroupID
                    ).ToList();

                foreach (var peopleGroup in peopleGroupList)
                    peopleGroup.GroupOrder--;

                currGroup.GroupOrder = newIndex;
                ESHCloudsContext.SaveChanges();
            }
            else
            {
                var currGroup = ESHCloudsContext.PeopleGroups.SingleOrDefault(r => r.GroupOrder == oldIndex);
                if (currGroup == null)
                    return false;

                var peopleGroupList = ESHCloudsContext.PeopleGroups
                    .Where(r =>
                        r.GroupOrder < oldIndex &&
                        r.GroupOrder >= newIndex &&
                        r.GroupID != currGroup.GroupID
                    ).ToList();

                foreach (var peopleGroup in peopleGroupList)
                    peopleGroup.GroupOrder++;

                currGroup.GroupOrder = newIndex;
                ESHCloudsContext.SaveChanges();
            }


比上次的方法容易且合理多了,如果grid有設定分頁的話,別忘了把page和pagesize也傳到後端進行判斷囉!!

2015年9月10日 星期四

60+ FREE JQUERY IMAGE SLIDER & SLIDESHOW PLUGINS




來源網站

內容簡述:


60+ FREE JQUERY IMAGE SLIDER & SLIDESHOW PLUGINS


The best free responsive jQuery image slider and slideshow plugins and tutorials are necessary for web designer and giving them the opportunity to create creative slider effects of each slide transition.

免費樣板

http://bootsnipp.com/
http://formvalidation.io/examples/
http://startbootstrap.com/
http://codepen.io/