@ -238,7 +238,7 @@ where res.taskcode = '0' and equipmentCode = 'C6' and res.OrderCode is not null
[operation_desc] , [ old_value ] , [ new_value ] , [ device_code ] , [ remark ] , [ order_code ] )
VALUES
( ' { CommonFunc . Common . GetUUID ( ) } ' , ' { LoginUser . UserId } ' , ' { LoginUser . UserName } ' , ' { type } ' , GetDate ( ) ,
' 工 单 状 态 更 新 - 暂停 ' , ' w2 ' , ' { status } ' , ' { deviceCode } ',' { remark } ',' { orderCode } ' ) ; ";
' 工 单 状 态 更 新 - 恢复 ' , ' w4 ' , ' { status } ' , ' { deviceCode } ',' { remark } ',' { orderCode } ' ) ; ";
}
else
{
@ -247,7 +247,7 @@ where res.taskcode = '0' and equipmentCode = 'C6' and res.OrderCode is not null
[operation_desc] , [ old_value ] , [ new_value ] , [ device_code ] , [ remark ] , [ order_code ] )
VALUES
( ' { CommonFunc . Common . GetUUID ( ) } ' , ' { LoginUser . UserId } ' , ' { LoginUser . UserName } ' , ' { type } ' , GetDate ( ) ,
' 工 单 状 态 更 新 - 恢复 ' , ' w4 ' , ' { status } ' , ' { deviceCode } ',' { remark } ',' { orderCode } ' ) ; ";
' 工 单 状 态 更 新 - 暂停 ' , ' w2 ' , ' { status } ' , ' { deviceCode } ',' { remark } ',' { orderCode } ' ) ; ";
}
string sql = $@"update pro_order_workorder set status = '{status}' where workorder_code = '{orderCode}'" ;
sqlList . Add ( sql ) ;
@ -624,7 +624,7 @@ VALUES
{ userCount } , ' { costCenter } ',' 0 ',' { batchCode } ',' { isEndReport } ',' { 0 } ',' { LoginUser . CurrDeviceIP } ',' { LoginUser . Version } ' ) ; ";
foreach ( string item in GetAllWorkReportsForOrderAndChildren ( selectRow [ "workorder_code" ] . ToString ( ) , selectRow , orderQuntity , reportCode , costCenter , batchCode ,
isEndReport , deviceCode , lineName , workCount , workTimeDic , userCountDic , 0 ) )
isEndReport , deviceCode , lineName , workCount , workTimeDic , userCountDic , 0 ) )
{
sqlList . Add ( item ) ;
}
@ -681,33 +681,47 @@ VALUES
//赵啸林又说sap有问题, 需要上位机修改报工标识2023-12-25,但仅在最终报工时,才更新此状态
if ( isEndReport . Equals ( "1" ) )
{
//更新订单状态为已报工;
string updateOrderSql = $@"update pro_order_workorder set status = 'w3', update_by = '{LoginUser.UserName}',update_time = GETDATE() where belong_work_order = '{selectRow[" workorder_code "]}' " ;
sqlList . Add ( updateOrderSql ) ;
//2024-04-15添加切线方案, 暂停状态下不修改报工状态,=w4的时候, 不加报工状态更新语句
if ( ! selectRow [ "status" ] . ToString ( ) . Equals ( "w4" ) )
{
//更新订单状态为已报工;
string updateOrderSql = $@"update pro_order_workorder set status = 'w3', update_by = '{LoginUser.UserName}',update_time = GETDATE() where belong_work_order = '{selectRow[" workorder_code "]}' " ;
sqlList . Add ( updateOrderSql ) ;
//修改报工逻辑, 最终报工时添加子母工单领料单状态更新2024-02-20
if ( subOrder ! = "" ) //有子单
{
//更新子单状态
string updateSubOrderPrepareSql = $"update mes_prepare set status = 'L1' where workorder_code = '{subOrder}'" ;
//更新母单状态
string updateMainOrderPrepareSql = $"update mes_prepare set status = 'L1' where workorder_code = '{selectRow[" workorder_code "]}'" ;
sqlList . Add ( updateSubOrderPrepareSql ) ;
sqlList . Add ( updateMainOrderPrepareSql ) ;
}
else //无子单
{
//更新母单状态
string updateMainOrderPrepareSql = $"update mes_prepare set status = 'L1' where workorder_code = '{selectRow[" workorder_code "]}'" ;
sqlList . Add ( updateMainOrderPrepareSql ) ;
//修改报工逻辑, 最终报工时添加子母工单领料单状态更新2024-02-20
//递归更新子单领料状态
foreach ( var item in GetUpdatePrepareSql ( selectRow [ "workorder_code" ] . ToString ( ) ) )
{
sqlList . Add ( item ) ;
}
}
//if (subOrder != "") //有子单
//{
// //更新子单状态
// string updateSubOrderPrepareSql = $"update mes_prepare set status = 'L1' where workorder_code = '{subOrder}'";
// //更新母单状态
// string updateMainOrderPrepareSql = $"update mes_prepare set status = 'L1' where workorder_code = '{selectRow["workorder_code"]}'";
// sqlList.Add(updateSubOrderPrepareSql);
// sqlList.Add(updateMainOrderPrepareSql);
//}
//else //无子单
//{
// //更新母单状态
// string updateMainOrderPrepareSql = $"update mes_prepare set status = 'L1' where workorder_code = '{selectRow["workorder_code"]}'";
// sqlList.Add(updateMainOrderPrepareSql);
//}
}
# endregion
#region 批次报工状态更新
//添加批次报工状态更新--2023-12-26
string updateBatchOrderStatusSql = $@"update pro_order_workorder_batch set status = '0', update_by = '{LoginUser.UserName}',update_time = GETDATE() where workorder_id = '{selectRow[" workorder_id "]}' and batch_code = '{batchCode}' " ;
sqlList . Add ( updateBatchOrderStatusSql ) ;
//2024-04-15添加切线方案, 暂停状态下不修改报工状态,=w4的时候, 不加报工状态更新语句
if ( ! selectRow [ "status" ] . ToString ( ) . Equals ( "w4" ) )
{
//添加批次报工状态更新--2023-12-26
string updateBatchOrderStatusSql = $@"update pro_order_workorder_batch set status = '0', update_by = '{LoginUser.UserName}',update_time = GETDATE() where workorder_id = '{selectRow[" workorder_id "]}' and batch_code = '{batchCode}' " ;
sqlList . Add ( updateBatchOrderStatusSql ) ;
}
# endregion
@ -715,11 +729,29 @@ VALUES
}
List < string > workReports = new List < string > ( ) ;
List < string > updatePrepareSqlList = new List < string > ( ) ;
/// <summary>
/// 递归获取子单报工SQL
/// </summary>
/// <param name="orderId"></param>
/// <param name="selectRow"></param>
/// <param name="orderQuntity"></param>
/// <param name="reportCode"></param>
/// <param name="costCenter"></param>
/// <param name="batchCode"></param>
/// <param name="isEndReport"></param>
/// <param name="deviceCode"></param>
/// <param name="lineName"></param>
/// <param name="workCount"></param>
/// <param name="workTimeDic"></param>
/// <param name="userCountDic"></param>
/// <param name="sortNo"></param>
/// <returns></returns>
public List < string > GetAllWorkReportsForOrderAndChildren ( string orderId , DataRowView selectRow , string orderQuntity , string reportCode , string costCenter , string batchCode ,
string isEndReport , string deviceCode , string lineName , string workCount , Dictionary < int , string > workTimeDic , Dictionary < int , string > userCountDic , int sortNo )
string isEndReport , string deviceCode , string lineName , string workCount , Dictionary < int , string > workTimeDic , Dictionary < int , string > userCountDic , int sortNo )
{
//获取子工单的信息
string getSubOrderSql = $"select workorder_code,product_code,product_name,quantity_split,unit from pro_order_workorder where parent_order = '{orderId}'" ;
string subOrder = "" ;
@ -736,7 +768,34 @@ VALUES
subQuntity = dtSubOrder . Tables [ 0 ] . Rows [ 0 ] [ "quantity_split" ] . ToString ( ) ;
subUnit = dtSubOrder . Tables [ 0 ] . Rows [ 0 ] [ "unit" ] . ToString ( ) ;
double rate = Convert . ToDouble ( workCount ) / Convert . ToDouble ( orderQuntity ) ;
double subOrderQty = rate * Convert . ToDouble ( subQuntity ) ;
double subOrderQty = 0 ;
LogHelper . instance . log . Info ( "rate>>>" + rate ) ;
//根据base_product_attach表里的报工比例, 计算子单数量, 又取消了
string sqlGetReportRate = $@"select isnull(report_rate,0) as report_rate from base_product where product_code = '{selectRow[" product_code "]}'" ;
//DataSet dtReportRate = Utils.netClientDBHelper.getDataSet(sqlGetReportRate);
//string reportRate = "0";
//if (dtReportRate != null && dtReportRate.Tables.Count > 0 && dtReportRate.Tables[0].Rows.Count > 0)
//{
// reportRate = dtReportRate.Tables[0].Rows[0][0].ToString();
// LogHelper.instance.log.Info("获取到报工效率为:" + reportRate+",产品编码为:"+ selectRow["product_code"]+",子单数量为:"+ subQuntity);
//}
//if (sortNo < 3)
//{
// if (reportRate.Equals("0"))
// {
// subOrderQty = rate * Convert.ToDouble(subQuntity);
// }
// else
// {
// subOrderQty = Convert.ToDouble(reportRate) * Convert.ToDouble(subQuntity);
// }
//}
if ( sortNo < 3 )
{
subOrderQty = rate * Convert . ToDouble ( subQuntity ) ;
}
string subOrderSql = $ @ "INSERT INTO [dbo].[mes_report_work]
( [ id ] , [ report_type ] , [ report_code ] , [ workorder_code ] , [ product_code ] , [ product_name ] ,
[spec] , [ unit ] , [ quantity ] , [ quantity_feedback ] , [ quantity_qualified ] , [ quantity_unqualified ] ,
@ -752,10 +811,10 @@ VALUES
'无' , ' { workTimeDic [ sortNo ] } ' , ' { deviceCode } ' , ' { lineName } ' , N ' { LoginUser . TeamCode } ' , ' { selectRow [ "shift_id" ] } ' ,
NULL , NULL , NULL , NULL , ' { LoginUser . UserName } ' , ' { DateTime . Now . ToString ( "yyyy-MM-dd HH:mm:ss" ) } ' ,
' { DateTime . Now . ToString ( "yyyy-MM-dd HH:mm:ss" ) } ' , ' { LoginUser . UserName } ' , '0' , NULL , ' prod ' ,
{ userCountDic [ sortNo ] } , ' { costCenter } ',' 0 ',' { batchCode } ',' { isEndReport } ',' { selectRow[ "workorder_code" ] } ',' { LoginUser . CurrDeviceIP } ',' { LoginUser . Version } ' ) ; ";
{ userCountDic [ sortNo ] } , ' { costCenter } ',' 0 ',' { batchCode } ',' { isEndReport } ',' { orderId } ',' { LoginUser . CurrDeviceIP } ',' { LoginUser . Version } ' ) ; ";
workReports . Add ( subOrderSql ) ;
sortNo + + ;
GetAllWorkReportsForOrderAndChildren ( subOrder , selectRow , orderQuntity , reportCode , costCenter , batchCode , isEndReport , deviceCode , lineName , subQuntity , workTimeDic , userCountDic , sortNo ) ;
GetAllWorkReportsForOrderAndChildren ( subOrder , selectRow , orderQuntity , reportCode , costCenter , batchCode , isEndReport , deviceCode , lineName , subQuntity , workTimeDic , userCountDic , sortNo ) ;
}
@ -763,6 +822,23 @@ VALUES
}
public List < string > GetUpdatePrepareSql ( string orderId )
{
string updateMainOrderPrepareSql = $"update mes_prepare set status = 'L1', update_by = '{LoginUser.UserName}',update_time = GETDATE() where workorder_code = '{orderId}' and del_flag = '0'" ;
updatePrepareSqlList . Add ( updateMainOrderPrepareSql ) ;
//获取子工单的信息
string getSubOrderSql = $"select workorder_code,product_code,product_name,quantity_split,unit from pro_order_workorder where parent_order = '{orderId}'" ;
string subOrder = "" ;
DataSet dtSubOrder = Utils . netClientDBHelper . getDataSet ( getSubOrderSql ) ;
if ( dtSubOrder ! = null & & dtSubOrder . Tables . Count > 0 & & dtSubOrder . Tables [ 0 ] . Rows . Count > 0 )
{
subOrder = dtSubOrder . Tables [ 0 ] . Rows [ 0 ] [ "workorder_code" ] . ToString ( ) ;
GetUpdatePrepareSql ( subOrder ) ;
}
return updatePrepareSqlList ;
}
public bool ChangeShiftsInfo ( string deviceCode )
{
/ /
@ -836,7 +912,11 @@ VALUES
return sql ;
}
/// <summary>
/// 获取母单的包工人数
/// </summary>
/// <param name="orderCode"></param>
/// <returns></returns>
public DataTable GetFatherOrderUserCount ( string orderCode )
{
string sql = $@"SELECT top 1 use_man FROM [dbo].[mes_report_work] where workorder_code = '{orderCode}' order by create_time" ;
@ -849,6 +929,24 @@ VALUES
return null ;
}
/// <summary>
/// 获取报工总数量
/// </summary>
/// <param name="orderCode"></param>
/// <returns></returns>
public DataTable GetOrderReportSumQty ( string orderCode )
{
string sql = $@"SELECT sum(quantity_feedback) FROM [dbo].[mes_report_work] where workorder_code = '{orderCode}' GROUP BY workorder_code" ;
DataSet dtset = Utils . netClientDBHelper . getDataSet ( sql ) ;
if ( dtset ! = null & & dtset . Tables . Count > 0 & & dtset . Tables [ 0 ] . Rows . Count > 0 )
{
return dtset . Tables [ 0 ] ;
}
return null ;
}
public DataTable GetSubOrderCount ( string orderCode )
{
//获取子工单的信息