Exemple #1
0
        /// <summary>
        /// Required: Number of valid days in the selected period to compare with the ones in the database
        ///
        /// Option 1: Need list with correct free days (together with weekends) to calculate them.
        ///
        /// Option 2 (this):
        /// - check if "today" date is higher than stored "lastDate" date
        /// - if so, get file with any one currency for whole existing period from source
        /// - if databse has fewer, update it
        /// </summary>
        public static void UpdateValidDaysHtml()
        {
            //DateTime lastDate = Convert.ToDateTime(GlobalConfig.GetAppConfig("LastDate"));
            DateTime lastDate = Convert.ToDateTime(GlobalConfig.LastDate); // temp: can't set web.config

            lastDate.AddDayHour(0, 14);

            DateTime today = DateTime.Now;

            if (today.Hour < 14)
            {
                today.AddDayHour(-1, 14);
            }
            else
            {
                today.AddDayHour(0, 14);
            }

            if (today > lastDate)
            {
                using (WebClient webClient = new WebClient())
                {
                    string _lastDate = today.ToShortDateString();
                    //GlobalConfig.SetAppConfig("LastDate", _lastDate);
                    GlobalConfig.LastDate = _lastDate; // temp: can't set web.config

                    string       page = webClient.DownloadString(GlobalConfig.GetAppConfig("ValidDaysHtml"));
                    HtmlDocument doc  = new HtmlDocument();
                    doc.LoadHtml(page);

                    string dir  = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName;
                    string path = Path.Combine(dir, "Files");
                    string file = "ValidDays.html";

                    doc.Save("C:\\Files\\ValidDays.html");
                    //htmlDoc.Save(Path.Combine(path, file));
                }
            }
        }