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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CY.IDAL;
using CY.Infrastructure.Common;
using AbstractFactory;
using CY.Model;
using System.Data;
namespace CY.BLL.OA
{
    public class OA_CommoditySpeciAssociateBLL
    {
        IOA_CommoditySpeciAssociateDAL CommoditySpeciAssociateDAL = null;
 
        public OA_CommoditySpeciAssociateBLL()
        {
            CommoditySpeciAssociateDAL = Factory.GetDALByInterfaceName(DALInterface.IOA_CommoditySpeciAssociateDAL) as IOA_CommoditySpeciAssociateDAL;
 
 
        }
 
 
 
        /// <summary>
        /// 批量新增
        /// </summary>
        /// <param name="SpecificationList"></param>
        /// <param name="CommodityId"></param>
        /// <returns></returns>
        public bool InsertModel(string[] SpecificationList, string CommodityId)
        {
            int? commodityId = MyConvert.ConvertToInt32(CommodityId);
            if (!commodityId.HasValue) return false; else { }
 
            List<OA_CommoditySpeciAssociate> commoditySpeciAssociates = new List<OA_CommoditySpeciAssociate>();
 
            for (int i = 0; i < SpecificationList.Length; i++)
            {
                if (!MyConvert.ConvertToInt32(SpecificationList[i]).HasValue) return false; else { }
 
                commoditySpeciAssociates.Add(new OA_CommoditySpeciAssociate()
                {
                    CommodityId = commodityId,
                    SpecificationId = SpecificationList[i].ToInt32()
                });
 
            }
            return CommoditySpeciAssociateDAL.InserModel(commoditySpeciAssociates.ToArray());
 
        }
 
 
        /// <summary>
        /// 批量删除
        /// </summary>
        /// <param name="models"></param>
        /// <returns></returns>
        public bool DeleteModel(string[] SpecificationList, string CommodityId)
        {
            int? commodityId = MyConvert.ConvertToInt32(CommodityId);
            if (!commodityId.HasValue) return false; else { }
            List<OA_CommoditySpeciAssociate> commoditySpeciAssociates = new List<OA_CommoditySpeciAssociate>();
            for (int i = 0; i < SpecificationList.Length; i++)
            {
                if (!MyConvert.ConvertToInt32(SpecificationList[i]).HasValue) return false;
                commoditySpeciAssociates.Add(new OA_CommoditySpeciAssociate() { CommodityId = commodityId, SpecificationId = SpecificationList[i].ToInt32() });
            }
            return CommoditySpeciAssociateDAL.DeleteModel(commoditySpeciAssociates.ToArray());
 
        }
 
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool UpdateModel(Infrastructure.Domain.IAggregateRoot model)
        {
 
            return CommoditySpeciAssociateDAL.UpdateModel(model);
        }
 
        
        /// <summary>
        /// 单个查询
        /// </summary>
        /// <param name="SpecificationId"></param>
        /// <returns></returns>
        public Model.OA_CommoditySpeciAssociate SelectSingelModel(string SpecificationId)
        {
            return CommoditySpeciAssociateDAL.SelectSingelModel(SpecificationId);
        }
 
        /// <summary>
        /// 得到类别--规格对应
        /// </summary>
        /// <param name="CommodityId"></param>
        /// <returns></returns>
        public DataTable SelectModelPage(string CommodityId)
        {
            return CommoditySpeciAssociateDAL.SelectModelPage(CommodityId);
 
        }
        public IEnumerable<Model.OA_CommoditySpeciAssociate> SelectALLModel(string CommodityId)
        {
            return CommoditySpeciAssociateDAL.SelectALLModel(CommodityId);
        }
 
 
        public bool MananeModel(string[] SpecificationListBefore, string[] SpecificationListAfter, string CommodityId)
        {
 
            int? commodityId = MyConvert.ConvertToInt32(CommodityId);
            if (!commodityId.HasValue) return false; else { }
 
            List<OA_CommoditySpeciAssociate> Deletemodels = new List<OA_CommoditySpeciAssociate>();
 
            for (int i = 0; i < SpecificationListBefore.Length; i++)
            {
                if (!MyConvert.ConvertToInt32(SpecificationListBefore[i]).HasValue) return false; else { }
 
                Deletemodels.Add(new OA_CommoditySpeciAssociate()
                {
                    CommodityId = commodityId,
                    SpecificationId = SpecificationListBefore[i].ToInt32()
                });
            }
            List<OA_CommoditySpeciAssociate> Insertmodles = new List<OA_CommoditySpeciAssociate>();
 
            for (int i = 0; i < SpecificationListAfter.Length; i++)
            {
                if (!MyConvert.ConvertToInt32(SpecificationListAfter[i]).HasValue) return false; else { }
 
                Insertmodles.Add(new OA_CommoditySpeciAssociate()
                {
                    CommodityId = commodityId,
                    SpecificationId = SpecificationListAfter[i].ToInt32()
                });
            }
            return CommoditySpeciAssociateDAL.MananeModel(Deletemodels.ToArray(), Insertmodles.ToArray());
        }
    }
 
}