Thursday, September 25, 2008

Resize and DataGridView

VS 2005
.NET 2.0

Resize control : Anchor

DataGridView can not automatically sort if the datasource from Arraylist even bounded the DataPropertyName. But can change the arraylist to datatable, but need to do manually.

Dim propertyList As ArrayList = propertyController.getPMPropertyList()
Dim dt As New DataTable

dt.Columns.Add("pid")
dt.Columns.Add("ptype")
dt.Columns.Add("street")
dt.Columns.Add("suburb")
dt.Columns.Add("state")
dt.Columns.Add("available")
dt.Columns.Add("rent")
dt.Columns.Add("oid")
dt.Columns.Add("pmid")
dt.Columns.Add("tid")
For Each objProperty As PropertyClass In propertyList
dt.Rows.Add(New Object() {objProperty.pid, objProperty.ptype, objProperty.street, objProperty.suburb, objProperty.state, objProperty.available, objProperty.rent, objProperty.oid, objProperty.pmid, objProperty.tid})
Next
Me.dgvProperty.DataSource = dt

Friday, September 19, 2008

Bluetooth in window sp 2, 3 and vista

如果想用bluetooth on pc to transfer files, window sp2 已經有driver for bluetooth and able to transfer files, 但係大部份 bluetooth device (speaker, headphone) 都必須要夾埋service in order to make it work. 但對於舊既 bluetooth usb (即係 window sp1 既時候), 通常附送既CD 雖然有driver and utility, 但係window sp2裝到, 用唔到, 裝完My Bluetooth Place but 找不到 bluetooth 裝置.

Reason: I think it is because window knows the device and use window's diver. and the my bluetooth place can't detect it.

Solution: download other utility and driver, because of my level one bluetooth usb, i find one latest in level1.com but actually made by Toshiba. seems 30 days......><.... can run in vista.

http://download.level1.com/level1/driver/ToshibaBTS(5.10.02)_2007-03-01.zip

Tuesday, August 19, 2008

JScreenFix

from http://avbcd.blogspot.com/ 三章

今次介紹這個不是什麼圖像軟件,JScreenFix 是一個web 2.0(在線)修理LCD光點或死點的軟件;它透過一連串在瀏覽器上以快速、重覆及共振活動,達至激活LCD上的晶體,從而把死點、光點復活過來。
當然它不能保證100%修理好,但對付輕微或初期的光點、死點症狀,甚為有效。
由於它免費而且不需要安裝,如果你有LCD出現光點或死點打算丟棄或修理,不妨花20分鐘來試一試,或者會有意想不到的收獲。
JScreenFix - Fix stuck pixels

另外,JScreenFix還有deluxe版本,供Plasma電視使用。除了修理能光點、死點外,還可以修復鬼影(Screen burn-in)問題。不過deluxe版本需要收費。

Sunday, August 17, 2008

Firefox 突然唔 save cookies?

Suddenly, all cookies can't store in firefox, login and save info in google and yahoo 之後重開又要 login過, 試過晒 remove cookies, clear data, 都係咁.

隔左好耐終於忍唔住上網查下咩事...

http://support.mozilla.com/tiki-view_forum_thread.php?locale=en-US&forumId=1&comments_parentId=97006#threadId97036

Q and cor-el post 左解決方法:
1. 關閉所有firefox
2. 開始->執行->enter
%APPDATA%
3. 入去 Mozilla\Firefox\Profiles\xxxxx.default
4. 入面有個cookies.sqlite, 將佢改名 cookies.sqlite.old
5. 重新開過firefox 就ok.


問題應該係因為cookies file入面有d野撞左...所以要連file initial part 再create...
好彩firefox 識自動重新 create the cookies file

Saturday, August 9, 2008

xoops,可以登入,但馬上又登出

個人架設的xoops網站近日發生問題,可以登入,但馬上又登出,無法進入管理介面,本以為死了,要重新再來,資料又很多,真慘!在拜過google大神,得到解答,真是有求必應。把文章貼上供大家參考。
參考網址:http://forum.tpc.edu.tw/ShowPost.aspx?PostID=4431

