bklLiudl
2024-07-23 675b8bcc4a3630d95e3d0b97d933e63442075ecb
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
using Commom.Utility;
using Common;
using Model;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Text;
 
namespace BLL.DAL
{
    public class DALRegion
    {
        /// <summary>
        /// 获取区域集合
        /// </summary>
        /// <param name="region"></param>
        /// <param name="page"></param>
        /// <returns></returns>
        public IList<Region> GetRegionItems(QueryRegion region,ref PageInfo page) 
        {
            try
            {
                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.Append("select * from View_Region_UserInfo where IsDel = 0 ");
                if (region.RegionCode != null && region.RegionCode != "") 
                {
                    stringBuilder.Append("and RegionCode like '%" + region.RegionCode + "%'");
                }
                if (region.RegionName != null && region.RegionName != "")
                {
                    stringBuilder.Append("and RegionName like '%" + region.RegionName + "%'");
                }
 
                SqlParam[] para = new SqlParam[]
                {
                };
 
                DataTable dt = DataFactory.SqlDataBase().GetPageList(stringBuilder.ToString(), para, "CreatTime", "DESC", ref page);
                IList<Region> list = ModelConvertHelper<Region>.DataTableToModel(dt);
 
                return list;
            }
            catch
            {
                throw new NotImplementedException();
            }
        }
 
        public IList<Region> GetRegionItems()
        {
            try
            {
                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.Append("select * from View_Region_UserInfo where IsDel = '0' ");
 
                DataTable dt = DataFactory.SqlDataBase().GetDataTableBySQL(stringBuilder);
                return ModelConvertHelper<Region>.DataTableToModel(dt);
            }
            catch
            {
                throw new NotImplementedException();
            }
        }
 
        /// <summary>
        /// 获取指定区域信息
        /// </summary>
        /// <param name="RegionCode"></param>
        /// <returns></returns>
        public Region getRegion(string RegionCode) 
        {
            try
            {
                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.Append("select * from View_Region_UserInfo where IsDel = '0' ");
                if (RegionCode != null && RegionCode != "")
                {
                    stringBuilder.Append("and RegionCode like '%"+ RegionCode + "%' ");
 
                    SqlParam[] para = new SqlParam[]
                    {
                    };
 
                    IDataReader dt = DataFactory.SqlDataBase().GetDataReaderBySQL(stringBuilder, para);
                    return ModelConvertHelper<Region>.ReaderToModel(dt);
                }
 
                return null;
            }
            catch
            {
                throw new NotImplementedException();
            }
        }
 
        /// <summary>
        /// 保存区域信息
        /// </summary>
        /// <param name="region"></param>
        /// <param name="loginUser"></param>
        /// <returns>true:成功 false:失败</returns>
        public bool SetRegions(SetRegion region,string loginUser) 
        {
            try
            {
                bool bl = false;
                int rowCount = 0;
                Hashtable ht = new Hashtable();
                if (region.Operation == "Add")
                {
                    ht["RegionCode"] = region.RegionCode.AddQuotes();
                    ht["RegionName"] = region.RegionName.AddQuotes();
                    ht["Demo"] = region.Demo.AddQuotes();
                    ht["CreatTime"] = "convert(varchar(20),getdate(),120)";
                    ht["CreatUser"] = loginUser.AddQuotes();
                    ht["UpdateTime"] = "convert(varchar(20),getdate(),120)";
                    ht["UpdateUser"] = loginUser.AddQuotes();
 
                    rowCount = DataFactory.SqlDataBase().InsertByHashtableNullParam("Region", ht);
                }
                else 
                {
                    ht["RegionName"] = region.RegionName.AddQuotes();
                    ht["Demo"] = region.Demo.AddQuotes();
                    ht["UpdateTime"] = "convert(varchar(20),getdate(),120)";
                    ht["UpdateUser"] = loginUser.AddQuotes();
 
                    rowCount = DataFactory.SqlDataBase().UpdateByHashtable("Region", 
                        "RegionCode", region.RegionCode.AddQuotes(), ht);
                }
 
                if (rowCount > 0) 
                {
                    bl = true;
                }
 
                return bl;
            }
            catch
            {
                throw new NotImplementedException();
            }
        }
 
        /// <summary>
        /// 删除区域(逻辑删除)
        /// </summary>
        /// <param name="regionCodes"></param>
        /// <param name="loginUser"></param>
        /// <returns>true:成功 false:失败</returns>
        public bool DelRegions(string[] regionCodes, string loginUser) 
        {
            try
            {
                bool bl = false;
                int rowCount = 0;
                Hashtable ht = new Hashtable();
                foreach (string regionCode in regionCodes) 
                {
                    ht["IsDel"] = 1;
                    rowCount += DataFactory.SqlDataBase().UpdateByHashtable("Region",
                            "RegionCode", regionCode.AddQuotes(), ht);
                }
 
                if (rowCount > 0) 
                {
                    bl = true;
                }
 
                return bl;
            }
            catch 
            {
                throw new NotImplementedException();
            }
        }
 
        /// <summary>
        /// 检查是否已存在
        /// </summary>
        /// <param name="region"></param>
        /// <returns></returns>
        public bool IsExist(SetRegion region) 
        {
            try
            {
                bool bl = false;
                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.Append("select count(*) from Region where (RegionCode = "+region.RegionCode.AddQuotes());
                stringBuilder.Append(" or RegionName = " + region.RegionName.AddQuotes()+") and isDel = 0 ");
                if (region.Operation == "Edit") 
                {
                    stringBuilder.Append("and RegionCode != " + region.RegionCode.AddQuotes());
                }
                DataTable dt = DataFactory.SqlDataBase().GetDataTableBySQL(stringBuilder);
                if (dt.Rows[0][0].ToString() != "0")
                {
                    bl = true;
                }
 
                return bl;
            }
            catch 
            {
                throw new NotImplementedException();
            }
        }
    }
}