/// <summary> /// 新增抓取规则 /// </summary> /// <param name="crawlRule"></param> /// <returns></returns> private int SaveCrawlRule(CrawlRuleViewModel crawlRule) { if (string.IsNullOrEmpty(crawlRule.Name) || string.IsNullOrEmpty(crawlRule.Url) || string.IsNullOrEmpty(crawlRule.Partten)) { return(0); } var row = SQLite.ExecuteNonQuery("INSERT INTO crawl_rules(ID, NAME, URL, PARTTEN, MAX_PAGE, ENABLE) VALUES ((SELECT MAX(ID)+1 FROM crawl_rules), @Name, @Url, @Partten, @MaxPage, @Enable)", new List <SQLiteParameter> { new SQLiteParameter("@Name", crawlRule.Name), new SQLiteParameter("@Url", crawlRule.Url), new SQLiteParameter("@Partten", crawlRule.Partten), new SQLiteParameter("@MaxPage", crawlRule.MaxPage), new SQLiteParameter("@Enable", crawlRule.Enable) }); if (row > 0) { //查询最新添加的记录ID var newID = SQLite.sqlone("SELECT MAX(id) FROM crawl_rules", null); crawlRule.Id = Convert.ToInt32(newID); } if (crawlRule.Enable == Convert.ToByte(1)) { ProxyFactoryV2.RestartCrawlIPService(); } return(row); }
public EditCrawlDialog(CrawlRuleViewModel crawlRule) { InitializeComponent(); DataContext = this; if (null != crawlRule) { McrawlRule = crawlRule; } }
/// <summary> /// 修改抓取规则 /// </summary> /// <param name="crawlRule"></param> /// <returns></returns> private int ModifyCrawlRule(CrawlRuleViewModel crawlRule) { var row = SQLite.ExecuteNonQuery("UPDATE crawl_rules SET NAME = @Name, URL = @Url, PARTTEN = @Partten, MAX_PAGE = @MaxPage, ENABLE = @Enable WHERE ID = @Id", new List <SQLiteParameter> { new SQLiteParameter("@Name", crawlRule.Name), new SQLiteParameter("@Url", crawlRule.Url), new SQLiteParameter("@Partten", crawlRule.Partten), new SQLiteParameter("@MaxPage", crawlRule.MaxPage), new SQLiteParameter("@Enable", crawlRule.Enable), new SQLiteParameter("@Id", crawlRule.Id) }); if (crawlRule.Enable == Convert.ToByte(1)) { ProxyFactoryV2.RestartCrawlIPService(); } return(row); }