📄 collect.cs
字号:
//======================================================
//== (c)2008 aspxcms inc by NeTCMS v1.0 ==
//== Forum:bbs.aspxcms.com ==
//== Website:www.aspxcms.com ==
//======================================================
using System;
using System.Text;
using System.Data;
using System.Text.RegularExpressions;
using System.Data.SqlClient;
using System.Collections;
using NetCMS.DALFactory;
using NetCMS.Model;
using NetCMS.Global;
using NetCMS.DALProfile;
using NetCMS.Config;
using NetCMS.Control;
namespace NetCMS.DALSQLServer
{
public class Collect : DbBase, ICollect
{
public DataTable GetFolderSitePage(int FolderID, int PageIndex, int PageSize, out int RecordCount, out int PageCount)
{
if (FolderID < 1)
{
SqlConnection cn = new SqlConnection(DBConfig.CollectConString);
cn.Open();
int nf = Convert.ToInt32(DbHelper.ExecuteScalar(cn, CommandType.Text, "select count(*) from " + Pre + "Collect_SiteFolder where ChannelID='" + Current.SiteID + "'", null));
int ns = Convert.ToInt32(DbHelper.ExecuteScalar(cn, CommandType.Text, "select count(*) from " + Pre + "Collect_Site where ChannelID='" + Current.SiteID + "' and (Folder is null or Folder=0)", null));
RecordCount = nf + ns;
if (RecordCount % PageSize == 0)
PageCount = RecordCount / PageSize;
else
PageCount = RecordCount / PageSize + 1;
if (PageIndex > PageCount)
PageIndex = PageCount;
if (PageIndex < 1)
PageIndex = 1;
int nStart = PageSize * (PageIndex - 1);
string Sql = "(select 0 as TP,ID,SiteFolder as SName,'' as objURL,'' as LockState from " + Pre + "Collect_SiteFolder where ChannelID='" + Current.SiteID + "') union (select 1 as TP,ID,SiteName as SName,objURL,case when LinkSetting is null or PagebodySetting is null or PageTitleSetting is null then '不可用' else '有效' end as LockState from " + Pre + "Collect_Site where ChannelID='" + Current.SiteID + "' and (Folder is null or Folder=0))";
SqlDataAdapter ap = new SqlDataAdapter(Sql, cn);
DataSet st = new DataSet();
ap.Fill(st, nStart, PageSize, "REST");
DataTable tb = st.Tables[0];
st.Dispose();
if (cn.State == ConnectionState.Open)
cn.Close();
return tb;
}
else
{
return DbHelper.ExecutePage(DBConfig.CollectConString, "1 as TP,ID,SiteName as SName,objURL,case when LinkSetting is null or PagebodySetting is null or PageTitleSetting is null then '不可用' else '有效' end as LockState", Pre + "Collect_Site where ChannelID='" + Current.SiteID + "' and Folder=" + FolderID, "ID", "Order by ID", PageIndex, PageSize, out RecordCount, out PageCount, null);
}
}
public void SiteCopy(int id)
{
SqlConnection cn = new SqlConnection(DBConfig.CollectConString);
cn.Open();
try
{
string Sql = "select * from " + Pre + "Collect_Site where ChannelID='" + Current.SiteID + "' and ID=" + id;
IDataReader rd = DbHelper.ExecuteReader(cn, CommandType.Text, Sql, null);
string snm = "", Column = "";
if (rd.Read())
{
snm = rd["SiteName"].ToString();
for (int i = 0; i < rd.FieldCount; i++)
{
string clnm = rd.GetName(i);
if (!(clnm.Equals("ID") || clnm.Equals("SiteName")))
{
Column += "," + clnm;
}
}
}
else
{
rd.Close();
throw new Exception("0%没有找到该记录");
}
rd.Close();
string snewnm = "复件 " + snm;
int n = 2;
while (Convert.ToInt32(DbHelper.ExecuteScalar(cn, CommandType.Text, "select count(*) from " + Pre + "Collect_Site where SiteName='" + snewnm + "'", null)) > 0)
{
snewnm = "复件(" + n + ") " + snm;
n++;
}
Sql = "insert into " + Pre + "Collect_Site (SiteName" + Column + ") select '" + snewnm + "' as NewName" + Column + " from " + Pre + "Collect_Site where ChannelID='" + Current.SiteID + "' and ID=" + id;
DbHelper.ExecuteNonQuery(cn, CommandType.Text, Sql, null);
}
finally
{
if (cn != null && cn.State == ConnectionState.Open)
cn.Close();
}
}
public void FolderCopy(int id)
{
SqlConnection cn = new SqlConnection(DBConfig.CollectConString);
cn.Open();
try
{
string Sql = "select SiteFolder from " + Pre + "Collect_SiteFolder where ChannelID='" + Current.SiteID + "' and ID=" + id;
object snm = DbHelper.ExecuteScalar(cn, CommandType.Text, Sql, null);
if (snm == null)
throw new Exception("没有找到相关目录的记录");
int n = 2;
string snewnm = "复件 " + snm;
/*
if (Regex.Match(snm,@"^复件\s").Success)
{
snewnm = "复件(" + n + ")" + snm;
n++;
}
else if (Regex.Match(snm, @"^复件(/d)").Success)
{
n = int.Parse(Regex.Match(snm, @"(?<=复件\()\d+?(?=\).+)").Value);
n++;
snewnm = "复件(" + n + ")" + snm;
n++;
}
else
{
snewnm = "复件 " + snm;
}
*/
while (Convert.ToInt32(DbHelper.ExecuteScalar(cn, CommandType.Text, "select count(*) from " + Pre + "Collect_SiteFolder where SiteFolder='" + snewnm + "'", null)) > 0)
{
snewnm = "复件(" + n + ") " + snm;
n++;
}
Sql = "insert into " + Pre + "Collect_SiteFolder (SiteFolder,SiteFolderDetail,ChannelID) select '" + snewnm + "' as NewName,SiteFolderDetail,ChannelID from " + Pre + "Collect_SiteFolder where ChannelID='" + Current.SiteID + "' and ID=" + id;
DbHelper.ExecuteNonQuery(cn, CommandType.Text, Sql, null);
}
finally
{
if (cn != null && cn.State == ConnectionState.Open)
cn.Close();
}
}
public void FolderDelete(int id)
{
SqlConnection cn = new SqlConnection(DBConfig.CollectConString);
cn.Open();
try
{
string Sql = "select count(*) from " + Pre + "Collect_Site where ChannelID='" + Current.SiteID + "' and Folder=" + id;
int n = Convert.ToInt32(DbHelper.ExecuteScalar(cn, CommandType.Text, Sql, null));
if (n > 0)
throw new Exception("该栏目下有站点,不能删除!");
Sql = "Delete from " + Pre + "Collect_SiteFolder where ChannelID='" + Current.SiteID + "' and ID=" + id;
DbHelper.ExecuteNonQuery(cn, CommandType.Text, Sql, null);
}
finally
{
if (cn != null && cn.State == ConnectionState.Open)
cn.Close();
}
}
public void SiteDelete(int id)
{
SqlConnection cn = new SqlConnection(DBConfig.CollectConString);
cn.Open();
SqlTransaction tran = cn.BeginTransaction();
try
{
string[] Sql = new string[2];
DbHelper.ExecuteNonQuery(tran, CommandType.Text, "Delete from " + Pre + "Collect_RuleApply where SiteID=" + id, null);
DbHelper.ExecuteNonQuery(tran, CommandType.Text, "Delete from " + Pre + "Collect_Site where ChannelID='" + Current.SiteID + "' and ID=" + id, null);
tran.Commit();
}
catch
{
tran.Rollback();
throw;
}
finally
{
if (cn != null && cn.State == ConnectionState.Open)
cn.Close();
}
}
public DataTable GetFolder(int id, bool all)
{
string Sql = "select ID,SiteFolder,SiteFolderDetail from " + Pre + "Collect_SiteFolder where ChannelID='" + Current.SiteID + "'";
if (!all)
Sql += " and ID=" + id;
return DbHelper.ExecuteTable(DBConfig.CollectConString, CommandType.Text, Sql, null);
}
public DataTable GetSite(int id)
{
string Sql = "select a.*,b.OldContent,b.ReContent,b.IgnoreCase from " + Pre + "Collect_Site a left join (" + Pre + "Collect_Rule b inner join " + Pre + "Collect_RuleApply c on b.ID=c.RuleID) on c.SiteID=a.ID where a.ChannelID='" + Current.SiteID + "' and a.ID=" + id;
return DbHelper.ExecuteTable(DBConfig.CollectConString, CommandType.Text, Sql, null);
}
public int SiteAdd(CollectSiteInfo st)
{
SqlConnection cn = new SqlConnection(DBConfig.CollectConString);
cn.Open();
try
{
string Sql = "select count(*) from " + Pre + "Collect_Site where ChannelID='" + Current.SiteID + "' and SiteName=@SiteName";
SqlParameter parm = new SqlParameter("@SiteName", SqlDbType.NVarChar, 50);
parm.Value = st.SiteName;
int n = Convert.ToInt32(DbHelper.ExecuteScalar(cn, CommandType.Text, Sql, parm));
if (n > 0)
{
cn.Close();
throw new Exception("采集站点名称重复!");
}
Sql = "insert into " + Pre + "Collect_Site (";
Sql += "SiteName,objURL,Folder,SaveRemotePic,Audit,IsReverse,IsAutoPicNews,TextTF";
Sql += ",IsStyle,IsDIV,IsA,IsClass,IsFont,IsSpan,IsObject,IsIFrame,IsScript,Encode,ClassID,ChannelID";
Sql += ",IsAutoCollect";
Sql += ") values (";
Sql += "@SiteName,@objURL,@Folder,@SaveRemotePic,@Audit,@IsReverse,@IsAutoPicNews,@TextTF";
Sql += ",@IsStyle,@IsDIV,@IsA,@IsClass,@IsFont,@IsSpan,@IsObject,@IsIFrame,@IsScript,@Encode,@ClassID,'" + Current.SiteID + "',";
Sql += "@IsAutoCollect)";
Sql += ";SELECT @@IDENTITY";
int result = Convert.ToInt32(DbHelper.ExecuteScalar(cn, CommandType.Text, Sql, GetParameters(st)));
return result;
}
finally
{
if (cn.State == ConnectionState.Open)
cn.Close();
}
}
public int FolderAdd(string Name, string Description)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -