2010年9月4日 星期六

jQuery Collapse - 點擊標題後可展開或關閉內容

jQuery Collapse - 點擊標題後可展開或關閉內容

~程式段~
<head id="Head1" runat="server">
<script type="text/javascript">
$(function()
{
    $(".pp").click(function(event)
    {
       event.preventDefault();//取消預設事件
       $(this).next("div").slideToggle(100);//通過高度變化來切換所有匹配元素的可見性,並在切換完成後可選地觸發一個回調函數。
       //$("#caja").slideDown();//通過高度變化(向下增大)
       //slideToggle(speed,callback)
       //這裡的 speed (String|Number): (可選) 三種預定速度之一的字符串("slow", "normal", or "fast")或表示動畫時長的毫秒數值(如:1000)
       
    });

    $("#mostrar2").click(function(event)
    {
       event.preventDefault();//取消預設事件
       $("#caja2").slideToggle(1);//通過高度變化來切換所有匹配元素的可見性,並在切換完成後可選地觸發一個回調函數。
       //$("#caja").slideDown();//通過高度變化(向下增大)
       //slideToggle(speed,callback)
       //這裡的 speed (String|Number): (可選) 三種預定速度之一的字符串("slow", "normal", or "fast")或表示動畫時長的毫秒數值(如:1000)
       
    });

    $("#caja a").click(function(event)
    {
       event.preventDefault();//取消預設事件
       $("#caja").slideUp("fast",function(){alert("bye bye!")});// 通過高度變化(向上減小)
    });
   
    $("#caja2 a").click(function(event)
    {
       event.preventDefault();//取消預設事件
       $("#caja2").slideUp("fast",function(){alert("bye bye2!")});// 通過高度變化(向上減小)
    });
   
    $("#webA").click(function(event)
    {
       event.preventDefault();//取消預設事件
       alert("大家好!!!");
    });
   
   
});

//使用的css
<style type="text/css">  
body {  
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size: 11px;
    color: #666666;    
}  
a{color:#993300; text-decoration:blink;}  
#caja {
    width:70%;
    display: none;
    padding:5px;
    border:2px solid #FADDA9;
    background-color:#FDF4E1;
}  
a2{color:#993300; text-decoration:blink;}  
#caja2 {
    width:70%;
    display: none;
    padding:5px;
    border:2px solid #FADDA9;
    background-color:#FDF4E1;
}

#mostrar{  
    display:block;
    width:70%;
    padding:5px;
    border:2px solid #D0E8F4;
    background-color:#ECF8FD;
}
 #mostrar2{  
    display:block;
    width:70%;
    padding:5px;
    border:2px solid #00AA66;
    background-color:#66DD78;
}
</style>

