123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using CB.Admin.Plugins.OpenCode;
- using CB.Common;
- using CB.Data;
- using CB.Entity;
- using CB.Framework;
- namespace CB.Admin.Plugins.Lottery
- {
- public partial class LotteryEdit : AdminPage
- {
- protected string title = string.Empty, Action = string.Empty;
- private int Cid = 0; //Cid表示彩种
- protected void Page_Load(object sender, EventArgs e)
- {
- Action = WRequest.GetQueryString("Action");
- Cid = WRequest.GetQueryInt("Cid");
- if (!Page.IsPostBack)
- {
- InitData();
- }
- }
- protected override void InitData()
- {
- BindList();
- }
- protected void BindList()
- {
- IList<AreaInfo> arealist = AreaService.ToList();
- if (null != arealist && arealist.Count > 0)
- {
- foreach (var item in arealist)
- {
- dpArea.Items.Add(new ListItem(item.Name, item.Aid.ToString()));
- }
- }
- if (Action == "Add")
- {
- title = "添加";
- }
- if (Action == "Modify")
- {
- title = "修改";
- LotteryInfo entity = LotteryService.Get(Cid);
- if (null != entity)
- {
- txtLotteryName.Text = entity.Name;
- txtTerm.Text = entity.Term;
- txtOrderBy.Text = entity.OrderBy.ToString();
- dpArea.SelectedValue = entity.Aid.ToString();
- dpFrequency.SelectedValue = entity.Frequency ? "1" : "0";
- dpStatus.SelectedValue = entity.Status ? "1" : "0";
- }
- }
- }
- //新增或修改
- protected void btnEdit_Click(object sender, EventArgs e)
- {
- LotteryInfo entity = GetEntity();
- Tuple<bool, string> validate = Violation(entity);
- if (validate.Item1)
- {
- if (LotteryService.Save(entity))
- {
- if (Action == "Add")
- {
- Logs("添加彩种", string.Format("添加彩种[Name={0}]", entity.Name));
- ShowMessageBox("提示:添加成功!");
- }
- if (Action == "Modify")
- {
- Logs("修改彩种", string.Format("修改彩种[CID={0}]", entity.Id));
- ShowMessageBox("提示:修改成功!");
- }
- }
- else
- {
- ShowMessageBox("提示:操作失败!");
- }
- }
- else
- {
- ShowMessageBox(validate.Item2);
- }
- }
- //创建实体
- private LotteryInfo GetEntity()
- {
- LotteryInfo entity = new LotteryInfo();
- entity.Cid = Cid;
- if (txtLotteryName.Text.Trim() != "")
- {
- entity.Name = txtLotteryName.Text.Trim();
- }
- else
- {
- entity.Name = "-1";
- }
- if (txtTerm.Text.Trim() != "")
- {
- entity.Term = txtTerm.Text.Trim();
- }
- else
- {
- entity.Term = "-1";
- }
- if (txtOrderBy.Text.Trim() != "")
- {
- entity.OrderBy = txtOrderBy.Text.Trim().ToInt();
- }
- else
- {
- entity.OrderBy = 0;
- }
- if (dpArea.SelectedValue != "-1")
- {
- entity.Aid = dpArea.SelectedValue.ToInt();
- }
- else
- {
- entity.Aid = 0;
- }
- if (dpFrequency.SelectedValue != "-1")
- {
- entity.Frequency = dpFrequency.SelectedValue == "1";
- }
- else
- {
- entity.Frequency = false;
- }
- if (dpStatus.SelectedValue != "-1")
- {
- entity.Status = dpStatus.SelectedValue == "1";
- }
- else
- {
- entity.Status = false;
- }
- return entity;
- }
- protected void btnClear_Click(object sender, EventArgs e)
- {
- txtLotteryName.Text = "";
- txtTerm.Text = "";
- txtOrderBy.Text = "";
- dpArea.SelectedValue = "-1";
- dpFrequency.SelectedValue = "-1";
- dpStatus.SelectedValue = "-1";
- }
- public static Tuple<bool, string> Violation(LotteryInfo entity)
- {
- if (entity.Name == "-1")
- return new Tuple<bool, string>(false, "请输入彩种名称!");
- if (entity.Aid == 0)
- return new Tuple<bool, string>(false, "请选择彩种所对应地区!");
- return new Tuple<bool, string>(true, "验证通过!");
- }
- }
- }
|