2024-05-08 17:17:11 +08:00
using System ;
using System.Collections.Generic ;
using System.Data.SqlClient ;
using System.Data ;
using System.Linq ;
using BLL ;
namespace FineUIPro.Web.WeldMat.UsingPlan
{
public partial class UsingPlan : PageBase
{
#region 加 载 页 面
/// <summary>
/// 加载页面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load ( object sender , EventArgs e )
{
if ( ! IsPostBack )
{
ddlPageSize . SelectedValue = Grid1 . PageSize . ToString ( ) ;
this . drpProjectId . DataTextField = "ProjectCode" ;
this . drpProjectId . DataValueField = "ProjectId" ;
this . drpProjectId . DataSource = BLL . Base_ProjectService . GetOnProjectListByUserId ( this . CurrUser . UserId , "1" ) ;
this . drpProjectId . DataBind ( ) ;
Funs . FineUIPleaseSelect ( this . drpProjectId ) ;
string lastPlan = @ "SELECT p.UsingPlanId FROM dbo.Weld_UsingPlan p
WHERE p . OrderDate < CONVERT ( char ( 10 ) , GetDate ( ) , 120 )
AND p . IsCancel = 0
AND ( SELECT COUNT ( * ) FROM dbo . Weld_UsingMat u WHERE u . UsingPlanId = p . UsingPlanId ) = 0 ";
DataTable dt = SQLHelper . GetDataTableRunText ( lastPlan , null ) ;
if ( dt . Rows . Count > 0 )
{
for ( int i = 0 ; i < dt . Rows . Count ; i + + )
{
string usingPlanId = dt . Rows [ i ] [ "UsingPlanId" ] . ToString ( ) ;
BLL . UsingPlanService . UpdateIsCancel ( usingPlanId , "超时未领用" ) ;
}
}
// 绑定表格
BindGrid ( ) ;
}
}
/// <summary>
/// 绑定数据
/// </summary>
private void BindGrid ( )
{
string projectIds = BLL . Project_UserService . GetStrProjectIds ( this . CurrUser . UserId ) ;
string strSql = @ "SELECT UsingPlan.UsingPlanId, UsingPlan.WeldId, UsingPlan.ProjectId, UsingPlan.UsePosition,team.TeamGroupName,UsingPlan.STE_Name,
unit . UnitName AS UsingUnit , UsingPlan . Amount , UsingPlan . UsingManOne , UsingPlan . InPutDate ,
UsingPlan . OrderDate , UsingPlan . OrderTime , UsingPlan . CancelDate , UsingPlan . IsNeedConfirm ,
( CASE UsingPlan . IsSteelStru WHEN 1 THEN '是' WHEN 0 THEN '否' ELSE ' ' END ) AS IsSteelStru ,
( CASE UsingPlan . IsSubmit WHEN 1 THEN '是' WHEN 0 THEN '否' ELSE ' ' END ) AS IsSubmit ,
( CASE UsingPlan . IsCancel WHEN 1 THEN '是' WHEN 0 THEN '否' ELSE ' ' END ) AS IsCancel ,
Weld . WeldCode , Weld . WeldName , Weld . WeldSpec , WeldType . WeldUnit , WeldType . WeldTypeName ,
Project . ProjectCode , Welder . WED_Name AS UsingManOneName , UsingPlan . IsSubmit AS WelderAudit ,
2026-02-10 15:55:39 +08:00
( CASE WHEN UsingPlan . InPutMan IS NOT NULL THEN ( CASE WHEN userInput . UserName IS NOT NULL THEN userInput . UserName ELSE welderInput . WED_Name END )
2024-05-08 17:17:11 +08:00
ELSE ' ' END ) AS InPutMan ,
2026-02-10 15:55:39 +08:00
auditMan . UserName AS ConfirmMan , - - 焊 工 领 料 计 划 审 核 人
2024-05-08 17:17:11 +08:00
( ( SELECT ISNULL ( SUM ( ISNULL ( us . Amount , 0 ) ) , 0 ) FROM dbo . Weld_UsingMat us WHERE us . UsingPlanId = UsingPlan . UsingPlanId ) -
( SELECT ISNULL ( SUM ( ISNULL ( re . RecycleAmount , 0 ) ) , 0 ) FROM dbo . Weld_RecycleMat re WHERE re . UsingPlanId = UsingPlan . UsingPlanId ) )
AS UsedAmount , ( CASE UsingPlan . IsFinish WHEN 1 THEN '是' WHEN 0 THEN '否' ELSE NULL END ) AS IsFinish
FROM dbo . Weld_UsingPlan AS UsingPlan
LEFT JOIN dbo . Weld_WeldInfo AS Weld ON Weld . WeldId = UsingPlan . WeldId
LEFT JOIN dbo . Base_Project AS Project ON Project . ProjectId = UsingPlan . ProjectId
LEFT JOIN dbo . Weld_WeldType AS WeldType ON WeldType . WeldTypeId = Weld . WeldTypeId
LEFT JOIN dbo . HJGL_BS_Welder AS Welder ON Welder . WED_ID = UsingPlan . UsingManOne
LEFT JOIN dbo . Base_Unit unit ON unit . UnitId = UsingPlan . UsingUnit
LEFT JOIN dbo . Sys_User AS userInput ON userInput . UserId = UsingPlan . InPutMan
2026-02-10 15:55:39 +08:00
LEFT JOIN dbo . Sys_User AS auditMan ON auditMan . UserId = UsingPlan . ConfirmMan
2024-05-08 17:17:11 +08:00
LEFT JOIN dbo . HJGL_BS_Welder AS welderInput ON welderInput . WED_ID = UsingPlan . InPutMan
LEFT JOIN dbo . Base_TeamGroup team ON team . TeamGroupId = UsingPlan . TeamGroupId
WHERE Project . IsClosed = 0 ";
List < SqlParameter > listStr = new List < SqlParameter > ( ) ;
if ( this . rblUsed . SelectedValue = = "0" ) // 未领用
{
strSql + = " AND IsCancel=0 AND (SELECT COUNT(*) FROM dbo.Weld_UsingMat u WHERE u.UsingPlanId=UsingPlan.UsingPlanId)=0 " ;
}
else if ( this . rblUsed . SelectedValue = = "1" ) // 已领用
{
strSql + = " AND (SELECT COUNT(*) FROM dbo.Weld_UsingMat u WHERE u.UsingPlanId=UsingPlan.UsingPlanId)>0 " ;
}
else // 已作废
{
strSql + = " AND IsCancel=1" ;
}
if ( this . drpProjectId . SelectedValue ! = Const . _Null )
{
strSql + = " AND UsingPlan.ProjectId = @ProjectId" ;
listStr . Add ( new SqlParameter ( "@ProjectId" , this . drpProjectId . SelectedValue ) ) ;
}
if ( CurrUser . Account ! = Const . Gly )
{
strSql + = " AND CHARINDEX(UsingPlan.ProjectId,@ProjectIds)>0" ;
//listStr.Add(new SqlParameter("@UsingUnit", CurrUser.UnitId));
listStr . Add ( new SqlParameter ( "@ProjectIds" , projectIds ) ) ;
//strSql += " AND UsingPlan.UsingUnit = @UsingUnit";
//listStr.Add(new SqlParameter("@UsingUnit", CurrUser.UnitId));
}
if ( ! string . IsNullOrEmpty ( this . txtWeldName . Text . Trim ( ) ) )
{
strSql + = " AND Weld.WeldName LIKE @WeldName" ;
listStr . Add ( new SqlParameter ( "@WeldName" , "%" + this . txtWeldName . Text . Trim ( ) + "%" ) ) ;
}
if ( ! string . IsNullOrEmpty ( this . txtUsingMan . Text . Trim ( ) ) )
{
strSql + = " AND Welder.WED_Name LIKE @UsingMan" ;
listStr . Add ( new SqlParameter ( "@UsingMan" , "%" + this . txtUsingMan . Text . Trim ( ) + "%" ) ) ;
}
if ( ! string . IsNullOrEmpty ( this . txtInputMan . Text . Trim ( ) ) )
{
strSql + = " AND (CASE WHEN UsingPlan.InPutMan IS NOT NULL THEN (CASE WHEN userInput.UserName IS NOT NULL THEN userInput.UserName ELSE welderInput.WED_Name END) ELSE '' END) LIKE @InputMan" ;
listStr . Add ( new SqlParameter ( "@InputMan" , "%" + this . txtInputMan . Text . Trim ( ) + "%" ) ) ;
}
if ( ! string . IsNullOrEmpty ( this . txtUsingUnit . Text . Trim ( ) ) )
{
strSql + = " AND unit.UnitName LIKE @UnitName" ;
listStr . Add ( new SqlParameter ( "@UnitName" , "%" + this . txtUsingUnit . Text . Trim ( ) + "%" ) ) ;
}
//if (cbIsNeedConfirm.Checked)
//{
// strSql += " AND UsingPlan.IsNeedConfirm = 1";
//}
SqlParameter [ ] parameter = listStr . ToArray ( ) ;
DataTable tb = SQLHelper . GetDataTableRunText ( strSql , parameter ) ;
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 drpProjectId_SelectedIndexChanged ( object sender , EventArgs e )
{
BindGrid ( ) ;
}
protected void btnSelect_Click ( object sender , EventArgs e )
{
BindGrid ( ) ;
}
protected void rblUsed_SelectedIndexChanged ( object sender , EventArgs e )
{
BindGrid ( ) ;
}
#endregion
protected void Grid1_RowCommand ( object sender , GridCommandEventArgs e )
{
if ( e . CommandName = = "ConfirmFinish" )
{
if ( ! string . IsNullOrEmpty ( this . Grid1 . SelectedRowID ) )
{
var plan = BLL . UsingPlanService . GetUsingPlanById ( this . Grid1 . SelectedRowID ) ;
if ( plan . IsFinish = = null | | plan . IsFinish = = false )
{
string window = String . Format ( "../../FingerMark/FingerConfirm.aspx?keyId={0}&flag=2&grid=4" , this . Grid1 . SelectedRowID , "编辑 - " ) ;
PageContext . RegisterStartupScript ( Window2 . GetSaveStateReference ( this . Grid1 . SelectedRowID )
+ Window2 . GetShowReference ( window ) ) ;
}
else
{
ShowNotify ( "该领料计划已完成" ) ;
}
}
}
}
protected void Grid1_RowDataBound ( object sender , GridRowEventArgs e )
{
DataRowView row = e . DataItem as DataRowView ;
//bool con = false;
//if (row["IsNeedConfirm"].ToString()!="")
//{
// con= Convert.ToBoolean(row["IsNeedConfirm"]);
//}
//if (con)
//{
// e.RowCssClass = "color1";
//}
var plan = BLL . UsingPlanService . GetUsingPlanById ( e . RowID ) ;
if ( plan ! = null )
{
var welder = BLL . HJGL_PersonManageService . GetWelderByWenId ( plan . InPutMan ) ;
if ( welder = = null )
{
CheckBoxField cb = Grid1 . FindColumn ( "WelderAudit" ) as CheckBoxField ;
e . CellCssClasses [ cb . ColumnIndex ] = "hidethis" ;
}
}
}
#region 表 头 过 滤
protected void Grid1_FilterChange ( object sender , EventArgs e )
{
BindGrid ( ) ;
}
#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 ( ) ;
}
#endregion
#region 排 序
/// <summary>
/// 排序
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_Sort ( object sender , 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 ddlPageSize_SelectedIndexChanged ( object sender , EventArgs e )
{
Grid1 . PageSize = Convert . ToInt32 ( ddlPageSize . SelectedValue ) ;
BindGrid ( ) ;
}
#endregion
#region 弹 出 编 辑 窗 口 关 闭 事 件
/// <summary>
/// 弹出编辑窗体关闭事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Window1_Close ( object sender , WindowCloseEventArgs e )
{
BindGrid ( ) ;
}
#endregion
#region 查 询
/// <summary>
/// 查询
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void TextBox_TextChanged ( object sender , EventArgs e )
{
BindGrid ( ) ;
}
#endregion
#region 增 加 按 钮
/// <summary>
/// 增加按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnNew_Click ( object sender , EventArgs e )
{
if ( BLL . CommonService . GetAllButtonPowerList ( this . CurrUser . LoginProjectId , this . CurrUser . UserId , BLL . Const . CLGL_UsingPlanMenuId , BLL . Const . BtnAdd ) )
{
PageContext . RegisterStartupScript ( Window1 . GetShowReference ( String . Format ( "UsingPlanEdit.aspx?UsingPlanId={0}" , string . Empty , "编辑 - " ) ) ) ;
}
}
#endregion
#region 编 辑
/// <summary>
/// 双击Grid事件
/// </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 ( BLL . CommonService . GetAllButtonPowerList ( this . CurrUser . LoginProjectId , this . CurrUser . UserId , BLL . Const . CLGL_UsingPlanMenuId , BLL . Const . BtnModify ) )
{
if ( Grid1 . SelectedRowIndexArray . Length = = 0 )
{
Alert . ShowInTop ( "请至少选择一条记录!" , MessageBoxIcon . Warning ) ;
return ;
}
string id = Grid1 . SelectedRowID ;
if ( ! string . IsNullOrEmpty ( id ) )
{
var usedMat = BLL . UsingMatService . GetUsingMatByPlanId ( id ) ;
if ( usedMat = = null )
{
PageContext . RegisterStartupScript ( Window1 . GetShowReference ( String . Format ( "UsingPlanEdit.aspx?UsingPlanId={0}" , id , "编辑 - " ) ) ) ;
}
else
{
Alert . ShowInTop ( "已有领用,不能修改!" , MessageBoxIcon . Warning ) ;
return ;
}
}
}
else
{
Alert . ShowInTop ( "您没有这个权限,请与管理员联系!" , MessageBoxIcon . Warning ) ;
return ;
}
}
#endregion
protected void btnConfirm_Click ( object sender , EventArgs e )
{
if ( BLL . CommonService . GetAllButtonPowerList ( this . CurrUser . LoginProjectId , this . CurrUser . UserId , BLL . Const . CLGL_UsingPlanMenuId , BLL . Const . BtnAuditing ) )
{
if ( Grid1 . SelectedRowIndexArray . Length = = 0 )
{
Alert . ShowInTop ( "请至少选择一条记录!" , MessageBoxIcon . Warning ) ;
return ;
}
string id = Grid1 . SelectedRowID ;
if ( ! string . IsNullOrEmpty ( id ) )
{
var noComfirm = BLL . UsingPlanService . GetUsingPlanById ( id ) ;
if ( noComfirm . UsingUnit = = CurrUser . UnitId )
{
if ( noComfirm ! = null & & noComfirm . IsNeedConfirm = = true )
{
BLL . UsingPlanService . UpdateIsNeedConfirm ( noComfirm . UsingPlanId , false ) ;
Alert . ShowInTop ( "已审核确认!" , MessageBoxIcon . Success ) ;
BindGrid ( ) ;
}
else
{
Alert . ShowInTop ( "正常计划不用确认!" , MessageBoxIcon . Warning ) ;
return ;
}
}
else
{
Alert . ShowInTop ( "非本单位数据,不能审核确认!" , MessageBoxIcon . Warning ) ;
return ;
}
}
}
else
{
Alert . ShowInTop ( "您没有这个权限,请与管理员联系!" , MessageBoxIcon . Warning ) ;
return ;
}
}
/// <summary>
/// 焊工录入计划审核
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnAudit_Click ( object sender , EventArgs e )
{
if ( BLL . CommonService . GetAllButtonPowerList ( this . CurrUser . LoginProjectId , this . CurrUser . UserId , BLL . Const . CLGL_UsingPlanMenuId , BLL . Const . BtnAuditing ) )
{
bool selectItem = false ;
CheckBoxField cb = Grid1 . FindColumn ( "WelderAudit" ) as CheckBoxField ;
for ( int i = 0 ; i < Grid1 . Rows . Count ; i + + )
{
string planId = Grid1 . DataKeys [ i ] [ 0 ] . ToString ( ) ;
var plan = BLL . UsingPlanService . GetUsingPlanById ( planId ) ;
var welder = BLL . HJGL_PersonManageService . GetWelderByWenId ( plan . InPutMan ) ;
if ( cb . GetCheckedState ( i ) = = true & & welder ! = null )
{
2026-02-10 15:55:39 +08:00
BLL . UsingPlanService . UpdateIsSubmit ( planId , this . CurrUser . UserId ) ;
2024-05-08 17:17:11 +08:00
selectItem = true ;
}
}
if ( selectItem )
{
BindGrid ( ) ;
ShowNotify ( "所选记录已审核!" , MessageBoxIcon . Success ) ;
}
else
{
Alert . ShowInTop ( "请选择要审核的记录!" , MessageBoxIcon . Warning ) ;
return ;
}
}
else
{
Alert . ShowInTop ( "您没有这个权限,请与管理员联系!" , MessageBoxIcon . Warning ) ;
return ;
}
}
#region 删 除
/// <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 ( BLL . CommonService . GetAllButtonPowerList ( this . CurrUser . LoginProjectId , this . CurrUser . UserId , BLL . Const . CLGL_UsingPlanMenuId , BLL . Const . BtnDelete ) )
{
if ( Grid1 . SelectedRowIndexArray . Length > 0 )
{
bool isShow = false ;
if ( Grid1 . SelectedRowIndexArray . Length = = 1 )
{
isShow = true ;
}
foreach ( int rowIndex in Grid1 . SelectedRowIndexArray )
{
string rowID = Grid1 . DataKeys [ rowIndex ] [ 0 ] . ToString ( ) ;
if ( this . judgementDelete ( rowID , isShow ) )
{
BLL . UsingPlanService . DeleteUsingPlanById ( rowID ) ;
BLL . Sys_LogService . AddLog ( BLL . Const . System_7 , this . CurrUser . LoginProjectId , this . CurrUser . UserId , "删除领料计划录入" ) ;
}
}
this . BindGrid ( ) ;
ShowNotify ( "删除数据成功!" , MessageBoxIcon . Success ) ;
}
}
else
{
Alert . ShowInTop ( "您没有这个权限,请与管理员联系!" , MessageBoxIcon . Warning ) ;
return ;
}
}
/// <summary>
/// 判断是否可删除
/// </summary>
/// <param name="rowID"></param>
/// <param name="isShow"></param>
/// <returns></returns>
private bool judgementDelete ( string rowID , bool isShow )
{
string content = string . Empty ;
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 btnImport_Click ( object sender , EventArgs e )
{
PageContext . RegisterStartupScript ( Window2 . GetShowReference ( String . Format ( "UsingPlanImport.aspx" , "导入 - " ) ) ) ;
}
#endregion
}
}