[xoops]xoops_session table毀損記
今早,家裡瞬間停電(我的電腦因當機強迫關機), 我的主機重開機後,fsck自動將一些錯誤修正,但是我的網站卻有不正常的現象,一直無法Post、Edit...看一些內容文章等...因為經歷上次老 婆的網站差點毀掉的教訓後,寫了網站自動備份的Script(還是備份在本機上),但是這次的現象不太像資料毀壞,因此決定採細部修復而不採備份回復的方 式(最近備份日期是2005/05/01,回復後會有資料遺失的風險)。
於是開始trace那裡出問題:
首先,因為發現以 Anonymous的身份,newbb內的文章可以讀,以註冊身份登入(要清除cookie方能再登入,而且要勾選自動登入才行),初步懷疑前些日子使用 的自動登入hack出問題,備份回未改前的狀態後,情況依舊,於是再改回,據此判斷應為mysql中的xoops的資料表出問題。
於是用mysqldump將xoops資料dump出來,出現了一個訊息:
引文:

....Can't open file: 'xoops_session.MYD'. (errno: 145).

所以應該是xoops_session這個table因瞬間停電造成毀損。 
於是用phpmyadmin將xoops_session這個table刪除,再將之前備份的xoops.sql中擷取xoops_session段重新建立:
xoops_session.sql
引文:

CREATE TABLE xoops_session (
sess_id varchar(32) NOT NULL default '',
sess_updated int(10) unsigned NOT NULL default '0',
sess_ip varchar(15) NOT NULL default '',
sess_data text NOT NULL,
PRIMARY KEY (sess_id),
KEY updated (sess_updated)
) TYPE=MyISAM;

Tuesday, August 5, 2008

EasyPHP - access phpMyAdmin and MySql from outside

33. How to have access to phpMyAdmin from my local network or Internet ?
  • In phpMyAdmin's configuration file (config.inc.php), set
    $cfgPmaAbsoluteUri = "http://$_SERVER[HTTP_HOST]:$_SERVER[SERVER_PORT]/mysql/";
  • Search for phpMyAdmin in Apache's configuration file. In Directory, add IP adresses of the computers you want to give the right to use phpMyAdmin. For example:
    Allow from 192.168.69.1


43. How to connect to MySql from the outside
Edit the configuration file from MySql and comment the following ligne:
bind-address=127.0.0.1


from: http://www.easyphp.org/faq.php

Friday, July 25, 2008

ExecuteNonQuery 傳回值

ExecuteNonQuery 方法不會返回任何 data record row, 它只會返回整數值, 來表示成功或受影響的data row 數目.

If use ExecuteNonQuery to create or modify database structure, eg. create table, this method returns -1 if success, returns 0 if fail.

If use ExecuteNonQuery to INSERT, UPDATE, DELETE, this method returns the Number of affected data row, but if fail, it returns 0.

Wednesday, June 4, 2008

Concurrency violation: the UpdateCommand affected 0 of the expected 1 records

使用ado.net使資料更新時.常常會發生
Concurrency violation: the UpdateCommand affected 0 of the expected 1 records
並行違規: UpdateCommand 已經影響必須是 1 記錄的 0.

解決的方式為
當使用TableAdapter Configuration Wizard定義時,選Advanced Options,把Use Optimistic concurrency選項去除,讓產生的update,delete語法只使用key值比對即可解決

