You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

670 lines
38 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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 XGL.Models.Model.FoamingMac;
namespace XGL.Data.DBService
{
public class FormingMachineService
{
/// <summary>
/// 获取成型机在产物料信息
/// </summary>
/// <param name="bdt"></param>
/// <param name="edt"></param>
/// <returns></returns>
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}%' ";
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 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(totalcountSql);
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;
}
/// <summary>
/// 获取成型机状态
/// </summary>
/// <param name="bdt"></param>
/// <param name="edt"></param>
/// <returns></returns>
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;
}
/// <summary>
/// 获取成型机状态
/// </summary>
/// <param name="bdt"></param>
/// <param name="edt"></param>
/// <returns></returns>
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;
}
/// <summary>
/// 查询出入记录
/// </summary>
/// <param name="bdt"></param>
/// <param name="edt"></param>
/// <returns></returns>
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;
}
/// <summary>
/// 查询完成记录
/// </summary>
/// <param name="bdt"></param>
/// <param name="edt"></param>
/// <returns></returns>
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;
}
/// <summary>
/// 获取工单当前状态,弃用
/// </summary>
/// <param name="bdt"></param>
/// <param name="edt"></param>
/// <returns></returns>
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;
}
/// <summary>
/// 更新工单状态
/// </summary>
/// <param name="bdt"></param>
/// <param name="edt"></param>
/// <returns></returns>
public bool UpdateWorkOrder(string orderCode,string status,string remark,string type,string deviceCode)
{
List<string> sqlList = new List<string>();
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(),
'工单状态更新-暂停', 'w2', '{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(),
'工单状态更新-恢复', 'w4', '{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 ;
}
/// <summary>
/// 更新工单
/// </summary>
/// <param name="bdt"></param>
/// <param name="edt"></param>
/// <returns></returns>
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;
}
/// <summary>
/// 报工
/// </summary>
/// <param name="bdt"></param>
/// <param name="edt"></param>
/// <returns></returns>
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<string> sqlList = new List<string>();
//有子单
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<string> reportWorkSqlList)
{
bool issucc = Utils.netClientDBHelper.executeBatchSql(reportWorkSqlList);
return issucc;
}
/// <summary>
/// 报工
/// </summary>
/// <param name="bdt"></param>
/// <param name="edt"></param>
/// <returns></returns>
public List<string> GetExecuteReportWorkSql(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<string> sqlList = new List<string>();
//有子单
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],[IP],[version])
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}','{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_time], [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}', {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"]}','{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_time], [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"]}', {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"]}','{LoginUser.CurrDeviceIP}','{LoginUser.Version}');";
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);
//赵啸林又说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);
}
//添加批次报工状态更新--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);
return sqlList;//> 0 ? true : false;
}
public bool ChangeShiftsInfo()
{
//
string sql = $@"INSERT INTO [dbo].[mes_changeshift_info] ([id], [shift_code], [change_time], [create_time], [create_by], [last_update], [update_by], [work_date])
VALUES ('{Common.GetUUID()}', '{LoginUser.ShiftCode}', GetDate(), GetDate(), '{LoginUser.UserName}', GetDate(), '{LoginUser.UserName}', '{LoginUser.WorkDate}');";
int ret = Utils.netClientDBHelper.executeUpdate(sql);
return ret > 0 ? true : false;
}
/// <summary>
/// 插入消耗表
/// </summary>
/// <param name="qty"></param>
/// <param name="remark"></param>
/// <param name="selectedRow"></param>
/// <param name="newReportCode"></param>
/// <param name="siteCode"></param>
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;
}
/// <summary>
/// 根据设备编码获取当前机台最新的吊满的RFID信息
/// </summary>
/// <param name="deviceCode"></param>
/// <returns></returns>
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 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 "";
}
}
}