Esempio n. 1
0
 /// <summary>
 /// 生成写入数据的SQL语句
 /// </summary>
 /// <param name="info">书籍信息结构体</param>
 /// <returns>SQL语句</returns>
 static string ToSQL(lib_info info)
 {
     return(@" delete from [dbo].[sxt_lib_info] where [lib_id] = " + info.nId + @"
     INSERT INTO [dbo].[sxt_lib_info]
                ([lib_id]
                ,[lib_title]
                ,[lib_author]
                ,[lib_press]
                ,[lib_subject]
                ,[lib_type]
                ,[lib_page]
                ,[lib_price]
                ,[lib_currency]
                ,[lib_isbn]
                ,[lib_callno]
                ,[lib_desc])
          VALUES
                ('" + info.nId + @"'
                ,'" + info.sTitle.Replace("'", "''") + @"'
                ,'" + info.sAuthor.Replace("'", "''") + @"'
                ,'" + info.sPress.Replace("'", "''") + @"'
                ,'" + info.sSubject.Replace("'", "''") + @"'
                ,'" + info.sType.Replace("'", "''") + @"'
                ,'" + info.nPage + @"'
                ,'" + info.fPrice.ToString("0.000") + @"'
                ,'" + info.sCurrency.Replace("'", "''") + @"'
                ,'" + info.sISBN.Replace("'", "''") + @"'
                ,'" + info.sCallNo.Replace("'", "''") + @"'
                ,'" + info.sDesc.Replace("'", "''") + @"')");
 }
Esempio n. 2
0
        /// <summary>
        /// 从网页中提取书籍内容
        /// </summary>
        /// <param name="sHTML">网页源代码</param>
        /// <param name="nId">书籍ID</param>
        /// <returns>书籍内容结构体</returns>
        static lib_info ToInfo(string sHTML, int nId)
        {
            // 获取题名
            string reTitle = @"\('TITLE','(.*?)'\)";
            // 获取作者
            string reAuthor = @"\('AUTHOR','([^']*?)'\)"">[^<]";
            // 出版社
            string rePress = @"<b>出版项:</b></font>(.*?)</td>";
            // 页码
            string rePage = @"<b>页码:&nbsp; </b></font>[^\d]*?(\d*?)[^\d]";
            // 价格
            string rePrice = @"<b>价格:&nbsp; </b></font>[^\d]*?([\d.]*?)[^\d.]";
            // 币别
            string reCurrency = @"<b>价格:&nbsp; </b></font>([^\d]*?)[\d.]*?&nbsp;</td>";
            // ISBN
            string reIsbn = @"<span id=""isbn"">(.*?)</span>";
            // 主题
            string reSubject = @"\('SUBJECT','([^']*?)'\)"">[^<]";
            // 索取号
            string reCallNo = @"\('CALLNO','(.*?)'\)";
            // 摘要
            string reDesc = @"<b>摘要:</b></font> (.*?)</a></td>";
            // 分类
            string reType = @"\('CLASSNO','(.*?)'\)";

            lib_info info = new lib_info();

            info.nId     = nId;
            info.sTitle  = GetData(Analtytic(reTitle, sHTML));
            info.sAuthor = GetDatas(Analtytic(reAuthor, sHTML));
            info.sPress  = GetData(Analtytic(rePress, sHTML));
            try { info.nPage = Convert.ToInt32(GetData(Analtytic(rePage, sHTML))); }
            catch (Exception) { info.nPage = -1; }
            try { info.fPrice = Convert.ToDouble(GetData(Analtytic(rePrice, sHTML))); }
            catch (Exception) { info.fPrice = -1; }
            info.sCurrency = GetData(Analtytic(reCurrency, sHTML));
            info.sISBN     = GetData(Analtytic(reIsbn, sHTML));
            info.sSubject  = GetDatas(Analtytic(reSubject, sHTML));
            info.sCallNo   = GetData(Analtytic(reCallNo, sHTML));
            info.sDesc     = GetData(Analtytic(reDesc, sHTML));
            info.sType     = GetData(Analtytic(reType, sHTML));

            return(info);
        }
Esempio n. 3
0
        /// <summary>
        /// 提取下载的网页中书籍信息
        /// </summary>
        /// <param name="nId">书籍ID</param>
        /// <returns>书籍结构体,若为null,这表示该网页不包含书籍信息</returns>
        static lib_info?WriteData(int nId)
        {
            string sHTML = ReadFile("lib_" + nId + ".html");

            if (string.IsNullOrEmpty(sHTML) || sHTML.IndexOf("打开主参数库错误") >= 0)
            {
                return(null);
            }
            lib_info info = ToInfo(sHTML, nId);

            if (info.sTitle == "")
            {
                return(null);
            }
            if (info.sTitle == "临时")
            {
                return(null);
            }
            WriteSQL(ToSQL(info));
            return(info);
        }