2024-02-08 18:10:24 +08:00
using BLL ;
using System ;
using System.Collections.Generic ;
using System.Data.SqlClient ;
using System.Data ;
using System.Linq ;
using System.Web ;
using System.Web.UI ;
using Model ;
using System.Collections ;
using Apache.NMS.ActiveMQ.Threads ;
using FineUIPro.Web.DataShow ;
using Newtonsoft.Json.Linq ;
using Aspose.Words.Lists ;
using System.Web.UI.DataVisualization.Charting ;
2024-03-11 09:46:11 +08:00
using static FineUIPro . Web . TestRun . Report . PreRunSchedule ;
using System.Reflection ;
using static FineUIPro . Web . TestRun . Report . TestRunSchedule ;
using NPOI.SS.UserModel ;
using NPOI.SS.Util ;
using NPOI.XSSF.UserModel ;
using System.IO ;
using NPOI.SS.Formula.Functions ;
2024-05-07 01:58:42 +08:00
using FineUIPro.Web.ProjectData ;
using System.Web.Services.Description ;
2024-02-08 18:10:24 +08:00
namespace FineUIPro.Web.TestRun.Report
{
public partial class ScheduleSetUp : PageBase
{
protected void Page_Load ( object sender , EventArgs e )
{
if ( ! IsPostBack )
{
TabStrip1 . ActiveTabIndex = 0 ;
DataBridYsc ( ) ;
}
}
#region 预 试 车
/// <summary>
/// 预试车绑定
/// </summary>
public void DataBridYsc ( )
{
2024-03-11 09:46:11 +08:00
var result = YscData ( ) ;
GridYsc . DataSource = result ;
TabStrip1 . ActiveTabIndex = 0 ;
GridYsc . DataBind ( ) ;
JObject summary = new JObject ( ) ;
summary . Add ( "AllNum" , result . Sum ( x = > x . AllNum ) ) ;
2024-03-28 10:14:38 +08:00
summary . Add ( "NotStartedNum" , result . Sum ( x = > x . NotStartedNum ) ) ;
2024-03-11 09:46:11 +08:00
summary . Add ( "ProgressNum" , result . Sum ( x = > x . ProgressNum ) ) ;
summary . Add ( "CompleteNum" , result . Sum ( x = > x . CompleteNum ) ) ;
GridYsc . SummaryData = summary ;
}
/// <summary>
/// 预试车数据
/// </summary>
/// <returns></returns>
public List < Run_ScheduleSetUpDto > YscData ( )
{
var result = new List < Run_ScheduleSetUpDto > ( ) ;
2024-02-08 18:10:24 +08:00
if ( Funs . DB . Run_ScheduleSetUp . Count ( x = > x . ProjectId = = this . CurrUser . LoginProjectId & & x . States = = 1 ) > 0 )
{
var query = from a in Funs . DB . Run_ScheduleSetUp
join b in Funs . DB . PreRun_WorkPackage on a . WorkPackId equals b . WorkPackId
where a . States = = 1 & & a . ProjectId = = this . CurrUser . LoginProjectId
orderby b . Sort ascending
select new Run_ScheduleSetUpDto
{
ScheduleId = a . ScheduleId ,
WorkPackId = a . WorkPackId ,
WorkPackName = b . WorkPackName ,
ProjectId = a . ProjectId ,
States = a . States ,
AllNum = a . AllNum ,
2024-03-28 10:14:38 +08:00
NotStartedNum = a . NotStartedNum ,
2024-02-08 18:10:24 +08:00
ProgressNum = a . ProgressNum ,
CompleteNum = a . CompleteNum ,
CompleteRate = a . CompleteRate ,
AddUser = a . AddUser ,
AddTime = a . AddTime ,
Sort = a . Sort
} ;
2024-03-11 09:46:11 +08:00
result = query . ToList ( ) ;
2024-02-08 18:10:24 +08:00
}
else
{
2024-03-11 09:46:11 +08:00
List < string > SubSystemIds = new List < string > ( ) ;
var devices = Funs . DB . PreRun_SysDevice . Where ( x = > x . ProjectId = = this . CurrUser . LoginProjectId & & x . PreRunLevel = = 4 ) . ToList ( ) ;
if ( devices . Count > 0 )
2024-02-08 18:10:24 +08:00
{
2024-03-11 09:46:11 +08:00
SubSystemIds = devices . ConvertAll ( x = > x . PreRunId ) ;
}
string allStr = $"select a.SubSystemId,a.SystemId,b.WorkPackId,b.WorkPackName,b.WorkPackType,(select count(1) from PreRun_SubPropertySelect as gd where gd.SubSystemId = a.SubSystemId) as GdallNum,(select count(1) from PreRun_SubTechnologySelect as sb where sb.SubSystemId = a.SubSystemId) as SballNum,(select count(1) from PreRun_SubInstrumentSelect as sy where sy.SubSystemId = a.SubSystemId) as SyallNum from PreRun_SubSysWorkPackage as a inner join PreRun_WorkPackage as b on a.WorkPackId = b.WorkPackId where a.SubSystemId in ('{string.Join(" ',' ", SubSystemIds)}') order by a.WorkPackCode asc" ;
var dt = SQLHelper . GetDataTableRunText ( allStr ) ;
string inspectStr = $"select a.WorkPackId,b.WorkPackName,b.Sort,SUM(case ISNULL(a.InspectIsClose, 0) when 1 then 1 else 0 end) as CloseNum,SUM(case ISNULL(a.InspectIsClose, 0) when 0 then 1 else 0 end) as NoCloseNum,COUNT(1) as AllNum from PreRun_SubInspectTerm as a inner join PreRun_WorkPackage as b on a.WorkPackId = b.WorkPackId where 1=1 and a.ProjectId = '{this.CurrUser.LoginProjectId}' and a.SubSystemId in ('{string.Join(" ',' ", SubSystemIds)}') group by a.WorkPackId,b.WorkPackName,b.Sort order by b.Sort asc" ;
var inspectDt = SQLHelper . GetDataTableRunText ( inspectStr ) ;
var inspectlist = DataTableToList < WorkPackageInspectDto > ( inspectDt ) ;
if ( dt . Rows . Count > 0 )
{
//获取所有子系统数量
var inspects = Funs . DB . PreRun_SubInspectTerm . Where ( x = > x . ProjectId = = this . CurrUser . LoginProjectId & & SubSystemIds . Contains ( x . SubSystemId ) ) ;
var querylist = DataTableToList < QuerySubSysWorkPackage > ( dt ) ;
var queryGroup = querylist . GroupBy ( x = > new { x . WorkPackId , x . WorkPackName , x . WorkPackType } ) . Select ( p = > new
{
p . Key . WorkPackId ,
p . Key . WorkPackName ,
p . Key . WorkPackType
} ) ;
2024-02-08 18:10:24 +08:00
int i = 1 ;
2024-03-11 09:46:11 +08:00
foreach ( var itemPack in queryGroup )
2024-02-08 18:10:24 +08:00
{
2024-03-11 09:46:11 +08:00
var itemQueryList = querylist . Where ( x = > x . WorkPackId = = itemPack . WorkPackId ) . ToList ( ) ;
2024-02-08 18:10:24 +08:00
var model = new Run_ScheduleSetUpDto ( ) ;
model . ScheduleId = Guid . NewGuid ( ) . ToString ( ) ;
2024-03-11 09:46:11 +08:00
model . WorkPackId = itemPack . WorkPackId ;
model . WorkPackName = itemPack . WorkPackName ;
2024-02-08 18:10:24 +08:00
model . ProjectId = this . CurrUser . LoginProjectId ;
model . States = 1 ;
2024-03-11 09:46:11 +08:00
model . AllNum = itemQueryList . Count ( x = > x . WorkPackId = = itemPack . WorkPackId ) ;
model . ProgressNum = 0 ;
model . CompleteNum = 0 ;
2024-03-28 10:14:38 +08:00
model . NotStartedNum = 0 ;
2024-03-11 09:46:11 +08:00
var subsystemids = itemQueryList . ConvertAll ( a = > a . SubSystemId ) . Distinct ( ) ;
foreach ( var itemsubid in subsystemids )
{
if ( inspects . Count ( x = > x . SubSystemId = = itemsubid ) > 0 )
{
var itemQuerylist = itemQueryList . FirstOrDefault ( x = > x . SubSystemId = = itemsubid & & x . WorkPackId = = itemPack . WorkPackId ) ;
var allNum = itemQuerylist . GdallNum + itemQuerylist . SballNum + itemQuerylist . SyallNum ;
if ( inspects . Count ( x = > x . SubInspectId = = itemsubid & & x . InspectIsClose ! = 1 ) > 0 )
{
model . ProgressNum + = 1 ;
}
else
{
var closeInspect = inspects . Where ( x = > x . SubInspectId = = itemsubid & & x . InspectIsClose = = 1 ) ;
var closeNums = closeInspect . Count ( ) > 0 ? closeInspect . Select ( x = > x . PropertyTechnologyId . Split ( ',' ) . Count ( ) ) . Sum ( x = > x ) : 0 ;
if ( allNum > closeNums )
{
model . ProgressNum + = 1 ;
}
else
{
model . CompleteNum + = 1 ;
}
}
}
else
{
2024-03-28 10:14:38 +08:00
model . NotStartedNum + = 1 ;
2024-03-11 09:46:11 +08:00
}
}
2024-02-08 18:10:24 +08:00
var rate = model . CompleteNum > 0 ? ( decimal ) Math . Round ( ( float ) model . CompleteNum / ( float ) model . AllNum * 100 , 2 , MidpointRounding . AwayFromZero ) : 0 ;
if ( rate > 100 ) rate = 100 ;
model . CompleteRate = rate ;
model . AddUser = this . CurrUser . UserId ;
model . AddTime = DateTime . Now ;
model . Sort = i ;
result . Add ( model ) ;
i + + ;
}
}
}
2024-03-11 09:46:11 +08:00
return result ;
2024-02-08 18:10:24 +08:00
}
/// <summary>
/// 预试车重置
/// </summary>
protected void btnYscReset_Click ( object sender , EventArgs e )
{
var list = Funs . DB . Run_ScheduleSetUp . Where ( x = > x . ProjectId = = this . CurrUser . LoginProjectId & & x . States = = 1 ) ;
if ( list . Count ( ) > 0 )
{
Funs . DB . Run_ScheduleSetUp . DeleteAllOnSubmit ( list ) ;
Funs . DB . SubmitChanges ( ) ;
}
DataBridYsc ( ) ;
ShowNotify ( "重置成功!" , MessageBoxIcon . Success ) ;
}
/// <summary>
/// 预试车保存
/// </summary>
protected void btnYscSave_Click ( object sender , EventArgs e )
{
try
{
var deletelist = Funs . DB . Run_ScheduleSetUp . Where ( x = > x . ProjectId = = this . CurrUser . LoginProjectId & & x . States = = 1 ) ;
Funs . DB . Run_ScheduleSetUp . DeleteAllOnSubmit ( deletelist ) ;
Funs . DB . SubmitChanges ( ) ;
var addList = new List < Run_ScheduleSetUp > ( ) ;
JArray mergedData = GridYsc . GetMergedData ( ) ;
foreach ( JObject mergedRow in mergedData )
{
string status = mergedRow . Value < string > ( "status" ) ;
JObject values = mergedRow . Value < JObject > ( "values" ) ;
int i = mergedRow . Value < int > ( "index" ) ;
var model = new Run_ScheduleSetUp ( ) ;
model . ScheduleId = this . GridYsc . Rows [ i ] . DataKeys [ 0 ] . ToString ( ) ;
model . WorkPackId = this . GridYsc . Rows [ i ] . DataKeys [ 1 ] . ToString ( ) ;
model . ProjectId = this . CurrUser . LoginProjectId ;
model . States = 1 ;
model . AllNum = ! string . IsNullOrWhiteSpace ( values . Value < string > ( "AllNum" ) ) ? int . Parse ( values . Value < string > ( "AllNum" ) ) : 0 ;
2024-03-28 10:14:38 +08:00
model . NotStartedNum = ! string . IsNullOrWhiteSpace ( values . Value < string > ( "NotStartedNum" ) ) ? int . Parse ( values . Value < string > ( "NotStartedNum" ) ) : 0 ;
2024-02-08 18:10:24 +08:00
model . ProgressNum = ! string . IsNullOrWhiteSpace ( values . Value < string > ( "ProgressNum" ) ) ? int . Parse ( values . Value < string > ( "ProgressNum" ) ) : 0 ;
model . CompleteNum = ! string . IsNullOrWhiteSpace ( values . Value < string > ( "CompleteNum" ) ) ? int . Parse ( values . Value < string > ( "CompleteNum" ) ) : 0 ;
var rate = model . CompleteNum > 0 ? ( decimal ) Math . Round ( ( float ) model . CompleteNum / ( float ) model . AllNum * 100 , 2 , MidpointRounding . AwayFromZero ) : 0 ;
if ( rate > 100 ) rate = 100 ;
model . CompleteRate = rate ;
model . AddUser = this . CurrUser . UserId ;
model . AddTime = DateTime . Now ;
model . Sort = i ;
addList . Add ( model ) ;
}
Funs . DB . Run_ScheduleSetUp . InsertAllOnSubmit ( addList ) ;
Funs . DB . SubmitChanges ( ) ;
DataBridYsc ( ) ;
ShowNotify ( "保存成功!" ) ;
}
catch ( Exception ex )
{
ShowNotify ( ex . Message , MessageBoxIcon . Error ) ;
}
}
2024-03-11 09:46:11 +08:00
/// <summary>
/// 预试车导出
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnYscExport_Click ( object sender , EventArgs e )
{
string rootPath = Server . MapPath ( "~/" ) + Const . ExcelUrl ;
//导出文件
string filePath = rootPath + DateTime . Now . ToString ( "yyyyMMddhhmmss" ) + "\\" ;
if ( ! Directory . Exists ( filePath ) )
{
Directory . CreateDirectory ( filePath ) ;
}
string ReportFileName = filePath + "预试车进度.xlsx" ;
var result = YscData ( ) ;
if ( result . Count > 0 )
{
XSSFWorkbook hssfworkbook = new XSSFWorkbook ( ) ;
XSSFSheet ws = ( XSSFSheet ) hssfworkbook . CreateSheet ( "预试车进度" ) ;
#region 列 宽
ws . SetColumnWidth ( 0 , ( 30 * 256 ) ) ;
ws . SetColumnWidth ( 1 , ( 20 * 256 ) ) ;
ws . SetColumnWidth ( 2 , ( 20 * 256 ) ) ;
ws . SetColumnWidth ( 3 , ( 20 * 256 ) ) ;
2024-03-28 10:14:38 +08:00
ws . SetColumnWidth ( 4 , ( 20 * 256 ) ) ;
2024-03-11 09:46:11 +08:00
#endregion
#region 样 式
//公共样式
ICellStyle style = SetExcelStyle ( hssfworkbook , BorderStyle . Thin , BorderStyle . Thin , BorderStyle . Thin , BorderStyle . Thin , VerticalAlignment . Center , HorizontalAlignment . Center , 10.5 , true ) ;
//公共样式加粗
ICellStyle styleBold = SetExcelStyle ( hssfworkbook , BorderStyle . Thin , BorderStyle . Thin , BorderStyle . Thin , BorderStyle . Thin , VerticalAlignment . Center , HorizontalAlignment . Center , 10.5 , true , true ) ;
#endregion
#region 头 部
2024-03-28 10:14:38 +08:00
ws = ExcelCreateRowTitle ( ws , hssfworkbook , style , 0 , 0 , 0 , 4 ) ;
2024-03-11 09:46:11 +08:00
//行1
ws . GetRow ( 0 ) . GetCell ( 0 ) . CellStyle = styleBold ;
ws . GetRow ( 0 ) . GetCell ( 0 ) . SetCellValue ( "工作包名称" ) ;
ws . GetRow ( 0 ) . GetCell ( 1 ) . CellStyle = styleBold ;
ws . GetRow ( 0 ) . GetCell ( 1 ) . SetCellValue ( "全部数量" ) ;
ws . GetRow ( 0 ) . GetCell ( 2 ) . CellStyle = styleBold ;
2024-03-28 10:14:38 +08:00
ws . GetRow ( 0 ) . GetCell ( 2 ) . SetCellValue ( "未开始数量" ) ;
2024-03-11 09:46:11 +08:00
ws . GetRow ( 0 ) . GetCell ( 3 ) . CellStyle = styleBold ;
2024-03-28 10:14:38 +08:00
ws . GetRow ( 0 ) . GetCell ( 3 ) . SetCellValue ( "进行中数量" ) ;
ws . GetRow ( 0 ) . GetCell ( 4 ) . CellStyle = styleBold ;
ws . GetRow ( 0 ) . GetCell ( 4 ) . SetCellValue ( "已完成数量" ) ;
2024-03-11 09:46:11 +08:00
#endregion
#region 表 格
var start = 1 ;
var end = result . Count ;
2024-03-28 10:14:38 +08:00
ws = ExcelCreateRowTitle ( ws , hssfworkbook , style , start , end , 0 , 4 ) ;
2024-03-11 09:46:11 +08:00
//数据
var dataIndex = 1 ;
foreach ( var item in result )
{
ws . GetRow ( dataIndex ) . GetCell ( 0 ) . SetCellValue ( item . WorkPackName ) ;
ws . GetRow ( dataIndex ) . GetCell ( 1 ) . SetCellValue ( item . AllNum . ToString ( ) ) ;
2024-03-28 10:14:38 +08:00
ws . GetRow ( dataIndex ) . GetCell ( 2 ) . SetCellValue ( item . NotStartedNum . ToString ( ) ) ;
ws . GetRow ( dataIndex ) . GetCell ( 3 ) . SetCellValue ( item . ProgressNum . ToString ( ) ) ;
ws . GetRow ( dataIndex ) . GetCell ( 4 ) . SetCellValue ( item . CompleteNum . ToString ( ) ) ;
2024-03-11 09:46:11 +08:00
dataIndex + + ;
}
#endregion
#region 尾 部
2024-03-28 10:14:38 +08:00
ws = ExcelCreateRowTitle ( ws , hssfworkbook , style , end + 1 , end + 1 , 0 , 4 ) ;
2024-03-11 09:46:11 +08:00
ws . GetRow ( end + 1 ) . GetCell ( 0 ) . SetCellValue ( "合计" ) ;
ws . GetRow ( end + 1 ) . GetCell ( 1 ) . SetCellValue ( result . Count > 0 ? result . Sum ( x = > x . AllNum ) . ToString ( ) : "0" ) ;
2024-03-28 10:14:38 +08:00
ws . GetRow ( end + 1 ) . GetCell ( 2 ) . SetCellValue ( result . Count > 0 ? result . Sum ( x = > x . NotStartedNum ) . ToString ( ) : "0" ) ;
ws . GetRow ( end + 1 ) . GetCell ( 3 ) . SetCellValue ( result . Count > 0 ? result . Sum ( x = > x . ProgressNum ) . ToString ( ) : "0" ) ;
ws . GetRow ( end + 1 ) . GetCell ( 4 ) . SetCellValue ( result . Count > 0 ? result . Sum ( x = > x . CompleteNum ) . ToString ( ) : "0" ) ;
2024-03-11 09:46:11 +08:00
#endregion
ws . PrintSetup . Landscape = false ;
ws . PrintSetup . PaperSize = 9 ;
ws . ForceFormulaRecalculation = true ;
using ( FileStream filess = File . OpenWrite ( ReportFileName ) )
{
hssfworkbook . Write ( filess ) ;
}
FileInfo filet = new FileInfo ( ReportFileName ) ;
Response . Clear ( ) ;
Response . Charset = "GB2312" ;
Response . ContentEncoding = System . Text . Encoding . UTF8 ;
// 添加头信息,为"文件下载/另存为"对话框指定默认文件名
Response . AddHeader ( "Content-Disposition" , "attachment; filename=" + Server . UrlEncode ( "预试车进度.xlsx" ) ) ;
// 添加头信息,指定文件大小,让浏览器能够显示下载进度
Response . AddHeader ( "Content-Length" , filet . Length . ToString ( ) ) ;
// 指定返回的是一个不能被客户端读取的流,必须被下载
Response . ContentType = "application/ms-excel" ;
// 把文件流发送到客户端
Response . WriteFile ( filet . FullName ) ;
// 停止页面的执行
Response . End ( ) ;
}
}
2024-02-08 18:10:24 +08:00
#endregion
#region 试 车
/// <summary>
/// 试车绑定
/// </summary>
public void DataBridSc ( )
{
2024-03-11 09:46:11 +08:00
var result = ScData ( ) ;
GridSc . DataSource = result ;
TabStrip1 . ActiveTabIndex = 1 ;
GridSc . DataBind ( ) ;
JObject summary = new JObject ( ) ;
summary . Add ( "AllNum" , result . Sum ( x = > x . AllNum ) ) ;
2024-03-28 10:14:38 +08:00
summary . Add ( "NotStartedNum" , result . Sum ( x = > x . NotStartedNum ) ) ;
2024-03-11 09:46:11 +08:00
summary . Add ( "ProgressNum" , result . Sum ( x = > x . ProgressNum ) ) ;
summary . Add ( "CompleteNum" , result . Sum ( x = > x . CompleteNum ) ) ;
GridSc . SummaryData = summary ;
}
/// <summary>
/// 试车数据
/// </summary>
/// <returns></returns>
public List < Run_ScheduleSetUpDto > ScData ( )
{
var result = new List < Run_ScheduleSetUpDto > ( ) ;
2024-02-08 18:10:24 +08:00
if ( Funs . DB . Run_ScheduleSetUp . Count ( x = > x . ProjectId = = this . CurrUser . LoginProjectId & & x . States = = 2 ) > 0 )
{
var query = from a in Funs . DB . Run_ScheduleSetUp
join b in Funs . DB . TestRun_WorkPackage on a . WorkPackId equals b . WorkPackId
where a . States = = 2 & & a . ProjectId = = this . CurrUser . LoginProjectId
orderby b . Sort ascending
select new Run_ScheduleSetUpDto
{
ScheduleId = a . ScheduleId ,
WorkPackId = a . WorkPackId ,
WorkPackName = b . WorkPackName ,
ProjectId = a . ProjectId ,
States = a . States ,
AllNum = a . AllNum ,
2024-03-28 10:14:38 +08:00
NotStartedNum = a . NotStartedNum ,
2024-02-08 18:10:24 +08:00
ProgressNum = a . ProgressNum ,
CompleteNum = a . CompleteNum ,
CompleteRate = a . CompleteRate ,
AddUser = a . AddUser ,
AddTime = a . AddTime ,
Sort = a . Sort
} ;
2024-03-11 09:46:11 +08:00
result = query . ToList ( ) ;
2024-02-08 18:10:24 +08:00
}
else
{
2024-03-11 09:46:11 +08:00
List < string > SystemIds = new List < string > ( ) ;
var devices = Funs . DB . PreRun_SysDevice . Where ( x = > x . ProjectId = = this . CurrUser . LoginProjectId & & x . PreRunLevel = = 3 ) . ToList ( ) ;
if ( devices . Count > 0 )
{
SystemIds = devices . ConvertAll ( x = > x . PreRunId ) ;
}
string allStr = $"select b.WorkPackId,b.WorkPackName,COUNT(a.SystemId) as WorkPackNum from TestRun_SubSysWorkPackage as a inner join TestRun_WorkPackage as b on a.WorkPackId = b.WorkPackId where a.SystemId in ('{string.Join(" ',' ", SystemIds)}') group by b.WorkPackId,b.WorkPackName" ;
var dt = SQLHelper . GetDataTableRunText ( allStr ) ;
if ( dt . Rows . Count > 0 )
2024-02-08 18:10:24 +08:00
{
2024-03-11 09:46:11 +08:00
string inspectStr = $"select a.WorkPackId,b.WorkPackName,b.Sort,SUM(case ISNULL(a.InspectIsClose, 0) when 1 then 1 else 0 end) as CloseNum,SUM(case ISNULL(a.InspectIsClose, 0) when 0 then 1 else 0 end) as NoCloseNum,COUNT(1) as AllNum from TestRun_SubInspectTerm as a inner join TestRun_WorkPackage as b on a.WorkPackId = b.WorkPackId where 1=1 and a.ProjectId = '{this.CurrUser.LoginProjectId}' group by a.WorkPackId,b.WorkPackName,b.Sort order by b.Sort asc" ;
var inspectDt = SQLHelper . GetDataTableRunText ( inspectStr ) ;
var inspectlist = DataTableToList < WorkPackageInspectDto > ( inspectDt ) ;
2024-02-08 18:10:24 +08:00
int i = 1 ;
2024-03-11 09:46:11 +08:00
var list = DataTableToList < TestRunScheduleDto > ( dt ) ;
foreach ( var item in list )
2024-02-08 18:10:24 +08:00
{
var model = new Run_ScheduleSetUpDto ( ) ;
model . ScheduleId = Guid . NewGuid ( ) . ToString ( ) ;
2024-03-11 09:46:11 +08:00
model . WorkPackId = item . WorkPackId ;
model . WorkPackName = item . WorkPackName ;
2024-02-08 18:10:24 +08:00
model . ProjectId = this . CurrUser . LoginProjectId ;
model . States = 2 ;
2024-03-11 09:46:11 +08:00
if ( inspectlist . Count ( x = > x . WorkPackId = = item . WorkPackId ) > 0 )
{
var itemInspect = inspectlist . FirstOrDefault ( x = > x . WorkPackId = = item . WorkPackId ) ;
model . AllNum = itemInspect . AllNum ;
model . ProgressNum = itemInspect . NoCloseNum ;
2024-03-28 10:14:38 +08:00
model . NotStartedNum = 0 ;
2024-03-11 09:46:11 +08:00
model . CompleteNum = itemInspect . CloseNum ;
}
else
{
2024-03-28 10:14:38 +08:00
model . AllNum = 1 ;
2024-03-11 09:46:11 +08:00
model . ProgressNum = 0 ;
model . CompleteNum = 0 ;
2024-03-28 10:14:38 +08:00
model . NotStartedNum = 1 ;
2024-03-11 09:46:11 +08:00
}
2024-02-08 18:10:24 +08:00
model . CompleteRate = model . CompleteNum > 0 ? ( decimal ) Math . Round ( ( float ) model . CompleteNum / ( float ) model . AllNum , 2 , MidpointRounding . AwayFromZero ) : 0 ;
model . AddUser = this . CurrUser . UserId ;
model . AddTime = DateTime . Now ;
model . Sort = i ;
result . Add ( model ) ;
i + + ;
}
}
}
2024-03-11 09:46:11 +08:00
return result ;
2024-02-08 18:10:24 +08:00
}
/// <summary>
/// 试车重置
/// </summary>
protected void btnScReset_Click ( object sender , EventArgs e )
{
var list = Funs . DB . Run_ScheduleSetUp . Where ( x = > x . ProjectId = = this . CurrUser . LoginProjectId & & x . States = = 2 ) ;
if ( list . Count ( ) > 0 )
{
Funs . DB . Run_ScheduleSetUp . DeleteAllOnSubmit ( list ) ;
Funs . DB . SubmitChanges ( ) ;
}
DataBridSc ( ) ;
ShowNotify ( "重置成功!" , MessageBoxIcon . Success ) ;
}
/// <summary>
/// 试车保存
/// </summary>
protected void btnScSave_Click ( object sender , EventArgs e )
{
try
{
var deletelist = Funs . DB . Run_ScheduleSetUp . Where ( x = > x . ProjectId = = this . CurrUser . LoginProjectId & & x . States = = 2 ) ;
Funs . DB . Run_ScheduleSetUp . DeleteAllOnSubmit ( deletelist ) ;
Funs . DB . SubmitChanges ( ) ;
var addList = new List < Run_ScheduleSetUp > ( ) ;
JArray mergedData = GridSc . GetMergedData ( ) ;
foreach ( JObject mergedRow in mergedData )
{
string status = mergedRow . Value < string > ( "status" ) ;
JObject values = mergedRow . Value < JObject > ( "values" ) ;
int i = mergedRow . Value < int > ( "index" ) ;
var model = new Run_ScheduleSetUp ( ) ;
model . ScheduleId = this . GridSc . Rows [ i ] . DataKeys [ 0 ] . ToString ( ) ;
model . WorkPackId = this . GridSc . Rows [ i ] . DataKeys [ 1 ] . ToString ( ) ;
model . ProjectId = this . CurrUser . LoginProjectId ;
model . States = 2 ;
model . AllNum = ! string . IsNullOrWhiteSpace ( values . Value < string > ( "AllNum" ) ) ? int . Parse ( values . Value < string > ( "AllNum" ) ) : 0 ;
2024-03-28 10:14:38 +08:00
model . NotStartedNum = ! string . IsNullOrWhiteSpace ( values . Value < string > ( "NotStartedNum" ) ) ? int . Parse ( values . Value < string > ( "NotStartedNum" ) ) : 0 ;
2024-02-08 18:10:24 +08:00
model . ProgressNum = ! string . IsNullOrWhiteSpace ( values . Value < string > ( "ProgressNum" ) ) ? int . Parse ( values . Value < string > ( "ProgressNum" ) ) : 0 ;
model . CompleteNum = ! string . IsNullOrWhiteSpace ( values . Value < string > ( "CompleteNum" ) ) ? int . Parse ( values . Value < string > ( "CompleteNum" ) ) : 0 ;
model . CompleteRate = model . CompleteNum > 0 ? ( decimal ) Math . Round ( ( float ) model . CompleteNum / ( float ) model . AllNum , 2 , MidpointRounding . AwayFromZero ) : 0 ;
model . AddUser = this . CurrUser . UserId ;
model . AddTime = DateTime . Now ;
model . Sort = i ;
addList . Add ( model ) ;
}
Funs . DB . Run_ScheduleSetUp . InsertAllOnSubmit ( addList ) ;
Funs . DB . SubmitChanges ( ) ;
DataBridSc ( ) ;
ShowNotify ( "保存成功!" ) ;
}
catch ( Exception ex )
{
ShowNotify ( ex . Message , MessageBoxIcon . Error ) ;
}
}
2024-03-11 09:46:11 +08:00
/// <summary>
/// 试车导出
/// </summary>
protected void btnScExport_Click ( object sender , EventArgs e )
{
string rootPath = Server . MapPath ( "~/" ) + Const . ExcelUrl ;
//导出文件
string filePath = rootPath + DateTime . Now . ToString ( "yyyyMMddhhmmss" ) + "\\" ;
if ( ! Directory . Exists ( filePath ) )
{
Directory . CreateDirectory ( filePath ) ;
}
string ReportFileName = filePath + "试车进度.xlsx" ;
var result = ScData ( ) ;
if ( result . Count > 0 )
{
XSSFWorkbook hssfworkbook = new XSSFWorkbook ( ) ;
XSSFSheet ws = ( XSSFSheet ) hssfworkbook . CreateSheet ( "试车进度" ) ;
#region 列 宽
ws . SetColumnWidth ( 0 , ( 30 * 256 ) ) ;
ws . SetColumnWidth ( 1 , ( 20 * 256 ) ) ;
ws . SetColumnWidth ( 2 , ( 20 * 256 ) ) ;
ws . SetColumnWidth ( 3 , ( 20 * 256 ) ) ;
2024-03-28 10:14:38 +08:00
ws . SetColumnWidth ( 4 , ( 20 * 256 ) ) ;
2024-03-11 09:46:11 +08:00
#endregion
#region 样 式
//公共样式
ICellStyle style = SetExcelStyle ( hssfworkbook , BorderStyle . Thin , BorderStyle . Thin , BorderStyle . Thin , BorderStyle . Thin , VerticalAlignment . Center , HorizontalAlignment . Center , 10.5 , true ) ;
//公共样式加粗
ICellStyle styleBold = SetExcelStyle ( hssfworkbook , BorderStyle . Thin , BorderStyle . Thin , BorderStyle . Thin , BorderStyle . Thin , VerticalAlignment . Center , HorizontalAlignment . Center , 10.5 , true , true ) ;
#endregion
#region 头 部
2024-03-28 10:14:38 +08:00
ws = ExcelCreateRowTitle ( ws , hssfworkbook , style , 0 , 0 , 0 , 4 ) ;
2024-03-11 09:46:11 +08:00
//行1
ws . GetRow ( 0 ) . GetCell ( 0 ) . CellStyle = styleBold ;
ws . GetRow ( 0 ) . GetCell ( 0 ) . SetCellValue ( "工作包名称" ) ;
ws . GetRow ( 0 ) . GetCell ( 1 ) . CellStyle = styleBold ;
ws . GetRow ( 0 ) . GetCell ( 1 ) . SetCellValue ( "全部数量" ) ;
ws . GetRow ( 0 ) . GetCell ( 2 ) . CellStyle = styleBold ;
2024-03-28 10:14:38 +08:00
ws . GetRow ( 0 ) . GetCell ( 2 ) . SetCellValue ( "未开始数量" ) ;
2024-03-11 09:46:11 +08:00
ws . GetRow ( 0 ) . GetCell ( 3 ) . CellStyle = styleBold ;
2024-03-28 10:14:38 +08:00
ws . GetRow ( 0 ) . GetCell ( 3 ) . SetCellValue ( "进行中数量" ) ;
ws . GetRow ( 0 ) . GetCell ( 4 ) . CellStyle = styleBold ;
ws . GetRow ( 0 ) . GetCell ( 4 ) . SetCellValue ( "已完成数量" ) ;
2024-03-11 09:46:11 +08:00
#endregion
#region 表 格
var start = 1 ;
var end = result . Count ;
2024-03-28 10:14:38 +08:00
ws = ExcelCreateRowTitle ( ws , hssfworkbook , style , start , end , 0 , 4 ) ;
2024-03-11 09:46:11 +08:00
//数据
var dataIndex = 1 ;
foreach ( var item in result )
{
ws . GetRow ( dataIndex ) . GetCell ( 0 ) . SetCellValue ( item . WorkPackName ) ;
ws . GetRow ( dataIndex ) . GetCell ( 1 ) . SetCellValue ( item . AllNum . ToString ( ) ) ;
2024-03-28 10:14:38 +08:00
ws . GetRow ( dataIndex ) . GetCell ( 2 ) . SetCellValue ( item . NotStartedNum . ToString ( ) ) ;
ws . GetRow ( dataIndex ) . GetCell ( 3 ) . SetCellValue ( item . ProgressNum . ToString ( ) ) ;
ws . GetRow ( dataIndex ) . GetCell ( 4 ) . SetCellValue ( item . CompleteNum . ToString ( ) ) ;
2024-03-11 09:46:11 +08:00
dataIndex + + ;
}
#endregion
#region 尾 部
2024-03-28 10:14:38 +08:00
ws = ExcelCreateRowTitle ( ws , hssfworkbook , style , end + 1 , end + 1 , 0 , 4 ) ;
2024-03-11 09:46:11 +08:00
ws . GetRow ( end + 1 ) . GetCell ( 0 ) . SetCellValue ( "合计" ) ;
ws . GetRow ( end + 1 ) . GetCell ( 1 ) . SetCellValue ( result . Count > 0 ? result . Sum ( x = > x . AllNum ) . ToString ( ) : "0" ) ;
2024-03-28 10:14:38 +08:00
ws . GetRow ( end + 1 ) . GetCell ( 2 ) . SetCellValue ( result . Count > 0 ? result . Sum ( x = > x . NotStartedNum ) . ToString ( ) : "0" ) ;
ws . GetRow ( end + 1 ) . GetCell ( 3 ) . SetCellValue ( result . Count > 0 ? result . Sum ( x = > x . ProgressNum ) . ToString ( ) : "0" ) ;
ws . GetRow ( end + 1 ) . GetCell ( 4 ) . SetCellValue ( result . Count > 0 ? result . Sum ( x = > x . CompleteNum ) . ToString ( ) : "0" ) ;
2024-03-11 09:46:11 +08:00
#endregion
ws . PrintSetup . Landscape = false ;
ws . PrintSetup . PaperSize = 9 ;
ws . ForceFormulaRecalculation = true ;
using ( FileStream filess = File . OpenWrite ( ReportFileName ) )
{
hssfworkbook . Write ( filess ) ;
}
FileInfo filet = new FileInfo ( ReportFileName ) ;
Response . Clear ( ) ;
Response . Charset = "GB2312" ;
Response . ContentEncoding = System . Text . Encoding . UTF8 ;
// 添加头信息,为"文件下载/另存为"对话框指定默认文件名
Response . AddHeader ( "Content-Disposition" , "attachment; filename=" + Server . UrlEncode ( "试车进度.xlsx" ) ) ;
// 添加头信息,指定文件大小,让浏览器能够显示下载进度
Response . AddHeader ( "Content-Length" , filet . Length . ToString ( ) ) ;
// 指定返回的是一个不能被客户端读取的流,必须被下载
Response . ContentType = "application/ms-excel" ;
// 把文件流发送到客户端
Response . WriteFile ( filet . FullName ) ;
// 停止页面的执行
Response . End ( ) ;
}
}
#endregion
#region 三 查 四 定
/// <summary>
/// 三查四定绑定
/// </summary>
public void DataBridScsd ( )
{
var result = ScsdData ( ) ;
GridScsd . DataSource = result ;
TabStrip1 . ActiveTabIndex = 2 ;
GridScsd . DataBind ( ) ;
JObject summary = new JObject ( ) ;
summary . Add ( "AllNum" , result . Sum ( x = > x . AllNum ) ) ;
summary . Add ( "ProgressNum" , result . Sum ( x = > x . ProgressNum ) ) ;
summary . Add ( "CompleteNum" , result . Sum ( x = > x . CompleteNum ) ) ;
GridScsd . SummaryData = summary ;
}
/// <summary>
/// 三查四定数据
/// </summary>
/// <returns></returns>
public List < Run_ScheduleSetUp > ScsdData ( )
{
var result = new List < Run_ScheduleSetUp > ( ) ;
if ( Funs . DB . Run_ScheduleSetUp . Count ( x = > x . ProjectId = = this . CurrUser . LoginProjectId & & x . States = = 3 ) > 0 )
{
result = Funs . DB . Run_ScheduleSetUp . Where ( a = > a . States = = 3 & & a . ProjectId = = this . CurrUser . LoginProjectId ) . OrderBy ( o = > o . LevelName ) . ToList ( ) ;
}
else
{
var list = new List < FourDecisionScheduleBridDto > ( ) ;
string allStr = $"select Level,COUNT(1) as AllNum,SUM(case ISNULL(a.DecisionIsClose,0) when 0 then 1 else 0 end) as NoCloseNum,SUM(case ISNULL(a.DecisionIsClose,0) when 1 then 1 else 0 end) as CloseNum from PreRun_SubThreeChecksFourDecision as a where a.ProjectId='{this.CurrUser.LoginProjectId}' group by a.Level order by a.Level asc" ;
var dt = SQLHelper . GetDataTableRunText ( allStr ) ;
if ( dt . Rows . Count > 0 )
{
int i = 1 ;
list = DataTableToList < FourDecisionScheduleBridDto > ( dt ) ;
foreach ( var item in list )
{
var model = new Run_ScheduleSetUp ( ) ;
model . ScheduleId = Guid . NewGuid ( ) . ToString ( ) ;
model . ProjectId = this . CurrUser . LoginProjectId ;
model . LevelName = item . Level ;
model . States = 3 ;
model . AllNum = item . AllNum ;
model . ProgressNum = item . NoCloseNum ;
model . CompleteNum = item . CloseNum ;
model . CompleteRate = model . CompleteNum > 0 ? ( decimal ) Math . Round ( ( float ) model . CompleteNum / ( float ) model . AllNum , 2 , MidpointRounding . AwayFromZero ) : 0 ;
model . AddUser = this . CurrUser . UserId ;
model . AddTime = DateTime . Now ;
model . Sort = i ;
result . Add ( model ) ;
i + + ;
}
}
}
return result ;
}
/// <summary>
/// 三查四定重置
/// </summary>
protected void btnScsdReset_Click ( object sender , EventArgs e )
{
var list = Funs . DB . Run_ScheduleSetUp . Where ( x = > x . ProjectId = = this . CurrUser . LoginProjectId & & x . States = = 3 ) ;
if ( list . Count ( ) > 0 )
{
Funs . DB . Run_ScheduleSetUp . DeleteAllOnSubmit ( list ) ;
Funs . DB . SubmitChanges ( ) ;
}
DataBridScsd ( ) ;
ShowNotify ( "重置成功!" , MessageBoxIcon . Success ) ;
}
/// <summary>
/// 三查四定保存
/// </summary>
protected void btnScsdSave_Click ( object sender , EventArgs e )
{
try
{
var deletelist = Funs . DB . Run_ScheduleSetUp . Where ( x = > x . ProjectId = = this . CurrUser . LoginProjectId & & x . States = = 3 ) ;
Funs . DB . Run_ScheduleSetUp . DeleteAllOnSubmit ( deletelist ) ;
Funs . DB . SubmitChanges ( ) ;
var addList = new List < Run_ScheduleSetUp > ( ) ;
JArray mergedData = GridScsd . GetMergedData ( ) ;
foreach ( JObject mergedRow in mergedData )
{
string status = mergedRow . Value < string > ( "status" ) ;
JObject values = mergedRow . Value < JObject > ( "values" ) ;
int i = mergedRow . Value < int > ( "index" ) ;
var model = new Run_ScheduleSetUp ( ) ;
model . ScheduleId = this . GridScsd . Rows [ i ] . DataKeys [ 0 ] . ToString ( ) ;
model . LevelName = this . GridScsd . Rows [ i ] . DataKeys [ 1 ] . ToString ( ) ;
model . ProjectId = this . CurrUser . LoginProjectId ;
model . States = 3 ;
model . AllNum = ! string . IsNullOrWhiteSpace ( values . Value < string > ( "AllNum" ) ) ? int . Parse ( values . Value < string > ( "AllNum" ) ) : 0 ;
model . ProgressNum = ! string . IsNullOrWhiteSpace ( values . Value < string > ( "ProgressNum" ) ) ? int . Parse ( values . Value < string > ( "ProgressNum" ) ) : 0 ;
model . CompleteNum = ! string . IsNullOrWhiteSpace ( values . Value < string > ( "CompleteNum" ) ) ? int . Parse ( values . Value < string > ( "CompleteNum" ) ) : 0 ;
model . CompleteRate = model . CompleteNum > 0 ? ( decimal ) Math . Round ( ( float ) model . CompleteNum / ( float ) model . AllNum , 2 , MidpointRounding . AwayFromZero ) : 0 ;
model . AddUser = this . CurrUser . UserId ;
model . AddTime = DateTime . Now ;
model . Sort = i ;
addList . Add ( model ) ;
}
Funs . DB . Run_ScheduleSetUp . InsertAllOnSubmit ( addList ) ;
Funs . DB . SubmitChanges ( ) ;
DataBridScsd ( ) ;
ShowNotify ( "保存成功!" ) ;
}
catch ( Exception ex )
{
ShowNotify ( ex . Message , MessageBoxIcon . Error ) ;
}
}
/// <summary>
/// 三查四定导出
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnScsdExport_Click ( object sender , EventArgs e )
{
string rootPath = Server . MapPath ( "~/" ) + Const . ExcelUrl ;
//导出文件
string filePath = rootPath + DateTime . Now . ToString ( "yyyyMMddhhmmss" ) + "\\" ;
if ( ! Directory . Exists ( filePath ) )
{
Directory . CreateDirectory ( filePath ) ;
}
string ReportFileName = filePath + "三查四定进度.xlsx" ;
var result = ScsdData ( ) ;
if ( result . Count > 0 )
{
XSSFWorkbook hssfworkbook = new XSSFWorkbook ( ) ;
XSSFSheet ws = ( XSSFSheet ) hssfworkbook . CreateSheet ( "三查四定进度" ) ;
#region 列 宽
ws . SetColumnWidth ( 0 , ( 30 * 256 ) ) ;
ws . SetColumnWidth ( 1 , ( 20 * 256 ) ) ;
ws . SetColumnWidth ( 2 , ( 20 * 256 ) ) ;
ws . SetColumnWidth ( 3 , ( 20 * 256 ) ) ;
#endregion
#region 样 式
//公共样式
ICellStyle style = SetExcelStyle ( hssfworkbook , BorderStyle . Thin , BorderStyle . Thin , BorderStyle . Thin , BorderStyle . Thin , VerticalAlignment . Center , HorizontalAlignment . Center , 10.5 , true ) ;
//公共样式加粗
ICellStyle styleBold = SetExcelStyle ( hssfworkbook , BorderStyle . Thin , BorderStyle . Thin , BorderStyle . Thin , BorderStyle . Thin , VerticalAlignment . Center , HorizontalAlignment . Center , 10.5 , true , true ) ;
#endregion
#region 头 部
ws = ExcelCreateRowTitle ( ws , hssfworkbook , style , 0 , 0 , 0 , 3 ) ;
//行1
ws . GetRow ( 0 ) . GetCell ( 0 ) . CellStyle = styleBold ;
ws . GetRow ( 0 ) . GetCell ( 0 ) . SetCellValue ( "类别名称" ) ;
ws . GetRow ( 0 ) . GetCell ( 1 ) . CellStyle = styleBold ;
ws . GetRow ( 0 ) . GetCell ( 1 ) . SetCellValue ( "全部数量" ) ;
ws . GetRow ( 0 ) . GetCell ( 2 ) . CellStyle = styleBold ;
ws . GetRow ( 0 ) . GetCell ( 2 ) . SetCellValue ( "进行中数量" ) ;
ws . GetRow ( 0 ) . GetCell ( 3 ) . CellStyle = styleBold ;
ws . GetRow ( 0 ) . GetCell ( 3 ) . SetCellValue ( "已完成数量" ) ;
#endregion
#region 表 格
var start = 1 ;
var end = result . Count ;
ws = ExcelCreateRowTitle ( ws , hssfworkbook , style , start , end , 0 , 3 ) ;
//数据
var dataIndex = 1 ;
foreach ( var item in result )
{
ws . GetRow ( dataIndex ) . GetCell ( 0 ) . SetCellValue ( item . LevelName ) ;
ws . GetRow ( dataIndex ) . GetCell ( 1 ) . SetCellValue ( item . AllNum . ToString ( ) ) ;
ws . GetRow ( dataIndex ) . GetCell ( 2 ) . SetCellValue ( item . ProgressNum . ToString ( ) ) ;
ws . GetRow ( dataIndex ) . GetCell ( 3 ) . SetCellValue ( item . CompleteNum . ToString ( ) ) ;
dataIndex + + ;
}
#endregion
#region 尾 部
ws = ExcelCreateRowTitle ( ws , hssfworkbook , style , end + 1 , end + 1 , 0 , 3 ) ;
ws . GetRow ( end + 1 ) . GetCell ( 0 ) . SetCellValue ( "合计" ) ;
ws . GetRow ( end + 1 ) . GetCell ( 1 ) . SetCellValue ( result . Count > 0 ? result . Sum ( x = > x . AllNum ) . ToString ( ) : "0" ) ;
ws . GetRow ( end + 1 ) . GetCell ( 2 ) . SetCellValue ( result . Count > 0 ? result . Sum ( x = > x . ProgressNum ) . ToString ( ) : "0" ) ;
ws . GetRow ( end + 1 ) . GetCell ( 3 ) . SetCellValue ( result . Count > 0 ? result . Sum ( x = > x . CompleteNum ) . ToString ( ) : "0" ) ;
#endregion
ws . PrintSetup . Landscape = false ;
ws . PrintSetup . PaperSize = 9 ;
ws . ForceFormulaRecalculation = true ;
using ( FileStream filess = File . OpenWrite ( ReportFileName ) )
{
hssfworkbook . Write ( filess ) ;
}
FileInfo filet = new FileInfo ( ReportFileName ) ;
Response . Clear ( ) ;
Response . Charset = "GB2312" ;
Response . ContentEncoding = System . Text . Encoding . UTF8 ;
// 添加头信息,为"文件下载/另存为"对话框指定默认文件名
Response . AddHeader ( "Content-Disposition" , "attachment; filename=" + Server . UrlEncode ( "三查四定进度.xlsx" ) ) ;
// 添加头信息,指定文件大小,让浏览器能够显示下载进度
Response . AddHeader ( "Content-Length" , filet . Length . ToString ( ) ) ;
// 指定返回的是一个不能被客户端读取的流,必须被下载
Response . ContentType = "application/ms-excel" ;
// 把文件流发送到客户端
Response . WriteFile ( filet . FullName ) ;
// 停止页面的执行
Response . End ( ) ;
}
}
2024-02-08 18:10:24 +08:00
#endregion
2024-05-07 01:58:42 +08:00
#region 投 料 试 车
/// <summary>
/// 投料试车绑定
/// </summary>
public void gvFeedingBrid ( )
{
var result = new List < ParameterSettingsDto > ( ) ;
if ( Funs . DB . Run_ParameterSettings . Count ( x = > x . ProjectId = = this . CurrUser . LoginProjectId & & x . States = = 1 ) = = 0 )
{
var query = from runsys in Funs . DB . PreRun_SysDevice
join install in Funs . DB . PreRun_SysDevice on runsys . InstallationId equals install . PreRunId
join proce in Funs . DB . PreRun_SysDevice on runsys . ProcessesId equals proce . PreRunId
join project in Funs . DB . Base_Project on runsys . ProjectId equals project . ProjectId
where runsys . PreRunLevel = = 3 & & runsys . ProjectId = = this . CurrUser . LoginProjectId
orderby runsys . Sort ascending
select new ParameterSettingsDto ( )
{
ProjectId = this . CurrUser . LoginProjectId ,
ProjectName = project . ProjectName ,
InstallationId = runsys . InstallationId ,
InstallationName = install . PreRunName ,
ProcessesId = runsys . ProcessesId ,
ProcessesName = proce . PreRunName ,
SystemId = runsys . PreRunId ,
SystemName = runsys . PreRunName ,
States = 1 ,
RunType = 1
} ;
if ( query . Count ( ) > 0 )
{
result = query . ToList ( ) ;
result . ForEach ( x = > { x . SettingsId = Guid . NewGuid ( ) . ToString ( ) ; } ) ;
}
}
else
{
var query = from setting in Funs . DB . Run_ParameterSettings
join install in Funs . DB . PreRun_SysDevice on setting . InstallationId equals install . PreRunId
join proce in Funs . DB . PreRun_SysDevice on setting . ProcessesId equals proce . PreRunId
join sys in Funs . DB . PreRun_SysDevice on setting . SystemId equals sys . PreRunId
join project in Funs . DB . Base_Project on setting . ProjectId equals project . ProjectId
where setting . ProjectId = = this . CurrUser . LoginProjectId & & setting . States = = 1
orderby setting . Sort ascending
select new ParameterSettingsDto ( )
{
SettingsId = setting . SettingsId ,
ProjectId = setting . ProjectId ,
ProjectName = project . ProjectName ,
InstallationId = setting . InstallationId ,
InstallationName = install . PreRunName ,
ProcessesId = setting . ProcessesId ,
ProcessesName = proce . PreRunName ,
SystemId = setting . SystemId ,
SystemName = sys . PreRunName ,
States = setting . States ,
RunType = setting . RunType ,
AddUser = setting . AddUser ,
AddTime = setting . AddTime ,
Sort = setting . Sort ,
} ;
if ( query . Count ( ) > 0 )
{
result = query . ToList ( ) ;
}
}
gvFeeding . DataSource = result ;
TabStrip1 . ActiveTabIndex = 3 ;
gvFeeding . DataBind ( ) ;
}
/// <summary>
/// 投料试车保存
/// </summary>
protected void btnFeedingSave_Click ( object sender , EventArgs e )
{
try
{
var deletelist = Funs . DB . Run_ParameterSettings . Where ( x = > x . ProjectId = = this . CurrUser . LoginProjectId & & x . States = = 1 ) ;
Funs . DB . Run_ParameterSettings . DeleteAllOnSubmit ( deletelist ) ;
Funs . DB . SubmitChanges ( ) ;
var addList = new List < Run_ParameterSettings > ( ) ;
JArray mergedData = gvFeeding . GetMergedData ( ) ;
foreach ( JObject mergedRow in mergedData )
{
string status = mergedRow . Value < string > ( "status" ) ;
JObject values = mergedRow . Value < JObject > ( "values" ) ;
int i = mergedRow . Value < int > ( "index" ) ;
var model = new Run_ParameterSettings ( ) ;
model . SettingsId = this . gvFeeding . Rows [ i ] . DataKeys [ 0 ] . ToString ( ) ;
model . ProjectId = this . CurrUser . LoginProjectId ;
model . InstallationId = this . gvFeeding . Rows [ i ] . DataKeys [ 1 ] . ToString ( ) ;
model . ProcessesId = this . gvFeeding . Rows [ i ] . DataKeys [ 2 ] . ToString ( ) ;
model . SystemId = this . gvFeeding . Rows [ i ] . DataKeys [ 3 ] . ToString ( ) ;
model . States = 1 ;
var runtype = ! string . IsNullOrWhiteSpace ( values . Value < string > ( "RunType" ) ) ? values . Value < string > ( "RunType" ) : string . Empty ;
if ( ! string . IsNullOrWhiteSpace ( runtype ) )
{
model . RunType = int . Parse ( runtype ) ;
}
model . AddUser = this . CurrUser . UserId ;
model . AddTime = DateTime . Now ;
model . Sort = i ;
addList . Add ( model ) ;
}
Funs . DB . Run_ParameterSettings . InsertAllOnSubmit ( addList ) ;
Funs . DB . SubmitChanges ( ) ;
gvFeedingBrid ( ) ;
ShowNotify ( "保存成功!" ) ;
}
catch ( Exception ex )
{
ShowNotify ( ex . Message , MessageBoxIcon . Error ) ;
}
}
#endregion
#region 生 产 性 能 考 核
/// <summary>
/// 生产性能考核绑定
/// </summary>
public void PerformPageInit ( )
{
var model = Funs . DB . Run_ProductionSettings . FirstOrDefault ( x = > x . ProjectId = = this . CurrUser . LoginProjectId ) ;
if ( model ! = null )
{
if ( model . States = = 1 )
{
txtStartData . Hidden = true ;
txtEndData . Hidden = true ;
rbtNotStarted . Checked = true ;
}
else if ( model . States = = 2 )
{
txtStartData . Hidden = false ;
txtEndData . Hidden = false ;
rbtInProgress . Checked = true ;
txtStartData . Text = model . StartTime . Value . ToString ( "yyyy-MM-dd" ) ;
txtEndData . Text = model . EndTime . Value . ToString ( "yyyy-MM-dd" ) ;
}
else if ( model . States = = 2 )
{
txtStartData . Hidden = true ;
txtEndData . Hidden = true ;
rbtComplete . Checked = true ;
}
}
}
/// <summary>
/// 保存
/// </summary>
protected void btnSubmit_Click ( object sender , EventArgs e )
{
bool add = false ;
if ( rbtInProgress . Checked & & string . IsNullOrWhiteSpace ( txtStartData . Text ) )
{
ShowNotify ( "开始时间不能为空!" , MessageBoxIcon . Warning ) ;
return ;
}
if ( rbtInProgress . Checked & & string . IsNullOrWhiteSpace ( txtEndData . Text ) )
{
ShowNotify ( "结束时间不能为空!" , MessageBoxIcon . Warning ) ;
return ;
}
var state = 0 ;
if ( rbtNotStarted . Checked )
{
state = 1 ;
}
if ( rbtInProgress . Checked )
{
state = 2 ;
}
if ( rbtComplete . Checked )
{
state = 3 ;
}
var model = Funs . DB . Run_ProductionSettings . FirstOrDefault ( x = > x . ProjectId = = this . CurrUser . LoginProjectId ) ;
if ( model = = null )
{
add = true ;
model = new Run_ProductionSettings ( ) ;
model . ProductionId = Guid . NewGuid ( ) . ToString ( ) ;
model . ProjectId = this . CurrUser . LoginProjectId ;
model . AddUser = this . CurrUser . UserId ;
model . AddTime = DateTime . Now ;
}
model . States = state ;
if ( state = = 2 )
{
model . StartTime = DateTime . Parse ( txtStartData . Text . ToString ( ) ) ;
model . EndTime = DateTime . Parse ( txtEndData . Text . ToString ( ) ) ;
}
else
{
model . StartTime = null ;
model . EndTime = null ;
}
if ( add ) Funs . DB . Run_ProductionSettings . InsertOnSubmit ( model ) ;
Funs . DB . SubmitChanges ( ) ;
PerformPageInit ( ) ;
ShowNotify ( "保存成功!" ) ;
}
/// <summary>
/// 考核选择
/// </summary>
protected void rbtCheck_CheckedChanged ( object sender , CheckedEventArgs e )
{
if ( rbtInProgress . Checked )
{
txtStartData . Hidden = false ;
txtEndData . Hidden = false ;
}
else
{
txtStartData . Hidden = true ;
txtEndData . Hidden = true ;
}
}
#endregion
#region 生 产 试 运 行
/// <summary>
///生产试运行绑定
/// </summary>
public void gvProducBrid ( )
{
var result = new List < ParameterSettingsDto > ( ) ;
if ( Funs . DB . Run_ParameterSettings . Count ( x = > x . ProjectId = = this . CurrUser . LoginProjectId & & x . States = = 2 ) = = 0 )
{
var query = from runsys in Funs . DB . PreRun_SysDevice
join install in Funs . DB . PreRun_SysDevice on runsys . InstallationId equals install . PreRunId
join proce in Funs . DB . PreRun_SysDevice on runsys . ProcessesId equals proce . PreRunId
join project in Funs . DB . Base_Project on runsys . ProjectId equals project . ProjectId
where runsys . PreRunLevel = = 3 & & runsys . ProjectId = = this . CurrUser . LoginProjectId
orderby runsys . Sort ascending
select new ParameterSettingsDto ( )
{
ProjectId = this . CurrUser . LoginProjectId ,
ProjectName = project . ProjectName ,
InstallationId = runsys . InstallationId ,
InstallationName = install . PreRunName ,
ProcessesId = runsys . ProcessesId ,
ProcessesName = proce . PreRunName ,
SystemId = runsys . PreRunId ,
SystemName = runsys . PreRunName ,
States = 2 ,
RunType = 1
} ;
if ( query . Count ( ) > 0 )
{
result = query . ToList ( ) ;
result . ForEach ( x = > { x . SettingsId = Guid . NewGuid ( ) . ToString ( ) ; } ) ;
}
}
else
{
var query = from setting in Funs . DB . Run_ParameterSettings
join install in Funs . DB . PreRun_SysDevice on setting . InstallationId equals install . PreRunId
join proce in Funs . DB . PreRun_SysDevice on setting . ProcessesId equals proce . PreRunId
join sys in Funs . DB . PreRun_SysDevice on setting . SystemId equals sys . PreRunId
join project in Funs . DB . Base_Project on setting . ProjectId equals project . ProjectId
where setting . ProjectId = = this . CurrUser . LoginProjectId & & setting . States = = 2
orderby setting . Sort ascending
select new ParameterSettingsDto ( )
{
SettingsId = setting . SettingsId ,
ProjectId = setting . ProjectId ,
ProjectName = project . ProjectName ,
InstallationId = setting . InstallationId ,
InstallationName = install . PreRunName ,
ProcessesId = setting . ProcessesId ,
ProcessesName = proce . PreRunName ,
SystemId = setting . SystemId ,
SystemName = sys . PreRunName ,
States = setting . States ,
RunType = setting . RunType ,
AddUser = setting . AddUser ,
AddTime = setting . AddTime ,
Sort = setting . Sort ,
} ;
if ( query . Count ( ) > 0 )
{
result = query . ToList ( ) ;
}
}
gvProduc . DataSource = result ;
TabStrip1 . ActiveTabIndex = 5 ;
gvProduc . DataBind ( ) ;
}
/// <summary>
/// 生产试运行保存
/// </summary>
protected void btnProducSave_Click ( object sender , EventArgs e )
{
try
{
var deletelist = Funs . DB . Run_ParameterSettings . Where ( x = > x . ProjectId = = this . CurrUser . LoginProjectId & & x . States = = 2 ) ;
Funs . DB . Run_ParameterSettings . DeleteAllOnSubmit ( deletelist ) ;
Funs . DB . SubmitChanges ( ) ;
var addList = new List < Run_ParameterSettings > ( ) ;
JArray mergedData = gvProduc . GetMergedData ( ) ;
foreach ( JObject mergedRow in mergedData )
{
string status = mergedRow . Value < string > ( "status" ) ;
JObject values = mergedRow . Value < JObject > ( "values" ) ;
int i = mergedRow . Value < int > ( "index" ) ;
var model = new Run_ParameterSettings ( ) ;
model . SettingsId = this . gvProduc . Rows [ i ] . DataKeys [ 0 ] . ToString ( ) ;
model . ProjectId = this . CurrUser . LoginProjectId ;
model . InstallationId = this . gvProduc . Rows [ i ] . DataKeys [ 1 ] . ToString ( ) ;
model . ProcessesId = this . gvProduc . Rows [ i ] . DataKeys [ 2 ] . ToString ( ) ;
model . SystemId = this . gvProduc . Rows [ i ] . DataKeys [ 3 ] . ToString ( ) ;
model . States = 2 ;
var runtype = ! string . IsNullOrWhiteSpace ( values . Value < string > ( "RunType" ) ) ? values . Value < string > ( "RunType" ) : string . Empty ;
if ( ! string . IsNullOrWhiteSpace ( runtype ) )
{
model . RunType = int . Parse ( runtype ) ;
}
model . AddUser = this . CurrUser . UserId ;
model . AddTime = DateTime . Now ;
model . Sort = i ;
addList . Add ( model ) ;
}
Funs . DB . Run_ParameterSettings . InsertAllOnSubmit ( addList ) ;
Funs . DB . SubmitChanges ( ) ;
gvProducBrid ( ) ;
ShowNotify ( "保存成功!" ) ;
}
catch ( Exception ex )
{
ShowNotify ( ex . Message , MessageBoxIcon . Error ) ;
}
}
#endregion
2024-02-08 18:10:24 +08:00
#region 私 有 方 法
2024-03-11 09:46:11 +08:00
/// <summary>
/// 创建头部
/// </summary>
/// <returns></returns>
private XSSFSheet ExcelCreateRowTitle ( XSSFSheet ws , XSSFWorkbook hssfworkbook , ICellStyle style , int sRows , int eRows , int cStart , int cEnd , float height = 21 )
{
for ( int i = sRows ; i < = eRows ; i + + )
{
ws . CreateRow ( i ) ;
ws . GetRow ( i ) . HeightInPoints = height ;
for ( int j = cStart ; j < = cEnd ; j + + )
{
ws . GetRow ( i ) . CreateCell ( j ) ;
ws . GetRow ( i ) . CreateCell ( j ) . CellStyle = style ;
}
}
return ws ;
}
/// <summary>
/// 创建样式
/// </summary>
/// <returns></returns>
public static ICellStyle SetExcelStyle ( XSSFWorkbook wb , BorderStyle Bottom , BorderStyle Left , BorderStyle Right , BorderStyle Top , VerticalAlignment VerAig , HorizontalAlignment HorAig , double FontSize , bool WrapText = true , bool Bold = false , string FontName = "宋体" )
{
ICellStyle style = wb . CreateCellStyle ( ) ;
style . BorderBottom = Bottom ;
style . BorderLeft = Left ;
style . BorderRight = Right ;
style . BorderTop = Top ;
style . VerticalAlignment = VerAig ;
style . Alignment = HorAig ;
IFont font = wb . CreateFont ( ) ;
font . FontHeightInPoints = FontSize ;
font . IsBold = Bold ;
font . FontName = FontName ;
style . SetFont ( font ) ;
style . WrapText = WrapText ;
return style ;
}
2024-02-08 18:10:24 +08:00
/// <summary>
/// 私有方法
/// </summary>
protected void TabStrip1_TabIndexChanged ( object sender , EventArgs e )
{
if ( TabStrip1 . ActiveTabIndex = = 0 )
{
//预试车
DataBridYsc ( ) ;
}
else if ( TabStrip1 . ActiveTabIndex = = 1 )
{
//试车
DataBridSc ( ) ;
}
2024-03-11 09:46:11 +08:00
else if ( TabStrip1 . ActiveTabIndex = = 2 )
{
//三查四定
DataBridScsd ( ) ;
}
2024-05-07 01:58:42 +08:00
else if ( TabStrip1 . ActiveTabIndex = = 3 )
{
//投料试车
gvFeedingBrid ( ) ;
}
else if ( TabStrip1 . ActiveTabIndex = = 4 )
{
//生产性能考核
PerformPageInit ( ) ;
}
else if ( TabStrip1 . ActiveTabIndex = = 5 )
{
//生产试运行
gvProducBrid ( ) ;
}
2024-02-08 18:10:24 +08:00
}
public class Run_ScheduleSetUpDto : Run_ScheduleSetUp
{
/// <summary>
/// 工作包名称
/// </summary>
public string WorkPackName { get ; set ; }
}
2024-03-11 09:46:11 +08:00
/// <summary>
/// 试车检查表实体
/// </summary>
public class WorkPackageInspectDto
{
/// <summary>
/// 工作包主键
/// </summary>
public string WorkPackId { get ; set ; }
/// <summary>
/// 工作包名称
/// </summary>
public string WorkPackName { get ; set ; }
/// <summary>
/// 检查表数量
/// </summary>
public int AllNum { get ; set ; }
/// <summary>
/// 未关闭任务单数量
/// </summary>
public int NoCloseNum { get ; set ; }
/// <summary>
/// 已关闭任务单数量
/// </summary>
public int CloseNum { get ; set ; }
}
/// <summary>
/// 三查四定统计实体
/// </summary>
public class FourDecisionScheduleBridDto
{
/// <summary>
/// 级别
/// </summary>
public string Level { get ; set ; }
/// <summary>
/// 尾项数量
/// </summary>
public int AllNum { get ; set ; }
/// <summary>
/// 未关闭尾项数量
/// </summary>
public int NoCloseNum { get ; set ; }
/// <summary>
/// 已关闭尾项数量
/// </summary>
public int CloseNum { get ; set ; }
}
2024-05-07 01:58:42 +08:00
/// <summary>
/// 投料试车实体
/// </summary>
public class ParameterSettingsDto : Run_ParameterSettings
{
/// <summary>
/// 项目名称
/// </summary>
public string ProjectName { get ; set ; }
/// <summary>
/// 装置名称
/// </summary>
public string InstallationName { get ; set ; }
/// <summary>
/// 工序名称
/// </summary>
public string ProcessesName { get ; set ; }
/// <summary>
/// 系统名称
/// </summary>
public string SystemName { get ; set ; }
}
2024-02-08 18:10:24 +08:00
#endregion
2024-03-11 09:46:11 +08:00
#region 转 换
/// <summary>
/// DataTable转换List
/// </summary>
/// <returns></returns>
public List < T > DataTableToList < T > ( DataTable table )
{
List < T > list = new List < T > ( ) ;
T t = default ( T ) ;
PropertyInfo [ ] propertypes = null ;
string tempName = string . Empty ;
foreach ( DataRow row in table . Rows )
{
t = Activator . CreateInstance < T > ( ) ;
propertypes = t . GetType ( ) . GetProperties ( ) ;
foreach ( PropertyInfo pro in propertypes )
{
tempName = pro . Name ;
if ( table . Columns . Contains ( tempName ) )
{
object value = row [ tempName ] ;
if ( ! value . ToString ( ) . Equals ( "" ) )
{
pro . SetValue ( t , value , null ) ;
}
}
}
list . Add ( t ) ;
}
return list . Count = = 0 ? new List < T > ( ) : list ;
}
#endregion
2024-02-08 18:10:24 +08:00
}
}