2010年12月3日 星期五

.Net Reflector (二)

上篇.Net Reflector介紹,這次再說明.Net Reflector的Export功能,至於為什麼要說明是源自於辦公室同事專案裡引用的DLL檔Source Code沒有了,所以想藉由.Net Reflector產出Source Code,因為操作簡單我不做過多解釋會直接以圖例說明

1.開啟 .Net Reflector(例子的.Net Reflector版本為6.5)


2.選取欲Export的DLL檔


3.點選組件SSOUtil後再按滑鼠右鍵Export


4.點選Start按鈕


5.點選Close按鈕


6.產出路徑(XP 環境)

2010年11月1日 星期一

線上網頁編輯器FCKeditor(二)

最近要開發的系統有引用到FCKeditor,但Toolbar並不需要所有的項目,只需要部份項目,經由google大神的幫忙找到了解決方式,解決方式分為二步驟

步驟一:修改fckconfig.js


FCKConfig.ToolbarSets["JSSG"] = [
['Bold', 'Italic', 'Underline', '-', 'FontSize', 'TextColor', 'BGColor'], '/',
['JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyFull']
];


上面的程式碼片段'-'代表每一列Toolbar各區塊的分隔符號,'/'則代表換列

步驟二:設定.aspx上的FCKeditor控制項屬性







*相關參考
1.http://docs.cksource.com/FCKeditor_2.x/Developers_Guide/Configuration/Toolbar
2.http://m955.com/wp/archives/77

2010年10月22日 星期五

在MasterPage引用jquery檔案

以往在使用MasterPage時,都和引用它的.aspx檔案放在同個目錄,最近想把MasterPage檔案與aspx檔案分開放在不同的目錄,可是在實作過程發生了一些問題,所以記錄下解決方法

目錄結構
\
|___\Styles
| |_styles.css
|___\Scripts
| |_jquery-1.4.1.min.js
| |_DD_roundies_0.0.2a-min.js
|___\MasterPages
| |_DefaultMaster.master
| |_DefaultMaster.master.cs
|_Default.aspx
|_Default.aspx.cs

底下為程式碼

2010年10月10日 星期日

Tech.Days 2010 SQL Server 2008 R2 T-SQL心得

今年Tech.Days有參加楊志強老師SQL 2008 R2 T-SQL技術與建議的課程,覺得獲益良多,因此想寫入以加深印象,以下是 Where Clause使用 Like 子句與 Left的差別

測試環境
Cpu:T4200
Ram:2G
OS:winxp sp3
DB:Microsoft SQL Server 2005 Developer Edition

測試資料表為一訂單主檔資料表,筆數為122798

以下語法為找出2006年9月的訂單

SELECT IssNum
FROM IssMaster
WHERE IssNum LIKE '200609%'

SELECT IssNum
FROM IssMaster
WHERE LEFT(IssNum, 6) = '200609'



可以看出採用 Like子句的成本花費較Left函數來得小,原因在於Like是採用clustered index seek而Left函數會採用index scan,這裡要注意的是如果Like由 '200609%'改為'%200609%'則會變成index scan,相關資料可由google鍵入index seek index scan得到

2010年10月5日 星期二

新版Microsoft SQL Server Management Studio摘要在那裡?

最近工作上的SQL Server從2005升級到2008,所以SSMS(SQL Server Management Studio)也安裝了新版。在使用新版的SSMS居然找不到摘要可供物件的排序,後來利用google搜尋後才知道新版的SSMS已經不叫摘要而叫物件總管詳細資料,使用方式可以在「檢視」點選「物件總管詳細資料」或直接按F7。

2010年7月19日 星期一

NPOI使用

會使用這個元件的主要原因是因為要在一個Excel檔裡建立多個sheet的資料,底下是整理出的範例



using System;
using System.Web;
using System.IO;
using NPOI;
using NPOI.HSSF;
using NPOI.HSSF.Util;
using NPOI.HSSF.Model;
using NPOI.HSSF.UserModel;

