username@email.com
2025-05-21 a980cd04341d71216e0f59bd4b7327fe9fc50032
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CY.IDAL;
using System.Data.SqlClient;
using CY.Model;
using System.Data;
 
namespace CY.SQLDAL
{
    public class CategoriesDAL : ICategoriesDAL
    {
 
        #region ICommonDAL 成员
 
        public bool InserModel(Infrastructure.Domain.IAggregateRoot model)
        {
            Categories trueModel = model as Categories;
            if (trueModel != null)
            {
                SqlParameter[] parameters = {
                    
                    new SqlParameter("@CategoryName", SqlDbType.NVarChar,15),
                    new SqlParameter("@Description", SqlDbType.NText),
                    new SqlParameter("@Picture", SqlDbType.Image)};
                parameters[0].Value = trueModel.CategoryName;
                parameters[1].Value = trueModel.Description;
                parameters[2].Value = DBNull.Value;
 
                new Database().Query("Categories_ADD", CommandType.StoredProcedure, parameters);
                return true;
            }
            return false;
        }
 
        public bool UpdateModel(Infrastructure.Domain.IAggregateRoot model)
        {
            throw new NotImplementedException();
        }
 
        public bool DeleteModel(Infrastructure.Domain.IAggregateRoot model)
        {
            throw new NotImplementedException();
        }
 
        #endregion
 
        #region IGetAllModel<Categories> 成员
 
        public IEnumerable<Categories> SelectAllModel(Infrastructure.Query.Query query)
        {
            List<Categories> list = new List<Categories>();
            DataTable dt = new Database().QueryDataTable(query.SPName, CommandType.StoredProcedure, null);
            Categories model = null;
            foreach (DataRow dr in dt.Rows)
            {
                model = new Categories();
                model.CategoryID = int.Parse(dr["CategoryID"].ToString());
                model.CategoryName = dr["CategoryName"].ToString();
                model.Description = dr["Description"].ToString();
                list.Add(model);
            }
            return list;
        }
 
        #endregion
 
        #region IPaging<Categories> 成员
 
        public IEnumerable<Categories> SelectModelPage(Infrastructure.Query.Query query, Infrastructure.Query.Pagination pagination)
        {
            List<Categories> list = new List<Categories>();
            SqlParameter[] parameters = {
                    new SqlParameter("@Columns", SqlDbType.VarChar),
                    new SqlParameter("@TableName", SqlDbType.VarChar),
                    new SqlParameter("@Condition", SqlDbType.VarChar),
                    new SqlParameter("@OrderByRow", SqlDbType.VarChar),
                    new SqlParameter("@OrderByTable", SqlDbType.VarChar),
                    new SqlParameter("@PageNum ", SqlDbType.Int),
                    new SqlParameter("@PageSize", SqlDbType.Int),
                    new SqlParameter("@PageCount", SqlDbType.Int),
                    new SqlParameter("@RecordCount", SqlDbType.Int)
            };
            parameters[0].Value = query.Criteria[0].Value;
            parameters[1].Value = query.Criteria[1].Value;
            parameters[2].Value = query.Criteria[2].Value;
            parameters[3].Value = query.Criteria[3].Value;
            parameters[4].Value = query.Criteria[4].Value;
            parameters[5].Value = pagination.PageIndex;
            parameters[6].Value = pagination.PageSize;
            parameters[7].Direction = ParameterDirection.Output;
            parameters[8].Direction = ParameterDirection.Output;
            DataTable dt = new Database().QueryDataTable("sp_CurrencyPage", CommandType.StoredProcedure, parameters);
            Categories model = null;
            if (dt.Rows.Count > 0)
            {
                pagination.PageCount = Convert.ToInt32(parameters[6].Value);
                pagination.RecordCount = Convert.ToInt32(parameters[7].Value);
                foreach (DataRow dr in dt.Rows)
                {
                    model = new Categories();
                    model.CategoryID = int.Parse(dr["CategoryID"].ToString());
                    model.CategoryName = dr["CategoryName"].ToString();
                    model.Description = dr["Description"].ToString();
                    list.Add(model);
                }
            }
            return list;
        }
 
        #endregion
 
        #region ICategoriesDAL 成员
 
        public IList<Products> GetProductsByCategorieId(int CategorieId)
        {
            List<Products> list = new List<Products>();
            Products model = null;
            SqlParameter[] parameters = {
                    new SqlParameter("@CategorieId", SqlDbType.Int)
            };
            parameters[0].Value = CategorieId;
            DataTable dt = new Database().QueryDataTable("Products_GetModelByCategorieId", CommandType.StoredProcedure, parameters);
            foreach (DataRow dr in dt.Rows)
            {
                model = new Products();
                model.ProductName = dr["ProductName"].ToString();
                model.UnitPrice = Convert.ToDecimal(dr["UnitPrice"].ToString());
                list.Add(model);
            }
            return list;
        }
 
        #endregion
    }
}