2022-09-05 16:36:31 +08:00
using BLL ;
using Newtonsoft.Json.Linq ;
using System ;
using System.Data ;
using System.Data.SqlClient ;
using System.Collections.Generic ;
using System.Linq ;
using System.Web.UI.WebControls ;
using AspNet = System . Web . UI . WebControls ;
namespace FineUIPro.Web.CQMS.Material
{
public partial class NoticeAndSupervisionEdit : PageBase
{
/// <summary>
/// 主键
/// </summary>
public string NoticeAndSupervisionId
{
get
{
return ( string ) ViewState [ "NoticeAndSupervisionId" ] ;
}
set
{
ViewState [ "NoticeAndSupervisionId" ] = value ;
}
}
/// <summary>
/// 办理类型
/// </summary>
public string State
{
get
{
return ( string ) ViewState [ "State" ] ;
}
set
{
ViewState [ "State" ] = value ;
}
}
protected void Page_Load ( object sender , EventArgs e )
{
if ( ! IsPostBack )
{
2023-06-26 15:42:26 +08:00
BLL . UnitService . InitUnitDropDownList ( this . drpUnit , this . CurrUser . LoginProjectId , true ) ;
2022-09-05 16:36:31 +08:00
BLL . MainItemService . InitMainItemDownList ( drpMainItem , this . CurrUser . LoginProjectId , true ) ;
BLL . NoticeAndSupervisionTypeService . InitNoticeAndSupervisionType ( this . drpNoticeAndSupervisionType , true ) ;
NoticeAndSupervisionId = Request . Params [ "NoticeAndSupervisionId" ] ;
if ( ! string . IsNullOrEmpty ( NoticeAndSupervisionId ) )
{
Model . Material_NoticeAndSupervision NoticeAndSupervision = BLL . CQMS_NoticeAndSupervisionService . GetNoticeAndSupervisionByNoticeAndSupervisionId ( NoticeAndSupervisionId ) ;
Model . Material_Inspection inspection = BLL . CQMS_InspectionService . GetInspectionByInspectionId ( NoticeAndSupervision . InspectionId ) ;
txtInspectionCode . Text = inspection . InspectionCode ;
if ( ! string . IsNullOrEmpty ( NoticeAndSupervision . UnitId ) )
{
drpUnit . SelectedValue = NoticeAndSupervision . UnitId ;
}
if ( ! string . IsNullOrEmpty ( NoticeAndSupervision . MainItemId ) )
{
drpMainItem . SelectedValue = NoticeAndSupervision . MainItemId ;
}
if ( ! string . IsNullOrEmpty ( NoticeAndSupervision . NoticeAndSupervisionTypeId ) )
{
drpNoticeAndSupervisionType . SelectedValue = NoticeAndSupervision . NoticeAndSupervisionTypeId ;
}
this . txtUnit . Text = NoticeAndSupervision . Unit ;
if ( NoticeAndSupervision . Num ! = null )
{
this . txtNum . Text = NoticeAndSupervision . Num . ToString ( ) ;
}
if ( NoticeAndSupervision . NoticeDate ! = null )
{
this . txtNoticeDate . Text = string . Format ( "{0:yyyy-MM-dd}" , NoticeAndSupervision . NoticeDate ) ;
}
this . txtConclusion . Text = NoticeAndSupervision . Conclusion ;
BindData ( inspection . InspectionType , NoticeAndSupervision . InspectionId ) ;
}
}
}
private void BindData ( string type , string inspectionId )
{
if ( type = = "M" ) //材料报验
{
string strSql = @ "select C.*,C.MaterialId as Id,M.MainItemName,U.UnitName from [dbo].[Material_Material] C
left join [ dbo ] . [ ProjectData_MainItem ] M on C . MainItemId = M . MainItemId
left join [ dbo ] . [ Base_Unit ] U on U . UnitId = C . UnitId where 1 = 1 ";
List < SqlParameter > listStr = new List < SqlParameter > ( ) ;
strSql + = " AND C.InspectionId = @InspectionId" ;
listStr . Add ( new SqlParameter ( "@InspectionId" , inspectionId ) ) ;
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 ( ) ;
}
else
{
string strSql = @ "select C.*,C.EquipmentId as Id,C.EquipmentName as MaterialName,C.EquipmentCode as MaterialCode,M.MainItemName,U.UnitName from [dbo].[Material_Equipment] C
left join [ dbo ] . [ ProjectData_MainItem ] M on C . MainItemId = M . MainItemId
left join [ dbo ] . [ Base_Unit ] U on U . UnitId = C . UnitId where 1 = 1 ";
List < SqlParameter > listStr = new List < SqlParameter > ( ) ;
strSql + = " AND C.InspectionId = @InspectionId" ;
listStr . Add ( new SqlParameter ( "@InspectionId" , inspectionId ) ) ;
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 ( ) ;
this . Grid1 . Columns [ 4 ] . HeaderText = "设备名称" ;
this . Grid1 . Columns [ 6 ] . HeaderText = "设备位号" ;
this . Grid1 . Columns [ 7 ] . Hidden = true ;
}
}
protected void Grid1_Sort ( object sender , GridSortEventArgs e )
{
}
protected void WindowAtt_Close ( object sender , WindowCloseEventArgs e )
{
}
/// <summary>
/// 时间转换
/// </summary>
/// <param name="date"></param>
/// <returns></returns>
public string ConvertDate ( object date )
{
if ( date ! = null )
{
return string . Format ( "{0:yyyy-MM-dd}" , Convert . ToDateTime ( date ) ) ;
}
else
{
return null ;
}
}
protected void imgBtnFileN_Click ( object sender , EventArgs e )
{
PageContext . RegisterStartupScript ( WindowAtt . GetShowReference ( String . Format ( "../../AttachFile/webuploader.aspx?type=1&toKeyId={0}&path=FileUpload/CQMS/NoticeAndSupervision&menuId={1}" , this . NoticeAndSupervisionId + "N" , BLL . Const . NoticeAndSupervisionMenuId ) ) ) ;
}
protected void imgBtnFileS_Click ( object sender , EventArgs e )
{
PageContext . RegisterStartupScript ( WindowAtt . GetShowReference ( String . Format ( "../../AttachFile/webuploader.aspx?type=1&toKeyId={0}&path=FileUpload/CQMS/NoticeAndSupervision&menuId={1}" , this . NoticeAndSupervisionId + "S" , BLL . Const . NoticeAndSupervisionMenuId ) ) ) ;
}
protected void imgBtnFile_Click ( object sender , EventArgs e )
{
PageContext . RegisterStartupScript ( WindowAtt . GetShowReference ( String . Format ( "../../AttachFile/webuploader.aspx?type=1&toKeyId={0}&path=FileUpload/CQMS/NoticeAndSupervision&menuId={1}" , this . NoticeAndSupervisionId , BLL . Const . NoticeAndSupervisionMenuId ) ) ) ;
}
protected void btnSave_Click ( object sender , EventArgs e )
{
if ( validate ( ) )
{
Saveinspection ( "save" ) ;
}
}
/// <summary>
/// 保存
/// </summary>
public void Saveinspection ( string saveType )
{
Model . Material_NoticeAndSupervision NoticeAndSupervision = BLL . CQMS_NoticeAndSupervisionService . GetNoticeAndSupervisionByNoticeAndSupervisionId ( this . NoticeAndSupervisionId ) ;
if ( NoticeAndSupervision ! = null )
{
if ( this . drpUnit . SelectedValue ! = BLL . Const . _Null )
{
NoticeAndSupervision . UnitId = this . drpUnit . SelectedValue ;
}
if ( this . drpMainItem . SelectedValue ! = BLL . Const . _Null )
{
NoticeAndSupervision . MainItemId = this . drpMainItem . SelectedValue ;
}
if ( this . drpNoticeAndSupervisionType . SelectedValue ! = BLL . Const . _Null )
{
NoticeAndSupervision . NoticeAndSupervisionTypeId = this . drpNoticeAndSupervisionType . SelectedValue ;
}
NoticeAndSupervision . Unit = this . txtUnit . Text . Trim ( ) ;
NoticeAndSupervision . Num = Funs . GetNewDecimalOrZero ( this . txtNum . Text . Trim ( ) ) ;
NoticeAndSupervision . NoticeDate = Funs . GetNewDateTimeOrNow ( this . txtNoticeDate . Text . Trim ( ) ) ;
NoticeAndSupervision . Conclusion = this . txtConclusion . Text . Trim ( ) ;
NoticeAndSupervision . CompileMan = this . CurrUser . PersonId ;
NoticeAndSupervision . CompileDate = DateTime . Now ;
CQMS_NoticeAndSupervisionService . UpdateNoticeAndSupervision ( NoticeAndSupervision ) ;
LogService . AddSys_Log ( CurrUser , NoticeAndSupervision . InspectionId , NoticeAndSupervision . NoticeAndSupervisionId , Const . NoticeAndSupervisionMenuId , "修改告知和监检" ) ;
}
PageContext . RegisterStartupScript ( ActiveWindow . GetHidePostBackReference ( ) ) ;
}
/// <summary>
/// 表格数据验证
/// </summary>
private bool validate ( )
{
bool res = false ;
string err = string . Empty ;
if ( this . drpUnit . SelectedValue = = BLL . Const . _Null )
{
err + = "请选择分包单位!" ;
}
//var att = BLL.AttachFileService.GetAttachFileByToKeyId(this.NoticeAndSupervisionId);
//if (att == null)
//{
// err += "请上传质量证明文件!";
//}
if ( ! string . IsNullOrWhiteSpace ( err ) )
{
Alert . ShowInTop ( err , MessageBoxIcon . Warning ) ;
}
else
{
res = true ;
}
return res ;
}
private string GetStringByArray ( string [ ] array )
{
string str = string . Empty ;
foreach ( var item in array )
{
if ( item ! = BLL . Const . _Null )
{
str + = item + "," ;
}
}
if ( ! string . IsNullOrEmpty ( str ) )
{
str = str . Substring ( 0 , str . LastIndexOf ( "," ) ) ;
}
return str ;
}
}
}