Пример #1
0
 protected void bntInterfaceAdd_Click(object sender, EventArgs e)
 {
     if (ddlInterfaceType.SelectedItem.Value == "-1")
     {
         ddlInterfaceType.Focus();
         return;
     }
     if (txtInterfaceUrl.Text.Equals("")
         ||txtInterfaceName.Text.Equals("")
         ||txtInterfaceBody.Text.Equals("")
         ||txtInterfaceSource.Text.Equals("")
         ||txtInterfaceSourceUrl.Text.Equals(""))
     {
         return;
     }
     CnInterfaceInfo cnf = new CnInterfaceInfo();
     cnf.CnInterfaceTypeID = Convert.ToInt32(ddlInterfaceType.SelectedItem.Value);
     cnf.CnInterfaceAppearTime = Convert.ToDateTime(txtInterfaceAppearTime.Text);
     cnf.CnInterfaceName = txtInterfaceName.Text;
     cnf.CnInterfaceUrl = txtInterfaceUrl.Text;
     cnf.CnInterfacebody = txtInterfaceBody.Text;
     cnf.CnInterfaceSource = txtInterfaceSource.Text;
     cnf.CnInterfaceSourceUrl = txtInterfaceSourceUrl.Text;
     InterfaceInfo IFI = new InterfaceInfo();
     int insertcount = IFI.InsertCnInterfaceInfo(cnf);
     Response.Write(insertcount.ToString());
 }
Пример #2
0
        /// <summary>
        /// 插入接口表(Cn_InterfaceInfo)数据
        /// </summary>
        /// <param name="cii">接口实体对象</param>
        int ICnInterfaceInfo.InsertCnInterfaceInfo(CnInterfaceInfo cnf)
        {
            int excutecount = 0;
            string sql = @"DECLARE @cnf_id INT
SELECT  @cnf_id = ID
FROM    Cn_InterfaceInfo
WHERE   CnInterfaceUrl = @CnInterfaceUrl
        AND CnInterfaceName = @CnInterfaceName

IF @cnf_id IS NULL 
    BEGIN
INSERT INTO [Cn_InterfaceInfo]
           ([CnInterfaceTypeID]
           ,[CnInterfaceName]
           ,[CnInterfaceUrl]
           ,[CnInterfaceInfo]
           ,[CnInterfaceSource]
           ,[CnInterfaceSourceUrl]
           ,[CnInterfaceAppearTime])
     VALUES
           (@CnInterfaceTypeID
           ,@CnInterfaceName
           ,@CnInterfaceUrl
           ,@CnInterfaceInfo
           ,@CnInterfaceSource
           ,@CnInterfaceSourceUrl
           ,@CnInterfaceAppearTime) 
      END";
             string conStr = System.Configuration.ConfigurationSettings.AppSettings["ConnectionStr"].ToString();
             using (SqlConnection conn = new SqlConnection(conStr))
             {
                 conn.Open();
                 SqlCommand cmd = conn.CreateCommand();
                 cmd.CommandType = CommandType.Text;
                 cmd.CommandText = sql;
                 cmd.Parameters.AddWithValue("@CnInterfaceTypeID", cnf.CnInterfaceTypeID);
                 cmd.Parameters.AddWithValue("@CnInterfaceName", cnf.CnInterfaceName);
                 cmd.Parameters.AddWithValue("@CnInterfaceUrl", cnf.CnInterfaceUrl);
                 cmd.Parameters.AddWithValue("@CnInterfaceInfo", cnf.CnInterfacebody);
                 cmd.Parameters.AddWithValue("@CnInterfaceSource", cnf.CnInterfaceSource);
                 cmd.Parameters.AddWithValue("@CnInterfaceSourceUrl", cnf.CnInterfaceSourceUrl);
                 cmd.Parameters.AddWithValue("@CnInterfaceAppearTime", cnf.CnInterfaceAppearTime);

                 excutecount = cmd.ExecuteNonQuery();
             }
             return excutecount;
        }
Пример #3
0
 /// <summary>
 /// 更新接口表(Cn_InterfaceInfo)数据
 /// </summary>
 /// <param name="cii">接口实体对象</param>
 void ICnInterfaceInfo.UpdateCnInterfaceInfo(CnInterfaceInfo cii)
 {
     throw new NotImplementedException();
 }
