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.

1871 lines
106 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.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using XGL.Models;
using XGL.Models.Model.FoamingMac;
using static Snap7.S7Client;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
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,
ord.start_work_time,
ord.end_work_time,
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 + " 0:00:00"}', 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 string GetShiftById(string shiftCode)
{
string sql = $@"select shift_desc from base_shifts_t where del_flag ='0' and Shift_Id = '{shiftCode}'";
var obj = Utils.netClientDBHelper.getScalar(sql, null);
string issucc = obj == null ? "" : obj.ToString();
return issucc;
}
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>
/// 获取接口URL
/// </summary>
/// <param name="bdt"></param>
/// <param name="edt"></param>
/// <returns></returns>
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;
}
/// <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(),
'工单状态更新-恢复', '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}');";
}
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],
[reason], [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],
[reason], [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],
[reason], [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 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<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],
[reason], [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],
[reason], [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],
[reason], [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;
}
/// <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, Dictionary<int, string> workTimeDic, Dictionary<int, string> userCountDic, string xiaolv, string shijian)
{
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 生成报工数据
//获取子工单的信息
#region 订单不能是已经被删除的
string getSubOrderSql = $"select workorder_code,product_code,product_name,quantity_split,unit from pro_order_workorder where parent_order = '{selectRow["workorder_code"]}' and del_flag=0";
#endregion
//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],
[reason], [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"]}',
'{xiaolv}', '{shijian}', 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],
[reason], [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"))
{
LogHelper.instance.log.Info("最终报工706行workorder_code值为>>>" + selectRow["workorder_code"].ToString());
LogHelper.instance.log.Info("最终报工707行product_code值为>>>" + selectRow["product_code"].ToString());
Getorderworkordermaterial(selectRow["workorder_code"].ToString(), selectRow["product_code"].ToString());
//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() ,end_work_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<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)
{
//获取子工单的信息
#region 子单不能是已经被删除的
string getSubOrderSql = $"select workorder_code,product_code,product_name,quantity_split,unit from pro_order_workorder where parent_order = '{orderId}' and del_flag=0";
#endregion
//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);//workCount是报工数量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],
[reason], [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<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)
{
//
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}',Null, '{LoginUser.UserName}', '{LoginUser.WorkDate}','{deviceCode}');";
int ret = Utils.netClientDBHelper.executeUpdate(sql);
return ret > 0 ? true : false;
}
public bool ChangeShiftsInfo(string deviceCode, string data, string shift)
{
//
string sql = $@"UPDATE mes_changeshift_info SET last_update=GetDate( ) WHERE device_code='{deviceCode}' AND CONVERT(VARCHAR, create_time, 23) = '{data}' AND shift_code='{shift}';";
int ret = Utils.netClientDBHelper.executeUpdate(sql);
return ret > 0 ? true : false;
}
public DataTable selectShiftsInfo(string deviceCode, string data, string shift)
{
//
string sql = $@"
SELECT top 1 * FROM mes_changeshift_info WHERE device_code='{deviceCode}' AND work_date = '{data}' AND last_update is NULL AND shift_code='{shift}' ORDER BY create_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="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],[rspos],[wastage])
// 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}','{selectedConsumeRow["attr1"]}', '{selectedConsumeRow["wastage"]}'); ";
// //int ret = Utils.netClientDBHelper.executeUpdate(sql);
// return sql;
//}
public string GetMergeConsumeInfoSql(DataRowView selectedConsumeRow, string newReportCode, string siteCode)
{
string sql = $@"
MERGE [dbo].[mes_report_work_consume] AS target
USING (SELECT
'{selectedConsumeRow["workorder_code"]}' AS workorder_code,
'{selectedConsumeRow["material_code"]}' AS material_code
) AS source
ON target.workorder_code = source.workorder_code
AND target.material_code = source.material_code
WHEN MATCHED THEN
UPDATE SET
material_name = '{selectedConsumeRow["material_name"]}',
material_spc = '{selectedConsumeRow["material_spc"]}',
quantity = '{selectedConsumeRow["qty"]}',
unit = '{selectedConsumeRow["unit"]}',
remark = '{selectedConsumeRow["remark"]}',
update_by = '{LoginUser.UserName}',
update_time = GETDATE(),
factory_code = '{siteCode}',
report_code = '{newReportCode}',
del_flag = '0',
parent_order = '{selectedConsumeRow["parent_work_order"]}',
recoil = '{selectedConsumeRow["recoil"]}',
IP = '{LoginUser.CurrDeviceIP}',
version = '{LoginUser.Version}',
rspos = '{selectedConsumeRow["attr1"]}',
wastage = '{selectedConsumeRow["wastage"]}'
WHEN NOT MATCHED THEN
INSERT ([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], [rspos], [wastage])
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}', '{selectedConsumeRow["attr1"]}', '{selectedConsumeRow["wastage"]}');
";
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";
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="orderCode"></param>
/// <returns></returns>
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;
}
/// <summary>
/// 处理重复物料2024-06-13陈恒杰说的
/// </summary>
/// <param name="orderCode"></param>
/// <returns></returns>
public bool Getorderworkordermaterial(string workorderCode, string materialCode)
{
string sql = $@"UPDATE mes_report_work_consume SET rspos = ( SELECT attr1 FROM mes_prepare_detail WHERE material_code = '{materialCode}' AND parent_work_order = '{workorderCode}' ) WHERE
material_code = '{materialCode}'
AND workorder_code = '{workorderCode}';";
DataSet dtset = Utils.netClientDBHelper.getDataSet(sql);
int ret = Utils.netClientDBHelper.executeUpdate(sql);
return ret > 0 ? true : false;
}
/// <summary>
/// 获取所在车间
/// </summary>
/// <param name="orderCode"></param>
/// <returns></returns>
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;
}
/// <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)
{
//获取子工单的信息
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;
}
/// <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;
}
/// <summary>
/// 获取报修描述
/// </summary>
/// <returns></returns>
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 DataTable GetReportCodeeqment(string eqment)
{
string getReportCodeSql = $@"select * from equ_bind_auxiliary_equipment where equipment_code ='{eqment}'";
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 "";
}
public List<report> GetReportData(string nickName)
{
List<report> reportList = new List<report>();
try
{
//查找前六条信息
string sql = @"select top 6 Id,team,OpenLineCheckBox,ReplaceLineCheckBox,unqualified,clear,residue,lineClear,UserKnow,qualified,equipStatus,StampCorrect,isClear,positionCorrect,isLineClear,create_time CreateTime
from [dbo].[mes_report] where user_nick_name = '" + nickName + "' order by create_time desc";
DataSet dtset = Utils.netClientDBHelper.getDataSet(sql);
if (dtset != null && dtset.Tables.Count > 0 && dtset.Tables[0].Rows.Count > 0)
{
foreach (DataRow dr in dtset.Tables[0].Rows)
{
report r = new report();
r.Id = dr["Id"].ToString();
r.unqualified = dr["unqualified"].ToString();
r.clear = dr["clear"].ToString();
r.residue = dr["residue"].ToString();
r.lineClear = dr["lineClear"].ToString();
r.UserKnow = dr["UserKnow"].ToString();
r.qualified = dr["qualified"].ToString();
r.equipStatus = dr["equipStatus"].ToString();
r.StampCorrect = dr["StampCorrect"].ToString();
r.isClear = dr["isClear"].ToString();
r.positionCorrect = dr["positionCorrect"].ToString();
r.isLineClear = dr["isLineClear"].ToString();
r.OpenLineCheckBox = dr["OpenLineCheckBox"].ToString();
r.ReplaceLineCheckBox = dr["ReplaceLineCheckBox"].ToString();
r.team = dr["team"].ToString();
reportList.Add(r);
}
}
}
catch
{
}
for (int i = reportList.Count; i < 6; i++)
{
reportList.Add(new report());
}
return reportList;
}
public int uporderstarttime(string id)
{
string sql = $@"update [dbo].[pro_order_workorder] set start_work_time='{DateTime.Now}' where workorder_id='{id}'";
return Utils.netClientDBHelper.executeUpdate(sql);
}
public int uporderendtime(string id)
{
string sql = $@"update [dbo].[pro_order_workorder] set end_work_time='{DateTime.Now}' where workorder_id='{id}'";
return Utils.netClientDBHelper.executeUpdate(sql);
}
public int EditReport(report report)
{
string sql = $@"update [dbo].[mes_report] set team='{report.team}',OpenLineCheckBox='{report.OpenLineCheckBox}',ReplaceLineCheckBox='{report.ReplaceLineCheckBox}',unqualified='{report.unqualified}',clear='{report.clear}',residue='{report.residue}',lineClear='{report.lineClear}',UserKnow='{report.UserKnow}',qualified='{report.qualified}',equipStatus='{report.equipStatus}',StampCorrect='{report.StampCorrect}',isClear='{report.isClear}',positionCorrect='{report.positionCorrect}',isLineClear='{report.isLineClear}' where Id='{report.Id}'";
return Utils.netClientDBHelper.executeUpdate(sql);
}
public int AddReport(report report)
{
string sql = $@"insert into [dbo].[mes_report] (Id,user_nick_name,team,OpenLineCheckBox,ReplaceLineCheckBox,unqualified,clear,residue,lineClear,UserKnow,qualified,equipStatus,StampCorrect,isClear,positionCorrect,isLineClear,create_time) values ('{report.Id}','{report.NickName}','{report.team}','{report.OpenLineCheckBox}','{report.ReplaceLineCheckBox}','{report.unqualified}','{report.clear}','{report.residue}','{report.lineClear}','{report.UserKnow}','{report.qualified}','{report.equipStatus}','{report.StampCorrect}','{report.isClear}','{report.positionCorrect}','{report.isLineClear}',GETDATE())";
return Utils.netClientDBHelper.executeUpdate(sql);
}
public bool GetProOrderWorkOrder(string workorderId)
{
string sql = "select del_flag from pro_order_workorder where workorder_id = '" + workorderId + "'";
DataSet dtset = Utils.netClientDBHelper.getDataSet(sql);
if (dtset != null && dtset.Tables.Count > 0 && dtset.Tables[0].Rows.Count > 0)
{
object value = dtset.Tables[0].Rows[0]["del_flag"];
if (value != null && value.ToString() == "0")
{
return true;
}
}
return false;
}
public DataTable GetProOrderWorkorder(string deviceCode, string workDate)
{
string date = DateTime.Parse(workDate).ToString("yyyy-MM-dd");
string sql = $@"select workorder_id,product_name,product_code
from pro_order_workorder
where prod_line_code like '%{deviceCode}%' and product_date='{date}' and status='w2' and del_flag='0' and parent_order='0' order by parent_order";
//string sql = $@"select workorder_id,product_name
// from pro_order_workorder
// where prod_line_code like '%{deviceCode}% and status='w2''";
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 GetProOrderWorkorder(string id)
{
string sql = $@"select workorder_id,product_name,product_code
from pro_order_workorder
where workorder_id='{id}'";
//string sql = $@"select workorder_id,product_name
// from pro_order_workorder
// where prod_line_code like '%{deviceCode}% and status='w2''";
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 List<SelfInspectionModel> GetSelfInspections(string deviceCode, string workDate, string nickName, string workOrderId)
{
List<SelfInspectionModel> selfInspectionList = new List<SelfInspectionModel>();
try
{
string sql = $@"select top 7
Id,Other,Inspector,Reason,deviceCode,workDate,
InspectionTime,MissingTie,Package,DateCode,PackageGood,LeakProduct,NormalOpen,BoxQuantity
from mes_self_inspection
where deviceCode='{deviceCode}' and workDate='{workDate}' and Inspector='{nickName}' and workorder_id ='{workOrderId}' order by CreateTime desc";
DataSet dtset = Utils.netClientDBHelper.getDataSet(sql);
if (dtset != null && dtset.Tables.Count > 0 && dtset.Tables[0].Rows.Count > 0)
{
foreach (DataRow dr in dtset.Tables[0].Rows)
{
selfInspectionList.Add(new SelfInspectionModel()
{
Id = dr["Id"].ToString(),
Other = dr["Other"].ToString(),
Inspector = dr["Inspector"].ToString(),
Reason = dr["Reason"].ToString(),
deviceCode = dr["deviceCode"].ToString(),
workDate = dr["workDate"].ToString(),
InspectionTime = dr["InspectionTime"].ToString(),
MissingTie = dr["MissingTie"].ToString(),
Package = dr["Package"].ToString(),
DateCode = dr["DateCode"].ToString(),
PackageGood = dr["PackageGood"].ToString(),
LeakProduct = dr["LeakProduct"].ToString(),
NormalOpen = dr["NormalOpen"].ToString(),
BoxQuantity = dr["BoxQuantity"].ToString()
});
}
}
}
catch
{
}
while (selfInspectionList.Count < 7)
{
selfInspectionList.Add(new SelfInspectionModel());
}
return selfInspectionList;
}
public int AddSelfInspection(SelfInspectionModel selfInspection)
{
string sql = $@"insert into [dbo].[mes_self_inspection] (Id,Other,Inspector,Reason,deviceCode,workDate,InspectionTime,MissingTie,Package,DateCode,PackageGood,LeakProduct,NormalOpen,BoxQuantity,workorder_id,CreateTime) values ('{selfInspection.Id}','{selfInspection.Other}','{selfInspection.Inspector}','{selfInspection.Reason}','{selfInspection.deviceCode}','{selfInspection.workDate}','{selfInspection.InspectionTime}','{selfInspection.MissingTie}','{selfInspection.Package}','{selfInspection.DateCode}','{selfInspection.PackageGood}','{selfInspection.LeakProduct}','{selfInspection.NormalOpen}','{selfInspection.BoxQuantity}','{selfInspection.workOrderId}',GETDATE())";
return Utils.netClientDBHelper.executeUpdate(sql);
}
public int EditSelfInspection(SelfInspectionModel selfInspection)
{
string sql = $@"update [dbo].[mes_self_inspection] set Other='{selfInspection.Other}',Inspector='{selfInspection.Inspector}',Reason='{selfInspection.Reason}',InspectionTime='{selfInspection.InspectionTime}',MissingTie='{selfInspection.MissingTie}',Package='{selfInspection.Package}',DateCode='{selfInspection.DateCode}',PackageGood='{selfInspection.PackageGood}',LeakProduct='{selfInspection.LeakProduct}',NormalOpen='{selfInspection.NormalOpen}',BoxQuantity='{selfInspection.BoxQuantity}' where Id='{selfInspection.Id}'";
return Utils.netClientDBHelper.executeUpdate(sql);
}
public List<FirstInspectionReportModel> GetFirstInspectionReportModels(string userName, string workDate)
{
string sql = $@"select top 5
Id,CheckTimeLeft,InspectionTime,CheckTimeRight,MaterialLeft,MaterialRight,AppearanceLeft,AppearanceRight,StampLeft,StampRight
SprayLeft,SprayRight,PackageLeft,PackageRight,GenerateLeft,GenerateRight,DeviceLeft,DeviceRight,WorkLeft,WorkRight,OtherLeft,OtherRight,
OverLeft,OverRight,CreateTime,UserName,WorkDateLeft,WorkDateRight from mes_first_inspection_report where UserName='{userName}' and WorkDateLeft='{workDate}' order by CreateTime desc";
List<FirstInspectionReportModel> firstInspectionReportList = new List<FirstInspectionReportModel>();
try
{
DataSet dtset = Utils.netClientDBHelper.getDataSet(sql);
if (dtset != null && dtset.Tables.Count > 0 && dtset.Tables[0].Rows.Count > 0)
{
foreach (DataRow dr in dtset.Tables[0].Rows)
{
firstInspectionReportList.Add(new FirstInspectionReportModel()
{
Id = dr["Id"].ToString(),
CheckTimeLeft = dr["CheckTimeLeft"].ToString(),
InspectionTime = dr["InspectionTime"].ToString(),
CheckTimeRight = dr["CheckTimeRight"].ToString(),
MaterialLeft = dr["MaterialLeft"].ToString(),
MaterialRight = dr["MaterialRight"].ToString(),
AppearanceLeft = dr["AppearanceLeft"].ToString(),
AppearanceRight = dr["AppearanceRight"].ToString(),
StampLeft = dr["StampLeft"].ToString(),
StampRight = dr["StampRight"].ToString(),
SprayLeft = dr["SprayLeft"].ToString(),
SprayRight = dr["SprayRight"].ToString(),
PackageLeft = dr["PackageLeft"].ToString(),
PackageRight = dr["PackageRight"].ToString(),
GenerateLeft = dr["GenerateLeft"].ToString(),
GenerateRight = dr["GenerateRight"].ToString(),
DeviceLeft = dr["DeviceLeft"].ToString(),
DeviceRight = dr["DeviceRight"].ToString(),
WorkLeft = dr["WorkLeft"].ToString(),
WorkRight = dr["WorkRight"].ToString(),
OtherLeft = dr["OtherLeft"].ToString(),
OtherRight = dr["OtherRight"].ToString(),
OverLeft = dr["OverLeft"].ToString(),
OverRight = dr["OverRight"].ToString(),
UserName = dr["UserName"].ToString(),
WorkDateLeft = dr["WorkDate"].ToString(),
WorkDateRight = dr["WorkDate"].ToString(),
});
}
}
}
catch
{
}
while (firstInspectionReportList.Count < 5)
{
firstInspectionReportList.Add(new FirstInspectionReportModel());
}
return firstInspectionReportList;
}
public void AddFirstInspectionReportModel(FirstInspectionReportModel item)
{
string sql = $@"insert into [dbo].[mes_first_inspection_report] (Id,CheckTimeLeft,InspectionTime,CheckTimeRight,MaterialLeft,MaterialRight,AppearanceLeft,AppearanceRight,StampLeft,StampRight,SprayLeft,SprayRight,PackageLeft,PackageRight,GenerateLeft,GenerateRight,DeviceLeft,DeviceRight,WorkLeft,WorkRight,OtherLeft,OtherRight,OverLeft,OverRight,CreateTime,UserName,WorkDateLeft,WorkDateRight) values ('{item.Id}','{item.CheckTimeLeft}','{item.InspectionTime}','{item.CheckTimeRight}','{item.MaterialLeft}','{item.MaterialRight}','{item.AppearanceLeft}','{item.AppearanceRight}','{item.StampLeft}','{item.StampRight}','{item.SprayLeft}','{item.SprayRight}','{item.PackageLeft}','{item.PackageRight}','{item.GenerateLeft}','{item.GenerateRight}','{item.DeviceLeft}','{item.DeviceRight}','{item.WorkLeft}','{item.WorkRight}','{item.OtherLeft}','{item.OtherRight}','{item.OverLeft}','{item.OverRight}',GETDATE(),'{item.UserName}','{item.WorkDateLeft}','{item.WorkDateRight}')";
Utils.netClientDBHelper.executeUpdate(sql);
}
public void UpdateFirstInspectionReportModel(FirstInspectionReportModel item)
{
string sql = $@"update [dbo].[mes_first_inspection_report] set CheckTimeLeft='{item.CheckTimeLeft}',InspectionTime='{item.InspectionTime}',CheckTimeRight='{item.CheckTimeRight}',MaterialLeft='{item.MaterialLeft}',MaterialRight='{item.MaterialRight}',AppearanceLeft='{item.AppearanceLeft}',AppearanceRight='{item.AppearanceRight}',StampLeft='{item.StampLeft}',StampRight='{item.StampRight}',SprayLeft='{item.SprayLeft}',SprayRight='{item.SprayRight}',PackageLeft='{item.PackageLeft}',PackageRight='{item.PackageRight}',GenerateLeft='{item.GenerateLeft}',GenerateRight='{item.GenerateRight}',DeviceLeft='{item.DeviceLeft}',DeviceRight='{item.DeviceRight}',WorkLeft='{item.WorkLeft}',WorkRight='{item.WorkRight}',OtherLeft='{item.OtherLeft}',OtherRight='{item.OtherRight}',OverLeft='{item.OverLeft}',OverRight='{item.OverRight}' where Id='{item.Id}'";
Utils.netClientDBHelper.executeUpdate(sql);
}
public string GetBaseEquipment(string v)
{
string sql = $@"select equipment_code,equipment_name from base_equipment where equipment_code='{v}'";
DataSet dtset = Utils.netClientDBHelper.getDataSet(sql);
if (dtset != null && dtset.Tables.Count > 0 && dtset.Tables[0].Rows.Count > 0)
{
return dtset.Tables[0].Rows[0]["equipment_name"].ToString();
}
return "";
}
public List<BaseDictData> GetConversionReportType()
{
List<BaseDictData> list = new List<BaseDictData>();
string sql = $@"select dict_code, dict_sort, dict_label, dict_value, dict_type, css_class, list_class, is_default, status, create_by, create_time, remark
from base_dict_data
where dict_type = 'self_mutual_inspection'
order by dict_sort asc";
DataSet ds = Utils.netClientDBHelper.getDataSet(sql);
if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
{
foreach (DataRow dr in ds.Tables[0].Rows)
{
list.Add(new BaseDictData()
{
dict_code = dr["dict_code"].ToString(),
dict_sort = dr["dict_sort"].ToString(),
dict_label = dr["dict_label"].ToString(),
dict_value = dr["dict_value"].ToString(),
dict_type = dr["dict_type"].ToString(),
});
}
}
return list;
}
public List<BaseDictData> GetSelfCheckInfo(string dicType)
{
List<BaseDictData> list = new List<BaseDictData>();
string sql = $@"select dict_code, dict_sort, dict_label, dict_value, dict_type, css_class, list_class, is_default, status, create_by, create_time, remark
from base_dict_data
where dict_type = '{dicType}'
order by dict_sort asc";
DataSet ds = Utils.netClientDBHelper.getDataSet(sql);
if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
{
foreach (DataRow dr in ds.Tables[0].Rows)
{
list.Add(new BaseDictData()
{
dict_code = dr["dict_code"].ToString(),
dict_sort = dr["dict_sort"].ToString(),
dict_label = dr["dict_label"].ToString(),
dict_value = dr["dict_value"].ToString(),
dict_type = dr["dict_type"].ToString(),
remark = dr["remark"].ToString()
});
}
}
return list;
}
public int InsertMesTableSelf(MesTableSelf model)
{
string sql = $@"insert into [dbo].[mes_table_self] (id,report_name,line_code,product_date,product_code,product_name,check_date,remark,bz,create_by,create_time,update_by,update_time,factory_code,del_flag) values ('{model.id}','{model.report_name}','{model.line_code}','{model.product_date}','{model.product_code}','{model.product_name}','{model.check_date}','{model.remark}','{model.bz}','{LoginUser.UserName}',GetDate(),'{model.update_by}',GetDate(),'{model.factory_code}','{model.del_flag}')";
return Utils.netClientDBHelper.executeUpdate(sql);
}
public MesTableSelf GetMesTableSelf(string lineCode, string productCode, string checkDate, string reprot_name)
{
string sql = $@"select * from [dbo].[mes_table_self] where line_code='{lineCode}' and check_date='{checkDate}' and report_name='{reprot_name}'";
if (!string.IsNullOrEmpty(productCode))
{
sql += $@" and product_name='{productCode}'";
}
DataSet ds = Utils.netClientDBHelper.getDataSet(sql);
if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
{
DataRow dr = ds.Tables[0].Rows[0];
MesTableSelf mesTableSelf = new MesTableSelf()
{
id = dr["id"].ToString(),
line_code = dr["line_code"].ToString(),
product_date = dr["product_date"].ToString(),
product_code = dr["product_code"].ToString(),
product_name = dr["product_name"].ToString(),
check_date = dr["check_date"].ToString(),
remark = dr["remark"].ToString(),
bz = dr["bz"].ToString(),
create_by = dr["create_by"].ToString(),
create_time = dr["create_time"].ToString(),
update_by = dr["update_by"].ToString(),
update_time = dr["update_time"].ToString(),
factory_code = dr["factory_code"].ToString(),
del_flag = dr["del_flag"].ToString(),
report_name = dr["report_name"].ToString(),
};
mesTableSelf.IsFinal = dr["is_final"].ToString() == "1";
return mesTableSelf;
}
return null;
}
public List<MesTableSelfDetialModel> GetMesTableSelfDetial(string id, int count)
{
string sql = $@"select * from [dbo].[mes_table_self_detial] where belong_to='{id}'";
DataSet ds = Utils.netClientDBHelper.getDataSet(sql);
List<MesTableSelfDetialModel> list = new List<MesTableSelfDetialModel>();
if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
{
foreach (DataRow dr in ds.Tables[0].Rows)
{
int dable_line = 0;
try
{
dable_line = int.Parse(dr["table_line"].ToString());
}
catch
{
}
list.Add(new MesTableSelfDetialModel()
{
id = dr["id"].ToString(),
belong_to = dr["belong_to"].ToString(),
remark = dr["remark"].ToString(),
bz = dr["bz"].ToString(),
factory_code = dr["factory_code"].ToString(),
del_flag = dr["del_flag"].ToString(),
check_time_s = dr["check_time_s"].ToString(),
check_time_e = dr["check_time_e"].ToString(),
check_result = dr["check_result"].ToString(),
info_code = dr["info_code"].ToString(),
info_name = dr["info_name"].ToString(),
table_line = dable_line,
});
}
list = list.OrderByDescending(t => t.table_line).ToList();
var distinctList = list.OrderByDescending(t => t.table_line).Select(t => t.table_line).Distinct().ToList();
for (int i = 0; i < distinctList.Count; i++)
{
list.Where(t => t.table_line == distinctList[i]).ToList().ForEach(t =>
{
t.index = i;
});
if (i > count)
{
list.RemoveAll(t => t.table_line == distinctList[i]);
}
}
}
return list;
}
public List<MesTableSelfDetialModel> GetMesTableSelfDetialByShiftCode(string id,string shiftCode, int count)
{
string sql = $@"select * from [dbo].[mes_table_self_detial] where belong_to='{id}' and remark = '{shiftCode}' and CONVERT(date, create_time) = CONVERT(date, GETDATE())";
DataSet ds = Utils.netClientDBHelper.getDataSet(sql);
List<MesTableSelfDetialModel> list = new List<MesTableSelfDetialModel>();
if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
{
foreach (DataRow dr in ds.Tables[0].Rows)
{
int dable_line = 0;
try
{
dable_line = int.Parse(dr["table_line"].ToString());
}
catch
{
}
list.Add(new MesTableSelfDetialModel()
{
id = dr["id"].ToString(),
belong_to = dr["belong_to"].ToString(),
remark = dr["remark"].ToString(),
bz = dr["bz"].ToString(),
factory_code = dr["factory_code"].ToString(),
del_flag = dr["del_flag"].ToString(),
check_time_s = dr["check_time_s"].ToString(),
check_time_e = dr["check_time_e"].ToString(),
check_result = dr["check_result"].ToString(),
info_code = dr["info_code"].ToString(),
info_name = dr["info_name"].ToString(),
table_line = dable_line,
});
}
list = list.OrderByDescending(t => t.table_line).ToList();
var distinctList = list.OrderByDescending(t => t.table_line).Select(t => t.table_line).Distinct().ToList();
for (int i = 0; i < distinctList.Count; i++)
{
list.Where(t => t.table_line == distinctList[i]).ToList().ForEach(t =>
{
t.index = i;
});
if (i > count)
{
list.RemoveAll(t => t.table_line == distinctList[i]);
}
}
}
return list;
}
public int InsertMesTableSelfDetial(MesTableSelfDetialModel model)
{
string sql = $@"insert into [dbo].[mes_table_self_detial] (id,table_line,belong_to,remark,bz,factory_code,del_flag,check_time_s,check_time_e,check_result,info_code,info_name,create_time) values ('{model.id}','{model.table_line}','{model.belong_to}','{model.remark}','{model.bz}','{model.factory_code}','{model.del_flag}','{model.check_time_s}','{model.check_time_e}','{model.check_result}','{model.info_code}','{model.info_name}',GetDate())";
return Utils.netClientDBHelper.executeUpdate(sql);
}
public int UpdateMesTableSelfDetial(MesTableSelfDetialModel model)
{
string sql = $@"update [dbo].[mes_table_self_detial] set update_time=GetDate(),remark='{model.remark}',bz='{model.bz}',factory_code='{model.factory_code}',del_flag='{model.del_flag}',check_time_s='{model.check_time_s}',check_time_e='{model.check_time_e}',check_result='{model.check_result}',info_code='{model.info_code}',info_name='{model.info_name}' where id='{model.id}'";
return Utils.netClientDBHelper.executeUpdate(sql);
}
public MesTableSelfDetialModel GetMesTableSelfDetialById(string id)
{
string sql = $@"select check_result,check_time_s,check_time_e,is_final from [dbo].[mes_table_self_detial] where id='{id}'";
DataSet ds = Utils.netClientDBHelper.getDataSet(sql);
if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
{
return new MesTableSelfDetialModel()
{
check_result = ds.Tables[0].Rows[0]["check_result"].ToString(),
check_time_s = ds.Tables[0].Rows[0]["check_time_s"].ToString(),
check_time_e = ds.Tables[0].Rows[0]["check_time_e"].ToString(),
};
}
return null;
}
public void UpdateMesTableSelf(string id, string text, string text1, string isFinal)
{
string sql = $@"update [dbo].[mes_table_self] set bz='{text}',create_by='{text1}',is_final='{isFinal}' where id='{id}'";
Utils.netClientDBHelper.executeUpdate(sql);
}
public List<string> GetBatchCode(string workId)
{
//string sql = $@"select batch_code from pro_order_workorder_batch where workorder_id='{workId}'";
string sql = $@"select a.batch_code from pro_order_workorder_batch a join pro_order_workorder b on a.workorder_id=b.workorder_id where b.workorder_id='{workId}' and b.status='w2' and a.del_flag='0'";
DataSet ds = Utils.netClientDBHelper.getDataSet(sql);
List<string> list = new List<string>();
if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
{
foreach (DataRow dr in ds.Tables[0].Rows)
{
list.Add(dr["batch_code"].ToString());
}
}
return list;
}
public int InsertMesUnitPriceReport(string user_name, string nick_name, string post, string gs, string kk, string remark, string deviceCode, string product_code, string product_name, string childprocess_code, string childprocess_name, string workorder_code, string workorder_code_sap, string workDate, string attr1)
{
string sql = $@"insert into mes_unitprice_report (id,workorder_code,workorder_code_sap,product_name,product_code,childprocess_code,childprocess_name,user_name,nick_name,create_time,line_code,post,kk,attr2,remark,work_order_product_date,attr1,attr3)
values ('{Guid.NewGuid().ToString().Substring(0, 32)}','{workorder_code}','{workorder_code_sap}','{product_name}','{product_code}','{childprocess_code}','{childprocess_name}','{user_name}','{nick_name}',GetDate(),'{deviceCode}','{post}',{kk},'{gs}','{remark}','{workDate}','{attr1}','f')";
return Utils.netClientDBHelper.executeUpdate(sql);
}
public string GetProOrderWorkorderBatchStatusById(string workorderId, string batch_code)
{
string sql = $@"select qc_status from [dbo].[pro_order_workorder_batch] where workorder_id='{workorderId}' and batch_code='{batch_code}' and del_flag='0'";
DataSet ds = Utils.netClientDBHelper.getDataSet(sql);
if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
{
return ds.Tables[0].Rows[0]["qc_status"].ToString();
}
else
{
return "";
}
}
public DataTable GetBaseProduct(string productCode)
{
string sql = $@"select product_desc_en,box_type,umrez from base_product where product_code='{productCode}'";
DataSet ds = Utils.netClientDBHelper.getDataSet(sql);
if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
{
return ds.Tables[0];
}
return null;
}
public DataTable GetBaseProductAtt(string productCode)
{
string adjustedProductCode = productCode.Length > 7 ? productCode.Substring(7) : productCode;
string sql = $@"select pack_type from base_product_attached where product_code='{adjustedProductCode}'";
DataSet ds = Utils.netClientDBHelper.getDataSet(sql);
if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
{
return ds.Tables[0];
}
return null;
}
public bool UpdateProWorkBatchInWork(string lineCode, string batchCode, string workorderCode, string productCode, string productName, string productdescen, string boxType, string packType, string umrez, string status, string productDate)
{
string sql = $@"update pro_workbatch_inwork set workorder_code='{workorderCode}',batch='{batchCode}',product_code='{productCode}',status='{status}',product_name='{productName}',product_name_en='{productdescen}',box_type='{boxType}',pack_type='{packType}',umrez='{umrez}',product_date='{productDate}' where line_code='{lineCode}' ";
LogHelper.instance.log.Info($"sql:" + sql);
return Utils.netClientDBHelper.executeUpdate(sql) > 0;
}
///// <summary>
///// 恢复生产时再次写入装数
///// </summary>
///// <param name="umrez"></param>
///// <param name="lineCode"></param>
///// <returns></returns>
//public bool SecondUpdateProWorkBatchInWork(string umrez, string lineCode)
//{
// string sql = $@"update pro_workbatch_inwork set workorder_code='{workorderCode}',product_code='{productCode}',status='{status}',product_name='{productName}',product_name_en='{productdescen}',pack_type='{packType}',umrez='{umrez}',product_date='{productDate}' where line_code='{lineCode}' ";
// LogHelper.instance.log.Info($"sql:" + sql);
// return Utils.netClientDBHelper.executeUpdate(sql) > 0;
//}
public DataTable GetProductSize(string productCode)
{
string sql = $"SELECT length,width,height from base_product where product_code='{productCode}'";
DataSet ds = Utils.netClientDBHelper.getDataSet(sql);
if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
{
return ds.Tables[0];
}
return null;
}
public DataTable GetWcsPlcPoint(string[] plcPointNo, string equip)
{
string plcPointNoStr = "";
foreach (string item in plcPointNo)
{
plcPointNoStr += $"'{item}',";
}
plcPointNoStr = plcPointNoStr.TrimEnd(',');
string sql = $"SELECT * FROM wcs_plc_point WHERE plc_point_no IN ({plcPointNoStr}) and equip='{equip}'";
DataSet ds = Utils.netClientDBHelper.getDataSet(sql);
if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
{
return ds.Tables[0];
}
return null;
}
public bool UpdateProWorkBatchInWorkStatus(string lineCode, string status,string packType)
{
string sql = $@"update pro_workbatch_inwork set status='{status}',pack_type='{packType}' where line_code='{lineCode}' ";
return Utils.netClientDBHelper.executeUpdate(sql) > 0;
}
public bool UpdateProWorkBatchInWorkBatchCode(string lineCode, string batchCode, string status, string productCode, string productName)
{
string sql = $@"update pro_workbatch_inwork set batch='{batchCode}',product_code='{productCode}',product_name='{productName}',status='{status}' where line_code='{lineCode}' ";
return Utils.netClientDBHelper.executeUpdate(sql) > 0;
}
public DataTable GetMesBoxInfo(string box_type)
{
string sql = $"select * from mes_box where box_type='{box_type}' and del_flag='0'";
DataSet ds = Utils.netClientDBHelper.getDataSet(sql);
if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
{
return ds.Tables[0];
}
return null;
}
public string GetWorkOrderParentStatus(string workorderCode)
{
string sql = $@"select status from pro_order_workorder where workorder_code='{workorderCode}' and parent_order='0'";
DataSet ds = Utils.netClientDBHelper.getDataSet(sql);
if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
{
return ds.Tables[0].Rows[0]["status"].ToString();
}
return "";
}
public DataTable GetWcsPlcPointBoxCount(string pointNo)
{
string sql = $"SELECT * FROM wcs_plc_point WHERE plc_point_no ='{pointNo}' and equip='BoxCount'";
DataSet ds = Utils.netClientDBHelper.getDataSet(sql);
if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
{
return ds.Tables[0];
}
return null;
}
}
public class MesTableSelfDetialModel
{
public string id { get; set; }
public string belong_to { get; set; }
public string remark { get; set; }
public string bz { get; set; }
public string factory_code { get; set; }
public string del_flag { get; set; } = "0";
public string check_time_s { get; set; }
public string check_time_e { get; set; }
public string check_result { get; set; }
public string info_code { get; set; }
public string info_name { get; set; }
public int table_line { get; set; }
public int index { get; set; }
}
public class MesTableFirstInspectionDetialModel
{
public string id { get; set; }
public string belong_to { get; set; }
public string remark { get; set; }
public string bz { get; set; }
public string factory_code { get; set; }
public string del_flag { get; set; } = "0";
public string check_time_s { get; set; }
public string check_time_e { get; set; }
public string check_result { get; set; }
public string info_code { get; set; }
public string info_name { get; set; }
public int table_line { get; set; }
public int index { get; set; }
}
}