/*
 * 软件名称：化工产业数据库
 * 
 * 软件作者：随风缘(QQ：4259024,MAIL：jumbot114@126.com)
 * 
 */

using System;
using System.Data;
using System.Web;
using JumboTCMS.Utils;
using JumboTCMS.Common;
namespace JumboTCMS.Server.Plus
{
    public partial class _autotask : JumboTCMS.UI.BasicPage
    {
        private string _operType = string.Empty;
        private string _response = string.Empty;
        private string _spliter = "'";
        protected void Page_Load(object sender, EventArgs e)
        {
            Server.ScriptTimeout = 900;//默认脚本过期时间
            this._operType = q("oper");
            switch (this._operType)
            {
                case "DeleteNotice":
                    DeleteNotice();
                    break;
                case "DeleteUnactivedUser":
                    DeleteUnactivedUser();
                    break;
                case "DeleteCollectLogs":
                    DeleteCollectLogs();
                    break;
                case "DeleteUncheckArticle":
                    DeleteUncheckArticle();
                    break;
                case "AutoCollectNews":
                    AutoCollectNews();
                    break;
                default:
                    DefaultResponse();
                    break;
            }
            Response.Write(this._response);
        }
        private void DefaultResponse()
        {
            this._response = "未知操作";
        }
        private void DeleteNotice()
        {
            string _password = q("password");
            if (_password != System.Configuration.ConfigurationManager.AppSettings["AutoTask:Password"])
            {
                this._response = "密码错误";
                return;
            }
            doh.Reset();
            doh.ConditionExpress = "[State]=1 AND [ReadTime]<=" + _spliter + System.DateTime.Now.AddDays(-7).ToString("yyyy-MM-dd") + _spliter;
            int _doCount = doh.Delete("jcms_normal_user_notice");
            doh.Reset();
            doh.ConditionExpress = "[State]=1 AND [ReadTime]<=" + _spliter + System.DateTime.Now.AddDays(-30).ToString("yyyy-MM-dd") + _spliter;
            int _doCount2 = doh.Delete("jcms_normal_user_message");
            this._response = "有" + _doCount + "条已阅读的站内信被删除；有" + _doCount2 + "条已阅读的通知被删除";
        }
        private void DeleteUncheckArticle()
        {
            string _password = q("password");
            if (_password != System.Configuration.ConfigurationManager.AppSettings["AutoTask:Password"])
            {
                this._response = "密码错误";
                return;
            }
            doh.Reset();
            doh.ConditionExpress = "[IsPass]=0 AND [AddDate]<=" + _spliter + System.DateTime.Now.AddDays(-7).ToString("yyyy-MM-dd") + _spliter;
            int _doCount = doh.Delete("jcms_module_article");
            this._response = "有" + _doCount + "篇未审核的新闻被删除";
        }
        private void DeleteCollectLogs()
        {
            string _password = q("password");
            if (_password != System.Configuration.ConfigurationManager.AppSettings["AutoTask:Password"])
            {
                this._response = "密码错误";
                return;
            }
            doh.Reset();
            doh.ConditionExpress = "[EndTime]<=" + _spliter + System.DateTime.Now.AddDays(-14).ToString("yyyy-MM-dd") + _spliter;
            int _doCount = doh.Delete("jcms_module_article_colllogs");
            this._response = "有" + _doCount + "条采集日志被删除";
        }
        private void DeleteUnactivedUser()
        {
            string _password = q("password");
            if (_password != System.Configuration.ConfigurationManager.AppSettings["AutoTask:Password"])
            {
                this._response = "密码错误";
                return;
            }
            doh.Reset();
            doh.ConditionExpress = "[State]=0 AND [RegTime]<=" + _spliter + System.DateTime.Now.AddDays(-3).ToString("yyyy-MM-dd") + _spliter;
            int _doCount = doh.Delete("jcms_normal_user");
            this._response = "有" + _doCount + "个未激活的会员被删除";
        }
        private void AutoCollectNews()
        {
            string _password = q("password");
            if (_password != System.Configuration.ConfigurationManager.AppSettings["AutoTask:Password"])
            {
                this._response = "密码错误";
                return;
            }
            if (Str2Int(q("init")) == 1)
            {
                doh.Reset();
                doh.ConditionExpress = "1=1";
                doh.AddFieldItem("IsRunning", 0);
                doh.Update("jcms_module_article_collitem");

            }
            string CollitemName = "";
            this._response = CollectionNews("0", 0, "机器人", ref CollitemName);
        }
    }
}