yzh
2022-06-07 dbda463cdacc6c6101acdf9d58e22450a281b9b0
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
 
using Common;
using Dao;
using Model;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Profile;
using System.Web.SessionState;
using System.Text;
 
public partial  class _GwOrderCreate : PageBase<SysUser>, IRequiresSessionState
{
 
    protected List<GwProduct> GwProductList;
    protected List<GwClient> GwClientList;
    protected List<GwSp> GwSpList;
    //返回URL
    public string backUrl = "";
 
    //控制标志:0-按客户账号查询;1-按API账号查询
    public int _controlFlag = 0;
 
    private int _userId = -1;
    private int _userType = -1;
    private string _account = "";
 
    protected void Page_Load(object sender, EventArgs e)
    {
        //this.CheckRight("201", FailedOperation.ErrorMsgOnly);
 
        _userId = this.AppContext.SessionObject.UserID;
        _userType = this.AppContext.SessionObject.UserType;
        _account = this.AppContext.SessionObject.Account;
 
        using (GwClientDao gwClientDao = new GwClientDao())
            this.GwClientList = gwClientDao.Clientlist();
 
        //获取产品或产品分类
        using (GwProductDao gwProductDao = new GwProductDao())
        {
            GwProduct bean = new GwProduct();
            bean.Classes = -1;
            bean.IsEnable = -1;
            bean.IsDefault = -1;
            this.GwProductList = gwProductDao.getAllList(bean);
        }
 
        using (GwSpDao gwSpDao = new GwSpDao())
        {
            if (!string.IsNullOrEmpty(this.ClientId))
            {
                this.GwOrder = new GwOrder();
                this.GwOrder.ClientId = ClientId;
 
                string permissionsSQL = new GwClientDao().GetClientPermissions(_userId, _userType, null);
                this.GwSpList = gwSpDao.LoadInfoList(null, null, this.ClientId, permissionsSQL);
 
            }
 
             if (!string.IsNullOrEmpty(this.SpID))
            {
                GwSp  gwSp = gwSpDao.Get(this.SpID);
                if(gwSp==null)
                {
                    throw new ArgumentException("账号不存在!");
 
                }
                else if (gwSp.Status==0)
                {
                    throw new ArgumentException("账号状态已停用!");
 
                }
 
 
                GwClient gwClient = new GwClient();
                using (GwClientDao gwClientDao = new GwClientDao())
                {
                    gwClient = gwClientDao.Get(gwSp.ClientID);
                }
 
 
                this.GwOrder = new GwOrder();
                    this.GwOrder.SpId = gwSp.SpID;
                    this.GwOrder.ClientId = gwSp.ClientID;
                    this.GwOrder.ProductId = gwSp.ProductId;
                    this.GwOrder.Price = gwSp.Price;
                    this.GwOrder.BasicNum = gwSp.BasicNum;  //基本条数
                    this.GwOrder.GivingNum = gwSp.GivingNum;
 
                    this.GwOrder.Balance = long.Parse(gwClient.Balance.ToString());    //余额
            }
 
        }
    }
 
 
    public GwOrder GwOrder { get; protected set; }
 
    public string SpID
    {
        get
        {
            if (!string.IsNullOrEmpty(this.AppContext.GetString("spId")))
            {
                backUrl = "GwSp.aspx";
                _controlFlag = 1;
            }
 
            return this.AppContext.GetString("spId");
        }
    }
 
    public string ClientId
    {
        get
        {
            if(!string.IsNullOrEmpty(this.AppContext.GetString("clientId")) )
            {
                backUrl = "GwClient.aspx";
                _controlFlag = 0;
            }
 
            return this.AppContext.GetString("clientId");
        }
    }
 
 
    //获取产品信息
    public string GetProductOptions(string productId)
    {
        StringBuilder stringBuilder = new StringBuilder();
        if (this.GwProductList.Count == 0)
            return "<option value='0'>无</option>";
        stringBuilder.AppendFormat("<option value=\"{0}\" >{1}</option>", (object)"", (object)"无");
        foreach (GwProduct bean in this.GwProductList)
        {
            //停用的产品分类不再显示
            if (bean.IsEnable == 0)
            {
                continue;
            }
 
            if (productId!=null && productId.Equals(bean.Id))
                stringBuilder.AppendFormat("<option value=\"{0}\" selected>{1}</option>", (object)bean.Id, (object)bean.Name);
            else
                stringBuilder.AppendFormat("<option value=\"{0}\">{1}</option>", (object)bean.Id, (object)bean.Name);
        }
        return stringBuilder.ToString();
    }
 
    //获取客户信息
    public string GetClientOptions(string clientId)
    {
        StringBuilder stringBuilder = new StringBuilder();
        if (this.GwClientList.Count == 0)
            return "<option value='0'>无</option>";
        stringBuilder.AppendFormat("<option value=\"{0}\" >{1}</option>", (object)"", (object)"无");
        foreach (GwClient bean in this.GwClientList)
        {
            if (clientId!=null && clientId.Equals(bean.ClientID))
                stringBuilder.AppendFormat("<option value=\"{0}\" selected>{1}</option>", (object)bean.ClientID, (object)bean.Company);
            else
                stringBuilder.AppendFormat("<option value=\"{0}\">{1}</option>", (object)bean.ClientID, (object)bean.Company);
        }
        return stringBuilder.ToString();
    }
 
 
    //获取客户API账号信息
    public string GetSpOptions()
    {
        StringBuilder stringBuilder = new StringBuilder();
        if (this.GwClientList.Count == 0)
            return "<option value='0'>无</option>";
        stringBuilder.AppendFormat("<option value=\"{0}\" >{1}</option>", (object)"", (object)"无");
        foreach (GwSp bean in this.GwSpList)
        {
            if (bean.Status == 0)
            {
                continue;
            }
 
            if (!string.IsNullOrEmpty(bean.SpID))
                //stringBuilder.AppendFormat("<option value=\"{0}\" >{1}</option>", (object)bean.SpID, (object)ProductToName(bean.ProductId ) );
                stringBuilder.AppendFormat("<option value=\"{0}\" >{0}</option>", (object)bean.SpID );
 
        }
        return stringBuilder.ToString();
    }
 
    //产品或产品分类ID转换名称
    private string ProductToName(string productId)
    {
        if (this.GwProductList == null)
            return string.Empty;
        GwProduct bean = this.GwProductList.Find((Predicate<GwProduct>)(product => product.Id == productId));
        if (bean != null)
            //return string.Format("{0}-{1}", (object)bean.Id, (object)bean.Name);
            return string.Format("{0}", (object)bean.Name);
        return string.Empty;
    }
 
}