目前分類:未分類文章 (11)

瀏覽方式: 標題列表 簡短摘要

一般點擊 Window的標題列,接著滑鼠移動,視窗自然而然就會跟著動,但是在 Window的 WindowStyle設為 None時,Window的標題列不見囉

這時該怎麼移動 Window呢?

作法是添加 MouseLeftButtonDown再加 MouseMove 這兩個事件去處理滑鼠移動數及改變 Window的 Top和 Left的值。

首先,先宣告一個全域 Point,程式碼如下:

private Point _startPoint;

在 Constructor或 Window_Load處添加 MouseButtonEventHandler和 MouseEventHandler,程式碼如下:

this.PreviewMouseLeftButtonDown += 
        new MouseButtonEventHandler(Window_PreviewMouseLeftButtonDown);
this.PreviewMouseMove += new MouseEventHandler(Window_PreviewMouseMove);

接著,實作 Window_PreviewMouseLeftButtonDown和 Window_PreviewMouseMove,程式碼如下:

private void Window_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
    _startPoint = e.GetPosition(null);
}

private void Window_PreviewMouseMove(object sender, MouseEventArgs e)
{
    if (e.LeftButton == MouseButtonState.Pressed)
    {
        Point position = e.GetPosition(null);
        Top += position.Y - _startPoint.Y;
        Left += position.X - _startPoint.X;
    }
}

 

以上的是拖移 Window的程式碼,那接下來是有關 Drag&Drop的東西

也就是你可以把元件A拖拉到元件B,正常來說這是禁止的,如何讓他可以啟用呢?

首先,你要先將元件A的 AllowDrop設為 True。

接下來的動作很像上面的程式碼,例如宣告一個全域 Point和在 Constructor或 Window_Load處添加 MouseButtonEventHandler和 MouseEventHandler,不過這次要指定這兩個事件是元件A的。

this.[元件A].PreviewMouseLeftButtonDown += 
        new MouseButtonEventHandler([元件A]_PreviewMouseLeftButtonDown);
this.[元件A].PreviewMouseMove += new MouseEventHandler([元件A]_PreviewMouseMove);

接著一樣,實作 [元件A]_PreviewMouseLeftButtonDown和 [元件A]_PreviewMouseMove,[元件A]_PreviewMouseLeftButtonDown的內容和上面的一樣,[元件A]_PreviewMouseMove就有點不同了,程式碼如下:

private void Window_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
    _startPoint = e.GetPosition(null);
}

private void Window_PreviewMouseMove(object sender, MouseEventArgs e)
{
        if (e.LeftButton == MouseButtonState.Pressed)
        {
                Point position = e.GetPosition(null);

                if (Math.Abs(position.X - _startPoint.X) > 
                                SystemParameters.MinimumHorizontalDragDistance ||
                        Math.Abs(position.Y - _startPoint.Y) > 
                                SystemParameters.MinimumVerticalDragDistance)
                {
                        DataObject data = new DataObject(System.Windows.DataFormats.Text.ToString(), 
                                "Drag&Drop");
                        DragDropEffects de = DragDrop.DoDragDrop([元件A], data, DragDropEffects.Move);
                }
        } 
}

DataObject 就是拖拉到元件B時,元件B獲得的東西,在此宣告為字串 "Drag&Drop"

參考至 http://blogs.msdn.com/b/jaimer/archive/2007/07/12/drag-drop-in-wpf-explained-end-to-end.aspx

膩撐 發表在 痞客邦 留言(1) 人氣()

於WPF視窗程式內加入報表(ReportViewer),再將資料庫的資料輸出成報表顯示出來

膩撐 發表在 痞客邦 留言(0) 人氣()

reference: http://www.linuxtopia.org/online_books/centos_linux_guides/centos_linux_step_by_step_guide/s1-q-and-a-root-passwd.html

Forgotten root Password

  1. At the boot loader menu, use the arrow keys to highlight the installation you want to edit and type [A] to enter into append mode.

  2. You are presented with a prompt that looks similar to the following:

    grub append> ro root=LABEL=/
    
  3. Press the Spacebar once to add a blank space, then add the word single to tell GRUB to boot into single-user Linux mode. The result should look like the following:

    ro root=LABEL=/ single
    
  4. Press [Enter] and GRUB will boot single-user Linux mode. After it finishes loading, you will be presented with a shell prompt similar to the following:

    sh-2.05b#
    
  5. You can now change the root password by typing

    passwd root
    

    You will be asked to re-type the password for verification. Once you are finished, the password will be changed. You can then reboot by typing reboot at the prompt; then you can log in to root as you normally would.

