2008年7月28日 星期一

圖片寬度大於600像素,都強制顯示為200像素寬,高則是跟隨寬度等比例縮小

在<head>...</head>裡置入下列指令:
<style type="text/css">
img {width:expression(this.width>600?"200px":this.width+"px");}
</style>

圖片寬度大於600像素,都強制顯示為200像素寬,高則是跟隨寬度等比例縮小適合用在讓 user 自行上傳的頁面,美化頁面用,圖檔 k 數不會縮小

JavaScript 取用 ASP.Net 2.0 的 RadioButtonList 與 CheckBoxList

function getRadioButtonList(){
var radioObj = document.getElementById("<%=RadioButtonList1.ClientID %>");
var radioList = radioObj.getElementsByTagName('input');

for(var i = 0; i < radioList.length; i++)
{
if(radioList[i].checked)
{
alert(radioList[i].value);
}
}
}

function getCheckBoxList(){
var cboxObj = document.getElementById("<%=CheckBoxList1.ClientID %>");
var cboxList = cboxObj.getElementsByTagName('input');
var lbList = cboxObj.getElementsByTagName('label');

for(var i = 0; i < cboxList.length; i++)
{
if(cboxList[i].checked)
{
alert(lbList[i].innerText);
}
}
}

2008年7月25日 星期五

動態產生註冊文字圖檔

void BuildDynamicPic(string AvgRating)
{
if (AvgRating == null AvgRating.Length == 0) AvgRating = "0";
// 圖形
System.Drawing.Bitmap BMP1 = new System.Drawing.Bitmap(Server.MapPath("~/images/placeholder-100.jpg"));
//-----------------------------------------------------------------
//畫出文字
//-----------------------------------------------------------------

//定義繪圖元件
System.Drawing.Graphics formGraphics = System.Drawing.Graphics.FromImage(BMP1);

System.Drawing.Font drawFont = new System.Drawing.Font("John Handy LET", 32);
//定義筆刷
System.Drawing.SolidBrush drawBrush = new System.Drawing.SolidBrush(System.Drawing.Color.White);
Single X = (AvgRating.Length > 1) ? 5 : 22;
Single Y = 15;
System.Drawing.StringFormat drawFormat = new System.Drawing.StringFormat();
//繪製文字
formGraphics.DrawString(AvgRating, drawFont, drawBrush, X, Y, drawFormat);
drawFont.Dispose();
drawBrush.Dispose();
formGraphics.Dispose();
//從另一張網頁 ShowBitmap 輸出
Session["BMP1"] = BMP1;
//在最後加入Guid是為了解決圖檔放在updatepanel中做非同步時該圖檔也要觸發重新抓取
imgAvgRating.ImageUrl = "ShowBitmap.aspx?imgID=BMP1&r=" + Guid.NewGuid().ToString();
imgAvgRating.Visible = true;
}


//在ShowBipmap.aspx.cs的Page_Load寫上
protected void Page_Load(object sender, EventArgs e)
{
System.Drawing.Bitmap BMP ;
BMP = (System.Drawing.Bitmap)Session[Request["imgID"].ToString()];
BMP.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
BMP.Dispose();
Response.End();
}


結果

2008年7月24日 星期四

Javascript處理數字國字

