Esempio n. 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();
        }
Esempio n. 2
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(ModelTaskLabel model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update [S_TaskLabel] set ");
            strSql.Append("LabelName=@LabelName,");
            strSql.Append("IsLoop=@IsLoop,");
            strSql.Append("TestViewUrl=@TestViewUrl,");
            strSql.Append("LabelNameCutRegex=@LabelNameCutRegex,");
            strSql.Append("LabelHtmlRemove=@LabelHtmlRemove,");
            strSql.Append("LabelRemove=@LabelRemove,");
            strSql.Append("LabelReplace=@LabelReplace,");
            strSql.Append("TaskID=@TaskID,");
            strSql.Append("GuidNum=@GuidNum,");
            strSql.Append("OrderID=@OrderID,");
            strSql.Append("CreateTime=@CreateTime,");
            strSql.Append("SpiderLabelPlugin=@SpiderLabelPlugin,");
            strSql.Append("IsDownResource=@IsDownResource,");
            strSql.Append("DownResourceExts=@DownResourceExts");
            strSql.Append(" where ID=@ID ");
            int rowsAffected = DbHelper.Execute(CommonHelper.SQLiteConnectionString, strSql.ToString(), model);

            if (rowsAffected > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        /// <summary>
        /// 测试单个标签
        /// </summary>
        /// <param name="itemLabel"></param>
        /// <param name="pageContent"></param>
        /// <returns></returns>
        public string TestSingleLabel(ModelTaskLabel itemLabel, string pageContent)
        {
            var CutContent = string.Empty;

            CutContent += "【" + itemLabel.LabelName + "】: ";
            CutContent += GetLabelContent("测试", 10, "", itemLabel, pageContent, true);
            return(CutContent);
        }
Esempio n. 4
0
        public List <ModelTaskLabel> GetModelByTaskID(int TaskID)
        {
            List <ModelTaskLabel> list = new List <ModelTaskLabel>();
            DataTable             dt   = this.GetList(" TaskID=" + TaskID + " Order by OrderID asc").Tables[0];

            foreach (DataRow dr in dt.Rows)
            {
                ModelTaskLabel model = this.GetModel(int.Parse("0" + dr["ID"]));
                list.Add(model);
            }
            return(list);
        }
Esempio n. 5
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(ModelTaskLabel model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into [S_TaskLabel] (");
            strSql.Append("LabelName,IsLoop,TestViewUrl,LabelNameCutRegex,LabelHtmlRemove,LabelRemove,LabelReplace,TaskID,GuidNum,OrderID,CreateTime,SpiderLabelPlugin,IsDownResource,DownResourceExts)");
            strSql.Append(" values (");
            strSql.Append("@LabelName,@IsLoop,@TestViewUrl,@LabelNameCutRegex,@LabelHtmlRemove,@LabelRemove,@LabelReplace,@TaskID,@GuidNum,@OrderID,@CreateTime,@SpiderLabelPlugin,@IsDownResource,@DownResourceExts)");
            object obj = DbHelper.Execute(CommonHelper.SQLiteConnectionString, strSql.ToString(), model);

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            int            ID    = int.Parse("0" + this.txtID.Text);
            ModelTaskLabel model = new ModelTaskLabel();

            model.TaskID            = TaskID;
            model.LabelName         = this.txtLabelName.Text;
            model.LabelNameCutRegex = this.txtLabelNameCutRegex.Text.Replace("'", "''");
            model.LabelRemove       = string.Empty;
            model.LabelReplace      = string.Empty;

            #region Html¹ýÂË
            model.LabelHtmlRemove = string.Empty;
            if (this.chkAllHtml.Checked)
            {
                model.LabelHtmlRemove += "all||||";
            }
            if (this.chkTable.Checked)
            {
                model.LabelHtmlRemove += "table||||";
            }
            if (this.chkFont.Checked)
            {
                model.LabelHtmlRemove += "font<span>||||";
            }
            if (this.chkhref.Checked)
            {
                model.LabelHtmlRemove += "a||||";
            }
            if (this.chkScript.Checked)
            {
                model.LabelHtmlRemove += "script||||";
            }
            if (model.LabelHtmlRemove.Trim() != "")
            {
                model.LabelHtmlRemove = model.LabelHtmlRemove.Remove(model.LabelHtmlRemove.Length - 4);
            }
            #endregion

            #region ÄÚÈÝÅųý
            foreach (ListViewItem item in this.listViewContentRemove.Items)
            {
                model.LabelRemove += item.SubItems[0].Text + "||" + item.SubItems[1].Text + "$$$$";
            }
            if (model.LabelRemove.Trim() != "")
            {
                model.LabelRemove = model.LabelRemove.Remove(model.LabelRemove.Length - 4);
            }
            #endregion

            #region ÄÚÈÝÌæ»»
            foreach (ListViewItem item in this.listViewContentReplace.Items)
            {
                model.LabelReplace += item.SubItems[0].Text + "||" + item.SubItems[1].Text + "$$$$";
            }
            if (model.LabelReplace.Trim() != "")
            {
                model.LabelReplace = model.LabelReplace.Remove(model.LabelReplace.Length - 4);
            }
            #endregion

            model.IsLoop            = this.chkLabelIsLoop.Checked ? 1 : 0;
            model.SpiderLabelPlugin = this.cmbSpiderPlugin.Text;
            model.IsDownResource    = this.chkDownResource.Checked ? 1 : 0;
            model.DownResourceExts  = this.txtDownResourceExt.Text;

            if (ID > 0)
            {
                model.ID = ID;
                dal.Update(model);
            }
            else if (ID == 0)
            {
                int OrderID = dal.GetMaxOrderID(TaskID) + 1;
                model.OrderID = OrderID;
                ID            = dal.Add(model);
            }
            ViewLabel?.Invoke(this, ev);
            this.Hide();
            this.Close();
        }
        private void btnTest_Click(object sender, EventArgs e)
        {
            this.txtLogView.Clear();
            this.btnTest.Enabled = false;

            var model = new ModelTaskLabel();

            model.TestViewUrl       = this.txtTestUrl.Text;
            model.TaskID            = TaskID;
            model.LabelName         = this.txtLabelName.Text;
            model.LabelNameCutRegex = this.txtLabelNameCutRegex.Text.Replace("'", "''");
            model.LabelRemove       = string.Empty;
            model.LabelReplace      = string.Empty;

            #region Html¹ýÂË
            model.LabelHtmlRemove = string.Empty;
            if (this.chkAllHtml.Checked)
            {
                model.LabelHtmlRemove += "all||||";
            }
            if (this.chkTable.Checked)
            {
                model.LabelHtmlRemove += "table||||";
            }
            if (this.chkFont.Checked)
            {
                model.LabelHtmlRemove += "font<span>||||";
            }
            if (this.chkhref.Checked)
            {
                model.LabelHtmlRemove += "a||||";
            }
            if (this.chkScript.Checked)
            {
                model.LabelHtmlRemove += "script||||";
            }
            if (model.LabelHtmlRemove.Trim() != "")
            {
                model.LabelHtmlRemove = model.LabelHtmlRemove.Remove(model.LabelHtmlRemove.Length - 4);
            }
            #endregion

            #region ÄÚÈÝÅųý
            foreach (ListViewItem item in this.listViewContentRemove.Items)
            {
                model.LabelRemove += item.SubItems[0].Text + "||" + item.SubItems[1].Text + "$$$$";
            }
            if (model.LabelRemove.Trim() != "")
            {
                model.LabelRemove = model.LabelRemove.Remove(model.LabelRemove.Length - 4);
            }
            #endregion

            #region ÄÚÈÝÌæ»»
            foreach (ListViewItem item in this.listViewContentReplace.Items)
            {
                model.LabelReplace += item.SubItems[0].Text + "||" + item.SubItems[1].Text + "$$$$";
            }
            if (model.LabelReplace.Trim() != "")
            {
                model.LabelReplace = model.LabelReplace.Remove(model.LabelReplace.Length - 4);
            }
            #endregion

            model.IsLoop            = this.chkLabelIsLoop.Checked ? 1 : 0;
            model.SpiderLabelPlugin = this.cmbSpiderPlugin.Text;
            model.IsDownResource    = this.chkDownResource.Checked ? 1 : 0;
            model.DownResourceExts  = this.txtDownResourceExt.Text;

            var task = new System.Threading.Tasks.TaskFactory().StartNew(() => {
                var pageContent = CommonHelper.getPageContent(model.TestViewUrl, PageEncode);
                var spider      = new SpiderViewHelper();
                var s           = spider.TestSingleLabel(model, pageContent);

                this.Invoke(new MethodInvoker(() => {
                    this.btnTest.Enabled = true;
                    this.txtLogView.AppendText(s);
                    this.txtLogView.AppendText("\r\n");
                }));
            });
        }
        /// <summary>
        /// ±à¼­±êÇ©
        /// </summary>
        private void Bind_DataEdit()
        {
            DALTaskLabel dal = new DALTaskLabel();

            ListView.SelectedListViewItemCollection item = (ListView.SelectedListViewItemCollection)EditItem;
            int            ID    = int.Parse("0" + item[0].Tag);
            ModelTaskLabel model = dal.GetModel(ID);

            this.txtID.Text                = ID.ToString();
            this.txtLabelName.Text         = model.LabelName;
            this.txtLabelNameCutRegex.Text = model.LabelNameCutRegex;
            this.chkScript.Checked         = false;
            this.chkhref.Checked           = false;
            if (!string.IsNullOrEmpty(model.LabelHtmlRemove))
            {
                string[] arr = model.LabelHtmlRemove.Split(new string[] { "||||" }, StringSplitOptions.RemoveEmptyEntries);
                foreach (string str in arr)
                {
                    if (str == "all")
                    {
                        this.chkAllHtml.Checked = true;
                    }
                    else if (str == "table")
                    {
                        this.chkTable.Checked = true;
                    }
                    else if (str == "font<span>")
                    {
                        this.chkFont.Checked = true;
                    }
                    else if (str == "a")
                    {
                        this.chkhref.Checked = true;
                    }
                    else if (str == "script")
                    {
                        this.chkScript.Checked = true;
                    }
                }
            }

            #region ÄÚÈÝÅųý
            if (!string.IsNullOrEmpty(model.LabelRemove))
            {
                foreach (string str in model.LabelRemove.Split(new string[] { "$$$$" }, StringSplitOptions.RemoveEmptyEntries))
                {
                    string[]     aa  = str.Split(new string[] { "||" }, StringSplitOptions.None);
                    ListViewItem lvi = new ListViewItem(aa[0]);
                    lvi.SubItems.Add(aa[1]);
                    this.listViewContentRemove.Items.Add(lvi);
                }
            }
            #endregion

            #region ÄÚÈÝÌæ»»
            if (!string.IsNullOrEmpty(model.LabelReplace))
            {
                foreach (string str in model.LabelReplace.Split(new string[] { "$$$$" }, StringSplitOptions.RemoveEmptyEntries))
                {
                    string[]     aa  = str.Split(new string[] { "||" }, StringSplitOptions.None);
                    ListViewItem lvi = new ListViewItem(aa[0]);
                    lvi.SubItems.Add(aa[1]);
                    this.listViewContentReplace.Items.Add(lvi);
                }
            }
            #endregion

            this.chkLabelIsLoop.Checked  = model.IsLoop == 1 ? true : false;
            this.cmbSpiderPlugin.Text    = model.SpiderLabelPlugin == string.Empty ? "²»Ê¹Óòå¼þ" : model.SpiderLabelPlugin;
            this.chkDownResource.Checked = model.IsDownResource == 1 ? true : false;
            this.txtDownResourceExt.Text = model.DownResourceExts;
        }
Esempio n. 9
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(ModelTaskLabel model)
        {
            StringBuilder strSql  = new StringBuilder();
            StringBuilder strSql1 = new StringBuilder();
            StringBuilder strSql2 = new StringBuilder();

            if (model.LabelName != null)
            {
                strSql1.Append("LabelName,");
                strSql2.Append("'" + model.LabelName + "',");
            }
            if (model.LabelSource != null)
            {
                strSql1.Append("LabelSource,");
                strSql2.Append(model.LabelSource + ",");
            }
            if (model.LabelNameCutRegex != null)
            {
                strSql1.Append("LabelNameCutRegex,");
                strSql2.Append("'" + model.LabelNameCutRegex + "',");
            }
            if (model.LabelHtmlRemove != null)
            {
                strSql1.Append("LabelHtmlRemove,");
                strSql2.Append("'" + model.LabelHtmlRemove + "',");
            }
            if (model.LblHtmlRemove != null)
            {
                strSql1.Append("LblHtmlRemove,");
                strSql2.Append("'" + model.LblHtmlRemove + "',");
            }
            if (model.LabelRemove != null)
            {
                strSql1.Append("LabelRemove,");
                strSql2.Append("'" + model.LabelRemove + "',");
            }
            if (model.LabelReplace != null)
            {
                strSql1.Append("LabelReplace,");
                strSql2.Append("'" + model.LabelReplace + "',");
            }
            if (model.TaskID != null)
            {
                strSql1.Append("TaskID,");
                strSql2.Append("" + model.TaskID + ",");
            }
            if (model.GuidNum != null)
            {
                strSql1.Append("GuidNum,");
                strSql2.Append("'" + model.GuidNum + "',");
            }
            if (model.OrderID != null)
            {
                strSql1.Append("OrderID,");
                strSql2.Append("" + model.OrderID + ",");
            }
            if (model.CreateTime != null)
            {
                strSql1.Append("CreateTime,");
                strSql2.Append("'" + model.CreateTime + "',");
            }
            //=============================================2012 2-6
            if (model.IsLoop != null)
            {
                strSql1.Append("IsLoop,");
                strSql2.Append("" + model.IsLoop + ",");
            }
            if (model.IsNoNull != null)
            {
                strSql1.Append("IsNoNull,");
                strSql2.Append("" + model.IsNoNull + ",");
            }
            if (model.IsLinkUrl != null)
            {
                strSql1.Append("IsLinkUrl,");
                strSql2.Append("" + model.IsLinkUrl + ",");
            }
            if (model.IsPager != null)
            {
                strSql1.Append("IsPager,");
                strSql2.Append("" + model.IsPager + ",");
            }
            if (model.LabelValueLinkUrlRegex != null)
            {
                strSql1.Append("LabelValueLinkUrlRegex,");
                strSql2.Append("'" + model.LabelValueLinkUrlRegex + "',");
            }
            if (model.LabelValuePagerRegex != null)
            {
                strSql1.Append("LabelValuePagerRegex,");
                strSql2.Append("'" + model.LabelValuePagerRegex + "',");
            }
            //
            if (model.SpiderLabelPlugin != null)
            {
                strSql1.Append("SpiderLabelPlugin,");
                strSql2.Append("'" + model.SpiderLabelPlugin + "',");
            }
            //
            if (model.IsDownResource != null)
            {
                strSql1.Append("IsDownResource,");
                strSql2.Append("" + model.IsDownResource + ",");
            }
            if (model.DownResourceExts != null)
            {
                strSql1.Append("DownResourceExts,");
                strSql2.Append("'" + model.DownResourceExts + "',");
            }
            strSql.Append("insert into S_TaskLabel(");
            strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1));
            strSql.Append(")");
            strSql.Append(" values (");
            strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1));
            strSql.Append(")");
            strSql.Append(";select LAST_INSERT_ROWID()");
            object obj = SQLiteHelper.ExecuteScalar(dbStr, strSql.ToString());

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Esempio n. 10
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public ModelTaskLabel GetModel(int ID)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  ");
            strSql.Append(" * ");
            strSql.Append(" from S_TaskLabel ");
            strSql.Append(" where ID=" + ID + "");
            ModelTaskLabel model = new ModelTaskLabel();
            DataSet        ds    = SQLiteHelper.Query1(dbStr, strSql.ToString());

            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["ID"].ToString() != "")
                {
                    model.ID = int.Parse(ds.Tables[0].Rows[0]["ID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["LabelName"] != null)
                {
                    model.LabelName = ds.Tables[0].Rows[0]["LabelName"].ToString();
                }
                if (ds.Tables[0].Rows[0]["LabelSource"] != null)
                {
                    model.LabelSource = int.Parse(ds.Tables[0].Rows[0]["LabelSource"].ToString());
                }
                if (ds.Tables[0].Rows[0]["LabelNameCutRegex"] != null)
                {
                    model.LabelNameCutRegex = ds.Tables[0].Rows[0]["LabelNameCutRegex"].ToString();
                }
                if (ds.Tables[0].Rows[0]["LabelHtmlRemove"] != null)
                {
                    model.LabelHtmlRemove = ds.Tables[0].Rows[0]["LabelHtmlRemove"].ToString();
                }
                if (ds.Tables[0].Rows[0]["LblHtmlRemove"] != null)
                {
                    model.LblHtmlRemove = ds.Tables[0].Rows[0]["LblHtmlRemove"].ToString();
                }
                if (ds.Tables[0].Rows[0]["LabelRemove"] != null)
                {
                    model.LabelRemove = ds.Tables[0].Rows[0]["LabelRemove"].ToString();
                }
                if (ds.Tables[0].Rows[0]["LabelReplace"] != null)
                {
                    model.LabelReplace = ds.Tables[0].Rows[0]["LabelReplace"].ToString();
                }
                if (ds.Tables[0].Rows[0]["TaskID"].ToString() != "")
                {
                    model.TaskID = int.Parse(ds.Tables[0].Rows[0]["TaskID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["GuidNum"] != null)
                {
                    model.GuidNum = ds.Tables[0].Rows[0]["GuidNum"].ToString();
                }
                if (ds.Tables[0].Rows[0]["OrderID"].ToString() != "")
                {
                    model.OrderID = int.Parse(ds.Tables[0].Rows[0]["OrderID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["CreateTime"] != null)
                {
                    model.CreateTime = ds.Tables[0].Rows[0]["CreateTime"].ToString();
                }
                //=================================2012 2-6
                if (ds.Tables[0].Rows[0]["IsLoop"] != null && ds.Tables[0].Rows[0]["IsLoop"].ToString() != "")
                {
                    model.IsLoop = int.Parse(ds.Tables[0].Rows[0]["IsLoop"].ToString());
                }
                if (ds.Tables[0].Rows[0]["IsNoNull"] != null && ds.Tables[0].Rows[0]["IsNoNull"].ToString() != "")
                {
                    model.IsNoNull = int.Parse(ds.Tables[0].Rows[0]["IsNoNull"].ToString());
                }
                if (ds.Tables[0].Rows[0]["IsLinkUrl"] != null && ds.Tables[0].Rows[0]["IsLinkUrl"].ToString() != "")
                {
                    model.IsLinkUrl = int.Parse(ds.Tables[0].Rows[0]["IsLinkUrl"].ToString());
                }
                if (ds.Tables[0].Rows[0]["IsPager"] != null && ds.Tables[0].Rows[0]["IsPager"].ToString() != "")
                {
                    model.IsPager = int.Parse(ds.Tables[0].Rows[0]["IsPager"].ToString());
                }
                if (ds.Tables[0].Rows[0]["LabelValueLinkUrlRegex"] != null)
                {
                    model.LabelValueLinkUrlRegex = ds.Tables[0].Rows[0]["LabelValueLinkUrlRegex"].ToString();
                }
                if (ds.Tables[0].Rows[0]["LabelValuePagerRegex"] != null)
                {
                    model.LabelValuePagerRegex = ds.Tables[0].Rows[0]["LabelValuePagerRegex"].ToString();
                }
                //
                if (ds.Tables[0].Rows[0]["SpiderLabelPlugin"] != null)
                {
                    model.SpiderLabelPlugin = ds.Tables[0].Rows[0]["SpiderLabelPlugin"].ToString();
                }
                //
                if (ds.Tables[0].Rows[0]["IsDownResource"] != null && ds.Tables[0].Rows[0]["IsDownResource"].ToString() != "")
                {
                    model.IsDownResource = int.Parse(ds.Tables[0].Rows[0]["IsDownResource"].ToString());
                }
                if (ds.Tables[0].Rows[0]["DownResourceExts"] != null)
                {
                    model.DownResourceExts = ds.Tables[0].Rows[0]["DownResourceExts"].ToString();
                }
                return(model);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 11
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(ModelTaskLabel model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update S_TaskLabel set ");
            if (model.LabelName != null)
            {
                strSql.Append("LabelName='" + model.LabelName + "',");
            }
            if (model.LabelSource != null)
            {
                strSql.Append("LabelSource=" + model.LabelSource + ",");
            }
            if (model.LabelNameCutRegex != null)
            {
                strSql.Append("LabelNameCutRegex='" + model.LabelNameCutRegex + "',");
            }
            if (model.LabelHtmlRemove != null)
            {
                strSql.Append("LabelHtmlRemove='" + model.LabelHtmlRemove + "',");
            }
            if (model.LblHtmlRemove != null)
            {
                strSql.Append("LblHtmlRemove='" + model.LblHtmlRemove.Replace("'", "''") + "',");
            }
            if (model.LabelRemove != null)
            {
                strSql.Append("LabelRemove='" + model.LabelRemove + "',");
            }
            if (model.LabelReplace != null)
            {
                strSql.Append("LabelReplace='" + model.LabelReplace + "',");
            }
            if (model.TaskID != null)
            {
                strSql.Append("TaskID=" + model.TaskID + ",");
            }
            if (model.GuidNum != null)
            {
                strSql.Append("GuidNum='" + model.GuidNum + "',");
            }
            //=========================================2012 2-6
            if (model.IsLoop != null)
            {
                strSql.Append("IsLoop=" + model.IsLoop + ",");
            }
            if (model.IsNoNull != null)
            {
                strSql.Append("IsNoNull=" + model.IsNoNull + ",");
            }
            if (model.IsLinkUrl != null)
            {
                strSql.Append("IsLinkUrl=" + model.IsLinkUrl + ",");
            }
            if (model.IsPager != null)
            {
                strSql.Append("IsPager=" + model.IsPager + ",");
            }
            if (model.LabelValueLinkUrlRegex != null)
            {
                strSql.Append("LabelValueLinkUrlRegex='" + model.LabelValueLinkUrlRegex + "',");
            }
            if (model.LabelValuePagerRegex != null)
            {
                strSql.Append("LabelValuePagerRegex='" + model.LabelValuePagerRegex + "',");
            }
            //
            if (model.SpiderLabelPlugin != null)
            {
                strSql.Append("SpiderLabelPlugin='" + model.SpiderLabelPlugin + "',");
            }
            //
            if (model.IsDownResource != null)
            {
                strSql.Append("IsDownResource=" + model.IsDownResource + ",");
            }
            if (model.DownResourceExts != null)
            {
                strSql.Append("DownResourceExts='" + model.DownResourceExts + "',");
            }
            int n = strSql.ToString().LastIndexOf(",");

            strSql.Remove(n, 1);
            strSql.Append(" where ID=" + model.ID + "");
            int rowsAffected = SQLiteHelper.Execute(dbStr, strSql.ToString());

            if (rowsAffected > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        /// <summary>
        /// 获取标签内容
        /// </summary>
        /// <param name="taskName"></param>
        /// <param name="collectionContentStepTime"></param>
        /// <param name="spiderViewUrl"></param>
        /// <param name="itemTaskLebel"></param>
        /// <param name="pageContent"></param>
        /// <param name="isTest"></param>
        /// <returns></returns>
        private string GetLabelContent(string taskName, int collectionContentStepTime, string spiderViewUrl, ModelTaskLabel itemTaskLebel, string pageContent, bool isTest = false)
        {
            var remoteViewUrl = itemTaskLebel.TestViewUrl;

            if (string.IsNullOrEmpty(itemTaskLebel.TestViewUrl))
            {
                remoteViewUrl = spiderViewUrl;
            }

            string regContent = HtmlHelper.Instance.ParseCollectionStrings(itemTaskLebel.LabelNameCutRegex);

            regContent = CommonHelper.ReplaceSystemRegexTag(regContent);
            string CutContent = CollectionHelper.Instance.CutStr(pageContent, regContent)[0];

            #region  载资源
            var imgTag = ImageDownHelper.GetImgTag(CutContent);
            if (itemTaskLebel.IsDownResource == 1)
            {
                string[] imgExtArr   = itemTaskLebel.DownResourceExts.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
                var      downImgPath = AppDomain.CurrentDomain.BaseDirectory + "Data\\Collection\\" + taskName + "\\Images\\";
                int      ii          = 1;
                foreach (var img in imgTag)
                {
                    var remoteImg = CollectionHelper.Instance.FormatUrl(remoteViewUrl, img);
                    var newImg    = DateTime.Now.ToString("yyyyMMddHHmmssffffff") + "_" + ii + ".jpg";
                    if (!string.IsNullOrEmpty(itemTaskLebel.DownResourceExts))
                    {
                        var imgExt = remoteImg.Substring(remoteImg.LastIndexOf("."));
                        if (imgExtArr.SingleOrDefault(x => x.ToLower() == imgExt.ToLower()) != imgExt.ToLower())
                        {
                            continue;
                        }
                    }
                    CutContent = CutContent.Replace(img, downImgPath + newImg);
                    if (!isTest)
                    {
                        QueueImgHelper.AddImg(Model.ID, downImgPath + newImg, remoteImg, collectionContentStepTime);
                    }
                    ii++;
                }
            }
            else
            {
                foreach (var img in imgTag)
                {
                    var remoteImg = CollectionHelper.Instance.FormatUrl(remoteViewUrl, img);
                    CutContent = CutContent.Replace(img, remoteImg);
                }
            }
            #endregion

            #region 结果为循环
            if (itemTaskLebel.IsLoop == 1)
            {
                string[] LabelString = CollectionHelper.Instance.CutStr(pageContent, regContent);
                foreach (string s in LabelString)
                {
                    CutContent += s + "$$$$";
                }
                int n = CutContent.LastIndexOf("$$$$");
                CutContent = CutContent.Remove(n, 4);
            }
            #endregion

            #region 过滤Html
            if (!string.IsNullOrEmpty(itemTaskLebel.LabelHtmlRemove))
            {
                string[] arr = itemTaskLebel.LabelHtmlRemove.Split(new string[] { "||||" }, StringSplitOptions.RemoveEmptyEntries);
                foreach (string str in arr)
                {
                    if (str == "all")
                    {
                        CutContent = CollectionHelper.Instance.NoHtml(CutContent);
                        break;
                    }
                    else if (str == "table")
                    {
                        CutContent = CollectionHelper.Instance.ScriptHtml(CutContent, "table", 2);
                    }
                    else if (str == "font<span>")
                    {
                        CutContent = CollectionHelper.Instance.ScriptHtml(CutContent, "font", 3);
                        CutContent = CollectionHelper.Instance.ScriptHtml(CutContent, "span", 3);
                    }
                    else if (str == "a")
                    {
                        CutContent = CollectionHelper.Instance.ScriptHtml(CutContent, "a", 3);
                    }
                }
            }
            #endregion

            #region 排除字符
            if (!string.IsNullOrEmpty(itemTaskLebel.LabelRemove))
            {
                foreach (string str in itemTaskLebel.LabelRemove.Split(new string[] { "$$$$" }, StringSplitOptions.RemoveEmptyEntries))
                {
                    string[] ListStr = str.Split(new string[] { "||" }, StringSplitOptions.RemoveEmptyEntries);
                    if (ListStr[1] == "1")
                    {
                        CutContent = CollectionHelper.RemoveHtml(CutContent, ListStr[0]);
                    }
                    else
                    {
                        CutContent = CutContent.Replace(ListStr[0], "");
                    }
                }
            }
            #endregion

            #region 替换字符
            if (!string.IsNullOrEmpty(itemTaskLebel.LabelReplace))
            {
                foreach (string str in itemTaskLebel.LabelReplace.Split(new string[] { "$$$$" }, StringSplitOptions.RemoveEmptyEntries))
                {
                    string[] ListStr = str.Split(new string[] { "||" }, StringSplitOptions.RemoveEmptyEntries);
                    CutContent = CutContent.Replace(ListStr[0], ListStr[1]);
                }
            }
            #endregion

            #region 加载插件
            string SpiderLabelPlugin = itemTaskLebel.SpiderLabelPlugin;
            if (SpiderLabelPlugin != "不使用插件" && !string.IsNullOrEmpty(SpiderLabelPlugin))
            {
                CutContent = PythonExtHelper.RunPython(PluginUtility.SpiderContentPluginPath + SpiderLabelPlugin, new object[] { remoteViewUrl, CutContent });
            }
            #endregion

            return(CutContent);
        }
Esempio n. 13
0
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            int            ID    = int.Parse("0" + this.txtID.Text);
            ModelTaskLabel model = new ModelTaskLabel();

            model.TaskID            = TaskID;
            model.LabelName         = this.txtLabelName.Text;
            model.LabelSource       = this.radioBtnSource.Checked ? 1 : 0;
            model.LabelNameCutRegex = this.txtLabelNameCutRegex.Text.Replace("'", "''");
            model.LabelRemove       = string.Empty;
            model.LabelReplace      = string.Empty;

            #region Html过滤
            model.LabelHtmlRemove = string.Empty;
            if (this.chkAllHtml.Checked)
            {
                model.LabelHtmlRemove += "all||||";
            }
            if (this.chkTable.Checked)
            {
                model.LabelHtmlRemove += "table||||";
            }
            if (this.chkFont.Checked)
            {
                model.LabelHtmlRemove += "font<span>||||";
            }
            if (this.chkhref.Checked)
            {
                model.LabelHtmlRemove += "a||||";
            }
            if (this.chkScript.Checked)
            {
                model.LabelHtmlRemove += "script||||";
            }
            if (model.LabelHtmlRemove.Trim() != "")
            {
                model.LabelHtmlRemove = model.LabelHtmlRemove.Remove(model.LabelHtmlRemove.Length - 4);
            }
            #endregion

            #region 标签内容过滤
            model.LblHtmlRemove = string.Empty;
            if (this.chkTableLbl.Checked)
            {
                model.LblHtmlRemove += "table||||";
            }
            if (this.chkScriptLbl.Checked)
            {
                model.LblHtmlRemove += "script||||";
            }
            if (this.chkHrefLbl.Checked)
            {
                model.LblHtmlRemove += "a||||";
            }
            if (this.chkSpanLbl.Checked)
            {
                model.LblHtmlRemove += "span||||";
            }
            if (this.chkPLbl.Checked)
            {
                model.LblHtmlRemove += "p||||";
            }
            if (this.chkIFrameLbl.Checked)
            {
                model.LblHtmlRemove += "iframe||||";
            }
            if (this.chkFontLbl.Checked)
            {
                model.LblHtmlRemove += "font||||";
            }
            if (this.chkStyleLbl.Checked)
            {
                model.LblHtmlRemove += "style||||";
            }
            if (this.chkDivLbl.Checked)
            {
                model.LblHtmlRemove += "div||||";
            }
            if (this.chkRemarkLbl.Checked)
            {
                model.LblHtmlRemove += "remark||||";
            }
            if (model.LblHtmlRemove.Trim() != "")
            {
                model.LblHtmlRemove = model.LblHtmlRemove.Remove(model.LblHtmlRemove.Length - 4);
            }
            #endregion
            #region 内容排除
            foreach (ListViewItem item in this.listViewContentRemove.Items)
            {
                //model.LabelRemove += item.SubItems[0].Text + "$$$$";
                model.LabelRemove += item.SubItems[0].Text + "||" + item.SubItems[1].Text + "$$$$";
            }
            if (model.LabelRemove.Trim() != "")
            {
                model.LabelRemove = model.LabelRemove.Remove(model.LabelRemove.Length - 4);
            }
            #endregion
            #region 内容替换
            foreach (ListViewItem item in this.listViewContentReplace.Items)
            {
                model.LabelReplace += item.SubItems[0].Text + "||" + item.SubItems[1].Text + "$$$$";
            }
            if (model.LabelReplace.Trim() != "")
            {
                model.LabelReplace = model.LabelReplace.Remove(model.LabelReplace.Length - 4);
            }
            #endregion

            model.IsLoop    = this.chkLabelIsLoop.Checked ? 1 : 0;
            model.IsNoNull  = this.chkLabelNoNull.Checked ? 1 : 0;
            model.IsLinkUrl = this.chkLabelIsLinkUrl.Checked ? 1 : 0;
            model.IsPager   = this.chkLabelIsPager.Checked ? 1 : 0;
            model.LabelValueLinkUrlRegex = this.txtLabelValueIsLinkUrlRegex.Text.Replace("'", "''");
            model.LabelValuePagerRegex   = this.txtLabelValueIsPagerRegex.Text.Replace("'", "''");
            //
            model.SpiderLabelPlugin = this.cmbSpiderPlugin.Text;
            //下载文件
            model.IsDownResource   = this.chkDownResource.Checked ? 1 : 0;
            model.DownResourceExts = this.txtDownResourceExt.Text;
            if (ID > 0)
            {
                model.ID = ID;
                dal.Update(model);
            }
            else if (ID == 0)
            {
                //获取最大的排序ID
                int OrderID = dal.GetMaxOrderID(TaskID) + 1;
                model.OrderID = OrderID;
                ID            = dal.Add(model);
            }
            if (ViewLabel != null)
            {
                ViewLabel(this, ev);
            }
            this.Hide();
            this.Close();
        }
Esempio n. 14
0
        /// <summary>
        /// 编辑标签
        /// </summary>
        private void Bind_DataEdit()
        {
            DALTaskLabel dal = new DALTaskLabel();

            ListView.SelectedListViewItemCollection item = (ListView.SelectedListViewItemCollection)EditItem;
            int            ID    = int.Parse("0" + item[0].Tag);
            ModelTaskLabel model = dal.GetModel(ID);

            this.txtID.Text        = ID.ToString();
            this.txtLabelName.Text = model.LabelName;
            if (model.LabelSource == 1)
            {
                this.radioBtnSource.Checked = true;
            }
            else
            {
                this.radioBtnUrl.Checked = true;
            }
            this.txtLabelNameCutRegex.Text = model.LabelNameCutRegex;
            this.chkScript.Checked         = false;
            this.chkhref.Checked           = false;
            if (!string.IsNullOrEmpty(model.LabelHtmlRemove))
            {
                string[] arr = model.LabelHtmlRemove.Split(new string[] { "||||" }, StringSplitOptions.RemoveEmptyEntries);
                foreach (string str in arr)
                {
                    if (str == "all")
                    {
                        this.chkAllHtml.Checked = true;
                    }
                    else if (str == "table")
                    {
                        this.chkTable.Checked = true;
                    }
                    else if (str == "font<span>")
                    {
                        this.chkFont.Checked = true;
                    }
                    else if (str == "a")
                    {
                        this.chkhref.Checked = true;
                    }
                    else if (str == "script")
                    {
                        this.chkScript.Checked = true;
                    }
                }
            }
            if (!string.IsNullOrEmpty(model.LblHtmlRemove))
            {
                string[] arr = model.LblHtmlRemove.Split(new string[] { "||||" }, StringSplitOptions.RemoveEmptyEntries);
                foreach (string str in arr)
                {
                    if (str == "table")
                    {
                        this.chkTableLbl.Checked = true;
                    }
                    else if (str == "script")
                    {
                        this.chkScriptLbl.Checked = true;
                    }
                    else if (str == "a")
                    {
                        this.chkHrefLbl.Checked = true;
                    }
                    else if (str == "span")
                    {
                        this.chkSpanLbl.Checked = true;
                    }
                    else if (str == "p")
                    {
                        this.chkPLbl.Checked = true;
                    }
                    else if (str == "iframe")
                    {
                        this.chkIFrameLbl.Checked = true;
                    }
                    else if (str == "font")
                    {
                        this.chkFontLbl.Checked = true;
                    }
                    else if (str == "style")
                    {
                        this.chkStyleLbl.Checked = true;
                    }
                    else if (str == "div")
                    {
                        this.chkDivLbl.Checked = true;
                    }
                    else if (str == "remark")
                    {
                        this.chkRemarkLbl.Checked = true;
                    }
                }
            }
            #region 内容排除
            if (!string.IsNullOrEmpty(model.LabelRemove))
            {
                foreach (string str in model.LabelRemove.Split(new string[] { "$$$$" }, StringSplitOptions.RemoveEmptyEntries))
                {
                    //ListViewItem lvi = new ListViewItem(str);
                    //this.listViewContentRemove.Items.Add(lvi);
                    string[]     aa  = str.Split(new string[] { "||" }, StringSplitOptions.None);
                    ListViewItem lvi = new ListViewItem(aa[0]);
                    lvi.SubItems.Add(aa[1]);
                    this.listViewContentRemove.Items.Add(lvi);
                }
            }
            #endregion

            #region 内容替换
            if (!string.IsNullOrEmpty(model.LabelReplace))
            {
                foreach (string str in model.LabelReplace.Split(new string[] { "$$$$" }, StringSplitOptions.RemoveEmptyEntries))
                {
                    string[]     aa  = str.Split(new string[] { "||" }, StringSplitOptions.None);
                    ListViewItem lvi = new ListViewItem(aa[0]);
                    lvi.SubItems.Add(aa[1]);
                    this.listViewContentReplace.Items.Add(lvi);
                }
            }
            #endregion


            this.chkLabelIsLoop.Checked    = model.IsLoop == 1 ? true : false;
            this.chkLabelNoNull.Checked    = model.IsNoNull == 1 ? true : false;
            this.chkLabelIsLinkUrl.Checked = model.IsLinkUrl == 1 ? true : false;
            this.chkLabelIsPager.Checked   = model.IsPager == 1 ? true : false;

            this.txtLabelValueIsLinkUrlRegex.Text = model.LabelValueLinkUrlRegex;
            this.txtLabelValueIsPagerRegex.Text   = model.LabelValuePagerRegex;


            this.cmbSpiderPlugin.Text = model.SpiderLabelPlugin == string.Empty ? "不使用插件" : model.SpiderLabelPlugin;

            //下载资源
            this.chkDownResource.Checked = model.IsDownResource == 1 ? true : false;
            this.txtDownResourceExt.Text = model.DownResourceExts;
        }