TopicClassEdit.aspx.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. using CB.Framework;
  8. using CB.Common;
  9. using CB.Entity;
  10. using CB.Data;
  11. namespace CB.Admin.Plugins.Basic
  12. {
  13. public partial class TopicClassEdit : AdminPage
  14. {
  15. protected string Action = string.Empty;
  16. private static int id;
  17. protected void Page_Load(object sender, EventArgs e)
  18. {
  19. Action = WRequest.GetQueryString("Action");
  20. if (!Page.IsPostBack)
  21. {
  22. InitData();
  23. }
  24. }
  25. protected override void InitData()
  26. {
  27. BindList();
  28. }
  29. protected void BindList()
  30. {
  31. id = WRequest.GetQueryInt("id");
  32. TopicClassInfo entity = TopicClassService.Get(id);
  33. //绑定父类型
  34. int aindex = 0;
  35. IList<TopicClassInfo> ais = TopicClassService.ToList();
  36. int j = 0;
  37. foreach (var item in ais)
  38. {
  39. ddlParent.Items.Add(new ListItem(item.Name, item.Cid.ToString()));
  40. j++;
  41. if (entity != null && entity.ParentId == item.Cid)
  42. {
  43. aindex = j;
  44. }
  45. }
  46. if (entity != null && entity.Cid > 0)
  47. {
  48. txtcid.Text = entity.Cid.ToString().Trim();
  49. txtName.Text = entity.Name.ToString().Trim();
  50. ddlParent.SelectedIndex = aindex;
  51. }
  52. }
  53. //新增或修改
  54. protected void btnEdit_Click(object sender, EventArgs e)
  55. {
  56. #region 修改ID为自增
  57. //if (string.IsNullOrEmpty(txtcid.Text.Trim()))
  58. //{
  59. // ShowMessageBox("标题ID不能为空");
  60. //}
  61. //if (TypeConverter.StrToInt(txtcid.Text.Trim())<=0)
  62. //{
  63. // ShowMessageBox("标题ID大于0");
  64. //}
  65. #endregion
  66. if (string.IsNullOrEmpty(txtName.Text.Trim()))
  67. {
  68. ShowMessageBox("名称不能为空!");
  69. }
  70. TopicClassInfo entity = new TopicClassInfo
  71. {
  72. Cid = TypeConverter.StrToInt(txtcid.Text.Trim()),
  73. Name = txtName.Text.Trim(),
  74. ParentId = TypeConverter.StrToInt(ddlParent.SelectedValue),
  75. RootId = TypeConverter.StrToInt(ddlParent.SelectedValue),
  76. Depth = TypeConverter.StrToInt(ddlParent.SelectedValue) > 0 ? CB.Data.TopicClassService.Get(TypeConverter.StrToInt(ddlParent.SelectedValue)).Depth + 1 : TypeConverter.StrToInt(ddlParent.SelectedValue)
  77. };
  78. if (CB.Data.TopicClassService.Get(entity.Cid) != null && Action == "Add")
  79. {
  80. ShowMessageBox("已存在改CID数据,若要修改,请执行修改操作");
  81. }
  82. if (TopicClassService.Save(entity))
  83. {
  84. string returnPath = System.Web.HttpContext.Current.Request.Path;
  85. //生成当期及后期数据走势图和遗漏数据
  86. if (Action == "Add")
  87. {
  88. Logs("添加标题类型", string.Format("添加标题类型[Cid={0}]", entity.Cid));
  89. ShowMessageBox("提示:添加成功!", returnPath + "?authPage=TopicList");
  90. }
  91. if (Action == "Modify")
  92. {
  93. Logs("修改区域", string.Format("修改区域[Cid={0}]", entity.Cid));
  94. ShowMessageBox("提示:修改成功!", returnPath + "?authPage=TopicList");
  95. }
  96. }
  97. else
  98. {
  99. ShowMessageBox("提示:操作失败!");
  100. }
  101. }
  102. //重置
  103. protected void btnClear_Click(object sender, EventArgs e)
  104. {
  105. txtName.Text = string.Empty;
  106. txtcid.Text = string.Empty;
  107. ddlParent.SelectedIndex = 0;
  108. }
  109. }
  110. }