123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using CB.Framework;
- using CB.Common;
- using CB.Data;
- using CB.Entity;
- using System.Text.RegularExpressions;
- using System.Text;
- using CB.TrendTool;
- using System.Reflection;
- namespace CB.Admin.Plugins.TrendTool
- {
- public partial class TrendToolInfoPage : AdminPage
- {
- protected int PageId = 0;
- protected void Page_Load(object sender, EventArgs e)
- {
- PageId = WRequest.GetInt("PageID", 0);
- if (!IsPostBack)
- {
- List<ToolFunctionAttr> list = new List<ToolFunctionAttr>();
- BindList<TrendToolRule>(ref list);
- foreach (ToolFunctionAttr item in list)
- {
- ListItem li = new ListItem(item.Name, ((int)item.FilterType).ToString());
- ddlFilterFunEnum.Items.Add(li);
- }
- BindRepeaterList();
- }
- }
- protected override void BindRepeaterList()
- {
- int id = WRequest.GetInt("ID", 0);
- List<Entity.TrendToolInfo> lists = new List<Entity.TrendToolInfo>();
- lists = TrendToolService.ChildToList(new Entity.TrendToolInfo() { Id = id }).ToList();
- //lists = Caches.GetTrendToolChildList(new Entity.TrendToolInfo() { Id = id }).ToList();
- repeaterList.DataSource = lists;
- repeaterList.DataBind();
- BindDropDownListToolName(lists.ToList());
- }
- int levelNum = 1;
- private void BindDropDownListToolName(List<TrendToolInfo> list, int parentId = -1)
- {
- TrendToolInfo parent = new TrendToolInfo();
- parent = parentId == -1 ? list.Find(x => x.ParentID == parentId) : list.Find(x => x.Id == parentId);
- if (parentId == -1)
- {
- ddlParentID.Items.Clear();
- ddlParentID.Items.Insert(0, new ListItem("--请选择--", "-1"));
- }
- if (parent != null)
- {
- ListItem li = new ListItem(GetPrefix() + parent.ToolName, parent.Id.ToString());
- ddlParentID.Items.Add(li);
- }
- List<TrendToolInfo> childs = list.FindAll(x => parent != null && x.ParentID == parent.Id);
- foreach (TrendToolInfo item in childs)
- {
- List<TrendToolInfo> childItems = list.FindAll(x => x.ParentID == item.Id);
- levelNum += 1;
- if (childItems.Count > 0)
- {
- BindDropDownListToolName(list, item.Id);
- }
- else
- {
- ListItem li = new ListItem(GetPrefix() + item.ToolName, item.Id.ToString());
- ddlParentID.Items.Add(li);
- }
- levelNum -= 1;
- }
- }
- private string GetPrefix()
- {
- string prefix = "";
- for (int i = 0; i < levelNum; i++)
- {
- prefix += "-";
- }
- return prefix;
- }
- protected void repeaterList_ItemCommand(object source, RepeaterCommandEventArgs e)
- {
- switch (e.CommandName)
- {
- case "dnedit":
- {
- int id = TypeConverter.ObjectToInt(e.CommandArgument, 0);
- Entity.TrendToolInfo entity = TrendToolService.Get(id);
- BindEntityToPage(entity);
- }
- break;
- case "dndel":
- {
- int id = TypeConverter.ObjectToInt(e.CommandArgument, 0);
- TrendToolService.Delete(id);
- BindRepeaterList();
- }
- break;
- }
- }
- protected void btnUpdate_Click(object sender, EventArgs e)
- {
- }
- protected void btnClear_Click(object sender, EventArgs e)
- {
- ClearFormElement();
- }
- protected void btnSave_Click(object sender, EventArgs e)
- {
- TrendToolInfo nowEntity = PageToEntity(false);
- TrendToolService.Save(nowEntity);
- ClearFormElement();
- BindRepeaterList();
- //ShowMessageBox("保存成功!");
- }
- protected void btnCreateHTML_Click(object sender, EventArgs e)
- {
- if (this.ddlParentID.SelectedValue == "")
- {
- ShowMessageBox("请选择父节点");
- return;
- }
- TrendToolInfo nowEntity = PageToEntity(true);
- List<Entity.TrendToolInfo> lists = new List<Entity.TrendToolInfo>();
- //lists = TrendToolService.ChildToList(new Entity.TrendToolInfo() { Id = nowEntity.Id }).ToList();
- lists = Caches.GetTrendToolChildList(new Entity.TrendToolInfo() { Id = nowEntity.Id }).ToList();
- lists.Remove(lists.Find(x => x.Id == nowEntity.Id));
- lists.Add(nowEntity);
- lists = lists.OrderBy(x => x.ToolOrder).ToList();
- string html = TrendToolHtml.GetToolHtml(nowEntity.Id, lists);
- if (html.Length > 4)
- {
- if (html.Trim().Substring(0, 4) == "<tr>")
- { html = "<table>" + html + "</table>"; }
- }
- this.txtOldHTML.Value = html;
- }
- /// <summary>
- /// 实体绑定到页面
- /// </summary>
- /// <param name="entity"></param>
- private void BindEntityToPage(TrendToolInfo entity)
- {
- //this.txtNewHTML.Value = "";
- this.txtID.Value = entity.Id.ToString();
- this.txtToolName.Text = entity.ToolName;
- this.txtTitle.Text = entity.Title;
- this.txtRemark.Text = entity.Remark;
- this.txtPageID.Value = entity.PageID.ToString();
- this.txtItemValue.Text = entity.ItemValue;
- this.txtItemCount.Text = entity.ItemCount.ToString();
- this.txtIndexStart.Text = entity.IndexStart.ToString();
- this.txtIndexEnd.Text = entity.IndexEnd.ToString();
- string html = entity.HTML;
- if (entity.HTML.Length > 0 && html.Trim().Substring(0, 4) == "<tr>")
- { html = "<table>" + html + "</table>"; }
- this.txtOldHTML.Value = html;
- this.txtTemplateHtml.Value = entity.TemplateHTML;
- this.txtToolOrder.Text = entity.ToolOrder.ToString();
- this.ddlStatus.ClearSelection();
- ListItem li0 = this.ddlStatus.Items.FindByValue(Convert.ToInt32(entity.Status).ToString());
- if (li0 != null) li0.Selected = true;
- this.ddlIsSaveData.ClearSelection();
- ListItem li1 = this.ddlIsSaveData.Items.FindByValue(entity.IsSaveData.ToString());
- if (li1 != null) li1.Selected = true;
- this.ddlFilterFunEnum.ClearSelection();
- ListItem li2 = ddlFilterFunEnum.Items.FindByValue(Convert.ToInt32(entity.FilterFunEnum).ToString());
- if (li2 != null) li2.Selected = true;
- //this.ddlToolType.ClearSelection();
- //this.ddlToolType.SelectedValue = Convert.ToInt32(entity.ToolType).ToString();
- this.ddlParentID.ClearSelection();
- ListItem li3 = this.ddlParentID.Items.FindByValue(entity.ParentID.ToString());
- if (li3 != null) li3.Selected = true;
- this.ddlFilterCodeType.ClearSelection();
- ListItem li4 = this.ddlFilterCodeType.Items.FindByValue(Convert.ToInt32(entity.FilterCodeType).ToString());
- if (li4 != null) li4.Selected = true;
- }
- /// <summary>
- /// 页面转换为实体
- /// </summary>
- /// <param name="isCreateHtml">是否是重新生成HTML</param>
- /// <returns></returns>
- private TrendToolInfo PageToEntity(bool isCreateHtml)
- {
- TrendToolInfo entity = new TrendToolInfo();
- entity.Id = TypeConverter.ObjectToInt(this.txtID.Value, 0);
- entity.ToolName = this.txtToolName.Text.Trim();
- entity.ItemValue = this.txtItemValue.Text.Trim();
- entity.Title = this.txtTitle.Text.Trim();
- entity.Remark = this.txtRemark.Text.Trim();
- string html = this.txtOldHTML.Value.Trim();
- if (!isCreateHtml && html.Length > 7)
- {
- if (html.Substring(0, 7) == "<table>")
- html = html.Substring(7, html.Length - 7).Trim();
- if (html.Substring(0, 7) == "<tbody>")
- html = html.Substring(7, html.Length - 7).Trim();
- if (html.Substring(html.Length - 8, 8) == "</table>")
- html = html.Substring(0, html.Length - 8).Trim();
- if (html.Substring(html.Length - 8, 8) == "</tbody>")
- html = html.Substring(0, html.Length - 8).Trim();
- entity.HTML = html.Trim();
- }
- entity.TemplateHTML = this.txtTemplateHtml.Value.Trim();
- if (string.IsNullOrEmpty(this.txtPageID.Value.Trim()))
- {
- PageId = WRequest.GetInt("PageID", 0);
- }
- entity.PageID = PageId;
- entity.ParentID = TypeConverter.ObjectToInt(this.ddlParentID.SelectedValue, -1);
- entity.ItemCount = TypeConverter.ObjectToInt(this.txtItemCount.Text.Trim());
- entity.IndexStart = TypeConverter.ObjectToInt(this.txtIndexStart.Text.Trim());
- entity.IndexEnd = TypeConverter.ObjectToInt(this.txtIndexEnd.Text.Trim());
- entity.ToolOrder = TypeConverter.ObjectToInt(this.txtToolOrder.Text.Trim());
- string statusValue = this.ddlStatus.SelectedValue;
- entity.Status = TypeConverter.StringToEnum<FilterStatus>(statusValue);
- string funValue = ddlFilterFunEnum.SelectedValue;
- entity.FilterFunEnum = TypeConverter.StringToEnum<FilterType>(funValue);
- //string toolTypeValue = ddlToolType.SelectedValue;
- //entity.ToolType = TypeConverter.StringToEnum<ToolType>(toolTypeValue);
- string filterCodeType = ddlFilterCodeType.SelectedValue;
- entity.FilterCodeType = TypeConverter.StringToEnum<FilterCodeType>(filterCodeType);
- entity.IsSaveData = TypeConverter.ObjectToBool(this.txtTitle.Text.Trim(), false);
- return entity;
- }
- private void ClearFormElement()
- {
- this.form1.Controls.OfType<TextBox>().ToList().ForEach(t => t.Text = "");
- this.form1.Controls.OfType<DropDownList>().ToList().ForEach(t => { t.ClearSelection(); t.SelectedIndex = 0; });
- this.form1.Controls.OfType<HiddenField>().ToList().ForEach(t => t.Value = "");
- this.form1.Controls.OfType<Label>().ToList().ForEach(t => t.Text = "");
- this.txtTemplateHtml.Value = "";
- this.txtOldHTML.Value = "";
- }
- protected void Button1_Click(object sender, EventArgs e)
- {
- TrendToolHtml.GetToolsHtml(PageId);
- }
- //绑定方法列表方法
- private void BindList<T>(ref List<ToolFunctionAttr> lists)
- {
- MethodInfo[] methodList = typeof(T).GetMethods();
- if (null == methodList || 0 >= methodList.Length) return;
- foreach (MethodInfo item in methodList)
- {
- ToolFunctionAttr[] description = item.GetCustomAttributes(typeof(ToolFunctionAttr), false) as ToolFunctionAttr[];
- if (null != description && 1 <= description.Length)
- lists.Add(new ToolFunctionAttr(description[0].Name, description[0].FilterType));
- }
- }
- }
- }
|