而此訊息說真的蠻困擾的,有時是不定時發生 :(

可以參考說明 http://msdn2.microsoft.com/en-us/library/aa0416cz(VS.80).aspx

Wednesday, April 23, 2008

EasyPHP IP problem

在剛安裝完成 EasyPHP1.8時.. 請進安裝目錄下的Apache Folder 中找 httpd.conf <--- 這個檔案, 其中有一段如下:


# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, in addition to the default. See also the
# directive.
#
#Listen 3000
#Listen 12.34.56.78:80
Listen 127.0.0.1:80 <-- 改成 Listen:80 (把127.0.0.1拿掉)
存檔重新Restart your EasyPHP 就可以了...


因為這裡的設定已經強制為 127.0.0.1 聽 80埠.
所以你打 http://localhost/ 或是 http://127.0.0.1/是可以的
但是打你的IP是不行的.. 你試著拿掉試試看. 我想應該就可以了. (記得先停止你的 IIS). 一般我裝安Apache 時的預設值是 Listen:80, 可是 EasyPHP1.8 是 Listen 127.0.0.1:80
所以別人永遠連不上你,你也無法打自己的IP 連自己.

Thursday, February 21, 2008

FreeTextBox

Very Good Editor to get what you see...

website:http://freetextbox.com/

Here are some important points to remember when using the Image Gallery control with the Freetextbox, in ASP.NET.
The image gallery control that is packed with the Freetext box control has some significant functionality that we could use instead of spending time to develop the Image uploads, resizing retaining its resolutions and maintaining your own image gallery in a web application. Freetext box, gives you facility of editing some content and save with its formatting. What it saves is basically HTML.

First you should download the Freetext box control from http://www.FreeTextbox.com/ site and add the control to the Tools. Then double click on the Freetext box and add the control to your web page.

Set the Validate Request of the ASPX page to false on the page directive.

ValidateRequest="false"

By default in ASPX pages the RequestValidation is set to true to avoid un-encoded HTML content being submitted to the server. But we will set this status false, since we need to send HTML to the server.

Now lets add the Image Gallery to this Freetextbox. Go to the folder that you downloaded and Freetextbox ->examples ->fullyloaded->ftb.imagegallery.aspx and add this to your web application.

Under the Freetextbox properties Click on ToolbarLayout property, and copy the following.

ParagraphMenu,FontFacesMenu,FontSizesMenu,

FontForeColorsMenuBold,Italic,Underline,Strikethrough;Superscript,

Subscript,RemoveFormatJustifyLeft,JustifyRight,JustifyCenter,

JustifyFull;BulletedList,NumberedList,Indent,Outdent;CreateLink,

Unlink,InsertImage,InsertRuleCut,Copy,Paste;Undo,Redo,

Print,InsertImageFromGallery,Preview,

SelectAll,WordClean,NetSpell


The ToolbarLayout property will contain the functionality of the Freetextbox and the blue colored parts indicated the image gallery functionalities, that we added newly.

Now we need to set some properties as to Create folders, Upload Images, Delete Images and etc, so click on the ftb.imagegallery.aspx and in the code find where it references the freetextbox and set the following properties.

AllowImageDelete="true" AllowImageUpload="true" AllowDirectoryCreate="true" AllowDirectoryDelete="true" runat="Server" />

One significant point is that by default all the images are saved in the "images" folder in your application and any directory we create will also be created in side the "images" folder. There fore its a point to remember that if your site uses any other images that you do not require user involvements (such as images in banners or buttons) better place then in a separate folder, and create a folder with the name of "images" inside your web application.

If you user master pages then there is a small change you need to do in the ftb.imagegallery.aspx. Make the header part runat server.



Image Gallery



Freetextbox is used as to allow the user to have the flexibility to design the content as he wishes, there for the length of the text we need to store would be a problem there for by using a data type "text" in the SQL server would give the facility to store enough text as requests.

Now that all are done lets take a look at how it appears.

Fckeditor Integration ASPNet

Chinese: http://ajunlee.pbwiki.com/FckeditorIntegrationASPNet

English : http://wiki.fckeditor.net/Developer%27s_Guide/Integration/ASP.Net

boot.ini error

"Invalid Boot.ini" or "Windows could not start" error messages when you start your computer

Article ID : 330184
Last Review : May 7, 2007
Revision : 2.2

This article was previously published under Q330184
SYMPTOMS
When you start your computer after you upgrade to Microsoft Windows XP, you may receive one or both of the following error messages:
Invalid Boot.ini
Windows could not start because the following file is missing or corrupt:

Windows\System32\Hal.dll
Back to the top

CAUSE
This issue may occur if the Boot.ini file is missing, damaged, or contains incorrect entries.
Back to the top

RESOLUTION
To resolve this issue, start the computer from the Windows XP CD, start the Recovery Console, and then use the Bootcfg.exe tool to rebuild the Boot.ini file. To do this, follow these steps: 1. Configure the computer to start from the CD-ROM or DVD-ROM drive. For information about how to do this, see your computer documentation, or contact your computer manufacturer.
2. Insert the Windows XP CD-ROM into your CD-ROM or DVD-ROM drive, and then restart your computer.
3. When you receive the "Press any key to boot from CD" message, press a key to start your computer from the Windows XP CD-ROM.
4. When you receive the "Welcome to Setup" message, press R to start the Recovery Console.
5. If you have a dual-boot or multiple-boot computer, select the installation that you have to use from the Recovery Console.
6. When you are prompted, type the administrator password, and then press ENTER.
7. At the command prompt, type bootcfg /list, and then press ENTER. The entries in your current Boot.ini file appear on the screen.
8. At the command prompt, type bootcfg /rebuild, and then press ENTER. This command scans the hard disks of the computer for Windows XP, Microsoft Windows 2000, or Microsoft Windows NT installations, and then displays the results. Follow the instructions that appear on the screen to add the Windows installations to the Boot.ini file. For example, follow these steps to add a Windows XP installation to the Boot.ini file: a. When you receive a message that is similar to the following message, press Y:
Total Identified Windows Installs: 1

[1] C:\Windows
Add installation to boot list? (Yes/No/All)
b. You receive a message that is similar to the following message:
Enter Load Identifier
This is the name of the operating system. When you receive this message, type the name of your operating system, and then press ENTER. This is either Microsoft Windows XP Professional or Microsoft Windows XP Home Edition.
c. You receive a message that is similar to the following:
Enter OS Load options
When you receive this message, type /fastdetect, and then press ENTER.

Note The instructions that appear on your screen may be different, depending on the configuration of your computer.

9. Type exit, and then press ENTER to quit Recovery Console. Your computer restarts, and the updated boot list appears when you receive the "Please select the operating system to start" message.

How to drop all tables in Oracle

Written by coregps on December 6th, 2006 in Oracle.




We sometimes need to drop all tables in Oracle. If there are many tables in the database, it will be a terrible work. The easiest way is to write a simple small SQL*Plus script to retrieve all tables of a specified user and generate DROP statements. It is something look like this:

SQL> spool c:\drop_tables.sql
SQL> SELECT ‘DROP TABLE ‘ || table_name || ‘ CASCADE CONSTRAINTS;’ FROM user_tables;
SQL> spool off
Then we can execute the generated script “drop_tables.sql” like following:

SQL> @c:\drop_tables.sql
But be careful! Be sure to log on as the correct user!

If we login as sys or system, we can run this script:

spool c:\drop_all_tables.sql
select “drop table ” || table_name || ” cascade constraints;” from all_tables where owner = ‘User Name’
spool off

MySQL Reconfiguration problems.

MySQL has some bugs, may be a bug, i am not sure, may be my wrong configuration.

if do reconfig, it will get error during excuting the details, actually in starting the service.

after do some research, i found a related answer as below. in today's case, it should be the old entries still in the registry.

Obviously there are some bugs, which might interact with each other:
a) Pathnames, as proposed, with included blanks (and probably dots, etc).
b) A security/acl issue when trying to alter the security settings.
c) When there a old entries in the registry...

