You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
979 lines
41 KiB
979 lines
41 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
|
|
//Ref:
|
|
using System.Data;
|
|
|
|
using QMAPP.BoraUpgrade.Common;
|
|
using QMAPP.BoraUpgrade.Entity;
|
|
using QMAPP.FJC.Entity.Operation;
|
|
using QMAPP.FJC.Entity.Basic;
|
|
|
|
namespace QMAPP.BoraUpgrade.DAL
|
|
{
|
|
public class WorkOrderDAL
|
|
{
|
|
#region 根据工单ID提取物料列表
|
|
/// <summary>
|
|
/// 根据工单ID提取物料列表
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static DataTable GetMaterialByWorkOrderID(string workOrderID, string material_Type)
|
|
{
|
|
DataTable returnVal = new DataTable();
|
|
|
|
string sqlScript =
|
|
@"
|
|
Select * From T_MD_MATERIAL Where Material_Code In
|
|
(
|
|
Select Material_Code From T_MD_PBOM_ITEM Where PBOM_CODE IN
|
|
(
|
|
Select PBOM_Code From dbo.T_PP_WORKORDER Where PID = '{0}'
|
|
|
|
) And FLGDEl = 0
|
|
)
|
|
And FLGDEl = 0
|
|
And Material_Type_Code Like '{1}%'
|
|
";
|
|
|
|
DataSet dataSet = SqlHelper.ExecuteDataset(
|
|
Config.maindbConnectionString, CommandType.Text, string.Format(sqlScript, workOrderID, material_Type));
|
|
|
|
if (dataSet.Tables.Count > 0)
|
|
{
|
|
returnVal = dataSet.Tables[0];
|
|
}
|
|
|
|
return returnVal;
|
|
}
|
|
#endregion
|
|
|
|
static string GetOldFisOrderSql(string WORKCENTER_CODE, int pState, int pQty)
|
|
{
|
|
StringBuilder strSql = new StringBuilder();
|
|
//List<DataParameter> parameters = new List<DataParameter>();
|
|
strSql.Append(" SELECT TOP " + pQty);
|
|
strSql.Append(" T1.ORDER_NO,T1.BZDCode, T1.PID,T1.VWSEQ,T1.PRODNO,T1.CARSETDESC_CN, T1.CP5A,T1.[LINENO], ");
|
|
strSql.Append("T1.KIN,T1.VIN,T1.SCANSTATE, T2.WORKCENTER_CODE ");
|
|
strSql.Append(" FROM dbo.V_PP_FISORDER T1 ");
|
|
strSql.Append(" INNER JOIN dbo.V_PP_FISORDERSENDDETAIL T2 ");
|
|
strSql.Append(" on T1.PID=T2.FIS_PID ");
|
|
strSql.Append(" WHERE T1.scanstate=0 ");
|
|
//strSql.Append(" and LEFT(T1.VWSEQ,2)='" + pFistype + "' AND T1.flagdel=0 ");
|
|
strSql.Append(" AND T1.flagdel=0 ");
|
|
strSql.Append($" AND T1.State={pState} ");
|
|
if (!string.IsNullOrEmpty(WORKCENTER_CODE))
|
|
{
|
|
strSql.Append(" and T2.WORKCENTER_CODE='" + WORKCENTER_CODE + "'");
|
|
}
|
|
strSql.Append(" ORDER BY T1.CP5A ASC,T1.VWSEQ ASC,T1.PRODNO ASC ");
|
|
|
|
return strSql.ToString();
|
|
}
|
|
static string GetNewFisOrderSql(string WORKCENTER_CODE, int pState, int pQty)
|
|
{
|
|
//string fisSendState = "";
|
|
//if(pState ==10)
|
|
//{
|
|
// fisSendState = "AND T1.SendState=0 ";
|
|
//}
|
|
//else if (pState == 11)
|
|
//{
|
|
// fisSendState = "AND T1.SendState=9 ";
|
|
//}
|
|
//else if (pState == 12)
|
|
//{
|
|
// fisSendState = "AND ( T1.SendState=0 or T1.SendState=9 ) ";
|
|
//}
|
|
//else
|
|
//{
|
|
// fisSendState = $"AND T1.SendState={pState} ";
|
|
//}
|
|
//StringBuilder strSql = new StringBuilder();
|
|
////List<DataParameter> parameters = new List<DataParameter>();
|
|
//strSql.Append(" SELECT TOP " + pQty);
|
|
//strSql.Append(" T1.ORDER_NO,T1.BZDCode, T1.PID,T1.VWSEQ,T1.PRODNO,T1.CARSETDESC_CN, T1.CP5A,T1.[LINENO], T1.[SendState], ");
|
|
//strSql.Append("T1.KIN,T1.VIN,T1.SCANSTATE ,T1.WORKCENTER_CODE ");
|
|
//strSql.Append(" FROM dbo.V_PP_FISORDER_ZDQ T1 ");
|
|
//strSql.Append(" WHERE 1=1 ");
|
|
////strSql.Append(" and LEFT(T1.VWSEQ,2)='" + pFistype + "' AND T1.flagdel=0 ");
|
|
//strSql.Append(" AND T1.flagdel=0 ");
|
|
////strSql.Append($" AND T1.SendState={pState} "); //T1.State是发运状态. T1.SendState是T_AW_FisSendState表的状态 //and T1.CP5A > '202008150108' and T1.order_no is not null
|
|
//strSql.Append(fisSendState);
|
|
//if (!string.IsNullOrEmpty(WORKCENTER_CODE))
|
|
//{
|
|
// strSql.Append(" and T1.WORKCENTER_CODE='" + WORKCENTER_CODE + "'");
|
|
//}
|
|
//strSql.Append(" ORDER BY T1.CP5A ASC,T1.VWSEQ ASC,T1.PRODNO ASC ");
|
|
//strSql.Append(" WHERE T1.scanstate=0 ");
|
|
|
|
StringBuilder strSql = new StringBuilder();
|
|
strSql.Append("SELECT TOP " + pQty);
|
|
strSql.Append(" W.[PID] ");
|
|
strSql.Append(" ,W.[ORDERPLANID] ");
|
|
strSql.Append(" ,W.[ORDERPLAN_NO] ");
|
|
strSql.Append(" ,W.[ORDER_TYPE] ");
|
|
strSql.Append(" ,W.[SEQ] ");
|
|
strSql.Append(" ,W.[MATERIAL_CODE] ");
|
|
strSql.Append(" ,M.[MATERIAL_NAME] ");
|
|
strSql.Append(" ,W.[PBOM_CODE] ");
|
|
strSql.Append(" ,W.[QTY] ");
|
|
strSql.Append(" ,W.[COMPLETE_QTY] ");
|
|
strSql.Append(" ,W.[PLAN_DATE] ");
|
|
strSql.Append(" ,W.[SHIFT_CODE] ");
|
|
strSql.Append(" ,W.[WORKCENTER_CODE] ");
|
|
strSql.Append(" ,W.[WORKCENTER_NAME] ");
|
|
strSql.Append(" ,W.[WORKCELL_CODE] ");
|
|
strSql.Append(" ,W.[WORKCELL_NAME] ");
|
|
strSql.Append(" ,W.[WORKLOC_CODE] ");
|
|
strSql.Append(" ,W.[REMARK] ");
|
|
strSql.Append(" ,W.[EQPT_NAME] ");
|
|
strSql.Append(" ,W.[EQPT_CODE] ");
|
|
strSql.Append(" ,W.[STATE] ");
|
|
strSql.Append(" ,W.[MOULD_CODE] ");
|
|
strSql.Append(" ,W.[PRI] ");
|
|
strSql.Append(" ,W.[UPDATEDATE] ");
|
|
strSql.Append(" ,P.[IGNORE_FISBREAK] ");
|
|
strSql.Append(" ,P.[FIS_ASMSETCODE] ");
|
|
strSql.Append(" FROM [T_PP_WORKORDER] AS W WITH(NOLOCK) ");
|
|
strSql.Append(" LEFT JOIN [T_PP_ORDERPLAN] AS P WITH(NOLOCK) ");
|
|
strSql.Append(" ON P.[PID]=W.[ORDERPLANID] ");
|
|
strSql.Append(" LEFT JOIN [T_MD_MATERIAL] AS M WITH(NOLOCK)");
|
|
strSql.Append(" ON W.[MATERIAL_CODE] = M.[MATERIAL_CODE] ");
|
|
strSql.Append(" WHERE W.[WORKCELL_CODE] = '" + WORKCENTER_CODE + "'");
|
|
switch (pState)
|
|
{
|
|
case 1:
|
|
{
|
|
strSql.Append(" AND W.[STATE]<>4 ");
|
|
break;
|
|
}
|
|
case 2:
|
|
{
|
|
strSql.Append(" AND W.[STATE]=4 ");
|
|
break;
|
|
}
|
|
}
|
|
strSql.AppendFormat(" ORDER BY W.[UPDATEDATE],W.[PRI],W.[PLAN_DATE],P.PLAN_SEQ,W.[SEQ],W.[MATERIAL_CODE] ");
|
|
|
|
|
|
|
|
return strSql.ToString();
|
|
}
|
|
/// <summary>
|
|
/// 查询fis订单
|
|
/// </summary>
|
|
/// <param name="state">0:未处理 1:已打印BZD 2:已器具排序</param>
|
|
/// <returns></returns>
|
|
public static DataTable GetFisOrders( string WORKCENTER_CODE, int pState,int pQty)
|
|
{
|
|
#region
|
|
|
|
try
|
|
{
|
|
DataTable returnDt = null;
|
|
string sqlStr = GetNewFisOrderSql(WORKCENTER_CODE, pState, pQty);
|
|
//using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
//{
|
|
// returnDt = session.GetTable(strSql.ToString(), parameters.ToArray());
|
|
//}
|
|
DataSet ds = SqlHelper.ExecuteDataset(
|
|
Config.maindbConnectionString, CommandType.Text, sqlStr);
|
|
returnDt = ds.Tables[0];
|
|
|
|
//逻辑说明
|
|
//FIS要货计划都有大众上线时间CP5A:201611011001表示2016年11月1号10点01分上线
|
|
//FIS要货计划都有一个大众顺序号VWSEQ: 018029或是029382,前两位01和02表示东厂和西厂,没有锦衣卫
|
|
//后面四位表示实际顺序号,所以9999台一轮回,
|
|
//实际出现的情况有可能出现同一个分钟上线的大众顺序号可能有两个
|
|
//如果出现019999和010001,实际的顺序是019999在前,010001在后,即上一个轮回的最后一条和下一个轮回的第一条
|
|
//如果这样前面的查询语句中就会把010001排在019999前面
|
|
//所以要处理这种情况。
|
|
|
|
//实现方式就是获取数据后,放到两个表中,这两个表相同,遍历第一个表,用记录和后一条记录比较,
|
|
//如果大众上线时间相同并且两个顺序号的差值在1000以上,一定是顺序出差,
|
|
//差值1000是个估计值,9999与1差值是9998,我们之前1000
|
|
//修改第二个表中的对应的数据
|
|
//极端情况出现一个大众上线时间对一个三个大众顺序号,
|
|
//这里一并处理
|
|
//if (returnDt.Rows.Count > 1)
|
|
//{
|
|
|
|
// //必须进行第一次循环
|
|
// bool flag = true;
|
|
|
|
// while (flag)
|
|
// {
|
|
// //复制表
|
|
// DataTable dt = returnDt.Copy();
|
|
|
|
// //是否进行了值的交换标记
|
|
// bool isChange = false;
|
|
|
|
// for (int i = 0; i < dt.Rows.Count; i++)
|
|
// {
|
|
|
|
// if (i == dt.Rows.Count - 1)
|
|
// continue;
|
|
|
|
// //获取当前行对象
|
|
// DataRow dr = dt.Rows[i];
|
|
// string cp5aDr = dr["CP5A"].ToString();
|
|
// int seqDr = Convert.ToInt32(dr["VWSEQ"].ToString().Substring(2));
|
|
|
|
// //获取下一行对象
|
|
// DataRow nextDr = dt.Rows[i + 1];
|
|
// string nextCp5a = nextDr["CP5A"].ToString();
|
|
// int nextSeq = Convert.ToInt32(nextDr["VWSEQ"].ToString().Substring(2));
|
|
|
|
// //如果两行记录的大众上线时间不相同
|
|
// //不需要比较
|
|
// if (cp5aDr != nextCp5a)
|
|
// continue;
|
|
|
|
// //如果大众上线时间相同并且前后值大于1000,
|
|
// //我们默认是
|
|
// if (nextSeq - seqDr > 1000)
|
|
// {
|
|
// returnDt.Rows[i]["PID"] = nextDr["PID"].ToString();
|
|
// returnDt.Rows[i]["VWSEQ"] = nextDr["VWSEQ"].ToString();
|
|
// returnDt.Rows[i]["PRODNO"] = nextDr["PRODNO"].ToString();
|
|
// returnDt.Rows[i]["CARSETDESC_CN"] = nextDr["CARSETDESC_CN"].ToString();
|
|
// returnDt.Rows[i]["CP5A"] = nextDr["CP5A"].ToString();
|
|
// returnDt.Rows[i]["LINENO"] = nextDr["LINENO"].ToString();
|
|
// returnDt.Rows[i]["KIN"] = nextDr["KIN"].ToString();
|
|
// returnDt.Rows[i]["VIN"] = nextDr["VIN"].ToString();
|
|
// returnDt.Rows[i]["SCANSTATE"] = nextDr["SCANSTATE"].ToString();
|
|
|
|
// returnDt.Rows[i + 1]["PID"] = dr["PID"].ToString();
|
|
// returnDt.Rows[i + 1]["VWSEQ"] = dr["VWSEQ"].ToString();
|
|
// returnDt.Rows[i + 1]["PRODNO"] = dr["PRODNO"].ToString();
|
|
// returnDt.Rows[i + 1]["CARSETDESC_CN"] = dr["CARSETDESC_CN"].ToString();
|
|
// returnDt.Rows[i + 1]["CP5A"] = dr["CP5A"].ToString();
|
|
// returnDt.Rows[i + 1]["LINENO"] = dr["LINENO"].ToString();
|
|
// returnDt.Rows[i + 1]["KIN"] = dr["KIN"].ToString();
|
|
// returnDt.Rows[i + 1]["VIN"] = dr["VIN"].ToString();
|
|
// returnDt.Rows[i + 1]["SCANSTATE"] = dr["SCANSTATE"].ToString();
|
|
|
|
// //设置值的交换标记值为true
|
|
// isChange = true;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// //将是否 交换标记值付给外层标记值
|
|
// //如果未进行交换,跳出while循环
|
|
// //如果进行了交换就得再次循环,放在一个大众上线时间对应两个以上大众顺序号的情况
|
|
// flag = isChange;
|
|
// }
|
|
//}
|
|
return returnDt;
|
|
|
|
}
|
|
catch (System.Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
#endregion
|
|
}
|
|
|
|
//public static DataTable GetFisOrder(int state)
|
|
//{
|
|
// DataTable returnVal = new DataTable();
|
|
// string sqlScript = $" select * from V_PP_FISORDER where State = {state}";
|
|
// DataSet dataSet = SqlHelper.ExecuteDataset(
|
|
// Config.maindbConnectionString, CommandType.Text, sqlScript);
|
|
// if (dataSet.Tables.Count > 0)
|
|
// {
|
|
// returnVal = dataSet.Tables[0];
|
|
// }
|
|
|
|
// return returnVal;
|
|
//}
|
|
|
|
/// <summary>
|
|
/// 更改状态
|
|
/// </summary>
|
|
/// <param name="orderNo"></param>
|
|
/// <param name="state"></param>
|
|
/// <returns></returns>
|
|
public static bool UpdateFisOrderState(string pOrderNo,string pBzdCode, int state)
|
|
{
|
|
string sqlScript = $" select * from T_AW_FisSendState where FisOrderNo = '{pOrderNo}'";
|
|
DataSet dataSet = SqlHelper.ExecuteDataset(
|
|
Config.maindbConnectionString, CommandType.Text, sqlScript);
|
|
DataTable dataTable = dataSet.Tables[0];
|
|
string saveSql = string.Empty;
|
|
if(dataTable.Rows.Count >0)
|
|
{
|
|
saveSql = $" update T_AW_FisSendState set State = {state},BZDCode ='{pBzdCode}' where FisOrderNo= '{pOrderNo}'";
|
|
}
|
|
else
|
|
{
|
|
saveSql = $" insert into T_AW_FisSendState(FisOrderNo,State,BZDCode) values('{pOrderNo}',{state},'{pBzdCode}')";
|
|
}
|
|
|
|
bool returnVal = false;
|
|
try
|
|
{
|
|
//执行SQL
|
|
int count = SqlHelper.ExecuteNonQuery(Config.maindbConnectionString, CommandType.Text, saveSql);
|
|
|
|
if (count > 0)
|
|
{
|
|
returnVal = true;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//后续加入日志
|
|
throw;
|
|
}
|
|
|
|
return returnVal;
|
|
}
|
|
|
|
public static bool SaveSacnOrderRecord(DataRow dataRow)
|
|
{
|
|
string sqlScript = $" insert into T_AW_FinalSortRecord(BZDCode,ProductCode,[Desc],OrderNo,[LINENO]) " +
|
|
$" values('{dataRow["BZDCode"].ToString()}','{dataRow["ProductCode"].ToString()}','{dataRow["Desc"].ToString()}','{dataRow["OrderNo"].ToString()}','{dataRow["LINENO"].ToString()}') ";
|
|
|
|
bool returnVal = false;
|
|
try
|
|
{
|
|
//执行SQL
|
|
int count = SqlHelper.ExecuteNonQuery(Config.maindbConnectionString, CommandType.Text, sqlScript);
|
|
|
|
if (count > 0)
|
|
{
|
|
returnVal = true;
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
//后续加入日志
|
|
throw;
|
|
}
|
|
|
|
return returnVal;
|
|
|
|
|
|
}
|
|
public static string GetA3MaterialCodeByBZD(string bzdCode)
|
|
{
|
|
//productCode = "052 998A4K501H %";
|
|
string pCode = bzdCode.Replace(" ", "");
|
|
string first = pCode.Substring(0, 3);
|
|
string companyCode = pCode.Substring(3, 3);
|
|
string vt = pCode.Substring(6, 1);
|
|
string cc = pCode.Substring(7, 1);
|
|
|
|
string sqlScript = $" select * from T_BD_BZDConfig where barcodeFist ='{first}' and Company_code='{companyCode}' and Vehicle_type='{vt}' and configColor='{cc}' ";
|
|
//DataSet dataSet = SqlHelper.ExecuteDataset(
|
|
// Config.a3dbConnectionString, CommandType.Text, sqlScript);
|
|
//DataTable dataTable = dataSet.Tables[0];
|
|
|
|
DataTable dataTable = GetDataTable(sqlScript, Config.bzdConnectionString);
|
|
if (dataTable.Rows.Count==0)
|
|
{
|
|
throw new Exception($"BZD条码{bzdCode}在表T_BD_BZDConfig中没找到物料号");
|
|
}
|
|
else if (dataTable.Rows.Count >1)
|
|
{
|
|
throw new Exception($"BZD条码{bzdCode}在表T_BD_BZDConfig中配置了多个物料号,目标不明确,请检查配置!");
|
|
}
|
|
else
|
|
{
|
|
return dataTable.Rows[0]["MATERIALCODDE"].ToString();
|
|
}
|
|
}
|
|
|
|
public static string GetA3MaterialCodeByPID(string mpid)
|
|
{
|
|
//productCode = "052 998A4K501H %";
|
|
//string pCode = bzdCode.Replace(" ", "");
|
|
//string first = pCode.Substring(0, 3);
|
|
//string companyCode = pCode.Substring(3, 3);
|
|
//string vt = pCode.Substring(6, 1);
|
|
//string cc = pCode.Substring(7, 1);
|
|
|
|
string sqlScript = $" select * from T_BD_BZDConfig where pid ='{mpid}' ";
|
|
//DataSet dataSet = SqlHelper.ExecuteDataset(
|
|
// Config.a3dbConnectionString, CommandType.Text, sqlScript);
|
|
//DataTable dataTable = dataSet.Tables[0];
|
|
|
|
DataTable dataTable = GetDataTable(sqlScript, Config.bzdConnectionString);
|
|
if (dataTable.Rows.Count == 0)
|
|
{
|
|
throw new Exception($"mpid条码{mpid}在表T_BD_BZDConfig中没找到物料号");
|
|
}
|
|
else if (dataTable.Rows.Count > 1)
|
|
{
|
|
throw new Exception($"mpid条码{mpid}在表T_BD_BZDConfig中配置了多个物料号,目标不明确,请检查配置!");
|
|
}
|
|
else
|
|
{
|
|
return dataTable.Rows[0]["MATERIALCODDE"].ToString();
|
|
}
|
|
}
|
|
|
|
public static bool IsNoUsedBzdCode(string pBzdCode)
|
|
{
|
|
string sqlScript = $" select * from T_AW_FisSendState where BZDCode ='{pBzdCode}' ";
|
|
|
|
DataSet dataSet = SqlHelper.ExecuteDataset(
|
|
Config.maindbConnectionString, CommandType.Text, sqlScript);
|
|
|
|
DataTable dataTable = dataSet.Tables[0];
|
|
if(dataTable.Rows.Count>0)
|
|
{
|
|
throw new Exception($"BZD条码{pBzdCode}已被使用,请重试!");
|
|
}
|
|
else
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
|
|
public static DataTable GetMainInfo(string productCode)
|
|
{
|
|
string sqlScript = $"select * from T_AW_MAIN where EPIDERMISCODE='{productCode}'";
|
|
|
|
DataSet dataSet = SqlHelper.ExecuteDataset(
|
|
Config.maindbConnectionString, CommandType.Text, sqlScript);
|
|
|
|
DataTable dataTable = dataSet.Tables[0];
|
|
return dataTable;
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据产品号查询物料号
|
|
/// 查询product表最新一条记录的物料号,然后联合bom查询总成零件号
|
|
/// </summary>
|
|
/// <param name="productCode"></param>
|
|
/// <returns></returns>
|
|
public static string GetPMaterialCode(string productCode)
|
|
{
|
|
string sqlScript = $" select Top 1 MATERIAL_CODE FROM [dbo].[T_AW_PRODUCT] where PRODUCTCODE='{productCode}' order by CREATEDATE desc ";
|
|
DataSet dataSet = SqlHelper.ExecuteDataset(
|
|
Config.maindbConnectionString, CommandType.Text, sqlScript);
|
|
DataTable dataTable = dataSet.Tables[0];
|
|
if(dataTable.Rows.Count >0)
|
|
{
|
|
string materialCode = dataTable.Rows[0]["MATERIAL_CODE"].ToString();
|
|
|
|
string mainSql = $" select a.MATERIAL_CODE from [T_MD_PBOM] a,[T_MD_PBOM_ITEM] b where a.PBOM_CODE = b.PBOM_CODE and b.MATERIAL_CODE = '{materialCode}'";
|
|
DataSet mainSet = SqlHelper.ExecuteDataset(
|
|
Config.maindbConnectionString, CommandType.Text, mainSql);
|
|
DataTable mainTable = mainSet.Tables[0];
|
|
if(mainTable.Rows.Count == 0)
|
|
{
|
|
throw new Exception($"T_MD_PBOM_ITEM中没有查询到物料号{materialCode}的配置信息");
|
|
}
|
|
else if (mainTable.Rows.Count > 1)
|
|
{
|
|
throw new Exception($"物料号{materialCode} 在T_MD_PBOM_ITEM表中配置了多条记录,无法确定唯一产品零件号");
|
|
}
|
|
else
|
|
{
|
|
return mainTable.Rows[0]["MATERIAL_CODE"].ToString();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
throw new Exception($"T_AW_PRODUCT表中没有查询到条码{productCode}产生的加工记录信息");
|
|
}
|
|
|
|
}
|
|
public static bool IsBarCodeRepet(string productCode)
|
|
{
|
|
string sqlScript = $" select * FROM [dbo].[T_AW_MAIN] where EPIDERMISCODE='{productCode}' ";
|
|
DataSet dataSet = SqlHelper.ExecuteDataset(
|
|
Config.maindbConnectionString, CommandType.Text, sqlScript);
|
|
DataTable mainTable = dataSet.Tables[0];
|
|
if (mainTable.Rows.Count == 0)
|
|
{
|
|
return false;
|
|
}
|
|
else
|
|
{
|
|
//planCode = mainTable.Rows[0]["PLAN_NO"].ToString();
|
|
return true;
|
|
}
|
|
}
|
|
public static bool VerifyLastCellOver(string productCode, string lastCellCode)
|
|
{
|
|
string sqlScript = $" select * FROM [dbo].[T_AW_MAINOPERATION] where PRODUCTCODE='{productCode}' AND WORKCELL_CODE='{lastCellCode}' ";
|
|
DataSet dataSet = SqlHelper.ExecuteDataset(
|
|
Config.maindbConnectionString, CommandType.Text, sqlScript);
|
|
DataTable mainTable = dataSet.Tables[0];
|
|
if(mainTable.Rows.Count == 0)
|
|
{
|
|
return false;
|
|
}
|
|
else
|
|
{
|
|
//planCode = mainTable.Rows[0]["PLAN_NO"].ToString();
|
|
return true;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 根据条码查询计划编号
|
|
/// </summary>
|
|
/// <param name="productCode"></param>
|
|
/// <returns></returns>
|
|
public static string GetPlanCode(string productCode)
|
|
{
|
|
string sqlScript = $" select top 1 PLAN_NO FROM [dbo].[T_AW_PRODUCT] where PRODUCTCODE='{productCode}' AND PLAN_NO is not null ";
|
|
DataSet dataSet = SqlHelper.ExecuteDataset(
|
|
Config.maindbConnectionString, CommandType.Text, sqlScript);
|
|
DataTable mainTable = dataSet.Tables[0];
|
|
|
|
if (mainTable.Rows.Count == 0)
|
|
{
|
|
return null;
|
|
}
|
|
else
|
|
{
|
|
return mainTable.Rows[0]["PLAN_NO"].ToString();
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据条码查询计划编号
|
|
/// </summary>
|
|
/// <param name="productCode"></param>
|
|
/// <returns></returns>
|
|
public static string GetBoraBZDCode(string productCode,string materialCode)
|
|
{
|
|
string sqlScript = $" SELECT MAINCODE FROM [dbo].[T_AW_MAIN] WHERE EPIDERMISCODE = '{productCode}' AND MATERIAL_CODE = '{materialCode}' ";
|
|
DataSet dataSet = SqlHelper.ExecuteDataset(
|
|
Config.maindbConnectionString, CommandType.Text, sqlScript);
|
|
DataTable mainTable = dataSet.Tables[0];
|
|
|
|
if (mainTable.Rows.Count == 0)
|
|
{
|
|
return null;
|
|
}
|
|
else
|
|
{
|
|
return mainTable.Rows[0]["MAINCODE"].ToString();
|
|
}
|
|
|
|
}
|
|
/// <summary>
|
|
/// 根据BZD条码,在BZD库里面查询生产本体条码
|
|
/// </summary>
|
|
/// <param name="bzdCode"></param>
|
|
/// <returns></returns>
|
|
public static string GetA3ProductCodeByBzd(string bzdCode)
|
|
{
|
|
string sqlScript = $"select ProductCode from T_BD_BZDRecorder where BZDCODE='{bzdCode}'";
|
|
//DataSet dataSet = SqlHelper.ExecuteDataset(
|
|
// Config.bzdConnectionString, CommandType.Text, sqlScript);
|
|
//DataTable mainTable = dataSet.Tables[0];
|
|
DataTable mainTable = GetDataTable(sqlScript, Config.bzdConnectionString);
|
|
if (mainTable.Rows.Count == 0)
|
|
{
|
|
return null;
|
|
}
|
|
else
|
|
{
|
|
return mainTable.Rows[0]["ProductCode"].ToString();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据BZD条码,在BZD库里面查询生产时间
|
|
/// </summary>
|
|
/// <param name="bzdCode"></param>
|
|
/// <returns></returns>
|
|
public static string GetA3ProductCreateByBzd(string bzdCode)
|
|
{
|
|
string sqlScript = $"select CREATEDATE from T_BD_BZDRecorder where BZDCODE='{bzdCode}'";
|
|
//DataSet dataSet = SqlHelper.ExecuteDataset(
|
|
// Config.bzdConnectionString, CommandType.Text, sqlScript);
|
|
//DataTable mainTable = dataSet.Tables[0];
|
|
DataTable mainTable = GetDataTable(sqlScript, Config.bzdConnectionString);
|
|
if (mainTable.Rows.Count == 0)
|
|
{
|
|
return null;
|
|
}
|
|
else
|
|
{
|
|
return mainTable.Rows[0]["CREATEDATE"].ToString();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据BZD条码,在BZD库里面查询生产本体条码
|
|
/// </summary>
|
|
/// <param name="bzdCode"></param>
|
|
/// <returns></returns>
|
|
public static string GetA3MpidCodeByBzd(string bzdCode)
|
|
{
|
|
string sqlScript = $"select MPID from T_BD_BZDRecorder where BZDCODE='{bzdCode}'";
|
|
//DataSet dataSet = SqlHelper.ExecuteDataset(
|
|
// Config.bzdConnectionString, CommandType.Text, sqlScript);
|
|
//DataTable mainTable = dataSet.Tables[0];
|
|
DataTable mainTable = GetDataTable(sqlScript, Config.bzdConnectionString);
|
|
if (mainTable.Rows.Count == 0)
|
|
{
|
|
return null;
|
|
}
|
|
else
|
|
{
|
|
return mainTable.Rows[0]["Mpid"].ToString();
|
|
}
|
|
}
|
|
|
|
private static DataTable GetDataTable(string sql,string connStr)
|
|
{
|
|
DataSet dataSet = SqlHelper.ExecuteDataset(
|
|
connStr, CommandType.Text, sql);
|
|
DataTable mainTable = dataSet.Tables[0];
|
|
return mainTable;
|
|
}
|
|
|
|
public static List<ProduceShift> GetShiftList()
|
|
{
|
|
List<ProduceShift> list = new List<ProduceShift>();
|
|
string sqlScript = "SELECT M.PID ,M.PRODUCESHIFTNAME,M.PRODUCESHIFTTCODE,M.PSSTART,M.PSEND,M.PRODUCELINE,M.MEMO,M.CREATEUSER,M.CREATEDATE,M.UPDATEUSER,M.UPDATEDATE,C.USERNAME AS CREATEUSERNAME,U.USERNAME AS UPDATEUSERNAMEFROM FROM T_BD_PRODUCESHIFT M LEFT JOIN T_QM_USER C ON C.USERID=M.CREATEUSER LEFT JOIN T_QM_USER U ON U.USERID=M.UPDATEUSER ";
|
|
DataSet dataSet = SqlHelper.ExecuteDataset(
|
|
Config.maindbConnectionString, CommandType.Text, sqlScript);
|
|
DataTable mainTable = dataSet.Tables[0];
|
|
foreach(DataRow dataRow in mainTable.Rows)
|
|
{
|
|
ProduceShift sf = new ProduceShift();
|
|
sf.PRODUCESHIFTNAME = dataRow["PRODUCESHIFTNAME"].ToString();
|
|
sf.PRODUCESHIFTTCODE = dataRow["PRODUCESHIFTTCODE"].ToString();
|
|
sf.PSSTART = string.IsNullOrEmpty( dataRow["PSSTART"].ToString()) ? DateTime.MinValue : DateTime.Parse(dataRow["PSSTART"].ToString());
|
|
sf.PSEND = string.IsNullOrEmpty(dataRow["PSEND"].ToString()) ? DateTime.MinValue : DateTime.Parse(dataRow["PSEND"].ToString());
|
|
sf.PRODUCELINE = dataRow["PRODUCELINE"].ToString();
|
|
list.Add(sf);
|
|
}
|
|
return list;
|
|
|
|
}
|
|
/// <summary>
|
|
/// 订单挂起
|
|
/// </summary>
|
|
/// <param name="dataRow"></param>
|
|
/// <returns></returns>
|
|
public static bool UpdateFisSetState(DataRow dataRow)
|
|
{
|
|
string searchsql = $" select * from T_AW_FisSendState where FisOrderNo='{dataRow["ORDER_NO"]}'";
|
|
DataTable dataTable = SqlHelper.ExecuteDataset(
|
|
Config.maindbConnectionString, CommandType.Text, searchsql).Tables[0];
|
|
string insertSql = string.Empty;
|
|
if(dataTable.Rows.Count >0)
|
|
{
|
|
insertSql = $"Update T_AW_FisSendState set State = 9 where ID ={dataTable.Rows[0]["ID"]}";
|
|
}
|
|
else
|
|
{
|
|
insertSql = $"insert into T_AW_FisSendState(FisOrderNo,State,BZDCode,Remark) values ('{dataRow["ORDER_NO"]}',9,'','挂起状态')";
|
|
}
|
|
bool returnVal = false;
|
|
try
|
|
{
|
|
//执行SQL
|
|
int count = SqlHelper.ExecuteNonQuery(Config.maindbConnectionString, CommandType.Text, insertSql);
|
|
|
|
if (count > 0)
|
|
{
|
|
returnVal = true;
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
//后续加入日志
|
|
throw;
|
|
}
|
|
|
|
return returnVal;
|
|
|
|
}
|
|
|
|
public static DataTable GetStoreData(int count=100)
|
|
{
|
|
//string sql = $"select top {count} * from T_AW_MAIN where PRODUCELINE='A3IPASSY_STORE' order by CREATEDATE desc";
|
|
string sql = $@"select top {count} a.* ,b.MATERIAL_NAME FROM [T_AW_MAIN] a
|
|
left join T_MD_MATERIAL b on a.MATERIAL_CODE = b.MATERIAL_CODE
|
|
where PRODUCELINE = 'A3IPASSY_STORE' order by CREATEDATE desc";
|
|
|
|
DataTable dataTable = GetDataTable(sql, Config.a3dbConnectionString);
|
|
return dataTable;
|
|
}
|
|
|
|
public static void SaveA3MainRecord(string[] basicData, string bzdCode,string productionCode, string userID,string materialCode,string lineCode)
|
|
{
|
|
string searchSql = $" select * from T_AW_MAIN where MAINCODE='{bzdCode}'";
|
|
DataTable dataTable = GetDataTable(searchSql,Config.a3dbConnectionString);
|
|
if(dataTable.Rows.Count == 0)
|
|
{
|
|
DataTable materialInitTable = GetMaterialCodeInit(materialCode);
|
|
//string produceLine = "";
|
|
string workCellCode = "";
|
|
string workLocCode = "";
|
|
string workCenterCode = "";
|
|
string materialType = "";
|
|
|
|
if (materialInitTable.Rows.Count>0)
|
|
{
|
|
//produceLine = materialInitTable.Rows[0]["WORKCENTER_CODE_INIT"].ToString();
|
|
|
|
workCellCode = materialInitTable.Rows[0]["WORKCELL_CODE"].ToString();
|
|
workLocCode = materialInitTable.Rows[0]["WORKLOC_CODE"].ToString();
|
|
workCenterCode = materialInitTable.Rows[0]["WORKCENTER_CODE"].ToString();
|
|
materialType = materialInitTable.Rows[0]["MATERIAL_TYPE"].ToString();
|
|
}
|
|
|
|
string insertSql = $@"insert into T_AW_MAIN(PID,MAINCODE,EPIDERMISCODE,MACHINECODDE,PROCESSSTATE,STATUS,CURRENTPROCESS,COMPLETEFLAG,
|
|
PRODUCELINE,OUTFLAG,COMPLETETIME,CREATEUSER,CREATEDATE,UPDATEUSER,UPDATEDATE,WORKCELL_CODE,WORKLOC_CODE,WORKCENTER_CODE,MATERIAL_TYPE,MATERIAL_CODE) values
|
|
( '{Guid.NewGuid()}','{bzdCode}','{productionCode}','{basicData[0]}','1','0','15','1','{lineCode}','0','{DateTime.Now}','{userID}','{DateTime.Now}','{userID}','{DateTime.Now}',
|
|
'{workCellCode}','{workLocCode}','{workCenterCode}','{materialType}','{materialCode}')";
|
|
|
|
try
|
|
{
|
|
//执行SQL
|
|
int count = SqlHelper.ExecuteNonQuery(Config.a3dbConnectionString, CommandType.Text, insertSql);
|
|
|
|
}
|
|
catch (Exception)
|
|
{
|
|
//后续加入日志
|
|
throw;
|
|
}
|
|
}
|
|
//20210111 DQZhang T_AW_MAIN表已被触发器插入的记录补充字段内容
|
|
else if (dataTable.Rows.Count == 1)
|
|
{
|
|
DataTable materialInitTable = GetMaterialCodeInit(materialCode);
|
|
//string produceLine = "";
|
|
string workCellCode = "";
|
|
string workLocCode = "";
|
|
string workCenterCode = "";
|
|
string materialType = "";
|
|
|
|
if (materialInitTable.Rows.Count > 0)
|
|
{
|
|
//produceLine = materialInitTable.Rows[0]["WORKCENTER_CODE_INIT"].ToString();
|
|
|
|
workCellCode = materialInitTable.Rows[0]["WORKCELL_CODE"].ToString();
|
|
workLocCode = materialInitTable.Rows[0]["WORKLOC_CODE"].ToString();
|
|
workCenterCode = materialInitTable.Rows[0]["WORKCENTER_CODE"].ToString();
|
|
materialType = materialInitTable.Rows[0]["MATERIAL_TYPE"].ToString();
|
|
}
|
|
|
|
string insertSql = $@"UPDATE T_AW_MAIN SET MACHINECODDE='{basicData[0]}',PROCESSSTATE='1',STATUS='0',CURRENTPROCESS='15',COMPLETEFLAG='1',
|
|
PRODUCELINE='{lineCode}',OUTFLAG='0',COMPLETETIME='{DateTime.Now}',UPDATEUSER='{userID}',UPDATEDATE='{DateTime.Now}',
|
|
WORKCELL_CODE='{workCellCode}',WORKCENTER_CODE='{workCenterCode}',MATERIAL_TYPE='{materialType}' WHERE MAINCODE ='{bzdCode}' ";
|
|
|
|
try
|
|
{
|
|
//执行SQL
|
|
int count = SqlHelper.ExecuteNonQuery(Config.a3dbConnectionString, CommandType.Text, insertSql);
|
|
|
|
}
|
|
catch (Exception)
|
|
{
|
|
//后续加入日志
|
|
throw;
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
public static DataTable GetMaterialCodeInit(string materialCode)
|
|
{
|
|
string sql = $"select b.* FROM T_MD_MATERIAL a,T_BD_MATERIALCODEINIT b where a.MATERIAL_CODE = b.MATERIAL_CODE and a.MATERIAL_TYPE_CODE = b.MATERIAL_TYPE and a.MATERIAL_CODE = '{materialCode}'";
|
|
DataTable dataTable = GetDataTable(sql, Config.a3dbConnectionString);
|
|
return dataTable;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查询每天早8:30到第二天8:30的产量
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static string GetDayYield()
|
|
{
|
|
|
|
string sql = $@" declare
|
|
@tt varchar(20) = format(GetDate(), 'HH:mm')
|
|
|
|
if @tt > '08:30'
|
|
select count(0) as c from T_AW_MAIN where CREATEDATE > format(GetDate(), 'yyyy-MM-dd') + ' 08:30:00.000'
|
|
and CREATEDATE < format(dateadd(day, 1, GetDate()), 'yyyy-MM-dd') + ' 08:30:00.000'
|
|
else
|
|
select count(0) as c from T_AW_MAIN where CREATEDATE > format(dateadd(day, -1, GetDate()), 'yyyy-MM-dd') + ' 08:30:00.000'
|
|
and CREATEDATE < format(GetDate(), 'yyyy-MM-dd') + ' 08:30:00.000'";
|
|
DataTable dataTable = GetDataTable(sql, Config.a3dbConnectionString);
|
|
|
|
|
|
return dataTable.Rows[0]["c"].ToString();
|
|
}
|
|
/// <summary>
|
|
/// 并线发运 A3每天产量
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static string GetA3DayYield()
|
|
{
|
|
|
|
string sql = $@" declare
|
|
@tt varchar(20) = format(GetDate(), 'HH:mm')
|
|
|
|
if @tt > '08:30'
|
|
select count(0) as c from T_AW_MAIN where CREATEDATE > format(GetDate(), 'yyyy-MM-dd') + ' 08:30:00.000'
|
|
and CREATEDATE < format(dateadd(day, 1, GetDate()), 'yyyy-MM-dd') + ' 08:30:00.000'
|
|
else
|
|
select count(0) as c from T_AW_MAIN where CREATEDATE > format(dateadd(day, -1, GetDate()), 'yyyy-MM-dd') + ' 08:30:00.000'
|
|
and CREATEDATE < format(GetDate(), 'yyyy-MM-dd') + ' 08:30:00.000'";
|
|
DataTable dataTable = GetDataTable(sql, Config.a3dbConnectionString);
|
|
|
|
|
|
return dataTable.Rows[0]["c"].ToString();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 并线发运 Bora高配每天产量
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static string GetBoraHDayYield()
|
|
{
|
|
|
|
string sql = $@" declare
|
|
@tt varchar(20) = format(GetDate(), 'HH:mm')
|
|
|
|
if @tt > '08:30'
|
|
select count(0) as c from (select a.* ,b.MATERIAL_NAME FROM T_AW_MAIN a left join T_MD_MATERIAL b on a.MATERIAL_CODE = b.MATERIAL_CODE where MATERIAL_NAME like '%豪华%' or MATERIAL_NAME like '%高配%' ) a
|
|
where CREATEDATE > format(GetDate(), 'yyyy-MM-dd') + ' 08:30:00.000'
|
|
and CREATEDATE < format(dateadd(day, 1, GetDate()), 'yyyy-MM-dd') + ' 08:30:00.000'
|
|
else
|
|
select count(0) as c from (select a.* ,b.MATERIAL_NAME FROM T_AW_MAIN a left join T_MD_MATERIAL b on a.MATERIAL_CODE = b.MATERIAL_CODE where MATERIAL_NAME like '%豪华%' or MATERIAL_NAME like '%高配%' ) a
|
|
where CREATEDATE > format(dateadd(day, -1, GetDate()), 'yyyy-MM-dd') + ' 08:30:00.000'
|
|
and CREATEDATE < format(GetDate(), 'yyyy-MM-dd') + ' 08:30:00.000'";
|
|
DataTable dataTable = GetDataTable(sql, Config.maindbConnectionString);
|
|
|
|
|
|
return dataTable.Rows[0]["c"].ToString();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 并线发运 Bora低配每天产量
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static string GetBoraLDayYield()
|
|
{
|
|
|
|
string sql = $@" declare
|
|
@tt varchar(20) = format(GetDate(), 'HH:mm')
|
|
|
|
if @tt > '08:30'
|
|
select count(0) as c from (select a.* ,b.MATERIAL_NAME FROM T_AW_MAIN a left join T_MD_MATERIAL b on a.MATERIAL_CODE = b.MATERIAL_CODE where MATERIAL_NAME like '%舒适%' or MATERIAL_NAME like '%低配%' ) a
|
|
where a.CREATEDATE > format(GetDate(), 'yyyy-MM-dd') + ' 08:30:00.000'
|
|
and a.CREATEDATE < format(dateadd(day, 1, GetDate()), 'yyyy-MM-dd') + ' 08:30:00.000'
|
|
else
|
|
select count(0) as c from (select a.* ,b.MATERIAL_NAME FROM T_AW_MAIN a left join T_MD_MATERIAL b on a.MATERIAL_CODE = b.MATERIAL_CODE where MATERIAL_NAME like '%舒适%' or MATERIAL_NAME like '%低配%' ) a
|
|
where a.CREATEDATE > format(dateadd(day, -1, GetDate()), 'yyyy-MM-dd') + ' 08:30:00.000'
|
|
and a.CREATEDATE < format(GetDate(), 'yyyy-MM-dd') + ' 08:30:00.000'";
|
|
DataTable dataTable = GetDataTable(sql, Config.maindbConnectionString);
|
|
|
|
|
|
return dataTable.Rows[0]["c"].ToString();
|
|
}
|
|
/// <summary>
|
|
/// 取消挂起
|
|
/// </summary>
|
|
/// <param name="dataRow"></param>
|
|
/// <returns></returns>
|
|
public static bool UpdateFisSetStateDisposes(List<DataRow> upRows)
|
|
{
|
|
List<string> orderNoList = upRows.Select(p => p.Field<string>("ORDER_NO")).ToList();
|
|
string updateSql = $"Update T_AW_FisSendState set State = 0,Remark='取消挂起' where FisOrderNo in ('{string.Join("','", orderNoList)}') and State=9 ";
|
|
bool returnVal = false;
|
|
try
|
|
{
|
|
//执行SQL
|
|
int count = SqlHelper.ExecuteNonQuery(Config.maindbConnectionString, CommandType.Text, updateSql);
|
|
|
|
if (count > 0)
|
|
{
|
|
returnVal = true;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//后续加入日志
|
|
throw;
|
|
}
|
|
|
|
return returnVal;
|
|
|
|
}
|
|
|
|
//public static bool UpdateFisSetStateDispose(DataRow dataRow)
|
|
//{
|
|
// string updateSql = $"Update T_AW_FisSendState set State = 0,Remark='取消挂起' where FisOrderNo ='{dataRow["ORDER_NO"]}' and State=9 ";
|
|
// bool returnVal = false;
|
|
// try
|
|
// {
|
|
// //执行SQL
|
|
// int count = SqlHelper.ExecuteNonQuery(Config.maindbConnectionString, CommandType.Text, updateSql);
|
|
|
|
// if (count > 0)
|
|
// {
|
|
// returnVal = true;
|
|
// }
|
|
// }
|
|
// catch (Exception ex)
|
|
// {
|
|
// //后续加入日志
|
|
// throw;
|
|
// }
|
|
|
|
// return returnVal;
|
|
|
|
//}
|
|
|
|
|
|
public static void SaveStartIndex(int startIndex)
|
|
{
|
|
try
|
|
{
|
|
string updateSql = $"Update T_MD_StartIndex set [StartIndex]={startIndex}";
|
|
int count = SqlHelper.ExecuteNonQuery(Config.maindbConnectionString, CommandType.Text, updateSql);
|
|
if (count == 0)
|
|
{
|
|
string insertSql = $" insert into T_MD_StartIndex(StartIndex) values ({startIndex})";
|
|
SqlHelper.ExecuteNonQuery(Config.maindbConnectionString, CommandType.Text, insertSql);
|
|
}
|
|
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
public static int GetStartIndex()
|
|
{
|
|
string searchSql = $"select top 1 StartIndex from T_MD_StartIndex ";
|
|
DataTable dataTable = GetDataTable(searchSql, Config.maindbConnectionString);
|
|
if (dataTable.Rows.Count == 0) return 0;
|
|
try
|
|
{
|
|
return int.Parse(dataTable.Rows[0]["StartIndex"].ToString());
|
|
}
|
|
catch
|
|
{
|
|
return 0;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|