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

📄 pagecommon.cs

📁 c#的多线程采集源代码
💻 CS
📖 第 1 页 / 共 3 页
字号:
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.OleDb;

using DataEntity;
using System.IO;
using System.Net;

namespace DataFactory
{
    public class PageCommon
    {
        public PageCommon()
        { }

        #region 变量定义
        /// <summary>
        /// 数据库操作类
        /// </summary>
        DataFactory.DataOperater Run = new DataOperater();

        #region 实体类引用

        //private Gather_Article Article = new Gather_Article();
        //private Gather_BasicConfig BasicConfig = new Gather_BasicConfig();
        private Gather_DataSourceConfig DataSourceConfig = new Gather_DataSourceConfig();
        //private Gather_Message Message = new Gather_Message();
        //private Gather_OperationKind OperationKind = new Gather_OperationKind();
        private Gather_ParticularConfig ParticularConfig = new Gather_ParticularConfig();
        //private Gather_Period Period = new Gather_Period();
        

        #endregion

        #endregion 

        #region 信息分类配置函数
        public int AddMessage(Gather_Message entity1)  // 新增
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("INSERT INTO Gather_Message (MgPId,MgName,DataSourceIds,OrderId,Remark) Values (");
            builder.Append(entity1.MgPId + ",");
            builder.Append("'" + entity1.MgName.Replace("'","''") + "',");
            builder.Append("'" + entity1.DataSourceIds.Replace("'","''") + "',");
            builder.Append(entity1.OrderId + ",");
            builder.Append("'" + entity1.Remark.Replace("'","''")  + "'");
            builder.Append(")");
            try
            {
                return (Run.RunSql_Int(builder.ToString()));
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex);
            }
        }
        //说明: 右键点击信息分类父节点时,弹出窗体,增加信息分类。
        private bool Update(Gather_Message entity) // 修改
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("Update Gather_Message Set MgPId=" + entity.MgPId);
            builder.Append(",MgName='" + entity.MgName.Replace("'","''")  + "'");
            builder.Append(",DataSourceIds='" + entity.DataSourceIds.Replace("'","''")  + "'");
            builder.Append(",OrderId=" + entity.OrderId);
            builder.Append(",Remark='" + entity.Remark.Replace("'","''")  + "'");
            builder.Append(";RETURN 1");
            String sqlStr = builder.ToString();
            try
            {
                int rev = Run.RunSql_Int(sqlStr);
                if (rev == 1)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex);
            }
        }

        /// <summary>
        /// 删除信息类别的同时,遍历其下分的各个信息子类,同时删除信息子类的数据源和采集周期,此处需要修改
        /// </summary>
        /// <param name="intId"></param>
        /// <returns></returns>
        public int DeleteMessage(int intId)
        {
            //递归获取某类信息的所有子类MgIds
            string MgIds = intId.ToString() + ",";
            MgIds += GetMgIds(intId.ToString());

            string[] MgId = MgIds.Split(',');

            //根据信息类别编号,获取所有的信息类别对应的数据源编号DataSourceIds
            string DataSourceIds = string.Empty;

            for (int i = 0; i < MgId.Length - 1; i++)
            {
                DataSourceIds += this.GetMessageModel(int.Parse(MgId[i].ToString())).DataSourceIds.ToString();
            }

            if (DataSourceIds != "")
            {
                try
                {
                    //删除数据源编号DataSourceIds
                    int Num = Run.RunSql_Int("delete from Gather_DataSourceConfig where DataSourceId in (" + DataSourceIds.Substring(0, DataSourceIds.Length - 1) + ")");
                }
                catch(Exception ex)
                { 
                    throw new Exception(ex.Message, ex);
                }
            }

            //删除信息类别
            try
            {
                //删除数据源编号DataSourceIds
                int Num = Run.RunSql_Int("delete from Gather_Message where MgId in (" + MgIds.Substring(0, MgIds.Length - 1) + ")");
                return 1;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex);
            }
            return 0;
        }

        /// <summary>
        /// 递归获取某类信息的所有子类
        /// </summary>
        /// <param name="pNodeId"></param>
        /// <returns></returns>
        private string GetMgIds(string pNodeId)
        {
            string MgIds = string.Empty;

            DataSet ds = new DataSet();
            ds = this.GetMessage("MgPId=" + pNodeId);

            if (ds != null)
            {
                if (ds.Tables.Count > 0)
                {
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        foreach (DataRow myRow in ds.Tables[0].Rows)
                        {
                            MgIds += myRow["MgId"].ToString() + "," + GetMgIds(myRow["MgId"].ToString());
                        }
                    }
                }
            }
            return MgIds;
        }

        //说明:获取所有信息分类
        public DataSet GetMessage()                   // 获取所有信息分类
        {
            String sqlStr = "SELECT * FROM Gather_Message Order By MgId";

            DataSet ds = null;
            try
            {
                ds = Run.RunSql_DataSet(sqlStr);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex);
            }
            return ds;
        }
        //说明:获取信息分类信息
        public DataSet GetMessage(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT *  ");
            strSql.Append(" FROM Gather_Message ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append("  Order By MgId");
            return Run.RunSql_DataSet(strSql.ToString());
        }

        /// <summary>
        /// 获取所有父类信息类别
        /// </summary>
        /// <returns></returns>
        public DataSet GetMessageParent()
        {
            return GetMessage("MgPId=0");
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public int UpdateMessage(Gather_Message model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update Gather_Message set ");
            strSql.Append("MgPId=" + model.MgPId + ",");
            strSql.Append("MgName='" + model.MgName.Replace("'","''") + "',");
            strSql.Append("DataSourceIds='" + model.DataSourceIds.Replace("'","''") + "',");
            strSql.Append("OrderId=" + model.OrderId + ",");
            strSql.Append("Remark='" + model.Remark.Replace("'","''")  + "'");
            strSql.Append(" where MgId=" + model.MgId + "");
            return Run.RunSql_Int(strSql.ToString());
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Gather_Message GetMessageModel(int MgId)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * from Gather_Message ");
            strSql.Append(" where MgId=" + MgId);
            Gather_Message model = new Gather_Message();
            DataSet ds = Run.RunSql_DataSet(strSql.ToString());
            model.MgId = MgId;
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["MgPId"].ToString() != "")
                {
                    model.MgPId = int.Parse(ds.Tables[0].Rows[0]["MgPId"].ToString());
                }
                model.MgName = ds.Tables[0].Rows[0]["MgName"].ToString();
                model.DataSourceIds = ds.Tables[0].Rows[0]["DataSourceIds"].ToString();
                if (ds.Tables[0].Rows[0]["OrderId"].ToString() != "")
                {
                    model.OrderId = int.Parse(ds.Tables[0].Rows[0]["OrderId"].ToString());
                }
                model.Remark = ds.Tables[0].Rows[0]["Remark"].ToString();
                return model;
            }
            else
            {
                return null;
            }
        }        

        //说明:取得所有的信息分类集合。
        public DataSet GetDataSourceIds(int intId)  // 获取该信息类别下的所有数据源
        {
            OleDbDataReader oDr = null;
            String nDataSourceIds = ""; //该分类下的所有数据源ID
            try
            {
                String dscSqlstr = "SELECT DataSourceIds FROM Gather_Message Where MgId=" + intId;

                oDr = Run.RunSql_DataReader(dscSqlstr);
                if (oDr.Read())
                {
                    nDataSourceIds = oDr["DataSourceIds"].ToString();
                }
                oDr.Close();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex);
            }
            if (nDataSourceIds != "")
            {
                String sqlStr1 = "SELECT * FROM Gather_DataSourceConfig Where DataSourceId in (" + nDataSourceIds.Remove(nDataSourceIds.Length-1,1) + ") Order By OrderId";
                DataSet ds = null;
                try
                {
                    ds = Run.RunSql_DataSet(sqlStr1);
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message, ex);
                }

                return ds;
            }
            else
            {
                return null;
            }
        }

       
        #endregion

        #region Web 数据源配置
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public int DeleteDataSourceConfig(int DataSourceId)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete Gather_DataSourceConfig ");
            strSql.Append(" where DataSourceId=" + DataSourceId);
            return Run.RunSql_Int(strSql.ToString());
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public int UpdateDataSourceConfig(Gather_DataSourceConfig model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update Gather_DataSourceConfig set ");
            strSql.Append("DataSourceName='" + model.DataSourceName.Replace("'","''") + "',");
            strSql.Append("DataSourceUrl='" + model.DataSourceUrl.Replace("'","''") + "',");
            strSql.Append("DataSourceEncoding='" + model.DataSourceEncoding.Replace("'","''") + "',");
            strSql.Append("PeriodId=" + model.PeriodId + ",");
            strSql.Append("OrderId=" + model.OrderId + ",");
            strSql.Append("Remark='" + model.Remark.Replace("'","''")  + "'");
            strSql.Append(" where DataSourceId=" + model.DataSourceId + "");
            return Run.RunSql_Int(strSql.ToString());
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int AddDataSourceConfig(Gather_DataSourceConfig model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into Gather_DataSourceConfig(");
            strSql.Append("DataSourceName,DataSourceUrl,DataSourceEncoding,PeriodId,OrderId,Remark");
            strSql.Append(")");
            strSql.Append(" values (");
            strSql.Append("'" + model.DataSourceName.Replace("'","''") + "',");
            strSql.Append("'" + model.DataSourceUrl.Replace("'","''") + "',");
            strSql.Append("'" + model.DataSourceEncoding.Replace("'","''") + "',");
            strSql.Append("" + model.PeriodId + ",");
            strSql.Append("" + model.OrderId + ",");
            strSql.Append("'" + model.Remark.Replace("'","''")  + "'");
            strSql.Append(");select @@IDENTITY;");

            OleDbDataReader dr;
            dr = Run.RunSql_DataReader(strSql.ToString());

            int Id = 0;
            if (dr.Read())

⌨️ 快捷键说明

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