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.TianJin { /// /// 模块编号:M20 /// 作 用:发运模块 /// 作 者:张松男 /// 编写日期:2021-12-20 /// public class TJFrmPlaceDAL : BaseDAL { /// /// 获得FIS发货信息信息(列表) /// /// /// /// public DataTable GetList(string pFistype, string WORKCENTER_CODE) { #region try { DataTable returnDt = null; StringBuilder strSql = new StringBuilder(); List parameters = new List(); // // strSql.Append(" SELECT TOP 1000 O.PID,O.SEQ,O.MATERIAL_CODE,O.MATERIAL_NAME,O.STATE,O.[LINENO]," + "CASE O.MOULD_CODE WHEN 'LF' THEN '左前' WHEN 'LR' THEN '左后' WHEN 'RF' THEN '右前' WHEN 'RR' THEN '右后' ELSE O.MOULD_CODE END as 'MOULD_CODE'," + "O.PLAN_DATE FROM T_PP_TJFY_WORKORDER AS O LEFT JOIN T_PP_TJFY_ORDERPLAN AS P ON P.PID = O.ORDERPLANID "); if (!string.IsNullOrEmpty(pFistype) && pFistype == "01") { strSql.Append(" WHERE O.MOULD_CODE IN( 'LF', 'LR' ) "); } else { strSql.Append(" WHERE O.MOULD_CODE IN( 'RF', 'RR' ) "); } strSql.Append(" and O.STATE in ('0','1') "); strSql.Append(" ORDER BY O.PLAN_DATE DESC,SEQ,O.MOULD_CODE "); //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 } public int UpdateWorkOrderState(List Ids) { var ids = ""; foreach (var id in Ids) { ids += $"'{id}',"; } ids = ids.TrimEnd(','); var strSql = $" update T_PP_TJFY_WORKORDER set STATE = '4' where PID IN ({ids})"; using (IDataSession session = AppDataFactory.CreateMainSession()) { return session.ExecuteSql(strSql.ToString()); } } /// /// 贴车单记录查询 /// /// /// /// /// /// public DataTable GetPastecardInfoWithVin(string ppastercardno, string strbegindate, string strenddate, string vinLack, string PlantCode, string Operator) { #region StringBuilder strSql = new StringBuilder(); DataTable returnDt = null; List parameters = new List(); 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 like '%{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 } /// /// 根据贴车单主键查询贴车单明细 /// /// /// public DataTable GetPasteDetails(string ppastercarKey) { #region StringBuilder strSql = new StringBuilder(); DataTable returnDt = null; List parameters = new List(); //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 } /// /// 根据贴车单ID获取详细 /// /// /// public DataTable GetPascardDetailsByPid(string ppastercarKey) { #region StringBuilder strSql = new StringBuilder(); DataTable returnDt = null; List parameters = new List(); strSql.AppendLine("SELECT D.ROWINDEX ,F.SEQ as 'VWSEQ' ,F.PRODUCTCODE as 'VIN' ,F.MATERIAL_CODE as 'PRODNO' ,F.MATERIAL_NAME as 'CARSETDESC_CN' ,CASE F.MOULD_CODE WHEN 'LF' THEN '左前' WHEN 'LR' THEN '左后' WHEN 'RF' THEN '右前' WHEN 'RR' THEN '右后' ELSE F.MOULD_CODE END AS 'CP5A', "); strSql.AppendLine("F.[LINENO] ,C.PASTECARDNO FROM T_PP_PASCARDDETAILS AS D LEFT JOIN T_PP_TJFY_WORKORDER AS F ON F.PID = D.FISDETAILID LEFT JOIN T_PP_PASTECARD AS C ON C.PID = D.PASTECARDID "); strSql.AppendLine(" WHERE PASTECARDID='" + ppastercarKey.ToString() + "' "); strSql.AppendLine(" ORDER BY D.ROWINDEX,F.SEQ,F.MATERIAL_CODE"); using (IDataSession session = AppDataFactory.CreateMainSession()) { returnDt = session.GetTable(strSql.ToString(), parameters.ToArray()); } return returnDt; #endregion } /// /// 获取贴车单当天的总条数 /// /// public DataTable GetPastecardNo(string strcreatetime) { #region StringBuilder strSql = new StringBuilder(); DataTable returnDt = null; List parameters = new List(); 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; } } /// /// 获取发车信息 /// /// public DataTable GetPastecardIndex(string PLANTNAME, string PASTECARDNO) { #region StringBuilder strSql = new StringBuilder(); StringBuilder whereBuilder = new StringBuilder(); DataTable returnDt = null; List parameters = new List(); 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 } /// /// 获取贴车明细单当天的总条数 /// /// public DataTable GetPastecardDeatis() { #region StringBuilder strSql = new StringBuilder(); DataTable returnDt = null; List parameters = new List(); 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 } /// /// 获取下护板扫描表其他条码号 /// /// /// public DataTable GetOhterCode(string code) { #region try { List parameters = new List(); 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(); } /// /// 生成贴车单明细SQL /// /// /// private string Insertdetailcard(int rowindex, TJEPasteDetailsCard 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 } /// /// 获取配置表中的规则类型值 /// /// /// 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 parameters = new List(); 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 } /// /// 根据条码标识查询零件信息 /// /// /// public DataTable GetSparepartsinfo(string strbarcode) { #region StringBuilder strSql = new StringBuilder(); List parameters = new List(); 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 } /// /// 实现校准功能 /// /// 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 } /// /// 更新FIS队列表。 /// /// private string updateFisOrder(TJEPasteDetailsCard Details) { #region StringBuilder strSql = new StringBuilder(); if (!string.IsNullOrEmpty(Details.FIS_KEY)) strSql.Append(string.Format($" UPDATE T_PP_TJFY_WORKORDER SET STATE =2,PRODUCTCODE = '{Details.SANBARCODE}' WHERE PID= '{Details.FIS_KEY}' ")); else { strSql.Append($"INSERT INTO[dbo].[T_PP_TJFY_WORKORDER] ([PID], [ORDERPLANID], [ORDERPLAN_NO], [SEQ], [MATERIAL_CODE], [MATERIAL_NAME], [PLAN_DATE], [PRODUCTCODE], [MOULD_CODE], [STATE], [UPDATEDATE], [LINENO]) VALUES('{Guid.NewGuid().ToString()}','','','','{Details.PRODNO}','{Details.CARSETDESC_CN}','{DateTime.Now}','{Details.SANBARCODE}','{Details.MOULDCODE}','2','{DateTime.Now}','{Details.LINENO}')"); } 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 } /// /// 删除FIS发运表 /// /// /// 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 } /// /// 添加贴车单 /// /// /// /// public int AddPasteCard(TJEPasteCard ppastecard) { #region try { 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 (TJEPasteDetailsCard decard in ppastecard.DetailsCardlist) { int rowindex = strindex; string strinsertsql = Insertdetailcard(rowindex, decard); string updatesql = updateFisOrder(decard); 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"), "")); 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 } /// /// 添加贴车单 /// /// /// /// public int AddNewPasteCard(TJEPasteCard ppastecard,int Count) { try { #region 获取贴车单序列号 string indexNumber = string.Format("select PASTECARDNO from T_DAS_PASTE_CARDINDEX where PLANTCODE like '%{0}%'", ppastecard.PLANTNAME); string pastCardNo = ""; using (IDataSession session = AppDataFactory.CreateMainSession()) { pastCardNo = Convert.ToString(session.ExecuteSqlScalar(indexNumber, new List().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 { if (ppastecard.DetailsCardlist.Count == Count) { 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(); 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("'" + ppastecard.PASTECARDNO + "',"); 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','{ppastecard.PLANTNAME}'"); strSql.Append(" INSERT INTO T_PP_PASTECARD "); strSql.Append(" (" + strFields.ToString() + ")"); strSql.Append(" VALUES "); strSql.Append(" (" + strValues.ToString() + ")"); sqllist.Add(strSql.ToString()); foreach (TJEPasteDetailsCard decard in ppastecard.DetailsCardlist) { int rowindex = strindex; string strinsertsql = Insertdetailcard(rowindex, decard); //string updatesql = UpdateFISORDERSENDDETAIL(decard.FIS_KEY); string updatesql2 = updateFisOrder(decard); //string updatesql3 = updateProduct(decard.PRODUCT_PID, decard.VIN, decard.KIN, decard.VWSEQ); sqllist.Add(strinsertsql.ToString()); //sqllist.Add(updatesql.ToString()); sqllist.Add(updatesql2.ToString()); //sqllist.Add(updatesql3.ToString()); strindex++; } //2016-10-31 闫永刚 //更新发货单记录表 sqllist.Add(string.Format("update T_DAS_PASTE_CARDINDEX set PASTECARDNO='{0}',PASTECARDDATE='{1}' where PLANTCODE='{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()); } } return reindex; } catch (System.Exception ex) { throw ex; } } /// /// 更新贴车单信息 /// /// /// 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 } /// /// 判断条码是否重复 /// /// /// public DataTable ExistBarcode(int barcodetime, string pbarcode) { StringBuilder strSql = new StringBuilder(); strSql.Append($"SELECT PRODUCTCODE FROM T_PP_TJFY_WORKORDER WHERE PRODUCTCODE = '{pbarcode}'"); List parameters = new List(); //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()); } } /// /// 打印条码 /// /// /// public DataTable WriteFile(string sql) { List parameters = new List(); using (IDataSession session = AppDataFactory.CreateMainSession()) { return session.GetTable(sql.ToString(), parameters.ToArray()); } } /// /// 更新贴车单补打印时间 /// /// 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()); } } /// /// 获取扫取条形码是否存在 /// /// /// public int GetExitsCode(string code) { #region try { object result; List parameters = new List(); 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 } /// /// 查询是否为成品 /// /// /// public object GetExitsStatus(string code) { #region try { object result; List parameters = new List(); 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 } /// /// 获取工作中心 /// /// /// public DataTable GetWORKCENTERCODE() { #region try { DataTable result; List parameters = new List(); 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 } ///// ///// 更新index表 ///// ///// ///// //public DataTable GetWORKCENTERCODE() //{ // #region // try // { // DataTable result; // List parameters = new List(); // 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 //} /// /// 获取 DASPASTECARDINDEX表数据 /// /// /// public DataTable GetDaspssteCarIndexByPlanName(string PlanTName) { #region try { DataTable result; List parameters = new List(); string strSql = "select PASTECARDNO,PASTECARDDATE,PLANTCODE, PLANTNAME from T_DAS_PASTE_CARDINDEX where PLANTCODE='" + PlanTName + "'"; using (IDataSession session = AppDataFactory.CreateMainSession()) { result = session.GetTable(strSql.ToString(), parameters.ToArray()); } return result; } catch (Exception ex) { throw ex; } #endregion } /// /// 插入 DASPASTECARDINDEX表数据 /// /// /// public int InsertDaspssteCarIndexByPlanName(EPasteCard ppastecard) { try { int result; List parameters = new List(); 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 parameters = new List(); 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; } } } }