username@email.com
2025-05-15 6fe02a16e55f17e45a3997171e1b2284d45af25b
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using CY.Infrastructure.Common;
using CY.Model;
using CY.BLL.OA;
using System.Text;
namespace CY.WebForm.Pages.procurement
{
    public partial class CommodityEdit : BasePage
    {
        OA_CommodityBLL _OA_CommodityBLL = null;
        OA_Commodity Commodity = null;
        OA_BrandBLL _OA_BrandBLL = null;
 
        public CommodityEdit()
        {
            _OA_BrandBLL = new OA_BrandBLL();
            _OA_CommodityBLL = new OA_CommodityBLL();
            Commodity = new OA_Commodity();
        }
 
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.txtOrderNum.Value = _OA_BrandBLL.GetMaxOrderNum(CurrentUser.MemberId, "OA_Commodity");
                if (Request["Keyid"].ToInt32() > 0)
                {
                    InitialCommityData();
                }
            }
        }
 
        protected void InitialCommityData()
        {
            Commodity = _OA_CommodityBLL.SelectSingleModel(Request["Keyid"].ToString2());
            if (Commodity != null)
            {
                this.txtCommodityName.Value = Commodity.CommodityName;
                //this.selIsPaper.Value = Commodity.IsPaper.ToString2();
                this.selIsUsed.Value = Commodity.IsUsed.ToString2();
                this.txtOrderNum.Value = Commodity.OrderNum.ToString2();
                //selParent.Value = Commodity.ParentId.ToString2();
            }
            else
            {
                this.txtCommodityName.Value = "";
                this.selIsUsed.Value = "True";
                this.txtOrderNum.Value = _OA_BrandBLL.GetMaxOrderNum(CurrentUser.MemberId, "OA_Commodity");
            }
        }
 
        #region 上级父类数据初始化
        public void InitialData()
        {
            DataTable ds = _OA_CommodityBLL.SelectModelPage(CurrentUser.MemberId, "", "true");
            var dic = new Dictionary<string, string>();
            //selParent.Items.Insert(0, new ListItem("请选择", "0"));
            //GetDataByLevel(selParent, ds,0,0);
        }
        public static void GetDataByLevel(System.Web.UI.HtmlControls.HtmlSelect sel, DataTable data, int parentId, int level)
        {
            DataRow[] result = data.Select(string.Format("ParentId={0}", parentId));
            int i = -1;
            while (++i < result.Length)
            {
                sel.Items.Add(new ListItem(GetSplitChar(level) + result[i]["CommodityName"].ToString2(), result[i]["Keyid"].ToString2()));
                GetDataByLevel(sel, 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;
        }
        #endregion
 
        /// <summary>
        /// 点击提交、修改或添加货品类别
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btn_config_Click(object sender, EventArgs e)
        {
            if (Request["Keyid"].ToInt32() > 0)
            {
                Commodity = _OA_CommodityBLL.SelectSingleModel(Request["Keyid"].ToString2());
            }
 
            Commodity.OrderNum = this.txtOrderNum.Value.ToInt32();
            Commodity.CommodityName = txtCommodityName.Value;
            Commodity.FirmId = CurrentUser.MemberId;
            Commodity.IsPaper = 0;
            Commodity.IsUsed = MyConvert.ConvertToBoolean(this.selIsUsed.Value);
            Commodity.LastUpdateTime = DateTime.Now;
 
            Commodity.ParentId = 0;
            Commodity.Remark = "";
            if (Request["Keyid"].ToInt32() > 0)
            {
                if (_OA_CommodityBLL.UpdateModel(Commodity))
                    JavaScript.MessageBox("更新成功", this, true, true);
                else
                    JavaScript.MessageBox("更新失败", this);
            }
            else
            {
                Commodity.Operator = CurrentUser.ShortName;
                if (_OA_CommodityBLL.insertModel(Commodity))
                {
                    //InitialCommityData();
                    this.txtCommodityName.Value = "";
                    this.selIsUsed.Value = "True";
                    this.txtOrderNum.Value = _OA_BrandBLL.GetMaxOrderNum(CurrentUser.MemberId, "OA_Commodity");
                    JavaScript.MessageBox("添加成功", this, false, true);
                }
                else
                {
                    JavaScript.MessageBox("添加失败", this);
                }
            }
        }
    }
}