1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/**  
* SysDictionaryInfoManage.aspx.cs
*
* 功 能: 字典表信息维护
* 类 名: SysDictionaryInfoManage
*
* Ver    变更日期             负责人  变更内容
* ───────────────────────────────────
* V0.01  2013-4-8 16:05       吴崎均    初版
* V0.02  2013-4-12 17:45      吴崎均    初成
* V0.03  2013-4-16            吴崎均    应对新增“代表值”字段的修改
*
*
*
*
*
*
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CY.BLL.Sys;
using CY.Infrastructure.Common;
using CY.Model;
 
namespace CY.WebForm.Pages.sysglobal
{
 
    /*
    * 字典表信息维护
    * 
    * 作用:维护字典表信息
    * 创建时间:2013-4-8 16:05
    * 修改时间:2013-4-12 17:45
    * 创建人:吴崎均
    * 修改人:吴崎均
    */
 
 
    /// <summary>
    /// 字典表信息维护
    /// </summary>
    public partial class SysDictionaryInfoManage : BasePage
    {
 
 
        private Sys_DictionaryBLL _dicBll = null;//业务逻辑操作类
        /// <summary>
        /// 初始化
        /// </summary>
        public SysDictionaryInfoManage()
        {
            _dicBll = new Sys_DictionaryBLL();
        }
        protected void Page_Load(object sender, EventArgs e)
        {
 
 
            try
            {
                switch (Request["Target"])
                {
                    case "SaveDictionary":
                        SaveData();
                        break;
                    case "DeleteDictionaryById":
                        DeleteDataById();
                        break;
                    default://一般情况不处理
                        ddlDateType.SelectedIndexChanged += new EventHandler(ddlDateType_SelectedIndexChanged);
                        btnRefresh.Click += new EventHandler(btnRefresh_Click);
                        ddlDateType.AutoPostBack = true;
                        if (IsPostBack || IsCallback) return;
                        LoadDicTypes();
                        return;
                }
            }
            catch (Exception ex)
            {
                PAGEHandleException(ex);
                Response.Clear();
                Response.Write("-1");
 
            }
            Response.End();
 
 
        }
 
        /// <summary>
        /// 刷新按钮点击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void btnRefresh_Click(object sender, EventArgs e)
        {
 
            LoadListDataByDataType();
            LoadDicTypes();
        }
 
        /// <summary>
        /// 下拉框选择项改变事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void ddlDateType_SelectedIndexChanged(object sender, EventArgs e)
        {
            LoadListDataByDataType();
        }
 
 
 
        /// <summary>
        /// 添加数据
        /// </summary>
        private void SaveData()
        {
 
            Dictionary<string, string> requestParams = JsonHelper.GetObjectByJsonString(Request["RequestParams"], JsonDataType.Dictionary) as Dictionary<string, string>;
            Sys_Dictionary dicInfo = new Sys_Dictionary();
 
            foreach (string key in requestParams.Keys)
            {
                dicInfo.Visiter(key, -1, true, requestParams[key]);
            }
            dicInfo.Operator = CurrentUser.ShortName;
 
            //编号没有值或者值为0时 调用添加方法 否则修改
            Response.Write((!dicInfo.Keyid.HasValue || 0 == dicInfo.Keyid ? _dicBll.AddData(dicInfo) : _dicBll.UpdataData(dicInfo)) ? "1" : "0");
 
 
        }
        /// <summary>
        /// 根据编号删除数据
        /// </summary>
        private void DeleteDataById()
        {
 
            Sys_Dictionary dic = new Sys_Dictionary();
            dic.Keyid = MyConvert.ConvertToInt(Request["id"]);
 
            if (0 == dic.Keyid)
            {
                Response.Write("-1");
                return;
            }
 
            Response.Write(_dicBll.DeleteData(dic) ? "1" : "0");
        }
 
        /// <summary>
        /// 根据数据类型加载数据列表
        /// </summary>
        private void LoadListDataByDataType()
        {
 
 
            rptData.DataSource = string.IsNullOrEmpty(ddlDateType.SelectedValue) ? null : _dicBll.GetDataByType(ddlDateType.SelectedValue);
            rptData.DataBind();
        }
        /// <summary>
        /// 加载数据类型
        /// </summary>
        private void LoadDicTypes()
        {
            string selectedValue = -1 == ddlDateType.SelectedIndex ? "" : ddlDateType.SelectedValue;
            ddlDateType.DataSource = _dicBll.GetDataTypes();
            ddlDateType.DataBind();
            ddlDateType.Items.Add(new ListItem("请选择", ""));
            IList<Sys_Dictionary> dictionarys = rptData.DataSource as IList<Sys_Dictionary>;
            if (null == dictionarys || dictionarys.Count == 0) return;
            ddlDateType.SelectedValue = selectedValue;
        }
    }
}