LotteryEdit.aspx.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Web;
  6. using System.Web.UI;
  7. using System.Web.UI.WebControls;
  8. using CB.Admin.Plugins.OpenCode;
  9. using CB.Common;
  10. using CB.Data;
  11. using CB.Entity;
  12. using CB.Framework;
  13. namespace CB.Admin.Plugins.Lottery
  14. {
  15. public partial class LotteryEdit : AdminPage
  16. {
  17. protected string title = string.Empty, Action = string.Empty;
  18. private int Cid = 0; //Cid表示彩种
  19. protected void Page_Load(object sender, EventArgs e)
  20. {
  21. Action = WRequest.GetQueryString("Action");
  22. Cid = WRequest.GetQueryInt("Cid");
  23. if (!Page.IsPostBack)
  24. {
  25. InitData();
  26. }
  27. }
  28. protected override void InitData()
  29. {
  30. BindList();
  31. }
  32. protected void BindList()
  33. {
  34. IList<AreaInfo> arealist = AreaService.ToList();
  35. if (null != arealist && arealist.Count > 0)
  36. {
  37. foreach (var item in arealist)
  38. {
  39. dpArea.Items.Add(new ListItem(item.Name, item.Aid.ToString()));
  40. }
  41. }
  42. if (Action == "Add")
  43. {
  44. title = "添加";
  45. }
  46. if (Action == "Modify")
  47. {
  48. title = "修改";
  49. LotteryInfo entity = LotteryService.Get(Cid);
  50. if (null != entity)
  51. {
  52. txtLotteryName.Text = entity.Name;
  53. txtTerm.Text = entity.Term;
  54. txtOrderBy.Text = entity.OrderBy.ToString();
  55. dpArea.SelectedValue = entity.Aid.ToString();
  56. dpFrequency.SelectedValue = entity.Frequency ? "1" : "0";
  57. dpStatus.SelectedValue = entity.Status ? "1" : "0";
  58. }
  59. }
  60. }
  61. //新增或修改
  62. protected void btnEdit_Click(object sender, EventArgs e)
  63. {
  64. LotteryInfo entity = GetEntity();
  65. Tuple<bool, string> validate = Violation(entity);
  66. if (validate.Item1)
  67. {
  68. if (LotteryService.Save(entity))
  69. {
  70. if (Action == "Add")
  71. {
  72. Logs("添加彩种", string.Format("添加彩种[Name={0}]", entity.Name));
  73. ShowMessageBox("提示:添加成功!");
  74. }
  75. if (Action == "Modify")
  76. {
  77. Logs("修改彩种", string.Format("修改彩种[CID={0}]", entity.Id));
  78. ShowMessageBox("提示:修改成功!");
  79. }
  80. }
  81. else
  82. {
  83. ShowMessageBox("提示:操作失败!");
  84. }
  85. }
  86. else
  87. {
  88. ShowMessageBox(validate.Item2);
  89. }
  90. }
  91. //创建实体
  92. private LotteryInfo GetEntity()
  93. {
  94. LotteryInfo entity = new LotteryInfo();
  95. entity.Cid = Cid;
  96. if (txtLotteryName.Text.Trim() != "")
  97. {
  98. entity.Name = txtLotteryName.Text.Trim();
  99. }
  100. else
  101. {
  102. entity.Name = "-1";
  103. }
  104. if (txtTerm.Text.Trim() != "")
  105. {
  106. entity.Term = txtTerm.Text.Trim();
  107. }
  108. else
  109. {
  110. entity.Term = "-1";
  111. }
  112. if (txtOrderBy.Text.Trim() != "")
  113. {
  114. entity.OrderBy = txtOrderBy.Text.Trim().ToInt();
  115. }
  116. else
  117. {
  118. entity.OrderBy = 0;
  119. }
  120. if (dpArea.SelectedValue != "-1")
  121. {
  122. entity.Aid = dpArea.SelectedValue.ToInt();
  123. }
  124. else
  125. {
  126. entity.Aid = 0;
  127. }
  128. if (dpFrequency.SelectedValue != "-1")
  129. {
  130. entity.Frequency = dpFrequency.SelectedValue == "1";
  131. }
  132. else
  133. {
  134. entity.Frequency = false;
  135. }
  136. if (dpStatus.SelectedValue != "-1")
  137. {
  138. entity.Status = dpStatus.SelectedValue == "1";
  139. }
  140. else
  141. {
  142. entity.Status = false;
  143. }
  144. return entity;
  145. }
  146. protected void btnClear_Click(object sender, EventArgs e)
  147. {
  148. txtLotteryName.Text = "";
  149. txtTerm.Text = "";
  150. txtOrderBy.Text = "";
  151. dpArea.SelectedValue = "-1";
  152. dpFrequency.SelectedValue = "-1";
  153. dpStatus.SelectedValue = "-1";
  154. }
  155. public static Tuple<bool, string> Violation(LotteryInfo entity)
  156. {
  157. if (entity.Name == "-1")
  158. return new Tuple<bool, string>(false, "请输入彩种名称!");
  159. if (entity.Aid == 0)
  160. return new Tuple<bool, string>(false, "请选择彩种所对应地区!");
  161. return new Tuple<bool, string>(true, "验证通过!");
  162. }
  163. }
  164. }