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
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.Model;
using CY.BLL;
using CY.Infrastructure.Common;
using CY.BLL.Sys;
using CY.BLL.EC;
using CY.Infrastructure.DESEncrypt;
using CY.Infrastructure.Query;
using CY.BLL.OA;
using System.Transactions;
 
namespace CY.WebForm.Pages.work
{
    //吴辉
    //新增请示
    public partial class MyRequestAdd : BasePage
    {
 
        OA_DepartmentBll departmentBll = null;
        OA_StaffBLL oA_StaffBLL = null;
        Sys_DictionaryBLL bll_Sys_DictionaryBLL = null;
        OA_WorkPlanBll oA_WorkReminderBll = null;
        OA_CarDictionaryBLL bll_OA_CarDictionaryBLL = null;
        OA_SuppliersBLL _OA_SuppliersBLL = null;
        OA_WorkPlan_attachmentBLL oA_WorkPlan_AttachmentBLL = null;
        public MyRequestAdd()
        {
            departmentBll = new OA_DepartmentBll();
            bll_Sys_DictionaryBLL = new Sys_DictionaryBLL();
            oA_WorkReminderBll = new OA_WorkPlanBll();
            oA_StaffBLL = new OA_StaffBLL();
            bll_OA_CarDictionaryBLL = new OA_CarDictionaryBLL();
            _OA_SuppliersBLL = new OA_SuppliersBLL();
            oA_WorkPlan_AttachmentBLL = new OA_WorkPlan_attachmentBLL();
        }
 
        //页面加载
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.selPlanTitle.DataSource = bll_OA_CarDictionaryBLL.SelectListByMemberIdAndParType(CurrentUser.MemberId, "出车事由");//出车事由
                this.selPlanTitle.DataValueField = "ParName";
                this.selPlanTitle.DataTextField = "ParName";
                this.selPlanTitle.DataBind();
                this.selPlanTitle.Items.Insert(0, new ListItem("全部", ""));
 
                //供应商
                this.selSuppliers.DataSource = _OA_SuppliersBLL.getSupplierTable(CurrentUser.MemberId);
                this.selSuppliers.DataBind();
                this.selSuppliers.Items.Insert(0, new ListItem("全部", ""));
 
