Example #1
0
        private void  制任务ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int     ID  = Get_DataViewID();
            DALTask dal = new DALTask();

            int       currentMaxId    = dal.GetMaxId();
            ModelTask model           = dal.GetModelSingleTask(ID);
            string    currentTaskName = model.TaskName + "复制" + DateTime.Now.Millisecond;


            model.ID       = currentMaxId;
            model.TaskName = currentTaskName;
            dal.Add(model);
            DALTaskLabel dalLable = new DALTaskLabel();
            DataTable    dt       = dalLable.GetList(" TaskId=" + ID).Tables[0];

            if (dt != null && dt.Rows.Count > 0)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    ModelTaskLabel modelLabel = dalLable.GetModel(StringHelper.Instance.SetNumber(dr["Id"].ToString()));
                    modelLabel.TaskID = currentMaxId;
                    dalLable.Add(modelLabel);
                }
            }
            CreateDataFile(currentTaskName, currentMaxId);
            this.ClassID = model.TaskClassID.Value;
            Bind_DataList();
        }
Example #2
0
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            string WebCollectionModule = this.txtWebCollectionModule.Text;

            if (string.IsNullOrEmpty(WebCollectionModule))
            {
                MessageBox.Show("采集模块不能为空!");
                return;
            }

            var     model        = SerializeHelper.DeserializeObject <ModelTask>(WebCollectionModule);
            DALTask dal          = new DALTask();
            int     currentMaxId = dal.GetMaxId();

            model.ID = currentMaxId;
            dal.Add(model);
            foreach (ModelTaskLabel label in model.ListTaskLabel)
            {
                label.TaskID = currentMaxId;
                var d = new DALTaskLabel();
                var m = d.GetMaxID();
                label.ID = m;
                d.Add(label);
            }
            foreach (ModelWebPublishModule label in model.ListModelWebPublishModule)
            {
                label.TaskID = currentMaxId;
                var d = new DALWebPublishModule();
                label.ID = 0;
                d.Add(label);
            }
            MessageBox.Show("导入成功");
            RefreshParentForm?.Invoke(this, new EventArgs());
            this.Hide();
            this.Close();
        }
