554 lines
22 KiB
C#
554 lines
22 KiB
C#
using BLL;
|
|
using FineUIPro.Web.BaseInfo;
|
|
using FineUIPro.Web.DataShow;
|
|
using Model;
|
|
using Model.Customization;
|
|
using Newtonsoft.Json.Linq;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Data.SqlClient;
|
|
using System.Linq;
|
|
using AspNet = System.Web.UI.WebControls;
|
|
|
|
namespace FineUIPro.Web.ProjectData
|
|
{
|
|
public partial class MasterProjectData : PageBase
|
|
{
|
|
#region 加载
|
|
/// <summary>
|
|
/// 加载页面
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
if (!IsPostBack)
|
|
{
|
|
Funs.DropDownPageSize(this.ddlPageSize);
|
|
this.ddlPageSize.SelectedValue = Grid1.PageSize.ToString();
|
|
//// 绑定表格
|
|
//this.BindGrid();
|
|
TabStrip1_TabIndexChanged(null, null);
|
|
}
|
|
}
|
|
|
|
protected void TabStrip1_TabIndexChanged(object sender, EventArgs e)
|
|
{
|
|
if (TabStrip1.ActiveTabIndex == 0)
|
|
{
|
|
this.Panel1.Title = "企业主数据与QHSE系统项目建立一览表";
|
|
this.BindGrid();
|
|
}
|
|
else
|
|
{
|
|
this.Panel1.Title = "企业QHSE项目使用情况一览表";
|
|
this.BindGrid2();
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 集团在建项目使用情况
|
|
|
|
|
|
#region 绑定数据
|
|
/// <summary>
|
|
/// 绑定数据
|
|
/// </summary>
|
|
private void BindGrid()
|
|
{
|
|
var list = new List<MasterProjectDataInfo>();
|
|
var db = Funs.DB;
|
|
var masterProDatas = ProjectService.GetMasterProjectDataInfos();
|
|
var query = (from x in masterProDatas
|
|
join pro in db.Base_Project on x.Pro_id equals pro.MasterSysId into proGroup
|
|
from pro in proGroup.DefaultIfEmpty()
|
|
join use in db.Project_MasterDataUsage on x.Pro_id equals use.Pro_id into useGroup
|
|
from use in useGroup.DefaultIfEmpty()
|
|
select new MasterProjectDataInfo
|
|
{
|
|
//Pid = x.Pro_id + (pro != null ? $"-{pro.ProjectId}" : ""),
|
|
Pid = $"{x.Pro_id}|{(pro != null ? $"{pro.ProjectId}" : "")}|{(use != null ? use.Id : "")}",
|
|
Pro_id = x.Pro_id,
|
|
Pro_name = x.Pro_name,
|
|
Pro_code = x.Pro_code,
|
|
Start_date = x.Start_date,
|
|
Con_mode_desc = x.Con_mode_desc,
|
|
Pro_nature = x.Pro_nature,
|
|
Pro_status = x.Pro_status,
|
|
Org_name = x.Org_name,
|
|
Amount = ConvertAmount(x.Ori_amt_sum_vat_fc, x.Amt_add_sum_vat_fc_local),
|
|
ProjectId = pro != null ? pro.ProjectId : null,
|
|
ProjectName = pro != null ? pro.ProjectName : "",
|
|
ProjectCode = pro != null ? pro.ProjectCode : "",
|
|
StartDate = pro != null ? pro.StartDate : null,
|
|
ProjectState = pro != null ? pro.ProjectState : "",
|
|
Relate = pro != null && pro.MasterSysId != null ? 1 : 2,
|
|
RelateName = pro != null && pro.MasterSysId != null ? "已关联" : "未关联",
|
|
UseId = use != null ? use.Id : null,
|
|
//Use = use == null ? "" : (use != null && use.Is_use == true) ? "已使用" : "未使用",
|
|
ReasonType = use != null ? use.ReasonType : "",
|
|
Reason = use != null ? use.Reason : "",
|
|
//Situation = use != null ? use.Situation : "",
|
|
//Remark = use != null ? use.Remark : "",
|
|
}).ToList();
|
|
|
|
string startDate = this.txtStartTime.Text.Trim();
|
|
string endDate = this.txtEndTime.Text.Trim();
|
|
if (!string.IsNullOrWhiteSpace(startDate))
|
|
{
|
|
query = query.Where(x => Funs.GetNewDateTime(x.Start_date) >= Funs.GetNewDateTime(startDate)).ToList();
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(endDate))
|
|
{
|
|
query = query.Where(x => Funs.GetNewDateTime(x.Start_date) <= Funs.GetNewDateTime(endDate)).ToList();
|
|
}
|
|
query = query.OrderByDescending(x => x.StartDate).ToList();
|
|
list.AddRange(query);
|
|
|
|
|
|
//// 获取施工中的项目
|
|
var getProjects = ProjectService.GetProjectWorkList();
|
|
getProjects = getProjects.Where(x => x.MasterSysId == null).OrderByDescending(x => x.StartDate).ToList();
|
|
foreach (var pro in getProjects)
|
|
{
|
|
list.Add(new MasterProjectDataInfo
|
|
{
|
|
Pid = $"|{pro.ProjectId}|",
|
|
Pro_id = "",
|
|
Pro_name = "",
|
|
Pro_code = "",
|
|
Start_date = "",
|
|
Con_mode_desc = "",
|
|
Pro_nature = "",
|
|
Pro_status = "",
|
|
Org_name = "",
|
|
Amount = "",
|
|
ProjectId = pro != null ? pro.ProjectId : null,
|
|
ProjectName = pro != null ? pro.ProjectName : "",
|
|
ProjectCode = pro != null ? pro.ProjectCode : "",
|
|
StartDate = pro != null ? pro.StartDate : null,
|
|
ProjectState = pro != null ? pro.ProjectState : "",
|
|
Relate = 3,
|
|
RelateName = "未对应",
|
|
UseId = null,
|
|
//Use = use == null ? "" : (use != null && use.Is_use == true) ? "已使用" : "未使用",
|
|
ReasonType = "",
|
|
Reason = "",
|
|
//Situation = use != null ? use.Situation : "",
|
|
//Remark = use != null ? use.Remark : "",
|
|
});
|
|
}
|
|
|
|
string proName = this.txtProName.Text.Trim();
|
|
string proCode = this.txtProCode.Text.Trim();
|
|
string projectName = this.txtProjectName.Text.Trim();
|
|
string projectCode = this.txtProjectCode.Text.Trim();
|
|
int relate = int.Parse(this.rblIsRelate.SelectedValue);
|
|
|
|
if (!string.IsNullOrEmpty(proName))
|
|
{
|
|
list = list.Where(x => x.Pro_name.Contains(proName)).ToList();
|
|
}
|
|
if (!string.IsNullOrEmpty(proCode))
|
|
{
|
|
list = list.Where(x => x.Pro_code.Contains(proCode)).ToList();
|
|
}
|
|
if (!string.IsNullOrEmpty(projectName))
|
|
{
|
|
list = list.Where(x => x.ProjectName.Contains(projectName)).ToList();
|
|
}
|
|
if (!string.IsNullOrEmpty(projectCode))
|
|
{
|
|
list = list.Where(x => x.ProjectCode.Contains(projectCode)).ToList();
|
|
}
|
|
if (relate > 0)
|
|
{
|
|
list = list.Where(x => x.Relate == relate).ToList();
|
|
}
|
|
|
|
DataTable tb = Funs.LINQToDataTable(list);
|
|
Grid1.RecordCount = tb.Rows.Count;
|
|
var table = this.GetPagedDataTable(Grid1, tb);
|
|
Grid1.DataSource = table;
|
|
Grid1.DataBind();
|
|
|
|
//int masterNum = query.Count();
|
|
int masterNum = 0;
|
|
int relateNum = 0;
|
|
int allQhseNum = 0;
|
|
try
|
|
{
|
|
for (int i = 0; i < Grid1.Rows.Count; i++)
|
|
{
|
|
var mpCode = table.Rows[i]["Pro_code"].ToString().Trim();
|
|
var pCode = table.Rows[i]["ProjectCode"].ToString().Trim();
|
|
var relateStr = table.Rows[i]["RelateName"].ToString().Trim();
|
|
var reason = table.Rows[i]["Reason"].ToString().Trim();
|
|
if (Grid1.Rows[i].DataKeys[0] != null && relateStr == "未关联" && !string.IsNullOrWhiteSpace(reason))
|
|
{
|
|
Grid1.Rows[i].RowCssClass = "Pause";
|
|
}
|
|
if (relateStr == "已关联")
|
|
{
|
|
relateNum++;
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(mpCode))
|
|
{
|
|
masterNum++;
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(pCode))
|
|
{
|
|
allQhseNum++;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex) { }
|
|
|
|
|
|
JObject summary = new JObject();
|
|
summary.Add("tfNumber", "合计");
|
|
//summary.Add("Pro_name", masterNum);
|
|
//summary.Add("ProjectName", allQhseNum);
|
|
//summary.Add("RelateName", $"已关联:{relateNum}");
|
|
|
|
summary.Add("Pro_name", $"主数据(已关联/总数):{relateNum}/{masterNum}");
|
|
summary.Add("ProjectName", $"QHSE(已关联/总数):{relateNum}/{allQhseNum}");
|
|
|
|
Grid1.SummaryData = summary;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 合同额(亿)
|
|
/// </summary>
|
|
/// <param name="Ori_amt">合同含税金额原始存档(元)</param>
|
|
/// <param name="Amt_add">增补合同本币含税金额(元)</param>
|
|
/// <returns></returns>
|
|
protected string ConvertAmount(decimal? Ori_amt, decimal? Amt_add)
|
|
{
|
|
string result = string.Empty;
|
|
Ori_amt = Ori_amt == null ? 0 : Ori_amt;
|
|
Amt_add = Amt_add == null ? 0 : Amt_add;
|
|
decimal? all = Amt_add + Ori_amt;
|
|
if (all != null)
|
|
{
|
|
double amount = all == null ? 0 : (Math.Round((double)(all / 100000000m), 2));
|
|
result = amount.ToString();
|
|
}
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 项目状态
|
|
/// </summary>
|
|
/// <param name="addType"></param>
|
|
/// <returns></returns>
|
|
protected string ConvertProjectState(object state)
|
|
{
|
|
string result = string.Empty;
|
|
string stateStr = state.ToString();
|
|
if (state != null && !string.IsNullOrWhiteSpace(stateStr))
|
|
{
|
|
result = stateStr == "2" ? "暂停中" : stateStr == "3" ? "已完工" : "施工中";
|
|
}
|
|
return result;
|
|
}
|
|
#endregion
|
|
|
|
#region Grid
|
|
|
|
protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e)
|
|
{
|
|
EditData(sender, e);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 编辑数据方法
|
|
/// </summary>
|
|
private void EditData(object sender, GridRowClickEventArgs e)
|
|
{
|
|
if (Grid1.SelectedRowIndexArray.Length == 0)
|
|
{
|
|
Alert.ShowInTop("请至少选择一条记录", MessageBoxIcon.Warning);
|
|
return;
|
|
}
|
|
var pId = Grid1.SelectedRowID;
|
|
|
|
string pro_id = pId.Split('|')[0];
|
|
string projectId = pId.Split('|')[1];
|
|
string useId = pId.Split('|')[2];
|
|
|
|
var obj = Grid1.SelectedRow.Values;
|
|
string num = obj[0].ToString();
|
|
string pro_name = obj[2].ToString();
|
|
string pro_code = obj[3].ToString();
|
|
string startdate = obj[7].ToString();
|
|
string prostatus = obj[9].ToString();
|
|
string projectName = obj[11].ToString();
|
|
string projectCode = obj[12].ToString();
|
|
string startDate = obj[13].ToString();
|
|
string lblState = (Grid1.SelectedRow.FindControl("lblState") as AspNet.Label).Text;
|
|
|
|
if (!string.IsNullOrWhiteSpace(pro_id))
|
|
{
|
|
var masterUsage = Funs.DB.Project_MasterDataUsage.Where(x => x.Pro_id == pro_id).FirstOrDefault();
|
|
if (masterUsage != null)
|
|
{
|
|
useId = masterUsage.Id;
|
|
}
|
|
else
|
|
{
|
|
useId = SQLHelper.GetNewID(typeof(Model.Project_MasterDataUsage));
|
|
Model.Project_MasterDataUsage model = new Model.Project_MasterDataUsage();
|
|
model.Id = useId;
|
|
model.Pro_id = pro_id;
|
|
model.Pro_code = pro_code;
|
|
model.Pro_name = pro_name;
|
|
model.Is_relate = !string.IsNullOrWhiteSpace(projectId);
|
|
model.Is_use = !string.IsNullOrWhiteSpace(projectId);
|
|
model.Projectid = projectId;
|
|
model.Projectcode = projectName;
|
|
model.Projectname = projectCode;
|
|
model.Create_user = this.CurrUser.UserName;
|
|
model.Create_date = DateTime.Now;
|
|
ProjectMasterDataUsageService.AddProjectMasterDataUsage(model);
|
|
}
|
|
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("MasterProjectDataUsage.aspx?UseId={0}", useId)));
|
|
//PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("MasterProjectDataUsage.aspx?UseId={0}&ProId={1}", useId, pro_id)));
|
|
}
|
|
}
|
|
|
|
protected void Window1_Close(object sender, WindowCloseEventArgs e)
|
|
{
|
|
this.BindGrid();
|
|
}
|
|
protected void TextBox_TextChanged(object sender, EventArgs e)
|
|
{
|
|
this.BindGrid();
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
|
|
{
|
|
BindGrid();
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue);
|
|
BindGrid();
|
|
}
|
|
|
|
protected void Grid1_Sort(object sender, FineUIPro.GridSortEventArgs e)
|
|
{
|
|
BindGrid();
|
|
}
|
|
#endregion
|
|
|
|
#region 导出按钮
|
|
|
|
/// <summary>
|
|
/// 导出按钮
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void btnOut_Click(object sender, EventArgs e)
|
|
{
|
|
Response.ClearContent();
|
|
string filename = Funs.GetNewFileName();
|
|
Response.AddHeader("content-disposition", "attachment; filename=" + System.Web.HttpUtility.UrlEncode("企业主数据与QHSE系统项目建立一览表" + filename, System.Text.Encoding.UTF8) + ".xls");
|
|
Response.ContentType = "application/excel";
|
|
Response.ContentEncoding = System.Text.Encoding.UTF8;
|
|
this.Grid1.PageSize = this.Grid1.RecordCount;
|
|
this.BindGrid();
|
|
Response.Write(GetGridMultiHeaderTableHtml(Grid1));
|
|
//Response.Write(GetGridTableHtml(Grid1));
|
|
Response.End();
|
|
}
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
#region 企业QHSE在建项目使用情况
|
|
|
|
|
|
/// <summary>
|
|
/// 绑定数据
|
|
/// </summary>
|
|
private void BindGrid2()
|
|
{
|
|
var db = Funs.DB;
|
|
//// 获取施工中的项目
|
|
var getProjects = ProjectService.GetProjectWorkList();
|
|
|
|
string projectName = this.txtProjectName2.Text.Trim();
|
|
string projectCode = this.txtProjectCode2.Text.Trim();
|
|
int relate = int.Parse(this.rblIsRelate.SelectedValue);
|
|
|
|
var list = new List<QHSEProjectDataInfo>();
|
|
if (!string.IsNullOrEmpty(projectName))
|
|
{
|
|
getProjects = getProjects.Where(x => x.ProjectName.Contains(projectName)).ToList();
|
|
}
|
|
if (!string.IsNullOrEmpty(projectCode))
|
|
{
|
|
getProjects = getProjects.Where(x => x.ProjectCode.Contains(projectCode)).ToList();
|
|
}
|
|
|
|
string startDate = this.txtStartTime2.Text.Trim();
|
|
string endDate = this.txtEndTime2.Text.Trim();
|
|
if (!string.IsNullOrWhiteSpace(startDate))
|
|
{
|
|
getProjects = getProjects.Where(x => x.StartDate >= Funs.GetNewDateTime(startDate)).ToList();
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(endDate))
|
|
{
|
|
getProjects = getProjects.Where(x => x.StartDate <= Funs.GetNewDateTime(endDate)).ToList();
|
|
}
|
|
|
|
var dateNow = DateTime.Now.Date;//现在
|
|
var dateMonthAgo = dateNow.AddMonths(-1);//一个月前
|
|
|
|
var datas = (from x in db.Project_HSSEData_HSSE
|
|
where x.ReportDate == dateNow || x.ReportDate == dateMonthAgo
|
|
select new QHSEProjectHSSEData
|
|
{
|
|
ProjectId = x.ProjectId,
|
|
ReportDate = x.ReportDate,
|
|
DataMetricsSum = (x.JoinConstructionPersonNum ?? 0) + (x.GeneralClosedNum ?? 0) + (x.GeneralNotClosedNum ?? 0) + (x.SafeWorkingHour ?? 0)
|
|
}).ToList();
|
|
|
|
foreach (var pro in getProjects)
|
|
{
|
|
string result = "正常";
|
|
var nowData = datas.Where(x => x.ProjectId == pro.ProjectId && x.ReportDate == dateNow).FirstOrDefault();
|
|
var monthAgoData = datas.Where(x => x.ProjectId == pro.ProjectId && x.ReportDate == dateMonthAgo).FirstOrDefault();
|
|
if (nowData != null && monthAgoData != null)
|
|
{//两个时间点都有指标数据
|
|
if (nowData.DataMetricsSum == monthAgoData.DataMetricsSum)
|
|
{
|
|
result = "异常";
|
|
}
|
|
}
|
|
//else if (nowData != null)
|
|
//{//现在有指标数据,一个月前没有
|
|
// result = "正常";
|
|
//}
|
|
//else if (monthAgoData != null)
|
|
//{//现在没有指标数据,一个月前有
|
|
// result = "正常";
|
|
//}
|
|
|
|
list.Add(new QHSEProjectDataInfo
|
|
{
|
|
ProjectId = pro.ProjectId,
|
|
ProjectName = pro.ProjectName,
|
|
ShortName = pro.ShortName,
|
|
ProjectCode = pro.ProjectCode,
|
|
StartDate = pro.StartDate,
|
|
EndDate = pro.EndDate,
|
|
ProjectState = pro.ProjectState,
|
|
Usage = result
|
|
});
|
|
}
|
|
|
|
DataTable tb = Funs.LINQToDataTable(list);
|
|
Grid2.RecordCount = tb.Rows.Count;
|
|
var table = this.GetPagedDataTable(Grid2, tb);
|
|
Grid2.DataSource = table;
|
|
Grid2.DataBind();
|
|
|
|
int exNum = 0;
|
|
int allQhseNum = 0;
|
|
//int allQhseNum = list.Count();
|
|
try
|
|
{
|
|
for (int i = 0; i < Grid2.Rows.Count; i++)
|
|
{
|
|
allQhseNum++;
|
|
var usage = table.Rows[i]["Usage"].ToString().Trim();
|
|
if (usage == "异常")
|
|
{
|
|
Grid2.Rows[i].RowCssClass = "Pause";
|
|
exNum++;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex) { }
|
|
|
|
|
|
JObject summary = new JObject();
|
|
summary.Add("tfNumber", "合计");
|
|
summary.Add("ProjectCode", allQhseNum);
|
|
summary.Add("Usage", $"异常:{exNum}");
|
|
|
|
Grid2.SummaryData = summary;
|
|
}
|
|
|
|
protected void TextBox_TextChanged2(object sender, EventArgs e)
|
|
{
|
|
this.BindGrid2();
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void Grid2_PageIndexChange(object sender, GridPageEventArgs e)
|
|
{
|
|
this.BindGrid2();
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void ddlPageSize2_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
Grid2.PageSize = Convert.ToInt32(ddlPageSize2.SelectedValue);
|
|
this.BindGrid2();
|
|
}
|
|
|
|
protected void Grid2_Sort(object sender, FineUIPro.GridSortEventArgs e)
|
|
{
|
|
this.BindGrid2();
|
|
}
|
|
|
|
#region 导出按钮
|
|
|
|
/// <summary>
|
|
/// 导出按钮
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void btnOut_Click2(object sender, EventArgs e)
|
|
{
|
|
Response.ClearContent();
|
|
string filename = Funs.GetNewFileName();
|
|
Response.AddHeader("content-disposition", "attachment; filename=" + System.Web.HttpUtility.UrlEncode("企业QHSE项目使用情况一览表" + filename, System.Text.Encoding.UTF8) + ".xls");
|
|
Response.ContentType = "application/excel";
|
|
Response.ContentEncoding = System.Text.Encoding.UTF8;
|
|
this.Grid2.PageSize = this.Grid2.RecordCount;
|
|
this.BindGrid2();
|
|
Response.Write(GetGridMultiHeaderTableHtml(Grid2));
|
|
//Response.Write(GetGridTableHtml(Grid2));
|
|
Response.End();
|
|
}
|
|
#endregion
|
|
|
|
|
|
#endregion
|
|
}
|
|
} |