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
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.Model;
using CY.Infrastructure.Query;
using CY.Infrastructure.Common;
using CY.BLL.OA;
using CY.BLL.Sys;
using System.IO;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
using System.Transactions;
using CY.BLL.EC;
using CY.BLL.Inquiry;
using CY.Model.Inquiry;
 
namespace CY.WebForm.Pages.financial 
{
    public partial class ShiJuanBiaoQianList : BasePage
    {
 
        OA_ShiJuanBiaoQianBLL _ShiJuanBiaoQianBLL = new OA_ShiJuanBiaoQianBLL();
         
 
        protected void Page_Load(object sender, EventArgs e)
        {
            UCPager1.AspNetPager.PageChanged += AspNetPager1_PageChanged;
            if (!IsPostBack)
            {
               
             
                BindList();
            }
 
            if (Request["Target"] != null && Request["Target"] == "BatchDelete")
            {
                CY.WebForm.cs.WebUtil.DeleteData(_ShiJuanBiaoQianBLL.DeleteDataByIds, CurrentUser.ShortName);//调用通用删除方法
                Response.End();
            }
 
        }
 
 
        /// <summary>
        /// 加载全部数据
        /// </summary>
        private void BindList()
        {
            
            Pagination pa = new Pagination();
            pa.PageSize = this.UCPager1.AspNetPager.PageSize;
            pa.PageIndex = this.UCPager1.AspNetPager.CurrentPageIndex;
            
            this.RepSubjeSetctList.DataSource = _ShiJuanBiaoQianBLL.SelectModelPage(pa,CurrentUser.MemberId,this.txtBeginData.Value.Trim(),this.txtEndDate.Value.Trim(),
                this.txtBianhao.Value.Trim(), this.txtQuyu.Value.Trim(), this.txtXuexiao.Value.Trim(), this.txtNianji.Value.Trim(), this.txtKemu.Value.Trim());
 
            this.RepSubjeSetctList.DataBind();
             UCPager1.AspNetPager.RecordCount = pa.RecordCount;
           
        }
 
        protected void AspNetPager1_PageChanged(object src, EventArgs e)
        {
            BindList();
        }
 
        protected void btn_Register_Click(object sender, EventArgs e)
        {
            BindList();
        }
 
         
 
