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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CY.Model;
using CY.Infrastructure.Common;
using CY.BLL.OA;
using CY.BLL.Sys;
using CY.BLL;
 
namespace CY.WebForm.Pages.financial
{
    public partial class FirmAccountExpensesEdit : BasePage
    {
        Sys_DictionaryBLL _Sys_DictionaryBLL = null;
        OA_SubjectSetBLL _OA_SubjectSetBLL = null;
        OA_FirmAccountBLL _OA_FirmAccountBLL = null;
        OA_FirmAccountRecordBLL _OA_FirmAccountRecordBLL = null;
        OA_FirmAccountRecord firmAccountRecord = null;
        OA_FirmAccount firmAccount = null;
        OA_BaozhengjinBLL oA_BaozhengjinBLL = null;
        OA_StaffBLL staffBLL = null;
        public FirmAccountExpensesEdit()
        {
            firmAccount = new OA_FirmAccount();
            _Sys_DictionaryBLL = new Sys_DictionaryBLL();
            _OA_FirmAccountBLL = new OA_FirmAccountBLL();
            _OA_FirmAccountRecordBLL = new OA_FirmAccountRecordBLL();
            _OA_SubjectSetBLL = new OA_SubjectSetBLL();
            firmAccountRecord = new OA_FirmAccountRecord();
            oA_BaozhengjinBLL = new OA_BaozhengjinBLL();
            staffBLL = new OA_StaffBLL();
        }
 
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                switch (Request["DataType"])
                {
                    case "change":
                        Response.Write(reLoadAccountName(Request["TypeName"].ToString2()));
                        break;
                    default://一般情况不处理
                        if (IsPostBack || IsCallback)
                            return;
                        else
                        {
                            InitialData();
                        }
                        return;
                }
            }
            catch (Exception ex)
            {
                PAGEHandleException(ex);
                Response.Clear();
                Response.Write("-1");
            }
            Response.End();
        }
 
        protected void InitialData()
        {
            //科目名称
            selSubject.DataSource = _OA_SubjectSetBLL.getAllSubject(CurrentUser.MemberId, "贷");
            selSubject.DataBind();
            selSubject.Items.Insert(0, new ListItem("请选择", ""));
 
            ///账户类型
            selAcoountType.DataSource = _Sys_DictionaryBLL.GetDataByType("账户类型");
            selAcoountType.DataBind();
 
            selshenqingren.DataSource =  staffBLL.SelectListByFirmId(CurrentUser.MemberId,null, null).Where(x => x.DepartmentId == 2);
            selshenqingren.DataBind();
        }
 
        protected string reLoadAccountName(string selAcoountType)
        {
            return JsonHelper.GetJsonStringByObject(_OA_FirmAccountBLL.getAllSubject(CurrentUser.MemberId, selAcoountType));
        }
 
        protected void btn_Submit_Click(object sender, EventArgs e)
        {
            try
            {
               // selshenqingren
 
                firmAccount = _OA_FirmAccountBLL.getSingleSubject(Request["selAccountName"].ToInt32());
 
                firmAccountRecord.AccountId = Request["selAccountName"].ToInt32();
                firmAccountRecord.LastUpdateTime = DateTime.Now;
                firmAccountRecord.Money = this.txtMoney.Value.ToDecimal2();
                firmAccountRecord.OperationalMatters = this.txtOperationalMatters.Value;
                firmAccountRecord.Operator = CurrentUser.ShortName;
                firmAccountRecord.PaymentUnit = this.txtPaymentUnit.Value;
                firmAccountRecord.RecordTypeId = 2;//支出
                firmAccountRecord.Remark = this.txtRemark.Value;
                firmAccountRecord.SubjectId = this.selSubject.Value.ToInt32();
                firmAccountRecord.ResidualAmount = firmAccount.Balance - this.txtMoney.Value.ToDecimal2();
                firmAccountRecord.Department = this.txtDepartment.Value;
 
                firmAccount.AllExpenses = this.txtMoney.Value.ToDecimal2() + firmAccount.AllExpenses;
                firmAccount.Balance = firmAccount.Balance - this.txtMoney.Value.ToDecimal2();
 
                if (_OA_FirmAccountRecordBLL.AddModel(firmAccountRecord, firmAccount))
                {
                    if (!string.IsNullOrEmpty(this.selSubject.Value))
                    {
                        var oA_SubjectSet = _OA_SubjectSetBLL.getSingleSubject(firmAccountRecord.SubjectId);
                        if (oA_SubjectSet.SubjectName.IndexOf("投标保证金") >= 0 || oA_SubjectSet.SubjectName.IndexOf("履约保证金") >= 0)
                        {
                            //如果选择科目是保证金,插入以条保证金数据
                            OA_Baozhengjin oA_Baozhengjin = new OA_Baozhengjin();
                            oA_Baozhengjin.FirmId = CurrentUser.MemberId;
                            oA_Baozhengjin.FukuanTime = DateTime.Now;
 
                            oA_Baozhengjin.Zhanghuleixing = this.selAcoountType.Value;
 
                            var ss = _Sys_DictionaryBLL.GetDataByType("账户类型").FirstOrDefault(x => x.Name == oA_Baozhengjin.Zhanghuleixing);
                            if (ss != null)
                            {
                                oA_Baozhengjin.ReceiveWay = ss.Keyid;
                            }
 
                            oA_Baozhengjin.Account = Request["selAccountName"].ToInt32();
                            oA_Baozhengjin.Fukuanzhanghu = firmAccount.AccountName + "-" + firmAccount.UserName;
                            oA_Baozhengjin.Subject = firmAccountRecord.SubjectId;
                            oA_Baozhengjin.Fukuankemu = oA_SubjectSet.SubjectName;
                            oA_Baozhengjin.Fukuanmoney = firmAccountRecord.Money;
                            oA_Baozhengjin.Shoukuandanwei = firmAccountRecord.PaymentUnit;
                            oA_Baozhengjin.remark = firmAccountRecord.OperationalMatters;
                            oA_Baozhengjin.TuikuanTime = null;
 
                            oA_Baozhengjin.TuikuanStatus = 1;
                            oA_Baozhengjin.Creater = CurrentUser.ShortName;
                            oA_Baozhengjin.CreateTime = oA_Baozhengjin.FukuanTime;
                            oA_Baozhengjin.Updater = CurrentUser.ShortName;
                            oA_Baozhengjin.LastUpdateTime = oA_Baozhengjin.FukuanTime;
                            oA_Baozhengjin.MemberId = this.selshenqingren.Value.ToInt32();
                            if(oA_Baozhengjin.MemberId.HasValue && oA_Baozhengjin.MemberId.Value > 0)
                            {
                                var aaa = staffBLL.GetModelByKeyid(oA_Baozhengjin.MemberId);
                                if (aaa != null)
                                {
                                    oA_Baozhengjin.MemberName = aaa.Name;
                                }
                            }
 
                            var sss = oA_BaozhengjinBLL.InsertModel(oA_Baozhengjin);
 
                        }
                    }
                   
                    this.selSubject.Value = "";
                    this.txtMoney.Value = "";
                    this.txtDepartment.Value = "";
                    this.txtPaymentUnit.Value = "";
                    this.txtOperationalMatters.Value = "";
                    JavaScript.MessageBox("添加成功", this, false, true);
                }
                else
                    JavaScript.MessageBox("添加失败", this);
            }
            catch (Exception ex)
            {
                PAGEHandleException(ex);
                JavaScript.MessageBox("添加失败", this);
            }
        }
    }
}