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

📄 periodmanage.cs

📁 c#的多线程采集源代码
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using DataFactory;
using DataEntity;

namespace WebDataGather
{
    public partial class PeriodManage : Form
    {
        #region 变量定义
        /// <summary>
        /// 周期Id
        /// </summary>
        public int PeriodId = 0;
        /// <summary>
        /// 新增周期的数据源Id
        /// </summary>
        public int DataSourceId = 0;
        /// <summary>
        /// 数据操作类
        /// </summary>
        private PageCommon Common = new PageCommon();
        /// <summary>
        /// 数据源列表数据
        /// </summary>
        DataSet ds = new DataSet();
        #endregion

        #region 系统初始化

        public PeriodManage()
        {
            InitializeComponent();

            //加载所有数据源至GridView
            DataBindGridView();

        }

        private void DataBindGridView()
        {
            ds = Common.GetPeriodList();

            this.dataGridView1.DataSource = ds.Tables[0].DefaultView;

            this.dataGridView1.ReadOnly = true;

            //自动选中GridView中PeriodId的行
            
        }

        private void PeriodManage_Load(object sender, EventArgs e)
        {
            if (this.PeriodId != 0)
                DataBindForm();
        }

        #endregion

        #region GridView行单击事件

        private void dataGridView1_MouseUp(object sender, MouseEventArgs e)
        {
            int RowNum = 0;
            RowNum = this.dataGridView1.CurrentRow.Index;
            //绑定编辑区控件值
            this.PeriodId = int.Parse(ds.Tables[0].Rows[RowNum]["PeriodId"].ToString());
            DataBindForm();
        }

        private void DataBindForm()
        {
            Gather_Period Period = new Gather_Period();
            Period = Common.GetPeriodModel(this.PeriodId);

            this.Description.Text = Period.Description;
            this.TimeGather.Text = Period.TimeGather;

            if (Period.PeriodGather != 0)
            {
                this.radioButton1.Checked = false;
                this.radioButton2.Checked = true;
                int Hour = Period.PeriodGather / 60;
                int Minute = Period.PeriodGather - Period.PeriodGather / 60;
                this.PeriodGatherHour.Text = Hour.ToString();
                this.PeriodGatherMinute.Text = Minute.ToString();
            }
            else
            {
                this.radioButton1.Checked = true;
                this.radioButton2.Checked = false;
            }
            this.StartTime.Text = Period.StartTime.ToString();
            this.EndTime.Text = Period.EndTime.ToString();
        }
        #endregion

        #region 按钮事件

        /// <summary>
        /// 取消按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Cancel_Click(object sender, EventArgs e)
        {
            //如何在此处更新主窗体的树型控件?
            this.Close();
        }

        /// <summary>
        /// 保存按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Save_Click(object sender, EventArgs e)
        {
            //判断有效性
            if (this.Description.Text.Trim() == "")
            {
                this.errorProvider1.SetError(this.Description, "周期描述不可为空!");
                MessageBox.Show(this, "周期描述不可为空!", "信息提示", MessageBoxButtons.OK);
                return;
            }
            if (this.radioButton1.Checked == true)
            {
                if (this.TimeGather.Text.Trim() == "")
                {
                    this.errorProvider1.SetError(this.TimeGather, "定时采集时间不可为空!");
                    MessageBox.Show(this, "定时采集时间不可为空!", "信息提示", MessageBoxButtons.OK);
                    return;
                }
            }

            if (this.radioButton2.Checked == true)
            {
                if (this.PeriodGatherHour.Text.Trim() == "")
                {
                    this.errorProvider1.SetError(this.PeriodGatherHour, "小时不可为空!");
                    MessageBox.Show(this, "小时不可为空!", "信息提示", MessageBoxButtons.OK);
                    return;
                }

                if (this.PeriodGatherMinute.Text.Trim() == "")
                {
                    this.errorProvider1.SetError(this.PeriodGatherMinute, "分钟不可为空!");
                    MessageBox.Show(this, "分钟不可为空!", "信息提示", MessageBoxButtons.OK);
                    return;
                }

                if (this.StartTime.Text.Trim() == "")
                {
                    this.errorProvider1.SetError(this.StartTime, "开始时间不可为空!");
                    MessageBox.Show(this, "开始时间不可为空", "信息提示", MessageBoxButtons.OK);
                    return;
                }

                if (this.EndTime.Text.Trim() == "")
                {
                    this.errorProvider1.SetError(this.EndTime, "结束时间不可为空!");
                    MessageBox.Show(this, "结束时间不可为空", "信息提示", MessageBoxButtons.OK);
                    return;
                }
            }

            Gather_Period Period = new Gather_Period();

            Period.Description = this.Description.Text.Trim();

            if (this.radioButton1.Checked == true)
                Period.TimeGather = this.TimeGather.Text.Trim();
            else
                Period.TimeGather = "00:00:00";

            if (this.radioButton2.Checked == true)
            {
                Period.PeriodGather = int.Parse(this.PeriodGatherHour.Text.ToString()) * 60 + int.Parse(this.PeriodGatherMinute.Text.ToString());
                Period.StartTime = this.StartTime.Text.ToString();
                Period.EndTime = this.EndTime.Text.ToString();
            }
            else
            {
                Period.PeriodGather = 0;
                Period.StartTime = "00:00:00";
                Period.EndTime = "00:00:00";
            }

            int Num = 0;
            //表示添加新周期
            if (this.PeriodId == 0)
            {
                //添加周期,返回新周期的Id
                this.PeriodId = Common.AddPeriod(Period);
            }
            else
            {
                Period.PeriodId = this.PeriodId;
                Num = Common.UpdatePeriod(Period);
            }

            //将PeriodId,更新至DataSource表的PeriodId字段
            Gather_DataSourceConfig DataSourceConfig = new Gather_DataSourceConfig();
            DataSourceConfig = Common.GetDataSourceConfig(DataSourceId);

            DataSourceConfig.PeriodId = PeriodId;

            Num = Common.UpdateDataSourceConfig(DataSourceConfig);


            if (Num == 1)
            {
                MessageBox.Show(this, "保存成功!", "信息提示", MessageBoxButtons.OK);
            }
            else
            {
                MessageBox.Show(this, "保存失败!", "信息提示", MessageBoxButtons.OK);
            }

            //刷新GridView
            DataBindGridView();
        }

        #endregion

        #region 定时采集和循环采集选择

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            
                //this.radioButton1.Checked = true;
                //this.radioButton2.Checked = false;
                this.TimeGather.Enabled = true;
                this.PeriodGatherHour.Enabled = false;
                this.PeriodGatherMinute.Enabled = false;
                this.StartTime.Enabled = false;
                this.EndTime.Enabled = false;

                this.PeriodGatherHour.Text = "0";
                this.PeriodGatherMinute.Text = "0";
                this.StartTime.Text = "00:00:00";
                this.EndTime.Text = "00:00:00";
            
        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {

            //this.radioButton1.Checked = false;
            //this.radioButton2.Checked = true;
            this.TimeGather.Enabled = false;
            this.PeriodGatherHour.Enabled = true;
            this.PeriodGatherMinute.Enabled = true;
            this.StartTime.Enabled = true;
            this.EndTime.Enabled = true;

            this.TimeGather.Text = "00:00:00";
        }
        #endregion

    }
}

⌨️ 快捷键说明

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