예제 #1
0
파일: MainForm.cs 프로젝트: xiaoluoji/arcdb
 //点击复制发布规则按钮
 private void btnCopyPubConfig_Click(object sender, EventArgs e)
 {
     try
     {
         ListViewItem checkedItem = listViewPublish.CheckedItems[0];
         long         pubID       = long.Parse(checkedItem.SubItems[0].Text);
         string       pubName     = checkedItem.SubItems[1].Text;
         mySqlDB      myDB        = new mySqlDB(_coConnString);
         string       sResult     = "";
         int          count       = 0;
         long         LastInsertedId;
         string       sql = "insert into pub_config(pub_name,co_typeid,co_typename,pub_typeid,pub_typename,pub_nums,random_date_start,random_date_stop)";
         sql   = sql + " select pub_name,co_typeid,co_typename,pub_typeid,pub_typename,pub_nums,random_date_start,random_date_stop";
         sql   = sql + " from pub_config where id = '" + pubID.ToString() + "'";
         count = myDB.executeDMLSQL(sql, ref sResult);
         if (sResult == mySqlDB.SUCCESS && count == 1)
         {
             LastInsertedId = myDB.LastInsertedId;
             MessageBox.Show(string.Format("复制成功!复制的发布规则ID为:{0}", LastInsertedId));
             string sqlRename = "update pub_config set pub_name = '" + pubName + "复件'" + " where id ='" + LastInsertedId.ToString() + "'";
             count = myDB.executeDMLSQL(sqlRename, ref sResult);
             loadPubConfig();
         }
         else
         {
             MessageBox.Show(string.Format("复制失败:{0}", sResult));
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("请选择需要复制的发布规则项!");
     }
 }
예제 #2
0
        //完成发布任务后更新发布表中对应发布规则的已发布数量
        private void updatePublishState(ArticlePublish articlePublish)
        {
            int     pubID         = articlePublish.PubID;
            int     coTypeID      = articlePublish.CoTypeID;
            int     publishedNums = articlePublish.CurrentExportedArticles;
            mySqlDB coMyDB        = new mySqlDB(_coConnString);
            string  sResult       = "";
            int     counts        = 0;
            //更新发布配置表中的信息
            string sql = "update pub_config set published_nums=published_nums+'" + publishedNums.ToString() + "'";

            sql    = sql + ",pub_export_date = CURRENT_TIMESTAMP";
            sql    = sql + " where id = '" + pubID.ToString() + "'";
            counts = coMyDB.executeDMLSQL(sql, ref sResult);
            if (sResult != mySqlDB.SUCCESS)
            {
                List <Exception> pubException = articlePublish.PubException;
                Exception        mysqlError   = new Exception(sResult);
                pubException.Add(mysqlError);
            }
            //更新分类表中的统计信息,发不完以后对应的分类中的可发布数量应该减去当前的数量
            sql    = "update arc_type set unused_nums=unused_nums-'" + publishedNums.ToString() + "'";
            sql    = sql + " where tid='" + coTypeID.ToString() + "'";
            counts = coMyDB.executeDMLSQL(sql, ref sResult);
            if (sResult != mySqlDB.SUCCESS)
            {
                List <Exception> pubException = articlePublish.PubException;
                Exception        mysqlError   = new Exception(sResult);
                pubException.Add(mysqlError);
            }
        }
예제 #3
0
        private void initializeForm()
        {
            mySqlDB coMyDB  = new mySqlDB(_coConnString);
            string  sResult = "";
            int     counts  = 0;
            string  sql;

            listViewPubArticles.BeginUpdate();
            foreach (string item in _ListPubID)
            {
                int pubID = int.Parse(item);
                sql = "select * from pub_config where id='" + item + "'";
                List <Dictionary <string, object> > pubConfigRecords = coMyDB.GetRecords(sql, ref sResult, ref counts);
                if (sResult == mySqlDB.SUCCESS && counts > 0)
                {
                    _queuePubID.Enqueue(pubID);
                    string       pubName     = pubConfigRecords[0]["pub_name"].ToString();
                    string       coTypename  = pubConfigRecords[0]["co_typename"].ToString();
                    string       pubTypename = pubConfigRecords[0]["pub_typename"].ToString();
                    string       pubNums     = pubConfigRecords[0]["pub_nums"].ToString();
                    string[]     subItems    = new string[] { "待发布", item, pubName, coTypename, pubTypename, pubNums, "0", "0" };
                    ListViewItem listItem    = new ListViewItem(subItems);
                    listViewPubArticles.Items.Add(listItem);
                }
            }
            listViewPubArticles.EndUpdate();
            listViewPubArticles.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
            listViewPubArticles.GridLines = true;
        }
예제 #4
0
        //显示需要修改的发布规则的配置信息
        private void displayConfig()
        {
            mySqlDB myDB    = new mySqlDB(_coConnString);
            string  sResult = "";
            int     counts  = 0;
            string  sql     = @"select * from pub_config where id='" + _pubID.ToString() + "'";
            List <Dictionary <string, object> > pubConfigRecords = myDB.GetRecords(sql, ref sResult, ref counts);

            if (sResult == mySqlDB.SUCCESS)
            {
                Dictionary <string, object> pubConfig = pubConfigRecords[0];
                tboxPubName.Text           = pubConfig["pub_name"].ToString();
                tboxPubNums.Text           = pubConfig["pub_nums"].ToString();
                tboxCoTypeid.Text          = pubConfig["co_typeid"].ToString();
                tboxCoTypename.Text        = pubConfig["co_typename"].ToString();
                tboxPubTypeid.Text         = pubConfig["pub_typeid"].ToString();
                tboxPubTypename.Text       = pubConfig["pub_typename"].ToString();
                tboxPubFilterKeywords.Text = pubConfig["pub_filter_keywords"].ToString();
                tboxRandomDateStart.Text   = pubConfig["random_date_start"].ToString();
                tboxRandomDateStop.Text    = pubConfig["random_date_stop"].ToString();
                setVarValue();  //将控件中的值同步到对应的变量中
            }
            else
            {
                MessageBox.Show(string.Format("数据加载错误:{0}", sResult));
            }
        }
예제 #5
0
파일: MainForm.cs 프로젝트: xiaoluoji/arcdb
 //复制采集规则
 private void btnCopyCoconfig_Click(object sender, EventArgs e)
 {
     try
     {
         ListViewItem checkedItem = listViewCollect.CheckedItems[0];
         long         cid         = long.Parse(checkedItem.SubItems[0].Text);
         string       coName      = checkedItem.SubItems[1].Text;
         mySqlDB      myDB        = new mySqlDB(_coConnString);
         string       sResult     = "";
         int          count       = 0;
         long         LastInsertedId;
         string       sql = "insert into co_config(co_name,type_name,source_lang,source_site,co_offline,list_path,more_list_pages,xpath_arcurl_node,";
         sql   = sql + " xpath_title_node,xpath_content_node,arc_subpage_symbol,arc_subpage_startnum,sub_node_params,regex_params) ";
         sql   = sql + " select co_name,type_name,source_lang,source_site,co_offline,list_path,more_list_pages,xpath_arcurl_node,";
         sql   = sql + "xpath_title_node,xpath_content_node,arc_subpage_symbol,arc_subpage_startnum,sub_node_params,regex_params";
         sql   = sql + " from co_config where cid = '" + cid.ToString() + "'";
         count = myDB.executeDMLSQL(sql, ref sResult);
         if (sResult == mySqlDB.SUCCESS && count == 1)
         {
             LastInsertedId = myDB.LastInsertedId;
             MessageBox.Show(string.Format("复制成功!复制的采集规则ID为:{0}", LastInsertedId));
             string sqlRename = "update co_config set co_name = '" + coName + "复件'" + " where cid ='" + LastInsertedId.ToString() + "'";
             count = myDB.executeDMLSQL(sqlRename, ref sResult);
             loadCoConfig();
         }
         else
         {
             MessageBox.Show(string.Format("复制失败:{0}", sResult));
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("请选择需要复制的采集规则项!");
     }
 }
예제 #6
0
        //成功发布一篇文章后,更新采集文章库中对应文章的信息
        private bool updateCoArticle(long aid, long cmsAid)
        {
            bool    isCorrectUpdated = true;
            mySqlDB myDB             = new mySqlDB(_coConnString);
            string  sResult          = "";
            int     counts           = 0;
            string  sql = "update arc_contents set cms_aid='" + cmsAid.ToString() + "' where aid='" + aid.ToString() + "'";

            counts = myDB.executeDMLSQL(sql, ref sResult);
            if (sResult != mySqlDB.SUCCESS || counts == 0)
            {
                isCorrectUpdated = false;
                Exception ex = new Exception(sResult);
                ex.Data.Add("错误信息", "发布文章后更新cms_aid字段信息错误");
                ex.Data.Add("采集文章ID", aid);
                ex.Data.Add("发布文章ID", cmsAid);
            }
            sql    = "update arc_contents set usedby_pc='yes' where aid='" + aid.ToString() + "'";
            counts = myDB.executeDMLSQL(sql, ref sResult);
            if (sResult != mySqlDB.SUCCESS || counts == 0)
            {
                isCorrectUpdated = false;
                Exception ex = new Exception(sResult);
                ex.Data.Add("错误信息", "发布文章后更新usedby_pc字段信息错误");
                ex.Data.Add("采集文章ID", aid);
                ex.Data.Add("发布文章ID", cmsAid);
            }
            return(isCorrectUpdated);
        }
예제 #7
0
        //随机获取一条符合发布条件的文章记录
        private Dictionary <string, object> getOneRecord()
        {
            List <Dictionary <string, object> > dbResult;
            mySqlDB myDB     = new mySqlDB(_coConnString);
            string  sResult  = "";
            int     counts   = 0;
            string  sql      = "select aid,litpic,title,source_site,description,content from arc_contents where type_id='" + _coTypeid.ToString() + "' and usedby_pc='no'";
            string  countSql = "select count(aid) from arc_contents where type_id='" + _coTypeid.ToString() + "' and usedby_pc='no'";

            if (_pubFilterKeywords.Length > 0)
            {
                sql      = sql + " and (title like '%" + _pubFilterKeywords[0] + "%'";
                countSql = countSql + " and (title like '%" + _pubFilterKeywords[0] + "%'";
                for (int i = 1; i < _pubFilterKeywords.Length; i++)
                {
                    sql      = sql + " or title like '%" + _pubFilterKeywords[i] + "%'";
                    countSql = countSql + " or title like '%" + _pubFilterKeywords[i] + "%'";
                }
                sql      = sql + ")";
                countSql = countSql + ")";
            }
            int startPosition = getRandomStartPosition(countSql);

            if (startPosition != 0)
            {
                sql = sql + " order by aid limit " + startPosition.ToString() + ",1";
            }
            else
            {
                sql = sql + " order by aid limit 1";
            }
            dbResult = myDB.GetRecords(sql, ref sResult, ref counts);
            if (sResult == mySqlDB.SUCCESS && counts > 0)
            {
                return(dbResult[0]);
            }
            else
            {
                if (sResult != mySqlDB.SUCCESS)
                {
                    Exception ex = new Exception(sResult);
                    ex.Data.Add("错误信息", "从指定采集分类中获取未发布文章错误");
                    ex.Data.Add("采集分类ID", _coTypeid);
                    _pubExceptions.Add(ex);
                }
                if (counts == 0)
                {
                    Exception ex = new Exception(sResult);
                    ex.Data.Add("提示信息", "指定采集分类中已没有可发布的文章");
                    ex.Data.Add("采集分类ID", _coTypeid);
                    _cancelException = ex;
                }
                return(null);
            }
        }
예제 #8
0
파일: MainForm.cs 프로젝트: xiaoluoji/arcdb
        private void setPubArticleDescription(object state)
        {
            _coConnString  = GetCoConnString();
            _pubConnString = GetPubConnString();
            int finishedArticles = 0;

            if (_pubConnString != "" && _coConnString != "")
            {
                System.Threading.Timer timer = new System.Threading.Timer(
                    //timeCB,
                    //PrintTime,      //TimerCallBack委托对象
                    delegate {
                    this.Invoke((Action) delegate { lblFinishedGetPubArcDescCount.Text = string.Format("{0}", finishedArticles); });
                },
                    //(object state)=>labTime.Text = string.Format("Time is {0}\n", DateTime.Now.ToLongTimeString()),
                    null,        //想传入的参数 (null表示没有参数)
                    0,           //在开始之前,等待多长时间(以毫秒为单位)
                    1000);       //每次调用的间隔时间(以毫秒为单位)

                mySqlDB coMyDB  = new mySqlDB(_coConnString);
                string  sResult = "";
                int     counts  = 0;
                string  sql     = "select aid,cms_aid,description from arc_contents where description is not null and cms_aid is not null";
                List <Dictionary <string, object> > coRecords = coMyDB.GetRecords(sql, ref sResult, ref counts);
                if (sResult == mySqlDB.SUCCESS && counts > 0)
                {
                    foreach (Dictionary <string, object> item in coRecords)
                    {
                        string  cms_aid     = item["cms_aid"].ToString();
                        string  description = item["description"].ToString();
                        mySqlDB pubMyDB     = new mySqlDB(_pubConnString);
                        sql    = "update " + _pubTablePrename + "_news set description='" + description + "' where id='" + cms_aid + "'";
                        counts = pubMyDB.executeDMLSQL(sql, ref sResult);
                        if (counts > 0 && sResult == mySqlDB.SUCCESS)
                        {
                            finishedArticles += 1;
                        }
                        else
                        {
                            tboxArctoolOutput.AppendText(string.Format("错误信息:{0}\n", sResult));
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("请正确配置发布数据库参数!");
            }
        }
예제 #9
0
        //从数据库中加载配置
        private void displayConfig()
        {
            mySqlDB myDB    = new mySqlDB(_connString);
            string  sResult = "";
            int     counts  = 0;
            string  sql     = @"select * from co_config where cid = '" + _cid.ToString() + "'";
            List <Dictionary <string, object> > coConfigRecords = myDB.GetRecords(sql, ref sResult, ref counts);

            if (sResult == mySqlDB.SUCCESS)
            {
                Dictionary <string, object> coConfig = coConfigRecords[0];
                tboxCoName.Text        = coConfig["co_name"].ToString();
                cboxCoSource_Lang.Text = coConfig["source_lang"].ToString();
                cboxCoSource_Site.Text = coConfig["source_site"].ToString();
                cboxCoTypeName.Text    = coConfig["type_name"].ToString();
                if (coConfig["co_offline"].ToString() == "yes")
                {
                    rbtnCo_Offline_yes.Checked = true;
                }
                else
                {
                    rbtnCo_Offline_no.Checked = true;
                }
                tboxCoListPath.Text         = coConfig["list_path"].ToString();
                tboxCoStartPageNumber.Text  = coConfig["start_page_number"].ToString();
                tboxCoStopPageNumber.Text   = coConfig["stop_page_number"].ToString();
                tboxMoreListPages.Text      = coConfig["more_list_pages"].ToString();
                tboxXpathArcurlNode.Text    = coConfig["xpath_arcurl_node"].ToString();
                tboxXpathTitleNode.Text     = coConfig["xpath_title_node"].ToString();
                tboxXpathContentNode.Text   = coConfig["xpath_content_node"].ToString();
                tboxArcSubpageSymbol.Text   = coConfig["arc_subpage_symbol"].ToString();
                tboxArcSubpageStartNum.Text = coConfig["arc_subpage_startnum"].ToString();
                tboxSubNodeParams.Text      = coConfig["sub_node_params"].ToString();
                tboxRegexParams.Text        = coConfig["regex_params"].ToString();

                setVarValue();  //将控件中的值同步到对应的变量中
            }
            else
            {
                MessageBox.Show(string.Format("数据加载错误:{0}", sResult));
            }
        }
예제 #10
0
        //加载发布分类信息
        private void loadPubTypeInfo(string searchCondition = "")
        {
            listViewPubTypeinfo.Items.Clear();
            mySqlDB myDB    = new mySqlDB(_pubConnString);
            string  sResult = "";
            int     counts  = 0;
            string  sql     = "select catid,catname,items from " + _pubTablePrename + "_category where parentid <> 0 and modelid=1";

            if (searchCondition != "")
            {
                sql = sql + " and catname like '%" + searchCondition + "%'";
            }
            List <Dictionary <string, object> > listPubTypeinfo = myDB.GetRecords(sql, ref sResult, ref counts);

            if (sResult == mySqlDB.SUCCESS && counts > 0)
            {
                listViewPubTypeinfo.BeginUpdate();
                foreach (Dictionary <string, object> item in listPubTypeinfo)
                {
                    List <string> subItems = new List <string>();
                    foreach (KeyValuePair <string, object> kvp in item)
                    {
                        subItems.Add(kvp.Value.ToString());
                    }
                    ListViewItem listItem = new ListViewItem(subItems.ToArray());
                    listViewPubTypeinfo.Items.Add(listItem);
                }
                listViewPubTypeinfo.EndUpdate();
                listViewPubTypeinfo.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
            }
            else
            {
                if (counts == 0)
                {
                    MessageBox.Show(string.Format("未找到搜索的分类!"));
                }
                else
                {
                    MessageBox.Show(string.Format("加载采集分类数据出错!:{0}", sResult));
                }
            }
        }
예제 #11
0
        //查寻符合发布条件的文章总数,根据文章总数随机一个从1到总数的数,作为获取一条记录的起始位置
        private int getRandomStartPosition(string sql)
        {
            int startPosition = 0;
            int recordCounts  = 0;
            List <Dictionary <string, object> > dbResult;
            mySqlDB myDB    = new mySqlDB(_coConnString);
            string  sResult = "";
            int     counts  = 0;

            dbResult = myDB.GetRecords(sql, ref sResult, ref counts);
            if (sResult == mySqlDB.SUCCESS && counts > 0)
            {
                recordCounts = int.Parse(dbResult[0]["count(aid)"].ToString());
                if (recordCounts != 0)
                {
                    Random rnd = new Random();
                    startPosition = rnd.Next(1, recordCounts);
                }
            }
            return(startPosition);
        }
예제 #12
0
        //随机获取一条符合发布条件的文章记录
        private Dictionary <string, object> getOneRecord()
        {
            List <Dictionary <string, object> > dbResult;
            mySqlDB myDB    = new mySqlDB(_coConnString);
            string  sResult = "";
            int     counts  = 0;
            //查寻符合发布条件的文章记录,满足条件必须包括 is_edited字段为yes, usedby_pc字段为no, cms_typeid字段不能为null, 如果传入参数aid,则查寻指定aid的文章
            string sql = "select aid,litpic,title,type_id,cms_typeid,source_site,description,keywords,content from arc_contents where is_edited='yes' and usedby_pc='no' and cms_typeid<>'null'";

            if (_aid != 0)
            {
                sql = sql + " and aid='" + _aid.ToString() + "'";
            }
            else
            {
                sql = sql + " order by aid limit 1";
            }

            dbResult = myDB.GetRecords(sql, ref sResult, ref counts);
            if (sResult == mySqlDB.SUCCESS && counts > 0)
            {
                return(dbResult[0]);
            }
            else
            {
                if (sResult != mySqlDB.SUCCESS)
                {
                    Exception ex = new Exception(sResult);
                    ex.Data.Add("错误信息", "获取未发布文章错误");
                    _pubExceptions.Add(ex);
                }
                if (counts == 0)
                {
                    Exception ex = new Exception(sResult);
                    ex.Data.Add("提示信息", "没有可发布的文章");
                    _cancelException = ex;
                }
                return(null);
            }
        }
예제 #13
0
        //导出一篇文章到CMS中
        private bool exportOneRecord(Dictionary <string, object> coArticle, ref long cmsAid)
        {
            cmsAid = -1;                            //news表中插入记录后的ID值
            string typeid          = "0";
            string title           = coArticle["title"].ToString();
            string litpic          = coArticle["litpic"].ToString();
            string sourceSite      = coArticle["source_site"].ToString();
            string content         = coArticle["content"].ToString();
            string description     = coArticle["description"].ToString();
            string url             = "";
            string status          = "99";
            string sysadd          = "1";
            string username        = "******";
            long   pubDateUnixtime = getRandomPubDate();
            //将文章信息插入到news表中
            mySqlDB pubMyDB = new mySqlDB(_pubConnString);
            string  sResult = "";
            int     counts  = 0;
            string  sql     = "insert into " + _pubTablePrename + "_news(catid,typeid,title,thumb,description,url,status,sysadd,username,inputtime,updatetime)";

            sql    = sql + " values ('" + _pubTypeid + "'";
            sql    = sql + ",'" + typeid + "'";
            sql    = sql + ",'" + mySqlDB.EscapeString(title) + "'";
            sql    = sql + ",'" + litpic + "'";
            sql    = sql + ",'" + mySqlDB.EscapeString(description) + "'";
            sql    = sql + ",'" + url + "'";
            sql    = sql + ",'" + status + "'";
            sql    = sql + ",'" + sysadd + "'";
            sql    = sql + ",'" + username + "'";
            sql    = sql + ",'" + pubDateUnixtime + "'";
            sql    = sql + ",'" + pubDateUnixtime + "')";
            counts = pubMyDB.executeDMLSQL(sql, ref sResult);
            if (sResult == mySqlDB.SUCCESS && counts > 0)
            {
                cmsAid = pubMyDB.LastInsertedId;
            }
            else
            {
                Exception ex = new Exception(sResult);
                ex.Data.Add("错误信息", "发布文章至news表错误");
                _pubExceptions.Add(ex);
                return(false);
            }
            //将相应的文章数据插入到news_data表中
            string maxcharperpage = "3000";  //文章按多少字分页
            string paginationtype = "1";     //表示文章自动分页
            string groupids_view  = "";
            string template       = "";

            sql    = "insert into " + _pubTablePrename + "_news_data(id,content,groupids_view,paginationtype,maxcharperpage,template,copyfrom)";
            sql    = sql + " values ('" + cmsAid.ToString() + "'";
            sql    = sql + ",'" + mySqlDB.EscapeString(content) + "'";
            sql    = sql + ",'" + groupids_view + "'";
            sql    = sql + ",'" + paginationtype + "'";
            sql    = sql + ",'" + maxcharperpage + "'";
            sql    = sql + ",'" + template + "'";
            sql    = sql + ",'" + mySqlDB.EscapeString(sourceSite) + "')";
            counts = pubMyDB.executeDMLSQL(sql, ref sResult);
            if (sResult == mySqlDB.SUCCESS && counts > 0)
            {
            }
            else
            {
                Exception ex = new Exception(sResult);
                ex.Data.Add("错误信息", "发布文章至news_data表错误");
                ex.Data.Add("发布文章ID", cmsAid);
                _pubExceptions.Add(ex);
                return(false);
            }
            //将相应的文章数据插入到hits表中
            string hitsid = "c-1-" + cmsAid.ToString();

            sql    = "INSERT IGNORE INTO " + _pubTablePrename + "_hits(hitsid,catid) Values('" + hitsid + "','" + _pubTypeid + "')";
            counts = pubMyDB.executeDMLSQL(sql, ref sResult);
            if (sResult == mySqlDB.SUCCESS && counts > 0)
            {
                return(true);
            }
            else
            {
                Exception ex = new Exception(sResult);
                ex.Data.Add("错误信息", "发布文章-添加点击数记录至hits表错误");
                ex.Data.Add("发布文章ID", cmsAid);
                _pubExceptions.Add(ex);
            }
            return(true);
        }
예제 #14
0
 private void displayArticles(int typeID, string searchArcTitle = "", int displayCount = 0, bool onlyUnEdited = false)
 {
     if (typeID != 0)
     {
         mySqlDB myDB    = new mySqlDB(_coConnString);
         string  sResult = "";
         int     counts  = 0;
         string  sql     = "select aid,pic_count,is_edited,title from arc_contents where usedby_pc='no' and  type_id='" + typeID.ToString() + "'";
         sql = sql + " and is_display='yes'";
         if (onlyUnEdited)
         {
             sql = sql + " and is_edited='no'";
         }
         if (searchArcTitle != "")
         {
             sql = sql + " and title like '%" + searchArcTitle + "%'";
         }
         //sql = sql + " order by aid DESC";
         if (displayCount != 0)
         {
             sql = sql + " limit " + displayCount.ToString();
         }
         else
         {
             sql = sql + " limit 100";
         }
         List <Dictionary <string, object> > listArticles = myDB.GetRecords(sql, ref sResult, ref counts);
         listViewArticles.Items.Clear();
         if (sResult == mySqlDB.SUCCESS && counts > 0)
         {
             listViewArticles.BeginUpdate();
             foreach (Dictionary <string, object> item in listArticles)
             {
                 List <string> subItems = new List <string>();
                 foreach (KeyValuePair <string, object> kvp in item)
                 {
                     subItems.Add(kvp.Value.ToString());
                 }
                 ListViewItem listItem = new ListViewItem(subItems.ToArray());
                 listViewArticles.Items.Add(listItem);
             }
             listViewArticles.EndUpdate();
             listViewArticles.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
         }
         else
         {
             if (counts == 0)
             {
                 //MessageBox.Show("当前分类没有可发布文章!");
             }
             else
             {
                 MessageBox.Show("获取文章出错!");
             }
         }
     }
     else
     {
         MessageBox.Show("请选择文章分类!");
     }
 }
예제 #15
0
        //导出一篇文章到CMS中
        private bool exportOneRecord(Dictionary <string, object> coArticle, ref long cmsAid)
        {
            cmsAid = -1;                            //news表中插入记录后的ID值
            string        title       = coArticle["title"].ToString();
            string        litpic      = coArticle["litpic"].ToString();
            string        sourceSite  = coArticle["source_site"].ToString();
            string        content     = coArticle["content"].ToString();
            string        keywords    = coArticle["keywords"].ToString();
            string        description = coArticle["description"].ToString();
            string        username    = "******";
            List <string> pageContent = new List <string>();
            Regex         regSplit    = new Regex("<hr.*?class=[^>]*>");

            //获取文章内容字段,处理文章分页信息
            if (regSplit.IsMatch(content))
            {
                pageContent = getPageContent(content);
            }
            //获取发布时间
            long pubDateUnixtime = 0;

            if (_randomDateStart != "" && _randomDateStop != "")
            {
                pubDateUnixtime = getRandomPubDate();
            }
            else
            {
                DateTime currentTime = DateTime.Now;
                pubDateUnixtime = getUnixTime(currentTime);
            }

            //创建mysql连接对象
            mySqlDB pubMyDB = new mySqlDB(_pubConnString);
            string  sResult = "";
            int     counts  = 0;

            //如果发布CMS为phpcms
            if (_cmsType == "phpcms")
            {
                string url    = "";
                string status = "99";
                string sysadd = "1";
                string typeid = "0";
                if (keywords != "")
                {
                    keywords = keywords.Replace(",", " ");
                }
                //将文章信息插入到news表中
                string sql = "insert into " + _pubTablePrename + "_news(catid,typeid,title,thumb,keywords,description,url,status,sysadd,username,inputtime,updatetime)";
                sql    = sql + " values ('" + _pubTypeid + "'";
                sql    = sql + ",'" + typeid + "'";
                sql    = sql + ",'" + mySqlDB.EscapeString(title) + "'";
                sql    = sql + ",'" + litpic + "'";
                sql    = sql + ",'" + mySqlDB.EscapeString(keywords) + "'";
                sql    = sql + ",'" + mySqlDB.EscapeString(description) + "'";
                sql    = sql + ",'" + url + "'";
                sql    = sql + ",'" + status + "'";
                sql    = sql + ",'" + sysadd + "'";
                sql    = sql + ",'" + username + "'";
                sql    = sql + ",'" + pubDateUnixtime + "'";
                sql    = sql + ",'" + pubDateUnixtime + "')";
                counts = pubMyDB.executeDMLSQL(sql, ref sResult);
                if (sResult == mySqlDB.SUCCESS && counts > 0)
                {
                    cmsAid = pubMyDB.LastInsertedId;
                }
                else
                {
                    Exception ex = new Exception(sResult);
                    ex.Data.Add("错误信息", "发布文章至news表错误");
                    _pubExceptions.Add(ex);
                    return(false);
                }
                //将相应的文章数据插入到news_data表中
                string maxcharperpage = "3000";  //文章按多少字分页
                string paginationtype = "1";     //表示文章自动分页
                string groupids_view  = "";
                string template       = "";
                if (pageContent.Count > 1)
                {
                    paginationtype = "2";  //表示手工分页
                    content        = "";
                    for (int i = 0; i < pageContent.Count - 1; i++)
                    {
                        content += pageContent[i];
                        content += "<br /> [page] <br />";
                    }
                    content += pageContent[pageContent.Count - 1];
                }
                sql    = "insert into " + _pubTablePrename + "_news_data(id,content,groupids_view,paginationtype,maxcharperpage,template,copyfrom)";
                sql    = sql + " values ('" + cmsAid.ToString() + "'";
                sql    = sql + ",'" + mySqlDB.EscapeString(content) + "'";
                sql    = sql + ",'" + groupids_view + "'";
                sql    = sql + ",'" + paginationtype + "'";
                sql    = sql + ",'" + maxcharperpage + "'";
                sql    = sql + ",'" + template + "'";
                sql    = sql + ",'" + mySqlDB.EscapeString(sourceSite) + "')";
                counts = pubMyDB.executeDMLSQL(sql, ref sResult);
                if (sResult == mySqlDB.SUCCESS && counts > 0)
                {
                }
                else
                {
                    Exception ex = new Exception(sResult);
                    ex.Data.Add("错误信息", "发布文章至news_data表错误");
                    ex.Data.Add("发布文章ID", cmsAid);
                    _pubExceptions.Add(ex);
                    return(false);
                }
                //将相应的文章数据插入到hits表中
                string hitsid = "c-1-" + cmsAid.ToString();
                sql    = "INSERT IGNORE INTO " + _pubTablePrename + "_hits(hitsid,catid) Values('" + hitsid + "','" + _pubTypeid + "')";
                counts = pubMyDB.executeDMLSQL(sql, ref sResult);
                if (sResult == mySqlDB.SUCCESS && counts > 0)
                {
                    return(true);
                }
                else
                {
                    Exception ex = new Exception(sResult);
                    ex.Data.Add("错误信息", "发布文章-添加点击数记录至hits表错误");
                    ex.Data.Add("发布文章ID", cmsAid);
                    _pubExceptions.Add(ex);
                }
                //更新分类表中栏目文章数统计字段
                sql = "update " + _pubTablePrename + "_category set items=items+1 where catid='" + _pubTypeid.ToString() + "'";
                if (sResult != mySqlDB.SUCCESS)
                {
                    Exception ex = new Exception(sResult);
                    ex.Data.Add("错误信息", "更新分类表中items字段和allitems字段错误");
                    ex.Data.Add("发布分类ID", _pubTypeid);
                    _pubExceptions.Add(ex);
                }
            }

            //如果发布CMS为phpcms
            if (_cmsType == "akcms")
            {
                int pagenum = 0;
                if (pageContent.Count > 1)
                {
                    pagenum = pageContent.Count - 1;
                }
                string sql = "insert into " + _pubTablePrename + "_items(category,module,title,picture,pagenum,keywords,digest,editor,dateline,lastupdate)";
                sql    = sql + " values ('" + _pubTypeid + "'";
                sql    = sql + ",'1'";
                sql    = sql + ",'" + mySqlDB.EscapeString(title) + "'";
                sql    = sql + ",'" + litpic + "'";
                sql    = sql + ",'" + pagenum.ToString() + "'";
                sql    = sql + ",'" + mySqlDB.EscapeString(keywords) + "'";
                sql    = sql + ",'" + mySqlDB.EscapeString(description) + "'";
                sql    = sql + ",'" + username + "'";
                sql    = sql + ",'" + pubDateUnixtime + "'";
                sql    = sql + ",'" + pubDateUnixtime + "')";
                counts = pubMyDB.executeDMLSQL(sql, ref sResult);
                if (sResult == mySqlDB.SUCCESS && counts > 0)
                {
                    cmsAid = pubMyDB.LastInsertedId;
                }
                else
                {
                    Exception ex = new Exception(sResult);
                    ex.Data.Add("错误信息", "发布文章至news表错误");
                    _pubExceptions.Add(ex);
                    return(false);
                }
                //将相应的文章数据插入到news_data表中
                if (pagenum == 0)  //如果文章没分页
                {
                    sql    = "insert into " + _pubTablePrename + "_texts(itemid,text,page)";
                    sql    = sql + " values ('" + cmsAid.ToString() + "'";
                    sql    = sql + ",'" + mySqlDB.EscapeString(content) + "'";
                    sql    = sql + ",'" + pagenum.ToString() + "')";
                    counts = pubMyDB.executeDMLSQL(sql, ref sResult);
                    if (sResult == mySqlDB.SUCCESS && counts > 0)
                    {
                    }
                    else
                    {
                        Exception ex = new Exception(sResult);
                        ex.Data.Add("错误信息", "发布文章至texts表错误");
                        ex.Data.Add("发布文章ID", cmsAid);
                        _pubExceptions.Add(ex);
                        return(false);
                    }
                }
                else  //如果文章有分页
                {
                    int count = 0;
                    foreach (string pageText in pageContent)
                    {
                        sql    = "insert into " + _pubTablePrename + "_texts(itemid,text,page)";
                        sql    = sql + " values ('" + cmsAid.ToString() + "'";
                        sql    = sql + ",'" + mySqlDB.EscapeString(pageText) + "'";
                        sql    = sql + ",'" + count.ToString() + "')";
                        counts = pubMyDB.executeDMLSQL(sql, ref sResult);
                        if (sResult == mySqlDB.SUCCESS && counts > 0)
                        {
                        }
                        else
                        {
                            Exception ex = new Exception(sResult);
                            ex.Data.Add("错误信息", "发布文章至texts表错误");
                            ex.Data.Add("发布文章ID", cmsAid);
                            _pubExceptions.Add(ex);
                            return(false);
                        }
                        count++;  //分页编号+1
                    }
                }
                //更新栏目文章计数
                sql    = "update " + _pubTablePrename + "_categories set items=items+1,allitems=allitems+1 where id='" + _pubTypeid.ToString() + "'";
                counts = pubMyDB.executeDMLSQL(sql, ref sResult);
                if (sResult != mySqlDB.SUCCESS)
                {
                    Exception ex = new Exception(sResult);
                    ex.Data.Add("错误信息", "更新分类表中items字段和allitems字段错误");
                    ex.Data.Add("发布分类ID", _pubTypeid);
                    _pubExceptions.Add(ex);
                }
            }

            return(true);
        }
예제 #16
0
        //保存配置到数据库中
        private void saveConfig()
        {
            mySqlDB myDB    = new mySqlDB(_connString);
            string  sResult = "";
            int     counts  = 0;
            string  sql     = "";

            setVarValue();  //先将变量中的值更新成当前控件中的值
            bool validateResult = validateCoConfig();

            if (!validateResult)
            {
                MessageBox.Show("必填项未填写完整或未填写正确,请检查表达是否填写完整并正确填写!");
            }
            else
            {
                if (_cid != -1)  //如果传入cid不等于-1说明是更新配置
                {
                    sql = "update co_config set co_name = '" + _coName + "'";
                    sql = sql + ", type_name = '" + _typeName + "'";
                    sql = sql + ", source_lang = '" + _sourceLang + "'";
                    sql = sql + ", source_site = '" + mySqlDB.EscapeString(_sourceSite) + "'";
                    sql = sql + ", co_offline = '" + _coOffline + "'";
                    sql = sql + ", list_path = '" + mySqlDB.EscapeString(_listPath) + "'";
                    sql = sql + ", start_page_number = '" + _startPageNumber + "'";
                    sql = sql + ", stop_page_number = '" + _stopPageNumber + "'";
                    sql = sql + ", xpath_arcurl_node = '" + mySqlDB.EscapeString(_xpathArcurlNode) + "'";
                    sql = sql + ", xpath_title_node = '" + mySqlDB.EscapeString(_xpathTitleNode) + "'";
                    sql = sql + ", xpath_content_node = '" + mySqlDB.EscapeString(_xpathContentNode) + "'";
                    sql = sql + ",up_time=current_timestamp";
                    sql = sql + ", more_list_pages = '" + mySqlDB.EscapeString(_moreListPages) + "'";
                    sql = sql + ", sub_node_params = '" + mySqlDB.EscapeString(_subNodeParams) + "'";
                    sql = sql + ", regex_params = '" + mySqlDB.EscapeString(_regexParams) + "'";

                    if (_arcSubPageSymbol != "")
                    {
                        sql = sql + ", arc_subpage_symbol = '" + mySqlDB.EscapeString(_arcSubPageSymbol) + "'";
                    }
                    if (_arcSubPageStartNum != "")
                    {
                        sql = sql + ", arc_subpage_startnum = '" + _arcSubPageStartNum + "'";
                    }

                    sql = sql + " where cid = '" + _cid.ToString() + "'";

                    try
                    {
                        counts = myDB.executeDMLSQL(sql, ref sResult);
                        if (counts == 1 && sResult == mySqlDB.SUCCESS)
                        {
                            MessageBox.Show("成功更新采集规则!");
                        }
                        else
                        {
                            MessageBox.Show(string.Format("更新采集规则失败!错误信息:{0}", sResult));
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(string.Format("修改规则出错! 请检查数据格式是否正确!错误信息:", ex.Message));
                    }
                }
                else   //增加新配置
                {
                    sql = "insert into co_config (co_name,type_name,source_lang,source_site,co_offline,list_path,start_page_number,stop_page_number,xpath_arcurl_node,xpath_title_node,xpath_content_node";
                    string valueOption = "";
                    if (_arcSubPageSymbol != "")
                    {
                        sql         = sql + ",arc_subpage_symbol";
                        valueOption = valueOption + ",'" + mySqlDB.EscapeString(_arcSubPageSymbol) + "'";
                    }
                    if (_arcSubPageStartNum != "")
                    {
                        sql         = sql + ", arc_subpage_startnum";
                        valueOption = valueOption + ",'" + _arcSubPageStartNum + "'";
                    }
                    if (_moreListPages != "")
                    {
                        sql         = sql + ",more_list_pages";
                        valueOption = valueOption + ",'" + mySqlDB.EscapeString(_moreListPages) + "'";
                    }
                    if (_subNodeParams != "")
                    {
                        sql         = sql + ",sub_node_params";
                        valueOption = valueOption + ",'" + mySqlDB.EscapeString(_subNodeParams) + "'";
                    }
                    if (_regexParams != "")
                    {
                        sql         = sql + ",regex_params";
                        valueOption = valueOption + ",'" + mySqlDB.EscapeString(_regexParams) + "'";
                    }
                    sql = sql + ") values ('" + _coName + "'";
                    sql = sql + ",'" + _typeName + "'";
                    sql = sql + ",'" + _sourceLang + "'";
                    sql = sql + ",'" + mySqlDB.EscapeString(_sourceSite) + "'";
                    sql = sql + ",'" + _coOffline + "'";
                    sql = sql + ",'" + mySqlDB.EscapeString(_listPath) + "'";
                    sql = sql + ",'" + _startPageNumber + "'";
                    sql = sql + ",'" + _stopPageNumber + "'";
                    sql = sql + ",'" + mySqlDB.EscapeString(_xpathArcurlNode) + "'";
                    sql = sql + ",'" + mySqlDB.EscapeString(_xpathTitleNode) + "'";
                    sql = sql + ",'" + mySqlDB.EscapeString(_xpathContentNode) + "'";
                    sql = sql + valueOption + ")";
                    try
                    {
                        counts = myDB.executeDMLSQL(sql, ref sResult);
                        if (counts == 1 && sResult == mySqlDB.SUCCESS)
                        {
                            _cid = myDB.LastInsertedId;
                            MessageBox.Show(string.Format("成功添加新采集规则!新规则ID:{0}", _cid));
                        }
                        else
                        {
                            MessageBox.Show(string.Format("添加采集规则失败!错误信息:{0}", sResult));
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(string.Format("添加新规则错误! 请检查数据格式是否正确!错误信息:", ex.Message));
                    }
                } //添加规则结束
            }     //判断表单数据是否填写完整结束
        }
예제 #17
0
파일: MainForm.cs 프로젝트: xiaoluoji/arcdb
        //生成文章点击数数据
        private void createHitsRecords(object state)
        {
            _pubConnString = GetPubConnString();
            int finishedArticles = 0;

            if (_pubConnString != "")
            {
                System.Threading.Timer timer = new System.Threading.Timer(
                    //timeCB,
                    //PrintTime,      //TimerCallBack委托对象
                    delegate
                {
                    this.Invoke((Action) delegate { lblFinishedCreateHitsRecordsCount.Text = string.Format("{0}", finishedArticles); });
                },
                    //(object state)=>labTime.Text = string.Format("Time is {0}\n", DateTime.Now.ToLongTimeString()),
                    null,        //想传入的参数 (null表示没有参数)
                    0,           //在开始之前,等待多长时间(以毫秒为单位)
                    1000);       //每次调用的间隔时间(以毫秒为单位)            }
                mySqlDB pubMydb = new mySqlDB(_pubConnString);
                string  sResult = "";
                int     counts  = 0;
                string  sql     = "select count(id) from " + _pubTablePrename + "_news";
                List <Dictionary <string, object> > dbResult = new List <Dictionary <string, object> >();
                dbResult = pubMydb.GetRecords(sql, ref sResult, ref counts);
                if (sResult == mySqlDB.SUCCESS && counts > 0)
                {
                    int articleCounts = int.Parse(dbResult[0]["count(id)"].ToString());
                    tboxArctoolOutput.AppendText(string.Format("文章总数:{0}\n", articleCounts));
                    int startPosition = 0;
                    int onceNums      = 1000;
                    if (articleCounts > 0)
                    {
                        while (startPosition < articleCounts)
                        {
                            sql      = "select id,catid from " + _pubTablePrename + "_news limit " + startPosition.ToString() + "," + onceNums.ToString();
                            dbResult = pubMydb.GetRecords(sql, ref sResult, ref counts);
                            if (sResult == mySqlDB.SUCCESS && counts > 0)
                            {
                                foreach (Dictionary <string, object> item in dbResult)
                                {
                                    string id     = item["id"].ToString();
                                    string catid  = item["catid"].ToString();
                                    string hitsid = "c-1-" + id.ToString();
                                    sql    = "INSERT IGNORE INTO " + _pubTablePrename + "_hits(hitsid,catid) Values('" + hitsid + "','" + catid + "')";
                                    counts = pubMydb.executeDMLSQL(sql, ref sResult);
                                    if (sResult == mySqlDB.SUCCESS && counts > 0)
                                    {
                                        finishedArticles += 1;
                                    }
                                    else
                                    {
                                        tboxArctoolOutput.AppendText(string.Format("插入hits表数据出错或记录已存在!sql语句:{0}  错误信息:{1}\n", sql, sResult));
                                    }
                                }
                                startPosition += onceNums;
                            }
                            else
                            {
                                tboxArctoolOutput.AppendText("CMS数据库获取文章ID和分类ID出错!终止\n");
                                break;
                            }
                        }
                    }
                }
            }
        }
예제 #18
0
파일: MainForm.cs 프로젝트: xiaoluoji/arcdb
 //加载采集规则
 private void loadCoConfig()
 {
     _coConnString = GetCoConnString();
     if (_coConnString != "")
     {
         listViewCollect.Items.Clear();
         mySqlDB myDB    = new mySqlDB(_coConnString);
         string  sResult = "";
         int     counts  = 0;
         string  filter  = getCoFilter();
         string  sql     = @"select cid,co_name,type_name,source_lang,source_site,up_time,co_time,co_nums from co_config";
         if (filter != "")
         {
             sql += filter;
         }
         List <Dictionary <string, object> > coConfigRecords = myDB.GetRecords(sql, ref sResult, ref counts);
         if (sResult == mySqlDB.SUCCESS)
         {
             listViewCollect.GridLines = true;
             listViewCollect.BeginUpdate();
             foreach (Dictionary <string, object> item in coConfigRecords)
             {
                 List <string> subItems = new List <string>();
                 foreach (KeyValuePair <string, object> kvp in item)
                 {
                     if (kvp.Key == "up_time" || kvp.Key == "co_time")
                     {
                         string fullDate = kvp.Value.ToString();
                         try  //尝试将完整时间格式转换成短日期格式
                         {
                             if (fullDate == "")
                             {
                                 subItems.Add(fullDate);
                             }
                             else
                             {
                                 DateTime dt        = DateTime.Parse(fullDate);
                                 string   shortDate = dt.ToShortDateString();
                                 subItems.Add(shortDate);
                             }
                         }
                         catch (Exception)   //如果转换失败,则继续用完整日期格式
                         {
                             subItems.Add(fullDate);
                         }
                     }
                     else
                     {
                         subItems.Add(kvp.Value.ToString());
                     }
                 }
                 ListViewItem listItem = new ListViewItem(subItems.ToArray());
                 listViewCollect.Items.Add(listItem);
             }
             listViewCollect.EndUpdate();
             listViewCollect.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
         }
         else
         {
             MessageBox.Show(string.Format("加载数据出错!:{0}", sResult));
         }
     }
 }
예제 #19
0
파일: MainForm.cs 프로젝트: xiaoluoji/arcdb
        private void getCoArticleDescription(object state)
        {
            _coConnString = GetCoConnString();
            int descriptionLength = 120;
            int finishedArticles  = 0;

            if (int.TryParse(tboxCoArcDescLength.Text, out descriptionLength))
            {
                descriptionLength = int.Parse(tboxCoArcDescLength.Text);
            }
            else
            {
                MessageBox.Show("文章概要长度值不是整数,使用默认长度120!");
            }
            if (_coConnString != "")
            {
                System.Threading.Timer timer = new System.Threading.Timer(
                    //timeCB,
                    //PrintTime,      //TimerCallBack委托对象
                    delegate {
                    this.Invoke((Action) delegate { lblFinishedGetCoArcDescCounts.Text = string.Format("{0}", finishedArticles); });
                },
                    //(object state)=>labTime.Text = string.Format("Time is {0}\n", DateTime.Now.ToLongTimeString()),
                    null,        //想传入的参数 (null表示没有参数)
                    0,           //在开始之前,等待多长时间(以毫秒为单位)
                    1000);       //每次调用的间隔时间(以毫秒为单位)
                mySqlDB coMyDB  = new mySqlDB(_coConnString);
                string  sResult = "";
                int     counts  = 0;
                string  sql     = "select aid,title,content from arc_contents where description is null limit 1";
                List <Dictionary <string, object> > articleRecord = new List <Dictionary <string, object> >();
                articleRecord = coMyDB.GetRecords(sql, ref sResult, ref counts);
                while (sResult == mySqlDB.SUCCESS && counts > 0)
                {
                    string aid        = articleRecord[0]["aid"].ToString();
                    string title      = articleRecord[0]["title"].ToString();
                    string arcContent = articleRecord[0]["content"].ToString();
                    HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
                    try
                    {
                        doc.LoadHtml(arcContent);
                        string arcContentPiece = doc.DocumentNode.InnerText;
                        arcContentPiece = arcContentPiece.Replace("\r\n\t", "");
                        arcContentPiece = arcContentPiece.Replace("\r\n", "");
                        arcContentPiece = arcContentPiece.Replace("\r", "");
                        arcContentPiece = arcContentPiece.Replace("\n", "");
                        arcContentPiece = arcContentPiece.Replace("\t", "");
                        arcContentPiece = arcContentPiece.Replace("&nbsp;", "");
                        arcContentPiece = arcContentPiece.Replace("amp;", "");
                        arcContentPiece = arcContentPiece.Replace(" ", "");
                        if (arcContentPiece.Length > 200)
                        {
                            arcContentPiece = arcContentPiece.Substring(0, 200);
                        }
                        string description = ArcTool.GetDescription(arcContentPiece, descriptionLength);
                        string updateSql   = "update arc_contents set description='" + description + "' where aid='" + aid + "'";
                        counts = coMyDB.executeDMLSQL(updateSql, ref sResult);
                        if (sResult == mySqlDB.SUCCESS && counts > 0)
                        {
                            finishedArticles += 1;
                        }
                        else
                        {
                            tboxArctoolOutput.AppendText(string.Format("错误信息:{0}\n", sResult));
                        }
                    }
                    catch (Exception ex)
                    {
                        tboxArctoolOutput.AppendText(string.Format("错误信息:{0}: {1} : {2} \n", aid, title, ex.Message));
                    }
                    //再次从数据里获取一篇文章
                    articleRecord = coMyDB.GetRecords(sql, ref sResult, ref counts);
                }
            }
            else
            {
                MessageBox.Show("请正确配置采集数据库参数!");
            }
        }
예제 #20
0
파일: MainForm.cs 프로젝트: xiaoluoji/arcdb
 //加载采集规则方法
 private void loadPubConfig()
 {
     _coConnString  = GetCoConnString();
     _pubConnString = GetPubConnString();
     if (_coConnString != "" && _pubConnString != "")
     {
         listViewPublish.Items.Clear();
         mySqlDB myDB    = new mySqlDB(_coConnString);
         string  sResult = "";
         int     counts  = 0;
         string  filter  = getPubFilter();
         string  sql     = @"select id,pub_name,co_typename,arc_type.unused_nums,pub_typename,pub_nums,published_nums,pub_add_date,pub_export_date from pub_config left join arc_type on pub_config.co_typeid=arc_type.tid";
         if (filter != "")
         {
             sql += filter;
         }
         List <Dictionary <string, object> > pubConfigRecords = myDB.GetRecords(sql, ref sResult, ref counts);
         if (sResult == mySqlDB.SUCCESS)
         {
             listViewPublish.GridLines = true;
             listViewPublish.BeginUpdate();
             foreach (Dictionary <string, object> item in pubConfigRecords)
             {
                 List <string> subItems = new List <string>();
                 foreach (KeyValuePair <string, object> kvp in item)
                 {
                     if (kvp.Key == "pub_add_date" || kvp.Key == "pub_export_date")
                     {
                         string fullDate = kvp.Value.ToString();
                         try  //尝试将完整时间格式转换成短日期格式
                         {
                             if (fullDate == "")
                             {
                                 subItems.Add(fullDate);
                             }
                             else
                             {
                                 DateTime dt        = DateTime.Parse(fullDate);
                                 string   shortDate = dt.ToShortDateString();
                                 subItems.Add(shortDate);
                             }
                         }
                         catch (Exception)   //如果转换失败,则继续用完整日期格式
                         {
                             subItems.Add(fullDate);
                         }
                     }
                     else
                     {
                         if (kvp.Key == "unused_nums")
                         {
                             string unUsedNums = kvp.Value.ToString();
                             if (unUsedNums == "")
                             {
                                 unUsedNums = "0";
                             }
                             subItems.Add(unUsedNums);
                         }
                         else
                         {
                             subItems.Add(kvp.Value.ToString());
                         }
                     }
                 }
                 ListViewItem listItem = new ListViewItem(subItems.ToArray());
                 listViewPublish.Items.Add(listItem);
             }
             listViewPublish.EndUpdate();
             listViewPublish.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
         }
         else
         {
             MessageBox.Show(string.Format("加载数据出错!:{0}", sResult));
         }
     }
     else
     {
         MessageBox.Show("请正确填写采集数据库和发布数据库配置信息!");
     }
 }
예제 #21
0
        //保存配置 或者 新增配置
        private void saveConfig()
        {
            mySqlDB myDB    = new mySqlDB(_coConnString);
            string  sResult = "";
            int     counts  = 0;
            string  sql     = "";

            setVarValue();  //先将变量中的值更新成当前控件中的值
            bool validateResult = validatePubConfig();

            if (!validateResult)
            {
                MessageBox.Show("必填项未填写完整或未填写正确,请检查表达是否填写完整并正确填写!");
            }
            else
            {
                if (_pubID != -1)
                {
                    sql = "update pub_config set pub_name = '" + _pubName + "'";
                    sql = sql + ", co_typeid = '" + _coTypeid + "'";
                    sql = sql + ", co_typename = '" + _coTypename + "'";
                    sql = sql + ", pub_typeid = '" + _pubTypeid + "'";
                    sql = sql + ", pub_typename = '" + _pubTypename + "'";
                    sql = sql + ", pub_filter_keywords = '" + _pubFilterKeywords + "'";
                    sql = sql + ", pub_nums = '" + _pubNums + "'";
                    sql = sql + ", random_date_start = '" + _randomDateStart + "'";
                    sql = sql + ", random_date_stop = '" + _randomDateStop + "'";
                    sql = sql + ",pub_add_date=current_timestamp";
                    sql = sql + " where id = '" + _pubID.ToString() + "'";
                    try
                    {
                        counts = myDB.executeDMLSQL(sql, ref sResult);
                        if (counts == 1 && sResult == mySqlDB.SUCCESS)
                        {
                            MessageBox.Show("成功更新发布规则!");
                        }
                        else
                        {
                            MessageBox.Show(string.Format("修改发布规则失败!错误信息:{0}", sResult));
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(string.Format("修改规则出错! 请检查数据格式是否正确!错误信息:", ex.Message));
                    }
                }
                else
                {
                    sql = "insert into pub_config(pub_name,co_typeid,co_typename,pub_typeid,pub_typename,pub_filter_keywords,pub_nums,random_date_start,random_date_stop)";
                    sql = sql + " values ('" + _pubName + "'";
                    sql = sql + ",'" + _coTypeid + "'";
                    sql = sql + ",'" + _coTypename + "'";
                    sql = sql + ",'" + _pubTypeid + "'";
                    sql = sql + ",'" + _pubTypename + "'";
                    sql = sql + ",'" + _pubFilterKeywords + "'";
                    sql = sql + ",'" + _pubNums + "'";
                    sql = sql + ",'" + _randomDateStart + "'";
                    sql = sql + ",'" + _randomDateStop + "')";
                    try
                    {
                        counts = myDB.executeDMLSQL(sql, ref sResult);
                        if (counts == 1 && sResult == mySqlDB.SUCCESS)
                        {
                            _pubID = (int)myDB.LastInsertedId;
                            MessageBox.Show(string.Format("成功添加新发布规则!新规则ID:{0}", _pubID));
                        }
                        else
                        {
                            MessageBox.Show(string.Format("添加发布规则失败!错误信息:{0}", sResult));
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(string.Format("添加新规则错误! 请检查数据格式是否正确!错误信息:", ex.Message));
                    }
                }
            }
        }
예제 #22
0
        private void startOneTask(object state)
        {
            int pubID = getOnePubID();

            if (pubID != -1)
            {
                mySqlDB coMyDB  = new mySqlDB(_coConnString);
                string  sResult = "";
                int     counts  = 0;
                string  sql     = "select * from pub_config where id='" + pubID.ToString() + "'";
                List <Dictionary <string, object> > pubConfigRecords = coMyDB.GetRecords(sql, ref sResult, ref counts);
                if (sResult == mySqlDB.SUCCESS && counts > 0)
                {
                    Dictionary <string, object> dicConfig   = pubConfigRecords[0];
                    Dictionary <string, string> checkFields = new Dictionary <string, string>();
                    checkFields.Add("id", dicConfig["id"].ToString());
                    checkFields.Add("pub_name", dicConfig["pub_name"].ToString());
                    checkFields.Add("co_typeid", dicConfig["co_typeid"].ToString());
                    checkFields.Add("co_typename", dicConfig["co_typename"].ToString());
                    checkFields.Add("pub_typeid", dicConfig["pub_typeid"].ToString());
                    checkFields.Add("pub_typename", dicConfig["pub_typename"].ToString());
                    checkFields.Add("pub_nums", dicConfig["pub_nums"].ToString());
                    checkFields.Add("random_date_start", dicConfig["random_date_start"].ToString());
                    checkFields.Add("random_date_stop", dicConfig["random_date_stop"].ToString());
                    if (!validatePubConfig(checkFields))
                    {
                        tboxErrorOutput.AppendText(string.Format("采集规则: (ID:{0}) 配置检查错误,请重新编辑采集规则项,确认必填项数据都已正确填写! \n", pubID));
                    }
                    else
                    {
                        int      coTypeid          = int.Parse(dicConfig["co_typeid"].ToString());
                        int      pubTypeid         = int.Parse(dicConfig["pub_typeid"].ToString());
                        int      pubNums           = int.Parse(dicConfig["pub_nums"].ToString());
                        string   randomDateStart   = dicConfig["random_date_start"].ToString();
                        string   randomDateStop    = dicConfig["random_date_stop"].ToString();
                        string[] pubFilterKeywords = new string[0];
                        if (dicConfig["pub_filter_keywords"].ToString() != "")
                        {
                            pubFilterKeywords = dicConfig["pub_filter_keywords"].ToString().Split('|');
                        }
                        ArticlePublish          articlePublish    = new ArticlePublish(pubID, _coConnString, _pubConnString, _pubTablePrename, coTypeid, pubTypeid, pubNums, pubFilterKeywords, randomDateStart, randomDateStop);
                        CancellationTokenSource cancelTokenSource = new CancellationTokenSource();
                        articlePublish.CancelTokenSource = cancelTokenSource;
                        //articlePublish.ProcessPublishArticles();
                        //创建发布任务的监控时钟,并且开始记时
                        Stopwatch sw = new Stopwatch();
                        sw.Start();
                        //通过委托代理异步执行发布任务
                        PublishProcess publishProcesArticles = new PublishProcess(ProcessPublishArticles);
                        publishProcesArticles.BeginInvoke(articlePublish, ProcessPublishArticlesComplete, null);


                        //创建新的Dictionary集合,其中包括采集对象,包括用来监控耗时的Stopwatch对象
                        Dictionary <string, object> oneCollect = new Dictionary <string, object>();
                        oneCollect.Add("publish", articlePublish);
                        oneCollect.Add("watch", sw);

                        //将当前采集对象添加到全局用来监控采集进程的采集对象集合中。
                        bool addResult = false;
                        do
                        {
                            addResult = _articlePubCollections.TryAdd(pubID, oneCollect);
                        } while (!addResult);
                    }
                }
                else
                {
                    tboxErrorOutput.AppendText(string.Format("发布规则(ID:{0}) 读取数据库采集配置错误!:{1} \n", pubID, sResult));
                }
            }
        }
예제 #23
0
파일: MainForm.cs 프로젝트: xiaoluoji/arcdb
 //点击删除发布规则按钮
 private void btnDelPubConfig_Click(object sender, EventArgs e)
 {
     try
     {
         ListView.CheckedListViewItemCollection checkedItems = listViewPublish.CheckedItems;
         if (checkedItems.Count > 0)
         {
             List <long> pubIDList   = new List <long>();
             string      pubIDString = "";
             foreach (ListViewItem item in checkedItems)
             {
                 long pubID = long.Parse(item.SubItems[0].Text);
                 pubIDList.Add(pubID);
                 pubIDString = pubIDString + pubID.ToString() + ", ";
             }
             string showMessage = "确认删除以下" + checkedItems.Count.ToString() + "项发布规则项?: " + pubIDString.TrimEnd(',', ' ');
             if (MessageBox.Show(showMessage, "确认删除", MessageBoxButtons.YesNo) == DialogResult.Yes)
             {
                 mySqlDB myDB               = new mySqlDB(_coConnString);
                 string  sResult            = "";
                 int     counts             = 0;
                 string  deletedItems       = "";
                 string  unDeletedItems     = "";
                 string  errorMessage       = "";
                 string  messageAfterDelete = "";
                 foreach (long id in pubIDList)
                 {
                     string sql = "delete from pub_config where id = '" + id.ToString() + "'";
                     try
                     {
                         counts = myDB.executeDMLSQL(sql, ref sResult);
                         if (sResult == mySqlDB.SUCCESS && counts == 1)
                         {
                             deletedItems = deletedItems + id.ToString() + ", ";
                         }
                         else
                         {
                             unDeletedItems = unDeletedItems + id.ToString() + ", ";
                         }
                     }
                     catch (Exception exDb)
                     {
                         errorMessage   = errorMessage + exDb.Message + "\n";
                         unDeletedItems = unDeletedItems + ", ";
                     }
                 }
                 if (deletedItems != "")
                 {
                     messageAfterDelete = "成功删除以下规则:" + deletedItems.TrimEnd(',', ' ') + "\n";
                     if (unDeletedItems != "")
                     {
                         messageAfterDelete = messageAfterDelete + "未成功删除项:" + unDeletedItems.TrimEnd(',', ' ') + "\n";
                     }
                     messageAfterDelete = messageAfterDelete + errorMessage;
                 }
                 else if (unDeletedItems != "")
                 {
                     messageAfterDelete = messageAfterDelete + "未成功删除项:" + unDeletedItems.TrimEnd(',', ' ') + "\n" + errorMessage;
                 }
                 MessageBox.Show(messageAfterDelete);
                 loadPubConfig();
             }
         }
         else
         {
             MessageBox.Show("未选中任何采集规则,请选择要删除的规则项!");
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(string.Format("删除出错!{0}", ex.Message));
     }
 }