/*--------------------------------- * Description: Get live price and put them into Live DB * ----------------------------------- */ public static void ExeLivePrice(string sPath) { int iInterest = 20; if (DateTime.Now.Hour > 8) { while (DateTime.Now.Hour <= 11) { if ((DateTime.Now.Second % iInterest) == 0) { // Ha Noi WebLib.HttpPostTime("http://www.hastc.org.vn/InfoShow/OnlineShareContinuousInterface.aspx", sPath, "HN"); // HCM if (DateTime.Now.Hour < 10 && DateTime.Now.Minute < 31) { WebLib.HttpPostTime("http://www.hsx.vn/LS_HSX/HoSTC_Livesecurity.htm", sPath, "HCM"); } } } } }
private void btnAuto_Click(object sender, EventArgs e) { txtMessage.Text = ""; int pageAll = chkAll.Checked ? 308 : 2; List <string> urls = db.GetUrls(10002); string dir = Application.StartupPath + @"\Data\News\"; // get info from hsx.vn int orderNum = 1; foreach (string url in urls) { if (!WebLib.HttpPost(url, dir, orderNum, "")) { txtMessage.AppendText("Không lấy được dữ liệu từ url:" + url); txtMessage.AppendText(Environment.NewLine); } else { txtMessage.AppendText("Lấy xong dữ liệu từ url" + url); txtMessage.AppendText(Environment.NewLine); orderNum++; } } //import data string[] files = Directory.GetFiles(dir); StreamReader read; string content; string[] data = new string[4]; int pos, len, typeId; string file = dir + WebLib.GetDateName() + "-"; string file1; for (int page = 1; page < orderNum; page++) { file1 = file; file1 += page + ".htm"; read = new StreamReader(file1); content = read.ReadToEnd(); //http://www.psi.vn typeId = db.UrlType(urls[page - 1]); if (urls[page - 1].Substring(0, "http://www.psi.vn".Length) == "http://www.psi.vn") { while ((pos = content.IndexOf("<item>")) != -1) { content = content.Substring(pos + 21); pos = content.IndexOf("</title>"); data[0] = content.Substring(0, pos); // title content = content.Substring(pos + 21); pos = content.IndexOf("</link>"); data[1] = content.Substring(0, pos); // link content = content.Substring(pos + 28); pos = content.IndexOf("</description>"); data[2] = content.Substring(0, pos); // description content = content.Substring(pos + 49); pos = content.IndexOf("</pubDate>"); data[3] = content.Substring(0, pos); if (db.NewsInsert(data[0], data[2], typeId, false, 0, 0, Convert.ToDateTime(data[3]), data[1]) == 0) { txtMessage.Text += "Dữ liệu bị trùng: " + parseArray(data) + "!\r\n"; break; } } } else { while ((pos = content.IndexOf("<item>")) != -1) { content = content.Substring(pos + 13); pos = content.IndexOf("</title>"); data[0] = content.Substring(0, pos); //title content = content.Substring(pos + 25); pos = content.IndexOf("/>"); content = content.Substring(pos + 2); pos = content.IndexOf("</description>"); data[1] = content.Substring(0, pos); //description content = content.Substring(pos + 20); pos = content.IndexOf("</link>"); data[2] = content.Substring(0, pos); //link content = content.Substring(pos + 16); pos = content.IndexOf("</pubDate>"); data[3] = content.Substring(0, pos); if (db.NewsInsert(data[0], data[1], typeId, false, 0, 0, Convert.ToDateTime(data[3]), data[2]) == 0) { txtMessage.Text += "Dữ liệu bị trùng: " + parseArray(data) + "!\r\n"; break; } } } txtMessage.Text += "Xử lý xong file " + file1 + "!\r\n"; read.Close(); } txtMessage.Text += "Xử lý hoan tat!"; ClearFolder(dir); }
private void btnAutoUpdateStock_Click(object sender, EventArgs e) { lblMsg.Text = "Status: Auto Updating!"; List <Branch> lst = db.BranchList(); string dirBranchStock = @"D:\Data\Stock\Branch\Stock"; int pos, pos1; StreamReader read; string content; string[] lstData; //foreach (Branch item in lst) //{ // WebLib.HttpPost(item.Url, dirBranchStock, 0, ""); // read = new StreamReader(dirBranchStock + WebLib.GetDateName() + ".htm"); // content = read.ReadToEnd(); // pos = content.IndexOf(">Vốn TT (Tỷ)</a>") + 100; // content = content.Substring(pos); // lstData = new string[14]; // while (content.IndexOf("</table>") > 50) // { // pos = content.IndexOf("<strong>") + "<strong>".Length; // content = content.Substring(pos); // pos1 = content.IndexOf("</strong>"); // lstData[0] = content.Substring(0, pos1); // pos = content.IndexOf("<span class=") + "<span class=".Length; // content = content.Substring(pos); // pos = content.IndexOf(">") + 1; // content = content.Substring(pos); // pos1 = content.IndexOf("<"); // lstData[1] = content.Substring(0, pos1); // pos = content.IndexOf("(") + 1; // content = content.Substring(pos); // pos1 = content.IndexOf(")"); // lstData[2] = content.Substring(0, pos1); // int start = 3; // for (int i = 0; i < 10; i++) // { // pos = content.IndexOf("align=\"right\">") + "align=\"right\">".Length; // content = content.Substring(pos); // pos1 = content.IndexOf("<"); // if (i == 8) // { // lstData[start + i] = content.Substring(0, pos1); // pos = content.IndexOf("(") + 1; // content = content.Substring(pos); // pos1 = content.IndexOf(")"); // lstData[++start + i] = content.Substring(0, pos1); // } // else lstData[start + i] = content.Substring(0, pos1); // } // content = content.Substring(pos1); // db.StockInsert(lstData, item.Id); // } // read.Close(); //} // Update missing detail Term term = db.DefinitionById(20515); List <Stock> lstStock = db.StockMissingDetailList(); foreach (Stock stock in lstStock) { if (stock.Code.Length > 3) { continue; } try { WebLib.HttpPost(term.Name.Replace("{code}", stock.Code), dirBranchStock, 0, stock.Code); } catch (Exception) { continue; } read = new StreamReader(dirBranchStock + stock.Code + ".htm"); content = read.ReadToEnd(); pos = content.IndexOf("<h1>") + "<h1>".Length; content = content.Substring(pos); lstData = new string[9]; pos1 = content.IndexOf("</h1>"); if (pos1 == -1) { continue; } lstData[0] = content.Substring(0, pos1); pos = content.IndexOf("margin-left:30px") + "margin-left:30px".Length; content = content.Substring(pos); for (int i = 1; i <= 8; i++) { pos = content.IndexOf("<td align=\"right\"><strong>") + "<td align=\"right\"><strong>".Length; content = content.Substring(pos); pos1 = content.IndexOf("</strong>"); lstData[i] = content.Substring(0, pos1); } content = content.Substring(pos1); db.StockUpdate(lstData, stock.Id); read.Close(); } lblMsg.Text = "Status: Completed!"; }
private void btnAutoUpdate_Click(object sender, EventArgs e) { lblMsg.Text = "Status: Auto Updating!"; string dirBranch = @"D:\Data\Stock\Branch\"; WebLib.HttpPost("http://www.cophieu68.vn/categorylist.php", dirBranch, 0, "branch"); StreamReader read = new StreamReader(dirBranch + WebLib.GetDateName() + ".htm"); string content = read.ReadToEnd(); int pos = content.IndexOf(">Vốn TT (Tỷ)</a>") + 100; int pos1; content = content.Substring(pos); string[] lstData = new string[16]; while (content.IndexOf("</table>") > 50) { pos = content.IndexOf("http://www.cophieu68.vn/categorylist_detail.php?category=^"); content = content.Substring(pos); pos1 = content.IndexOf("',"); lstData[15] = content.Substring(0, pos1); pos = content.IndexOf("<strong>") + "<strong>".Length; content = content.Substring(pos); pos1 = content.IndexOf("</strong>"); lstData[0] = content.Substring(0, pos1); pos = content.IndexOf("<span class=") + "<span class=".Length; content = content.Substring(pos); pos = content.IndexOf(">") + 1; content = content.Substring(pos); pos1 = content.IndexOf("<"); lstData[1] = content.Substring(0, pos1); pos = content.IndexOf("(") + 1; content = content.Substring(pos); pos1 = content.IndexOf(")"); lstData[2] = content.Substring(0, pos1); int start = 3; for (int i = 0; i < 11; i++) { pos = content.IndexOf("align=\"right\" >") + "align=\"right\" >".Length; content = content.Substring(pos); pos1 = content.IndexOf("<"); if (i == 9) { lstData[start + i] = content.Substring(0, pos1); pos = content.IndexOf("(") + 1; content = content.Substring(pos); pos1 = content.IndexOf(")"); lstData[++start + i] = content.Substring(0, pos1); } else { lstData[start + i] = content.Substring(0, pos1); } } content = content.Substring(pos1); db.BranchInsert(lstData); } read.Close(); lblMsg.Text = "Status: Completed!"; }
private void Auto() { txtMessage.Text = ""; int pageAll = chkAll.Checked ? 308 : 2; string url = db.GetUrls(10001)[0]; string temp; string dir = Application.StartupPath + @"\Data\Event\"; // get info from hsx.vn for (int page = 1; page < pageAll; page++) { temp = url.Replace("currentPage=1", "currentPage=" + page); if (!WebLib.HttpPost(temp, dir, page, "")) { txtMessage.AppendText("Không lấy được lịch sự kiện từ cophieu68.vn!"); txtMessage.AppendText(Environment.NewLine); } else { txtMessage.AppendText("Lấy xong lịch sự kiện từ cophieu68.vn!"); txtMessage.AppendText(Environment.NewLine); } } //import data string[] files = Directory.GetFiles(dir); StreamReader read; string line; string[] data = new string[6]; int pos; string file = dir + WebLib.GetDateName() + "-"; string file1; for (int page = 1; page < pageAll; page++) { file1 = file; file1 += page + ".htm"; read = new StreamReader(file1); while ((line = read.ReadLine()) != null) { if (line.IndexOf("<td class=\"td_bottom3 td_bg1\"><a href=\"eventschedule.php?id=") < 0) { continue; } pos = line.IndexOf("id=") + 3; data[0] = line.Substring(pos, line.IndexOf("\"><strong>") - pos); for (int i = 0; i < 3; i++) { line = read.ReadLine(); pos = line.IndexOf("\">") + 2; data[i + 1] = line.Substring(pos, line.IndexOf("</td>") - pos); } line = read.ReadLine(); line = read.ReadLine(); pos = 6; data[4] = line.Substring(pos, line.IndexOf("\t", pos) - pos); line = read.ReadLine(); line = read.ReadLine(); pos = line.IndexOf("\t", 7); data[5] = line.Substring(6, line.Length - pos); if (db.EventInsert(data) == 0) { txtMessage.Text += "Dữ liệu bị trùng: " + parseArray(data) + "!\r\n"; break; } } txtMessage.Text += "Xử lý xong file " + file1 + "!\r\n"; read.Close(); } txtMessage.Text += "Xử lý hoan tat!"; ClearFolder(dir); dgvList.DataSource = db.EventList(); }