using Mall.Common.Plugin;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using System.Text;
using Mall.WindowsService.Helper;
namespace Mall.WindowsService
{
    partial class WindowsService : ServiceBase
    {
        System.Timers.Timer timer1;  //计时器
        private System.Timers.Timer timer2;  //订单取消计时器
        private System.Timers.Timer timer3;  //订单自动收货计时器
        private System.Timers.Timer timer4;  //七天自动取消下线计时器
        private System.Timers.Timer timer5;  //定时上架和下架
        private System.Timers.Timer timer6;  //资讯定时上架和下架
        private System.Timers.Timer timer7;  //会员储值卡赠送状态更新
        private System.Timers.Timer timer8;//会员购买储值卡收入
        private System.Timers.Timer timer9;//相亲每日随机查询信息删除
        private System.Timers.Timer timer10;  //教育咖啡劵
        public WindowsService()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            // TODO: 在此处添加代码以启动服务。
            Helper.LogHelper.Write("主服务开始运行......");
            TimersHelper helper = new TimersHelper();
            timer1 = new System.Timers.Timer();
            timer1.Interval = 1000 * (60 * 30); //60分钟
            timer1.Elapsed += new System.Timers.ElapsedEventHandler(helper.RevenueFinance);
            timer1.Enabled = true;

            #region 订单取消定时器

            timer2 = new System.Timers.Timer
            {
                Interval = 1000 * (60 * 10) //10分钟处理一次
            };
            timer2.Elapsed += new System.Timers.ElapsedEventHandler(helper.AutoCancelOrder);
            timer2.Enabled = true;

            #endregion

            #region 订单自动完成定时器

            timer3 = new System.Timers.Timer();
            timer3 = new System.Timers.Timer
            {
                Interval = 1000 * (60 * 60) //60分钟调用一次
            };
            timer3.Elapsed += new System.Timers.ElapsedEventHandler(helper.AutoReceivingOrder);
            timer3.Enabled = true;

            #endregion

            #region 七天自动取消下线

            timer4 = new System.Timers.Timer();
            timer4 = new System.Timers.Timer
            {
                Interval = 1000 * (60 * 60) //60分钟调用一次
            };
            timer4.Elapsed += new System.Timers.ElapsedEventHandler(helper.AutoReleaseTheOffline);
            timer4.Enabled = true;

            #endregion

            #region 商品定时上下架
            timer5 = new System.Timers.Timer();
            timer5 = new System.Timers.Timer
            {
                Interval = 1000 * (60 * 2) //10分钟调用一次
            };
            timer5.Elapsed += new System.Timers.ElapsedEventHandler(helper.GoodsShelves);
            timer5.Enabled = true;
            #endregion


            #region 资讯上下架
            timer6 = new System.Timers.Timer();
            timer6 = new System.Timers.Timer
            {
                Interval = 1000 * (60 * 2) //10分钟调用一次
            };
            timer6.Elapsed += new System.Timers.ElapsedEventHandler(helper.EducationArticleShelves);
            timer6.Enabled = true;
            #endregion

            #region 会员储值卡赠送状态更新
            timer7 = new System.Timers.Timer();
            timer7 = new System.Timers.Timer
            {
                Interval = 1000 * (60 * 10) //10分钟调用一次
            };
            timer7.Elapsed += new System.Timers.ElapsedEventHandler(helper.MemberDepositBuyShelves);
            timer7.Enabled = true;
            #endregion


            #region 储值卡收入

            timer8 = new System.Timers.Timer();
            timer8 = new System.Timers.Timer
            {
                Interval = 1000 * (60 * 30) //10分钟调用一次
            };
            timer8.Elapsed += new System.Timers.ElapsedEventHandler(helper.DepositIncomeFinanceShelves);
            timer8.Enabled = true;

            #endregion


            #region 相亲每日随机查询信息删除
            timer9 = new System.Timers.Timer();
            timer9 = new System.Timers.Timer
            {
                Interval = 1000 * (60 * 240) //4小时调用一次
            };
            timer9.Elapsed += new System.Timers.ElapsedEventHandler(helper.DailyRandomShelves);
            timer9.Enabled = true;
            #endregion

            #region 咖啡劵定时器
            timer10 = new System.Timers.Timer();
            timer10 = new System.Timers.Timer
            {
                Interval = 1000 * (60 * 2) //2 分钟调用一次
            };
            timer10.Elapsed += new System.Timers.ElapsedEventHandler(helper.EduInitFreeCoffee);
            timer10.Enabled = true;
            #endregion

        }

        protected override void OnStop()
        {
            // TODO: 在此处添加代码以执行停止服务所需的关闭操作。
            Helper.LogHelper.Write("主服务停止运行......");
            this.timer1.Enabled = false;
            this.timer2.Enabled = false;
            this.timer3.Enabled = false;
            this.timer4.Enabled = false;
            this.timer5.Enabled = false;
            this.timer6.Enabled = false;
            this.timer7.Enabled = false;
            this.timer8.Enabled = false;
            this.timer9.Enabled = false;
            this.timer10.Enabled = false;
        }
    }
}
