Archive for 八月, 2009

How to Dispaly XML Attribute in HTML by XSLT

取得Attribute的方式和取得Element的方式相同,
唯一的差異在於取Attribute時,名稱前面必須加上@

全體適用
<xsl:template match=”/”>
取得第二層內的資料
<xsl:for-each select=”books/book”>
取得第二層資料的屬性值
<xsl:value-of select=”@ISBN” /> <xsl:value-of select=”@author” />
資料來源:
http://www.programmersheaven.com/2/FAQ-XML-Display-XML-Attributes-XSLT
Create a XML File
<?xml version=”1.0″?>
<?xml-stylesheet type=”text/xsl” href=”books06.xsl”?>
<books>
<book ISBN=”0321173481″ author=”Michael R. Sweet” />
<book ISBN=”0849371643″ author=”Gerald Farin” />
<book ISBN=”1558606696″ author=”David Rogers” />
<book ISBN=”1568810849″ author=”Gerald Farin” />
</books>
Create a XSL File
<?xml version=”1.0″?>
<xsl:stylesheet version=”1.0″ xmlns:xsl=”http://www.w3.org/1999/XSL/Transform”>
<xsl:output method=”html” encoding=”UTF-8″/>
<xsl:template match=”/”>
<html>
<head><title>Books</title>
</head>
<body>
<table width=”100%” border=”1″>
[...]

Continue reading »

Get Columns Schema In Table(SQL Server)

IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = ‘TEST’ AND COLUMN_NAME = ‘TEST_DATE’)
BEGIN
ALTER TABLE TEST ADD TEST_DATE DATETIME
END

Continue reading »

取得執行 動態SQL 的回傳值

/*版本二:已測試成功*/
IF OBJECT_ID(‘tempdb..#ERRFILE’) is not null  //檢查tempdb內是否存在暫存資料表
DROP TABLE #ERRFILE                                                //移除暫存資料表
DECLARE @CMD VARCHAR(1000)
DECLARE @EXECERROR INT
CREATE TABLE #ERRFILE(EXECERROR INT)     //新增暫存資料表
SET @CMD = ‘INSERT #ERRFILE SELECT 1′         //設定動態SQL的值
EXEC (@CMD)                                                                    //執行動態SQL
SET @EXECERROR = (SELECT * FROM #ERRFILE)
SELECT * FROM #ERRFILE                                         //取得暫存資料表內的值
/*版本一:有點問題*/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N’#RESULT’) AND OBJECTPROPERTY(id, N’IsUserTable’) = 1)
CREATE TABLE #RESULT (ROW INT);
DECLARE [...]

Continue reading »

Vi 跳到文件第一行、最后一行(指令說明)

:$ 跳到文件最后一行
:0或:1 跳到文件第一行

Continue reading »

(批次檔)自動刪除檔案

::請存成副檔名為.bat的檔案
cd\
cd C:\UAT\SALES\ORDER_REQUEST\DownLoadFile\
del /Q *.*
echo Deleting Files
echo File Deleted
pause
exit

Continue reading »

利用FileSteam 讀檔 , 回傳字串資料

//File Content Transfer to String
private String LoadDecodedFile(String file)
{
String DecodedString = “”;
FileStream fs = new FileStream(file, FileMode.Open);
StreamReader r = new StreamReader(fs);
// Position the file pointer at the beginning of the file.
r.BaseStream.Seek(0, SeekOrigin.Begin);
// Read the entire file into a string and decode each chunk.
while (r.Peek() > -1)
DecodedString += Server.HtmlDecode(r.ReadLine());
r.Close();
return DecodedString;
}

Continue reading »

From DataSet To Html & Excel (方法一)

private int ExportExcel(string strCondition)
{
//Get Export Data
ORDER_REQUEST objOR = new ORDER_REQUEST();
DataSet dsResult = new DataSet();
objOR.GetList_ModelExport(strCondition, out dsResult); //DataSetName = “NewDataSet” , TableName = “data”
//Check Data Existed Or Not
if (dsResult != null && dsResult.Tables.Count != 0 && dsResult.Tables[0].Rows.Count > 0)
{
//Get FileName
Random rd = new Random();
String filePathHtml = “././DownLoadFile/” + Convert.ToString(rd.Next()) + “.html”;
String filePathExcel = filePathHtml.Replace(“html”, “xls”);
//Create the [...]

Continue reading »

Excel File DownLoad From Server

protected void Page_Load(object sender, EventArgs e)
{
NameValueCollection coll=Request.QueryString;
String strRequest = coll["file"];
if (strRequest != “”)
{
String path = Server.MapPath(strRequest);
FileInfo file = new FileInfo(path);
if (file.Exists)
{
Response.Clear();
Response.AddHeader(“Content-Disposition”, “attachment; filename=” + file.Name);
Response.AddHeader(“Content-Length”, file.Length.ToString());
Response.ContentType = “application/vnd.ms-excel”;
Response.WriteFile(file.FullName);
Response.End();
}
}
}

Continue reading »