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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CY.BLL.Inquiry;
using CY.Model;
using CY.Infrastructure.Common;
using CY.Model.Inquiry;
namespace CY.WebForm.Pages.sysInquiry
{
    public partial class PaperPriceList : BasePage
    {
        #region 变量
        PaperInfoBLL _paperInfoBLL = new PaperInfoBLL();
        BrandInfoBLL _brandInfoBLL = new BrandInfoBLL();
        PaperTypeBLL _paperTypeBLL = new PaperTypeBLL();
        #endregion
 
        #region 属性
        /// <summary>
        /// 纸张信息json字符串
        /// </summary>
        public string PaperListStr { get; set; }
 
        #endregion
 
        #region 方法
        /// <summary>
        /// 获取纸张信息json字符串
        /// </summary>
        /// <returns></returns>
        private string GetPaperListStr()
        {
            PaperListStr = "[{ id: -1, parentId: 0, name: \"纸张列表\" }";
                //PaperListStr += " ,{id:" + model.PapeId + ",parentId:-1,name:\"" + model.PaperName + "\"}";
                IEnumerable<SysInquiry_PaperType> paperTypeList = _paperTypeBLL.GetPaperTypeList();
                if (paperTypeList != null && paperTypeList.Count() > 0)
                {
                    foreach (SysInquiry_PaperType paperType in paperTypeList)
                    {
                        int paperTypeKeyId = paperType.KeyId + 1000;
                        PaperListStr += " ,{id:" + paperTypeKeyId + ",parentId:-1,name:\"" + paperType.PaperTypeName + "\"}";
                        IEnumerable<SysInquiry_PaperInfo> paperInfoList = _paperInfoBLL.GetPaperListByPaperType(paperType.KeyId);
                        if (paperInfoList != null && paperInfoList.Count() > 0)
                        {
                            foreach (SysInquiry_PaperInfo paperInfo in paperInfoList)
                            {
                                PaperListStr += " ,{id:" + paperInfo.PapeId + ",parentId:" + paperTypeKeyId + ",name:\"" + paperInfo.PaperName + "\"}";
                            }
                        }
                    }
                }
            PaperListStr += "]";
            return PaperListStr;
        }
        ///// <summary>
        ///// 绑定品牌列表
        ///// </summary>
        //private void BindddlDefaultBrand()
        //{
        //    this.ddlBrandList.DataSource = _brandInfoBLL.GetBrandList();
        //    this.ddlBrandList.DataTextField = "BrandName";
        //    this.ddlBrandList.DataValueField = "KeyId";
        //    this.ddlBrandList.DataBind();
        //}
        #endregion
 
        #region 事件
        /// <summary>
        /// 初始化
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (InquiryConditionObj.FirmId.ToString() == UtilConst.AdminFirmId)
                {
                    this.hidIsFirm.Value = "false";
                }
                else
                {
                    this.hidIsFirm.Value = "true";
                }
                GetPaperListStr();
                //BindddlDefaultBrand();
            }
 
 
 
            if (Request["Init"] != null)
            {
                string result = string.Empty;
                string brandListStr = string.Empty;
                string resultList = string.Empty;
                string str = string.Empty;
                int paperId = int.Parse(Request["paperId"].ToString());
                IList<SysInquiry_BrandInfo> brandList = _paperInfoBLL.GetBrandInfoByPaper(paperId);
                if (brandList != null && brandList.Count > 0)
                {
                    foreach (SysInquiry_BrandInfo brand in brandList)
                    {
                        str += "{brandKey:" + brand.KeyId + ",brandName:'" + brand.BrandName + "'},";
                    }
                    if (!string.IsNullOrEmpty(str))
                    {
                        str = str.Substring(0, str.Length - 1);
                    }
                }
                brandListStr = "[" + str + "]";
                int brandId = -1;
                if (Request["brandId"].ToString() == "")
                {
                    if (brandList != null && brandList.Count > 0)
                    brandId = brandList[0].KeyId;
                }
                else
                {
                    brandId = int.Parse(Request["brandId"].ToString());
                }
                str = string.Empty;
                IEnumerable<Inquiry_PaperPriceInfo> paperPriceList = _paperInfoBLL.GetAllPaperPriceList(paperId, brandId, InquiryConditionObj.InquiryId);
                if (paperPriceList != null && paperPriceList.Count() > 0)
                {
                    foreach (Inquiry_PaperPriceInfo model in paperPriceList)
                    {
                        str += "{ GramWeight:" + model.GramWeight + ",PaperPrice:" + model.PaperPrice.ToString("0.00") + "},";
                    }
                    if (!string.IsNullOrEmpty(str))
                    {
                        str = str.Substring(0, str.Length - 1);
                    }
                }
                resultList = "[" + str + "]";
                result = "{brandId:" + brandId + ",paperPriceList:" + resultList + ",brandList:" + brandListStr + "}";
                Response.Write(result);
                Response.End();
            }
 
            if (Request["save"] != null)
            {
                List<Inquiry_PaperPriceInfo> modelList = new List<Inquiry_PaperPriceInfo>();
                Inquiry_PaperPriceInfo model = null;
                int paperId = int.Parse(Request["paperId"].ToString());
                int brandId = int.Parse(Request["brandId"].ToString());
                string priceList = Request["priceList"].ToString();
                bool isSuccess = false;
                string result = string.Empty;
 
                if (string.IsNullOrEmpty(priceList))
                {
                    result = "该品牌下的纸张没有设置相关克重,保存失败";
                }
                else
                {
                    int gramWeightValue = -1;
                    decimal paperPrice = 0;
                    string[] priceListArry = priceList.Split(',');
                    foreach (string priceListStr in priceListArry)
                    {
                        string[] priceStr = priceListStr.Split(':');
                        gramWeightValue = int.Parse(priceStr[0]);
                        paperPrice = Convert.ToDecimal(priceStr[1]);
 
                        model = new Inquiry_PaperPriceInfo();
                        model.PaperId = paperId;
                        model.FirmId = InquiryConditionObj.ActualFirmId;
                        model.BrandId = brandId;
                        model.GramWeight = gramWeightValue;
                        model.PaperPrice = paperPrice;
                        model.Unit = "元";
                        model.Status = true;
                        model.Operater = CurrentUser.ShortName;
                        model.OperateTime = DateTime.Now;
                        model.LastUpdateTime = DateTime.Now;
                        modelList.Add(model);
                    }
                    isSuccess = _paperInfoBLL.SavePaperPrice(modelList, InquiryConditionObj);
                    if (isSuccess)
                    {
                        result = "保存成功";
                    }
                    else
                    {
                        result = "保存失败";
                    }
                }
                Response.Write(result);
                Response.End();
            }
        }
        #endregion
    }
}