试题导出调整

This commit is contained in:
夏菊 2025-10-15 16:08:06 +08:00
parent 39a8b67c25
commit 902b3ac541
3 changed files with 352 additions and 212 deletions

View File

@ -10,89 +10,92 @@
</head>
<body>
<form id="form1" runat="server">
<f:PageManager ID="PageManager1" AutoSizePanelID="Panel1" runat="server" />
<f:Panel ID="Panel1" runat="server" ShowBorder="false" ShowHeader="false" Layout="Region">
<Items>
<f:Panel runat="server" ID="panelLeftRegion" RegionPosition="Left" RegionSplit="true"
EnableCollapse="true" Width="210px" Title="考试试题库" TitleToolTip="考试试题库" ShowBorder="true"
ShowHeader="false" AutoScroll="true" BodyPadding="2px" IconFont="ArrowCircleLeft"
Layout="Fit">
<Items>
<f:Toolbar ID="Toolbar2" Position="Top" runat="server" ToolbarAlign="Right">
<Items>
<%-- <f:Button ID="btnNew" Icon="Add" runat="server" OnClick="btnNew_Click" Hidden="true">
<f:PageManager ID="PageManager1" AutoSizePanelID="Panel1" runat="server" />
<f:Panel ID="Panel1" runat="server" ShowBorder="false" ShowHeader="false" Layout="Region">
<Items>
<f:Panel runat="server" ID="panelLeftRegion" RegionPosition="Left" RegionSplit="true"
EnableCollapse="true" Width="210px" Title="考试试题库" TitleToolTip="考试试题库" ShowBorder="true"
ShowHeader="false" AutoScroll="true" BodyPadding="2px" IconFont="ArrowCircleLeft"
Layout="Fit">
<Items>
<f:Toolbar ID="Toolbar2" Position="Top" runat="server" ToolbarAlign="Right">
<Items>
<%-- <f:Button ID="btnNew" Icon="Add" runat="server" OnClick="btnNew_Click" Hidden="true">
</f:Button>--%>
<f:Button ID="btnOut" ToolTip="导出" Icon="FolderUp" runat="server"
<f:Button ID="btnOut" ToolTip="导出" Icon="FolderUp" runat="server"
OnClick="btnMenuOut_Click">
</f:Button>
</Items>
</f:Toolbar>
<f:Tree ID="tvTestTraining" EnableCollapse="true" ShowHeader="true" Title="考试试题库" OnNodeCommand="tvTestTraining_NodeCommand"
AutoLeafIdentification="true" runat="server" EnableTextSelection="True">
<Listeners>
<f:Listener Event="beforenodecontextmenu" Handler="onTreeNodeContextMenu" />
</Listeners>
</f:Tree>
</Items>
</f:Panel>
<f:Panel runat="server" ID="panelCenterRegion" RegionPosition="Center" ShowBorder="true"
Layout="VBox" ShowHeader="false" BodyPadding="5px" IconFont="PlusCircle" Title="考试试题明细"
TitleToolTip="考试试题明细" AutoScroll="true">
<Items>
<f:Grid ID="Grid1" Width="870px" ShowBorder="true" ShowHeader="false" EnableCollapse="true"
runat="server" BoxFlex="1" DataKeyNames="TrainingItemId" DataIDField="TrainingItemId"
AllowSorting="true" SortField="TrainingItemCode" ForceFit="true"
SortDirection="DESC" OnSort="Grid1_Sort" AllowPaging="true" IsDatabasePaging="true"
PageSize="15" OnPageIndexChange="Grid1_PageIndexChange" EnableRowDoubleClickEvent="true"
OnRowDoubleClick="Grid1_RowDoubleClick" EnableTextSelection="True" EnableColumnLines="true">
<Toolbars>
<f:Toolbar ID="Toolbar3" Position="Top" runat="server">
<Items>
<f:TextBox ID="txtName" runat="server" Label="查询" EmptyText="输入查询条件"
AutoPostBack="true" OnTextChanged="TextBox_TextChanged" Width="250px" LabelWidth="80px"
LabelAlign="Right">
</f:TextBox>
<f:DropDownList runat="server" ID="drptype" AutoPostBack="true" Label="题型" LabelWidth="60px" OnSelectedIndexChanged="TextBox_TextChanged">
<f:ListItem Value="0" Text="全部" Selected="true"/>
<f:ListItem Value="1" Text="单选题"/>
<f:ListItem Value="2" Text="多选题"/>
<f:ListItem Value="3" Text="判断题"/>
</f:DropDownList>
<f:CheckBox runat="server" ID="ckIsItem" Text="选项不全" AutoPostBack="true" OnCheckedChanged="ckIsItem_CheckedChanged"></f:CheckBox>
<f:ToolbarFill ID="ToolbarFill1" runat="server">
</f:ToolbarFill>
<f:Button ID="btnNewDetail" ToolTip="新增" Icon="Add" runat="server" OnClick="btnNewDetail_Click"
Hidden="true">
</f:Button>
<f:Button ID="btnImport" ToolTip="导入" Icon="PageExcel" Hidden="true" runat="server"
</f:Button>
</Items>
</f:Toolbar>
<f:Tree ID="tvTestTraining" EnableCollapse="true" ShowHeader="true" Title="考试试题库" OnNodeCommand="tvTestTraining_NodeCommand"
AutoLeafIdentification="true" runat="server" EnableTextSelection="True">
<Listeners>
<f:Listener Event="beforenodecontextmenu" Handler="onTreeNodeContextMenu" />
</Listeners>
</f:Tree>
</Items>
</f:Panel>
<f:Panel runat="server" ID="panelCenterRegion" RegionPosition="Center" ShowBorder="true"
Layout="VBox" ShowHeader="false" BodyPadding="5px" IconFont="PlusCircle" Title="考试试题明细"
TitleToolTip="考试试题明细" AutoScroll="true">
<Items>
<f:Grid ID="Grid1" Width="870px" ShowBorder="true" ShowHeader="false" EnableCollapse="true"
runat="server" BoxFlex="1" DataKeyNames="TrainingItemId" DataIDField="TrainingItemId"
AllowSorting="true" SortField="TrainingItemCode" ForceFit="true"
SortDirection="DESC" OnSort="Grid1_Sort" AllowPaging="true" IsDatabasePaging="true"
PageSize="15" OnPageIndexChange="Grid1_PageIndexChange" EnableRowDoubleClickEvent="true"
OnRowDoubleClick="Grid1_RowDoubleClick" EnableTextSelection="True" EnableColumnLines="true">
<Toolbars>
<f:Toolbar ID="Toolbar3" Position="Top" runat="server">
<Items>
<f:TextBox ID="txtName" runat="server" Label="查询" EmptyText="输入查询条件"
AutoPostBack="true" OnTextChanged="TextBox_TextChanged" Width="250px" LabelWidth="80px"
LabelAlign="Right">
</f:TextBox>
<f:DropDownList runat="server" ID="drptype" AutoPostBack="true" Label="题型" LabelWidth="60px" OnSelectedIndexChanged="TextBox_TextChanged">
<f:ListItem Value="0" Text="全部" Selected="true" />
<f:ListItem Value="1" Text="单选题" />
<f:ListItem Value="2" Text="多选题" />
<f:ListItem Value="3" Text="判断题" />
</f:DropDownList>
<f:CheckBox runat="server" ID="ckIsItem" Text="选项不全" AutoPostBack="true" OnCheckedChanged="ckIsItem_CheckedChanged"></f:CheckBox>
<f:ToolbarFill ID="ToolbarFill1" runat="server">
</f:ToolbarFill>
<f:Button ID="btnNewDetail" ToolTip="新增" Icon="Add" runat="server" OnClick="btnNewDetail_Click"
Hidden="true">
</f:Button>
<f:Button ID="btnImport" ToolTip="导入" Icon="PageExcel" Hidden="true" runat="server"
OnClick="btnImport_Click">
</f:Button>
<f:Button ID="Button1" OnClick="btnMenuOut1_Click" runat="server" ToolTip="导出" Icon="FolderUp"
</f:Button>
<f:Button ID="Button1" OnClick="btnOut_Click" runat="server" ToolTip="导出" Icon="FolderUp"
EnableAjax="false" DisableControlBeforePostBack="false">
</f:Button>
<%--<f:Button ID="Button1" OnClick="btnMenuOut1_Click" runat="server" ToolTip="导出" Icon="FolderUp"
EnableAjax="false" DisableControlBeforePostBack="false">
</f:Button>
<%-- <f:Button ID="btnRefresh" ToolTip="按基础数据刷新" Icon="ArrowRefresh" runat="server" OnClick="Refresh_Click"
</f:Button>--%>
<%-- <f:Button ID="btnRefresh" ToolTip="按基础数据刷新" Icon="ArrowRefresh" runat="server" OnClick="Refresh_Click"
Hidden="true">
</f:Button>
<f:Button ID="btnRefresh1" ToolTip="按列表名称刷新" Icon="ArrowRefresh" runat="server" OnClick="Refresh1_Click"
Hidden="true">
</f:Button>--%>
</Items>
</f:Toolbar>
</Toolbars>
<Columns>
<f:RenderField ColumnID="TrainingItemCode" DataField="TrainingItemCode" SortField="TrainingItemCode"
Width="80px" FieldType="String" HeaderText="编号" HeaderTextAlign="Center" TextAlign="left">
</f:RenderField>
<f:RenderField ColumnID="Abstracts" DataField="Abstracts" SortField="Abstracts"
Width="600px" FieldType="String" HeaderText="教材内容" HeaderTextAlign="Center" TextAlign="left">
</f:RenderField>
<f:RenderField ColumnID="WorkPostNames" DataField="WorkPostNames" SortField="WorkPostNames"
Width="200px" FieldType="String" HeaderText="适合岗位" HeaderTextAlign="Center" TextAlign="left">
</f:RenderField>
<f:RenderField ColumnID="TestTypeName" DataField="TestTypeName" SortField="TestTypeName"
Width="70px" FieldType="String" HeaderText="题型" HeaderTextAlign="Center" TextAlign="left">
</f:RenderField>
<%-- <f:RenderField Width="200px" ColumnID="AItem" DataField="AItem" FieldType="String"
</Items>
</f:Toolbar>
</Toolbars>
<Columns>
<f:RenderField ColumnID="TrainingItemCode" DataField="TrainingItemCode" SortField="TrainingItemCode"
Width="80px" FieldType="String" HeaderText="编号" HeaderTextAlign="Center" TextAlign="left">
</f:RenderField>
<f:RenderField ColumnID="Abstracts" DataField="Abstracts" SortField="Abstracts"
Width="600px" FieldType="String" HeaderText="教材内容" HeaderTextAlign="Center" TextAlign="left">
</f:RenderField>
<f:RenderField ColumnID="WorkPostNames" DataField="WorkPostNames" SortField="WorkPostNames"
Width="200px" FieldType="String" HeaderText="适合岗位" HeaderTextAlign="Center" TextAlign="left">
</f:RenderField>
<f:RenderField ColumnID="TestTypeName" DataField="TestTypeName" SortField="TestTypeName"
Width="70px" FieldType="String" HeaderText="题型" HeaderTextAlign="Center" TextAlign="left">
</f:RenderField>
<%-- <f:RenderField Width="200px" ColumnID="AItem" DataField="AItem" FieldType="String"
HeaderText="答案项A" HeaderTextAlign="Center" TextAlign="Left">
</f:RenderField>
<f:RenderField Width="200px" ColumnID="BItem" DataField="BItem" FieldType="String"
@ -110,57 +113,57 @@
<f:RenderField Width="90px" ColumnID="AnswerItems" DataField="AnswerItems" FieldType="String"
HeaderText="正确答案项" HeaderTextAlign="Center" TextAlign="Left">
</f:RenderField> --%>
</Columns>
<Listeners>
<f:Listener Event="beforerowcontextmenu" Handler="onRowContextMenu" />
</Listeners>
<PageItems>
<f:ToolbarSeparator ID="ToolbarSeparator1" runat="server">
</f:ToolbarSeparator>
<f:ToolbarText ID="ToolbarText1" runat="server" Text="每页记录数:">
</f:ToolbarText>
<f:DropDownList runat="server" ID="ddlPageSize" Width="80px" AutoPostBack="true"
OnSelectedIndexChanged="ddlPageSize_SelectedIndexChanged">
</f:DropDownList>
</PageItems>
</f:Grid>
</Items>
</f:Panel>
</Items>
</f:Panel>
<f:Window ID="Window1" Title="考试试题" Hidden="true" EnableIFrame="true" EnableMaximize="true"
Target="Parent" EnableResize="false" runat="server" OnClose="Window1_Close" IsModal="true"
Width="600px" Height="350px">
</f:Window>
<f:Window ID="Window2" Title="考试试题详情" Hidden="true" EnableIFrame="true" EnableMaximize="true"
Target="Parent" EnableResize="false" runat="server" OnClose="Window2_Close" IsModal="true"
Width="900px" Height="580px">
</f:Window>
<f:Window ID="Window3" Title="导入信息" Hidden="true" EnableIFrame="true" EnableMaximize="true"
Target="Parent" EnableResize="false" runat="server" OnClose="Window3_Close" IsModal="false"
CloseAction="HidePostBack" Width="1200px" Height="560px">
</f:Window>
<f:Menu ID="Menu1" runat="server">
<f:MenuButton ID="btnMenuEdit" OnClick="btnMenuEdit_Click" EnablePostBack="true"
runat="server" Text="编辑" Hidden="true" Icon="Pencil">
</f:MenuButton>
<f:MenuButton ID="btnMenuDelete" OnClick="btnMenuDelete_Click" EnablePostBack="true"
Icon="Delete" ConfirmText="删除选中行?" ConfirmTarget="Parent" runat="server" Text="删除"
Hidden="true">
</f:MenuButton>
</f:Menu>
<f:Menu ID="Menu2" runat="server">
<f:MenuButton ID="btnMenuADD" OnClick="btnMenuADD_Click" EnablePostBack="true"
runat="server" Text="新增" Icon="Add" Hidden="true">
</f:MenuButton>
<f:MenuButton ID="btnTreeMenuEdit" OnClick="btnTreeMenuEdit_Click" EnablePostBack="true"
runat="server" Text="编辑" Hidden="true" Icon="Pencil">
</f:MenuButton>
<f:MenuButton ID="btnTreeMenuDelete" OnClick="btnTreeMenuDelete_Click" EnablePostBack="true"
Icon="Delete" ConfirmText="删除选中节点?" ConfirmTarget="Parent" runat="server" Text="删除"
Hidden="true">
</f:MenuButton>
</f:Menu>
</Columns>
<Listeners>
<f:Listener Event="beforerowcontextmenu" Handler="onRowContextMenu" />
</Listeners>
<PageItems>
<f:ToolbarSeparator ID="ToolbarSeparator1" runat="server">
</f:ToolbarSeparator>
<f:ToolbarText ID="ToolbarText1" runat="server" Text="每页记录数:">
</f:ToolbarText>
<f:DropDownList runat="server" ID="ddlPageSize" Width="80px" AutoPostBack="true"
OnSelectedIndexChanged="ddlPageSize_SelectedIndexChanged">
</f:DropDownList>
</PageItems>
</f:Grid>
</Items>
</f:Panel>
</Items>
</f:Panel>
<f:Window ID="Window1" Title="考试试题" Hidden="true" EnableIFrame="true" EnableMaximize="true"
Target="Parent" EnableResize="false" runat="server" OnClose="Window1_Close" IsModal="true"
Width="600px" Height="350px">
</f:Window>
<f:Window ID="Window2" Title="考试试题详情" Hidden="true" EnableIFrame="true" EnableMaximize="true"
Target="Parent" EnableResize="false" runat="server" OnClose="Window2_Close" IsModal="true"
Width="900px" Height="580px">
</f:Window>
<f:Window ID="Window3" Title="导入信息" Hidden="true" EnableIFrame="true" EnableMaximize="true"
Target="Parent" EnableResize="false" runat="server" OnClose="Window3_Close" IsModal="false"
CloseAction="HidePostBack" Width="1200px" Height="560px">
</f:Window>
<f:Menu ID="Menu1" runat="server">
<f:MenuButton ID="btnMenuEdit" OnClick="btnMenuEdit_Click" EnablePostBack="true"
runat="server" Text="编辑" Hidden="true" Icon="Pencil">
</f:MenuButton>
<f:MenuButton ID="btnMenuDelete" OnClick="btnMenuDelete_Click" EnablePostBack="true"
Icon="Delete" ConfirmText="删除选中行?" ConfirmTarget="Parent" runat="server" Text="删除"
Hidden="true">
</f:MenuButton>
</f:Menu>
<f:Menu ID="Menu2" runat="server">
<f:MenuButton ID="btnMenuADD" OnClick="btnMenuADD_Click" EnablePostBack="true"
runat="server" Text="新增" Icon="Add" Hidden="true">
</f:MenuButton>
<f:MenuButton ID="btnTreeMenuEdit" OnClick="btnTreeMenuEdit_Click" EnablePostBack="true"
runat="server" Text="编辑" Hidden="true" Icon="Pencil">
</f:MenuButton>
<f:MenuButton ID="btnTreeMenuDelete" OnClick="btnTreeMenuDelete_Click" EnablePostBack="true"
Icon="Delete" ConfirmText="删除选中节点?" ConfirmTarget="Parent" runat="server" Text="删除"
Hidden="true">
</f:MenuButton>
</f:Menu>
</form>
<script type="text/javascript">
var treeID = '<%= tvTestTraining.ClientID %>';

