using CommonFunc;
using CommonFunc.Tools;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using XGL.Models.Model.FoamingMac;
namespace XGL.Data.DBService
{
public class FormingMachineService
{
///
/// 获取成型机在产物料信息
///
///
///
///
public DataTable GetFormingMachineInfo(string devicecode, string workDate)
{
//过于复杂,给数据库造成了压力,经常死锁
// string sql = $@"SELECT DISTINCT
// ord.workorder_id,
// ord.workorder_code,
// res.OrderCode,
// ord.product_name,
// product_code,
// isnull( car_num, 0 ) AS car_num,
// isnull( plan_time, '1900-01-01 08:00:00' ) AS plan_time,
// ord.status ,
// ord.route_code,
// ord.attr1,
// ord.shift_id ,totalCount,shift.Shift_Desc
//FROM
//pro_order_workorder ord WITH (NOLOCK)
// LEFT JOIN mes_material_transfer_result res WITH (NOLOCK) ON res.OrderCode = ord.workorder_id
// LEFT JOIN pro_wet_material_plan_detail wet WITH (NOLOCK) ON wet.workorder_id = res.OrderCode
// LEFT JOIN pro_rfid_process_detail rfid WITH (NOLOCK) ON rfid.workorder_code = ord.workorder_code
// left join (select count(*) as totalCount,ordercode from mes_material_transfer_result WITH (NOLOCK)
// where CONVERT(VARCHAR(10), update_time , 120) = CONVERT(VARCHAR(10),'{workDate}', 120) and equipmentCode = '{devicecode}' group by OrderCode) tt
//on (tt.ordercode = wet.workorder_id )
// AND rfid.rfid = res.rfid
//LEFT JOIN base_shifts_t shift WITH (NOLOCK) on ord.shift_id = shift.Shift_Id
//WHERE
// CONVERT(VARCHAR(10), wet.plan_time , 120) = CONVERT(VARCHAR(10), '{workDate}', 120 )
// And ord.prod_line_code like '%{devicecode}%' and totalCount is not null
//ORDER BY
// ( isnull( plan_time, '1900-01-01 08:00:00' ) ) DESC";
string sql = $@"SELECT DISTINCT
ord.workorder_id,
ord.workorder_code,
ord.product_name,
product_code,
isnull( car_num, 0 ) AS car_num,
isnull( product_date, '1900-01-01 08:00:00' ) AS plan_time,
ord.status,
ord.route_code,
ord.attr1,
ord.shift_id,
shift.Shift_Desc,'0' as totalCount
FROM
pro_order_workorder ord WITH (NOLOCK)
LEFT JOIN base_shifts_t shift WITH (NOLOCK) on ord.shift_id = shift.Shift_Id
WHERE
CONVERT(VARCHAR(10), ord.product_date , 120) = CONVERT(VARCHAR(10), '{workDate}', 120 )
And ord.prod_line_code like '%{devicecode}%' AND ord.del_flag='0'";
DataSet dtset = Utils.netClientDBHelper.getDataSet(sql);
if (dtset != null && dtset.Tables.Count > 0 && dtset.Tables[0].Rows.Count > 0)
{
foreach (DataRow item in dtset.Tables[0].Rows)
{
string work0rderID = item["workorder_id"].ToString();
string totalsql = $"SELECT count(*) FROM mes_material_transfer_result result WHERE result.equipmentCode =" +
$" '{devicecode}' AND result.update_time >= ( SELECT TOP 1 create_time FROM mes_changeshift_info WHERE device_code" +
$" = '{devicecode}' ORDER BY create_time DESC ) AND result.rfid_status='1' ;";
// string totalcountSql = $@" select count(*) as totalCount from mes_material_transfer_result WITH (NOLOCK)
//where CONVERT(VARCHAR(10), work_date , 120) = CONVERT(VARCHAR(10),'{workDate}', 120) and equipmentCode = '{devicecode}' and OrderCode = '{work0rderID}' group by OrderCode ";
DataSet dtsetTotalCount = Utils.netClientDBHelper.getDataSet(totalsql);
if (dtsetTotalCount != null && dtsetTotalCount.Tables.Count > 0 && dtsetTotalCount.Tables[0].Rows.Count > 0)
{
item["totalCount"] = dtsetTotalCount.Tables[0].Rows[0][0];
}
}
return dtset.Tables[0];
}
return null;
}
public DataTable GetShiftList()
{
string sql = $@"select shift_id,shift_code,shift_desc,Shift_Start_Time,Shift_End_Time from base_shifts_t where del_flag ='0' ";
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 GetTeamList()
{
string sql = $@"SELECT team_id,team_code,team_desc FROM [dbo].[base_team_t] where del_flag ='0' ";
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 string getnumber(string order, string devicecode, string shetl)
{
string sql = $@"SELECT COUNT(*) FROM mes_material_transfer_result WHERE equipmentCode='{order}' and work_date='{devicecode}' and shift_id='{shetl}' and rfid_status='1'";
DataSet dtset = Utils.netClientDBHelper.getDataSet(sql);
if (dtset != null && dtset.Tables.Count > 0)
{
// 获取查询结果中的计数值并转换为字符串
string countAsString = dtset.Tables[0].Rows[0][0].ToString();
return countAsString;
}
return null;
}
///
/// 获取接口URL
///
///
///
///
public string InterfaceUrl( string url_type)
{
string sql = $@"select url FROM mes_interface_url WHERE url_type='{url_type}'";
DataSet dtset = Utils.netClientDBHelper.getDataSet(sql);
if (dtset != null && dtset.Tables.Count > 0)
{
// 获取查询结果中的计数值并转换为字符串
string countAsString = dtset.Tables[0].Rows[0][0].ToString();
return countAsString;
}
return null;
}
///
/// 获取成型机状态
///
///
///
///
public DataTable GetFormingMachineState(string devicecode)
{
string sql = $@"select status,plc_ip from base_equipment where equipment_code = '{devicecode}'; ";
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 GetInOutHistoryList(string workOrderCode, string devicecode, string workDate)
{
string sql = $@"SELECT DISTINCT ord.workorder_id,ord.workorder_code,res.OrderCode,ord.product_name,product_code,isnull(car_num,0) as car_num,
isnull([begin],'1900-01-01 08:00:00') as [begin],ord.status,ord.route_code,ord.attr1,work_batch_code,res.taskcode,res.rfid,plan_time ,res.update_time
FROM [dbo].[mes_material_transfer_result] res
LEFT JOIN pro_order_workorder ord on res.OrderCode = ord.workorder_id
left JOIN pro_wet_material_plan_detail wet on wet.workorder_id = ord.workorder_id
LEFT JOIN pro_rfid_process_detail rfid on rfid.workorder_code = ord.workorder_code and rfid.rfid = res.rfid
where equipmentCode = '{devicecode}' and work_date = '{workDate}' and ord.workorder_code = '{workOrderCode}' and res.OrderCode is not null ORDER BY update_time desc; ";
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 GetCompleteHistoryList(string devicecode)
{
//taskcode=1,当前机台完成,ord.status = 'w3'当前工单完成
// string sql = $@"SELECT workorder_code,product_name,product_code,isnull(car_num,0) as car_num,isnull([begin],'1900-00-00') as [begin],beout,ord.status,product_date,ord.create_time FROM [dbo].[mes_material_transfer_result] res
//LEFT JOIN pro_order_workorder ord on res.OrderCode = ord.workorder_id
//where res.taskcode = '1' and equipmentCode = '{devicecode}'; ";
string sql = $@"SELECT ord.workorder_id,ord.workorder_code,res.OrderCode,ord.product_name,product_code,isnull(car_num,0) as car_num,
isnull([begin],'1900-01-01 08:00:00') as [begin],ord.status ,ord.route_code,ord.attr1,work_batch_code,res.taskcode,res.rfid,plan_time ,res.update_time
FROM [dbo].[mes_material_transfer_result] res
LEFT JOIN pro_order_workorder ord on res.OrderCode = ord.workorder_id
left JOIN pro_wet_material_plan_detail wet on wet.workorder_id = ord.workorder_id
LEFT JOIN pro_rfid_process_detail rfid on rfid.workorder_code = ord.workorder_code and rfid.rfid = res.rfid
where res.taskcode = '0' and equipmentCode = 'C6' and res.OrderCode is not null ORDER BY plan_time; ";
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 string GetWorkOrderStatus(string orderCode)
{
string sql = $@"select status from pro_order_workorder where workorder_code = '{orderCode}'";
var obj = Utils.netClientDBHelper.getScalar(sql, null);
string issucc = obj == null ? "" : obj.ToString();
return issucc;
}
///
/// 更新工单状态
///
///
///
///
public bool UpdateWorkOrder(string orderCode, string status, string remark, string type, string deviceCode)
{
List sqlList = new List();
string logSql = "";
if (status.Equals("w2"))
{
logSql = $@"INSERT INTO [dbo].[mes_operation_log]
([id], [user_id], [user_name], [operation_type], [operation_time],
[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}');";
}
else
{
logSql = $@"INSERT INTO [dbo].[mes_operation_log]
([id], [user_id], [user_name], [operation_type], [operation_time],
[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}');";
}
string sql = $@"update pro_order_workorder set status = '{status}' where workorder_code = '{orderCode}'";
sqlList.Add(sql);
sqlList.Add(logSql);
bool issucc = Utils.netClientDBHelper.executeBatchSql(sqlList);
return issucc;
}
///
/// 更新工单
///
///
///
///
public bool InsertData(FoamingMacModel formingModel)
{
string sql = $@"INSERT INTO [mes_material_transfer_result] (
[id],
[begin],
[beout],
[equipmentCode],
[OrderCode],
[sku],
[planID],
[rfid],
[now_process_id],
[status],
[create_time],
[rfid_status],
[taskcode],
[state],
[update_time]
)
VALUES
(
'{CommonFunc.Common.GetUUID()}',
'GetDate()',
'GetDate()',
'{Utils.GetAppSetting("DeviceCode")}',
'{formingModel.workorder_id}',
'{formingModel.product_code}',
'',
'{formingModel.rfid}',
'',
'4',
'GetDate()',
'1',
'0',
'1',
'GetDate()'
);";
int issucc = Utils.netClientDBHelper.executeUpdate(sql);
return issucc > 0 ? true : false;
}
///
/// 报工
///
///
///
///
public bool ExecuteReportWork(DataRowView selectRow, string orderQuntity, string workCount, string reportCode, string workTime, string userCount, string costCenter, string batchCode, string isEndReport, string deviceCode)
{
string getReportCodeSql = $@"SELECT equipment_code,equipment_name FROM [dbo].[base_equipment] WHERE equipment_code='{deviceCode}'";
string lineName = "";
DataSet dtset = Utils.netClientDBHelper.getDataSet(getReportCodeSql);
if (dtset != null && dtset.Tables.Count > 0 && dtset.Tables[0].Rows.Count > 0)
{
lineName = dtset.Tables[0].Rows[0]["equipment_name"].ToString();
}
//获取子工单的信息
string getSubOrderSql = $"select workorder_code,product_code,product_name,quantity_split,unit from pro_order_workorder where parent_order = '{selectRow["workorder_code"]}'";
string subOrder = "";
string subProductCode = "";
string subProductName = "";
string subQuntity = "";
string subUnit = "";
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();
subProductCode = dtSubOrder.Tables[0].Rows[0]["product_code"].ToString();
subProductName = dtSubOrder.Tables[0].Rows[0]["product_name"].ToString();
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);
List sqlList = new List();
//有子单
if (subOrder != "")
{
string mainOrderSql = $@"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],
[user_name], [nick_name], [feedback_channel], [feedback_time], [record_user], [status],
[remark], [work_time], [machine_code], [machine_name], [team_code], [shift_code],
[attr1], [attr2], [attr3], [attr4], [create_by], [create_time],
[update_time], [update_by], [upload_time], [upload_status], [upload_msg], [prod_type],
[use_man], [work_center],[del_flag],[batch],[end_report],[parent_order])
VALUES
('{Common.GetUUID()}', 'SELF', '{reportCode}', '{selectRow["workorder_code"]}', '{selectRow["product_code"]}', '{selectRow["product_name"]}',
'{selectRow["product_spc"]}', '{selectRow["unit"]}', {workCount}, {workCount}, 0, 0,
'{LoginUser.UserCode}', '{LoginUser.UserName}', 'PC', '{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}', '{LoginUser.UserName}', 'PREPARE',
'无', '{workTime}', '{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}',GetDate(), '0', NULL, 'prod',
{userCount}, '{costCenter}','0','{batchCode}','{isEndReport}','{0}');";
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],
[user_name], [nick_name], [feedback_channel], [feedback_time], [record_user], [status],
[remark], [work_time], [machine_code], [machine_name], [team_code], [shift_code],
[attr1], [attr2], [attr3], [attr4], [create_by], [create_time],
[update_time], [update_by], [upload_time], [upload_status], [upload_msg], [prod_type],
[use_man], [work_center],[del_flag],[batch],[end_report],[parent_order])
VALUES
('{Common.GetUUID()}', 'SELF', '{reportCode}', '{subOrder}', '{subProductCode}', '{subProductName}',
'{selectRow["product_spc"]}', '{subUnit}', {subOrderQty}, {subOrderQty}, 0, 0,
'{LoginUser.UserCode}', '{LoginUser.UserName}', 'PC', '{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}', '{LoginUser.UserName}', 'PREPARE',
'无', '{workTime}', '{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}',GetDate(), '0', NULL, 'prod',
{userCount}, '{costCenter}','0','{batchCode}','{isEndReport}','{selectRow["workorder_code"]}');";
sqlList.Add(mainOrderSql);
sqlList.Add(subOrderSql);
}
else
{
//无子单
string mainOrderSql = $@"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],
[user_name], [nick_name], [feedback_channel], [feedback_time], [record_user], [status],
[remark], [work_time], [machine_code], [machine_name], [team_code], [shift_code],
[attr1], [attr2], [attr3], [attr4], [create_by], [create_time],
[update_time], [update_by], [upload_time], [upload_status], [upload_msg], [prod_type],
[use_man], [work_center],[del_flag],[batch],[end_report],[parent_order])
VALUES
('{Common.GetUUID()}', 'SELF', '{reportCode}', '{selectRow["workorder_code"]}', '{selectRow["product_code"]}', '{selectRow["product_name"]}',
'{selectRow["product_spc"]}', '{selectRow["unit"]}', {workCount}, {workCount}, 0, 0,
'{LoginUser.UserCode}', '{LoginUser.UserName}', 'PC', '{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}', '{LoginUser.UserName}', 'PREPARE',
'无', '{workTime}', '{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}',GetDate(), '0', NULL, 'prod',
{userCount}, '{costCenter}','0','{batchCode}','{isEndReport}','{selectRow["parent_order"]}');";
sqlList.Add(mainOrderSql);
}
//赵啸林说不用上位机更新报工标识
//string updateOrderSql = $@"update pro_order_workorder set status = 'w3', update_by = '{LoginUser.UserName}',update_time = GETDATE() where workorder_id = '{selectRow["workorder_id"]}' ";
//sqlList.Add(sql);
//sqlList.Add(updateOrderSql);
bool issucc = Utils.netClientDBHelper.executeBatchSql(sqlList);
return issucc;//> 0 ? true : false;
}
public bool GetExecuteReportWorkSql(List reportWorkSqlList)
{
bool issucc = Utils.netClientDBHelper.executeBatchSql(reportWorkSqlList);
return issucc;
}
///
/// 报工
///
///
///
///
public List GetExecuteReportWorkSql(DataRowView selectRow, string orderQuntity, string workCount, string reportCode, string workTime, string userCount, string costCenter, string batchCode, string isEndReport, string deviceCode, string fatherOrderUserCount)
{
string getReportCodeSql = $@"SELECT equipment_code,equipment_name FROM [dbo].[base_equipment] WHERE equipment_code='{deviceCode}'";
string lineName = "";
DataSet dtset = Utils.netClientDBHelper.getDataSet(getReportCodeSql);
if (dtset != null && dtset.Tables.Count > 0 && dtset.Tables[0].Rows.Count > 0)
{
lineName = dtset.Tables[0].Rows[0]["equipment_name"].ToString();
}
#region 生成报工数据
//获取子工单的信息
string getSubOrderSql = $"select workorder_code,product_code,product_name,quantity_split,unit from pro_order_workorder where parent_order = '{selectRow["workorder_code"]}'";
string subOrder = "";
string subProductCode = "";
string subProductName = "";
string subQuntity = "";
string subUnit = "";
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();
subProductCode = dtSubOrder.Tables[0].Rows[0]["product_code"].ToString();
subProductName = dtSubOrder.Tables[0].Rows[0]["product_name"].ToString();
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);
List sqlList = new List();
//有子单
if (subOrder != "")
{
string mainOrderSql = $@"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],
[user_name], [nick_name], [feedback_channel], [feedback_time], [record_user], [status],
[remark], [work_time], [machine_code], [machine_name], [team_code], [shift_code],
[attr1], [attr2], [attr3], [attr4], [create_by], [create_time],
[update_time], [update_by], [upload_status], [upload_msg], [prod_type],
[use_man], [work_center],[del_flag],[batch],[end_report],[parent_order],[IP],[version])
VALUES
('{Common.GetUUID()}', 'SELF', '{reportCode}', '{selectRow["workorder_code"]}', '{selectRow["product_code"]}', '{selectRow["product_name"]}',
'{selectRow["product_spc"]}', '{selectRow["unit"]}', {selectRow["batch_quantity"]}, {workCount}, 0, 0,
'{LoginUser.UserCode}', '{LoginUser.UserName}', 'PC', '{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}', '{LoginUser.UserName}', 'PREPARE',
'无', '{workTime}', '{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',
{fatherOrderUserCount}, '{costCenter}','0','{batchCode}','{isEndReport}','{0}','{LoginUser.CurrDeviceIP}','{LoginUser.Version}');";
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],
[user_name], [nick_name], [feedback_channel], [feedback_time], [record_user], [status],
[remark], [work_time], [machine_code], [machine_name], [team_code], [shift_code],
[attr1], [attr2], [attr3], [attr4], [create_by], [create_time],
[update_time], [update_by], [upload_status], [upload_msg], [prod_type],
[use_man], [work_center],[del_flag],[batch],[end_report],[parent_order],[IP],[version])
VALUES
('{Common.GetUUID()}', 'SELF', '{reportCode}', '{subOrder}', '{subProductCode}', '{subProductName}',
'{selectRow["product_spc"]}', '{subUnit}', {selectRow["batch_quantity"]}, {subOrderQty}, 0, 0,
'{LoginUser.UserCode}', '{LoginUser.UserName}', 'PC', '{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}', '{LoginUser.UserName}', 'PREPARE',
'无', '{workTime}', '{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',
{userCount}, '{costCenter}','0','{batchCode}','{isEndReport}','{selectRow["workorder_code"]}','{LoginUser.CurrDeviceIP}','{LoginUser.Version}');";
sqlList.Add(mainOrderSql);
sqlList.Add(subOrderSql);
}
else
{
//无子单
string mainOrderSql = $@"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],
[user_name], [nick_name], [feedback_channel], [feedback_time], [record_user], [status],
[remark], [work_time], [machine_code], [machine_name], [team_code], [shift_code],
[attr1], [attr2], [attr3], [attr4], [create_by], [create_time],
[update_time], [update_by], [upload_status], [upload_msg], [prod_type],
[use_man], [work_center],[del_flag],[batch],[end_report],[parent_order],[IP],[version])
VALUES
('{Common.GetUUID()}', 'SELF', '{reportCode}', '{selectRow["workorder_code"]}', '{selectRow["product_code"]}', '{selectRow["product_name"]}',
'{selectRow["product_spc"]}', '{selectRow["unit"]}', {selectRow["batch_quantity"]}, {workCount}, 0, 0,
'{LoginUser.UserCode}', '{LoginUser.UserName}', 'PC', '{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}', '{LoginUser.UserName}', 'PREPARE',
'无', '{workTime}', '{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',
{userCount}, '{costCenter}','0','{batchCode}','{isEndReport}','{selectRow["parent_order"]}','{LoginUser.CurrDeviceIP}','{LoginUser.Version}');";
sqlList.Add(mainOrderSql);
}
#endregion
//赵啸林说不用上位机更新报工标识
//string updateOrderSql = $@"update pro_order_workorder set status = 'w3', update_by = '{LoginUser.UserName}',update_time = GETDATE() where workorder_id = '{selectRow["workorder_id"]}' ";
//sqlList.Add(sql);
//sqlList.Add(updateOrderSql);
#region 最终报工,更新工单状态为已报工
//赵啸林又说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-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);
}
}
#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);
#endregion
return sqlList;//> 0 ? true : false;
}
///
/// 新版报工
///
///
///
///
public List GetExecuteReportWorkSql(DataRowView selectRow, string orderQuntity, string workCount, string reportCode, string workTime, string userCount, string costCenter, string batchCode,
string isEndReport, string deviceCode, Dictionary workTimeDic, Dictionary userCountDic)
{
string getReportCodeSql = $@"SELECT equipment_code,equipment_name FROM [dbo].[base_equipment] WHERE equipment_code='{deviceCode}'";
string lineName = "";
DataSet dtset = Utils.netClientDBHelper.getDataSet(getReportCodeSql);
if (dtset != null && dtset.Tables.Count > 0 && dtset.Tables[0].Rows.Count > 0)
{
lineName = dtset.Tables[0].Rows[0]["equipment_name"].ToString();
}
#region 生成报工数据
//获取子工单的信息
string getSubOrderSql = $"select workorder_code,product_code,product_name,quantity_split,unit from pro_order_workorder where parent_order = '{selectRow["workorder_code"]}'";
string subOrder = "";
//string subProductCode = "";
//string subProductName = "";
//string subQuntity = "";
//string subUnit = "";
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();
//subProductCode = dtSubOrder.Tables[0].Rows[0]["product_code"].ToString();
//subProductName = dtSubOrder.Tables[0].Rows[0]["product_name"].ToString();
//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);
List sqlList = new List();
//有子单
if (subOrder != "")
{
string mainOrderSql = $@"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],
[user_name], [nick_name], [feedback_channel], [feedback_time], [record_user], [status],
[remark], [work_time], [machine_code], [machine_name], [team_code], [shift_code],
[attr1], [attr2], [attr3], [attr4], [create_by], [create_time],
[update_time], [update_by], [upload_status], [upload_msg], [prod_type],
[use_man], [work_center],[del_flag],[batch],[end_report],[parent_order],[IP],[version])
VALUES
('{Common.GetUUID()}', 'SELF', '{reportCode}', '{selectRow["workorder_code"]}', '{selectRow["product_code"]}', '{selectRow["product_name"]}',
'{selectRow["product_spc"]}', '{selectRow["unit"]}', {selectRow["batch_quantity"]}, {workCount}, 0, 0,
'{LoginUser.UserCode}', '{LoginUser.UserName}', 'PC', '{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}', '{LoginUser.UserName}', 'PREPARE',
'无', '{workTime}', '{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',
{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))
{
sqlList.Add(item);
}
//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],
// [user_name], [nick_name], [feedback_channel], [feedback_time], [record_user], [status],
// [remark], [work_time], [machine_code], [machine_name], [team_code], [shift_code],
// [attr1], [attr2], [attr3], [attr4], [create_by], [create_time],
// [update_time], [update_by], [upload_status], [upload_msg], [prod_type],
// [use_man], [work_center],[del_flag],[batch],[end_report],[parent_order],[IP],[version])
// VALUES
// ('{Common.GetUUID()}', 'SELF', '{reportCode}', '{subOrder}', '{subProductCode}', '{subProductName}',
// '{selectRow["product_spc"]}', '{subUnit}', {selectRow["batch_quantity"]}, {subOrderQty}, 0, 0,
// '{LoginUser.UserCode}', '{LoginUser.UserName}', 'PC', '{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}', '{LoginUser.UserName}', 'PREPARE',
// '无', '{workTime}', '{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',
// {userCount}, '{costCenter}','0','{batchCode}','{isEndReport}','{selectRow["workorder_code"]}','{LoginUser.CurrDeviceIP}','{LoginUser.Version}');";
sqlList.Add(mainOrderSql);
//sqlList.Add(subOrderSql);
}
else
{
//无子单
string mainOrderSql = $@"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],
[user_name], [nick_name], [feedback_channel], [feedback_time], [record_user], [status],
[remark], [work_time], [machine_code], [machine_name], [team_code], [shift_code],
[attr1], [attr2], [attr3], [attr4], [create_by], [create_time],
[update_time], [update_by], [upload_status], [upload_msg], [prod_type],
[use_man], [work_center],[del_flag],[batch],[end_report],[parent_order],[IP],[version])
VALUES
('{Common.GetUUID()}', 'SELF', '{reportCode}', '{selectRow["workorder_code"]}', '{selectRow["product_code"]}', '{selectRow["product_name"]}',
'{selectRow["product_spc"]}', '{selectRow["unit"]}', {selectRow["batch_quantity"]}, {workCount}, 0, 0,
'{LoginUser.UserCode}', '{LoginUser.UserName}', 'PC', '{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}', '{LoginUser.UserName}', 'PREPARE',
'无', '{workTime}', '{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',
{userCount}, '{costCenter}','0','{batchCode}','{isEndReport}','{selectRow["parent_order"]}','{LoginUser.CurrDeviceIP}','{LoginUser.Version}');";
sqlList.Add(mainOrderSql);
}
#endregion
//赵啸林说不用上位机更新报工标识
//string updateOrderSql = $@"update pro_order_workorder set status = 'w3', update_by = '{LoginUser.UserName}',update_time = GETDATE() where workorder_id = '{selectRow["workorder_id"]}' ";
//sqlList.Add(sql);
//sqlList.Add(updateOrderSql);
#region 最终报工,更新工单状态为已报工
//赵啸林又说sap有问题,需要上位机修改报工标识2023-12-25,但仅在最终报工时,才更新此状态
if (isEndReport.Equals("1"))
{
//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
//递归更新子单领料状态
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 批次报工状态更新
//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
return sqlList;//> 0 ? true : false;
}
List workReports = new List();
List updatePrepareSqlList = new List();
///
/// 递归获取子单报工SQL
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
public List GetAllWorkReportsForOrderAndChildren(string orderId, DataRowView selectRow, string orderQuntity, string reportCode, string costCenter, string batchCode,
string isEndReport, string deviceCode, string lineName, string workCount, Dictionary workTimeDic, Dictionary 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 = "";
string subProductCode = "";
string subProductName = "";
string subQuntity = "";
string subUnit = "";
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();
subProductCode = dtSubOrder.Tables[0].Rows[0]["product_code"].ToString();
subProductName = dtSubOrder.Tables[0].Rows[0]["product_name"].ToString();
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 = 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],
[user_name], [nick_name], [feedback_channel], [feedback_time], [record_user], [status],
[remark], [work_time], [machine_code], [machine_name], [team_code], [shift_code],
[attr1], [attr2], [attr3], [attr4], [create_by], [create_time],
[update_time], [update_by], [upload_status], [upload_msg], [prod_type],
[use_man], [work_center],[del_flag],[batch],[end_report],[parent_order],[IP],[version])
VALUES
('{Common.GetUUID()}', 'SELF', '{reportCode}', '{subOrder}', '{subProductCode}', '{subProductName}',
'{selectRow["product_spc"]}', '{subUnit}', {selectRow["batch_quantity"]}, {subOrderQty}, 0, 0,
'{LoginUser.UserCode}', '{LoginUser.UserName}', 'PC', '{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}', '{LoginUser.UserName}', 'PREPARE',
'无', '{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}','{orderId}','{LoginUser.CurrDeviceIP}','{LoginUser.Version}');";
workReports.Add(subOrderSql);
sortNo++;
GetAllWorkReportsForOrderAndChildren(subOrder, selectRow, orderQuntity, reportCode, costCenter, batchCode, isEndReport, deviceCode, lineName, subQuntity, workTimeDic, userCountDic, sortNo);
}
return workReports;
}
public List 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)
{
//
string sql = $@"INSERT INTO [dbo].[mes_changeshift_info] ([id], [shift_code], [change_time], [create_time], [create_by], [last_update], [update_by], [work_date],[device_code])
VALUES ('{Common.GetUUID()}', '{LoginUser.ShiftCode}', GetDate(), GetDate(), '{LoginUser.UserName}', GetDate(), '{LoginUser.UserName}', '{LoginUser.WorkDate}','{deviceCode}');";
int ret = Utils.netClientDBHelper.executeUpdate(sql);
return ret > 0 ? true : false;
}
///
/// 插入消耗表
///
///
///
///
///
///
public bool InsertConsumeInfo(string qty, string remark, DataRowView selectedRow, string newReportCode, string siteCode, string recoil, string parentOrder)
{
string sql = $@" INSERT INTO [dbo].[mes_report_work_consume]
([record_id], [workorder_code], [material_code], [material_name], [material_spc],
[quantity], [unit], [remark], [attr1], [attr2],
[attr3], [attr4], [create_by], [create_time], [update_by],
[update_time], [factory_code], [report_code], [del_flag],[parent_order],[recoil])
VALUES
('{Common.GetUUID()}', '{selectedRow["workorder_code"]}', '{selectedRow["product_code"]}', '{selectedRow["product_name"]}', '{selectedRow["product_spc"]}',
'{qty}','{selectedRow["unit"]}', '{remark}', NULL, NULL,
NULL, NULL, '{LoginUser.UserName}', GetDate(), '{LoginUser.UserName}',
GetDate(), '{siteCode}', '{newReportCode}', '0','{parentOrder}','{recoil}'); ";
int ret = Utils.netClientDBHelper.executeUpdate(sql);
return ret > 0 ? true : false;
}
public bool UpdateFirstCheckTask(string workorderID, string batchCode)
{
string sql = $@"update pro_order_workorder_batch set qc_status = '1', update_by = '{LoginUser.UserName}',update_time = GETDATE() where workorder_id = '{workorderID}' and batch_code = '{batchCode}'";
int ret = Utils.netClientDBHelper.executeUpdate(sql);
return ret > 0 ? true : false;
}
public bool InsertConsumeInfo(DataRowView selectedConsumeRow, string newReportCode, string siteCode)
{
string sql = $@" INSERT INTO [dbo].[mes_report_work_consume]
([record_id], [workorder_code], [material_code], [material_name], [material_spc],
[quantity], [unit], [remark], [attr1], [attr2],
[attr3], [attr4], [create_by], [create_time], [update_by],
[update_time], [factory_code], [report_code], [del_flag],[parent_order],[recoil])
VALUES
('{Common.GetUUID()}', '{selectedConsumeRow["workorder_code"]}', '{selectedConsumeRow["material_code"]}', '{selectedConsumeRow["material_name"]}', '{selectedConsumeRow["material_spc"]}',
'{selectedConsumeRow["qty"]}','{selectedConsumeRow["unit"]}', '{selectedConsumeRow["remark"]}', NULL, NULL,
NULL, NULL, '{LoginUser.UserName}', GetDate(), '{LoginUser.UserName}',
GetDate(), '{siteCode}', '{newReportCode}', '0','{selectedConsumeRow["parent_work_order"]}','{selectedConsumeRow["recoil"]}'); ";
int ret = Utils.netClientDBHelper.executeUpdate(sql);
return ret > 0 ? true : false;
}
public string GetInsertConsumeInfoSql(DataRowView selectedConsumeRow, string newReportCode, string siteCode)
{
string sql = $@" INSERT INTO [dbo].[mes_report_work_consume]
([record_id], [workorder_code], [material_code], [material_name], [material_spc],
[quantity], [unit], [remark], [attr1], [attr2],
[attr3], [attr4], [create_by], [create_time], [update_by],
[update_time], [factory_code], [report_code], [del_flag],[parent_order],[recoil],[IP],[version])
VALUES
('{Common.GetUUID()}', '{selectedConsumeRow["workorder_code"]}', '{selectedConsumeRow["material_code"]}', '{selectedConsumeRow["material_name"]}', '{selectedConsumeRow["material_spc"]}',
'{selectedConsumeRow["qty"]}','{selectedConsumeRow["unit"]}', '{selectedConsumeRow["remark"]}', NULL, NULL,
NULL, NULL, '{LoginUser.UserName}', GetDate(), '{LoginUser.UserName}',
GetDate(), '{siteCode}', '{newReportCode}', '0','{selectedConsumeRow["parent_work_order"]}','{selectedConsumeRow["recoil"]}','{LoginUser.CurrDeviceIP}','{LoginUser.Version}'); ";
//int ret = Utils.netClientDBHelper.executeUpdate(sql);
return sql;
}
///
/// 获取母单的包工人数
///
///
///
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";
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 Getorderworkorder(string orderCode)
{
string sql = $@"select * from pro_order_workorder WHERE workorder_code='{orderCode}' AND del_flag='0'";
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 GetWorkShop(string eqment)
{
string sql = $@"select * from base_equipment WHERE equipment_code='{eqment}' AND del_flag='0'";
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 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)
{
//获取子工单的信息
string getSubOrderSql = $"select workorder_code,product_code,product_name,quantity_split,unit from pro_order_workorder where parent_order = '{orderCode}'";
DataSet dtSubOrder = Utils.netClientDBHelper.getDataSet(getSubOrderSql);
if (dtSubOrder != null && dtSubOrder.Tables.Count > 0 && dtSubOrder.Tables[0].Rows.Count > 0)
{
return dtSubOrder.Tables[0];
}
return null;
}
///
/// 根据设备编码获取当前机台最新的吊满的RFID信息
///
///
///
public DataTable GetRfidInfo(string deviceCode)
{
string sql = $@"select top 2 rfid.workorder_code, rfid, machine_code,order_num, rfid.create_time, rfid.update_by, rfid.update_time, work_batch_code, bind_status ,workorder.product_code
from pro_rfid_process_detail rfid
LEFT JOIN pro_order_workorder workorder on rfid.workorder_code = workorder.workorder_code
where machine_code = 'X1' and bind_status = '0' order by update_time DESC";
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 ConvertToFaultModelList()
{
string getReportCodeSql = "SELECT fault_code, fault_subclass FROM equ_fault_description";
DataSet dtset = Utils.netClientDBHelper.getDataSet(getReportCodeSql);
if (dtset != null && dtset.Tables.Count > 0 && dtset.Tables[0].Rows.Count > 0)
{
return dtset.Tables[0];
}
return null;
}
public DataTable GetNewRFID()
{
string sql = $@"select max(rfid) as rfid from mes_rfidandsfc_bind where CONVERT(VARCHAR(10), create_time , 120) = CONVERT(VARCHAR(10),Getdate(), 120)";
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 GetReportCode()
{
string getReportCodeSql = $@"select max(report_code) as report_code from mes_report_work where CONVERT(VARCHAR(10), create_time , 120) = CONVERT(VARCHAR(10),Getdate(), 120)";
DataSet dtset = Utils.netClientDBHelper.getDataSet(getReportCodeSql);
if (dtset != null && dtset.Tables.Count > 0 && dtset.Tables[0].Rows.Count > 0)
{
return dtset.Tables[0];
}
return null;
}
public string GetInterfaceUrl(string v)
{
string getReportCodeSql = $@"SELECT url FROM [dbo].[mes_interface_url] where url_type = '{v}' and del_flag = '0'";
DataSet dtset = Utils.netClientDBHelper.getDataSet(getReportCodeSql);
if (dtset != null && dtset.Tables.Count > 0 && dtset.Tables[0].Rows.Count > 0)
{
return dtset.Tables[0].Rows[0][0].ToString();
}
return "";
}
}
}