2024-05-08 17:17:11 +08:00
using BLL ;
using Model ;
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.YLRQ.ConstructionManagement
{
public partial class WeldReport : PageBase
{
/// <summary>
/// 焊接日报主键
/// </summary>
public string DReportID
{
get { return ( string ) ViewState [ "DReportID" ] ; }
set { ViewState [ "DReportID" ] = value ; }
}
/// <summary>
/// 项目ID
/// </summary>
public string ProjectId
{
get { return ( string ) ViewState [ "ProjectId" ] ; }
set { ViewState [ "ProjectId" ] = value ; }
}
/// <summary>
/// 页面加载
/// </summary>
protected void Page_Load ( object sender , EventArgs e )
{
if ( ! IsPostBack )
{
this . ddlPageSize . SelectedValue = this . Grid1 . PageSize . ToString ( ) ;
this . DReportID = string . Empty ;
this . txtReportDate . Text = string . Format ( "{0:yyyy-MM}" , DateTime . Now ) ;
BridProjectGrid ( ) ;
this . InitTreeMenu ( ) ; //加载树
}
}
#region 树 控 件
/// <summary>
/// 绑定项目
/// </summary>
public void BridProjectGrid ( )
{
GridProject . DataSource = BLL . Base_ProjectService . GetYlrqProjectListByUserId ( this . CurrUser . UserId , "2" ) ;
GridProject . DataBind ( ) ;
drpProject . Value = this . CurrUser . LoginProjectId ;
}
/// <summary>
/// 加载树
/// </summary>
private void InitTreeMenu ( )
{
this . tvControlItem . Nodes . Clear ( ) ;
if ( string . IsNullOrEmpty ( this . txtReportDate . Text . Trim ( ) ) )
{
ShowNotify ( "请选择日报月份!" , MessageBoxIcon . Warning ) ;
return ;
}
TreeNode rootNode = new TreeNode ( ) ;
rootNode . Text = "月份-日期-日报号" ;
rootNode . NodeID = "0" ;
rootNode . ToolTip = "月份" ;
rootNode . Expanded = true ;
this . tvControlItem . Nodes . Add ( rootNode ) ;
DateTime startTime = Funs . GetNewDateTime ( this . txtReportDate . Text . Trim ( ) ) . Value ;
DateTime endTime = startTime . AddMonths ( 1 ) ;
var days = ( from x in Funs . DB . PV_BO_WeldReportMain
where x . ReportDate > = startTime & & x . ReportDate < endTime
& & x . ProjectId = = this . drpProject . Value & & x . ReportType = = 1
orderby x . ReportDate descending
select x . ReportDate ) . Distinct ( ) ;
foreach ( var item in days )
{
TreeNode newNode = new TreeNode ( ) ;
newNode . Text = string . Format ( "{0:yyyy-MM-dd}" , item ) ;
newNode . NodeID = item . ToString ( ) + "|" + rootNode . NodeID ;
newNode . ToolTip = "日期" ;
newNode . EnableExpandEvent = true ;
rootNode . Nodes . Add ( newNode ) ;
TreeNode tn = new TreeNode ( ) ;
tn . NodeID = "temp" ;
tn . Text = "正在加载..." ;
newNode . Nodes . Add ( tn ) ;
}
}
/// <summary>
/// 绑定树节点
/// </summary>
private void BindNodes ( TreeNode node , string projectId )
{
if ( node . ToolTip = = "日期" )
{
var dReports = from x in Funs . DB . PV_BO_WeldReportMain
where x . ReportDate = = Funs . GetNewDateTime ( node . Text )
& & x . ProjectId = = projectId & & x . ReportType = = 1
orderby x . WeldDailyReportNo descending
select x ;
foreach ( var item in dReports )
{
TreeNode newNode = new TreeNode ( ) ;
newNode . Text = ! string . IsNullOrEmpty ( item . WeldDailyReportNo ) ? item . WeldDailyReportNo : newNode . Text = "未知" ;
if ( string . IsNullOrEmpty ( this . IsDelete ( item . DReportID ) ) )
{
newNode . Text = "<font color='#FF7575'>" + newNode . Text + "</font>" ;
node . Text = "<font color='#FF7575'>" + node . Text + "</font>" ;
node . ToolTip = "该日报下焊口所在批已关闭或已做热处理,不能删除" ;
node . ParentNode . Text = "<font color='#FF7575'>" + node . ParentNode . Text + "</font>" ;
}
newNode . NodeID = item . DReportID ;
newNode . EnableClickEvent = true ;
node . Nodes . Add ( newNode ) ;
}
}
}
/// <summary>
/// 施工号下拉框
/// </summary>
protected void drpProject_TextChanged ( object sender , EventArgs e )
{
this . InitTreeMenu ( ) ;
this . BindGrid ( this . DReportID ) ;
}
#endregion
#region 点 击 TreeView
/// <summary>
/// 点击TreeView
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void tvControlItem_NodeCommand ( object sender , TreeCommandEventArgs e )
{
if ( tvControlItem . SelectedNodeID ! = null )
{
var report = Funs . DB . PV_BO_WeldReportMain . FirstOrDefault ( p = > p . DReportID = = tvControlItem . SelectedNodeID ) ;
this . ProjectId = report . ProjectId ;
this . DReportID = report . DReportID ;
this . BindGrid ( report . DReportID ) ;
}
}
/// <summary>
/// 节点树搜索
/// </summary>
protected void tvControlItem_NodeExpand ( object sender , TreeNodeEventArgs e )
{
if ( e . Node . Nodes ! = null )
{
e . Node . Nodes . Clear ( ) ;
}
this . BindNodes ( e . Node , this . drpProject . Value ) ;
}
#endregion
#region 数 据 绑 定
/// <summary>
/// 数据绑定
/// </summary>
private void BindGrid ( string dReportID )
{
this . PageInfoLoad ( dReportID ) ;
string strSql = @"SELECT weld.WeldingId,project.ProjectCode,weld.WeldingCode,weld.BackingWelderId,(select a.pkidStr from (SELECT STUFF(( SELECT ',' +convert(VARCHAR, WED_Name) FROM (select Welder.WED_Name from HJGL_BS_Welder as Welder where Welder.WED_ID in (select Id from StrToTable(weld.BackingWelderId)))t FOR XML PATH('')), 1, 1, '') AS pkidStr) a) as BackingWelderName,weld.CoverWelderId,(select a.pkidStr from (SELECT STUFF(( SELECT ',' +convert(VARCHAR, WED_Name) FROM (select Welder.WED_Name from HJGL_BS_Welder as Welder where Welder.WED_ID in (select Id from StrToTable(weld.CoverWelderId)))t FOR XML PATH('')), 1, 1, '') AS pkidStr) a) as CoverWelderName,WeldMethod.WME_Name,weld.Confirmation,(case Confirmation when 0 then '未确认' when 1 then '已确认' else '' end) as ConfirmationName,weld.SortField FROM PV_WeldInformation AS weld LEFT JOIN HJGL_BS_WeldMethod AS weldMethod ON weldMethod.WME_ID = weld.WmeId LEFT JOIN Base_Project as project on project.ProjectId=weld.ProjectId WHERE weld.DReportID=@DReportID order by weld.SortField" ;
List < SqlParameter > listStr = new List < SqlParameter > ( ) ;
listStr . Add ( new SqlParameter ( "@DReportID" , dReportID ) ) ;
SqlParameter [ ] parameter = listStr . ToArray ( ) ;
DataTable tb = SQLHelper . GetDataTableRunText ( strSql , parameter ) ;
// 2.获取当前分页数据
Grid1 . RecordCount = tb . Rows . Count ;
tb = GetFilteredTable ( Grid1 . FilteredData , tb ) ;
var table = this . GetPagedDataTable ( Grid1 , tb ) ;
Grid1 . DataSource = table ;
Grid1 . DataBind ( ) ;
}
/// <summary>
/// 加载页面输入提交信息
/// </summary>
private void PageInfoLoad ( string dReportID )
{
this . btnEdit . Hidden = true ;
this . btnDelete . Hidden = true ;
this . SimpleForm1 . Reset ( ) ; ///重置所有字段
var report = Funs . DB . PV_BO_WeldReportMain . FirstOrDefault ( p = > p . DReportID = = dReportID ) ;
if ( report ! = null )
{
this . lblWeldDailyReportNo . Text = report . WeldDailyReportNo ;
if ( ! string . IsNullOrEmpty ( report . UnitId ) )
{
var unit = BLL . Base_UnitService . GetUnit ( report . UnitId ) ;
if ( unit ! = null )
{
this . lblUnit . Text = unit . UnitName ;
}
}
if ( ! string . IsNullOrEmpty ( report . Tabler ) )
{
var tabler = BLL . Sys_UserService . GetUsersByUserId ( report . Tabler ) ;
if ( tabler ! = null )
{
this . lblTabler . Text = tabler . UserName ;
}
}
this . lblTableDate . Text = string . Format ( "{0:yyyy-MM-dd}" , report . TableDate ) ;
this . lblbReportDate . Text = string . Format ( "{0:yyyy-MM-dd}" , report . ReportDate ) ;
this . lblRemark . Text = report . Remark ;
this . btnDelete . Hidden = false ;
if ( string . IsNullOrEmpty ( this . IsDelete ( report . DReportID ) ) )
{
this . btnEdit . Hidden = false ;
}
}
}
#endregion
/// <summary>
/// 判断是否可删除
/// </summary>
/// <returns></returns>
private string IsDelete ( string dReportID )
{
string isDeleteInfo = string . Empty ;
#region 注 释
//// 判断页面信息是否能修改 是否已点口
//var infos = from x in Funs.DB.HJGL_PW_JointInfo where x.DReportID == dReportID select x;
//if (infos.Count() > 0)
//{
// string massage = string.Empty;
// foreach (var item in infos)
// {
// var batchDetail = BLL.HJGL_BO_BatchDetailService.GetBatchDetailByJotId(item.JOT_ID);
// if (batchDetail != null)
// {
// var batch = BLL.HJGL_BO_BatchService.GetBatchById(batchDetail.BatchId);
// if (batch != null && batch.BatchIsClosed == true)
// {
// massage += "焊口号:" + item.JOT_JointNo + ";所在批号:" + batch.BatchCode;
// }
// }
// }
// if (!string.IsNullOrEmpty(massage))
// {
// isDeleteInfo += "该日报下焊口所在批已关闭!" + massage;
// }
//}
////是否已做热处理
//var hotProessItem = from x in Funs.DB.View_HotProessItem where x.DReportID == dReportID && x.HotProessId != null select x;
//if (hotProessItem.Count() > 0)
//{
// string hotMassage = string.Empty;
// foreach (var itemHot in hotProessItem)
// {
// hotMassage += "焊口号:" + itemHot.JOT_JointNo;
// var dr = Funs.DB.HJGL_HotProess.FirstOrDefault(x => x.HotProessId == itemHot.HotProessId);
// if (dr != null)
// {
// hotMassage += ";热处理单号:" + dr.HotProessNo;
// }
// }
// isDeleteInfo += "该日报下焊口已做热处理!" + hotMassage;
//}
#endregion
return isDeleteInfo ;
}
#region 分 页 排 序
/// <summary>
/// 页索引改变事件
/// </summary>
protected void Grid1_PageIndexChange ( object sender , GridPageEventArgs e )
{
Grid1 . PageIndex = e . NewPageIndex ;
BindGrid ( this . DReportID ) ;
}
/// <summary>
/// 排序
/// </summary>
protected void Grid1_Sort ( object sender , GridSortEventArgs e )
{
Grid1 . SortDirection = e . SortDirection ;
Grid1 . SortField = e . SortField ;
BindGrid ( this . DReportID ) ;
}
/// <summary>
/// 分页选择下拉改变事件
/// </summary>
protected void ddlPageSize_SelectedIndexChanged ( object sender , EventArgs e )
{
Grid1 . PageSize = Convert . ToInt32 ( ddlPageSize . SelectedValue ) ;
BindGrid ( this . DReportID ) ;
}
#endregion
#region 焊 接 日 报
/// <summary>
/// 焊接日报
/// </summary>
protected void btnNew_Click ( object sender , EventArgs e )
{
if ( CommonService . GetAllButtonPowerList ( this . CurrUser . LoginProjectId , this . CurrUser . UserId , Const . PV_WeldReport , Const . BtnAdd ) )
{
if ( CommonService . GetAllButtonPowerList ( this . CurrUser . LoginProjectId , this . CurrUser . UserId , Const . HJGL_WeldReportMenuId , Const . BtnAdd ) )
{
string window = String . Format ( "WeldReportEdit.aspx?DReportID={0}" , string . Empty , "新增 - " ) ;
PageContext . RegisterStartupScript ( Window1 . GetSaveStateReference ( this . hdDReportID . ClientID )
+ Window1 . GetShowReference ( window ) ) ;
}
else
{
ShowNotify ( "您没有这个权限,请与管理员联系!" , MessageBoxIcon . Warning ) ;
}
}
else
{
ShowNotify ( "您没有这个权限,请与管理员联系!" , MessageBoxIcon . Warning ) ;
}
}
/// <summary>
/// 编辑焊接日报
/// </summary>
protected void btnEdit_Click ( object sender , EventArgs e )
{
if ( CommonService . GetAllButtonPowerList ( this . CurrUser . LoginProjectId , this . CurrUser . UserId , Const . PV_WeldReport , Const . BtnEdit ) )
{
if ( ! string . IsNullOrEmpty ( this . IsDelete ( this . DReportID ) ) )
{
ShowNotify ( "已使用单据不能修改!" , MessageBoxIcon . Warning ) ;
return ;
}
var weldReport = Funs . DB . PV_BO_WeldReportMain . FirstOrDefault ( x = > x . DReportID = = this . DReportID ) ;
if ( weldReport ! = null )
{
string window = string . Format ( "WeldReportEdit.aspx?DReportID={0}" , this . DReportID , "编辑 - " ) ;
PageContext . RegisterStartupScript ( Window1 . GetSaveStateReference ( this . hdDReportID . ClientID )
+ Window1 . GetShowReference ( window ) ) ;
}
else
{
ShowNotify ( "请先选择日报!" , MessageBoxIcon . Warning ) ;
}
}
else
{
ShowNotify ( "您没有这个权限,请与管理员联系!" , MessageBoxIcon . Warning ) ;
}
}
/// <summary>
/// 删除焊接日报
/// </summary>
protected void btnDelete_Click ( object sender , EventArgs e )
{
if ( CommonService . GetAllButtonPowerList ( this . CurrUser . LoginProjectId , this . CurrUser . UserId , Const . PV_WeldReport , Const . BtnDelete ) )
{
string info = this . IsDelete ( this . DReportID ) ;
if ( ! String . IsNullOrEmpty ( info ) )
{
Alert . ShowInTop ( info , MessageBoxIcon . Warning ) ;
return ;
}
if ( ! string . IsNullOrEmpty ( this . DReportID ) )
{
List < PV_WeldInformation > weldInfo = Funs . DB . PV_WeldInformation . Where ( p = > p . DReportID = = this . DReportID ) . ToList ( ) ;
if ( weldInfo . Count > 0 )
{
foreach ( var item in weldInfo )
{
item . DReportID = null ;
item . CoverWelderId = string . Empty ;
item . BackingWelderId = string . Empty ;
2026-02-10 15:55:39 +08:00
item . Confirmation = null ;
2024-05-08 17:17:11 +08:00
Funs . DB . SubmitChanges ( ) ;
}
}
var reportModel = Funs . DB . PV_BO_WeldReportMain . FirstOrDefault ( p = > p . DReportID = = this . DReportID ) ;
Funs . DB . PV_BO_WeldReportMain . DeleteOnSubmit ( reportModel ) ;
2026-02-10 15:55:39 +08:00
Funs . DB . SubmitChanges ( ) ;
2024-05-08 17:17:11 +08:00
Alert . ShowInTop ( "删除成功!" , MessageBoxIcon . Success ) ;
this . InitTreeMenu ( ) ;
this . BindGrid ( this . DReportID ) ;
}
else
{
ShowNotify ( "请先选择日报!" , MessageBoxIcon . Warning ) ;
}
}
else
{
ShowNotify ( "您没有这个权限,请与管理员联系!" , MessageBoxIcon . Warning ) ;
}
}
#endregion
#region 关 闭 弹 出 窗 口 及 刷 新 页 面
/// <summary>
/// 关闭弹出窗口
/// </summary>
protected void Window1_Close ( object sender , WindowCloseEventArgs e )
{
this . DReportID = this . hdDReportID . Text ;
this . BindGrid ( this . DReportID ) ;
this . InitTreeMenu ( ) ;
this . hdDReportID . Text = string . Empty ;
}
/// <summary>
/// 查询
/// </summary>
protected void Tree_TextChanged ( object sender , EventArgs e )
{
this . InitTreeMenu ( ) ;
this . BindGrid ( this . DReportID ) ;
}
#endregion
#region 私 有 方 法
/// <summary>
/// 得到是否热处理
/// </summary>
/// <returns></returns>
protected string ConvertISProess ( string weldingId )
{
var result = string . Empty ;
var weldModel = Funs . DB . PV_WeldInformation . FirstOrDefault ( p = > p . WeldingId = = weldingId ) ;
if ( weldModel ! = null )
{
result = weldModel . IsProess ! = null ? ( weldModel . IsProess . Value ? "是" : "否" ) : string . Empty ;
}
return result ;
}
#endregion
}
}