username@email.com
2025-05-07 451ec557d579f8f9e1b0c84754709cc8b3d2090e
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
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CY.BLL;
using CY.BLL.Sys;
using CY.Model;
using CY.Infrastructure.Query;
using CY.Infrastructure.Common;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
using System.IO;
 
namespace CY.WebForm.Pages.work
{
    //吴辉
    //我的请示
    public partial class BaoxiaoFukuanList : BasePage
    {
        Sys_DictionaryBLL bll_Sys_DictionaryBLL = null;
        OA_WorkPlanBll bll_OA_WorkPlanBll = null;
        OA_WorkPlan_attachmentBLL oA_WorkPlan_AttachmentBLL = null;
        OA_DepartmentBll oA_DepartmentBll = null;
        OA_StaffBLL oA_StaffBLL = null;
        OA_WorkPlan_shenpiBLL oA_WorkPlan_ShenpiBLL = null;
        //初始化
        public BaoxiaoFukuanList()
        {
            bll_Sys_DictionaryBLL = new Sys_DictionaryBLL();
            bll_OA_WorkPlanBll = new OA_WorkPlanBll();
            oA_WorkPlan_AttachmentBLL = new OA_WorkPlan_attachmentBLL();
            oA_DepartmentBll = new OA_DepartmentBll();
            oA_StaffBLL = new OA_StaffBLL();
            oA_WorkPlan_ShenpiBLL = new OA_WorkPlan_shenpiBLL();
        }
 
        //页面加载
        protected void Page_Load(object sender, EventArgs e)
        {
            UCPager1.AspNetPager.PageChanged += AspNetPager1_PageChanged;
            if (!IsPostBack)
            {
                this.selEvaluationStatus.Value = "2";
                BindList();
            }
            if (Request["delete"] != null)
            {
                OA_WorkPlan model = bll_OA_WorkPlanBll.GetModelByKeyid(Request["delete"].ToInt32());
                if (model != null && model.Keyid != null)
                {
                    bll_OA_WorkPlanBll.DeleteModel(model, CurrentUser.TrueName);
                    JavaScript.MessageBox("删除成功", this);
                    Response.Redirect("/Pages/work/BaoxiaoFukuanList.aspx");
                }
                else
                {
                    JavaScript.MessageBox("删除失败", this);
                }
            }
 
            if (Request["deleteKeyIds"] != null)
            {
                List<int> deleteKeyIdList = new List<int>();
                string deleteKeyIds = Request["deleteKeyIds"].ToString();
                if (deleteKeyIds.Contains(","))
                {
                    string[] keyIdArry = deleteKeyIds.Split(',');
                    foreach (string keyId in keyIdArry)
                    {
                        OA_WorkPlan model = bll_OA_WorkPlanBll.GetModelByKeyid(keyId.ToInt32());
                        if (model.Keyid != null && model != null)
                        {
                            bll_OA_WorkPlanBll.DeleteModel(model, CurrentUser.TrueName);
                        }
                        else
                        {
                            JavaScript.MessageBox("删除失败", this);
                            break;
                        }
 
                    }
                    JavaScript.MessageBox("删除成功", this);
                }
                else
                {
                    OA_WorkPlan model = bll_OA_WorkPlanBll.GetModelByKeyid(Request["deleteKeyIds"].ToInt32());
                    if (model.Keyid != null && model != null)
                    {
                        bll_OA_WorkPlanBll.DeleteModel(model, CurrentUser.TrueName);
                        JavaScript.MessageBox("删除成功", this);
                    }
                    else
                    {
                        JavaScript.MessageBox("删除失败", this);
 
                    }
                }
 
                Response.Redirect("/Pages/work/BaoxiaoFukuanList.aspx");
            }
        }
 
