2024-05-08 10:17:02 +08:00
using BLL ;
using NPOI.XSSF.UserModel ;
using NPOI.SS.UserModel ;
using System ;
using System.Collections.Generic ;
using System.Collections.Specialized ;
using System.Data ;
using System.Data.SqlClient ;
using System.IO ;
using System.Linq ;
using System.Web ;
using System.Net ;
using ICSharpCode.SharpZipLib ;
using ICSharpCode.SharpZipLib.Zip ;
using ICSharpCode.SharpZipLib.Checksum ;
using Model ;
using BLL.Common ;
using FineUIPro.Web.common ;
namespace FineUIPro.Web.SES
{
public partial class SESRelatedData : PageBase
{
#region 加 载
/// <summary>
/// 加载页面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load ( object sender , EventArgs e )
{
// 表头过滤
FilterDataRowItem = FilterDataRowItemImplement ;
if ( ! IsPostBack )
{
//StartTime.Text = DateTime.Now.AddMonths(-1).ToString(StartTime.DateFormatString);
//EndTime.Text = DateTime.Now.ToString(EndTime.DateFormatString);
GetButtonPower ( ) ; //权限设置
BLL . ContractorService . InitDropDownList ( this . drpContractor , true ) ;
//是否需要交工资料
//this.drpConstRecords.DataTextField = "ConstText";
//this.drpConstRecords.DataValueField = "ConstValue";
//this.drpConstRecords.DataSource = BLL.ConstValue.drpConstItemList(ConstValue.Group_YesOrNo);
//this.drpConstRecords.DataBind();
//this.drpConstRecords.SelectedValue = "N";
//文件类型
this . drpFileType2 . DataTextField = "Text" ;
this . drpFileType2 . DataValueField = "Value" ;
this . drpFileType2 . DataSource = BLL . DropListService . getFileTypeDropList ( ) ;
this . drpFileType2 . DataBind ( ) ;
Funs . FineUIPleaseSelect ( this . drpFileType2 ) ;
this . drpFileType2Select . DataTextField = "Text" ;
this . drpFileType2Select . DataValueField = "Value" ;
this . drpFileType2Select . DataSource = BLL . DropListService . getFileTypeDropList ( ) ;
this . drpFileType2Select . DataBind ( ) ;
Funs . FineUIPleaseSelect ( this . drpFileType2Select ) ;
//文件类型
BLL . FileTypeService . InitFileTypeDropDownList ( this . drpFileType3 , true ) ;
//BLL.FileTypeService.InitFileTypeDropDownList(this.drpFileType3Select, true);
BLL . FileTypeService . InitFileTypeDropDownList ( this . drpExportFileType , true ) ;
btnNew . OnClientClick = Window1 . GetShowReference ( "SESRelatedDataEdit.aspx" ) + "return false;" ;
btnDelete . OnClientClick = Grid1 . GetNoSelectionAlertReference ( "Please select at least one item!" ) ;
btnDelete . ConfirmText = String . Format ( "Are you sure you want to delete the selected <b><script>{0}</script></b> rows?" , Grid1 . GetSelectedCountReference ( ) ) ;
ddlPageSize . SelectedValue = Grid1 . PageSize . ToString ( ) ;
// 绑定表格
BindGrid ( ) ;
}
else if ( GetRequestEventArgument ( ) = = "FilterChange" )
{
BindGrid ( ) ;
}
}
/// <summary>
/// 绑定数据
/// </summary>
private void BindGrid ( )
{
//var sesdata = from x in Funs.DB.FC_SESRelatedData select x;
//var u = string.Join(",", sesdata.Where(p => p.User_Representative != null).Select(p => p.User_Representative).Distinct());
//var m = string.Join(",", sesdata.Where(p => p.Main_Coordinator != null).Select(p => p.Main_Coordinator).Distinct());
string cruUser = CurrUser . UserId ;
string strSql = @"SELECT * from View_FC_SESRelatedData WHERE 1=1 " ;
List < SqlParameter > listStr = new List < SqlParameter > ( ) ;
if ( ! string . IsNullOrEmpty ( hdConstRecords . Text . Trim ( ) ) )
{
strSql + = " AND ConstRecords =@ConstRecords" ;
listStr . Add ( new SqlParameter ( "@ConstRecords" , this . hdConstRecords . Text . Trim ( ) ) ) ;
}
if ( ! string . IsNullOrEmpty ( hdFoNo . Text . Trim ( ) ) )
{
strSql + = " AND FO_NO LIKE @FO_NO" ;
listStr . Add ( new SqlParameter ( "@FO_NO" , "%" + this . hdFoNo . Text . Trim ( ) + "%" ) ) ;
}
if ( ! string . IsNullOrEmpty ( txtFO . Text . Trim ( ) ) )
{
strSql + = " AND FO_NO LIKE @FO" ;
listStr . Add ( new SqlParameter ( "@FO" , "%" + this . txtFO . Text . Trim ( ) + "%" ) ) ;
}
if ( ! string . IsNullOrEmpty ( hdDiscipline . Text . Trim ( ) ) )
{
strSql + = " AND DisciplineId =@disciplineId" ;
listStr . Add ( new SqlParameter ( "@disciplineId" , hdDiscipline . Text . Trim ( ) ) ) ;
}
if ( ! string . IsNullOrEmpty ( this . hdContractor . Text . Trim ( ) ) )
{
strSql + = " AND ContractorId =@ContractorId" ;
listStr . Add ( new SqlParameter ( "@ContractorId" , this . hdContractor . Text . Trim ( ) ) ) ;
}
if ( drpContractor . SelectedValue ! = Const . _Null )
{
strSql + = " AND ContractorId =@con" ;
listStr . Add ( new SqlParameter ( "@con" , drpContractor . SelectedValue ) ) ;
}
if ( ! string . IsNullOrEmpty ( this . hdContractAdmin . Text . Trim ( ) ) )
{
strSql + = " AND Contract_AdminId =@Contract_Admin" ;
listStr . Add ( new SqlParameter ( "@Contract_Admin" , this . hdContractAdmin . Text . Trim ( ) ) ) ;
}
if ( ! string . IsNullOrEmpty ( this . hdBuyer . Text . Trim ( ) ) )
{
strSql + = " AND Buyer=@Buyer" ;
listStr . Add ( new SqlParameter ( "@Buyer" , this . hdBuyer . Text . Trim ( ) ) ) ;
}
if ( ! string . IsNullOrEmpty ( this . hdMainCoord . Text . Trim ( ) ) )
{
strSql + = " AND Main_CoordinatorId =@Main_Coordinator" ;
listStr . Add ( new SqlParameter ( "@Main_Coordinator" , this . hdMainCoord . Text . Trim ( ) ) ) ;
}
if ( ! string . IsNullOrEmpty ( this . hdMCDepartment . Text . Trim ( ) ) )
{
strSql + = " AND MCDept=@MCDept" ;
listStr . Add ( new SqlParameter ( "@MCDept" , this . hdMCDepartment . Text . Trim ( ) ) ) ;
}
if ( ! string . IsNullOrEmpty ( this . hdFCStatus . Text . Trim ( ) ) )
{
strSql + = " AND FC_Status=@FC_Status" ;
listStr . Add ( new SqlParameter ( "@FC_Status" , this . hdFCStatus . Text . Trim ( ) ) ) ;
//if (this.hdFCStatus.Text.Trim() == "Valid")
//{
// strSql += " AND Expire_Date > GETDATE()";
//}
//else if (this.hdFCStatus.Text.Trim() == "Expired Soon")
//{
// strSql += " AND DATEADD(MONTH,-6,Expire_Date) <= GETDATE() AND Expire_Date > GETDATE() ";
//}
//else if (this.hdFCStatus.Text.Trim() == "Expired")
//{
// strSql += " AND Expire_Date < GETDATE()";
//}
}
if ( ! string . IsNullOrEmpty ( this . hdFoType . Text . Trim ( ) ) )
{
strSql + = " AND FOTypeId=@FOTypeId" ;
listStr . Add ( new SqlParameter ( "@FOTypeId" , this . hdFoType . Text . Trim ( ) ) ) ;
}
//if (u.Contains(cruUser) || m.Contains(cruUser))
//{
// strSql += " AND (Main_CoordinatorId=@Main_Coordinator or User_RepresentativeId=@User_Representative)";
// listStr.Add(new SqlParameter("@Main_Coordinator", cruUser));
// listStr.Add(new SqlParameter("@User_Representative", cruUser));
//}
SqlParameter [ ] parameter = listStr . ToArray ( ) ;
DataTable tb = SQLHelper . GetDataTableRunText ( strSql , parameter ) ;
Grid1 . RecordCount = tb . Rows . Count ;
tb = GetFilteredTable ( Grid1 . FilteredData , tb ) ;
var table = this . GetPagedDataTable ( Grid1 , tb ) ;
Grid1 . DataSource = table . DefaultView ;
Grid1 . DataBind ( ) ;
}
#endregion
#region 删 除 数 据
/// <summary>
/// 批量删除数据
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnDelete_Click ( object sender , EventArgs e )
{
this . DeleteData ( ) ;
}
/// <summary>
/// 右键删除事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnMenuDelete_Click ( object sender , EventArgs e )
{
this . DeleteData ( ) ;
}
/// <summary>
/// 删除方法
/// </summary>
private void DeleteData ( )
{
if ( Grid1 . SelectedRowIndexArray . Length > 0 )
{
foreach ( int rowIndex in Grid1 . SelectedRowIndexArray )
{
string rowID = Grid1 . DataKeys [ rowIndex ] [ 0 ] . ToString ( ) ;
var SESRelatedData = BLL . SESRelatedDataService . GetSESRelatedDataById ( rowID ) ;
if ( SESRelatedData ! = null )
{
if ( judgementDelete ( rowID , false ) )
{
var signedContractsList = BLL . SignedContractsService . GetSignedContractsByDataId ( rowID ) ;
if ( signedContractsList ! = null )
{
BLL . SignedContractsService . DeleteSignedContractsByDataId ( rowID ) ;
}
var contractManagement = BLL . ContractManagementService . GetContractManagementByDataId ( rowID ) ;
if ( contractManagement ! = null )
{
BLL . ContractManagementService . DeleteContractManagementByDataId ( rowID ) ;
}
BLL . SESRelatedDataService . DeleteSESRelatedDataById ( rowID ) ;
}
}
}
BindGrid ( ) ;
BLL . Sys_LogService . AddLog ( this . CurrUser . UserId , "Delete SES related data" ) ;
ShowNotify ( "Deleted successfully!" ) ;
}
}
#endregion
#region 过 滤 表 头
/// <summary>
/// 过滤表头
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_FilterChange ( object sender , EventArgs e )
{
BindGrid ( ) ;
}
/// <summary>
/// 根据表头信息过滤列表数据
/// </summary>
/// <param name="sourceObj"></param>
/// <param name="fillteredOperator"></param>
/// <param name="fillteredObj"></param>
/// <param name="column"></param>
/// <returns></returns>
private bool FilterDataRowItemImplement ( object sourceObj , string fillteredOperator , object fillteredObj , string column )
{
bool valid = false ;
if ( column = = "FO_NO" )
{
string sourceValue = sourceObj . ToString ( ) ;
string fillteredValue = fillteredObj . ToString ( ) ;
if ( fillteredOperator = = "equal" & & sourceValue = = fillteredValue )
{
valid = true ;
}
else if ( fillteredOperator = = "contain" & & sourceValue . Contains ( fillteredValue ) )
{
valid = true ;
}
}
if ( column = = "FOType" )
{
string sourceValue = sourceObj . ToString ( ) ;
string fillteredValue = fillteredObj . ToString ( ) ;
if ( fillteredOperator = = "equal" & & sourceValue = = fillteredValue )
{
valid = true ;
}
else if ( fillteredOperator = = "contain" & & sourceValue . Contains ( fillteredValue ) )
{
valid = true ;
}
}
if ( column = = "Contract_Title" )
{
string sourceValue = sourceObj . ToString ( ) ;
string fillteredValue = fillteredObj . ToString ( ) ;
if ( fillteredOperator = = "equal" & & sourceValue = = fillteredValue )
{
valid = true ;
}
else if ( fillteredOperator = = "contain" & & sourceValue . Contains ( fillteredValue ) )
{
valid = true ;
}
}
if ( column = = "Pricing_Scheme" )
{
string sourceValue = sourceObj . ToString ( ) ;
string fillteredValue = fillteredObj . ToString ( ) ;
if ( fillteredOperator = = "equal" & & sourceValue = = fillteredValue )
{
valid = true ;
}
else if ( fillteredOperator = = "contain" & & sourceValue . Contains ( fillteredValue ) )
{
valid = true ;
}
}
if ( column = = "Contractor" )
{
string sourceValue = sourceObj . ToString ( ) ;
string fillteredValue = fillteredObj . ToString ( ) ;
if ( fillteredOperator = = "equal" & & sourceValue = = fillteredValue )
{
valid = true ;
}
else if ( fillteredOperator = = "contain" & & sourceValue . Contains ( fillteredValue ) )
{
valid = true ;
}
}
if ( column = = "Vendor_NO" )
{
string sourceValue = sourceObj . ToString ( ) ;
string fillteredValue = fillteredObj . ToString ( ) ;
if ( fillteredOperator = = "equal" & & sourceValue = = fillteredValue )
{
valid = true ;
}
else if ( fillteredOperator = = "contain" & & sourceValue . Contains ( fillteredValue ) )
{
valid = true ;
}
}
if ( column = = "Item" )
{
string sourceValue = sourceObj . ToString ( ) ;
string fillteredValue = fillteredObj . ToString ( ) ;
if ( fillteredOperator = = "equal" & & sourceValue = = fillteredValue )
{
valid = true ;
}
else if ( fillteredOperator = = "contain" & & sourceValue . Contains ( fillteredValue ) )
{
valid = true ;
}
}
if ( column = = "Discipline" )
{
string sourceValue = sourceObj . ToString ( ) ;
string fillteredValue = fillteredObj . ToString ( ) ;
if ( fillteredOperator = = "equal" & & sourceValue = = fillteredValue )
{
valid = true ;
}
else if ( fillteredOperator = = "contain" & & sourceValue . Contains ( fillteredValue ) )
{
valid = true ;
}
}
if ( column = = "DisciplineCategory" )
{
string sourceValue = sourceObj . ToString ( ) ;
string fillteredValue = fillteredObj . ToString ( ) ;
if ( fillteredOperator = = "equal" & & sourceValue = = fillteredValue )
{
valid = true ;
}
else if ( fillteredOperator = = "contain" & & sourceValue . Contains ( fillteredValue ) )
{
valid = true ;
}
}
if ( column = = "Currency" )
{
string sourceValue = sourceObj . ToString ( ) ;
string fillteredValue = fillteredObj . ToString ( ) ;
if ( fillteredOperator = = "equal" & & sourceValue = = fillteredValue )
{
valid = true ;
}
else if ( fillteredOperator = = "contain" & & sourceValue . Contains ( fillteredValue ) )
{
valid = true ;
}
}
if ( column = = "Material_Group" )
{
string sourceValue = sourceObj . ToString ( ) ;
string fillteredValue = fillteredObj . ToString ( ) ;
if ( fillteredOperator = = "equal" & & sourceValue = = fillteredValue )
{
valid = true ;
}
else if ( fillteredOperator = = "contain" & & sourceValue . Contains ( fillteredValue ) )
{
valid = true ;
}
}
if ( column = = "Purchase_Group" )
{
string sourceValue = sourceObj . ToString ( ) ;
string fillteredValue = fillteredObj . ToString ( ) ;
if ( fillteredOperator = = "equal" & & sourceValue = = fillteredValue )
{
valid = true ;
}
else if ( fillteredOperator = = "contain" & & sourceValue . Contains ( fillteredValue ) )
{
valid = true ;
}
}
if ( column = = "Cost_Element" )
{
string sourceValue = sourceObj . ToString ( ) ;
string fillteredValue = fillteredObj . ToString ( ) ;
if ( fillteredOperator = = "equal" & & sourceValue = = fillteredValue )
{
valid = true ;
}
else if ( fillteredOperator = = "contain" & & sourceValue . Contains ( fillteredValue ) )
{
valid = true ;
}
}
if ( column = = "Type" )
{
string sourceValue = sourceObj . ToString ( ) ;
string fillteredValue = fillteredObj . ToString ( ) ;
if ( fillteredOperator = = "equal" & & sourceValue = = fillteredValue )
{
valid = true ;
}
else if ( fillteredOperator = = "contain" & & sourceValue . Contains ( fillteredValue ) )
{
valid = true ;
}
}
if ( column = = "Contract_Admin" )
{
string sourceValue = sourceObj . ToString ( ) ;
string fillteredValue = fillteredObj . ToString ( ) ;
if ( fillteredOperator = = "equal" & & sourceValue = = fillteredValue )
{
valid = true ;
}
else if ( fillteredOperator = = "contain" & & sourceValue . Contains ( fillteredValue ) )
{
valid = true ;
}
}
if ( column = = "Buyer" )
{
string sourceValue = sourceObj . ToString ( ) ;
string fillteredValue = fillteredObj . ToString ( ) ;
if ( fillteredOperator = = "equal" & & sourceValue = = fillteredValue )
{
valid = true ;
}
else if ( fillteredOperator = = "contain" & & sourceValue . Contains ( fillteredValue ) )
{
valid = true ;
}
}
if ( column = = "Main_Coordinator" )
{
string sourceValue = sourceObj . ToString ( ) ;
string fillteredValue = fillteredObj . ToString ( ) ;
if ( fillteredOperator = = "equal" & & sourceValue = = fillteredValue )
{
valid = true ;
}
else if ( fillteredOperator = = "contain" & & sourceValue . Contains ( fillteredValue ) )
{
valid = true ;
}
}
if ( column = = "MCDept" )
{
string sourceValue = sourceObj . ToString ( ) ;
string fillteredValue = fillteredObj . ToString ( ) ;
if ( fillteredOperator = = "equal" & & sourceValue = = fillteredValue )
{
valid = true ;
}
else if ( fillteredOperator = = "contain" & & sourceValue . Contains ( fillteredValue ) )
{
valid = true ;
}
}
if ( column = = "User_Representative" )
{
string sourceValue = sourceObj . ToString ( ) ;
string fillteredValue = fillteredObj . ToString ( ) ;
if ( fillteredOperator = = "equal" & & sourceValue = = fillteredValue )
{
valid = true ;
}
else if ( fillteredOperator = = "contain" & & sourceValue . Contains ( fillteredValue ) )
{
valid = true ;
}
}
if ( column = = "Valid_Date" )
{
string sourceValue = sourceObj . ToString ( ) ;
string fillteredValue = fillteredObj . ToString ( ) ;
if ( fillteredOperator = = "equal" & & sourceValue = = fillteredValue )
{
valid = true ;
}
else if ( fillteredOperator = = "contain" & & sourceValue . Contains ( fillteredValue ) )
{
valid = true ;
}
}
if ( column = = "Expire_Date" )
{
string sourceValue = sourceObj . ToString ( ) ;
string fillteredValue = fillteredObj . ToString ( ) ;
if ( fillteredOperator = = "equal" & & sourceValue = = fillteredValue )
{
valid = true ;
}
else if ( fillteredOperator = = "contain" & & sourceValue . Contains ( fillteredValue ) )
{
valid = true ;
}
}
if ( column = = "FC_Status" )
{
string sourceValue = sourceObj . ToString ( ) ;
string fillteredValue = fillteredObj . ToString ( ) ;
if ( fillteredOperator = = "equal" & & sourceValue = = fillteredValue )
{
valid = true ;
}
else if ( fillteredOperator = = "contain" & & sourceValue . Contains ( fillteredValue ) )
{
valid = true ;
}
}
if ( column = = "Contract_Person" )
{
string sourceValue = sourceObj . ToString ( ) ;
string fillteredValue = fillteredObj . ToString ( ) ;
if ( fillteredOperator = = "equal" & & sourceValue = = fillteredValue )
{
valid = true ;
}
else if ( fillteredOperator = = "contain" & & sourceValue . Contains ( fillteredValue ) )
{
valid = true ;
}
}
if ( column = = "Cost_Checker" )
{
string sourceValue = sourceObj . ToString ( ) ;
string fillteredValue = fillteredObj . ToString ( ) ;
if ( fillteredOperator = = "equal" & & sourceValue = = fillteredValue )
{
valid = true ;
}
else if ( fillteredOperator = = "contain" & & sourceValue . Contains ( fillteredValue ) )
{
valid = true ;
}
}
if ( column = = "Contract_Tel" )
{
string sourceValue = sourceObj . ToString ( ) ;
string fillteredValue = fillteredObj . ToString ( ) ;
if ( fillteredOperator = = "equal" & & sourceValue = = fillteredValue )
{
valid = true ;
}
else if ( fillteredOperator = = "contain" & & sourceValue . Contains ( fillteredValue ) )
{
valid = true ;
}
}
if ( column = = "VolumeAllocation" )
{
string sourceValue = sourceObj . ToString ( ) ;
string fillteredValue = fillteredObj . ToString ( ) ;
if ( fillteredOperator = = "equal" & & sourceValue = = fillteredValue )
{
valid = true ;
}
else if ( fillteredOperator = = "contain" & & sourceValue . Contains ( fillteredValue ) )
{
valid = true ;
}
}
if ( column = = "Actual_Budget" )
{
string sourceValue = sourceObj . ToString ( ) ;
string fillteredValue = fillteredObj . ToString ( ) ;
if ( fillteredOperator = = "equal" & & sourceValue = = fillteredValue )
{
valid = true ;
}
else if ( fillteredOperator = = "contain" & & sourceValue . Contains ( fillteredValue ) )
{
valid = true ;
}
}
if ( column = = "ConnectedTransaction" )
{
string sourceValue = sourceObj . ToString ( ) ;
string fillteredValue = fillteredObj . ToString ( ) ;
if ( fillteredOperator = = "equal" & & sourceValue = = fillteredValue )
{
valid = true ;
}
else if ( fillteredOperator = = "contain" & & sourceValue . Contains ( fillteredValue ) )
{
valid = true ;
}
}
if ( column = = "CheckedValue" )
{
string sourceValue = sourceObj . ToString ( ) ;
string fillteredValue = fillteredObj . ToString ( ) ;
if ( fillteredOperator = = "equal" & & sourceValue = = fillteredValue )
{
valid = true ;
}
else if ( fillteredOperator = = "contain" & & sourceValue . Contains ( fillteredValue ) )
{
valid = true ;
}
}
if ( column = = "RemainingBudget" )
{
string sourceValue = sourceObj . ToString ( ) ;
string fillteredValue = fillteredObj . ToString ( ) ;
if ( fillteredOperator = = "equal" & & sourceValue = = fillteredValue )
{
valid = true ;
}
else if ( fillteredOperator = = "contain" & & sourceValue . Contains ( fillteredValue ) )
{
valid = true ;
}
}
if ( column = = "RemainingBudgetRate" )
{
string sourceValue = sourceObj . ToString ( ) ;
string fillteredValue = fillteredObj . ToString ( ) ;
if ( fillteredOperator = = "equal" & & sourceValue = = fillteredValue )
{
valid = true ;
}
else if ( fillteredOperator = = "contain" & & sourceValue . Contains ( fillteredValue ) )
{
valid = true ;
}
}
if ( column = = "RemainingDuration" )
{
string sourceValue = sourceObj . ToString ( ) ;
string fillteredValue = fillteredObj . ToString ( ) ;
if ( fillteredOperator = = "equal" & & sourceValue = = fillteredValue )
{
valid = true ;
}
else if ( fillteredOperator = = "contain" & & sourceValue . Contains ( fillteredValue ) )
{
valid = true ;
}
}
if ( column = = "Email" )
{
string sourceValue = sourceObj . ToString ( ) ;
string fillteredValue = fillteredObj . ToString ( ) ;
if ( fillteredOperator = = "equal" & & sourceValue = = fillteredValue )
{
valid = true ;
}
else if ( fillteredOperator = = "contain" & & sourceValue . Contains ( fillteredValue ) )
{
valid = true ;
}
}
if ( column = = "MainHead" )
{
string sourceValue = sourceObj . ToString ( ) ;
string fillteredValue = fillteredObj . ToString ( ) ;
if ( fillteredOperator = = "equal" & & sourceValue = = fillteredValue )
{
valid = true ;
}
else if ( fillteredOperator = = "contain" & & sourceValue . Contains ( fillteredValue ) )
{
valid = true ;
}
}
if ( column = = "MainHeadPosition" )
{
string sourceValue = sourceObj . ToString ( ) ;
string fillteredValue = fillteredObj . ToString ( ) ;
if ( fillteredOperator = = "equal" & & sourceValue = = fillteredValue )
{
valid = true ;
}
else if ( fillteredOperator = = "contain" & & sourceValue . Contains ( fillteredValue ) )
{
valid = true ;
}
}
if ( column = = "MainHeadContact" )
{
string sourceValue = sourceObj . ToString ( ) ;
string fillteredValue = fillteredObj . ToString ( ) ;
if ( fillteredOperator = = "equal" & & sourceValue = = fillteredValue )
{
valid = true ;
}
else if ( fillteredOperator = = "contain" & & sourceValue . Contains ( fillteredValue ) )
{
valid = true ;
}
}
if ( column = = "SafetyOfficer" )
{
string sourceValue = sourceObj . ToString ( ) ;
string fillteredValue = fillteredObj . ToString ( ) ;
if ( fillteredOperator = = "equal" & & sourceValue = = fillteredValue )
{
valid = true ;
}
else if ( fillteredOperator = = "contain" & & sourceValue . Contains ( fillteredValue ) )
{
valid = true ;
}
}
if ( column = = "SafetyOfficerPosition" )
{
string sourceValue = sourceObj . ToString ( ) ;
string fillteredValue = fillteredObj . ToString ( ) ;
if ( fillteredOperator = = "equal" & & sourceValue = = fillteredValue )
{
valid = true ;
}
else if ( fillteredOperator = = "contain" & & sourceValue . Contains ( fillteredValue ) )
{
valid = true ;
}
}
if ( column = = "SafetyOfficerContact" )
{
string sourceValue = sourceObj . ToString ( ) ;
string fillteredValue = fillteredObj . ToString ( ) ;
if ( fillteredOperator = = "equal" & & sourceValue = = fillteredValue )
{
valid = true ;
}
else if ( fillteredOperator = = "contain" & & sourceValue . Contains ( fillteredValue ) )
{
valid = true ;
}
}
if ( column = = "ProjectManager" )
{
string sourceValue = sourceObj . ToString ( ) ;
string fillteredValue = fillteredObj . ToString ( ) ;
if ( fillteredOperator = = "equal" & & sourceValue = = fillteredValue )
{
valid = true ;
}
else if ( fillteredOperator = = "contain" & & sourceValue . Contains ( fillteredValue ) )
{
valid = true ;
}
}
if ( column = = "ProjectManagerPosition" )
{
string sourceValue = sourceObj . ToString ( ) ;
string fillteredValue = fillteredObj . ToString ( ) ;
if ( fillteredOperator = = "equal" & & sourceValue = = fillteredValue )
{
valid = true ;
}
else if ( fillteredOperator = = "contain" & & sourceValue . Contains ( fillteredValue ) )
{
valid = true ;
}
}
if ( column = = "ProjectManagerContact" )
{
string sourceValue = sourceObj . ToString ( ) ;
string fillteredValue = fillteredObj . ToString ( ) ;
if ( fillteredOperator = = "equal" & & sourceValue = = fillteredValue )
{
valid = true ;
}
else if ( fillteredOperator = = "contain" & & sourceValue . Contains ( fillteredValue ) )
{
valid = true ;
}
}
if ( column = = "ConstRecords" )
{
string sourceValue = sourceObj . ToString ( ) ;
string fillteredValue = fillteredObj . ToString ( ) ;
if ( fillteredOperator = = "equal" & & sourceValue = = fillteredValue )
{
valid = true ;
}
else if ( fillteredOperator = = "contain" & & sourceValue . Contains ( fillteredValue ) )
{
valid = true ;
}
}
return valid ;
}
#endregion
#region 分 页 、 排 序
/// <summary>
/// 分页
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_PageIndexChange ( object sender , GridPageEventArgs e )
{
Grid1 . PageIndex = e . NewPageIndex ;
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 )
{
Grid1 . SortDirection = e . SortDirection ;
Grid1 . SortField = e . SortField ;
BindGrid ( ) ;
}
#endregion
#region 查 询
/// <summary>
/// 查询
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Text_TextChanged ( object sender , EventArgs e )
{
BindGrid ( ) ;
}
protected void btnFind_Click ( object sender , EventArgs e )
{
BindGrid ( ) ;
}
#endregion
#region 关 闭 弹 出 窗 口
/// <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 btnSendEmail_Click ( object sender , EventArgs e )
{
bool IsComplite = false ;
string errorMsg = string . Empty ;
string compMsg = string . Empty ;
// 过期提示,30天范围
var foList = from x in Funs . DB . FC_SESRelatedData
where x . Expire_Date ! = null
& & x . Expire_Date . Value . AddMonths ( - 6 ) . Date < = DateTime . Now . Date
& & x . Expire_Date . Value . Date > = DateTime . Now . Date
select x ;
if ( foList . Count ( ) > 0 )
{
foreach ( var fo in foList )
{
List < Model . Sys_User > userList = new List < Sys_User > ( ) ;
EmailPop pops = Funs . DB . EmailPop . FirstOrDefault ( x = > x . EmailID = = BLL . Const . EmailPopId ) ;
if ( pops = = null )
{
return ;
}
string [ ] mailTo = null ;
string mailBody = string . Empty ;
string mailAttch = string . Empty ;
string mailCode = string . Empty ;
string mailPriority = string . Empty ;
string [ ] mailCC = null ;
string resultMessage = "" ;
string departId = string . Empty ;
var contractor = BLL . ContractorService . GetContractorById ( fo . Contractor ) ;
var discipline = BLL . DisciplineService . GetDisciplineById ( fo . DisciplineId ) ;
string disc = discipline . Discipline . Replace ( "\r\n" , " " ) ;
if ( ! string . IsNullOrEmpty ( discipline . DisciplineCN ) )
{
disc = disc + " " + discipline . DisciplineCN ;
}
mailCode = fo . FO_NO + "|" + disc + "|" + contractor . Contractor + " " + contractor . ContractorCN ;
var contractAdmin = from x in Funs . DB . Sys_User where x . UserId = = fo . Contract_Admin & & x . Email ! = null & & x . Email ! = "" select x ;
var buyer = from x in Funs . DB . Sys_User where x . UserName = = fo . Buyer & & x . Email ! = null & & x . Email ! = "" select x ;
if ( buyer . Count ( ) > 0 )
{
userList . Add ( buyer . First ( ) ) ;
mailCode = mailCode + "|" + buyer . First ( ) . UserName ;
}
else
{
mailCode = mailCode + "|" + "" ;
}
if ( contractAdmin . Count ( ) > 0 )
{
userList . Add ( contractAdmin . First ( ) ) ;
mailCode = mailCode + "|" + contractAdmin . First ( ) . UserName ;
}
else
{
mailCode = mailCode + "|" + "" ;
}
var mainCoor = from x in Funs . DB . Sys_User where x . UserId = = fo . Main_Coordinator & & x . Email ! = null & & x . Email ! = "" select x ;
if ( mainCoor . Count ( ) > 0 )
{
userList . Add ( mainCoor . First ( ) ) ;
mailCode = mailCode + "|" + mainCoor . First ( ) . UserName ;
string depId = mainCoor . First ( ) . DepartId ;
if ( ! string . IsNullOrEmpty ( depId ) )
{
string dep = BLL . DepartService . GetDepartNameById ( depId ) ;
if ( dep . Length > = 3 )
{
string departName = dep . Substring ( 0 , 3 ) ;
var d = BLL . DepartService . GetDepartByName ( departName ) ;
departId = d . DepartId ;
}
}
}
else
{
mailCode = mailCode + "|" + "" ;
}
var userRepresentative = from x in Funs . DB . Sys_User where x . UserId = = fo . User_Representative & & x . Email ! = null & & x . Email ! = "" select x ;
if ( userRepresentative . Count ( ) > 0 )
{
userList . Add ( userRepresentative . First ( ) ) ;
mailCode = mailCode + "|" + userRepresentative . First ( ) . UserName ;
}
else
{
mailCode = mailCode + "|" + "" ;
}
var cost = from x in Funs . DB . Sys_User
join y in Funs . DB . Sys_Role on x . RoleId equals y . RoleId
join z in Funs . DB . Base_Depart on x . DepartId equals z . DepartId
where ( y . RoleName = = "Cost Engineer Leader" | | y . RoleName = = "Contractor_Leader" | | z . DepartCode = = "CT/K" ) & & x . Email ! = null & & x . Email ! = ""
select x ;
if ( cost . Count ( ) > 0 )
{
foreach ( var c in cost )
{
userList . Add ( c ) ;
}
}
mailCode = mailCode + "|" + fo . Expire_Date . Value . ToShortDateString ( ) ;
var cc = from x in Funs . DB . Sys_User
join y in Funs . DB . Sys_Role on x . RoleId equals y . RoleId
where x . Email ! = null & & x . Email ! = ""
& & ( y . RoleName = = "CTE/D Manager" | | y . RoleName = = "Purchasing Manager" | | y . RoleName = = "CGP Director" | | ( y . RoleName = = "CT Director" & & x . DepartId = = departId ) )
select x ;
mailTo = userList . Select ( x = > x . Email ) . ToArray ( ) ;
mailCC = cc . Select ( x = > x . Email ) . ToArray ( ) ;
//var nowDate = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00");
//&& p.CreateTime.Value >= nowDate
var email = Funs . DB . SendEmail . Where ( p = > p . EmailStatus = = "发送成功"
& & p . EmailTile . Contains ( "到期提醒" ) & & p . EmailTile . Contains ( discipline . Discipline . Replace ( "\r\n" , "" ) )
& & p . EmailTile . Contains ( fo . FO_NO ) & & mailTo . Contains ( p . EmailURL ) ) . ToList ( ) ;
if ( email . Count > 0 )
{
var emailurl = email . Select ( p = > p . EmailURL ) . ToList ( ) ;
mailTo = mailTo . Where ( p = > ! emailurl . Contains ( p ) ) . ToArray ( ) ;
}
if ( mailTo ! = null & & mailTo . Length > 0 )
{
var EmailTemplate = Funs . DB . SendEmailTemplate . Where ( x = > x . EmailName . Contains ( "ExpiredSoon" ) ) ;
if ( EmailTemplate . Count ( ) > 0 )
{
string templetpath = EmailTemplate . Select ( p = > p . EmailContext ) . FirstOrDefault ( ) ;
NameValueCollection myCol = new NameValueCollection ( ) ;
mailBody = TemplateHelper . BulidByFile2 ( templetpath , myCol ) ;
IsComplite = MailHelper . SendNetMail1 ( pops , pops . EmailYx , mailTo , "工程维修施工合同-" + fo . FO_NO + ":" + discipline . Discipline . Replace ( "\r\n" , "" ) + " 到期提醒" , mailBody , mailAttch , mailCode , mailPriority , mailCC , null , out resultMessage ) ;
if ( IsComplite )
{
compMsg = compMsg + "合同:" + fo . FO_NO + ",专业:" + discipline . Discipline . Replace ( "\r\n" , "" ) + ",到期提醒邮件发送成功!" ;
}
else
{
errorMsg = errorMsg + "合同:" + fo . FO_NO + ",专业:" + discipline . Discipline . Replace ( "\r\n" , "" ) + ",到期提醒邮件发送失败!" ;
}
}
}
}
if ( compMsg = = string . Empty & & errorMsg = = string . Empty )
{
Alert . ShowInParent ( "过期提醒邮件已发送!" ) ;
}
else
{
Alert . ShowInParent ( compMsg + errorMsg ) ;
}
}
else
{
Alert . ShowInParent ( "无过期提醒邮件需发送!" ) ;
return ;
}
}
#endregion
#region 编 辑
/// <summary>
/// 编辑
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnEdit_Click ( object sender , EventArgs e )
{
if ( Grid1 . SelectedRowIndexArray . Length = = 0 )
{
Alert . ShowInParent ( "Please select at least one record!" ) ;
return ;
}
string Id = Grid1 . SelectedRowID ;
PageContext . RegisterStartupScript ( Window1 . GetShowReference ( String . Format ( "SESRelatedDataEdit.aspx?id={0}" , Id , "编辑 - " ) ) ) ;
}
/// <summary>
/// 右键编辑事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnMenuEdit_Click ( object sender , EventArgs e )
{
btnEdit_Click ( null , null ) ;
}
/// <summary>
/// Grid行双击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_RowDoubleClick ( object sender , GridRowClickEventArgs e )
{
btnEdit_Click ( null , null ) ;
}
#endregion
#region 判 断 是 否 可 删 除
/// <summary>
/// 判断是否可以删除
/// </summary>
/// <returns></returns>
private bool judgementDelete ( string id , bool isShow )
{
string content = string . Empty ;
//if (Funs.DB.Sys_User.FirstOrDefault(x => x.RoleId == id) != null)
//{
// content = "This role is already in use in [user information] and cannot be deleted!";
//}
if ( string . IsNullOrEmpty ( content ) )
{
return true ;
}
else
{
if ( isShow )
{
Alert . ShowInTop ( content ) ;
}
return false ;
}
}
#endregion
#region 导 出
/// <summary>
/// 导出按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnExport_Click ( object sender , EventArgs e )
{
string rootPath = Server . MapPath ( "~/" ) + Const . ExcelUrl ;
//模板文件
string TempletFileName = rootPath + "FC_List.xlsx" ;
//导出文件
string filePath = rootPath + DateTime . Now . ToString ( "yyyyMMddhhmmss" ) + "\\" ;
if ( ! Directory . Exists ( filePath ) )
{
Directory . CreateDirectory ( filePath ) ;
}
string ReportFileName = filePath + "out.xlsx" ;
FileStream file = new FileStream ( TempletFileName , FileMode . Open , FileAccess . Read ) ;
XSSFWorkbook hssfworkbook = new XSSFWorkbook ( file ) ;
#region FC_List
XSSFSheet reportModel = ( XSSFSheet ) hssfworkbook . GetSheet ( "FC_List" ) ;
IDataFormat dataformat = hssfworkbook . CreateDataFormat ( ) ;
ICellStyle styleQfw = hssfworkbook . CreateCellStyle ( ) ;
styleQfw . DataFormat = dataformat . GetFormat ( "#,##0.00" ) ;
ICellStyle styleDate = hssfworkbook . CreateCellStyle ( ) ;
styleDate . DataFormat = dataformat . GetFormat ( "yyyy/m/d" ) ;
XSSFFont cs_content_Font = ( XSSFFont ) hssfworkbook . CreateFont ( ) ; //创建字体
cs_content_Font . FontName = "sans-serif" ; //字体
cs_content_Font . FontHeightInPoints = 10 ; //字体大小
var list = ( from x in Funs . DB . View_FC_SESRelatedData orderby x . FC_Status descending select x ) . ToList ( ) ;
if ( ! string . IsNullOrEmpty ( hdConstRecords . Text . Trim ( ) ) )
{
list = list . Where ( x = > x . ConstRecords = = hdConstRecords . Text . Trim ( ) ) . ToList ( ) ;
}
if ( ! string . IsNullOrEmpty ( hdFoNo . Text . Trim ( ) ) )
{
list = list . Where ( x = > x . FO_NO . Contains ( hdFoNo . Text . Trim ( ) ) ) . ToList ( ) ;
}
if ( ! string . IsNullOrEmpty ( hdDiscipline . Text . Trim ( ) ) )
{
list = list . Where ( x = > x . DisciplineId = = hdDiscipline . Text . Trim ( ) ) . ToList ( ) ;
}
if ( ! string . IsNullOrEmpty ( this . hdContractor . Text . Trim ( ) ) )
{
list = list . Where ( x = > x . ContractorId . Contains ( hdContractor . Text . Trim ( ) ) ) . ToList ( ) ;
}
if ( ! string . IsNullOrEmpty ( this . hdContractAdmin . Text . Trim ( ) ) )
{
list = list . Where ( x = > x . Contract_AdminId . Contains ( hdContractAdmin . Text . Trim ( ) ) ) . ToList ( ) ;
}
if ( ! string . IsNullOrEmpty ( this . hdBuyer . Text . Trim ( ) ) )
{
list = list . Where ( x = > x . Buyer . Contains ( hdBuyer . Text . Trim ( ) ) ) . ToList ( ) ;
}
if ( ! string . IsNullOrEmpty ( this . hdMainCoord . Text . Trim ( ) ) )
{
list = list . Where ( x = > x . Main_CoordinatorId . Contains ( hdMainCoord . Text . Trim ( ) ) ) . ToList ( ) ;
}
if ( ! string . IsNullOrEmpty ( this . hdMCDepartment . Text . Trim ( ) ) )
{
list = list . Where ( x = > x . MCDept . Contains ( hdMCDepartment . Text . Trim ( ) ) ) . ToList ( ) ;
}
if ( ! string . IsNullOrEmpty ( this . hdFCStatus . Text . Trim ( ) ) )
{
if ( this . hdFCStatus . Text . Trim ( ) = = "Valid" )
{
list = list . Where ( x = > x . Expire_Date > DateTime . Now ) . ToList ( ) ;
}
else if ( this . hdFCStatus . Text . Trim ( ) = = "Expired Soon" )
{
list = list . Where ( x = > x . Expire_Date . Value . AddMonths ( - 6 ) < = DateTime . Now & & x . Expire_Date > DateTime . Now ) . ToList ( ) ;
}
else if ( this . hdFCStatus . Text . Trim ( ) = = "Expired" )
{
list = list . Where ( x = > x . Expire_Date < DateTime . Now ) . ToList ( ) ;
}
}
if ( list . Count > 0 )
{
var rowIndex = 1 ;
foreach ( var itemOver in list )
{
if ( reportModel . GetRow ( rowIndex ) = = null ) reportModel . CreateRow ( rowIndex ) ;
#region 列 赋 值
//FO No.
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 0 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 0 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 0 ) . SetCellValue ( itemOver . FO_NO . ToString ( ) ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 0 ) . CellStyle . SetFont ( cs_content_Font ) ; //将字体绑定到样式
//Discipline
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 1 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 1 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 1 ) . SetCellValue ( itemOver . Discipline ) ;
//Fo Type
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 2 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 2 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 2 ) . SetCellValue ( itemOver . FOType ) ;
//Pricing Scheme
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 3 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 3 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 3 ) . SetCellValue ( itemOver . Pricing_Scheme ) ;
//Contractor
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 4 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 4 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 4 ) . SetCellValue ( itemOver . Contractor ) ;
//Vendor NO.
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 5 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 5 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 5 ) . SetCellValue ( itemOver . Vendor_NO ) ;
//Item
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 6 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 6 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 6 ) . SetCellValue ( itemOver . Item ) ;
//Discipline Category
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 7 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 7 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 7 ) . SetCellValue ( itemOver . DisciplineCategory ) ;
//Currency
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 8 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 8 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 8 ) . SetCellValue ( itemOver . Currency ) ;
//Material Group
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 9 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 9 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 9 ) . SetCellValue ( itemOver . Material_Group ) ;
//Purchase Group
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 10 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 10 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 10 ) . SetCellValue ( itemOver . Purchase_Group ) ;
//Cost Element
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 11 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 11 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 11 ) . SetCellValue ( itemOver . Cost_Element ) ;
//Service Type
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 12 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 12 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 12 ) . SetCellValue ( itemOver . Type ) ;
//Contract Admin
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 13 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 13 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 13 ) . SetCellValue ( itemOver . Contract_Admin ) ;
//Cost_Checker
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 14 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 14 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 14 ) . SetCellValue ( itemOver . Cost_Checker ) ;
//Buyer
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 15 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 15 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 15 ) . SetCellValue ( itemOver . Buyer ) ;
//Main Coordinator
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 16 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 16 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 16 ) . SetCellValue ( itemOver . Main_Coordinator ) ;
//M.C.Dept.
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 17 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 17 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 17 ) . SetCellValue ( itemOver . MCDept ) ;
//User Representative
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 18 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 18 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 18 ) . SetCellValue ( itemOver . User_Representative ) ;
//Validate Date
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 19 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 19 ) ;
if ( itemOver . Validate_Date . HasValue )
{
reportModel . GetRow ( rowIndex ) . GetCell ( 19 ) . SetCellValue ( ( DateTime ) itemOver . Validate_Date . Value ) ; //string.Format("{0:yyyy/MM/dd}", itemOver.Validate_Date)
reportModel . GetRow ( rowIndex ) . GetCell ( 19 ) . CellStyle = styleDate ;
}
//Expire Date
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 20 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 20 ) ;
if ( itemOver . Expire_Date . HasValue )
{
reportModel . GetRow ( rowIndex ) . GetCell ( 20 ) . SetCellValue ( ( DateTime ) itemOver . Expire_Date . Value ) ; // string.Format("{0:yyyy/MM/dd}", itemOver.Expire_Date)
reportModel . GetRow ( rowIndex ) . GetCell ( 20 ) . CellStyle = styleDate ;
}
//FC Status
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 21 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 21 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 21 ) . SetCellValue ( itemOver . FC_Status ) ;
//Contact Person
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 22 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 22 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 22 ) . SetCellValue ( itemOver . Contract_Person ) ;
//Tel.
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 23 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 23 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 23 ) . SetCellValue ( itemOver . Contract_Tel ) ;
// Allocation
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 24 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 24 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 24 ) . SetCellValue ( itemOver . Allocation ! = null ? itemOver . Allocation : "" ) ;
//Volume Allocation
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 25 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 25 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 25 ) . SetCellValue ( itemOver . VolumeAllocation ! = null ? ( ( double ) itemOver . VolumeAllocation . Value * 100.0 ) . ToString ( "0.00" ) + "%" : "" ) ;
//Contract Budget
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 26 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 26 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 26 ) . SetCellValue ( itemOver . Actual_Budget ! = null ? ( double ) itemOver . Actual_Budget . Value : 0 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 26 ) . CellStyle = styleQfw ;
//Connected Transaction
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 27 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 27 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 27 ) . SetCellValue ( itemOver . Connectedtransaction ) ;
//Checked Value
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 28 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 28 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 28 ) . SetCellValue ( itemOver . CheckedValue ! = null ? ( double ) itemOver . CheckedValue . Value : 0 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 28 ) . CellStyle = styleQfw ;
//Remaining Budget
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 29 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 29 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 29 ) . SetCellValue ( itemOver . RemainingBudget ! = null ? ( double ) itemOver . RemainingBudget . Value : 0 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 29 ) . CellStyle = styleQfw ;
//Remaining Budget%
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 30 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 30 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 30 ) . SetCellValue ( itemOver . RemainingBudgetRate ) ;
//Remaining Duration%
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 31 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 31 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 31 ) . SetCellValue ( itemOver . RemainingDuration ) ;
//Email
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 32 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 32 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 32 ) . SetCellValue ( itemOver . Email ) ;
//主要负责人
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 33 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 33 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 33 ) . SetCellValue ( itemOver . MainHead ) ;
//主要负责人联系方式
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 34 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 34 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 34 ) . SetCellValue ( itemOver . MainHeadContact ) ;
//安全负责人
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 35 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 35 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 35 ) . SetCellValue ( itemOver . SafetyOfficer ) ;
//安全负责人联系方式
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 36 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 36 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 36 ) . SetCellValue ( itemOver . SafetyOfficerContact ) ;
//项目经理
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 37 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 37 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 37 ) . SetCellValue ( itemOver . ProjectManager ) ;
//项目经理联系方式
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 38 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 38 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 38 ) . SetCellValue ( itemOver . ProjectManagerContact ) ;
//Const.Records
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 39 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 39 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 39 ) . SetCellValue ( itemOver . ConstRecords ) ;
//Const.Records
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 40 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 40 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 40 ) . SetCellValue ( itemOver . Remark ) ;
#endregion
rowIndex + + ;
}
}
#endregion
reportModel . ForceFormulaRecalculation = true ;
using ( FileStream filess = 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=FC_List" + Server . UrlEncode ( DateTime . Now . ToString ( "yyyyMMddhhmmss" ) + ".xlsx" ) ) ;
// 添加头信息,指定文件大小,让浏览器能够显示下载进度
Response . AddHeader ( "Content-Length" , filet . Length . ToString ( ) ) ;
// 指定返回的是一个不能被客户端读取的流,必须被下载
Response . ContentType = "application/ms-excel" ;
// 把文件流发送到客户端
Response . WriteFile ( filet . FullName ) ;
// 停止页面的执行
Response . End ( ) ;
}
// 人员导出
protected void btnExport1_Click ( object sender , EventArgs e )
{
string rootPath = Server . MapPath ( "~/" ) + Const . ExcelUrl ;
//模板文件
string TempletFileName = rootPath + "FC_Contractor_Contact_Person_List.xlsx" ;
//导出文件
string filePath = rootPath + DateTime . Now . ToString ( "yyyyMMddhhmmss" ) + "\\" ;
if ( ! Directory . Exists ( filePath ) )
{
Directory . CreateDirectory ( filePath ) ;
}
string ReportFileName = filePath + "out.xlsx" ;
FileStream file = new FileStream ( TempletFileName , FileMode . Open , FileAccess . Read ) ;
XSSFWorkbook hssfworkbook = new XSSFWorkbook ( file ) ;
#region FC_List
XSSFSheet reportModel = ( XSSFSheet ) hssfworkbook . GetSheet ( "Sheet1" ) ;
XSSFFont cs_content_Font = ( XSSFFont ) hssfworkbook . CreateFont ( ) ; //创建字体
cs_content_Font . FontName = "sans-serif" ; //字体
cs_content_Font . FontHeightInPoints = 10 ; //字体大小
var list = ( from x in Funs . DB . View_FC_SESRelatedData where x . Type = = "现场服务类" & & ( x . FC_Status = = "Valid" | | x . FC_Status = = "Expired Soon" ) orderby x . FO_NO descending select x ) . ToList ( ) ;
if ( ! string . IsNullOrEmpty ( hdConstRecords . Text . Trim ( ) ) )
{
list = list . Where ( x = > x . ConstRecords = = hdConstRecords . Text . Trim ( ) ) . ToList ( ) ;
}
if ( ! string . IsNullOrEmpty ( hdFoNo . Text . Trim ( ) ) )
{
list = list . Where ( x = > x . FO_NO . Contains ( hdFoNo . Text . Trim ( ) ) ) . ToList ( ) ;
}
if ( ! string . IsNullOrEmpty ( hdDiscipline . Text . Trim ( ) ) )
{
list = list . Where ( x = > x . DisciplineId = = hdDiscipline . Text . Trim ( ) ) . ToList ( ) ;
}
if ( ! string . IsNullOrEmpty ( this . hdContractor . Text . Trim ( ) ) )
{
list = list . Where ( x = > x . ContractorId . Contains ( hdContractor . Text . Trim ( ) ) ) . ToList ( ) ;
}
if ( ! string . IsNullOrEmpty ( this . hdContractAdmin . Text . Trim ( ) ) )
{
list = list . Where ( x = > x . Contract_AdminId . Contains ( hdContractAdmin . Text . Trim ( ) ) ) . ToList ( ) ;
}
if ( ! string . IsNullOrEmpty ( this . hdBuyer . Text . Trim ( ) ) )
{
list = list . Where ( x = > x . Buyer . Contains ( hdBuyer . Text . Trim ( ) ) ) . ToList ( ) ;
}
if ( ! string . IsNullOrEmpty ( this . hdMainCoord . Text . Trim ( ) ) )
{
list = list . Where ( x = > x . Main_CoordinatorId . Contains ( hdMainCoord . Text . Trim ( ) ) ) . ToList ( ) ;
}
if ( ! string . IsNullOrEmpty ( this . hdMCDepartment . Text . Trim ( ) ) )
{
list = list . Where ( x = > x . MCDept . Contains ( hdMCDepartment . Text . Trim ( ) ) ) . ToList ( ) ;
}
if ( ! string . IsNullOrEmpty ( this . hdFCStatus . Text . Trim ( ) ) )
{
if ( this . hdFCStatus . Text . Trim ( ) = = "Valid" )
{
list = list . Where ( x = > x . Expire_Date > DateTime . Now ) . ToList ( ) ;
}
else if ( this . hdFCStatus . Text . Trim ( ) = = "Expired Soon" )
{
list = list . Where ( x = > x . Expire_Date . Value . AddMonths ( - 6 ) < = DateTime . Now & & x . Expire_Date > DateTime . Now ) . ToList ( ) ;
}
else if ( this . hdFCStatus . Text . Trim ( ) = = "Expired" )
{
list = list . Where ( x = > x . Expire_Date < DateTime . Now ) . ToList ( ) ;
}
}
if ( list . Count > 0 )
{
var rowIndex = 1 ;
foreach ( var itemOver in list )
{
if ( reportModel . GetRow ( rowIndex ) = = null ) reportModel . CreateRow ( rowIndex ) ;
#region 列 赋 值
//Discipline
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 0 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 0 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 0 ) . SetCellValue ( itemOver . Discipline ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 0 ) . CellStyle . SetFont ( cs_content_Font ) ; //将字体绑定到样式
//Contractor
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 1 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 1 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 1 ) . SetCellValue ( itemOver . Contractor ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 1 ) . CellStyle . SetFont ( cs_content_Font ) ; //将字体绑定到样式
//FO No.
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 2 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 2 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 2 ) . SetCellValue ( itemOver . FO_NO . ToString ( ) ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 2 ) . CellStyle . SetFont ( cs_content_Font ) ; //将字体绑定到样式
//Contract Admin
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 3 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 3 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 3 ) . SetCellValue ( itemOver . Contract_Admin ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 3 ) . CellStyle . SetFont ( cs_content_Font ) ; //将字体绑定到样式
//Buyer
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 4 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 4 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 4 ) . SetCellValue ( itemOver . Buyer ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 4 ) . CellStyle . SetFont ( cs_content_Font ) ; //将字体绑定到样式
//Main Coordinator
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 5 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 5 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 5 ) . SetCellValue ( itemOver . Main_Coordinator ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 5 ) . CellStyle . SetFont ( cs_content_Font ) ; //将字体绑定到样式
//User Representative
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 6 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 6 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 6 ) . SetCellValue ( itemOver . User_Representative ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 6 ) . CellStyle . SetFont ( cs_content_Font ) ; //将字体绑定到样式
//Service Type
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 7 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 7 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 7 ) . SetCellValue ( itemOver . Type ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 7 ) . CellStyle . SetFont ( cs_content_Font ) ; //将字体绑定到样式
//合同联系人
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 8 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 8 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 8 ) . SetCellValue ( itemOver . Contract_Person ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 8 ) . CellStyle . SetFont ( cs_content_Font ) ; //将字体绑定到样式
//联系方式
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 9 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 9 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 9 ) . SetCellValue ( itemOver . Contract_Tel ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 9 ) . CellStyle . SetFont ( cs_content_Font ) ; //将字体绑定到样式
//eMail
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 10 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 10 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 10 ) . SetCellValue ( itemOver . Email ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 10 ) . CellStyle . SetFont ( cs_content_Font ) ; //将字体绑定到样式
//主要负责人
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 11 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 11 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 11 ) . SetCellValue ( itemOver . MainHead ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 11 ) . CellStyle . SetFont ( cs_content_Font ) ; //将字体绑定到样式
//主要负责人联系方式
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 12 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 12 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 12 ) . SetCellValue ( itemOver . MainHeadContact ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 12 ) . CellStyle . SetFont ( cs_content_Font ) ; //将字体绑定到样式
//安全负责人
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 13 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 13 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 13 ) . SetCellValue ( itemOver . SafetyOfficer ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 13 ) . CellStyle . SetFont ( cs_content_Font ) ; //将字体绑定到样式
//安全负责人联系方式
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 14 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 14 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 14 ) . SetCellValue ( itemOver . SafetyOfficerContact ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 14 ) . CellStyle . SetFont ( cs_content_Font ) ; //将字体绑定到样式
//项目经理
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 15 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 15 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 15 ) . SetCellValue ( itemOver . ProjectManager ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 15 ) . CellStyle . SetFont ( cs_content_Font ) ; //将字体绑定到样式
//项目经理联系方式
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 16 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 16 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 16 ) . SetCellValue ( itemOver . ProjectManagerContact ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 16 ) . CellStyle . SetFont ( cs_content_Font ) ; //将字体绑定到样式
#endregion
rowIndex + + ;
}
}
#endregion
reportModel . ForceFormulaRecalculation = true ;
using ( FileStream filess = 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=FC_Contractor_Contact_Person_List" + Server . UrlEncode ( DateTime . Now . ToString ( "yyyyMMddhhmmss" ) + ".xlsx" ) ) ;
// 添加头信息,指定文件大小,让浏览器能够显示下载进度
Response . AddHeader ( "Content-Length" , filet . Length . ToString ( ) ) ;
// 指定返回的是一个不能被客户端读取的流,必须被下载
Response . ContentType = "application/ms-excel" ;
// 把文件流发送到客户端
Response . WriteFile ( filet . FullName ) ;
// 停止页面的执行
Response . End ( ) ;
}
protected void btnFoExport_Click ( object sender , EventArgs e )
{
string rootPath = Server . MapPath ( "~/" ) + Const . ExcelUrl ;
//模板文件
string TempletFileName = rootPath + "FO Report.xlsx" ;
//导出文件
string filePath = rootPath + DateTime . Now . ToString ( "yyyyMMddhhmmss" ) + "\\" ;
if ( ! Directory . Exists ( filePath ) )
{
Directory . CreateDirectory ( filePath ) ;
}
string ReportFileName = filePath + "out.xlsx" ;
FileStream file = new FileStream ( TempletFileName , FileMode . Open , FileAccess . Read ) ;
XSSFWorkbook hssfworkbook = new XSSFWorkbook ( file ) ;
#region FO Report
XSSFSheet reportModel = ( XSSFSheet ) hssfworkbook . GetSheet ( "Sheet1" ) ;
IDataFormat dataformat = hssfworkbook . CreateDataFormat ( ) ;
ICellStyle styleQfw = hssfworkbook . CreateCellStyle ( ) ;
styleQfw . DataFormat = dataformat . GetFormat ( "#,##0.00" ) ;
ICellStyle styleDate = hssfworkbook . CreateCellStyle ( ) ;
styleDate . DataFormat = dataformat . GetFormat ( "yyyy/m/d" ) ;
XSSFFont cs_content_Font = ( XSSFFont ) hssfworkbook . CreateFont ( ) ; //创建字体
cs_content_Font . FontName = "sans-serif" ; //字体
cs_content_Font . FontHeightInPoints = 10 ; //字体大小
var list = ( from x in Funs . DB . View_FC_Report orderby x . FC_Status descending select x ) . ToList ( ) ;
if ( ! string . IsNullOrEmpty ( hdConstRecords . Text . Trim ( ) ) )
{
list = list . Where ( x = > x . ConstRecords = = hdConstRecords . Text . Trim ( ) ) . ToList ( ) ;
}
if ( ! string . IsNullOrEmpty ( hdFoNo . Text . Trim ( ) ) )
{
list = list . Where ( x = > x . FO_NO . Contains ( hdFoNo . Text . Trim ( ) ) ) . ToList ( ) ;
}
if ( ! string . IsNullOrEmpty ( hdDiscipline . Text . Trim ( ) ) )
{
list = list . Where ( x = > x . DisciplineId = = hdDiscipline . Text . Trim ( ) ) . ToList ( ) ;
}
if ( ! string . IsNullOrEmpty ( this . hdContractor . Text . Trim ( ) ) )
{
list = list . Where ( x = > x . ContractorId . Contains ( hdContractor . Text . Trim ( ) ) ) . ToList ( ) ;
}
if ( ! string . IsNullOrEmpty ( this . hdContractAdmin . Text . Trim ( ) ) )
{
list = list . Where ( x = > x . Contract_AdminId . Contains ( hdContractAdmin . Text . Trim ( ) ) ) . ToList ( ) ;
}
if ( ! string . IsNullOrEmpty ( this . hdBuyer . Text . Trim ( ) ) )
{
list = list . Where ( x = > x . Buyer . Contains ( hdBuyer . Text . Trim ( ) ) ) . ToList ( ) ;
}
if ( ! string . IsNullOrEmpty ( this . hdMainCoord . Text . Trim ( ) ) )
{
list = list . Where ( x = > x . Main_CoordinatorId . Contains ( hdMainCoord . Text . Trim ( ) ) ) . ToList ( ) ;
}
if ( ! string . IsNullOrEmpty ( this . hdMCDepartment . Text . Trim ( ) ) )
{
list = list . Where ( x = > x . MCDept . Contains ( hdMCDepartment . Text . Trim ( ) ) ) . ToList ( ) ;
}
if ( ! string . IsNullOrEmpty ( this . hdFCStatus . Text . Trim ( ) ) )
{
if ( this . hdFCStatus . Text . Trim ( ) = = "Valid" )
{
list = list . Where ( x = > x . Expire_Date > DateTime . Now ) . ToList ( ) ;
}
else if ( this . hdFCStatus . Text . Trim ( ) = = "Expired Soon" )
{
list = list . Where ( x = > x . Expire_Date . Value . AddMonths ( - 6 ) < = DateTime . Now & & x . Expire_Date > DateTime . Now ) . ToList ( ) ;
}
else if ( this . hdFCStatus . Text . Trim ( ) = = "Expired" )
{
list = list . Where ( x = > x . Expire_Date < DateTime . Now ) . ToList ( ) ;
}
}
if ( list . Count > 0 )
{
var rowIndex = 1 ;
foreach ( var itemOver in list )
{
if ( reportModel . GetRow ( rowIndex ) = = null ) reportModel . CreateRow ( rowIndex ) ;
#region 列 赋 值
//FO No.
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 0 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 0 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 0 ) . SetCellValue ( itemOver . FO_NO . ToString ( ) ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 0 ) . CellStyle . SetFont ( cs_content_Font ) ; //将字体绑定到样式
//Contractor
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 1 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 1 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 1 ) . SetCellValue ( itemOver . Contractor ) ;
//Discipline
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 2 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 2 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 2 ) . SetCellValue ( itemOver . Discipline ) ;
//Contract_Admin
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 3 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 3 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 3 ) . SetCellValue ( itemOver . Contract_Admin ) ;
//Buyer
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 4 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 4 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 4 ) . SetCellValue ( itemOver . Buyer ) ;
//Main_Coordinator
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 5 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 5 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 5 ) . SetCellValue ( itemOver . Main_Coordinator ) ;
//M.C.Dept
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 6 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 6 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 6 ) . SetCellValue ( itemOver . MCDept ) ;
//Budget
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 7 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 7 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 7 ) . SetCellValue ( itemOver . Budget ! = null ? ( double ) itemOver . Budget . Value : 0 ) ;
//Actual_Cost
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 8 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 8 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 8 ) . SetCellValue ( itemOver . Actual_Cost ! = null ? ( double ) itemOver . Actual_Cost . Value : 0 ) ;
//Commitment
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 9 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 9 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 9 ) . SetCellValue ( itemOver . Commitment ! = null ? ( double ) itemOver . Commitment . Value : 0 ) ;
//Spending_commitment
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 10 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 10 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 10 ) . SetCellValue ( itemOver . Spending_commitment ! = null ? ( double ) itemOver . Spending_commitment . Value : 0 ) ;
//Validate Date
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 11 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 11 ) ;
if ( itemOver . Validate_Date . HasValue )
{
reportModel . GetRow ( rowIndex ) . GetCell ( 11 ) . SetCellValue ( ( DateTime ) itemOver . Validate_Date . Value ) ; //string.Format("{0:yyyy/MM/dd}", itemOver.Validate_Date)
reportModel . GetRow ( rowIndex ) . GetCell ( 11 ) . CellStyle = styleDate ;
}
//Expire Date
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 12 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 12 ) ;
if ( itemOver . Expire_Date . HasValue )
{
reportModel . GetRow ( rowIndex ) . GetCell ( 12 ) . SetCellValue ( ( DateTime ) itemOver . Expire_Date . Value ) ; // string.Format("{0:yyyy/MM/dd}", itemOver.Expire_Date)
reportModel . GetRow ( rowIndex ) . GetCell ( 12 ) . CellStyle = styleDate ;
}
//UnusedBudget
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 13 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 13 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 13 ) . SetCellValue ( itemOver . UnusedBudget ! = null ? ( double ) itemOver . UnusedBudget . Value : 0 ) ;
//UnusedBudgetRate
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 14 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 14 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 14 ) . SetCellValue ( itemOver . UnusedBudgetRate ) ;
//Volume_Allocation
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 15 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 15 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 15 ) . SetCellValue ( itemOver . Volume_Allocation ) ;
//Target_Volume
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 16 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 16 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 16 ) . SetCellValue ( itemOver . Target_Volume ) ;
//Actual_Volume
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 17 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 17 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 17 ) . SetCellValue ( itemOver . Actual_Volume ) ;
//Volume_Deviation
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 18 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 18 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 18 ) . SetCellValue ( itemOver . Volume_Deviation ) ;
//Volume_allocation_deviation
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 19 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 19 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 19 ) . SetCellValue ( itemOver . Volume_allocation_deviation ) ;
//Budget_Running_out
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 20 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 20 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 20 ) . SetCellValue ( itemOver . Budget_Running_out ) ;
//Budget_progress_VS_Time
if ( reportModel . GetRow ( rowIndex ) . GetCell ( 21 ) = = null ) reportModel . GetRow ( rowIndex ) . CreateCell ( 21 ) ;
reportModel . GetRow ( rowIndex ) . GetCell ( 21 ) . SetCellValue ( itemOver . Budget_progress_VS_Time ) ;
#endregion
rowIndex + + ;
}
}
#endregion
reportModel . ForceFormulaRecalculation = true ;
using ( FileStream filess = 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=FO Report" + Server . UrlEncode ( DateTime . Now . ToString ( "yyyyMMddhhmmss" ) + ".xlsx" ) ) ;
// 添加头信息,指定文件大小,让浏览器能够显示下载进度
Response . AddHeader ( "Content-Length" , filet . Length . ToString ( ) ) ;
// 指定返回的是一个不能被客户端读取的流,必须被下载
Response . ContentType = "application/ms-excel" ;
// 把文件流发送到客户端
Response . WriteFile ( filet . FullName ) ;
// 停止页面的执行
Response . End ( ) ;
}
protected void btnNCRExport_Click ( object sender , EventArgs e )
{
string rootPath = Server . MapPath ( "~/" ) + Const . ExcelUrl ;
//导出文件
string filePath = rootPath + DateTime . Now . ToString ( "yyyyMMddhhmmss" ) + "\\" ;
if ( ! Directory . Exists ( filePath ) )
{
Directory . CreateDirectory ( filePath ) ;
}
string ReportFileName = filePath + "out1.xlsx" ;
int rowIndex = 0 ;
XSSFWorkbook hssfworkbook = new XSSFWorkbook ( ) ;
//XSSFSheet ws = (XSSFSheet)hssfworkbook.CreateSheet("NCR报表");
string reportName = string . Empty ;
var foList = from x in Funs . DB . FC_SESRelatedData orderby x . FC_Status descending select x ;
var fileType = from x in Funs . DB . Base_FileType orderby x . FileType select x ;
if ( drpExportFileType . SelectedValue ! = Const . _Null )
{
XSSFSheet ws = ( XSSFSheet ) hssfworkbook . CreateSheet ( drpExportFileType . SelectedText ) ;
reportName = drpExportFileType . SelectedText ;
ws . SetColumnWidth ( 0 , ( 10 * 256 ) ) ; //4.77
ws . SetColumnWidth ( 1 , ( 8 * 256 ) ) ; //6.62
var fy = BLL . FileTypeService . GetFileTypeById ( drpExportFileType . SelectedValue ) ;
// 头部 第0行
if ( ws . GetRow ( rowIndex ) = = null ) ws . CreateRow ( rowIndex ) ;
if ( ws . GetRow ( rowIndex ) . GetCell ( 0 ) = = null ) ws . GetRow ( rowIndex ) . CreateCell ( 0 ) ;
ws . GetRow ( rowIndex ) . GetCell ( 0 ) . SetCellValue ( "FO合同号" ) ;
if ( ws . GetRow ( rowIndex ) . GetCell ( 1 ) = = null ) ws . GetRow ( rowIndex ) . CreateCell ( 1 ) ;
ws . GetRow ( rowIndex ) . GetCell ( 1 ) . SetCellValue ( fy . FileType ) ;
//数据行
foreach ( var q in foList )
{
rowIndex = rowIndex + 1 ;
if ( ws . GetRow ( rowIndex ) = = null ) ws . CreateRow ( rowIndex ) ;
if ( ws . GetRow ( rowIndex ) . GetCell ( 0 ) = = null ) ws . GetRow ( rowIndex ) . CreateCell ( 0 ) ;
ws . GetRow ( rowIndex ) . GetCell ( 0 ) . SetCellValue ( q . FO_NO ) ;
var conFile = from x in Funs . DB . FC_ContractManagement where x . FC_ID = = q . ID & & x . FileTypeId = = drpExportFileType . SelectedValue select x ;
if ( ws . GetRow ( rowIndex ) . GetCell ( 1 ) = = null ) ws . GetRow ( rowIndex ) . CreateCell ( 1 ) ;
if ( conFile . Count ( ) > 0 )
{
ws . GetRow ( rowIndex ) . GetCell ( 1 ) . SetCellValue ( "有" ) ;
}
else
{
ws . GetRow ( rowIndex ) . GetCell ( 1 ) . SetCellValue ( "无" ) ;
}
}
}
else
{
XSSFSheet ws = ( XSSFSheet ) hssfworkbook . CreateSheet ( "Sheet1" ) ;
reportName = "Report" ;
#region 列 宽
for ( int i = 0 ; i < = fileType . Count ( ) ; i + + )
{
if ( i = = 0 )
{
ws . SetColumnWidth ( i , ( 10 * 256 ) ) ; //4.77
}
else
{
ws . SetColumnWidth ( i , ( 8 * 256 ) ) ; //6.62
}
}
#endregion
// 头部 第0行
if ( ws . GetRow ( rowIndex ) = = null ) ws . CreateRow ( rowIndex ) ;
if ( ws . GetRow ( rowIndex ) . GetCell ( 0 ) = = null ) ws . GetRow ( rowIndex ) . CreateCell ( 0 ) ;
ws . GetRow ( rowIndex ) . GetCell ( 0 ) . SetCellValue ( "FO合同号" ) ;
int ic = 1 ;
foreach ( var fy in fileType )
{
if ( ws . GetRow ( rowIndex ) . GetCell ( ic ) = = null ) ws . GetRow ( rowIndex ) . CreateCell ( ic ) ;
ws . GetRow ( rowIndex ) . GetCell ( ic ) . SetCellValue ( fy . FileType ) ;
ic + + ;
}
//数据行
foreach ( var q in foList )
{
rowIndex = rowIndex + 1 ;
if ( ws . GetRow ( rowIndex ) = = null ) ws . CreateRow ( rowIndex ) ;
if ( ws . GetRow ( rowIndex ) . GetCell ( 0 ) = = null ) ws . GetRow ( rowIndex ) . CreateCell ( 0 ) ;
ws . GetRow ( rowIndex ) . GetCell ( 0 ) . SetCellValue ( q . FO_NO ) ;
int icr = 1 ;
foreach ( var fy in fileType )
{
var conFile = from x in Funs . DB . FC_ContractManagement where x . FC_ID = = q . ID & & x . FileTypeId = = fy . FileTypeId select x ;
if ( ws . GetRow ( rowIndex ) . GetCell ( icr ) = = null ) ws . GetRow ( rowIndex ) . CreateCell ( icr ) ;
if ( conFile . Count ( ) > 0 )
{
ws . GetRow ( rowIndex ) . GetCell ( icr ) . SetCellValue ( "有" ) ;
}
else
{
ws . GetRow ( rowIndex ) . GetCell ( icr ) . SetCellValue ( "无" ) ;
}
icr + + ;
}
}
}
using ( FileStream filess = 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=" + reportName + "_" + Server . UrlEncode ( DateTime . Now . ToString ( "yyyyMMddhhmmss" ) + ".xlsx" ) ) ;
// 添加头信息,指定文件大小,让浏览器能够显示下载进度
Response . AddHeader ( "Content-Length" , filet . Length . ToString ( ) ) ;
// 指定返回的是一个不能被客户端读取的流,必须被下载
Response . ContentType = "application/ms-excel" ;
// 把文件流发送到客户端
Response . WriteFile ( filet . FullName ) ;
// 停止页面的执行
Response . End ( ) ;
}
/// <summary>
/// 根据sql获取数据
/// </summary>
/// <param name="strSql"></param>
/// <param name="tableName"></param>
/// <param name="parameters"></param>
/// <returns></returns>
public static DataTable GetDataTableNameRunText ( string strSql , string tableName = "" , params SqlParameter [ ] parameters )
{
DataTable dataTable = string . IsNullOrEmpty ( tableName ) ? new DataTable ( ) : new DataTable ( tableName ) ;
using ( SqlConnection Connection = new SqlConnection ( Funs . ConnString ) )
{
try
{
Connection . Open ( ) ;
SqlCommand command = new SqlCommand ( strSql , Connection ) ;
command . CommandType = CommandType . Text ;
if ( parameters ! = null )
{
command . Parameters . AddRange ( parameters ) ;
}
SqlDataAdapter adapter = new SqlDataAdapter ( command ) ;
adapter . Fill ( dataTable ) ;
}
finally
{
Connection . Close ( ) ;
}
}
return dataTable ;
}
#endregion
#region 权 限 设 置
/// <summary>
/// 菜单按钮权限
/// </summary>
private void GetButtonPower ( )
{
var buttonList = BLL . CommonService . GetAllButtonList ( this . CurrUser . UserId , BLL . Const . SESRelatedDateMenuId ) ;
if ( buttonList . Count ( ) > 0 )
{
if ( buttonList . Contains ( BLL . Const . BtnAdd ) )
{
this . btnNew . Hidden = false ;
}
if ( buttonList . Contains ( BLL . Const . BtnModify ) )
{
this . btnEdit . Hidden = false ;
this . btnMenuEdit . Hidden = false ;
}
if ( buttonList . Contains ( BLL . Const . BtnDelete ) )
{
this . btnDelete . Hidden = false ;
this . btnMenuDelete . Hidden = false ;
}
if ( buttonList . Contains ( BLL . Const . BtnSend ) )
{
this . btnSendEmail . Hidden = false ;
}
if ( buttonList . Contains ( BLL . Const . BtnBatchDownload ) )
{
drpDownloadType . Hidden = false ;
this . btnBatchDownload . Hidden = false ;
}
else
{
drpDownloadType . Hidden = true ;
}
if ( buttonList . Contains ( BLL . Const . BtnSave ) )
{
this . Grid1 . EnableRowDoubleClickEvent = true ;
}
else
{
this . Grid1 . EnableRowDoubleClickEvent = false ;
}
#region 合 同 权 限
if ( buttonList . Contains ( BLL . Const . BtnSignedAdd ) )
{
this . btnAddFile2 . Hidden = false ;
}
if ( buttonList . Contains ( BLL . Const . BtnSignedModify ) )
{
this . btnMenuEdit2 . Hidden = false ;
this . Grid2 . EnableRowDoubleClickEvent = true ;
}
else
{
this . Grid2 . EnableRowDoubleClickEvent = false ;
}
if ( buttonList . Contains ( BLL . Const . BtnSignedDelete ) )
{
this . btnMenuDelete2 . Hidden = false ;
}
if ( buttonList . Contains ( BLL . Const . BtnSignedView ) )
{
TabSigned . Hidden = false ;
}
else
{
TabSigned . Hidden = true ;
}
if ( buttonList . Contains ( BLL . Const . BtnManageAdd ) )
{
this . btnAddFile3 . Hidden = false ;
}
if ( buttonList . Contains ( BLL . Const . BtnManageModify ) )
{
this . btnMenuEdit3 . Hidden = false ;
this . Grid3 . EnableRowDoubleClickEvent = true ;
}
else
{
this . Grid3 . EnableRowDoubleClickEvent = false ;
}
if ( buttonList . Contains ( BLL . Const . BtnManageDelete ) )
{
this . btnMenuDelete3 . Hidden = false ;
}
if ( buttonList . Contains ( BLL . Const . BtnManageView ) )
{
TabManagement . Hidden = false ;
}
else
{
TabManagement . Hidden = true ;
}
#endregion
if ( buttonList . Contains ( BLL . Const . BtnOut ) )
2024-09-18 10:36:26 +08:00
{
this . btnNCRExport . Hidden = false ;
}
if ( buttonList . Contains ( BLL . Const . FCExport ) )
2024-05-08 10:17:02 +08:00
{
this . btnExport . Hidden = false ;
}
2024-09-18 10:36:26 +08:00
if ( buttonList . Contains ( BLL . Const . PersonExport ) )
{
this . btnExport1 . Hidden = false ;
}
if ( buttonList . Contains ( BLL . Const . FoExport ) )
{
this . btnFoExport . Hidden = false ;
}
2024-05-08 10:17:02 +08:00
}
}
#endregion
#region 打 印
///// <summary>
///// 打印
///// </summary>
///// <param name="sender"></param>
///// <param name="e"></param>
//protected void btnPrint_Click(object sender, EventArgs e)
//{
// if (Grid1.SelectedRowIndexArray.Length == 0)
// {
// Alert.ShowInParent("Please select at least one record!");
// return;
// }
// string ContractNo = Grid1.SelectedRow.Values[1].ToString();
// string sData = StartTime.Text;
// string eData = EndTime.Text;
// PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("../Report/ReportPrint.aspx?report=4&fcid=" + ContractNo + "&sData=" + sData + "&eData=" + eData + "", "Print - ")));
//}
#endregion
#region 行 绑 定 后 事 件
/// <summary>
/// 行绑定后事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_RowDataBound ( object sender , GridRowEventArgs e )
{
DataRowView row = e . DataItem as DataRowView ;
string id = row [ "ID" ] . ToString ( ) ;
//for (int i = 0; i < this.Grid1.Rows.Count; i++)
//{
if ( ! string . IsNullOrEmpty ( id ) )
{
var data = BLL . SESRelatedDataService . GetSESRelatedDataById ( id ) ;
if ( data ! = null )
{
if ( data . Expire_Date . HasValue )
{
if ( data . Expire_Date < DateTime . Now ) //过期
{
e . RowCssClass = "color2" ;
}
else if ( data . Expire_Date . Value . AddMonths ( - 6 ) < = DateTime . Now & & data . Expire_Date > DateTime . Now ) //六个月后过期
{
e . RowCssClass = "color1" ;
}
}
if ( data . FC_Status = = "Closed" )
{
e . RowCssClass = "color2" ;
}
//Remaining Budget/Contract Budget<10 显示红色
var checkedValue = BLL . SESReportService . getSumSSRActualCostByFo ( data . FO_NO ) ;
var remainmingBudget = data . Actual_Budget - checkedValue ;
if ( data . Actual_Budget > 0 )
{
var remainmingBudgetRate = remainmingBudget / data . Actual_Budget * 100 ;
if ( remainmingBudgetRate < 10 )
{
e . CellCssClasses [ 30 ] = "colorRed" ;
}
}
//如果(合同过期日-今天)/(合同生效总天数)<10显示红色
if ( data . Validate_Date . HasValue & & data . Expire_Date . HasValue )
{
decimal a = ( data . Expire_Date - DateTime . Now ) . Value . Days ;
decimal b = ( data . Expire_Date - data . Validate_Date ) . Value . Days ; //合同生效总天数
if ( b > 0 )
{
decimal c = a / b * 100 ;
if ( c < 10 )
{
e . CellCssClasses [ 31 ] = "colorRed" ;
}
}
}
}
}
//}
}
#endregion
#region 查 询
/// <summary>
/// 查询
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSearch_Click ( object sender , EventArgs e )
{
string s = this . hdConstRecords . Text . Trim ( ) + "|" +
this . hdFoNo . Text . Trim ( ) + "|" +
this . hdDiscipline . Text . Trim ( ) + "|" +
this . hdContractor . Text . Trim ( ) + "|" +
this . hdContractAdmin . Text . Trim ( ) + "|" +
this . hdBuyer . Text . Trim ( ) + "|" +
this . hdMainCoord . Text . Trim ( ) + "|" +
this . hdMCDepartment . Text . Trim ( ) + "|" +
this . hdFCStatus . Text . Trim ( ) + "|" +
this . hdFoType . Text . Trim ( ) + "|" ;
string window = String . Format ( "SESRelatedDataSearch.aspx?s={0}" , s , "查询 - " ) ;
PageContext . RegisterStartupScript ( Window3 . GetSaveStateReference ( hdItemsString . ClientID ) + Window3 . GetShowReference ( window ) ) ;
}
/// <summary>
/// 查询返回值
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Window3_Close ( object sender , WindowCloseEventArgs e )
{
List < string > lists = Funs . GetStrListByStr ( hdItemsString . Text , '|' ) ;
this . hdConstRecords . Text = lists [ 0 ] ;
this . hdFoNo . Text = lists [ 1 ] ;
this . hdDiscipline . Text = lists [ 2 ] ;
this . hdContractor . Text = lists [ 3 ] ;
this . hdContractAdmin . Text = lists [ 4 ] ;
this . hdBuyer . Text = lists [ 5 ] ;
this . hdMainCoord . Text = lists [ 6 ] ;
this . hdMCDepartment . Text = lists [ 7 ] ;
this . hdFCStatus . Text = lists [ 8 ] ;
this . hdFoType . Text = lists [ 9 ] ;
BindGrid ( ) ;
}
#endregion
#region 查 看
/// <summary>
/// 查看
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnMenuView_Click ( object sender , EventArgs e )
{
if ( Grid1 . SelectedRowIndexArray . Length = = 0 )
{
Alert . ShowInParent ( "Please select at least one record!" ) ;
return ;
}
string Id = Grid1 . SelectedRowID ;
PageContext . RegisterStartupScript ( Window1 . GetShowReference ( String . Format ( "SESRelatedDataEdit.aspx?id={0}&view=1" , Id , "编辑 - " ) ) ) ;
}
#endregion
#region Grid行点击事件
/// <summary>
///Grid行点击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_RowSelect ( object sender , GridRowSelectEventArgs e )
{
this . hdID . Text = this . Grid1 . SelectedRowID ;
if ( ! string . IsNullOrEmpty ( this . hdID . Text ) )
{
var sESRelatedData = BLL . SESRelatedDataService . GetSESRelatedDataById ( this . hdID . Text ) ;
if ( sESRelatedData ! = null )
{
GetButtonPower ( ) ; //权限设置
string cruUser = CurrUser . UserId ;
string [ ] mcdeptLeader = null ;
if ( ! string . IsNullOrEmpty ( sESRelatedData . Applicant ) )
{
string depName = string . Empty ;
if ( sESRelatedData . Applicant . Contains ( "/" ) )
{
depName = sESRelatedData . Applicant . Split ( '/' ) [ 0 ] ;
}
else
{
depName = sESRelatedData . Applicant ;
}
var dep = from x in Funs . DB . Base_Depart where ( x . DepartName = = depName | | x . DepartName = = sESRelatedData . Applicant ) & & x . DepartLeader ! = null select x ;
if ( dep . Count ( ) > 0 )
{
if ( ! string . IsNullOrEmpty ( dep . First ( ) . DepartLeader ) )
{
mcdeptLeader = dep . Select ( x = > x . DepartLeader ) . ToArray ( ) ;
}
}
}
if ( ( ! string . IsNullOrEmpty ( sESRelatedData . User_Representative ) & & sESRelatedData . User_Representative . Contains ( cruUser ) ) | | ( ! string . IsNullOrEmpty ( sESRelatedData . Main_Coordinator ) & & sESRelatedData . Main_Coordinator . Contains ( cruUser ) ) | | ( mcdeptLeader ! = null & & mcdeptLeader . Contains ( cruUser ) ) | | cruUser = = Const . GlyId )
{
TabSigned . Hidden = false ;
TabManagement . Hidden = false ;
this . TabStrip1 . ActiveTabIndex = 0 ;
}
var foType = BLL . FOTypeService . GetFoTypeById ( sESRelatedData . FOTypeId ) ;
if ( foType ! = null & & foType . FOType . Contains ( "TAR" ) )
{
var buttonList = BLL . CommonService . GetAllButtonList ( this . CurrUser . UserId , BLL . Const . SESRelatedDateMenuId ) ;
if ( buttonList . Contains ( Const . BtnTARSignedView ) )
{
TabSigned . Hidden = false ;
}
if ( buttonList . Contains ( Const . BtnTARManageView ) )
{
TabManagement . Hidden = false ;
}
this . TabStrip1 . ActiveTabIndex = 0 ;
}
if ( this . TabStrip1 . ActiveTabIndex = = 0 )
{
BindGrid2 ( this . hdID . Text ) ;
}
else if ( this . TabStrip1 . ActiveTabIndex = = 1 )
{
BindGrid3 ( this . hdID . Text ) ;
}
}
}
}
#endregion
#region 数 据 绑 定
/// <summary>
/// Grid2数据绑定
/// </summary>
/// <param name="id"></param>
private void BindGrid2 ( string id )
{
string strSql = @ "SELECT Signed.FileId,
Signed . FC_ID ,
Signed . FileName ,
( CASE Signed . FileType WHEN '1' THEN ' 合 同 ' WHEN '2' THEN ' 变 更 的 合 同 ' END ) AS FileType ,
Signed . FileTypeCode ,
Signed . UploadMan ,
Signed . UploadDate ,
Signed . Remark ,
Signed . AttachUrl ,
U . UserName AS UploadManName
FROM FC_SignedContracts AS Signed
LEFT JOIN Sys_User AS U ON U . UserId = Signed . UploadMan
WHERE Signed . FC_ID = @id ";
List < SqlParameter > listStr = new List < SqlParameter > ( ) ;
listStr . Add ( new SqlParameter ( "@id" , id ) ) ;
if ( drpFileType2 . SelectedValue ! = Const . _Null )
{
strSql + = " AND Signed.FileType=@FileType" ;
listStr . Add ( new SqlParameter ( "@FileType" , drpFileType2 . SelectedValue ) ) ;
}
strSql + = " ORDER BY Signed.UploadDate DESC" ;
SqlParameter [ ] parameter = listStr . ToArray ( ) ;
DataTable tb = SQLHelper . GetDataTableRunText ( strSql , parameter ) ;
Grid2 . RecordCount = tb . Rows . Count ;
var table = this . GetPagedDataTable ( Grid2 , tb ) ;
Grid2 . DataSource = table ;
Grid2 . DataBind ( ) ;
for ( int i = 0 ; i < Grid2 . Rows . Count ; i + + )
{
System . Web . UI . WebControls . LinkButton lbtnUrl = ( ( System . Web . UI . WebControls . LinkButton ) ( this . Grid2 . Rows [ i ] . FindControl ( "lbtnUrl1" ) ) ) ;
string url = lbtnUrl . CommandArgument . ToString ( ) ;
if ( ! string . IsNullOrEmpty ( url ) )
{
url = url . Replace ( '\\' , '/' ) ;
lbtnUrl . Text = BLL . UploadAttachmentService . ShowAttachment ( "../" , url ) ;
}
}
}
private void BindGrid3 ( string id )
{
string strSql = @ "SELECT con.FileId,
con . FC_ID ,
con . FileName ,
con . FileTypeId ,
con . FileTypeCode ,
con . UploadMan ,
con . UploadDate ,
con . Remark ,
con . AttachUrl ,
U . UserName AS UploadManName ,
F . FileType
FROM FC_ContractManagement AS con
LEFT JOIN Base_FileType AS F ON F . FileTypeId = con . FileTypeId
LEFT JOIN Sys_User AS U ON U . UserId = con . UploadMan
WHERE con . FC_ID = @id ";
List < SqlParameter > listStr = new List < SqlParameter > ( ) ;
listStr . Add ( new SqlParameter ( "@id" , id ) ) ;
if ( drpFileType3 . SelectedValue ! = Const . _Null )
{
strSql + = " AND con.FileTypeId=@FileType" ;
listStr . Add ( new SqlParameter ( "@FileType" , drpFileType3 . SelectedValue ) ) ;
}
strSql + = " ORDER BY con.UploadDate DESC" ;
SqlParameter [ ] parameter = listStr . ToArray ( ) ;
DataTable tb = SQLHelper . GetDataTableRunText ( strSql , parameter ) ;
Grid3 . RecordCount = tb . Rows . Count ;
var table = this . GetPagedDataTable ( Grid3 , tb ) ;
Grid3 . DataSource = table ;
Grid3 . DataBind ( ) ;
for ( int i = 0 ; i < Grid3 . Rows . Count ; i + + )
{
System . Web . UI . WebControls . LinkButton lbtnUrl = ( ( System . Web . UI . WebControls . LinkButton ) ( this . Grid3 . Rows [ i ] . FindControl ( "lbtnUrl2" ) ) ) ;
string url = lbtnUrl . CommandArgument . ToString ( ) ;
if ( ! string . IsNullOrEmpty ( url ) )
{
url = url . Replace ( '\\' , '/' ) ;
lbtnUrl . Text = BLL . UploadAttachmentService . ShowAttachment ( "../" , url ) ;
}
}
}
#endregion
#region 选 项 卡 改 变 事 件
/// <summary>
/// 选项卡改变事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void TabStrip1_TabIndexChanged ( object sender , EventArgs e )
{
this . hdID . Text = string . Empty ;
if ( ! string . IsNullOrEmpty ( this . Grid1 . SelectedRowID ) )
{
this . hdID . Text = this . Grid1 . SelectedRowID ;
}
else
{
if ( ! string . IsNullOrEmpty ( Grid1 . Rows [ 0 ] . RowID ) )
{
this . hdID . Text = Grid1 . Rows [ 0 ] . RowID ;
}
}
if ( ! string . IsNullOrEmpty ( this . hdID . Text ) )
{
var sESRelatedData = BLL . SESRelatedDataService . GetSESRelatedDataById ( this . hdID . Text ) ;
if ( sESRelatedData ! = null )
{
string cruUser = CurrUser . UserId ;
string mcdeptLeader = string . Empty ;
if ( this . TabStrip1 . ActiveTabIndex = = 0 )
{
BindGrid2 ( this . hdID . Text ) ;
}
else if ( this . TabStrip1 . ActiveTabIndex = = 1 )
{
BindGrid3 ( this . hdID . Text ) ;
}
}
}
}
#endregion
#region Signed Contracts
/// <summary>
/// Signed Contracts
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
//protected void btnSignedContracts_Click(object sender, EventArgs e)
//{
// if (Grid1.SelectedRowIndexArray.Length == 0)
// {
// Alert.ShowInParent("Please select at least one record!");
// return;
// }
// string Id = Grid1.SelectedRowID;
// PageContext.RegisterStartupScript(Window4.GetShowReference(String.Format("SESRelatedDataSigned.aspx?id={0}", Id, "编辑 - ")));
//}
protected void btnAddFile2_Click ( object sender , EventArgs e )
{
if ( Grid1 . SelectedRowIndexArray . Length = = 0 )
{
Alert . ShowInParent ( "Please select FC Record!" ) ;
return ;
}
if ( drpFileType2Select . SelectedValue = = Const . _Null )
{
Alert . ShowInParent ( "Please select FileType!" ) ;
return ;
}
PageContext . RegisterStartupScript ( WindowAtt . GetShowReference ( String . Format ( "../AttachFile/webuploader3.aspx?type=add&toKeyId={0}&path=FileUpload/SES/SESRelatedData/SignedContracts&menuId={1}&mainTableId={2}" , drpFileType2Select . SelectedValue , BLL . Const . SESRelatedDateMenuId , Grid1 . SelectedRowID ) ) ) ;
}
/// <summary>
/// Grid2行双击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid2_RowDoubleClick ( object sender , GridRowClickEventArgs e )
{
btnMenuEdit2_Click ( null , null ) ;
}
/// <summary>
/// Grid2右键编辑
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnMenuEdit2_Click ( object sender , EventArgs e )
{
if ( Grid2 . SelectedRowIndexArray . Length = = 0 )
{
Alert . ShowInParent ( "Please select Signed Contracts!" ) ;
return ;
}
string fileId = Grid2 . SelectedRowID ;
PageContext . RegisterStartupScript ( WindowAtt . GetShowReference ( String . Format ( "../AttachFile/webuploader3.aspx?type=edit&toKeyId={0}&path=FileUpload/SES/SESRelatedData/SignedContracts&menuId={1}" , fileId , BLL . Const . SESRelatedDateMenuId ) ) ) ;
//PageContext.RegisterStartupScript(Window4.GetShowReference(String.Format("SESRelatedDataSigned.aspx?fileId={0}", fileId, "编辑 - ")));
}
/// <summary>
/// Grid2右键删除
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnMenuDelete2_Click ( object sender , EventArgs e )
{
if ( Grid2 . SelectedRowIndexArray . Length > 0 )
{
foreach ( int rowIndex in Grid2 . SelectedRowIndexArray )
{
string rowID = Grid2 . DataKeys [ rowIndex ] [ 0 ] . ToString ( ) ;
var signedContracts = BLL . SignedContractsService . GetSignedContractsById ( rowID ) ;
if ( signedContracts ! = null )
{
BLL . SignedContractsService . DeleteSignedContractsById ( rowID ) ;
}
}
BindGrid2 ( this . hdID . Text ) ;
BLL . Sys_LogService . AddLog ( this . CurrUser . UserId , "Delete Signed Contracts" ) ;
ShowNotify ( "Deleted successfully!" ) ;
}
}
protected void drpFileType2_OnSelectedIndexChanged ( object sender , EventArgs e )
{
BindGrid2 ( this . hdID . Text ) ;
}
/// <summary>
/// 关闭Signed Contracts弹出框
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void WindowAtt_Close ( object sender , WindowCloseEventArgs e )
{
BindGrid2 ( this . hdID . Text ) ;
BindGrid3 ( this . hdID . Text ) ;
}
#endregion
#region Contract Management
/// <summary>
/// Contract Management
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
//protected void btnContractManagement_Click(object sender, EventArgs e)
//{
// if (Grid1.SelectedRowIndexArray.Length == 0)
// {
// Alert.ShowInParent("Please select at least one record!");
// return;
// }
// string Id = Grid1.SelectedRowID;
// //PageContext.RegisterStartupScript(Window5.GetShowReference(String.Format("SESRelatedDataContractManage.aspx?id={0}", Id, "编辑 - ")));
//}
protected void btnAddFile3_Click ( object sender , EventArgs e )
{
if ( Grid1 . SelectedRowIndexArray . Length = = 0 )
{
Alert . ShowInParent ( "Please select FC Record!" ) ;
return ;
}
//if (drpFileType3Select.SelectedValue == Const._Null)
//{
// Alert.ShowInParent("Please select FileType!");
// return;
//}
string Id = Grid1 . SelectedRowID ;
//PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("../AttachFile/webuploader3.aspx?type=add&toKeyId={0}&path=FileUpload/SES/SESRelatedData/ContractManagement&menuId={1}&mainTableId={2}", drpFileType3Select.SelectedValue, BLL.Const.SESRelatedDateMenuId, Grid1.SelectedRowID)));
PageContext . RegisterStartupScript ( Window5 . GetShowReference ( String . Format ( "SESRelatedDataContractManage.aspx?id={0}" , Id , "编辑 - " ) ) ) ;
}
/// <summary>
/// Grid3行双击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid3_RowDoubleClick ( object sender , GridRowClickEventArgs e )
{
btnMenuEdit3_Click ( null , null ) ;
}
/// <summary>
/// Grid3右键编辑
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnMenuEdit3_Click ( object sender , EventArgs e )
{
if ( Grid3 . SelectedRowIndexArray . Length = = 0 )
{
Alert . ShowInParent ( "Please select at least one record!" ) ;
return ;
}
string fileId = Grid3 . SelectedRowID ;
//PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("../AttachFile/webuploader3.aspx?type=edit&toKeyId={0}&path=FileUpload/SES/SESRelatedData/ContractManagement&menuId={1}", fileId, BLL.Const.SESRelatedDateMenuId)));
PageContext . RegisterStartupScript ( Window5 . GetShowReference ( String . Format ( "SESRelatedDataContractManage.aspx?fileId={0}" , fileId , "编辑 - " ) ) ) ;
}
/// <summary>
/// Grid3右键删除
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnMenuDelete3_Click ( object sender , EventArgs e )
{
if ( Grid3 . SelectedRowIndexArray . Length > 0 )
{
foreach ( int rowIndex in Grid3 . SelectedRowIndexArray )
{
string rowID = Grid3 . DataKeys [ rowIndex ] [ 0 ] . ToString ( ) ;
var contracts = BLL . ContractManagementService . GetContractManagementById ( rowID ) ;
if ( contracts ! = null )
{
BLL . ContractManagementService . DeleteContractManagementById ( rowID ) ;
}
}
BindGrid3 ( this . hdID . Text ) ;
BLL . Sys_LogService . AddLog ( this . CurrUser . UserId , "Delete Contract Management" ) ;
ShowNotify ( "Deleted successfully!" ) ;
}
}
protected void drpFileType3_OnSelectedIndexChanged ( object sender , EventArgs e )
{
BindGrid3 ( this . hdID . Text ) ;
}
/// <summary>
/// 关闭弹出窗体
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Window5_Close ( object sender , WindowCloseEventArgs e )
{
BindGrid3 ( this . hdID . Text ) ;
}
#endregion
protected void btnBatchDownload_Click ( object sender , EventArgs e )
{
string rootPath = Server . MapPath ( "~/" ) . Replace ( '\\' , '/' ) ;
string date = DateTime . Now . ToString ( "yyyyMMddHHmmss" ) ;
if ( drpDownloadType . SelectedValue = = "0" )
{
Alert . ShowInParent ( "Please select Download!" ) ;
return ;
}
if ( drpDownloadType . SelectedValue = = "1" )
{
string destFile = rootPath + "FileUpload\\Temp\\SignedContracts_" + date ;
string zipFileName = "SignedContracts_" + date ;
if ( ! Directory . Exists ( destFile ) )
{
Directory . CreateDirectory ( destFile ) ;
}
List < string > urlList = ( from x in Funs . DB . FC_SignedContracts where x . AttachUrl ! = null & & x . AttachUrl ! = "" select x . AttachUrl ) . ToList ( ) ;
foreach ( string url in urlList )
{
string sourceFileName = rootPath + url . Replace ( '\\' , '/' ) ;
string [ ] subUrl = sourceFileName . Split ( '/' ) ;
string fileName = subUrl [ subUrl . Count ( ) - 1 ] ;
string newFileName = fileName . Substring ( fileName . IndexOf ( "~" ) + 1 ) ;
if ( newFileName . Contains ( "_" ) )
{
if ( newFileName . Substring ( 0 , 1 ) = = "_" )
{
newFileName = newFileName . Substring ( 1 , newFileName . Length - 1 ) ;
}
else
{
newFileName = newFileName . Replace ( newFileName . Split ( '_' ) [ 0 ] , "" ) ;
newFileName = newFileName . Substring ( 1 ) ;
}
}
string destFileName = destFile + "/" + newFileName ;
if ( File . Exists ( sourceFileName ) )
{
File . Copy ( sourceFileName , destFileName , true ) ;
}
}
FileZipDownload ( destFile . Replace ( '\\' , '/' ) , zipFileName ) ;
//List<string> durl = new List<string>();
//List<string> urlList = (from x in Funs.DB.FC_SignedContracts where x.AttachUrl != null && x.AttachUrl != "" select x.AttachUrl).ToList();
//foreach (string url in urlList)
//{
// string fullUrl = rootPath + url.Replace('\\', '/');
// if (File.Exists(fullUrl))
// {
// durl.Add(url);
// }
//}
//// 1-Signed Contracts,2-Contract Management
//string strcon = DownloadFileByHttpUrl(durl, "1");
//ShowNotify(strcon);
}
if ( drpDownloadType . SelectedValue = = "2" )
{
//string destFile = rootPath + "FileUpload\\SES\\SESRelatedData\\ContractManagement";
string destFile = rootPath + "FileUpload\\Temp\\ContractManagement_" + date ;
string zipFileName = "ContractManagement_" + date ;
if ( ! Directory . Exists ( destFile ) )
{
Directory . CreateDirectory ( destFile ) ;
}
List < string > urlList = ( from x in Funs . DB . FC_ContractManagement where x . AttachUrl ! = null & & x . AttachUrl ! = "" select x . AttachUrl ) . ToList ( ) ;
foreach ( string url in urlList )
{
string sourceFileName = rootPath + url . Replace ( '\\' , '/' ) ;
string [ ] subUrl = sourceFileName . Split ( '/' ) ;
string fileName = subUrl [ subUrl . Count ( ) - 1 ] ;
string newFileName = fileName . Substring ( fileName . IndexOf ( "~" ) + 1 ) ;
if ( newFileName . Contains ( "_" ) )
{
if ( newFileName . Substring ( 0 , 1 ) = = "_" )
{
newFileName = newFileName . Substring ( 1 , newFileName . Length - 1 ) ;
}
else
{
newFileName = newFileName . Replace ( newFileName . Split ( '_' ) [ 0 ] , "" ) ;
newFileName = newFileName . Substring ( 1 ) ;
}
}
string destFileName = destFile + "/" + newFileName ;
if ( File . Exists ( sourceFileName ) )
{
File . Copy ( sourceFileName , destFileName , true ) ;
}
}
FileZipDownload ( destFile . Replace ( '\\' , '/' ) , zipFileName ) ;
//List<string> durl = new List<string>();
//List<string> urlList = (from x in Funs.DB.FC_ContractManagement where x.AttachUrl != null && x.AttachUrl != "" select x.AttachUrl).ToList();
//foreach (string url in urlList)
//{
// string fullUrl = rootPath + url.Replace('\\', '/');
// if (File.Exists(fullUrl))
// {
// durl.Add(url);
// }
//}
//string strcon = DownloadFileByHttpUrl(durl, "2");
//ShowNotify(strcon);
}
}
private void FileZipDownload ( string destFilePath , string zipFileName )
{
string zipFilePath = destFilePath + ".zip" ;
System . IO . Compression . ZipFile . CreateFromDirectory ( destFilePath , zipFilePath ) ;
FileInfo info = new FileInfo ( zipFilePath ) ;
long fileSize = info . Length ;
System . Web . HttpContext . Current . Response . Clear ( ) ;
System . Web . HttpContext . Current . Response . ContentType = "application/x-zip-compressed" ;
System . Web . HttpContext . Current . Response . AddHeader ( "Content-Disposition" , "attachment;filename=" + System . Web . HttpUtility . UrlEncode ( zipFileName + ".zip" , System . Text . Encoding . UTF8 ) ) ;
System . Web . HttpContext . Current . Response . AddHeader ( "Content-Length" , fileSize . ToString ( ) ) ;
System . Web . HttpContext . Current . Response . TransmitFile ( zipFilePath , 0 , fileSize ) ;
System . Web . HttpContext . Current . Response . Flush ( ) ;
System . Web . HttpContext . Current . Response . Close ( ) ;
Funs . DeleteDir ( destFilePath ) ;
File . Delete ( zipFilePath ) ;
}
public string DownloadFileByHttpUrl ( List < string > HttpUrlList , string type )
{
if ( HttpUrlList = = null | | HttpUrlList . Count = = 0 )
{
return "没有附件" ;
}
try
{
var random = new Random ( ) ;
var zipMs = new MemoryStream ( ) ;
ZipOutputStream zipStream = new ZipOutputStream ( zipMs ) ;
zipStream . SetLevel ( 6 ) ; //压缩率0~9
foreach ( var url in HttpUrlList )
{
if ( ! string . IsNullOrWhiteSpace ( url ) )
{
string rootPath = System . Configuration . ConfigurationManager . AppSettings [ "RootUrl" ] ;
string surl = rootPath + url . Replace ( '\\' , '/' ) ;
var urlStr = HttpUtility . UrlDecode ( surl ) ;
Console . WriteLine ( urlStr ) ;
string fileExt = Path . GetExtension ( urlStr ) . ToLower ( ) ;
string fileNameWithoutExtension = Path . GetFileNameWithoutExtension ( urlStr ) ;
var strName = fileNameWithoutExtension . Substring ( fileNameWithoutExtension . LastIndexOf ( "/" ) + 1 ) + random . Next ( 1000 , 9999 ) + fileExt ;
zipStream . PutNextEntry ( new ZipEntry ( strName ) ) ;
HttpWebRequest request = ( HttpWebRequest ) WebRequest . Create ( urlStr ) ;
request . AllowAutoRedirect = true ;
WebProxy proxy = new WebProxy ( ) ;
proxy . BypassProxyOnLocal = true ;
proxy . UseDefaultCredentials = true ;
request . Proxy = proxy ;
WebResponse response = request . GetResponse ( ) ;
using ( Stream streams = response . GetResponseStream ( ) )
{
Byte [ ] buffer = new Byte [ 1024 ] ;
int current = 0 ;
while ( ( current = streams . Read ( buffer , 0 , buffer . Length ) ) ! = 0 )
{
zipStream . Write ( buffer , 0 , current ) ;
}
zipStream . Flush ( ) ;
}
}
}
zipStream . Finish ( ) ;
zipMs . Position = 0 ;
//下边为打包压缩
MemoryStream stream = zipMs ;
byte [ ] srcBuf = new Byte [ stream . Length ] ;
stream . Read ( srcBuf , 0 , srcBuf . Length ) ;
stream . Seek ( 0 , SeekOrigin . Begin ) ;
string filePath = "C:/DownLoad" ; //Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
if ( ! Directory . Exists ( filePath ) )
{
Directory . CreateDirectory ( filePath ) ;
}
string date = DateTime . Now . ToString ( "yyyyMMddHHmmss" ) ;
string con = string . Empty ;
if ( type = = "1" )
{
con = "FC_Signed Contracts" ;
}
else
{
con = "FC_Contract Management" ;
}
var file_name = con + "_" + date + ".zip" ;
using ( FileStream fs = new FileStream ( filePath + "\\" + file_name , FileMode . Create , FileAccess . Write ) )
{
fs . Write ( srcBuf , 0 , srcBuf . Length ) ;
fs . Close ( ) ;
return "已下载到C://Download文件下! " ;
}
}
catch ( Exception ex )
{
return "下载失败:" + ex . ToString ( ) ;
}
}
protected void drpDownloadType_SelectedIndexChanged ( object sender , EventArgs e )
{
}
}
}