public bool saveToDb(SinaHLDayEx shl)
        {
            bool result = false;

            try
            {
                DateTime solarDate = DateTime.Parse(shl.m_date.Value);

                string cmdText = string.Format(
                    "INSERT INTO wy_sinahuangli(solarDate, soloarDate_str, lunarDate, yearOrder, zodiac, monthOrder, dayOrder, birthGod, fiveElem, collide, pengAvoid, goodAngelYi, evilAngelJi, yi, ji) " +
                    " VALUES ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}', '{8}', '{9}', '{10}', '{11}', '{12}', '{13}', '{14}')",
                    solarDate.ToShortDateString(), shl.m_solarDate.Value, shl.m_lunarDate.Value, shl.m_yearOrder.Value, shl.m_zodiac.Value, shl.m_monthOrder.Value, shl.m_dayOrder.Value,
                    shl.m_birthGod.Value, shl.m_fiveElem.Value, shl.m_collide.Value, shl.m_pengAvoid.Value, shl.m_goodAngelYi.Value, shl.m_evilAngelJi.Value, shl.m_Yi.Value, shl.m_Ji.Value);

                Debug.WriteLine(cmdText);

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

                if (cmdSql.ExecuteNonQuery() == 1)
                {
                    result = true;
                }
            }
            catch (FormatException fx)
            {
                // Do nothing
            }

            return result;
        }
        public int parseHLDayFiles(string dirpath)
        {
            int nResult = 0;

            SinaHDDB db = new SinaHDDB();
            db.initDb();

            string[] filenames = Directory.GetFiles(dirpath);
            foreach (string fn in filenames)
            {
                FileStream fs = new FileStream(fn, FileMode.Open);
                if (fs != null)
                {
                    TextReader tr = new StreamReader(fs);
                    string strHtml = tr.ReadToEnd();
                    ZHtmlParser htmlParser = new ZHtmlParser(strHtml);
                    SinaHLDayEx hlday = new SinaHLDayEx(htmlParser);

                    db.saveToDb(hlday);

                    tr.Close();
                }
                fs.Close();
            }
            db.closeDb();
            return nResult;
        }
Exemple #3
0
        public SinaHLDayEx getSinaHlInfo(int year, int month, int day)
        {
            if (!initDb())
            {
                return null;
            }

            DateTime solarDate = new DateTime(year, month, day);
            SinaHLDayEx hld = null;

            try
            {
                string cmdText = string.Format("SELECT * FROM `wy_sinahuangli`WHERE DATE_FORMAT(solarDate, '%Y/%c/%e' ) = DATE_FORMAT( '{0}', '%Y/%c/%e' )",
                    solarDate);
                MySqlCommand cmdSql = new MySqlCommand(cmdText, m_connSql);
                cmdSql.CommandType = CommandType.Text;

                MySqlDataReader sqlReader = cmdSql.ExecuteReader();
                if (sqlReader.Read())
                {
                    hld = new SinaHLDayEx();

                    hld.m_solarDate  .Value = sqlReader.GetString("solarDate");
                    hld.m_lunarDate  .Value = sqlReader.GetString("lunarDate");
                    hld.m_yearOrder  .Value = sqlReader.GetString("yearOrder");
                    hld.m_zodiac     .Value = sqlReader.GetString("zodiac");
                    hld.m_monthOrder .Value = sqlReader.GetString("monthOrder");
                    hld.m_dayOrder   .Value = sqlReader.GetString("dayOrder");
                    hld.m_birthGod   .Value = sqlReader.GetString("birthGod");
                    hld.m_fiveElem   .Value = sqlReader.GetString("fiveElem");
                    hld.m_collide    .Value = sqlReader.GetString("collide");
                    hld.m_pengAvoid  .Value = sqlReader.GetString("pengAvoid");
                    hld.m_goodAngelYi.Value = sqlReader.GetString("goodAngelYi");
                    hld.m_evilAngelJi.Value = sqlReader.GetString("evilAngelJi");
                    hld.m_Yi         .Value = sqlReader.GetString("yi");
                    hld.m_Ji         .Value = sqlReader.GetString("ji");

                }
                sqlReader.Close(); // 必须关闭
                cmdSql = null;
                sqlReader = null;
            }
            catch (MySqlException ex)
            {
                hld = null;
                Debug.Write(ex.Message);
            }

            return hld;
        }