using Cksoft.Data; using Cksoft.Data.Repository; using DllEapEntity; using DllStatusShowDal; using System; using System.Collections.Generic; using System.Text; using System.Linq; using DllEapDal; using DllHsms; using Cksoft.Unity; using DllEapEntity.Rms; using DllDiodesMesDal; using DllDiodesMesEntity; using DllDiodesMesEntity.Dto; namespace DllLotServer { public class CallFunction { public static string CurrDbCode = "eap"; public static string MesDbCode = "mes"; private static string CurrStaffCode = "S00001"; public static int LotStart(string maccode, List mcadetails, string usercode, ref string errorinfo) { IDatabase CurrDb = null; IDatabase MesDb = null; try { CurrDb = DbFactory.Base(CurrDbCode); MesDb = DbFactory.Base(MesDbCode); CurrentLoginUserDal userdal = new CurrentLoginUserDal(MesDb); CurrStaffCode = userdal.GetCurrUserCode(); //CurrDb.BeginTrans(); List ttlist = mcadetails.Where(t => t.FCode == StandardCode.SVID_LotNo).ToList(); if(ttlist.Count<=0) { errorinfo = $"未读取到机台【{maccode}】上的LOT编号。"; return -1; } string lotno = ttlist[0].FVal; MacOrderSendDal senddal = new MacOrderSendDal(CurrDb); //调用lot查询接口 int result = QueryLot(MesDb, lotno, ref errorinfo); if(result<=0) { //查询lot失败,给机台发送消息 string temperrorinfo = ""; senddal.SendS10F3(maccode, "Read LotInfo Failed from Mes.", ref temperrorinfo); return -1; } //调用lot trackin接口 result = TrackIn(MesDb, lotno, maccode, ref errorinfo); if (result <= 0) { //查询lot失败,给机台发送消息 string temperrorinfo = ""; senddal.SendS10F3(maccode, $"Mes Track In Failed {errorinfo}", ref temperrorinfo); return -1; } else { string temperrorinfo = ""; senddal.SendS10F3(maccode, "Mes Track In Success", ref temperrorinfo); } //CurrDb.Commit(); return 1; } catch(Exception ex) { errorinfo = ex.Message.ToString(); return -1; } finally { if (CurrDb != null) CurrDb.Close(); if (MesDb != null) MesDb.Close(); } } public static int QueryLot(IDatabase mesdb,string lot,ref string errorinfo) { try { mesdb.BeginTrans(); LotDal dal = new LotDal(mesdb); LotMst mst= dal.ImportLotFromMes(lot, "", ref errorinfo); if (mst == null) { mesdb.Rollback(); return -1; } mesdb.Commit(); return 1; } catch(Exception ex) { errorinfo = ex.Message.ToString(); return -1; } } public static int TrackIn(IDatabase mesdb, string lot,string maccode, ref string errorinfo) { try { LotDal dal = new LotDal(mesdb); int result = dal.TrackIn(lot,maccode, "", CurrStaffCode, ref errorinfo); if (result<=0) return -1; return 1; } catch (Exception ex) { errorinfo = ex.Message.ToString(); return -1; } } public static int QtyColle(IDatabase mesdb,string lot,string maccode, List mcadetails, ref string errorinfo) { try { QtyColllectDto inparam = new QtyColllectDto(); inparam.Lot = lot; inparam.MacCode = maccode; List ttlists = mcadetails.Where(t => t.FCode == StandardCode.SVID_StaffCode).ToList(); if(ttlists.Count<=0) { errorinfo = $"未抓取到操作员工号。"; return -1; } inparam.StaffCode = ttlists[0].FVal; ttlists = mcadetails.Where(t => t.FCode == StandardCode.SVID_LotFinishUnit).ToList(); if (ttlists.Count <= 0) { errorinfo = $"未抓取到Lot完成量。"; return -1; } inparam.ProQty = int.Parse(ttlists[0].FVal); inparam.Yield = 1; mesdb.BeginTrans(); LotDal dal = new LotDal(mesdb); int result = dal.QtyCollect(inparam, ref errorinfo); if (result <= 0) { mesdb.Rollback(); return -1; } mesdb.Commit(); return 1; } catch (Exception ex) { errorinfo = ex.Message.ToString(); return -1; } } public static int DataColle(IDatabase mesdb,string lot, ref string errorinfo) { try { mesdb.BeginTrans(); LotDal dal = new LotDal(mesdb); int result = dal.MaterialCheck(lot, ref errorinfo); if (result <= 0) { mesdb.Rollback(); return -1; } mesdb.Commit(); return 1; } catch (Exception ex) { errorinfo = ex.Message.ToString(); return -1; } } private static int AddLoss(IDatabase mesdb,int loss,int mstid,ref string errorinfo) { LotExceptionDal lossdal = new LotExceptionDal(mesdb); LotException exc = new LotException(); exc.ExceptionCode = "DPEP"; exc.FCount = loss; exc.LotProcessReportID = mstid; int tempresult = lossdal.Add(exc, "", ref errorinfo); //if (tempresult <= 0) //{ // mesdb.Rollback(); // return -1; //} return 1; } public static int TrackOut(IDatabase mesdb, string lot, List mcadetails, ref string errorinfo) { try { //计算不良数量 int goods = 0; List ttlists = mcadetails.Where(t => t.FCode == StandardCode.SVID_LotFinishUnit).ToList(); if (ttlists.Count > 0&& ttlists[0].FVal!="") { //errorinfo = $"未抓取到Lot完成量。"; //return -1; goods = int.Parse(ttlists[0].FVal); } int intotal = 0; //int goods = int.Parse(ttlists[0].FVal); //读取lot的投入量 List lps = mesdb.FindListForCondition($" and d.lotno='{lot}'", ref errorinfo).ToList(); if(lps.Count>0&&lps[0].InTotal.ToString()!="") { //errorinfo = $"未找到【{lot}】的lot"; //return -1; intotal = lps[0].InTotal; } //int intotal = lps[0].InTotal; //if(intotal<=0) //{ // errorinfo = $"lot【{lot}】的投入量小于等于0,这样的数据不合理。"; // return -1; //} int loss = intotal - goods; //if (loss < 0) //{ // errorinfo = $"当前报废数量={loss}小于0,报废数量不能小于0"; // return -1; //} if(loss>0) { mesdb.BeginTrans(); //添加报废 AddLoss(mesdb, loss, lps[0].ID, ref errorinfo); mesdb.Commit(); } mesdb.BeginTrans(); LotDal dal = new LotDal(mesdb); int result = dal.TrackOut(lot,goods,"", CurrStaffCode, ref errorinfo); //if (result <= 0) //{ // mesdb.Rollback(); // return -1; //} mesdb.Commit(); return 1; } catch (Exception ex) { errorinfo = ex.Message.ToString(); return -1; } } public static int LotEnd(string maccode, List mcadetails, string usercode, ref string errorinfo) { IDatabase CurrDb = null; IDatabase MesDb = null; try { CurrDb = DbFactory.Base(CurrDbCode); MesDb = DbFactory.Base(MesDbCode); CurrentLoginUserDal userdal = new CurrentLoginUserDal(MesDb); CurrStaffCode = userdal.GetCurrUserCode(); //CurrDb.BeginTrans(); List ttlist = mcadetails.Where(t => t.FCode == StandardCode.SVID_LotNo).ToList(); if (ttlist.Count <= 0) { errorinfo = $"未读取到机台【{maccode}】上的LOT编号。"; return -1; } string lotno = ttlist[0].FVal; MacOrderSendDal senddal = new MacOrderSendDal(CurrDb); //调用产量收集 int result = QtyColle(MesDb, lotno, maccode, mcadetails, ref errorinfo); if (result <= 0) { //查询lot失败,给机台发送消息 string temperrorinfo = ""; senddal.SendS10F3(maccode, "Mes QtyCollect Failed.", ref temperrorinfo); //return -1; } //调用数据接口 result = DataColle(MesDb, lotno, ref errorinfo); if (result <= 0) { //查询lot失败,给机台发送消息 string temperrorinfo = ""; senddal.SendS10F3(maccode, "Mes DataCollect Failed", ref temperrorinfo); //return -1; } //调用lot trackOut接口 result = TrackOut(MesDb,lotno, mcadetails, ref errorinfo); if (result <= 0) { //查询lot失败,给机台发送消息 string temperrorinfo = ""; senddal.SendS10F3(maccode, "Mes Track Out Failed", ref temperrorinfo); //return -1; } else { string temperrorinfo = ""; senddal.SendS10F3(maccode, "Mes Track Out Success", ref temperrorinfo); } //CurrDb.Commit(); return 1; } catch (Exception ex) { errorinfo = ex.Message.ToString(); return -1; } finally { if (CurrDb != null) CurrDb.Close(); if (MesDb != null) MesDb.Close(); } } /// /// 清洗吸嘴 /// /// /// /// /// public static int CollectLife(string maccode, List mcadetails, string usercode, ref string errorinfo) { IDatabase CurrDb = null; IDatabase MesDb = null; try { CurrDb = DbFactory.Base(CurrDbCode); MesDb = DbFactory.Base(MesDbCode); //CurrDb.BeginTrans(); List ttlist = mcadetails.Where(t => t.FCode == StandardCode.SVID_LotNo).ToList(); if (ttlist.Count <= 0) { errorinfo = $"未读取到机台【{maccode}】上的LOT编号。"; return -1; } string lotno = ttlist[0].FVal; MesDb.BeginTrans(); string sqlstr = $@"update lotprocess set CollectLife=CollectLife+1 where LotMstID = (select id from lotmst where lotno = '{lotno}')"; MesDb.ExecuteBySql(sqlstr); MesDb.BeginTrans(); //CurrDb.Commit(); return 1; } catch (Exception ex) { errorinfo = ex.Message.ToString(); return -1; } finally { if (CurrDb != null) CurrDb.Close(); if (MesDb != null) MesDb.Close(); } } } }