2023-06-05 10:32:48 +08:00
using BLL ;
using System ;
using System.Collections.Generic ;
using System.Data ;
using System.Data.SqlClient ;
2023-06-06 09:02:55 +08:00
using System.IO ;
2023-06-05 10:32:48 +08:00
using System.Linq ;
2023-06-06 09:02:55 +08:00
using NPOI.SS.Util ;
2023-06-05 10:32:48 +08:00
namespace FineUIPro.Web.ZHGL.Plan
{
public partial class ProjectPlan : PageBase
{
#region 加 载
/// <summary>
/// 加载页面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load ( object sender , EventArgs e )
{
if ( ! IsPostBack )
{
Funs . DropDownPageSize ( this . ddlPageSize ) ;
////权限按钮方法
this . GetButtonPower ( ) ;
this . btnNew . OnClientClick = Window1 . GetShowReference ( "ProjectPlanEdit.aspx" ) + "return false;" ;
ProjectService . InitAllProjectDropDownList ( this . drpProject , false ) ;
Funs . FineUIPleaseSelect ( drpProject , "按项目查询" ) ;
// 绑定表格
this . BindGrid ( ) ;
}
}
/// <summary>
/// 绑定数据
/// </summary>
private void BindGrid ( )
{
string strSql = "SELECT ProjectPlan.ProjectPlanId,ProjectPlan.ProjectId,Project.ProjectName,ProjectPlanCode,ProjectPlan.ProjectPlanName,ProjectPlan.VersionNo,(CASE ProjectPlan.ProjectType WHEN '1' THEN 'EPC' WHEN '2' THEN 'EPCM' WHEN '3' THEN 'C' WHEN '4' THEN '其他' END ) AS ProjectType,ProjectPlan.ProjectPlanContents,ProjectPlan.CompileMan,Users.PersonName AS CompileManName, ProjectPlan.CompileDate,ProjectPlan.States"
+ @" FROM ActionPlan_ProjectPlan AS ProjectPlan "
+ @" LEFT JOIN Base_Project AS Project ON ProjectPlan.ProjectId=Project.ProjectId "
+ @" LEFT JOIN Sys_FlowOperate AS FlowOperate ON ProjectPlan.ProjectPlanId=FlowOperate.DataId AND FlowOperate.IsClosed <> 1"
+ @" LEFT JOIN Person_Persons AS OperateUser ON FlowOperate.OperaterId=OperateUser.PersonId "
+ @" LEFT JOIN Person_Persons AS Users ON Users.PersonId = ProjectPlan.CompileMan "
+ @" WHERE 1=1 " ;
List < SqlParameter > listStr = new List < SqlParameter > ( ) ;
if ( this . drpProject . SelectedValue ! = BLL . Const . _Null )
{
if ( this . drpProject . SelectedValue = = "Company" )
{
strSql + = " AND ProjectPlan.ProjectId is null" ;
}
else
{
strSql + = " AND ProjectPlan.ProjectId = @ProjectId" ;
listStr . Add ( new SqlParameter ( "@ProjectId" , this . drpProject . SelectedValue ) ) ;
}
}
if ( ! string . IsNullOrEmpty ( this . txtProjectPlanCode . Text . Trim ( ) ) )
{
strSql + = " AND ProjectPlanCode LIKE @ProjectPlanCode" ;
listStr . Add ( new SqlParameter ( "@ProjectPlanCode" , "%" + this . txtProjectPlanCode . Text . Trim ( ) + "%" ) ) ;
}
if ( ! string . IsNullOrEmpty ( this . txtProjectPlanName . Text . Trim ( ) ) )
{
strSql + = " AND ProjectPlanName LIKE @ProjectPlanName" ;
listStr . Add ( new SqlParameter ( "@ProjectPlanName" , "%" + this . txtProjectPlanName . Text . Trim ( ) + "%" ) ) ;
}
SqlParameter [ ] parameter = listStr . ToArray ( ) ;
DataTable tb = SQLHelper . GetDataTableRunText ( strSql , parameter ) ;
Grid1 . RecordCount = tb . Rows . Count ;
var table = this . GetPagedDataTable ( Grid1 , tb ) ;
Grid1 . DataSource = table ;
Grid1 . DataBind ( ) ;
}
#endregion
#region 分 页 排 序
/// <summary>
/// 改变索引事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_PageIndexChange ( object sender , GridPageEventArgs e )
{
BindGrid ( ) ;
}
/// <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 ( ) ;
}
/// <summary>
/// 排序
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_Sort ( object sender , FineUIPro . GridSortEventArgs e )
{
BindGrid ( ) ;
}
/// <summary>
/// 关闭弹出窗口
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Window1_Close ( object sender , EventArgs e )
{
BindGrid ( ) ;
}
#endregion
#region 查 询
/// <summary>
/// 查询
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void TextBox_TextChanged ( object sender , EventArgs e )
{
this . BindGrid ( ) ;
BLL . LogService . AddSys_Log ( this . CurrUser , string . Empty , string . Empty , BLL . Const . OfficeProjectPlanMenuId , Const . BtnQuery ) ;
}
#endregion
#region 编 辑
/// <summary>
/// 双击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_RowDoubleClick ( object sender , GridRowClickEventArgs e )
{
this . EditData ( ) ;
}
/// <summary>
/// 右键编辑事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnMenuEdit_Click ( object sender , EventArgs e )
{
this . EditData ( ) ;
}
/// <summary>
/// 编辑数据方法
/// </summary>
private void EditData ( )
{
if ( Grid1 . SelectedRowIndexArray . Length = = 0 )
{
Alert . ShowInTop ( "请至少选择一条记录!" , MessageBoxIcon . Warning ) ;
return ;
}
string id = Grid1 . SelectedRowID . Split ( ',' ) [ 0 ] ;
Model . ActionPlan_ProjectPlan ProjectPlan = ProjectPlanService . GetProjectPlanById ( id ) ;
if ( ProjectPlan . States = = Const . ProjectPlan_Complete )
{
Alert . ShowInTop ( "该文件已经审批完成,无法操作,请右键查看!" , MessageBoxIcon . Warning ) ;
return ;
}
else if ( ProjectPlan . States = = Const . ProjectPlan_Compile )
{
if ( ProjectPlan . CompileMan = = CurrUser . PersonId | | CurrUser . PersonId = = Const . sysglyId )
{
PageContext . RegisterStartupScript ( Window1 . GetShowReference ( String . Format ( "ProjectPlanEdit.aspx?ProjectPlanId={0}" , id ) ) ) ;
}
else
{
Alert . ShowInTop ( "您不是编制人,无法操作!请右键查看" , MessageBoxIcon . Warning ) ;
return ;
}
}
else if ( ProjectPlan . States = = Const . ProjectPlan_Reviewing | | ProjectPlan . States = = Const . ProjectPlan_ReCompile )
{
Model . ActionPlan_ProjectPlanApprove approve = ProjectPlanApproveService . GetProjectPlanApproveByApproveMan ( id , CurrUser . PersonId ) ;
if ( approve ! = null | | CurrUser . PersonId = = Const . sysglyId )
{
PageContext . RegisterStartupScript ( Window1 . GetShowReference ( String . Format ( "ProjectPlanEdit.aspx?ProjectPlanId={0}" , id ) ) ) ;
return ;
//Response.Redirect("ProjectPlanAudit.aspx?ProjectPlanId=" + id);
//PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("CheckListView.aspx?CheckControlCode={0}", id, "查看 - ")));
}
else
{
if ( ProjectPlan . CompileMan . Equals ( CurrUser . PersonId ) )
{
PageContext . RegisterStartupScript ( Window1 . GetShowReference ( String . Format ( "ProjectPlanEdit.aspx?ProjectPlanId={0}" , id ) ) ) ;
}
else
{
Alert . ShowInTop ( "您不是办理用户,无法操作!请右键查看" , MessageBoxIcon . Warning ) ;
return ;
}
}
}
}
#endregion
protected void btnMenuView_Click ( object sender , EventArgs e )
{
if ( Grid1 . SelectedRowIndexArray . Length = = 0 )
{
Alert . ShowInTop ( "请至少选择一条记录!" , MessageBoxIcon . Warning ) ;
return ;
}
string id = Grid1 . SelectedRowID . Split ( ',' ) [ 0 ] ;
PageContext . RegisterStartupScript ( Window1 . GetShowReference ( String . Format ( "ProjectPlanView.aspx?ProjectPlanId={0}" , id ) ) ) ;
}
#region 删 除
/// <summary>
/// 右键删除事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnMenuDelete_Click ( object sender , EventArgs e )
{
if ( Grid1 . SelectedRowIndexArray . Length > 0 )
{
bool isShow = false ;
if ( Grid1 . SelectedRowIndexArray . Length = = 1 )
{
isShow = true ;
}
foreach ( int rowIndex in Grid1 . SelectedRowIndexArray )
{
string rowID = Grid1 . DataKeys [ rowIndex ] [ 0 ] . ToString ( ) ;
if ( this . judgementDelete ( rowID , isShow ) )
{
var getV = BLL . ProjectPlanService . GetProjectPlanById ( rowID ) ;
if ( getV ! = null )
{
BLL . LogService . AddSys_Log ( this . CurrUser , getV . ProjectPlanCode , getV . ProjectPlanId , BLL . Const . OfficeProjectPlanMenuId , Const . BtnDelete ) ;
BLL . ProjectPlanService . DeleteProjectPlanById ( rowID ) ;
}
}
}
BindGrid ( ) ;
ShowNotify ( "删除数据成功!" , MessageBoxIcon . Success ) ;
}
}
/// <summary>
/// 判断是否可以删除
/// </summary>
/// <returns></returns>
private bool judgementDelete ( string id , bool isShow )
{
string content = string . Empty ;
if ( string . IsNullOrEmpty ( content ) )
{
return true ;
}
else
{
if ( isShow )
{
Alert . ShowInTop ( content ) ;
}
return false ;
}
}
#endregion
#region 获 取 按 钮 权 限
/// <summary>
/// 获取按钮权限
/// </summary>
/// <param name="button"></param>
/// <returns></returns>
private void GetButtonPower ( )
{
if ( Request . Params [ "value" ] = = "0" )
{
return ;
}
var buttonList = BLL . CommonService . GetAllButtonList ( this . CurrUser . LoginProjectId , this . CurrUser . PersonId , BLL . Const . OfficeProjectPlanMenuId ) ;
if ( buttonList . Count ( ) > 0 )
{
if ( buttonList . Contains ( BLL . Const . BtnAdd ) )
{
this . btnNew . Hidden = false ;
}
if ( buttonList . Contains ( BLL . Const . BtnModify ) )
{
this . btnMenuEdit . Hidden = false ;
}
if ( buttonList . Contains ( BLL . Const . BtnDelete ) )
{
this . btnMenuDelete . Hidden = false ;
}
}
}
#endregion
#region 导 出 按 钮
/// 导出按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnOut_Click ( object sender , EventArgs e )
{
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 = 5000 ;
this . BindGrid ( ) ;
Response . Write ( GetGridTableHtml ( Grid1 ) ) ;
Response . End ( ) ;
}
2023-06-06 09:02:55 +08:00
/// 导出按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnOut2_Click ( object sender , EventArgs e )
{
string rootPath = Server . MapPath ( "~/" ) ;
string initTemplatePath = string . Empty ;
string uploadfilepath = string . Empty ;
string newUrl = string . Empty ;
string filePath = string . Empty ;
initTemplatePath = Const . OpinionTemplateUrl ;
uploadfilepath = rootPath + initTemplatePath ;
string id = Grid1 . SelectedRowID . Split ( ',' ) [ 0 ] ;
Model . ActionPlan_ProjectPlan ProjectPlan = ProjectPlanService . GetProjectPlanById ( id ) ;
if ( ProjectPlan ! = null )
{
string projectName = BLL . ProjectService . GetProjectNameByProjectId ( ProjectPlan . ProjectId ) ;
newUrl = uploadfilepath . Replace ( ".xlsx" , ProjectPlan . ProjectPlanCode + "(" + ProjectPlan . ProjectPlanName + ")" + ".xlsx" ) ;
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 ) ;
}
// 创建单元格样式
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 ;
var font = workbook . CreateFont ( ) ;
font . FontHeightInPoints = 10 ;
//font.FontHeightInPoints = (short)8.5;字号为小数时要转为short
cellStyle . SetFont ( font ) ;
// 第二步:创建新数据行
NPOI . SS . UserModel . ISheet sheet = workbook . GetSheetAt ( 0 ) ;
var opinions = ProjectPlanOpinionService . getListData ( id , null ) ;
int i = 1 ;
foreach ( var item in opinions )
{
// 第二步:创建新数据行
NPOI . SS . UserModel . IRow row = sheet . GetRow ( i ) ;
NPOI . SS . UserModel . ICell cell ;
// 添加数据
cell = row . CreateCell ( 0 ) ;
cell . CellStyle = cellStyle ;
cell . SetCellValue ( i . ToString ( ) ) ;
cell = row . CreateCell ( 1 ) ;
cell . CellStyle = cellStyle ;
cell . SetCellValue ( projectName ) ;
cell = row . CreateCell ( 2 ) ;
cell . CellStyle = cellStyle ;
cell . SetCellValue ( item . OriginalNum ) ;
cell = row . CreateCell ( 3 ) ;
cell . CellStyle = cellStyle ;
cell . SetCellValue ( item . OriginalContent ) ;
cell = row . CreateCell ( 4 ) ;
cell . CellStyle = cellStyle ;
cell . SetCellValue ( item . Opinion ) ;
cell = row . CreateCell ( 5 ) ;
cell . CellStyle = cellStyle ;
cell . SetCellValue ( Person_PersonsService . GetPersonsNameById ( item . OpinionMan ) ) ;
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 ) ;
}
}
2023-06-05 10:32:48 +08:00
#endregion
/// <summary>
/// 把办理人转换代号为文字形式
/// </summary>
/// <param name="ProjectPlanId"></param>
/// <returns></returns>
///
public static string ConvertApproveMan ( object ProjectPlanId )
{
string name = string . Empty ;
if ( ProjectPlanId ! = null )
{
var approves = BLL . ProjectPlanApproveService . GetProjectPlanApprovesNotHandleList ( ProjectPlanId . ToString ( ) ) ;
foreach ( var item in approves )
{
name + = BLL . Person_PersonsService . GetPersonsNameById ( item . ApproveMan ) + "," ;
}
if ( ! string . IsNullOrEmpty ( name ) )
{
name = name . Substring ( 0 , name . Length - 1 ) ;
}
}
return name ;
}
}
}