Ejemplo n.º 1
0
        bool saveToFile(TXHuangDaoDay hdd, FileFormat iFormat)
        {
            bool result = true;

            try
            {
                string tmp_filename = hdd.FID + ".txt";

                FileStream fs = new FileStream(tmp_filename, FileMode.CreateNew);
                StreamWriter sw = new StreamWriter(fs, Encoding.GetEncoding("UTF-8"));

                switch (iFormat)
                {
                    case FileFormat.FM_JSON:
                        sw.Write(hdd.SerialToJSON());
                        break;
                    case FileFormat.FM_XML:
                        sw.Write(hdd.SerialToXML());
                        break;
                }

                sw.Close();
                fs.Close();

            }
            catch (IOException ex)
            {
                result = false;
            }

            return result;
        }
Ejemplo n.º 2
0
        private void readWebData()
        {
            int page_count = m_endPage - m_startPage + 1;

            for (int i = 0; i < page_count; i++)
            {
                m_strHtml = m_wclient.DownloadString(getBookUrl(i));
                TXHuangDaoDay hdd = new TXHuangDaoDay(m_strHtml);

                saveToDb(hdd);
            }
        }
Ejemplo n.º 3
0
        bool saveToDb(TXHuangDaoDay hdd)
        {
            bool result = false;
            if (!initDb())
            {
                return false;
            }

            string cmdText = string.Format("INSERT INTO wy_huangli(fid, showtime, lunerdate, goodtodo, badtodo) VALUES(\'{0}\', \'{1}\', \'{2}\', \'{3}\', \'{4}\')",
                             hdd.FID, hdd.ShowTime, hdd.LunerDate, hdd.GoodToDo, hdd.BadToDo);

            MySqlCommand cmdSql = new MySqlCommand(cmdText, m_connSql);
            cmdSql.CommandType = CommandType.Text;

            if (cmdSql.ExecuteNonQuery() == 1)
            {
                result = true;
            }

            return result;
        }
Ejemplo n.º 4
0
        public TXHuangDaoDay selectHlData(string where_clause)
        {
            if (!initDb())
            {
                return null;
            }

            TXHuangDaoDay hdd = null;

            try
            {
                // Get record count
                string cmdText = "SELECT count(*) FROM wy_huangli " + where_clause;
                MySqlCommand cmdSql = new MySqlCommand(cmdText, m_connSql);
                cmdSql.CommandType = CommandType.Text;

                int row_count = (int)cmdSql.ExecuteScalar();

                if (row_count > 0)
                {
                    TXHuangDaoDay[] hdds = new TXHuangDaoDay[row_count];

                    cmdText = "SELECT * FROM wy_huangli " + where_clause;
                    cmdSql.CommandText = cmdText;

                    MySqlDataReader sqlReader = cmdSql.ExecuteReader();
                    for (int i = 0; (i < row_count) && sqlReader.Read(); i++)
                    {
                        hdds[i].FID = sqlReader.GetString("fid");
                        hdds[i].ShowTime = sqlReader.GetDateTime("showtime");
                        hdds[i].LunerDate = sqlReader.GetString("lunerdate");
                        hdds[i].GoodToDo = sqlReader.GetString("goodtodo");
                        hdds[i].BadToDo = sqlReader.GetString("badtodo");
                    }

                    sqlReader.Close();
                }

            }
            catch (MySqlException ex)
            {
                hdd = null;
            }

            return hdd;
        }