天津投入产出系统后端
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.
 
 
 
 
 
 

1349 lines
55 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QMAPP.DAL;
using QMFrameWork.Data;
using QMAPP.FJC.Entity.FIS;
using QMFrameWork.Log;
using System.Data;
using System.Collections;
using Model;
namespace QMAPP.FJC.DAL.FrmPlace
{
/// <summary>
/// 模块编号:M20
/// 作 用:发运模块
/// 作 者:崔法宝
/// 编写日期:20170905
///</summary>
public class FrmPlaceDAL : BaseDAL
{
/// <summary>
/// 获得FIS发货信息信息(列表)
/// </summary>
/// <param name="pFisOrder"></param>
/// <param name="pFistype"></param>
/// <returns></returns>
public DataTable GetList(string pFistype, string WORKCENTER_CODE)
{
#region
try
{
DataTable returnDt = null;
StringBuilder strSql = new StringBuilder();
List<DataParameter> parameters = new List<DataParameter>();
strSql.Append(" SELECT TOP 1000 ");
strSql.Append(" 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.T_PP_FISORDER T1 ");
strSql.Append(" INNER JOIN dbo.T_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 + "' ");
strSql.Append(" AND T1.flagdel=0 ");
//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 ");
using (IDataSession session = AppDataFactory.CreateMainSession())
{
returnDt = session.GetTable(strSql.ToString(), parameters.ToArray());
}
//逻辑说明
//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
}
/// <summary>
/// 贴车单记录查询
/// </summary>
/// <param name="ppastercardno"></param>
/// <param name="strbegindate"></param>
/// <param name="strenddate"></param>
/// <param name="vinLack"></param>
/// <returns></returns>
public DataTable GetPastecardInfoWithVin(string ppastercardno, string strbegindate, string strenddate, string vinLack, string PlantCode, string Operator)
{
#region
StringBuilder strSql = new StringBuilder();
DataTable returnDt = null;
List<DataParameter> parameters = new List<DataParameter>();
strSql.Append(@"SELECT PID,PASTECARDNO, PLANTNAME,PASTECARDDATE,PASTECARDDATE2,OPERATOR, CASE PRODUCTIONNAME WHEN '01' THEN '混' ELSE '单' END AS PRODUCTIONNAME ,CREATETIME, CASE VINLACK WHEN '1' THEN '是' ELSE '否' END AS VINLACK FROM T_PP_PASTECARD ");
if (!string.IsNullOrEmpty(strbegindate) && !string.IsNullOrEmpty(strenddate))
{
strSql.Append(string.Format(" WHERE CREATETIME >='{0} 00:00:00' AND CREATETIME <= '{1} 23:59:59' ", strbegindate, strenddate));
if (vinLack == "1")
{
strSql.Append(string.Format(" AND VINLACK='{0}'", vinLack));
}
strSql.Append(string.Format(" AND FLAGDEL='0'"));
}
if (!string.IsNullOrEmpty(ppastercardno))
{
strSql.Append(string.Format(" AND PASTECARDNO='{0}' ", ppastercardno));
}
if (!string.IsNullOrEmpty(PlantCode))
{
strSql.Append(string.Format(" AND PLANTNAME='{0}' ", PlantCode));
}
if (!string.IsNullOrEmpty(Operator))
{
strSql.Append(string.Format(" AND OPERATOR='{0}' ", Operator));
}
strSql.Append(" ORDER BY CREATETIME desc");
using (IDataSession session = AppDataFactory.CreateMainSession())
{
returnDt = session.GetTable(strSql.ToString(), parameters.ToArray());
}
return returnDt;
#endregion
}
/// <summary>
/// 根据贴车单主键查询贴车单明细
/// </summary>
/// <param name="ppastercarKey"></param>
/// <returns></returns>
public DataTable GetPasteDetails(string ppastercarKey)
{
#region
StringBuilder strSql = new StringBuilder();
DataTable returnDt = null;
List<DataParameter> parameters = new List<DataParameter>();
//strSql.Append(@"SELECT ROWINDEX,VWSEQ,KIN,VIN,PRODNO,CARSETDESC_CN,CP5A,[LINENO],SANBARCODE,SCANDATE,PASTECARDNO,PRODUCTIONNAME,T_PP_PASTECARD.PASTE_CARD_KEY ");
//strSql.Append(@"FROM T_PP_PASCARDDETAILS,T_PP_PASTECARD,T_PM_FISORDER_YB ");
//strSql.Append(string.Format("WHERE T_PP_PASCARDDETAILS.FIS_KEY=T_PM_FISORDER_YB.FIS_KEY AND T_PP_PASTECARD.PASTE_CARD_KEY=T_PP_PASCARDDETAILS.PASTE_CARD_KEY AND T_PP_PASCARDDETAILS.PASTE_CARD_KEY='{0}' AND T_PP_PASCARDDETAILS.FLAGDEL='0' ORDER BY ROWINDEX", ppastercarKey));
strSql.Append(@" SELECT
t1.ROWINDEX,
t3.VWSEQ,
t3.KIN,
t3.VIN,
t3.PRODNO,
t3.CARSETDESC_CN,
t3.CP5A,
t3.[LINENO],
t1.SANBARCODE,
t1.SCANDATE,
t2.PASTECARDNO,
t2.PRODUCTIONNAME,
t2.pid AS PASTE_CARD_KEY
FROM T_PP_PASCARDDETAILS t1
inner join
T_PP_PASTECARD t2 on t2.PID= t1.PID
inner join
(
SELECT *
FROM dbo.T_PP_FISORDER T1
INNER JOIN dbo.T_PP_FISORDERSENDDETAIL T2
on t1.pid=T2.FIS_PID
)t3
on t1.pid=t3.pid ");
strSql.Append(string.Format("AND T1.pid='{0}' AND t1.FLAGDEL='0' ORDER BY t1.ROWINDEX ", ppastercarKey));
using (IDataSession session = AppDataFactory.CreateMainSession())
{
returnDt = session.GetTable(strSql.ToString(), parameters.ToArray());
}
return returnDt;
#endregion
}
/// <summary>
/// 根据贴车单ID获取详细
/// </summary>
/// <param name="ppastercarKey"></param>
/// <returns></returns>
public DataTable GetPascardDetailsByPid(string ppastercarKey)
{
#region
StringBuilder strSql = new StringBuilder();
DataTable returnDt = null;
List<DataParameter> parameters = new List<DataParameter>();
// strSql.Append(@" select t1.ROWINDEX,T2.VWSEQ,T2.VIN,T2.PRODNO,T2.CARSETDESC_CN ,T2.CP5A,t2.[LINENO],t2.PASTECARDNO from T_PP_PASCARDDETAILS t1
// INNER JOIN
// (
//
// SELECT T11.pid ,T11.[LINENO],T11.VWSEQ,t11.VIN,t11.PRODNO,t11.CARSETDESC_CN,t11.CP5A
// FROM dbo.T_PP_FISORDER T11
// INNER JOIN dbo.T_PP_FISORDERSENDDETAIL T22
// on T11.PID=T22.FIS_PID
// ) t2 ON t1.FISDETAILID=t2.PID and t1.PASTECARDID='" + ppastercarKey.ToString() + "' ");
strSql.AppendLine("SELECT D.ROWINDEX ");
strSql.AppendLine(" ,F.VWSEQ ");
strSql.AppendLine(" ,F.VIN ");
strSql.AppendLine(" ,F.PRODNO ");
strSql.AppendLine(" ,F.CARSETDESC_CN ");
strSql.AppendLine(" ,F.CP5A ");
strSql.AppendLine(" ,F.[LINENO] ");
strSql.AppendLine(" ,C.PASTECARDNO ");
strSql.AppendLine(" FROM T_PP_PASCARDDETAILS AS D ");
strSql.AppendLine(" LEFT JOIN T_PP_FISORDER AS F ");
strSql.AppendLine(" ON F.PID=D.FISDETAILID ");
strSql.AppendLine(" LEFT JOIN T_PP_PASTECARD AS C ");
strSql.AppendLine(" ON C.PID=D.PASTECARDID ");
strSql.AppendLine(" WHERE PASTECARDID='" + ppastercarKey.ToString() + "' ");
strSql.AppendLine(" ORDER BY ROWINDEX,CP5A,VWSEQ,PRODNO");
using (IDataSession session = AppDataFactory.CreateMainSession())
{
returnDt = session.GetTable(strSql.ToString(), parameters.ToArray());
}
return returnDt;
#endregion
}
/// <summary>
/// 获取贴车单当天的总条数
/// </summary>
/// <returns></returns>
public DataTable GetPastecardNo(string strcreatetime)
{
#region
StringBuilder strSql = new StringBuilder();
DataTable returnDt = null;
List<DataParameter> parameters = new List<DataParameter>();
strSql.Append(@"SELECT COUNT(*)+1 FROM T_PP_PASTECARD ");
strSql.Append(string.Format(" WHERE CREATETIME>='{0} 00:00:00' AND CREATETIME<='{0} 23:59:59' AND FLAGDEL='0' ", strcreatetime));
using (IDataSession session = AppDataFactory.CreateMainSession())
{
returnDt = session.GetTable(strSql.ToString(), parameters.ToArray());
}
return returnDt;
#endregion
}
public int UpdatePasteCardPasteCardDate2Value(string PASTECARDNO, string PasteCarddate2, string OPERATOR)
{
try
{
StringBuilder strSql = new StringBuilder();
strSql.AppendFormat(" update T_PP_PASTECARD set PasteCarddate2='" + PasteCarddate2 + "' , OPERATOR='" + OPERATOR + "' WHERE PASTECARDNO='" + PASTECARDNO + "'");
using (IDataSession session = AppDataFactory.CreateMainSession())
{
return session.ExecuteSql(strSql.ToString());
}
}
catch (System.Exception ex)
{
throw ex;
}
}
/// <summary>
/// 获取发车信息
/// </summary>
/// <returns></returns>
public DataTable GetPastecardIndex(string PLANTNAME, string PASTECARDNO)
{
#region
StringBuilder strSql = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
DataTable returnDt = null;
List<DataParameter> parameters = new List<DataParameter>();
strSql.Append(" SELECT PASTECARDNO,PASTECARDDATE,PLANTCODE,PLANTNAME FROM T_DAS_PASTE_CARDINDEX");
if (PLANTNAME != "")
{
whereBuilder.Append(" AND PLANTNAME = '" + PLANTNAME + "'");
}
if (PASTECARDNO != "")
{
whereBuilder.Append(" AND PASTECARDNO like '%" + PASTECARDNO + "%'");
}
if (whereBuilder.Length > 0)
{
strSql.Append(" WHERE " + whereBuilder.ToString().Substring(4));
}
strSql.Append(" ORDER BY PLANTCODE ASC");
using (IDataSession session = AppDataFactory.CreateMainSession())
{
returnDt = session.GetTable(strSql.ToString(), parameters.ToArray());
}
return returnDt;
#endregion
}
/// <summary>
/// 获取贴车明细单当天的总条数
/// </summary>
/// <returns></returns>
public DataTable GetPastecardDeatis()
{
#region
StringBuilder strSql = new StringBuilder();
DataTable returnDt = null;
List<DataParameter> parameters = new List<DataParameter>();
strSql.Append(@"SELECT COUNT(*)+1 FROM T_PP_PASCARDDETAILS ");
strSql.Append(string.Format(" WHERE SCANDATE>='{0} 00:00:00' AND SCANDATE<='{0} 23:59:59' AND FLAGDEL='0'", DateTime.Now.ToShortDateString()));
using (IDataSession session = AppDataFactory.CreateMainSession())
{
returnDt = session.GetTable(strSql.ToString(), parameters.ToArray());
}
//return SqlHelper.QueryReturnDataTable(strSql.ToString());
return returnDt;
#endregion
}
/// <summary>
/// 获取下护板扫描表其他条码号
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public DataTable GetOhterCode(string code)
{
#region
try
{
List<DataParameter> parameters = new List<DataParameter>();
string strSql = string.Format(@"SELECT OTHERCODE,SENDED FROM T_AW_PRODUCT WHERE SCANCODE='{0}'", code);
using (IDataSession session = AppDataFactory.CreateMainSession())
{
return session.GetTable(strSql.ToString(), parameters.ToArray());
}
}
catch (Exception ex)
{
throw ex;
}
#endregion
}
private string UpdateFISORDERSENDDETAIL(string FIS_PID)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("UPDATE T_PP_FISORDERSENDDETAIL SET state='1' WHERE FIS_PID='" + FIS_PID + "'");
return strSql.ToString();
}
/// <summary>
/// 生成贴车单明细SQL
/// </summary>
/// <param name="pdecard"></param>
/// <returns></returns>
private string Insertdetailcard(int rowindex, EPasteDetailsCard pdecard)
{
#region
StringBuilder strSql = new StringBuilder();
StringBuilder strFields = new StringBuilder();
StringBuilder strValues = new StringBuilder();
strFields.Append(" PID ,");
strFields.Append(" FISDETAILID ,");
strFields.Append(" PASTECARDID, ");
strFields.Append(" SANBARCODE, ");
strFields.Append(" SCANDATE,");
strFields.Append(" ROWINDEX,");
strFields.Append(" FLAGDEL ");
strValues.Append("'" + pdecard.PASTEDETAILED_CARD_KEY + "',");
strValues.Append("'" + pdecard.FIS_KEY + "',");
strValues.Append("'" + pdecard.PASTE_CARD_KEY + "',");
strValues.Append("'" + pdecard.SANBARCODE + "',");
strValues.Append("'" + pdecard.SCANDATE + "',");
strValues.Append("'" + rowindex + "',");
strValues.Append("'0'");
strSql.Append(" INSERT INTO T_PP_PASCARDDETAILS ");
strSql.Append(" (" + strFields.ToString() + ")");
strSql.Append(" VALUES ");
strSql.Append(" (" + strValues.ToString() + ")");
return strSql.ToString();
#endregion
}
/// <summary>
/// 获取配置表中的规则类型值
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public DataTable GetRule(string cartype, string nf)
{
#region
try
{
//string nfcheck = string.Format(@"SELECT COUNT(*) FROM T_DCS_FISCHECKRULE WHERE CARTYPE='{0}' AND BINDINGTYPE = '{1}'", cartype, nf);
//int count = (int)SqlHelper.GetSingle(nfcheck);
//if (count > 0)
//{
// string strSql = string.Format(@"SELECT BINDINGTYPE, BINDINGVALUE AS OTHERCODE FROM T_DCS_FISCHECKRULE WHERE CARTYPE='{0}' AND BINDINGTYPE <>'下护板'", cartype);
// return SqlHelper.QueryReturnDataTable(strSql.ToString());
//}
//return null;
DataTable dt = new DataTable();
List<DataParameter> parameters = new List<DataParameter>();
string strSql = string.Format(@"SELECT BINDINGTYPE, BINDINGVALUE AS OTHERCODE FROM T_DCS_FISCHECKRULE WHERE CARTYPE='{0}'", cartype);
using (IDataSession session = AppDataFactory.CreateMainSession())
{
dt = session.GetTable(strSql.ToString(), parameters.ToArray());
}
return dt;
}
catch (Exception ex)
{
throw ex;
}
#endregion
}
/// <summary>
/// 根据条码标识查询零件信息
/// </summary>
/// <param name="strbarcode"></param>
/// <returns></returns>
public DataTable GetSparepartsinfo(string strbarcode)
{
#region
StringBuilder strSql = new StringBuilder();
List<DataParameter> parameters = new List<DataParameter>();
strSql.Append(@"SELECT CUSTOMERSPAREPARTS,BARCODEIDENTIFICATION,VEHICLETYPE,CODENAME FROM T_DAS_SPAREPARTS_INFO ,T_QM_CODE ");
strSql.Append(@"WHERE T_DAS_SPAREPARTS_INFO.VEHICLETYPE= T_QM_CODE.CODENUM AND T_QM_CODE.CODE='101' ");
strSql.Append(string.Format(" AND T_DAS_SPAREPARTS_INFO.FLAGDEL='0' AND BARCODEIDENTIFICATION='{0}' ", strbarcode));
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//dt = session.GetTable(strSql.ToString(), parameters.ToArray());
return session.GetTable(strSql.ToString(), parameters.ToArray());
}
#endregion
}
/// <summary>
/// 实现校准功能
/// </summary>
/// <param name="strvwseq"></param>
public void UpdateFisOrder(string strvwseq, string strCP5A, string workcenter)
{
#region
StringBuilder strSql = new StringBuilder();
StringBuilder strSql2 = new StringBuilder();
//增加更新数据的条件: LEFT(VWSEQ,2)='{0}' AND ,需按单线或混线更新数据。MODIFIED BY SUUN GQ ON 20130330.
// StringBuilder deleteSql = new StringBuilder();
// // strSql.Append(string.Format(@"UPDATE T_PP_FISORDERSENDDETAIL SET SCANSTATE=2 WHERE LEFT(VWSEQ,2)='{0}' AND CP5A <= '{1}' AND SCANSTATE=0 AND FLAGDEL='0'", strvwseq.Substring(0, 2), strCP5A));
// strSql.Append(string.Format(@"update T_PP_FISORDERSENDDETAIL set STATE='2' where FIS_PID in (
// select PID from T_PP_FISORDER where LEFT(VWSEQ,2)='{0}' AND CP5A <= '{1}' AND SCANSTATE=0 AND FLAGDEL='0' )", strvwseq.Substring(0, 2), strCP5A));
// strSql2.Append(string.Format(@" UPDATE dbo.T_PP_FISORDER
// SET SCANSTATE=(SELECT MIN(STATE) AS STATE FROM dbo.T_PP_FISORDERSENDDETAIL WHERE FIS_pid in (SELECT pid from T_PP_FISORDER WHERE LEFT(VWSEQ,2)='{0}' AND CP5A <= '{1}' AND SCANSTATE=0 AND FLAGDEL='0' ) )
// WHERE LEFT(VWSEQ,2)='{0}' AND CP5A <= '{1}' AND SCANSTATE=0 AND FLAGDEL='0' ", strvwseq.Substring(0, 2), strCP5A));
//deleteSql.Append(string.Format(@"delete from T_PP_FISORDER WHERE LEFT(VWSEQ,2)='{0}' AND CP5A <= '{1}' AND SCANSTATE=0 AND FLAGDEL='0'", strvwseq.Substring(0, 2), strCP5A));
strSql.AppendLine("UPDATE T_PP_FISORDERSENDDETAIL ");
strSql.AppendLine("SET STATE=3 ");
strSql.AppendLine("WHERE FIS_PID IN(SELECT F.PID ");
strSql.AppendLine(" FROM T_PP_FISORDER AS F ");
strSql.AppendLine(" LEFT JOIN T_PP_FISORDERSENDDETAIL AS D ");
strSql.AppendLine(" ON D.FIS_PID=F.PID ");
strSql.AppendFormat(" WHERE F.CP5A<='{0}'", strCP5A);
strSql.AppendFormat(" AND D.WORKCENTER_CODE='{0}'", workcenter);
strSql.AppendLine(" AND F.SCANSTATE='0') ");
strSql2.AppendLine("UPDATE T_PP_FISORDER ");
strSql2.AppendLine("SET SCANSTATE=3 ");
strSql2.AppendLine("WHERE PID IN(SELECT F.PID");
strSql2.AppendLine(" FROM T_PP_FISORDER AS F");
strSql2.AppendLine(" LEFT JOIN T_PP_FISORDERSENDDETAIL AS D");
strSql2.AppendLine(" ON D.FIS_PID=F.PID ");
strSql2.AppendFormat(" WHERE F.CP5A<='{0}'", strCP5A);
strSql2.AppendFormat(" AND D.WORKCENTER_CODE='{0}'", workcenter);
strSql2.AppendLine(" AND F.SCANSTATE='0')");
using (IDataSession session = AppDataFactory.CreateMainSession())
{
session.ExecuteSql(strSql.ToString());
session.ExecuteSql(strSql2.ToString());
//session.ExecuteSql(deleteSql.ToString());
}
//SqlHelper.ExecuteSqlTran(sqlList);
#endregion
}
/// <summary>
/// 更新FIS队列表。
/// </summary>
/// <returns></returns>
private string updateFisOrder(string pfiskey)
{
#region
StringBuilder strSql = new StringBuilder();
strSql.Append(string.Format(" UPDATE T_PP_FISORDER SET SCANSTATE =1 WHERE PID= '{0}' AND FLAGDEL='0' ", pfiskey));
// strSql.Append(string.Format(@" UPDATE dbo.T_PP_FISORDER
// SET SCANSTATE=(SELECT MIN(STATE) AS STATE FROM dbo.T_PP_FISORDERSENDDETAIL WHERE FIS_pid= '{0}' )
// WHERE PID= '{0}' AND FLAGDEL='0' ", pfiskey));
return strSql.ToString();
#endregion
}
private string updateProduct(string product_pid)
{
#region
StringBuilder strSql = new StringBuilder();
strSql.Append(string.Format(@" UPDATE t_aw_product
SET OUTFLAG='1'
WHERE PID='{0}' ", product_pid));
return strSql.ToString();
#endregion
}
private string updateProduct(string product_pid, string vin, string kin, string seq)
{
#region
StringBuilder strSql = new StringBuilder();
string vin_rev = "";
if (!string.IsNullOrWhiteSpace(vin))
{
vin_rev = new string(vin.Reverse().ToArray());
}
strSql.Append(string.Format(@" UPDATE t_aw_product
SET OUTFLAG='1',VIN='{1}',VIN_REV='{4}',KIN='{2}',VWSEQ='{3}'
WHERE PID='{0}' ", product_pid, vin, kin, seq, vin_rev));
return strSql.ToString();
#endregion
}
/// <summary>
/// 删除FIS发运表
/// </summary>
/// <param name="pfiskey"></param>
/// <returns></returns>
private string DeleteSPFisOrder(string pfiskey)
{
#region
StringBuilder strSql = new StringBuilder();
strSql.Append(string.Format(" delete from T_PP_FISORDER WHERE PID= '{0}' AND FLAGDEL='0' ", pfiskey));
return strSql.ToString();
#endregion
}
public string UpdateScan(string scancode)
{
#region
try
{
string strSql = string.Format(@"UPDATE T_AW_PRODUCT SET SENDED='1' WHERE SCANCODE='{0}'", scancode);
return strSql;
}
catch (Exception ex)
{
throw ex;
}
#endregion
}
/// <summary>
/// 添加贴车单
/// </summary>
/// <param name="ppastecard"></param>
/// <param name="pDetailsCard"></param>
/// <returns></returns>
public int AddPasteCard(EPasteCard ppastecard)
{
#region
try
{
#region 判断是否出现底盘号情况
if (ppastecard.DetailsCardlist.Count == 1)
{
ppastecard.VINLACK = "0";
}
else
{
int firstVin = Convert.ToInt32(ppastecard.DetailsCardlist[0].VIN.Substring(10, 7));
int lastVin = Convert.ToInt32(ppastecard.DetailsCardlist[ppastecard.DetailsCardlist.Count - 1].VIN.Substring(10, 7));
if ((lastVin - firstVin) == ppastecard.DetailsCardlist.Count - 1)
{
ppastecard.VINLACK = "0";
}
else
{
ppastecard.VINLACK = "1";
}
}
#endregion
DataTable tbl = GetPastecardDeatis();
int strindex = 0;
int reindex = 0;
if (tbl != null)
{
strindex = int.Parse(tbl.Rows[0][0].ToString());
reindex = strindex;
}
ArrayList sqllist = new ArrayList();
StringBuilder strSql = new StringBuilder();
StringBuilder strFields = new StringBuilder();
StringBuilder strValues = new StringBuilder();
strFields.Append(" PID ,");
strFields.Append(" PASTECARDNO ,");
strFields.Append(" PASTECARDDATE, ");
strFields.Append(" PASTECARDDATE2, ");
strFields.Append(" OPERATOR, ");
strFields.Append(" PRODUCTIONNAME, ");
strFields.Append(" CREATETIME, ");
strFields.Append(" VINLACK, ");
strFields.Append(" FLAGDEL, ");
strFields.Append(" PLANTNAME ");
//strValues.Append(" '" + pLog.LOGDATE + "',");
strValues.Append("'" + ppastecard.PASTE_CARD_KEY + "',");
strValues.Append("'" + ppastecard.PASTECARDNO + "',");
strValues.Append("'" + ppastecard.PASTECARDDATE + "',");
strValues.Append("'" + ppastecard.PASTECARDDATE2 + "',");
strValues.Append("'" + ppastecard.OPERATOR + "',");
strValues.Append("'" + ppastecard.PRODUCTIONNAME + "',");
strValues.Append("'" + ppastecard.CREATETIME + "',");
strValues.Append("'" + ppastecard.VINLACK + "',");
strValues.Append("'0',");
strValues.Append("'" + ppastecard.PLANTNAME + "'");
strSql.Append(" INSERT INTO T_PP_PASTECARD ");
strSql.Append(" (" + strFields.ToString() + ")");
strSql.Append(" VALUES ");
strSql.Append(" (" + strValues.ToString() + ")");
StringBuilder strSqllog = new StringBuilder();
StringBuilder strFieldslog = new StringBuilder();
StringBuilder strValueslog = new StringBuilder();
strFieldslog.Append(" TID ,");
strFieldslog.Append(" FCT_OPERTYPE ,");
strFieldslog.Append(" FCT_NO, ");
strFieldslog.Append(" FCT_REASON, ");
strFieldslog.Append(" FCT_DATE, ");
strFieldslog.Append(" FCT_OPER, ");
strFieldslog.Append(" FLAGDEL ");
//strValues.Append(" '" + pLog.LOGDATE + "',");
strValueslog.Append("'" + ppastecard.FailLog.TID + "',");
strValueslog.Append("'" + ppastecard.FailLog.FCT_OPERTYPE + "',");
strValueslog.Append("'" + ppastecard.FailLog.FCT_NO + "',");
strValueslog.Append("'" + ppastecard.FailLog.FCT_REASON + "',");
strValueslog.Append("'" + ppastecard.FailLog.FCT_DATE + "',");
strValueslog.Append("'" + ppastecard.FailLog.FCT_OPER + "',");
strValueslog.Append("'0'");
strSqllog.Append(" INSERT INTO T_DAS_FAILCODE ");
strSqllog.Append(" (" + strFieldslog.ToString() + ")");
strSqllog.Append(" VALUES ");
strSqllog.Append(" (" + strValueslog.ToString() + ")");
sqllist.Add(strSqllog.ToString());
sqllist.Add(strSql.ToString());
foreach (EPasteDetailsCard decard in ppastecard.DetailsCardlist)
{
int rowindex = strindex;
string strinsertsql = Insertdetailcard(rowindex, decard);
string updatesql = updateFisOrder(decard.FIS_KEY);
string deleteSql = DeleteSPFisOrder(decard.FIS_KEY);
sqllist.Add(strinsertsql);
//更新FIS原表T_PM_FISORDER_YB
sqllist.Add(updatesql);
//删除FIS发货表T_PP_FISORDER(错误)(瞎说)
//DCS系统存储FIS要货信息时存了两张表,MES只存了一张
//sqllist.Add(deleteSql);
//2016-9-13 闫永刚更新
if (decard.SANBARCODE.Substring(0, 2) == "xxxxx")
{
string updateScanBarCodesql = UpdateScan(decard.SANBARCODE);
sqllist.Add(updateScanBarCodesql);
}
strindex++;
}
//2016-10-31 闫永刚
//更新发货单记录表
sqllist.Add(string.Format("update T_DAS_PASTE_CARDINDEX set PASTECARDNO='{0}',PASTECARDDATE='{1}' where PLANTNAME='{2}'", ppastecard.PASTECARDNO, System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), ppastecard.PLANTNAME));
for (var i = 0; i < sqllist.Count; i++)
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
session.ExecuteSql(sqllist[i].ToString());
}
}
// SqlHelper.ExecuteSqlTran(sqllist);
return reindex;
}
catch (System.Exception ex)
{
throw ex;
}
#endregion
}
/// <summary>
/// 添加贴车单
/// </summary>
/// <param name="ppastecard"></param>
/// <param name="pDetailsCard"></param>
/// <returns></returns>
public int AddNewPasteCard(EPasteCard ppastecard)
{
try
{
#region 获取贴车单序列号
string indexNumber = string.Format("select PASTECARDNO from T_DAS_PASTE_CARDINDEX where PLANTNAME='{0}'", ppastecard.PLANTNAME);
string pastCardNo = "";
using (IDataSession session = AppDataFactory.CreateMainSession())
{
pastCardNo = Convert.ToString(session.ExecuteSqlScalar(indexNumber, new List<DataParameter>().ToArray()));
}
if (pastCardNo.Substring(ppastecard.PLANTNAME.Length, 8)
== System.DateTime.Now.ToString("yyyyMMdd"))
{
int numberIndex = Convert.ToInt32(pastCardNo.Substring(ppastecard.PLANTNAME.Length + 8, 4));
pastCardNo = pastCardNo.Substring(0, ppastecard.PLANTNAME.Length + 8) + (numberIndex + 1).ToString().PadLeft(4, '0');
}
else
{
pastCardNo = pastCardNo.Substring(0, ppastecard.PLANTNAME.Length) + System.DateTime.Now.ToString("yyyyMMdd") + "0001";
}
#endregion
if (ppastecard.DetailsCardlist.Count == 1)
{
ppastecard.VINLACK = "0";
}
else
{
int firstVin = Convert.ToInt32(ppastecard.DetailsCardlist[0].VIN.Substring(10, 7));
int lastVin = Convert.ToInt32(ppastecard.DetailsCardlist[ppastecard.DetailsCardlist.Count - 1].VIN.Substring(10, 7));
if ((lastVin - firstVin) == ppastecard.DetailsCardlist.Count - 1)
{
ppastecard.VINLACK = "0";
}
else
{
ppastecard.VINLACK = "1";
}
}
DataTable tbl = GetPastecardDeatis();
int strindex = 0;
int reindex = 0;
if (tbl != null)
{
strindex = int.Parse(tbl.Rows[0][0].ToString());
reindex = strindex;
}
ArrayList sqllist = new ArrayList();
ArrayList sqllistMP4 = new ArrayList();
StringBuilder strSql = new StringBuilder();
StringBuilder strFields = new StringBuilder();
StringBuilder strValues = new StringBuilder();
strFields.Append(" PID ,");
strFields.Append(" PASTECARDNO ,");
strFields.Append(" PASTECARDDATE, ");
strFields.Append(" PASTECARDDATE2, ");
strFields.Append(" OPERATOR, ");
strFields.Append(" PRODUCTIONNAME, ");
strFields.Append(" CREATETIME, ");
strFields.Append(" VINLACK, ");
strFields.Append(" FLAGDEL, ");
strFields.Append(" PLANTNAME ");
strValues.Append("'" + ppastecard.PASTE_CARD_KEY + "',");
strValues.Append("'" + pastCardNo + "',");
strValues.Append("'" + ppastecard.PASTECARDDATE + "',");
strValues.Append("'" + ppastecard.PASTECARDDATE2 + "',");
strValues.Append("'" + ppastecard.OPERATOR + "',");
strValues.Append("'" + ppastecard.PRODUCTIONNAME + "',");
ppastecard.CREATETIME = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
strValues.Append("'" + ppastecard.CREATETIME + "',");
strValues.Append("'" + ppastecard.VINLACK + "',");
strValues.Append("'0',");
strValues.Append("'" + ppastecard.PLANTNAME + "'");
strSql.Append(" INSERT INTO T_PP_PASTECARD ");
strSql.Append(" (" + strFields.ToString() + ")");
strSql.Append(" VALUES ");
strSql.Append(" (" + strValues.ToString() + ")");
sqllist.Add(strSql.ToString());
List<DataParameter> parameters = new List<DataParameter>();
foreach (EPasteDetailsCard decard in ppastecard.DetailsCardlist)
{
int rowindex = strindex;
string strinsertsql = Insertdetailcard(rowindex, decard);
string updatesql = UpdateFISORDERSENDDETAIL(decard.FIS_KEY);
string updatesql2 = updateFisOrder(decard.FIS_KEY);
string updatesql3 = updateProduct(decard.PRODUCT_PID, decard.VIN, decard.KIN, decard.VWSEQ);
sqllist.Add(strinsertsql.ToString());
sqllist.Add(updatesql.ToString());
sqllist.Add(updatesql2.ToString());
var TABLE = new DataTable();
using (IDataSession session = AppDataFactory.CreateMainSession())
{
TABLE = session.GetTable($"select * from T_AW_PRODUCT where PID = '{decard.PRODUCT_PID}'", parameters.ToArray());
}
if (TABLE.Rows.Count > 0)
{
sqllist.Add(updatesql3.ToString());
}
else
{
sqllistMP4.Add(updatesql3.ToString());
}
strindex++;
}
//2016-10-31 闫永刚
//更新发货单记录表
sqllist.Add(string.Format("update T_DAS_PASTE_CARDINDEX set PASTECARDNO='{0}',PASTECARDDATE='{1}' where PLANTNAME='{2}'", pastCardNo, System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), ppastecard.PLANTNAME));
for (var i = 0; i < sqllist.Count; i++)
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
session.ExecuteSql(sqllist[i].ToString());
}
}
for (var i = 0; i < sqllistMP4.Count; i++)
{
using (IDataSession session = AppDataFactory.CreateSession("maindbBC316_MP4"))
{
session.ExecuteSql(sqllistMP4[i].ToString());
}
}
return reindex;
}
catch (System.Exception ex)
{
throw ex;
}
}
/// <summary>
/// 更新贴车单信息
/// </summary>
/// <param name="UpdatePastecardIndex"></param>
/// <param name="dt"></param>
public int UpdatePastecardIndex(string UpdatePastecardIndex, System.DateTime dt, string Plantname)
{
#region
try
{
StringBuilder strSql = new StringBuilder();
strSql.AppendFormat(" update T_DAS_PASTE_CARDINDEX set PASTECARDNO='{0}',PASTECARDDATE='{1}' where plantname='{2}'", UpdatePastecardIndex, dt.ToString("yyyy-MM-dd HH:mm:ss"), Plantname);
//SqlHelper.ExecuteSql(strSql.ToString());
using (IDataSession session = AppDataFactory.CreateMainSession())
{
return session.ExecuteSql(strSql.ToString());
}
}
catch (System.Exception ex)
{
throw ex;
}
#endregion
}
/// <summary>
/// 判断条码是否重复
/// </summary>
/// <param name="barcodetime"></param>
/// <returns></returns>
public DataTable ExistBarcode(int barcodetime, string pbarcode)
{
StringBuilder strSql = new StringBuilder();
strSql.Append(@"SELECT SANBARCODE FROM T_PP_PASCARDDETAILS ");
List<DataParameter> parameters = new List<DataParameter>();
DateTime dtime = DateTime.Now;
string bdatetime = dtime.AddDays(-barcodetime).ToShortDateString();
strSql.Append(string.Format(" WHERE SANBARCODE='{2}' AND SCANDATE>='{0} 00:00:00' and SCANDATE<='{1} 23:59:59' AND FLAGDEL='0' ", bdatetime, DateTime.Now.ToShortDateString(), pbarcode));
using (IDataSession session = AppDataFactory.CreateMainSession())
{
return session.GetTable(strSql.ToString(), parameters.ToArray());
}
}
/// <summary>
/// 打印条码
/// </summary>
/// <param name="barcodetime"></param>
/// <returns></returns>
public DataTable WriteFile(string sql)
{
List<DataParameter> parameters = new List<DataParameter>();
using (IDataSession session = AppDataFactory.CreateMainSession())
{
return session.GetTable(sql.ToString(), parameters.ToArray());
}
}
/// <summary>
/// 更新贴车单补打印时间
/// </summary>
/// <param name="pastecardno"></param>
public void UpdataBarcodeDate(string pastecardno)
{
StringBuilder strSql = new StringBuilder();
strSql.Append(string.Format("UPDATE T_PP_PASTECARD SET PASTECARDDATE2='{0}' WHERE PASTECARDNO='{1}'", DateTime.Now.ToString(), pastecardno));
using (IDataSession session = AppDataFactory.CreateMainSession())
{
session.ExecuteSql(strSql.ToString());
}
}
public void InsertLog(EFailLog plog)
{
StringBuilder strSqllog = new StringBuilder();
StringBuilder strFieldslog = new StringBuilder();
StringBuilder strValueslog = new StringBuilder();
strFieldslog.Append(" TID ,");
strFieldslog.Append(" FCT_OPERTYPE ,");
strFieldslog.Append(" FCT_NO, ");
strFieldslog.Append(" FCT_REASON, ");
strFieldslog.Append(" FCT_DATE, ");
strFieldslog.Append(" FCT_OPER, ");
strFieldslog.Append(" FLAGDEL ");
//strValues.Append(" '" + pLog.LOGDATE + "',");
strValueslog.Append("'" + plog.TID + "',");
strValueslog.Append("'" + plog.FCT_OPERTYPE + "',");
strValueslog.Append("'" + plog.FCT_NO + "',");
strValueslog.Append("'" + plog.FCT_REASON + "',");
strValueslog.Append("'" + plog.FCT_DATE + "',");
strValueslog.Append("'" + plog.FCT_OPER + "',");
strValueslog.Append("'0'");
strSqllog.Append(" INSERT INTO T_DAS_FAILCODE ");
strSqllog.Append(" (" + strFieldslog.ToString() + ")");
strSqllog.Append(" VALUES ");
strSqllog.Append(" (" + strValueslog.ToString() + ")");
using (IDataSession session = AppDataFactory.CreateMainSession())
{
session.ExecuteSql(strSqllog.ToString());
}
}
/// <summary>
/// 获取扫取条形码是否存在
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public int GetExitsCode(string code)
{
#region
try
{
object result;
List<DataParameter> parameters = new List<DataParameter>();
string strSql = string.Format(@"SELECT count(1) as NUM FROM dbo.T_AW_PRODUCT where PRODUCTCODE='{0}'", code);
using (IDataSession session = AppDataFactory.CreateMainSession())
{
result = session.ExecuteSqlScalar(strSql.ToString(), parameters.ToArray());
}
return Convert.ToInt32(result);
}
catch (Exception ex)
{
throw ex;
}
#endregion
}
/// <summary>
/// 查询是否为成品
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public object GetExitsStatus(string code)
{
#region
try
{
object result;
List<DataParameter> parameters = new List<DataParameter>();
string strSql = string.Format(@"SELECT Status FROM dbo.T_AW_PRODUCT where PRODUCTCODE='{0}'", code);
using (IDataSession session = AppDataFactory.CreateMainSession())
{
result = session.ExecuteSqlScalar(strSql.ToString(), parameters.ToArray());
}
return result;
}
catch (Exception ex)
{
throw ex;
}
#endregion
}
/// <summary>
/// 获取工作中心
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public DataTable GetWORKCENTERCODE()
{
#region
try
{
DataTable result;
List<DataParameter> parameters = new List<DataParameter>();
string strSql = "SELECT [WORKCENTER_CODE],[WORKCENTER_NAME] FROM [T_MD_WORKCENTER] WHERE CENTER_TYPE='1'";
using (IDataSession session = AppDataFactory.CreateMainSession())
{
result = session.GetTable(strSql.ToString(), parameters.ToArray());
}
return result;
}
catch (Exception ex)
{
throw ex;
}
#endregion
}
///// <summary>
///// 更新index表
///// </summary>
///// <param name="id"></param>
///// <returns></returns>
//public DataTable GetWORKCENTERCODE()
//{
// #region
// try
// {
// DataTable result;
// List<DataParameter> parameters = new List<DataParameter>();
// string strSql = "select WORKCENTER_CODE from dbo.T_PP_FISORDERSENDDETAIL group by WORKCENTER_CODE";
// using (IDataSession session = AppDataFactory.CreateMainSession())
// {
// result = session.GetTable(strSql.ToString(), parameters.ToArray());
// }
// return result;
// }
// catch (Exception ex)
// {
// throw ex;
// }
// #endregion
//}
/// <summary>
/// 获取 DASPASTECARDINDEX表数据
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public DataTable GetDaspssteCarIndexByPlanName(string PlanTName)
{
#region
try
{
DataTable result;
List<DataParameter> parameters = new List<DataParameter>();
string strSql = "select PASTECARDNO,PASTECARDDATE,PLANTCODE, PLANTNAME from T_DAS_PASTE_CARDINDEX where PLANTNAME='" + PlanTName + "'";
using (IDataSession session = AppDataFactory.CreateMainSession())
{
result = session.GetTable(strSql.ToString(), parameters.ToArray());
}
return result;
}
catch (Exception ex)
{
throw ex;
}
#endregion
}
/// <summary>
/// 插入 DASPASTECARDINDEX表数据
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public int InsertDaspssteCarIndexByPlanName(EPasteCard ppastecard)
{
try
{
int result;
List<DataParameter> parameters = new List<DataParameter>();
StringBuilder strSql = new StringBuilder();
StringBuilder strFields = new StringBuilder();
StringBuilder strValues = new StringBuilder();
strFields.Append(" PID ,");
strFields.Append(" PASTECARDNO ,");
strFields.Append(" PASTECARDDATE, ");
strFields.Append(" PLANTCODE, ");
strFields.Append(" PLANTNAME ");
strValues.Append("'" + ppastecard.PASTE_CARD_KEY + "',");
strValues.Append("'" + ppastecard.PASTECARDNO + "',");
strValues.Append("'" + ppastecard.PASTECARDDATE + "',");
strValues.Append("'" + ppastecard.PRODUCTIONNAME + "',");
strValues.Append("'" + ppastecard.PLANTNAME + "'");
strSql.Append(" INSERT INTO T_DAS_PASTE_CARDINDEX ");
strSql.Append(" (" + strFields.ToString() + ")");
strSql.Append(" VALUES ");
strSql.Append(" (" + strValues.ToString() + ")");
using (IDataSession session = AppDataFactory.CreateMainSession())
{
result = session.ExecuteSql(strSql.ToString(), parameters.ToArray());
}
return result;
}
catch (Exception ex)
{
throw ex;
}
}
public DataTable GetLastPastCard()
{
try
{
#region
DataTable result;
StringBuilder strSql = new StringBuilder();
List<DataParameter> parameters = new List<DataParameter>();
strSql.Append(@"SELECT [TIMEOUT_KEY] ,[TIMEOUT_TYPE],[TIMEOUT_VALUE],[FLAGDEL] FROM [T_DCS_TIMEOUT_SET] ");
using (IDataSession session = AppDataFactory.CreateMainSession())
{
result = session.GetTable(strSql.ToString(), parameters.ToArray());
}
return result;
#endregion
}
catch (System.Exception ex) { throw ex; } } } }