2014年7月7日 星期一

C# Delete Process

如果您的WinAP執行了一大堆,開啟工作管理員一個一個刪除的話
那可以服用這段程式碼幫你快速刪除


foreach (Process p in Process.GetProcessesByName("process_Name")) //不需要.exe
{
   p.Kill();
}

真是輕鬆又快樂

Javascript KeyDown Listener

javascript版 鍵盤按鈕Listener 程式碼的數量真是..... 相較winap真是差太多
 window.addEventListener("keydown", checkKeyPressed, false);

 function checkKeyPressed(e) {
     alert(e.keyCode);
     if (e.keyCode == "65") {
         alert("The 'a' key is pressed.");
     }
 }


不過GridView分頁要用鍵盤數字鍵去做分頁選擇的話
比較簡單的做法,直接放一個TextBox和一個Button
後端Page_Load裡面一個 TextBox1.Focus();

前端
<div style="position: absolute; top: -1500px">
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:Button ID="Button2" runat="server" Text="Button" OnClick="Button2_Click" />
 </div>
後端
 protected void Page_Load(object sender, EventArgs e)
 {
            if (!IsPostBack)
            {
           
            }
         
            TextBox1.Focus();
}

要注意Button2放的位置,如果上一個有Button的話,在TextBox按下ENTER 只會執行第一個Button

2014年7月6日 星期日

C# NPOI export xls

Third Part NPOI Nuget搜尋NPOI
 var workbook = new HSSFWorkbook();
 var sheetReportResult = workbook.CreateSheet("結果");
 
 sheetReportResult.CreateRow(0).CreateCell(0).SetCellValue("開始時間");
 
 //之後的用GetRow 取得在CreateCell
 sheetReportResult.GetRow(0).CreateCell(1).SetCellValue("結束時間");
 sheetReportResult.GetRow(0).CreateCell(2).SetCellValue("資料大小(KB)");
 
 sheetReportResult.GetRow(0).CreateCell(3).SetCellValue("花費時間(s)");
 
 sheetReportResult.GetRow(0).CreateCell(4).SetCellValue("速度(KB/s)");

 int i = 1;
 foreach (string str in sb.ToString().Split('|'))
 {
 
     if (str != "")
     {
         sheetReportResult.CreateRow(i).CreateCell(0).SetCellValue(str.Split(',')[0].Replace("Start Time: ", ""));
         sheetReportResult.GetRow(i).CreateCell(1).SetCellValue(str.Split(',')[1].Replace(" End Time :", ""));
         sheetReportResult.GetRow(i).CreateCell(2).SetCellValue(str.Split(',')[2].Replace(" Size:", ""));
         sheetReportResult.GetRow(i).CreateCell(3).SetCellValue(str.Split(',')[3].Replace(" Total:", ""));
         sheetReportResult.GetRow(i).CreateCell(4).SetCellValue(str.Split(',')[4].Replace(" Speed:", ""));
 
         i++;
     }
 }
 
 sheetReportResult.SetColumnWidth(0, 20 * 256);
 sheetReportResult.SetColumnWidth(1, 40 * 256);
 sheetReportResult.SetColumnWidth(2, 40 * 256);
 
 var file = new FileStream("C:/ample.xls", FileMode.Create);
 
 workbook.Write(file);
 file.Close();
 

2014年7月3日 星期四

JQuery Div Hide&Show

這段程式碼主要用在DIV顯示跟隱藏 剛好最近在幫客戶家功能,使用GridView做呈現 如果你非常懶的改後端,那就讓前端去幫你處理吧
$('#dvdeatil  div').each(function () {
 var data = $("#" + this.getAttribute('id')).attr("title");
 var county = data ? data.split(",")[0] : ""
   switch ($("#<%=ddlcounty.ClientID %>").find(":selected").text()) {
      case "全部":
         $("#tr_" + this.getAttribute('id')).show();
        break;
      default:
         $("#tr_" + this.getAttribute('id')).show();
         if (county != $("#<%=ddlcounty.ClientID %>").find(":selected").text())           {   
           $("#tr_" + this.getAttribute('id')).hide();
         }
       break;
    }
});

2014年7月2日 星期三

C# XmlDocument &XDocument Interconversion

using System.Xml.Linq;

XmlDocument  to  XDocument 

XmlDocument Xmldoc = new XmlDocument();
XDocument XDoc = XDocument.Parse(Xmldoc.OuterXml);

XDocument to XmlDocument

XDocument Xdoc = new XDocument();
XmlDocument Xmldoc = new XmlDocument();
Xmldoc.LoadXml(Xdoc.Document.ToString());

C# XML To List


最近經常跟Xml當好朋友,要是他能夠變成List<class>那就更好了,下面飯粒

public class UserMessage
{
            public string id { get; set; }
            public DateTime updated_time { get; set; }
            public string snippet { get; set; }
            public List<dat> participants { get; set; }
}
public class dat
{
            public string name { get; set; }
            public string email { get; set; }
            public string id { get; set; }
}

 List<UserMessage> lma1 = xd1.Descendants("data").Select(d => new UserMessage()
 {

                id = d.Element("id").Value,
                updated_time = Convert.ToDateTime(d.Element("updated_time").Value),
                snippet = d.Element("snippet").Value,
                participants = d.Descendants("dat").Select(f => new dat()
                {
                    email = f.Element("email").Value,
                    id = f.Element("id").Value,
                    name = f.Element("name").Value,
                }).ToList().Where(m => m.email != "facebook.com").Select(m => new dat()
                {
                    email = m.email,
                    id = m.id,
                    name = m.name,
                }).ToList(),

}).ToList();

2014年6月26日 星期四

JavaScript Hello World

前言就不需要了,想看歷史Google一下吧!

開發工具用Chrome就可以了,打開Chrome 按F12,上面的工具列選擇Console
輸入:
alert("Hello World")
或 console.log("Hello World")
或 document.write("Hello World")

講一下這三種使用上差別:
1: alert("Hello World") 這個很經常使用到,我們再開發的時候如果需要提示使用者,或是一些注意事項的時候可以使用這個方法。還有另一個常用的語法
if(confirm("我帥嗎?")) { alert("不帥!"); } else { alert("帥!"); }


2: console.log("Hello World")
這個方法也很常使用到,我們再寫flow的時候就可以透過這個方式Debug,將我們的處理過程顯示出來。

3: document.write("Hello World")
這個就很少再使用了,用這個語法會把所有的資料全部清掉,只秀出Hello World