📄 configstep1.cs
字号:
namespace PowerEasy.WebSite.Admin.Collection
{
using PowerEasy.Collection;
using PowerEasy.Common;
using PowerEasy.CommonModel;
using PowerEasy.Contents;
using PowerEasy.Controls;
using PowerEasy.Model.Collection;
using PowerEasy.Model.CommonModel;
using PowerEasy.Model.Contents;
using PowerEasy.Web.UI;
using System;
using System.Collections.Generic;
using System.Web.UI.WebControls;
public class ConfigStep1 : AdminPage
{
protected Button BtnSubmit;
protected DropDownList DropModelId;
protected DropDownList DropNodeId;
protected HiddenField HdnAction;
protected HiddenField HdnItemName;
protected HiddenField HiddenModel;
protected AlternateLiteral LblTitle;
protected RadioButtonList RadlCodeType;
protected RadioButtonList RadOrderType;
protected ExtendedSiteMapPath SmpNavigator;
protected TextBox TxtIntro;
protected TextBox TxtItemName;
protected TextBox TxtMaxNum;
protected TextBox TxtUrl;
protected TextBox TxtWebSite;
protected PowerEasy.Controls.RequiredFieldValidator ValeItemName;
protected PowerEasy.Controls.RequiredFieldValidator ValeModelId;
protected PowerEasy.Controls.RequiredFieldValidator ValeNodeId;
protected PowerEasy.Controls.RequiredFieldValidator ValeUrl;
protected void DropNode_SelectedIndexChanged(object sender, EventArgs e)
{
this.SetModelList(DataConverter.CLng(this.DropNodeId.SelectedValue));
}
protected void EBtnSubmit_Click(object sender, EventArgs e)
{
if (this.Page.IsValid)
{
if (string.IsNullOrEmpty(this.TxtUrl.Text))
{
AdminPage.WriteErrMsg("采集URL地址不能为空!");
}
else if (this.TxtUrl.Text.Substring(0, 7) != "http://")
{
AdminPage.WriteErrMsg("采集URL不是有效的URL地址!");
}
else
{
bool flag;
CollectionItemInfo collectionItemInfo = new CollectionItemInfo();
collectionItemInfo.ItemName = this.TxtItemName.Text;
collectionItemInfo.NodeId = DataConverter.CLng(this.DropNodeId.SelectedValue);
collectionItemInfo.ModelId = DataConverter.CLng(this.DropModelId.SelectedValue);
collectionItemInfo.Url = this.TxtUrl.Text;
collectionItemInfo.UrlName = this.TxtWebSite.Text;
collectionItemInfo.CodeType = this.RadlCodeType.SelectedValue;
collectionItemInfo.MaxNum = DataConverter.CLng(this.TxtMaxNum.Text);
collectionItemInfo.OrderType = DataConverter.CLng(this.RadOrderType.SelectedValue);
collectionItemInfo.Intro = this.TxtIntro.Text;
collectionItemInfo.Detection = false;
bool flag2 = false;
if (this.HdnAction.Value == "Modify")
{
collectionItemInfo.ItemId = BasePage.RequestInt32("ItemID");
if (collectionItemInfo.ItemName == this.HdnItemName.Value)
{
flag = false;
}
else
{
flag = CollectionItem.Exists(collectionItemInfo.ItemName);
}
}
else
{
flag = CollectionItem.Exists(collectionItemInfo.ItemName);
}
if (flag)
{
AdminPage.WriteErrMsg("<li>数据库中已经存在此采集项目!</li>");
}
if (this.HdnAction.Value == "Modify")
{
if (collectionItemInfo.ModelId != DataConverter.CLng(this.HiddenModel.Value))
{
CollectionFieldRules.DeleteItem(collectionItemInfo.ItemId);
}
flag2 = CollectionItem.Update(collectionItemInfo);
}
else
{
flag2 = CollectionItem.Add(collectionItemInfo);
}
if (flag2)
{
BasePage.ResponseRedirect("ConfigStep2.aspx?Action=" + this.HdnAction.Value + "&ItemId=" + collectionItemInfo.ItemId.ToString());
}
else
{
AdminPage.WriteErrMsg("保存采集配置第一步失败!");
}
}
}
}
protected void Page_Load(object sender, EventArgs e)
{
string str = BasePage.RequestString("Action", "Add");
if (!base.IsPostBack)
{
this.DropNodeId.Items.Clear();
IList<NodeInfo> nodeNameForContainerItems = Nodes.GetNodeNameForContainerItems();
this.DropNodeId.DataSource = nodeNameForContainerItems;
this.DropNodeId.DataBind();
if (str == "Modify")
{
int id = BasePage.RequestInt32("ItemId");
if (id <= 0)
{
AdminPage.WriteErrMsg("<li>ItemID不存在!");
}
CollectionItemInfo infoById = CollectionItem.GetInfoById(id);
if (infoById.IsNull)
{
AdminPage.WriteErrMsg("<li>采集项目规则不存在!");
}
if (!infoById.IsNull)
{
this.TxtItemName.Text = infoById.ItemName;
this.DropNodeId.SelectedValue = infoById.NodeId.ToString();
this.TxtWebSite.Text = infoById.UrlName;
this.TxtUrl.Text = infoById.Url;
this.RadlCodeType.SelectedValue = infoById.CodeType;
this.TxtMaxNum.Text = infoById.MaxNum.ToString();
this.RadOrderType.SelectedValue = infoById.OrderType.ToString();
this.TxtIntro.Text = infoById.Intro;
this.SetModelList(infoById.NodeId);
this.DropModelId.SelectedValue = infoById.ModelId.ToString();
this.HdnAction.Value = str;
this.HdnItemName.Value = infoById.ItemName;
this.HiddenModel.Value = infoById.ModelId.ToString();
}
else
{
this.SetModelList(DataConverter.CLng(this.DropNodeId.Items[0].Value));
}
this.SmpNavigator.CurrentNode = "<span style='color:red;'>采集项目设置</span> >> <a title=\"列表页采集设置\" href=\"ConfigStep2.aspx?Action=Modify&ItemID=" + id.ToString() + "\">列表页采集设置</a> >> <a title=\"内容页采集设置\" href=\"ConfigStep3.aspx?Action=Modify&ItemID=" + id.ToString() + "\">内容页采集设置</a>";
}
else
{
this.SetModelList(DataConverter.CLng(this.DropNodeId.Items[0].Value));
}
}
}
protected void SetModelList(int nodeId)
{
this.DropModelId.Items.Clear();
foreach (NodesModelTemplateRelationShipInfo info2 in ModelManager.GetNodesModelTemplateList(nodeId))
{
ModelInfo cacheModelById = ModelManager.GetCacheModelById(info2.ModelId);
if (!cacheModelById.IsNull)
{
this.DropModelId.Items.Add(new ListItem(cacheModelById.ModelName, cacheModelById.ModelId.ToString()));
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -