Example #1
0
        public void UpdateLibor()
        {
            try
            {
                ClearData("Libor");
                Libor LiborItem = new Libor();
                //指定來源網頁
                WebClient url = new WebClient();
                //將網頁來源資料暫存到記憶體內
                MemoryStream ms = new MemoryStream(url.DownloadData("https://ibank.firstbank.com.tw/NetBank/7/0117.html?sh=none"));
                //以GoogleFinance為範例

                // 使用預設編碼讀入 HTML
                HtmlDocument doc = new HtmlDocument();

                HtmlNode        tempNode;
                List <HtmlNode> trNode;
                doc.Load(ms, Encoding.Default);

                tempNode = doc.DocumentNode.SelectSingleNode(@"/html[1]/body[1]/table[2]");
                trNode   = tempNode.CssSelect("tr").ToList();

                for (int i = 3; i < 180; i++)
                {
                    Libor TempLibor = new Libor();

                    TempLibor.QuotedDate = DateTime.Parse(trNode[i].SelectSingleNode(@"td[1]").InnerText);
                    TempLibor.C0N        = Decimal.Parse(trNode[i].SelectSingleNode(@"td[2]").InnerText);
                    TempLibor.C1W        = Decimal.Parse(trNode[i].SelectSingleNode(@"td[3]").InnerText);
                    TempLibor.C1M        = Decimal.Parse(trNode[i].SelectSingleNode(@"td[4]").InnerText);
                    TempLibor.C3M        = Decimal.Parse(trNode[i].SelectSingleNode(@"td[5]").InnerText);
                    TempLibor.C6M        = Decimal.Parse(trNode[i].SelectSingleNode(@"td[6]").InnerText);
                    TempLibor.C12M       = Decimal.Parse(trNode[i].SelectSingleNode(@"td[7]").InnerText);

                    db.Libors.Add(TempLibor);
                }
                db.SaveChanges();

                //清除資料
                doc = null;
                url = null;
                ms.Close();
            }
            catch (System.IO.IOException e)
            {
                logger.Error(LogUtility.GetExceptionDetails(e));
                return;
            }
        }
Example #2
0
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Libor obj)
 {
     return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr);
 }