123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373 |
- 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<McaSecVDetail> 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<McaSecVDetail> 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<McaSecVDetail> mcadetails, ref string errorinfo)
- {
- try
- {
- QtyColllectDto inparam = new QtyColllectDto();
- inparam.Lot = lot;
- inparam.MacCode = maccode;
- List<McaSecVDetail> 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<McaSecVDetail> mcadetails, ref string errorinfo)
- {
- try
- {
- //计算不良数量
- int goods = 0;
- List<McaSecVDetail> 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 <LotProcess> lps = mesdb.FindListForCondition<LotProcess>($" 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<McaSecVDetail> 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<McaSecVDetail> 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();
- }
- }
- /// <summary>
- /// 清洗吸嘴
- /// </summary>
- /// <param name="maccode"></param>
- /// <param name="usercode"></param>
- /// <param name="errorinfo"></param>
- /// <returns></returns>
- public static int CollectLife(string maccode, List<McaSecVDetail> mcadetails, string usercode, ref string errorinfo)
- {
- IDatabase CurrDb = null;
- IDatabase MesDb = null;
- try
- {
- CurrDb = DbFactory.Base(CurrDbCode);
- MesDb = DbFactory.Base(MesDbCode);
- //CurrDb.BeginTrans();
- List<McaSecVDetail> 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();
- }
- }
- }
- }
|