Example #3
0
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            DALTask   dal   = new DALTask();
            ModelTask model = new ModelTask();

            errorProvider.Clear();
            if (string.IsNullOrEmpty(this.cmbSiteClassID.Text))
            {
                errorProvider.SetError(this.cmbSiteClassID, "所属站点不能为空!");
                return;
            }

            if (string.IsNullOrEmpty(this.txtTaskName.Text))
            {
                errorProvider.SetError(this.txtTaskName, "任务名称不能为空!");
                return;
            }
            if (string.IsNullOrEmpty(this.txtDemoListUrl.Text))
            {
                errorProvider.SetError(this.txtDemoListUrl, "测试网站列表地址不能为空!");
                return;
            }
            if (string.IsNullOrEmpty(this.ddlItemEncode.Text))
            {
                errorProvider.SetError(this.ddlItemEncode, "网页编码不能为空!");
                return;
            }
            int    ID                = int.Parse(this.txtID.Text);
            int    TaskClassID       = int.Parse(this.cmbSiteClassID.SelectedValue.ToString());
            string TaskName          = this.txtTaskName.Text;
            string OldTaskName       = this.txtOldTaskName.Text;
            int    IsSpiderUrl       = this.chkIsSpiderUrl.Checked ? 1 : 0;
            int    IsSpiderContent   = this.chkIsSpiderContent.Checked ? 1 : 0;
            int    IsPublishContent  = this.chkIsPublishContent.Checked ? 1 : 0;
            string PageEncode        = ((ListItem)this.ddlItemEncode.SelectedItem).Value;
            string CollectionContent = string.Empty;

            foreach (string str in listBoxLinkUrl.Items)
            {
                CollectionContent += str + "$$$$";
            }
            string LinkUrlMustIncludeStr   = this.txtLinkUrlMustIncludeStr.Text;
            string LinkUrlNoMustIncludeStr = this.txtLinkUrlNoMustIncludeStr.Text;
            string LinkUrlCutAreaStart     = this.txtLinkUrlCutAreaStart.Text.Replace("'", "''");
            string LinkUrlCutAreaEnd       = this.txtLinkUrlCutAreaEnd.Text.Replace("'", "''");
            string TestViewUrl             = this.txtTextViewUrl.Text;
            int    IsWebOnlinePublish1     = this.chkPublish01.Checked ? 1 : 0;
            int    IsSaveLocal2            = this.chkPublish02.Checked ? 1 : 0;
            string SaveFileFormat2         = this.ddlSaveFileFormat2.Text;
            string SaveDirectory2          = this.txtSaveDirectory2.Text;
            string SaveHtmlTemplate2       = this.txtSaveHtmlTemplate2.Text;
            int    IsSaveDataBase3         = this.chkPublish03.Checked ? 1 : 0;
            int    SaveDataType3           = 0;

            if (this.rbtnAccess.Checked)
            {
                SaveDataType3 = 1;
            }
            else if (this.rbtnMsSql.Checked)
            {
                SaveDataType3 = 2;
            }
            else if (this.rbtnSqlite.Checked)
            {
                SaveDataType3 = 3;
            }
            else if (this.rbtnMySql.Checked)
            {
                SaveDataType3 = 4;
            }
            else if (this.rbtnSqlite.Checked)
            {
                SaveDataType3 = 5;
            }
            string  SaveDataUrl3 = this.txtSaveDataUrl3.Text;
            string  SaveDataSQL3 = this.txtSaveDataSQL3.Text;
            int     IsSaveSQL4   = this.chkPublish04.Checked ? 1 : 0;
            decimal CollectionContentThreadCount = this.nudCollectionContentThreadCount.Value;
            decimal CollectionContentStepTime    = this.nudCollectionContentStepTime.Value;
            decimal PublishContentThreadCount    = this.nudPublishContentThreadCount.Value;
            decimal PublishContentStepTimeMin    = this.nudPublishContentStepTimeMin.Value;
            decimal PublishContentStepTimeMax    = this.nudPublishContentStepTimeMax.Value;

            int    IsHandGetUrl           = this.chkIsHandGetUrl.Checked ? 1 : 0;
            string HandCollectionUrlRegex = this.txtHandCollectionUrlRegex.Text;
            int    IsPlan     = this.chkTaskSetStatus.Checked ? 1 : 0;
            string PlanFormat = this.txtHiddenPlanFormat.Text;

            model.ID                           = ID;
            model.TaskClassID                  = TaskClassID;
            model.TaskName                     = TaskName;
            model.IsSpiderUrl                  = IsSpiderUrl;
            model.IsSpiderContent              = IsSpiderContent;
            model.IsPublishContent             = IsPublishContent;
            model.PageEncode                   = PageEncode;
            model.CollectionContent            = CollectionContent;
            model.LinkUrlMustIncludeStr        = LinkUrlMustIncludeStr;
            model.LinkUrlNoMustIncludeStr      = LinkUrlNoMustIncludeStr;
            model.LinkUrlCutAreaStart          = LinkUrlCutAreaStart;
            model.LinkUrlCutAreaEnd            = LinkUrlCutAreaEnd;
            model.TestViewUrl                  = TestViewUrl;
            model.IsWebOnlinePublish1          = IsWebOnlinePublish1;
            model.IsSaveLocal2                 = IsSaveLocal2;
            model.SaveFileFormat2              = SaveFileFormat2;
            model.SaveDirectory2               = SaveDirectory2;
            model.SaveHtmlTemplate2            = SaveHtmlTemplate2;
            model.IsSaveDataBase3              = IsSaveDataBase3;
            model.SaveDataType3                = SaveDataType3;
            model.SaveDataUrl3                 = SaveDataUrl3;
            model.SaveDataSQL3                 = SaveDataSQL3;
            model.IsSaveSQL4                   = IsSaveSQL4;
            model.PluginSpiderUrl              = this.cmbSpiderUrlPlugins.Text;
            model.PluginSaveContent            = this.cmbSaveConentPlugins.Text;
            model.PluginPublishContent         = this.cmbPublishContentPlugins.Text;
            model.CollectionUrlStepTime        = int.Parse(nudCollectionUrlStepTime.Value.ToString());
            model.CollectionContentThreadCount = Convert.ToInt32(CollectionContentThreadCount);
            model.CollectionContentStepTime    = Convert.ToInt32(CollectionContentStepTime);
            model.PublishContentThreadCount    = Convert.ToInt32(PublishContentThreadCount);
            model.PublishContentStepTimeMin    = Convert.ToInt32(PublishContentStepTimeMin);
            model.PublishContentStepTimeMax    = Convert.ToInt32(PublishContentStepTimeMax);

            model.IsHandGetUrl           = IsHandGetUrl;
            model.HandCollectionUrlRegex = HandCollectionUrlRegex;

            model.DemoListUrl = this.txtDemoListUrl.Text;
            model.IsPlan      = IsPlan;
            model.PlanFormat  = PlanFormat;
            model.Status      = this.cmbStatus.SelectedIndex == 0 ? 1 : 0;

            model.IsSource   = this.chkIsSource.Checked ? 1 : 0;
            model.SourceText = this.txtSourceText.Text;


            if (ID == 0)
            {
                string guid = Guid.NewGuid().ToString();
                ID         = dal.GetMaxId();
                model.ID   = ID;
                model.Guid = guid;
                dal.Add(model);
                DALTaskLabel dalTaskLabel = new DALTaskLabel();
                dalTaskLabel.UpdateTaskLabelByTaskID(ID);
                if (TaskOpDelegate != null)
                {
                    TaskOpEv.TaskIndex = TaskIndex;
                    TaskOpDelegate(this, TaskOpEv);
                }
            }
            else if (ID > 0)
            {
                if (TaskName != OldTaskName)
                {
                    string RootPath    = AppDomain.CurrentDomain.BaseDirectory + "Data\\Collection\\";
                    string OldTaskPath = RootPath + OldTaskName;
                    string NewTaskPath = RootPath + TaskName;
                    if (Directory.Exists(NewTaskPath))
                    {
                        MessageBox.Show("任务名称存在!请换个名称试试!");
                        return;
                    }
                    try {
                        Directory.Move(OldTaskPath, NewTaskPath);
                    }
                    catch (Exception ex) {
                        MessageBox.Show("修改异常!" + ex.Message);
                        return;
                    }
                }
                if (!dal.CheckTaskGuid(ID))
                {
                    model.Guid = Guid.NewGuid().ToString();
                }
                dal.Update(model);
                if (TaskOpDelegate != null)
                {
                    TaskOpEv.TaskIndex = TaskIndex;
                    TaskOpEv.OpType    = 1;
                    TaskOpDelegate(this, TaskOpEv);
                }
            }
            CreateDataFile(TaskName, ID);

            #region 更新计划任务
            if (model.IsPlan == 1)
            {
                PlanTaskHelper.PushJobDetail(ID);
            }
            #endregion

            this.CloseForm();
        }