username@email.com
2025-05-15 6fe02a16e55f17e45a3997171e1b2284d45af25b
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CY.Model;
using CY.Infrastructure.Common;
using CY.BLL.Sys;
using CY.Infrastructure.Singleton;
 
namespace CY.WebForm
{
    public partial class frmSubmitJsonDataTest : BasePage
    {
 
 
        private Sys_DictionaryBLL _dicBll = null;//业务逻辑操作类
        /// <summary>
        /// 初始化
        /// </summary>
        public frmSubmitJsonDataTest()
        {
            _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 = "sys";
 
            //编号没有值或者值为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()
        {
            ddlDateType.DataSource = _dicBll.GetDataTypes();
            ddlDateType.DataBind();
            ddlDateType.Items.Add(new ListItem("请选择", ""));
            ddlDateType.SelectedValue = "";
        }
    }
}