site.cs

来自「最好用的站点内容管理系统 全部源代码都有」· CS 代码 · 共 339 行 · 第 1/2 页

CS
339
字号
//======================================================
//==     (c)2008 aspxcms inc by NeTCMS v1.0              ==
//==          Forum:bbs.aspxcms.com                   ==
//==         Website:www.aspxcms.com                  ==
//======================================================
using System;
using System.Text;
using System.Collections;
using System.Data;
using System.Data.SqlClient;
using NetCMS.DALFactory;
using NetCMS.Model;
using NetCMS.Common;
using NetCMS.DALProfile;
using NetCMS.Config;

namespace NetCMS.DALSQLServer
{
    public class Site : DbBase, ISite
    {
        private SqlTransaction Trans;
        public int Add(STSite site, string CurrentSiteID, out string SiteID)
        {
            SqlConnection cn = new SqlConnection(DBConfig.CmsConString);
            cn.Open();
            try
            {
                SiteID = Rand.Number(12);
                while (true)
                {
                    string SqlRptID = "select count(*) from " + Pre + "News_site where ChannelID='" + SiteID + "'";
                    int RcdCount = (int)DbHelper.ExecuteScalar(cn, CommandType.Text, SqlRptID, null);
                    if (RcdCount < 1)
                        break;
                    else
                        SiteID = NetCMS.Common.Rand.Number(12, true);
                }
                string SqlRptEnm = "select count(*) from " + Pre + "News_site where EName='" + site.EName + "'";
                int n = (int)DbHelper.ExecuteScalar(cn, CommandType.Text, SqlRptEnm, null);
                if (n > 0)
                {
                    throw new Exception("对不起,该英文名称已被别的频道所使用!");
                }
                string SqlRptCnm = "select count(*) from " + Pre + "News_site where CName='" + site.CName + "'";
                n = (int)DbHelper.ExecuteScalar(cn, CommandType.Text, SqlRptCnm, null);
                if (n > 0)
                {
                    throw new Exception("对不起,该中文名称已被别的频道所使用!");
                }
                string Sql = "insert into " + Pre + "News_site (";
                Sql += "ChannelID,CName,EName,ParentID,ChannCName,isLock,IsURL,Urladdress,DataLib,IndexTemplet,ClassTemplet,ReadNewsTemplet,SpecialTemplet,Domain,";
                Sql += "isCheck,Keywords,Descript,ContrTF,ShowNaviTF,UpfileType,UpfileSize,NaviContent,NaviPicURL,SaveType,PicSavePath,SaveFileType,";
                Sql += "SaveDirPath,SaveDirRule,SaveFileRule,NaviPosition,IndexEXName,ClassEXName,NewsEXName,SpecialEXName,classRefeshNum,infoRefeshNum,";
                Sql += "DelNum,SpecialNum,isDelPoint,Gpoint,iPoint,GroupNumber,CreatTime,SiteID";
                Sql += ") values ('" + SiteID + "',";
                Sql += "@CName,@EName,'0',@ChannCName,@isLock,@IsURL,@Urladdress,@DataLib,@IndexTemplet,@ClassTemplet,@ReadNewsTemplet,@SpecialTemplet,@Domain,";
                Sql += "@isCheck,@Keywords,@Descript,@ContrTF,@ShowNaviTF,@UpfileType,@UpfileSize,@NaviContent,@NaviPicURL,@SaveType,@PicSavePath,@SaveFileType,";
                Sql += "@SaveDirPath,@SaveDirRule,@SaveFileRule,@NaviPosition,@IndexEXName,@ClassEXName,@NewsEXName,@SpecialEXName,@classRefeshNum,@infoRefeshNum,";
                Sql += "@DelNum,@SpecialNum,@isDelPoint,@Gpoint,@iPoint,@GroupNumber";
                Sql += ",'" + DateTime.Now + "','" + CurrentSiteID + "')";
                Sql += ";SELECT @@IDENTITY";
                SqlParameter[] param = GetParameters(site);
                int result = Convert.ToInt32(DbHelper.ExecuteScalar(cn, CommandType.Text, Sql, param));
                return result;
            }
            finally
            {
                if (cn != null && cn.State == ConnectionState.Open)
                    cn.Close();
            }
        }
        public bool Delete(string id, out Exception e, out string[] DelFiles)
        {
            bool flag = false;
            DelFiles = null;
            e = null;
            id = "'" + id + "'";
            if (id.IndexOf(",") > 0)
                id = id.Replace(",", "','");
            SqlConnection cn = new SqlConnection(DBConfig.CmsConString);
            cn.Open();

            ArrayList FilePath = new ArrayList();
            FilePath.Clear();
            try
            {
                ArrayList NewsTable = this.GetNewsTables(cn);
                for (int i = 0; i < NewsTable.Count; i++)
                {
                    string SqlPath = "select SavePath,FileName,FileEXName from " + NewsTable[i].ToString() + " where SiteID in (" + id + ")";
                    IDataReader rd = DbHelper.ExecuteReader(cn, CommandType.Text, SqlPath, null);
                    while (rd.Read())
                    {
                        if (!rd.IsDBNull(0) && !rd.IsDBNull(1) && !rd.IsDBNull(2))
                        {
                            string filepath = rd.GetString(0) + rd.GetString(1) + rd.GetString(2);
                            FilePath.Add(filepath);
                        }
                    }
                    rd.Close();
                }
                DelFiles = (string[])FilePath.ToArray(typeof(string));
                Trans = cn.BeginTransaction();
                for (int i = 0; i < NewsTable.Count; i++)
                {
                    string SqlDelNews = "delete from " + NewsTable[i].ToString() + " where SiteID in (" + id + ")";
                    DbHelper.ExecuteNonQuery(Trans, CommandType.Text, SqlDelNews, null);
                }
                string SqlDelSpc = "delete from " + Pre + "News_special where SiteID in (" + id + ")";
                DbHelper.ExecuteNonQuery(Trans, CommandType.Text, SqlDelSpc, null);
                string SqlDelCls = "delete from " + Pre + "News_Class where SiteID in (" + id + ")";
                DbHelper.ExecuteNonQuery(Trans, CommandType.Text, SqlDelCls, null);
                string SqlDelSt = "delete from " + Pre + "News_site where ChannelID in (" + id + ")";
                DbHelper.ExecuteNonQuery(Trans, CommandType.Text, SqlDelSt, null);
                Trans.Commit();
                flag = true;
            }
            catch (Exception ex)
            {
                Trans.Rollback();
                e = ex;
                flag = false;
            }
            finally
            {
                if (cn != null && cn.State == ConnectionState.Open)
                    cn.Close();
            }
            return flag;
        }
        public void Update(int id, STSite site)
        {

            SqlConnection cn = new SqlConnection(DBConfig.CmsConString);
            cn.Open();
            try
            {
                string SqlEnm = "select count(*) from " + Pre + "News_site where Id<>" + id + " and EName='" + site.EName + "'";
                int n = (int)DbHelper.ExecuteScalar(cn, CommandType.Text, SqlEnm, null);
                if (n > 0)
                {
                    throw new Exception("对不起,该英文名称已被别的频道所使用");
                }
                string SqlCnm = "select count(*) from " + Pre + "News_site where Id<>" + id + " and CName='" + site.CName + "'";
                n = (int)DbHelper.ExecuteScalar(cn, CommandType.Text, SqlCnm, null);
                if (n > 0)
                {

                    throw new Exception("对不起,该中文名称已被别的频道所使用");
                }
                string Sql = "update " + Pre + "News_site set CName=@CName,ChannCName=@ChannCName,isLock=@isLock,IsURL=@IsURL,Urladdress=@Urladdress,";
                Sql += "DataLib=@DataLib,IndexTemplet=@IndexTemplet,ClassTemplet=@ClassTemplet,ReadNewsTemplet=@ReadNewsTemplet,SpecialTemplet=@SpecialTemplet,";
                Sql += "Domain=@Domain,isCheck=@isCheck,Keywords=@Keywords,Descript=@Descript,ContrTF=ContrTF,ShowNaviTF=@ShowNaviTF,";
                Sql += "UpfileType=@UpfileType,UpfileSize=@UpfileSize,NaviContent=@NaviContent,NaviPicURL=@NaviPicURL,SaveType=@SaveType,PicSavePath=@PicSavePath,";
                Sql += "SaveFileType=@SaveFileType,SaveDirPath=@SaveDirPath,SaveDirRule=@SaveDirRule,SaveFileRule=@SaveFileRule,NaviPosition=@NaviPosition,IndexEXName=@IndexEXName,";
                Sql += "ClassEXName=@ClassEXName,NewsEXName=@NewsEXName,SpecialEXName=@SpecialEXName,classRefeshNum=@classRefeshNum,infoRefeshNum=@infoRefeshNum,DelNum=@DelNum,";
                Sql += "SpecialNum=@SpecialNum,isDelPoint=@isDelPoint,Gpoint=@Gpoint,iPoint=@iPoint,GroupNumber=@GroupNumber where Id=" + id;
                SqlParameter[] param = GetParameters(site);
                DbHelper.ExecuteNonQuery(cn, CommandType.Text, Sql, param);
            }
            catch
            {
                if (cn != null && cn.State == ConnectionState.Open)
                    cn.Close();
                throw;
            }
        }
        public void Recyle(string id)
        {
            SqlConnection cn = new SqlConnection(DBConfig.CmsConString);

⌨️ 快捷键说明

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