Exemple #1
0
        public void InsertTask(task_tb m)
        {
            MySqlConnection con = pool.Get();

            string query = @"INSERT INTO `task_tb` (`id`,`url`,`mark`,`type`,`link_reg`,`next_reg`,`craw_flag`)VALUES
                                    (@id,@url,@mark,@type,@link_reg,@next_reg,@craw_flag)";

            con.Execute(query, m);
            pool.Put(con);
        }
        private void btn_add_Click(object sender, EventArgs e)
        {
            task_tb site = new task_tb()
            {
                url       = this.txt_url.Text,
                mark      = this.txt_mark.Text,
                link_reg  = this.txt_now_reg.Text,
                next_reg  = this.txt_next_reg.Text,
                craw_flag = 0,
                type      = this.type_list.SelectedIndex
            };

            #region 验证参数
            if (!site.url.Contains("http"))
            {
                MessageBox.Show("提示", "URL 不合法");
                this.txt_url.Text = string.Empty;
                this.txt_url.Focus();
                return;
            }

            if (site.type == -1)
            {
                MessageBox.Show("提示", "请选择一种类型");
                this.type_list.Focus();
                return;
            }

            if (site.link_reg == string.Empty)
            {
                MessageBox.Show("提示", "当前页面解析规则为空");
                this.txt_now_reg.Focus();
                return;
            }

            if (site.link_reg == string.Empty)
            {
                MessageBox.Show("提示", "下一个页面解析规则为空");
                this.txt_next_reg.Focus();
                return;
            }
            #endregion

            dao.InsertTask(site);
            MessageBox.Show("提示", "添加成功");

            this.btn_clear_Click(null, null);
            this.btn_search_Click(null, null);
        }