Пример #4
0
        /// <summary>
        /// 查询接口表(Cn_InterfaceInfo)数据(根据关键字等条件查询)
        /// </summary>
        /// <param name="searchwords">查询关键字</param>
        /// <param name="pagesize">每页数量</param>
        /// <param name="pageindex">当前页码</param>
        /// <param name="totalcount">数据总条数</param>
        /// <param name="totalpage">分页总页数</param>
        /// <returns>接口实体对象集合</returns>
        IList<CnInterfaceInfo> ICnInterfaceInfo.GetCnInterfaceInfoByName(int ttype,string searchwords, int pagesize, int pageindex, out int totalcount, out int totalpage)
        {
            string sql = @"SELECT  a.*
                                INTO    #temp_search_article
                                FROM    ( SELECT    id ,
                                                    0 AS MATCH
                                          FROM      Cn_InterfaceInfo
                                          WHERE  CnInterfaceTypeID=@ttype  AND   CnInterfaceName LIKE '%' + @searchwords + '%'
                                                    AND CnInterfaceInfo LIKE '%' + @searchwords + '%'
                                          UNION ALL
                                          SELECT    id ,
                                                    1 AS MATCH
                                          FROM      Cn_InterfaceInfo
                                          WHERE  CnInterfaceTypeID=@ttype  AND   CnInterfaceName LIKE '%' + @searchwords + '%'
                                                    AND CnInterfaceInfo NOT LIKE '%' + @searchwords + '%'
                                          UNION ALL
                                          SELECT    id ,
                                                    2 AS MATCH
                                          FROM      Cn_InterfaceInfo
                                          WHERE  CnInterfaceTypeID=@ttype  AND   CnInterfaceInfo LIKE '%' + @searchwords + '%'
                                                    AND CnInterfaceName NOT LIKE '%' + @searchwords + '%'
                                        ) a


                                SELECT  b.MATCH ,
                                        c.*
                                FROM    ( SELECT TOP ( @pagesize )
                                                    *
                                          FROM      #temp_search_article b
                                          WHERE     id NOT IN ( SELECT TOP ( @pagesize * ( @pageindex - 1 ) )
                                                                        id
                                                                FROM    #temp_search_article )
                                        ) b
                                        INNER JOIN Cn_InterfaceInfo c ON b.id = c.id
                                ORDER BY b.MATCH ASC ,c.CnInterfaceAppearTime DESC

                                -- 总的记录数
                                DECLARE @totalcount INT ;
                                -- 总的页数
                                DECLARE @totalpage INT ;

                                SELECT  @totalcount = COUNT(0)
                                FROM    #temp_search_article

                                SET @totalpage = @totalcount / @pagesize
                                IF @totalcount % @pagesize <> 0 
                                    SET @totalpage = @totalpage + 1 
                                SELECT  @totalcount AS totalcount ,
                                        @totalpage AS totalpage 

                                DROP TABLE #temp_search_article
                                ";
            if (ttype == 0)
            {
                sql = @"SELECT  a.*
                                INTO    #temp_search_article
                                FROM    ( SELECT    id ,
                                                    0 AS MATCH
                                          FROM      Cn_InterfaceInfo
                                          WHERE     CnInterfaceName LIKE '%' + @searchwords + '%'
                                                    AND CnInterfaceInfo LIKE '%' + @searchwords + '%'
                                          UNION ALL
                                          SELECT    id ,
                                                    1 AS MATCH
                                          FROM      Cn_InterfaceInfo
                                          WHERE     CnInterfaceName LIKE '%' + @searchwords + '%'
                                                    AND CnInterfaceInfo NOT LIKE '%' + @searchwords + '%'
                                          UNION ALL
                                          SELECT    id ,
                                                    2 AS MATCH
                                          FROM      Cn_InterfaceInfo
                                          WHERE     CnInterfaceInfo LIKE '%' + @searchwords + '%'
                                                    AND CnInterfaceName NOT LIKE '%' + @searchwords + '%'
                                        ) a


                                SELECT  b.MATCH ,
                                        c.*
                                FROM    ( SELECT TOP ( @pagesize )
                                                    *
                                          FROM      #temp_search_article b
                                          WHERE     id NOT IN ( SELECT TOP ( @pagesize * ( @pageindex - 1 ) )
                                                                        id
                                                                FROM    #temp_search_article )
                                        ) b
                                        INNER JOIN Cn_InterfaceInfo c ON b.id = c.id
                                ORDER BY b.MATCH ASC ,c.CnInterfaceAppearTime DESC

                                -- 总的记录数
                                DECLARE @totalcount INT ;
                                -- 总的页数
                                DECLARE @totalpage INT ;

                                SELECT  @totalcount = COUNT(0)
                                FROM    #temp_search_article

                                SET @totalpage = @totalcount / @pagesize
                                IF @totalcount % @pagesize <> 0 
                                    SET @totalpage = @totalpage + 1 
                                SELECT  @totalcount AS totalcount ,
                                        @totalpage AS totalpage 

                                DROP TABLE #temp_search_article
                                ";
            }
            string conStr = System.Configuration.ConfigurationSettings.AppSettings["ConnectionStr"].ToString();
            using (SqlConnection conn = new SqlConnection(conStr))
            {
                conn.Open();
                SqlCommand cmd = conn.CreateCommand();
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = sql;
                cmd.Parameters.AddWithValue("@searchwords", searchwords);
                if (ttype > 0)
                {
                    cmd.Parameters.AddWithValue("@ttype", ttype);
                }
                cmd.Parameters.AddWithValue("@pagesize", pagesize);
                cmd.Parameters.AddWithValue("@pageindex", pageindex);
                SqlDataAdapter sda = new SqlDataAdapter(cmd);
                DataSet ds = new DataSet();
                sda.Fill(ds);
                if (ds.Tables[0].Rows.Count > 0)
                {
                    IList<CnInterfaceInfo> ICII =new List<CnInterfaceInfo>();
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        CnInterfaceInfo cii = new CnInterfaceInfo();
                        cii.CnInterfaceTypeID =Convert.ToInt32(ds.Tables[0].Rows[i]["CnInterfaceTypeID"]);
                        cii.CnInterfaceName = ds.Tables[0].Rows[i]["CnInterfaceName"] as string;
                        cii.CnInterfaceUrl = ds.Tables[0].Rows[i]["CnInterfaceUrl"] as string;
                        cii.CnInterfacebody = ds.Tables[0].Rows[i]["CnInterfaceInfo"] as string;
                        cii.CnInterfaceSource = ds.Tables[0].Rows[i]["CnInterfaceSource"] as string;
                        cii.CnInterfaceSourceUrl = ds.Tables[0].Rows[i]["CnInterfaceSourceUrl"] as string;
                        cii.CreateDateTime = Convert.ToDateTime(ds.Tables[0].Rows[i]["CreateDateTime"]);
                        cii.CnInterfaceAppearTime = Convert.ToDateTime(ds.Tables[0].Rows[i]["CnInterfaceAppearTime"]);
                        ICII.Add(cii);
                    }
                    totalcount = Convert.ToInt32(ds.Tables[1].Rows[0]["totalcount"]);
                    totalpage = Convert.ToInt32(ds.Tables[1].Rows[0]["totalpage"]);
                    return ICII;
                }
                else
                {
                    totalcount = 0;
                    totalpage = 0;
                    return null;
                }
            }
        }
Пример #5
0
 /// <summary>
 /// 更新接口表(Cn_InterfaceInfo)数据
 /// </summary>
 /// <param name="cii">接口实体对象</param>
 public void UpdateCnInterfaceInfo(CnInterfaceInfo cii)
 {
     ObjectCreate.CreateInterfaceInfo().UpdateCnInterfaceInfo(cii);
 }
Пример #6
0
 /// <summary>
 /// 插入接口表(Cn_InterfaceInfo)数据
 /// </summary>
 /// <param name="cii">接口实体对象</param>
 public int InsertCnInterfaceInfo(CnInterfaceInfo cii)
 {
     return ObjectCreate.CreateInterfaceInfo().InsertCnInterfaceInfo(cii);
 }
Пример #7
0
        /// <summary>
        /// 获取有道接口查询结果
        /// </summary>
        /// <param name="html">网络地址</param>
        /// <returns>有道查询结果</returns>
        public static int GetCnInterfaceInfoFromYoudao(string url)
        {
            int insertcount = 0;

            WebClient wc = new WebClient
            {
                Encoding = Encoding.GetEncoding("gb2312")
            };
            string html = wc.DownloadString(url.Trim());

            //string html = "";
            //System.IO.StreamReader sr = new System.IO.StreamReader("D:\\CnInterface\\CnWeb\\html\\youdaocode.txt", Encoding.GetEncoding("gb2312"));
            //lock (sr)
            //{
            //    html = sr.ReadToEnd();
            //    sr.Close();
            //}

            var doc = new HtmlDocument();
            doc.LoadHtml(html);
            string nameValue = "";
            string urlValue = "";
            string bodyValue = "";
            string timeValue = "";
            //StringBuilder sb = new StringBuilder();
            for (int i = 1; i <= 10; i++)
            {
                try
                {
                    string nameXpath = "/body[1]/div[6]/div[2]/ul[1]/li["+i.ToString()+"]/h3[1]/a[1]";
                    string urlXpath = "/body[1]/div[6]/div[2]/ul[1]/li[" + i.ToString() + "]/h3[1]/a[1]/@href[1]";
                    string bodyXpath = "/body[1]/div[6]/div[2]/ul[1]/li[" + i.ToString() + "]/div[1]";
                    string timeXpath = "/body[1]/div[6]/div[2]/ul[1]/li[" + i.ToString() + "]/p[1]/span[1]";

                    nameValue = doc.DocumentNode.SelectSingleNode(nameXpath).InnerText;
                    nameValue = new HtmlToText().ConvertHtml(nameValue).Trim();
                    urlValue = doc.DocumentNode.SelectSingleNode(urlXpath).Attributes["href"].Value;
                    try
                    {
                        bodyValue = doc.DocumentNode.SelectSingleNode(bodyXpath).InnerHtml;
                        bodyValue = new HtmlToText().ConvertHtml(bodyValue).Trim();
                    }
                    catch
                    {
                        bodyValue = "";
                    }
                    try
                    {
                        timeValue = doc.DocumentNode.SelectSingleNode(timeXpath).InnerText;
                        timeValue = timeValue.Substring(timeValue.LastIndexOf("20")).Replace("-->", "");
                    }
                    catch
                    {
                        timeValue = "";
                    }

                    //sb.Append(" <div style=\"margin-top: 20px; margin-bottom: 20px; width:678px\">");
                    //sb.Append(" <div>");
                    //sb.Append(" <a target=\"_blank\"  href=\"" + urlValue + "\"><font color=blue>" + nameValue.Replace("接口", "<font color=red>接口</font>") + "</font></a>");
                    //sb.Append(" </div>");
                    //sb.Append(" <div style=\"font-size: 13px;\">");
                    //sb.Append(" <font size=2 >" + bodyValue.Replace("接口", "<font color=red>接口</font>") + "</font>");
                    //sb.Append(" </div>");
                    //sb.Append(" <div>");
                    //sb.Append(" <font color=#006600>" + urlValue + "</font>&nbsp;&nbsp;<font size=2 color=#006600>" + timeValue + "</font>&nbsp;&nbsp;<a target=\"_blank\" href=\"" + url + "\"><font size=2  color=#666699>有道搜索</font></a>");
                    //sb.Append("  </div>");
                    //sb.Append(" </div>");
                }
                catch
                {
                    continue;
                }

                try
                {
                    DateTime dt = Convert.ToDateTime(timeValue);
                }
                catch
                {
                    timeValue = DateTime.Now.ToString("yyyy-MM-dd");
                }
                CnInterfaceInfo cnf = new CnInterfaceInfo
                {
                    CnInterfaceTypeID = 2,
                    CnInterfaceName = nameValue,
                    CnInterfacebody = bodyValue,
                    CnInterfaceUrl = urlValue,
                    CnInterfaceSource = "有道搜索",
                    CnInterfaceSourceUrl = url,
                    CnInterfaceAppearTime = Convert.ToDateTime(timeValue)
                };
                InterfaceInfo IFI = new InterfaceInfo();
                int cont = IFI.InsertCnInterfaceInfo(cnf);
                if (cont > 0)
                    insertcount++;

                System.Threading.Thread.Sleep(200);
            }

            return insertcount;
        }
Пример #8
0
        /// <summary>
        /// 通过URL获取接口对象.
        /// </summary>
        /// <param name="wc">WebClient 对象.</param>
        /// <param name="url">接口列表URL.</param>
        /// <param name="cnurlxp">接口地址(XPath).</param>
        /// <param name="cnurlRgx">接口地址正则表达式(Regex).</param>
        /// <param name="cnnamexp">接口名称(XPath).</param>
        /// <param name="cnnameRgx">接口名称正则表达式(Regex)</param>
        /// <param name="cnbodyXp">接口内容(XPath).</param>
        /// <param name="cnbodyRgx">接口内容正则表达式(Regex).</param>
        /// <param name="cntimeXp">接口发布时间(XPath).</param>
        /// <param name="cntimeRgx">接口发布时间正则表达式(Regex).</param>
        /// <param name="cntimeF">接口发布时间Format.</param>
        /// <param name="cnsource">接口网络来源.</param>
        /// <param name="cnsourceurl">接口网络来源地址.</param>
        /// <returns>接口对象.</returns>
        public static int GetCnInterfaceInfoEntity(WebClient wc,
                                                                                              string url,
                                                                                              string cnurlxp,
                                                                                              string cnurlRgx,
                                                                                              string cnnamexp,
                                                                                              string cnnameRgx,
                                                                                              string cnbodyXp,
                                                                                              string cnbodyRgx,
                                                                                              string cntimeXp,
                                                                                              string cntimeRgx,
                                                                                              string cntimeF,
                                                                                              string cnsource,
                                                                                              string cnsourceurl,
                                                                                              int cntypeid,
                                                                                              int sourceno,
                                                                                              int pagesize)
        {
            var html = wc.DownloadString(url);
            var doc = new HtmlDocument();
            doc.LoadHtml(html);

            int insertcount = 0;
            for (int i = 1; i <=pagesize; i++)
            {
                try
                {
                    //xpath处理
                    string urlllog = "";
                    if (sourceno == 1)
                    {
                        cnurlxp = cnurlxp.Replace("cnface", (i * 2).ToString());
                        cnnamexp = cnnamexp.Replace("cnface", (i * 2).ToString());
                        cnbodyXp = cnbodyXp.Replace("cnface", i.ToString());
                        cntimeXp = cntimeXp.Replace("cnface", (i * 3).ToString());
                    }
                    if (sourceno == 2)
                    {
                        cnurlxp = cnurlxp.Replace("cnface", i.ToString());
                        cnnamexp = cnnamexp.Replace("cnface", i.ToString());
                        cnbodyXp = cnbodyXp.Replace("cnface", i.ToString());
                        cntimeXp = cntimeXp.Replace("cnface", i.ToString());
                        urlllog = "http://www.skycn.com/";
                    }
                    //取接口地址
                    var cnurl = urlllog + doc.DocumentNode.SelectSingleNode(cnurlxp).Attributes["href"].Value;
                    if (cnurlRgx != null && !cnurlRgx.Equals(""))
                        cnurl = new Regex(cnurlRgx).Match(cnurl).Groups[1].Value;
                    //取接口名称
                    var title = doc.DocumentNode.SelectSingleNode(cnnamexp).InnerHtml;
                    if (cnnameRgx != null && !cnnameRgx.Equals(""))
                        title = new Regex(cnnameRgx).Match(title).Groups[1].Value;
                    title = new HtmlToText().ConvertHtml(title).Trim();
                    //取接口内容
                    var body = doc.DocumentNode.SelectSingleNode(cnbodyXp).InnerHtml;
                    if (cnbodyRgx != null && !cnbodyRgx.Equals(""))
                        title = new Regex(cnbodyRgx).Match(body).Groups[1].Value;
                    body = new HtmlToText().ConvertHtml(body).Trim();

                    //取接口发布时间
                    var ptStr = doc.DocumentNode.SelectSingleNode(cntimeXp).InnerHtml;
                    if (cntimeRgx != null && !cntimeRgx.Equals(""))
                        ptStr = new Regex(cntimeRgx).Match(ptStr).Groups[1].Value;

                    CnInterfaceInfo cnf = new CnInterfaceInfo
                    {
                        CnInterfaceTypeID = cntypeid,
                        CnInterfaceName = title,
                        CnInterfacebody = body,
                        CnInterfaceUrl = cnurl,
                        CnInterfaceSource = cnsource,
                        CnInterfaceSourceUrl = cnsourceurl,
                        CnInterfaceAppearTime = Convert.ToDateTime(ptStr)
                    };
                    InterfaceInfo IFI = new InterfaceInfo();
                    int cont= IFI.InsertCnInterfaceInfo(cnf);
                    if (cont > 0)
                        insertcount += cont;
                }
                catch { continue; }
                System.Threading.Thread.Sleep(200);
            }
            return insertcount;
        }