⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 collect.cs

📁 最好用的站点内容管理系统 全部源代码都有
💻 CS
📖 第 1 页 / 共 4 页
字号:
                SqlParameter[] parm = new SqlParameter[5];
                parm[0] = new SqlParameter("@RuleName", SqlDbType.NVarChar, 50);
                parm[0].Value = Name;
                parm[1] = new SqlParameter("@OldContent", SqlDbType.NVarChar, 100);
                parm[1].Value = OldStr;
                parm[2] = new SqlParameter("@ReContent", SqlDbType.NVarChar, 100);
                parm[2].Value = NewStr;
                parm[3] = new SqlParameter("@AddDate", SqlDbType.DateTime);
                parm[3].Value = DateTime.Now;
                parm[4] = new SqlParameter("@IgnoreCase", SqlDbType.Bit);
                parm[4].Value = IgnoreCase;
                id = Convert.ToInt32(DbHelper.ExecuteScalar(Trans, CommandType.Text, Sql, parm));
                if (AppSites != null && AppSites.Length > 0)
                {
                    foreach (int stid in AppSites)
                    {
                        Sql = "delete from " + Pre + "Collect_RuleApply where SiteID=" + stid;
                        DbHelper.ExecuteNonQuery(Trans, CommandType.Text, Sql, null);
                        Sql = "insert into " + Pre + "Collect_RuleApply(SiteID,RuleID,RefreshTime) values (" + stid + "," + id + ",'" + DateTime.Now + "')";
                        DbHelper.ExecuteNonQuery(Trans, CommandType.Text, Sql, null);
                    }
                }
                Trans.Commit();
            }
            catch
            {
                Trans.Rollback();
                throw;
            }
            finally
            {
                if (cn != null && cn.State == ConnectionState.Open)
                    cn.Close();
            }
            return id;
        }
        public void RuleUpdate(int RuleID, string Name, string OldStr, string NewStr, int[] AppSites, bool IgnoreCase)
        {
            SqlConnection cn = new SqlConnection(DBConfig.CollectConString);
            cn.Open();
            string Sql = "select count(*) from " + Pre + "Collect_Rule where RuleName=@RuleName and ChannelID='" + Current.SiteID + "' and ID<>" + RuleID;
            SqlParameter param = new SqlParameter("@RuleName", SqlDbType.NVarChar, 50);
            param.Value = Name;
            int n = Convert.ToInt32(DbHelper.ExecuteScalar(cn, CommandType.Text, Sql, param));
            if (n > 0)
            {
                cn.Close();
                throw new Exception("规则名称重复");
            }
            SqlTransaction Trans = cn.BeginTransaction();
            try
            {
                Sql = "update " + Pre + "Collect_Rule set RuleName=@RuleName,OldContent=@OldContent,ReContent=@ReContent,IgnoreCase=@IgnoreCase where ChannelID='" + Current.SiteID + "' and ID=" + RuleID;
                SqlParameter[] parm = new SqlParameter[4];
                parm[0] = new SqlParameter("@RuleName", SqlDbType.NVarChar, 50);
                parm[0].Value = Name;
                parm[1] = new SqlParameter("@OldContent", SqlDbType.NVarChar, 100);
                parm[1].Value = OldStr;
                parm[2] = new SqlParameter("@ReContent", SqlDbType.NVarChar, 100);
                parm[2].Value = NewStr;
                parm[3] = new SqlParameter("@IgnoreCase", SqlDbType.Bit);
                parm[3].Value = IgnoreCase;
                DbHelper.ExecuteNonQuery(Trans, CommandType.Text, Sql, parm);
                Sql = "delete from " + Pre + "Collect_RuleApply where RuleID=" + RuleID;
                DbHelper.ExecuteNonQuery(Trans, CommandType.Text, Sql, null);
                if (AppSites != null && AppSites.Length > 0)
                {
                    foreach (int stid in AppSites)
                    {
                        Sql = "delete from " + Pre + "Collect_RuleApply where SiteID=" + stid;
                        DbHelper.ExecuteNonQuery(Trans, CommandType.Text, Sql, null);
                        Sql = "insert into " + Pre + "Collect_RuleApply(SiteID,RuleID,RefreshTime) values (" + stid + "," + RuleID + ",'" + DateTime.Now + "')";
                        DbHelper.ExecuteNonQuery(Trans, CommandType.Text, Sql, null);
                    }
                }
                Trans.Commit();
            }
            catch
            {
                Trans.Rollback();
                throw;
            }
            finally
            {
                if (cn != null && cn.State == ConnectionState.Open)
                    cn.Close();
            }
        }
        public DataTable GetRule(int id)
        {
            string Sql = "select * from " + Pre + "Collect_Rule where ChannelID='" + Current.SiteID + "' and ID=" + id;
            return DbHelper.ExecuteTable(DBConfig.CollectConString, CommandType.Text, Sql, null);
        }
        public DataTable SiteList()
        {
            string Sql = "select a.id,SiteName,RuleID from " + Pre + "Collect_Site a left outer join " + Pre + "Collect_RuleApply b on a.ID = b.SiteID where a.ChannelID='" + Current.SiteID + "'";
            return DbHelper.ExecuteTable(DBConfig.CollectConString, CommandType.Text, Sql, null);
        }
        public void NewsAdd(CollectNewsInfo newsinfo)
        {
            string Sql = "insert into " + Pre + "Collect_News ([Title],[Links],[Author],[Source],[Content],[AddDate],[ImagesCount],[SiteID],[History],[ReviewTF],[CollectTime],[ChannelID],[ClassID]) values (";
            Sql += "@Title,@Links,@Author,@Source,@Content,@AddDate,0,@SiteID,0,0,'" + DateTime.Now + "','" + Current.SiteID + "',@ClassID)";
            DbHelper.ExecuteNonQuery(DBConfig.CollectConString, CommandType.Text, Sql, GetNewsParams(newsinfo));
        }
        public bool TitleExist(string title)
        {
            string Sql = "select count(id) from " + Pre + "Collect_News where Title=@Title";
            SqlParameter Param = new SqlParameter("@Title", title);
            int n = Convert.ToInt32(DbHelper.ExecuteScalar(DBConfig.CollectConString, CommandType.Text, Sql, Param));
            if (n > 0)
                return true;
            else
                return false;
        }
        public DataTable GetNewsPage(int PageIndex, int PageSize, out int RecordCount, out int PageCount)
        {
            return DbHelper.ExecutePage(DBConfig.CollectConString, "a.ID,Title,AddDate,SiteName,History,CollectTime", Pre + "Collect_News a left join " + Pre + "Collect_Site b on a.SiteID=b.ID where a.ChannelID='" + Current.SiteID + "'", "a.ID", "Order by History asc,a.ID desc", PageIndex, PageSize, out RecordCount, out PageCount, null);
        }
        public void NewsDelete(string id)
        {
            string Sql = "Delete from " + Pre + "Collect_News where ChannelID='" + Current.SiteID + "'";
            if (id.Equals("0"))
                Sql += " and History=1";
            else
                Sql += " and ID in (" + id + ")";
            DbHelper.ExecuteNonQuery(DBConfig.CollectConString, CommandType.Text, Sql, null);
        }
        public CollectNewsInfo GetNews(int id)
        {
            CollectNewsInfo info = new CollectNewsInfo();
            string Sql = "select [Title],[Links],[SiteID],[Author],[Source],[AddDate],[Content],[CollectTime],[ClassID] from " + Pre + "Collect_News where ChannelID='" + Current.SiteID + "' and ID=" + id;
            IDataReader rd = DbHelper.ExecuteReader(DBConfig.CollectConString, CommandType.Text, Sql, null);
            if (rd.Read())
            {
                info.Title = rd.GetString(0);
                info.Links = rd.GetString(1);
                info.SiteID = rd.GetInt32(2);
                if (!rd.IsDBNull(3)) info.Author = rd.GetString(3);
                if (!rd.IsDBNull(4)) info.Source = rd.GetString(4);
                if (!rd.IsDBNull(5)) info.AddDate = rd.GetDateTime(5);
                if (!rd.IsDBNull(6)) info.Content = rd.GetString(6);
                info.CollectTime = rd.GetDateTime(7);
                info.ClassID = rd.GetString(8);
            }
            rd.Close();
            return info;
        }
        public void NewsUpdate(int id, CollectNewsInfo info)
        {
            string Sql = "update " + Pre + "Collect_News set [Title]=@Title,[Links]=@Links,[SiteID]=@SiteID,[Author]=@Author";
            Sql += ",[Source]=@Source,[AddDate]=@AddDate,[Content]=@Content,[ClassID]=@ClassID where ChannelID='" + Current.SiteID + "' and ID=" + id;
            DbHelper.ExecuteNonQuery(DBConfig.CollectConString, CommandType.Text, Sql, GetNewsParams(info));
        }
        private SqlParameter[] GetNewsParams(CollectNewsInfo info)
        {
            SqlParameter[] param = new SqlParameter[8];
            param[0] = new SqlParameter("@Title", SqlDbType.NVarChar, 100);
            param[0].Value = info.Title;
            param[1] = new SqlParameter("@Links", SqlDbType.NVarChar, 200);
            param[1].Value = info.Links;
            param[2] = new SqlParameter("@Author", SqlDbType.NVarChar, 100);
            param[2].Value = info.Author.Trim().Equals("") ? DBNull.Value : (object)info.Author;
            param[3] = new SqlParameter("@Source", SqlDbType.NVarChar, 100);
            param[3].Value = info.Source.Trim().Equals("") ? DBNull.Value : (object)info.Source;
            param[4] = new SqlParameter("@Content", SqlDbType.NText);
            param[4].Value = info.Content;
            param[5] = new SqlParameter("@AddDate", SqlDbType.DateTime);
            param[5].Value = info.AddDate.Year < 1753 ? DBNull.Value : (object)info.AddDate;
            param[6] = new SqlParameter("@SiteID", SqlDbType.Int);
            param[6].Value = info.SiteID;
            param[7] = new SqlParameter("@ClassID", SqlDbType.NVarChar, 12);
            param[7].Value = info.ClassID;
            return param;
        }
        #region 新闻入库
        ///////////////////////////新闻入库专用///////////////////////////////////////
        private SqlConnection connetion;
        private SqlConnection connetcms;
        private int nStoreSucceed = 0;
        private int nStoreFailed = 0;
        public void StoreNews(bool UnStore, int[] id, out int nSucceed, out int nFailed)
        {
            nSucceed = 0;
            nFailed = 0;
            connetion = new SqlConnection(DBConfig.CollectConString);
            connetcms = new SqlConnection(DBConfig.CmsConString);
            string Sql = "select a.ID,a.Title,a.Links,a.Author,a.Source,a.Content,a.AddDate,a.RecTF,a.TodayNewsTF,a.MarqueeNews";
            Sql += ",a.SBSNews,a.ReviewTF,a.ClassID,b.Audit from " + Pre + "Collect_News a inner join " + Pre + "Collect_Site b";
            Sql += " on a.SiteID=b.ID where a.ChannelID='" + Current.SiteID + "'";
            try
            {
                connetion.Open();
                connetcms.Open();
                if (UnStore)
                {
                    Sql += " and History=0";
                }
                else
                {
                    string strid = "";
                    for (int i = 0; i < id.Length; i++)
                    {
                        if (i > 0)
                            strid += ",";
                        strid += id[i].ToString();
                    }
                    Sql += " and a.id in (" + strid + ")";
                }
                StoreStep(Sql);
                nSucceed = nStoreSucceed;
                nFailed = nStoreFailed;
            }
            finally
            {
                StoreEnd();
            }
        }
        private void StoreStep(string Sql)
        {
            int IsAudit = 3;
            int AID = 0;
            object obj = DbHelper.ExecuteScalar(connetcms, CommandType.Text, "select max(id) from " + Pre + "news", null);
            if (obj != null && obj != DBNull.Value)
                AID = Convert.ToInt32(obj);
            AID++;
            DataTable dt = DbHelper.ExecuteTable(connetion, CommandType.Text, Sql, null);
            CollectNewsInfo Info = new CollectNewsInfo();
            foreach (DataRow r in dt.Rows)
            {
                try
                {
                    int id = Convert.ToInt32(r["id"]);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -