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.
2544 lines
124 KiB
2544 lines
124 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using ICSSoft.Frame.Data.Entity;
|
|
using ICSSoft.Base.Config.AppConfig;
|
|
using System.Configuration;
|
|
using ICSSoft.Entity.PU_AppVouch;
|
|
using Newtonsoft.Json;
|
|
using System.Net;
|
|
using System.IO;
|
|
using ICSSoft.YT.Entity.Vouch;
|
|
using ICSSoft.YT.Entity.OM_PO;
|
|
using System.Data;
|
|
using ICSSoft.Frame.Data.Entity.NcApiEntity;
|
|
|
|
namespace ICSSoft.Frame.Data.DAL
|
|
{
|
|
public class ICSCollectDAL
|
|
{
|
|
private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
|
private static string APIURL = System.Configuration.ConfigurationSettings.AppSettings["APIURL"].ToString();
|
|
private static string DataCollectWW = APIURL + "APICreateInventory_PU_AppVouch";
|
|
private static string urlCreatPO = APIURL + "sendPO";//生成采购入库单
|
|
private static string urlCreat4D = APIURL + "send4D";//生成材料出库单
|
|
private static string urlClosePOLine = APIURL + "sendM21Rowclose";//关闭工单行
|
|
|
|
public static string CheckRoute(FramDataContext db, ICSLOTONWIP onwip)
|
|
{
|
|
var lotcount = db.ICSMO2User.Count(a => a.LOTNO == onwip.LOTNO);
|
|
var routecount = db.ICSITEMROUTE2OPLot.Count(a => a.LotNo == onwip.LOTNO);
|
|
if (lotcount != routecount)
|
|
{
|
|
return "跟踪单:" + onwip.LOTNO + ",存在新增工序尚未派工,请重新派工后再进行报工操作!\n\r";
|
|
}
|
|
else
|
|
{
|
|
return "";
|
|
}
|
|
}
|
|
public static void CheckInfo(FramDataContext db, ICSLOTSIMULATION simulation)
|
|
{
|
|
//try
|
|
//{
|
|
// var user = db.Sys_User.SingleOrDefault(a => a.UserCode == simulation.MUSER);
|
|
// if (user == null)
|
|
// throw new Exception("用户不存在!");
|
|
|
|
// var mouser = db.ICSMO2User.SingleOrDefault(a => a.LOTNO == simulation.LOTNO && a.OPCODE == simulation.OPCODE);
|
|
// if (mouser == null)
|
|
// throw new Exception("批次工序派工信息不存在!");
|
|
|
|
// var mo = db.ICSMO.SingleOrDefault(a => a.MOCODE == mouser.MOCODE && a.MOSEQ == mouser.MOSEQ.ToString());
|
|
// if (mo == null)
|
|
// throw new Exception("工单信息不存在!");
|
|
|
|
// var moroute = db.ICSMO2ROUTE.SingleOrDefault(a => a.MOID == mo.ID);
|
|
// if (moroute == null)
|
|
// throw new Exception("工单未关联途程!");
|
|
|
|
// if (moroute.ROUTECODE != mouser.RouteCode)
|
|
// throw new Exception("工单途程与派工途程不同!");
|
|
|
|
// var itemop = db.ICSITEMROUTE2OPLot.SingleOrDefault(a => a.LotNo == mouser.LOTNO && a.ITEMCODE == mo.ITEMCODE && a.ROUTECODE == moroute.ROUTECODE && a.OPCODE == mouser.OPCODE);
|
|
// if (itemop == null)
|
|
// throw new Exception("产品途程工序不存在!");
|
|
|
|
// var sim = db.ICSLOTSIMULATION.SingleOrDefault(a => a.LOTNO == simulation.LOTNO);
|
|
// var itemops = db.ICSITEMROUTE2OPLot.Where(a => a.LotNo == mouser.LOTNO && a.ITEMCODE == itemop.ITEMCODE && a.ROUTECODE == itemop.ROUTECODE && a.OPSEQ < itemop.OPSEQ);
|
|
// if (sim == null && itemops != null && itemops.Count() > 0)
|
|
// throw new Exception("请从第一道工序开始报工!");
|
|
|
|
// //判断
|
|
// if (sim != null)
|
|
// {
|
|
// if (sim.ISCOM == "1")
|
|
// {
|
|
// throw new Exception("该批次已完工!");
|
|
// }
|
|
// //如果是完工判断是否是当前工序、设备
|
|
// else if (sim.CollectStatus == "COLLECT_BEGIN")
|
|
// {
|
|
// if (sim.OPCODE != simulation.OPCODE)
|
|
// throw new Exception(string.Format("应采集工序:{0}!", sim.OPCODE));
|
|
// if (sim.EQPCODE != simulation.EQPCODE)
|
|
// throw new Exception(string.Format("应采集设备:{0}!", sim.EQPCODE));
|
|
// }
|
|
// //开始下道工序时判断下一道工序是否正确
|
|
// else if (sim.CollectStatus == "COLLECT_END")
|
|
// {
|
|
// var simitemop = db.ICSITEMROUTE2OPLot.SingleOrDefault(a => a.LotNo == mouser.LOTNO && a.ITEMCODE == sim.ITEMCODE && a.ROUTECODE == sim.ROUTECODE && a.OPCODE == sim.OPCODE);
|
|
// var ops = db.ICSITEMROUTE2OPLot.Where(a => a.LotNo == mouser.LOTNO && a.ITEMCODE == simitemop.ITEMCODE && a.ROUTECODE == simitemop.ROUTECODE && a.OPSEQ > simitemop.OPSEQ).OrderBy(a => a.OPSEQ).FirstOrDefault();
|
|
// if (ops == null)
|
|
// throw new Exception("已是最后一道工序,无需再采集!");
|
|
// else if (ops.OPCODE != simulation.OPCODE)
|
|
// throw new Exception(string.Format("应采集工序:{0}!", ops.OPCODE));
|
|
|
|
// //完工状态判断是否检验
|
|
// var wipCheck = (from a in db.ICSLOTONWIP
|
|
// join b in db.ICSLOTONWIPCheck on a.ID equals b.ONWIPID
|
|
// where a.LOTNO == sim.LOTNO && a.SEQ == sim.SEQ
|
|
// select b).FirstOrDefault();
|
|
// if (wipCheck != null)
|
|
// {
|
|
// if (wipCheck.Result == "不合格" && (wipCheck.TResult == null || wipCheck.TResult == "报废"))
|
|
// throw new Exception("上道工序不合格且不是让步或返工状态,不能开始该工序!");
|
|
// }
|
|
// else
|
|
// {
|
|
// throw new Exception("上道工序未做检验,不能开始该工序!");
|
|
// }
|
|
// }
|
|
// if (sim.LOTStatus.Equals("暂停"))
|
|
// {
|
|
// throw new Exception("该批次工序处于暂停状态!");
|
|
// }
|
|
// if (sim.CollectStatus.Equals(simulation.EATTRIBUTE1))
|
|
// {
|
|
// throw new Exception("状态不正确,请重新扫描!");
|
|
// }
|
|
// }
|
|
|
|
// //var onwipNow = db.ICSLOTONWIP.SingleOrDefault(a => a.LOTNO == sim.LOTNO && a.SEQ == sim.SEQ);
|
|
// var onwipNow = db.ICSLOTONWIP.Where(a => a.LOTNO == mouser.LOTNO && a.ROUTECODE == mouser.RouteCode && a.OPCODE == mouser.OPCODE).OrderByDescending(a => a.MTIME).FirstOrDefault();
|
|
// //var onwip = db.ICSLOTONWIP.SingleOrDefault(a => a.EQPCODE == simulation.EQPCODE && a.ACTIONRESULT == "COLLECT_BEGIN");
|
|
// //if (onwip != null && onwipNow == null)
|
|
// // throw new Exception("设备正在使用,不能采集!");
|
|
// //else if (onwip != null && onwipNow != null && onwip.ID != onwipNow.ID)
|
|
// // throw new Exception("设备正在使用,不能采集!");
|
|
|
|
// if (onwipNow != null && !onwipNow.UserCodeBegin.Equals(simulation.MUSER))
|
|
// {
|
|
// var UserCodeBegin = db.Sys_User.SingleOrDefault(a => a.UserCode == onwipNow.UserCodeBegin);
|
|
// throw new Exception("与开工人员:" + onwipNow.UserCodeBegin + ";" + UserCodeBegin.UserName + "不同,不能采集!");
|
|
// }
|
|
//}
|
|
//catch (Exception ex)
|
|
//{
|
|
// throw ex;
|
|
//}
|
|
}
|
|
public static string CheckInfoWW(FramDataContext db, ICSLOTONWIP onwip)
|
|
{
|
|
try
|
|
{
|
|
var user = db.Sys_User.SingleOrDefault(a => a.UserCode == onwip.MUSER);
|
|
if (user == null)
|
|
throw new Exception("跟踪单:" + onwip.LOTNO + ",用户不存在!\n\r");
|
|
|
|
var mouser = db.ICSMO2User.SingleOrDefault(a => a.LOTNO == onwip.LOTNO && a.OPCODE == onwip.OPCODE);
|
|
if (mouser == null)
|
|
throw new Exception("跟踪单:" + onwip.LOTNO + ",批次工序派工信息不存在!\n\r");
|
|
|
|
var mo = db.ICSMO.SingleOrDefault(a => a.MOCODE == mouser.MOCODE && a.MOSEQ == mouser.MOSEQ.ToString());
|
|
if (mo == null)
|
|
throw new Exception("跟踪单:" + onwip.LOTNO + ",工单信息不存在!\n\r");
|
|
|
|
var moroute = db.ICSMO2ROUTE.SingleOrDefault(a => a.MOID == mo.ID);
|
|
if (moroute == null)
|
|
throw new Exception("跟踪单:" + onwip.LOTNO + ",工单未关联途程!\n\r");
|
|
|
|
if (moroute.ROUTECODE != mouser.RouteCode)
|
|
throw new Exception("跟踪单:" + onwip.LOTNO + ",工单途程与派工途程不同!\n\r");
|
|
|
|
var itemop = db.ICSITEMROUTE2OPLot.SingleOrDefault(a => a.LotNo == mouser.LOTNO && a.ITEMCODE == mo.ITEMCODE && a.ROUTECODE == moroute.ROUTECODE && a.OPCODE == mouser.OPCODE);
|
|
if (itemop == null)
|
|
throw new Exception("跟踪单:" + onwip.LOTNO + ",产品途程工序不存在!\n\r");
|
|
|
|
//var sim = db.ICSLOTSIMULATION.SingleOrDefault(a => a.LOTNO == simulation.LOTNO);
|
|
//var itemops = db.ICSITEMROUTE2OPLot.Where(a => a.LotNo == mouser.LOTNO && a.ITEMCODE == itemop.ITEMCODE && a.ROUTECODE == itemop.ROUTECODE && a.OPSEQ < itemop.OPSEQ);
|
|
//if (sim == null && itemops != null && itemops.Count() > 0)
|
|
// throw new Exception("跟踪单:" + simulation.LOTNO + ",请从第一道工序开始报工!\n\r");
|
|
|
|
////判断
|
|
//if (sim != null)
|
|
//{
|
|
// if (sim.ISCOM == "1")
|
|
// {
|
|
// throw new Exception("跟踪单:" + simulation.LOTNO + ",该批次已完工!\n\r");
|
|
// }
|
|
// //如果是完工判断是否是当前工序、设备
|
|
// else if (sim.CollectStatus == "COLLECT_BEGIN")
|
|
// {
|
|
// if (sim.OPCODE != simulation.OPCODE)
|
|
// throw new Exception(string.Format("跟踪单:" + simulation.LOTNO + ",应采集工序:{0}!\n\r", sim.OPCODE));
|
|
// if (sim.EQPCODE != simulation.EQPCODE)
|
|
// throw new Exception(string.Format("跟踪单:" + simulation.LOTNO + ",应采集设备:{0}!\n\r", sim.EQPCODE));
|
|
// }
|
|
// //开始下道工序时判断下一道工序是否正确
|
|
// else if (sim.CollectStatus == "COLLECT_END")
|
|
// {
|
|
// var simitemop = db.ICSITEMROUTE2OPLot.SingleOrDefault(a => a.LotNo == mouser.LOTNO && a.ITEMCODE == sim.ITEMCODE && a.ROUTECODE == sim.ROUTECODE && a.OPCODE == sim.OPCODE);
|
|
// var ops = db.ICSITEMROUTE2OPLot.Where(a => a.LotNo == mouser.LOTNO && a.ITEMCODE == simitemop.ITEMCODE && a.ROUTECODE == simitemop.ROUTECODE && a.OPSEQ > simitemop.OPSEQ).OrderBy(a => a.OPSEQ).FirstOrDefault();
|
|
// if (ops == null)
|
|
// throw new Exception("跟踪单:" + simulation.LOTNO + ",已是最后一道工序,无需再采集!\n\r");
|
|
// else if (ops.OPCODE != simulation.OPCODE)
|
|
// throw new Exception(string.Format("跟踪单:" + simulation.LOTNO + ",应采集工序:{0}!\n\r", ops.OPCODE));
|
|
|
|
// //完工状态判断是否检验
|
|
// var wipCheck = (from a in db.ICSLOTONWIP
|
|
// join b in db.ICSLOTONWIPCheck on a.ID equals b.FORTRANID
|
|
// where a.LOTNO == sim.LOTNO && a.SEQ == sim.SEQ
|
|
// select b).FirstOrDefault();
|
|
// if (wipCheck != null)
|
|
// {
|
|
// if (wipCheck.Status != "正常" && wipCheck.Status != "放行")
|
|
// throw new Exception("跟踪单:" + simulation.LOTNO + ",上道工序不合格且不是放行状态,不能开始该工序!\n\r");
|
|
// }
|
|
// else
|
|
// {
|
|
// throw new Exception("跟踪单:" + simulation.LOTNO + ",上道工序未做检验,不能开始该工序!\n\r");
|
|
// }
|
|
// }
|
|
// if (sim.LOTStatus.Equals("暂停"))
|
|
// {
|
|
// throw new Exception("跟踪单:" + simulation.LOTNO + ",该批次工序处于暂停状态!\n\r");
|
|
// }
|
|
// if (sim.CollectStatus.Equals(simulation.EATTRIBUTE1))
|
|
// {
|
|
// throw new Exception("跟踪单:" + simulation.LOTNO + ",状态不正确,请重新扫描!\n\r");
|
|
// }
|
|
//}
|
|
|
|
////var onwipNow = db.ICSLOTONWIP.SingleOrDefault(a => a.LOTNO == sim.LOTNO && a.SEQ == sim.SEQ);
|
|
//var onwipNow = db.ICSLOTONWIP.Where(a => a.LOTNO == mouser.LOTNO && a.ROUTECODE == mouser.RouteCode && a.OPCODE == mouser.OPCODE).OrderByDescending(a => a.MTIME).FirstOrDefault();
|
|
////var onwip = db.ICSLOTONWIP.SingleOrDefault(a => a.EQPCODE == simulation.EQPCODE && a.ACTIONRESULT == "COLLECT_BEGIN");
|
|
////if (onwip != null && onwipNow == null)
|
|
//// throw new Exception("跟踪单:" + simulation.LOTNO + ",设备正在使用,不能采集!\n\r");
|
|
////else if (onwip != null && onwipNow != null && onwip.ID != onwipNow.ID)
|
|
//// throw new Exception("跟踪单:" + simulation.LOTNO + ",设备正在使用,不能采集!\n\r");
|
|
|
|
//if (onwipNow != null && !onwipNow.UserCodeBegin.Equals(simulation.MUSER))
|
|
//{
|
|
// throw new Exception("跟踪单:" + simulation.LOTNO + ",与开工人员不同,不能采集!\n\r");
|
|
//}
|
|
return "";
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return ex.Message;
|
|
}
|
|
}
|
|
public static void Save(FramDataContext db, ICSLOTSIMULATION simulation)
|
|
{
|
|
try
|
|
{
|
|
var user = db.Sys_User.SingleOrDefault(a => a.UserCode == simulation.MUSER);
|
|
var mouser = db.ICSMO2User.SingleOrDefault(a => a.LOTNO == simulation.LOTNO && a.OPCODE == simulation.OPCODE);
|
|
var lot = db.ICSITEMLot.SingleOrDefault(a => a.LotNO == simulation.LOTNO);
|
|
var itemop = db.ICSITEMROUTE2OPLot.Where(a => a.LotNo == mouser.LOTNO && a.ITEMCODE == lot.ItemCode && a.ROUTECODE == mouser.RouteCode).OrderByDescending(a => a.OPSEQ).FirstOrDefault();
|
|
|
|
bool simNew = false;
|
|
var simulationNew = db.ICSLOTSIMULATION.SingleOrDefault(a => a.LOTNO == simulation.LOTNO);
|
|
#region simulation
|
|
//ICSLOTSIMULATION simulationNew = new ICSLOTSIMULATION();
|
|
if (simulationNew == null)
|
|
{
|
|
simNew = true;
|
|
simulationNew = new ICSLOTSIMULATION();
|
|
simulationNew.ID = AppConfig.GetGuid();
|
|
simulationNew.LOTNO = simulation.LOTNO;
|
|
simulationNew.MOCODE = mouser.MOCODE;
|
|
simulationNew.LOTSEQ = 0;
|
|
|
|
simulationNew.LOTQTY = Convert.ToInt32(lot.LOTQTY);
|
|
simulationNew.GOODQTY = simulationNew.LOTQTY;
|
|
simulationNew.NGQTY = 0;
|
|
simulationNew.LOTStatus = "新增";
|
|
|
|
simulationNew.MODELCODE = "";
|
|
simulationNew.ITEMCODE = lot.ItemCode;
|
|
simulationNew.FROMROUTE = "";
|
|
simulationNew.FROMOP = "";
|
|
|
|
simulationNew.ROUTECODE = mouser.RouteCode;
|
|
simulationNew.RESCODE = "";
|
|
simulationNew.CHECKLOTNO = "";
|
|
simulationNew.CARTONCODE = "";
|
|
simulationNew.PALLETCODE = "";
|
|
simulationNew.PRODUCTSTATUS = "GOOD";
|
|
|
|
simulationNew.LACTION = "GOOD";
|
|
simulationNew.ACTIONLIST = "GOOD";
|
|
simulationNew.NGTIMES = 0;
|
|
simulationNew.ISCOM = "0";
|
|
|
|
simulationNew.ISHOLD = 0;
|
|
simulationNew.SHELFNO = "";
|
|
simulationNew.MOSEQ = mouser.MOSEQ;
|
|
simulationNew.CollectStatus = "COLLECT_BEGIN";
|
|
//simulationNew.SEQ = 1;
|
|
simulationNew.BeginTime = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
|
|
}
|
|
else
|
|
{
|
|
if (simulationNew.OPCODE == simulation.OPCODE)
|
|
{
|
|
simulationNew.CollectStatus = "COLLECT_END";
|
|
}
|
|
else
|
|
{
|
|
simulationNew.CollectStatus = "COLLECT_BEGIN";
|
|
simulationNew.LOTSEQ = simulationNew.LOTSEQ + 1;
|
|
}
|
|
if (itemop.OPCODE == simulation.OPCODE && simulationNew.CollectStatus == "COLLECT_END")
|
|
{
|
|
simulationNew.ISCOM = "1";
|
|
}
|
|
}
|
|
simulationNew.OPCODE = simulation.OPCODE;
|
|
simulationNew.EQPCODE = simulation.EQPCODE;
|
|
|
|
simulationNew.EndTime = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
|
|
simulationNew.MUSER = AppConfig.UserCode;
|
|
simulationNew.MUSERName = AppConfig.UserName;
|
|
simulationNew.MTIME = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
|
|
simulationNew.WorkPoint = AppConfig.WorkPointCode;
|
|
if (simNew)
|
|
db.ICSLOTSIMULATION.InsertOnSubmit(simulationNew);
|
|
#endregion
|
|
|
|
bool wipNew = false;
|
|
ICSLOTONWIP onwipNew = db.ICSLOTONWIP.SingleOrDefault(a => a.LOTNO == simulationNew.LOTNO && a.LOTSEQ == simulationNew.LOTSEQ);
|
|
#region onwip
|
|
|
|
//ICSLOTONWIP onwipNew = new ICSLOTONWIP();
|
|
if (onwipNew == null)
|
|
{
|
|
wipNew = true;
|
|
onwipNew = new ICSLOTONWIP();
|
|
onwipNew.ID = AppConfig.GetGuid();
|
|
onwipNew.LOTNO = simulationNew.LOTNO;
|
|
onwipNew.LOTSEQ = simulationNew.LOTSEQ;
|
|
onwipNew.SEGCODE = "";
|
|
onwipNew.SSCODE = "";
|
|
onwipNew.SHIFTTYPECODE = "";
|
|
onwipNew.MOCODE = simulationNew.MOCODE;
|
|
//onwipNew.LOTSEQ = 0;
|
|
onwipNew.MODELCODE = simulationNew.MODELCODE;
|
|
onwipNew.ITEMCODE = simulationNew.ITEMCODE;
|
|
onwipNew.ROUTECODE = simulationNew.ROUTECODE;
|
|
onwipNew.RESCODE = simulationNew.RESCODE;
|
|
onwipNew.ACTION = "GOOD";
|
|
onwipNew.ACTIONRESULT = "COLLECT_BEGIN";
|
|
onwipNew.NGTIMES = simulationNew.NGTIMES;
|
|
onwipNew.SHELFNO = simulationNew.SHELFNO;
|
|
onwipNew.MOSEQ = simulationNew.MOSEQ;
|
|
onwipNew.Processed = 0;
|
|
onwipNew.LOTQTY = (int)simulationNew.LOTQTY;
|
|
onwipNew.GOODQTY = (int)simulationNew.GOODQTY;
|
|
onwipNew.NGQTY = (int)simulationNew.NGQTY;
|
|
|
|
onwipNew.BeginTime = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
|
|
onwipNew.UserCodeBegin = simulation.MUSER;
|
|
}
|
|
else
|
|
{
|
|
onwipNew.ACTIONRESULT = "COLLECT_END";
|
|
//调用接口生成四个单据
|
|
if (Convert.ToBoolean(ConfigurationManager.AppSettings["IsOpen"]))
|
|
{
|
|
var eqp = db.ICSEquipment.SingleOrDefault(a => a.EQPCode == simulation.EQPCODE);
|
|
//泛微设备回写109账套
|
|
if (eqp != null && eqp.MTStatus.Equals("是"))
|
|
{
|
|
var op = db.ICSOP.SingleOrDefault(a => a.OPCODE == simulationNew.OPCODE);
|
|
List<VouchHead> headList = new List<VouchHead>();
|
|
VouchHead head = new VouchHead();
|
|
head.cMemo = simulationNew.OPCODE + op.OPDESC;
|
|
head.UserCode = AppConfig.UserCode;
|
|
head.TargetAccount = ConfigurationManager.AppSettings["TargetAccount"];
|
|
head.list = new List<VouchBody>();
|
|
|
|
VouchBody body = new VouchBody();
|
|
body.cInvCode = simulationNew.ITEMCODE;
|
|
body.iQuantity = simulationNew.LOTQTY;
|
|
body.iNum = simulationNew.LOTQTY * lot.EATTRIBUTE3;
|
|
body.cBatch = lot.VenderLotNO;
|
|
body.MOCode = simulationNew.MOCODE;
|
|
body.MOSeq = simulationNew.MOSEQ.ToString();
|
|
body.OPCode = simulationNew.OPCODE;
|
|
var price = db.ICSItemOPPrice.Where(a => a.ITEMCODE == simulationNew.ITEMCODE && a.OPCODE == simulationNew.OPCODE).OrderByDescending(a => a.MTIME).FirstOrDefault();
|
|
body.iCost = price == null ? 0.1M : (price.Price ?? 0.1M);
|
|
head.list.Add(body);
|
|
headList.Add(head);
|
|
|
|
string Istr = JsonConvert.SerializeObject(headList);
|
|
string iresult = HttpPost(System.Configuration.ConfigurationSettings.AppSettings["APIURL"].ToString() + "APICreateVouch", Istr);
|
|
Result INVOUTResult = new Result();
|
|
INVOUTResult = JsonConvert.DeserializeObject<Result>(iresult);
|
|
if (INVOUTResult.code != "200")
|
|
{
|
|
throw new Exception(INVOUTResult.msg);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
onwipNew.OPCODE = simulationNew.OPCODE;
|
|
onwipNew.EQPCODE = simulationNew.EQPCODE;
|
|
onwipNew.RESCODE = simulation.RESCODE;
|
|
onwipNew.SHIFTTYPECODE = simulation.CHECKLOTNO;
|
|
|
|
onwipNew.EndTime = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
|
|
onwipNew.UserCodeEnd = simulation.MUSER;
|
|
|
|
onwipNew.MUSER = AppConfig.UserCode;
|
|
onwipNew.MUSERName = AppConfig.UserName;
|
|
onwipNew.MTIME = DateTime.Now;
|
|
onwipNew.WorkPoint = AppConfig.WorkPointCode;
|
|
if (wipNew)
|
|
{
|
|
db.ICSLOTONWIP.InsertOnSubmit(onwipNew);
|
|
}
|
|
#endregion
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
public static void Save(FramDataContext db, ICSLOTONWIP onwip)
|
|
{
|
|
try
|
|
{
|
|
var user = db.Sys_User.SingleOrDefault(a => a.UserCode == onwip.MUSER);
|
|
var mouser = db.ICSMO2User.SingleOrDefault(a => a.LOTNO == onwip.LOTNO && a.OPCODE == onwip.OPCODE);
|
|
var lot = db.ICSITEMLot.SingleOrDefault(a => a.LotNO == onwip.LOTNO);
|
|
var itemop = db.ICSITEMROUTE2OPLot.Where(a => a.LotNo == mouser.LOTNO && a.ITEMCODE == lot.ItemCode && a.ROUTECODE == mouser.RouteCode).OrderByDescending(a => a.OPSEQ).FirstOrDefault();
|
|
|
|
bool simNew = false;
|
|
var simulationNew = db.ICSLOTSIMULATION.SingleOrDefault(a => a.LOTNO == onwip.LOTNO);
|
|
#region simulation
|
|
//ICSLOTSIMULATION simulationNew = new ICSLOTSIMULATION();
|
|
if (simulationNew == null)
|
|
{
|
|
simNew = true;
|
|
simulationNew = new ICSLOTSIMULATION();
|
|
simulationNew.ID = AppConfig.GetGuid();
|
|
simulationNew.LOTNO = onwip.LOTNO;
|
|
simulationNew.MOCODE = mouser.MOCODE;
|
|
simulationNew.LOTSEQ = 0;
|
|
|
|
simulationNew.LOTQTY = Convert.ToInt32(lot.LOTQTY);
|
|
simulationNew.GOODQTY = simulationNew.LOTQTY;
|
|
simulationNew.NGQTY = 0;
|
|
simulationNew.LOTStatus = "新增";
|
|
|
|
simulationNew.MODELCODE = "";
|
|
simulationNew.ITEMCODE = lot.ItemCode;
|
|
simulationNew.FROMROUTE = "";
|
|
simulationNew.FROMOP = "";
|
|
|
|
simulationNew.ROUTECODE = mouser.RouteCode;
|
|
simulationNew.RESCODE = "";
|
|
simulationNew.CHECKLOTNO = "";
|
|
simulationNew.CARTONCODE = "";
|
|
simulationNew.PALLETCODE = "";
|
|
simulationNew.PRODUCTSTATUS = "GOOD";
|
|
|
|
simulationNew.LACTION = "GOOD";
|
|
simulationNew.ACTIONLIST = "GOOD";
|
|
simulationNew.NGTIMES = 0;
|
|
simulationNew.ISCOM = "0";
|
|
|
|
simulationNew.ISHOLD = 0;
|
|
simulationNew.SHELFNO = "";
|
|
simulationNew.MOSEQ = mouser.MOSEQ;
|
|
simulationNew.CollectStatus = "COLLECT_BEGIN";
|
|
//simulationNew.SEQ = 1;
|
|
simulationNew.BeginTime = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
|
|
}
|
|
else
|
|
{
|
|
//if (simulationNew.OPCODE == onwip.OPCODE)
|
|
//{
|
|
// simulationNew.CollectStatus = "COLLECT_END";
|
|
//}
|
|
//else
|
|
//{
|
|
// simulationNew.CollectStatus = "COLLECT_BEGIN";
|
|
// simulationNew.SEQ = simulationNew.SEQ + 1;
|
|
//}
|
|
if (itemop.OPCODE == onwip.OPCODE && simulationNew.CollectStatus == "COLLECT_END")
|
|
{
|
|
simulationNew.ISCOM = "1";
|
|
}
|
|
}
|
|
simulationNew.OPCODE = onwip.OPCODE;
|
|
simulationNew.EQPCODE = onwip.EQPCODE;
|
|
|
|
//simulationNew.EndTime = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
|
|
simulationNew.MUSER = AppConfig.UserCode;
|
|
simulationNew.MUSERName = AppConfig.UserName;
|
|
simulationNew.MTIME = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
|
|
simulationNew.WorkPoint = AppConfig.WorkPointCode;
|
|
if (simNew)
|
|
db.ICSLOTSIMULATION.InsertOnSubmit(simulationNew);
|
|
#endregion
|
|
|
|
bool wipNew = false;
|
|
ICSLOTONWIP onwipNew = db.ICSLOTONWIP.SingleOrDefault(a => a.LOTNO == simulationNew.LOTNO && a.OPCODE == simulationNew.OPCODE);
|
|
#region onwip
|
|
|
|
//ICSLOTONWIP onwipNew = new ICSLOTONWIP();
|
|
if (onwipNew == null)
|
|
{
|
|
wipNew = true;
|
|
onwipNew = new ICSLOTONWIP();
|
|
onwipNew.ID = AppConfig.GetGuid();
|
|
onwipNew.LOTNO = simulationNew.LOTNO;
|
|
onwipNew.LOTSEQ = simulationNew.LOTSEQ;
|
|
onwipNew.SEGCODE = "";
|
|
onwipNew.SSCODE = "";
|
|
onwipNew.SHIFTTYPECODE = "";
|
|
onwipNew.MOCODE = simulationNew.MOCODE;
|
|
onwipNew.LOTSEQ = 0;
|
|
onwipNew.MODELCODE = simulationNew.MODELCODE;
|
|
onwipNew.ITEMCODE = simulationNew.ITEMCODE;
|
|
onwipNew.ROUTECODE = simulationNew.ROUTECODE;
|
|
onwipNew.RESCODE = simulationNew.RESCODE;
|
|
onwipNew.ACTION = "GOOD";
|
|
onwipNew.ACTIONRESULT = "COLLECT_BEGIN";
|
|
onwipNew.NGTIMES = simulationNew.NGTIMES;
|
|
onwipNew.SHELFNO = simulationNew.SHELFNO;
|
|
onwipNew.MOSEQ = simulationNew.MOSEQ;
|
|
onwipNew.Processed = 0;
|
|
onwipNew.LOTQTY = (int)simulationNew.LOTQTY;
|
|
onwipNew.GOODQTY = (int)simulationNew.GOODQTY;
|
|
onwipNew.NGQTY = (int)simulationNew.NGQTY;
|
|
|
|
onwipNew.BeginTime = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
|
|
onwipNew.UserCodeBegin = onwip.MUSER;
|
|
}
|
|
else
|
|
{
|
|
onwipNew.ACTIONRESULT = "COLLECT_END";
|
|
////调用接口生成四个单据
|
|
//if (Convert.ToBoolean(ConfigurationManager.AppSettings["IsOpen"]))
|
|
//{
|
|
// var eqp = db.ICSEquipment.SingleOrDefault(a => a.EQPCode == simulation.EQPCODE);
|
|
// //泛微设备回写109账套
|
|
// if (eqp != null && eqp.MTStatus.Equals("是"))
|
|
// {
|
|
// var op = db.ICSOP.SingleOrDefault(a => a.OPCODE == simulationNew.OPCODE);
|
|
// List<VouchHead> headList = new List<VouchHead>();
|
|
// VouchHead head = new VouchHead();
|
|
// head.cMemo = simulationNew.OPCODE + op.OPDESC;
|
|
// head.UserCode = AppConfig.UserCode;
|
|
// head.TargetAccount = ConfigurationManager.AppSettings["TargetAccount"];
|
|
// head.list = new List<VouchBody>();
|
|
|
|
// VouchBody body = new VouchBody();
|
|
// body.cInvCode = simulationNew.ITEMCODE;
|
|
// body.iQuantity = simulationNew.LOTQTY;
|
|
// body.iNum = simulationNew.LOTQTY * lot.EATTRIBUTE3;
|
|
// body.cBatch = lot.VenderLotNO;
|
|
// body.MOCode = simulationNew.MOCODE;
|
|
// body.MOSeq = simulationNew.MOSEQ.ToString();
|
|
// body.OPCode = simulationNew.OPCODE;
|
|
// var price = db.ICSItemOPPrice.Where(a => a.ITEMCODE == simulationNew.ITEMCODE && a.OPCODE == simulationNew.OPCODE).OrderByDescending(a => a.MTIME).FirstOrDefault();
|
|
// body.iCost = price == null ? 0.1M : (price.Price ?? 0.1M);
|
|
// head.list.Add(body);
|
|
// headList.Add(head);
|
|
|
|
// string Istr = JsonConvert.SerializeObject(headList);
|
|
// string iresult = HttpPost(System.Configuration.ConfigurationSettings.AppSettings["APIURL"].ToString() + "APICreateVouch", Istr);
|
|
// Result INVOUTResult = new Result();
|
|
// INVOUTResult = JsonConvert.DeserializeObject<Result>(iresult);
|
|
// if (INVOUTResult.code != "200")
|
|
// {
|
|
// throw new Exception(INVOUTResult.msg);
|
|
// }
|
|
// }
|
|
//}
|
|
}
|
|
|
|
onwipNew.OPCODE = simulationNew.OPCODE;
|
|
onwipNew.EQPCODE = simulationNew.EQPCODE;
|
|
onwipNew.RESCODE = onwip.RESCODE;
|
|
//onwipNew.SHIFTTYPECODE = onwip.CHECKLOTNO;
|
|
|
|
onwipNew.EndTime = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
|
|
onwipNew.UserCodeEnd = onwip.MUSER;
|
|
|
|
onwipNew.MUSER = AppConfig.UserCode;
|
|
onwipNew.MUSERName = AppConfig.UserName;
|
|
onwipNew.MTIME = DateTime.Now;
|
|
onwipNew.WorkPoint = AppConfig.WorkPointCode;
|
|
if (wipNew)
|
|
{
|
|
db.ICSLOTONWIP.InsertOnSubmit(onwipNew);
|
|
}
|
|
#endregion
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
public static void SaveLogInfo(FramDataContext db, ICSLOTSIMULATION simulation, bool IsSend)
|
|
{
|
|
var lotinfolog = db.ICSWareHouseLotInfoLog.Where(a => a.LotNO == simulation.LOTNO).FirstOrDefault();
|
|
if (IsSend == true)
|
|
{
|
|
lotinfolog = db.ICSWareHouseLotInfoLog.Where(a => a.LotNO == simulation.LOTNO && a.Memo == simulation.OPCODE && a.BusinessCode == "委外发料" && a.TransType == "发").FirstOrDefault();
|
|
}
|
|
else
|
|
{
|
|
lotinfolog = db.ICSWareHouseLotInfoLog.Where(a => a.LotNO == simulation.LOTNO && a.BusinessCode == "委外发料" && a.TransType == "发" && a.Memo == simulation.OPCODE).FirstOrDefault();
|
|
}
|
|
var poinfo = db.ICSPO_PoMain.Where(a => a.POCode == lotinfolog.TransNO && a.InvCode == lotinfolog.ITEMCODE.Split('_')[0] + "_" + simulation.OPCODE).FirstOrDefault();
|
|
#region ICSWareHouseLotInfolog
|
|
var log = db.ICSWareHouseLotInfoLog.SingleOrDefault(a => a.LotNO == simulation.LOTNO && a.Memo == simulation.OPCODE && a.TransType == "收" && a.BusinessCode == "委外发料");
|
|
if (log == null)
|
|
{
|
|
ICSWareHouseLotInfoLog infolog = new ICSWareHouseLotInfoLog();
|
|
infolog.ID = AppConfig.GetGuid();
|
|
infolog.TransNO = lotinfolog.TransNO;
|
|
infolog.TransLine = lotinfolog.TransLine;
|
|
infolog.ITEMCODE = lotinfolog.ITEMCODE;
|
|
infolog.LotNO = lotinfolog.LotNO;
|
|
infolog.Memo = simulation.OPCODE;
|
|
infolog.TransQTY = lotinfolog.TransQTY;
|
|
infolog.TransType = "收";
|
|
infolog.BusinessCode = "委外发料";
|
|
infolog.MUSER = AppConfig.UserCode;
|
|
infolog.MUSERName = AppConfig.UserName;
|
|
infolog.WorkPoint = lotinfolog.WorkPoint;
|
|
infolog.MTIME = DateTime.Now;
|
|
db.ICSWareHouseLotInfoLog.InsertOnSubmit(infolog);
|
|
}
|
|
#endregion
|
|
}
|
|
public static void CheckListEnd(FramDataContext db, List<ICSLOTSIMULATION> InfoList)
|
|
{
|
|
foreach (ICSLOTSIMULATION info in InfoList)
|
|
{
|
|
var lotinfo = from A in db.ICSWareHouseLotInfoLog
|
|
where A.LotNO == info.LOTNO && A.BusinessCode == "委外发料" && A.TransType == "发"
|
|
select A;
|
|
foreach (var lotno in lotinfo)
|
|
{
|
|
var endlot = db.ICSWareHouseLotInfoLog.SingleOrDefault(a => a.LotNO == lotno.LotNO && a.Memo == lotno.Memo && a.BusinessCode == "委外发料" && a.TransType == "收");
|
|
if (endlot == null)
|
|
{
|
|
ICSWareHouseLotInfoLog infolog = new ICSWareHouseLotInfoLog();
|
|
infolog.ID = AppConfig.GetGuid();
|
|
infolog.TransNO = lotno.TransNO;
|
|
infolog.TransLine = lotno.TransLine;
|
|
infolog.ITEMCODE = lotno.ITEMCODE;
|
|
infolog.LotNO = lotno.LotNO;
|
|
infolog.Memo = lotno.Memo;
|
|
infolog.TransQTY = lotno.TransQTY;
|
|
infolog.TransType = "收";
|
|
infolog.BusinessCode = "委外发料";
|
|
infolog.MUSER = AppConfig.UserCode;
|
|
infolog.MUSERName = AppConfig.UserName;
|
|
infolog.WorkPoint = lotno.WorkPoint;
|
|
infolog.MTIME = DateTime.Now;
|
|
db.ICSWareHouseLotInfoLog.InsertOnSubmit(infolog);
|
|
db.SubmitChanges();
|
|
}
|
|
}
|
|
db.SubmitChanges();
|
|
}
|
|
}
|
|
public static void CheckAutoOP(FramDataContext db, List<ICSLOTSIMULATION> InfoList)
|
|
{
|
|
throw new Exception("表变更,注释掉此方法内容");
|
|
//foreach (ICSLOTSIMULATION info in InfoList)
|
|
//{
|
|
// int OPSEQ = 0;
|
|
// var opinfo = from A in db.ICSMO2User
|
|
// join B in db.ICSITEMROUTE2OPLot
|
|
// on A.LOTNO equals B.LotNo
|
|
// where A.OPCODE == B.OPCODE && A.OPCODE == info.OPCODE && A.LOTNO == info.LOTNO
|
|
// select B;
|
|
// foreach (var OP in opinfo)
|
|
// {
|
|
// OPSEQ = OP.OPSEQ;
|
|
// }
|
|
// var Status = db.ICSLOTSIMULATION.SingleOrDefault(a => a.LOTNO == info.LOTNO && a.OPCODE == info.OPCODE && a.CollectStatus == "COLLECT_BEGIN" && a.WorkPoint == AppConfig.WorkPointCode);
|
|
// if (Status != null)
|
|
// {
|
|
// Save(db, info);
|
|
// SaveLogInfo(db, Status, true);
|
|
// }
|
|
// else
|
|
// {
|
|
// var lotinfo = db.ICSLOTSIMULATION.SingleOrDefault(a => a.LOTNO == info.LOTNO && a.WorkPoint == AppConfig.WorkPointCode);
|
|
// if (lotinfo.CollectStatus == "COLLECT_END")
|
|
// {
|
|
// throw new Exception("跟踪单:" + lotinfo.LOTNO + "没有对应工序不是已发料的状态,不能进行委外收料!");
|
|
// }
|
|
// else
|
|
// {
|
|
// var opseqmin = db.ICSITEMROUTE2OPLot.SingleOrDefault(a => a.LotNo == lotinfo.LOTNO && a.OPCODE == lotinfo.OPCODE);
|
|
// //var opseq = from A in db.ICSMO2User
|
|
// // join B in db.ICSITEMROUTE2OPLot
|
|
// // on A.LOTNO equals B.LotNo
|
|
// // where B.OPSEQ > lotinfo.SEQ && B.OPSEQ <= OPSEQ && A.OPCODE == B.OPCODE && A.LOTNO == lotinfo.LOTNO
|
|
// // && A.EATTRIBUTE1 == "1"
|
|
// // select A;
|
|
// var opseq = from A in db.ICSITEMROUTE2OPLot
|
|
// join B in db.ICSMO2User
|
|
// on A.LotNo equals B.LOTNO
|
|
// where A.OPSEQ >= opseqmin.OPSEQ && A.OPSEQ <= OPSEQ && A.OPCODE == B.OPCODE && B.LOTNO == lotinfo.LOTNO
|
|
// && B.EATTRIBUTE1 == "1"
|
|
// orderby A.OPSEQ
|
|
// select B;
|
|
// if (opseq == null)
|
|
// {
|
|
// throw new Exception("上级委外工序尚未发料,不能进行委外收料!");
|
|
// }
|
|
// else
|
|
// {
|
|
// foreach (var lot in opseq)
|
|
// {
|
|
// ICSLOTSIMULATION simulation = new ICSLOTSIMULATION();
|
|
// simulation.MUSER = AppConfig.UserCode;
|
|
// simulation.LOTNO = lot.LOTNO;
|
|
// simulation.OPCODE = lot.OPCODE;
|
|
// simulation.EQPCODE = lot.EQPCode;
|
|
// var simulationinfo = db.ICSLOTSIMULATION.SingleOrDefault(a => a.LOTNO == lot.LOTNO && a.OPCODE == lot.OPCODE);
|
|
// if (simulationinfo == null)
|
|
// {
|
|
// simulation.ID = AppConfig.GetGuid();
|
|
// for (int i = 0; i < 2; i++)
|
|
// {
|
|
// Save(db, simulation);
|
|
// SaveLogInfo(db, simulation, false);
|
|
// db.SubmitChanges();
|
|
// }
|
|
// if (lot.OPCODE != info.OPCODE)
|
|
// {
|
|
// var onwipcheck = db.ICSLOTONWIP.SingleOrDefault(a => a.LOTNO == lot.LOTNO && a.OPCODE == lot.OPCODE);
|
|
// var check = new ICSLOTONWIPCheck();
|
|
// check.ID = AppConfig.GetGuid();
|
|
// check.ONWIPID = onwipcheck.ID;
|
|
// check.Result = "待检";
|
|
// check.USER = null;
|
|
// check.TIME = null;
|
|
// //check.RUSER = AppConfig.UserCode;
|
|
// //check.RTIME = DateTime.Now;
|
|
// check.MUSER = AppConfig.UserCode;
|
|
// check.MUSERName = AppConfig.UserName;
|
|
// check.MTIME = DateTime.Now;
|
|
// check.WorkPoint = AppConfig.WorkPointCode;
|
|
// db.ICSLOTONWIPCheck.InsertOnSubmit(check);
|
|
// }
|
|
// }
|
|
// else
|
|
// {
|
|
// simulationinfo.CollectStatus = "COLLECT_END";
|
|
// Save(db, simulationinfo);
|
|
// db.SubmitChanges();
|
|
// if (lot.OPCODE != info.OPCODE)
|
|
// {
|
|
// var onwipcheck = db.ICSLOTONWIP.SingleOrDefault(a => a.LOTNO == lot.LOTNO && a.OPCODE == lot.OPCODE);
|
|
// var check = new ICSLOTONWIPCheck();
|
|
// check.ID = AppConfig.GetGuid();
|
|
// check.ONWIPID = onwipcheck.ID;
|
|
// check.Result = "待检";
|
|
// check.USER = null;
|
|
// check.TIME = null;
|
|
// //check.RUSER = AppConfig.UserCode;
|
|
// //check.RTIME = DateTime.Now;
|
|
// check.MUSER = AppConfig.UserCode;
|
|
// check.MUSERName = AppConfig.UserName;
|
|
// check.MTIME = DateTime.Now;
|
|
// check.WorkPoint = AppConfig.WorkPointCode;
|
|
// db.ICSLOTONWIPCheck.InsertOnSubmit(check);
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
//}
|
|
}
|
|
|
|
public static void CheckTransferInfo(FramDataContext db, ICSLOTSIMULATION simulation)
|
|
{
|
|
try
|
|
{
|
|
var user = db.Sys_User.SingleOrDefault(a => a.UserCode == simulation.MUSER);
|
|
if (user == null)
|
|
throw new Exception("用户不存在!");
|
|
|
|
var mouser = db.ICSMO2User.SingleOrDefault(a => a.LOTNO == simulation.LOTNO && a.OPCODE == simulation.OPCODE);
|
|
if (mouser == null)
|
|
throw new Exception("批次工序派工信息不存在!");
|
|
|
|
var mo = db.ICSMO.SingleOrDefault(a => a.MOCODE == mouser.MOCODE && a.MOSEQ == mouser.MOSEQ.ToString());
|
|
if (mo == null)
|
|
throw new Exception("工单信息不存在!");
|
|
|
|
var moroute = db.ICSMO2ROUTE.SingleOrDefault(a => a.MOID == mo.ID);
|
|
if (moroute == null)
|
|
throw new Exception("工单未关联途程!");
|
|
|
|
if (moroute.ROUTECODE != mouser.RouteCode)
|
|
throw new Exception("工单途程与派工途程不同!");
|
|
|
|
var itemop = db.ICSITEMROUTE2OPLot.SingleOrDefault(a => a.LotNo == mouser.LOTNO && a.ITEMCODE == mo.ITEMCODE && a.ROUTECODE == moroute.ROUTECODE && a.OPCODE == mouser.OPCODE);
|
|
if (itemop == null)
|
|
throw new Exception("产品途程工序不存在!");
|
|
|
|
var sim = db.ICSLOTSIMULATION.SingleOrDefault(a => a.LOTNO == simulation.LOTNO);
|
|
var itemops = db.ICSITEMROUTE2OPLot.Where(a => a.LotNo == mouser.LOTNO && a.ITEMCODE == itemop.ITEMCODE && a.ROUTECODE == itemop.ROUTECODE && a.OPSEQ < itemop.OPSEQ);
|
|
if (sim == null && itemops != null && itemops.Count() > 0)
|
|
throw new Exception("请从第一道工序开始报工!");
|
|
|
|
ICSLOTONWIP onwip = db.ICSLOTONWIP.SingleOrDefault(a => a.LOTNO == sim.LOTNO && a.LOTSEQ == sim.LOTSEQ);
|
|
|
|
//判断
|
|
if (sim == null)
|
|
{
|
|
throw new Exception("该批次不是在制品,任务不能转移!");
|
|
}
|
|
else if (onwip == null)
|
|
{
|
|
throw new Exception("该批次工序不是在制品,任务不能转移!");
|
|
}
|
|
else
|
|
{
|
|
if (sim.ISCOM == "1")
|
|
{
|
|
throw new Exception("该批次已完工!");
|
|
}
|
|
if (sim.LOTStatus.Equals("暂停"))
|
|
{
|
|
throw new Exception("该批次工序处于暂停状态,任务不能转移!");
|
|
}
|
|
if (sim.CollectStatus == "COLLECT_END")
|
|
{
|
|
throw new Exception("该工序已经完工,任务不能转移!");
|
|
}
|
|
if (onwip.UserCodeBegin.Equals(simulation.MUSER) && onwip.EQPCODE.Equals(simulation.EQPCODE))
|
|
{
|
|
throw new Exception("同一员工同一设备,任务不需要转移!");
|
|
}
|
|
if (sim.OPCODE != simulation.OPCODE)
|
|
{
|
|
throw new Exception("采集工序与输入工序不对应!");
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
public static void Transfer(FramDataContext db, ICSLOTSIMULATION simulation)
|
|
{
|
|
try
|
|
{
|
|
var user = db.Sys_User.SingleOrDefault(a => a.UserCode == simulation.MUSER);
|
|
var mouser = db.ICSMO2User.SingleOrDefault(a => a.LOTNO == simulation.LOTNO && a.OPCODE == simulation.OPCODE);
|
|
var lot = db.ICSITEMLot.SingleOrDefault(a => a.LotNO == simulation.LOTNO);
|
|
var itemop = db.ICSITEMROUTE2OPLot.Where(a => a.LotNo == mouser.LOTNO && a.ITEMCODE == lot.ItemCode && a.ROUTECODE == mouser.RouteCode).OrderByDescending(a => a.OPSEQ).FirstOrDefault();
|
|
|
|
var simulationNew = db.ICSLOTSIMULATION.SingleOrDefault(a => a.LOTNO == simulation.LOTNO);
|
|
ICSLOTONWIP onwip = db.ICSLOTONWIP.SingleOrDefault(a => a.LOTNO == simulationNew.LOTNO && a.LOTSEQ == simulationNew.LOTSEQ);
|
|
#region simulation
|
|
//ICSLOTSIMULATION simulationNew = new ICSLOTSIMULATION();
|
|
if (simulationNew == null)
|
|
{
|
|
throw new Exception("该批次不是在制品,任务不能转移!");
|
|
}
|
|
else
|
|
{
|
|
simulationNew.LOTSEQ = simulationNew.LOTSEQ + 1;
|
|
}
|
|
simulationNew.EQPCODE = simulation.EQPCODE;
|
|
|
|
simulationNew.EndTime = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
|
|
simulationNew.MUSER = AppConfig.UserCode;
|
|
simulationNew.MUSERName = AppConfig.UserName;
|
|
simulationNew.MTIME = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
|
|
simulationNew.WorkPoint = AppConfig.WorkPointCode;
|
|
#endregion
|
|
|
|
#region onwip
|
|
//ICSLOTONWIP onwipNew = new ICSLOTONWIP();
|
|
if (onwip == null)
|
|
{
|
|
throw new Exception("该批次工序未开工,任务不能转移!");
|
|
}
|
|
else
|
|
onwip.ACTIONRESULT = "COLLECT_END";
|
|
|
|
onwip.EATTRIBUTE1 = "转移";
|
|
onwip.OPCODE = simulationNew.OPCODE;
|
|
//onwip.EQPCODE = simulationNew.EQPCODE;
|
|
|
|
onwip.EndTime = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
|
|
//onwip.UserCodeEnd = simulation.MUSER;
|
|
|
|
onwip.MUSER = AppConfig.UserCode;
|
|
onwip.MUSERName = AppConfig.UserName;
|
|
onwip.MTIME = DateTime.Now;
|
|
onwip.WorkPoint = AppConfig.WorkPointCode;
|
|
#endregion
|
|
|
|
#region onwip
|
|
ICSLOTONWIP onwipNew = new ICSLOTONWIP();
|
|
onwipNew.ID = AppConfig.GetGuid();
|
|
|
|
onwipNew.LOTNO = onwip.LOTNO;
|
|
onwipNew.MOCODE = onwip.MOCODE;
|
|
onwipNew.LOTSEQ = onwip.LOTSEQ;
|
|
onwipNew.MODELCODE = onwip.MODELCODE;
|
|
onwipNew.ITEMCODE = onwip.ITEMCODE;
|
|
onwipNew.ROUTECODE = onwip.ROUTECODE;
|
|
onwipNew.OPCODE = onwip.OPCODE;
|
|
onwipNew.SEGCODE = onwip.SEGCODE;
|
|
onwipNew.SSCODE = onwip.SSCODE;
|
|
onwipNew.RESCODE = onwip.RESCODE;
|
|
onwipNew.EQPCODE = simulationNew.EQPCODE;
|
|
onwipNew.SHIFTTYPECODE = onwip.SHIFTTYPECODE;
|
|
onwipNew.ACTION = onwip.ACTION;
|
|
onwipNew.ACTIONRESULT = "COLLECT_BEGIN";
|
|
onwipNew.NGTIMES = onwip.NGTIMES;
|
|
onwipNew.SHELFNO = onwip.SHELFNO;
|
|
onwipNew.MOSEQ = onwip.MOSEQ;
|
|
onwipNew.Processed = onwip.Processed;
|
|
onwipNew.LOTQTY = onwip.LOTQTY;
|
|
onwipNew.GOODQTY = onwip.GOODQTY;
|
|
onwipNew.NGQTY = onwip.NGQTY;
|
|
|
|
|
|
onwipNew.UserCodeBegin = simulation.MUSER;
|
|
onwipNew.BeginTime = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
|
|
|
|
onwipNew.EndTime = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
|
|
onwipNew.UserCodeEnd = simulation.MUSER;
|
|
onwipNew.RESCODE = simulation.RESCODE;
|
|
onwipNew.SHIFTTYPECODE = simulation.CHECKLOTNO;
|
|
|
|
onwipNew.MUSER = AppConfig.UserCode;
|
|
onwipNew.MUSERName = AppConfig.UserName;
|
|
onwipNew.MTIME = DateTime.Now;
|
|
onwipNew.WorkPoint = AppConfig.WorkPointCode;
|
|
db.ICSLOTONWIP.InsertOnSubmit(onwipNew);
|
|
#endregion
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
public static void CheckItemInfo(FramDataContext db, ICSLOTONWIPITEM simulation)
|
|
{
|
|
try
|
|
{
|
|
var user = db.Sys_User.SingleOrDefault(a => a.UserCode == simulation.MUSER);
|
|
if (user == null)
|
|
throw new Exception("用户不存在!");
|
|
|
|
var mouser = db.ICSMO2User.SingleOrDefault(a => a.LOTNO == simulation.LOTNO && a.OPCODE == simulation.OPCODE);
|
|
if (mouser == null)
|
|
throw new Exception("批次工序派工信息不存在!");
|
|
|
|
var mo = db.ICSMO.SingleOrDefault(a => a.MOCODE == mouser.MOCODE && a.MOSEQ == mouser.MOSEQ.ToString());
|
|
if (mo == null)
|
|
throw new Exception("工单信息不存在!");
|
|
|
|
var moroute = db.ICSMO2ROUTE.SingleOrDefault(a => a.MOID == mo.ID);
|
|
if (moroute == null)
|
|
throw new Exception("工单未关联途程!");
|
|
|
|
if (moroute.ROUTECODE != mouser.RouteCode)
|
|
throw new Exception("工单途程与派工途程不同!");
|
|
|
|
var itemop = db.ICSITEMROUTE2OPLot.SingleOrDefault(a => a.LotNo == mouser.LOTNO && a.ITEMCODE == mo.ITEMCODE && a.ROUTECODE == moroute.ROUTECODE && a.OPCODE == mouser.OPCODE);
|
|
if (itemop == null)
|
|
throw new Exception("产品途程工序不存在!");
|
|
//获取上料历史记录信息
|
|
var LotOnWipItem = db.ICSLOTONWIPITEM.SingleOrDefault(a => a.LOTNO == simulation.LOTNO &&
|
|
a.INVLOTNO == simulation.INVLOTNO && a.OPCODE == simulation.OPCODE && a.WorkPoint == AppConfig.WorkPointCode);
|
|
if (LotOnWipItem != null)
|
|
{
|
|
//上料信息已存在,不用上料
|
|
throw new Exception("上料信息已存在!");
|
|
}
|
|
|
|
//检验在制品批次信息
|
|
var sim = db.ICSLOTSIMULATION.SingleOrDefault(a => a.LOTNO == simulation.LOTNO);
|
|
if (sim == null)
|
|
{
|
|
throw new Exception("该批次不是在制品,不能上料!");
|
|
}
|
|
else if (sim.OPCODE != simulation.OPCODE)
|
|
{
|
|
throw new Exception("不应该在工序:" + simulation.OPCODE + " 上料,请更换工序条码:" + sim.OPCODE);
|
|
}
|
|
else if (sim.ISCOM == "1")
|
|
{
|
|
throw new Exception("该批次已完工!");
|
|
}
|
|
if (sim.LOTStatus.Equals("暂停"))
|
|
{
|
|
throw new Exception("该批次工序处于暂停状态,不能上料!");
|
|
}
|
|
if (sim.CollectStatus == "COLLECT_END")
|
|
{
|
|
throw new Exception("该批次工序已经完工,不能上料!");
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
public static void SaveItem(FramDataContext db, ICSLOTONWIPITEM simulation)
|
|
{
|
|
try
|
|
{
|
|
var user = db.Sys_User.SingleOrDefault(a => a.UserCode == simulation.MUSER);
|
|
//var mouser = db.ICSMO2User.SingleOrDefault(a => a.LOTNO == simulation.LOTNO && a.OPCODE == simulation.OPCODE);
|
|
//var itemop = db.ICSITEMROUTE2OPLot.Where(a => a.LotNo == mouser.LOTNO && a.ITEMCODE == lot.ItemCode && a.ROUTECODE == mouser.RouteCode).OrderByDescending(a => a.OPSEQ).FirstOrDefault();
|
|
|
|
var lot = db.ICSITEMLot.SingleOrDefault(a => a.LotNO == simulation.INVLOTNO);
|
|
var simulationNew = db.ICSLOTSIMULATION.SingleOrDefault(a => a.LOTNO == simulation.LOTNO);
|
|
ICSLOTONWIP onwipNew = db.ICSLOTONWIP.SingleOrDefault(a => a.LOTNO == simulationNew.LOTNO && a.LOTSEQ == simulationNew.LOTSEQ);
|
|
|
|
ICSLOTONWIPITEM wipItem = new ICSLOTONWIPITEM();
|
|
wipItem.ID = AppConfig.GetGuid();
|
|
wipItem.LOTNO = onwipNew.LOTNO;
|
|
wipItem.INVCODE = lot.ItemCode;
|
|
wipItem.MCARDTYPE = onwipNew.EATTRIBUTE1;
|
|
wipItem.ITEMCODE = onwipNew.ITEMCODE;
|
|
wipItem.RESCODE = onwipNew.RESCODE;
|
|
wipItem.ROUTECODE = onwipNew.ROUTECODE;
|
|
wipItem.SEGCODE = onwipNew.SEGCODE;
|
|
wipItem.SHIFTTYPECODE = "";
|
|
wipItem.SSCODE = onwipNew.SSCODE;
|
|
wipItem.MOCODE = onwipNew.MOCODE;
|
|
wipItem.MODELCODE = onwipNew.MODELCODE;
|
|
wipItem.OPCODE = onwipNew.OPCODE;
|
|
|
|
wipItem.BeginSHIFTCODE = onwipNew.SHIFTTYPECODE;
|
|
wipItem.EndSHIFTCODE = onwipNew.SHIFTTYPECODE;
|
|
wipItem.BeginTPCODE = "";
|
|
wipItem.ENDTPCODE = "";
|
|
wipItem.INVLOTNO = simulation.INVLOTNO;
|
|
wipItem.MUSER = user.UserCode;
|
|
wipItem.MUSERName = user.UserName;
|
|
wipItem.MTIME = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
|
|
wipItem.WorkPoint = AppConfig.WorkPointCode;
|
|
wipItem.QTY = (decimal)onwipNew.LOTQTY;
|
|
wipItem.TRANSSTATUS = "否";
|
|
wipItem.MCARDTYPE = "1";
|
|
wipItem.LOTSEQ = (int)onwipNew.LOTSEQ;
|
|
//新增 采集类型
|
|
wipItem.ACTIONTYPE = 0;
|
|
wipItem.MOSEQ = onwipNew.MOSEQ;
|
|
|
|
db.ICSLOTONWIPITEM.InsertOnSubmit(wipItem);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
public static void Pause(FramDataContext db, ICSLOTSIMULATION simulation)
|
|
{
|
|
try
|
|
{
|
|
//var line = db.ICSLOTSIMULATION.SingleOrDefault(a => a.LOTNO == simulation.LOTNO);
|
|
//if (line != null && line.LOTStatus.Equals("暂停"))
|
|
//{
|
|
// throw new Exception("该批次工序已经暂停!");
|
|
//}
|
|
#region LOTPAUSE
|
|
ICSLOTPAUSE lotpause = new ICSLOTPAUSE();
|
|
lotpause.ID = AppConfig.GetGuid();
|
|
lotpause.LOTNO = simulation.LOTNO;
|
|
lotpause.MOCODE = simulation.MOCODE;
|
|
lotpause.LOTSEQ = int.Parse(simulation.LOTSEQ.ToString());
|
|
|
|
//lotpause.SEQ = ;
|
|
lotpause.MODELCODE = simulation.MODELCODE;
|
|
lotpause.ITEMCODE = simulation.ITEMCODE;
|
|
lotpause.ROUTECODE = simulation.ROUTECODE;
|
|
lotpause.OPCODE = simulation.OPCODE;
|
|
lotpause.RESCODE = simulation.RESCODE;
|
|
lotpause.EQPCODE = simulation.EQPCODE;
|
|
lotpause.BeginTime = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
|
|
lotpause.SEQ = simulation.LOTSEQ;
|
|
lotpause.MUSER = AppConfig.UserCode;
|
|
lotpause.MUSERName = AppConfig.UserName;
|
|
lotpause.MTIME = DateTime.Now;
|
|
lotpause.WorkPoint = AppConfig.WorkPointCode;
|
|
lotpause.EATTRIBUTE1 = simulation.EATTRIBUTE1;
|
|
#endregion
|
|
|
|
db.ICSLOTPAUSE.InsertOnSubmit(lotpause);
|
|
//更新采集表状态
|
|
simulation.LOTStatus = "暂停";
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
//public static ICSLOTONWIPCheck GetModel(string id, string dsconn)
|
|
//{
|
|
// //FramDataContext db = new FramDataContext(dsconn);
|
|
// //db.Connection.Open();
|
|
// //db.Transaction = db.Connection.BeginTransaction();
|
|
// //try
|
|
// //{
|
|
// // var line = db.ICSLOTONWIPCheck.SingleOrDefault(a => a.ID == id);
|
|
// // if (line != null)
|
|
// // {
|
|
// // return line;
|
|
|
|
// // }
|
|
// // return null;
|
|
// //}
|
|
// //catch (Exception ex)
|
|
// //{
|
|
// // db.Transaction.Rollback();
|
|
// // throw new Exception(ex.Message);
|
|
// //}
|
|
|
|
//}
|
|
|
|
#region 保存PDF
|
|
public static void AddPDF(string id, string fname, string dsconn)
|
|
{
|
|
|
|
//FramDataContext db = new FramDataContext(dsconn);
|
|
//db.Connection.Open();
|
|
//db.Transaction = db.Connection.BeginTransaction();
|
|
//try
|
|
//{
|
|
// var line = db.ICSLOTONWIPCheck.SingleOrDefault(a => a.ID == id);
|
|
// if (line != null)
|
|
// {
|
|
// line.EATTRIBUTE1 = fname;
|
|
|
|
// }
|
|
// db.SubmitChanges();
|
|
// db.Transaction.Commit();
|
|
//}
|
|
//catch (Exception ex)
|
|
//{
|
|
// db.Transaction.Rollback();
|
|
// throw new Exception(ex.Message);
|
|
//}
|
|
}
|
|
#endregion
|
|
|
|
public static void CancelPause(FramDataContext db, ICSLOTSIMULATION simulation)
|
|
{
|
|
try
|
|
{
|
|
ICSLOTPAUSE line = db.ICSLOTPAUSE.SingleOrDefault(a => a.LOTNO == simulation.LOTNO && a.OPCODE == simulation.OPCODE && a.EndTime == null);
|
|
if (line != null)
|
|
{
|
|
line.EndTime = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
|
|
|
|
line.MUSER = AppConfig.UserCode;
|
|
line.MUSERName = AppConfig.UserName;
|
|
line.MTIME = DateTime.Now;
|
|
line.WorkPoint = AppConfig.WorkPointCode;
|
|
|
|
//更新采集表状态
|
|
var sim = db.ICSLOTSIMULATION.SingleOrDefault(a => a.LOTNO == line.LOTNO);
|
|
sim.LOTStatus = "取消暂停";
|
|
}
|
|
else
|
|
{
|
|
throw new Exception("已取消暂停,无需再次操作!");
|
|
}
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
//结算料费
|
|
public static void Calculate(FramDataContext db, List<string> list, string Result)
|
|
{
|
|
throw new Exception("表变更,注释掉此方法内容");
|
|
//try
|
|
//{
|
|
// //调用接口生成三个单据
|
|
// if (Convert.ToBoolean(ConfigurationManager.AppSettings["IsOpen"]))
|
|
// {
|
|
|
|
// var data = from a in db.ICSLOTONWIPCheck
|
|
// join b in db.ICSLOTONWIP on a.ONWIPID equals b.ID
|
|
// join c in db.ICSITEMLot on b.LOTNO equals c.LotNO
|
|
// join d in db.ICSMO on c.TransNO + c.TransLine equals d.MOCODE + d.MOSEQ
|
|
// join e in db.ICSWareHouseLotInfoLog on b.LOTNO + b.OPCODE equals e.LotNO + e.Memo
|
|
// join f in db.ICSPO_PoMain on e.TransNO + e.TransLine equals f.POCode + f.PORow
|
|
// where list.Contains(a.ID) && e.BusinessCode == "委外发料" && e.TransType == "收" && a.Result == Result
|
|
// orderby f.WBS, d.EATTRIBUTE1
|
|
// select new
|
|
// {
|
|
// CheckID = a.ID,
|
|
// UserCode = AppConfig.UserCode,
|
|
// POID = f.WBS,
|
|
// cIWhCode = ConfigurationManager.AppSettings["WHCode"].ToString(),
|
|
// cOWhCode = ConfigurationManager.AppSettings["WHCode"].ToString(),
|
|
// MODId = d.EATTRIBUTE1,
|
|
|
|
// ID = f.Free5,
|
|
// cInvCode = b.ITEMCODE + "_" + b.OPCODE,
|
|
// iQuantity = b.LOTQTY ?? 0,
|
|
// iNum = (Convert.ToDecimal(b.LOTQTY ?? 0) * Convert.ToDecimal(c.EATTRIBUTE1 ?? "0")),
|
|
// cBatch = c.VenderLotNO,
|
|
// };
|
|
// if (data != null && data.Count() > 0)
|
|
// {
|
|
// List<OM_POmain> headList = new List<OM_POmain>();
|
|
// OM_POmain head = new OM_POmain();
|
|
// string key = "";
|
|
// foreach (var info in data)
|
|
// {
|
|
// ICSLOTONWIPCheck line = db.ICSLOTONWIPCheck.SingleOrDefault(a => a.ID == info.CheckID);
|
|
// if (line == null)
|
|
// {
|
|
// throw new Exception("检验信息不存在!");
|
|
// }
|
|
// line.IsInput = true;
|
|
// line.MUSER = AppConfig.UserCode;
|
|
// line.MUSERName = AppConfig.UserName;
|
|
// line.MTIME = DateTime.Now;
|
|
// line.WorkPoint = AppConfig.WorkPointCode;
|
|
|
|
// if (!key.Equals(info.UserCode + info.POID + info.cIWhCode + info.cOWhCode + info.MODId))
|
|
// {
|
|
// if (key != "")
|
|
// headList.Add(head);
|
|
// key = info.UserCode + info.POID + info.cIWhCode + info.cOWhCode + info.MODId;
|
|
// head = new OM_POmain();
|
|
// head.UserCode = info.UserCode;
|
|
// head.POID = info.POID;
|
|
// head.cIWhCode = info.cIWhCode;
|
|
// head.cOWhCode = info.cOWhCode;
|
|
// head.MODId = info.MODId;
|
|
// head.list = new List<OM_PODetails>();
|
|
// }
|
|
// OM_PODetails body = new OM_PODetails();
|
|
// body.ID = info.ID;
|
|
// body.cInvCode = info.cInvCode;
|
|
// body.iQuantity = Convert.ToDecimal(info.iQuantity);
|
|
// body.iNum = info.iNum;
|
|
// body.cBatch = info.cBatch;
|
|
// head.list.Add(body);
|
|
// }
|
|
// headList.Add(head);
|
|
|
|
// string Istr = JsonConvert.SerializeObject(headList);
|
|
// string iresult = HttpPost(System.Configuration.ConfigurationSettings.AppSettings["APIURL"].ToString() + "APIOM_POMain", Istr);
|
|
// Result INVOUTResult = new Result();
|
|
// INVOUTResult = JsonConvert.DeserializeObject<Result>(iresult);
|
|
// if (INVOUTResult.code != "200")
|
|
// {
|
|
// throw new Exception(INVOUTResult.msg);
|
|
// }
|
|
// }
|
|
// }
|
|
//}
|
|
//catch (Exception ex)
|
|
//{
|
|
// throw ex;
|
|
//}
|
|
}
|
|
//第一次判定
|
|
//public static void FirstResult(FramDataContext db, List<ICSLOTONWIPCheck> list, List<string> idList)
|
|
//{
|
|
// throw new Exception("表变更,注释掉此方法内容");
|
|
// //try
|
|
// //{
|
|
// // foreach (ICSLOTONWIPCheck check in list)
|
|
// // {
|
|
// // bool isNew = false;
|
|
// // ICSLOTONWIPCheck line = db.ICSLOTONWIPCheck.SingleOrDefault(a => a.ID == check.ID);
|
|
// // if (line == null)
|
|
// // {
|
|
// // isNew = true;
|
|
// // line = new ICSLOTONWIPCheck();
|
|
// // line.ID = check.ID;
|
|
// // line.ONWIPID = check.ONWIPID;
|
|
// // }
|
|
// // line.Result = check.Result;
|
|
// // line.USER = AppConfig.UserCode;
|
|
// // line.TIME = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
|
|
// // line.MUSER = AppConfig.UserCode;
|
|
// // line.MUSERName = AppConfig.UserName;
|
|
// // line.MTIME = DateTime.Now;
|
|
// // line.WorkPoint = AppConfig.WorkPointCode;
|
|
// // if (isNew)
|
|
// // db.ICSLOTONWIPCheck.InsertOnSubmit(line);
|
|
// // }
|
|
// // if (idList != null && idList.Count > 0)
|
|
// // {
|
|
// // db.SubmitChanges();
|
|
// // Calculate(db, idList, "合格");
|
|
// // }
|
|
// //}
|
|
// //catch (Exception ex)
|
|
// //{
|
|
// // throw ex;
|
|
// //}
|
|
//}
|
|
//第二次判定
|
|
//public static void SecondResult(FramDataContext db, List<ICSLOTONWIPCheck> list, List<string> idList)
|
|
//{
|
|
// throw new Exception("表变更,注释掉此方法内容");
|
|
// //try
|
|
// //{
|
|
// // foreach (ICSLOTONWIPCheck check in list)
|
|
// // {
|
|
// // bool isNew = false;
|
|
// // ICSLOTONWIPCheck line = db.ICSLOTONWIPCheck.SingleOrDefault(a => a.ID == check.ID);
|
|
// // if (line == null)
|
|
// // {
|
|
// // isNew = true;
|
|
// // line = new ICSLOTONWIPCheck();
|
|
// // line.ID = check.ID;
|
|
// // line.ONWIPID = check.ONWIPID;
|
|
// // }
|
|
// // line.Result = check.Result;
|
|
// // line.RUSER = AppConfig.UserCode;
|
|
// // line.RTIME = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
|
|
// // line.MUSER = AppConfig.UserCode;
|
|
// // line.MUSERName = AppConfig.UserName;
|
|
// // line.MTIME = DateTime.Now;
|
|
// // line.WorkPoint = AppConfig.WorkPointCode;
|
|
// // if (isNew)
|
|
// // db.ICSLOTONWIPCheck.InsertOnSubmit(line);
|
|
// // }
|
|
// // if (idList != null && idList.Count > 0)
|
|
// // {
|
|
// // db.SubmitChanges();
|
|
// // Calculate(db, idList, "合格");
|
|
// // }
|
|
// //}
|
|
// //catch (Exception ex)
|
|
// //{
|
|
// // throw ex;
|
|
// //}
|
|
//}
|
|
|
|
#region 根据条码获取条码采集信息
|
|
public static ICSLOTSIMULATION GetSimInfoByLotNo(string LotNo, string dsconn)
|
|
{
|
|
FramDataContext db = new FramDataContext(dsconn);
|
|
db.Connection.Open();
|
|
db.Transaction = db.Connection.BeginTransaction();
|
|
try
|
|
{
|
|
var line = db.ICSLOTSIMULATION.SingleOrDefault(a => a.LOTNO == LotNo && a.WorkPoint == AppConfig.WorkPointCode);
|
|
return line;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new Exception(ex.Message);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 检查当前检验的工序是否是委外工(True:委外,Flase:非委外)
|
|
public static bool GetLotOPInfoByCode(string LotNo, string OPCode, string dsconn)
|
|
{
|
|
FramDataContext db = new FramDataContext(dsconn);
|
|
db.Connection.Open();
|
|
db.Transaction = db.Connection.BeginTransaction();
|
|
try
|
|
{
|
|
var line = db.ICSMO2User.SingleOrDefault(a => a.LOTNO == LotNo && a.OPCODE == OPCode && a.WorkPoint == AppConfig.WorkPointCode);
|
|
if (line.EATTRIBUTE1 == "1")
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new Exception(ex.Message);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
//public static void TResult(FramDataContext db, List<ICSLOTONWIPCheck> list)
|
|
//{
|
|
// throw new Exception("表变更,注释掉此方法内容");
|
|
// //try
|
|
// //{
|
|
// // foreach (ICSLOTONWIPCheck check in list)
|
|
// // {
|
|
// // ICSLOTONWIPCheck line = db.ICSLOTONWIPCheck.SingleOrDefault(a => a.ID == check.ID);
|
|
// // if (line != null)
|
|
// // {
|
|
// // line.TResult = check.TResult;
|
|
// // line.TUSER = AppConfig.UserCode;
|
|
// // line.TTIME = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
|
|
|
|
// // line.MUSER = AppConfig.UserCode;
|
|
// // line.MUSERName = AppConfig.UserName;
|
|
// // line.MTIME = DateTime.Now;
|
|
// // line.WorkPoint = AppConfig.WorkPointCode;
|
|
// // }
|
|
// // }
|
|
// //}
|
|
// //catch (Exception ex)
|
|
// //{
|
|
// // throw ex;
|
|
// //}
|
|
//}
|
|
//public static void RResult(FramDataContext db, List<ICSLOTONWIPCheck> list)
|
|
//{
|
|
// throw new Exception("表变更,注释掉此方法内容");
|
|
// //try
|
|
// //{
|
|
// // foreach (ICSLOTONWIPCheck check in list)
|
|
// // {
|
|
// // ICSLOTONWIPCheck line = db.ICSLOTONWIPCheck.SingleOrDefault(a => a.ID == check.ID);
|
|
// // if (line != null)
|
|
// // {
|
|
// // line.RResult = check.RResult;
|
|
// // line.RUSER = AppConfig.UserCode;
|
|
// // line.RTIME = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
|
|
|
|
// // line.MUSER = AppConfig.UserCode;
|
|
// // line.MUSERName = AppConfig.UserName;
|
|
// // line.MTIME = DateTime.Now;
|
|
// // line.WorkPoint = AppConfig.WorkPointCode;
|
|
// // }
|
|
// // }
|
|
// //}
|
|
// //catch (Exception ex)
|
|
// //{
|
|
// // throw ex;
|
|
// //}
|
|
//}
|
|
|
|
//采购订单已发数量更新
|
|
public static void UpdatePOInfo(FramDataContext db, ICSPO_PoMain info)
|
|
{
|
|
var line = db.ICSPO_PoMain.SingleOrDefault(a => a.POCode == info.POCode && a.PORow == info.PORow);
|
|
line.INQty = Convert.ToDecimal(line.INQty) + Convert.ToDecimal(info.INQty);
|
|
line.MTIME = DateTime.Now;
|
|
}
|
|
|
|
//日志表条码对应采购订单信息记录
|
|
public static void AddLogInfo(FramDataContext db, ICSWareHouseLotInfoLog info)
|
|
{
|
|
var line = new ICSWareHouseLotInfoLog();
|
|
line.ID = info.ID;
|
|
line.TransNO = info.TransNO;
|
|
line.TransLine = info.TransLine;
|
|
line.ITEMCODE = info.ITEMCODE;
|
|
line.LotNO = info.LotNO;
|
|
line.TransQTY = info.TransQTY;
|
|
line.TransType = "发";
|
|
line.BusinessCode = "委外发料";
|
|
line.Memo = info.Memo;
|
|
line.MUSER = info.MUSER;
|
|
line.MUSERName = info.MUSERName;
|
|
line.MTIME = info.MTIME;
|
|
line.WorkPoint = info.WorkPoint;
|
|
db.ICSWareHouseLotInfoLog.InsertOnSubmit(line);
|
|
}
|
|
public static string HttpPost(string url, string body)
|
|
{
|
|
try
|
|
{
|
|
Encoding encoding = Encoding.UTF8;
|
|
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
|
|
request.Method = "POST";
|
|
request.Accept = "application/json, text/javascript, */*"; //"text/html, application/xhtml+xml, */*";
|
|
request.ContentType = "application/json; charset=utf-8";
|
|
|
|
byte[] buffer = encoding.GetBytes(body);
|
|
request.ContentLength = buffer.Length;
|
|
request.GetRequestStream().Write(buffer, 0, buffer.Length);
|
|
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
|
|
using (StreamReader reader = new StreamReader(response.GetResponseStream(), encoding))
|
|
{
|
|
return reader.ReadToEnd();
|
|
}
|
|
}
|
|
catch (WebException ex)
|
|
{
|
|
var res = (HttpWebResponse)ex.Response;
|
|
StringBuilder sb = new StringBuilder();
|
|
StreamReader sr = new StreamReader(res.GetResponseStream(), Encoding.UTF8);
|
|
sb.Append(sr.ReadToEnd());
|
|
//string ssb = sb.ToString();
|
|
throw new Exception(sb.ToString());
|
|
}
|
|
}
|
|
|
|
public static void DataDelete(FramDataContext db, List<FormICSCollectDataDeleteUIModel> infolist)
|
|
{
|
|
try
|
|
{
|
|
foreach (FormICSCollectDataDeleteUIModel info in infolist)
|
|
{
|
|
//删除ICSLOTONWIP数据
|
|
var lines1 = db.ICSLOTONWIP.Where(a => a.MOCODE == info.MOCode && a.LOTNO == info.LotNO && a.OPCODE == info.OPCode);
|
|
db.ICSLOTONWIP.DeleteAllOnSubmit(lines1);
|
|
db.SubmitChanges();
|
|
var lastInfo = db.ICSLOTONWIP.Where(a => a.LOTNO == info.LotNO && a.ACTIONRESULT == "COLLECT_END").OrderByDescending(a => a.MTIME).FirstOrDefault();
|
|
if (lastInfo == null)
|
|
{
|
|
//删除ICSLOTSIMULATION数据
|
|
var lines2 = db.ICSLOTSIMULATION.Where(a => a.MOCODE == info.MOCode && a.LOTNO == info.LotNO && a.OPCODE == info.OPCode);
|
|
db.ICSLOTSIMULATION.DeleteAllOnSubmit(lines2);
|
|
db.SubmitChanges();
|
|
}
|
|
else
|
|
{
|
|
//更新ICSLOTSIMULATION数据
|
|
var lines2 = db.ICSLOTSIMULATION.SingleOrDefault(a => a.MOCODE == info.MOCode && a.LOTNO == info.LotNO && a.OPCODE == info.OPCode);
|
|
lines2.MOSEQ = lastInfo.MOSEQ;
|
|
lines2.GOODQTY = lastInfo.GOODQTY;
|
|
lines2.NGQTY = lastInfo.NGQTY;
|
|
lines2.OPCODE = lastInfo.OPCODE;
|
|
lines2.LOTSEQ = lastInfo.LOTSEQ;
|
|
lines2.CollectStatus = lastInfo.ACTIONRESULT;
|
|
db.SubmitChanges();
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
public static void DataDeleteForWW(FramDataContext db, List<FormICSCollectWWDataDeleteUIModel> infolist)
|
|
{
|
|
try
|
|
{
|
|
foreach (FormICSCollectWWDataDeleteUIModel info in infolist)
|
|
{
|
|
var lines1 = db.ICSLOTONWIP.Where(a => a.MOCODE == info.MOCode && a.LOTNO == info.LotNO && a.OPCODE == info.OPCode);
|
|
if (lines1 != null)
|
|
{
|
|
db.ICSLOTONWIP.DeleteAllOnSubmit(lines1);
|
|
}
|
|
var lines3 = db.ICSWareHouseLotInfoLog.Where(a => a.TransNO == info.POCode && a.TransLine == info.PORow && a.LotNO == info.LotNO
|
|
&& a.ITEMCODE == info.ItemCode + "_" + info.OPCode && a.BusinessCode == "委外发料");
|
|
if (lines3 != null)
|
|
{
|
|
#region 删除前先存入删除日志表(ICSWWDataDeleteLog)
|
|
var loginfo = db.ICSWareHouseLotInfoLog.SingleOrDefault(a => a.TransNO == info.POCode && a.TransLine == info.PORow && a.LotNO == info.LotNO
|
|
&& a.ITEMCODE == info.ItemCode + "_" + info.OPCode && a.BusinessCode == "委外发料");
|
|
if (loginfo != null)
|
|
{
|
|
ICSWWDataDeleteLog dlog = new ICSWWDataDeleteLog();
|
|
dlog.ID = AppConfig.GetGuid();
|
|
dlog.TransNO = loginfo.TransNO;
|
|
dlog.TransLine = loginfo.TransLine;
|
|
dlog.ITEMCODE = loginfo.ITEMCODE;
|
|
dlog.LotNO = loginfo.LotNO;
|
|
dlog.TransQTY = loginfo.TransQTY;
|
|
dlog.Memo = loginfo.Memo;
|
|
dlog.TransType = loginfo.TransType;
|
|
dlog.BusinessCode = loginfo.BusinessCode;
|
|
dlog.MUSER = AppConfig.UserCode;
|
|
dlog.MUSERName = AppConfig.UserName;
|
|
dlog.MTIME = DateTime.Now;
|
|
dlog.WorkPoint = loginfo.WorkPoint;
|
|
dlog.EATTRIBUTE3 = info.PRCode;
|
|
db.ICSWWDataDeleteLog.InsertOnSubmit(dlog);
|
|
}
|
|
#endregion
|
|
db.ICSWareHouseLotInfoLog.DeleteAllOnSubmit(lines3);
|
|
}
|
|
else
|
|
{
|
|
throw new Exception("没有匹配到采购订单信息,无法删除委外开工记录,请联系开发人员!");
|
|
}
|
|
var lines4 = db.ICSPO_PoMain.SingleOrDefault(a => a.POCode == info.POCode && a.PORow == info.PORow);
|
|
if (lines4 != null)
|
|
{
|
|
lines4.INQty = lines4.INQty - info.LotQTY;
|
|
}
|
|
}
|
|
foreach (FormICSCollectWWDataDeleteUIModel wwinfo in infolist)
|
|
{
|
|
var lastInfo = db.ICSLOTONWIP.Where(a => a.LOTNO == wwinfo.LotNO && a.ACTIONRESULT == "COLLECT_END").OrderByDescending(a => a.MTIME).FirstOrDefault();
|
|
if (lastInfo == null)
|
|
{
|
|
//删除ICSLOTSIMULATION数据
|
|
var lines2 = db.ICSLOTSIMULATION.Where(a => a.MOCODE == wwinfo.MOCode && a.LOTNO == wwinfo.LotNO);
|
|
db.ICSLOTSIMULATION.DeleteAllOnSubmit(lines2);
|
|
db.SubmitChanges();
|
|
}
|
|
else
|
|
{
|
|
//更新ICSLOTSIMULATION数据
|
|
var lines2 = db.ICSLOTSIMULATION.SingleOrDefault(a => a.MOCODE == wwinfo.MOCode && a.LOTNO == wwinfo.LotNO);
|
|
lines2.MOSEQ = lastInfo.MOSEQ;
|
|
lines2.GOODQTY = lastInfo.GOODQTY;
|
|
lines2.NGQTY = lastInfo.NGQTY;
|
|
lines2.OPCODE = lastInfo.OPCODE;
|
|
lines2.LOTSEQ = lastInfo.LOTSEQ;
|
|
lines2.CollectStatus = lastInfo.ACTIONRESULT;
|
|
db.SubmitChanges();
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
#region 判断第二次检验是否与第一次检验相同(True:相同;False:不同)
|
|
//public static string CheckFSDifferent(FramDataContext db, List<ICSLOTONWIPCheck> infolist, List<string> LotNO, List<string> OPCode)
|
|
//{
|
|
// throw new Exception("表变更,注释掉此方法内容");
|
|
// //try
|
|
// //{
|
|
// // string Result = "";
|
|
// // for (int i = 0; i < infolist.Count(); i++)
|
|
// // {
|
|
// // var line = db.ICSLOTONWIPCheck.SingleOrDefault(a => a.ID == infolist[i].ID && a.Result == infolist[i].RResult);
|
|
// // if (line != null)
|
|
// // {
|
|
// // if (Result == "")
|
|
// // {
|
|
// // Result += "跟踪单:" + LotNO[0] + ",工序:" + OPCode[0] + ";\n";
|
|
// // }
|
|
// // else
|
|
// // {
|
|
// // Result += ",跟踪单:" + LotNO[0] + ",工序:" + OPCode[0] + ";\n";
|
|
// // }
|
|
// // }
|
|
// // }
|
|
// // if (Result != "")
|
|
// // {
|
|
// // Result += "以上跟踪单对应工序的第一次检验结果与第二次检验结果相同,\n不能进行第二次检验";
|
|
// // }
|
|
// // return Result;
|
|
// //}
|
|
// //catch (Exception ex)
|
|
// //{
|
|
// // throw new Exception(ex.Message);
|
|
// //}
|
|
//}
|
|
#endregion
|
|
|
|
|
|
/// <summary>
|
|
/// 发料
|
|
/// </summary>
|
|
/// <param name="send"></param>
|
|
/// <param name="ds"></param>
|
|
/// <param name="conn"></param>
|
|
public static void OutsourceSubmit(bool send, DataSet ds, string conn)
|
|
{
|
|
string TransType = "";
|
|
string BusinessCode = "";
|
|
string CollectStatus = "";
|
|
decimal GOODQTY = 0;
|
|
DateTime? EndTime = null;
|
|
string EndUser = "";
|
|
|
|
FramDataContext db = new FramDataContext(conn);
|
|
db.Connection.Open();
|
|
db.Transaction = db.Connection.BeginTransaction();
|
|
try
|
|
{
|
|
foreach (DataTable dt in ds.Tables)
|
|
{
|
|
#region 主数据
|
|
//发料时dt排序为正序,收料是倒序,因此此处取首行,即发料第一道工序,收料最后一道工序
|
|
string MOCODE = dt.Rows[0]["MOCODE"].ToString();
|
|
int MOSEQ = Convert.ToInt32(dt.Rows[0]["MOSEQ"].ToString());
|
|
string LOTNO = dt.Rows[0]["LotNo"].ToString();
|
|
string ITEMCODE = dt.Rows[0]["ITEMCODE"].ToString();
|
|
decimal LOTQTY = Convert.ToDecimal(dt.Rows[0]["PRQTY"].ToString());
|
|
decimal RcvNGQTY = Convert.ToDecimal(dt.Rows[0]["RcvNGQTY"].ToString());//收料:供应商欠料数量
|
|
string ROUTECODE = dt.Rows[0]["ROUTECODE"].ToString();
|
|
string OPCODE = dt.Rows[0]["OPCODE"].ToString();
|
|
int OPSEQ = Convert.ToInt32(dt.Rows[0]["OPSEQ"].ToString());
|
|
string EQPCODE = dt.Rows[0]["EQPCode"].ToString();
|
|
//string EQPName = dt.Rows[0]["EQPName"].ToString();
|
|
string CtrlType = dt.Rows[0]["控制方式"].ToString();
|
|
string VenCode = dt.Rows[0]["VenCode"].ToString();
|
|
//string VenName = dt.Rows[0]["VenName"].ToString();
|
|
if (send)
|
|
{
|
|
TransType = "发";
|
|
BusinessCode = "委外发料";
|
|
CollectStatus = "COLLECT_BEGIN";
|
|
GOODQTY = 0;
|
|
EndTime = null;
|
|
EndUser = null;
|
|
}
|
|
else
|
|
{
|
|
TransType = "收";
|
|
BusinessCode = "委外收料";
|
|
CollectStatus = "COLLECT_END";
|
|
GOODQTY = LOTQTY;
|
|
EndTime = DateTime.Now;
|
|
EndUser = VenCode;
|
|
}
|
|
#endregion
|
|
|
|
#region ICSLOTSIMULATION
|
|
bool isNew_Sim = false;
|
|
var simInfo = db.ICSLOTSIMULATION.SingleOrDefault(a => a.LOTNO == LOTNO);
|
|
if (simInfo == null)
|
|
{
|
|
if (send == false)
|
|
{
|
|
throw new Exception("跟踪单开工表无记录,不能收料");
|
|
}
|
|
isNew_Sim = true;
|
|
simInfo = new ICSLOTSIMULATION();
|
|
simInfo.ID = AppConfig.GetGuid();
|
|
simInfo.MOCODE = MOCODE;
|
|
simInfo.MOSEQ = MOSEQ;
|
|
simInfo.LOTNO = LOTNO;
|
|
simInfo.LOTSEQ = 1;
|
|
simInfo.LOTStatus = "新增";
|
|
simInfo.MODELCODE = "";
|
|
simInfo.ITEMCODE = ITEMCODE;
|
|
simInfo.ROUTECODE = ROUTECODE;
|
|
simInfo.NGTIMES = 0;
|
|
simInfo.ISCOM = "0";
|
|
simInfo.ISHOLD = 0;
|
|
simInfo.BeginTime = DateTime.Now;
|
|
simInfo.EndTime = null;
|
|
simInfo.WorkPoint = AppConfig.WorkPointCode;
|
|
}
|
|
else
|
|
{
|
|
simInfo.EATTRIBUTE1 = send ? simInfo.OPList : null;//发料:保存发料前的OPList,用于开工未完工删除时,回写. 收料:置null.
|
|
}
|
|
if (send == false)
|
|
{
|
|
//收料,是否结束跟踪单
|
|
int maxOpSeq = db.ICSITEMROUTE2OPLot.AsEnumerable().Max(a => a.OPSEQ);
|
|
if (OPSEQ > maxOpSeq)
|
|
{
|
|
throw new Exception("跟踪单" + LOTNO + "工艺路线变更,工序" + OPCODE + "(" + OPSEQ.ToString() + ")可能已被删除");
|
|
}
|
|
if (OPSEQ == maxOpSeq)
|
|
{
|
|
simInfo.EndTime = DateTime.Now;
|
|
simInfo.ISCOM = "1";
|
|
}
|
|
}
|
|
simInfo.CollectStatus = CollectStatus;
|
|
simInfo.LOTQTY = LOTQTY;
|
|
simInfo.GOODQTY = GOODQTY;
|
|
simInfo.NGQTY = 0;
|
|
simInfo.OPSEQ = OPSEQ;
|
|
simInfo.OPCODE = OPCODE;
|
|
simInfo.EQPCODE = EQPCODE;
|
|
simInfo.PRODUCTSTATUS = "GOOD";
|
|
simInfo.LACTION = "GOOD";
|
|
simInfo.ACTIONLIST = "GOOD";
|
|
simInfo.MUSER = AppConfig.UserCode;
|
|
simInfo.MUSERName = AppConfig.UserName;
|
|
simInfo.MTIME = DateTime.Now;
|
|
simInfo.OPList = OPSEQ.ToString();
|
|
simInfo.OPListAttr = CtrlType;
|
|
if (isNew_Sim)
|
|
{
|
|
db.ICSLOTSIMULATION.InsertOnSubmit(simInfo);
|
|
}
|
|
db.SubmitChanges();
|
|
#endregion
|
|
|
|
for (int i = 0; i < dt.Rows.Count; i++)
|
|
{
|
|
#region 行数据
|
|
OPCODE = dt.Rows[0]["OPCODE"].ToString();
|
|
OPSEQ = Convert.ToInt32(dt.Rows[0]["OPSEQ"].ToString());
|
|
string POCode = dt.Rows[0]["POCode"].ToString();
|
|
string PORow = dt.Rows[0]["PORow"].ToString();
|
|
string PRLineID = dt.Rows[0]["PRLine"].ToString();
|
|
#endregion
|
|
|
|
#region ICSLOTONWIP
|
|
var wipInfo = db.ICSLOTONWIP.SingleOrDefault(a => a.LOTNO == LOTNO && a.LOTSEQ == simInfo.LOTSEQ && a.OPCODE == OPCODE);
|
|
if (send)
|
|
{
|
|
//发料
|
|
if (wipInfo != null)
|
|
{
|
|
throw new Exception("跟踪单" + LOTNO + "工序" + OPCODE + "已有发料记录");
|
|
}
|
|
wipInfo = new ICSLOTONWIP();
|
|
wipInfo.ID = AppConfig.GetGuid();
|
|
}
|
|
else
|
|
{
|
|
//收料
|
|
if (wipInfo == null)
|
|
{
|
|
throw new Exception("跟踪单" + LOTNO + "工序" + OPCODE + "没有发料记录");
|
|
}
|
|
}
|
|
wipInfo.LOTNO = LOTNO;
|
|
wipInfo.LOTSEQ = simInfo.LOTSEQ;
|
|
wipInfo.MOSEQ = MOSEQ;
|
|
wipInfo.MOCODE = MOCODE;
|
|
wipInfo.MODELCODE = "";
|
|
wipInfo.ITEMCODE = ITEMCODE;
|
|
wipInfo.ROUTECODE = ROUTECODE;
|
|
wipInfo.OPSEQ = OPSEQ;
|
|
wipInfo.OPCODE = OPCODE;
|
|
wipInfo.SHIFTTYPECODE = "";
|
|
wipInfo.EQPCODE = EQPCODE;
|
|
wipInfo.ACTION = "GOOD";
|
|
wipInfo.NGTIMES = 0;
|
|
wipInfo.Processed = 0;
|
|
wipInfo.LOTQTY = simInfo.LOTQTY;
|
|
wipInfo.GOODQTY = GOODQTY;
|
|
wipInfo.NGQTY = 0;
|
|
wipInfo.RcvNGQTY = RcvNGQTY;
|
|
wipInfo.WorkPoint = AppConfig.WorkPointCode;
|
|
wipInfo.EATTRIBUTE1 = simInfo.OPListAttr;
|
|
wipInfo.UserCodeBegin = VenCode;
|
|
wipInfo.UserCodeEnd = EndUser;
|
|
wipInfo.BeginTime = DateTime.Now;
|
|
wipInfo.EndTime = EndTime;
|
|
wipInfo.ACTIONRESULT = CollectStatus;
|
|
wipInfo.MUSER = AppConfig.UserCode;
|
|
wipInfo.MUSERName = AppConfig.UserName;
|
|
wipInfo.MTIME = DateTime.Now;
|
|
if (send)
|
|
{
|
|
db.ICSLOTONWIP.InsertOnSubmit(wipInfo);
|
|
}
|
|
db.SubmitChanges();
|
|
#endregion
|
|
|
|
#region ICSPO_PoMain
|
|
var line = db.ICSPO_PoMain.SingleOrDefault(a => a.POCode == POCode && a.PORow == PORow && a.Free1 == PRLineID);
|
|
if (line == null)
|
|
{
|
|
throw new Exception("PO单:" + POCode + ",行: " + PORow + ",PrLineID(Free1): " + PRLineID + "不存在");
|
|
}
|
|
if (send)
|
|
{
|
|
//发料
|
|
line.INQty = Convert.ToDecimal(line.INQty) + LOTQTY;
|
|
line.MTIME = DateTime.Now;
|
|
if (line.Quantity < line.INQty)
|
|
{
|
|
throw new Exception("PO单:" + POCode + ",行: " + PORow + ",PrLineID(Free1): " + PRLineID + "发料" + LOTQTY.ToString() + "后数量超出" + line.Quantity.ToString());
|
|
}
|
|
db.SubmitChanges();
|
|
}
|
|
#endregion
|
|
|
|
#region ICSWareHouseLotInfoLog
|
|
ICSWareHouseLotInfoLog loginfo = new ICSWareHouseLotInfoLog();
|
|
loginfo.ID = AppConfig.GetGuid();
|
|
loginfo.TransNO = POCode;
|
|
loginfo.TransLine = PORow;
|
|
loginfo.ITEMCODE = ITEMCODE + "_" + OPCODE;
|
|
loginfo.LotNO = LOTNO;
|
|
loginfo.TransQTY = LOTQTY;
|
|
loginfo.Memo = OPCODE;
|
|
loginfo.MUSER = AppConfig.UserCode;
|
|
loginfo.MUSERName = AppConfig.UserName;
|
|
loginfo.MTIME = DateTime.Now;
|
|
loginfo.WorkPoint = AppConfig.WorkPointCode;
|
|
loginfo.TransType = TransType;
|
|
loginfo.BusinessCode = BusinessCode;
|
|
loginfo.EATTRIBUTE1 = PRLineID;
|
|
|
|
db.ICSWareHouseLotInfoLog.InsertOnSubmit(loginfo);
|
|
#endregion
|
|
|
|
#region 退镀
|
|
if (!send)
|
|
{
|
|
var lineop = db.ICSOP.SingleOrDefault(a => a.OPCODE == OPCODE && a.WorkPoint == AppConfig.WorkPointCode);
|
|
var lineR = db.ICSITEMROUTE2OPLot.SingleOrDefault(a => a.LotNo == LOTNO && a.ROUTECODE == ROUTECODE && a.OPCODE == OPCODE && a.OPSEQ == OPSEQ && a.WorkPoint == AppConfig.WorkPointCode);
|
|
if (lineop.OPDESC.Contains("退镀") && lineR.ISWWRW == true)
|
|
{
|
|
RecordPRLineProcessQTY(db, PRLineID, LOTQTY, 0);
|
|
//出入库
|
|
PoInMaterialOut4Rev(db, wipInfo.ID);
|
|
//关单
|
|
ClosePoByPRLine(db, PRLineID);
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
}
|
|
db.SubmitChanges();
|
|
db.Transaction.Commit();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
db.Transaction.Rollback();
|
|
throw ex;
|
|
}
|
|
finally
|
|
{
|
|
db.Connection.Close();
|
|
}
|
|
}
|
|
|
|
private static int RecordPRLineProcessQTY(FramDataContext db, string PRLineID, decimal OKQty, decimal NGQty)
|
|
{
|
|
string sql = @"
|
|
IF NOT EXISTS (SELECT QTY,OKQTY,NGQTY FROM dbo.ICSRWrecord WHERE PRlineID='{0}')
|
|
BEGIN
|
|
INSERT INTO [dbo].[ICSRWRecord]
|
|
([PRlineID]
|
|
,[QTY]
|
|
,[OKQTY]
|
|
,[NGQTY])
|
|
VALUES
|
|
(
|
|
'{0}'
|
|
,(SELECT TOP 1 PRQTY FROM dbo.ICSMO2User WHERE PRlineID='{0}')
|
|
,{1}
|
|
,{2})
|
|
END
|
|
ELSE
|
|
BEGIN
|
|
UPDATE [dbo].[ICSRWRecord] SET OKQTY=OKQTY+{1}, NGQTY=NGQTY+{2} WHERE PRlineID='{0}'
|
|
END
|
|
";
|
|
sql = string.Format(sql, PRLineID, OKQty, NGQty);
|
|
int I= db.ExecuteCommand(sql);
|
|
db.SubmitChanges();
|
|
return I;
|
|
}
|
|
|
|
|
|
private static void PoInMaterialOut4Rev(FramDataContext db, string ONWIPID)
|
|
{
|
|
var whcodes = db.Sys_EnumValues.Where(a => a.WorkPointCode == AppConfig.WorkPointCode && a.EnumKey == "009").FirstOrDefault();
|
|
if (whcodes == null)
|
|
throw new Exception("未维护默认仓库!");
|
|
string WHCode = whcodes.EnumText;
|
|
|
|
#region 采购入库信息查询
|
|
string sql = @"
|
|
SELECT 'Ahwit' AS [group],
|
|
CAST((row_number() over (ORDER BY a.id))*10 AS VARCHAR(100)) AS crowno,
|
|
d.InvCode AS cmaterialoid,
|
|
f.name AS cunitid,
|
|
e.vchangerate AS vchangerate,
|
|
a.GOODQTY AS nshouldassistnum,
|
|
a.GOODQTY AS nshouldnum,
|
|
a.GOODQTY AS nassistnum,
|
|
e.norigprice AS ncostprice,
|
|
e.norigmny AS ncostmny,
|
|
CONVERT(varchar(100),GETDATE(),120) AS dbizdate,
|
|
d.POCode AS vsourcebillcode,
|
|
d.WBS AS csourcebillhid,
|
|
d.Free5 AS cfirstbillbid,
|
|
a.WorkPoint AS org,
|
|
g.code AS corigcurrencyid,
|
|
h.code AS ctaxcodeid,'{2}' AS cwarehouseid,
|
|
i.code as creqstoorgoid ,
|
|
j. parentbilltype as cfirsttype,
|
|
j.pk_billtypecode as cfirsttranstype ,
|
|
k.parentbilltype as csourcetype ,
|
|
k.pk_billtypecode as csourcetranstype ,
|
|
d.VenCode AS cvendorid,
|
|
CAST(d.Free3 AS DECIMAL(18,2)) AS norignetprice,
|
|
CAST(d.Free3 AS DECIMAL(18,2)) AS nqtorignetprice,
|
|
CAST(d.Free2*a.GOODQTY-CAST((d.Free2-d.Free3)*a.GOODQTY AS DECIMAL(18,2)) AS DECIMAL(18,2)) AS norigmny,
|
|
CAST(d.Free2*a.GOODQTY-CAST((d.Free2-d.Free3)*a.GOODQTY AS DECIMAL(18,2)) AS DECIMAL(18,2)) AS nmny,
|
|
CAST(d.Free2 AS DECIMAL(18,2)) AS norigtaxnetprice,
|
|
CAST(d.Free2 AS DECIMAL(18,2)) AS nqtorigtaxnetprice,
|
|
CAST(d.Free2*a.GOODQTY-CAST((d.Free2-d.Free3)*a.GOODQTY AS DECIMAL(18,2)) AS DECIMAL(18,2)) AS ncaltaxmny,
|
|
CAST(d.Free2*a.GOODQTY AS DECIMAL(18,2)) AS ntaxmny,
|
|
CAST(d.Free4 AS DECIMAL(18,2)) AS ntaxrate,
|
|
CAST((d.Free2-d.Free3)*a.GOODQTY AS DECIMAL(18,2)) AS norigtax,
|
|
CAST(d.Free2*a.GOODQTY AS DECIMAL(18,2)) AS norigtaxmny
|
|
FROM ICSLOTONWIP a
|
|
INNER JOIN ICSMO2User c ON c.LOTNO+c.ROUTECODE+c.OPCODE+c.WorkPoint = a.LOTNO+a.RouteCode+a.OPCODE+a.WorkPoint
|
|
INNER JOIN ICSPO_PoMain d ON c.PRLineID=d.Free1 AND c.WorkPoint=d.WorkPoint
|
|
INNER JOIN {1}.[dbo].[po_order_b] e ON d.Free5=e.pk_order_b
|
|
INNER JOIN {1}.[dbo].[bd_measdoc] f ON e.castunitid = f.pk_measdoc
|
|
INNER JOIN {1}.[dbo].[bd_currtype] g ON e.corigcurrencyid = g.pk_currtype
|
|
INNER JOIN {1}.[dbo].[bd_taxcode] h ON e.ctaxcodeid = h.pk_taxcode
|
|
INNER JOIN {1}.[dbo].[org_stockorg_v] i ON i.pk_vid = e.pk_reqstoorg_v
|
|
INNER JOIN {1}.[dbo].[bd_billtype] j ON j.pk_billtypeid = e.vfirsttrantype
|
|
INNER JOIN {1}.[dbo].[bd_billtype] k ON k.pk_billtypeid = e.vsourcetrantype
|
|
WHERE a.ID ='{0}'
|
|
";
|
|
var infoERP = db.Sys_DataBase.SingleOrDefault(a => a.DBSourceName == "ERP" && a.WorkCode == AppConfig.WorkPointCode);
|
|
var infoMES = db.Sys_DataBase.SingleOrDefault(a => a.DBSourceName == "SYS" && a.WorkCode == AppConfig.WorkPointCode);
|
|
string erpDB = (infoERP.DBIpAddress == infoMES.DBIpAddress ? "" : "[" + infoERP.DBIpAddress + "].") + infoERP.DBName;
|
|
|
|
sql = string.Format(sql, ONWIPID, erpDB, WHCode);
|
|
var po = db.ExecuteQuery<CreatePODetailEntity>(sql).ToList();
|
|
if (po == null || po.Count() <= 0)
|
|
throw new Exception("采购入库信息查询失败!");
|
|
#endregion
|
|
|
|
#region 材料出库信息查询
|
|
sql = @"
|
|
SELECT 'Ahwit' AS [pk_group],
|
|
CAST((row_number() over (ORDER BY a.id))*10 AS VARCHAR(100)) AS crowno,
|
|
d.InvCode AS cmaterialoid,
|
|
f.name AS cunitid,
|
|
f.name AS castunitid,
|
|
e.vchangerate AS vchangerate,
|
|
a.GOODQTY AS nshouldnum,
|
|
a.GOODQTY AS nshouldassistnum,
|
|
a.GOODQTY AS nnum,
|
|
a.GOODQTY AS nassistnum,
|
|
CAST(e.norigprice AS DECIMAL(18,2)) AS ncostprice,
|
|
CAST(a.GOODQTY*CAST(e.norigprice AS DECIMAL(18,2)) AS DECIMAL(18,2)) AS ncostmny,
|
|
CONVERT(varchar(100),GETDATE(),120) AS dbizdate,
|
|
CONVERT(varchar(100),GETDATE(),120) AS drequiredate,
|
|
d.InvCode AS ccostobject,
|
|
a.MOCODE AS vproductbatch,
|
|
a.WorkPoint AS pk_org,
|
|
x.cpmohid AS csourcebillbid,
|
|
x.ID AS csourcebillhid
|
|
FROM ICSLOTONWIP a
|
|
INNER JOIN ICSMO2User c ON c.LOTNO+c.ROUTECODE+c.OPCODE+c.WorkPoint = a.LOTNO+a.RouteCode+a.OPCODE+a.WorkPoint
|
|
INNER JOIN ICSMO x ON c.MOCODE=x.MOCODE AND c.MOSEQ=x.MOSEQ AND c.WorkPoint=x.WorkPoint
|
|
INNER JOIN ICSPO_PoMain d ON c.PRLineID=d.Free1 AND c.WorkPoint=d.WorkPoint
|
|
INNER JOIN {1}.[dbo].[po_order_b] e ON d.Free5=e.pk_order_b
|
|
INNER JOIN {1}.[dbo].[bd_measdoc] f ON e.castunitid = f.pk_measdoc
|
|
WHERE a.ID ='{0}'
|
|
";
|
|
sql = string.Format(sql, ONWIPID, erpDB);
|
|
var rd = db.ExecuteQuery<Create4DDetailEntity>(sql).ToList();
|
|
if (rd == null || rd.Count() <= 0)
|
|
throw new Exception("材料出库信息查询失败!");
|
|
|
|
#endregion
|
|
|
|
#region NC接口专用账户查询
|
|
var infoApiUser = db.Sys_DataBase.SingleOrDefault(a => a.DBSourceName == "UserNCAPI" && a.WorkCode == AppConfig.WorkPointCode);
|
|
if (infoApiUser == null)
|
|
throw new Exception("数据源中未维护调用NC接口的用户:UserNCAPI");
|
|
string ApiUserCode = infoApiUser.DBUser;
|
|
string ApiUserPassword = AppConfig.FromMd5(infoApiUser.DBPwd);
|
|
#endregion
|
|
|
|
NcApiInputArguments inputInfo = new NcApiInputArguments();
|
|
inputInfo.datasource = "design";
|
|
inputInfo.usercode = ApiUserCode;// AppConfig.UserCode;
|
|
inputInfo.password = ApiUserPassword;// AppConfig.FromMd5(AppConfig.UserPwd);
|
|
inputInfo.list = new List<object>();
|
|
|
|
#region 采购入库
|
|
CreatePOEntity PO = new CreatePOEntity();
|
|
PO.group = "Ahwit";
|
|
PO.org = AppConfig.WorkPointCode;
|
|
string time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
|
PO.billmaker = AppConfig.UserCode;
|
|
PO.dbizdate = time;
|
|
PO.cpayfinorgvid = AppConfig.WorkPointCode;
|
|
PO.cfanaceorgvid = AppConfig.WorkPointCode;
|
|
PO.item = po;
|
|
inputInfo.list.Add(PO);
|
|
|
|
string inputJson = JsonConvert.SerializeObject(inputInfo);
|
|
log.Info("采购入库\r\n" + JsonConvert.SerializeObject(inputInfo.list));
|
|
string resStrCreatDeliveryPlan = HttpPost(urlCreatPO, inputJson);
|
|
NcApiOutArguments res = new NcApiOutArguments();
|
|
res = JsonConvert.DeserializeObject<NcApiOutArguments>(resStrCreatDeliveryPlan);
|
|
if (res.flat == "0")
|
|
{
|
|
throw new Exception("生成采购入库单失败:" + res.list_info);
|
|
}
|
|
#endregion
|
|
|
|
#region 材料出库
|
|
inputInfo.list = new List<object>();
|
|
Create4DEntity RD = new Create4DEntity();
|
|
RD.pk_group = "Ahwit";
|
|
RD.pk_org = AppConfig.WorkPointCode;
|
|
RD.corpoid = AppConfig.WorkPointCode;
|
|
RD.cwarehouseid = WHCode;
|
|
RD.cfanaceorgoid = AppConfig.WorkPointCode;
|
|
RD.cfanaceorgvid = AppConfig.WorkPointCode;
|
|
RD.vbillcode = "";
|
|
RD.dbilldate = time;
|
|
RD.creationtime = time;
|
|
RD.list = rd;
|
|
inputInfo.list.Add(RD);
|
|
|
|
string inputJsonRD = JsonConvert.SerializeObject(inputInfo);
|
|
log.Info("材料出库\r\n" + JsonConvert.SerializeObject(inputInfo.list));
|
|
string resStrCreatDeliveryPlanRD = HttpPost(urlCreat4D, inputJsonRD);
|
|
NcApiOutArguments resRD = new NcApiOutArguments();
|
|
resRD = JsonConvert.DeserializeObject<NcApiOutArguments>(resStrCreatDeliveryPlanRD);
|
|
if (resRD.flat == "0")
|
|
{
|
|
throw new Exception("生成材料出库单失败:" + resRD.list_info);
|
|
}
|
|
#endregion
|
|
}
|
|
|
|
private static void ClosePoByPRLine(FramDataContext db, string PRLineID)
|
|
{
|
|
#region 原采购订单行完成度查询
|
|
//1.正常委外本工序对应采购订单
|
|
//2.返工委外非退镀本工序对应采购订单
|
|
//3.返工委外退镀本工序对应采购订单,不关闭,已在收料时关闭
|
|
//4.返工工序对应 原采购订单
|
|
var lineRwrecord = db.ICSRWRecord.SingleOrDefault(a => a.PRlineID == PRLineID);
|
|
if (lineRwrecord == null)
|
|
{
|
|
throw new Exception("获取进度失败PRLineID" + PRLineID);
|
|
}
|
|
List<Close4POEntity> closepolines = new List<Close4POEntity>();
|
|
if (lineRwrecord.QTY != lineRwrecord.OKQTY + lineRwrecord.NGQTY)
|
|
{
|
|
return;
|
|
}
|
|
var lineMo2User = db.ICSMO2User.SingleOrDefault(a => a.PRLineID == lineRwrecord.PRlineID);
|
|
if (lineMo2User == null)
|
|
{
|
|
throw new Exception("派工记录表无此请购记录,prline:" + lineRwrecord.PRlineID);
|
|
}
|
|
var linePO = db.ICSPO_PoMain.SingleOrDefault(a => a.Free1 == lineRwrecord.PRlineID && a.WorkPoint == lineMo2User.WorkPoint);
|
|
if (linePO == null)
|
|
{
|
|
throw new Exception("采购订单行信息查询失败,prline:" + lineRwrecord.PRlineID);
|
|
}
|
|
List<Close4POEntity> closePolines = new List<Close4POEntity>();
|
|
Close4POEntity closepoline = new Close4POEntity();
|
|
closepoline.POCode = linePO.POCode;
|
|
closepoline.PORow = linePO.PORow;
|
|
closePolines.Add(closepoline);
|
|
#endregion
|
|
|
|
#region NC接口专用账户查询
|
|
var infoApiUser = db.Sys_DataBase.SingleOrDefault(a => a.DBSourceName == "UserNCAPI" && a.WorkCode == AppConfig.WorkPointCode);
|
|
if (infoApiUser == null)
|
|
throw new Exception("数据源中未维护调用NC接口的用户:UserNCAPI");
|
|
string ApiUserCode = infoApiUser.DBUser;
|
|
string ApiUserPassword = AppConfig.FromMd5(infoApiUser.DBPwd);
|
|
#endregion
|
|
|
|
#region 关闭采购订单行
|
|
NcApiInputArguments inputInfo = new NcApiInputArguments();
|
|
inputInfo.datasource = "design";
|
|
inputInfo.usercode = ApiUserCode;
|
|
inputInfo.password = ApiUserPassword;
|
|
inputInfo.list = new List<object>();
|
|
if (closePolines != null && closePolines.Count > 0)
|
|
{
|
|
//1.此处虽然是list,但是接口只能处理一行,要注意
|
|
//2.阿威特 poline和prline为一对一的
|
|
inputInfo.list = new List<object>();
|
|
inputInfo.list.Add(closePolines[0]);
|
|
string inputJsonClosepoline = JsonConvert.SerializeObject(inputInfo);
|
|
log.Info("关闭采购订单行\r\n" + JsonConvert.SerializeObject(inputInfo.list));
|
|
string resStrClose = HttpPost(urlClosePOLine, inputJsonClosepoline);
|
|
NcApiOutArguments resClose = new NcApiOutArguments();
|
|
resClose = JsonConvert.DeserializeObject<NcApiOutArguments>(resStrClose);
|
|
if (resClose.flat == "0")
|
|
{
|
|
throw new Exception("关闭采购订单行失败:" + resClose.list_info);
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
|
|
/// <summary>
|
|
/// 删除发料但未收料
|
|
/// </summary>
|
|
/// <param name="ds"></param>
|
|
/// <param name="conn"></param>
|
|
public static void DeleteWW(DataSet ds, string conn)
|
|
{
|
|
List<FormICSCollectWWDataDeleteUIModel> infolist = null;
|
|
FramDataContext db = new FramDataContext(conn);
|
|
db.Connection.Open();
|
|
db.Transaction = db.Connection.BeginTransaction();
|
|
try
|
|
{
|
|
foreach (DataTable dt in ds.Tables)
|
|
{
|
|
#region 主数据
|
|
//dt.Rows排序为OPSEQ正序
|
|
string MOCODE = dt.Rows[0]["MOCODE"].ToString();
|
|
int MOSEQ = Convert.ToInt32(dt.Rows[0]["MOSEQ"].ToString());
|
|
string LOTNO = dt.Rows[0]["LotNo"].ToString();
|
|
string ITEMCODE = dt.Rows[0]["ITEMCODE"].ToString();
|
|
decimal LOTQTY = Convert.ToDecimal(dt.Rows[0]["LOTQTY"].ToString());
|
|
string ROUTECODE = dt.Rows[0]["ROUTECODE"].ToString();
|
|
string OPCODE = dt.Rows[0]["OPCODE"].ToString();
|
|
int OPSEQ = Convert.ToInt32(dt.Rows[0]["OPSEQ"].ToString());
|
|
string EQPCODE = dt.Rows[0]["EQPCode"].ToString();
|
|
//string EQPName = dt.Rows[0]["EQPName"].ToString();
|
|
string CtrlType = dt.Rows[0]["CtrlType"].ToString();
|
|
string VenCode = dt.Rows[0]["VenCode"].ToString();
|
|
//string VenName = dt.Rows[0]["VenName"].ToString();
|
|
string wp = dt.Rows[0]["WorkPoint"].ToString();
|
|
#endregion
|
|
|
|
#region ICSLOTSIMULATION
|
|
var simInfo = db.ICSLOTSIMULATION.SingleOrDefault(a => a.LOTNO == LOTNO && a.ROUTECODE == ROUTECODE);
|
|
if (simInfo == null)
|
|
{
|
|
throw new Exception("跟踪单开工表(Sim)无记录");
|
|
}
|
|
|
|
//1.工艺路线详情
|
|
ICSITEMROUTE2OPLot[] RouteOp = db.ICSITEMROUTE2OPLot.Where(a => a.LotNo == simInfo.LOTNO && a.ROUTECODE == simInfo.ROUTECODE).OrderBy(a => a.OPSEQ).ToArray();
|
|
if (RouteOp.Count() == 0)
|
|
{
|
|
throw new Exception("跟踪单:" + LOTNO + "产品-途程-工序绑定信息已被删除");
|
|
}
|
|
//2.起始工序
|
|
int startSeq = RouteOp[0].OPSEQ;
|
|
if (OPSEQ == startSeq)
|
|
{
|
|
//如果是起始工序,删除
|
|
db.ICSLOTSIMULATION.DeleteOnSubmit(simInfo);
|
|
}
|
|
else
|
|
{
|
|
//否则还原工序
|
|
//1.获取上道工序完工信息
|
|
int preOpSeq = RouteOp.Where(a => a.OPSEQ < OPSEQ).Last().OPSEQ;
|
|
var lineOnwipPreOP = db.ICSLOTONWIP.SingleOrDefault(a => a.LOTNO == LOTNO && a.LOTSEQ == simInfo.LOTSEQ && a.OPSEQ == preOpSeq);
|
|
//2.还原
|
|
simInfo.LOTQTY = Convert.ToDecimal(lineOnwipPreOP.LOTQTY);
|
|
simInfo.OPSEQ = lineOnwipPreOP.OPSEQ;
|
|
simInfo.OPCODE = lineOnwipPreOP.OPCODE;
|
|
simInfo.GOODQTY = lineOnwipPreOP.GOODQTY;
|
|
simInfo.NGQTY = lineOnwipPreOP.NGQTY;
|
|
if (simInfo.NGQTY > 0)
|
|
{
|
|
simInfo.PRODUCTSTATUS = "NG";
|
|
simInfo.LACTION = "NG";
|
|
simInfo.ACTIONLIST = "NG";
|
|
}
|
|
else
|
|
{
|
|
simInfo.PRODUCTSTATUS = "GOOD";
|
|
simInfo.LACTION = "GOOD";
|
|
simInfo.ACTIONLIST = "GOOD";
|
|
}
|
|
simInfo.CollectStatus = "COLLECT_END";
|
|
simInfo.LOTStatus = "删除发料回退";
|
|
simInfo.EQPCODE = lineOnwipPreOP.EQPCODE;
|
|
simInfo.MUSER = AppConfig.UserCode;
|
|
simInfo.MUSERName = AppConfig.UserName;
|
|
simInfo.MTIME = DateTime.Now;
|
|
simInfo.OPList = simInfo.EATTRIBUTE1;//发料时保存的OPList
|
|
simInfo.OPListAttr = lineOnwipPreOP.EATTRIBUTE1;//并行,串行
|
|
simInfo.EATTRIBUTE1 = null;
|
|
db.SubmitChanges();
|
|
}
|
|
db.SubmitChanges();
|
|
#endregion
|
|
|
|
for (int i = 0; i < dt.Rows.Count; i++)
|
|
{
|
|
#region 行数据
|
|
OPCODE = dt.Rows[0]["OPCODE"].ToString();
|
|
OPSEQ = Convert.ToInt32(dt.Rows[0]["OPSEQ"].ToString());
|
|
string POCode = dt.Rows[0]["POCode"].ToString();
|
|
string PORow = dt.Rows[0]["PORow"].ToString();
|
|
string PRLineID = dt.Rows[0]["PRLine"].ToString();
|
|
#endregion
|
|
|
|
#region ICSLOTONWIP删除开工记录
|
|
var wipInfo = db.ICSLOTONWIP.SingleOrDefault(a => a.LOTNO == LOTNO && a.LOTSEQ == simInfo.LOTSEQ && a.OPCODE == OPCODE && a.WorkPoint == wp);
|
|
if (wipInfo == null)
|
|
{
|
|
throw new Exception("跟踪单" + LOTNO + "工序" + OPCODE + "没有发料记录");
|
|
}
|
|
db.ICSLOTONWIP.DeleteOnSubmit(wipInfo);
|
|
#endregion
|
|
|
|
#region ICSPO_PoMain发料数量回退
|
|
var line = db.ICSPO_PoMain.SingleOrDefault(a => a.POCode == POCode && a.PORow == PORow && a.Free1 == PRLineID && a.WorkPoint == wp);
|
|
if (line == null)
|
|
{
|
|
throw new Exception("PO单:" + POCode + ",行: " + PORow + ",PrLineID(Free1): " + PRLineID + "不存在");
|
|
}
|
|
line.INQty = Convert.ToDecimal(line.INQty) - LOTQTY;
|
|
line.MTIME = DateTime.Now;
|
|
if (line.INQty < 0)
|
|
{
|
|
throw new Exception("PO单:" + POCode + ",行: " + PORow + ",PrLineID(Free1): " + PRLineID + "撤销发料" + LOTQTY.ToString() + "后数量,已发数量<0");
|
|
}
|
|
db.SubmitChanges();
|
|
#endregion
|
|
|
|
#region ICSWWDataDeleteLog保存
|
|
var loginfo = db.ICSWareHouseLotInfoLog.SingleOrDefault(a => a.TransNO == POCode && a.TransLine == PORow && a.LotNO == LOTNO && a.Memo == OPCODE
|
|
&& a.BusinessCode == "委外发料" && a.TransType == "发");
|
|
//loginfo.MUSER = AppConfig.UserCode;
|
|
//loginfo.MUSERName = AppConfig.UserName;
|
|
//loginfo.MTIME = DateTime.Now;
|
|
//loginfo.TransType = "发,删";
|
|
//loginfo.BusinessCode = "委外发料,删";
|
|
|
|
ICSWWDataDeleteLog dlog = new ICSWWDataDeleteLog();
|
|
dlog.ID = AppConfig.GetGuid();
|
|
dlog.TransNO = loginfo.TransNO;
|
|
dlog.TransLine = loginfo.TransLine;
|
|
dlog.ITEMCODE = loginfo.ITEMCODE;
|
|
dlog.LotNO = loginfo.LotNO;
|
|
dlog.TransQTY = loginfo.TransQTY;
|
|
dlog.Memo = loginfo.Memo;
|
|
dlog.TransType = loginfo.TransType;
|
|
dlog.BusinessCode = loginfo.BusinessCode;
|
|
dlog.MUSER = AppConfig.UserCode;
|
|
dlog.MUSERName = AppConfig.UserName;
|
|
dlog.MTIME = DateTime.Now;
|
|
dlog.WorkPoint = loginfo.WorkPoint;
|
|
dlog.EATTRIBUTE3 = loginfo.EATTRIBUTE1;
|
|
db.ICSWWDataDeleteLog.InsertOnSubmit(dlog);
|
|
#endregion
|
|
|
|
#region ICSWareHouseLotInfoLog删除
|
|
db.ICSWareHouseLotInfoLog.DeleteOnSubmit(loginfo);
|
|
#endregion
|
|
}
|
|
}
|
|
db.SubmitChanges();
|
|
db.Transaction.Commit();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
db.Transaction.Rollback();
|
|
db.Connection.Close();
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
private static void xx(FramDataContext db, string id, decimal qty)
|
|
{
|
|
var whcodes = db.Sys_EnumValues.Where(a => a.WorkPointCode == AppConfig.WorkPointCode && a.EnumKey == "009").FirstOrDefault();
|
|
if (whcodes == null)
|
|
throw new Exception("未维护默认仓库!");
|
|
string whcode = whcodes.EnumText;
|
|
string sql = @"
|
|
|
|
SELECT
|
|
'Ahwit' AS [group],
|
|
CAST((row_number() over (ORDER BY C.id))*10 AS VARCHAR(100)) AS crowno,
|
|
d.InvCode AS cmaterialoid,
|
|
f.name AS cunitid,
|
|
e.vchangerate AS vchangerate,
|
|
{1} AS nshouldassistnum,
|
|
{1} AS nshouldnum,
|
|
{1} AS nassistnum,
|
|
e.norigprice AS ncostprice,
|
|
e.norigmny AS ncostmny,
|
|
CONVERT(varchar(100),GETDATE(),120) AS dbizdate,
|
|
d.POCode AS vsourcebillcode,
|
|
d.WBS AS csourcebillhid,
|
|
d.Free5 AS cfirstbillbid,
|
|
C.WorkPoint AS org,
|
|
g.code AS corigcurrencyid,
|
|
h.code AS ctaxcodeid,
|
|
'{3}' AS cwarehouseid,
|
|
i.code as creqstoorgoid ,
|
|
j. parentbilltype as cfirsttype,
|
|
j.pk_billtypecode as cfirsttranstype ,
|
|
k.parentbilltype as csourcetype ,
|
|
k.pk_billtypecode as csourcetranstype
|
|
,d.VenCode AS cvendorid,
|
|
CAST(d.Free3 AS DECIMAL(18,2)) AS norignetprice,CAST(d.Free3 AS DECIMAL(18,2)) AS nqtorignetprice,
|
|
CAST(d.Free3*{1} AS DECIMAL(18,2))AS norigmny,
|
|
CAST(d.Free3*{1} AS DECIMAL(18,2)) AS nmny,
|
|
CAST(d.Free2 AS DECIMAL(18,2)) AS norigtaxnetprice,CAST(d.Free2 AS DECIMAL(18,2)) AS nqtorigtaxnetprice,
|
|
CAST(d.Free3*{1} AS DECIMAL(18,2)) AS ncaltaxmny,
|
|
CAST(d.Free2*{1} AS DECIMAL(18,2)) AS ntaxmny,
|
|
CAST(d.Free4 AS DECIMAL(18,2)) AS ntaxrate,
|
|
CAST((d.Free2-d.Free3)*{1} AS DECIMAL(18,2)) AS norigtax,
|
|
CAST(d.Free2*{1} AS DECIMAL(18,2)) AS norigtaxmny
|
|
FROM ICSMO2User c
|
|
INNER JOIN ICSPO_PoMain d ON c.PRLineID=d.Free1 AND c.WorkPoint=d.WorkPoint
|
|
INNER JOIN {0}.[dbo].[po_order_b] e ON d.Free5=e.pk_order_b
|
|
INNER JOIN {0}.[dbo].[bd_measdoc] f ON e.castunitid = f.pk_measdoc
|
|
INNER JOIN {0}.[dbo].[bd_currtype] g ON e.corigcurrencyid = g.pk_currtype
|
|
INNER JOIN {0}.[dbo].[bd_taxcode] h ON e.ctaxcodeid = h.pk_taxcode
|
|
INNER JOIN {0}.[dbo].[org_stockorg_v] i ON i.pk_vid = e.pk_reqstoorg_v
|
|
INNER JOIN {0}.[dbo].[bd_billtype] j ON j.pk_billtypeid = e.vfirsttrantype
|
|
INNER JOIN {0}.[dbo].[bd_billtype] k ON k.pk_billtypeid = e.vsourcetrantype
|
|
WHERE C.ID ='{2}'
|
|
";
|
|
var infoERP = db.Sys_DataBase.SingleOrDefault(a => a.DBSourceName == "ERP" && a.WorkCode == AppConfig.WorkPointCode);
|
|
var infoMES = db.Sys_DataBase.SingleOrDefault(a => a.DBSourceName == "SYS" && a.WorkCode == AppConfig.WorkPointCode);
|
|
string DB = (infoERP.DBIpAddress == infoMES.DBIpAddress ? "" : "[" + infoERP.DBIpAddress + "].") + infoERP.DBName;
|
|
|
|
sql = string.Format(sql, DB, qty, id, whcode);
|
|
var po = db.ExecuteQuery<CreatePODetailEntity>(sql).ToList();
|
|
if (po == null || po.Count() <= 0)
|
|
throw new Exception("采购入库信息查询失败!");
|
|
sql = @"
|
|
SELECT
|
|
'Ahwit' AS [pk_group],
|
|
CAST((row_number() over (ORDER BY a.id))*10 AS VARCHAR(100)) AS crowno,
|
|
d.InvCode AS cmaterialoid,
|
|
f.name AS cunitid,
|
|
f.name AS castunitid,
|
|
e.vchangerate AS vchangerate,
|
|
{1} AS nshouldnum,
|
|
{1} AS nshouldassistnum,
|
|
{1} AS nnum,
|
|
{1} AS nassistnum,
|
|
CAST(e.norigprice AS DECIMAL(18,2)) AS ncostprice,
|
|
CAST({2}*CAST(e.norigprice AS DECIMAL(18,2)) AS DECIMAL(18,2)) AS ncostmny,
|
|
CONVERT(varchar(100),GETDATE(),120) AS dbizdate,
|
|
CONVERT(varchar(100),GETDATE(),120) AS drequiredate,
|
|
d.InvCode AS ccostobject,
|
|
b.MOCODE AS vproductbatch,
|
|
a.WorkPoint AS pk_org,
|
|
x.cpmohid AS csourcebillbid,
|
|
x.ID AS csourcebillhid
|
|
FROM ICSMO2User c
|
|
INNER JOIN ICSMO x ON c.MOCODE=x.MOCODE AND c.MOSEQ=x.MOSEQ AND c.WorkPoint=x.WorkPoint
|
|
INNER JOIN ICSPO_PoMain d ON c.PRLineID=d.Free1 AND c.WorkPoint=d.WorkPoint
|
|
INNER JOIN {0}.[dbo].[po_order_b] e ON d.Free5=e.pk_order_b
|
|
INNER JOIN {0}.[dbo].[bd_measdoc] f ON e.castunitid = f.pk_measdoc
|
|
WHERE c.ID ='{2}'
|
|
";
|
|
sql = string.Format(sql, DB, qty, id);
|
|
var rd = db.ExecuteQuery<Create4DDetailEntity>(sql).ToList();
|
|
if (rd == null || rd.Count() <= 0)
|
|
throw new Exception("材料出库信息查询失败!");
|
|
|
|
var infoApiUser = db.Sys_DataBase.SingleOrDefault(a => a.DBSourceName == "UserNCAPI" && a.WorkCode == AppConfig.WorkPointCode);
|
|
if (infoApiUser == null)
|
|
throw new Exception("数据源中未维护调用NC接口的用户:UserNCAPI");
|
|
string ApiUserCode = infoApiUser.DBUser;
|
|
string ApiUserPassword = AppConfig.FromMd5(infoApiUser.DBPwd);
|
|
|
|
sql = @"
|
|
SELECT
|
|
'{0}' AS datasource,
|
|
'{1}' AS usercode,
|
|
'{2}' AS password,
|
|
B.POCode,
|
|
B.PORow
|
|
FROM
|
|
dbo.ICSMO2User A
|
|
INNER JOIN dbo.ICSPO_PoMain B ON B.Free1=A.PRLineID AND A.WorkPoint=B.WorkPoint
|
|
WHERE A.ID='{3}'
|
|
";
|
|
sql = string.Format(sql, "design", ApiUserCode, ApiUserPassword, id);
|
|
List<Close4POEntity> closePoline = db.ExecuteQuery<Close4POEntity>(sql).ToList();
|
|
if (closePoline == null || closePoline.Count() <= 0)
|
|
throw new Exception("采购订单行信息查询失败!");
|
|
|
|
NcApiInputArguments inputInfo = new NcApiInputArguments();
|
|
inputInfo.datasource = "design";
|
|
inputInfo.usercode = ApiUserCode;// AppConfig.UserCode;
|
|
inputInfo.password = ApiUserPassword;// AppConfig.FromMd5(AppConfig.UserPwd);
|
|
inputInfo.list = new List<object>();
|
|
#region 采购入库
|
|
CreatePOEntity PO = new CreatePOEntity();
|
|
PO.group = "Ahwit";
|
|
PO.org = AppConfig.WorkPointCode;
|
|
string time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
|
PO.billmaker = AppConfig.UserCode;
|
|
PO.dbizdate = time;
|
|
PO.cpayfinorgvid = AppConfig.WorkPointCode;
|
|
PO.cfanaceorgvid = AppConfig.WorkPointCode;
|
|
PO.item = po;
|
|
inputInfo.list.Add(PO);
|
|
|
|
string inputJson = JsonConvert.SerializeObject(inputInfo);
|
|
log.Info("采购入库\r\n" + inputJson);
|
|
string resStrCreatDeliveryPlan = HttpPost(urlCreatPO, inputJson);
|
|
NcApiOutArguments res = new NcApiOutArguments();
|
|
res = JsonConvert.DeserializeObject<NcApiOutArguments>(resStrCreatDeliveryPlan);
|
|
if (res.flat == "0")
|
|
{
|
|
throw new Exception("生成采购入库单失败:" + res.list_info);
|
|
}
|
|
#endregion
|
|
inputInfo.list = new List<object>();
|
|
#region 材料出库
|
|
Create4DEntity RD = new Create4DEntity();
|
|
RD.pk_group = "Ahwit";
|
|
RD.pk_org = AppConfig.WorkPointCode;
|
|
RD.corpoid = AppConfig.WorkPointCode;
|
|
RD.cwarehouseid = whcode;
|
|
RD.cfanaceorgoid = AppConfig.WorkPointCode;
|
|
RD.cfanaceorgvid = AppConfig.WorkPointCode;
|
|
RD.vbillcode = "";
|
|
RD.dbilldate = time;
|
|
RD.creationtime = time;
|
|
RD.list = rd;
|
|
inputInfo.list.Add(RD);
|
|
|
|
string inputJsonRD = JsonConvert.SerializeObject(inputInfo);
|
|
log.Info("材料出库\r\n" + inputJsonRD);
|
|
string resStrCreatDeliveryPlanRD = HttpPost(urlCreat4D, inputJsonRD);
|
|
NcApiOutArguments resRD = new NcApiOutArguments();
|
|
resRD = JsonConvert.DeserializeObject<NcApiOutArguments>(resStrCreatDeliveryPlanRD);
|
|
if (resRD.flat == "0")
|
|
{
|
|
throw new Exception("生成材料出库单失败:" + resRD.list_info);
|
|
}
|
|
#endregion
|
|
|
|
#region 关闭采购订单行
|
|
string inputJsonClosepoline = JsonConvert.SerializeObject(closePoline);
|
|
log.Info("关闭采购订单行\r\n" + inputJsonClosepoline);
|
|
string resStrClose = HttpPost(urlClosePOLine, inputJsonClosepoline);
|
|
NcApiOutArguments resClose = new NcApiOutArguments();
|
|
resClose = JsonConvert.DeserializeObject<NcApiOutArguments>(resStrClose);
|
|
if (res.flat == "0")
|
|
{
|
|
throw new Exception("关闭采购订单行失败:" + res.list_info);
|
|
}
|
|
#endregion
|
|
}
|
|
}
|
|
}
|