var stmp = "";
function nst(t)
{
if(t.value==stmp) return;//如果等於上次輸入則返回
var ms = t.value.replace(/[^\d\.]/g,"").replace(/(\.\d{2}).+$/,"$1").replace(/^0+([1-9])/,"$1").replace(/^0+$/,"0");
//replace(/[^\d\.]/g,"")去掉輸入當中不是數字和.的字元
//replace(/(\.\d{2}).+$/,"$1")
//匹配從字元開始的第一個.後面的所有字元,由於沒有使用g標記,
//所以只匹配開始第一次 然後用小數點和後兩位進行替換以確定數值最後的格式正確 高.
//replace(/^0+([1-9])/,"$1") 匹配以多個0開頭的數值替換為去掉0後的數值做為數字的第一位 也是匹配開始的一次.
//replace(/^0+$/,"0") 匹配以0開始和結束的多個0為一個0 也就是0000000 輸入->轉換成一個0
//以下確定輸入的為過濾後的合法數位
//alert(ms);
var txt = ms.split(".");
//alert(txt[0]);
//如果ms值不小數點存在則txt[0]=小數點前的值否則等於ms
//regexp:/\d{4}(,|$)/ 匹配四位元數位和,的集合或者四位元數位和字元結尾的集合
while(/\d{4}(,|$)/.test(txt[0]))//如果為txt[0]=4123
txt[0] = txt[0].replace(/(\d)(\d{3}(,|$))/,"$1,$2");
//txt[0].replace(/(\d)(\d{3}(,|$))/,"$1,$2")是將txt[0]進行替換後再賦給它
//regexp:/(\d)(\d{3}(,|$))/ 將四個數字份為兩組第一個數字為第一位,後三位和其他結尾為每二位
//並替換成 第一位,第二位 注意 ,的使用很好. 也就是將4123先替換成4,123
//由於此運算式默認採用貪婪匹配所以從數值後向前匹配再通過迴圈進行再匹配替換從而可以將
//12345678分成你想要的123,456,78 樓主彩用(,|$)很精典,因為它略去了第二次匹配時的,問題
t.value = stmp = txt[0]+(txt.length>1?"."+txt[1]:"");
//最終賦值到輸入框中
//如果有小數點則加上並購成最終數位否則顯示替換後的txt[0]
bbb.value = number2num1(ms-0);
//將ms轉換為數位送到number2num1去轉換
}