<body>
    <form id="form1" runat="server">
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="XmlDataSource1"><ItemTemplate>
    <a href="#" id="mostrar" class="pp">Jolin護舊愛 信周董不沾賭
  <div id="caja" >
       <ahref="#" class="close">[x]<asp:Label ID="Label1" runat="server" Text='<%#Eval("id") %>'>
       <asp:Button ID="Button1" runat="server" Text="Button" />
       <input id="Button2" type="button" value="button" />「Jolin」蔡依林昨天為新專輯辦慶功,對於舊愛「周董」周杰倫近來被爆泡賭場狂輸上億台幣,
       Jolin為他澄清:「應該不可能吧,有點誇張。」至於她與眾追求者進展得如何,是否交換了MSN帳號?
       她則笑著反問:「這很重要嗎?拒絕回答。」等同間接認了已經有人擁有她的帳號,彼此已邁入網交階段。
       慶30歲 申請1週生日假Jolin最近為新專輯連續工作4個月,又喊著想放長假,但她也知一切是「肖想」:
       「年底要辦演唱會,要放也是明年。」因此9月中乾脆藉生日名義,向公司申請1週假期,「畢竟是20歲嘛
       (實際為30歲),一定要慶祝。」
       今年希望追求者送鑽戒嗎?Jolin則說:「我自己買得起。」她坦言價錢不是重點,重要的是送的人。
       教折手舞 大嘴巴40哀嚎Jolin之前上CHANNEL[V]「音樂這個讚」,教大嘴巴40跳voguing舞,40勾不到
       手痛到哀哀叫,「好痛!這樣超像在復健的。」Jolin還淘氣上前拉他一把,讓已經滿頭大汗的40叫得
       更大聲,趁廣告空檔藉機尿遁。</p>
    </div>
    </ItemTemplate></asp:Repeater>
    <a href="#" id="mostrar2">「非A型性格」求職最吃香</a>
    <div id="caja2">
       <a href="#" class="close">[x]</a>
       <p>經歷跳樓事件後,富士康重新招募員工,招考試題中,出現了有關抗壓特質的測試,例如「周圍有喧嚷聲,能不能馬上睡?」
       從題目看來,富士康想要測試,這些面試者對於一般人不太在意的事,是否也會產生激烈的壓力反應?也就是說,富士康很可能
       要找的是心理學中「非A型性格」的人。
       一九六○年代,兩位心臟科醫師費立德曼與羅森曼定義了「A型性格」的特性,他們發現容易罹患心血管疾病的人,通常具有一套
       共同的特質:傾向於工作狂熱、全力以赴,重視做事完美無缺,好競爭且懷有敵意,卻又害怕失敗。
       之後,心理學家研究發現,具有「A型性格」的特質,容易感受到壓力,如果他們感覺事情不在自己掌控之中,便會過分投入工作,
       時時刻刻都保持警戒,血壓也居高不下。
       反之,「非A型性格」即使在高壓的環境中,仍能不慌不忙、隨和易處,也沒有爭強好勝的壓力,在緊張之後,還能愉快的休息。
       也就是說,富士康希望新進的員工,他們的心理素質天生就比較能抗壓,即俗話說的「神經比較大條」,如此,當面對治軍嚴謹、
       一絲不苟、處處要找出細節裡的魔鬼富士康主管時,才承受得了。
       抗壓風並不是只有大陸,回頭看台灣,企業主面對突如其來的變化壓力,也有員工執著於求好心切而自殺,所以在人才募集,同樣
       有偏愛抗壓能力高者的趨勢。
       台灣的鴻海,徵才條件更早即趨向「高抗壓」。在富士康尚未發生跳樓事件前,鴻海宣稱,今年將有許多新計畫持續拓展,人才需
       求很大,希望找到抗壓性好「打不走、罵不退」的青年才俊。
       不只鴻海,近來新奇美、廣達、宏碁、英業達等科技大廠開出的徵才條件,不約而同,都把「抗壓性佳」列為必備資格。今年台積
       電徵才也突出了「抗壓力」這個主題,「台灣學生聰明程度不輸國外,但是抗壓明顯較弱。」台積電人力資源經理魏烈說,公司裡
       曾有博士提出想法時被多問幾句就失去自信;也有新人看到同事被責備,便難過起來,抗壓性不足。
       因此台積電的用人政策,除了看一般的IQ(智力商數)、EQ(情緒商數)外,更重視求職者的AQ(逆境商數),因為高科技業不斷
       追求技術領先,工作承受很大的壓力,逆境商數高者,才能面對劇烈變化。</p>
    </div>
    <p></p>
    <a href="Default.aspx" id="webA">回首頁</a>
       <asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="~/XMLFile.xml">

   


~註解~
$(".pp")      //抓取class=pp的資料
$(this).next("div")    //抓取下一層資料中div元件
$("#mostrar2")        //抓取id=mostrar2的資料

~範例~
http://140.96.149.85/JQuery/WebJQuery.aspx

2010年4月8日 星期四

Reporting Service

一、設計報表
新增一個報表檔(.rdl)
<Ⅰ>資料-->設定資料來源(dbserver、dbname、username、password等),然後填寫sql或讀取stored procedure去篩選報表資料
<Ⅱ>配置-->拉好所需的報表介面後,開始填入報表內容 。
報表內容:
    頁首、頁尾:參數中的全域參數(ex:pagenum、reportname)只能用在此處,不能放在主體。
                    table元件不可以放在此處,欄位的值也不可以放在此處。
                    使用textbox時,若內容的值一定要用欄位,可以將該欄位的值設成報表參數,再引用該報表參數到textbox。

ex:CarCategory是sql產生的欄位值之一,因為在頁首不能使用,所以加入一個參數,然後將隱藏、允許Null值勾選, 允許空白值預設
        就有勾選,接著可用的值跟預設值都設成"從查詢",然後資料集、值欄位設定好就可以了



    主體:使用table元件時,要注意header跟footer只能欄合併,不能列合併,所以要設計比較複制的header或footer,
            可以在頁首或頁尾設計,運算式運用可以參考http://technet.microsoft.com/zh-tw/library/ms157328.aspx
            若需要固定excel的列高時,需要將table元件的detail每個欄位CanGrow、CanShrink皆設為false
            匯出excel時才有效果,參考http://www.kodyaz.com/articles/reporting-services-excel-rendering-autogrow.aspx

