username@email.com
2025-05-12 ae6e40362a745caef9ead36f81f38313fb8c2c66
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CY.BLL.EC;
using CY.Infrastructure.Common;
using CY.Model;
using CY.BLL.OA;
using CY.BLL.Sys;
using System.Text;
using CY.BLL;
using System.Data;
using System.Transactions;
 
namespace CY.WebForm.Pages.financial
{
    //吴辉
    //外协预付款
    public partial class OutsourcePiliangPayMoney : BasePage
    {
        private EC_OrderBasicBLL _eC_OrderBasicBLL = null;
        private OA_CorporateClientsBLL bll_OA_CorporateClientsBLL = null;
        OA_FirmAccountBLL _OA_FirmAccountBLL = null;
        OA_FirmAccountRecordBLL _OA_FirmAccountRecordBLL = null;
        OA_FirmAccountRecord firmAccountRecord = null;
        OA_FirmAccount firmAccount = null;
        string orderNo = string.Empty;
 
        decimal? AllMoney = 0;
        decimal? ReceiveMoney = 0;
 
        /// <summary>
        /// 初始化构造 
        /// </summary>
        public OutsourcePiliangPayMoney()
        {
            bll_OA_CorporateClientsBLL = new OA_CorporateClientsBLL();
            _OA_FirmAccountBLL = new OA_FirmAccountBLL();
            firmAccountRecord = new OA_FirmAccountRecord();
            _OA_FirmAccountRecordBLL = new OA_FirmAccountRecordBLL();
        }
 