function number2num1(strg)
{
var number = Math.round(strg*100)/100;
//先進行小數位數轉換也就是四捨五入由於上面已限定了小數位可不用
number = number.toString(10).split('.');//轉換成十進位字元並用小數點隔開
var a = number[0];//取小數點前的值如果有小數點則取它前面的否則取這個數值
if (a.length > 12)//判斷是否超過了計算範圍
return "數值超出範圍!支持的最大數值為 999999999999.99";//退出
var e = "零壹貳參肆伍陸柒捌玖";
var num1 = "";
var len = a.length-1;
for (var i=0 ; i<=len; i++)//按單個數位逐個進行遍歷
num1 += e.charAt(parseInt(a.charAt(i))) + [["圓","萬","億"][Math.floor((len-i)/4)],"拾","佰","仟"][(len-i)%4];
//e.charAt(parseInt(a.charAt(i)))將所選數字對應到相應的大寫陣列下標並取出大寫值
//[["圓","萬","億"][Math.floor((len-i)/4)],"拾","佰","仟"][(len-i)%4]
// ["圓","萬","億"][Math.floor((len-i)/4)]如果小於4位元顯示 "圓"
// 如果大於4位元小於8位元則顯示 "萬"
// 如果大於8位元則顯示 "億"
//由上面得到一個新陣列 -> 如果小於4位元顯示 ["圓","拾","佰","仟"]
// 如果大於4位元小於8位元則顯示 ["萬","拾","佰","仟"]
// 如果大於8位元則顯示 ["億","拾","佰","仟"]
// [(len-i)%4] 得到相應的所屬下標 分別得到 "圓","萬","億","拾","佰","仟
//下面處理小數點後的數值
if(number.length==2 && number[1]!="")
{
var a = number[1];//得到.後數值
for (var i=0 ; i num1 += e.charAt(parseInt(a.charAt(i))) + ["角","分"];
}
//以上完成後再進行正則過濾掉一些重複字元
num1 = num1.replace(/零佰|零拾|零仟|零角/g,"零");//全域替換零
num1 = num1.replace(/零{2,}/g,"零");//替換2個以上零為一個零
num1 = num1.replace(/零(?=圓|萬|億)/g,"");//替換零圓,零萬,零億,中的零為空
num1 = num1.replace(/億萬/,"億");//替換億萬為億隻替換第一次
num1 = num1.replace(/^圓零?/,"");//替換字串中開始的圓零為空此匹配為非貪婪匹配.適用於.57轉換時
//如果要最終數值不為空並且該串結尾不為"分"結尾則加一個"整字"
if(num1!="" && !/分$/.test(num1))
num1 += "整";
return num1;
}


數字金額:

國字金額:

Javascript處理金額格式

function cc(s){
if(/[^0-9\.]/.test(s)) return "invalid value";
s=s.replace(/^(\d*)$/,"$1.");
s=(s+"00").replace(/(\d*\.\d\d)\d*/,"$1");
s=s.replace(".",",");
var re=/(\d)(\d{3},)/;
while(re.test(s))
s=s.replace(re,"$1,$2");
s=s.replace(/,(\d\d)$/,".$1");
return "$" + s.replace(/^\./,"0.")
}
加錢符號:

2008年6月30日 星期一

Google Maps API

Google Maps API 簡易使用文件
Summary
利用 var map = new GMap2 (document.getElementById("map")); 宣告一個 GMap 物件
Google Maps API 內建四種控制項:
GLargeMapControl : 適合給大型地圖的控制項。
GSmallMapControl : 適合給小型地圖的控制項。
GSmallZoomControl : 只有 Zoom Level 的調整,沒有地圖移動控制。
GMapTypeControl : 顯示地圖型態切換的控制項。
// 設定地圖中心點
map.setCenter(new GLatLng(centerY, centerX), ZoomSize);
// 使用自訂圖檔以顯示座標點
var GPSIcon = new GIcon(G_DEFAULT_ICON);
GPSIcon.image = "images/mainPhoto.gif";
GPSIcon.iconSize = new GSize(18, 14);
//設定點座標
var point = new GLatLng(SpotPointInfo[1]*1, SpotPointInfo[0]*1);
//產生一個點
var marker = new GMarker(point,{ icon:GPSIcon });
//在點上加入click動作以顯示說明方塊
GEvent.addListener(marker, "click", function() {
var myHtml = "#" + number + "
" + message[number -1]; map.openInfoWindowHtml(point, myHtml); });
//將點加入到地圖中
map.addOverlay(marker);

Google Maps API

2008年6月20日 星期五

將123456 轉為$123,456

Double aa = Double.Parse("123456");
this.Textbox1.Text = aa.ToString("$#,##0;($#,##0);Zero");

2008年6月19日 星期四

ASP.NET取得前一頁的URL

request.servervariables("HTTP_REFERER")

2008年5月7日 星期三

微軟員工與社群專家的blog連結

為了讓大家可以更方便地找到Blog資源,我們將在MSDN首頁放置微軟員工與社群專家的blog連結. 目前預定放入的有:

微軟員工:

王森(http://blogs.msdn.com/senwang/)

李匡正(http://blogs.msdn.com/tomleetaiwan/ )

李學麟(http://blogs.msdn.com/polo_lee/)

周旺暾(http://blogs.msdn.com/wtchou/)

邱立榕(http://blogs.msdn.com/ljchiu/)

胡士亮(http://blogs.msdn.com/roberthu/)

胡德民(http://peter5288.spaces.live.com/)

胡哲燁(http://blogs.msdn.com/erichu/)



社群專家



邱銘彰(http://x-solve.com/blog/)

卓立民(http://alexchuo.blogspot.com/)

崔啟文(http://dotnetframework.blogspot.com/)

蔡煥麟(http://huanlin.dyndns.org/CS/blogs/huan-lins_blog/archive/category/1000.aspx)

奚江華(http://blog.sina.com.tw/dotnet/index.php?pbgid=4907)

鄭子璉(http://tlcheng.spaces.live.com/)

董大偉(http://book.studyhost.com/default.aspx)

章立民(http://blog.xuite.net/alwaysfuturevision/liminzhang)

2008年1月22日 星期二

替換 Courier New 字型

替換 Courier New 字型
如果您長時間在寫程式,那麼現在可以選擇一個更合適的字型

於 Vista 與 Office 2007 新增了一個 Consolas 字型,這個字形除了為固定寬度 (就是每個字都是一樣寬),另外這個字形也是ClearType 最佳化的字型,您可以於Visual Studio 2005中的 工具 -> 選項 -> 一般 -> 字型與色彩 選擇 Consolas 字型 ,如果您沒有使用 Vista 或 Office 2007 ,也可以下載 Consolas Font Pack for Microsoft Visual Studio 2005

使用 Consolas 字型的心得,除了會感覺字型會比較清晰,另外行寬也會縮短一點,這樣對於同樣的螢幕與解析度,卻可以顯示更多行的程式碼,的確可以提供一些生產力
參考網址:http://www.ruri.com.tw/blogs/tech/archive/2007/11/07/Beyond-Courier-New.aspx

2008年1月16日 星期三

javascript Function設定對某物件做PostBack的動作

function RelationSetDate(id,postBack)
{
popUpRelation.close();
if (postBack)
__doPostBack(id,'');
}
NDA系統中應用到的程式UserControl/RelationTechnology.ascx

使用AJAX.dll來實現由Client的JavaScript來及時呼叫Server的對DB取值的功能

使用AJAX.dll來實現由Client的JavaScript來及時呼叫Server的對DB取值的功能
在Key入工號的同時即時回資料庫查詢是否有符合的資料,將正確值立即帶出顯示相關的資訊(【526274三趨一17SF200】)

1. 先將ajax.dll參考到專案中
2. 在web.config中加入





3. 在要引用的.cs上Using
using Ajax;
4. 在PageLoad時加入
Ajax.Utility.RegisterTypeForAjax(typeof(GetPlanProj)); //掛入Ajax的Library
GetPlanProj=>是此.cs的ClassName
5. 攥寫Server的Function
#region Ajax 利用計畫代號查詢相關資料
[Ajax.AjaxMethod()]
public string show_pojno(string pojno)
{
string str = "";
DataTable DT = prs020.SearchPrs020(pojno);
if (DT.Rows.Count != 0)
{
//支出計畫代號,計畫名稱,計畫主持人
str = DT.Rows[0]["s20_pojno"].ToString().Trim() + ","
+ DT.Rows[0]["s20_pojcname"].ToString().Trim() + ","
+ DT.Rows[0]["s20_noinchrg"].ToString().Trim() + ","
+ DT.Rows[0]["com_cname"].ToString().Trim() + ","
+ DT.Rows[0]["com_telext"].ToString().Trim();
}
else
{
str = "none,none,none";
}
return str;
}
#endregion
6. 在要引用的元件(TextBox)上加入onkeyup的屬性,以呼叫javascript的運作
tbxProjNo.Attributes.Add("onkeyup", this.ClientID + "jsquery_pojno('');");
7. 撰寫javascript的Function動作
/* 計畫代號查詢 keyin */
Script1.Append("function " + this.ClientID + "jsquery_pojno(org) { \n");
Script1.Append("var pojno=document.all['" + tbxProjNo.ClientID + "'].value; \n");
Script1.Append("var m = GetPlanProj.show_pojno(pojno).value.split(','); \n");
Script1.Append("if(m[0]!='none'){ \n");
Script1.Append("if(typeof(document.all['" + tbxProjNo.ClientID + "']) == 'object'){document.all['" + tbxProjNo.ClientID + "'].value=m[0];} \n");
Script1.Append("if(typeof(document.all['" + tbxProjCName.ClientID + "']) == 'object'){document.all['" + tbxProjCName.ClientID + "'].value=m[1];} \n");
Script1.Append("if(typeof(document.all['" + tbxProjHost.ClientID + "']) == 'object'){document.all['" + tbxProjHost.ClientID + "'].value=m[3]+'/'+m[2]+'/'+m[4];} \n");
Script1.Append("}else{ \n");
Script1.Append("if(typeof(document.all['" + tbxProjCName.ClientID + "']) == 'object'){document.all['" + tbxProjCName.ClientID + "'].value='';} \n");
Script1.Append("if(typeof(document.all['" + tbxProjHost.ClientID + "']) == 'object'){document.all['" + tbxProjHost.ClientID + "'].value='';} \n");
Script1.Append("}} \n");
A. 請注意m = GetPlanProj.show_pojno(pojno).value.split(',')是叫用Server的Function
B. GetPlanProj是ClassName
show_pojno是FunctionName
8. NDA系統中有用到的程式其中一個GetPlanProj.ascx
其他開窗程式也大多都有用到在UserControl資料夾下

GetTip使用說明


GetTip使用說明
 效果參閱下圖


1. 先將此三個(App_Data、bin、js)資料夾都放入專案中
2. 參考bin資料夾下的3個.dll檔案(EngageCommon.dll、EngageUtil.dll、ScriptUtil.dll)
3. 在需被引用的頁面嵌入GetTip.aspx的程式

4. 在要引用的元件上設定onMouseOver的屬性
(ImageButton)fvResult.FindControl("imbtIsDulHelp")).Attributes.Add("onMouseOver", "doShowTip(event, this, 'A03')");
5. 於App_Data下設定顯示的字樣(如下)

1. aaaaaaaaaaa
2. bbbbbbbbbbb
3. ccccccccccc