Hopefully, somebody of MySQL AB will recognise this to be a problem, since this is a annoying bug. The follwing receipt helped me on both 'essential' versons, MySQL Vs. 4.1.9 and 5.0.2, respectively.

Hope, it helps! ... regards, A.N.


Gary Williams wrote:
> Hi Guys,
>
> I've had exactly the same problem and this is how
> I got it working for me, starting with a non
> working installation.
>
> 1. Stop the windows service for any existing mysql
> installation.
>
> 2. Uninstall Mysql.
>
> As with most uninstalls, old files are left
> behind. If your directory is C:\mysql\ etc then
> delete the innob, etc, files but leave the
> directories themselves as well as any existing
> databases in 'data'. If your directory is
> C:\Program Files\ etc, delete all the mysql
> directories.
>
> 3. It's now worth running regedit to make sure
> the old registry entries are deleted as well by
> the uninstall. If not, delete them.
>
> 4. It's ok to use the new .msi installer
> (essential files only), however ....
>
> 5. Do not use their default install path! Some
> genius set a path with spaces in it! Choose the
> custom install and select a sensible path, ie,
> C:\mysql
>
> 6. Do not choose to alter the security settings.
> Uncheck the relevant box and the install will
> complete without having to set a root password.
>
> I think I have remembered everything.
>
> Good luck
>
> Gary

