Пример #1
0
        /// <summary>
        /// 处理日文单词
        /// </summary>
        /// <param name="result"></param>
        /// <returns></returns>
        private static Word[] DealWordJp(string result)
        {
            string[] pane = result.Match("word-details-pane");
            WordJp[] word = new WordJp[pane.Length];

            for (int i = 0; i < pane.Length; i++)
            {
                string value      = pane[i].Class("word-text");
                string sample     = pane[i].Class("simple");
                string pronounces = pane[i].Class("pronounces");
                string audio      = pronounces.Class(Tag.span, "word-audio");
                string detail     = pane[i].Class("word-details-item detail");
                string synant     = pane[i].Class("word-details-item synant");

                word[i]            = new WordJp();
                word[i].Value      = value.FilterHTML_();
                word[i].Sample     = sample.FilterHTML();
                word[i].Pronounces = pronounces.FilterHTML();
                word[i].Audio      = audio.Attr("data-src");
                word[i].Detail     = detail.FilterHTML_();
                word[i].Synant     = synant.FilterHTML_();
            }
            return(word);
        }
Пример #2
0
        /// <summary>
        /// 写入数据库
        /// </summary>
        private static void WriteWotd2DB(object o)
        {
            Word   word = (Word)o;
            string sql  = "";

            try
            {
                if (word.GetType() == typeof(WordEn))
                {
                    WordEn w = word as WordEn;
                    w   = (WordEn)w.FilterDB();
                    sql = @"UPDATE WORD_EN 
                            SET PronouncesUs = N'{1}', 
                                Sample = N'{2}', 
                                Phrase = N'{3}', 
                                Detail = N'{4}', 
                                PronouncesEn = N'{5}', 
                                DetailEnEn = N'{6}', 
                                Synant = N'{7}', 
                                Inflections = N'{8}', 
                                AudioUrl = N'{9}', 
                                UpdateCount = UpdateCount + 1, 
                                UpdateTime = GETDATE() WHERE VALUE = N'{0}';
                            IF @@ROWCOUNT = 0 
                            INSERT INTO WORD_EN(
                                Value, PronouncesUs, Sample, Phrase, Detail, PronouncesEn, 
                                DetailEnEn, Synant, Inflections, AudioUrl, Audio, 
                                UpdateCount, UpdateTime
                            ) VALUES (
                                N'{0}',N'{1}',N'{2}',N'{3}',N'{4}',N'{5}',N'{6}',N'{7}',N'{8}',N'{9}',NULL, 0, GETDATE()
                            )";
                    sql = string.Format(sql, w.Value, w.PronouncesUs, w.Sample, w.Phrase, w.Detail, w.PronouncesEn, w.DetailEnEn, w.Synant, w.Inflections, w.Audio);
                }
                else if (word.GetType() == typeof(WordJp))
                {
                    WordJp w = word as WordJp;
                    w   = (WordJp)w.FilterDB();
                    sql = @"UPDATE WORD_JP 
                            SET Sample = N'{2}', 
                                Detail = N'{3}',
                                Synant = N'{4}', 
                                AudioUrl = N'{5}', 
                                UpdateCount = UpdateCount + 1, 
                                UpdateTime = GETDATE() WHERE VALUE = N'{0}' AND Pronounces = N'{1}';
                            IF @@ROWCOUNT = 0 
                            INSERT INTO WORD_JP(
                                Value, Pronounces, Sample, Detail, Synant, AudioUrl, Audio, UpdateCount, UpdateTime
                            ) VALUES (N'{0}',N'{1}',N'{2}',N'{3}',N'{4}',N'{5}', NULL, 0, GETDATE())";
                    sql = string.Format(sql, w.Value, w.Pronounces, w.Sample, w.Detail, w.Synant, w.Audio);
                }

                using (DbManager db = new DbManager())
                {
                    db.ExeceteQuery(sql);
                }
            }
            catch (Exception ex)
            {
                if (ex.GetType() == typeof(SqlException) && ((SqlException)ex).Number == 2627)
                {
                    //sql = "UPDATE WORD_JP";
                }
                else
                {
                    Log.Write("WriteWotd2DB Filed [{0}]\t{1}", word.Value, ex.Message);
                    Log.Write("SQL【{0}】", sql);
                }
            }
        }