膩撐 發表在 痞客邦 留言(0) 人氣()

load() Function for PHP - Fetch URL Content

reference: http://www.bin-co.com/php/scripts/load/

* usage:

RETURN = load(URL, OPTIONS);

RETURN: (Array, String)

if ($options['return_info'] == true)

RETURN_TYPE is Array[Header, Body, Info]

else

RETURN_TYPE is String[Body]

URL: (String)

example: normal url or uri

OPTION: (Array)

is like $default_options

* default options:

$default_options = array(
        
'method'        => 'get',
        
'post_data'        => false,
        
'return_info'    => false,
        
'return_body'    => true,
        
'cache'            => false,
        
'referer'        => '',
        
'headers'        => array(),
        
'session'        => false,
        
'session_close'    => false,
    );

* examples:

1st:

$contents = load('http://example.com/rss.xml');

2nd:

$options = array(
    'return_info'   => true,
    'method'                => 'post'
);
$result = load('http://www.bin-co.com/rss.xml.php?section=2',$options);
print_r($result);

The output will be like this...

Array
(
    [headers] => Array
        (
            [Date] => Mon, 18 Jun 2007 13:56:22 GMT
            [Server] => Apache/2.0.54 (Unix) PHP/4.4.7 mod_ssl/2.0.54 OpenSSL/0.9.7e mod_fastcgi/2.4.2 DAV/2 SVN/1.4.2
            [X-Powered-By] => PHP/5.2.2
            [Expires] => Thu, 19 Nov 1981 08:52:00 GMT
            [Cache-Control] => no-store, no-cache, must-revalidate, post-check=0, pre-check=0
            [Pragma] => no-cache
            [Set-Cookie] => PHPSESSID=85g9n1i320ao08kp5tmmneohm1; path=/
            [Last-Modified] => Tue, 30 Nov 1999 00:00:00 GMT
            [Vary] => Accept-Encoding
            [Transfer-Encoding] => chunked
            [Content-Type] => text/xml
        )
    [body] => ... Contents of the Page ...
    [info] => Array
        (
            [url] => http://www.bin-co.com/rss.xml.php?section=2
            [content_type] => text/xml
            [http_code] => 200
            [header_size] => 501
            [request_size] => 146
            [filetime] => -1
            [ssl_verify_result] => 0
            [redirect_count] => 0
            [total_time] => 1.113792
            [namelookup_time] => 0.180019
            [connect_time] => 0.467973
            [pretransfer_time] => 0.468035
            [size_upload] => 0
            [size_download] => 2274
            [speed_download] => 2041
            [speed_upload] => 0
            [download_content_length] => 0
            [upload_content_length] => 0
            [starttransfer_time] => 0.826031
            [redirect_time] => 0
        )
)

* Code:

please visite http://www.bin-co.com/php/scripts/load/

comment(hidden)

膩撐 發表在 痞客邦 留言(0) 人氣()

reference:http://www.codingforums.com/showthread.php?t=20922

http://ant4js.blogspot.com/2008/12/function.html

function dispatcher()

{

switch(arguments.length)

{

case 1:real1(arguments[0]);break;

case 2:real2(arguments[0],arguments[1]);break;

case 3:real3(arguments[0],arguments[1],arguments[2]);break;

}

}

 

function real3(a,b,c)

{

alert(a+'-'+b+'-'+c);

}

 

function real2(a,b)

{

alert(a+'-'+b);

 

}

<button  onClick="dispatcher('a','b')">Test</button>
<button  onClick="dispatcher('a')">Test</button>
<button  onClick="dispatcher('a','b','c')">Test</button>

膩撐 發表在 痞客邦 留言(0) 人氣()

螞蟻的 JAVASCRIPT

http://ant4js.blogspot.com/

W3schools 各式各樣教學網站 (網路上有山寨中文版,請自行蒐尋)

http://www.w3schools.com/js/default.asp

