username@email.com
2024-12-20 ebd639c929bd5c05859b6b414787e3440cdcd4bc
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CY.BLL.OA;
using System.Data;
using System.Data.SqlClient;
using CY.Infrastructure.Common;
using CY.Model;
using CY.BLL.Sys;
 
namespace CY.WebForm.Pages.procurement
{
    public partial class ProcurementADD : BasePage
    {
        OA_SpecificationBLL _OA_SpecificationBLL = null;
        OA_SuppliersBLL _OA_SuppliersBLL = null;
        OA_CommodityBLL _OA_CommodityBLL = null;
        OA_GoodsInfoBLL _OA_GoodsInfoBLL = null;
        OA_ProcurementBLL _OA_ProcurementBLL = null;
        OA_GoodsInfo GoodsInfo = null;
        OA_Procurement procurement = null;
        Sys_DictionaryBLL bll_Sys_DictionaryBLL = null;
        OA_BrandBLL _OA_BrandBLL = null;
        OA_PaperWeightBLL _OA_PaperWeightBLL = null;
        string Keyid = string.Empty;
 
        public ProcurementADD()
        {
            _OA_PaperWeightBLL = new OA_PaperWeightBLL();
            _OA_SpecificationBLL = new OA_SpecificationBLL();
            _OA_BrandBLL = new OA_BrandBLL();
            procurement = new OA_Procurement();
            _OA_CommodityBLL = new OA_CommodityBLL();
            _OA_ProcurementBLL = new OA_ProcurementBLL();
            _OA_SuppliersBLL = new OA_SuppliersBLL();
            _OA_GoodsInfoBLL = new OA_GoodsInfoBLL();
            GoodsInfo = new OA_GoodsInfo();
            bll_Sys_DictionaryBLL = new Sys_DictionaryBLL();
        }
 
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                InitialData();
                if (dwCommity.SelectedItem.Text != "纸张")
                {
                    this.tanDiv.Visible = false;
                    this.tanDiv1.Visible = true;
                    this.dwPaperWeight.Visible = false;
                    this.trWeight.Visible = false;
                    this.div_td.Visible = false;
                    this.div_td1.Visible = true;
                }
                dwBrand.Items.Insert(0, new ListItem("请选择", ""));
                dwSpecification.Items.Insert(0, new ListItem("请选择", ""));
                dwGoodsList.Items.Insert(0, new ListItem("请选择", ""));
 
            }
        }
 
        /// <summary>
        /// 初始化下拉列表
        /// </summary>
        protected void InitialData()
        {
            var dataTable = _OA_SuppliersBLL.getSupplierTable(CurrentUser.MemberId);
            var sss = dataTable.Select(" SuppliersTypeId ='182' ");
 
 
            DataTable dtNew2 = dataTable.Clone(); //复制结构
            for (int i = 0; i < sss.Length; i++)
            {
                dtNew2.ImportRow(sss[i]); //ImportRow 是复制
            }
 
 
            ///供应商
            selSuppliers.DataSource = dtNew2;//.Select(" SuppliersTypeId='200' ")
 
            selSuppliers.DataBind();
            selSuppliers.Items.Insert(0, new ListItem("请选择", ""));
            ///产品类别
            ///
            dwCommity.Items.Insert(0, new ListItem("请选择", ""));
            DataTable dss = _OA_CommodityBLL.SelectModelPage(CurrentUser.MemberId, "", "true");
            GetDataByLevel(dwCommity, dss, 0, 0);
 
 
           
 
            if (Request["Keyid"].ToInt32() > 0)
            {
                Keyid = Request["Keyid"].ToString();
                ShowProcurementData();
            }
            else
            {
                dwCommity.SelectedValue = "4";
                DataTable ds = _OA_GoodsInfoBLL.SlectModleByCommity(dwCommity.SelectedValue, CurrentUser.MemberId);
                if (ds.Rows.Count > 0)
                {
                    dwGoodsList.DataSource = ds;
                    dwGoodsList.DataTextField = "GoodsName";
                    dwGoodsList.DataValueField = "Keyid";
                    dwGoodsList.DataBind();
                    dwGoodsList.Items.Insert(0, new ListItem("请选择", ""));
 
                    dwBrand.Items.Clear();
                    dwBrand.Items.Insert(0, new ListItem("请选择", ""));
 
                    dwSpecification.Items.Clear();
                    dwSpecification.Items.Insert(0, new ListItem("请选择", ""));
 
                    dwPaperWeight.Items.Clear();
                    dwPaperWeight.Items.Insert(0, new ListItem("请选择", ""));
 
                    if (dwCommity.SelectedItem.Text == "纸张")
                    {
                        this.dwPaperWeight.Visible = true;
                        this.trWeight.Visible = true;
                        this.tanDiv.Visible = true;
                        this.tanDiv1.Visible = false;
                        this.div_td.Visible = true;
                        this.div_td1.Visible = false;
                    }
                    else
                    {
                        this.dwPaperWeight.Visible = false;
                        this.trWeight.Visible = false;
                        this.tanDiv.Visible = false;
                        this.tanDiv1.Visible = true;
                        this.div_td.Visible = false;
                        this.div_td1.Visible = true;
                    }
                }
                else
                {
                    dwGoodsList.Items.Clear();
                    dwGoodsList.Items.Insert(0, new ListItem("请选择", ""));
 
                    dwBrand.Items.Clear();
                    dwBrand.Items.Insert(0, new ListItem("请选择", ""));
 
                    dwSpecification.Items.Clear();
                    dwSpecification.Items.Insert(0, new ListItem("请选择", ""));
 
                    dwPaperWeight.Items.Clear();
                    dwPaperWeight.Items.Insert(0, new ListItem("请选择", ""));
                }
            }
 
 
        }
 
        private void ShowProcurementData()
        {
            OA_Procurement procurementModel = null;
            procurementModel = new OA_Procurement();
            procurementModel = _OA_ProcurementBLL.SelectSingleModel(Keyid);
 
            this.selSuppliers.Value = procurementModel.SuppliersId.ToString();
            this.dwCommity.SelectedValue = procurementModel.Commodityid.ToString();
            DataTable ds = _OA_GoodsInfoBLL.SlectModleByCommity(dwCommity.SelectedValue, CurrentUser.MemberId);
            if (ds.Rows.Count > 0)
            {
                dwGoodsList.DataSource = ds;
                dwGoodsList.DataTextField = "GoodsName";
                dwGoodsList.DataValueField = "Keyid";
                dwGoodsList.DataBind();
            }
            else
            {
                dwGoodsList.Items.Clear();
                dwGoodsList.Items.Insert(0, new ListItem("请选择", ""));
            }
            this.dwGoodsList.SelectedValue = procurementModel.GoodsId.ToString();
            indecChage();
            this.dwBrand.SelectedValue = procurementModel.BrandId.ToString();
            this.dwSpecification.SelectedValue = procurementModel.SpecificationId.ToString();
            this.dwPaperWeight.SelectedValue = procurementModel.PaperWeightId.ToString();
            this.txtQuantity.Value = procurementModel.Quantity.ToString();
            this.txtPrice.Value = procurementModel.Price.ToString();
            this.txtTenPrice.Value = procurementModel.TanPrice.ToString();
            this.txtAllMoney.Value = procurementModel.AllMoney.ToString();
 
 
 
        }
 
        /// <summary>
        /// 产品类别
        /// </summary>
        /// <param name="dwCommity"></param>
        /// <param name="data"></param>
        /// <param name="parentId"></param>
        /// <param name="level"></param>
        public static void GetDataByLevel(System.Web.UI.WebControls.DropDownList dwCommity, DataTable data, int parentId, int level)
        {
            DataRow[] result = data.Select(string.Format("ParentId={0}", parentId));
            int i = -1;
            while (++i < result.Length)
            {
                dwCommity.Items.Add(new ListItem(GetSplitChar(level) + result[i]["CommodityName"].ToString2(), result[i]["Keyid"].ToString2()));
                GetDataByLevel(dwCommity, data, result[i]["Keyid"].ToInt32().Value, level + 1);
 
            }
        }
 
        public static string GetSplitChar(int level)
        {
            string splitchar = "";
            int i = -1;
            while (++i < level)
            {
                splitchar += ".";
            }
            return splitchar;
        }
 
        /// <summary>
        /// 类别选取
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void dwCommity_SelectedIndexChanged(object sender, EventArgs e)
        {
 
            DataTable ds = _OA_GoodsInfoBLL.SlectModleByCommity(dwCommity.SelectedValue, CurrentUser.MemberId);
            if (ds.Rows.Count > 0)
            {
                dwGoodsList.DataSource = ds;
                dwGoodsList.DataTextField = "GoodsName";
                dwGoodsList.DataValueField = "Keyid";
                dwGoodsList.DataBind();
                dwGoodsList.Items.Insert(0, new ListItem("请选择", ""));
 
                dwBrand.Items.Clear();
                dwBrand.Items.Insert(0, new ListItem("请选择", ""));
 
                dwSpecification.Items.Clear();
                dwSpecification.Items.Insert(0, new ListItem("请选择", ""));
 
                dwPaperWeight.Items.Clear();
                dwPaperWeight.Items.Insert(0, new ListItem("请选择", ""));
 
                if (dwCommity.SelectedItem.Text == "纸张")
                {
                    this.dwPaperWeight.Visible = true;
                    this.trWeight.Visible = true;
                    this.tanDiv.Visible = true;
                    this.tanDiv1.Visible = false;
                    this.div_td.Visible = true;
                    this.div_td1.Visible = false;
                }
                else
                {
                    this.dwPaperWeight.Visible = false;
                    this.trWeight.Visible = false;
                    this.tanDiv.Visible = false;
                    this.tanDiv1.Visible = true;
                    this.div_td.Visible = false;
                    this.div_td1.Visible = true;
                }
            }
            else
            {
                dwGoodsList.Items.Clear();
                dwGoodsList.Items.Insert(0, new ListItem("请选择", ""));
 
                dwBrand.Items.Clear();
                dwBrand.Items.Insert(0, new ListItem("请选择", ""));
 
                dwSpecification.Items.Clear();
                dwSpecification.Items.Insert(0, new ListItem("请选择", ""));
 
                dwPaperWeight.Items.Clear();
                dwPaperWeight.Items.Insert(0, new ListItem("请选择", ""));
            }
            //indecChage();
        }
 
        /// <summary>
        /// 根据产品名初始化数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void dwGoodsList_SelectedIndexChanged(object sender, EventArgs e)
        {
            indecChage();
        }
 
        /// <summary>
        /// 根据货品类别和货品名称选择规格和品牌
        /// </summary>
        protected void indecChage()
        {
            ///品牌
            DataTable dt_brand = _OA_BrandBLL.getAllBrand(CurrentUser.MemberId, this.dwCommity.SelectedValue, this.dwGoodsList.SelectedValue);
            if (dt_brand.Rows.Count > 0)
            {
                this.dwBrand.DataSource = dt_brand;
                this.dwBrand.DataTextField = "Name";
                this.dwBrand.DataValueField = "Keyid";
                this.dwBrand.DataBind();
            }
            else
            {
                this.dwBrand.Items.Clear();
                this.dwBrand.Items.Insert(0, new ListItem("请选择", ""));
            }
            DataTable dt_Specefiction = _OA_SpecificationBLL.getAllSpecification(CurrentUser.MemberId, this.dwCommity.SelectedValue, this.dwGoodsList.SelectedValue);
            //规格
            if (dt_Specefiction.Rows.Count > 0)
            {
                this.dwSpecification.DataSource = dt_Specefiction;
                this.dwSpecification.DataTextField = "Name";
                this.dwSpecification.DataValueField = "Keyid";
                this.dwSpecification.DataBind();
            }
            else
            {
                this.dwSpecification.Items.Clear();
                this.dwSpecification.Items.Insert(0, new ListItem("请选择", ""));
            }
            ///如果是纸张类型 则加载克重
            OA_Commodity model = _OA_CommodityBLL.getCommodityId(CurrentUser.MemberId);
            if (model.Keyid.ToString() == this.dwCommity.SelectedValue)
            {
                DataTable dt_PaperWeight = _OA_PaperWeightBLL.getPaperWeight(CurrentUser.MemberId, this.dwCommity.SelectedValue, this.dwGoodsList.SelectedValue);
                ///克重
                if (dt_PaperWeight.Rows.Count > 0)
                {
                    this.dwPaperWeight.DataSource = dt_PaperWeight;
                    this.dwPaperWeight.DataTextField = "Name";
                    this.dwPaperWeight.DataValueField = "Keyid";
                    this.dwPaperWeight.DataBind();
                    this.dwPaperWeight.Visible = true;
                    this.trWeight.Visible = true;
                    this.tanDiv.Visible = true;
                    this.tanDiv1.Visible = false;
                    this.div_td.Visible = true;
                    this.div_td1.Visible = false;
                }
                else
                {
                    this.dwPaperWeight.Items.Clear();
                    this.dwPaperWeight.Items.Insert(0, new ListItem("请选择", ""));
                }
            }
            else
            {
                this.dwPaperWeight.Visible = false;
                this.trWeight.Visible = false;
                this.tanDiv.Visible = false;
                this.tanDiv1.Visible = true;
                this.div_td.Visible = false;
                this.div_td1.Visible = true;
            }
        }
 
        protected void btn_config_Click(object sender, EventArgs e)
        {
            procurement.AllMoney = this.txtAllMoney.Value.ToDecimal2();
            procurement.Quantity = this.txtQuantity.Value.ToInt32();
            procurement.Price = this.txtPrice.Value.ToDecimal2();
            procurement.LastUpdateTime = DateTime.Now;
            procurement.Operator = CurrentUser.ShortName;
            if (string.IsNullOrEmpty(this.selSuppliers.Value))
            {
                procurement.SuppliersId = null;
            }
            else
            {
                procurement.SuppliersId = this.selSuppliers.Value.ToInt32();
            }
           
            procurement.FirmId = CurrentUser.MemberId;
            procurement.GoodsId = this.dwGoodsList.SelectedValue.ToInt32();
            procurement.Remark = this.txtRemark.Value;
            procurement.BrandId = this.dwBrand.SelectedValue.ToInt32();
            procurement.SpecificationId = this.dwSpecification.SelectedValue.ToInt32();
            procurement.PaperWeightId = this.dwPaperWeight.SelectedValue.ToInt32() ?? 0;
            procurement.TanPrice = this.txtTenPrice.Value.ToDecimal2() ?? 0;
            procurement.Commodityid = this.dwCommity.SelectedValue.ToInt32();
            procurement.PurchaseStatusId = bll_Sys_DictionaryBLL.GetKeyIdByKeyid(0, "采购状态"); ///采购状态
            procurement.ClearingStatusId = bll_Sys_DictionaryBLL.GetKeyIdByKeyid(0, "结账状态"); ///结算状态
            procurement.PurchaseTime = DateTime.Now;
            if (Request["Keyid"].ToInt32() > 0)
            {
                OA_Procurement procurementModel = new OA_Procurement();
                procurementModel = _OA_ProcurementBLL.SelectSingleModel(Request["Keyid"]);
                procurementModel.SuppliersId = this.selSuppliers.Value.ToInt32();
                procurementModel.Commodityid = this.dwCommity.SelectedValue.ToInt32();
                procurementModel.GoodsId = this.dwGoodsList.SelectedValue.ToInt32();
                procurementModel.BrandId = this.dwBrand.SelectedValue.ToInt32();
                procurementModel.SpecificationId = this.dwSpecification.SelectedValue.ToInt32();
                procurementModel.PaperWeightId = this.dwPaperWeight.SelectedValue.ToInt32();
                procurementModel.Quantity = this.txtQuantity.Value.ToInt32();
                procurementModel.Price = this.txtPrice.Value.ToDecimal2();
                procurementModel.TanPrice = this.txtTenPrice.Value.ToDecimal2();
                procurementModel.AllMoney = this.txtAllMoney.Value.ToDecimal2();
                procurementModel.PaperWeightId = this.dwPaperWeight.SelectedValue.ToInt32() ?? 0;
                procurementModel.LastUpdateTime = DateTime.Now;
                procurementModel.Operator = CurrentUser.ShortName;
                if (_OA_ProcurementBLL.UpdateModel(procurementModel))
                {
                    JavaScript.RefreshDIVOpener(this);
                }
                else
                {
                    JavaScript.MessageBox("修改失败", this);
                }
            }
            else
            {
                if (_OA_ProcurementBLL.insertModel(procurement))
                {
                    ClearData();
                    //JavaScript.RefreshDIVOpener(this);
                    JavaScript.MessageBox("操作成功", this, true, false);
                }
                else
                {
                    JavaScript.MessageBox("添加失败", this);
                }
            }
 
        }
        public void ClearData()
        {
            dwCommity_SelectedIndexChanged(null, null);
 
            txtQuantity.Value = "";
            txtPrice.Value = "";
            txtTenPrice.Value = "";
            txtAllMoney.Value = "";
        }
    }
}