SGGL_JT/SUBQHSE/FineUIPro.Web/Customization/CNCEC4/ZHGL/Report/HazardousEngineering.aspx.cs

326 lines
12 KiB
C#

using BLL;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace FineUIPro.Web.Customization.CNCEC4.ZHGL.Report
{
public partial class HazardousEngineering : PageBase
{
#region
/// <summary>
/// 加载页面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.ddlPageSize.SelectedValue = Grid1.PageSize.ToString();
this.txtMonth.Text = string.Format("{0:yyyy-MM}", DateTime.Now);
BLL.UnitService.InitBranchUnitDropDownList(this.drpUnitId, true);//所属单位
Funs.FineUIPleaseSelect(this.drpProjectId);//项目
//显示本单位信息
var thisUnit = BLL.CommonService.GetIsThisUnit();
if ((!string.IsNullOrEmpty(this.CurrUser.UnitId) && thisUnit.UnitId == this.CurrUser.UnitId) || this.CurrUser.UserId == BLL.Const.sysglyId || this.CurrUser.UserId == BLL.Const.hfnbdId)
{
this.drpUnitId.Enabled = true;
}
else
{
this.drpUnitId.Enabled = false;
this.drpUnitId.SelectedValue = this.CurrUser.UnitId;
}
// 绑定表格
this.BindGrid();
}
}
#region
/// <summary>
/// 绑定数据
/// </summary>
private void BindGrid()
{
string strSql = @"SELECT report.ReportId,
report.Months,
report.UnitId,
unit.UnitName,
report.ProjectId,
project.ProjectName,
report.SubProjectName,
report.WorksCategory,
(case when report.IsSuperDangerous='true' then '是' else '否' end) as IsSuperDangerous,
report.Address,
report.ConStartDate,
report.ConEndDate,
(CONVERT(varchar,report.ConStartDate,111)+'-'+CONVERT(varchar,report.ConEndDate,111)) as ConDate,
report.PlanSubmissionDate,
report.PlanApprovalDate,
report.CompletionDate,
report.SpecializedClass,
report.States"
+ @" FROM dbo.Report_HazardousEngineering as report"
+ @" LEFT JOIN dbo.Base_Project as project on project.projectId = report.ProjectId"
+ @" LEFT JOIN dbo.Base_Unit as unit on unit.UnitId = report.UnitId"
+ @" WHERE 1=1 ";
List<SqlParameter> listStr = new List<SqlParameter>();
//listStr.Add(new SqlParameter("@ProjectId", this.CurrUser.LoginProjectId));
if (!string.IsNullOrEmpty(this.txtMonth.Text.Trim()))
{
strSql += " AND report.Months = @months ";
listStr.Add(new SqlParameter("@months", Convert.ToDateTime(this.txtMonth.Text.Trim())));
}
if (this.drpUnitId.SelectedValue != BLL.Const._Null)
{
strSql += " AND report.UnitId = @UnitId ";
listStr.Add(new SqlParameter("@UnitId", this.drpUnitId.SelectedValue));
}
if (this.drpProjectId.SelectedValue != BLL.Const._Null)
{
strSql += " AND report.ProjectId = @ProjectId ";
listStr.Add(new SqlParameter("@ProjectId", this.drpProjectId.SelectedValue));
}
SqlParameter[] parameter = listStr.ToArray();
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
Grid1.RecordCount = tb.Rows.Count;
var table = this.GetPagedDataTable(Grid1, tb);
Grid1.DataSource = table;
Grid1.DataBind();
}
/// <summary>
/// 改变索引事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
{
BindGrid();
}
/// <summary>
/// 分页下拉选择事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
{
Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue);
BindGrid();
}
/// <summary>
/// 排序
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_Sort(object sender, FineUIPro.GridSortEventArgs e)
{
BindGrid();
}
/// <summary>
/// 关闭弹出窗口
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Window1_Close(object sender, EventArgs e)
{
BindGrid();
}
#endregion
#endregion
#region
/// <summary>
/// 增加按钮事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
//protected void btnNew_Click(object sender, EventArgs e)
//{
// if (GetButtonPower(Const.BtnAdd))
// {
// PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("HazardousEngineeringEdit.aspx", "新增 - ")));
// }
// else
// {
// Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
// return;
// }
//}
#endregion
#region
/// <summary>
/// 双击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e)
{
this.EditData();
}
/// <summary>
/// 右键编辑事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnMenuEdit_Click(object sender, EventArgs e)
{
this.EditData();
}
/// <summary>
/// 编辑数据方法
/// </summary>
private void EditData()
{
if (Grid1.SelectedRowIndexArray.Length == 0)
{
Alert.ShowInTop("请至少选择一条记录", MessageBoxIcon.Warning);
return;
}
if (GetButtonPower(Const.BtnModify))
{
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("HazardousEngineeringEdit.aspx?reportId={0}", Grid1.SelectedRowID, "编辑 - ")));
}
else
{
Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
return;
}
}
#endregion
#region
/// <summary>
/// 右键删除事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnMenuDelete_Click(object sender, EventArgs e)
{
if (GetButtonPower(Const.BtnDelete))
{
if (Grid1.SelectedRowIndexArray.Length > 0)
{
string strShowNotify = string.Empty;
foreach (int rowIndex in Grid1.SelectedRowIndexArray)
{
string rowID = Grid1.DataKeys[rowIndex][0].ToString();
var getReport = BLL.HazardousEngineeringService.GetReportById(rowID);
if (getReport != null)
{
string cont = judgementDelete(rowID);
if (string.IsNullOrEmpty(cont))
{
BLL.HazardousEngineeringService.DeleteHazardousEngineeringById(rowID);
}
else
{
strShowNotify += "危大工程实施清单月报" + ":" + getReport.SubProjectName + cont;
}
}
}
BindGrid();
if (!string.IsNullOrEmpty(strShowNotify))
{
Alert.ShowInTop(strShowNotify, MessageBoxIcon.Warning);
}
else
{
ShowNotify("删除成功!", MessageBoxIcon.Success);
}
}
}
else
{
Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
return;
}
}
#region
/// <summary>
/// 判断是否可以删除
/// </summary>
/// <returns></returns>
private string judgementDelete(string id)
{
string content = string.Empty;
//if (Funs.DB.Pipeline_WeldJoint.FirstOrDefault(x => x.PipeAssembly1Id == id) != null)
//{
// content += "已在【焊口信息】中使用,不能删除!";
//}
return content;
}
#endregion
#endregion
#region
/// <summary>
/// 获取按钮权限
/// </summary>
/// <param name="button"></param>
/// <returns></returns>
private bool GetButtonPower(string button)
{
return BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.ZHGL_HazardousEngineeringMenuId, button);
}
#endregion
#region
/// <summary>
/// 时间查询
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void txtMonth_TextChanged(object sender, EventArgs e)
{
BindGrid();
}
/// <summary>
/// 单位下拉查询
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void drpUnitId_SelectedIndexChanged(object sender, EventArgs e)
{
if (this.drpUnitId.SelectedValue != BLL.Const._Null)
{
this.drpProjectId.Items.Clear();
BLL.ProjectService.InitProjectByUnitIdDropDownList(this.drpProjectId, this.drpUnitId.SelectedValue, true);
this.drpProjectId.SelectedIndex = 0;
BindGrid();
}
}
/// <summary>
/// 项目下拉查询
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void drpProjectId_SelectedIndexChanged(object sender, EventArgs e)
{
if (this.drpProjectId.SelectedValue != BLL.Const._Null)
{
BindGrid();
}
}
#endregion
}
}