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();
}
}
///
/// 加载全部数据
///
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();
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;
}
///
/// 计划订单上传接口
///
///
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;
}
}
}