xinjiang/SGGL/FineUIPro.Web/HJGL/CheckManage/CheckManageStatic.aspx.cs

661 lines
26 KiB
C#

using BLL;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using Newtonsoft.Json.Linq;
using System.IO;
using NPOI.XSSF.UserModel;
using NPOI.SS.UserModel;
using System.Runtime.Serialization;
namespace FineUIPro.Web.HJGL.CheckManage
{
public partial class CheckManageStatic : 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 = this.Grid1.PageSize.ToString();
this.txtMonth.Text = string.Format("{0:yyyy-MM}", DateTime.Now);
this.InitTreeMenu();//加载树
}
}
#endregion
#region
/// <summary>
/// 导入焊接日报
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnImport_Click(object sender, EventArgs e)
{
if (BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.HJGL_CheckManageStaticMenuId, BLL.Const.BtnSave))
{
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("CheckManageDataIn.aspx", "导入 - ")));
}
else
{
ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
}
}
#endregion
#region --
/// <summary>
/// 加载树
/// </summary>
private void InitTreeMenu()
{
string SelectedNodeID = this.tvControlItem.SelectedNodeID;
this.tvControlItem.Nodes.Clear();
//检测方法
var detectionType = (from x in Funs.DB.Base_DetectionType orderby x.DetectionTypeCode select x).ToList();
string sql = @"SELECT distinct[ReportDate] ,[ReportNo],[DetectionTypeCode]
FROM [dbo].[CH_CheckStatic]
where [ReportDate]>=@dateA and [ReportDate]<@dateZ and ProjectId = @projectId
order by [DetectionTypeCode],[ReportDate] desc";
List<SqlParameter> listStr = new List<SqlParameter>
{
new SqlParameter("@projectId", this.CurrUser.LoginProjectId),
new SqlParameter("@dateA", this.txtMonth.Text+"-01"),
new SqlParameter("@dateZ", DateUtil.ToDateTime( this.txtMonth.Text+"-01").Value.AddMonths(1).ToString("yyyy-MM-dd")),
};
SqlParameter[] parameter = listStr.ToArray();
DataTable tb = SQLHelper.GetDataTableRunText(sql, parameter);
foreach (var type in detectionType)
{
TreeNode newNode = new TreeNode();
newNode.Text = type.DetectionTypeCode;
newNode.NodeID = type.DetectionTypeId;
newNode.ToolTip = "检测方法";
this.tvControlItem.Nodes.Add(newNode);
if (tb != null)
{
HashSet<string> dates = new HashSet<string>();
for (int i = 0; i < tb.Rows.Count; i++)
{
if (tb.Rows[i]["DetectionTypeCode"].ToString() == type.DetectionTypeCode)
{
string datetemp = tb.Rows[i]["ReportDate"].ToString();
if (!dates.Contains(datetemp))
{
dates.Add(datetemp);
TreeNode dateNode = new TreeNode();
dateNode.Text = datetemp.Substring(0, datetemp.IndexOf(' ')).Replace("/", "-");
dateNode.NodeID = type.DetectionTypeId + "|" + dateNode.Text;
dateNode.ToolTip = "报告日期";
newNode.Nodes.Add(dateNode);
for (int j = 0; j < tb.Rows.Count; j++)
{
if (tb.Rows[j]["DetectionTypeCode"].ToString() == type.DetectionTypeCode && tb.Rows[j]["ReportDate"].ToString() == datetemp)
{
TreeNode reportNoNode = new TreeNode();
reportNoNode.Text = tb.Rows[j]["ReportNo"].ToString();
reportNoNode.NodeID = tb.Rows[j]["ReportNo"].ToString() + "|" + dateNode.Text + "|" + type.DetectionTypeCode;
reportNoNode.ToolTip = "报告编号";
reportNoNode.EnableClickEvent = true;
dateNode.Nodes.Add(reportNoNode);
}
}
}
}
}
}
}
this.tvControlItem.SelectedNodeID = SelectedNodeID;
}
#endregion
protected void tvControlItem_NodeExpand(object sender, TreeNodeEventArgs e)
{
}
#region TreeView
/// <summary>
/// 点击TreeView
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void tvControlItem_NodeCommand(object sender, TreeCommandEventArgs e)
{
var p = this.tvControlItem.SelectedNodeID;
this.BindGrid();
}
#endregion
#region
/// <summary>
/// 数据绑定
/// </summary>
private void BindGrid()
{
string strSql = @"SELECT [CheckStaticId]
,[Installation_ID]
,[InstallationName]
,[CH_TrustID]
,[CH_TrustCode]
,[Trust_Date]
,[ISO_ID]
,[ISO_IsoNo]
,[JOT_ID]
,[JOT_JointNo]
,[WorkAmout1]
,[WorkAmout2]
,[FilmSpecifications]
,[FilmLocNum]
,[JOT_JointDesc]
,[MaterialId]
,[MaterialCode]
,[DetectionRateId]
,[DetectionRateCode]
,[WED_ID]
,[WED_Code]
,[CheckLevel]
,[DefectType]
,[DefectNum]
,[EvaluateLevel]
,[CheckDate]
,[CheckTemperature]
,[ReportNo]
,[ReportDate]
,[ReportAmount]
,[ProgressMoney]
,[CheckPerson]
,[RefilmReason]
,[FilmSpec]
,[CheckResult]
,[CheckResultDate]
,[CheckResultNum]
,[WME_ID]
,[WeldingMethodCode]
,[CheckThingName]
,[WorkAreaId]
,[WorkAreaCode]
,[UnidId]
,[UnitName]
,[ISOExecutive]
,[TrustUnitId]
,[TrustUnitName]
,[ProjectId]
,[ProjectName]
,[CheckThingType]
,[CheckOpportunity]
,[RadialType]
,[FilmBlack]
,[Remark]
,[CreateDate]
,[Status]
,[DetectionTypeCode]
,[DefectCode]
FROM [dbo].[CH_CheckStatic] where ProjectId = @projectId ";
List<SqlParameter> listStr = new List<SqlParameter>
{
new SqlParameter("@projectId", this.CurrUser.LoginProjectId)
};
if (!string.IsNullOrEmpty(this.tvControlItem.SelectedNodeID))
{
string[] SelectedNodes = this.tvControlItem.SelectedNodeID.Split('|');
if (SelectedNodes.Length > 0)
{
strSql += " and ReportNo = @ReportNo ";
listStr.Add(new SqlParameter("@ReportNo", SelectedNodes[0]));
}
if (SelectedNodes.Length > 1)
{
strSql += " and ReportDate >= @ReportDateA and ReportDate<=@ReportDateZ ";
listStr.Add(new SqlParameter("@ReportDateA", SelectedNodes[1]));
listStr.Add(new SqlParameter("@ReportDateZ", SelectedNodes[1] + " 23:59:59"));
}
if (SelectedNodes.Length > 2)
{
strSql += " and DetectionTypeCode = @DetectionTypeCode ";
listStr.Add(new SqlParameter("@DetectionTypeCode", SelectedNodes[2]));
}
}
if (!string.IsNullOrEmpty(txtJOT_JointNo.Text))
{
strSql += " and CH_TrustCode like @CH_TrustCode ";
listStr.Add(new SqlParameter("@CH_TrustCode", "%"+this.txtJOT_JointNo.Text+"%"));
}
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
#region
/// <summary>
/// 页索引改变事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
{
BindGrid();
}
#endregion
#region
/// <summary>
/// 排序
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_Sort(object sender, GridSortEventArgs e)
{
BindGrid();
}
#endregion
#region
/// <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();
}
#endregion
#endregion
#region
/// <summary>
/// Grid双击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e)
{
if (GetButtonPower(Const.BtnModify))
{
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("CheckManageStaticEdit.aspx?CheckStaticId={0}", Grid1.SelectedRowID, "编辑 - ")));
}
else
{
Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
return;
}
}
/// <summary>
/// 焊口信息编辑
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnMenuEdit_Click(object sender, EventArgs e)
{
if (GetButtonPower(Const.BtnModify))
{
if (Grid1.SelectedRowIndexArray.Length == 0)
{
Alert.ShowInTop("请选择一条记录!", MessageBoxIcon.Warning);
return;
}
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("CheckManageStaticEdit.aspx?CheckStaticId={0}", Grid1.SelectedRowID, "维护 - ")));
}
else
{
Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
return;
}
}
/// <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)
{
Alert.ShowInTop("请选择一条记录!", MessageBoxIcon.Warning);
return;
}
bool isShow = true;
if (Grid1.SelectedRowIndexArray.Length > 1)
{
isShow = false;
}
foreach (int rowIndex in Grid1.SelectedRowIndexArray)
{
string rowID = Grid1.DataKeys[rowIndex][0].ToString();
if (judgementDelete(rowID, isShow))
{
var checkStatic = Funs.DB.CH_CheckStatic.FirstOrDefault(x => x.CheckStaticId == rowID);
Funs.DB.CH_CheckStatic.DeleteOnSubmit(checkStatic);
Funs.DB.SubmitChanges();
//BLL.Sys_LogService.AddLog(BLL.Const.System_7, this.CurrUser.LoginProjectId, this.CurrUser.UserId, "删除焊口信息");
}
}
ShowNotify("删除成功!", MessageBoxIcon.Success);
this.BindGrid();
}
else
{
Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
}
}
#endregion
#region
/// <summary>
/// 报表打印
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnPrint_Click(object sender, EventArgs e)
{
string detectionMethod = this.tvControlItem.SelectedNodeID;
if (!string.IsNullOrEmpty(detectionMethod))
{
string strSql = @"SELECT [CheckStaticId]
,[Installation_ID]
,[InstallationName]
,[CH_TrustID]
,[CH_TrustCode]
,[Trust_Date]
,[ISO_ID]
,[ISO_IsoNo]
,[JOT_ID]
,[JOT_JointNo]
,[WorkAmout1]
,[WorkAmout2]
,[FilmSpecifications]
,[FilmLocNum]
,[JOT_JointDesc]
,[MaterialId]
,[MaterialCode]
,[DetectionRateId]
,[DetectionRateCode]
,[WED_ID]
,[WED_Code]
,[CheckLevel]
,[DefectType]
,[DefectNum]
,[EvaluateLevel]
,[CheckDate]
,[CheckTemperature]
,[ReportNo]
,[ReportDate]
,[ReportAmount]
,[ProgressMoney]
,[CheckPerson]
,[RefilmReason]
,[FilmSpec]
,[CheckResult]
,[CheckResultDate]
,[CheckResultNum]
,[WME_ID]
,[WeldingMethodCode]
,[CheckThingName]
,[WorkAreaId]
,[WorkAreaCode]
,[UnidId]
,[UnitName]
,[ISOExecutive]
,[TrustUnitId]
,[TrustUnitName]
,[ProjectId]
,[ProjectName]
,[CheckThingType]
,[CheckOpportunity]
,[RadialType]
,[FilmBlack]
,[Remark]
,[CreateDate]
,[Status]
,[DetectionTypeCode]
,[DefectCode]
FROM [dbo].[CH_CheckStatic] where ProjectId = @projectId ";
List<SqlParameter> listStr = new List<SqlParameter>
{
new SqlParameter("@projectId", this.CurrUser.LoginProjectId)
};
if (!string.IsNullOrEmpty(this.tvControlItem.SelectedNodeID))
{
string[] SelectedNodes = this.tvControlItem.SelectedNodeID.Split('|');
if (SelectedNodes.Length > 0)
{
strSql += " and ReportNo = @ReportNo ";
listStr.Add(new SqlParameter("@ReportNo", SelectedNodes[0]));
}
if (SelectedNodes.Length > 1)
{
strSql += " and ReportDate >= @ReportDateA and ReportDate<=@ReportDateZ ";
listStr.Add(new SqlParameter("@ReportDateA", SelectedNodes[1]));
listStr.Add(new SqlParameter("@ReportDateZ", SelectedNodes[1] + " 23:59:59"));
}
if (SelectedNodes.Length > 2)
{
strSql += " and DetectionTypeCode = @DetectionTypeCode ";
listStr.Add(new SqlParameter("@DetectionTypeCode", SelectedNodes[2]));
}
}
SqlParameter[] parameter = listStr.ToArray();
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
var projectName = BLL.ProjectService.GetProjectNameByProjectId(this.CurrUser.LoginProjectId);
Dictionary<string, string> keyValuePairs = new Dictionary<string, string>();
keyValuePairs.Add("ProjectName", projectName);
BLL.Common.FastReportService.ResetData();
if (tb != null)
{
tb.TableName = "Data";
if (tb.Rows.Count > 0)
{
keyValuePairs.Add("TrustUnit", tb.Rows[0]["TrustUnitName"].ToString());
keyValuePairs.Add("ConUnit", tb.Rows[0]["UnitName"].ToString());
keyValuePairs.Add("ReportNo", tb.Rows[0]["ReportNo"].ToString());
keyValuePairs.Add("WorkAreaCode", tb.Rows[0]["WorkAreaCode"].ToString());
keyValuePairs.Add("WeldingMethodCode", tb.Rows[0]["WeldingMethodCode"].ToString());
keyValuePairs.Add("DetectionRateCode", tb.Rows[0]["DetectionRateCode"].ToString());
keyValuePairs.Add("CheckOpportunity", tb.Rows[0]["CheckOpportunity"].ToString());
keyValuePairs.Add("CheckLevel", tb.Rows[0]["CheckLevel"].ToString());
keyValuePairs.Add("InstallationName", tb.Rows[0]["InstallationName"].ToString());
}
}
BLL.Common.FastReportService.AddFastreportParameter(keyValuePairs);
BLL.Common.FastReportService.AddFastreportTable(tb);
string initTemplatePath = "";
string rootPath = Server.MapPath("~/");
initTemplatePath = "File\\Fastreport\\管道MT报告模板.frx";
if (this.tvControlItem.SelectedNodeID.Split('|').Length > 2)
{
string type = this.tvControlItem.SelectedNodeID.Split('|')[2] ;
switch (type)
{
case "RT\\UT":
case "RT": initTemplatePath = "File\\Fastreport\\管道RT报告模板.frx"; break;
case "PT":
initTemplatePath = "File\\Fastreport\\管道PT报告模板.frx";
break;
case "UT":
initTemplatePath = "File\\Fastreport\\管道UT报告模板.frx";
break;
case "MT": initTemplatePath = "File\\Fastreport\\管道MT报告模板.frx"; break;
case "TOFD\\UT\\MT":
case "TOFD\\MT":
case "3D-TFM":
case "TOFD": initTemplatePath = "File\\Fastreport\\管道TOFD报告模板.frx"; break;
}
}
if (File.Exists(rootPath + initTemplatePath))
{
PageContext.RegisterStartupScript(Window5.GetShowReference(String.Format("../TrustManage/Fastreport.aspx?ReportPath={0}", rootPath + initTemplatePath)));
}
}
else
{
Alert.ShowInTop("请选择检测方法!", MessageBoxIcon.Warning);
return;
}
}
#endregion
#region
/// <summary>
/// 关闭弹出窗口
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Window1_Close(object sender, WindowCloseEventArgs e)
{
this.InitTreeMenu();//加载树
this.BindGrid();
}
/// <summary>
/// 查询
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void TextBox_TextChanged(object sender, EventArgs e)
{
this.BindGrid();
}
/// <summary>
/// 查询
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Tree_TextChanged(object sender, EventArgs e)
{
this.InitTreeMenu();
this.BindGrid();
}
#endregion
#region
/// <summary>
/// 判断是否可以删除
/// </summary>
/// <returns></returns>
private bool judgementDelete(string id, bool isShow)
{
string content = string.Empty;
//if (BLL.HJGL_HotProessManageEditService.GetHotProessByJotId(id) > 0)
//{
// content = "热处理已经使用了该焊口,不能删除!";
//}
//if (BLL.Funs.DB.HJGL_CH_TrustItem.FirstOrDefault(x => x.JOT_ID == id) != null)
//{
// content = "无损委托已经使用了该焊口,不能删除!";
//}
//if (BLL.Funs.DB.HJGL_CH_CheckItem.FirstOrDefault(x => x.JOT_ID == id) != null)
//{
// content = "检测单已经使用了该焊口,不能删除!";
//}
if (string.IsNullOrEmpty(content))
{
return true;
}
else
{
if (isShow)
{
Alert.ShowInTop(content, MessageBoxIcon.Error);
}
return false;
}
}
#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.HJGL_JointInfoMenuId, button);
}
#endregion
#region
/// <summary>
/// 查询
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void txtJOT_JointNo_TextChanged(object sender, EventArgs e)
{
BindGrid();
}
#endregion
}
}