Invalid postback or callback argument

每次 request 還沒來得急接收到 response 就又再點其它按鈕),會發生 Invalid postback or callback argument 錯誤:

Invalid postback or callback argument. Event validation is enabled using
in configuration or <%@ Page
EnableEventValidation="true" %> in a page. For security purposes, this
feature verifies that arguments to postback or callback events originate
from the server control that originally rendered them. If the data is valid
and expected, use the ClientScriptManager.RegisterForEventValidation method
in order to register the postback or callback data for validation.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Solution:

if you created a sub procedure that populates your
datalist and you are calling it when the user clicks a button within
your itemtemplate, after the data processing has been done (or whatever
processing you're doing with that button), make sure that it isn't also
being called in your Page_load sub. When your page FIRST loads and you
populate the datalist control, make sure that you have it within a If
Not Page.IsPostBack and not where it gets called on every load.

Upload Video in asp.net

First of all, by default, asp.net set the size is 4mb for each form request...if u want to upload larger file, u need to change the setting in web.config.

adding
between .

maxRequestLength is the maximum size of each form request
requestLengthDiskThreshold is the buffer size in server memory

before i didn't set executionTimeout, so the asp.net kills every request takes longer than 110seconds. so every time i upload the file takes longer than 2mins , it will comes up a not found page.....
set executionTimeout to allow the request time how long u want in seconds.

this method suppose is not good in uploading large files, it will spend all the server memory during upload progress. but in my project, there is only one person to upload the file, so it will not affect too much. But if so many people upload like youtube, hv to set sth like httphandle.....but i hvn't learn this, i think quite hard. btw, there is some control developed by company in order to handle this situation like PowUpload and KUpload. but not free.

then just use the control of FileUpload of asp.net.
and code:

aspx source:



code behind:
private bool CheckFileType(string fileName)
{
string ext = Path.GetExtension(fileName);
switch (ext.ToLower())
{
case ".rmvb":
return false;
default:
return true;
}
}
private void initialDataList()
{
string upFolder = MapPath("~/Video/VideoFiles/");
DirectoryInfo dir = new DirectoryInfo(upFolder);
DataList1.DataSource = dir.GetFiles();
DataList1.DataBind();
}
protected void Page_Load(object sender, EventArgs e)
{
initialDataList();
}
protected void btnAddVideo_Click(object sender, EventArgs e)
{
if (upVideo.HasFile)
{
if (CheckFileType(upVideo.FileName))
{
string filePath = "~/Video/VideoFiles/" + upVideo.FileName;
upVideo.SaveAs(MapPath(filePath));
}
}
initialDataList();
}

Load WebUserControl programmatically and Print it using session

Control _myControl;
protected void Page_Load(object sender, EventArgs e)
{
_myControl = LoadControl("SubContent1.ascx");
Arlyia_SubContent1 _subContent = (Arlyia_SubContent1)_myControl;
_subContent.XmlDataSourceXPath = "contents/content[@name='MainContent1']/subcontent[@name='SubContent1']/htmlcode[@language='"+Session["language"].ToString()+"']";
PlaceHolder1.Controls.Clear();
PlaceHolder1.Controls.Add(_myControl);
}
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
Session["ControlsToPrint"] = _myControl;
//Response.Write("var printWindow = window.open('PrintWindow.aspx', 'PrintWindow'," + "'toolbars=no,status=no,width=300,top=10,left=10,height=300,resizable=no,scrollbars=no,menubar=no');");

//Control _myPrintingPageControl = LoadControl("~/PrintingPage/PrintingPageControl.ascx");
//PrintingPage_PrintingPageControl _printingPage = (PrintingPage_PrintingPageControl)_myPrintingPageControl;

//_printingPage.MyControl = _myControl;

//_printingPage.Page.RegisterClientScriptBlock("", "");

//PlaceHolder2.Controls.Add(_myPrintingPageControl);

//TextBox a = (TextBox)_printingPage.FindControl("TextBox1");
//a.Text = "shit";

Page.RegisterClientScriptBlock("", "");

//PlaceHolder bb = (PlaceHolder)_printingPage.FindControl("PlaceHoder1");
//bb = PlaceHolder1;

//Response.Write(bb.Controls[0].ToString());

//PlaceHolder bb = (PlaceHolder)_printingPage.FindControl("PlaceHoder1");
//bb.Controls.Add(a);
//Response.Redirect("~/PrintingPage/PrintingPage.aspx");
//_myControl.PlaceHoder.Controls.Add(a);
}