        //绑定数据
        private void BindList()
        {
            Pagination pa = new Pagination();
            DateTime? beginTime = null;
            DateTime? endTime = null;
            pa.PageSize = UCPager1.AspNetPager.PageSize;
            pa.PageIndex = UCPager1.AspNetPager.CurrentPageIndex;
            var oA_WorkPlans = bll_OA_WorkPlanBll.SelectModelPage(pa, CurrentUser.MemberId, Guid.Empty, Guid.Empty, 3, 17, "", null, null, string.IsNullOrEmpty(this.txtRegTimeStart.Value) ? beginTime : Convert.ToDateTime(this.txtRegTimeStart.Value), string.IsNullOrEmpty(this.txtRegTimeEnd.Value) ? endTime : Convert.ToDateTime(this.txtRegTimeEnd.Value), this.txtPlanPeople.Value.Trim(), -1, 1, this.selEvaluationStatus.Value.ToInt32(), null,this.TxtRewardContent.Value.Trim(), this.txtPlanContent.Value.Trim());
            var oA_Staff = oA_StaffBLL.GetModelByMemberId(CurrentUser.TrueMemberId);
         
            foreach (var oA_WorkPlan in oA_WorkPlans)
            {
                var sss = oA_WorkPlan_AttachmentBLL.GetModelByKaipiaoId(oA_WorkPlan.Keyid.Value);
 
              var fapiaos =  sss.Where(x => x.AttachmentType == 1).ToList();
                var fujians = sss.Where(x => x.AttachmentType == 2).ToList();
                if (fapiaos.Count > 0)
                {
                    int i = 1;
                    oA_WorkPlan.Fapiao = "";
                    foreach (var oA_WorkPlan_Attachment  in fapiaos)
                    {
                        oA_WorkPlan.Fapiao += "<a title=\"查看发票\"    target=\"view_window\" href=\""+ oA_WorkPlan_Attachment.PlanAttachment+ "\">发票"+i+" </a> ";
 
                        i = i + 1;
                    }
                }
 
                if (fujians.Count > 0)
                {
                    int i = 1;
                    oA_WorkPlan.Fujian = "";
                    foreach (var oA_WorkPlan_Attachment in fujians)
                    {
                        oA_WorkPlan.Fujian += "<a title=\"查看附件\"    target=\"view_window\" href=\"" + oA_WorkPlan_Attachment.PlanAttachment + "\">附件" + i + " </a> ";
 
                        i = i + 1;
                    }
                }
 
                var oA_Department = oA_DepartmentBll.GetModelByKeyid(oA_WorkPlan.DepartId);
                if (oA_Department != null)
                {
                    oA_WorkPlan.DepartName = oA_Department.Name;
                }
                oA_WorkPlan.Nengfoushenpi = 0;
                var oA_WorkPlan_Shenpis = oA_WorkPlan_ShenpiBLL.GetModelByKaipiaoId(oA_WorkPlan.Keyid.Value).ToList();
                if (oA_WorkPlan.ApprovalStatus == 1 || oA_WorkPlan.ApprovalStatus == 2)
                {
                    oA_WorkPlan.Nengfoushenpi = 1;
                }
                else
                {
                    if (!oA_Staff.BF_IsBaoxiaozhuguan && !oA_Staff.BF_Isbaoxiaojingli)
                    {
                        oA_WorkPlan.Nengfoushenpi = 1;
                    }
                    else if(oA_Staff.BF_IsBaoxiaozhuguan && !oA_Staff.BF_Isbaoxiaojingli)
                    {
                        var oA_WorkPlan_Shenpis1 = oA_WorkPlan_Shenpis.Where(x => x.Buzhou == 1).ToList();
                        if (oA_WorkPlan_Shenpis1.Count > 1)
                        {
                            oA_WorkPlan.Nengfoushenpi = 1;
                        }
 
                        var shenpicount = oA_WorkPlan_Shenpis1.Count(x => x.ApprovalStaffId == CurrentUser.TrueMemberId);
                        if (shenpicount > 0)
                        {
                            oA_WorkPlan.Nengfoushenpi = 1;
                        }
                    }
                    else if (!oA_Staff.BF_IsBaoxiaozhuguan && oA_Staff.BF_Isbaoxiaojingli)
                    {
                        if (oA_WorkPlan_Shenpis.Count > 2)
                        {
                            oA_WorkPlan.Nengfoushenpi = 1;
                        }
                        if (oA_WorkPlan_Shenpis.Count < 2)
                        {
                            oA_WorkPlan.Nengfoushenpi = 1;
                        }
                    }
                    else if (oA_Staff.BF_IsBaoxiaozhuguan && oA_Staff.BF_Isbaoxiaojingli)
                    {
                        var oA_WorkPlan_Shenpis1 = oA_WorkPlan_Shenpis.Where(x => x.Buzhou == 1).ToList();
                        
 
                        var shenpicount = oA_WorkPlan_Shenpis1.Count(x => x.ApprovalStaffId == CurrentUser.TrueMemberId);
                        
 
 
                        if(oA_WorkPlan_Shenpis.Count != 2 && ((oA_WorkPlan_Shenpis1.Count > 1) || shenpicount > 0))
                        {
                            oA_WorkPlan.Nengfoushenpi = 1;
                        }
 
                        
                    }
                }
 
 
 
 
 
            }
 
          
            this.NowMoney.InnerText = oA_WorkPlans.Sum(x => x.PlanMoney).Value.ToString("F2");
            this.RepClientList.DataSource = oA_WorkPlans;
            this.RepClientList.DataBind();
            UCPager1.AspNetPager.RecordCount = pa.RecordCount;
        }
 
