private void btnFinish_Click(object sender, EventArgs e) { KiwiCrawler.Model.Urlconfigs_k urlFrmMode = new KiwiCrawler.Model.Urlconfigs_k(); urlFrmMode.kAddressBusinessType = txtBusinessType.Text.Trim(); urlFrmMode.kCaptureType = cbCaptureType.Text.Trim(); urlFrmMode.kComplateDegree = 0; urlFrmMode.kDetailPattern = txtDetailPattern.Text.Trim(); urlFrmMode.kDetailPatternType = cbDetailPatternType.Text.Trim(); urlFrmMode.kKeyWords = txtKeyWords.Text.Trim(); urlFrmMode.kNextPagePattern = txtNextPagePattern.Text.Trim(); urlFrmMode.kNextPagePatternType = cbNextPagePatternType.Text.Trim(); urlFrmMode.kPageTotal = String.IsNullOrEmpty(txtPageNum.Text.Trim()) ? -1 : Int32.Parse(txtPageNum.Text.Trim()); urlFrmMode.kUrl = txtUrl.Text.Trim(); string msg = ""; //保存到数据库 KiwiCrawler.BLL.Urlconfigs_kBll bll = new KiwiCrawler.BLL.Urlconfigs_kBll(); if (bll.Add(urlFrmMode)) { msg += "添加种子链接成功。\r\n"; //添加到抽取配置表 KiwiCrawler.BLL.Extractionconfig_kBll extractionconfigBll = new KiwiCrawler.BLL.Extractionconfig_kBll(); KiwiCrawler.Model.Extractionconfig_k extractionconfigModel = new KiwiCrawler.Model.Extractionconfig_k(); //extractionconfigModel.KId = bll.GetMaxId()-1;//查询出来的比实际加了1 extractionconfigModel.KId = bll.GetModelList("kUrl='" + urlFrmMode.kUrl + "'").FirstOrDefault().kId; extractionconfigModel.KUrl = urlFrmMode.kUrl; extractionconfigModel.KKeyword = urlFrmMode.kKeyWords; extractionconfigModel.KPercent = 0; if (extractionconfigBll.Add(extractionconfigModel)) { msg += "同步抽取信息成功。\r\n"; } else { msg += "同步抽取信息失败。"; } } else { msg += "添加种子链接失败。\r\n"; } MessageBox.Show(msg); urlFrmMode_k = urlFrmMode; this.Close(); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(KiwiCrawler.Model.Extractionconfig_k model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update extractionconfig_k set "); strSql.Append("KId=@KId,"); strSql.Append("KUrl=@KUrl,"); strSql.Append("KTitle=@KTitle,"); strSql.Append("KPublishDateTime=@KPublishDateTime,"); strSql.Append("KContent=@KContent,"); strSql.Append("KAddressBusinessType=@KAddressBusinessType,"); strSql.Append("KKeyword=@KKeyword,"); strSql.Append("KPercent=@KPercent"); strSql.Append(" where "); MySqlParameter[] parameters = { new MySqlParameter("@KId", MySqlDbType.Int32, 11), new MySqlParameter("@KUrl", MySqlDbType.Text), new MySqlParameter("@KTitle", MySqlDbType.Text), new MySqlParameter("@KPublishDateTime", MySqlDbType.DateTime), new MySqlParameter("@KContent", MySqlDbType.Text), new MySqlParameter("@KAddressBusinessType", MySqlDbType.Text), new MySqlParameter("@KKeyword", MySqlDbType.Text), new MySqlParameter("@KPercent", MySqlDbType.Float) }; parameters[0].Value = model.KId; parameters[1].Value = model.KUrl; parameters[2].Value = model.KTitle; parameters[3].Value = model.KPublishDateTime; parameters[4].Value = model.KContent; parameters[5].Value = model.KAddressBusinessType; parameters[6].Value = model.KKeyword; parameters[7].Value = model.KPercent; int rows = DbHelperMySQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public KiwiCrawler.Model.Extractionconfig_k DataRowToModel(DataRow row) { KiwiCrawler.Model.Extractionconfig_k model = new KiwiCrawler.Model.Extractionconfig_k(); if (row != null) { if (row["KId"] != null && row["KId"].ToString() != "") { model.KId = int.Parse(row["KId"].ToString()); } if (row["KUrl"] != null) { model.KUrl = row["KUrl"].ToString(); } if (row["KTitle"] != null) { model.KTitle = row["KTitle"].ToString(); } if (row["KPublishDateTime"] != null && row["KPublishDateTime"].ToString() != "") { model.KPublishDateTime = DateTime.Parse(row["KPublishDateTime"].ToString()); } if (row["KContent"] != null) { model.KContent = row["KContent"].ToString(); } if (row["KAddressBusinessType"] != null) { model.KAddressBusinessType = row["KAddressBusinessType"].ToString(); } if (row["KKeyword"] != null) { model.KKeyword = row["KKeyword"].ToString(); } if (row["KPercent"] != null && row["KPercent"].ToString() != "") { model.KPercent = decimal.Parse(row["KPercent"].ToString()); } } return(model); }
/// <summary> /// 得到一个对象实体 /// </summary> public KiwiCrawler.Model.Extractionconfig_k GetModel() { //该表无主键信息,请自定义主键/条件字段 StringBuilder strSql = new StringBuilder(); strSql.Append("select KId,KUrl,KTitle,KPublishDateTime,KContent,KAddressBusinessType,KKeyword,KPercent from extractionconfig_k "); strSql.Append(" where "); MySqlParameter[] parameters = { }; KiwiCrawler.Model.Extractionconfig_k model = new KiwiCrawler.Model.Extractionconfig_k(); DataSet ds = DbHelperMySQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
/// <summary> /// 得到一个对象实体 /// </summary> public KiwiCrawler.Model.Extractionconfig_k DataRowToModel(DataRow row) { KiwiCrawler.Model.Extractionconfig_k model=new KiwiCrawler.Model.Extractionconfig_k(); if (row != null) { if(row["KId"]!=null && row["KId"].ToString()!="") { model.KId=int.Parse(row["KId"].ToString()); } if(row["KUrl"]!=null) { model.KUrl=row["KUrl"].ToString(); } if(row["KTitle"]!=null) { model.KTitle=row["KTitle"].ToString(); } if(row["KPublishDateTime"]!=null && row["KPublishDateTime"].ToString()!="") { model.KPublishDateTime=DateTime.Parse(row["KPublishDateTime"].ToString()); } if(row["KContent"]!=null) { model.KContent=row["KContent"].ToString(); } if(row["KAddressBusinessType"]!=null) { model.KAddressBusinessType=row["KAddressBusinessType"].ToString(); } if(row["KKeyword"]!=null) { model.KKeyword=row["KKeyword"].ToString(); } if(row["KPercent"]!=null && row["KPercent"].ToString()!="") { model.KPercent=decimal.Parse(row["KPercent"].ToString()); } } return model; }
/// <summary> /// 得到一个对象实体 /// </summary> public KiwiCrawler.Model.Extractionconfig_k GetModel() { //该表无主键信息,请自定义主键/条件字段 StringBuilder strSql=new StringBuilder(); strSql.Append("select KId,KUrl,KTitle,KPublishDateTime,KContent,KAddressBusinessType,KKeyword,KPercent from extractionconfig_k "); strSql.Append(" where "); MySqlParameter[] parameters = { }; KiwiCrawler.Model.Extractionconfig_k model=new KiwiCrawler.Model.Extractionconfig_k(); DataSet ds=DbHelperMySQL.Query(strSql.ToString(),parameters); if(ds.Tables[0].Rows.Count>0) { return DataRowToModel(ds.Tables[0].Rows[0]); } else { return null; } }