AreaEdit.aspx.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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.Common;
  8. using CB.Entity;
  9. using CB.Framework;
  10. using CB.Data;
  11. using CB.TVUCenter.Config;
  12. namespace CB.Admin.Plugins.Lottery
  13. {
  14. public partial class AreaEdit : AdminPage
  15. {
  16. protected string Action = string.Empty;
  17. private static int id;
  18. protected void Page_Load(object sender, EventArgs e)
  19. {
  20. Action = WRequest.GetQueryString("Action");
  21. if (!Page.IsPostBack)
  22. {
  23. InitData();
  24. }
  25. }
  26. protected override void InitData()
  27. {
  28. BindList();
  29. }
  30. protected void BindList()
  31. {
  32. id = WRequest.GetQueryInt("id");
  33. AreaInfo entity = AreaService.Get(id);
  34. //绑定父类型
  35. int aindex = 0;
  36. int areaindex = 0;
  37. IList<AreaInfo> ais = AreaService.ToList();
  38. int j = 0;
  39. foreach (var item in ais)
  40. {
  41. ddlParent.Items.Add(new ListItem(item.Name,item.Aid.ToString()));
  42. j++;
  43. if (entity!=null&&entity.ParentId==item.Aid)
  44. {
  45. aindex = j;
  46. }
  47. }
  48. Array temp = Enum.GetValues(typeof(AreaType));
  49. for (int i = 0; i < temp.Length; i++)
  50. {
  51. string info = temp.GetValue(i).ToString();
  52. ddlAreaTypes.Items.Add(new ListItem(GetType(info),(i+1).ToString()));
  53. if (entity != null && info == entity.Depth.ToString())
  54. {
  55. areaindex = i + 1;
  56. }
  57. }
  58. if (entity!=null)
  59. {
  60. txtName.Text = entity.Name.ToString().Trim();
  61. ddlAreaTypes.SelectedIndex = areaindex;
  62. ddlParent.SelectedIndex = aindex;
  63. }
  64. }
  65. private string GetType(string type)
  66. {
  67. switch (type)
  68. {
  69. case "Country":
  70. return "全国性";
  71. case "Province":
  72. return "全省性";
  73. case "Area":
  74. return "地区联销";
  75. default:
  76. return "";
  77. }
  78. }
  79. //新增或修改
  80. protected void btnEdit_Click(object sender, EventArgs e)
  81. {
  82. if (string.IsNullOrEmpty(txtName.Text.Trim()))
  83. {
  84. ShowMessageBox("名称不能为空!");
  85. }
  86. if (ddlAreaTypes.SelectedIndex==0)
  87. {
  88. ShowMessageBox("请选择区域类型!");
  89. }
  90. AreaInfo entity = new AreaInfo {
  91. Aid=id,
  92. Name=txtName.Text.Trim(),
  93. ParentId=Convert.ToInt32(this.ddlParent.SelectedValue),
  94. Depth=(AreaType)Convert.ToInt32(this.ddlAreaTypes.SelectedValue)
  95. };
  96. if (AreaService.Save(entity))
  97. {
  98. //生成当期及后期数据走势图和遗漏数据
  99. if (Action == "Add")
  100. {
  101. UpdateTvConfig();
  102. Logs("添加区域", string.Format("添加区域[Name={0}]", entity.Name));
  103. ShowMessageBox("提示:添加成功!");
  104. }
  105. if (Action == "Modify")
  106. {
  107. UpdateTvConfig();
  108. Logs("修改区域", string.Format("修改区域[ID={0}]", entity.Aid));
  109. ShowMessageBox("提示:修改成功!");
  110. }
  111. }
  112. else
  113. {
  114. ShowMessageBox("提示:操作失败!");
  115. }
  116. }
  117. private bool UpdateTvConfig()
  118. {
  119. TVConfigInfo entity = CB.TVUCenter.Config.TVConfigs.GetConfig();
  120. entity.AreaVersion =TypeConverter.StrToInt(DateTime.Now.ToString("yyyyMMddHH").Substring(2, 8));
  121. return CB.TVUCenter.Config.TVConfigs.UpdateConfig(entity);
  122. }
  123. //重置
  124. protected void btnClear_Click(object sender, EventArgs e)
  125. {
  126. txtName.Text = string.Empty;
  127. ddlAreaTypes.SelectedIndex = 0;
  128. ddlParent.SelectedIndex = 0;
  129. }
  130. }
  131. }