edit xml in xmldatasource

edit xml in xmldatasource

protected void Page_Load(object sender, EventArgs e)
{
//UpdatableXmlDataSource1.FilterXPath = "contents/content[@position='test']/htmlcode[@language='english']";
XmlDataSource1.XPath = "contents/content[@position='test']/htmlcode[@language='english']";
}
protected void Button1_Click(object sender, EventArgs e)
{
XmlNode node = XmlDataSource1.GetXmlDocument().SelectSingleNode("contents/content[@position='test']/htmlcode[@language='english']");
node.InnerText = "hihi";
XmlDataSource1.Save();
}

Retrieve the Html code for a Web User Control

public static string GetHtmlForControl(Control control)
{
StringWriter textwriter = new StringWriter();
HtmlTextWriter writer = new HtmlTextWriter(textwriter);

control.DataBind();
control.RenderControl(writer);
string html = textwriter.GetStringBuilder().ToString();

return html;
}

Tip: If you're having problems with the generated Html being incomplete, then maybe you're calling the function above in the wrong time? I've been having some problems with databound EPiServer controls until we discovered that we were doing this too early. When we started doing it in the PreRenderComplete event of the page, then it started working:

protected void Page_PreRenderComplete(object sender, EventArgs e)
{
string html = FormHelper.GetHtmlForControl(Butikshuvud);
}

ASP.NET 2.0 Treeview - Expanding Nodes when Bound to SiteMap

The problem

A treenode can be selected or expanded. Selecting the node causes the SelectedNodeChange event to fire if the Treeview is configured correctly. Clicking the + icon on a node causes the TreeNodeExpanded event to fire. The selected event will not fire if the node is in Navigation mode. This behavior makes sense most of the time. The node is acting as a navigation link - it causes the browser to take you to a new page which means there is no postback. Your are going to a new page, without returning to the server first.

If the node has its NavigationUrl property set to an empty string, the node is in Selection mode. If the NavigationUrl is a non-zero length string ,the node is in Navigation mode.

For our project I wanted the children nodes to expand whenever the user selects a parent node. Yes, the user can click the + symbol to expand it, but our testing showed that many users expect the node to expand by clicking the node text instead. Since the nodes are in Navigation mode I couldn't put the code in the SelectedNodeChanged event.

My solution? Use the TreeNodeDatabound event to examine each node as it is being bound to the tree. If the current page URL matches the treenode NavigationUrl I expand all the of the current nodes children. It solves my problem. It still doesn't cause the SelectedNodeChanged to fire so it may not solve all your troubles. At least it's a start.

Protected Sub treeMainMenu_TreeNodeDataBound _
(
ByVal sender As Object, _
ByVal e As System.Web.UI.WebControls.TreeNodeEventArgs) _
Handles treeMainMenu.TreeNodeDataBound

' other binding code here...

If Request.Url.PathAndQuery = e.Node.NavigateUrl Then
e.Node.ExpandAll()
End If
End Sub