public class filedownload : IHttpHandler
{
public void ProcessRequest (HttpContext context)
{
MemoryStream ms = new MemoryStream();
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.CreateSheet("sample");
HSSFCell cell = null;
HSSFCellStyle borderStyle = null;
HSSFCellStyle colorStyle = null;
HSSFCellStyle fontStyle = null;
HSSFCellStyle heightStyle = null;
HSSFCellStyle spanStyle = null;
HSSFCellStyle wrapStyle = null;
HSSFFont font = null;

borderStyle = workbook.CreateCellStyle();
colorStyle = workbook.CreateCellStyle();
fontStyle = workbook.CreateCellStyle();
heightStyle = workbook.CreateCellStyle();
spanStyle = workbook.CreateCellStyle();
wrapStyle = workbook.CreateCellStyle();

//Style設定
borderStyle.BorderTop = HSSFCellStyle.BORDER_THIN;
borderStyle.BorderLeft = HSSFCellStyle.BORDER_THIN;
borderStyle.BorderBottom = HSSFCellStyle.BORDER_THIN;
borderStyle.BorderRight = HSSFCellStyle.BORDER_THIN;
colorStyle.FillForegroundColor = HSSFColor.LIGHT_CORNFLOWER_BLUE.index;
colorStyle.FillPattern = HSSFCellStyle.SOLID_FOREGROUND;
fontStyle.Alignment = HSSFCellStyle.ALIGN_CENTER;
fontStyle.VerticalAlignment = HSSFCellStyle.VERTICAL_CENTER;
heightStyle.Alignment = HSSFCellStyle.ALIGN_CENTER;
heightStyle.VerticalAlignment = HSSFCellStyle.VERTICAL_CENTER;
spanStyle.Alignment = HSSFCellStyle.ALIGN_CENTER;
spanStyle.VerticalAlignment = HSSFCellStyle.VERTICAL_CENTER;
wrapStyle.WrapText = true;

//指定紙張大小 A3=8, A4=9, Letter=1
sheet.PrintSetup.PaperSize = 9;

//指定直式或橫式 true=橫式 false=直式
sheet.PrintSetup.Landscape = true;

//藏隱格線
sheet.DisplayGridlines = false;

//設定欄寬
sheet.SetColumnWidth(0, 24 * 256);
sheet.SetColumnWidth(1, 24 * 256);

//指定列高
cell = sheet.CreateRow(0).CreateCell(0);
cell.SetCellValue("指定列高");
cell.CellStyle = heightStyle;
sheet.GetRow(0).HeightInPoints = 50;

//字型大小
font = workbook.CreateFont();
font.FontHeightInPoints = 14;
font.Boldweight = HSSFFont.BOLDWEIGHT_BOLD;
fontStyle.SetFont(font);
cell = sheet.CreateRow(1).CreateCell(0);
cell.CellStyle = fontStyle;
cell.SetCellValue("字型大小14粗體");

//合併儲存格
cell = sheet.CreateRow(2).CreateCell(0);
cell.SetCellValue("合併儲存格");
cell.CellStyle = spanStyle;
sheet.AddMergedRegion(new Region(2, 0, 3, 1));

//Wrap
cell = sheet.CreateRow(4).CreateCell(0);
cell.SetCellValue(string.Format("換行{0}測試", System.Environment.NewLine));
cell.CellStyle = wrapStyle;

//增加邊框
cell = sheet.CreateRow(5).CreateCell(1);
cell.SetCellValue("邊框 ");
cell.CellStyle = borderStyle;

//背景
cell = sheet.CreateRow(6).CreateCell(0);
cell.SetCellValue("背景");
cell.CellStyle = colorStyle;

//插入分頁
sheet.SetRowBreak(cell.RowIndex);

//下一頁資料
cell = sheet.CreateRow(7).CreateCell(0);
cell.SetCellValue("下一頁資料");

workbook.Write(ms);

context.Response.ContentType = "application/vnd.ms-excel";
context.Response.AddHeader("Content-Disposition", "attachment; filename=myExcel.xls");
context.Response.BinaryWrite(ms.ToArray());
}

public bool IsReusable
{
get
{
return false;
}
}
}

使用NPOI要注意的地方是如果你要設定每個儲存格不同的儲格格式,需要建立多個HSSFCellStyle並且將它指派給儲存格


*相關參考


NPOI ( Web C+ + + + - IT技術文章 )


NPOI 1.2教程(目录) - tonyqus.cn - 博客园


NPOI - Discussions - New line in cell


[C#]NPOI匯出Excel遇到資料換行的問題 - gipi的學習筆記-我的職場觀念、IT部落格- 點部落

2010年6月21日 星期一

利用T-SQL去除字串最後一個逗號

DECLARE @str varchar(20)
SET @str = 'A,B,C,D,E,'

SELECT @str

--將字串反轉
SET @str = REVERSE(@str)
SELECT @str

--去除逗號
SET @str = CASE WHEN CHARINDEX(',', @str) = 1 THEN STUFF(@str, 1, 1, '') ELSE @str END
SELECT @str

--將字串反轉
SET @str = REVERSE(@str)
SELECT @str

那上面的語法與一般我們利用SUBSTRING(@str, 1, LEN(@str) - 1)有什麼不同?我們利用上面的語法時我們可以不用考慮字串變數的值(如NULL)及長度,改用SUBSTRING(@str, 1, LEN(@str) - 1)時要注意字串變數的長度另外還是要判斷最後一碼是否為逗號。如果讓筆者選擇利用T-SQL或程式來去除最後一個逗號,筆者會傾向程式。