        /// <summary>
        /// 界面加载事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            _eC_OrderBasicBLL = new EC_OrderBasicBLL();
            btnSubmit.ServerClick += new EventHandler(btnSubmit_ServerClick);
            try
            {
                switch (Request["DataType"])
                {
                    case "change":
                        Response.Write(reLoadAccountName(Request["TypeName"].ToString2()));
                        break;
                    default://一般情况不处理
                        if (IsPostBack || IsCallback)
                            return;
                        else
                        {
                            LoadOrder();
                            InitialData();
                        }
                        return;
                }
            }
            catch (Exception ex)
            {
                PAGEHandleException(ex);
                Response.Clear();
                Response.Write("-1");
            }
            Response.End();
            InitPage();
 
        }
        protected void InitialData()
        {
            //科目名称
            Sys_DictionaryBLL _Sys_DictionaryBLL = new Sys_DictionaryBLL();
            OA_SubjectSetBLL _OA_SubjectSetBLL = new OA_SubjectSetBLL();
            OA_FirmAccountBLL oA_FirmAccountBLL = new OA_FirmAccountBLL();
            selSubject.DataSource = _OA_SubjectSetBLL.getAllSubject(CurrentUser.MemberId, "贷");
            selSubject.DataBind();
            selSubject.Items.Insert(0, new ListItem("请选择", ""));
 
            ///账户类型
            
            selAcoountType.DataSource = _Sys_DictionaryBLL.GetDataByType("账户类型");   
           
            selAcoountType.DataBind();
 
            //selAcoountType_SelectedIndexChanged(null, null);
 
        }
        protected string reLoadAccountName(string selAcoountType)
        {
            return JsonHelper.GetJsonStringByObject(_OA_FirmAccountBLL.getAllSubject(CurrentUser.MemberId, selAcoountType));
        }
        /// <summary>
        /// 提交按钮点击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void btnSubmit_ServerClick(object sender, EventArgs e)
        {
 
            string[] Keys = Request["Keyid"].ToString2().Trim('|').Split('|');
            
            //_orderBasic = new EC_OrderBasic();
            _eC_OrderBasicBLL = new EC_OrderBasicBLL();
            //_orderBasic = _eC_OrderBasicBLL.SelectModelById(orderId.Value);
            //string orderno = "";
            //string sellerName = "";
            firmAccount = _OA_FirmAccountBLL.getSingleSubject(Request["selAccountName"].ToInt32());
 
            if (firmAccount.Balance < this.txtReciveMoney.Text.ToDecimal2())
            {
                JavaScript.MessageBox("账户余额不足", this);
                return;
            }
 
            var ssss = false;
 
 
            using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required,
    new TransactionOptions
    {
        IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted,
        Timeout = TransactionManager.MaximumTimeout
    }
    ))
            {
                try
                {
                   
 
 
                    foreach (var item in Keys)
                    {
                        if (!string.IsNullOrEmpty(item))
                        {
                            var orderBasic = _eC_OrderBasicBLL.SelectModelById(item.ToInt32().Value);
                            if (orderBasic != null)
                            {
                                firmAccountRecord.AccountId = Request["selAccountName"].ToInt32();
                                firmAccountRecord.LastUpdateTime = DateTime.Now;
                                firmAccountRecord.Money = orderBasic.UnPayedMoney;
                                orderNo = orderBasic.SellerOrderId;
                                firmAccountRecord.OperationalMatters = "外协付款" + "(" + orderNo + ")";
                                firmAccountRecord.Operator = CurrentUser.ShortName;
                                firmAccountRecord.PaymentUnit = orderBasic.SellerName;
                                firmAccountRecord.RecordTypeId = 2;//支出
                                firmAccountRecord.Remark = this.txtRemark.Value;
                                firmAccountRecord.SubjectId = this.selSubject.Value.ToInt32();
                                firmAccountRecord.ResidualAmount = firmAccount.Balance - orderBasic.UnPayedMoney; ;
 
                                firmAccount.AllExpenses = orderBasic.UnPayedMoney + firmAccount.AllExpenses;
                                firmAccount.Balance = firmAccount.Balance - orderBasic.UnPayedMoney;
                                ssss = _OA_FirmAccountRecordBLL.AddModel(firmAccountRecord, firmAccount);
                                if (ssss)
                                {
                                    UsePrepare(orderBasic);
                                   
 
                                }
                                else
                                {
                                    JavaScript.MessageBox("添加失败", this);
                                    return;
                                }
 
                            }
 
                        }
                    }
 
                    
 
                    if (ssss)
                    {
                        
                        scope.Complete();
                        JavaScript.MessageBox("付款成功", this, "top.frmright.ReLoad();top.Dialog.close();");
                    }
                    else
                        JavaScript.MessageBox("添加失败", this);
                }
                catch (Exception ex)
                {
                    PAGEHandleException(ex);
                    JavaScript.MessageBox("添加失败", this);
                }
                finally
                {
                    scope.Dispose();
                }
 
 
            }
 
 
 
 
 
        }
 
        /// <summary>
        /// 加载页面数据
        /// </summary>
        private void InitPage()
        {
            try
            {
                Sys_DictionaryBLL _Sys_DictionaryBLL = new Sys_DictionaryBLL();
                //OA_SubjectSetBLL _OA_SubjectSetBLL = new OA_SubjectSetBLL();
                OA_FirmAccountBLL oA_FirmAccountBLL = new OA_FirmAccountBLL();               
 
                int i = -1;
                //账户类型
                List<Sys_Dictionary> accountsType = _Sys_DictionaryBLL.GetDataByType("账户类型") as List<Sys_Dictionary>;
                Request.RequestContext.RouteData.DataTokens.Add("accountsTypes", null == accountsType || accountsType.Count == 0 ? "[]" : JsonHelper.GetJsonStringByObject(accountsType));
 
                List<OA_FirmAccount> firmAccounts = oA_FirmAccountBLL.getAllSubject(CurrentUser.MemberId, "") as List<OA_FirmAccount>;
 
                const string ACCOUNTSJSONKEY = "accounts";
                if (null == firmAccounts)
                {
                    Request.RequestContext.RouteData.DataTokens.Add(ACCOUNTSJSONKEY, "[]");
                    return;
                }
 
                IEnumerable<IGrouping<string, OA_FirmAccount>> groupings = firmAccounts.GroupBy(fa => fa.AccountType);
                StringBuilder builder = new StringBuilder();
 
                foreach (IGrouping<string, OA_FirmAccount> groupitem in groupings)
                {
                    OA_FirmAccount[] items = groupitem.ToArray();
                    builder.AppendFormat("{0}\"{2}\":{3}{1}", ",", "", groupitem.Key, JsonHelper.GetJsonStringByObject(items));
                }
                builder.Append("}]");
                builder.Replace(",", "[{", 0, 1);
 
                Request.RequestContext.RouteData.DataTokens.Add(ACCOUNTSJSONKEY, null == firmAccounts ? "[]" : builder.ToString());
 
            }
            catch (Exception ex)
            {
                PAGEHandleException(ex);
            }
        }
 
        /// <summary>
        /// 加载订单
        /// </summary>
        private void LoadOrder()
        {
           
            string[] Keys = Request["Keyid"].ToString2().Trim('|').Split('|');
            foreach (var item in Keys)
            {
                if (!string.IsNullOrEmpty(item))
                {
                  var   orderBasic = _eC_OrderBasicBLL.SelectModelById(item.ToInt32().Value);
                    if (orderBasic != null)
                    {
                        var sumPrice = orderBasic.SumPrice ?? 0;
                        AllMoney += sumPrice;
                        ReceiveMoney += orderBasic.UnPayedMoney;
                    }
                }
            }
 
 
           
            this.spanAllMoney.InnerText = "¥" + AllMoney.Value.ToString("0.00");
            this.spanReceiveMoney.InnerText = "¥" + ReceiveMoney.Value.ToString("0.00");
            this.txtReciveMoney.Text = ReceiveMoney.Value.ToString("0.00");
            this.spanCountRe.InnerHtml = Keys.Count().ToString2() + " 单";
          
        }
        
        /// <summary>
        /// 使用预付款(付款、收款)
        /// </summary>
        /// <returns></returns>
        private bool UsePrepare(EC_OrderBasic orderBasic)
        {
            decimal? money = MyConvert.ConvertToDecimal(txtReciveMoney.Text);
            int operatTypeId = 3;
            string subject = "订单付款";
            switch (Request["outsourceType"])
            {
                case "1":
                    operatTypeId = 2;
                    subject = "外协付款";
                    break;
                default:
                    break;
            }
            string[] Keys = Request["Keyid"].ToString2().Trim('|').Split('|');
 
            
            
 
            return _eC_OrderBasicBLL.ReceiveMoney(orderBasic.SellerId, orderBasic.BuyerId, orderBasic.Keyid.Value, orderBasic.UnPayedMoney, operatTypeId, subject, CurrentUser.ShortName); ;// _eC_OrderBasicBLL.ReceiveMoney(_orderBasic.SellerId, _orderBasic.BuyerId, _orderBasic.Keyid.Value, money.Value, operatTypeId, subject, CurrentUser.ShortName);
        }
 
        //protected void selAcoountType_SelectedIndexChanged(object sender, EventArgs e)
        //{
        //    _OA_FirmAccountBLL = new OA_FirmAccountBLL();
        //    DataTable dt = _OA_FirmAccountBLL.getAllAountName(CurrentUser.MemberId, selAcoountType.SelectedItem.Text.ToString());
        //}
    }
}