Example #1
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            UrlAddress N = new UrlAddress();

            N.Urladdress("https://branch.taipower.com.tw/Content/NoticeBlackout/bulletin.aspx?&SiteID=564732646551216421&MmmID=616371300113254267");
            N.area("北市區");
            N.Html_Original();



            UrlAddress NN = new UrlAddress();

            NN.Urladdress("https://branch.taipower.com.tw/Content/NoticeBlackout/bulletin.aspx?&SiteID=564732636524040174&MmmID=616371300130136031");
            NN.area("北北區");
            NN.Html_Original();


            UrlAddress NS = new UrlAddress();

            NS.Urladdress("https://branch.taipower.com.tw/Content/NoticeBlackout/bulletin.aspx?&SiteID=564732646356736245&MmmID=616371300115522273");
            NS.area("北南區");
            NS.Html_Original();


            UrlAddress NW = new UrlAddress();

            NW.Urladdress("https://branch.taipower.com.tw/Content/NoticeBlackout/bulletin.aspx?&SiteID=564766277367364243&MmmID=616371300000777256");
            NW.area("北西區");
            NW.Html_Original();



            Application.Run(new Form1());
        }
Example #2
0
        //=====================================台電查詢=====================================
        private void Button2_Click(object sender, EventArgs e)
        {
            TD_richTextBox.Clear();
            DateTime d = DateTime.Now;
            //string t = textBox1.Text.ToString();
            string   t     = Strings.StrConv(TD_textbox.Text.ToString(), VbStrConv.Wide);
            int      count = 0;
            DateTime yday  = d.AddDays(1);              //明天
            string   yyday = yday.ToString("yyyyMMdd"); //明天轉字串
            string   day   = d.ToString("yyyyMMdd");    //今天轉字串
            string   line;

            string[] SecrH = new string[500];
            string[] text1 = new string[5000];
            int      num   = 0;
            int      Dnum  = 0;
            int      cos   = 0;
            int      Tcos  = 0;

            text1[0] = " ";
            string Sameday = d.GetDateTimeFormats('D')[1].ToString();

            foreach (var item in TD_area)
            {
                try
                {
                    StreamReader str = new StreamReader($@"{AppDomain.CurrentDomain.BaseDirectory}\{item}\{Sameday}-{item}.txt");
                    while ((line = str.ReadLine()) != null)
                    {
                        //  Console.WriteLine(line);
                        //text.Add(line);
                        if (num == 0 || num < 5000)
                        {
                            text1[num] = line;


                            int dayd = line.IndexOf(yyday); // 文本中搜尋明天

                            int ttd  = line.IndexOf(day);   //文本搜尋今天
                            int td   = line.IndexOf("日期:");
                            int time = line.IndexOf("分 至");

                            int r = line.IndexOf(t);


                            if (ttd != -1)           //當搜尋到今天日期 count=1
                            {
                                count = 1;
                                //richTextBox2.Text += $"{text1[num]}" + Environment.NewLine;
                                if (Tcos == 0)
                                {
                                    TD_richTextBox.Text += $"{DateTime.Now.ToString("yyyy/MM/dd")}" + Environment.NewLine;
                                    Tcos = 1;
                                }
                            }
                            else if (td != -1)
                            {
                                count = 0;
                            }
                            // Console.WriteLine(line);

                            if (time != -1)
                            {
                                SecrH[Dnum] = text1[num];
                                Dnum++;
                                cos = 1;
                            }


                            switch (count)
                            {
                            case 1:
                                if (r != -1)      //當搜尋到"日期"  "文字格中的字串" "自"  和count=1
                                {                 //輸出
                                    //richTextBox2.Text += $"{text1[num]}" + Environment.NewLine; 顯示區域
                                    if (cos == 1)
                                    {
                                        TD_richTextBox.Text += $"===============================" +
                                                               $"============================================" +
                                                               $"==========================================" +
                                                               $"\n{SecrH[Dnum - 1]}" + Environment.NewLine;
                                    }

                                    TD_richTextBox.Text += $"{text1[num]}" + Environment.NewLine;


                                    cos = 0;
                                }

                                break;

                            default:
                                break;
                            }

                            num++;
                        }
                    }
                    str.Close();
                }
                catch (Exception)
                {
                    UrlAddress N = new UrlAddress();
                    N.Urladdress("https://branch.taipower.com.tw/Content/NoticeBlackout/bulletin.aspx?&SiteID=564732646551216421&MmmID=616371300113254267");
                    N.area("北市區");
                    N.Html_Original();



                    UrlAddress NN = new UrlAddress();
                    NN.Urladdress("https://branch.taipower.com.tw/Content/NoticeBlackout/bulletin.aspx?&SiteID=564732636524040174&MmmID=616371300130136031");
                    NN.area("北北區");
                    NN.Html_Original();


                    UrlAddress NS = new UrlAddress();
                    NS.Urladdress("https://branch.taipower.com.tw/Content/NoticeBlackout/bulletin.aspx?&SiteID=564732646356736245&MmmID=616371300115522273");
                    NS.area("北南區");
                    NS.Html_Original();


                    UrlAddress NW = new UrlAddress();
                    NW.Urladdress("https://branch.taipower.com.tw/Content/NoticeBlackout/bulletin.aspx?&SiteID=564766277367364243&MmmID=616371300000777256");
                    NW.area("北西區");
                    NW.Html_Original();
                }
            }
        }