Simplify Ajax development with jQuery (IBM網站其中一篇)

  http://www.ibm.com/developerworks/library/x-ajaxjquery.html

 

膩撐 發表在 痞客邦 留言(0) 人氣()

javascript:

String to JSON/MAP (reference:http://jessewth.blogspot.com/2008/10/javascript-string-to-json.html)

string myJSONText = "{ /"name/", /"jessewang/", /"age/", /"18/"}";
var myObject = eval('(' + myJSONtext + ')');

JSON/MAP to URI (reference:http://api.jquery.com/jQuery.param/)

$.param();

 

膩撐 發表在 痞客邦 留言(0) 人氣()

隨意寫了一個跟jquery及javascript有關的網頁程式碼

他是一個模擬表單發送及獲取回傳結果的程式

例如:

google.com搜尋引擎

我們可以直接從網址打上參數進行搜尋,

http://www.google.com.tw/search?q=欲搜尋文字

 

於是乎製作了一個網頁,讓使用者可以在網頁上輸入目的網址(ex:http://www.google.com.tw/search)以及參數項目(q=xxxxx),

有些網頁要求的不只一個參數,所以使用者可以動態的增加/減少參數項目,

最後把回傳內容顯示出來。

程式:

由於程式碼中有用到jquery,所以要先加入jquery的library

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>

先看html的部分,

<span onclick="javascript:form_send();">Submit</span> <span id="detials"></span><br />
  <div id="form-header">
  <input type="text" id="form_action" size="70" title="please input action uri" />
  <select id="form_method">
<option value="0">POST</option>
<option value="1">GET</option>
  </select>
  <select id="data_type">
<option value="0">HTML</option>
<option value="1">TEXT</option>
<option value="2">SCRIPT</option>
<option value="3">JSON</option>
<option value="4">XML</option>
<option value="5">JSONP</option>
  </select>
  </div>
  <span onclick="javascript:form_item();">add</span><br />
  <div id="form-items"></div>
  <div id="results"></div>

接著css的部分,

<style>
.btn {cursor: pointer; color: blue; padding: 2px; margin: 2px;}
.btn:hover {color: white; background: black;}
#detials {color: gray; font-size: 13px;}
</style>

最後是javascript的部分,(10 functions)

    <script>

/***
* 待解決跨網域讀取出現錯誤的問題 ajax
*/
//main attibutes
var form_items, exist_items, form_dels;
var dataTypes = new Array("html", "text", "script", "json", "xml", "jsonp");
//initialize
function init() {
form_items = 0;
exist_items = 0;
form_dels = null;
form_dels = new Array();
}
//call form_item$()
function form_item() {
switch(arguments.length) {
case 1:
form_item2(arguments[0]);
break;
default:
form_item1();
}
}
//add form item function
function form_item1() {
exist_items++;
form_items++;
item_generate(form_items);
show_detial();
}
//delete form item function
function form_item2(item_id) {
exist_items--;
form_dels.push(item_id);
var del_id = '#form-item-' + item_id;
$(del_id).remove();
show_detial();
}
//generate form and get result
function form_send() {
//msg attibutes
var msg_err = "Sorry but there was an error: ";


//codes
// no items
if(exist_items < 1) {
alert('Sorry, there\'s no items.');
return -1;
}
// has items
var resultHeader = "<hr /><span onclick=\"javascript:clearResult();\" class=\"btn\" style=\"float:right;\">Clear</span>";
var form_action_val = $('#form_action').val();
var maps = eval('(' + maps_generate() + ')');
var method = ($('#form_method').val() == '0')? 'POST' : 'GET';
var datatype = $('#data_type').val();
$.ajax({
type: method,
url: form_action_val,
dataType: dataTypes[datatype],
data: $.param(maps),
success: function(response) {
$('#results').html(resultHeader + "<div>" + response + "</div>");
},
error: function(response) {
alert(response);
}
});
/**
$('#results').load(form_action_val, maps, function(response, response_status, xhr) {
if(response_status == "error") {
$(this).html(msg_err + xhr.status + " " + xhr.statusText);
} else {
$(this).html("<hr />" + response);
}
});
*/
}
function clearResult() {
$('#results > div').remove();
}
//generate vars
function maps_generate() {
var codes = "{ ";
var i;
for (i=0; i<exist_items; i++) {
if(search_dels_array(i, form_dels) < 0) {
codes += "'"+$('#form-item-'+i+'_name').val()+"': '"+$('#form-item-'+i+'_value').val()+"'";
}
if((i+1) < exist_items)
codes += ", ";
}
codes += " }";
return codes;
}
//search deleted array
function search_dels_array(item_id, array) {
var dels_len = array.length;
var k;
if(dels_len == 0)
return -1;
for (k=0; k<dels_len; k++) {
if(item_id == form_dels[k]) {
array.shift();
return 1;
}
}
return -1;
}
//generate form item
function item_generate(item_id) {
//items html attibutes
var div_id = "form-item-"+item_id;
var name_id = "form-item-"+item_id+"_name";
var name_class = "form-item_name";
var name_size = "20";
var name_title = "please input item name";
var value_id = "form-item-"+item_id+"_value";
var value_class = "form-item_value";
var value_size = "50";
var value_title = "please input item value";
var btn_click_func = "form_item("+item_id+")";
var btn_onclick="javascript:"+btn_click_func+";";
var btn_class = "btn";
var btn_val = "delete";
//generated code
var codes = "<div id=\""+div_id+"\">\n\t<input type=\"text\" id=\""+name_id+"\" class=\""+name_class+"\" size=\""+name_size+"\" title=\""+name_title+"\" />\n\t<input type=\"text\" id=\""+value_id+"\" class=\""+value_class+"\" size=\""+value_size+"\" title=\""+value_title+"\" />\n\t<span onclick=\""+btn_onclick+"\" class=\""+btn_class+"\">"+btn_val+"</span> item "+(item_id+1)+"</div>";
$('#form-items').append(codes);
}
//show detial about 'how many added or exist items?' or 'who's be deleted?'...
function show_detial() {
form_dels.sort();
$('#detials').html('added <b>'+(form_items+1)+'</b> items; be deleted array: <b>'+form_dels.toString()+'</b>; exist <b>'+exist_items+'</b> items');
}
$(document).ready(function() {
//TO DO
init();
exist_items++;
item_generate(form_items);
show_detial();
});
  </script>

膩撐 發表在 痞客邦 留言(0) 人氣()

As title.

[color]

blue: shell bash instruction

green: instruction's parameters

gray: required value

purple: custom value

my steps:

1. download phpmyadmin-3.3.8.1-all-languages.tar.gz

wget http://downloads.sourceforge.net/project/phpmyadmin/phpMyAdmin/3.3.8.1/phpMyAdmin-3.3.8.1-all-languages.tar.gz?r=http%3A%2F%2Fwww.phpmyadmin.net%2Fhome_page%2Fdownloads.php&ts=1291266404&use_mirror=nchc

2. uncompress phpmyadmin-3.3.8.1-all-languages.tar.gz

> tar zxf phpmyadmin-3.3.8.1-all-languages.tar.gz

3. (not requirment) copy phpMyAdmin-3.3.8.1-all-languages to another place

 

> cp -r phpMyAdmin-3.3.8.1-all-languages/* /var/www/phpmyadmin

4. (not requirment) edit httpd configure or .htaccess

> vim /etc/httpd/conf/httpd.conf

at the bottom, add the following:

> alias /phpmyadmin '/var/www/phpmyadmin'

5. copy config.sample.inc.php to config.inc.php

> cd /var/www/phpmyadmin

> cp config.sample.inc.php config.inc.php

6. edit config.inc.php

reference: http://goo.gl/SDSgf

> vim config.inc.php

find $cfg['blowfish_secret'] = ''; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */, and modify it

> $cfg['blowfish_secret'] = 'mycustomvalue';

find /* Advanced phpMyAdmin features */, and uncomment the following:

$cfg['Servers'][$i]['pmadb'] = 'phpmyadmin';
> $cfg['Servers'][$i]['bookmarktable'] = 'pma_bookmark';
> $cfg['Servers'][$i]['relation'] = 'pma_relation';
> $cfg['Servers'][$i]['table_info'] = 'pma_table_info';
> $cfg['Servers'][$i]['table_coords'] = 'pma_table_coords';
> $cfg['Servers'][$i]['pdf_pages'] = 'pma_pdf_pages';
> $cfg['Servers'][$i]['column_info'] = 'pma_column_info';
> $cfg['Servers'][$i]['history'] = 'pma_history';
> $cfg['Servers'][$i]['tracking'] = 'pma_tracking';
> $cfg['Servers'][$i]['designer_coords'] = 'pma_designer_coords';

7. import phpmyadmin database

reference: http://myandroid.tw/topic-274-0.htm

> mysql -u root -p your-root-password < /var/www/phpmyadmin/scripts/create_tables.sql 

8. finish~~php requirment: php-mcrypt

 

Requirement PHP Modules: php-mysql, php-mcrypt, php-mbstring

膩撐 發表在 痞客邦 留言(0) 人氣()

Requirement files:

dotProject 2.1.3 http://ge.tt/66hA5oo (updated:12/2, 30days)

 

install steps:

1. download dotproject

> wget http://ge.tt/66hA5oo

2. uncompress dotproject file

> tar zxf  dotproject_2_1_3_cht.tar

3. (Not Requirement) copy dotproject to another place, and modify httpd.conf

> cp -r dotproject_2_1_3_cht/* /var/www/dotproject/

> vim /etc/httpd/conf/httpd.conf

at the bottom, add the following:

> alias /dotproject '/var/www/dotproject/'

4. open browser and go to http://localhost/dotproject

5. click Next

6. check for Requirements, Database Connectors, Directory and File Permissions, PHP Settings

Requirements:

If something is error, use 'yum -y install' to resolve. (ex: php-gd)

Database Connectors:

Just check Mysql Support, if not, please install mysql and start mysqld!!

Directory and File Permissions:

cp /var/www/dotproject/include/config-dist.php /var/www/dotproject/include/config.php

> chmod 766 /var/www/dotproject/include/config.php

chmod 777 /var/www/dotproject/files

chmod 777 /var/www/dotproject/files/temp

chmod 777 /var/www/dotproject/locales/en

> chmod 777 /var/www/dotproject/locales/zh-TW

  PHP Settings:

vim /etc/php.ini

7. create a mysql-user and a database, and install

8. install finish, go to administrator panel, (id: admin, pw: passwd)

9. (Not Requirement) go to 'Default User Preferences', and set 'Locale: Traditional Chinese (Taiwan)'

10. finish~~

膩撐 發表在 痞客邦 留言(0) 人氣()

skip installed steps...

[change YUM's mirror to 義守's ftp]

reference: http://apt.nc.hcc.edu.tw/web/student_server_centos/student_server_centos.html#update

steps:

> cd /etc/yum.repos.d/

> cp CentOS-Base.repo CentOS-Base.repo.bak

> vim CentOS-Base.repo

 

 comment CentOS-Base.repo 裡 [base],[update],[addons],[extras],...等中的mirrorlist,

 uncomment baseurl,

    並改變

 baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/

    為 

 baseurl=http://ftp.cse.yzu.edu.tw/pub/CentOS/$releasever/updates/$basearch/

 

[update PHP 5.1 to the latest version]

reference: http://centos.blog.oni.tw/2010/05/centos54yum.html

steps:

> cd /etc/yum.repos.d/

> cp CentOS-Base.repo CentOS-Base.repo.bak

> vim CentOS-Base.repo

 

在CentOS-Base.repo 最底部空白處填入以下:

 [c5-testing]

 name=CentOS-5 Testing

 baseurl=http://dev.centos.org/centos/$releasever/testing/$basearch/

 enabled=0

 gpgcheck=1

 gpgkey=http://dev.centos.org/centos/RPM-GPG-KEY-CentOS-testing

更新 php

> yum --disablerepo=\* --enablerepo=c5-testing install php

更新 php-mcrypt

> yum --disablerepo=\* --enablerepo=c5-testing install php-mcrypt

 

[setup Mysql Admin's password first]

reference: http://www.ubuntu-tw.org/modules/newbb/viewtopic.php?topic_id=1875

mysqladmin -u root password your-new-password

 

[servers start/restart/stop]

$1: your server (ex: httpd, mysqld, vsftpd, ..., etc)

Server Start:

/etc/init.d/$1 start

Server Restart:

/etc/init.d/$1 restart

Server Stop:

/etc/init.d/$1 stop

膩撐 發表在 痞客邦 留言(0) 人氣()