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
using Commom.Utility;
using Common;
using Model;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace BLL.DAL
{
   public class DALBrand
    {
        public IList<Brand> GetList(AjaxBrandList Json, ref PageInfo pageInfo)
        {
            try
            {
                IList<Brand> list = new List<Brand>();
                StringBuilder strSql = new StringBuilder();
                List<SqlParam> para = new List<SqlParam>();
                strSql.Append("Select * from View_Brand_UserInfo where IsDel=0");
 
                if (Json.BrandCode != null && Json.BrandCode != "") 
                {
                    strSql.Append(" and BrandCode like '%" + Json.BrandCode + "%'  ");
                }
                if (Json.BrandName != null && Json.BrandName != "")
                {
                    strSql.Append(" and BrandName like '%" +Json.BrandName + "%'  ");
                }
 
                SqlParam[] param = null;
                if (para != null) 
                {
                    param = para.ToArray();
                }
 
                DataTable dt = DataFactory.SqlDataBase().GetPageList(strSql.ToString(), param, "CreatTime", "Desc", ref pageInfo);
                return ModelConvertHelper<Brand>.DataTableToModel(dt);
            }
            catch
            {
                throw new NotImplementedException();
            }
        }
        public bool Add(Brand model, string loginUser)
        {
            bool result = false;
            try
            {
                Hashtable ht = new Hashtable();
 
                ht["BrandCode"] = model.BrandCode.AddQuotes();
                ht["BrandName"] = "'" + model.BrandName + "'";
                ht["CreatTime"] = "Getdate()";
                ht["CreatUser"] = "'" + loginUser + "'";
                ht["Demo"] = "'" + model.Demo + "'";
 
                int _ret = DataFactory.SqlDataBase().InsertByHashtableNullParam("Brand", ht);
 
                if (_ret == 1) result = true;
 
                return result;
 
            }
            catch
            {
                return result;
            }
        }
        //修改品牌
        public bool Update(Brand model,string loginUser)
        {
            bool result = false;
            try
            {
                Hashtable ht = new Hashtable();
                ht["BrandName"] = string.IsNullOrEmpty(model.BrandName) ? "''" : "'" + model.BrandName + "'";
                ht["Demo"] = string.IsNullOrEmpty(model.Demo) ? "''" : "'" + model.Demo + "'";
                ht["UpdateTime"] = "getdate()";
                ht["UpdateUser"] = loginUser.AddQuotes();
 
                string ID = "'" + model.ID + "'";
 
                int _ret = DataFactory.SqlDataBase().UpdateByHashtable("Brand", "ID", ID, ht);
                if (_ret == 1) result = true;
 
                return result;
            }
            catch
            {
                return result;
            }
        }
        //逻辑删除
        public bool BatchDelete(string[] ID)
        {
            bool result = false;
            try
            {
                int dt = DataFactory.SqlDataBase().IsExist("Brand", "ID", ID);
                if (dt >= ID.Length)
                {
                    int i = 0;
                    while (i < ID.Length)
                    {
                        StringBuilder sql = new StringBuilder();
                        sql.Append("update Brand set IsDel=1 where ID='" + ID[i] + "'");
                        int _ret = DataFactory.SqlDataBase().ExecuteBySql(sql);
                        if (_ret >= ID.Length) result = true;
                        i++;
                    }
 
                }
                return result;
 
            }
            catch
            {
                return result;
            }
        }
        //编辑查询
        public Brand GetModel(string ID)
        {
            try
            {
                Brand us = null;
                StringBuilder strSql = new StringBuilder();
                strSql.Append("Select * from Brand where ");
                strSql.Append("ID = @ID ");
 
                SqlParam[] para = new SqlParam[]
                {
                    new SqlParam("@ID", ID),
                };
 
                IDataReader dt = DataFactory.SqlDataBase().GetDataReaderBySQL(strSql, para);
                us = ModelConvertHelper<Brand>.ReaderToModel(dt);
 
                return us;
            }
            catch
            {
                throw new NotImplementedException();
            }
        }
 
        public bool IsExist(string sqlWhere) 
        {
            return DataFactory.SqlDataBase().IsExist("brand", sqlWhere);
        }
 
        public bool IsExist(Brand model) 
        {
            bool result = false;
            try
            {
                StringBuilder strSql = new StringBuilder();
                strSql.Append("select count(id) from Brand where BrandName = " + model.BrandName.AddQuotes());
                strSql.Append(" and id != " + model.ID + ";");
                DataRow row = DataFactory.SqlDataBase().GetDataRowBySQL(strSql);
                if (row[0].ToString() == "0") 
                {
                    result = true;
                }
 
                return result;
            }
            catch (Exception)
            {
 
                return result;
            }
        }
 
        //物料查询品牌下拉框
        public IList<Brand> GetBrandList(string bdName)
        {
            try
            {
 
                IList<Brand> ls = new List<Brand>();
                StringBuilder strSql = new StringBuilder();
                strSql.Append("select ID,BrandCode,BrandName,guid from Brand where IsDel !=1");
                if (!string.IsNullOrEmpty(bdName)) 
                {
                    strSql.Append(" and BrandName like '%" + bdName + "%'");
                }
                strSql.Append(" order by ID;");
 
                IDataReader dt = DataFactory.SqlDataBase().GetDataReaderBySQL(strSql);
                ls = ModelConvertHelper<Brand>.DataReaderToModel(dt);
 
                return ls;
            }
            catch
            {
                throw new NotImplementedException();
            }
        }
    }
}