                InitData();
            }
        }
 
        //数据加载
        public void InitData()
        {
            Pagination pa = new Pagination();
            pa.PageSize = 500;
            pa.PageIndex = 1;
 
 
            OA_WorkPlan m_OA_WorkPlan = oA_WorkReminderBll.GetModelByKeyid(Request["keyid"].ToInt32());
            if (m_OA_WorkPlan != null)
            {
                this.selPlanDataType.Value = m_OA_WorkPlan.PlanDataType.ToString();
                this.txtPlanMoney.Value = m_OA_WorkPlan.PlanMoney.Value.ToString("0.00");
                this.txtPlanRemark.Value = m_OA_WorkPlan.PlanRemark.ToString();
                if (m_OA_WorkPlan.PlanDataType == 7)
                {
                    this.selPlanTitle.Value = m_OA_WorkPlan.PlanTitle.ToString();
                }
                else
                {
                    this.txtPlanTitle.Value = m_OA_WorkPlan.PlanTitle.ToString();
                }
                if (m_OA_WorkPlan.PlanDataType == 15)
                {
                    this.txtShoukuandanwei.Value = m_OA_WorkPlan.PlanComplany;
                }
                else
                {
                    this.txtShoukuandanwei.Value = "";
                }
                this.txtPlanContent.Value = m_OA_WorkPlan.PlanContent.ToString();
 
                if(m_OA_WorkPlan.PlanDataType == 15)
                {
                    this.RepClientList.DataSource = oA_WorkPlan_AttachmentBLL.GetModelByKaipiaoIdandType(Request["keyid"].ToInt32().Value,15);
                    this.RepClientList.DataBind();
                }
               
            }
        }
 
        //表单提交
        protected void btn_submit_form(object sender, EventArgs e)
        {
            using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required,
    new TransactionOptions
    {
        IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted,
        Timeout = TransactionManager.MaximumTimeout
    }
    )
             )
            {
 
                try
                {
                    bool res = true;
                    DateTime nowTime = DateTime.Now;
                    OA_WorkPlan m_OA_WorkPlan = oA_WorkReminderBll.GetModelByKeyid(Request["keyid"].ToInt32());
                    if (m_OA_WorkPlan == null)
                    {
                        m_OA_WorkPlan = new OA_WorkPlan();
                        m_OA_WorkPlan.ApprovalContent = "";
                        m_OA_WorkPlan.ApprovalStaffId = Guid.Empty;
                        m_OA_WorkPlan.ApprovalStaffName = "";
                        m_OA_WorkPlan.ApprovalStatus = 0;
                        m_OA_WorkPlan.ApprovalTime = nowTime;
                        m_OA_WorkPlan.EvaluationContent = "";
                        m_OA_WorkPlan.EvaluationStaff = "";
                        m_OA_WorkPlan.EvaluationStaffId = Guid.Empty;
                        m_OA_WorkPlan.EvaluationStatus = 0;
                        m_OA_WorkPlan.EvaluationTime = nowTime;
                        m_OA_WorkPlan.RewardContent = "";
                        m_OA_WorkPlan.RewardMoney = 0;
                        m_OA_WorkPlan.RewardResult = "";
                        m_OA_WorkPlan.RewardType = 0;
 
                        m_OA_WorkPlan.PlanStartTime = nowTime;
                        m_OA_WorkPlan.PlanStatus = 1;
                        m_OA_WorkPlan.SentStaffId = CurrentUser.TrueMemberId;
                        m_OA_WorkPlan.MemberId = CurrentUser.MemberId;
 
                        OA_Staff m_OA_Staff = oA_StaffBLL.GetModelByMemberId(CurrentUser.TrueMemberId);
                        if (m_OA_Staff != null)
                            m_OA_WorkPlan.DepartId = m_OA_Staff.DepartmentId;
                        else
                            m_OA_WorkPlan.DepartId = 0;
 
                        m_OA_WorkPlan.PlanPeople = CurrentUser.TrueName;
                        m_OA_WorkPlan.ReciveStaffId = CurrentUser.TrueMemberId;
                    }
                    else
                    {
 
                    }
 
                    m_OA_WorkPlan.Operator = CurrentUser.ShortName;
                    if (this.selPlanDataType.Value == "15")
                    {
                        if (!this.txtPlanMoney.Value.Trim().ToDecimal2().HasValue || this.txtPlanMoney.Value.Trim().ToDecimal2().Value <= 0)
                        {
                            JavaScript.MessageBox("付款申请请填写申请费用!", this);
                            return;
                        }
                        if (string.IsNullOrWhiteSpace(this.txtShoukuandanwei.Value))
                        {
                            JavaScript.MessageBox("付款申请请填写收款单位!", this);
                            return;
                        }
                        m_OA_WorkPlan.PlanComplany = this.txtShoukuandanwei.Value;
                    }
                    else
                    {
                        m_OA_WorkPlan.PlanComplany = "";
                    }
 
                    m_OA_WorkPlan.PlanContent = this.txtPlanContent.Value.Trim();
                    m_OA_WorkPlan.PlanDataType = this.selPlanDataType.Value.ToInt32();
                    m_OA_WorkPlan.PlanMoney = this.txtPlanMoney.Value.Trim().ToDecimal2() ?? 0;
                    m_OA_WorkPlan.PlanRemark = this.txtPlanRemark.Value.Trim();
                    m_OA_WorkPlan.PlanRunTime = DateTime.Now;
 
                    if (m_OA_WorkPlan.PlanDataType == 7)
                    {
                        m_OA_WorkPlan.PlanTitle = this.selPlanTitle.Value.Trim();
                    }
                    else
                    {
                        m_OA_WorkPlan.PlanTitle = this.txtPlanTitle.Value.Trim();
                    }
                    m_OA_WorkPlan.PlanType = 3;
                    m_OA_WorkPlan.LastUpdateTime = nowTime;
 
                    if (Request["keyid"].ToInt32() > 0)
                    {
                        res = oA_WorkReminderBll.UpdateModel(m_OA_WorkPlan);
 
                        if (res && m_OA_WorkPlan.PlanDataType == 15)
                        {
                            var HideKeyidFapiao = Request["HideKeyidFapiao"].Split(',');
                            var HideAttachmentFapiao = Request["HideAttachmentFapiao"].Split(',');
 
                          
                            //需要删除的附件
                            var oA_WorkPlan_Attachments = oA_WorkPlan_AttachmentBLL.GetModelByKaipiaoIdandType(m_OA_WorkPlan.Keyid.Value, 15);
                            List<int> HideKeyidFujianid = new List<int>();
                            for (int i = 0; i < HideKeyidFapiao.Length; i++)
                            {
                                if (!string.IsNullOrEmpty(HideKeyidFapiao[i]) && HideKeyidFapiao[i].ToInt32() != 0)
                                {
                                    HideKeyidFujianid.Add(HideKeyidFapiao[i].ToInt32().Value);
                                }
                            }
 
                            var oA_WorkPlan_Attachments1 = oA_WorkPlan_Attachments.Where(x => !HideKeyidFujianid.Contains(x.Keyid)).ToList();
 
                            foreach (var oa_WorkPlan_Attachment in oA_WorkPlan_Attachments1)
                            {
                                res = oA_WorkPlan_AttachmentBLL.DeleteModel(oa_WorkPlan_Attachment);
                            }
 
                            for (int i = 0; i < HideKeyidFapiao.Length; i++)
                            {
                                if (string.IsNullOrEmpty(HideKeyidFapiao[i]))
                                {
                                    var a_WorkPlan_Attachment = new OA_WorkPlan_attachment();
                                    a_WorkPlan_Attachment.OA_WorkPlanId = m_OA_WorkPlan.Keyid;
                                    a_WorkPlan_Attachment.AttachmentType = 15;
                                    a_WorkPlan_Attachment.PlanAttachment = HideAttachmentFapiao[i];
                                    a_WorkPlan_Attachment.CreateTime = DateTime.Now;
                                    a_WorkPlan_Attachment.Operator = CurrentUser.TrueName;
                                    var sss = oA_WorkPlan_AttachmentBLL.InsertModel(a_WorkPlan_Attachment);
                                }
                                else
                                {
                                    continue;
                                }
                            }
 
                            scope.Complete();
 
 
                            JavaScript.MessageBox("更新成功", this, true, true);
                        }
                        else
                            JavaScript.MessageBox("操作失败", this);
 
                    }
                    else
                    {
 
                        var aaaa = oA_WorkReminderBll.InserModelAndGetId(m_OA_WorkPlan);
                        m_OA_WorkPlan.Keyid = aaaa;
                        if (aaaa > 0 && m_OA_WorkPlan.PlanDataType == 15)
                        {
                            var HideKeyidFapiao = Request["HideKeyidFapiao"].Split(',');
                            var HideAttachmentFapiao = Request["HideAttachmentFapiao"].Split(',');
 
 
 
                           
                            for (int i = 0; i < HideKeyidFapiao.Length; i++)
                            {
                                if (string.IsNullOrEmpty(HideKeyidFapiao[i]))
                                {
                                    var a_WorkPlan_Attachment = new OA_WorkPlan_attachment();
                                    a_WorkPlan_Attachment.OA_WorkPlanId = m_OA_WorkPlan.Keyid;
                                    a_WorkPlan_Attachment.AttachmentType = 15;
                                    a_WorkPlan_Attachment.PlanAttachment = HideAttachmentFapiao[i];
                                    a_WorkPlan_Attachment.CreateTime = DateTime.Now;
                                    a_WorkPlan_Attachment.Operator = CurrentUser.TrueName;
                                    var sss = oA_WorkPlan_AttachmentBLL.InsertModel(a_WorkPlan_Attachment);
                                }
                                else
                                {
                                    continue;
                                }
                            }
 
 
 
                            scope.Complete();
 
 
 
                            JavaScript.MessageBox("新增成功", this, true, true);
                        }
                        else
                            JavaScript.MessageBox("操作失败", this);
                    }
 
 
 
 
 
                }
                catch (Exception ex)
                {
                    PAGEHandleException(ex);
                    JavaScript.MessageBox("操作失败", this);
                }
                finally
                {
                    // 释放资源
                    scope.Dispose();
                }
            }
        }
    }
}