View File

@ -1,8 +1,10 @@
using BLL;
using NPOI.POIFS.Properties;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
namespace FineUIPro.Web.HSSE.EduTrain
@ -53,7 +55,7 @@ namespace FineUIPro.Web.HSSE.EduTrain
TreeNode tn = null;
foreach (var dr in dt)
{
string name = dr.TrainingName;
string name = dr.TrainingName;
if (!string.IsNullOrEmpty(dr.TrainingCode))
{
name = "[" + dr.TrainingCode + "]" + dr.TrainingName;
@ -161,38 +163,50 @@ namespace FineUIPro.Web.HSSE.EduTrain
{
if (this.tvTestTraining.SelectedNode != null && !string.IsNullOrEmpty(this.tvTestTraining.SelectedNode.NodeID))
{
string strSql = @"SELECT TrainingItemId,TrainingId,TrainingItemCode,TrainingItemName,Abstracts,AttachUrl,VersionNum,TestType "
+ @" ,(CASE WHEN TestType = '1' THEN '单选题' WHEN TestType = '2' THEN '多选题' ELSE '判断题' END) AS TestTypeName "
+ @" ,(CASE WHEN WorkPostNames IS NULL THEN '通用' ELSE WorkPostNames END) AS WorkPostNames,AItem,BItem,CItem,DItem,EItem,AnswerItems "
+ @" FROM dbo.Training_TestTrainingItem"
+ @" WHERE TrainingId=@TrainingId ";
List<SqlParameter> listStr = new List<SqlParameter>
{
new SqlParameter("@TrainingId", this.tvTestTraining.SelectedNode.NodeID)
};
if (!string.IsNullOrEmpty(this.txtName.Text.Trim()))
{
strSql += " AND (TrainingItemCode LIKE @Name OR TrainingItemName LIKE @Name OR Abstracts LIKE @Name OR WorkPostNames LIKE @Name)";
listStr.Add(new SqlParameter("@Name", "%" + this.txtName.Text.Trim() + "%"));
}
if (this.drptype.SelectedValue != "0")
{
strSql += " AND TestType=@TestType";
listStr.Add(new SqlParameter("@TestType", this.drptype.SelectedValue));
}
if (this.ckIsItem.Checked)
{
strSql += " AND (AItem IS NULL OR BItem IS NULL OR AItem ='' OR BItem ='')";
}
SqlParameter[] parameter = listStr.ToArray();
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
Grid1.RecordCount = tb.Rows.Count;
string trainingId = this.tvTestTraining.SelectedNode.NodeID;
DataTable tb = BindData(trainingId);
Grid1.RecordCount = tb.Rows.Count;
var table = this.GetPagedDataTable(Grid1, tb);
Grid1.DataSource = table;
Grid1.DataBind();
}
}
/// <summary>
/// 数据加载
/// </summary>
/// <param name="trainingId"></param>
/// <returns></returns>
public DataTable BindData(string trainingId)
{
string strSql = @"SELECT TrainingItemId,TrainingId,TrainingItemCode,TrainingItemName,Abstracts,AttachUrl,VersionNum,TestType "
+ @" ,(CASE WHEN TestType = '1' THEN '单选题' WHEN TestType = '2' THEN '多选题' ELSE '判断题' END) AS TestTypeName "
+ @" ,(CASE WHEN WorkPostNames IS NULL THEN '通用' ELSE WorkPostNames END) AS WorkPostNames,AItem,BItem,CItem,DItem,EItem,AnswerItems "
+ @" FROM dbo.Training_TestTrainingItem"
+ @" WHERE TrainingId=@TrainingId ";
List<SqlParameter> listStr = new List<SqlParameter>
{
new SqlParameter("@TrainingId", trainingId)
};
if (!string.IsNullOrEmpty(this.txtName.Text.Trim()))
{
strSql += " AND (TrainingItemCode LIKE @Name OR TrainingItemName LIKE @Name OR Abstracts LIKE @Name OR WorkPostNames LIKE @Name)";
listStr.Add(new SqlParameter("@Name", "%" + this.txtName.Text.Trim() + "%"));
}
if (this.drptype.SelectedValue != "0")
{
strSql += " AND TestType=@TestType";
listStr.Add(new SqlParameter("@TestType", this.drptype.SelectedValue));
}
if (this.ckIsItem.Checked)
{
strSql += " AND (AItem IS NULL OR BItem IS NULL OR AItem ='' OR BItem ='')";
}
SqlParameter[] parameter = listStr.ToArray();
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
return tb;
}
#endregion
#region Events
@ -235,7 +249,7 @@ namespace FineUIPro.Web.HSSE.EduTrain
if (getD != null)
{
BLL.LogService.AddSys_Log(this.CurrUser, getD.TrainingItemCode, getD.TrainingItemId, BLL.Const.TestTrainingMenuId, BLL.Const.BtnDelete);
BLL.TestTrainingItemService.DeleteTestTrainingItemById(rowID);
BLL.TestTrainingItemService.DeleteTestTrainingItemById(rowID);
}
}
@ -314,7 +328,7 @@ namespace FineUIPro.Web.HSSE.EduTrain
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnNewDetail_Click(object sender, EventArgs e)
{
{
if (this.tvTestTraining.SelectedNode != null)
{
string id = this.tvTestTraining.SelectedNodeID;
@ -393,41 +407,162 @@ namespace FineUIPro.Web.HSSE.EduTrain
}
#endregion
#region
#region
/// <summary>
/// 导出按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnMenuOut_Click(object sender, EventArgs e)
protected void btnOut_Click(object sender, EventArgs e)
{
PageContext.RegisterStartupScript(Window3.GetShowReference(String.Format("TestTrainingOut.aspx", "导出 - ")));
}
/// <summary>
/// 导出按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnMenuOut1_Click(object sender, EventArgs e)
{
if (this.tvTestTraining.SelectedNode != null && this.tvTestTraining.SelectedNodeID != "0")
string rootPath = Server.MapPath("~/");
string initTemplatePath = Const.TestTrainingTemplateUrl;
string uploadfilepath = string.Empty;
string newUrl = string.Empty;
uploadfilepath = rootPath + initTemplatePath;
string trainingId = string.Empty;
if (this.tvTestTraining.SelectedNode != null && !string.IsNullOrEmpty(this.tvTestTraining.SelectedNode.NodeID))
{
Response.ClearContent();
string filename = Funs.GetNewFileName();
Response.AddHeader("content-disposition", "attachment; filename=" + System.Web.HttpUtility.UrlEncode("考试试题" + filename, System.Text.Encoding.UTF8) + ".xls");
Response.ContentType = "application/excel";
Response.ContentEncoding = System.Text.Encoding.UTF8;
this.Grid1.PageSize = Grid1.RecordCount;
BindGrid();
Response.Write(GetGridTableHtml(Grid1));
Response.End();
trainingId = this.tvTestTraining.SelectedNode.NodeID;
}
else
{
ShowNotify("请选择树节点!", MessageBoxIcon.Warning);
ShowNotify("请选择试题类型!", MessageBoxIcon.Warning);
return;
}
var testTraining = Funs.DB.Training_TestTraining.FirstOrDefault(x => x.TrainingId == trainingId);
var lists = (from x in Funs.DB.Training_TestTrainingItem
where x.TrainingId == trainingId
select x);
string tName = this.txtName.Text.Trim();
if (!string.IsNullOrEmpty(tName))
{
lists = lists.Where(x => x.TrainingItemCode.Contains(tName) || x.TrainingItemName.Contains(tName) || x.Abstracts.Contains(tName) || x.WorkPostNames.Contains(tName));
}
if (this.drptype.SelectedValue != "0")
{
lists = lists.Where(x => x.TestType == this.drptype.SelectedValue);
}
if (this.ckIsItem.Checked)
{
lists = lists.Where(x => string.IsNullOrWhiteSpace(x.AItem) == true || string.IsNullOrWhiteSpace(x.BItem) == true);
}
lists = lists.OrderByDescending(x => x.TrainingItemCode);
if (lists.Any())
{
//string projectName = BLL.ProjectService.GetShortNameByProjectId(this.CurrUser.LoginProjectId);
newUrl = uploadfilepath.Replace("考试试题模版", $"{testTraining.TrainingName}考试试题({DateTime.Now.ToString("yyyyMMddHHmmss")})");
if (File.Exists(newUrl))
{
File.Delete(newUrl);
}
File.Copy(uploadfilepath, newUrl);
// 第一步:读取文件流
NPOI.SS.UserModel.IWorkbook workbook;
using (FileStream stream = new FileStream(newUrl, FileMode.Open, FileAccess.Read))
{
//workbook = new NPOI.XSSF.UserModel.XSSFWorkbook(stream);
workbook = new NPOI.HSSF.UserModel.HSSFWorkbook(stream);
}
// 创建单元格样式
NPOI.SS.UserModel.ICellStyle cellStyle = workbook.CreateCellStyle();
cellStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
cellStyle.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
cellStyle.WrapText = true;//自动换行
var font = workbook.CreateFont();
font.FontHeightInPoints = 11;
cellStyle.SetFont(font);
// 第二步:创建新数据行
NPOI.SS.UserModel.ISheet sheet = workbook.GetSheetAt(0);
NPOI.SS.UserModel.IRow row = sheet.GetRow(0);
NPOI.SS.UserModel.ICell cell;
int i = 2;
foreach (var item in lists)
{
// 第二步:创建新数据行
row = sheet.CreateRow(i);
// 添加数据
cell = row.CreateCell(0);
cell.CellStyle = cellStyle;
cell.SetCellValue(testTraining.TrainingCode);//试题类型编号
cell = row.CreateCell(1);
cell.CellStyle = cellStyle;
cell.SetCellValue(testTraining.TrainingName);//试题类型
cell = row.CreateCell(2);
cell.CellStyle = cellStyle;
cell.SetCellValue(item.TrainingItemCode);//试题编号
string testTypeName = item.TestType == "1" ? "单选题" : item.TestType == "2" ? "多选题" : "判断题";
cell = row.CreateCell(3);
cell.CellStyle = cellStyle;
cell.SetCellValue(testTypeName);//题型
cell = row.CreateCell(4);
cell.CellStyle = cellStyle;
cell.SetCellValue(item.WorkPostNames);//适合岗位
cell = row.CreateCell(5);
cell.CellStyle = cellStyle;
cell.SetCellValue(item.Abstracts);//试题内容
cell = row.CreateCell(6);
cell.CellStyle = cellStyle;
cell.SetCellValue(item.AItem);//答案项A
cell = row.CreateCell(7);
cell.CellStyle = cellStyle;
cell.SetCellValue(item.BItem);//答案项B
cell = row.CreateCell(8);
cell.CellStyle = cellStyle;
cell.SetCellValue(item.CItem);//答案项C
cell = row.CreateCell(9);
cell.CellStyle = cellStyle;
cell.SetCellValue(item.DItem);//答案项D
cell = row.CreateCell(10);
cell.CellStyle = cellStyle;
cell.SetCellValue(item.EItem);//答案项E
cell = row.CreateCell(11);
cell.CellStyle = cellStyle;
cell.SetCellValue(item.AnswerItems);//正确答案
i++;
}
// 第三步:写入文件流
using (FileStream stream = new FileStream(newUrl, FileMode.Create, FileAccess.Write))
{
workbook.Write(stream);
workbook.Close();
}
string fileName = Path.GetFileName(newUrl);
FileInfo info = new FileInfo(newUrl);
long fileSize = info.Length;
Response.Clear();
Response.ContentType = "application/x-zip-compressed";
Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
Response.AddHeader("Content-Length", fileSize.ToString());
Response.TransmitFile(newUrl, 0, fileSize);
Response.Flush();
Response.Close();
File.Delete(newUrl);
}
else
{
Alert.ShowInTop("当前无记录,无法导出!", MessageBoxIcon.Warning);
}
}
#endregion
#region

View File

@ -7,11 +7,13 @@
// </自动生成>
//------------------------------------------------------------------------------
namespace FineUIPro.Web.HSSE.EduTrain {
public partial class TestTraining {
namespace FineUIPro.Web.HSSE.EduTrain
{
public partial class TestTraining
{
/// <summary>
/// form1 控件。
/// </summary>
@ -20,7 +22,7 @@ namespace FineUIPro.Web.HSSE.EduTrain {
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::System.Web.UI.HtmlControls.HtmlForm form1;
/// <summary>
/// PageManager1 控件。
/// </summary>
@ -29,7 +31,7 @@ namespace FineUIPro.Web.HSSE.EduTrain {
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.PageManager PageManager1;
/// <summary>
/// Panel1 控件。
/// </summary>
@ -38,7 +40,7 @@ namespace FineUIPro.Web.HSSE.EduTrain {
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.Panel Panel1;
/// <summary>
/// panelLeftRegion 控件。
/// </summary>
@ -47,7 +49,7 @@ namespace FineUIPro.Web.HSSE.EduTrain {
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.Panel panelLeftRegion;
/// <summary>
/// Toolbar2 控件。
/// </summary>
@ -56,7 +58,7 @@ namespace FineUIPro.Web.HSSE.EduTrain {
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.Toolbar Toolbar2;
/// <summary>
/// btnOut 控件。
/// </summary>
@ -65,7 +67,7 @@ namespace FineUIPro.Web.HSSE.EduTrain {
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.Button btnOut;
/// <summary>
/// tvTestTraining 控件。
/// </summary>
@ -74,7 +76,7 @@ namespace FineUIPro.Web.HSSE.EduTrain {
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.Tree tvTestTraining;
/// <summary>
/// panelCenterRegion 控件。
/// </summary>
@ -83,7 +85,7 @@ namespace FineUIPro.Web.HSSE.EduTrain {
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.Panel panelCenterRegion;
/// <summary>
/// Grid1 控件。
/// </summary>
@ -92,7 +94,7 @@ namespace FineUIPro.Web.HSSE.EduTrain {
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.Grid Grid1;
/// <summary>
/// Toolbar3 控件。
/// </summary>
@ -101,7 +103,7 @@ namespace FineUIPro.Web.HSSE.EduTrain {
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.Toolbar Toolbar3;
/// <summary>
/// txtName 控件。
/// </summary>
@ -110,7 +112,7 @@ namespace FineUIPro.Web.HSSE.EduTrain {
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.TextBox txtName;
/// <summary>
/// drptype 控件。
/// </summary>
@ -119,7 +121,7 @@ namespace FineUIPro.Web.HSSE.EduTrain {
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.DropDownList drptype;
/// <summary>
/// ckIsItem 控件。
/// </summary>
@ -128,7 +130,7 @@ namespace FineUIPro.Web.HSSE.EduTrain {
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.CheckBox ckIsItem;
/// <summary>
/// ToolbarFill1 控件。
/// </summary>
@ -137,7 +139,7 @@ namespace FineUIPro.Web.HSSE.EduTrain {
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.ToolbarFill ToolbarFill1;
/// <summary>
/// btnNewDetail 控件。
/// </summary>
@ -146,7 +148,7 @@ namespace FineUIPro.Web.HSSE.EduTrain {
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.Button btnNewDetail;
/// <summary>
/// btnImport 控件。
/// </summary>
@ -155,7 +157,7 @@ namespace FineUIPro.Web.HSSE.EduTrain {
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.Button btnImport;
/// <summary>
/// Button1 控件。
/// </summary>
@ -164,7 +166,7 @@ namespace FineUIPro.Web.HSSE.EduTrain {
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.Button Button1;
/// <summary>
/// ToolbarSeparator1 控件。
/// </summary>
@ -173,7 +175,7 @@ namespace FineUIPro.Web.HSSE.EduTrain {
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.ToolbarSeparator ToolbarSeparator1;
/// <summary>
/// ToolbarText1 控件。
/// </summary>
@ -182,7 +184,7 @@ namespace FineUIPro.Web.HSSE.EduTrain {
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.ToolbarText ToolbarText1;
/// <summary>
/// ddlPageSize 控件。
/// </summary>
@ -191,7 +193,7 @@ namespace FineUIPro.Web.HSSE.EduTrain {
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.DropDownList ddlPageSize;
/// <summary>
/// Window1 控件。
/// </summary>
@ -200,7 +202,7 @@ namespace FineUIPro.Web.HSSE.EduTrain {
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.Window Window1;
/// <summary>
/// Window2 控件。
/// </summary>
@ -209,7 +211,7 @@ namespace FineUIPro.Web.HSSE.EduTrain {
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.Window Window2;
/// <summary>
/// Window3 控件。
/// </summary>
@ -218,7 +220,7 @@ namespace FineUIPro.Web.HSSE.EduTrain {
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.Window Window3;
/// <summary>
/// Menu1 控件。
/// </summary>
@ -227,7 +229,7 @@ namespace FineUIPro.Web.HSSE.EduTrain {
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.Menu Menu1;
/// <summary>
/// btnMenuEdit 控件。
/// </summary>
@ -236,7 +238,7 @@ namespace FineUIPro.Web.HSSE.EduTrain {
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.MenuButton btnMenuEdit;
/// <summary>
/// btnMenuDelete 控件。
/// </summary>
@ -245,7 +247,7 @@ namespace FineUIPro.Web.HSSE.EduTrain {
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.MenuButton btnMenuDelete;
/// <summary>
/// Menu2 控件。
/// </summary>
@ -254,7 +256,7 @@ namespace FineUIPro.Web.HSSE.EduTrain {
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.Menu Menu2;
/// <summary>
/// btnMenuADD 控件。
/// </summary>
@ -263,7 +265,7 @@ namespace FineUIPro.Web.HSSE.EduTrain {
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.MenuButton btnMenuADD;
/// <summary>
/// btnTreeMenuEdit 控件。
/// </summary>
@ -272,7 +274,7 @@ namespace FineUIPro.Web.HSSE.EduTrain {
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.MenuButton btnTreeMenuEdit;
/// <summary>
/// btnTreeMenuDelete 控件。
/// </summary>