//整行选中进入编辑模式 private void dgvconfigspider_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e) { try { DataGridView dgvcurrnet = sender as DataGridView; var rowindex = e.RowIndex; DataGridViewRow row = dgvconfigspider.Rows[rowindex]; var spiderConfigID = Convert.ToInt32(row.Cells["SpiderConfigID"].Value); var sid = Convert.ToInt32(row.Cells["Sid"].Value); Model.spiderconfig config = bllspiderconfig.GetModel(spiderConfigID); Model.spider spidermodel = bllspider.GetModel(sid); if (config != null && config.Cid > 0) { txtselectpath.Text = config.SpiderPath; cbxspider.DataSource = null; cbxspider.Items.Clear(); cbxspider.Items.Insert(0, spidermodel.SpiderName); cbxspider.SelectedIndex = 0; if (!string.IsNullOrEmpty(config.LogName)) { cbxlog.SelectedItem = Path.GetExtension(config.LogName); if (config.LogName.Contains("nolog")) { cbxlog.SelectedItem = config.LogName; } txtlogname.Text = Path.GetFileNameWithoutExtension(config.LogName); } if (!string.IsNullOrEmpty(config.SpiderOutPut)) { cbxoutput.SelectedItem = Path.GetExtension(config.SpiderOutPut); txtoutputname.Text = Path.GetFileNameWithoutExtension(config.SpiderOutPut); } txtconfigname.Text = config.ConfigName; txtautoparms.Text = config.AutoParms; lblhidconfigid.Text = config.Cid.ToString(); NoteInfo(Info.Right, "当前成功选中行:" + (e.RowIndex + 1).ToString()); } } catch (Exception ex) { NoteInfo(Info.Error, "出现未知错误:" + ex.ToString()); } }
//edit the config spider model private void btnconfigedit_Click(object sender, EventArgs e) { int spiderconfigid = Convert.ToInt32(lblhidconfigid.Text.ToString()); if (spiderconfigid == 0) { return; } Model.spiderconfig spiderconfig = bllspiderconfig.GetModel(spiderconfigid); if (spiderconfig == null || spiderconfig.Cid < 1) { return; } spiderconfig.ConfigName = txtconfigname.Text.Trim(); spiderconfig.SpiderPath = txtselectpath.Text.Trim(); spiderconfig.AutoParms = txtautoparms.Text.Trim(); spiderconfig.LogName = ""; spiderconfig.SpiderOutPut = ""; if (txtlogname.Visible) { spiderconfig.LogName = txtlogname.Text.Trim() + cbxlog.SelectedItem.ToString(); } if (cbxlog.SelectedItem.ToString().Contains("nolog") && !txtlogname.Visible) { spiderconfig.LogName = cbxlog.SelectedItem.ToString(); } if (txtoutputname.Visible) { spiderconfig.SpiderOutPut = txtoutputname.Text.Trim() + cbxoutput.SelectedItem.ToString(); } if (bllspiderconfig.Update(spiderconfig)) { NoteInfo(Info.Right, "更新方案成功"); LoadSpider(); } else { NoteInfo(Info.Error, "更新方案失败"); } }
//AddConfig private void btnaddconfig_Click(object sender, EventArgs e) { NoteInfo(Info.Loading, "增加方案中..."); try { Model.spiderconfig spiderconfig = new Model.spiderconfig(); spiderconfig.ConfigName = txtconfigname.Text.Trim(); spiderconfig.SpiderPath = txtselectpath.Text.Trim(); spiderconfig.AutoParms = txtautoparms.Text.Trim(); spiderconfig.LogName = ""; spiderconfig.SpiderOutPut = ""; if (txtlogname.Visible) { spiderconfig.LogName = txtlogname.Text.Trim() + cbxlog.SelectedItem.ToString(); } if (cbxlog.SelectedItem.ToString().Contains("nolog") && !txtlogname.Visible) { spiderconfig.LogName = cbxlog.SelectedItem.ToString(); } if (txtoutputname.Visible) { spiderconfig.SpiderOutPut = txtoutputname.Text.Trim() + cbxoutput.SelectedItem.ToString(); } if (bllspiderconfig.Add(spiderconfig)) { NoteInfo(Info.Right, "新增一条配置成功!"); LoadSpider(); } else { NoteInfo(Info.Error, "新增失败!"); } } catch (Exception ex) { NoteInfo(Info.Error, "增加方案失败:" + ex.ToString()); throw; } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(ScrapyForm.Model.spiderconfig model) { return(dal.Update(model)); }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(ScrapyForm.Model.spiderconfig model) { return(dal.Add(model)); }