<Ⅲ>預覽-->觀看結果

二、在.NET上使用報表
<Ⅰ>以url方式直接產生報表
String scriptString = string.Format(@"
                            <script language=JavaScript>
                                <!-- begin
                                    window.open('http://localhost/ReportServer?/DirectoryName/FileName&rs:Format=excel&rs:ClearSession=true&rc:Parameters=false&ApplyNum='123456','','Width:400,Height:300,center:yes,status:no,scrollbars=no');
                                //end -->
                            </script> ");
            this.RegisterStartupScript("s", scriptString);
//DirectoryName 設置在report server上的資料夾
//FileName 報表名稱
//rs:Format=excel 這個參數是控制文件的格式,要轉出pdf則改為pdf,省略不寫則show出報表畫面,可以從所有格式中選擇其一匯出
//rc:Parameters=false 設為false時不會出現輸入參數的訊息
<Ⅱ>以ReportViewer元件呈現
        類似DataSource元件,拉進去後,填好資料來源、報表連結等資料就可以呈現。

-----------------------------------------分  格  線----------------------------------------分  格  線---------------------------------------------------
一般製作報表只需要上述兩點即可,接下來是要進行其他用途時才使用。

進行下面步驟的目的:
原本報表匯出時是直接給user點選匯出,但為了進行檔案內容的變更,所以先行將報表改成匯出到server
上(就是下述第三點),
然後再使用應用程式去開啟excel,變更格式後關閉(第四點),接著匯出(第五點)給user。                                                             



三、將報表直接存於server上
1.在專案新增web參考(webReference)=>ReportExecution2005
2.程式段
            localhost.ReportExecutionService rs = new localhost.ReportExecutionService();  //localhost為引用的webReference Name
            rs.Credentials = new System.Net.NetworkCredential("username", "password");

            string reportPath = "/Certificate/RptCertificate_G4"; //在report server上的報表檔案路徑
            string format = "EXCEL";
            string savePath = "D:\\Temp\\ReportTest.xls"; //儲存在server的資料夾路徑

            Byte[] result;
            localhost.ParameterValue[] parameters = new localhost.ParameterValue[1]; //這邊是報表參數,視其所需來增減
            parameters[0] = new localhost.ParameterValue();
            parameters[0].Name = "ApplyNum";
            parameters[0].Value = lblApplyNum.Text.Trim();
            string mimeType;
            localhost.Warning[] warnings = null;
            localhost.ParameterValue[] reportHistoryParameters = null;

            string[] streamIDs;
            string encoding;
            string devInfo = @"<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>"; //false為不顯示報表工具
            string historyId = null;
            localhost.ExecutionInfo execInfo = new localhost.ExecutionInfo();
            localhost.ExecutionHeader execHeader = new localhost.ExecutionHeader();
            string SessionId;
            string extenstion = "";
            rs.ExecutionHeaderValue = execHeader;

            try
            {
                execInfo = rs.LoadReport(reportPath, historyId);
                rs.SetExecutionParameters(parameters, "en-us");
                SessionId = rs.ExecutionHeaderValue.ExecutionID;

                result = rs.Render(format, devInfo, out extenstion, out mimeType, out encoding, out warnings, out streamIDs);
                execInfo = rs.GetExecutionInfo();
                FileStream stream = new FileStream(savePath, FileMode.Create);
                stream.Write(result, 0, result.Length);
                stream.Close();
            }
            catch (Exception ex)
            {
                string s = ex.Message;
            }
 
四、將儲存於server上的excel檔進行修改
<Ⅰ>直接使用Application開啟excel進行修改

加入參考=>Microsoft.Excel 11.0 Object Library

命名空間
using Microsoft.Office.Interop.Excel;
using System.Configuration;
using System.Reflection;
using System.Diagnostics;
using System.Runtime.InteropServices;

程式段
object missing = Missing.Value;
Excel.ApplicationClass app;
Excel.Workbook book;
Excel.Worksheet sheet;
Excel.Range ra;

app = new Excel.ApplicationClass();
try
{
    book = app.Workbooks.Open(savePath, missing, missing, missing, missing, missing,
    missing, missing, missing, missing, missing, missing, missing, missing, missing);

    //得到WorkSheet
    for (int i = 0; i < book.Sheets.Count; i++)
    {
        sheet = (Excel.Worksheet)book.Sheets.get_Item(i + 1);

        sheet.Rows.RowHeight = 36;
        sheet.UsedRange.Rows.RowHeight = 36;
        string aa = sheet.Cells[28, 1].ToString();
        string ab = sheet.get_Range(sheet.Cells[28, 1], sheet.Cells[28, 1]).Text.ToString();
        string ac = sheet.get_Range(sheet.Cells[28, 1], sheet.Cells[28, 1]).RowHeight.ToString();
        sheet.Cells[26, 1] = "1";
        sheet.Cells[29, 1] = "1";
        //調第27列(車型名稱最下面那列)
        if (reportPath == "/Certificate/RptCertificate_G4")
        {
            sheet.get_Range(sheet.Cells[27, 1], sheet.Cells[27, 1]).RowHeight = 24;
            //調內容那八列
            sheet.get_Range(sheet.Cells[28, 1], sheet.Cells[35, 1]).RowHeight = 27;
        }
        //設定顏色
        sheet.get_Range("B:B", Type.Missing).Font.Color = 255;
        //合併儲存格
        sheet.get_Range(sheet.Cells[37, 1], sheet.Cells[39, 1]).MergeCells = true;
        //得到使用過的欄位數目
        System.Runtime.InteropServices.Marshal.ReleaseComObject((object)sheet);
    }
    book.Close(true, Type.Missing, Type.Missing);
    app.Workbooks.Close();
    System.Runtime.InteropServices.Marshal.ReleaseComObject((object)book);
}
catch (Exception es)
{
    throw es;
}
finally
{
    app.Quit();
    try
    {
        IntPtr t = new IntPtr(app.Hwnd);
        int k = 0;
        GetWindowThreadProcessId(t, out k);
        System.Diagnostics.Process p = System.Diagnostics.Process.GetProcessById(k);
        p.Kill();
    }
    catch(Exception et)
    {
        string bo = et.Message;
    }

優點:可以直接修改excel的屬性,不會變動到整個資料格式。
缺點:process關不掉,會造成記憶體空間不足

<Ⅱ>使用NPOI修改excel
    利用記憶體讀取excel的資料後,另外匯出到另一個excel,而且可以設定excel的屬性。
參考如下
http://selene-tw.blogspot.com/2010/01/npoi.html

優點:不用擔心process關不掉的結果。
缺點:如果是複雜的報表格式,要一一重新設定格式,非常不適用,與其用報表設計完再從這裡進行修改,倒不如直接在這裡土法設計出報表格式,所以這個方法比較適用簡單的報表資料匯出


五、匯出檔案
            //開啟在server上的excel檔提供使用者下載或存檔
            System.IO.FileInfo fileinfo;
            string sFileName = "D://Temp//" + lblApplyNum.Text.Trim() + ".xls";
            fileinfo = new System.IO.FileInfo(sFileName);
            if (fileinfo.Exists)
            {
                Response.ClearHeaders();
                Response.Clear();
                string attachment = "attachment; filename=" + lblApplyNum.Text.Trim() + ".xls";
                Response.AddHeader("Accept-Language", "zh-tw");
                Response.AddHeader("Content-Disposition", attachment);
                Response.AddHeader("Content-Length", fileinfo.Length.ToString());
                Response.ContentType = "application/ms-excel";
                Response.WriteFile(fileinfo.FullName);
                Response.Flush();
                //刪除temp中該檔案
                fileinfo.Delete();
                Response.End();
            }
            string scriptString = string.Format(@"
                    <script language=JavaScript>
                    <!-- begin            
                     window.open('{0}');
                    //end -->
                    </script>
                    ", savePath);
            this.RegisterStartupScript("s", scriptString);

結論:由於第四點的兩種方法在實作上各有困難點,所以可以欣賞欣賞就好,慶幸的是最後格式的問題
         在報表中找到了解決方法,就是第一點在配置時的本體找到的固定excel列高方法。


2009年6月11日 星期四

進度條

進度條
在處理檔案或資料時,如果處理時間過長導致使用者無法等待時,
常常會需要將處理資料的動作改為背景作業,以便使用者進行其他事項。

以下是進行背景作業時產生進度條的做法(資源來自這裡)

功能頁 (要執行資料處理的那頁)

private void btnHistory_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
System.Threading.Thread thread=new System.Threading.Thread(new System.Threading.ThreadStart(LongTask));
thread.Start();

Session["State"]=1;
OpenProgressBar(this.Page);
}

private void LongTask()
{
//模擬長時間任務
//每個循環模擬任務進行到不同的階段
for(int i=0;i<101;i++)
{
System.Threading.Thread.Sleep(1000);
//設置每個階段的state值,用來顯示當前的進度
Session["State"] = i+1;
}
//任務結束
Session["State"] = 1000;

}

public static void OpenProgressBar(System.Web.UI.Page Page)
{
StringBuilder sbScript = new StringBuilder();

sbScript.Append("<script language='JavaScript' type='text/javascript'>\n");
sbScript.Append("<!--\n");

//IE5.5以下使用window.open
sbScript.Append("window.open('Progress.aspx','', 'height=100, width=350, toolbar =no, menubar=no, scrollbars=no, resizable=no, location=no, status=no');\n");
sbScript.Append("// -->\n");
sbScript.Append("</script>\n");

Page.RegisterClientScriptBlock("OpenProgressBar", sbScript.ToString());

}



進度表(Progress.aspx)

<%@ Page language="c#" Codebehind="Progress.aspx.cs" AutoEventWireup="false" Inherits="Approve.Progress" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>

<title>Progress</title>
<base target="_self">

</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:Label id="lblMessages" runat="server"></asp:Label> <asp:Panel id="panelBarSide" runat="server" Width="300px" BorderStyle="Solid" BorderWidth="1px" ForeColor="Silver"> <asp:Panel id="panelProgress" runat="server" Width="10px" BackColor="Green"></asp:Panel> </asp:Panel> <asp:Label id="lblPercent" runat="server" ForeColor="Blue"></asp:Label>
</form>
</body>
</HTML>

進度表(Progress.aspx.cs)

protected System.Web.UI.WebControls.Label lblMessages;
protected System.Web.UI.WebControls.Panel panelProgress;
protected System.Web.UI.WebControls.Panel panelBarSide;
protected System.Web.UI.WebControls.Label lblPercent;

private int state = 0;
private void Page_Load(object sender, System.EventArgs e)
{
// 在這裡放置使用者程式碼以初始化網頁 // Put user code to initialize the page here
if(Session["State"]!=null)
{
state = Convert.ToInt32(Session["State"].ToString());
}
else
{
Session["State"]=0;
}
if(state>0&&state<=100)
{
this.lblMessages.Text = "Task undertaking!";
this.panelProgress.Width = state*3;
this.lblPercent.Text = state + "%";
Page.RegisterStartupScript("","<script>window.setTimeout('window.Form1.submit()',100);</script>");
}
if(state==1000)
{
this.panelProgress.Visible = false;
this.panelBarSide.Visible = false;
this.lblMessages.Text = "Task Completed!";
Page.RegisterStartupScript("","<script>window.close();</script>");
}
}

master page

master page

這次的case是拿master page 當 frame set 用

不直接使用frame set是因為無法拿掉每個區塊間的空隙,

即使border width調成0,區塊間還是有空白的存在



正常使用master page的狀況如下
master page

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
<LINK href="css/sub_index.css" type="text/css" rel="stylesheet">
</head>
<body>
<form id="form1" runat="server">
<div>
<table width="100%" border=0 cellspacing=0 cellpadding=0>
<tr><td colspan="2"><embed src=".\images\banner.swf" width="100%"></embed></td></tr>
<tr>
<td style="width: 74px" valign="top">
<table border=0 cellspacing=0 cellpadding=0>
<tr><td><img src="images/web_02.gif" /></td></tr>
<tr><td><a href="HyperLink7.aspx" target="_self"><img src="images/web_24.gif" alt="綠色車輛查詢" border="0" /></a></td></tr>
<tr><td><a href="GreenCar.aspx" target="_self"><img src="images/27005563.gif" alt="綠色車輛指南網首頁" border="0" /></a></td></tr>
<tr><td><a href="http://www.epa.gov.tw/index.aspx" target="_blank"><img src="images/web_04.gif" alt="環保署首頁" border="0" /></a></td></tr>
<tr><td><a href="http://air.epa.gov.tw/Public/Main.aspx" target="_blank"><img src="images/web_05.gif" alt="空保處首頁" border="0" /></a></td></tr>
<tr><td><a href="http://mobile.epa.gov.tw/index.aspx" target="_blank"><img src="images/web_06.gif" alt="移動污染源管制網首頁" border="0" /></a></td></tr>
<tr><td><a href="http://mobile.epa.gov.tw/car_mQuery.asp" target="_blank"><img src="images/web_23.gif" border="0" alt="歷年汽機車審驗值資料" /></a></td></tr>
<tr><td><img src="images/web_07.gif" alt="綠色車輛介紹" /></td></tr>
<tr><td><a href="HyperLink.aspx" target="_self"><img src="images/web_08.gif" alt="電動自行車" border="0" /></a></td></tr>
<tr><td><a href="HyperLink2.aspx" target="_self"><img src="images/web_09.gif" alt="電動輔助自行車" border="0" /></a></td></tr>
<tr><td><a href="HyperLink3.aspx" target="_self"><img src="images/web_10.gif" alt="電動機車" border="0" /></a></td></tr>
<tr><td><a href="HyperLink4.aspx" target="_self"><img src="images/web_11.gif" alt="油電混合車" border="0" /></a></td></tr>
<tr><td><a href="HyperLink5.aspx" target="_self"><img src="images/web_12.gif" alt="先進環保技術" border="0" /></a></td></tr>
<tr><td><a href="HyperLink6.aspx" target="_self"><img src="images/web_13.gif" alt="車輛污染防制知識" border="0" /></a></td></tr>
<tr><td><img src="images/web_14.gif" alt="各國綠色車輛資訊" /></td></tr>
<tr><td><a href="http://www.epa.gov/greenvehicle" target="_blank"><img src="images/web_15.gif" alt="美國環保署" border="0" /></a></td></tr>
<tr><td><a href="http://www.vcacarfueldata.org.uk/information/how-to-use-the-data-tables.asp" target="_blank"><img src="images/web_16.gif" alt="英國車輛認證署" border="0" /></a></td></tr>
<tr><td><a href="http://www.greenvehicleguide.gov.au/GVGPublicUI/ApplicationFirstStartTaskWebForm.aspx" target="_blank"><img src="images/web_17.gif" alt="澳洲運輸及區域服務" border="0" /></a></td></tr>
<tr><td><a href="http://www.rightcar.govt.nz/" target="_blank"><img src="images/web_18.gif" alt="紐西蘭交通署" border="0" /></a></td></tr>
<tr><td><a href="http://www.eta.co.uk/" target="_blank"><img src="images/web_19.gif" alt="英國運輸與環境機構" border="0" /></a></td></tr>
<tr><td><img src="images/web_20.gif" alt="綠色運具資訊查詢" /></td></tr>
<tr><td><a href="http://greentransport.iot.gov.tw/" target="_blank"><img src="images/web_21.gif" alt="綠色運輸系統教育宣導網" border="0" /></a></td></tr>
<tr><td><a href="http://proj.moeaidb.gov.tw/lev/Product/" target="_blank"><img src="images/web_22.gif" alt="電動車輛產業網" border="0" /></a></td></tr>
</table></td>
<td valign=top><asp:contentplaceholder id="ContentPlaceHolder1" runat="server"> </asp:contentplaceholder></td></tr>
<tr><td colspan="2"><embed src=".\images\down.swf" height="150" width="100%"></embed></td></tr>
</table>
</div>
</form>
</body>
</html>

content

<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default" Title="預設首頁" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
程式區
</asp:Content>

程式區:
1.可以自行拉介面,就像平常在aspx一樣!! 但只有<body></body>內的東西
2.可以使用<!-- #include file = "index.html"--> 將整個網頁包進去,aspx也可以
3.可以使用<iframe> 通通都可以包進去

建構出來的畫面如下:

2009年4月13日 星期一

timeout

這幾天因為轉檔時出現timeout
無法順利轉檔~~
第一個想到的就是提升效能
讓執行時速度變快
也許時間就能壓制在timeout時限內

經過一番努力
把原本cursor的方式改掉後
終於把時間壓縮了1/3
由快60秒壓到37秒左右
但是執行時一樣會發生timeout
...........

後來只好從延長timeout時間來著手
原來使用sqlDataAdapter元件時
timeout的時間default是30秒
可以從command的commandtimeout去設定timeout的時間

2008年12月17日 星期三

讀取excel的欄位數目(不使用oledb)

讀取excel的欄位數目(不使用oledb)




這次遇到的問題是當excel中欄位數超過255欄時,以前用oledb讀入的方式會產生錯誤,執行到fill(ds)時就會掛掉了,連用try-catch都抓不出錯誤,就直接給我罷工(氣死)!!


經過google後援會一番商討後,終於看到了點希望,就在差點搞掛電腦ㄉ危險下終於ok!! 呼~~~


讓我寫下這可歌可泣ㄉ一面







~step1~


加入參考


1 .NET System.Data.OracleClient.dll


2. COM Microsoft Excel 11.0 Object Library







~step2~


加入namespace


using Excel;


using System.Configuration;


using System.Reflection;


using System.Diagnostics;






~step3~


object missing = Missing.Value;

Excel.ApplicationClass app;

Excel.Workbook book;

Excel.Worksheet sheet;

int excelcount;



app = new ApplicationClass();
try
{
book = app.Workbooks.Open(Files[j],missing,missing,missing,missing,missing,
missing,missing,missing,missing,missing,missing,missing,missing,missing);
}
catch (Exception e)
{
throw e;
}
//得到WorkSheet
sheet = (Excel.Worksheet)book.Sheets.get_Item(1);

//得到使用過的欄位數目
excelcount = sheet.UsedRange.Columns.Count;
book.Close(false,false,false);
app.Workbooks.Close();
app.Quit();

ps:記得application一定要關!! 不然會一直執行!! 無法測試,必須重開機,以上!!

2008年11月11日 星期二

在.net下執行command mode指令

在.net下執行command mode指令


using System;

using System.Diagnostics;



單行指令


public void ExeCommand(string commandline)
{

Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
p.Start();
string strOutput = null;
p.StandardInput.WriteLine(commandline);
p.StandardInput.WriteLine("exit");
strOutput = p.StandardOutput.ReadToEnd();
Console.WriteLine(strOutput);
p.WaitForExit();
p.Close();
}



多行指令


public string ExeCommand(string[] commandTexts)
{
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
string strOutput = null;
try
{
p.Start();
foreach (string item in commandTexts)
{
p.StandardInput.WriteLine(item);
}
p.StandardInput.WriteLine("exit");
strOutput = p.StandardOutput.ReadToEnd();
p.WaitForExit();
p.Close();
}
catch (Exception e)
{
strOutput = e.Message;
}
return strOutput;
}

coreftp

先安裝coreftp



然後就可以在command mode下使用指令執行



一般ftp模式



下載

"程式執行檔在路徑" -d 遠端ftp address -p 下載檔案放置ㄉ位置

ex:
"c:\program files\coreftp\coreftp.exe" -d ftp://UserId:Password@140.96.149.49/CHT/CHT_IN/*.txt -p c:\fail\


上傳

"程式執行檔在路徑" -u 上傳檔案放置ㄉ位置 -p 遠端ftp address

ex:
"c:\program files\coreftp\coreftp.exe" -u c:\fail\*.txt -p ftp://UserId:Password@140.96.149.49/CHT/CHT_OUT/*.txt


ftp加密模式


下載

"程式執行檔在路徑" -d(下載) 遠端ftp address -site SiteName -p(路徑) 下載檔案放置ㄉ位置


ex:


"c:\program files\coreftp\coreftp.exe" -d ftp://UserId:Password@140.96.149.49/CHT/CHT_IN/*.txt -site CarApprove -p c:\fail\



上傳


"程式執行檔在路徑" -u(上傳) 上傳檔案放置ㄉ位置 -site SiteName -p(路徑) 遠端ftp address


ex:


"c:\program files\coreftp\coreftp.exe" -u c:\fail\*.txt -site CarApprove -p ftp://UserId:Password@140.96.149.49/CHT/CHT_OUT/*.txt



sitename設定如下:





新增一個連結~~~Connection選擇AUTH SSL(加密模式),便於在command mode下使用



在上傳、下載時,指令最後若加上 -delsrc 在上傳、下載動作成功結束時會一併清除檔案來源

其他指令可以參考coreftp網頁及coreftp help

http://www.coreftp.com/docs/web1/Command_Line_FTP.htm

2008年10月7日 星期二

處理字串的方法

在.NET中,使用string、substring、length所取的字數皆為字元數(char),相當於2bytes,所以中、英字母的大小沒有區別。

但匯入文字檔(txt)所取ㄉ字數為位元數(byte),中文=2bytes、英文=1byte,須另行處理,使用substring、length會出現錯誤。

使用上有點不同~~分別列舉如下

ex:

<Ⅰ>字元數(char)寫法


string aa = "an中文txt"; 
int iCount = aa.Length();

string sChinese = aa.substring(aa, 2, 2);

 

iCount = 7

sChinese = "中文"

 

<Ⅱ>位元數(byte)寫法   
string aa = "an中文txt";

int iCount = System.Text.Encoding.Default.GetByteCount(aa);


byte[] bString = System.Text.Encoding.Default.GetBytes(aa);


string sChinese = System.Text.Encoding.Default.GetString(bString, 2, 2);


 


iCount = 9


sChinese = "中"  

  

2008年8月7日 星期四

interface
一般來說javascript只能單一繼承,沒辦法像c++可以使用多重繼承。
為了可以讓javascript擁有類似多重繼承的功能,所以使用interface。
interface跟 abstract class的差別
interface就如同字面意義"介面",像是主機板上面的PCI插槽,而PCI插槽可以插上顯示卡、音效卡、網路卡(相當於class),
藉由PCI來連接主機板跟顯示卡、音效卡間的作用。
abstract class相當於最基本的四邊形,而長方形、菱形、正方形、平行四邊形都繼承四邊形的特性,也有各自的特性。

2008年8月4日 星期一

重要ㄉ小老鼠

重要ㄉ小老鼠

原程式如下:
if(txtTop.Text.Trim() == "" txtTestDateStart.Text.Trim() == "" !CheckInt(txtTop.Text.Trim()))
{
if(txtTestDateStart.Text.Trim() == "")
{
ErrorMessage += "請輸入測試日期n";
}
if(txtTop.Text.Trim() == "")
{
ErrorMessage += "請輸入顯示TOP資料n";
}
else
{
ErrorMessage += "顯示TOP資料只能為>0的整數n";
}
String scriptString1 = string.Format(@"
<script language=JavaScript>
<!-- begin
alert('{0}')
//end -->
</script>
",ErrorMessage);
this.RegisterStartupScript("s",scriptString1);
修改後:
if(txtTop.Text.Trim() == "" txtTestDateStart.Text.Trim() == "" !CheckInt(txtTop.Text.Trim()))
{
if(txtTestDateStart.Text.Trim() == "")
{
ErrorMessage += @"請輸入測試日期n";
}
if(txtTop.Text.Trim() == "")
{
ErrorMessage += @"請輸入顯示TOP資料n";
}
else
{
ErrorMessage += @"顯示TOP資料只能為>0的整數n";
}
String scriptString1 = string.Format(@"
<script language=JavaScript>
<!-- begin
alert('{0}')
//end -->
</script>
",ErrorMessage);
this.RegisterStartupScript("s",scriptString1);
差別在ErrorMessage後的"@",不使用時會造成javascript結尾錯誤
很機車ㄉ錯誤~~差點去買乖乖來拜了>"<

2008年8月1日 星期五

自動在windows執行 每天刪除n天前的檔案

'自動化檔案維護管理程式
'天數
daysAgo = 7

'路徑
dirPath = "C:\\Temp2"

'副檔名
extName = ".txt"

';;;;;程式開始;;;;;
Set fs = CreateObject("Scripting.FileSystemObject")
Set w = WScript.CreateObject("WScript.Shell")

Set f = fs.GetFolder(dirPath)
Set fc = f.Files

dateBefore = Now() - daysAgo

For Each ff in fc
fileName = ff.Name
fileDate = ff.DateLastModified

If Right(fileName, Len(extName)) = extName And fileDate < dateBefore Then
fs.DeleteFile(dirPath & "\\" & fileName)
End If
Next

----------------------分格線-----------------------------------------
用途:自動在windows執行 每天刪除n天前的檔案
Step1:複製分格線以上ㄉ文字 貼在txt檔然後副檔名改成vbs
Step2:在windows的工作排程上使用該檔

後記:
上面是網路上找到ㄉ
試用後真ㄉ可以ㄝ!!
神奇ㄉVBS!!
有需要ㄉ可以參考看看!!
如果有直接使用command mode就可以完成ㄉ指令
也可以回覆我~~
3Q