2024-06-21 16:37:50 +08:00
using System ;
2024-05-11 15:22:08 +08:00
using System.Collections.Generic ;
using System.Data ;
2024-06-21 16:37:50 +08:00
using System.Data.SqlClient ;
using System.IO ;
2024-05-11 15:22:08 +08:00
using System.Linq ;
2024-06-21 16:37:50 +08:00
using System.Web ;
using BLL ;
using Model ;
using NPOI.HSSF.Util ;
2024-06-20 17:12:59 +08:00
using NPOI.SS.UserModel ;
2024-06-21 16:37:50 +08:00
using NPOI.SS.Util ;
2024-06-20 17:12:59 +08:00
using NPOI.XSSF.UserModel ;
2024-10-22 21:13:56 +08:00
using static System . Windows . Forms . VisualStyles . VisualStyleElement ;
2024-06-20 17:12:59 +08:00
2024-05-11 15:22:08 +08:00
namespace FineUIPro.Web.WeldingProcess.PMI
{
public partial class PMIDelegation : PageBase
{
#region 定 义 项
/// <summary>
/// PMI委托主键
/// </summary>
public string PMIDelegationId
{
get
{
return ( string ) ViewState [ "PMIDelegationId" ] ;
}
set
{
ViewState [ "PMIDelegationId" ] = value ;
}
}
2024-10-22 21:13:56 +08:00
/// <summary>
/// 上传预设的虚拟路径
/// </summary>
private string initPath = Const . ExcelUrl ;
/// <summary>
/// 错误集合
/// </summary>
public static string errorInfos = string . Empty ;
2024-05-11 15:22:08 +08:00
#endregion
#region 加 载 页 面
/// <summary>
/// 加载页面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load ( object sender , EventArgs e )
{
if ( ! IsPostBack )
{
this . ddlPageSize . SelectedValue = this . Grid1 . PageSize . ToString ( ) ;
this . PMIDelegationId = string . Empty ;
this . InitTreeMenu ( ) ; //加载树
}
}
#endregion
#region 加 载 树
/// <summary>
/// 加载树
/// </summary>
private void InitTreeMenu ( )
{
string projectName = string . Empty ;
var pro = BLL . Base_ProjectService . GetProjectByProjectId ( this . CurrUser . LoginProjectId ) ;
if ( pro ! = null )
{
this . tvControlItem . Nodes . Clear ( ) ;
TreeNode rootNode = new TreeNode ( ) ;
rootNode . Text = "[" + pro . ProjectCode + "]" + pro . ProjectName ;
rootNode . NodeID = "0" ;
rootNode . Expanded = true ;
rootNode . EnableClickEvent = true ;
this . tvControlItem . Nodes . Add ( rootNode ) ;
List < Model . PMI_Delegation > trustLists = new List < Model . PMI_Delegation > ( ) ; ///PMI委托单
2024-06-21 16:37:50 +08:00
2024-05-11 15:22:08 +08:00
if ( ! string . IsNullOrEmpty ( this . txtSearchNo . Text . Trim ( ) ) )
{
trustLists = ( from x in Funs . DB . PMI_Delegation where x . ProjectId = = CurrUser . LoginProjectId & & x . DelegationNo . Contains ( this . txtSearchNo . Text . Trim ( ) ) orderby x . DelegationNo select x ) . ToList ( ) ;
}
else
{
trustLists = ( from x in Funs . DB . PMI_Delegation where x . ProjectId = = CurrUser . LoginProjectId orderby x . DelegationNo select x ) . ToList ( ) ;
}
this . BindNodes ( rootNode , trustLists ) ;
}
}
#endregion
#region 绑 定 树 节 点
/// <summary>
/// 绑定树节点
/// </summary>
/// <param name="node"></param>
private void BindNodes ( TreeNode node , List < Model . PMI_Delegation > trustList )
{
foreach ( var item in trustList )
{
TreeNode newNode = new TreeNode ( ) ;
newNode . Text = item . DelegationNo ;
newNode . NodeID = item . Id ;
newNode . ToolTip = item . DelegationNo ;
newNode . CommandName = Resources . Lan . RequestSheetNumber ;
newNode . EnableClickEvent = true ;
node . Nodes . Add ( newNode ) ;
}
}
#endregion
#region 点 击 TreeView
/// <summary>
/// 点击TreeView
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void tvControlItem_NodeCommand ( object sender , TreeCommandEventArgs e )
{
if ( this . tvControlItem . SelectedNodeID ! = "0" )
{
this . PMIDelegationId = tvControlItem . SelectedNodeID ;
this . BindGrid ( ) ;
}
}
#endregion
#region DropDownList下拉选择事件
/// <summary>
/// 项目下拉选择事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void drpProjectId_SelectedIndexChanged ( object sender , EventArgs e )
{
this . InitTreeMenu ( ) ;
}
#endregion
#region 数 据 绑 定
/// <summary>
/// 数据绑定
/// </summary>
private void BindGrid ( )
{
string strSql = string . Empty ;
List < SqlParameter > listStr = new List < SqlParameter > ( ) ;
this . SetTextTemp ( ) ;
this . PageInfoLoad ( ) ; ///页面输入提交信息
if ( ! string . IsNullOrEmpty ( this . tvControlItem . SelectedNodeID ) )
{
2024-06-21 16:37:50 +08:00
var result = Funs . DB . PMI_Delegation . FirstOrDefault ( t = > t . Id = = this . tvControlItem . SelectedNodeID ) ;
2024-05-11 15:22:08 +08:00
if ( result ! = null )
{
this . PMIDelegationId = result . Id ;
2024-05-12 12:05:01 +08:00
strSql = @"SELECT *FROM [View_PMI_DelegationDetails] WHERE ProjectId= @ProjectId AND PMIID=@PMIDelegationId " ;
2024-05-11 15:22:08 +08:00
listStr . Add ( new SqlParameter ( "@ProjectId" , result ! = null ? result . ProjectId : this . CurrUser . LoginProjectId ) ) ;
2024-05-12 12:05:01 +08:00
listStr . Add ( new SqlParameter ( "@PMIDelegationId" , this . PMIDelegationId ) ) ;
2024-05-11 15:22:08 +08:00
if ( ! string . IsNullOrEmpty ( this . txtIsoNo . Text . Trim ( ) ) )
{
2024-05-12 14:23:37 +08:00
strSql + = @" and PipelineCode like '%'+@PipelineCode+'%' " ;
2024-05-11 15:22:08 +08:00
listStr . Add ( new SqlParameter ( "@PipelineCode" , this . txtIsoNo . Text . Trim ( ) ) ) ;
}
SqlParameter [ ] parameter = listStr . ToArray ( ) ;
DataTable tb = SQLHelper . GetDataTableRunText ( strSql , parameter ) ;
// 2.获取当前分页数据
//var table = this.GetPagedDataTable(Grid1, tb1);
Grid1 . RecordCount = tb . Rows . Count ;
//tb = GetFilteredTable(Grid1.FilteredData, tb);
var table = this . GetPagedDataTable ( Grid1 , tb ) ;
Grid1 . DataSource = table ;
Grid1 . DataBind ( ) ;
}
}
}
/// <summary>
/// 查询
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void TextBox_TextChanged ( object sender , EventArgs e )
{
this . BindGrid ( ) ;
}
#region 加 载 页 面 输 入 提 交 信 息
/// <summary>
/// 加载页面输入提交信息
/// </summary>
private void PageInfoLoad ( )
{
2024-06-21 16:37:50 +08:00
var trust = Funs . DB . PMI_Delegation . FirstOrDefault ( t = > t . Id = = this . PMIDelegationId ) ;
2024-05-11 15:22:08 +08:00
if ( trust ! = null )
{
this . txtDelegationNo . Text = trust . DelegationNo ;
if ( trust . DelegationDate . HasValue )
{
this . txtDelegationDate . Text = string . Format ( "{0:yyyy-MM-dd}" , trust . DelegationDate ) ;
}
if ( ! string . IsNullOrEmpty ( trust . InstallationId ) )
{
this . txtInstallationName . Text = BLL . Project_InstallationService . GetProject_InstallationNameByInstallationId ( trust . InstallationId ) ;
}
if ( ! string . IsNullOrEmpty ( trust . UnitId ) )
{
this . txtUnitName . Text = BLL . Base_UnitService . GetUnitNameByUnitId ( trust . UnitId ) ;
}
this . txtDetectionMethod . Text = "PMI光谱分析" ;
this . txtDetectionStandard . Text = trust . DetectionStandard ;
if ( ! string . IsNullOrEmpty ( trust . Tabler ) )
{
this . txtTabler . Text = BLL . Sys_UserService . GetUserNameByUserId ( trust . Tabler ) ;
}
this . txtRemark . Text = trust . Remark ;
}
}
#endregion
#region 清 空 文 本
/// <summary>
/// 清空文本
/// </summary>
private void SetTextTemp ( )
{
this . txtDelegationNo . Text = string . Empty ;
this . txtDelegationDate . Text = string . Empty ;
this . txtInstallationName . Text = string . Empty ;
this . txtUnitName . Text = string . Empty ;
this . txtDetectionMethod . Text = string . Empty ;
this . txtDetectionStandard . Text = string . Empty ;
this . txtTabler . Text = string . Empty ;
this . txtRemark . Text = string . Empty ;
}
#endregion
#endregion
#region 分 页 排 序
#region 页 索 引 改 变 事 件
/// <summary>
/// 页索引改变事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_PageIndexChange ( object sender , GridPageEventArgs e )
{
BindGrid ( ) ;
}
#endregion
#region 排 序
/// <summary>
/// 排序
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_Sort ( object sender , GridSortEventArgs e )
{
BindGrid ( ) ;
}
#endregion
#region 分 页 选 择 下 拉 改 变 事 件
/// <summary>
/// 分页选择下拉改变事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void ddlPageSize_SelectedIndexChanged ( object sender , EventArgs e )
{
Grid1 . PageSize = Convert . ToInt32 ( ddlPageSize . SelectedValue ) ;
BindGrid ( ) ;
}
#endregion
#endregion
#region PMI委托 维 护 事 件
/// <summary>
/// 增加PMI委托
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnNew_Click ( object sender , EventArgs e )
{
2024-06-11 17:27:06 +08:00
if ( CommonService . GetAllButtonPowerList ( this . CurrUser . LoginProjectId , this . CurrUser . UserId , Const . PMIDelegationMenuId , Const . BtnAdd ) )
2024-05-11 15:22:08 +08:00
{
this . SetTextTemp ( ) ;
2024-06-21 16:37:50 +08:00
string window = String . Format ( "PMIDelegationEdit.aspx?PMIDelegationId={0}" , string . Empty , "新增 - " ) ;
2024-05-12 15:49:21 +08:00
PageContext . RegisterStartupScript ( Window2 . GetSaveStateReference ( this . hdPMIDelegationId . ClientID )
2024-05-12 15:28:06 +08:00
+ Window2 . GetShowReference ( window ) ) ;
2024-05-11 15:22:08 +08:00
}
else
{
ShowNotify ( Resources . Lan . NoPrivilegePrompt , MessageBoxIcon . Warning ) ;
}
}
#region 编 辑 PMI委托
/// <summary>
/// 编辑PMI委托
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnEdit_Click ( object sender , EventArgs e )
{
if ( CommonService . GetAllButtonPowerList ( this . CurrUser . LoginProjectId , this . CurrUser . UserId , Const . HotProessTrustMenuId , Const . BtnSave ) )
{
2024-06-21 16:37:50 +08:00
var trustManage = Funs . DB . PMI_Delegation . FirstOrDefault ( t = > t . Id = = this . PMIDelegationId ) ;
2024-05-11 15:22:08 +08:00
if ( trustManage ! = null )
{
2024-05-12 15:49:21 +08:00
string openUrl = String . Format ( "PMIDelegationEdit.aspx?PMIDelegationId={0}" , this . PMIDelegationId , "编辑 - " ) ;
PageContext . RegisterStartupScript ( Window2 . GetSaveStateReference ( this . hdPMIDelegationId . ClientID )
+ Window2 . GetShowReference ( openUrl ) ) ;
2024-05-11 15:22:08 +08:00
}
else
{
2024-05-12 22:53:47 +08:00
ShowNotify ( "请选择要处理的PMI委托" , MessageBoxIcon . Warning ) ;
2024-05-11 15:22:08 +08:00
}
}
else
{
ShowNotify ( Resources . Lan . NoPrivilegePrompt , MessageBoxIcon . Warning ) ;
}
}
#endregion
#region 删 除 PMI委托
/// <summary>
/// 删除PMI委托
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnDelete_Click ( object sender , EventArgs e )
{
2024-06-11 17:27:06 +08:00
if ( CommonService . GetAllButtonPowerList ( this . CurrUser . LoginProjectId , this . CurrUser . UserId , Const . PMIDelegationMenuId , Const . BtnDelete ) )
2024-05-11 15:22:08 +08:00
{
2024-06-21 16:37:50 +08:00
var trustManage = Funs . DB . PMI_Delegation . FirstOrDefault ( t = > t . Id = = this . PMIDelegationId ) ;
2024-05-11 15:22:08 +08:00
if ( trustManage ! = null )
2024-06-21 16:37:50 +08:00
{
2024-05-11 15:22:08 +08:00
//删除主表数据
Funs . DB . PMI_Delegation . DeleteOnSubmit ( trustManage ) ;
//删除 明细表
2024-05-12 22:53:47 +08:00
var details = Funs . DB . PMI_DelegationDetails . Where ( t = > t . PMIId = = trustManage . Id ) . ToList ( ) ;
Funs . DB . PMI_DelegationDetails . DeleteAllOnSubmit ( details ) ;
2024-05-11 15:22:08 +08:00
Funs . DB . SubmitChanges ( ) ;
Alert . ShowInTop ( Resources . Lan . DeletedSuccessfully , MessageBoxIcon . Success ) ;
this . InitTreeMenu ( ) ;
SetTextTemp ( ) ;
this . Grid1 . DataSource = null ;
this . Grid1 . DataBind ( ) ;
}
else
{
ShowNotify ( Resources . Lan . PleaseSelectDeleteHotProessTrust , MessageBoxIcon . Warning ) ;
}
}
else
{
ShowNotify ( Resources . Lan . NoPrivilegePrompt , MessageBoxIcon . Warning ) ;
return ;
}
}
#endregion
#endregion
#region 关 闭 弹 出 窗 口 及 刷 新 页 面
/// <summary>
/// 关闭弹出窗口
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
2024-05-12 15:49:21 +08:00
protected void Window2_Close ( object sender , WindowCloseEventArgs e )
2024-05-11 15:22:08 +08:00
{
this . InitTreeMenu ( ) ;
this . BindGrid ( ) ;
2024-06-21 16:37:50 +08:00
2024-05-11 15:22:08 +08:00
}
#region 查 询
/// <summary>
/// 查询
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Tree_TextChanged ( object sender , EventArgs e )
{
this . InitTreeMenu ( ) ;
}
#endregion
#endregion
2024-06-21 16:37:50 +08:00
#region 获 取 按 钮 权 限
/// <summary>
/// 获取按钮权限
/// </summary>
/// <param name="button"></param>
/// <returns></returns>
private bool GetButtonPower ( string button )
2024-06-20 17:12:59 +08:00
{
2024-06-21 16:37:50 +08:00
return BLL . CommonService . GetAllButtonPowerList ( this . CurrUser . LoginProjectId , this . CurrUser . UserId , BLL . Const . DailyReportCompleteMenuId , button ) ;
2024-06-20 17:12:59 +08:00
}
2024-06-21 16:37:50 +08:00
#endregion
2024-06-20 17:12:59 +08:00
/// <summary>
2024-06-21 16:37:50 +08:00
/// 打印
2024-06-20 17:12:59 +08:00
/// </summary>
2024-06-21 16:37:50 +08:00
protected void btnExport_Click ( object sender , EventArgs e )
2024-06-20 17:12:59 +08:00
{
2024-06-21 16:37:50 +08:00
if ( string . IsNullOrWhiteSpace ( this . tvControlItem . SelectedNodeID ) )
{
Alert . ShowInTop ( "请选择委托单!" , MessageBoxIcon . Warning ) ;
return ;
}
string rootPath = Server . MapPath ( "~/" ) + Const . ExcelUrl ;
//导出文件
string filePath = rootPath + DateTime . Now . ToString ( "yyyyMMddhhmmss" ) + "\\" ;
if ( ! Directory . Exists ( filePath ) )
{
Directory . CreateDirectory ( filePath ) ;
}
string ReportFileName = filePath + "out.xlsx" ;
int rowIndex = 0 ;
XSSFWorkbook hssfworkbook = new XSSFWorkbook ( ) ;
XSSFSheet ws = ( XSSFSheet ) hssfworkbook . CreateSheet ( "无损检测委托单(PMI)" ) ;
#region 列 宽
ws . SetColumnWidth ( 0 , 6 * 256 ) ;
ws . SetColumnWidth ( 1 , 4 * 256 ) ;
ws . SetColumnWidth ( 2 , 6 * 256 ) ;
ws . SetColumnWidth ( 3 , 6 * 256 ) ;
ws . SetColumnWidth ( 4 , 6 * 256 ) ;
ws . SetColumnWidth ( 5 , 6 * 256 ) ;
ws . SetColumnWidth ( 6 , 9 * 256 ) ;
ws . SetColumnWidth ( 7 , 9 * 256 ) ;
ws . SetColumnWidth ( 8 , 5 * 256 ) ;
ws . SetColumnWidth ( 9 , 5 * 256 ) ;
ws . SetColumnWidth ( 10 , 5 * 256 ) ;
ws . SetColumnWidth ( 11 , 8 * 256 ) ;
ws . SetColumnWidth ( 12 , 9 * 256 ) ;
ws . SetColumnWidth ( 13 , 11 * 256 ) ;
#endregion
string pmiId = this . tvControlItem . SelectedNodeID ;
//头部
var pmititle = Funs . DB . PMI_Delegation . FirstOrDefault ( x = > x . Id = = pmiId ) ;
//列表
List < SqlParameter > listStr = new List < SqlParameter > ( ) ;
listStr . Add ( new SqlParameter ( "@ProjectId" , pmititle ! = null ? pmititle . ProjectId : this . CurrUser . LoginProjectId ) ) ;
listStr . Add ( new SqlParameter ( "@PMIID" , this . PMIDelegationId ) ) ;
SqlParameter [ ] parameter = listStr . ToArray ( ) ;
var tb = SQLHelper . GetDataTableRunText ( "SELECT * FROM View_PMI_DelegationDetails WHERE ProjectId=@ProjectId AND PMIID=@PMIID" , parameter ) ;
//模拟多页数据sql
//var tb = SQLHelper.GetDataTableRunText("SELECT * FROM View_PMI_DelegationDetails WHERE ProjectId=@ProjectId AND PMIID=@PMIID union all SELECT * FROM View_PMI_DelegationDetails WHERE ProjectId=@ProjectId AND PMIID=@PMIID union all SELECT * FROM View_PMI_DelegationDetails WHERE ProjectId=@ProjectId AND PMIID=@PMIID union all SELECT * FROM View_PMI_DelegationDetails WHERE ProjectId=@ProjectId AND PMIID=@PMIID union all SELECT * FROM View_PMI_DelegationDetails WHERE ProjectId=@ProjectId AND PMIID=@PMIID union all SELECT * FROM View_PMI_DelegationDetails WHERE ProjectId=@ProjectId AND PMIID=@PMIID union all SELECT * FROM View_PMI_DelegationDetails WHERE ProjectId=@ProjectId AND PMIID=@PMIID union all SELECT * FROM View_PMI_DelegationDetails WHERE ProjectId=@ProjectId AND PMIID=@PMIID union all SELECT * FROM View_PMI_DelegationDetails WHERE ProjectId=@ProjectId AND PMIID=@PMIID union all SELECT * FROM View_PMI_DelegationDetails WHERE ProjectId=@ProjectId AND PMIID=@PMIID union all SELECT * FROM View_PMI_DelegationDetails WHERE ProjectId=@ProjectId AND PMIID=@PMIID union all SELECT * FROM View_PMI_DelegationDetails WHERE ProjectId=@ProjectId AND PMIID=@PMIID union all SELECT * FROM View_PMI_DelegationDetails WHERE ProjectId=@ProjectId AND PMIID=@PMIID union all SELECT * FROM View_PMI_DelegationDetails WHERE ProjectId=@ProjectId AND PMIID=@PMIID union all SELECT * FROM View_PMI_DelegationDetails WHERE ProjectId=@ProjectId AND PMIID=@PMIID union all SELECT * FROM View_PMI_DelegationDetails WHERE ProjectId=@ProjectId AND PMIID=@PMIID union all SELECT * FROM View_PMI_DelegationDetails WHERE ProjectId=@ProjectId AND PMIID=@PMIID union all SELECT * FROM View_PMI_DelegationDetails WHERE ProjectId=@ProjectId AND PMIID=@PMIID union all SELECT * FROM View_PMI_DelegationDetails WHERE ProjectId=@ProjectId AND PMIID=@PMIID union all SELECT * FROM View_PMI_DelegationDetails WHERE ProjectId=@ProjectId AND PMIID=@PMIID union all SELECT * FROM View_PMI_DelegationDetails WHERE ProjectId=@ProjectId AND PMIID=@PMIID union all SELECT * FROM View_PMI_DelegationDetails WHERE ProjectId=@ProjectId AND PMIID=@PMIID union all SELECT * FROM View_PMI_DelegationDetails WHERE ProjectId=@ProjectId AND PMIID=@PMIID union all SELECT * FROM View_PMI_DelegationDetails WHERE ProjectId=@ProjectId AND PMIID=@PMIID union all SELECT * FROM View_PMI_DelegationDetails WHERE ProjectId=@ProjectId AND PMIID=@PMIID", parameter);
var style = CommonPrint . SetExcelStyle ( hssfworkbook , BorderStyle . Thin , BorderStyle . Thin , BorderStyle . Thin , BorderStyle . Thin , VerticalAlignment . Center , HorizontalAlignment . Center , 10 , true , false ) ;
var styleButton = CommonPrint . SetExcelStyle ( hssfworkbook , BorderStyle . None , BorderStyle . Thin , BorderStyle . Thin , BorderStyle . Thin , VerticalAlignment . Center , HorizontalAlignment . Center , 10 , true , false ) ;
var styleTop = CommonPrint . SetExcelStyle ( hssfworkbook , BorderStyle . Thin , BorderStyle . Thin , BorderStyle . Thin , BorderStyle . None , VerticalAlignment . Center , HorizontalAlignment . Center , 10 , true , false ) ;
var styleNone = CommonPrint . SetExcelStyle ( hssfworkbook , BorderStyle . None , BorderStyle . Thin , BorderStyle . Thin , BorderStyle . None , VerticalAlignment . Center , HorizontalAlignment . Center , 10 , true , false ) ;
if ( tb . Rows . Count > 0 & & pmititle ! = null )
{
var tbNum = tb . Rows . Count ;
var pageNum =
tbNum < 15 ? 1
: Math . Ceiling ( ( float ) ( tbNum - 14 ) / 14 ) + 1 ;
//循环页
for ( int i = 1 ; i < = pageNum ; i + + )
{
#region 头 部
ws = WsExcelCreateRow ( ws , hssfworkbook , rowIndex , rowIndex + 12 , style , 0 , 13 , 1 ) ;
//行0
CellRangeAddress region = new CellRangeAddress ( rowIndex , rowIndex + 3 , 0 , 3 ) ;
ws . AddMergedRegion ( region ) ;
ws . GetRow ( rowIndex ) . GetCell ( 0 ) . SetCellValue ( "NDE-002" ) ;
ws . GetRow ( rowIndex ) . GetCell ( 0 ) . CellStyle = style ;
ws . GetRow ( rowIndex ) . GetCell ( 1 ) . CellStyle = style ;
ws . GetRow ( rowIndex ) . GetCell ( 2 ) . CellStyle = style ;
ws . GetRow ( rowIndex ) . GetCell ( 3 ) . CellStyle = style ;
region = new CellRangeAddress ( rowIndex , rowIndex + 3 , 4 , 10 ) ;
ws . AddMergedRegion ( region ) ;
ws . GetRow ( rowIndex ) . GetCell ( 4 ) . SetCellValue ( "无损检测委托单\r\nPMI" ) ;
ws . GetRow ( rowIndex ) . GetCell ( 4 ) . CellStyle = CommonPrint . SetExcelStyle ( hssfworkbook , BorderStyle . Thin , BorderStyle . Thin , BorderStyle . Thin , BorderStyle . Thin , VerticalAlignment . Center , HorizontalAlignment . Center , 16 , true , true ) ;
ws . GetRow ( rowIndex ) . GetCell ( 5 ) . CellStyle = style ;
ws . GetRow ( rowIndex ) . GetCell ( 6 ) . CellStyle = style ;
ws . GetRow ( rowIndex ) . GetCell ( 7 ) . CellStyle = style ;
ws . GetRow ( rowIndex ) . GetCell ( 8 ) . CellStyle = style ;
ws . GetRow ( rowIndex ) . GetCell ( 9 ) . CellStyle = style ;
ws . GetRow ( rowIndex ) . GetCell ( 10 ) . CellStyle = style ;
region = new CellRangeAddress ( rowIndex , rowIndex , 11 , 13 ) ;
ws . AddMergedRegion ( region ) ;
ws . GetRow ( rowIndex ) . GetCell ( 11 ) . SetCellValue ( "工程名称:巴斯夫(广东)一体化项目专用化学品二区" ) ;
ws . GetRow ( rowIndex ) . GetCell ( 11 ) . CellStyle = CommonPrint . SetExcelStyle ( hssfworkbook , BorderStyle . None , BorderStyle . Thin , BorderStyle . Thin , BorderStyle . Thin , VerticalAlignment . Center , HorizontalAlignment . Justify , 10.5 , true , false ) ;
ws . GetRow ( rowIndex ) . GetCell ( 12 ) . CellStyle = styleButton ;
ws . GetRow ( rowIndex ) . GetCell ( 13 ) . CellStyle = styleButton ;
//行1
region = new CellRangeAddress ( rowIndex + 1 , rowIndex + 1 , 11 , 13 ) ;
ws . AddMergedRegion ( region ) ;
ws . GetRow ( rowIndex + 1 ) . GetCell ( 11 ) . SetCellValue ( "BASF (Guangdong) Integrated Project Citral Cluster" ) ;
ws . GetRow ( rowIndex + 1 ) . GetCell ( 11 ) . CellStyle = CommonPrint . SetExcelStyle ( hssfworkbook , BorderStyle . None , BorderStyle . Thin , BorderStyle . Thin , BorderStyle . None , VerticalAlignment . Center , HorizontalAlignment . Justify , 10.5 , true , false ) ;
ws . GetRow ( rowIndex + 1 ) . GetCell ( 12 ) . CellStyle = styleNone ;
ws . GetRow ( rowIndex + 1 ) . GetCell ( 13 ) . CellStyle = styleNone ;
//行2
region = new CellRangeAddress ( rowIndex + 2 , rowIndex + 2 , 11 , 13 ) ;
ws . AddMergedRegion ( region ) ;
ws . GetRow ( rowIndex + 2 ) . GetCell ( 11 ) . SetCellValue ( "单元名称:" ) ;
ws . GetRow ( rowIndex + 2 ) . GetCell ( 11 ) . CellStyle = CommonPrint . SetExcelStyle ( hssfworkbook , BorderStyle . None , BorderStyle . Thin , BorderStyle . Thin , BorderStyle . None , VerticalAlignment . Center , HorizontalAlignment . Justify , 10.5 , true , false ) ;
ws . GetRow ( rowIndex + 2 ) . GetCell ( 12 ) . CellStyle = styleNone ;
ws . GetRow ( rowIndex + 2 ) . GetCell ( 13 ) . CellStyle = styleNone ;
//行3
region = new CellRangeAddress ( rowIndex + 3 , rowIndex + 3 , 11 , 13 ) ;
ws . AddMergedRegion ( region ) ;
ws . GetRow ( rowIndex + 3 ) . GetCell ( 11 ) . SetCellValue ( "Unit Name:" ) ;
ws . GetRow ( rowIndex + 3 ) . GetCell ( 11 ) . CellStyle = CommonPrint . SetExcelStyle ( hssfworkbook , BorderStyle . Thin , BorderStyle . Thin , BorderStyle . Thin , BorderStyle . None , VerticalAlignment . Center , HorizontalAlignment . Justify , 10.5 , true , false ) ;
ws . GetRow ( rowIndex + 3 ) . GetCell ( 12 ) . CellStyle = styleTop ;
ws . GetRow ( rowIndex + 3 ) . GetCell ( 13 ) . CellStyle = styleTop ;
//行4
region = new CellRangeAddress ( rowIndex + 4 , rowIndex + 4 , 0 , 1 ) ;
ws . AddMergedRegion ( region ) ;
ws . GetRow ( rowIndex + 4 ) . GetCell ( 0 ) . SetCellValue ( "委托单位" ) ;
region = new CellRangeAddress ( rowIndex + 4 , rowIndex + 4 , 2 , 6 ) ;
ws . AddMergedRegion ( region ) ;
ws . GetRow ( rowIndex + 4 ) . GetCell ( 2 ) . SetCellValue ( "" ) ;
region = new CellRangeAddress ( rowIndex + 4 , rowIndex + 4 , 7 , 8 ) ;
ws . AddMergedRegion ( region ) ;
ws . GetRow ( rowIndex + 4 ) . GetCell ( 7 ) . SetCellValue ( "委托编号" ) ;
region = new CellRangeAddress ( rowIndex + 4 , rowIndex + 4 , 9 , 13 ) ;
ws . AddMergedRegion ( region ) ;
ws . GetRow ( rowIndex + 4 ) . GetCell ( 9 ) . SetCellValue ( "" ) ;
//行5
region = new CellRangeAddress ( rowIndex + 5 , rowIndex + 5 , 0 , 1 ) ;
ws . AddMergedRegion ( region ) ;
ws . GetRow ( rowIndex + 5 ) . GetCell ( 0 ) . SetCellValue ( "检测单位" ) ;
region = new CellRangeAddress ( rowIndex + 5 , rowIndex + 5 , 2 , 6 ) ;
ws . AddMergedRegion ( region ) ;
ws . GetRow ( rowIndex + 5 ) . GetCell ( 2 ) . SetCellValue ( "" ) ;
region = new CellRangeAddress ( rowIndex + 5 , rowIndex + 5 , 7 , 8 ) ;
ws . AddMergedRegion ( region ) ;
ws . GetRow ( rowIndex + 5 ) . GetCell ( 7 ) . SetCellValue ( "检测方法" ) ;
region = new CellRangeAddress ( rowIndex + 5 , rowIndex + 5 , 9 , 13 ) ;
ws . AddMergedRegion ( region ) ;
ws . GetRow ( rowIndex + 5 ) . GetCell ( 9 ) . SetCellValue ( "" ) ;
//行6
region = new CellRangeAddress ( rowIndex + 6 , rowIndex + 6 , 0 , 1 ) ;
ws . AddMergedRegion ( region ) ;
ws . GetRow ( rowIndex + 6 ) . GetCell ( 0 ) . SetCellValue ( "检件名称" ) ;
region = new CellRangeAddress ( rowIndex + 6 , rowIndex + 6 , 2 , 6 ) ;
ws . AddMergedRegion ( region ) ;
ws . GetRow ( rowIndex + 6 ) . GetCell ( 2 ) . SetCellValue ( "" ) ;
region = new CellRangeAddress ( rowIndex + 6 , rowIndex + 6 , 7 , 8 ) ;
ws . AddMergedRegion ( region ) ;
ws . GetRow ( rowIndex + 6 ) . GetCell ( 7 ) . SetCellValue ( "表面状态" ) ;
region = new CellRangeAddress ( rowIndex + 6 , rowIndex + 6 , 9 , 13 ) ;
ws . AddMergedRegion ( region ) ;
ws . GetRow ( rowIndex + 6 ) . GetCell ( 9 ) . SetCellValue ( "" ) ;
//行7
region = new CellRangeAddress ( rowIndex + 7 , rowIndex + 7 , 0 , 1 ) ;
ws . AddMergedRegion ( region ) ;
ws . GetRow ( rowIndex + 7 ) . GetCell ( 0 ) . SetCellValue ( "检测标准" ) ;
region = new CellRangeAddress ( rowIndex + 7 , rowIndex + 7 , 2 , 6 ) ;
ws . AddMergedRegion ( region ) ;
ws . GetRow ( rowIndex + 7 ) . GetCell ( 2 ) . SetCellValue ( "" ) ;
region = new CellRangeAddress ( rowIndex + 7 , rowIndex + 7 , 7 , 8 ) ;
ws . AddMergedRegion ( region ) ;
ws . GetRow ( rowIndex + 7 ) . GetCell ( 7 ) . SetCellValue ( "检测比例" ) ;
region = new CellRangeAddress ( rowIndex + 7 , rowIndex + 7 , 9 , 13 ) ;
ws . AddMergedRegion ( region ) ;
ws . GetRow ( rowIndex + 7 ) . GetCell ( 9 ) . SetCellValue ( "" ) ;
//行8
region = new CellRangeAddress ( rowIndex + 8 , rowIndex + 8 , 0 , 1 ) ;
ws . AddMergedRegion ( region ) ;
ws . GetRow ( rowIndex + 8 ) . GetCell ( 0 ) . SetCellValue ( "转动口/固定口" ) ;
region = new CellRangeAddress ( rowIndex + 8 , rowIndex + 8 , 2 , 6 ) ;
ws . AddMergedRegion ( region ) ;
ws . GetRow ( rowIndex + 8 ) . GetCell ( 2 ) . SetCellValue ( "" ) ;
region = new CellRangeAddress ( rowIndex + 8 , rowIndex + 8 , 7 , 8 ) ;
ws . AddMergedRegion ( region ) ;
ws . GetRow ( rowIndex + 8 ) . GetCell ( 7 ) . SetCellValue ( "委托日期" ) ;
region = new CellRangeAddress ( rowIndex + 8 , rowIndex + 8 , 9 , 13 ) ;
ws . AddMergedRegion ( region ) ;
ws . GetRow ( rowIndex + 8 ) . GetCell ( 9 ) . SetCellValue ( "" ) ;
//行9
region = new CellRangeAddress ( rowIndex + 9 , rowIndex + 9 , 0 , 1 ) ;
ws . AddMergedRegion ( region ) ;
ws . GetRow ( rowIndex + 9 ) . GetCell ( 0 ) . SetCellValue ( "焊接方法" ) ;
region = new CellRangeAddress ( rowIndex + 9 , rowIndex + 9 , 2 , 6 ) ;
ws . AddMergedRegion ( region ) ;
ws . GetRow ( rowIndex + 9 ) . GetCell ( 2 ) . SetCellValue ( "" ) ;
region = new CellRangeAddress ( rowIndex + 9 , rowIndex + 9 , 7 , 8 ) ;
ws . AddMergedRegion ( region ) ;
ws . GetRow ( rowIndex + 9 ) . GetCell ( 7 ) . SetCellValue ( "压力管道分级" ) ;
region = new CellRangeAddress ( rowIndex + 9 , rowIndex + 9 , 9 , 13 ) ;
ws . AddMergedRegion ( region ) ;
ws . GetRow ( rowIndex + 9 ) . GetCell ( 9 ) . SetCellValue ( "" ) ;
//行10
region = new CellRangeAddress ( rowIndex + 10 , rowIndex + 10 , 0 , 1 ) ;
ws . AddMergedRegion ( region ) ;
ws . GetRow ( rowIndex + 10 ) . GetCell ( 0 ) . SetCellValue ( "检测时机" ) ;
region = new CellRangeAddress ( rowIndex + 10 , rowIndex + 10 , 2 , 6 ) ;
ws . AddMergedRegion ( region ) ;
ws . GetRow ( rowIndex + 10 ) . GetCell ( 2 ) . SetCellValue ( "" ) ;
region = new CellRangeAddress ( rowIndex + 10 , rowIndex + 10 , 7 , 8 ) ;
ws . AddMergedRegion ( region ) ;
ws . GetRow ( rowIndex + 10 ) . GetCell ( 7 ) . SetCellValue ( "被检产品标准" ) ;
region = new CellRangeAddress ( rowIndex + 10 , rowIndex + 10 , 9 , 13 ) ;
ws . AddMergedRegion ( region ) ;
ws . GetRow ( rowIndex + 10 ) . GetCell ( 9 ) . SetCellValue ( "" ) ;
//行12
region = new CellRangeAddress ( rowIndex + 11 , rowIndex + 11 , 0 , 2 ) ;
ws . AddMergedRegion ( region ) ;
ws . GetRow ( rowIndex + 11 ) . GetCell ( 0 ) . SetCellValue ( "检件编号/管线号" ) ;
region = new CellRangeAddress ( rowIndex + 11 , rowIndex + 11 , 3 , 4 ) ;
ws . AddMergedRegion ( region ) ;
ws . GetRow ( rowIndex + 11 ) . GetCell ( 3 ) . SetCellValue ( "" ) ;
region = new CellRangeAddress ( rowIndex + 11 , rowIndex + 11 , 5 , 6 ) ;
ws . AddMergedRegion ( region ) ;
ws . GetRow ( rowIndex + 11 ) . GetCell ( 5 ) . SetCellValue ( "焊口总数" ) ;
region = new CellRangeAddress ( rowIndex + 11 , rowIndex + 11 , 7 , 9 ) ;
ws . AddMergedRegion ( region ) ;
ws . GetRow ( rowIndex + 11 ) . GetCell ( 7 ) . SetCellValue ( "" ) ;
region = new CellRangeAddress ( rowIndex + 11 , rowIndex + 11 , 10 , 11 ) ;
ws . AddMergedRegion ( region ) ;
ws . GetRow ( rowIndex + 11 ) . GetCell ( 10 ) . SetCellValue ( "抽检数量" ) ;
region = new CellRangeAddress ( rowIndex + 11 , rowIndex + 11 , 12 , 13 ) ;
ws . AddMergedRegion ( region ) ;
ws . GetRow ( rowIndex + 11 ) . GetCell ( 12 ) . SetCellValue ( "" ) ;
//行13
ws . GetRow ( rowIndex + 12 ) . GetCell ( 0 ) . SetCellValue ( "检测\r\n部位" ) ;
region = new CellRangeAddress ( rowIndex + 12 , rowIndex + 12 , 1 , 3 ) ;
ws . AddMergedRegion ( region ) ;
ws . GetRow ( rowIndex + 12 ) . GetCell ( 1 ) . SetCellValue ( "检件编号/管线号" ) ;
ws . GetRow ( rowIndex + 12 ) . GetCell ( 4 ) . SetCellValue ( "焊口号" ) ;
region = new CellRangeAddress ( rowIndex + 12 , rowIndex + 12 , 5 , 6 ) ;
ws . AddMergedRegion ( region ) ;
ws . GetRow ( rowIndex + 12 ) . GetCell ( 5 ) . SetCellValue ( "焊工代号" ) ;
region = new CellRangeAddress ( rowIndex + 12 , rowIndex + 12 , 7 , 10 ) ;
ws . AddMergedRegion ( region ) ;
ws . GetRow ( rowIndex + 12 ) . GetCell ( 7 ) . SetCellValue ( "检件材质" ) ;
region = new CellRangeAddress ( rowIndex + 12 , rowIndex + 12 , 11 , 12 ) ;
ws . AddMergedRegion ( region ) ;
ws . GetRow ( rowIndex + 12 ) . GetCell ( 11 ) . SetCellValue ( "检件规格(mm)" ) ;
ws . GetRow ( rowIndex + 12 ) . GetCell ( 13 ) . SetCellValue ( "备注" ) ;
#endregion
#region 表 格
ws = WsExcelCreateRow ( ws , hssfworkbook , rowIndex + 13 , rowIndex + 26 , style , 0 , 13 , 2 ) ;
var dataTit = rowIndex + 13 ;
var tIndex = 12 + 14 ;
var dStart = 0 ;
var dEnd = 0 ;
if ( i = = 1 )
{
dStart = 0 ;
dEnd = 14 ;
}
else
{
dStart = i = = 2 ? 14 : ( ( i - 2 ) * 14 ) + 14 ;
dEnd = ( ( i - 1 ) * 14 ) + 14 ;
}
//合并单元格
for ( int hb = dataTit ; hb < = rowIndex + tIndex ; hb + + )
{
region = new CellRangeAddress ( hb , hb , 1 , 3 ) ;
ws . AddMergedRegion ( region ) ;
region = new CellRangeAddress ( hb , hb , 5 , 6 ) ;
ws . AddMergedRegion ( region ) ;
region = new CellRangeAddress ( hb , hb , 7 , 10 ) ;
ws . AddMergedRegion ( region ) ;
region = new CellRangeAddress ( hb , hb , 11 , 12 ) ;
ws . AddMergedRegion ( region ) ;
}
//获取当前页数据
var pageTb = GetPageToTable ( tb , dStart , dEnd ) ;
for ( int j = 0 ; j < pageTb . Rows . Count ; j + + )
{
int dataIndex = dataTit + j ;
//检测部位
ws . GetRow ( dataIndex ) . GetCell ( 0 ) . SetCellValue ( "" ) ;
//检件编号/管线号
ws . GetRow ( dataIndex ) . GetCell ( 1 ) . SetCellValue ( "数据待绑定" ) ;
//焊口号
ws . GetRow ( dataIndex ) . GetCell ( 4 ) . SetCellValue ( "" ) ;
//焊工代号
ws . GetRow ( dataIndex ) . GetCell ( 5 ) . SetCellValue ( "" ) ;
//检件材质
ws . GetRow ( dataIndex ) . GetCell ( 7 ) . SetCellValue ( "" ) ;
//检件规格(mm)
ws . GetRow ( dataIndex ) . GetCell ( 11 ) . SetCellValue ( "" ) ;
//备注
ws . GetRow ( dataIndex ) . GetCell ( 13 ) . SetCellValue ( "" ) ;
}
if ( dataTit + pageTb . Rows . Count < 26 )
{
ws . GetRow ( dataTit + pageTb . Rows . Count ) . GetCell ( 0 ) . SetCellValue ( "以下空白" ) ;
}
rowIndex + = tIndex ;
#endregion
#region 尾 部
ws = WsExcelCreateRow ( ws , hssfworkbook , rowIndex + 1 , rowIndex + 9 , style , 0 , 13 , 3 ) ;
//合并单元格
for ( int hb = rowIndex + 1 ; hb < = rowIndex + 9 ; hb + + )
{
for ( int c = 0 ; c < = 13 ; c + + )
{
if ( hb > = rowIndex + 2 & & hb < = rowIndex + 3 )
{
ws . GetRow ( hb ) . GetCell ( c ) . CellStyle = CommonPrint . SetExcelStyle ( hssfworkbook , BorderStyle . None , BorderStyle . Thin , BorderStyle . Thin , BorderStyle . None , VerticalAlignment . Center , HorizontalAlignment . Left , 10.5 , true , false ) ;
}
if ( hb > = rowIndex + 4 & & hb < = rowIndex + 8 )
{
ws . GetRow ( hb ) . GetCell ( c ) . CellStyle = CommonPrint . SetExcelStyle ( hssfworkbook , BorderStyle . None , BorderStyle . Thin , BorderStyle . Thin , BorderStyle . None , VerticalAlignment . Center , HorizontalAlignment . Right , 10.5 , true , false ) ;
}
if ( hb = = rowIndex + 9 )
{
ws . GetRow ( hb ) . GetCell ( c ) . CellStyle = CommonPrint . SetExcelStyle ( hssfworkbook , BorderStyle . Thin , BorderStyle . Thin , BorderStyle . Thin , BorderStyle . None , VerticalAlignment . Center , HorizontalAlignment . Center , 10.5 , true , false ) ;
}
}
region = new CellRangeAddress ( hb , hb , 0 , 2 ) ;
ws . AddMergedRegion ( region ) ;
region = new CellRangeAddress ( hb , hb , 3 , 5 ) ;
ws . AddMergedRegion ( region ) ;
region = new CellRangeAddress ( hb , hb , 6 , 7 ) ;
ws . AddMergedRegion ( region ) ;
region = new CellRangeAddress ( hb , hb , 8 , 11 ) ;
ws . AddMergedRegion ( region ) ;
region = new CellRangeAddress ( hb , hb , 12 , 13 ) ;
ws . AddMergedRegion ( region ) ;
}
//尾部行1
ws . GetRow ( rowIndex + 1 ) . GetCell ( 0 ) . SetCellValue ( "施工单位" ) ;
ws . GetRow ( rowIndex + 1 ) . GetCell ( 3 ) . SetCellValue ( "监理单位" ) ;
ws . GetRow ( rowIndex + 1 ) . GetCell ( 6 ) . SetCellValue ( "管理公司" ) ;
ws . GetRow ( rowIndex + 1 ) . GetCell ( 8 ) . SetCellValue ( "建设单位" ) ;
ws . GetRow ( rowIndex + 1 ) . GetCell ( 12 ) . SetCellValue ( "检测单位" ) ;
//尾部行2
ws . GetRow ( rowIndex + 2 ) . GetCell ( 0 ) . SetCellValue ( "" ) ;
ws . GetRow ( rowIndex + 2 ) . GetCell ( 3 ) . SetCellValue ( "" ) ;
ws . GetRow ( rowIndex + 2 ) . GetCell ( 6 ) . SetCellValue ( "" ) ;
ws . GetRow ( rowIndex + 2 ) . GetCell ( 8 ) . SetCellValue ( "" ) ;
ws . GetRow ( rowIndex + 2 ) . GetCell ( 12 ) . SetCellValue ( "" ) ;
//尾部行3
ws . GetRow ( rowIndex + 3 ) . GetCell ( 0 ) . SetCellValue ( "质量检测员:" ) ;
ws . GetRow ( rowIndex + 3 ) . GetCell ( 3 ) . SetCellValue ( "专业工程师:" ) ;
ws . GetRow ( rowIndex + 3 ) . GetCell ( 6 ) . SetCellValue ( "专业/质量工程师:" ) ;
ws . GetRow ( rowIndex + 3 ) . GetCell ( 8 ) . SetCellValue ( "业主代表:" ) ;
ws . GetRow ( rowIndex + 3 ) . GetCell ( 12 ) . SetCellValue ( "接收人:" ) ;
//尾部行6
ws . GetRow ( rowIndex + 6 ) . GetCell ( 0 ) . SetCellValue ( "专业工程师:" ) ;
//尾部行8
ws . GetRow ( rowIndex + 8 ) . GetCell ( 0 ) . SetCellValue ( " 年 月 日" ) ;
ws . GetRow ( rowIndex + 8 ) . GetCell ( 3 ) . SetCellValue ( " 年 月 日" ) ;
ws . GetRow ( rowIndex + 8 ) . GetCell ( 6 ) . SetCellValue ( " 年 月 日" ) ;
ws . GetRow ( rowIndex + 8 ) . GetCell ( 8 ) . SetCellValue ( " 年 月 日" ) ;
ws . GetRow ( rowIndex + 8 ) . GetCell ( 12 ) . SetCellValue ( " 年 月 日" ) ;
#endregion
ws = WsExcelCreateRow ( ws , hssfworkbook , rowIndex + 10 , rowIndex + 10 , style , 0 , 13 , 3 , true ) ;
rowIndex + = 11 ;
}
}
ws . SetMargin ( MarginType . LeftMargin , 0.3 ) ;
ws . SetMargin ( MarginType . RightMargin , 0.2 ) ;
ws . SetMargin ( MarginType . BottomMargin , 0.4 ) ;
ws . PrintSetup . Landscape = false ;
ws . PrintSetup . PaperSize = 9 ;
ws . ForceFormulaRecalculation = true ;
using ( FileStream filess = System . IO . File . OpenWrite ( ReportFileName ) )
{
hssfworkbook . Write ( filess ) ;
}
FileInfo filet = new FileInfo ( ReportFileName ) ;
Response . Clear ( ) ;
Response . Charset = "GB2312" ;
Response . ContentEncoding = System . Text . Encoding . UTF8 ;
// 添加头信息,为"文件下载/另存为"对话框指定默认文件名
Response . AddHeader ( "Content-Disposition" , "attachment; filename=" + Server . UrlEncode ( "无损检测委托单(PMI).xlsx" ) ) ;
// 添加头信息,指定文件大小,让浏览器能够显示下载进度
Response . AddHeader ( "Content-Length" , filet . Length . ToString ( ) ) ;
// 指定返回的是一个不能被客户端读取的流,必须被下载
Response . ContentType = "application/ms-excel" ;
// 把文件流发送到客户端
Response . WriteFile ( filet . FullName ) ;
// 停止页面的执行
Response . End ( ) ;
2024-06-20 17:12:59 +08:00
}
2024-10-22 21:13:56 +08:00
#region 模 板 下 载
/// <summary>
/// 模板下载
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnDownLoad_Click ( object sender , EventArgs e )
{
string rootPath = Server . MapPath ( "~/" ) ;
string uploadfilepath = rootPath + Const . HJGL_PMITemplateUrl ;
string filePath = Const . HJGL_PMITemplateUrl ;
string fileName = Path . GetFileName ( filePath ) ;
FileInfo info = new FileInfo ( uploadfilepath ) ;
long fileSize = info . Length ;
Response . ClearContent ( ) ;
Response . AddHeader ( "Content-Disposition" , "attachment;filename=" + System . Web . HttpUtility . UrlEncode ( fileName , System . Text . Encoding . UTF8 ) ) ;
Response . ContentType = "excel/plain" ;
Response . ContentEncoding = System . Text . Encoding . UTF8 ;
Response . AddHeader ( "Content-Length" , fileSize . ToString ( ) . Trim ( ) ) ;
Response . TransmitFile ( uploadfilepath , 0 , fileSize ) ;
Response . End ( ) ;
//PageContext.RegisterStartupScript(Confirm.GetShowReference("确定要下载焊工信息导入模板?", String.Empty, MessageBoxIcon.Question, PageManager1.GetCustomEventReference(false, "Confirm_OK"), PageManager1.GetCustomEventReference("Confirm_Cancel")));
}
#endregion
protected void btnImport_Click ( object sender , EventArgs e )
{
string message = string . Empty ;
errorInfos = string . Empty ;
try
{
if ( this . fileUpload . HasFile = = false )
{
ShowNotify ( "请选择Excel文件!" , MessageBoxIcon . Warning ) ;
return ;
}
string IsXls = Path . GetExtension ( this . fileUpload . FileName ) . ToString ( ) . Trim ( ) . ToLower ( ) ;
if ( IsXls ! = ".xls" & & IsXls ! = ".xlsx" )
{
ShowNotify ( "只能选择Excel文件!" , MessageBoxIcon . Warning ) ;
return ;
}
string rootPath = Server . MapPath ( "~/" ) ;
string initFullPath = rootPath + initPath ;
if ( ! Directory . Exists ( initFullPath ) )
{
Directory . CreateDirectory ( initFullPath ) ;
}
//指定上传文件名称
this . hidFileName . Text = BLL . Funs . GetNewFileName ( ) + IsXls ;
//上传文件路径
string filePath = initFullPath + this . hidFileName . Text ;
//文件上传服务器
this . fileUpload . PostedFile . SaveAs ( filePath ) ;
//文件上传服务器后的名称
string fileName = rootPath + initPath + this . hidFileName . Text ;
//读取Excel
DataSet ds = NPOIHelper . ExcelToDataSet ( fileName , out errorInfos , true ) ;
//验证Excel读取是否有误
if ( ! string . IsNullOrEmpty ( errorInfos ) )
{
ShowNotify ( errorInfos , MessageBoxIcon . Warning ) ;
return ;
}
if ( ds . Tables . Count > 0 )
{
//定义错误集合实体类
var data = ValidateFieldsExcelData ( ds . Tables [ 0 ] ) ;
Funs . DB . PMI_ImportErrorLog . InsertAllOnSubmit ( data . Item2 ) ;
Funs . DB . SubmitChanges ( ) ;
//验证错误集合
if ( data . Item1 )
{
string batchNo = data . Item2 . Select ( t = > t . BatchNo ) . Distinct ( ) . First ( ) ;
PageContext . RegisterStartupScript ( Window4 . GetShowReference ( String . Format ( "ImportError.aspx?batchNo={0}" , batchNo ) , "PMI导入错误日志" ) ) ;
return ;
}
//导入数据
List < PMI_Delegation > listPMIData = new List < PMI_Delegation > ( ) ;
List < Model . PMI_DelegationDetails > listDetailData = new List < PMI_DelegationDetails > ( ) ;
foreach ( var item in data . Item2 )
{
if ( ! listPMIData . Any ( t = > t . DelegationNo = = item . DelegationNo ) )
{
List < PMI_DelegationDetails > ptpItemListData = new List < PMI_DelegationDetails > ( ) ;
Model . PMI_Delegation model = new PMI_Delegation ( ) ;
model . Id = SQLHelper . GetNewID ( typeof ( PMI_Delegation ) ) ;
model . DelegationNo = item . DelegationNo ;
model . UnitId = item . UnitId ;
model . ProjectId = item . ProjectId ;
model . InstallationId = item . InstallId ;
model . DetectionStandard = "GB 50184-2011" ;
model . DelegationDate = DateTime . Now ;
model . Tabler = this . CurrUser . UserId ;
listPMIData . Add ( model ) ;
var itemData = data . Item2 . Where ( t = > t . DelegationNo = = item . DelegationNo ) . ToList ( ) ;
foreach ( var item2 in itemData )
{
var model2 = new PMI_DelegationDetails ( ) ;
model2 . PMIId = model . Id ;
model2 . JointId = item2 . WeldJointId ;
model2 . WorkAreaId = item2 . WorkAreaId ;
model2 . Id = SQLHelper . GetNewID ( typeof ( PMI_DelegationDetails ) ) ;
listDetailData . Add ( model2 ) ;
}
}
}
Funs . DB . PMI_Delegation . InsertAllOnSubmit ( listPMIData ) ;
Funs . DB . PMI_DelegationDetails . InsertAllOnSubmit ( listDetailData ) ;
//绑定表格
Funs . DB . SubmitChanges ( ) ;
this . BindGrid ( ) ;
ShowNotify ( "导入成功!" , MessageBoxIcon . Success ) ;
PageContext . RegisterStartupScript ( ActiveWindow . GetWriteBackValueReference ( this . PMIDelegationId ) + ActiveWindow . GetHidePostBackReference ( ) ) ;
}
else
{
ShowAlert ( "没有数据!" , MessageBoxIcon . Warning ) ;
return ;
}
}
catch ( Exception ex )
{
ShowAlert ( "'" + ex . Message + "'" , MessageBoxIcon . Warning ) ;
}
}
/// <summary>
/// 验证Excle中的数据列是否符合要求
/// </summary>
private ( bool , List < PMI_ImportErrorLog > ) ValidateFieldsExcelData ( DataTable dt )
{
var listData = new List < PMI_ImportErrorLog > ( ) ;
bool flag = false ;
int k = 0 ;
string batchNo = DateTime . Now . ToString ( "yyyyMMddHHmmss" ) ;
foreach ( DataRow dr in dt . Rows )
{
var model = new PMI_ImportErrorLog ( ) ;
k + + ;
string delegationNo = dr [ 0 ] . ToString ( ) ; //委托单号
string untiCode = dr [ 1 ] . ToString ( ) ; //单位编号
string installCode = dr [ 2 ] . ToString ( ) ; //装置编号
string areaCode = dr [ 3 ] . ToString ( ) ; //区域编号
string pipelineCode = dr [ 4 ] . ToString ( ) ; //管线编号
string jointCode = dr [ 5 ] . ToString ( ) ; //焊口列表逗号
model . Id = SQLHelper . GetNewID ( typeof ( PMI_ImportErrorLog ) ) ;
model . DelegationNo = delegationNo ;
model . UnitCode = untiCode ;
model . InstallCode = installCode ;
model . AreaCode = areaCode ;
model . PiplineCode = pipelineCode ;
model . JointCode = jointCode ;
model . CreatedTime = DateTime . Now ;
model . RowId = k ;
model . UnitId = string . Empty ;
model . InstallId = string . Empty ;
model . WorkAreaId = string . Empty ;
model . ProjectId = this . CurrUser . LoginProjectId ;
model . PipelineId = string . Empty ;
model . BatchNo = batchNo ;
string errorMsg = string . Empty ;
//验证是否为空
if ( string . IsNullOrEmpty ( delegationNo ) )
{
errorMsg + = "试压包编号未填写 |" ;
}
if ( string . IsNullOrEmpty ( untiCode ) )
{
errorMsg + = "试单位编号未填写 | " ;
}
if ( string . IsNullOrEmpty ( installCode ) )
{
errorMsg + = "装置编号未填写 | " ;
}
if ( string . IsNullOrEmpty ( areaCode ) )
{
errorMsg + = "区域编号未填写 | " ;
}
if ( string . IsNullOrEmpty ( pipelineCode ) )
{
errorMsg + = "管线号未填写 | " ;
}
if ( string . IsNullOrEmpty ( jointCode ) )
{
errorMsg + = "是否全部焊口未填写 | " ;
}
//检查单位编号是否存在
var unitInfo = Funs . DB . Base_Unit . FirstOrDefault ( t = > t . UnitCode = = model . UnitCode ) ;
if ( unitInfo = = null )
{
errorMsg + = "未知的单位编号 | " ;
}
var installInfo = Funs . DB . Project_Installation . FirstOrDefault ( t = > t . InstallationCode = = model . InstallCode ) ;
if ( installInfo = = null )
{
errorMsg + = "未知的装置编号 | " ;
}
var areaInfo = Funs . DB . Project_WorkArea . FirstOrDefault ( t = > t . WorkAreaCode = = model . AreaCode ) ;
if ( areaInfo = = null )
{
errorMsg + = "未知的区域编号 | " ;
}
var isAnypipeline = Funs . DB . Pipeline_Pipeline . Any ( t = > t . PipelineCode = = model . PiplineCode ) ;
if ( ! isAnypipeline )
{
errorMsg + = "未知的管线号 | " ;
}
var isDelegationNo = Funs . DB . PMI_Delegation . Any ( t = > t . DelegationNo = = model . DelegationNo ) ;
if ( isDelegationNo )
{
errorMsg + = "该委托编号已存在 | " ;
}
if ( unitInfo ! = null & & installInfo ! = null & & areaInfo ! = null )
{
model . UnitId = unitInfo . UnitId ;
model . WorkAreaId = areaInfo . WorkAreaId ;
model . InstallId = installInfo . InstallationId ;
var newPipelineInfo = Funs . DB . Pipeline_Pipeline . FirstOrDefault ( t = > t . UnitId = = unitInfo . UnitId & &
t . InstallationId = = installInfo . InstallationId & & t . WorkAreaId = = areaInfo . WorkAreaId & &
t . PipelineCode = = model . PiplineCode ) ;
if ( newPipelineInfo = = null )
{
errorMsg + = "当前区域下不存在此管线号 | " ;
model . PipelineId = string . Empty ;
}
else
{
model . PipelineId = newPipelineInfo . PipelineId ;
string pipelineError = CheckPipeline ( this . CurrUser . LoginProjectId , unitInfo . UnitId , installInfo . InstallationId , newPipelineInfo . PipelineId ) ;
if ( ! string . IsNullOrEmpty ( pipelineError ) )
{
errorMsg + = pipelineError ;
}
else
{
var newWeldJointInfo = Funs . DB . Pipeline_WeldJoint . FirstOrDefault ( t = > t . PipelineId = = newPipelineInfo . PipelineId & & t . WeldJointCode = = jointCode ) ;
if ( newWeldJointInfo = = null )
{
errorMsg + = "当前管线下不存在此焊口 | " ;
model . WeldJointId = string . Empty ;
}
else
{
model . WeldJointId = newWeldJointInfo . WeldJointId ;
string weldJointError = CheckWeldJoint ( newPipelineInfo . PipelineId , model . WeldJointId ) ;
if ( ! string . IsNullOrEmpty ( weldJointError ) )
{
errorMsg + = weldJointError ;
model . WeldJointId = string . Empty ;
}
}
}
}
}
model . Remark = errorMsg ;
if ( ! string . IsNullOrEmpty ( model . Remark ) )
flag = true ;
listData . Add ( model ) ;
}
return ( flag , listData ) ;
}
public string CheckPipeline ( string ProjectId , string UnitId , string installId , string PipelineId )
{
string result = "" ;
//查询出来未达到PMI检测比例的数据
var pmiNocheckList = Funs . DB . View_PMIDetections
. Where ( t = > t . ProjectId = = ProjectId
& & t . InstallationId = = installId
& & t . UnitId = = UnitId
& & ( t . RateBys < = 2 & & t . PMIBySNum < = 2 ) | | ( t . RateByf < = 2 & & t . PMIByFNum < = 2 ) )
. AsQueryable ( ) ;
//排除已经委托过的
var listData = ( from a in Funs . DB . PMI_Delegation . AsQueryable ( )
join
b in Funs . DB . PMI_DelegationDetails . AsQueryable ( ) on
a . Id equals b . PMIId
select b . JointId
) . Distinct ( ) . ToList ( ) ;
//查询带有PMI处理且已经焊接过的管线数据
var iso = from a in Funs . DB . View_Pipeline_WeldJoint
where a . IsPMI = = true & & a . ProjectId = = ProjectId & & a . UnitId = = UnitId
& & a . InstallationId = = installId & & ( a . WeldingDailyId ! = "" & & a . WeldingDailyId ! = null )
select new { a . PipelineId , a . PipelineCode , a . WorkAreaId , a . WeldJointCode , a . WeldJointId }
;
iso = from a in iso
join b in pmiNocheckList on a . PipelineId equals b . PipelineId
select new
{
a . PipelineId ,
a . PipelineCode ,
a . WorkAreaId ,
a . WeldJointCode ,
a . WeldJointId
} ;
if ( listData . Count > 0 )
{
iso = iso . Where ( a = > ! listData . Contains ( a . WeldJointId ) ) ;
}
iso = iso . Where ( a = > a . PipelineId . Contains ( PipelineId ) ) ;
var isoList = iso . Select ( x = > x . PipelineId ) . Distinct ( ) . ToList ( ) ;
if ( isoList . Count = = 0 )
{
result = "该管线无法进行PMI委托 | " ;
}
return result ;
}
public string CheckWeldJoint ( string PipelineId , string WeldJointId )
{
string result = "" ;
//未达标的活动S口
var pmiViewJointBy_S = ( from a in Funs . DB . View_PMIDetections
join b in Funs . DB . Pipeline_WeldJoint
on a . PipelineId equals b . PipelineId
where b . JointAttribute = = "活动S"
& & a . PipelineId = = PipelineId
& & ( b . WeldingDailyId ! = null & & b . WeldingDailyId ! = "" )
& & ( a . RateBys > 2 | | a . PMIBySNum > 2 )
select b . WeldJointId )
. ToList ( ) ;
//未达标的固定F口
var pmiViewJointBy_F = ( from a in Funs . DB . View_PMIDetections
join b in Funs . DB . Pipeline_WeldJoint
on a . PipelineId equals b . PipelineId
where b . JointAttribute = = "固定F"
& & a . PipelineId = = PipelineId
& & ( b . WeldingDailyId ! = null & & b . WeldingDailyId ! = "" )
& & ( a . RateByf > 2 & & a . PMIByFNum > 2 )
select b . WeldJointId )
. ToList ( ) ;
//排除已经选择过的焊口
var listData = ( from a in Funs . DB . PMI_Delegation . AsQueryable ( )
join
b in Funs . DB . PMI_DelegationDetails . AsQueryable ( ) on
a . Id equals b . PMIId
select b . JointId
) . Distinct ( ) . ToList ( ) ;
var query = Funs . DB . View_Pipeline_WeldJoint . Where ( t = > t . IsPMI = = true
& & ( t . WeldingDailyId ! = null & & t . WeldingDailyId ! = "" )
& & t . PipelineId = = PipelineId ) ;
if ( listData . Count > 0 )
{
query = query . Where ( t = > ! listData . Contains ( t . WeldJointId ) ) ;
}
if ( pmiViewJointBy_S . Count > 0 )
{
query = query . Where ( t = > t . JointAttribute ! = "活动S" ) ;
}
if ( pmiViewJointBy_F . Count > 0 )
{
query = query . Where ( t = > t . JointAttribute ! = "固定F" ) ;
}
query = query . Where ( t = > t . WeldJointId = = WeldJointId ) ;
if ( query . Count ( ) = = 0 )
{
result = "该焊口无法进行PMI委托 | " ;
}
return result ;
}
2024-06-21 16:37:50 +08:00
#region 私 有 方 法
2024-06-20 17:12:59 +08:00
/// <summary>
/// 无损检测委托单行和列
/// </summary>
/// <returns></returns>
private XSSFSheet WsExcelCreateRow ( XSSFSheet ws , XSSFWorkbook hssfworkbook , int sRows , int eRows , ICellStyle style , int cStart , int cEnd , int excelpart , bool isnobk = false )
{
for ( int i = sRows ; i < = eRows ; i + + )
{
ws . CreateRow ( i ) ;
if ( excelpart = = 1 )
{
ws . GetRow ( i ) . HeightInPoints =
i = = sRows ? 27.75f :
i = = ( sRows + 1 ) ? 25.5f :
i = = ( sRows + 2 ) ? 25.5f :
i = = ( sRows + 3 ) ? 25.5f :
i = = ( sRows + 4 ) ? 23.25f :
i = = ( sRows + 5 ) ? 23.25f :
i = = ( sRows + 6 ) ? 23.25f :
i = = ( sRows + 7 ) ? 23.25f :
i = = ( sRows + 8 ) ? 23.25f :
i = = ( sRows + 9 ) ? 23.25f :
i = = ( sRows + 10 ) ? 23.25f :
i = = ( sRows + 11 ) ? 23.25f :
i = = ( sRows + 12 ) ? 23.25f :
17f ;
}
else if ( excelpart = = 2 )
{
ws . GetRow ( i ) . HeightInPoints = 25.5f ;
}
else
{
ws . GetRow ( i ) . HeightInPoints = 15.5f ;
}
for ( int j = cStart ; j < = cEnd ; j + + )
{
ws . GetRow ( i ) . CreateCell ( j ) ;
if ( isnobk )
{
ws . GetRow ( i ) . GetCell ( j ) . CellStyle = CommonPrint . SetExcelStyle ( hssfworkbook , BorderStyle . None , BorderStyle . None , BorderStyle . None , BorderStyle . None , VerticalAlignment . Center , HorizontalAlignment . Center , 10.5 , true , false ) ;
}
else
{
ws . GetRow ( i ) . GetCell ( j ) . CellStyle = style ;
}
}
}
return ws ;
}
/// <summary>
2024-06-21 16:37:50 +08:00
/// 行和列
2024-06-20 17:12:59 +08:00
/// </summary>
/// <returns></returns>
private XSSFSheet ClExcelCreateRow ( XSSFSheet ws , XSSFWorkbook hssfworkbook , int sRows , int eRows , ICellStyle style , int cStart , int cEnd , bool istitle = false , bool isnobk = false )
{
for ( int i = sRows ; i < = eRows ; i + + )
{
ws . CreateRow ( i ) ;
if ( istitle )
{
ws . GetRow ( i ) . HeightInPoints =
i = = sRows ? 27.75f :
i = = ( sRows + 1 ) ? 25f :
i = = ( sRows + 2 ) ? 21.75f :
i = = ( sRows + 3 ) ? 21.75f :
i = = ( sRows + 5 ) ? 28f :
14.75f ;
}
else
{
ws . GetRow ( i ) . HeightInPoints = 14.75f ;
}
for ( int j = cStart ; j < = cEnd ; j + + )
{
ws . GetRow ( i ) . CreateCell ( j ) ;
if ( isnobk )
{
2024-06-21 16:37:50 +08:00
ws . GetRow ( i ) . GetCell ( j ) . CellStyle = CommonPrint . SetExcelStyle ( hssfworkbook , BorderStyle . None , BorderStyle . None , BorderStyle . None , BorderStyle . None , VerticalAlignment . Center , HorizontalAlignment . Center , 10 , true , false ) ;
2024-06-20 17:12:59 +08:00
}
else
{
ws . GetRow ( i ) . GetCell ( j ) . CellStyle = style ;
}
}
}
return ws ;
}
/// <summary>
/// 查询指定条数分页
/// </summary>
/// <returns></returns>
public static DataTable GetPageToTable ( DataTable dt , int StartNum , int EndNum )
{
//0页代表每页数据, 直接返回
if ( EndNum = = 0 ) return dt ;
//数据源为空返回空DataTable
if ( dt = = null ) return new DataTable ( ) ;
DataTable newdt = dt . Copy ( ) ;
newdt . Clear ( ) ; //copy dt的框架
if ( StartNum > = dt . Rows . Count )
return newdt ; //源数据记录数小于等于要显示的记录, 直接返回dt
if ( EndNum > dt . Rows . Count )
EndNum = dt . Rows . Count ;
for ( int i = StartNum ; i < = EndNum - 1 ; i + + )
{
DataRow newdr = newdt . NewRow ( ) ;
DataRow dr = dt . Rows [ i ] ;
foreach ( DataColumn column in dt . Columns )
{
newdr [ column . ColumnName ] = dr [ column . ColumnName ] ;
}
newdt . Rows . Add ( newdr ) ;
}
return newdt ;
}
#endregion
2024-05-11 15:22:08 +08:00
}
}