        //分页事件
        protected void AspNetPager1_PageChanged(object src, EventArgs e)
        {
            BindList();
        }
 
        //查询事件
        protected void btn_Search_Click(object src, EventArgs e)
        {
            BindList();
        }
 
 
 
 
        //查询事件
        protected void btn_Daochu_Click(object src, EventArgs e)
        {
           
            byte[] fileBytes = ExportToExcel();
            if (fileBytes != null)
            {
                Response.Clear();
                Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                Response.AppendHeader("Content-Disposition", "attachment; filename=报销付款导出.xlsx");
                Response.BinaryWrite(fileBytes);
                Response.End();
            }
            else
            {
                // 处理导出失败的情况
                Response.Write("导出失败,请稍后重试!");
            }
 
        }
 
 
        public byte[] ExportToExcel()
        {
            byte[] bt = null;
            try
            {
                Pagination pa = new Pagination();
                DateTime? beginTime = null;
                DateTime? endTime = null;
                pa.PageSize = 10000;
                pa.PageIndex = 1;
                var oA_WorkPlans = bll_OA_WorkPlanBll.SelectModelPage(pa, CurrentUser.MemberId, Guid.Empty, Guid.Empty, 3, 17, "", null, null, string.IsNullOrEmpty(this.txtRegTimeStart.Value) ? beginTime : Convert.ToDateTime(this.txtRegTimeStart.Value), string.IsNullOrEmpty(this.txtRegTimeEnd.Value) ? endTime : Convert.ToDateTime(this.txtRegTimeEnd.Value), this.txtPlanPeople.Value.Trim(), -1, 1, this.selEvaluationStatus.Value.ToInt32(), null, this.TxtRewardContent.Value.Trim(), this.txtPlanContent.Value.Trim());
 
 
                // 创建工作簿
                IWorkbook workbook = new XSSFWorkbook();
                ISheet sheet = workbook.CreateSheet("导出数据");
 
                // 创建表头
                IRow headerRow = sheet.CreateRow(0);
                headerRow.CreateCell(0).SetCellValue("编号");
                headerRow.CreateCell(1).SetCellValue("申请日期");
                headerRow.CreateCell(2).SetCellValue("报销单号");
                headerRow.CreateCell(3).SetCellValue("部门");
                headerRow.CreateCell(4).SetCellValue("姓名");
                headerRow.CreateCell(5).SetCellValue("科目");
                headerRow.CreateCell(6).SetCellValue("摘要");
                headerRow.CreateCell(7).SetCellValue("金额");
                headerRow.CreateCell(8).SetCellValue("付款状态");
                headerRow.CreateCell(9).SetCellValue("审批人1");
                headerRow.CreateCell(10).SetCellValue("审批时间1");
                headerRow.CreateCell(11).SetCellValue("审批结果1");
                headerRow.CreateCell(12).SetCellValue("审批人2");
                headerRow.CreateCell(13).SetCellValue("审批时间2");
                headerRow.CreateCell(14).SetCellValue("审批结果2");
                headerRow.CreateCell(15).SetCellValue("审批人3");
                headerRow.CreateCell(16).SetCellValue("审批时间3");
                headerRow.CreateCell(17).SetCellValue("审批结果3");
 
                // 添加数据
                int rowIndex = 1;
                foreach (var order in oA_WorkPlans)
                {
                    IRow row = sheet.CreateRow(rowIndex++);
                    row.CreateCell(0).SetCellValue((rowIndex-1).ToString());
                    row.CreateCell(1).SetCellValue(order.PlanStartTime.Value.ToString("yyyy-MM-dd HH:mm:ss"));
                    row.CreateCell(2).SetCellValue(order.EvaluationContent);
                    row.CreateCell(3).SetCellValue(order.DepartName);
                    row.CreateCell(4).SetCellValue(order.PlanPeople);
                    row.CreateCell(5).SetCellValue(order.RewardContent);
                    row.CreateCell(6).SetCellValue(order.PlanContent);
                    row.CreateCell(7).SetCellValue(order.PlanMoney.ToString());
                    row.CreateCell(8).SetCellValue(order.EvaluationStatusName);
                    var oA_WorkPlan_Shenpis = oA_WorkPlan_ShenpiBLL.GetModelByKaipiaoId(order.Keyid.Value).OrderBy(x => x.Keyid).ToList();
                    foreach (var a_WorkPlan_Shenpi in oA_WorkPlan_Shenpis)
                    {
                        var oA_Staff = oA_StaffBLL.GetModelByMemberId(a_WorkPlan_Shenpi.ApprovalStaffId);
                        if (oA_Staff != null)
                        {
                            a_WorkPlan_Shenpi.ApprovalStaffName = oA_Staff.Name;
                        }
                    }
                    if (oA_WorkPlan_Shenpis.Count > 0)
                    {
                        row.CreateCell(9).SetCellValue(oA_WorkPlan_Shenpis[0].ApprovalStaffName);
                        row.CreateCell(10).SetCellValue(oA_WorkPlan_Shenpis[0].ApprovalTime.Value.ToString("yyyy-MM-dd HH:mm:ss"));
                        row.CreateCell(11).SetCellValue(oA_WorkPlan_Shenpis[0].ApprovalStatusName);
                       
                    }
                    if (oA_WorkPlan_Shenpis.Count > 1)
                    {
                        row.CreateCell(12).SetCellValue(oA_WorkPlan_Shenpis[1].ApprovalStaffName);
                        row.CreateCell(13).SetCellValue(oA_WorkPlan_Shenpis[1].ApprovalTime.Value.ToString("yyyy-MM-dd HH:mm:ss"));
                        row.CreateCell(14).SetCellValue(oA_WorkPlan_Shenpis[1].ApprovalStatusName);
 
                    }
                    if (oA_WorkPlan_Shenpis.Count > 2)
                    {
                        row.CreateCell(15).SetCellValue(oA_WorkPlan_Shenpis[2].ApprovalStaffName);
                        row.CreateCell(16).SetCellValue(oA_WorkPlan_Shenpis[2].ApprovalTime.Value.ToString("yyyy-MM-dd HH:mm:ss"));
                        row.CreateCell(17).SetCellValue(oA_WorkPlan_Shenpis[2].ApprovalStatusName);
 
                    }
                    
                }
 
                // 将工作簿写入内存流
                using (var ms = new MemoryStream())
                {
                    workbook.Write(ms);
                    bt = ms.ToArray();
                }
            }
            catch (Exception e)
            {
                bt = null;
                // 记录日志
               
            }
            return bt;
        }
 
 
 
 
 
 
    }
}