        protected void btn_Submit_Click(object sender, EventArgs e)
        {
 
            var files = Request.Files;
            if (files.Count <= 0)
                return;
 
            var file = files[0];
            if (file == null)
            {
                JavaScript.MessageBox("请选择文件", this);
                return;
            }
 
            //初始化上传参数
            var maxSize = 1024 * 1024 * 5; //上传大小5M
 
            var fileName = file.FileName;
            var fileExt = Path.GetExtension(fileName).ToLowerInvariant();
 
            //检查大小
            if (file.ContentLength > maxSize)
            {
               
                JavaScript.MessageBox("上传文件大小超过限制,最大允许上传5M", this);
                return;
            }
          
            string FileTypes = "xlsx";//xls,
            //检查文件扩展名
            if (string.IsNullOrEmpty(fileExt) ||
                Array.IndexOf(FileTypes.Split(','), fileExt.Substring(1).ToLower()) == -1)
            {
                JavaScript.MessageBox("上传文件扩展名是不允许的扩展名,请上传后缀名为:" + FileTypes, this);
                return;
            }
            var lie = new List<OA_ShiJuanBiaoQian>();
            
            using (var fileStream = file.InputStream)
            {
                // 使用HSSFWorkbook打开.xls格式的文件
                IWorkbook workbook = new XSSFWorkbook(fileStream);
 
                // 获取第一个工作表
                ISheet sheet = workbook.GetSheetAt(0);
 
 
 
 
 
 
 
                // 迭代工作表中的所有行
                for (int i = 1; i <= sheet.LastRowNum; i++)
                {
                    var hang = new OA_ShiJuanBiaoQian();
                  
 
 
                    IRow row = sheet.GetRow(i);
                    if (row == null) continue; // 跳过空行
 
 
                    ICell cell0 = row.GetCell(0);
                    if (cell0 == null)
                    {
                        JavaScript.MessageBox("第" + (i + 1) + "编号不能为空", this); 
                        return;
                    }
                    hang.Bianhao = getcellvalue(cell0);
 
                    ICell cell1 = row.GetCell(1);
                    if (cell1 == null)
                    {
                        JavaScript.MessageBox("第" + (i + 1) + "片区不能为空", this);
                        return;
                    }
                    hang.Quyu = getcellvalue(cell1);
 
                    ICell cell2 = row.GetCell(2);
                    if (cell2 == null)
                    {
                        JavaScript.MessageBox("第" + (i + 1) + "学校不能为空", this);
                        return;
                    }
                    hang.Xuexiao = getcellvalue(cell2);
 
                    ICell cell3 = row.GetCell(3);
                    if (cell3 == null)
                    {
                        JavaScript.MessageBox("第" + (i + 1) + "年级不能为空", this);
                        return;
                    }
                    hang.Nianji = getcellvalue(cell3);
 
                    ICell cell4 = row.GetCell(4);
                    if (cell4 == null)
                    {
                        JavaScript.MessageBox("第" + (i + 1) + "科目不能为空", this);
                        return;
                    }
                    hang.Kemu = getcellvalue(cell4);
 
                    ICell cell5 = row.GetCell(5);
                    if (cell5 == null)
                    {
                        JavaScript.MessageBox("第" + (i + 1) + "大不能为空", this);
                        return;
                    }
                    hang.Da = getcellvalue(cell5);
 
                    ICell cell6 = row.GetCell(6);
                    if (cell6 == null)
                    {
                        JavaScript.MessageBox("第" + (i + 1) + "小不能为空", this);
                        return;
                    }
                    hang.Xiao = getcellvalue(cell6);
                    lie.Add(hang);
 
                }
            }
        
 
 
 
 
 
 
 
 
              
            
 
 
            using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required,
        new TransactionOptions
        {
            IsolationLevel = IsolationLevel.ReadCommitted,
            Timeout = TransactionManager.MaximumTimeout
        }
        ))
            {
 
              
                if (lie != null && lie.Count > 0)
                {
                    var creater= CurrentUser.ShortName;
                    var creattiem = DateTime.Now;
                    var FirmId = CurrentUser.MemberId;
                    for (int j = 0; j < lie.Count; j++)
                    {
 
                        lie[j].Creater = creater;
                        lie[j].Updater = creater;
                        lie[j].CreateTime = creattiem;
                        lie[j].LastUpdateTime = creattiem;
                        lie[j].FirmId = FirmId;
 
                        var id = _ShiJuanBiaoQianBLL.InsertModel(lie[j]);
                            
                            
                       
 
                    }
 
 
                }
                else
                {
 
 
                    JavaScript.MessageBox("表格无数据", this);
                    return;
                }
                scope.Complete();
            }
 
 
 
           
          
 
            JavaScript.MessageBox("上传文件成功", this);
            BindList();
 
            return;
            }
 
 
 
 
    /// <summary>
    /// 计划订单上传接口
    /// </summary>
    /// <returns></returns>
    public string getcellvalue(ICell cell)
    {
        string cellvalue = "";
        switch (cell.CellType)
        {
            case CellType.String:
                // Console.WriteLine(cell.StringCellValue);
                cellvalue = cell.StringCellValue.Trim();
                break;
            case CellType.Numeric:
                //Console.WriteLine(cell.NumericCellValue);
                cellvalue = cell.NumericCellValue.ToString().Trim();
                break;
            case CellType.Boolean:
                //Console.WriteLine(cell.BooleanCellValue);
                cellvalue = cell.BooleanCellValue.ToString().Trim();
                break;
            case CellType.Error:
                // Console.WriteLine(cell.ErrorCellValue);
                cellvalue = cell.ErrorCellValue.ToString().Trim();
                break;
            case CellType.Blank:
                    // Console.WriteLine(cell.ErrorCellValue);
                    cellvalue = "";
                    break;
                    // 可以添加其他类型的case
            }
 
        return cellvalue;
    }
       
 
    }
}