Basf_FCL/FCL/FineUIPro.Web/SES/SESReport.aspx.cs

2078 lines
97 KiB
C#
Raw Normal View History

2024-05-08 10:17:02 +08:00
using BLL;
using BLL.Common;
using Model;
using NPOI.XSSF.UserModel;
using NPOI.SS.UserModel;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace FineUIPro.Web.SES
{
public partial class SESReport : PageBase
{
//定义变量
/// <summary>
/// 上传预设的虚拟路径
/// </summary>
private string initPath = Const.ExcelUrl;
/// <summary>
/// 集合
/// </summary>
public static List<Model.FC_SESReport> sesReports = new List<Model.FC_SESReport>();
/// <summary>
/// 错误集合
/// </summary>
public static string errorInfos = string.Empty;
/// <summary>
/// 加载页面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
// 表头过滤
FilterDataRowItem = FilterDataRowItemImplement;
if (!IsPostBack)
{
GetButtonPower();//按钮权限
ddlPageSize.SelectedValue = Grid1.PageSize.ToString();
// 绑定表格
BindGrid();
}
}
#region
/// <summary>
/// 绑定数据
/// </summary>
private void BindGrid()
{
string strSql = @"SELECT ID,
SES_No,
Short_Descrption,
Start_Date,
End_Date,
Created_by,
Created_on,
TECO_Date,
TECO_Format,
Requisitioner,
FO,
Item,
Vendor_Name,
Discipline,
SSR_budget,
Currency,
Contractor_quotation,
SSR_Actual_cost,
Cost_checker,
Tax_rate,
Changed_by,
Deviation,
Deviation_Percentage,
Overrun,
Long_text,
Work_Order,
Function_location,
Main_work_center,
Work_Center,
Dep,
Section,
Cost_center,
WBS,
Network,
TODAY,
Claim_sheets_receive,
CS_REC_Format,
No_SUBM_To_today,
Contractor_duration,
Engineer_confirmed_o,
ENG_CONF_Format,
No_BoQ_CONF_to_today,
BoQ_confirmation_dur,
SES_Confirmed_on,
SES_CONF_Format,
No_SES_to_today,
Settlement_duration,
Invoiced_on,
Invoice_duration,
Payment_made_on,
Payment_duration,
DateIn,
Remark1,
Remark2,
Accepted,
Deleted,
Blocked
FROM FC_SESReport WHERE 1=1 ";
List<SqlParameter> listStr = new List<SqlParameter>();
if (!string.IsNullOrEmpty(this.txtSES_No.Text.Trim()))
{
strSql += " AND SES_No LIKE @SES_No";
listStr.Add(new SqlParameter("@SES_No", "%" + this.txtSES_No.Text.Trim() + "%"));
}
if (!string.IsNullOrEmpty(this.txtShort_Descrption.Text.Trim()))
{
strSql += " AND Short_Descrption LIKE @Short_Descrption";
listStr.Add(new SqlParameter("@Short_Descrption", "%" + this.txtShort_Descrption.Text.Trim() + "%"));
}
SqlParameter[] parameter = listStr.ToArray();
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
// 2.获取当前分页数据
//var table = this.GetPagedDataTable(Grid1, tb1);
Grid1.RecordCount = tb.Rows.Count;
tb = GetFilteredTable(Grid1.FilteredData, tb);
var table = this.GetPagedDataTable(Grid1, tb);
Grid1.DataSource = table;
Grid1.DataBind();
}
#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 == "SES_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 == "Short_Descrption")
{
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 == "Start_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 == "End_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 == "Created_by")
{
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 == "Created_on")
{
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 == "TECO_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 == "TECO_Format")
{
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 == "Requisitioner")
{
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 == "FO")
{
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 == "Vendor_Name")
{
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 == "SSR_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 == "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 == "Contractor_quotation")
{
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 == "SSR_Actual_cost")
{
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 == "Tax_rate")
{
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 == "Changed_by")
{
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 == "Deviation")
{
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 == "Deviation_Percentage")
{
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 == "Overrun")
{
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 == "Long_text")
{
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 == "Work_Order")
{
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 == "Function_location")
{
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_work_center")
{
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 == "Work_Center")
{
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 == "Dep")
//{
// 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 == "Section")
//{
// 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_center")
{
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 == "WBS")
{
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 == "Network")
{
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 == "TODAY")
{
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 == "Claim_sheets_receive")
{
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 == "CS_REC_Format")
{
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 == "No_SUBM_To_today")
{
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_duration")
{
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 == "Engineer_confirmed_o")
{
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 == "ENG_CONF_Format")
{
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 == "No_BoQ_CONF_to_today")
{
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 == "BoQ_confirmation_dur")
{
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 == "SES_Confirmed_on")
{
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 == "SES_CONF_Format")
{
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 == "No_SES_to_today")
{
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 == "Settlement_duration")
{
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 == "Invoiced_on")
{
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 == "Payment_made_on")
{
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 == "Payment_duration")
{
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 == "Accepted")
{
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 == "Deleted")
{
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 == "Blocked")
{
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 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 report = BLL.SESReportService.GetSESReportById(rowID);
// if (report != null)
// {
// if (judgementDelete(rowID, false))
// {
// BLL.SESReportService.DeleteSESReportById(rowID);
// }
// }
// }
// BindGrid();
// BLL.Sys_LogService.AddLog(this.CurrUser.UserId, "Delete SES Report");
// ShowNotify("Deleted successfully!");
// }
//}
#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();
}
#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>
///// <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 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("SESReportEdit.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>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnAudit_Click(object sender, EventArgs e)
{
string fo = string.Empty;
string message = string.Empty;
errorInfos = string.Empty;
ConcurrentBag<FC_SESReport> fcSesList = new ConcurrentBag<FC_SESReport>();
try
{
if (this.fuAttachUrl.HasFile == false)
{
ShowNotify("Please select Excel file!", MessageBoxIcon.Warning);
return;
}
string IsXls = Path.GetExtension(this.fuAttachUrl.FileName).ToString().Trim().ToLower();
if (IsXls != ".xls" && IsXls != ".xlsx")
{
ShowNotify("Only Excel files can be selected!", MessageBoxIcon.Warning);
return;
}
if (sesReports != null)
{
sesReports.Clear();
}
if (!string.IsNullOrEmpty(errorInfos))
{
errorInfos = string.Empty;
}
string rootPath = Server.MapPath("~/");
string initFullPath = rootPath + initPath;
if (!Directory.Exists(initFullPath))
{
Directory.CreateDirectory(initFullPath);
}
//指定上传文件名称
this.hdFileName.Text = BLL.Funs.GetNewFileName() + IsXls;
//上传文件路径
string filePath = initFullPath + this.hdFileName.Text;
//文件上传服务器
this.fuAttachUrl.PostedFile.SaveAs(filePath);
//文件上传服务器后的名称
string fileName = rootPath + initPath + this.hdFileName.Text;
//读取Excel
DataSet ds = NPOIHelper.ExcelToDataSet(fileName, out errorInfos, true);
//验证Excel读取是否有误
if (!string.IsNullOrEmpty(errorInfos))
{
ShowNotify(errorInfos, MessageBoxIcon.Warning);
return;
}
//导入数据库
if (ds.Tables.Count > 0)
{
Parallel.For(0, ds.Tables[0].Rows.Count, i =>
{
FC_SESReport fcSesModel = new FC_SESReport();
#region
if (ds.Tables[0].Rows[i]["SES No."] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["SES No."].ToString()))
{
fcSesModel.SES_No = ds.Tables[0].Rows[i]["SES No."].ToString();
}
else
{
errorInfos += (i + 2) + "Line, [SES No.] cannot be empty";
}
fcSesModel.Short_Descrption = (ds.Tables[0].Rows[i]["Short Descrption"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["Short Descrption"].ToString())) ? ds.Tables[0].Rows[i]["Short Descrption"].ToString() : "";
if (ds.Tables[0].Rows[i]["Start Date"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["Start Date"].ToString()))
{
try
{
message = TimeValidation(ds.Tables[0].Rows[i]["Start Date"]);
if (string.IsNullOrEmpty(message))
{
fcSesModel.Start_Date = TimeValue(ds.Tables[0].Rows[i]["Start Date"]);
}
else
{
errorInfos += (i + 2) + " Line, [Start Date]" + message + "</br>";
}
}
catch (Exception)
{
errorInfos += (i + 2) + " Line, [Start Date]" + message + "</br>";
}
}
if (ds.Tables[0].Rows[i]["End Date"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["End Date"].ToString()))
{
try
{
message = TimeValidation(ds.Tables[0].Rows[i]["End Date"]);
if (string.IsNullOrEmpty(message))
{
fcSesModel.End_Date = TimeValue(ds.Tables[0].Rows[i]["End Date"]);
}
else
{
errorInfos += (i + 2) + "Line, [End Date]" + message + "</br>";
}
}
catch (Exception)
{
errorInfos += (i + 2) + "Line, [End Date]" + message + "</br>";
}
}
fcSesModel.Created_by = (ds.Tables[0].Rows[i]["Created by"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["Created by"].ToString())) ? ds.Tables[0].Rows[i]["Created by"].ToString() : "";
if (ds.Tables[0].Rows[i]["Created on"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["Created on"].ToString()))
{
try
{
message = TimeValidation(ds.Tables[0].Rows[i]["Created on"]);
if (string.IsNullOrEmpty(message))
{
fcSesModel.Created_on = TimeValue(ds.Tables[0].Rows[i]["Created on"]);
}
else
{
errorInfos += (i + 2) + "Line, [Created on]" + message + "</br>";
}
}
catch (Exception)
{
errorInfos += (i + 2) + "Line, [Created on]" + message + "</br>";
}
}
if (ds.Tables[0].Rows[i]["TECO Date"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["TECO Date"].ToString()))
{
try
{
message = TimeValidation(ds.Tables[0].Rows[i]["TECO Date"]);
if (string.IsNullOrEmpty(message))
{
fcSesModel.TECO_Date = TimeValue(ds.Tables[0].Rows[i]["TECO Date"]);
fcSesModel.TECO_Format = TimeValue(ds.Tables[0].Rows[i]["TECO Date"]);
}
else
{
errorInfos += (i + 2) + "Line, [TECO Date]" + message + "</br>";
}
}
catch (Exception)
{
errorInfos += (i + 2) + "Line, [TECO Date]" + message + "</br>";
}
}
if (ds.Tables[0].Rows[i]["Requisitioner"] != null && ds.Tables[0].Rows[i]["Requisitioner"].ToString() != "")
{
string requisitioner = ds.Tables[0].Rows[i]["Requisitioner"].ToString();
string[] reman = requisitioner.Split('/');
if (reman.Count() == 2)
{
fcSesModel.Requisitioner = reman[0];
}
else
{
fcSesModel.Requisitioner = requisitioner;
}
}
else
{
fcSesModel.Requisitioner = "";
}
if (ds.Tables[0].Rows[i]["FO"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["FO"].ToString()))
{
fcSesModel.FO = ds.Tables[0].Rows[i]["FO"].ToString();
fo = fcSesModel.FO;
}
else
{
errorInfos += (i + 2) + "Line, [FO] cannot be empty</br>";
}
if (ds.Tables[0].Rows[i]["Item"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["Item"].ToString()))
{
try
{
if (IsWholeNumber(ds.Tables[0].Rows[i]["Item"]))
{
fcSesModel.Item = int.Parse(ds.Tables[0].Rows[i]["Item"].ToString());
}
else
{
errorInfos += (i + 2) + " line[Item]Must be in numeric format</br>";
}
}
catch (Exception)
{
errorInfos += (i + 2) + " line[Item]Must be in numeric format</br>";
}
}
fcSesModel.Vendor_Name = (ds.Tables[0].Rows[i]["Vendor Name"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["Vendor Name"].ToString())) ? ds.Tables[0].Rows[i]["Vendor Name"].ToString() : "";
if (ds.Tables[0].Rows[i]["SSR budget"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["SSR budget"].ToString()))
{
try
{
if (IsNumber(ds.Tables[0].Rows[i]["SSR budget"]))
{
fcSesModel.SSR_budget = DecibelConversion(ds.Tables[0].Rows[i]["SSR budget"].ToString().Trim());
}
else
{
errorInfos += (i + 2) + "line[SSR budget]Must be in numeric format</br>";
}
}
catch (Exception)
{
errorInfos += (i + 2) + "line[SSR budget]Must be in numeric format</br>";
}
}
else
{
fcSesModel.SSR_budget = 0;
}
fcSesModel.Currency = (ds.Tables[0].Rows[i]["Currency"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["Currency"].ToString())) ? ds.Tables[0].Rows[i]["Currency"].ToString() : "";
if (ds.Tables[0].Rows[i]["Contractor quotation"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["Contractor quotation"].ToString()))
{
try
{
if (IsNumber(ds.Tables[0].Rows[i]["Contractor quotation"]))
{
fcSesModel.Contractor_quotation = DecibelConversion(ds.Tables[0].Rows[i]["Contractor quotation"].ToString().Trim());
}
else
{
errorInfos += (i + 2) + " line[Contractor quotation]Must be in numeric format</br>";
}
}
catch (Exception)
{
errorInfos += (i + 2) + " line[Contractor quotation]Must be in numeric format</br>";
}
}
else
{
fcSesModel.Contractor_quotation = 0;
}
if (ds.Tables[0].Rows[i]["SSR Actual cost"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["SSR Actual cost"].ToString()))
{
try
{
if (IsNumber(ds.Tables[0].Rows[i]["SSR Actual cost"]))
{
fcSesModel.SSR_Actual_cost = DecibelConversion(ds.Tables[0].Rows[i]["SSR Actual cost"].ToString().Trim());
}
else
{
errorInfos += (i + 2) + "line[SSR Actual cost]Must be in numeric format</br>";
}
}
catch (Exception)
{
errorInfos += (i + 2) + "line[SSR Actual cost]Must be in numeric format</br>";
}
}
else
{
fcSesModel.SSR_Actual_cost = 0;
}
if (ds.Tables[0].Rows[i]["Tax rate"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["Tax rate"].ToString()))
{
try
{
if (IsNumber(ds.Tables[0].Rows[i]["Tax rate"].ToString().Replace("%", "")))
{
fcSesModel.Tax_rate = DecibelConversion(ds.Tables[0].Rows[i]["Tax rate"].ToString().Replace("%", "").Trim());
}
else
{
errorInfos += (i + 2) + "line[Tax rate]Must be in numeric format</br>";
}
}
catch (Exception)
{
errorInfos += (i + 2) + "line[Tax rate]Must be in numeric format</br>";
}
}
if (ds.Tables[0].Rows[i]["Deviation"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["Deviation"].ToString()))
{
try
{
if (IsNumber(ds.Tables[0].Rows[i]["Deviation"]))
{
fcSesModel.Deviation = DecibelConversion(ds.Tables[0].Rows[i]["Deviation"].ToString().Trim());
}
else
{
errorInfos += (i + 2) + "line[Deviation]Must be in numeric format</br>";
}
}
catch (Exception)
{
errorInfos += (i + 2) + "line[Deviation]Must be in numeric format</br>";
}
}
if (ds.Tables[0].Rows[i]["Deviation Percentage"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["Deviation Percentage"].ToString()))
{
try
{
if (IsNumber(ds.Tables[0].Rows[i]["Deviation Percentage"]))
{
fcSesModel.Deviation_Percentage = DecibelConversion(ds.Tables[0].Rows[i]["Deviation Percentage"].ToString().Trim());
}
else
{
errorInfos += (i + 2) + "line[Deviation Percentage]Must be in numeric format</br>";
}
}
catch (Exception)
{
errorInfos += (i + 2) + "line[Deviation Percentage]Must be in numeric format</br>";
}
}
fcSesModel.Long_text = (ds.Tables[0].Rows[i]["Long text"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["Long text"].ToString())) ? ds.Tables[0].Rows[i]["Long text"].ToString() : "";
if (ds.Tables[0].Rows[i]["Work Order"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["Work Order"].ToString()))
{
try
{
if (IsWholeNumber(ds.Tables[0].Rows[i]["Work Order"]))
{
fcSesModel.Work_Order = int.Parse(ds.Tables[0].Rows[i]["Work Order"].ToString());
}
else
{
errorInfos += (i + 2) + "line[Work Order]Must be in pure number format</br>";
}
}
catch (Exception)
{
errorInfos += (i + 2) + "line[Work Order]Must be in pure number format</br>";
}
}
fcSesModel.Function_location = (ds.Tables[0].Rows[i]["Function location"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["Function location"].ToString())) ? ds.Tables[0].Rows[i]["Function location"].ToString() : "";
fcSesModel.Main_work_center = (ds.Tables[0].Rows[i]["Main work center"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["Main work center"].ToString())) ? ds.Tables[0].Rows[i]["Main work center"].ToString() : "";
if (ds.Tables[0].Rows[i]["Work Center"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["Work Center"].ToString()))
{
fcSesModel.Work_Center = ds.Tables[0].Rows[i]["Work Center"].ToString();
if (fcSesModel.Work_Center.Contains("CTM/L"))
{
fcSesModel.Dep = "CTM";
fcSesModel.Section = "CTM/P";
}
else if (fcSesModel.Work_Center.Length > 5 && (fcSesModel.Work_Center.ToString() == "CTA/LV" || fcSesModel.Work_Center.ToString() == "CTA/LW"))
{
fcSesModel.Dep = "CTA";
fcSesModel.Section = "CTA/L";
}
else if (fcSesModel.Work_Center.Length > 5 && fcSesModel.Work_Center.Substring(0, 5)== "CTA/L" && (fcSesModel.Work_Center.ToString() != "CTA/LV" || fcSesModel.Work_Center.ToString() != "CTA/LW"))
{
fcSesModel.Section = "CTA/P";
}
else if (fcSesModel.Work_Center.Length >= 5)
{
fcSesModel.Dep = fcSesModel.Work_Center.Substring(0, 3);
fcSesModel.Section = fcSesModel.Work_Center.Substring(0, 5);
}
}
else
{
if (ds.Tables[0].Rows[i]["WBS"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["WBS"].ToString()))
{
fcSesModel.Section = "PS";
}
}
fcSesModel.Cost_center = (ds.Tables[0].Rows[i]["Cost center"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["Cost center"].ToString())) ? ds.Tables[0].Rows[i]["Cost center"].ToString() : "";
fcSesModel.WBS = (ds.Tables[0].Rows[i]["WBS"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["WBS"].ToString())) ? ds.Tables[0].Rows[i]["WBS"].ToString() : "";
fcSesModel.Network = (ds.Tables[0].Rows[i]["Network"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["Network"].ToString())) ? ds.Tables[0].Rows[i]["Network"].ToString() : "";
if (ds.Tables[0].Rows[i]["Claim sheets receive"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["Claim sheets receive"].ToString()))
{
try
{
message = TimeValidation(ds.Tables[0].Rows[i]["Claim sheets receive"]);
if (string.IsNullOrEmpty(message))
{
fcSesModel.Claim_sheets_receive = TimeValue(ds.Tables[0].Rows[i]["Claim sheets receive"]);
fcSesModel.CS_REC_Format = TimeValue(ds.Tables[0].Rows[i]["Claim sheets receive"]);
}
else
{
errorInfos += (i + 2) + "Line, [Claim sheets receive]" + message + "</br>";
}
}
catch (Exception)
{
errorInfos += (i + 2) + "Line, [Claim sheets receive]" + message + "</br>";
}
}
if (ds.Tables[0].Rows[i]["Contractor duration"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["Contractor duration"].ToString()))
{
try
{
if (IsNumber(ds.Tables[0].Rows[i]["Contractor duration"]))
{
fcSesModel.Contractor_duration = DecibelConversion(ds.Tables[0].Rows[i]["Contractor duration"].ToString().Trim());
}
else
{
errorInfos += (i + 2) + "line[Contractor duration]Must be in numeric format</br>";
}
}
catch (Exception)
{
errorInfos += (i + 2) + "line[Contractor duration]Must be in numeric format</br>";
}
}
if (ds.Tables[0].Rows[i]["Engineer confirmed o"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["Engineer confirmed o"].ToString()))
{
try
{
message = TimeValidation(ds.Tables[0].Rows[i]["Engineer confirmed o"]);
if (string.IsNullOrEmpty(message))
{
fcSesModel.Engineer_confirmed_o = TimeValue(ds.Tables[0].Rows[i]["Engineer confirmed o"]);
fcSesModel.ENG_CONF_Format = TimeValue(ds.Tables[0].Rows[i]["Engineer confirmed o"]);
}
else
{
errorInfos += (i + 2) + "Line, [Engineer confirmed o]" + message + "</br>";
}
}
catch (Exception)
{
errorInfos += (i + 2) + "Line, [Engineer confirmed o]" + message + "</br>";
}
}
if (ds.Tables[0].Rows[i]["BoQ confirmation dur"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["BoQ confirmation dur"].ToString()))
{
try
{
if (IsNumber(ds.Tables[0].Rows[i]["BoQ confirmation dur"]))
{
fcSesModel.BoQ_confirmation_dur = DecibelConversion(ds.Tables[0].Rows[i]["BoQ confirmation dur"].ToString().Trim());
}
else
{
errorInfos += (i + 2) + "line[BoQ confirmation dur]Must be in numeric format</br>";
}
}
catch (Exception)
{
errorInfos += (i + 2) + "line[BoQ confirmation dur]Must be in numeric format</br>";
}
}
if (ds.Tables[0].Rows[i]["SES Confirmed on"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["SES Confirmed on"].ToString()))
{
try
{
message = TimeValidation(ds.Tables[0].Rows[i]["SES Confirmed on"]);
if (string.IsNullOrEmpty(message))
{
fcSesModel.SES_Confirmed_on = TimeValue(ds.Tables[0].Rows[i]["SES Confirmed on"]);
fcSesModel.SES_CONF_Format = TimeValue(ds.Tables[0].Rows[i]["SES Confirmed on"]);
}
else
{
errorInfos += (i + 2) + "Line, [SES Confirmed on]" + message + "</br>";
}
}
catch (Exception)
{
errorInfos += (i + 2) + "Line, [SES Confirmed on]" + message + "</br>";
}
}
if (ds.Tables[0].Rows[i]["Settlement duration"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["Settlement duration"].ToString()))
{
try
{
if (IsNumber(ds.Tables[0].Rows[i]["Settlement duration"]))
{
fcSesModel.Settlement_duration = DecibelConversion(ds.Tables[0].Rows[i]["Settlement duration"].ToString().Trim());
}
else
{
errorInfos += (i + 2) + "line[Settlement duration]Must be in numeric format</br>";
}
}
catch (Exception)
{
errorInfos += (i + 2) + "line[Settlement duration]Must be in numeric format</br>";
}
}
if (ds.Tables[0].Rows[i]["Invoiced on"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["Invoiced on"].ToString()))
{
try
{
message = TimeValidation(ds.Tables[0].Rows[i]["Invoiced on"]);
if (string.IsNullOrEmpty(message))
{
fcSesModel.Invoiced_on = TimeValue(ds.Tables[0].Rows[i]["Invoiced on"]);
}
else
{
errorInfos += (i + 2) + "Line, [Invoiced on]" + message + "</br>";
}
}
catch (Exception)
{
errorInfos += (i + 2) + "Line, [Invoiced on]" + message + "</br>";
}
}
if (ds.Tables[0].Rows[i]["Invoice duration"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["Invoice duration"].ToString()))
{
try
{
if (IsNumber(ds.Tables[0].Rows[i]["Invoice duration"]))
{
fcSesModel.Invoice_duration = DecibelConversion(ds.Tables[0].Rows[i]["Invoice duration"].ToString().Trim());
}
else
{
errorInfos += (i + 2) + "line[Invoice duration]Must be in numeric format</br>";
}
}
catch (Exception)
{
errorInfos += (i + 2) + "line[Invoice duration]Must be in numeric format</br>";
}
}
if (ds.Tables[0].Rows[i]["Payment made on"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["Payment made on"].ToString()))
{
try
{
message = TimeValidation(ds.Tables[0].Rows[i]["Payment made on"]);
if (string.IsNullOrEmpty(message))
{
fcSesModel.Payment_made_on = TimeValue(ds.Tables[0].Rows[i]["Payment made on"]);
}
else
{
errorInfos += (i + 2) + "Line, [Payment made on]" + message + "</br>";
}
}
catch (Exception)
{
errorInfos += (i + 2) + "Line, [Payment made on]" + message + "</br>";
}
}
if (ds.Tables[0].Rows[i]["Payment duration"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["Payment duration"].ToString()))
{
try
{
if (IsNumber(ds.Tables[0].Rows[i]["Payment duration"]))
{
fcSesModel.Payment_duration = DecibelConversion(ds.Tables[0].Rows[i]["Payment duration"].ToString().Trim());
}
else
{
errorInfos += (i + 2) + "line[Payment duration]Must be in numeric format</br>";
}
}
catch (Exception)
{
errorInfos += (i + 2) + "line[Payment duration]Must be in numeric format</br>";
}
}
fcSesModel.Accepted = (ds.Tables[0].Rows[i]["Accepted"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["Accepted"].ToString())) ? ds.Tables[0].Rows[i]["Accepted"].ToString() : "";
fcSesModel.Deleted = (ds.Tables[0].Rows[i]["Deleted"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["Deleted"].ToString())) ? ds.Tables[0].Rows[i]["Deleted"].ToString() : "";
fcSesModel.Blocked = (ds.Tables[0].Rows[i]["Blocked"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["Blocked"].ToString())) ? ds.Tables[0].Rows[i]["Blocked"].ToString() : "";
fcSesModel.Changed_by = (ds.Tables[0].Rows[i]["Changed by"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["Changed by"].ToString())) ? ds.Tables[0].Rows[i]["Changed by"].ToString() : "";
fcSesModel.DateIn = DateTime.Now;
#endregion
lock (fcSesModel)
{
fcSesList.Add(fcSesModel);
}
});
if (!string.IsNullOrEmpty(errorInfos))
{
Alert.ShowInTop(errorInfos, MessageBoxIcon.Warning);
return;
}
if (fcSesList.Count > 0)
{
//导入前先删除
SQLHelper.ExecutSql("truncate table FC_SESReport");
var result = SqlBulkHelper.BulkInsert(SqlBulkHelper.GetCon(), "FC_SESReport", fcSesList.ToList());
if (result > 0)
{
ddlPageSize.SelectedValue = Grid1.PageSize.ToString();
// 绑定表格
BindGrid();
}
//更新SSR中的Claim_sheets_receive 去掉逻辑2023.03.08
//foreach (var item in fcSesList)
//{
// var ssr = BLL.SSRService.GetSSRBySESNo(item.SES_No);
// if (ssr != null)
// {
// BLL.SSRService.UpdateSSR_SubmmisionDate(ssr.SSRId, item.Claim_sheets_receive);
// }
//}
ShowNotify("Import success!", MessageBoxIcon.Success);
}
else
{
Alert.ShowInTop("No data!", MessageBoxIcon.Warning);
return;
}
}
}
catch (Exception ex)
{
Alert.ShowInTop("'" + ex.Message + "'", MessageBoxIcon.Warning);
}
}
#endregion
#region
/// <summary>
/// 模板下载
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnDownLoad_Click(object sender, EventArgs e)
{
PageContext.RegisterStartupScript(Confirm.GetShowReference("Are you sure to download the import template?", String.Empty, MessageBoxIcon.Question, PageManager1.GetCustomEventReference(false, "Confirm_OK"), PageManager1.GetCustomEventReference("Confirm_Cancel")));
}
/// <summary>
/// 下载导入模板
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void PageManager1_CustomEvent(object sender, CustomEventArgs e)
{
if (e.EventArgument == "Confirm_OK")
{
string rootPath = Server.MapPath("~/");
string uploadfilepath = rootPath + Const.FC_SESReportTemplateUrl;
string filePath = Const.FC_SESReportTemplateUrl;
string fileName = Path.GetFileName(filePath);
FileInfo info = new FileInfo(uploadfilepath);
long fileSize = info.Length;
Response.ClearContent();
Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
Response.ContentType = "excel/plain";
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.AddHeader("Content-Length", fileSize.ToString().Trim());
Response.TransmitFile(uploadfilepath, 0, fileSize);
Response.End();
}
}
#endregion
#region
/// <summary>
/// 时间格式验证
/// </summary>
/// <param name="time"></param>
/// <returns></returns>
private static string TimeValidation(object time)
{
string message = string.Empty;
try
{
if (time.ToString().Contains("."))
{
DateTime.ParseExact(time.ToString(), "dd.MM.yyyy", CultureInfo.InvariantCulture);
}
else
{
Convert.ToDateTime(time);
}
}
catch (Exception ex)
{
message = "Please enter a valid time format";
}
return message;
}
/// <summary>
/// 带小数的数字验证
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public static bool IsNumber(object input)
{
string pattern = "^-?\\d+$|^(-?\\d+)(\\.\\d+)?$";
Regex regex = new Regex(pattern);
string value = input != null ? DecibelConversion(input.ToString()).ToString() : "";
return regex.IsMatch(value.Trim());
}
/// <summary>
/// 整数
/// </summary>
/// <param name="strNumber"></param>
/// <returns></returns>
public static bool IsWholeNumber(object input)
{
Regex g = new Regex(@"^[-]?[0-9]\d*$");
string value = input != null ? input.ToString() : "";
return g.IsMatch(value);
}
/// <summary>
/// 千分位转换
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public static decimal DecibelConversion(string input)
{
var inputValue = string.Empty;
if (input.Contains(',') && input.Contains('.'))
{
var inputstr = input.Replace(".", "").Split(',');
if (inputstr.Length > 0)
{
for (int i = 0; i < inputstr.Length; i++)
{
inputValue += i < (inputstr.Length - 1) ? inputstr[i] : "." + inputstr[i];
}
}
}
else if (input.Contains(','))
{
inputValue = input.Replace(",", ".");
}
else
{
inputValue = input;
}
inputValue = inputValue.Length > 18 ? inputValue.Substring(0, 17) : inputValue;
return decimal.Parse(inputValue);
}
/// <summary>
/// 时间格式转换
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static DateTime TimeValue(object value)
{
string dateValue = string.Empty;
if (value != null)
{
if (value.ToString().Contains("."))
{
dateValue = DateTime.ParseExact(value.ToString(), "dd.MM.yyyy", CultureInfo.InvariantCulture).ToString("yyyy-MM-dd");
}
else
{
dateValue = DateTime.Parse(value.ToString()).ToString("yyyy-MM-dd");
}
}
return DateTime.Parse(dateValue);
}
#endregion
#region
/// <summary>
/// 菜单按钮权限
/// </summary>
private void GetButtonPower()
{
var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.UserId, BLL.Const.SESReportMenuId);
if (buttonList.Count() > 0)
{
if (buttonList.Contains(BLL.Const.BtnIn))
{
this.btnAudit.Hidden = false;
this.btnDownLoad.Hidden = 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 + "SESReport.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 SESReport
XSSFSheet reportModel = (XSSFSheet)hssfworkbook.GetSheet("SESReport");
XSSFFont cs_content_Font = (XSSFFont)hssfworkbook.CreateFont(); //创建字体
cs_content_Font.FontName = "sans-serif";//字体
cs_content_Font.FontHeightInPoints = 9; //字体大小
IDataFormat dataformat = hssfworkbook.CreateDataFormat();
ICellStyle styleDate = hssfworkbook.CreateCellStyle();
styleDate.DataFormat = dataformat.GetFormat("yyyy/m/d");
var list = (from x in Funs.DB.FC_SESReport orderby x.ID select x).ToList();
if (!string.IsNullOrEmpty(this.txtSES_No.Text.Trim()))
{
list = list.Where(x => x.SES_No.Contains(this.txtSES_No.Text.Trim())).ToList();
}
if (!string.IsNullOrEmpty(this.txtShort_Descrption.Text.Trim()))
{
list = list.Where(x => x.Short_Descrption.Contains(this.txtShort_Descrption.Text.Trim())).ToList();
}
if (list.Count > 0)
{
var rowIndex = 1;
foreach (var itemOver in list)
{
if (reportModel.GetRow(rowIndex) == null) reportModel.CreateRow(rowIndex);
#region
//No.
if (reportModel.GetRow(rowIndex).GetCell(0) == null) reportModel.GetRow(rowIndex).CreateCell(0);
reportModel.GetRow(rowIndex).GetCell(0).SetCellValue(itemOver.ID.ToString());
reportModel.GetRow(rowIndex).GetCell(0).CellStyle.SetFont(cs_content_Font);//将字体绑定到样式
//Accepted
if (reportModel.GetRow(rowIndex).GetCell(1) == null) reportModel.GetRow(rowIndex).CreateCell(1);
reportModel.GetRow(rowIndex).GetCell(1).SetCellValue(itemOver.Accepted != null ? itemOver.Accepted.ToString() : "");
//Deleted
if (reportModel.GetRow(rowIndex).GetCell(2) == null) reportModel.GetRow(rowIndex).CreateCell(2);
reportModel.GetRow(rowIndex).GetCell(2).SetCellValue(itemOver.Deleted != null ? itemOver.Deleted.ToString() : "");
//Blocked
if (reportModel.GetRow(rowIndex).GetCell(3) == null) reportModel.GetRow(rowIndex).CreateCell(3);
reportModel.GetRow(rowIndex).GetCell(3).SetCellValue(itemOver.Blocked != null ? itemOver.Blocked.ToString() : "");
//SES No.
if (reportModel.GetRow(rowIndex).GetCell(4) == null) reportModel.GetRow(rowIndex).CreateCell(4);
reportModel.GetRow(rowIndex).GetCell(4).SetCellValue(itemOver.SES_No != null ? itemOver.SES_No.ToString() : "");
//Short Descrption
if (reportModel.GetRow(rowIndex).GetCell(5) == null) reportModel.GetRow(rowIndex).CreateCell(5);
reportModel.GetRow(rowIndex).GetCell(5).SetCellValue(itemOver.Short_Descrption != null ? itemOver.Short_Descrption.ToString() : "");
//Start Date
if (reportModel.GetRow(rowIndex).GetCell(6) == null) reportModel.GetRow(rowIndex).CreateCell(6);
if (itemOver.Start_Date.HasValue)
{
reportModel.GetRow(rowIndex).GetCell(6).SetCellValue((DateTime)itemOver.Start_Date.Value);
reportModel.GetRow(rowIndex).GetCell(6).CellStyle = styleDate;
}
//End Date
if (reportModel.GetRow(rowIndex).GetCell(7) == null) reportModel.GetRow(rowIndex).CreateCell(7);
if (itemOver.End_Date.HasValue)
{
reportModel.GetRow(rowIndex).GetCell(7).SetCellValue((DateTime)itemOver.End_Date.Value);
reportModel.GetRow(rowIndex).GetCell(7).CellStyle = styleDate;
}
//Created by
if (reportModel.GetRow(rowIndex).GetCell(8) == null) reportModel.GetRow(rowIndex).CreateCell(8);
reportModel.GetRow(rowIndex).GetCell(8).SetCellValue(itemOver.Created_by != null ? itemOver.Created_by.ToString() : "");
//Created on
if (reportModel.GetRow(rowIndex).GetCell(9) == null) reportModel.GetRow(rowIndex).CreateCell(9);
if (itemOver.Created_on.HasValue)
{
reportModel.GetRow(rowIndex).GetCell(9).SetCellValue((DateTime)itemOver.Created_on.Value);
reportModel.GetRow(rowIndex).GetCell(9).CellStyle = styleDate;
}
//TECO Date
if (reportModel.GetRow(rowIndex).GetCell(10) == null) reportModel.GetRow(rowIndex).CreateCell(10);
if (itemOver.TECO_Date.HasValue)
{
reportModel.GetRow(rowIndex).GetCell(10).SetCellValue((DateTime)itemOver.TECO_Date.Value);
reportModel.GetRow(rowIndex).GetCell(10).CellStyle = styleDate;
}
//Requisitioner
if (reportModel.GetRow(rowIndex).GetCell(11) == null) reportModel.GetRow(rowIndex).CreateCell(11);
reportModel.GetRow(rowIndex).GetCell(11).SetCellValue(itemOver.Requisitioner != null ? itemOver.Requisitioner.ToString() : "");
//FO
if (reportModel.GetRow(rowIndex).GetCell(12) == null) reportModel.GetRow(rowIndex).CreateCell(12);
reportModel.GetRow(rowIndex).GetCell(12).SetCellValue(itemOver.FO != null ? itemOver.FO.ToString() : "");
//Item
if (reportModel.GetRow(rowIndex).GetCell(13) == null) reportModel.GetRow(rowIndex).CreateCell(13);
reportModel.GetRow(rowIndex).GetCell(13).SetCellValue(itemOver.Item != null ? itemOver.Item.ToString() : "");
//Vendor Name
if (reportModel.GetRow(rowIndex).GetCell(14) == null) reportModel.GetRow(rowIndex).CreateCell(14);
reportModel.GetRow(rowIndex).GetCell(14).SetCellValue(itemOver.Vendor_Name != null ? itemOver.Vendor_Name.ToString() : "");
//SSR budget
if (reportModel.GetRow(rowIndex).GetCell(15) == null) reportModel.GetRow(rowIndex).CreateCell(15);
reportModel.GetRow(rowIndex).GetCell(15).SetCellValue(itemOver.SSR_budget.HasValue ? itemOver.SSR_budget.ToString() : "");
//Currency
if (reportModel.GetRow(rowIndex).GetCell(16) == null) reportModel.GetRow(rowIndex).CreateCell(16);
reportModel.GetRow(rowIndex).GetCell(16).SetCellValue(itemOver.Currency != null ? itemOver.Currency.ToString() : "");
//Contractor quotation
if (reportModel.GetRow(rowIndex).GetCell(17) == null) reportModel.GetRow(rowIndex).CreateCell(17);
reportModel.GetRow(rowIndex).GetCell(17).SetCellValue(itemOver.Contractor_quotation != null ? itemOver.Contractor_quotation.ToString() : "");
//SSR Actual cost
if (reportModel.GetRow(rowIndex).GetCell(18) == null) reportModel.GetRow(rowIndex).CreateCell(18);
reportModel.GetRow(rowIndex).GetCell(18).SetCellValue(itemOver.SSR_Actual_cost.HasValue ? itemOver.SSR_Actual_cost.ToString() : "");
//Reduced by quantity
if (reportModel.GetRow(rowIndex).GetCell(19) == null) reportModel.GetRow(rowIndex).CreateCell(19);
reportModel.GetRow(rowIndex).GetCell(19).SetCellValue(itemOver.Reduced_by_quantity.HasValue ? itemOver.Reduced_by_quantity.ToString() : "");
//User field
if (reportModel.GetRow(rowIndex).GetCell(20) == null) reportModel.GetRow(rowIndex).CreateCell(20);
reportModel.GetRow(rowIndex).GetCell(20).SetCellValue(itemOver.User_field != null ? itemOver.User_field.ToString() : "");
//Tax rate
if (reportModel.GetRow(rowIndex).GetCell(21) == null) reportModel.GetRow(rowIndex).CreateCell(21);
reportModel.GetRow(rowIndex).GetCell(21).SetCellValue(itemOver.Tax_rate.HasValue ? itemOver.Tax_rate.ToString() : "");
//Changed by
if (reportModel.GetRow(rowIndex).GetCell(22) == null) reportModel.GetRow(rowIndex).CreateCell(22);
reportModel.GetRow(rowIndex).GetCell(22).SetCellValue(itemOver.Created_by != null ? itemOver.Created_by.ToString() : "");
//Deviation
if (reportModel.GetRow(rowIndex).GetCell(23) == null) reportModel.GetRow(rowIndex).CreateCell(23);
reportModel.GetRow(rowIndex).GetCell(23).SetCellValue(itemOver.Deviation.HasValue ? itemOver.Deviation.ToString() : "");
//Deviation Percentage
if (reportModel.GetRow(rowIndex).GetCell(24) == null) reportModel.GetRow(rowIndex).CreateCell(24);
reportModel.GetRow(rowIndex).GetCell(24).SetCellValue(itemOver.Deviation_Percentage.HasValue ? itemOver.Deviation_Percentage.ToString() : "");
//Long text
if (reportModel.GetRow(rowIndex).GetCell(25) == null) reportModel.GetRow(rowIndex).CreateCell(25);
reportModel.GetRow(rowIndex).GetCell(25).SetCellValue(itemOver.Long_text != null ? itemOver.Long_text.ToString() : "");
//Work Order
if (reportModel.GetRow(rowIndex).GetCell(26) == null) reportModel.GetRow(rowIndex).CreateCell(26);
reportModel.GetRow(rowIndex).GetCell(26).SetCellValue(itemOver.Work_Order.HasValue ? itemOver.Work_Order.ToString() : "");
//Function location
if (reportModel.GetRow(rowIndex).GetCell(27) == null) reportModel.GetRow(rowIndex).CreateCell(27);
reportModel.GetRow(rowIndex).GetCell(27).SetCellValue(itemOver.Function_location != null ? itemOver.Function_location.ToString() : "");
//Main work center
if (reportModel.GetRow(rowIndex).GetCell(28) == null) reportModel.GetRow(rowIndex).CreateCell(28);
reportModel.GetRow(rowIndex).GetCell(28).SetCellValue(itemOver.Main_work_center != null ? itemOver.Main_work_center.ToString() : "");
//Work Center
if (reportModel.GetRow(rowIndex).GetCell(29) == null) reportModel.GetRow(rowIndex).CreateCell(29);
reportModel.GetRow(rowIndex).GetCell(29).SetCellValue(itemOver.Work_Center != null ? itemOver.Work_Center.ToString() : "");
//Cost center
if (reportModel.GetRow(rowIndex).GetCell(30) == null) reportModel.GetRow(rowIndex).CreateCell(30);
reportModel.GetRow(rowIndex).GetCell(30).SetCellValue(itemOver.Cost_center != null ? itemOver.Cost_center.ToString() : "");
//WBS
if (reportModel.GetRow(rowIndex).GetCell(31) == null) reportModel.GetRow(rowIndex).CreateCell(31);
reportModel.GetRow(rowIndex).GetCell(31).SetCellValue(itemOver.WBS != null ? itemOver.WBS.ToString() : "");
//Network
if (reportModel.GetRow(rowIndex).GetCell(32) == null) reportModel.GetRow(rowIndex).CreateCell(32);
reportModel.GetRow(rowIndex).GetCell(32).SetCellValue(itemOver.Network != null ? itemOver.Network.ToString() : "");
//Claim sheets receive
if (reportModel.GetRow(rowIndex).GetCell(33) == null) reportModel.GetRow(rowIndex).CreateCell(33);
if (itemOver.Claim_sheets_receive.HasValue)
{
reportModel.GetRow(rowIndex).GetCell(33).SetCellValue((DateTime)itemOver.Claim_sheets_receive.Value);
reportModel.GetRow(rowIndex).GetCell(33).CellStyle = styleDate;
}
//Contractor duration
if (reportModel.GetRow(rowIndex).GetCell(34) == null) reportModel.GetRow(rowIndex).CreateCell(34);
reportModel.GetRow(rowIndex).GetCell(34).SetCellValue(itemOver.Contractor_duration.HasValue ? itemOver.Contractor_duration.ToString() : "");
//Engineer confirmed o
if (reportModel.GetRow(rowIndex).GetCell(35) == null) reportModel.GetRow(rowIndex).CreateCell(35);
if(itemOver.Engineer_confirmed_o.HasValue)
{
reportModel.GetRow(rowIndex).GetCell(35).SetCellValue((DateTime)itemOver.Engineer_confirmed_o.Value);
reportModel.GetRow(rowIndex).GetCell(35).CellStyle = styleDate;
}
//BoQ confirmation dur
if (reportModel.GetRow(rowIndex).GetCell(36) == null) reportModel.GetRow(rowIndex).CreateCell(36);
reportModel.GetRow(rowIndex).GetCell(36).SetCellValue(itemOver.BoQ_confirmation_dur.HasValue ? itemOver.BoQ_confirmation_dur.ToString() : "");
//SES Confirmed on
if (reportModel.GetRow(rowIndex).GetCell(37) == null) reportModel.GetRow(rowIndex).CreateCell(37);
if (itemOver.SES_Confirmed_on.HasValue)
{
reportModel.GetRow(rowIndex).GetCell(37).SetCellValue((DateTime)itemOver.SES_Confirmed_on.Value);
reportModel.GetRow(rowIndex).GetCell(37).CellStyle = styleDate;
}
//Settlement duration
if (reportModel.GetRow(rowIndex).GetCell(38) == null) reportModel.GetRow(rowIndex).CreateCell(38);
reportModel.GetRow(rowIndex).GetCell(38).SetCellValue(itemOver.Settlement_duration.HasValue ? itemOver.Settlement_duration.ToString() : "");
//Invoiced on
if (reportModel.GetRow(rowIndex).GetCell(39) == null) reportModel.GetRow(rowIndex).CreateCell(39);
if(itemOver.Invoiced_on.HasValue)
{
reportModel.GetRow(rowIndex).GetCell(39).SetCellValue((DateTime)itemOver.Invoiced_on.Value);
reportModel.GetRow(rowIndex).GetCell(39).CellStyle = styleDate;
}
//Invoice duration
if (reportModel.GetRow(rowIndex).GetCell(40) == null) reportModel.GetRow(rowIndex).CreateCell(40);
reportModel.GetRow(rowIndex).GetCell(40).SetCellValue(itemOver.Invoice_duration.HasValue ? itemOver.Invoice_duration.ToString() : "");
//Payment made on
if (reportModel.GetRow(rowIndex).GetCell(41) == null) reportModel.GetRow(rowIndex).CreateCell(41);
if (itemOver.Payment_made_on.HasValue)
{
reportModel.GetRow(rowIndex).GetCell(41).SetCellValue((DateTime)itemOver.Payment_made_on.Value);
reportModel.GetRow(rowIndex).GetCell(41).CellStyle = styleDate;
}
//Payment duration
if (reportModel.GetRow(rowIndex).GetCell(42) == null) reportModel.GetRow(rowIndex).CreateCell(42);
reportModel.GetRow(rowIndex).GetCell(42).SetCellValue(itemOver.Payment_duration.HasValue ? itemOver.Payment_duration.ToString() : "");
#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=SESReport" + 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
}
}