using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using CB.Common; using CB.Entity; using CB.Framework; using CB.Data; using CB.TVUCenter.Config; namespace CB.Admin.Plugins.Lottery { public partial class AreaEdit : AdminPage { protected string Action = string.Empty; private static int id; protected void Page_Load(object sender, EventArgs e) { Action = WRequest.GetQueryString("Action"); if (!Page.IsPostBack) { InitData(); } } protected override void InitData() { BindList(); } protected void BindList() { id = WRequest.GetQueryInt("id"); AreaInfo entity = AreaService.Get(id); //绑定父类型 int aindex = 0; int areaindex = 0; IList ais = AreaService.ToList(); int j = 0; foreach (var item in ais) { ddlParent.Items.Add(new ListItem(item.Name,item.Aid.ToString())); j++; if (entity!=null&&entity.ParentId==item.Aid) { aindex = j; } } Array temp = Enum.GetValues(typeof(AreaType)); for (int i = 0; i < temp.Length; i++) { string info = temp.GetValue(i).ToString(); ddlAreaTypes.Items.Add(new ListItem(GetType(info),(i+1).ToString())); if (entity != null && info == entity.Depth.ToString()) { areaindex = i + 1; } } if (entity!=null) { txtName.Text = entity.Name.ToString().Trim(); ddlAreaTypes.SelectedIndex = areaindex; ddlParent.SelectedIndex = aindex; } } private string GetType(string type) { switch (type) { case "Country": return "全国性"; case "Province": return "全省性"; case "Area": return "地区联销"; default: return ""; } } //新增或修改 protected void btnEdit_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtName.Text.Trim())) { ShowMessageBox("名称不能为空!"); } if (ddlAreaTypes.SelectedIndex==0) { ShowMessageBox("请选择区域类型!"); } AreaInfo entity = new AreaInfo { Aid=id, Name=txtName.Text.Trim(), ParentId=Convert.ToInt32(this.ddlParent.SelectedValue), Depth=(AreaType)Convert.ToInt32(this.ddlAreaTypes.SelectedValue) }; if (AreaService.Save(entity)) { //生成当期及后期数据走势图和遗漏数据 if (Action == "Add") { UpdateTvConfig(); Logs("添加区域", string.Format("添加区域[Name={0}]", entity.Name)); ShowMessageBox("提示:添加成功!"); } if (Action == "Modify") { UpdateTvConfig(); Logs("修改区域", string.Format("修改区域[ID={0}]", entity.Aid)); ShowMessageBox("提示:修改成功!"); } } else { ShowMessageBox("提示:操作失败!"); } } private bool UpdateTvConfig() { TVConfigInfo entity = CB.TVUCenter.Config.TVConfigs.GetConfig(); entity.AreaVersion =TypeConverter.StrToInt(DateTime.Now.ToString("yyyyMMddHH").Substring(2, 8)); return CB.TVUCenter.Config.TVConfigs.UpdateConfig(entity); } //重置 protected void btnClear_Click(object sender, EventArgs e) { txtName.Text = string.Empty; ddlAreaTypes.SelectedIndex = 0; ddlParent.SelectedIndex = 0; } } }